Skip to content

Commit 2eb9a27

Browse files
committed
refactor(P060): collapse client-tools/schemas.ts into tools.ts
The tool-name registry (CLIENT_TOOL_NAMES, ClientToolName, isClientToolName) lived next to the LLM_STATIC_TOOLS map but in a separate file for no real reason. Merging both into tools.ts puts every LLM-tool decision (which schema, which name, the runtime guard) in one place. Adding a tool now touches one file in the adapter (tools.ts) + one switch arm in factory.ts.
1 parent 2a58fd4 commit 2eb9a27

5 files changed

Lines changed: 36 additions & 37 deletions

File tree

copilot/src/lib/embed-bridge-adapters/client-tools/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
SetFieldValueInput,
1313
} from '../../embed-bridge'
1414
import { composeMiddleware, type ToolMiddleware } from './middleware'
15-
import { type ClientToolName, isClientToolName } from './schemas'
15+
import { type ClientToolName, isClientToolName } from './tools'
1616

1717
export type ToolInput = Record<string, unknown>
1818

copilot/src/lib/embed-bridge-adapters/client-tools/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ export type { FinalisationAction, FinalisationToolMap } from './finalisation'
44
export { FINALISATION_ACTION, FINALISATION_TOOL, withFinalisationTool } from './finalisation'
55
export type { MiddlewareContext, ToolMiddleware } from './middleware'
66
export { composeMiddleware } from './middleware'
7-
export type { ClientToolName } from './schemas'
8-
export { CLIENT_TOOL_NAMES, isClientToolName } from './schemas'
9-
export { LLM_STATIC_TOOLS } from './tools'
7+
export type { ClientToolName } from './tools'
8+
export { CLIENT_TOOL_NAMES, isClientToolName, LLM_STATIC_TOOLS } from './tools'

copilot/src/lib/embed-bridge-adapters/client-tools/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BridgeResult } from '../../embed-bridge'
22
import type { ToolInput } from './factory'
3-
import type { ClientToolName } from './schemas'
3+
import type { ClientToolName } from './tools'
44

55
// Onion-style middleware. Each layer receives a context (tool name + input)
66
// and `next()` which triggers the inner dispatcher. Layers can short-circuit

copilot/src/lib/embed-bridge-adapters/client-tools/schemas.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

copilot/src/lib/embed-bridge-adapters/client-tools/tools.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ import {
1313
SetFieldValueInput,
1414
} from '../../embed-bridge'
1515

16-
// LLM tool registration map. Each entry pulls its description verbatim
17-
// from the bridge schema's `.describe()` — no duplication. Spread into
18-
// streamText({ tools: withFinalisationTool(LLM_STATIC_TOOLS) }) on both
19-
// the /api/chat and BYOK paths. Adding a new LLM tool is one line here +
20-
// one switch arm in `factory.ts`.
16+
// LLM-tool adapter for the bridge. The bridge owns the schemas (with
17+
// descriptions) in embed-bridge/schemas.ts; this file enumerates which
18+
// bridge operations are exposed to the LLM, under which snake_case tool
19+
// name, and pulls each description verbatim from the bridge schema's
20+
// `.describe()` — no duplicated text.
21+
//
22+
// Adding a new LLM tool: add an entry to LLM_STATIC_TOOLS, add the snake
23+
// name to CLIENT_TOOL_NAMES, add a switch arm in factory.ts. The switch
24+
// is exhaustive over ClientToolName, so any addition forces a matching
25+
// arm at compile time.
26+
2127
const tool = <TSchema extends z.ZodType>(inputSchema: TSchema): { description: string; inputSchema: TSchema } => ({
2228
description: inputSchema.description ?? '',
2329
inputSchema,
@@ -36,3 +42,24 @@ export const LLM_STATIC_TOOLS = {
3642
delete_pages: tool(DeletePagesInput),
3743
rotate_page: tool(RotatePageInput),
3844
} as const
45+
46+
export const CLIENT_TOOL_NAMES = [
47+
'get_fields',
48+
'get_document_content',
49+
'detect_fields',
50+
'delete_fields',
51+
'select_tool',
52+
'set_field_value',
53+
'focus_field',
54+
'go_to_page',
55+
'move_page',
56+
'delete_pages',
57+
'rotate_page',
58+
'submit',
59+
'download',
60+
] as const
61+
62+
export type ClientToolName = (typeof CLIENT_TOOL_NAMES)[number]
63+
64+
export const isClientToolName = (value: unknown): value is ClientToolName =>
65+
typeof value === 'string' && CLIENT_TOOL_NAMES.some((candidate) => candidate === value)

0 commit comments

Comments
 (0)