@theokit/agents 0.24.1 → 0.25.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/{bridge-entry-CILcYM0y.d.ts → bridge-entry-DfwOnvUB.d.ts} +8 -1
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +1 -1
- package/dist/{chunk-IFVNH37L.js → chunk-FP7VPNFW.js} +133 -14
- package/dist/chunk-FP7VPNFW.js.map +1 -0
- package/dist/decorators.d.ts +2 -2
- package/dist/index.d.ts +11 -4
- package/dist/index.js +1 -1
- package/dist/{skills-CTzgfoff.d.ts → skills-CLymniNy.d.ts} +7 -0
- package/package.json +9 -9
- package/LICENSE +0 -201
- package/dist/chunk-IFVNH37L.js.map +0 -1
|
@@ -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-
|
|
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-
|
|
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-
|
|
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
|
@@ -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,
|
|
@@ -550,7 +551,7 @@ function translateToolCallEvent(msg) {
|
|
|
550
551
|
type: "tool_call",
|
|
551
552
|
callId,
|
|
552
553
|
toolName,
|
|
553
|
-
input: msg.input ?? msg.arguments ?? {}
|
|
554
|
+
input: msg.args ?? msg.input ?? msg.arguments ?? {}
|
|
554
555
|
}
|
|
555
556
|
];
|
|
556
557
|
}
|
|
@@ -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
|
|
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
|
-
|
|
1003
|
-
|
|
1118
|
+
for await (const event of applyTextTransforms(merged, {
|
|
1119
|
+
parseThinkTags,
|
|
1120
|
+
stripToolDialect
|
|
1121
|
+
})) {
|
|
1004
1122
|
yield event;
|
|
1005
1123
|
}
|
|
1006
1124
|
if (!state.sawError) {
|
|
@@ -1452,6 +1570,7 @@ var AgentRunner = class {
|
|
|
1452
1570
|
model: opts.model,
|
|
1453
1571
|
reasoningEffort: opts.reasoningEffort,
|
|
1454
1572
|
parseThinkTags: opts.parseThinkTags,
|
|
1573
|
+
stripToolDialect: opts.stripToolDialect,
|
|
1455
1574
|
cwd: opts.cwd,
|
|
1456
1575
|
plugins: opts.plugins,
|
|
1457
1576
|
providers: opts.providers,
|
|
@@ -1755,4 +1874,4 @@ export {
|
|
|
1755
1874
|
generateAgentManifest,
|
|
1756
1875
|
agentsPlugin
|
|
1757
1876
|
};
|
|
1758
|
-
//# sourceMappingURL=chunk-
|
|
1877
|
+
//# sourceMappingURL=chunk-FP7VPNFW.js.map
|