@theokit/agents 7.3.1 → 7.4.0

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/index.js CHANGED
@@ -76,10 +76,7 @@ import {
76
76
  toolRuntimeName,
77
77
  translateSdkEvent,
78
78
  unicodeNormalizer
79
- } from "./chunk-7ECCHM4N.js";
80
- import {
81
- __name
82
- } from "./chunk-Z4QWC7IK.js";
79
+ } from "./chunk-NSJDG6XE.js";
83
80
 
84
81
  // src/index.ts
85
82
  import { Agent as AgentDoSdk } from "@theokit/sdk";
@@ -87,9 +84,6 @@ 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(
@@ -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,28 +117,15 @@ 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;
@@ -160,6 +134,9 @@ var ModelCapability = class {
160
134
  }
161
135
  if (id.trim().length === 0) throw new ConfigurationError("model: id n\xE3o pode ser vazio");
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,18 +152,10 @@ 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) {
@@ -204,16 +170,16 @@ var SkillsCapability = class {
204
170
  continue;
205
171
  }
206
172
  if (typeof e !== "object" || e === null || Array.isArray(e)) {
207
- throw new ConfigurationError(`skills: entrada inv\xE1lida (${describe(e)}) \u2014 use um nome ou um skill inline`);
173
+ throw new ConfigurationError(
174
+ `skills: entrada inv\xE1lida (${describe(e)}) \u2014 use um nome ou um skill inline`
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(`skills: skill inline sem \`${field}\` v\xE1lido (${describe(value)}) \u2014 name, description e instructions s\xE3o obrigat\xF3rios`);
180
+ throw new ConfigurationError(
181
+ `skills: skill inline sem \`${field}\` v\xE1lido (${describe(value)}) \u2014 name, description e instructions s\xE3o obrigat\xF3rios`
182
+ );
217
183
  }
218
184
  }
219
185
  }
@@ -232,40 +198,23 @@ 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
- ...previous.enabled ?? [],
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}" n\xE3o registrada. Conhecidas: ${known.join(", ") || "(nenhuma)"}.`);
212
+ super(
213
+ `capability "${requested}" n\xE3o registrada. Conhecidas: ${known.join(", ") || "(nenhuma)"}.`
214
+ );
263
215
  }
264
216
  };
265
217
  var CapabilityRegistry = class {
266
- static {
267
- __name(this, "CapabilityRegistry");
268
- }
269
218
  #factories = /* @__PURE__ */ new Map();
270
219
  register(name, factory) {
271
220
  this.#factories.set(name, factory);
@@ -275,9 +224,7 @@ var CapabilityRegistry = class {
275
224
  return this.#factories.has(name);
276
225
  }
277
226
  names() {
278
- return [
279
- ...this.#factories.keys()
280
- ];
227
+ return [...this.#factories.keys()];
281
228
  }
282
229
  resolve(name, arg) {
283
230
  const factory = this.#factories.get(name);
@@ -286,15 +233,12 @@ var CapabilityRegistry = class {
286
233
  }
287
234
  };
288
235
  var CapabilityPreset = class {
289
- static {
290
- __name(this, "CapabilityPreset");
291
- }
292
- name;
293
- #members;
294
236
  constructor(name, members) {
295
237
  this.name = name;
296
238
  this.#members = members;
297
239
  }
240
+ name;
241
+ #members;
298
242
  apply(draft) {
299
243
  for (const member of this.#members) member.apply(draft);
300
244
  }
@@ -302,169 +246,120 @@ var CapabilityPreset = class {
302
246
 
303
247
  // src/capability/agent-capabilities.ts
304
248
  var FieldCapability = class {
305
- static {
306
- __name(this, "FieldCapability");
307
- }
308
- value;
309
249
  constructor(value) {
310
250
  this.value = value;
311
251
  }
252
+ value;
312
253
  apply(draft) {
313
254
  setOnce(draft, this.field, this.value, this.name);
314
255
  }
315
256
  };
316
257
  var MemoryCapability = class extends FieldCapability {
317
- static {
318
- __name(this, "MemoryCapability");
319
- }
320
258
  name = "memory";
321
259
  field = "memory";
322
260
  };
323
261
  var ContextWindowCapability = class {
324
- static {
325
- __name(this, "ContextWindowCapability");
326
- }
327
- options;
328
- name = "context-window";
329
262
  constructor(options) {
330
263
  this.options = options;
331
264
  }
265
+ options;
266
+ name = "context-window";
332
267
  apply(draft) {
333
268
  setOnce(draft, "context", compileContextWindow(this.options).context, this.name);
334
269
  }
335
270
  };
336
271
  var ProjectContextCapability = class extends FieldCapability {
337
- static {
338
- __name(this, "ProjectContextCapability");
339
- }
340
272
  name = "project-context";
341
273
  field = "projectContext";
342
274
  };
343
275
  var McpServersCapability = class extends FieldCapability {
344
- static {
345
- __name(this, "McpServersCapability");
346
- }
347
276
  name = "mcp";
348
277
  field = "mcpServers";
349
278
  };
350
279
  var GuardrailsCapability = class extends FieldCapability {
351
- static {
352
- __name(this, "GuardrailsCapability");
353
- }
354
280
  name = "guardrails";
355
281
  field = "guardrails";
356
282
  };
357
283
  var CheckpointCapability = class {
358
- static {
359
- __name(this, "CheckpointCapability");
360
- }
361
- options;
362
- name = "checkpoint";
363
284
  constructor(options) {
364
285
  this.options = options;
365
286
  }
287
+ options;
288
+ name = "checkpoint";
366
289
  apply(draft) {
367
290
  if (this.options !== void 0 && this.options.storage !== "filesystem") {
368
- console.warn(`[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
+ console.warn(
292
+ `[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.`
293
+ );
369
294
  }
370
295
  setOnce(draft, "checkpoint", this.options, this.name);
371
296
  }
372
297
  };
373
298
  var HumanInTheLoopCapability = class extends FieldCapability {
374
- static {
375
- __name(this, "HumanInTheLoopCapability");
376
- }
377
299
  name = "human-in-the-loop";
378
300
  field = "hitl";
379
301
  };
380
302
  var SubAgentsCapability = class {
381
- static {
382
- __name(this, "SubAgentsCapability");
383
- }
384
- children;
385
- name = "sub-agents";
386
303
  constructor(children) {
387
304
  this.children = children;
388
305
  }
306
+ children;
307
+ name = "sub-agents";
389
308
  apply(draft) {
390
309
  for (const [name, child] of Object.entries(this.children)) {
391
310
  if (name in draft.agents && draft.agents[name] !== child) {
392
- throw new ConfigurationError(`sub-agents: filho "${name}" declarado duas vezes com defini\xE7\xF5es diferentes`);
311
+ throw new ConfigurationError(
312
+ `sub-agents: filho "${name}" declarado duas vezes com defini\xE7\xF5es diferentes`
313
+ );
393
314
  }
394
315
  draft.agents[name] = child;
395
316
  }
396
- draft.provenance.push({
397
- capability: this.name,
398
- contributed: [
399
- "agents"
400
- ]
401
- });
317
+ draft.provenance.push({ capability: this.name, contributed: ["agents"] });
402
318
  }
403
319
  };
404
320
  var SkillsOptionsCapability = class {
405
- static {
406
- __name(this, "SkillsOptionsCapability");
407
- }
408
- options;
409
- name = "skills";
410
321
  constructor(options) {
411
322
  this.options = options;
412
323
  }
324
+ options;
325
+ name = "skills";
413
326
  apply(draft) {
414
327
  setOnce(draft, "skills", compileSkills(this.options), this.name);
415
328
  }
416
329
  };
417
330
  var SettingSourcesCapability = class extends FieldCapability {
418
- static {
419
- __name(this, "SettingSourcesCapability");
420
- }
421
331
  name = "setting-sources";
422
332
  field = "settingSources";
423
333
  };
424
334
  var PluginsCapability = class extends FieldCapability {
425
- static {
426
- __name(this, "PluginsCapability");
427
- }
428
335
  name = "plugins";
429
336
  field = "plugins";
430
337
  };
431
338
  var RunContextCapability = class extends FieldCapability {
432
- static {
433
- __name(this, "RunContextCapability");
434
- }
435
339
  name = "run-context";
436
340
  field = "runContext";
437
341
  };
438
342
  var SkillsResolverCapability = class extends FieldCapability {
439
- static {
440
- __name(this, "SkillsResolverCapability");
441
- }
442
343
  name = "skills-resolver";
443
344
  field = "skillsResolver";
444
345
  };
445
346
  var AgentConfigCapability = class {
446
- static {
447
- __name(this, "AgentConfigCapability");
448
- }
449
- config;
450
- name = "agent-config";
451
347
  constructor(config) {
452
348
  this.config = config;
453
349
  if (typeof config !== "object" || config === null) {
454
350
  throw new ConfigurationError("agent-config: esperava um objeto de configura\xE7\xE3o");
455
351
  }
456
- for (const field of [
457
- "maxIterations",
458
- "timeoutMs"
459
- ]) {
352
+ for (const field of ["maxIterations", "timeoutMs"]) {
460
353
  const value = config[field];
461
354
  if (value !== void 0 && (!Number.isFinite(value) || value <= 0)) {
462
355
  throw new ConfigurationError(`agent-config: \`${field}\` deve ser um n\xFAmero positivo`);
463
356
  }
464
357
  }
465
358
  }
359
+ config;
360
+ name = "agent-config";
466
361
  apply(draft) {
467
- const claimedByMainLoop = /* @__PURE__ */ __name((field) => draft.provenance.some((p) => p.capability === "main-loop" && p.contributed.includes(field)), "claimedByMainLoop");
362
+ const claimedByMainLoop = (field) => draft.provenance.some((p) => p.capability === "main-loop" && p.contributed.includes(field));
468
363
  if (!claimedByMainLoop("maxIterations")) {
469
364
  setOnce(draft, "maxIterations", this.config.maxIterations, this.name);
470
365
  }
@@ -479,14 +374,11 @@ var AgentConfigCapability = class {
479
374
  }
480
375
  };
481
376
  var MainLoopCapability = class {
482
- static {
483
- __name(this, "MainLoopCapability");
484
- }
485
- config;
486
- name = "main-loop";
487
377
  constructor(config) {
488
378
  this.config = config;
489
379
  }
380
+ config;
381
+ name = "main-loop";
490
382
  apply(draft) {
491
383
  const contributed = [];
492
384
  if (this.config.maxIterations !== void 0) {
@@ -497,18 +389,12 @@ var MainLoopCapability = class {
497
389
  draft.timeoutMs = this.config.timeoutMs;
498
390
  contributed.push("timeoutMs");
499
391
  }
500
- if (contributed.length > 0) draft.provenance.push({
501
- capability: this.name,
502
- contributed
503
- });
392
+ if (contributed.length > 0) draft.provenance.push({ capability: this.name, contributed });
504
393
  }
505
394
  };
506
395
 
507
396
  // src/capability/toolbox.ts
508
397
  var ToolboxCapability = class {
509
- static {
510
- __name(this, "ToolboxCapability");
511
- }
512
398
  name = "toolbox";
513
399
  #instance;
514
400
  #declarations;
@@ -519,11 +405,15 @@ var ToolboxCapability = class {
519
405
  }
520
406
  const declared = options.tools ?? instance.constructor.tools;
521
407
  if (declared === void 0 || declared.length === 0) {
522
- throw new ConfigurationError(`toolbox: ${instance.constructor.name} n\xE3o declara tools \u2014 use \`static tools = [...]\` ou a op\xE7\xE3o \`tools\``);
408
+ throw new ConfigurationError(
409
+ `toolbox: ${instance.constructor.name} n\xE3o declara tools \u2014 use \`static tools = [...]\` ou a op\xE7\xE3o \`tools\``
410
+ );
523
411
  }
524
412
  for (const tool of declared) {
525
413
  if (typeof instance[tool.method] !== "function") {
526
- throw new ConfigurationError(`toolbox: ${instance.constructor.name}.${tool.method} n\xE3o \xE9 um m\xE9todo (tool "${tool.name}")`);
414
+ throw new ConfigurationError(
415
+ `toolbox: ${instance.constructor.name}.${tool.method} n\xE3o \xE9 um m\xE9todo (tool "${tool.name}")`
416
+ );
527
417
  }
528
418
  }
529
419
  this.#instance = instance;
@@ -532,15 +422,15 @@ var ToolboxCapability = class {
532
422
  for (const tool of declared) toolRuntimeName(this.#namespace, tool.name);
533
423
  }
534
424
  /**
535
- * The single derivation of this toolbox (M55). Both compilers below consume THIS object, so the
536
- * tool registry and the HITL gate map cannot disagree on a name — the property is structural, not
537
- * a convention repeated in two loops. That repetition is precisely how the two drifted apart in
538
- * #145: the tool became `ns_tool` while its gate stayed `ns.tool`, silently ungating it.
539
- *
540
- * Same technique the `opencode` harness uses for the analogous tool↔permission coupling, where
541
- * `Permission.visibleTools` filters the tool record itself rather than keeping a parallel map
542
- * ("so the two cannot drift" — `permission/index.ts`).
543
- */
425
+ * The single derivation of this toolbox (M55). Both compilers below consume THIS object, so the
426
+ * tool registry and the HITL gate map cannot disagree on a name — the property is structural, not
427
+ * a convention repeated in two loops. That repetition is precisely how the two drifted apart in
428
+ * #145: the tool became `ns_tool` while its gate stayed `ns.tool`, silently ungating it.
429
+ *
430
+ * Same technique the `opencode` harness uses for the analogous tool↔permission coupling, where
431
+ * `Permission.visibleTools` filters the tool record itself rather than keeping a parallel map
432
+ * ("so the two cannot drift" — `permission/index.ts`).
433
+ */
544
434
  #walk() {
545
435
  return {
546
436
  // `constructor` is typed `Function` by lib.d.ts; here it is used purely as an IDENTITY key
@@ -555,73 +445,47 @@ var ToolboxCapability = class {
555
445
  approval: tool.approval,
556
446
  trace: tool.trace ?? false,
557
447
  audit: tool.audit ?? false,
558
- ...tool.hitl !== void 0 ? {
559
- hitl: tool.hitl
560
- } : {}
448
+ ...tool.hitl !== void 0 ? { hitl: tool.hitl } : {}
561
449
  }))
562
450
  };
563
451
  }
564
452
  /**
565
- * M56 — the public `compile()` is GONE. It had zero callers anywhere in the monorepo and was kept
566
- * only because deleting a public method is breaking; that concession is exactly the dead surface
567
- * M55 set out to remove, preserved inside the milestone that removed it. `apply()` is the one path.
568
- */
453
+ * M56 — the public `compile()` is GONE. It had zero callers anywhere in the monorepo and was kept
454
+ * only because deleting a public method is breaking; that concession is exactly the dead surface
455
+ * M55 set out to remove, preserved inside the milestone that removed it. `apply()` is the one path.
456
+ */
569
457
  apply(draft) {
570
458
  const walk = this.#walk();
571
- draft.tools.push(...compileTools([
572
- walk
573
- ], /* @__PURE__ */ new Map([
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
- ]);
459
+ draft.tools.push(...compileTools([walk], /* @__PURE__ */ new Map([[walk.class, this.#instance]])));
460
+ draft.provenance.push({ capability: this.name, contributed: ["tools"] });
461
+ const gates = compileHitlGates([walk]);
588
462
  if (gates.size === 0) return;
589
463
  draft.hitl ??= /* @__PURE__ */ new Map();
590
464
  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
- });
465
+ draft.provenance.push({ capability: this.name, contributed: ["hitl"] });
597
466
  }
598
467
  };
599
468
 
600
469
  // src/capability/toolset.ts
601
470
  var ToolsetError = class extends Error {
602
- static {
603
- __name(this, "ToolsetError");
604
- }
605
- code;
606
471
  constructor(message, code) {
607
- super(message), this.code = code;
472
+ super(message);
473
+ this.code = code;
608
474
  this.name = "ToolsetError";
609
475
  }
476
+ code;
610
477
  };
611
478
  var Toolset = class _Toolset {
612
- static {
613
- __name(this, "Toolset");
614
- }
615
479
  #porNome;
616
480
  constructor(porNome) {
617
481
  this.#porNome = porNome;
618
482
  Object.freeze(this);
619
483
  }
620
484
  /**
621
- * Constrói a partir das tools já instanciadas. Falha alto em nome duplicado **na construção** — não
622
- * na resolução: um descritor com duas tools de mesmo nome está errado no momento em que é escrito, e
623
- * adiar o erro para o primeiro `resolve` esconde metade dos casos.
624
- */
485
+ * Constrói a partir das tools já instanciadas. Falha alto em nome duplicado **na construção** — não
486
+ * na resolução: um descritor com duas tools de mesmo nome está errado no momento em que é escrito, e
487
+ * adiar o erro para o primeiro `resolve` esconde metade dos casos.
488
+ */
625
489
  static from(tools) {
626
490
  const porNome = /* @__PURE__ */ new Map();
627
491
  for (const tool of tools) {
@@ -641,10 +505,10 @@ var Toolset = class _Toolset {
641
505
  return tool;
642
506
  }
643
507
  /**
644
- * Resolve uma whitelist. Falha alto em desconhecido **e** em duplicado dentro da própria lista:
645
- * um time nunca concede em silêncio uma tool que o role não declarou, nem descarta em silêncio uma
646
- * que declarou.
647
- */
508
+ * Resolve uma whitelist. Falha alto em desconhecido **e** em duplicado dentro da própria lista:
509
+ * um time nunca concede em silêncio uma tool que o role não declarou, nem descarta em silêncio uma
510
+ * que declarou.
511
+ */
648
512
  resolve(names) {
649
513
  const vistos = /* @__PURE__ */ new Set();
650
514
  return names.map((name) => {
@@ -657,15 +521,11 @@ var Toolset = class _Toolset {
657
521
  }
658
522
  /** Os nomes conhecidos, na ordem de registro. */
659
523
  names() {
660
- return [
661
- ...this.#porNome.keys()
662
- ];
524
+ return [...this.#porNome.keys()];
663
525
  }
664
526
  /** Todas as tools, na ordem de registro. */
665
527
  all() {
666
- return [
667
- ...this.#porNome.values()
668
- ];
528
+ return [...this.#porNome.values()];
669
529
  }
670
530
  };
671
531
 
@@ -673,7 +533,6 @@ var Toolset = class _Toolset {
673
533
  function trimTrailingSlash(url) {
674
534
  return url.endsWith("/") ? url.slice(0, -1) : url;
675
535
  }
676
- __name(trimTrailingSlash, "trimTrailingSlash");
677
536
  function buildAgentCard(entry, options) {
678
537
  const base = trimTrailingSlash(options.baseUrl);
679
538
  return {
@@ -686,24 +545,14 @@ function buildAgentCard(entry, options) {
686
545
  pushNotifications: false,
687
546
  stateTransitionHistory: false
688
547
  },
689
- defaultInputModes: [
690
- "text"
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
- }))
548
+ defaultInputModes: ["text"],
549
+ defaultOutputModes: ["text"],
550
+ skills: entry.tools.map((t) => ({ id: t.name, name: t.name, description: t.description }))
700
551
  };
701
552
  }
702
- __name(buildAgentCard, "buildAgentCard");
703
553
  function wellKnownCardPath(agentName) {
704
554
  return `/.well-known/${agentName}/agent-card.json`;
705
555
  }
706
- __name(wellKnownCardPath, "wellKnownCardPath");
707
556
 
708
557
  // src/a2a/mcp-server-manifest.ts
709
558
  var MCP_PROTOCOL_VERSION = "2024-11-05";
@@ -711,33 +560,20 @@ function buildMcpToolDescriptors(entry) {
711
560
  return entry.tools.map((t) => ({
712
561
  name: t.name,
713
562
  description: t.description,
714
- inputSchema: {
715
- type: "object",
716
- properties: {}
717
- }
563
+ inputSchema: { type: "object", properties: {} }
718
564
  }));
719
565
  }
720
- __name(buildMcpToolDescriptors, "buildMcpToolDescriptors");
721
566
  function mcpServerInfo(entry) {
722
- return {
723
- name: entry.name,
724
- version: "1.0",
725
- protocolVersion: MCP_PROTOCOL_VERSION
726
- };
567
+ return { name: entry.name, version: "1.0", protocolVersion: MCP_PROTOCOL_VERSION };
727
568
  }
728
- __name(mcpServerInfo, "mcpServerInfo");
729
569
 
730
570
  // src/a2a/a2a-client.ts
731
571
  function buildHeaders(config) {
732
- const headers = {
733
- "content-type": "application/json",
734
- ...config.headers
735
- };
572
+ const headers = { "content-type": "application/json", ...config.headers };
736
573
  if (config.auth?.bearer) headers.authorization = `Bearer ${config.auth.bearer}`;
737
574
  if (config.auth?.apiKey) headers[config.auth.apiKey.header] = config.auth.apiKey.value;
738
575
  return headers;
739
576
  }
740
- __name(buildHeaders, "buildHeaders");
741
577
  function createA2ATool(config) {
742
578
  const doFetch = config.fetchImpl ?? fetch;
743
579
  return {
@@ -745,34 +581,24 @@ function createA2ATool(config) {
745
581
  description: config.description,
746
582
  inputSchema: {
747
583
  type: "object",
748
- properties: {
749
- message: {
750
- type: "string",
751
- description: "The message to send to the remote agent."
752
- }
753
- },
754
- required: [
755
- "message"
756
- ]
584
+ properties: { message: { type: "string", description: "The message to send to the remote agent." } },
585
+ required: ["message"]
757
586
  },
758
- handler: /* @__PURE__ */ __name(async (input) => {
587
+ handler: async (input) => {
759
588
  const message = typeof input.message === "string" ? input.message : "";
760
589
  const res = await doFetch(config.url, {
761
590
  method: "POST",
762
591
  headers: buildHeaders(config),
763
- body: JSON.stringify({
764
- message
765
- })
592
+ body: JSON.stringify({ message })
766
593
  });
767
594
  if (!res.ok) {
768
595
  throw new Error(`A2A call to "${config.name}" failed: ${res.status} ${res.statusText}`);
769
596
  }
770
597
  const data = await res.json();
771
598
  return data.response ?? data.text ?? "";
772
- }, "handler")
599
+ }
773
600
  };
774
601
  }
775
- __name(createA2ATool, "createA2ATool");
776
602
 
777
603
  // src/conversation-scope.ts
778
604
  var SEPARATOR = "/";
@@ -781,19 +607,14 @@ function deriveConversationId(resource, thread) {
781
607
  if (!thread) throw new Error("[@theokit/agents] deriveConversationId: thread must be non-empty");
782
608
  return `${encodeURIComponent(resource)}${SEPARATOR}${encodeURIComponent(thread)}`;
783
609
  }
784
- __name(deriveConversationId, "deriveConversationId");
785
610
  function parseConversationId(id) {
786
611
  const idx = id.indexOf(SEPARATOR);
787
612
  if (idx <= 0 || idx >= id.length - 1) return null;
788
613
  const resource = decodeURIComponent(id.slice(0, idx));
789
614
  const thread = decodeURIComponent(id.slice(idx + 1));
790
615
  if (!resource || !thread) return null;
791
- return {
792
- resource,
793
- thread
794
- };
616
+ return { resource, thread };
795
617
  }
796
- __name(parseConversationId, "parseConversationId");
797
618
 
798
619
  // src/skills-resolver.ts
799
620
  async function resolveEnabledSkills(selection, ctx) {
@@ -809,22 +630,15 @@ async function resolveEnabledSkills(selection, ctx) {
809
630
  if (!names.every((n) => typeof n === "string" && n.trim().length > 0)) {
810
631
  throw new Error("[@theokit/agents] skills resolver must return non-empty skill NAME strings");
811
632
  }
812
- return [
813
- ...names
814
- ];
633
+ return [...names];
815
634
  }
816
- __name(resolveEnabledSkills, "resolveEnabledSkills");
817
635
 
818
636
  // src/acp/protocol.ts
819
637
  function encodeAcpMessage(message) {
820
638
  return `${JSON.stringify(message)}
821
639
  `;
822
640
  }
823
- __name(encodeAcpMessage, "encodeAcpMessage");
824
641
  var AcpMessageDecoder = class {
825
- static {
826
- __name(this, "AcpMessageDecoder");
827
- }
828
642
  buffer = "";
829
643
  /** Feed a chunk; returns the messages completed by this chunk (possibly empty). */
830
644
  push(chunk) {
@@ -838,9 +652,7 @@ var AcpMessageDecoder = class {
838
652
  try {
839
653
  messages.push(JSON.parse(line));
840
654
  } catch (cause) {
841
- throw new Error(`[@theokit/agents] ACP decode failed on line: ${line}`, {
842
- cause
843
- });
655
+ throw new Error(`[@theokit/agents] ACP decode failed on line: ${line}`, { cause });
844
656
  }
845
657
  }
846
658
  newlineIndex = this.buffer.indexOf("\n");
@@ -853,20 +665,10 @@ var AcpMessageDecoder = class {
853
665
  function isResponse(m) {
854
666
  return typeof m.id === "number" && ("result" in m || "error" in m) && !("method" in m);
855
667
  }
856
- __name(isResponse, "isResponse");
857
668
  function isServerRequest(m) {
858
669
  return typeof m.method === "string" && typeof m.id === "number";
859
670
  }
860
- __name(isServerRequest, "isServerRequest");
861
671
  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
672
  constructor(transport) {
871
673
  this.transport = transport;
872
674
  transport.subscribe((chunk) => {
@@ -875,20 +677,17 @@ var AcpClient = class {
875
677
  }
876
678
  });
877
679
  }
680
+ transport;
681
+ nextId = 1;
682
+ pending = /* @__PURE__ */ new Map();
683
+ handlers = /* @__PURE__ */ new Map();
684
+ decoder = new AcpMessageDecoder();
878
685
  /** Send a JSON-RPC request and resolve with its `result` (or reject on `error`). */
879
686
  request(method, params) {
880
687
  const id = this.nextId++;
881
688
  return new Promise((resolve, reject) => {
882
- this.pending.set(id, {
883
- resolve,
884
- reject
885
- });
886
- this.transport.send(encodeAcpMessage({
887
- jsonrpc: "2.0",
888
- id,
889
- method,
890
- params
891
- }));
689
+ this.pending.set(id, { resolve, reject });
690
+ this.transport.send(encodeAcpMessage({ jsonrpc: "2.0", id, method, params }));
892
691
  });
893
692
  }
894
693
  /** Register a handler for a server→client request method (e.g. `session/request_permission`). */
@@ -911,32 +710,22 @@ var AcpClient = class {
911
710
  async handleServerRequest(req) {
912
711
  const handler = this.handlers.get(req.method);
913
712
  if (!handler) {
914
- this.transport.send(encodeAcpMessage({
915
- jsonrpc: "2.0",
916
- id: req.id,
917
- error: {
918
- code: -32601,
919
- message: `No handler: ${req.method}`
920
- }
921
- }));
713
+ this.transport.send(
714
+ encodeAcpMessage({ jsonrpc: "2.0", id: req.id, error: { code: -32601, message: `No handler: ${req.method}` } })
715
+ );
922
716
  return;
923
717
  }
924
718
  try {
925
719
  const result = await handler(req.params);
926
- this.transport.send(encodeAcpMessage({
927
- jsonrpc: "2.0",
928
- id: req.id,
929
- result
930
- }));
720
+ this.transport.send(encodeAcpMessage({ jsonrpc: "2.0", id: req.id, result }));
931
721
  } catch (err) {
932
- this.transport.send(encodeAcpMessage({
933
- jsonrpc: "2.0",
934
- id: req.id,
935
- error: {
936
- code: -32603,
937
- message: err instanceof Error ? err.message : "handler failed"
938
- }
939
- }));
722
+ this.transport.send(
723
+ encodeAcpMessage({
724
+ jsonrpc: "2.0",
725
+ id: req.id,
726
+ error: { code: -32603, message: err instanceof Error ? err.message : "handler failed" }
727
+ })
728
+ );
940
729
  }
941
730
  }
942
731
  };
@@ -946,7 +735,12 @@ import { Squad, Tool, Provider } from "@theokit/sdk";
946
735
  import { setDiagnosticsSink } from "@theokit/sdk";
947
736
  import { SubAgent } from "@theokit/sdk/a2a";
948
737
  import { assertNoSymlinkEscape, isForbiddenPath, safePathJoin } from "@theokit/sdk/path-safety";
949
- import { CONTEXT_WINDOW_FLOOR, CONTEXT_WINDOW_MARGIN, ContextWindowMarginError, resolveEffectiveContextWindow } from "@theokit/sdk/compaction";
738
+ import {
739
+ CONTEXT_WINDOW_FLOOR,
740
+ CONTEXT_WINDOW_MARGIN,
741
+ ContextWindowMarginError,
742
+ resolveEffectiveContextWindow
743
+ } from "@theokit/sdk/compaction";
950
744
  export * from "@theokit/sdk/errors";
951
745
  export * from "@theokit/sdk/retry";
952
746
  export * from "@theokit/sdk/concurrency";
@@ -957,11 +751,10 @@ import { BudgetExceededError as BudgetExceededError2 } from "@theokit/sdk/errors
957
751
 
958
752
  // src/in-process-turn.ts
959
753
  var InProcessApprovalRequiredError = class extends Error {
960
- static {
961
- __name(this, "InProcessApprovalRequiredError");
962
- }
963
754
  constructor(toolNames) {
964
- super(`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
+ super(
756
+ `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).`
757
+ );
965
758
  this.name = "InProcessApprovalRequiredError";
966
759
  }
967
760
  };
@@ -971,62 +764,38 @@ function resolvedorDaPostura(postura) {
971
764
  case "interactive":
972
765
  return postura.awaitApproval;
973
766
  case "auto-approve":
974
- return () => Promise.resolve({
975
- approved: true,
976
- reason: postura.reason
977
- });
767
+ return () => Promise.resolve({ approved: true, reason: postura.reason });
978
768
  case "auto-reject":
979
- return () => Promise.resolve({
980
- approved: false,
981
- reason: postura.reason
982
- });
769
+ return () => Promise.resolve({ approved: false, reason: postura.reason });
983
770
  case "owned-by-surface":
984
771
  return void 0;
985
772
  }
986
773
  }
987
- __name(resolvedorDaPostura, "resolvedorDaPostura");
988
- function streamAgentTurnInProcess(mod, apiKey, input, deps = {
989
- stream: streamAgentUIMessages
990
- }) {
774
+ function streamAgentTurnInProcess(mod, apiKey, input, deps = { stream: streamAgentUIMessages }) {
991
775
  const compiled = compileAgentModule(mod, input.source);
992
776
  const gated = compiled.hitl;
993
777
  if (gated && gated.size > 0 && !input.awaitApproval && input.approvals === void 0) {
994
- throw new InProcessApprovalRequiredError([
995
- ...gated.keys()
996
- ]);
778
+ throw new InProcessApprovalRequiredError([...gated.keys()]);
997
779
  }
998
780
  const resolve = input.awaitApproval;
999
- const resolverDeAprovacao = resolve ? (approvalId, opts, toolName) => resolve({
1000
- approvalId,
1001
- toolName,
1002
- opts
1003
- }) : resolvedorDaPostura(input.approvals);
1004
- const hitl = gated && gated.size > 0 && resolverDeAprovacao ? {
1005
- gated,
1006
- awaitApproval: resolverDeAprovacao
1007
- } : void 0;
781
+ const resolverDeAprovacao = resolve ? (approvalId, opts, toolName) => resolve({ approvalId, toolName, opts }) : resolvedorDaPostura(input.approvals);
782
+ const hitl = gated && gated.size > 0 && resolverDeAprovacao ? { gated, awaitApproval: resolverDeAprovacao } : void 0;
1008
783
  const sessionId = input.sessionId ?? crypto.randomUUID();
1009
784
  return (async function* () {
1010
785
  if (compiled.skillsResolver) {
1011
786
  const enabled = await resolveEnabledSkills(compiled.skillsResolver, compiled.runContext ?? {});
1012
- if (enabled !== void 0) compiled.skills = {
1013
- enabled,
1014
- autoInject: true
1015
- };
787
+ if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
1016
788
  }
1017
789
  yield* deps.stream(compiled, apiKey, {
1018
790
  message: input.message,
1019
791
  // M35 — pass images through so the SDK send uses the structured `{ text, images }` form.
1020
- ...input.images !== void 0 ? {
1021
- images: input.images
1022
- } : {},
792
+ ...input.images !== void 0 ? { images: input.images } : {},
1023
793
  sessionId,
1024
794
  hitl,
1025
795
  signal: input.signal
1026
796
  });
1027
797
  })();
1028
798
  }
1029
- __name(streamAgentTurnInProcess, "streamAgentTurnInProcess");
1030
799
 
1031
800
  // src/index.ts
1032
801
  var Agent = AgentDoSdk;