77 getTableById ,
88 type CreateAccessTokenVo ,
99} from '@teable/openapi' ;
10+ import { MarkdownPreview } from '@teable/sdk' ;
1011import { useBaseId , useTableId } from '@teable/sdk/hooks' ;
1112import {
1213 Button ,
@@ -123,23 +124,6 @@ const generateAIContext = (
123124
124125 return `# Table: ${ tableName }
125126${ tableDescription ? `\nDescription: ${ tableDescription } \n` : '' }
126- ## Fields
127- ${ fieldDescriptions }
128-
129- ## API Configuration
130- - **Base URL**: ${ baseUrl }
131- - **Table ID**: ${ tableId }
132- - **API Token**: ${ displayToken }
133- - **Endpoint**: \`${ baseUrl } /api/table/${ tableId } /record\`
134-
135- ## Authentication
136- All requests require the \`Authorization\` header:
137- \`\`\`
138- Authorization: Bearer ${ displayToken }
139- \`\`\`
140-
141- ---
142-
143127## API Operations
144128
145129### 1. Read Records (GET)
@@ -244,6 +228,25 @@ curl -X DELETE "${baseUrl}/api/table/${tableId}/record/{recordId}" \\
244228
245229---
246230
231+ ## API Configuration
232+ - **Base URL**: ${ baseUrl }
233+ - **Table ID**: ${ tableId }
234+ - **API Token**: ${ displayToken }
235+ - **Endpoint**: \`${ baseUrl } /api/table/${ tableId } /record\`
236+
237+ ## Authentication
238+ All requests require the \`Authorization\` header:
239+ \`\`\`
240+ Authorization: Bearer ${ displayToken }
241+ \`\`\`
242+
243+ ---
244+
245+ ## Fields
246+ ${ fieldDescriptions }
247+
248+ ---
249+
247250## Notes for AI
248251- Fields marked [PRIMARY] are the main identifier field
249252- Fields marked [READ-ONLY] are computed and cannot be directly modified
@@ -351,17 +354,8 @@ export const APIDialog = ({ children }: APIDialogProps) => {
351354 ) ;
352355 } , [ tableInfo , fields , currentUrl , tableId , generatedToken ] ) ;
353356
354- const handleCopy = useCallback ( ( ) => {
355- const textArea = document . createElement ( 'textarea' ) ;
356- textArea . value = aiContext ;
357- textArea . style . position = 'fixed' ;
358- textArea . style . left = '-999999px' ;
359- textArea . style . top = '-999999px' ;
360- document . body . appendChild ( textArea ) ;
361- textArea . focus ( ) ;
362- textArea . select ( ) ;
363- document . execCommand ( 'copy' ) ;
364- document . body . removeChild ( textArea ) ;
357+ const handleCopy = useCallback ( async ( ) => {
358+ await navigator . clipboard . writeText ( aiContext ) ;
365359 setCopied ( true ) ;
366360 setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
367361 } , [ aiContext ] ) ;
@@ -372,7 +366,7 @@ export const APIDialog = ({ children }: APIDialogProps) => {
372366 return (
373367 < Dialog open = { open } onOpenChange = { setOpen } >
374368 < DialogTrigger asChild > { children } </ DialogTrigger >
375- < DialogContent className = "max-h-[90vh] max-w-4xl" >
369+ < DialogContent className = "flex max-h-[90vh] max-w-4xl flex-col overflow-hidden " >
376370 < DialogHeader >
377371 < DialogTitle className = "flex items-center gap-2" >
378372 < Code2 className = "size-5" />
@@ -392,7 +386,7 @@ export const APIDialog = ({ children }: APIDialogProps) => {
392386 </ TabsTrigger >
393387 </ TabsList >
394388
395- < TabsContent value = "ai-context" >
389+ < TabsContent value = "ai-context" className = "w-full overflow-hidden" >
396390 { isDataLoading ? (
397391 < div className = "flex h-64 items-center justify-center" >
398392 < Loader2 className = "size-8 animate-spin text-muted-foreground" />
@@ -413,11 +407,16 @@ export const APIDialog = ({ children }: APIDialogProps) => {
413407
414408 < div className = "flex items-center justify-between gap-4" >
415409 { generatedToken ? (
416- < div className = "flex items-center gap-2 text-sm text-green-600 dark:text-green-400" >
417- < Check className = "size-4" />
418- { t ( 'table:toolbar.others.api.tokenInfo' , {
419- expiry : new Date ( generatedToken . expiredTime ) . toLocaleDateString ( ) ,
420- } ) }
410+ < div className = "flex flex-col gap-1" >
411+ < div className = "flex items-center gap-2 text-sm text-green-600 dark:text-green-400" >
412+ < Check className = "size-4" />
413+ { t ( 'table:toolbar.others.api.tokenCreatedSuccess' ) }
414+ </ div >
415+ < div className = "text-xs text-muted-foreground" >
416+ { t ( 'table:toolbar.others.api.tokenInfo' , {
417+ expiry : new Date ( generatedToken . expiredTime ) . toLocaleDateString ( ) ,
418+ } ) }
419+ </ div >
421420 </ div >
422421 ) : (
423422 < Button
@@ -448,14 +447,14 @@ export const APIDialog = ({ children }: APIDialogProps) => {
448447 ) : (
449448 < >
450449 < Copy className = "size-4" />
451- { t ( 'table:toolbar.others.api.copyToClipboard ' ) }
450+ { t ( 'table:toolbar.others.api.copy ' ) }
452451 </ >
453452 ) }
454453 </ Button >
455454 </ div >
456455
457456 < ScrollArea className = "h-[400px] rounded-lg border bg-muted/20 p-4" >
458- < pre className = "whitespace-pre-wrap text-sm" > { aiContext } </ pre >
457+ < MarkdownPreview > { aiContext } </ MarkdownPreview >
459458 </ ScrollArea >
460459 </ div >
461460 ) }
0 commit comments