@theokit/agents 0.24.0 → 0.25.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.
@@ -1,5 +1,5 @@
1
1
  import { ExecutionContext } from '@theokit/http';
2
- import { A as AgentOptions, T as ToolOptions, g as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, f as GatewayOptions, l as MemoryOptions, t as SkillsOptions, e as ContextWindowOptions, q as ProjectContextOptions, j as McpServersMap, b as CompactionDecoratorConfig, R as ReasoningEffort } from './skills-CTzgfoff.js';
2
+ import { A as AgentOptions, T as ToolOptions, g as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, f as GatewayOptions, l as MemoryOptions, t as SkillsOptions, e as ContextWindowOptions, q as ProjectContextOptions, j as McpServersMap, b as CompactionDecoratorConfig, R as ReasoningEffort } from './skills-CLymniNy.js';
3
3
  import { SystemPromptResolver, SkillsSettings, ContextSettings, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition, BudgetTracker, ConversationStorageAdapter, CustomTool, ModelSelection } from '@theokit/sdk';
4
4
  import { RetryOptions } from '@theokit/sdk/retry';
5
5
  import { z } from 'zod';
@@ -138,6 +138,8 @@ interface CompiledAgentOptions {
138
138
  reasoningEffort?: ReasoningEffort;
139
139
  /** Opt-in `<think>`-tag extraction declared via `@Agent({ parseThinkTags })` (M2); wraps the stream when true. */
140
140
  parseThinkTags?: boolean;
141
+ /** Opt-in tool-dialect stripping declared via `@Agent({ stripToolDialect })` (theocode#32); strips leaked `<function=…></tool_call>` from text when true. */
142
+ stripToolDialect?: boolean;
141
143
  /** Static prompt OR a per-request {@link SystemPromptResolver} (V4-L.1, Axis-B). */
142
144
  systemPrompt?: string | SystemPromptResolver;
143
145
  tools: CompiledTool[];
@@ -427,6 +429,11 @@ interface RuntimeOverrides {
427
429
  * `<think>`-tag extractor so inline `<think>…</think>` text becomes `thinking` StreamEvents.
428
430
  */
429
431
  parseThinkTags?: boolean;
432
+ /**
433
+ * Per-run opt-in (`?? compiled.stripToolDialect`): when true, strip a leaked Hermes
434
+ * `<function=…></tool_call>` tool-call dialect out of the assistant text stream (theocode#32).
435
+ */
436
+ stripToolDialect?: boolean;
430
437
  /** Per-run cwd → `Agent.create({ local: { cwd } })` → `SystemPromptContext.cwd`. */
431
438
  cwd?: string;
432
439
  /**
package/dist/bridge.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { A as AgentExecutionContext, b as AgentManifest, c as AgentManifestEntry, d as AgentManifestTool, e as AgentRoute, f as AgentRouteContext, g as AgentRunInfo, h as AgentStreamEvent, i as AgentWalkResult, j as AgentWarningCode, k as AgentsPluginOptions, l as ApprovalRequiredEvent, m as ArtifactChunkEvent, n as ArtifactStartEvent, B as BudgetExceededError, o as CheckpointSavedEvent, C as CompiledAgentOptions, p as CompiledContextWindow, a as CompiledTool, r as DelegateOptions, s as DelegationError, D as DelegationResult, t as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, G as RunStartedEvent, H as SdkMessage, J as Segment, K as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, M as ThinkingEvent, N as ToolCallEvent, O as ToolResultEvent, P as ToolWalkResult, Q as ToolboxWalkResult, U as agentsPlugin, V as buildModelSelection, W as compileAgent, X as compileContextWindow, Y as compileProjectContext, Z as compileSkills, _ as compileTools, $ as createAgentExecutionContext, a0 as createSdkAgentStream, a1 as createThinkTagExtractor, a2 as delegate, a3 as extractThinkTagStream, a4 as generateAgentManifest, a5 as generateAgentRoutes, a6 as isAgentContext, a7 as isApprovalRequired, a8 as isDone, a9 as isError, aa as isTextDelta, ab as isToolCall, ac as isToolResult, ag as projectContextMetadataOnlyKnobs, aj as streamAgentResponse, ak as translateSdkEvent, al as validateUniqueRoutes, am as walkAgentMetadata } from './bridge-entry-CILcYM0y.js';
1
+ export { A as AgentExecutionContext, b as AgentManifest, c as AgentManifestEntry, d as AgentManifestTool, e as AgentRoute, f as AgentRouteContext, g as AgentRunInfo, h as AgentStreamEvent, i as AgentWalkResult, j as AgentWarningCode, k as AgentsPluginOptions, l as ApprovalRequiredEvent, m as ArtifactChunkEvent, n as ArtifactStartEvent, B as BudgetExceededError, o as CheckpointSavedEvent, C as CompiledAgentOptions, p as CompiledContextWindow, a as CompiledTool, r as DelegateOptions, s as DelegationError, D as DelegationResult, t as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, G as RunStartedEvent, H as SdkMessage, J as Segment, K as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, M as ThinkingEvent, N as ToolCallEvent, O as ToolResultEvent, P as ToolWalkResult, Q as ToolboxWalkResult, U as agentsPlugin, V as buildModelSelection, W as compileAgent, X as compileContextWindow, Y as compileProjectContext, Z as compileSkills, _ as compileTools, $ as createAgentExecutionContext, a0 as createSdkAgentStream, a1 as createThinkTagExtractor, a2 as delegate, a3 as extractThinkTagStream, a4 as generateAgentManifest, a5 as generateAgentRoutes, a6 as isAgentContext, a7 as isApprovalRequired, a8 as isDone, a9 as isError, aa as isTextDelta, ab as isToolCall, ac as isToolResult, ag as projectContextMetadataOnlyKnobs, aj as streamAgentResponse, ak as translateSdkEvent, al as validateUniqueRoutes, am as walkAgentMetadata } from './bridge-entry-DfwOnvUB.js';
2
2
  import '@theokit/http';
3
- import './skills-CTzgfoff.js';
3
+ import './skills-CLymniNy.js';
4
4
  import '@theokit/sdk';
5
5
  import 'zod';
6
6
  import '@theokit/sdk/retry';
package/dist/bridge.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  translateSdkEvent,
29
29
  validateUniqueRoutes,
30
30
  walkAgentMetadata
31
- } from "./chunk-FJXXNWCG.js";
31
+ } from "./chunk-DOEEZXSW.js";
32
32
  import "./chunk-GVPUUKKE.js";
33
33
  import "./chunk-7QVYU63E.js";
34
34
  export {
@@ -302,6 +302,7 @@ function compileAgent(walkResult, toolboxInstances = /* @__PURE__ */ new Map())
302
302
  model: walkResult.agentConfig.model,
303
303
  reasoningEffort: walkResult.agentConfig.reasoningEffort,
304
304
  parseThinkTags: walkResult.agentConfig.parseThinkTags,
305
+ stripToolDialect: walkResult.agentConfig.stripToolDialect,
305
306
  systemPrompt: walkResult.agentConfig.systemPrompt,
306
307
  tools,
307
308
  agents,
@@ -753,6 +754,104 @@ async function* extractThinkTagStream(source) {
753
754
  }
754
755
  __name(extractThinkTagStream, "extractThinkTagStream");
755
756
 
757
+ // src/bridge/tool-dialect-stripper.ts
758
+ var OPEN2 = "<function=";
759
+ var CLOSE2 = "</tool_call>";
760
+ function heldPrefixLength2(s, delim) {
761
+ const max = Math.min(s.length, delim.length - 1);
762
+ for (let k = max; k >= 1; k--) {
763
+ if (s.slice(s.length - k) === delim.slice(0, k)) return k;
764
+ }
765
+ return 0;
766
+ }
767
+ __name(heldPrefixLength2, "heldPrefixLength");
768
+ function createToolDialectStripper() {
769
+ let mode = "text";
770
+ let buffer = "";
771
+ let pendingLeak = "";
772
+ const write = /* @__PURE__ */ __name((chunk) => {
773
+ buffer += chunk;
774
+ const out = [];
775
+ for (; ; ) {
776
+ if (mode === "text") {
777
+ const idx2 = buffer.indexOf(OPEN2);
778
+ if (idx2 !== -1) {
779
+ const content = buffer.slice(0, idx2);
780
+ if (content) out.push({
781
+ kind: "text",
782
+ content
783
+ });
784
+ pendingLeak = OPEN2;
785
+ buffer = buffer.slice(idx2 + OPEN2.length);
786
+ mode = "stripping";
787
+ continue;
788
+ }
789
+ const keep2 = heldPrefixLength2(buffer, OPEN2);
790
+ const emit = buffer.slice(0, buffer.length - keep2);
791
+ if (emit) out.push({
792
+ kind: "text",
793
+ content: emit
794
+ });
795
+ buffer = buffer.slice(buffer.length - keep2);
796
+ break;
797
+ }
798
+ const idx = buffer.indexOf(CLOSE2);
799
+ if (idx !== -1) {
800
+ buffer = buffer.slice(idx + CLOSE2.length);
801
+ pendingLeak = "";
802
+ mode = "text";
803
+ continue;
804
+ }
805
+ const keep = heldPrefixLength2(buffer, CLOSE2);
806
+ pendingLeak += buffer.slice(0, buffer.length - keep);
807
+ buffer = buffer.slice(buffer.length - keep);
808
+ break;
809
+ }
810
+ return out;
811
+ }, "write");
812
+ const end = /* @__PURE__ */ __name(() => {
813
+ const leftover = mode === "stripping" ? pendingLeak + buffer : buffer;
814
+ buffer = "";
815
+ pendingLeak = "";
816
+ return leftover ? [
817
+ {
818
+ kind: "text",
819
+ content: leftover
820
+ }
821
+ ] : [];
822
+ }, "end");
823
+ return {
824
+ write,
825
+ end
826
+ };
827
+ }
828
+ __name(createToolDialectStripper, "createToolDialectStripper");
829
+ async function* stripToolDialectStream(source) {
830
+ const stripper = createToolDialectStripper();
831
+ try {
832
+ for await (const event of source) {
833
+ if (event.type === "text_delta" && typeof event.content === "string") {
834
+ for (const seg of stripper.write(event.content)) {
835
+ yield {
836
+ type: "text_delta",
837
+ content: seg.content
838
+ };
839
+ }
840
+ } else {
841
+ yield event;
842
+ }
843
+ }
844
+ } finally {
845
+ for (const seg of stripper.end()) {
846
+ yield {
847
+ type: "text_delta",
848
+ content: seg.content
849
+ };
850
+ }
851
+ }
852
+ }
853
+ __name(stripToolDialectStream, "stripToolDialectStream");
854
+
756
855
  // src/bridge/sdk-adapter.ts
757
856
  function assembleM8CreateOptions(compiled) {
758
857
  const options = {};
@@ -930,10 +1029,35 @@ function createDeltaSink(queue) {
930
1029
  };
931
1030
  }
932
1031
  __name(createDeltaSink, "createDeltaSink");
1032
+ function resolveTextTransformFlags(compiled, overrides) {
1033
+ return {
1034
+ parseThinkTags: overrides.parseThinkTags ?? compiled.parseThinkTags ?? false,
1035
+ stripToolDialect: overrides.stripToolDialect ?? compiled.stripToolDialect ?? false
1036
+ };
1037
+ }
1038
+ __name(resolveTextTransformFlags, "resolveTextTransformFlags");
1039
+ function applyTextTransforms(events, opts) {
1040
+ let out = opts.parseThinkTags ? extractThinkTagStream(events) : events;
1041
+ if (opts.stripToolDialect) out = stripToolDialectStream(out);
1042
+ return out;
1043
+ }
1044
+ __name(applyTextTransforms, "applyTextTransforms");
1045
+ function buildSdkTools(compiledTools, defineTool, extraSdkTools = []) {
1046
+ return [
1047
+ ...compiledTools.map((t) => defineTool({
1048
+ name: t.name,
1049
+ description: t.description,
1050
+ inputSchema: t.inputSchema,
1051
+ handler: t.handler
1052
+ })),
1053
+ ...extraSdkTools
1054
+ ];
1055
+ }
1056
+ __name(buildSdkTools, "buildSdkTools");
933
1057
  function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
934
1058
  const model = overrides.model ?? compiled.model ?? "openai/gpt-4o-mini";
935
1059
  const reasoningEffort = overrides.reasoningEffort ?? compiled.reasoningEffort;
936
- const parseThinkTags = overrides.parseThinkTags ?? compiled.parseThinkTags ?? false;
1060
+ const { parseThinkTags, stripToolDialect } = resolveTextTransformFlags(compiled, overrides);
937
1061
  let storage = overrides.conversationStorage;
938
1062
  return (message, sessionId, factoryOpts) => ({
939
1063
  async *[Symbol.asyncIterator]() {
@@ -956,15 +1080,7 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
956
1080
  };
957
1081
  return;
958
1082
  }
959
- const sdkTools = [
960
- ...compiledTools.map((t) => defineTool({
961
- name: t.name,
962
- description: t.description,
963
- inputSchema: t.inputSchema,
964
- handler: t.handler
965
- })),
966
- ...overrides.sdkTools ?? []
967
- ];
1083
+ const sdkTools = buildSdkTools(compiledTools, defineTool, overrides.sdkTools);
968
1084
  let agent;
969
1085
  try {
970
1086
  const { options: m8, applied } = assembleM8CreateOptions(compiled);
@@ -999,8 +1115,10 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
999
1115
  });
1000
1116
  const openStream = /* @__PURE__ */ __name(async () => (await sendPromise).stream(), "openStream");
1001
1117
  const merged = mergeDeltaStream(queue, openStream, runId, state);
1002
- const events = parseThinkTags ? extractThinkTagStream(merged) : merged;
1003
- for await (const event of events) {
1118
+ for await (const event of applyTextTransforms(merged, {
1119
+ parseThinkTags,
1120
+ stripToolDialect
1121
+ })) {
1004
1122
  yield event;
1005
1123
  }
1006
1124
  if (!state.sawError) {
@@ -1165,9 +1283,8 @@ function stableStringify(value) {
1165
1283
  return `{${entries.join(",")}}`;
1166
1284
  }
1167
1285
  __name(stableStringify, "stableStringify");
1168
- function roundSignature(toolCalls, text) {
1169
- const calls = toolCalls.map((tc) => `${tc.name}:${stableStringify(tc.input)}`).sort((a, b) => a.localeCompare(b)).join(",");
1170
- return `${calls}|${text}`;
1286
+ function roundSignature(toolCalls) {
1287
+ return toolCalls.map((tc) => `${tc.name}:${stableStringify(tc.input)}`).sort((a, b) => a.localeCompare(b)).join(",");
1171
1288
  }
1172
1289
  __name(roundSignature, "roundSignature");
1173
1290
  function terminalReason(reflectionContinue, roundReason, round, maxIterations) {
@@ -1368,8 +1485,8 @@ async function* runReflectiveLoopStream(factory, message, sessionId, config) {
1368
1485
  if (Number.isFinite(budget) && acc.cost > budget) {
1369
1486
  throw new BudgetExceededError(agentName, acc.cost, budget);
1370
1487
  }
1371
- if (r.finishReason === TOOL_CALLS) {
1372
- const sig = roundSignature(r.toolCalls, r.responseText);
1488
+ if (r.finishReason === TOOL_CALLS && r.toolCalls.length > 0) {
1489
+ const sig = roundSignature(r.toolCalls);
1373
1490
  stuck = sig === prevSig ? stuck + 1 : 0;
1374
1491
  if (stuck >= NO_PROGRESS_THRESHOLD) return finalize(acc, round, "no_progress", loop.name);
1375
1492
  prevSig = sig;
@@ -1453,6 +1570,7 @@ var AgentRunner = class {
1453
1570
  model: opts.model,
1454
1571
  reasoningEffort: opts.reasoningEffort,
1455
1572
  parseThinkTags: opts.parseThinkTags,
1573
+ stripToolDialect: opts.stripToolDialect,
1456
1574
  cwd: opts.cwd,
1457
1575
  plugins: opts.plugins,
1458
1576
  providers: opts.providers,
@@ -1756,4 +1874,4 @@ export {
1756
1874
  generateAgentManifest,
1757
1875
  agentsPlugin
1758
1876
  };
1759
- //# sourceMappingURL=chunk-FJXXNWCG.js.map
1877
+ //# sourceMappingURL=chunk-DOEEZXSW.js.map