@theokit/agents 7.3.1 → 7.4.1
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/{agent-handle-tgyu8J7q.d.ts → agent-handle-BX4oFqfb.d.ts} +10 -10
- package/dist/auth.d.ts +68 -66
- package/dist/auth.js +106 -98
- package/dist/auth.js.map +1 -1
- package/dist/{bridge-entry-ofFpOe-j.d.ts → bridge-entry-Z8GjrwH4.d.ts} +85 -84
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +1 -2
- package/dist/{chunk-CVDPGEJF.js → chunk-FJA4QQLZ.js} +191 -246
- package/dist/chunk-FJA4QQLZ.js.map +1 -0
- package/dist/{chunk-7ECCHM4N.js → chunk-PHUNONZT.js} +523 -1053
- package/dist/chunk-PHUNONZT.js.map +1 -0
- package/dist/client-react.d.ts +1 -1
- package/dist/client-react.js +3 -9
- package/dist/client-react.js.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -2
- package/dist/index.d.ts +82 -50
- package/dist/index.js +161 -394
- package/dist/index.js.map +1 -1
- package/dist/interactive.js +6 -3
- package/dist/interactive.js.map +1 -1
- package/dist/persistence.js +0 -2
- package/dist/persistence.js.map +1 -1
- package/dist/pty.js +7 -3
- package/dist/pty.js.map +1 -1
- package/dist/sandbox.js +26 -3
- package/dist/sandbox.js.map +1 -1
- package/dist/testing.js +3 -21
- package/dist/testing.js.map +1 -1
- package/dist/tools.js +55 -3
- package/dist/tools.js.map +1 -1
- package/package.json +12 -12
- package/LICENSE +0 -201
- package/dist/chunk-7ECCHM4N.js.map +0 -1
- package/dist/chunk-CVDPGEJF.js.map +0 -1
- package/dist/chunk-Z4QWC7IK.js +0 -7
- package/dist/chunk-Z4QWC7IK.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -76,10 +76,7 @@ import {
|
|
|
76
76
|
toolRuntimeName,
|
|
77
77
|
translateSdkEvent,
|
|
78
78
|
unicodeNormalizer
|
|
79
|
-
} from "./chunk-
|
|
80
|
-
import {
|
|
81
|
-
__name
|
|
82
|
-
} from "./chunk-Z4QWC7IK.js";
|
|
79
|
+
} from "./chunk-PHUNONZT.js";
|
|
83
80
|
|
|
84
81
|
// src/index.ts
|
|
85
82
|
import { Agent as AgentDoSdk } from "@theokit/sdk";
|
|
@@ -87,16 +84,13 @@ import { Agent as AgentDoSdk } from "@theokit/sdk";
|
|
|
87
84
|
// src/capability/capability.ts
|
|
88
85
|
import { isDeepStrictEqual } from "util";
|
|
89
86
|
var CapabilityConflictError = class extends Error {
|
|
90
|
-
static {
|
|
91
|
-
__name(this, "CapabilityConflictError");
|
|
92
|
-
}
|
|
93
87
|
name = "CapabilityConflictError";
|
|
94
88
|
constructor(field, previous, next, capability) {
|
|
95
89
|
super(
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
`capability "${capability}":
|
|
90
|
+
// NEVER echo the values: a draft assembled from a config file may carry an MCP token, an auth
|
|
91
|
+
// header, a memory credential. Report the SHAPE, as the capabilities' boundary validation
|
|
92
|
+
// already does.
|
|
93
|
+
`capability "${capability}": field "${field}" already declared (${shapeOf(previous)}) and redeclared with a different value (${shapeOf(next)}) \u2014 declare it once.`
|
|
100
94
|
);
|
|
101
95
|
}
|
|
102
96
|
};
|
|
@@ -108,21 +102,14 @@ function shapeOf(value) {
|
|
|
108
102
|
}
|
|
109
103
|
return typeof value;
|
|
110
104
|
}
|
|
111
|
-
__name(shapeOf, "shapeOf");
|
|
112
105
|
function createDraft() {
|
|
113
|
-
return {
|
|
114
|
-
tools: [],
|
|
115
|
-
agents: {},
|
|
116
|
-
provenance: []
|
|
117
|
-
};
|
|
106
|
+
return { tools: [], agents: {}, provenance: [] };
|
|
118
107
|
}
|
|
119
|
-
__name(createDraft, "createDraft");
|
|
120
108
|
function applyCapabilities(capabilities, draft = createDraft()) {
|
|
121
109
|
for (const c of capabilities) c.apply(draft);
|
|
122
110
|
draft.stream ??= true;
|
|
123
111
|
return draft;
|
|
124
112
|
}
|
|
125
|
-
__name(applyCapabilities, "applyCapabilities");
|
|
126
113
|
function setOnce(draft, field, value, capability) {
|
|
127
114
|
if (value === void 0) return;
|
|
128
115
|
const previous = draft[field];
|
|
@@ -130,36 +117,26 @@ function setOnce(draft, field, value, capability) {
|
|
|
130
117
|
throw new CapabilityConflictError(field, previous, value, capability);
|
|
131
118
|
}
|
|
132
119
|
draft[field] = value;
|
|
133
|
-
draft.provenance.push({
|
|
134
|
-
capability,
|
|
135
|
-
contributed: [
|
|
136
|
-
field
|
|
137
|
-
]
|
|
138
|
-
});
|
|
120
|
+
draft.provenance.push({ capability, contributed: [field] });
|
|
139
121
|
}
|
|
140
|
-
__name(setOnce, "setOnce");
|
|
141
122
|
|
|
142
123
|
// src/capability/capabilities.ts
|
|
143
124
|
function describe(value) {
|
|
144
125
|
if (value === null) return "null";
|
|
145
126
|
return Array.isArray(value) ? "array" : typeof value;
|
|
146
127
|
}
|
|
147
|
-
__name(describe, "describe");
|
|
148
128
|
var ModelCapability = class {
|
|
149
|
-
static {
|
|
150
|
-
__name(this, "ModelCapability");
|
|
151
|
-
}
|
|
152
|
-
id;
|
|
153
|
-
reasoningEffort;
|
|
154
|
-
name = "model";
|
|
155
129
|
constructor(id, reasoningEffort) {
|
|
156
130
|
this.id = id;
|
|
157
131
|
this.reasoningEffort = reasoningEffort;
|
|
158
132
|
if (typeof id !== "string") {
|
|
159
|
-
throw new ConfigurationError(`model:
|
|
133
|
+
throw new ConfigurationError(`model: expected a string, got ${describe(id)}`);
|
|
160
134
|
}
|
|
161
|
-
if (id.trim().length === 0) throw new ConfigurationError("model: id
|
|
135
|
+
if (id.trim().length === 0) throw new ConfigurationError("model: id cannot be empty");
|
|
162
136
|
}
|
|
137
|
+
id;
|
|
138
|
+
reasoningEffort;
|
|
139
|
+
name = "model";
|
|
163
140
|
apply(draft) {
|
|
164
141
|
setOnce(draft, "model", this.id, this.name);
|
|
165
142
|
if (this.reasoningEffort !== void 0) {
|
|
@@ -168,9 +145,6 @@ var ModelCapability = class {
|
|
|
168
145
|
}
|
|
169
146
|
};
|
|
170
147
|
var ToolsCapability = class {
|
|
171
|
-
static {
|
|
172
|
-
__name(this, "ToolsCapability");
|
|
173
|
-
}
|
|
174
148
|
name = "tools";
|
|
175
149
|
#tools;
|
|
176
150
|
constructor(tools) {
|
|
@@ -178,42 +152,34 @@ var ToolsCapability = class {
|
|
|
178
152
|
}
|
|
179
153
|
apply(draft) {
|
|
180
154
|
draft.tools.push(...this.#tools);
|
|
181
|
-
draft.provenance.push({
|
|
182
|
-
capability: this.name,
|
|
183
|
-
contributed: [
|
|
184
|
-
"tools"
|
|
185
|
-
]
|
|
186
|
-
});
|
|
155
|
+
draft.provenance.push({ capability: this.name, contributed: ["tools"] });
|
|
187
156
|
}
|
|
188
157
|
};
|
|
189
158
|
var SkillsCapability = class {
|
|
190
|
-
static {
|
|
191
|
-
__name(this, "SkillsCapability");
|
|
192
|
-
}
|
|
193
159
|
name = "skills";
|
|
194
160
|
#entries;
|
|
195
161
|
constructor(entries) {
|
|
196
162
|
if (!Array.isArray(entries)) {
|
|
197
|
-
throw new ConfigurationError(`skills:
|
|
163
|
+
throw new ConfigurationError(`skills: expected an array of names, got ${describe(entries)}`);
|
|
198
164
|
}
|
|
199
165
|
for (const e of entries) {
|
|
200
166
|
if (typeof e === "string") {
|
|
201
167
|
if (e.trim().length === 0) {
|
|
202
|
-
throw new ConfigurationError("skills:
|
|
168
|
+
throw new ConfigurationError("skills: empty name \u2014 use a non-empty skill name");
|
|
203
169
|
}
|
|
204
170
|
continue;
|
|
205
171
|
}
|
|
206
172
|
if (typeof e !== "object" || e === null || Array.isArray(e)) {
|
|
207
|
-
throw new ConfigurationError(
|
|
173
|
+
throw new ConfigurationError(
|
|
174
|
+
`skills: invalid entry (${describe(e)}) \u2014 use a name or an inline skill`
|
|
175
|
+
);
|
|
208
176
|
}
|
|
209
|
-
for (const field of [
|
|
210
|
-
"name",
|
|
211
|
-
"description",
|
|
212
|
-
"instructions"
|
|
213
|
-
]) {
|
|
177
|
+
for (const field of ["name", "description", "instructions"]) {
|
|
214
178
|
const value = e[field];
|
|
215
179
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
216
|
-
throw new ConfigurationError(
|
|
180
|
+
throw new ConfigurationError(
|
|
181
|
+
`skills: inline skill without a valid \`${field}\` (${describe(value)}) \u2014 name, description and instructions are all required`
|
|
182
|
+
);
|
|
217
183
|
}
|
|
218
184
|
}
|
|
219
185
|
}
|
|
@@ -232,40 +198,21 @@ var SkillsCapability = class {
|
|
|
232
198
|
// and no reference array form can express it) — revisit when one can.
|
|
233
199
|
...previous,
|
|
234
200
|
...compiled.skills,
|
|
235
|
-
enabled: [
|
|
236
|
-
|
|
237
|
-
...compiled.skills.enabled ?? []
|
|
238
|
-
],
|
|
239
|
-
...previous.inline !== void 0 || compiled.skills.inline !== void 0 ? {
|
|
240
|
-
inline: [
|
|
241
|
-
...previous.inline ?? [],
|
|
242
|
-
...compiled.skills.inline ?? []
|
|
243
|
-
]
|
|
244
|
-
} : {}
|
|
201
|
+
enabled: [...previous.enabled ?? [], ...compiled.skills.enabled ?? []],
|
|
202
|
+
...previous.inline !== void 0 || compiled.skills.inline !== void 0 ? { inline: [...previous.inline ?? [], ...compiled.skills.inline ?? []] } : {}
|
|
245
203
|
};
|
|
246
|
-
draft.provenance.push({
|
|
247
|
-
capability: this.name,
|
|
248
|
-
contributed: [
|
|
249
|
-
"skills"
|
|
250
|
-
]
|
|
251
|
-
});
|
|
204
|
+
draft.provenance.push({ capability: this.name, contributed: ["skills"] });
|
|
252
205
|
}
|
|
253
206
|
};
|
|
254
207
|
|
|
255
208
|
// src/capability/registry.ts
|
|
256
209
|
var UnknownCapabilityError = class extends Error {
|
|
257
|
-
static {
|
|
258
|
-
__name(this, "UnknownCapabilityError");
|
|
259
|
-
}
|
|
260
210
|
name = "UnknownCapabilityError";
|
|
261
211
|
constructor(requested, known) {
|
|
262
|
-
super(`capability "${requested}"
|
|
212
|
+
super(`capability "${requested}" is not registered. Known: ${known.join(", ") || "(none)"}.`);
|
|
263
213
|
}
|
|
264
214
|
};
|
|
265
215
|
var CapabilityRegistry = class {
|
|
266
|
-
static {
|
|
267
|
-
__name(this, "CapabilityRegistry");
|
|
268
|
-
}
|
|
269
216
|
#factories = /* @__PURE__ */ new Map();
|
|
270
217
|
register(name, factory) {
|
|
271
218
|
this.#factories.set(name, factory);
|
|
@@ -275,9 +222,7 @@ var CapabilityRegistry = class {
|
|
|
275
222
|
return this.#factories.has(name);
|
|
276
223
|
}
|
|
277
224
|
names() {
|
|
278
|
-
return [
|
|
279
|
-
...this.#factories.keys()
|
|
280
|
-
];
|
|
225
|
+
return [...this.#factories.keys()];
|
|
281
226
|
}
|
|
282
227
|
resolve(name, arg) {
|
|
283
228
|
const factory = this.#factories.get(name);
|
|
@@ -286,15 +231,12 @@ var CapabilityRegistry = class {
|
|
|
286
231
|
}
|
|
287
232
|
};
|
|
288
233
|
var CapabilityPreset = class {
|
|
289
|
-
static {
|
|
290
|
-
__name(this, "CapabilityPreset");
|
|
291
|
-
}
|
|
292
|
-
name;
|
|
293
|
-
#members;
|
|
294
234
|
constructor(name, members) {
|
|
295
235
|
this.name = name;
|
|
296
236
|
this.#members = members;
|
|
297
237
|
}
|
|
238
|
+
name;
|
|
239
|
+
#members;
|
|
298
240
|
apply(draft) {
|
|
299
241
|
for (const member of this.#members) member.apply(draft);
|
|
300
242
|
}
|
|
@@ -302,169 +244,120 @@ var CapabilityPreset = class {
|
|
|
302
244
|
|
|
303
245
|
// src/capability/agent-capabilities.ts
|
|
304
246
|
var FieldCapability = class {
|
|
305
|
-
static {
|
|
306
|
-
__name(this, "FieldCapability");
|
|
307
|
-
}
|
|
308
|
-
value;
|
|
309
247
|
constructor(value) {
|
|
310
248
|
this.value = value;
|
|
311
249
|
}
|
|
250
|
+
value;
|
|
312
251
|
apply(draft) {
|
|
313
252
|
setOnce(draft, this.field, this.value, this.name);
|
|
314
253
|
}
|
|
315
254
|
};
|
|
316
255
|
var MemoryCapability = class extends FieldCapability {
|
|
317
|
-
static {
|
|
318
|
-
__name(this, "MemoryCapability");
|
|
319
|
-
}
|
|
320
256
|
name = "memory";
|
|
321
257
|
field = "memory";
|
|
322
258
|
};
|
|
323
259
|
var ContextWindowCapability = class {
|
|
324
|
-
static {
|
|
325
|
-
__name(this, "ContextWindowCapability");
|
|
326
|
-
}
|
|
327
|
-
options;
|
|
328
|
-
name = "context-window";
|
|
329
260
|
constructor(options) {
|
|
330
261
|
this.options = options;
|
|
331
262
|
}
|
|
263
|
+
options;
|
|
264
|
+
name = "context-window";
|
|
332
265
|
apply(draft) {
|
|
333
266
|
setOnce(draft, "context", compileContextWindow(this.options).context, this.name);
|
|
334
267
|
}
|
|
335
268
|
};
|
|
336
269
|
var ProjectContextCapability = class extends FieldCapability {
|
|
337
|
-
static {
|
|
338
|
-
__name(this, "ProjectContextCapability");
|
|
339
|
-
}
|
|
340
270
|
name = "project-context";
|
|
341
271
|
field = "projectContext";
|
|
342
272
|
};
|
|
343
273
|
var McpServersCapability = class extends FieldCapability {
|
|
344
|
-
static {
|
|
345
|
-
__name(this, "McpServersCapability");
|
|
346
|
-
}
|
|
347
274
|
name = "mcp";
|
|
348
275
|
field = "mcpServers";
|
|
349
276
|
};
|
|
350
277
|
var GuardrailsCapability = class extends FieldCapability {
|
|
351
|
-
static {
|
|
352
|
-
__name(this, "GuardrailsCapability");
|
|
353
|
-
}
|
|
354
278
|
name = "guardrails";
|
|
355
279
|
field = "guardrails";
|
|
356
280
|
};
|
|
357
281
|
var CheckpointCapability = class {
|
|
358
|
-
static {
|
|
359
|
-
__name(this, "CheckpointCapability");
|
|
360
|
-
}
|
|
361
|
-
options;
|
|
362
|
-
name = "checkpoint";
|
|
363
282
|
constructor(options) {
|
|
364
283
|
this.options = options;
|
|
365
284
|
}
|
|
285
|
+
options;
|
|
286
|
+
name = "checkpoint";
|
|
366
287
|
apply(draft) {
|
|
367
288
|
if (this.options !== void 0 && this.options.storage !== "filesystem") {
|
|
368
|
-
console.warn(
|
|
289
|
+
console.warn(
|
|
290
|
+
`[THEO_AGENT_CHECKPOINT_STORAGE_METADATA_ONLY] checkpoint({ storage: '${this.options.storage ?? "memory"}' }) does NOT resume across requests \u2014 only 'filesystem' selects the SDK's durable conversation store. Use checkpoint({ storage: 'filesystem' }) for cross-request resume.`
|
|
291
|
+
);
|
|
369
292
|
}
|
|
370
293
|
setOnce(draft, "checkpoint", this.options, this.name);
|
|
371
294
|
}
|
|
372
295
|
};
|
|
373
296
|
var HumanInTheLoopCapability = class extends FieldCapability {
|
|
374
|
-
static {
|
|
375
|
-
__name(this, "HumanInTheLoopCapability");
|
|
376
|
-
}
|
|
377
297
|
name = "human-in-the-loop";
|
|
378
298
|
field = "hitl";
|
|
379
299
|
};
|
|
380
300
|
var SubAgentsCapability = class {
|
|
381
|
-
static {
|
|
382
|
-
__name(this, "SubAgentsCapability");
|
|
383
|
-
}
|
|
384
|
-
children;
|
|
385
|
-
name = "sub-agents";
|
|
386
301
|
constructor(children) {
|
|
387
302
|
this.children = children;
|
|
388
303
|
}
|
|
304
|
+
children;
|
|
305
|
+
name = "sub-agents";
|
|
389
306
|
apply(draft) {
|
|
390
307
|
for (const [name, child] of Object.entries(this.children)) {
|
|
391
308
|
if (name in draft.agents && draft.agents[name] !== child) {
|
|
392
|
-
throw new ConfigurationError(
|
|
309
|
+
throw new ConfigurationError(
|
|
310
|
+
`sub-agents: child "${name}" declared twice with different definitions`
|
|
311
|
+
);
|
|
393
312
|
}
|
|
394
313
|
draft.agents[name] = child;
|
|
395
314
|
}
|
|
396
|
-
draft.provenance.push({
|
|
397
|
-
capability: this.name,
|
|
398
|
-
contributed: [
|
|
399
|
-
"agents"
|
|
400
|
-
]
|
|
401
|
-
});
|
|
315
|
+
draft.provenance.push({ capability: this.name, contributed: ["agents"] });
|
|
402
316
|
}
|
|
403
317
|
};
|
|
404
318
|
var SkillsOptionsCapability = class {
|
|
405
|
-
static {
|
|
406
|
-
__name(this, "SkillsOptionsCapability");
|
|
407
|
-
}
|
|
408
|
-
options;
|
|
409
|
-
name = "skills";
|
|
410
319
|
constructor(options) {
|
|
411
320
|
this.options = options;
|
|
412
321
|
}
|
|
322
|
+
options;
|
|
323
|
+
name = "skills";
|
|
413
324
|
apply(draft) {
|
|
414
325
|
setOnce(draft, "skills", compileSkills(this.options), this.name);
|
|
415
326
|
}
|
|
416
327
|
};
|
|
417
328
|
var SettingSourcesCapability = class extends FieldCapability {
|
|
418
|
-
static {
|
|
419
|
-
__name(this, "SettingSourcesCapability");
|
|
420
|
-
}
|
|
421
329
|
name = "setting-sources";
|
|
422
330
|
field = "settingSources";
|
|
423
331
|
};
|
|
424
332
|
var PluginsCapability = class extends FieldCapability {
|
|
425
|
-
static {
|
|
426
|
-
__name(this, "PluginsCapability");
|
|
427
|
-
}
|
|
428
333
|
name = "plugins";
|
|
429
334
|
field = "plugins";
|
|
430
335
|
};
|
|
431
336
|
var RunContextCapability = class extends FieldCapability {
|
|
432
|
-
static {
|
|
433
|
-
__name(this, "RunContextCapability");
|
|
434
|
-
}
|
|
435
337
|
name = "run-context";
|
|
436
338
|
field = "runContext";
|
|
437
339
|
};
|
|
438
340
|
var SkillsResolverCapability = class extends FieldCapability {
|
|
439
|
-
static {
|
|
440
|
-
__name(this, "SkillsResolverCapability");
|
|
441
|
-
}
|
|
442
341
|
name = "skills-resolver";
|
|
443
342
|
field = "skillsResolver";
|
|
444
343
|
};
|
|
445
344
|
var AgentConfigCapability = class {
|
|
446
|
-
static {
|
|
447
|
-
__name(this, "AgentConfigCapability");
|
|
448
|
-
}
|
|
449
|
-
config;
|
|
450
|
-
name = "agent-config";
|
|
451
345
|
constructor(config) {
|
|
452
346
|
this.config = config;
|
|
453
347
|
if (typeof config !== "object" || config === null) {
|
|
454
|
-
throw new ConfigurationError("agent-config:
|
|
348
|
+
throw new ConfigurationError("agent-config: expected a configuration object");
|
|
455
349
|
}
|
|
456
|
-
for (const field of [
|
|
457
|
-
"maxIterations",
|
|
458
|
-
"timeoutMs"
|
|
459
|
-
]) {
|
|
350
|
+
for (const field of ["maxIterations", "timeoutMs"]) {
|
|
460
351
|
const value = config[field];
|
|
461
352
|
if (value !== void 0 && (!Number.isFinite(value) || value <= 0)) {
|
|
462
|
-
throw new ConfigurationError(`agent-config: \`${field}\`
|
|
353
|
+
throw new ConfigurationError(`agent-config: \`${field}\` must be a positive number`);
|
|
463
354
|
}
|
|
464
355
|
}
|
|
465
356
|
}
|
|
357
|
+
config;
|
|
358
|
+
name = "agent-config";
|
|
466
359
|
apply(draft) {
|
|
467
|
-
const claimedByMainLoop =
|
|
360
|
+
const claimedByMainLoop = (field) => draft.provenance.some((p) => p.capability === "main-loop" && p.contributed.includes(field));
|
|
468
361
|
if (!claimedByMainLoop("maxIterations")) {
|
|
469
362
|
setOnce(draft, "maxIterations", this.config.maxIterations, this.name);
|
|
470
363
|
}
|
|
@@ -479,14 +372,11 @@ var AgentConfigCapability = class {
|
|
|
479
372
|
}
|
|
480
373
|
};
|
|
481
374
|
var MainLoopCapability = class {
|
|
482
|
-
static {
|
|
483
|
-
__name(this, "MainLoopCapability");
|
|
484
|
-
}
|
|
485
|
-
config;
|
|
486
|
-
name = "main-loop";
|
|
487
375
|
constructor(config) {
|
|
488
376
|
this.config = config;
|
|
489
377
|
}
|
|
378
|
+
config;
|
|
379
|
+
name = "main-loop";
|
|
490
380
|
apply(draft) {
|
|
491
381
|
const contributed = [];
|
|
492
382
|
if (this.config.maxIterations !== void 0) {
|
|
@@ -497,33 +387,31 @@ var MainLoopCapability = class {
|
|
|
497
387
|
draft.timeoutMs = this.config.timeoutMs;
|
|
498
388
|
contributed.push("timeoutMs");
|
|
499
389
|
}
|
|
500
|
-
if (contributed.length > 0) draft.provenance.push({
|
|
501
|
-
capability: this.name,
|
|
502
|
-
contributed
|
|
503
|
-
});
|
|
390
|
+
if (contributed.length > 0) draft.provenance.push({ capability: this.name, contributed });
|
|
504
391
|
}
|
|
505
392
|
};
|
|
506
393
|
|
|
507
394
|
// src/capability/toolbox.ts
|
|
508
395
|
var ToolboxCapability = class {
|
|
509
|
-
static {
|
|
510
|
-
__name(this, "ToolboxCapability");
|
|
511
|
-
}
|
|
512
396
|
name = "toolbox";
|
|
513
397
|
#instance;
|
|
514
398
|
#declarations;
|
|
515
399
|
#namespace;
|
|
516
400
|
constructor(instance, options = {}) {
|
|
517
401
|
if (typeof instance !== "object" || instance === null) {
|
|
518
|
-
throw new ConfigurationError("toolbox:
|
|
402
|
+
throw new ConfigurationError("toolbox: expected a toolbox instance");
|
|
519
403
|
}
|
|
520
404
|
const declared = options.tools ?? instance.constructor.tools;
|
|
521
405
|
if (declared === void 0 || declared.length === 0) {
|
|
522
|
-
throw new ConfigurationError(
|
|
406
|
+
throw new ConfigurationError(
|
|
407
|
+
`toolbox: ${instance.constructor.name} declares no tools \u2014 use \`static tools = [...]\` or the \`tools\` option`
|
|
408
|
+
);
|
|
523
409
|
}
|
|
524
410
|
for (const tool of declared) {
|
|
525
411
|
if (typeof instance[tool.method] !== "function") {
|
|
526
|
-
throw new ConfigurationError(
|
|
412
|
+
throw new ConfigurationError(
|
|
413
|
+
`toolbox: ${instance.constructor.name}.${tool.method} is not a method (tool "${tool.name}")`
|
|
414
|
+
);
|
|
527
415
|
}
|
|
528
416
|
}
|
|
529
417
|
this.#instance = instance;
|
|
@@ -532,15 +420,15 @@ var ToolboxCapability = class {
|
|
|
532
420
|
for (const tool of declared) toolRuntimeName(this.#namespace, tool.name);
|
|
533
421
|
}
|
|
534
422
|
/**
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
423
|
+
* The single derivation of this toolbox (M55). Both compilers below consume THIS object, so the
|
|
424
|
+
* tool registry and the HITL gate map cannot disagree on a name — the property is structural, not
|
|
425
|
+
* a convention repeated in two loops. That repetition is precisely how the two drifted apart in
|
|
426
|
+
* #145: the tool became `ns_tool` while its gate stayed `ns.tool`, silently ungating it.
|
|
427
|
+
*
|
|
428
|
+
* Same technique the `opencode` harness uses for the analogous tool↔permission coupling, where
|
|
429
|
+
* `Permission.visibleTools` filters the tool record itself rather than keeping a parallel map
|
|
430
|
+
* ("so the two cannot drift" — `permission/index.ts`).
|
|
431
|
+
*/
|
|
544
432
|
#walk() {
|
|
545
433
|
return {
|
|
546
434
|
// `constructor` is typed `Function` by lib.d.ts; here it is used purely as an IDENTITY key
|
|
@@ -555,117 +443,87 @@ var ToolboxCapability = class {
|
|
|
555
443
|
approval: tool.approval,
|
|
556
444
|
trace: tool.trace ?? false,
|
|
557
445
|
audit: tool.audit ?? false,
|
|
558
|
-
...tool.hitl !== void 0 ? {
|
|
559
|
-
hitl: tool.hitl
|
|
560
|
-
} : {}
|
|
446
|
+
...tool.hitl !== void 0 ? { hitl: tool.hitl } : {}
|
|
561
447
|
}))
|
|
562
448
|
};
|
|
563
449
|
}
|
|
564
450
|
/**
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
451
|
+
* M56 — the public `compile()` is GONE. It had zero callers anywhere in the monorepo and was kept
|
|
452
|
+
* only because deleting a public method is breaking; that concession is exactly the dead surface
|
|
453
|
+
* M55 set out to remove, preserved inside the milestone that removed it. `apply()` is the one path.
|
|
454
|
+
*/
|
|
569
455
|
apply(draft) {
|
|
570
456
|
const walk = this.#walk();
|
|
571
|
-
draft.tools.push(...compileTools([
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
[
|
|
575
|
-
walk.class,
|
|
576
|
-
this.#instance
|
|
577
|
-
]
|
|
578
|
-
])));
|
|
579
|
-
draft.provenance.push({
|
|
580
|
-
capability: this.name,
|
|
581
|
-
contributed: [
|
|
582
|
-
"tools"
|
|
583
|
-
]
|
|
584
|
-
});
|
|
585
|
-
const gates = compileHitlGates([
|
|
586
|
-
walk
|
|
587
|
-
]);
|
|
457
|
+
draft.tools.push(...compileTools([walk], /* @__PURE__ */ new Map([[walk.class, this.#instance]])));
|
|
458
|
+
draft.provenance.push({ capability: this.name, contributed: ["tools"] });
|
|
459
|
+
const gates = compileHitlGates([walk]);
|
|
588
460
|
if (gates.size === 0) return;
|
|
589
461
|
draft.hitl ??= /* @__PURE__ */ new Map();
|
|
590
462
|
for (const [key, options] of gates) draft.hitl.set(key, options);
|
|
591
|
-
draft.provenance.push({
|
|
592
|
-
capability: this.name,
|
|
593
|
-
contributed: [
|
|
594
|
-
"hitl"
|
|
595
|
-
]
|
|
596
|
-
});
|
|
463
|
+
draft.provenance.push({ capability: this.name, contributed: ["hitl"] });
|
|
597
464
|
}
|
|
598
465
|
};
|
|
599
466
|
|
|
600
467
|
// src/capability/toolset.ts
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
__name(this, "ToolsetError");
|
|
604
|
-
}
|
|
605
|
-
code;
|
|
468
|
+
import { TheokitAgentError } from "@theokit/sdk/errors";
|
|
469
|
+
var ToolsetError = class extends TheokitAgentError {
|
|
606
470
|
constructor(message, code) {
|
|
607
|
-
super(message)
|
|
608
|
-
this.
|
|
471
|
+
super(message);
|
|
472
|
+
this.code = code;
|
|
609
473
|
}
|
|
474
|
+
code;
|
|
475
|
+
name = "ToolsetError";
|
|
610
476
|
};
|
|
611
477
|
var Toolset = class _Toolset {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
#porNome;
|
|
616
|
-
constructor(porNome) {
|
|
617
|
-
this.#porNome = porNome;
|
|
478
|
+
#byName;
|
|
479
|
+
constructor(byName) {
|
|
480
|
+
this.#byName = byName;
|
|
618
481
|
Object.freeze(this);
|
|
619
482
|
}
|
|
620
483
|
/**
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
484
|
+
* Builds from tools that are already instantiated. Fails loud on a duplicate name **at construction**
|
|
485
|
+
* — not at resolution: a descriptor with two tools of the same name is wrong the moment it is
|
|
486
|
+
* written, and deferring the error to the first `resolve` hides half the cases.
|
|
487
|
+
*/
|
|
625
488
|
static from(tools) {
|
|
626
|
-
const
|
|
489
|
+
const byName = /* @__PURE__ */ new Map();
|
|
627
490
|
for (const tool of tools) {
|
|
628
|
-
if (
|
|
491
|
+
if (byName.has(tool.name)) {
|
|
629
492
|
throw new ToolsetError(`duplicate tool "${tool.name}" in toolset`, "duplicate_tool");
|
|
630
493
|
}
|
|
631
|
-
|
|
494
|
+
byName.set(tool.name, tool);
|
|
632
495
|
}
|
|
633
|
-
return new _Toolset(
|
|
496
|
+
return new _Toolset(byName);
|
|
634
497
|
}
|
|
635
|
-
/**
|
|
498
|
+
/** One tool by name. Throws with the name in the error — never returns `undefined` silently. */
|
|
636
499
|
get(name) {
|
|
637
|
-
const tool = this.#
|
|
500
|
+
const tool = this.#byName.get(name);
|
|
638
501
|
if (tool === void 0) {
|
|
639
502
|
throw new ToolsetError(`unknown tool "${name}"`, "unknown_tool");
|
|
640
503
|
}
|
|
641
504
|
return tool;
|
|
642
505
|
}
|
|
643
506
|
/**
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
*/
|
|
507
|
+
* Resolves a whitelist. Fails loud on an unknown name **and** on a duplicate within the list itself:
|
|
508
|
+
* a team never silently grants a tool the role did not declare, nor silently drops one it did.
|
|
509
|
+
*/
|
|
648
510
|
resolve(names) {
|
|
649
|
-
const
|
|
511
|
+
const seen = /* @__PURE__ */ new Set();
|
|
650
512
|
return names.map((name) => {
|
|
651
|
-
if (
|
|
513
|
+
if (seen.has(name)) {
|
|
652
514
|
throw new ToolsetError(`duplicate tool "${name}" in a whitelist`, "duplicate_tool");
|
|
653
515
|
}
|
|
654
|
-
|
|
516
|
+
seen.add(name);
|
|
655
517
|
return this.get(name);
|
|
656
518
|
});
|
|
657
519
|
}
|
|
658
|
-
/**
|
|
520
|
+
/** The known names, in registration order. */
|
|
659
521
|
names() {
|
|
660
|
-
return [
|
|
661
|
-
...this.#porNome.keys()
|
|
662
|
-
];
|
|
522
|
+
return [...this.#byName.keys()];
|
|
663
523
|
}
|
|
664
|
-
/**
|
|
524
|
+
/** All the tools, in registration order. */
|
|
665
525
|
all() {
|
|
666
|
-
return [
|
|
667
|
-
...this.#porNome.values()
|
|
668
|
-
];
|
|
526
|
+
return [...this.#byName.values()];
|
|
669
527
|
}
|
|
670
528
|
};
|
|
671
529
|
|
|
@@ -673,7 +531,6 @@ var Toolset = class _Toolset {
|
|
|
673
531
|
function trimTrailingSlash(url) {
|
|
674
532
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
675
533
|
}
|
|
676
|
-
__name(trimTrailingSlash, "trimTrailingSlash");
|
|
677
534
|
function buildAgentCard(entry, options) {
|
|
678
535
|
const base = trimTrailingSlash(options.baseUrl);
|
|
679
536
|
return {
|
|
@@ -686,24 +543,14 @@ function buildAgentCard(entry, options) {
|
|
|
686
543
|
pushNotifications: false,
|
|
687
544
|
stateTransitionHistory: false
|
|
688
545
|
},
|
|
689
|
-
defaultInputModes: [
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
defaultOutputModes: [
|
|
693
|
-
"text"
|
|
694
|
-
],
|
|
695
|
-
skills: entry.tools.map((t) => ({
|
|
696
|
-
id: t.name,
|
|
697
|
-
name: t.name,
|
|
698
|
-
description: t.description
|
|
699
|
-
}))
|
|
546
|
+
defaultInputModes: ["text"],
|
|
547
|
+
defaultOutputModes: ["text"],
|
|
548
|
+
skills: entry.tools.map((t) => ({ id: t.name, name: t.name, description: t.description }))
|
|
700
549
|
};
|
|
701
550
|
}
|
|
702
|
-
__name(buildAgentCard, "buildAgentCard");
|
|
703
551
|
function wellKnownCardPath(agentName) {
|
|
704
552
|
return `/.well-known/${agentName}/agent-card.json`;
|
|
705
553
|
}
|
|
706
|
-
__name(wellKnownCardPath, "wellKnownCardPath");
|
|
707
554
|
|
|
708
555
|
// src/a2a/mcp-server-manifest.ts
|
|
709
556
|
var MCP_PROTOCOL_VERSION = "2024-11-05";
|
|
@@ -711,33 +558,20 @@ function buildMcpToolDescriptors(entry) {
|
|
|
711
558
|
return entry.tools.map((t) => ({
|
|
712
559
|
name: t.name,
|
|
713
560
|
description: t.description,
|
|
714
|
-
inputSchema: {
|
|
715
|
-
type: "object",
|
|
716
|
-
properties: {}
|
|
717
|
-
}
|
|
561
|
+
inputSchema: { type: "object", properties: {} }
|
|
718
562
|
}));
|
|
719
563
|
}
|
|
720
|
-
__name(buildMcpToolDescriptors, "buildMcpToolDescriptors");
|
|
721
564
|
function mcpServerInfo(entry) {
|
|
722
|
-
return {
|
|
723
|
-
name: entry.name,
|
|
724
|
-
version: "1.0",
|
|
725
|
-
protocolVersion: MCP_PROTOCOL_VERSION
|
|
726
|
-
};
|
|
565
|
+
return { name: entry.name, version: "1.0", protocolVersion: MCP_PROTOCOL_VERSION };
|
|
727
566
|
}
|
|
728
|
-
__name(mcpServerInfo, "mcpServerInfo");
|
|
729
567
|
|
|
730
568
|
// src/a2a/a2a-client.ts
|
|
731
569
|
function buildHeaders(config) {
|
|
732
|
-
const headers = {
|
|
733
|
-
"content-type": "application/json",
|
|
734
|
-
...config.headers
|
|
735
|
-
};
|
|
570
|
+
const headers = { "content-type": "application/json", ...config.headers };
|
|
736
571
|
if (config.auth?.bearer) headers.authorization = `Bearer ${config.auth.bearer}`;
|
|
737
572
|
if (config.auth?.apiKey) headers[config.auth.apiKey.header] = config.auth.apiKey.value;
|
|
738
573
|
return headers;
|
|
739
574
|
}
|
|
740
|
-
__name(buildHeaders, "buildHeaders");
|
|
741
575
|
function createA2ATool(config) {
|
|
742
576
|
const doFetch = config.fetchImpl ?? fetch;
|
|
743
577
|
return {
|
|
@@ -745,34 +579,24 @@ function createA2ATool(config) {
|
|
|
745
579
|
description: config.description,
|
|
746
580
|
inputSchema: {
|
|
747
581
|
type: "object",
|
|
748
|
-
properties: {
|
|
749
|
-
|
|
750
|
-
type: "string",
|
|
751
|
-
description: "The message to send to the remote agent."
|
|
752
|
-
}
|
|
753
|
-
},
|
|
754
|
-
required: [
|
|
755
|
-
"message"
|
|
756
|
-
]
|
|
582
|
+
properties: { message: { type: "string", description: "The message to send to the remote agent." } },
|
|
583
|
+
required: ["message"]
|
|
757
584
|
},
|
|
758
|
-
handler:
|
|
585
|
+
handler: async (input) => {
|
|
759
586
|
const message = typeof input.message === "string" ? input.message : "";
|
|
760
587
|
const res = await doFetch(config.url, {
|
|
761
588
|
method: "POST",
|
|
762
589
|
headers: buildHeaders(config),
|
|
763
|
-
body: JSON.stringify({
|
|
764
|
-
message
|
|
765
|
-
})
|
|
590
|
+
body: JSON.stringify({ message })
|
|
766
591
|
});
|
|
767
592
|
if (!res.ok) {
|
|
768
593
|
throw new Error(`A2A call to "${config.name}" failed: ${res.status} ${res.statusText}`);
|
|
769
594
|
}
|
|
770
595
|
const data = await res.json();
|
|
771
596
|
return data.response ?? data.text ?? "";
|
|
772
|
-
}
|
|
597
|
+
}
|
|
773
598
|
};
|
|
774
599
|
}
|
|
775
|
-
__name(createA2ATool, "createA2ATool");
|
|
776
600
|
|
|
777
601
|
// src/conversation-scope.ts
|
|
778
602
|
var SEPARATOR = "/";
|
|
@@ -781,19 +605,14 @@ function deriveConversationId(resource, thread) {
|
|
|
781
605
|
if (!thread) throw new Error("[@theokit/agents] deriveConversationId: thread must be non-empty");
|
|
782
606
|
return `${encodeURIComponent(resource)}${SEPARATOR}${encodeURIComponent(thread)}`;
|
|
783
607
|
}
|
|
784
|
-
__name(deriveConversationId, "deriveConversationId");
|
|
785
608
|
function parseConversationId(id) {
|
|
786
609
|
const idx = id.indexOf(SEPARATOR);
|
|
787
610
|
if (idx <= 0 || idx >= id.length - 1) return null;
|
|
788
611
|
const resource = decodeURIComponent(id.slice(0, idx));
|
|
789
612
|
const thread = decodeURIComponent(id.slice(idx + 1));
|
|
790
613
|
if (!resource || !thread) return null;
|
|
791
|
-
return {
|
|
792
|
-
resource,
|
|
793
|
-
thread
|
|
794
|
-
};
|
|
614
|
+
return { resource, thread };
|
|
795
615
|
}
|
|
796
|
-
__name(parseConversationId, "parseConversationId");
|
|
797
616
|
|
|
798
617
|
// src/skills-resolver.ts
|
|
799
618
|
async function resolveEnabledSkills(selection, ctx) {
|
|
@@ -809,22 +628,15 @@ async function resolveEnabledSkills(selection, ctx) {
|
|
|
809
628
|
if (!names.every((n) => typeof n === "string" && n.trim().length > 0)) {
|
|
810
629
|
throw new Error("[@theokit/agents] skills resolver must return non-empty skill NAME strings");
|
|
811
630
|
}
|
|
812
|
-
return [
|
|
813
|
-
...names
|
|
814
|
-
];
|
|
631
|
+
return [...names];
|
|
815
632
|
}
|
|
816
|
-
__name(resolveEnabledSkills, "resolveEnabledSkills");
|
|
817
633
|
|
|
818
634
|
// src/acp/protocol.ts
|
|
819
635
|
function encodeAcpMessage(message) {
|
|
820
636
|
return `${JSON.stringify(message)}
|
|
821
637
|
`;
|
|
822
638
|
}
|
|
823
|
-
__name(encodeAcpMessage, "encodeAcpMessage");
|
|
824
639
|
var AcpMessageDecoder = class {
|
|
825
|
-
static {
|
|
826
|
-
__name(this, "AcpMessageDecoder");
|
|
827
|
-
}
|
|
828
640
|
buffer = "";
|
|
829
641
|
/** Feed a chunk; returns the messages completed by this chunk (possibly empty). */
|
|
830
642
|
push(chunk) {
|
|
@@ -838,9 +650,7 @@ var AcpMessageDecoder = class {
|
|
|
838
650
|
try {
|
|
839
651
|
messages.push(JSON.parse(line));
|
|
840
652
|
} catch (cause) {
|
|
841
|
-
throw new Error(`[@theokit/agents] ACP decode failed on line: ${line}`, {
|
|
842
|
-
cause
|
|
843
|
-
});
|
|
653
|
+
throw new Error(`[@theokit/agents] ACP decode failed on line: ${line}`, { cause });
|
|
844
654
|
}
|
|
845
655
|
}
|
|
846
656
|
newlineIndex = this.buffer.indexOf("\n");
|
|
@@ -853,20 +663,10 @@ var AcpMessageDecoder = class {
|
|
|
853
663
|
function isResponse(m) {
|
|
854
664
|
return typeof m.id === "number" && ("result" in m || "error" in m) && !("method" in m);
|
|
855
665
|
}
|
|
856
|
-
__name(isResponse, "isResponse");
|
|
857
666
|
function isServerRequest(m) {
|
|
858
667
|
return typeof m.method === "string" && typeof m.id === "number";
|
|
859
668
|
}
|
|
860
|
-
__name(isServerRequest, "isServerRequest");
|
|
861
669
|
var AcpClient = class {
|
|
862
|
-
static {
|
|
863
|
-
__name(this, "AcpClient");
|
|
864
|
-
}
|
|
865
|
-
transport;
|
|
866
|
-
nextId = 1;
|
|
867
|
-
pending = /* @__PURE__ */ new Map();
|
|
868
|
-
handlers = /* @__PURE__ */ new Map();
|
|
869
|
-
decoder = new AcpMessageDecoder();
|
|
870
670
|
constructor(transport) {
|
|
871
671
|
this.transport = transport;
|
|
872
672
|
transport.subscribe((chunk) => {
|
|
@@ -875,20 +675,17 @@ var AcpClient = class {
|
|
|
875
675
|
}
|
|
876
676
|
});
|
|
877
677
|
}
|
|
678
|
+
transport;
|
|
679
|
+
nextId = 1;
|
|
680
|
+
pending = /* @__PURE__ */ new Map();
|
|
681
|
+
handlers = /* @__PURE__ */ new Map();
|
|
682
|
+
decoder = new AcpMessageDecoder();
|
|
878
683
|
/** Send a JSON-RPC request and resolve with its `result` (or reject on `error`). */
|
|
879
684
|
request(method, params) {
|
|
880
685
|
const id = this.nextId++;
|
|
881
686
|
return new Promise((resolve, reject) => {
|
|
882
|
-
this.pending.set(id, {
|
|
883
|
-
|
|
884
|
-
reject
|
|
885
|
-
});
|
|
886
|
-
this.transport.send(encodeAcpMessage({
|
|
887
|
-
jsonrpc: "2.0",
|
|
888
|
-
id,
|
|
889
|
-
method,
|
|
890
|
-
params
|
|
891
|
-
}));
|
|
687
|
+
this.pending.set(id, { resolve, reject });
|
|
688
|
+
this.transport.send(encodeAcpMessage({ jsonrpc: "2.0", id, method, params }));
|
|
892
689
|
});
|
|
893
690
|
}
|
|
894
691
|
/** Register a handler for a server→client request method (e.g. `session/request_permission`). */
|
|
@@ -911,32 +708,22 @@ var AcpClient = class {
|
|
|
911
708
|
async handleServerRequest(req) {
|
|
912
709
|
const handler = this.handlers.get(req.method);
|
|
913
710
|
if (!handler) {
|
|
914
|
-
this.transport.send(
|
|
915
|
-
jsonrpc: "2.0",
|
|
916
|
-
|
|
917
|
-
error: {
|
|
918
|
-
code: -32601,
|
|
919
|
-
message: `No handler: ${req.method}`
|
|
920
|
-
}
|
|
921
|
-
}));
|
|
711
|
+
this.transport.send(
|
|
712
|
+
encodeAcpMessage({ jsonrpc: "2.0", id: req.id, error: { code: -32601, message: `No handler: ${req.method}` } })
|
|
713
|
+
);
|
|
922
714
|
return;
|
|
923
715
|
}
|
|
924
716
|
try {
|
|
925
717
|
const result = await handler(req.params);
|
|
926
|
-
this.transport.send(encodeAcpMessage({
|
|
927
|
-
jsonrpc: "2.0",
|
|
928
|
-
id: req.id,
|
|
929
|
-
result
|
|
930
|
-
}));
|
|
718
|
+
this.transport.send(encodeAcpMessage({ jsonrpc: "2.0", id: req.id, result }));
|
|
931
719
|
} catch (err) {
|
|
932
|
-
this.transport.send(
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
code: -32603,
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
}));
|
|
720
|
+
this.transport.send(
|
|
721
|
+
encodeAcpMessage({
|
|
722
|
+
jsonrpc: "2.0",
|
|
723
|
+
id: req.id,
|
|
724
|
+
error: { code: -32603, message: err instanceof Error ? err.message : "handler failed" }
|
|
725
|
+
})
|
|
726
|
+
);
|
|
940
727
|
}
|
|
941
728
|
}
|
|
942
729
|
};
|
|
@@ -946,7 +733,12 @@ import { Squad, Tool, Provider } from "@theokit/sdk";
|
|
|
946
733
|
import { setDiagnosticsSink } from "@theokit/sdk";
|
|
947
734
|
import { SubAgent } from "@theokit/sdk/a2a";
|
|
948
735
|
import { assertNoSymlinkEscape, isForbiddenPath, safePathJoin } from "@theokit/sdk/path-safety";
|
|
949
|
-
import {
|
|
736
|
+
import {
|
|
737
|
+
CONTEXT_WINDOW_FLOOR,
|
|
738
|
+
CONTEXT_WINDOW_MARGIN,
|
|
739
|
+
ContextWindowMarginError,
|
|
740
|
+
resolveEffectiveContextWindow
|
|
741
|
+
} from "@theokit/sdk/compaction";
|
|
950
742
|
export * from "@theokit/sdk/errors";
|
|
951
743
|
export * from "@theokit/sdk/retry";
|
|
952
744
|
export * from "@theokit/sdk/concurrency";
|
|
@@ -957,76 +749,51 @@ import { BudgetExceededError as BudgetExceededError2 } from "@theokit/sdk/errors
|
|
|
957
749
|
|
|
958
750
|
// src/in-process-turn.ts
|
|
959
751
|
var InProcessApprovalRequiredError = class extends Error {
|
|
960
|
-
static {
|
|
961
|
-
__name(this, "InProcessApprovalRequiredError");
|
|
962
|
-
}
|
|
963
752
|
constructor(toolNames) {
|
|
964
|
-
super(
|
|
753
|
+
super(
|
|
754
|
+
`Agent has HITL-gated tool(s) [${toolNames.join(", ")}] but no \`awaitApproval\` resolver was supplied to streamAgentTurnInProcess. In-process runs must resolve approvals inline \u2014 pass awaitApproval, or remove the gate. Refused (fail-closed).`
|
|
755
|
+
);
|
|
965
756
|
this.name = "InProcessApprovalRequiredError";
|
|
966
757
|
}
|
|
967
758
|
};
|
|
968
|
-
function
|
|
969
|
-
if (
|
|
970
|
-
switch (
|
|
759
|
+
function postureResolver(posturePolicy) {
|
|
760
|
+
if (posturePolicy === void 0) return void 0;
|
|
761
|
+
switch (posturePolicy.kind) {
|
|
971
762
|
case "interactive":
|
|
972
|
-
return
|
|
763
|
+
return posturePolicy.awaitApproval;
|
|
973
764
|
case "auto-approve":
|
|
974
|
-
return () => Promise.resolve({
|
|
975
|
-
approved: true,
|
|
976
|
-
reason: postura.reason
|
|
977
|
-
});
|
|
765
|
+
return () => Promise.resolve({ approved: true, reason: posturePolicy.reason });
|
|
978
766
|
case "auto-reject":
|
|
979
|
-
return () => Promise.resolve({
|
|
980
|
-
approved: false,
|
|
981
|
-
reason: postura.reason
|
|
982
|
-
});
|
|
767
|
+
return () => Promise.resolve({ approved: false, reason: posturePolicy.reason });
|
|
983
768
|
case "owned-by-surface":
|
|
984
769
|
return void 0;
|
|
985
770
|
}
|
|
986
771
|
}
|
|
987
|
-
|
|
988
|
-
function streamAgentTurnInProcess(mod, apiKey, input, deps = {
|
|
989
|
-
stream: streamAgentUIMessages
|
|
990
|
-
}) {
|
|
772
|
+
function streamAgentTurnInProcess(mod, apiKey, input, deps = { stream: streamAgentUIMessages }) {
|
|
991
773
|
const compiled = compileAgentModule(mod, input.source);
|
|
992
774
|
const gated = compiled.hitl;
|
|
993
775
|
if (gated && gated.size > 0 && !input.awaitApproval && input.approvals === void 0) {
|
|
994
|
-
throw new InProcessApprovalRequiredError([
|
|
995
|
-
...gated.keys()
|
|
996
|
-
]);
|
|
776
|
+
throw new InProcessApprovalRequiredError([...gated.keys()]);
|
|
997
777
|
}
|
|
998
778
|
const resolve = input.awaitApproval;
|
|
999
|
-
const
|
|
1000
|
-
|
|
1001
|
-
toolName,
|
|
1002
|
-
opts
|
|
1003
|
-
}) : resolvedorDaPostura(input.approvals);
|
|
1004
|
-
const hitl = gated && gated.size > 0 && resolverDeAprovacao ? {
|
|
1005
|
-
gated,
|
|
1006
|
-
awaitApproval: resolverDeAprovacao
|
|
1007
|
-
} : void 0;
|
|
779
|
+
const approvalResolver = resolve ? (approvalId, opts, toolName) => resolve({ approvalId, toolName, opts }) : postureResolver(input.approvals);
|
|
780
|
+
const hitl = gated && gated.size > 0 && approvalResolver ? { gated, awaitApproval: approvalResolver } : void 0;
|
|
1008
781
|
const sessionId = input.sessionId ?? crypto.randomUUID();
|
|
1009
782
|
return (async function* () {
|
|
1010
783
|
if (compiled.skillsResolver) {
|
|
1011
784
|
const enabled = await resolveEnabledSkills(compiled.skillsResolver, compiled.runContext ?? {});
|
|
1012
|
-
if (enabled !== void 0) compiled.skills = {
|
|
1013
|
-
enabled,
|
|
1014
|
-
autoInject: true
|
|
1015
|
-
};
|
|
785
|
+
if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
|
|
1016
786
|
}
|
|
1017
787
|
yield* deps.stream(compiled, apiKey, {
|
|
1018
788
|
message: input.message,
|
|
1019
789
|
// M35 — pass images through so the SDK send uses the structured `{ text, images }` form.
|
|
1020
|
-
...input.images !== void 0 ? {
|
|
1021
|
-
images: input.images
|
|
1022
|
-
} : {},
|
|
790
|
+
...input.images !== void 0 ? { images: input.images } : {},
|
|
1023
791
|
sessionId,
|
|
1024
792
|
hitl,
|
|
1025
793
|
signal: input.signal
|
|
1026
794
|
});
|
|
1027
795
|
})();
|
|
1028
796
|
}
|
|
1029
|
-
__name(streamAgentTurnInProcess, "streamAgentTurnInProcess");
|
|
1030
797
|
|
|
1031
798
|
// src/index.ts
|
|
1032
799
|
var Agent = AgentDoSdk;
|