Skip to content

Commit 735945a

Browse files
committed
refactor(P060): keep loadDocument on the bridge (not exposed as LLM tool)
Restores `bridge.loadDocument` + `LoadDocumentInput`. The method stays available for direct host-app consumers / SDK adapters; it is NOT in LLM_STATIC_TOOLS or ClientToolName, so the LLM cannot invoke it via the copilot tool registry. This separates the bridge surface (full iframe contract) from the LLM-tool surface (a curated subset).
1 parent aa32048 commit 735945a

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

copilot/src/lib/embed-bridge/bridge.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
FocusFieldInput,
77
GetDocumentContentInput,
88
GoToInput,
9+
LoadDocumentInput,
910
MovePageInput,
1011
RotatePageInput,
1112
SelectToolInput,
@@ -51,6 +52,7 @@ const getRequestTimeoutMs = (requestType: BridgeRequestType): number => {
5152
case 'GET_FIELDS':
5253
case 'DOWNLOAD':
5354
case 'GO_TO':
55+
case 'LOAD_DOCUMENT':
5456
case 'MOVE_PAGE':
5557
case 'ROTATE_PAGE':
5658
case 'SELECT_TOOL':
@@ -403,6 +405,7 @@ export const createBridge = ({
403405
}
404406
const bridge: IframeBridge = {
405407
getState: () => state,
408+
loadDocument: (args) => parseAndSend(LoadDocumentInput, 'LOAD_DOCUMENT', args),
406409
getFields: () => sendRequest<{ fields: FieldRecord[] }>('GET_FIELDS', {}),
407410
getDocumentContent: (args) => parseAndSend<typeof GetDocumentContentInput, DocumentContentResult>(
408411
GetDocumentContentInput,

copilot/src/lib/embed-bridge/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
GetDocumentContentInput,
1212
GetFieldsInput,
1313
GoToInput,
14+
LoadDocumentInput,
1415
MovePageInput,
1516
NoInput,
1617
RotatePageInput,

copilot/src/lib/embed-bridge/schemas.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,14 @@ export const SubmitInput = z
9898
export const DownloadInput = NoInput.describe(
9999
'Finalizes the filled PDF and triggers an in-browser download for the user. Use only when the user asks to download.',
100100
)
101+
102+
// Bridge-only — not exposed as an LLM tool. Direct callers (host apps,
103+
// SDK adapters) load documents via this; the copilot demo itself bootstraps
104+
// from URL params and doesn't currently use it.
105+
export const LoadDocumentInput = z
106+
.object({
107+
data_url: z.string(),
108+
name: z.string().optional(),
109+
page: z.number().int().positive().optional(),
110+
})
111+
.describe('Loads a PDF document into the editor by URL or data-URL.')

copilot/src/lib/embed-bridge/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export type BridgeState =
7474
// Request type union. Every postMessage the bridge sends carries one of these
7575
// as its `type` field. The editor honours each.
7676
export type BridgeRequestType =
77+
| 'LOAD_DOCUMENT'
7778
| 'GO_TO'
7879
| 'SELECT_TOOL'
7980
| 'DETECT_FIELDS'
@@ -98,6 +99,7 @@ export type FocusFieldResult = { hint: { type: 'user_action_expected'; message:
9899
// re-validate.
99100
export type IframeBridge = {
100101
getState: () => BridgeState
102+
loadDocument: (args: unknown) => Promise<BridgeResult>
101103
getFields: () => Promise<BridgeResult<{ fields: FieldRecord[] }>>
102104
getDocumentContent: (args: unknown) => Promise<BridgeResult<DocumentContentResult>>
103105
detectFields: () => Promise<BridgeResult<{ detected_count: number }>>

0 commit comments

Comments
 (0)