@theokit/agents 0.46.0 → 0.47.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/bridge.js CHANGED
@@ -47,7 +47,7 @@ import {
47
47
  translateSdkEvent,
48
48
  validateUniqueRoutes,
49
49
  walkAgentMetadata
50
- } from "./chunk-YBNKD5UM.js";
50
+ } from "./chunk-FEH7JFH7.js";
51
51
  import "./chunk-NERDIS45.js";
52
52
  import "./chunk-7QVYU63E.js";
53
53
  export {
@@ -27,6 +27,142 @@ import {
27
27
  __name
28
28
  } from "./chunk-7QVYU63E.js";
29
29
 
30
+ // src/bridge/define-agent.ts
31
+ var AGENT_BRAND = /* @__PURE__ */ Symbol.for("theokit.agent.definition");
32
+ function defineAgent(config) {
33
+ return {
34
+ ...config,
35
+ [AGENT_BRAND]: true
36
+ };
37
+ }
38
+ __name(defineAgent, "defineAgent");
39
+ function isAgentDefinition(value) {
40
+ return typeof value === "object" && value !== null && value[AGENT_BRAND] === true;
41
+ }
42
+ __name(isAgentDefinition, "isAgentDefinition");
43
+ function toCompiledTool(tool) {
44
+ const handler = tool.handler;
45
+ const compiled = {
46
+ name: tool.name,
47
+ description: tool.description,
48
+ inputSchema: tool.inputSchema,
49
+ handler: /* @__PURE__ */ __name((input, ctx) => handler(input, ctx), "handler")
50
+ };
51
+ for (const sym of Object.getOwnPropertySymbols(tool)) {
52
+ ;
53
+ compiled[sym] = tool[sym];
54
+ }
55
+ return compiled;
56
+ }
57
+ __name(toCompiledTool, "toCompiledTool");
58
+ function compileAgentDefinition(def) {
59
+ return {
60
+ model: def.model,
61
+ reasoningEffort: def.reasoningEffort,
62
+ systemPrompt: def.system,
63
+ tools: (def.tools ?? []).map(toCompiledTool),
64
+ agents: {},
65
+ stream: true,
66
+ // M7 — run-context flows to CompiledAgentOptions.runContext (distinct from the
67
+ // context-window `context` field the decorator path uses); absent ⇒ no key.
68
+ ...def.context !== void 0 ? {
69
+ runContext: def.context
70
+ } : {},
71
+ // M9 — guardrails flow through unchanged; the runner applies them at the input boundary.
72
+ ...def.guardrails !== void 0 ? {
73
+ guardrails: def.guardrails
74
+ } : {},
75
+ // M14 — HITL approvals compile into the same `hitl` map the decorator path produces.
76
+ ...def.approvals !== void 0 ? {
77
+ hitl: compileApprovals(def)
78
+ } : {},
79
+ // M13 — skills: a static list → SDK skills.enabled; a resolver → carried for the request path.
80
+ ...compileSkillsSelection(def.skills),
81
+ // theokit-file-based-config — the declared `.theokit/` sources flow to the run path, which
82
+ // projects them into `Agent.create({ local.settingSources })`; absent ⇒ inline config only.
83
+ ...def.settingSources !== void 0 ? {
84
+ settingSources: def.settingSources
85
+ } : {},
86
+ // M49 — memory flows to the projection layer; `assembleM8CreateOptions` forwards it to Agent.create.
87
+ ...def.memory !== void 0 ? {
88
+ memory: def.memory
89
+ } : {},
90
+ // Hooks are converted here — the layer EVERY path converges on — rather than on the builder, so
91
+ // `defineAgent({ hooks })` cannot type-check and silently no-op. A lifecycle hook that is
92
+ // declared but never registered is a security gate that does not gate.
93
+ ...compileHooksAndPlugins(def),
94
+ // MCP — builder/`defineAgent` servers converge on the same `mcpServers` field the `@MCP`
95
+ // decorator path populates; the SDK adapter forwards it to `Agent.create({ mcpServers })`.
96
+ ...def.mcpServers !== void 0 ? {
97
+ mcpServers: def.mcpServers
98
+ } : {}
99
+ };
100
+ }
101
+ __name(compileAgentDefinition, "compileAgentDefinition");
102
+ function compileHooksAndPlugins(def) {
103
+ const map = def.hooks;
104
+ const entries = Object.entries(map ?? {}).filter(([, h]) => typeof h === "function");
105
+ const explicit = def.plugins ?? [];
106
+ if (entries.length === 0) {
107
+ return def.plugins !== void 0 ? {
108
+ plugins: def.plugins
109
+ } : {};
110
+ }
111
+ const plugin = {
112
+ name: "theokit-builder-hooks",
113
+ version: "1.0.0",
114
+ kind: "general",
115
+ register(ctx) {
116
+ for (const [hookName, handler] of entries) {
117
+ ctx.on(hookName, handler);
118
+ }
119
+ }
120
+ };
121
+ return {
122
+ plugins: [
123
+ ...explicit,
124
+ plugin
125
+ ]
126
+ };
127
+ }
128
+ __name(compileHooksAndPlugins, "compileHooksAndPlugins");
129
+ function compileSkillsSelection(skills) {
130
+ if (skills === void 0) return {};
131
+ if (typeof skills === "function") return {
132
+ skillsResolver: skills
133
+ };
134
+ const enabled = [];
135
+ const inline = [];
136
+ for (const entry of skills) {
137
+ if (typeof entry === "string") enabled.push(entry);
138
+ else inline.push(entry);
139
+ }
140
+ return {
141
+ skills: {
142
+ enabled,
143
+ autoInject: true,
144
+ ...inline.length > 0 ? {
145
+ inline
146
+ } : {}
147
+ }
148
+ };
149
+ }
150
+ __name(compileSkillsSelection, "compileSkillsSelection");
151
+ function compileApprovals(def) {
152
+ const toolNames = new Set((def.tools ?? []).map((t) => t.name));
153
+ const gates = /* @__PURE__ */ new Map();
154
+ for (const [toolName, options] of Object.entries(def.approvals ?? {})) {
155
+ if (!toolNames.has(toolName)) {
156
+ throw new Error(`[@theokit/agents] defineAgent approval references unknown tool "${toolName}". Declared tools: ${[
157
+ ...toolNames
158
+ ].join(", ") || "(none)"}.`);
159
+ }
160
+ gates.set(toolName, options);
161
+ }
162
+ return gates;
163
+ }
164
+ __name(compileApprovals, "compileApprovals");
165
+
30
166
  // src/bridge/agent-execution-context.ts
31
167
  function createAgentExecutionContext(base, agent2, run, toolCall) {
32
168
  return {
@@ -506,142 +642,6 @@ function generateAgentRoutes(ctx) {
506
642
  }
507
643
  __name(generateAgentRoutes, "generateAgentRoutes");
508
644
 
509
- // src/bridge/define-agent.ts
510
- var AGENT_BRAND = /* @__PURE__ */ Symbol.for("theokit.agent.definition");
511
- function defineAgent(config) {
512
- return {
513
- ...config,
514
- [AGENT_BRAND]: true
515
- };
516
- }
517
- __name(defineAgent, "defineAgent");
518
- function isAgentDefinition(value) {
519
- return typeof value === "object" && value !== null && value[AGENT_BRAND] === true;
520
- }
521
- __name(isAgentDefinition, "isAgentDefinition");
522
- function toCompiledTool(tool) {
523
- const handler = tool.handler;
524
- const compiled = {
525
- name: tool.name,
526
- description: tool.description,
527
- inputSchema: tool.inputSchema,
528
- handler: /* @__PURE__ */ __name((input, ctx) => handler(input, ctx), "handler")
529
- };
530
- for (const sym of Object.getOwnPropertySymbols(tool)) {
531
- ;
532
- compiled[sym] = tool[sym];
533
- }
534
- return compiled;
535
- }
536
- __name(toCompiledTool, "toCompiledTool");
537
- function compileAgentDefinition(def) {
538
- return {
539
- model: def.model,
540
- reasoningEffort: def.reasoningEffort,
541
- systemPrompt: def.system,
542
- tools: (def.tools ?? []).map(toCompiledTool),
543
- agents: {},
544
- stream: true,
545
- // M7 — run-context flows to CompiledAgentOptions.runContext (distinct from the
546
- // context-window `context` field the decorator path uses); absent ⇒ no key.
547
- ...def.context !== void 0 ? {
548
- runContext: def.context
549
- } : {},
550
- // M9 — guardrails flow through unchanged; the runner applies them at the input boundary.
551
- ...def.guardrails !== void 0 ? {
552
- guardrails: def.guardrails
553
- } : {},
554
- // M14 — HITL approvals compile into the same `hitl` map the decorator path produces.
555
- ...def.approvals !== void 0 ? {
556
- hitl: compileApprovals(def)
557
- } : {},
558
- // M13 — skills: a static list → SDK skills.enabled; a resolver → carried for the request path.
559
- ...compileSkillsSelection(def.skills),
560
- // theokit-file-based-config — the declared `.theokit/` sources flow to the run path, which
561
- // projects them into `Agent.create({ local.settingSources })`; absent ⇒ inline config only.
562
- ...def.settingSources !== void 0 ? {
563
- settingSources: def.settingSources
564
- } : {},
565
- // M49 — memory flows to the projection layer; `assembleM8CreateOptions` forwards it to Agent.create.
566
- ...def.memory !== void 0 ? {
567
- memory: def.memory
568
- } : {},
569
- // Hooks are converted here — the layer EVERY path converges on — rather than on the builder, so
570
- // `defineAgent({ hooks })` cannot type-check and silently no-op. A lifecycle hook that is
571
- // declared but never registered is a security gate that does not gate.
572
- ...compileHooksAndPlugins(def),
573
- // MCP — builder/`defineAgent` servers converge on the same `mcpServers` field the `@MCP`
574
- // decorator path populates; the SDK adapter forwards it to `Agent.create({ mcpServers })`.
575
- ...def.mcpServers !== void 0 ? {
576
- mcpServers: def.mcpServers
577
- } : {}
578
- };
579
- }
580
- __name(compileAgentDefinition, "compileAgentDefinition");
581
- function compileHooksAndPlugins(def) {
582
- const map = def.hooks;
583
- const entries = Object.entries(map ?? {}).filter(([, h]) => typeof h === "function");
584
- const explicit = def.plugins ?? [];
585
- if (entries.length === 0) {
586
- return def.plugins !== void 0 ? {
587
- plugins: def.plugins
588
- } : {};
589
- }
590
- const plugin = {
591
- name: "theokit-builder-hooks",
592
- version: "1.0.0",
593
- kind: "general",
594
- register(ctx) {
595
- for (const [hookName, handler] of entries) {
596
- ctx.on(hookName, handler);
597
- }
598
- }
599
- };
600
- return {
601
- plugins: [
602
- ...explicit,
603
- plugin
604
- ]
605
- };
606
- }
607
- __name(compileHooksAndPlugins, "compileHooksAndPlugins");
608
- function compileSkillsSelection(skills) {
609
- if (skills === void 0) return {};
610
- if (typeof skills === "function") return {
611
- skillsResolver: skills
612
- };
613
- const enabled = [];
614
- const inline = [];
615
- for (const entry of skills) {
616
- if (typeof entry === "string") enabled.push(entry);
617
- else inline.push(entry);
618
- }
619
- return {
620
- skills: {
621
- enabled,
622
- autoInject: true,
623
- ...inline.length > 0 ? {
624
- inline
625
- } : {}
626
- }
627
- };
628
- }
629
- __name(compileSkillsSelection, "compileSkillsSelection");
630
- function compileApprovals(def) {
631
- const toolNames = new Set((def.tools ?? []).map((t) => t.name));
632
- const gates = /* @__PURE__ */ new Map();
633
- for (const [toolName, options] of Object.entries(def.approvals ?? {})) {
634
- if (!toolNames.has(toolName)) {
635
- throw new Error(`[@theokit/agents] defineAgent approval references unknown tool "${toolName}". Declared tools: ${[
636
- ...toolNames
637
- ].join(", ") || "(none)"}.`);
638
- }
639
- gates.set(toolName, options);
640
- }
641
- return gates;
642
- }
643
- __name(compileApprovals, "compileApprovals");
644
-
645
645
  // src/bridge/event-translator.ts
646
646
  function asString(value, fallback) {
647
647
  if (typeof value === "string") return value;
@@ -1904,6 +1904,125 @@ var UIMessageStreamPresenter = class {
1904
1904
  return out;
1905
1905
  }
1906
1906
  };
1907
+ var ANSI = {
1908
+ text: "",
1909
+ reasoning: "\x1B[2m",
1910
+ tool: "\x1B[36m",
1911
+ "tool-result": "\x1B[2m",
1912
+ "tool-error": "\x1B[31m",
1913
+ error: "\x1B[31m",
1914
+ status: "\x1B[35m",
1915
+ finish: "\x1B[2m"
1916
+ };
1917
+ var RESET = "\x1B[0m";
1918
+ function preview(value, max) {
1919
+ const raw = typeof value === "string" ? value : safeJson(value);
1920
+ const flat = raw.replace(/\s+/g, " ").trim();
1921
+ return flat.length > max ? `${flat.slice(0, max - 1)}\u2026` : flat;
1922
+ }
1923
+ __name(preview, "preview");
1924
+ __name2(preview, "preview");
1925
+ function safeJson(value) {
1926
+ if (value === void 0 || value === null) return "";
1927
+ try {
1928
+ return JSON.stringify(value);
1929
+ } catch {
1930
+ return typeof value === "bigint" ? value.toString() : "";
1931
+ }
1932
+ }
1933
+ __name(safeJson, "safeJson");
1934
+ __name2(safeJson, "safeJson");
1935
+ function suffix(open, value, close) {
1936
+ return value === void 0 ? "" : open + value + close;
1937
+ }
1938
+ __name(suffix, "suffix");
1939
+ __name2(suffix, "suffix");
1940
+ var TerminalPresenter = class {
1941
+ static {
1942
+ __name(this, "TerminalPresenter");
1943
+ }
1944
+ static {
1945
+ __name2(this, "TerminalPresenter");
1946
+ }
1947
+ surface = "terminal";
1948
+ #ansi;
1949
+ #max;
1950
+ constructor(options = {}) {
1951
+ this.#ansi = options.ansi ?? false;
1952
+ this.#max = options.maxPreview ?? 88;
1953
+ }
1954
+ present(event) {
1955
+ switch (event.type) {
1956
+ case "text":
1957
+ return event.text.length > 0 ? [
1958
+ this.#row("text", event.text)
1959
+ ] : [];
1960
+ case "reasoning":
1961
+ return event.text.length > 0 ? [
1962
+ this.#row("reasoning", `\xB7 ${event.text}`)
1963
+ ] : [];
1964
+ case "tool-call":
1965
+ return [
1966
+ this.#row("tool", `\u23FA ${event.name}(${preview(event.input, this.#max)})`)
1967
+ ];
1968
+ case "tool-result":
1969
+ return [
1970
+ this.#toolResult(event.isError === true, preview(event.result, this.#max))
1971
+ ];
1972
+ case "error":
1973
+ return [
1974
+ this.#row("error", `\u2716 ${event.message}${suffix(" (", event.code, ")")}`)
1975
+ ];
1976
+ case "status":
1977
+ return [
1978
+ this.#row("status", `\u25CF ${event.status}${suffix(" \u2014 ", event.detail, "")}`)
1979
+ ];
1980
+ case "finish":
1981
+ return [
1982
+ this.#row("finish", this.#finishText(event.reason, event.usage?.totalTokens))
1983
+ ];
1984
+ // `partial-tool-call` streams incremental args — the committed `tool-call` renders them.
1985
+ default:
1986
+ return [];
1987
+ }
1988
+ }
1989
+ #toolResult(isError2, body) {
1990
+ return this.#row(isError2 ? "tool-error" : "tool-result", ` \u23BF ${body}`);
1991
+ }
1992
+ #finishText(reason, tokens) {
1993
+ const r = suffix(" ", reason, "");
1994
+ const t = tokens === void 0 ? "" : ` \xB7 ${tokens} tokens`;
1995
+ return `<<${r}${t} >>`;
1996
+ }
1997
+ #row(kind, text) {
1998
+ return {
1999
+ kind,
2000
+ text: this.#ansi && ANSI[kind] !== "" ? `${ANSI[kind]}${text}${RESET}` : text
2001
+ };
2002
+ }
2003
+ };
2004
+ var JsonPresenter = class {
2005
+ static {
2006
+ __name(this, "JsonPresenter");
2007
+ }
2008
+ static {
2009
+ __name2(this, "JsonPresenter");
2010
+ }
2011
+ surface = "json";
2012
+ #ns;
2013
+ constructor(options = {}) {
2014
+ this.#ns = options.namespace ?? "agent.";
2015
+ }
2016
+ present(event) {
2017
+ const { type, ...payload } = event;
2018
+ return [
2019
+ {
2020
+ type: `${this.#ns}${type}`,
2021
+ ...payload
2022
+ }
2023
+ ];
2024
+ }
2025
+ };
1907
2026
 
1908
2027
  // src/bridge/present-ui-message-stream.ts
1909
2028
  function toAgentOutputEvent(e) {
@@ -3403,6 +3522,10 @@ function matchRoute(routes, method, pathname) {
3403
3522
  __name(matchRoute, "matchRoute");
3404
3523
 
3405
3524
  export {
3525
+ AGENT_BRAND,
3526
+ isAgentDefinition,
3527
+ compileAgentDefinition,
3528
+ compileSkillsSelection,
3406
3529
  createAgentExecutionContext,
3407
3530
  isAgentContext,
3408
3531
  compileContextWindow,
@@ -3423,9 +3546,6 @@ export {
3423
3546
  isError,
3424
3547
  isApprovalRequired,
3425
3548
  generateAgentRoutes,
3426
- AGENT_BRAND,
3427
- isAgentDefinition,
3428
- compileAgentDefinition,
3429
3549
  translateSdkEvent,
3430
3550
  buildModelSelection,
3431
3551
  createThinkTagExtractor,
@@ -3475,4 +3595,4 @@ export {
3475
3595
  generateAgentManifest,
3476
3596
  agentsPlugin
3477
3597
  };
3478
- //# sourceMappingURL=chunk-YBNKD5UM.js.map
3598
+ //# sourceMappingURL=chunk-FEH7JFH7.js.map