@things-factory/ai-client-base 10.1.278 → 10.1.279
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/service/agent/ai-client-for.js +2 -0
- package/dist-server/service/agent/ai-model-price.d.ts +22 -0
- package/dist-server/service/agent/ai-model-price.js +81 -0
- package/dist-server/service/agent/ai-usage-summary.d.ts +8 -1
- package/dist-server/service/agent/ai-usage-summary.js +17 -4
- package/dist-server/service/agent/ai-usage.d.ts +2 -0
- package/dist-server/service/agent/ai-usage.js +12 -2
- package/dist-server/service/agent/index.d.ts +2 -0
- package/dist-server/service/agent/index.js +4 -1
- package/dist-server/service/agent/model-price-boot.d.ts +1 -0
- package/dist-server/service/agent/model-price-boot.js +14 -0
- package/dist-server/service/agent/model-price.d.ts +77 -0
- package/dist-server/service/agent/model-price.js +214 -0
- package/dist-server/service/index.d.ts +3 -1
- package/dist-server/service/index.js +3 -1
- package/dist-server/service/providers/anthropic.js +2 -5
- package/dist-server/service/providers/gemini.js +2 -6
- package/dist-server/service/providers/openai.js +2 -5
- package/dist-server/service/providers/usage.d.ts +18 -0
- package/dist-server/service/providers/usage.js +50 -0
- package/dist-server/service/types.d.ts +6 -0
- package/package.json +20 -6
- package/translations/en.json +5 -1
- package/translations/es.json +5 -1
- package/translations/ja.json +5 -1
- package/translations/ko.json +5 -1
- package/translations/ms.json +5 -1
- package/translations/zh.json +5 -1
- package/dist-server/index.js.map +0 -1
- package/dist-server/service/agent/agent-directory.js.map +0 -1
- package/dist-server/service/agent/agent-settings-save.js.map +0 -1
- package/dist-server/service/agent/agent-spec.js.map +0 -1
- package/dist-server/service/agent/ai-client-for.js.map +0 -1
- package/dist-server/service/agent/ai-usage-summary.js.map +0 -1
- package/dist-server/service/agent/ai-usage.js.map +0 -1
- package/dist-server/service/agent/index.js.map +0 -1
- package/dist-server/service/agent/provider-models.js.map +0 -1
- package/dist-server/service/agentic-loop/agentic-loop.js.map +0 -1
- package/dist-server/service/agentic-loop/index.js.map +0 -1
- package/dist-server/service/analysis-contract.js.map +0 -1
- package/dist-server/service/assistant/abort-notice.js.map +0 -1
- package/dist-server/service/assistant/assistant-chat.js.map +0 -1
- package/dist-server/service/assistant/index.js.map +0 -1
- package/dist-server/service/assistant/open-subject.js.map +0 -1
- package/dist-server/service/assistant/registry-assistant.js.map +0 -1
- package/dist-server/service/assistant/registry-gate.js.map +0 -1
- package/dist-server/service/assistant/summarize.js.map +0 -1
- package/dist-server/service/assistant/tool-budget.js.map +0 -1
- package/dist-server/service/assistant/tool-scope.js.map +0 -1
- package/dist-server/service/capability.js.map +0 -1
- package/dist-server/service/decision/config.js.map +0 -1
- package/dist-server/service/decision/decision.js.map +0 -1
- package/dist-server/service/decision/index.js.map +0 -1
- package/dist-server/service/decision/jev.js.map +0 -1
- package/dist-server/service/factory.js.map +0 -1
- package/dist-server/service/index.js.map +0 -1
- package/dist-server/service/providers/anthropic.js.map +0 -1
- package/dist-server/service/providers/gemini.js.map +0 -1
- package/dist-server/service/providers/index.js.map +0 -1
- package/dist-server/service/providers/openai.js.map +0 -1
- package/dist-server/service/providers/request-options.js.map +0 -1
- package/dist-server/service/testing/tool-call-context.js.map +0 -1
- package/dist-server/service/tool-registry/call-recorder.js.map +0 -1
- package/dist-server/service/tool-registry/index.js.map +0 -1
- package/dist-server/service/tool-registry/registry.js.map +0 -1
- package/dist-server/service/tool-registry/translate.js.map +0 -1
- package/dist-server/service/tool-registry/types.js.map +0 -1
- package/dist-server/service/types.js.map +0 -1
- package/dist-server/service/utils/grounding.js.map +0 -1
- package/dist-server/service/utils/index.js.map +0 -1
- package/dist-server/service/utils/parse-json.js.map +0 -1
- package/dist-server/service/utils/transient.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
- package/docs/grounded-analysis-contract.md +0 -54
- package/experiments/entity360/README.md +0 -224
- package/experiments/entity360/apps.cjs +0 -103
- package/experiments/entity360/apps.test.cjs +0 -24
- package/experiments/entity360/baseline-apps-results.json +0 -3357
- package/experiments/entity360/baseline-expanded-results.json +0 -5952
- package/experiments/entity360/baseline-results.json +0 -1507
- package/experiments/entity360/expanded.cjs +0 -65
- package/experiments/entity360/fixtures.json +0 -100
- package/experiments/entity360/index.html +0 -44
- package/experiments/entity360/jev-apps-results.json +0 -3440
- package/experiments/entity360/jev-expanded-results.json +0 -6095
- package/experiments/entity360/jev-results.json +0 -1542
- package/experiments/entity360/run.cjs +0 -100
- package/server/index.ts +0 -19
- package/server/service/agent/agent-directory.test.ts +0 -206
- package/server/service/agent/agent-directory.ts +0 -198
- package/server/service/agent/agent-settings-save.test.ts +0 -151
- package/server/service/agent/agent-settings-save.ts +0 -205
- package/server/service/agent/agent-spec.ts +0 -103
- package/server/service/agent/ai-client-for.test.ts +0 -170
- package/server/service/agent/ai-client-for.ts +0 -215
- package/server/service/agent/ai-usage-summary.test.ts +0 -65
- package/server/service/agent/ai-usage-summary.ts +0 -146
- package/server/service/agent/ai-usage.ts +0 -97
- package/server/service/agent/index.ts +0 -7
- package/server/service/agent/one-door.test.ts +0 -57
- package/server/service/agent/provider-models.ts +0 -43
- package/server/service/agentic-loop/agentic-loop.test.ts +0 -1118
- package/server/service/agentic-loop/agentic-loop.ts +0 -745
- package/server/service/agentic-loop/index.ts +0 -1
- package/server/service/agentic-loop/proposal-key.test.ts +0 -83
- package/server/service/analysis-contract.test.ts +0 -20
- package/server/service/analysis-contract.ts +0 -77
- package/server/service/assistant/abort-notice.ts +0 -67
- package/server/service/assistant/assistant-chat.test.ts +0 -240
- package/server/service/assistant/assistant-chat.ts +0 -104
- package/server/service/assistant/index.ts +0 -13
- package/server/service/assistant/open-subject.test.ts +0 -91
- package/server/service/assistant/open-subject.ts +0 -140
- package/server/service/assistant/registry-assistant.test.ts +0 -627
- package/server/service/assistant/registry-assistant.ts +0 -240
- package/server/service/assistant/registry-gate.ts +0 -76
- package/server/service/assistant/summarize.ts +0 -47
- package/server/service/assistant/tool-budget.test.ts +0 -246
- package/server/service/assistant/tool-budget.ts +0 -186
- package/server/service/assistant/tool-scope.test.ts +0 -123
- package/server/service/assistant/tool-scope.ts +0 -103
- package/server/service/capability.test.ts +0 -40
- package/server/service/capability.ts +0 -49
- package/server/service/decision/config.test.ts +0 -55
- package/server/service/decision/config.ts +0 -49
- package/server/service/decision/decision.test.ts +0 -94
- package/server/service/decision/decision.ts +0 -112
- package/server/service/decision/index.ts +0 -3
- package/server/service/decision/jev.ts +0 -40
- package/server/service/factory.ts +0 -28
- package/server/service/index.ts +0 -17
- package/server/service/providers/anthropic.ts +0 -274
- package/server/service/providers/gemini.ts +0 -396
- package/server/service/providers/index.ts +0 -8
- package/server/service/providers/json-answer.test.ts +0 -53
- package/server/service/providers/openai-models.test.ts +0 -30
- package/server/service/providers/openai.ts +0 -326
- package/server/service/providers/request-options.ts +0 -12
- package/server/service/providers/request-signal.test.ts +0 -77
- package/server/service/providers/transcribe.test.ts +0 -18
- package/server/service/testing/tool-call-context.ts +0 -38
- package/server/service/tool-registry/call-recorder.ts +0 -116
- package/server/service/tool-registry/index.ts +0 -50
- package/server/service/tool-registry/registry.test.ts +0 -319
- package/server/service/tool-registry/registry.ts +0 -248
- package/server/service/tool-registry/translate.ts +0 -12
- package/server/service/tool-registry/types.ts +0 -305
- package/server/service/types.ts +0 -221
- package/server/service/utils/grounding.test.ts +0 -119
- package/server/service/utils/grounding.ts +0 -131
- package/server/service/utils/index.ts +0 -3
- package/server/service/utils/parse-json.ts +0 -116
- package/server/service/utils/transient.test.ts +0 -92
- package/server/service/utils/transient.ts +0 -92
- package/tsconfig.json +0 -9
|
@@ -1,627 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* What this guards: **a product with no document of its own gets a working conversation, and only
|
|
3
|
-
* the tools it can actually run.**
|
|
4
|
-
*
|
|
5
|
-
* The gap this closes: the registry half of building a conversation lived inside board-ai, so
|
|
6
|
-
* operato-figure mounted the dock, registered four tools, and had nothing to call — the only
|
|
7
|
-
* mutation that could run them was in a package figure does not load.
|
|
8
|
-
*
|
|
9
|
-
* The trap on the other side is subtler. A registered category can carry `write` and `action`
|
|
10
|
-
* tools, which produce edit ops for a document the host owns. A host with no document cannot
|
|
11
|
-
* apply them, so offering them would put a name in front of the model that leads nowhere. These
|
|
12
|
-
* tests fix that: offered and dispatchable are the same set, and it is the answering kinds only.
|
|
13
|
-
*/
|
|
14
|
-
import { registryAssistantChat, REGISTRY_MAX_ITERATIONS } from './registry-assistant'
|
|
15
|
-
import { clearToolCallRecorders, clearToolRegistry, registerToolCallRecorder, registerToolCategory, type ToolCallRecord } from '../tool-registry/index.js'
|
|
16
|
-
import { toolCallContextFixture } from '../testing/tool-call-context.js'
|
|
17
|
-
import type { AIToolCall, AIToolChatResult } from '../types.js'
|
|
18
|
-
|
|
19
|
-
const TC = (name: string, args: any = {}, id = 't1'): AIToolCall =>
|
|
20
|
-
({ id, name, arguments: args, type: 'tool_use' } as any)
|
|
21
|
-
|
|
22
|
-
const okResult = (text?: string, toolCalls: AIToolCall[] = []): AIToolChatResult =>
|
|
23
|
-
({ text, toolCalls, stopReason: toolCalls.length > 0 ? 'tool_use' : 'end_turn', usage: undefined } as any)
|
|
24
|
-
|
|
25
|
-
/** Records what the provider was handed, so the tests can read the offer rather than infer it. */
|
|
26
|
-
function recordingClient(replies: AIToolChatResult[] = [okResult('answered')]) {
|
|
27
|
-
const seen: Array<{ tools: any[]; options: any }> = []
|
|
28
|
-
let turn = 0
|
|
29
|
-
return {
|
|
30
|
-
seen,
|
|
31
|
-
client: {
|
|
32
|
-
chatWithTools: async (_msgs: any, tools: any[], options: any) => {
|
|
33
|
-
seen.push({ tools, options })
|
|
34
|
-
return replies[Math.min(turn++, replies.length - 1)]
|
|
35
|
-
}
|
|
36
|
-
} as any
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const ran: Array<{ name: string; args: any; context: any }> = []
|
|
41
|
-
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
clearToolRegistry()
|
|
44
|
-
ran.length = 0
|
|
45
|
-
|
|
46
|
-
registerToolCategory({
|
|
47
|
-
name: 'figure-authoring',
|
|
48
|
-
guidance: 'Always look at the figure before describing it.',
|
|
49
|
-
specs: [
|
|
50
|
-
{
|
|
51
|
-
kind: 'read',
|
|
52
|
-
name: 'listFigures',
|
|
53
|
-
description: 'lists figures',
|
|
54
|
-
doors: ['Query.figures'],
|
|
55
|
-
schema: { type: 'object', properties: {} },
|
|
56
|
-
builder: (args: any, context: any) => {
|
|
57
|
-
ran.push({ name: 'listFigures', args, context })
|
|
58
|
-
return { figures: ['roller-conveyor'] }
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
kind: 'write',
|
|
63
|
-
name: 'addComponent',
|
|
64
|
-
description: 'adds a component to the document',
|
|
65
|
-
doors: ['Mutation.updateBoard'],
|
|
66
|
-
schema: { type: 'object', properties: {} },
|
|
67
|
-
builder: () => {
|
|
68
|
-
ran.push({ name: 'addComponent', args: {}, context: null })
|
|
69
|
-
return []
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
} as any)
|
|
74
|
-
|
|
75
|
-
registerToolCategory({
|
|
76
|
-
name: 'plant-ops',
|
|
77
|
-
guidance: 'Never state a quantity you did not read.',
|
|
78
|
-
specs: [
|
|
79
|
-
{
|
|
80
|
-
kind: 'read',
|
|
81
|
-
name: 'readOrderState',
|
|
82
|
-
description: 'reads live order state',
|
|
83
|
-
doors: ['Query.jobOrders'],
|
|
84
|
-
schema: { type: 'object', properties: {} },
|
|
85
|
-
builder: (args: any, context: any) => {
|
|
86
|
-
ran.push({ name: 'readOrderState', args, context })
|
|
87
|
-
return { orders: 3 }
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
]
|
|
91
|
-
} as any)
|
|
92
|
-
|
|
93
|
-
/*
|
|
94
|
-
* A category whose tools change something outside the conversation, each naming the GraphQL door
|
|
95
|
-
* it reaches. This is the shape of board-import's `materializeImportSession`, which creates a Board.
|
|
96
|
-
*/
|
|
97
|
-
registerToolCategory({
|
|
98
|
-
name: 'board-import',
|
|
99
|
-
guidance: 'Create a board only after the user confirms.',
|
|
100
|
-
specs: [
|
|
101
|
-
{
|
|
102
|
-
kind: 'read',
|
|
103
|
-
name: 'getImportSession',
|
|
104
|
-
description: 'reads an import session',
|
|
105
|
-
doors: ['Query.importSession'],
|
|
106
|
-
schema: { type: 'object', properties: {} },
|
|
107
|
-
builder: (args: any, context: any) => {
|
|
108
|
-
ran.push({ name: 'getImportSession', args, context })
|
|
109
|
-
return { status: 'completed' }
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
kind: 'external',
|
|
114
|
-
name: 'materializeImportSession',
|
|
115
|
-
description: 'creates a board from an import session',
|
|
116
|
-
doors: ['Mutation.materializeImportSession'],
|
|
117
|
-
schema: { type: 'object', properties: {} },
|
|
118
|
-
builder: (args: any, context: any) => {
|
|
119
|
-
ran.push({ name: 'materializeImportSession', args, context })
|
|
120
|
-
return { boardId: 'b-1' }
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
]
|
|
124
|
-
} as any)
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
const input = (over: any = {}) => ({
|
|
128
|
-
client: recordingClient().client,
|
|
129
|
-
messages: [{ role: 'user' as const, content: 'what figures do we have' }],
|
|
130
|
-
systemPrompt: 'you help someone draw a figure',
|
|
131
|
-
state: { domain: { id: 'dom-1' }, user: { id: 'u-1' } },
|
|
132
|
-
/*
|
|
133
|
-
* Every tool here names a door, and a door is asked of the host (ADR-0071 decision 2). A caller
|
|
134
|
-
* who passes them all is the uninteresting case, so it is the default; the tests about the gate
|
|
135
|
-
* itself pass their own check, and one passes `toolAccess: undefined` on purpose.
|
|
136
|
-
*/
|
|
137
|
-
toolAccess: async () => true,
|
|
138
|
-
...over
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
describe('what the model is offered', () => {
|
|
142
|
-
it('★ only the kinds that answer — a write tool is not offered to a surface with no document', async () => {
|
|
143
|
-
const { client, seen } = recordingClient()
|
|
144
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring', 'plant-ops'] }))
|
|
145
|
-
|
|
146
|
-
const offered = seen[0].tools.map(tool => tool.name)
|
|
147
|
-
expect(offered).toEqual(expect.arrayContaining(['listFigures', 'readOrderState']))
|
|
148
|
-
expect(offered).not.toContain('addComponent')
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('the category filter narrows the offer', async () => {
|
|
152
|
-
const { client, seen } = recordingClient()
|
|
153
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
154
|
-
|
|
155
|
-
expect(seen[0].tools.map(tool => tool.name)).toEqual(['listFigures'])
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
it('an empty category list offers nothing — a plain conversation is a legitimate surface', async () => {
|
|
159
|
-
const { client, seen } = recordingClient()
|
|
160
|
-
await registryAssistantChat(input({ client, toolCategories: [] }))
|
|
161
|
-
|
|
162
|
-
expect(seen[0].tools).toEqual([])
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it('the result reports what was offered, so the caller can log it without guessing', async () => {
|
|
166
|
-
const result = await registryAssistantChat(input({ toolCategories: ['plant-ops'] }))
|
|
167
|
-
expect(result.offeredTools).toEqual(['readOrderState'])
|
|
168
|
-
})
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
describe('the rules for using a tool travel with it', () => {
|
|
172
|
-
it('★ guidance of the exposed categories reaches the prompt', async () => {
|
|
173
|
-
const { client, seen } = recordingClient()
|
|
174
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
175
|
-
|
|
176
|
-
expect(seen[0].options.systemPrompt).toContain('you help someone draw a figure')
|
|
177
|
-
expect(seen[0].options.systemPrompt).toContain('Always look at the figure before describing it.')
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
it('guidance of a category this conversation cannot call is not read to the model', async () => {
|
|
181
|
-
const { client, seen } = recordingClient()
|
|
182
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
183
|
-
|
|
184
|
-
expect(seen[0].options.systemPrompt).not.toContain('Never state a quantity you did not read.')
|
|
185
|
-
})
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
describe('running a tool', () => {
|
|
189
|
-
it('★ the registered builder runs and is handed the caller state and the host context', async () => {
|
|
190
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures', { q: 'roller' })]), okResult('two of them')])
|
|
191
|
-
|
|
192
|
-
const result = await registryAssistantChat(
|
|
193
|
-
input({ client, toolCategories: ['figure-authoring'], hostContext: { surface: 'figure-modeller', figureId: 'fig-1' } })
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
expect(ran).toHaveLength(1)
|
|
197
|
-
expect(ran[0].name).toBe('listFigures')
|
|
198
|
-
expect(ran[0].args).toEqual({ q: 'roller' })
|
|
199
|
-
expect(ran[0].context.state.domain.id).toBe('dom-1')
|
|
200
|
-
expect(ran[0].context.host).toEqual({ surface: 'figure-modeller', figureId: 'fig-1' })
|
|
201
|
-
expect(result.reply).toContain('two of them')
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
it('★ a write tool call is not executed — the same set decides offering and dispatch', async () => {
|
|
206
|
-
const { client } = recordingClient([okResult(undefined, [TC('addComponent')]), okResult('cannot do that')])
|
|
207
|
-
|
|
208
|
-
/* The category is allowed; the kind is what keeps the write out. */
|
|
209
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
210
|
-
|
|
211
|
-
expect(ran.map(one => one.name)).not.toContain('addComponent')
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('★ a tool outside the allowed categories does not run', async () => {
|
|
215
|
-
const { client } = recordingClient([okResult(undefined, [TC('readOrderState')]), okResult('done')])
|
|
216
|
-
|
|
217
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
218
|
-
|
|
219
|
-
expect(ran.map(one => one.name)).not.toContain('readOrderState')
|
|
220
|
-
})
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
describe('what a tool is handed (A3)', () => {
|
|
224
|
-
it('★ exactly the shared shape — state and host side by side', async () => {
|
|
225
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
226
|
-
const state = { domain: { id: 'dom-1' }, user: { id: 'u-1' } }
|
|
227
|
-
|
|
228
|
-
await registryAssistantChat(input({ client, state, toolCategories: ['figure-authoring'], hostContext: { figureId: 'fig-1' } }))
|
|
229
|
-
|
|
230
|
-
expect(ran[0].context).toEqual(toolCallContextFixture({ domainId: 'dom-1', userId: 'u-1', host: { figureId: 'fig-1' } }))
|
|
231
|
-
expect(ran[0].context.state).not.toHaveProperty('host')
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
it('★ host is an empty object when the surface sent none — a tool never reads it off undefined', async () => {
|
|
235
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
236
|
-
|
|
237
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
238
|
-
|
|
239
|
-
expect(ran[0].context.host).toEqual({})
|
|
240
|
-
})
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
describe('who may use a tool (A1)', () => {
|
|
244
|
-
const grantAll = async () => true
|
|
245
|
-
const denyAll = async () => false
|
|
246
|
-
|
|
247
|
-
it('★ omitting the category list offers nothing and runs nothing', async () => {
|
|
248
|
-
const { client, seen } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('done')])
|
|
249
|
-
|
|
250
|
-
await registryAssistantChat(input({ client, toolAccess: grantAll }))
|
|
251
|
-
|
|
252
|
-
expect(seen[0].tools).toEqual([])
|
|
253
|
-
expect(ran).toHaveLength(0)
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
it('★ a tool that changes something outside is not offered here, even when its door is open', async () => {
|
|
257
|
-
const { client, seen } = recordingClient([okResult(undefined, [TC('materializeImportSession')]), okResult('done')])
|
|
258
|
-
|
|
259
|
-
await registryAssistantChat(input({ client, toolCategories: ['board-import'], toolAccess: grantAll }))
|
|
260
|
-
|
|
261
|
-
expect(seen[0].tools.map((t: any) => t.name)).not.toContain('materializeImportSession')
|
|
262
|
-
expect(ran.map(one => one.name)).not.toContain('materializeImportSession')
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
it('★ a tool whose door the caller cannot pass is neither offered nor run when called by name', async () => {
|
|
266
|
-
const { client, seen } = recordingClient([okResult(undefined, [TC('getImportSession')]), okResult('done')])
|
|
267
|
-
|
|
268
|
-
await registryAssistantChat(input({ client, toolCategories: ['board-import'], toolAccess: denyAll }))
|
|
269
|
-
|
|
270
|
-
expect(seen[0].tools.map((t: any) => t.name)).not.toContain('getImportSession')
|
|
271
|
-
expect(ran.map(one => one.name)).not.toContain('getImportSession')
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
it('★ with no access check at all, a tool that reaches a door stays closed', async () => {
|
|
275
|
-
const { client, seen } = recordingClient([okResult(undefined, [TC('getImportSession')]), okResult('done')])
|
|
276
|
-
|
|
277
|
-
await registryAssistantChat(input({ client, toolCategories: ['board-import'], toolAccess: undefined }))
|
|
278
|
-
|
|
279
|
-
expect(seen[0].tools.map((t: any) => t.name)).not.toContain('getImportSession')
|
|
280
|
-
expect(ran.map(one => one.name)).not.toContain('getImportSession')
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
it('the access check is asked for the doors the tool names, and a caller holding them opens it', async () => {
|
|
284
|
-
const asked: any[] = []
|
|
285
|
-
const { client, seen } = recordingClient([okResult(undefined, [TC('getImportSession')]), okResult('done')])
|
|
286
|
-
|
|
287
|
-
await registryAssistantChat(
|
|
288
|
-
input({
|
|
289
|
-
client,
|
|
290
|
-
toolCategories: ['board-import'],
|
|
291
|
-
toolAccess: async (door: string) => {
|
|
292
|
-
asked.push(door)
|
|
293
|
-
return door.startsWith('Query.')
|
|
294
|
-
}
|
|
295
|
-
})
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
expect(asked).toContain('Query.importSession')
|
|
299
|
-
expect(seen[0].tools.map((t: any) => t.name)).toContain('getImportSession')
|
|
300
|
-
expect(ran.map(one => one.name)).toContain('getImportSession')
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
it('guidance of a category whose every tool is withheld is not read to the model', async () => {
|
|
304
|
-
const { client, seen } = recordingClient()
|
|
305
|
-
|
|
306
|
-
await registryAssistantChat(input({ client, toolCategories: ['board-import'], toolAccess: denyAll }))
|
|
307
|
-
|
|
308
|
-
expect(seen[0].options.systemPrompt).not.toContain('Create a board only after the user confirms.')
|
|
309
|
-
})
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
describe('a client that cannot call tools', () => {
|
|
313
|
-
it('★ refuses instead of answering from nothing', async () => {
|
|
314
|
-
await expect(registryAssistantChat(input({ client: {} as any }))).rejects.toThrow(/cannot call tools/)
|
|
315
|
-
})
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
/*
|
|
319
|
-
* 도구가 「어느 대화에서 불렸나」를 안다 — ADR-0061 결정 3.
|
|
320
|
-
*
|
|
321
|
-
* 이 칸은 A2(모드를 서버가 등록한다)가 서기 전까지 비어 있었고 주석만 「A2 가 서면」이라고 적혀 있었다.
|
|
322
|
-
* A2 가 선 뒤에도 채우는 쪽이 없어서 도구는 계속 `host` 만 봤다 — 그것은 클라이언트가 채우는 칸이다.
|
|
323
|
-
*/
|
|
324
|
-
describe('the tool context carries the conversation', () => {
|
|
325
|
-
it('★ 부르는 쪽이 준 mode 가 도구에게 간다 — 서버의 값이다', async () => {
|
|
326
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
327
|
-
|
|
328
|
-
await registryAssistantChat(
|
|
329
|
-
input({ client, toolCategories: ['figure-authoring'], mode: { kind: 'twin.space', target: 'SITE-1' } })
|
|
330
|
-
)
|
|
331
|
-
|
|
332
|
-
expect(ran[0].context.mode).toEqual({ kind: 'twin.space', target: 'SITE-1' })
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
it('★ 그 값은 `host` 와 섞이지 않는다 — 하나는 서버가, 하나는 클라이언트가 채운다', async () => {
|
|
336
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
337
|
-
|
|
338
|
-
await registryAssistantChat(
|
|
339
|
-
input({
|
|
340
|
-
client,
|
|
341
|
-
toolCategories: ['figure-authoring'],
|
|
342
|
-
hostContext: { figureId: 'fig-1' },
|
|
343
|
-
mode: { kind: 'figure.modeller' }
|
|
344
|
-
})
|
|
345
|
-
)
|
|
346
|
-
|
|
347
|
-
expect(ran[0].context).toEqual(
|
|
348
|
-
toolCallContextFixture({ domainId: 'dom-1', userId: 'u-1', host: { figureId: 'fig-1' }, mode: { kind: 'figure.modeller' } })
|
|
349
|
-
)
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
it('mode 를 안 주면 그 칸은 없다 — 빈 값을 지어내지 않는다', async () => {
|
|
353
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
354
|
-
|
|
355
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
356
|
-
|
|
357
|
-
expect(ran[0].context).not.toHaveProperty('mode')
|
|
358
|
-
})
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
describe('a question that needs many lookups', () => {
|
|
362
|
-
it('★ at the limit the model answers from what it read — no notice tells the person to split the question', async () => {
|
|
363
|
-
const seen: any[] = []
|
|
364
|
-
const client = {
|
|
365
|
-
chatWithTools: async (_msgs: any, _tools: any[], options: any) => {
|
|
366
|
-
seen.push(options.toolChoice)
|
|
367
|
-
return options.toolChoice === 'none' ? okResult('found two; the third is missing') : okResult(undefined, [TC('listFigures')])
|
|
368
|
-
}
|
|
369
|
-
} as any
|
|
370
|
-
|
|
371
|
-
const result = await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
372
|
-
|
|
373
|
-
expect(ran).toHaveLength(REGISTRY_MAX_ITERATIONS)
|
|
374
|
-
expect(REGISTRY_MAX_ITERATIONS).toBeGreaterThan(8)
|
|
375
|
-
expect(seen[seen.length - 1]).toBe('none')
|
|
376
|
-
expect(result.reply).toBe('found two; the third is missing')
|
|
377
|
-
})
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
/*
|
|
381
|
-
* 도구가 사람이 읽는 글을 쓸 번역기와, 서버가 확인한 이번 턴의 파일 — ADR-0061 2026-10-16 판정 1·2.
|
|
382
|
-
*
|
|
383
|
-
* 둘 다 없던 칸이다. 그래서 도구는 카드 제목을 한국어로 박았고(`figure-tools.ts`), 데이터 읽기의
|
|
384
|
-
* `wordsOf` 는 `context.t` 를 읽었지만 채우는 문이 없어 늘 폴백을 냈다. 첨부는 바깥 대화에만 붙고
|
|
385
|
-
* 도구에는 `host` 만 갔으므로, 도형 생성기는 사람이 올린 그림을 받지 못했다.
|
|
386
|
-
*/
|
|
387
|
-
describe('the request translator and the checked attachments (ADR-0061, 2026-10-16)', () => {
|
|
388
|
-
const PNG = { id: 'att-1', name: 'sketch.png', kind: 'image' as const, mediaType: 'image/png', size: 4, data: Buffer.from([1, 2, 3, 4]) }
|
|
389
|
-
|
|
390
|
-
it('★ the request translator reaches the tool as context.t — the one the caller built', async () => {
|
|
391
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
392
|
-
const t = (key: string) => `ko:${key}`
|
|
393
|
-
|
|
394
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'], t }))
|
|
395
|
-
|
|
396
|
-
expect(ran[0].context.t).toBe(t)
|
|
397
|
-
})
|
|
398
|
-
|
|
399
|
-
it('★ without one, the tool still has a translator — it writes the English default value, placeholders filled', async () => {
|
|
400
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
401
|
-
|
|
402
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
403
|
-
|
|
404
|
-
expect(ran[0].context.t('figure.label', { name: 'Mixer', defaultValue: 'Make {name}' })).toBe('Make Mixer')
|
|
405
|
-
/* No default value: the key comes back, so a reader such as `wordsOf` knows nothing was translated. */
|
|
406
|
-
expect(ran[0].context.t('figure.label')).toBe('figure.label')
|
|
407
|
-
})
|
|
408
|
-
|
|
409
|
-
it('★ a translator in the host context is not the one a tool gets — the server builds it', async () => {
|
|
410
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
411
|
-
const fromClient = () => 'from the client'
|
|
412
|
-
|
|
413
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'], hostContext: { t: fromClient } }))
|
|
414
|
-
|
|
415
|
-
expect(ran[0].context.t).not.toBe(fromClient)
|
|
416
|
-
})
|
|
417
|
-
|
|
418
|
-
it('★ the checked attachments reach the tool in their own field, never mixed into host', async () => {
|
|
419
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
420
|
-
|
|
421
|
-
await registryAssistantChat(
|
|
422
|
-
input({ client, toolCategories: ['figure-authoring'], hostContext: { figureId: 'fig-1' }, attachments: [PNG] })
|
|
423
|
-
)
|
|
424
|
-
|
|
425
|
-
expect(ran[0].context.attachments).toEqual([PNG])
|
|
426
|
-
expect(ran[0].context.host).toEqual({ figureId: 'fig-1' })
|
|
427
|
-
})
|
|
428
|
-
|
|
429
|
-
it('★ files the client put in the host context are not attachments', async () => {
|
|
430
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
431
|
-
|
|
432
|
-
await registryAssistantChat(
|
|
433
|
-
input({ client, toolCategories: ['figure-authoring'], hostContext: { image: { data: 'AAAA', mediaType: 'image/png' }, attachments: [PNG] } })
|
|
434
|
-
)
|
|
435
|
-
|
|
436
|
-
expect(ran[0].context.attachments).toEqual([])
|
|
437
|
-
})
|
|
438
|
-
|
|
439
|
-
it('the shared fixture builds the same shape the door hands — translator and attachments included', async () => {
|
|
440
|
-
const { client } = recordingClient([okResult(undefined, [TC('listFigures')]), okResult('ok')])
|
|
441
|
-
const t = (key: string) => key
|
|
442
|
-
const state = { domain: { id: 'dom-1' }, user: { id: 'u-1' } }
|
|
443
|
-
|
|
444
|
-
await registryAssistantChat(input({ client, state, toolCategories: ['figure-authoring'], t, attachments: [PNG] }))
|
|
445
|
-
|
|
446
|
-
expect(ran[0].context).toEqual(toolCallContextFixture({ domainId: 'dom-1', userId: 'u-1', t, attachments: [PNG] }))
|
|
447
|
-
})
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
describe('every call is handed to the recorders - as a digest (ADR-0061 decision 8)', () => {
|
|
451
|
-
const recorded: Array<{ record: ToolCallRecord; context: any }> = []
|
|
452
|
-
const keep = (record: ToolCallRecord, context: any) => {
|
|
453
|
-
recorded.push({ record, context })
|
|
454
|
-
}
|
|
455
|
-
beforeEach(() => {
|
|
456
|
-
clearToolCallRecorders()
|
|
457
|
-
recorded.length = 0
|
|
458
|
-
registerToolCategory({
|
|
459
|
-
name: 'ledger',
|
|
460
|
-
guidance: 'Read the ledger before saying a balance.',
|
|
461
|
-
specs: [
|
|
462
|
-
{
|
|
463
|
-
kind: 'read',
|
|
464
|
-
name: 'readBrokenLedger',
|
|
465
|
-
description: 'a list whose query fails',
|
|
466
|
-
doors: ['Query.ledger'],
|
|
467
|
-
schema: { type: 'object', properties: {} },
|
|
468
|
-
builder: () => {
|
|
469
|
-
throw new Error('the ledger of 김급여 could not be read')
|
|
470
|
-
}
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
kind: 'read',
|
|
474
|
-
name: 'readPay',
|
|
475
|
-
description: 'pay lines',
|
|
476
|
-
doors: ['Query.pay'],
|
|
477
|
-
schema: { type: 'object', properties: {} },
|
|
478
|
-
builder: (args: any) => (args.refuse ? { rejected: true, error: 'query-failed', message: 'unauthorized' } : { read: 2, rows: [{ name: '김급여', net: 3_100_000 }, { name: '이급여', net: 2_900_000 }] })
|
|
479
|
-
}
|
|
480
|
-
]
|
|
481
|
-
} as any)
|
|
482
|
-
})
|
|
483
|
-
afterAll(() => clearToolCallRecorders())
|
|
484
|
-
|
|
485
|
-
it('★ the tool, its category, the ids it names, the size and hash of what came back - and the conversation it ran in', async () => {
|
|
486
|
-
registerToolCallRecorder(keep)
|
|
487
|
-
const { client } = recordingClient([okResult(undefined, [TC('readPay', { employeeId: 'e-7', month: '2026-09' })]), okResult('two people')])
|
|
488
|
-
await registryAssistantChat(input({ client, toolCategories: ['ledger'], mode: { kind: 'office.finance' } }))
|
|
489
|
-
expect(recorded).toHaveLength(1)
|
|
490
|
-
const { record, context } = recorded[0]
|
|
491
|
-
expect(record).toMatchObject({ tool: 'readPay', category: 'ledger', targetIds: ['e-7'], resultCount: 2, ok: true })
|
|
492
|
-
expect(record.argsHash).toMatch(/^[0-9a-f]{64}$/)
|
|
493
|
-
expect(record.resultHash).toMatch(/^[0-9a-f]{64}$/)
|
|
494
|
-
expect(record.resultSize).toBeGreaterThan(0)
|
|
495
|
-
expect(context.mode).toEqual({ kind: 'office.finance' })
|
|
496
|
-
expect(context.state.domain.id).toBe('dom-1')
|
|
497
|
-
})
|
|
498
|
-
|
|
499
|
-
it('★ pay and names are not in the record by default - only a category the recorder names carries them', async () => {
|
|
500
|
-
registerToolCallRecorder(keep)
|
|
501
|
-
const { client } = recordingClient([okResult(undefined, [TC('readPay', { month: '2026-09' })]), okResult('two people')])
|
|
502
|
-
const turn: any = await registryAssistantChat(input({ client, toolCategories: ['ledger'] }))
|
|
503
|
-
expect(recorded[0].record.raw).toBeUndefined()
|
|
504
|
-
/* The conversation row keeps the same shape - the dock's tool panel shows how many, never whose pay. */
|
|
505
|
-
expect(turn.loop.toolUsages[0].result).toEqual({ size: expect.any(Number), count: 2, keys: ['read', 'rows'] })
|
|
506
|
-
expect(JSON.stringify(turn.loop.toolUsages)).not.toMatch(/김급여|3100000/)
|
|
507
|
-
expect(JSON.stringify(recorded[0].record)).not.toMatch(/김급여|3100000|2026-09/)
|
|
508
|
-
|
|
509
|
-
clearToolCallRecorders()
|
|
510
|
-
recorded.length = 0
|
|
511
|
-
registerToolCallRecorder(keep, { raw: ['ledger'] })
|
|
512
|
-
const again = recordingClient([okResult(undefined, [TC('readPay', { month: '2026-09' })]), okResult('two people')])
|
|
513
|
-
await registryAssistantChat(input({ client: again.client, toolCategories: ['ledger'] }))
|
|
514
|
-
expect(recorded[0].record.raw).toEqual({ args: { month: '2026-09' }, result: { read: 2, rows: [{ name: '김급여', net: 3_100_000 }, { name: '이급여', net: 2_900_000 }] } })
|
|
515
|
-
})
|
|
516
|
-
|
|
517
|
-
it('★ a tool that throws or refuses is recorded by a code, never by its message - and the model is still told', async () => {
|
|
518
|
-
registerToolCallRecorder(keep)
|
|
519
|
-
const { client } = recordingClient([okResult(undefined, [TC('readBrokenLedger'), TC('readPay', { refuse: true }, 't2')]), okResult('could not read it')])
|
|
520
|
-
const result = await registryAssistantChat(input({ client, toolCategories: ['ledger'] }))
|
|
521
|
-
expect(recorded.map(one => [one.record.tool, one.record.errorCode, one.record.ok])).toEqual([
|
|
522
|
-
['readBrokenLedger', 'tool-threw', false],
|
|
523
|
-
['readPay', 'query-failed', false]
|
|
524
|
-
])
|
|
525
|
-
expect(recorded[0].record.resultSize).toBe(0)
|
|
526
|
-
expect(JSON.stringify(recorded[0].record)).not.toMatch(/김급여/)
|
|
527
|
-
expect(result.reply).toContain('could not read it')
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
it('a recorder that fails does not stop the answer', async () => {
|
|
531
|
-
registerToolCallRecorder(() => {
|
|
532
|
-
throw new Error('audit table missing')
|
|
533
|
-
})
|
|
534
|
-
registerToolCallRecorder(keep)
|
|
535
|
-
const { client } = recordingClient([okResult(undefined, [TC('readOrderState')]), okResult('three orders')])
|
|
536
|
-
const result = await registryAssistantChat(input({ client, toolCategories: ['plant-ops'] }))
|
|
537
|
-
expect(result.reply).toContain('three orders')
|
|
538
|
-
expect(recorded).toHaveLength(1)
|
|
539
|
-
})
|
|
540
|
-
|
|
541
|
-
it('a tool that was not offered is not run, so nothing is recorded', async () => {
|
|
542
|
-
registerToolCallRecorder(keep)
|
|
543
|
-
const { client } = recordingClient([okResult(undefined, [TC('readOrderState')]), okResult('done')])
|
|
544
|
-
await registryAssistantChat(input({ client, toolCategories: ['figure-authoring'] }))
|
|
545
|
-
expect(recorded).toHaveLength(0)
|
|
546
|
-
})
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
describe('an unattended run goes through the same door (design/ai/unattended-run.md)', () => {
|
|
550
|
-
const recorded: Array<{ record: ToolCallRecord; context: any }> = []
|
|
551
|
-
const RUN = { id: 'run-1', source: 'office.strategy-review', subject: 'policy-9', scheduledAt: '2026-11-01T07:00:00.000Z' }
|
|
552
|
-
beforeEach(() => {
|
|
553
|
-
clearToolCallRecorders()
|
|
554
|
-
recorded.length = 0
|
|
555
|
-
registerToolCallRecorder((record, context) => {
|
|
556
|
-
recorded.push({ record, context })
|
|
557
|
-
})
|
|
558
|
-
registerToolCategory({
|
|
559
|
-
name: 'ledger',
|
|
560
|
-
guidance: 'Read the pay before saying it.',
|
|
561
|
-
specs: [
|
|
562
|
-
{
|
|
563
|
-
kind: 'read',
|
|
564
|
-
name: 'readPay',
|
|
565
|
-
description: 'pay lines',
|
|
566
|
-
doors: ['Query.pay'],
|
|
567
|
-
schema: { type: 'object', properties: {} },
|
|
568
|
-
builder: (args: any, context: any) => {
|
|
569
|
-
ran.push({ name: 'readPay', args, context })
|
|
570
|
-
if (args.fail) throw new Error('the pay of 김급여 could not be read')
|
|
571
|
-
return { read: 1, rows: [{ name: '김급여', net: 3_100_000 }] }
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
]
|
|
575
|
-
} as any)
|
|
576
|
-
})
|
|
577
|
-
afterAll(() => clearToolCallRecorders())
|
|
578
|
-
|
|
579
|
-
it('★ the run reaches the tool and the recorder as context.run - and a turn carries none', async () => {
|
|
580
|
-
const run = recordingClient([okResult(undefined, [TC('readPay')]), okResult('drafted')])
|
|
581
|
-
await registryAssistantChat(input({ client: run.client, toolCategories: ['ledger'], run: RUN }))
|
|
582
|
-
expect(ran[0].context.run).toEqual(RUN)
|
|
583
|
-
expect(recorded[0].context.run).toEqual(RUN)
|
|
584
|
-
|
|
585
|
-
const turn = recordingClient([okResult(undefined, [TC('readPay')]), okResult('answered')])
|
|
586
|
-
await registryAssistantChat(input({ client: turn.client, toolCategories: ['ledger'] }))
|
|
587
|
-
expect('run' in ran[1].context).toBe(false)
|
|
588
|
-
expect('run' in recorded[1].context).toBe(false)
|
|
589
|
-
})
|
|
590
|
-
|
|
591
|
-
it('★ onToolCall is handed the very digest the recorders get - one reading of a call, success and failure', async () => {
|
|
592
|
-
const seen: ToolCallRecord[] = []
|
|
593
|
-
const { client } = recordingClient([okResult(undefined, [TC('readPay', { employeeId: 'e-7' }, 'a'), TC('readPay', { fail: true }, 'b')]), okResult('drafted')])
|
|
594
|
-
await registryAssistantChat(input({ client, toolCategories: ['ledger'], run: RUN, onToolCall: (record: ToolCallRecord) => seen.push(record) }))
|
|
595
|
-
expect(seen).toHaveLength(2)
|
|
596
|
-
const strip = ({ durationMs: _d, ...rest }: any) => rest
|
|
597
|
-
expect(seen.map(strip)).toEqual(recorded.map(one => strip(one.record)))
|
|
598
|
-
expect(seen[0]).toMatchObject({ tool: 'readPay', targetIds: ['e-7'], ok: true, resultCount: 1 })
|
|
599
|
-
expect(seen[1]).toMatchObject({ tool: 'readPay', ok: false, errorCode: 'tool-threw', resultSize: 0 })
|
|
600
|
-
expect(JSON.stringify(seen)).not.toMatch(/김급여|3100000/)
|
|
601
|
-
})
|
|
602
|
-
|
|
603
|
-
it('an onToolCall that throws does not stop the run or the recorders', async () => {
|
|
604
|
-
const { client } = recordingClient([okResult(undefined, [TC('readPay')]), okResult('drafted')])
|
|
605
|
-
const result = await registryAssistantChat(input({ client, toolCategories: ['ledger'], onToolCall: () => { throw new Error('boom') } }))
|
|
606
|
-
expect(result.reply).toContain('drafted')
|
|
607
|
-
expect(recorded).toHaveLength(1)
|
|
608
|
-
})
|
|
609
|
-
|
|
610
|
-
it('★ the signal reaches every provider request, and the step limit holds with no wrap-up call', async () => {
|
|
611
|
-
const abort = new AbortController()
|
|
612
|
-
const { client, seen } = recordingClient([okResult(undefined, [TC('readPay')])])
|
|
613
|
-
const result = await registryAssistantChat(
|
|
614
|
-
input({ client, toolCategories: ['ledger'], signal: abort.signal, maxIterations: 3, salvageOnMaxIterations: false })
|
|
615
|
-
)
|
|
616
|
-
expect(seen).toHaveLength(3)
|
|
617
|
-
expect(seen.every(one => one.options.signal === abort.signal)).toBe(true)
|
|
618
|
-
expect(result.loop.abortReason).toMatchObject({ type: 'max_iterations' })
|
|
619
|
-
})
|
|
620
|
-
|
|
621
|
-
it('without the new inputs a turn keeps its limit and its wrap-up', async () => {
|
|
622
|
-
const { client, seen } = recordingClient([okResult(undefined, [TC('readPay')])])
|
|
623
|
-
await registryAssistantChat(input({ client, toolCategories: ['ledger'] }))
|
|
624
|
-
/* REGISTRY_MAX_ITERATIONS lookups and one wrap-up without tools. */
|
|
625
|
-
expect(seen).toHaveLength(REGISTRY_MAX_ITERATIONS + 1)
|
|
626
|
-
})
|
|
627
|
-
})
|