@theokit/agents 16.3.0 → 16.5.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/CHANGELOG.md +30 -0
- package/dist/a2a.d.ts +33 -1
- package/dist/a2a.js +353 -3
- package/dist/a2a.js.map +1 -1
- package/dist/{agent-compiler-JSYkHpa7.d.ts → agent-compiler-C-4X_vKz.d.ts} +1 -51
- package/dist/{agent-orchestrator-BFWg2URC.d.ts → agent-orchestrator-BHF1bS6k.d.ts} +1 -1
- package/dist/{agent-runner-BUJKNNuI.d.ts → agent-runner-BoMoOnHV.d.ts} +2 -2
- package/dist/auth.d.ts +5 -4
- package/dist/auth.js.map +1 -1
- package/dist/{bridge-entry-BNWDrPzg.d.ts → bridge-entry-DO1LjHkc.d.ts} +215 -8
- package/dist/bridge.d.ts +6 -6
- package/dist/bridge.js +25 -9
- package/dist/{chunk-A7RXWJZE.js → chunk-AZ2FOUSN.js} +450 -476
- package/dist/chunk-AZ2FOUSN.js.map +1 -0
- package/dist/{chunk-MB23MSOK.js → chunk-K4MY4CV7.js} +45 -22
- package/dist/chunk-K4MY4CV7.js.map +1 -0
- package/dist/{chunk-CJMYZKUL.js → chunk-RZWD73QG.js} +429 -14
- package/dist/chunk-RZWD73QG.js.map +1 -0
- package/dist/{chunk-SAKSZKVK.js → chunk-ZLKZOSWR.js} +39 -17
- package/dist/chunk-ZLKZOSWR.js.map +1 -0
- package/dist/code-mode-quickjs.d.ts +33 -0
- package/dist/code-mode-quickjs.js +353 -0
- package/dist/code-mode-quickjs.js.map +1 -0
- package/dist/code-mode.d.ts +110 -0
- package/dist/code-mode.js +165 -0
- package/dist/code-mode.js.map +1 -0
- package/dist/{delegation-scoring-Cn5eM4lQ.d.ts → delegation-scoring-BBPJ9eug.d.ts} +8 -2
- package/dist/evals.d.ts +2 -2
- package/dist/evals.js +3 -1
- package/dist/evals.js.map +1 -1
- package/dist/handoff.d.ts +3 -3
- package/dist/handoff.js +2 -2
- package/dist/index.d.ts +25 -10
- package/dist/index.js +31 -9
- package/dist/index.js.map +1 -1
- package/dist/persistence.d.ts +1 -1
- package/dist/persistence.js +2 -1
- package/dist/persistence.js.map +1 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +2 -0
- package/dist/sandbox.js.map +1 -1
- package/dist/{sdk-adapter-DQnKx7bA.d.ts → sdk-adapter-C57SpmLH.d.ts} +3 -1
- package/dist/testing.d.ts +1 -1
- package/dist/tools.d.ts +140 -5
- package/dist/tools.js +591 -29
- package/dist/tools.js.map +1 -1
- package/docs/capability-map.md +80 -6
- package/package.json +23 -5
- package/dist/chunk-A7RXWJZE.js.map +0 -1
- package/dist/chunk-CJMYZKUL.js.map +0 -1
- package/dist/chunk-MB23MSOK.js.map +0 -1
- package/dist/chunk-SAKSZKVK.js.map +0 -1
|
@@ -849,6 +849,296 @@ function translateInteractionUpdate(update) {
|
|
|
849
849
|
}
|
|
850
850
|
__name(translateInteractionUpdate, "translateInteractionUpdate");
|
|
851
851
|
|
|
852
|
+
// src/bridge/sdk-timeline.ts
|
|
853
|
+
function idsOf(e, raw) {
|
|
854
|
+
const ids = [];
|
|
855
|
+
const callId = typeof e.callId === "string" ? e.callId : "";
|
|
856
|
+
if (callId !== "") ids.push(callId);
|
|
857
|
+
const model = raw?.modelCallId;
|
|
858
|
+
if (typeof model === "string" && model !== "" && model !== callId) ids.push(model);
|
|
859
|
+
return ids;
|
|
860
|
+
}
|
|
861
|
+
__name(idsOf, "idsOf");
|
|
862
|
+
function bucketFor(e, seen) {
|
|
863
|
+
if (e.type === "tool_call") return seen.started;
|
|
864
|
+
if (e.type === "tool_result") return seen.completed;
|
|
865
|
+
return void 0;
|
|
866
|
+
}
|
|
867
|
+
__name(bucketFor, "bucketFor");
|
|
868
|
+
function isToolLifecycleEvent(e) {
|
|
869
|
+
return e.type === "tool_call" || e.type === "tool_result" || e.type === "partial_tool_call";
|
|
870
|
+
}
|
|
871
|
+
__name(isToolLifecycleEvent, "isToolLifecycleEvent");
|
|
872
|
+
function mergeIntoPending(e, ids, seen) {
|
|
873
|
+
if (e.type !== "tool_result" || !e.isError) return;
|
|
874
|
+
const held = seen.pending.find((p) => p.ids.some((id) => ids.includes(id)));
|
|
875
|
+
if (held?.event.type !== "tool_result") return;
|
|
876
|
+
held.event = {
|
|
877
|
+
...held.event,
|
|
878
|
+
isError: true
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
__name(mergeIntoPending, "mergeIntoPending");
|
|
882
|
+
function dedupeTools(events, raw, seen) {
|
|
883
|
+
return events.filter((e) => {
|
|
884
|
+
if (e.type === "thinking") {
|
|
885
|
+
if (seen.sawThinkingDelta) return false;
|
|
886
|
+
seen.sawThinkingDelta = true;
|
|
887
|
+
return true;
|
|
888
|
+
}
|
|
889
|
+
const bucket = bucketFor(e, seen);
|
|
890
|
+
if (bucket === void 0) return true;
|
|
891
|
+
const ids = idsOf(e, raw);
|
|
892
|
+
if (ids.length === 0) return true;
|
|
893
|
+
if (ids.some((id) => bucket.has(id))) {
|
|
894
|
+
mergeIntoPending(e, ids, seen);
|
|
895
|
+
return false;
|
|
896
|
+
}
|
|
897
|
+
for (const id of ids) bucket.add(id);
|
|
898
|
+
if (e.type === "tool_result") {
|
|
899
|
+
seen.pending.push({
|
|
900
|
+
ids,
|
|
901
|
+
event: e
|
|
902
|
+
});
|
|
903
|
+
return false;
|
|
904
|
+
}
|
|
905
|
+
return true;
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
__name(dedupeTools, "dedupeTools");
|
|
909
|
+
function releasePendingToolResults(translated, seen) {
|
|
910
|
+
if (seen.pending.length === 0) return [];
|
|
911
|
+
if (translated.length === 0 || translated.every(isToolLifecycleEvent)) return [];
|
|
912
|
+
return flushPendingToolResults(seen);
|
|
913
|
+
}
|
|
914
|
+
__name(releasePendingToolResults, "releasePendingToolResults");
|
|
915
|
+
function flushPendingToolResults(seen) {
|
|
916
|
+
const out = seen.pending.map((p) => p.event);
|
|
917
|
+
seen.pending = [];
|
|
918
|
+
return out;
|
|
919
|
+
}
|
|
920
|
+
__name(flushPendingToolResults, "flushPendingToolResults");
|
|
921
|
+
function createToolSeen() {
|
|
922
|
+
return {
|
|
923
|
+
started: /* @__PURE__ */ new Set(),
|
|
924
|
+
completed: /* @__PURE__ */ new Set(),
|
|
925
|
+
pending: [],
|
|
926
|
+
sawThinkingDelta: false
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
__name(createToolSeen, "createToolSeen");
|
|
930
|
+
function translateTimelineEvent(ev, runId, seen) {
|
|
931
|
+
if (ev.kind === "delta") {
|
|
932
|
+
if (ev.update === void 0) return [];
|
|
933
|
+
const events2 = translateInteractionUpdate(ev.update);
|
|
934
|
+
const released2 = releasePendingToolResults(events2, seen);
|
|
935
|
+
return [
|
|
936
|
+
...released2,
|
|
937
|
+
...dedupeTools(events2, ev.update, seen)
|
|
938
|
+
];
|
|
939
|
+
}
|
|
940
|
+
if (ev.message === void 0) return [];
|
|
941
|
+
const events = translateSdkEvent(ev.message, runId);
|
|
942
|
+
const kept = ev.textAlreadyStreamed === true ? events.filter((e) => e.type !== "text_delta") : events;
|
|
943
|
+
const released = releasePendingToolResults(kept, seen);
|
|
944
|
+
return [
|
|
945
|
+
...released,
|
|
946
|
+
...dedupeTools(kept, ev.message, seen)
|
|
947
|
+
];
|
|
948
|
+
}
|
|
949
|
+
__name(translateTimelineEvent, "translateTimelineEvent");
|
|
950
|
+
|
|
951
|
+
// src/bridge/think-tag-extractor.ts
|
|
952
|
+
var TAG = "think";
|
|
953
|
+
var OPEN = `<${TAG}>`;
|
|
954
|
+
var CLOSE = `</${TAG}>`;
|
|
955
|
+
function heldPrefixLength(s, delim) {
|
|
956
|
+
const max = Math.min(s.length, delim.length - 1);
|
|
957
|
+
for (let k = max; k >= 1; k--) {
|
|
958
|
+
if (s.slice(s.length - k) === delim.slice(0, k)) return k;
|
|
959
|
+
}
|
|
960
|
+
return 0;
|
|
961
|
+
}
|
|
962
|
+
__name(heldPrefixLength, "heldPrefixLength");
|
|
963
|
+
function createThinkTagExtractor() {
|
|
964
|
+
let mode = "text";
|
|
965
|
+
let buffer = "";
|
|
966
|
+
const write = /* @__PURE__ */ __name((chunk) => {
|
|
967
|
+
buffer += chunk;
|
|
968
|
+
const out = [];
|
|
969
|
+
for (; ; ) {
|
|
970
|
+
const delim = mode === "text" ? OPEN : CLOSE;
|
|
971
|
+
const idx = buffer.indexOf(delim);
|
|
972
|
+
if (idx !== -1) {
|
|
973
|
+
const content = buffer.slice(0, idx);
|
|
974
|
+
if (content) out.push({
|
|
975
|
+
kind: mode,
|
|
976
|
+
content
|
|
977
|
+
});
|
|
978
|
+
buffer = buffer.slice(idx + delim.length);
|
|
979
|
+
mode = mode === "text" ? "thinking" : "text";
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
const keep = heldPrefixLength(buffer, delim);
|
|
983
|
+
const emit = buffer.slice(0, buffer.length - keep);
|
|
984
|
+
if (emit) out.push({
|
|
985
|
+
kind: mode,
|
|
986
|
+
content: emit
|
|
987
|
+
});
|
|
988
|
+
buffer = buffer.slice(buffer.length - keep);
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
return out;
|
|
992
|
+
}, "write");
|
|
993
|
+
const end = /* @__PURE__ */ __name(() => {
|
|
994
|
+
if (!buffer) return [];
|
|
995
|
+
const seg = {
|
|
996
|
+
kind: mode,
|
|
997
|
+
content: buffer
|
|
998
|
+
};
|
|
999
|
+
buffer = "";
|
|
1000
|
+
return [
|
|
1001
|
+
seg
|
|
1002
|
+
];
|
|
1003
|
+
}, "end");
|
|
1004
|
+
return {
|
|
1005
|
+
write,
|
|
1006
|
+
end
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
__name(createThinkTagExtractor, "createThinkTagExtractor");
|
|
1010
|
+
function segmentToEvent(seg) {
|
|
1011
|
+
return seg.kind === "thinking" ? {
|
|
1012
|
+
type: "thinking",
|
|
1013
|
+
content: seg.content
|
|
1014
|
+
} : {
|
|
1015
|
+
type: "text_delta",
|
|
1016
|
+
content: seg.content
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
__name(segmentToEvent, "segmentToEvent");
|
|
1020
|
+
async function* extractThinkTagStream(source) {
|
|
1021
|
+
const extractor = createThinkTagExtractor();
|
|
1022
|
+
try {
|
|
1023
|
+
for await (const event of source) {
|
|
1024
|
+
if (event.type === "text_delta" && typeof event.content === "string") {
|
|
1025
|
+
for (const seg of extractor.write(event.content)) yield segmentToEvent(seg);
|
|
1026
|
+
} else {
|
|
1027
|
+
yield event;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
} finally {
|
|
1031
|
+
for (const seg of extractor.end()) yield segmentToEvent(seg);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
__name(extractThinkTagStream, "extractThinkTagStream");
|
|
1035
|
+
|
|
1036
|
+
// src/bridge/definition-or-thunk.ts
|
|
1037
|
+
function project(def, overrides) {
|
|
1038
|
+
const compiled = compileAgentDefinition(def);
|
|
1039
|
+
return {
|
|
1040
|
+
compiled,
|
|
1041
|
+
model: overrides.model ?? compiled.model ?? "openai/gpt-4o-mini",
|
|
1042
|
+
reasoningEffort: overrides.reasoningEffort ?? compiled.reasoningEffort,
|
|
1043
|
+
runContext: overrides.runContext ?? compiled.runContext
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
__name(project, "project");
|
|
1047
|
+
function resolveProjection(def, overrides) {
|
|
1048
|
+
if (typeof def === "function") {
|
|
1049
|
+
return async (sessionId) => project(await def(sessionId), overrides);
|
|
1050
|
+
}
|
|
1051
|
+
const eager = project(def, overrides);
|
|
1052
|
+
return () => Promise.resolve(eager);
|
|
1053
|
+
}
|
|
1054
|
+
__name(resolveProjection, "resolveProjection");
|
|
1055
|
+
|
|
1056
|
+
// src/bridge/handle-wrappers.ts
|
|
1057
|
+
function withStepCeiling(handle, maxIterations) {
|
|
1058
|
+
if (maxIterations === void 0) return handle;
|
|
1059
|
+
return {
|
|
1060
|
+
get agentId() {
|
|
1061
|
+
return handle.agentId;
|
|
1062
|
+
},
|
|
1063
|
+
dispose: /* @__PURE__ */ __name(() => handle.dispose(), "dispose"),
|
|
1064
|
+
...forwardedMembers(handle),
|
|
1065
|
+
send: /* @__PURE__ */ __name((msg, sendOpts) => handle.send(msg, {
|
|
1066
|
+
maxIterations,
|
|
1067
|
+
...sendOpts
|
|
1068
|
+
}), "send")
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
__name(withStepCeiling, "withStepCeiling");
|
|
1072
|
+
function withGuardrails(handle, guardrails) {
|
|
1073
|
+
if (guardrails === void 0 || guardrails.length === 0) return handle;
|
|
1074
|
+
return {
|
|
1075
|
+
get agentId() {
|
|
1076
|
+
return handle.agentId;
|
|
1077
|
+
},
|
|
1078
|
+
dispose: /* @__PURE__ */ __name(() => handle.dispose(), "dispose"),
|
|
1079
|
+
...forwardedMembers(handle),
|
|
1080
|
+
send: /* @__PURE__ */ __name(async (msg, sendOpts) => {
|
|
1081
|
+
const guarded = await runInputGuards(msg, guardrails);
|
|
1082
|
+
return guardTurn(await handle.send(guarded, sendOpts), guardrails);
|
|
1083
|
+
}, "send")
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
__name(withGuardrails, "withGuardrails");
|
|
1087
|
+
function forwardedMembers(handle) {
|
|
1088
|
+
return {
|
|
1089
|
+
...handle.generate === void 0 ? {} : {
|
|
1090
|
+
generate: handle.generate.bind(handle)
|
|
1091
|
+
},
|
|
1092
|
+
...handle.pluginManager === void 0 ? {} : {
|
|
1093
|
+
pluginManager: handle.pluginManager.bind(handle)
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
__name(forwardedMembers, "forwardedMembers");
|
|
1098
|
+
function guardTurn(turn, guardrails) {
|
|
1099
|
+
let outcome;
|
|
1100
|
+
const guardedOutcome = /* @__PURE__ */ __name(() => outcome ??= turn.wait().then(async (out) => out.result === void 0 ? out : {
|
|
1101
|
+
...out,
|
|
1102
|
+
result: await runOutputGuards(out.result, guardrails)
|
|
1103
|
+
}), "guardedOutcome");
|
|
1104
|
+
return {
|
|
1105
|
+
wait: guardedOutcome,
|
|
1106
|
+
async *stream() {
|
|
1107
|
+
let out;
|
|
1108
|
+
try {
|
|
1109
|
+
out = await guardedOutcome();
|
|
1110
|
+
} catch (err) {
|
|
1111
|
+
if (!(err instanceof GuardrailViolationError)) throw err;
|
|
1112
|
+
yield errorStatus(err.message);
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
if (out.result !== void 0) {
|
|
1116
|
+
yield {
|
|
1117
|
+
type: "assistant",
|
|
1118
|
+
message: {
|
|
1119
|
+
content: [
|
|
1120
|
+
{
|
|
1121
|
+
type: "text",
|
|
1122
|
+
text: out.result
|
|
1123
|
+
}
|
|
1124
|
+
]
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
if (out.status === "error") yield errorStatus(out.error?.message ?? "run error");
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
__name(guardTurn, "guardTurn");
|
|
1133
|
+
function errorStatus(message) {
|
|
1134
|
+
return {
|
|
1135
|
+
type: "status",
|
|
1136
|
+
status: "ERROR",
|
|
1137
|
+
message
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
__name(errorStatus, "errorStatus");
|
|
1141
|
+
|
|
852
1142
|
// src/bridge/sdk-adapter-create-options.ts
|
|
853
1143
|
import { createRequire } from "module";
|
|
854
1144
|
import { PermissionEngine, PermissionPlugin } from "@theokit/sdk";
|
|
@@ -889,27 +1179,7 @@ function isCodePlugin(entry) {
|
|
|
889
1179
|
__name(isCodePlugin, "isCodePlugin");
|
|
890
1180
|
|
|
891
1181
|
// src/bridge/sdk-adapter-create-options.ts
|
|
892
|
-
var HOOK_GATE_SINCE = {
|
|
893
|
-
major: 5,
|
|
894
|
-
minor: 4
|
|
895
|
-
};
|
|
896
|
-
var COMPAT_IMPORT_SINCE = {
|
|
897
|
-
major: 5,
|
|
898
|
-
minor: 4
|
|
899
|
-
};
|
|
900
1182
|
var COMPAT_ROOT_SINCE_MAJOR = 5;
|
|
901
|
-
var HookGateUnsupportedError = class extends TheokitAgentError2 {
|
|
902
|
-
static {
|
|
903
|
-
__name(this, "HookGateUnsupportedError");
|
|
904
|
-
}
|
|
905
|
-
name = "HookGateUnsupportedError";
|
|
906
|
-
constructor(version) {
|
|
907
|
-
super(`a hook approval gate was declared, but the installed @theokit/sdk (${version ?? "version unreadable"}) cannot honour it: \`local.hooks\` landed in ${String(HOOK_GATE_SINCE.major)}.${String(HOOK_GATE_SINCE.minor)}.0. Forwarding it anyway would leave every hook spawning unreviewed while the gate reports as installed. Upgrade @theokit/sdk, or remove \`hookApproval\` and keep whatever refusal you have today (usetheokit/theokit#686).`, {
|
|
908
|
-
code: "hook_gate_unsupported",
|
|
909
|
-
isRetryable: false
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
1183
|
var CompatRootUnsupportedError = class CompatRootUnsupportedError2 extends TheokitAgentError2 {
|
|
914
1184
|
static {
|
|
915
1185
|
__name(this, "CompatRootUnsupportedError");
|
|
@@ -919,18 +1189,6 @@ var CompatRootUnsupportedError = class CompatRootUnsupportedError2 extends Theok
|
|
|
919
1189
|
super(`\`compatSources\` asks for a foreign configuration root to be read, but the installed @theokit/sdk (${version ?? "version unreadable"}) does not know that option and drops it in silence \u2014 so EVERY foreign surface would be unavailable while the package resolves, compiles and runs. It landed in ${String(COMPAT_ROOT_SINCE_MAJOR)}.0.0, and this package declares a floor above it, so reaching this error means an override pinned the SDK lower. Remove the override, or drop \`compatSources\` if the foreign root is not wanted (usetheokit/theokit#739).`);
|
|
920
1190
|
}
|
|
921
1191
|
};
|
|
922
|
-
var CompatImportUnsupportedError = class extends TheokitAgentError2 {
|
|
923
|
-
static {
|
|
924
|
-
__name(this, "CompatImportUnsupportedError");
|
|
925
|
-
}
|
|
926
|
-
name = "CompatImportUnsupportedError";
|
|
927
|
-
constructor(version) {
|
|
928
|
-
super(`\`claudeCode.import\` narrows WHICH surfaces of a foreign configuration root to read, but the installed @theokit/sdk (${version ?? "version unreadable"}) cannot honour it: the narrowed shape landed in ${String(COMPAT_IMPORT_SINCE.major)}.${String(COMPAT_IMPORT_SINCE.minor)}.0. An older runtime drops the unrecognised shape in silence, so the root would not be read AT ALL \u2014 less than you asked for, not more. Upgrade @theokit/sdk, or omit \`import\` to read every surface of the root (usetheokit/theokit#686).`, {
|
|
929
|
-
code: "compat_import_unsupported",
|
|
930
|
-
isRetryable: false
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
};
|
|
934
1192
|
function compatSourcesForSdk(sources) {
|
|
935
1193
|
const out = [];
|
|
936
1194
|
for (const source of sources) {
|
|
@@ -947,28 +1205,6 @@ function compatSourcesForSdk(sources) {
|
|
|
947
1205
|
return out;
|
|
948
1206
|
}
|
|
949
1207
|
__name(compatSourcesForSdk, "compatSourcesForSdk");
|
|
950
|
-
function assertSdkCanReadNarrowedImport(version) {
|
|
951
|
-
const [major, minor] = (version ?? "").split(".").map((n) => Number.parseInt(n, 10));
|
|
952
|
-
const known = Number.isFinite(major) && Number.isFinite(minor);
|
|
953
|
-
const supported = known && (major > COMPAT_IMPORT_SINCE.major || major === COMPAT_IMPORT_SINCE.major && minor >= COMPAT_IMPORT_SINCE.minor);
|
|
954
|
-
if (!supported) throw new CompatImportUnsupportedError(version);
|
|
955
|
-
}
|
|
956
|
-
__name(assertSdkCanReadNarrowedImport, "assertSdkCanReadNarrowedImport");
|
|
957
|
-
function assertSdkCanGateHooks(version) {
|
|
958
|
-
const [major, minor] = (version ?? "").split(".").map((n) => Number.parseInt(n, 10));
|
|
959
|
-
const known = Number.isFinite(major) && Number.isFinite(minor);
|
|
960
|
-
const supported = known && (major > HOOK_GATE_SINCE.major || major === HOOK_GATE_SINCE.major && minor >= HOOK_GATE_SINCE.minor);
|
|
961
|
-
if (!supported) throw new HookGateUnsupportedError(version);
|
|
962
|
-
}
|
|
963
|
-
__name(assertSdkCanGateHooks, "assertSdkCanGateHooks");
|
|
964
|
-
function installedSdkVersion() {
|
|
965
|
-
try {
|
|
966
|
-
return createRequire(import.meta.url)("@theokit/sdk/package.json").version;
|
|
967
|
-
} catch {
|
|
968
|
-
return void 0;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
__name(installedSdkVersion, "installedSdkVersion");
|
|
972
1208
|
function refuseIfSdkCannotReadCompatSources() {
|
|
973
1209
|
let version;
|
|
974
1210
|
try {
|
|
@@ -1009,7 +1245,7 @@ function applyPlugins(compiled, options, applied) {
|
|
|
1009
1245
|
}
|
|
1010
1246
|
}
|
|
1011
1247
|
__name(applyPlugins, "applyPlugins");
|
|
1012
|
-
function applyLocalSources(compiled, options, applied
|
|
1248
|
+
function applyLocalSources(compiled, options, applied) {
|
|
1013
1249
|
if (compiled.settingSources !== void 0 && compiled.settingSources.length > 0) {
|
|
1014
1250
|
options.local = {
|
|
1015
1251
|
...options.local,
|
|
@@ -1034,9 +1270,6 @@ function applyLocalSources(compiled, options, applied, sdkVersion) {
|
|
|
1034
1270
|
}
|
|
1035
1271
|
if (compiled.compatSources !== void 0 && compiled.compatSources.length > 0) {
|
|
1036
1272
|
const forSdk = compatSourcesForSdk(compiled.compatSources);
|
|
1037
|
-
if (forSdk.some((c) => typeof c === "object" && "import" in c)) {
|
|
1038
|
-
assertSdkCanReadNarrowedImport(sdkVersion ?? installedSdkVersion());
|
|
1039
|
-
}
|
|
1040
1273
|
if (forSdk.length > 0) {
|
|
1041
1274
|
options.local = {
|
|
1042
1275
|
...options.local,
|
|
@@ -1048,9 +1281,8 @@ function applyLocalSources(compiled, options, applied, sdkVersion) {
|
|
|
1048
1281
|
}
|
|
1049
1282
|
}
|
|
1050
1283
|
__name(applyLocalSources, "applyLocalSources");
|
|
1051
|
-
function applyHookApproval(compiled, options, applied
|
|
1284
|
+
function applyHookApproval(compiled, options, applied) {
|
|
1052
1285
|
if (compiled.hookApproval === void 0) return;
|
|
1053
|
-
assertSdkCanGateHooks(sdkVersion ?? installedSdkVersion());
|
|
1054
1286
|
options.local = {
|
|
1055
1287
|
...options.local,
|
|
1056
1288
|
hooks: compiled.hookApproval
|
|
@@ -1058,7 +1290,7 @@ function applyHookApproval(compiled, options, applied, sdkVersion) {
|
|
|
1058
1290
|
applied.push("hookApproval");
|
|
1059
1291
|
}
|
|
1060
1292
|
__name(applyHookApproval, "applyHookApproval");
|
|
1061
|
-
function assembleM8CreateOptions(compiled
|
|
1293
|
+
function assembleM8CreateOptions(compiled) {
|
|
1062
1294
|
const options = {};
|
|
1063
1295
|
const applied = [];
|
|
1064
1296
|
const base = compiled.systemPrompt;
|
|
@@ -1071,8 +1303,8 @@ function assembleM8CreateOptions(compiled, deps = {}) {
|
|
|
1071
1303
|
options.agents = compiled.agents;
|
|
1072
1304
|
applied.push("agents");
|
|
1073
1305
|
}
|
|
1074
|
-
applyLocalSources(compiled, options, applied
|
|
1075
|
-
applyHookApproval(compiled, options, applied
|
|
1306
|
+
applyLocalSources(compiled, options, applied);
|
|
1307
|
+
applyHookApproval(compiled, options, applied);
|
|
1076
1308
|
if (compiled.context) {
|
|
1077
1309
|
options.context = compiled.context;
|
|
1078
1310
|
applied.push("context");
|
|
@@ -1098,254 +1330,63 @@ function assembleM8CreateOptions(compiled, deps = {}) {
|
|
|
1098
1330
|
}
|
|
1099
1331
|
options.memory = {
|
|
1100
1332
|
enabled: true
|
|
1101
|
-
};
|
|
1102
|
-
}
|
|
1103
|
-
applied.push("memory");
|
|
1104
|
-
}
|
|
1105
|
-
if (compiled.telemetry !== void 0) {
|
|
1106
|
-
options.telemetry = compiled.telemetry;
|
|
1107
|
-
applied.push("telemetry");
|
|
1108
|
-
}
|
|
1109
|
-
return {
|
|
1110
|
-
options,
|
|
1111
|
-
applied
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
__name(assembleM8CreateOptions, "assembleM8CreateOptions");
|
|
1115
|
-
function stopReasonOf(result) {
|
|
1116
|
-
if (result.stoppedByDoomLoop === true) return "no_progress";
|
|
1117
|
-
if (result.stoppedAtIterationLimit === true) return "step_limit";
|
|
1118
|
-
return void 0;
|
|
1119
|
-
}
|
|
1120
|
-
__name(stopReasonOf, "stopReasonOf");
|
|
1121
|
-
function doneUsage(sdkUsage) {
|
|
1122
|
-
const usage = sdkUsage ?? {};
|
|
1123
|
-
const inputTokens = countOrZero(usage.inputTokens);
|
|
1124
|
-
const outputTokens = countOrZero(usage.outputTokens);
|
|
1125
|
-
return {
|
|
1126
|
-
inputTokens,
|
|
1127
|
-
outputTokens,
|
|
1128
|
-
totalTokens: inputTokens + outputTokens,
|
|
1129
|
-
reasoningTokens: countOrZero(usage.reasoningTokens),
|
|
1130
|
-
cacheReadTokens: countOrZero(usage.cacheReadTokens),
|
|
1131
|
-
cacheWriteTokens: countOrZero(usage.cacheWriteTokens)
|
|
1132
|
-
};
|
|
1133
|
-
}
|
|
1134
|
-
__name(doneUsage, "doneUsage");
|
|
1135
|
-
function countOrZero(count) {
|
|
1136
|
-
return count ?? 0;
|
|
1137
|
-
}
|
|
1138
|
-
__name(countOrZero, "countOrZero");
|
|
1139
|
-
function realUsageDone(result, t0, model) {
|
|
1140
|
-
const stopReason = stopReasonOf(result);
|
|
1141
|
-
return {
|
|
1142
|
-
type: "done",
|
|
1143
|
-
result: result.result ?? "",
|
|
1144
|
-
usage: doneUsage(result.usage),
|
|
1145
|
-
durationMs: Date.now() - t0,
|
|
1146
|
-
...knownCost(result.cost),
|
|
1147
|
-
...terminalExtras(stopReason, model)
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
__name(realUsageDone, "realUsageDone");
|
|
1151
|
-
function terminalExtras(stopReason, model) {
|
|
1152
|
-
const extras = {};
|
|
1153
|
-
if (stopReason !== void 0) extras.stopReason = stopReason;
|
|
1154
|
-
if (model !== void 0) extras.model = model;
|
|
1155
|
-
return extras;
|
|
1156
|
-
}
|
|
1157
|
-
__name(terminalExtras, "terminalExtras");
|
|
1158
|
-
|
|
1159
|
-
// src/bridge/think-tag-extractor.ts
|
|
1160
|
-
var TAG = "think";
|
|
1161
|
-
var OPEN = `<${TAG}>`;
|
|
1162
|
-
var CLOSE = `</${TAG}>`;
|
|
1163
|
-
function heldPrefixLength(s, delim) {
|
|
1164
|
-
const max = Math.min(s.length, delim.length - 1);
|
|
1165
|
-
for (let k = max; k >= 1; k--) {
|
|
1166
|
-
if (s.slice(s.length - k) === delim.slice(0, k)) return k;
|
|
1167
|
-
}
|
|
1168
|
-
return 0;
|
|
1169
|
-
}
|
|
1170
|
-
__name(heldPrefixLength, "heldPrefixLength");
|
|
1171
|
-
function createThinkTagExtractor() {
|
|
1172
|
-
let mode = "text";
|
|
1173
|
-
let buffer = "";
|
|
1174
|
-
const write = /* @__PURE__ */ __name((chunk) => {
|
|
1175
|
-
buffer += chunk;
|
|
1176
|
-
const out = [];
|
|
1177
|
-
for (; ; ) {
|
|
1178
|
-
const delim = mode === "text" ? OPEN : CLOSE;
|
|
1179
|
-
const idx = buffer.indexOf(delim);
|
|
1180
|
-
if (idx !== -1) {
|
|
1181
|
-
const content = buffer.slice(0, idx);
|
|
1182
|
-
if (content) out.push({
|
|
1183
|
-
kind: mode,
|
|
1184
|
-
content
|
|
1185
|
-
});
|
|
1186
|
-
buffer = buffer.slice(idx + delim.length);
|
|
1187
|
-
mode = mode === "text" ? "thinking" : "text";
|
|
1188
|
-
continue;
|
|
1189
|
-
}
|
|
1190
|
-
const keep = heldPrefixLength(buffer, delim);
|
|
1191
|
-
const emit = buffer.slice(0, buffer.length - keep);
|
|
1192
|
-
if (emit) out.push({
|
|
1193
|
-
kind: mode,
|
|
1194
|
-
content: emit
|
|
1195
|
-
});
|
|
1196
|
-
buffer = buffer.slice(buffer.length - keep);
|
|
1197
|
-
break;
|
|
1198
|
-
}
|
|
1199
|
-
return out;
|
|
1200
|
-
}, "write");
|
|
1201
|
-
const end = /* @__PURE__ */ __name(() => {
|
|
1202
|
-
if (!buffer) return [];
|
|
1203
|
-
const seg = {
|
|
1204
|
-
kind: mode,
|
|
1205
|
-
content: buffer
|
|
1206
|
-
};
|
|
1207
|
-
buffer = "";
|
|
1208
|
-
return [
|
|
1209
|
-
seg
|
|
1210
|
-
];
|
|
1211
|
-
}, "end");
|
|
1212
|
-
return {
|
|
1213
|
-
write,
|
|
1214
|
-
end
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
__name(createThinkTagExtractor, "createThinkTagExtractor");
|
|
1218
|
-
function segmentToEvent(seg) {
|
|
1219
|
-
return seg.kind === "thinking" ? {
|
|
1220
|
-
type: "thinking",
|
|
1221
|
-
content: seg.content
|
|
1222
|
-
} : {
|
|
1223
|
-
type: "text_delta",
|
|
1224
|
-
content: seg.content
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
__name(segmentToEvent, "segmentToEvent");
|
|
1228
|
-
async function* extractThinkTagStream(source) {
|
|
1229
|
-
const extractor = createThinkTagExtractor();
|
|
1230
|
-
try {
|
|
1231
|
-
for await (const event of source) {
|
|
1232
|
-
if (event.type === "text_delta" && typeof event.content === "string") {
|
|
1233
|
-
for (const seg of extractor.write(event.content)) yield segmentToEvent(seg);
|
|
1234
|
-
} else {
|
|
1235
|
-
yield event;
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
} finally {
|
|
1239
|
-
for (const seg of extractor.end()) yield segmentToEvent(seg);
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
__name(extractThinkTagStream, "extractThinkTagStream");
|
|
1243
|
-
|
|
1244
|
-
// src/bridge/definition-or-thunk.ts
|
|
1245
|
-
function project(def, overrides) {
|
|
1246
|
-
const compiled = compileAgentDefinition(def);
|
|
1247
|
-
return {
|
|
1248
|
-
compiled,
|
|
1249
|
-
model: overrides.model ?? compiled.model ?? "openai/gpt-4o-mini",
|
|
1250
|
-
reasoningEffort: overrides.reasoningEffort ?? compiled.reasoningEffort,
|
|
1251
|
-
runContext: overrides.runContext ?? compiled.runContext
|
|
1252
|
-
};
|
|
1253
|
-
}
|
|
1254
|
-
__name(project, "project");
|
|
1255
|
-
function resolveProjection(def, overrides) {
|
|
1256
|
-
if (typeof def === "function") {
|
|
1257
|
-
return async (sessionId) => project(await def(sessionId), overrides);
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
applied.push("memory");
|
|
1336
|
+
}
|
|
1337
|
+
if (compiled.telemetry !== void 0) {
|
|
1338
|
+
options.telemetry = compiled.telemetry;
|
|
1339
|
+
applied.push("telemetry");
|
|
1258
1340
|
}
|
|
1259
|
-
const eager = project(def, overrides);
|
|
1260
|
-
return () => Promise.resolve(eager);
|
|
1261
|
-
}
|
|
1262
|
-
__name(resolveProjection, "resolveProjection");
|
|
1263
|
-
|
|
1264
|
-
// src/bridge/handle-wrappers.ts
|
|
1265
|
-
function withStepCeiling(handle, maxIterations) {
|
|
1266
|
-
if (maxIterations === void 0) return handle;
|
|
1267
1341
|
return {
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
},
|
|
1271
|
-
dispose: /* @__PURE__ */ __name(() => handle.dispose(), "dispose"),
|
|
1272
|
-
...forwardedMembers(handle),
|
|
1273
|
-
send: /* @__PURE__ */ __name((msg, sendOpts) => handle.send(msg, {
|
|
1274
|
-
maxIterations,
|
|
1275
|
-
...sendOpts
|
|
1276
|
-
}), "send")
|
|
1342
|
+
options,
|
|
1343
|
+
applied
|
|
1277
1344
|
};
|
|
1278
1345
|
}
|
|
1279
|
-
__name(
|
|
1280
|
-
function
|
|
1281
|
-
if (
|
|
1282
|
-
return
|
|
1283
|
-
|
|
1284
|
-
return handle.agentId;
|
|
1285
|
-
},
|
|
1286
|
-
dispose: /* @__PURE__ */ __name(() => handle.dispose(), "dispose"),
|
|
1287
|
-
...forwardedMembers(handle),
|
|
1288
|
-
send: /* @__PURE__ */ __name(async (msg, sendOpts) => {
|
|
1289
|
-
const guarded = await runInputGuards(msg, guardrails);
|
|
1290
|
-
return guardTurn(await handle.send(guarded, sendOpts), guardrails);
|
|
1291
|
-
}, "send")
|
|
1292
|
-
};
|
|
1346
|
+
__name(assembleM8CreateOptions, "assembleM8CreateOptions");
|
|
1347
|
+
function stopReasonOf(result) {
|
|
1348
|
+
if (result.stoppedByDoomLoop === true) return "no_progress";
|
|
1349
|
+
if (result.stoppedAtIterationLimit === true) return "step_limit";
|
|
1350
|
+
return void 0;
|
|
1293
1351
|
}
|
|
1294
|
-
__name(
|
|
1295
|
-
function
|
|
1352
|
+
__name(stopReasonOf, "stopReasonOf");
|
|
1353
|
+
function doneUsage(sdkUsage) {
|
|
1354
|
+
const usage = sdkUsage ?? {};
|
|
1355
|
+
const inputTokens = countOrZero(usage.inputTokens);
|
|
1356
|
+
const outputTokens = countOrZero(usage.outputTokens);
|
|
1296
1357
|
return {
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1358
|
+
inputTokens,
|
|
1359
|
+
outputTokens,
|
|
1360
|
+
totalTokens: inputTokens + outputTokens,
|
|
1361
|
+
reasoningTokens: countOrZero(usage.reasoningTokens),
|
|
1362
|
+
cacheReadTokens: countOrZero(usage.cacheReadTokens),
|
|
1363
|
+
cacheWriteTokens: countOrZero(usage.cacheWriteTokens)
|
|
1303
1364
|
};
|
|
1304
1365
|
}
|
|
1305
|
-
__name(
|
|
1306
|
-
function
|
|
1307
|
-
|
|
1308
|
-
const guardedOutcome = /* @__PURE__ */ __name(() => outcome ??= turn.wait().then(async (out) => out.result === void 0 ? out : {
|
|
1309
|
-
...out,
|
|
1310
|
-
result: await runOutputGuards(out.result, guardrails)
|
|
1311
|
-
}), "guardedOutcome");
|
|
1312
|
-
return {
|
|
1313
|
-
wait: guardedOutcome,
|
|
1314
|
-
async *stream() {
|
|
1315
|
-
let out;
|
|
1316
|
-
try {
|
|
1317
|
-
out = await guardedOutcome();
|
|
1318
|
-
} catch (err) {
|
|
1319
|
-
if (!(err instanceof GuardrailViolationError)) throw err;
|
|
1320
|
-
yield errorStatus(err.message);
|
|
1321
|
-
return;
|
|
1322
|
-
}
|
|
1323
|
-
if (out.result !== void 0) {
|
|
1324
|
-
yield {
|
|
1325
|
-
type: "assistant",
|
|
1326
|
-
message: {
|
|
1327
|
-
content: [
|
|
1328
|
-
{
|
|
1329
|
-
type: "text",
|
|
1330
|
-
text: out.result
|
|
1331
|
-
}
|
|
1332
|
-
]
|
|
1333
|
-
}
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
if (out.status === "error") yield errorStatus(out.error?.message ?? "run error");
|
|
1337
|
-
}
|
|
1338
|
-
};
|
|
1366
|
+
__name(doneUsage, "doneUsage");
|
|
1367
|
+
function countOrZero(count) {
|
|
1368
|
+
return count ?? 0;
|
|
1339
1369
|
}
|
|
1340
|
-
__name(
|
|
1341
|
-
function
|
|
1370
|
+
__name(countOrZero, "countOrZero");
|
|
1371
|
+
function realUsageDone(result, t0, model) {
|
|
1372
|
+
const stopReason = stopReasonOf(result);
|
|
1342
1373
|
return {
|
|
1343
|
-
type: "
|
|
1344
|
-
|
|
1345
|
-
|
|
1374
|
+
type: "done",
|
|
1375
|
+
result: result.result ?? "",
|
|
1376
|
+
usage: doneUsage(result.usage),
|
|
1377
|
+
durationMs: Date.now() - t0,
|
|
1378
|
+
...knownCost(result.cost),
|
|
1379
|
+
...terminalExtras(stopReason, model)
|
|
1346
1380
|
};
|
|
1347
1381
|
}
|
|
1348
|
-
__name(
|
|
1382
|
+
__name(realUsageDone, "realUsageDone");
|
|
1383
|
+
function terminalExtras(stopReason, model) {
|
|
1384
|
+
const extras = {};
|
|
1385
|
+
if (stopReason !== void 0) extras.stopReason = stopReason;
|
|
1386
|
+
if (model !== void 0) extras.model = model;
|
|
1387
|
+
return extras;
|
|
1388
|
+
}
|
|
1389
|
+
__name(terminalExtras, "terminalExtras");
|
|
1349
1390
|
|
|
1350
1391
|
// src/bridge/sdk-error.ts
|
|
1351
1392
|
function sdkErrorEvent(err) {
|
|
@@ -1367,105 +1408,6 @@ function sdkErrorEvent(err) {
|
|
|
1367
1408
|
}
|
|
1368
1409
|
__name(sdkErrorEvent, "sdkErrorEvent");
|
|
1369
1410
|
|
|
1370
|
-
// src/bridge/sdk-timeline.ts
|
|
1371
|
-
function idsOf(e, raw) {
|
|
1372
|
-
const ids = [];
|
|
1373
|
-
const callId = typeof e.callId === "string" ? e.callId : "";
|
|
1374
|
-
if (callId !== "") ids.push(callId);
|
|
1375
|
-
const model = raw?.modelCallId;
|
|
1376
|
-
if (typeof model === "string" && model !== "" && model !== callId) ids.push(model);
|
|
1377
|
-
return ids;
|
|
1378
|
-
}
|
|
1379
|
-
__name(idsOf, "idsOf");
|
|
1380
|
-
function bucketFor(e, seen) {
|
|
1381
|
-
if (e.type === "tool_call") return seen.started;
|
|
1382
|
-
if (e.type === "tool_result") return seen.completed;
|
|
1383
|
-
return void 0;
|
|
1384
|
-
}
|
|
1385
|
-
__name(bucketFor, "bucketFor");
|
|
1386
|
-
function isToolLifecycleEvent(e) {
|
|
1387
|
-
return e.type === "tool_call" || e.type === "tool_result" || e.type === "partial_tool_call";
|
|
1388
|
-
}
|
|
1389
|
-
__name(isToolLifecycleEvent, "isToolLifecycleEvent");
|
|
1390
|
-
function mergeIntoPending(e, ids, seen) {
|
|
1391
|
-
if (e.type !== "tool_result" || !e.isError) return;
|
|
1392
|
-
const held = seen.pending.find((p) => p.ids.some((id) => ids.includes(id)));
|
|
1393
|
-
if (held?.event.type !== "tool_result") return;
|
|
1394
|
-
held.event = {
|
|
1395
|
-
...held.event,
|
|
1396
|
-
isError: true
|
|
1397
|
-
};
|
|
1398
|
-
}
|
|
1399
|
-
__name(mergeIntoPending, "mergeIntoPending");
|
|
1400
|
-
function dedupeTools(events, raw, seen) {
|
|
1401
|
-
return events.filter((e) => {
|
|
1402
|
-
if (e.type === "thinking") {
|
|
1403
|
-
if (seen.sawThinkingDelta) return false;
|
|
1404
|
-
seen.sawThinkingDelta = true;
|
|
1405
|
-
return true;
|
|
1406
|
-
}
|
|
1407
|
-
const bucket = bucketFor(e, seen);
|
|
1408
|
-
if (bucket === void 0) return true;
|
|
1409
|
-
const ids = idsOf(e, raw);
|
|
1410
|
-
if (ids.length === 0) return true;
|
|
1411
|
-
if (ids.some((id) => bucket.has(id))) {
|
|
1412
|
-
mergeIntoPending(e, ids, seen);
|
|
1413
|
-
return false;
|
|
1414
|
-
}
|
|
1415
|
-
for (const id of ids) bucket.add(id);
|
|
1416
|
-
if (e.type === "tool_result") {
|
|
1417
|
-
seen.pending.push({
|
|
1418
|
-
ids,
|
|
1419
|
-
event: e
|
|
1420
|
-
});
|
|
1421
|
-
return false;
|
|
1422
|
-
}
|
|
1423
|
-
return true;
|
|
1424
|
-
});
|
|
1425
|
-
}
|
|
1426
|
-
__name(dedupeTools, "dedupeTools");
|
|
1427
|
-
function releasePendingToolResults(translated, seen) {
|
|
1428
|
-
if (seen.pending.length === 0) return [];
|
|
1429
|
-
if (translated.length === 0 || translated.every(isToolLifecycleEvent)) return [];
|
|
1430
|
-
return flushPendingToolResults(seen);
|
|
1431
|
-
}
|
|
1432
|
-
__name(releasePendingToolResults, "releasePendingToolResults");
|
|
1433
|
-
function flushPendingToolResults(seen) {
|
|
1434
|
-
const out = seen.pending.map((p) => p.event);
|
|
1435
|
-
seen.pending = [];
|
|
1436
|
-
return out;
|
|
1437
|
-
}
|
|
1438
|
-
__name(flushPendingToolResults, "flushPendingToolResults");
|
|
1439
|
-
function createToolSeen() {
|
|
1440
|
-
return {
|
|
1441
|
-
started: /* @__PURE__ */ new Set(),
|
|
1442
|
-
completed: /* @__PURE__ */ new Set(),
|
|
1443
|
-
pending: [],
|
|
1444
|
-
sawThinkingDelta: false
|
|
1445
|
-
};
|
|
1446
|
-
}
|
|
1447
|
-
__name(createToolSeen, "createToolSeen");
|
|
1448
|
-
function translateTimelineEvent(ev, runId, seen) {
|
|
1449
|
-
if (ev.kind === "delta") {
|
|
1450
|
-
if (ev.update === void 0) return [];
|
|
1451
|
-
const events2 = translateInteractionUpdate(ev.update);
|
|
1452
|
-
const released2 = releasePendingToolResults(events2, seen);
|
|
1453
|
-
return [
|
|
1454
|
-
...released2,
|
|
1455
|
-
...dedupeTools(events2, ev.update, seen)
|
|
1456
|
-
];
|
|
1457
|
-
}
|
|
1458
|
-
if (ev.message === void 0) return [];
|
|
1459
|
-
const events = translateSdkEvent(ev.message, runId);
|
|
1460
|
-
const kept = ev.textAlreadyStreamed === true ? events.filter((e) => e.type !== "text_delta") : events;
|
|
1461
|
-
const released = releasePendingToolResults(kept, seen);
|
|
1462
|
-
return [
|
|
1463
|
-
...released,
|
|
1464
|
-
...dedupeTools(kept, ev.message, seen)
|
|
1465
|
-
];
|
|
1466
|
-
}
|
|
1467
|
-
__name(translateTimelineEvent, "translateTimelineEvent");
|
|
1468
|
-
|
|
1469
1411
|
// src/bridge/tool-context-injection.ts
|
|
1470
1412
|
function withInjectedToolContext(handler, injection) {
|
|
1471
1413
|
return (input, ctx) => handler(input, {
|
|
@@ -1645,25 +1587,30 @@ function withLeakedDialectRecovery(providers) {
|
|
|
1645
1587
|
}
|
|
1646
1588
|
__name(withLeakedDialectRecovery, "withLeakedDialectRecovery");
|
|
1647
1589
|
function buildExtraCreateOptions(overrides, compiled) {
|
|
1648
|
-
const recoverLeakedToolCalls = overrides.recoverLeakedToolCalls ?? compiled.recoverLeakedToolCalls ?? false;
|
|
1649
1590
|
const extra = {};
|
|
1650
|
-
if (overrides.plugins !== void 0)
|
|
1651
|
-
const asArray = /* @__PURE__ */ __name((v) => Array.isArray(v) ? v : void 0, "asArray");
|
|
1652
|
-
const overrideList = asArray(overrides.plugins);
|
|
1653
|
-
const compiledList = asArray(compiled.plugins);
|
|
1654
|
-
extra.plugins = overrideList !== void 0 && compiledList !== void 0 ? [
|
|
1655
|
-
...compiledList,
|
|
1656
|
-
...overrideList
|
|
1657
|
-
] : overrides.plugins;
|
|
1658
|
-
}
|
|
1591
|
+
if (overrides.plugins !== void 0) extra.plugins = mergePlugins(overrides.plugins, compiled.plugins);
|
|
1659
1592
|
if (overrides.providers !== void 0) {
|
|
1660
|
-
extra.providers =
|
|
1593
|
+
extra.providers = leakedRecoveryEnabled(overrides, compiled) ? withLeakedDialectRecovery(overrides.providers) : overrides.providers;
|
|
1661
1594
|
}
|
|
1662
1595
|
if (overrides.agents !== void 0) extra.agents = overrides.agents;
|
|
1663
1596
|
if (overrides.budgetTracker !== void 0) extra.budgetTracker = overrides.budgetTracker;
|
|
1664
1597
|
return extra;
|
|
1665
1598
|
}
|
|
1666
1599
|
__name(buildExtraCreateOptions, "buildExtraCreateOptions");
|
|
1600
|
+
function leakedRecoveryEnabled(overrides, compiled) {
|
|
1601
|
+
return overrides.recoverLeakedToolCalls ?? compiled.recoverLeakedToolCalls ?? false;
|
|
1602
|
+
}
|
|
1603
|
+
__name(leakedRecoveryEnabled, "leakedRecoveryEnabled");
|
|
1604
|
+
function mergePlugins(override, compiledPlugins) {
|
|
1605
|
+
const asArray = /* @__PURE__ */ __name((v) => Array.isArray(v) ? v : void 0, "asArray");
|
|
1606
|
+
const overrideList = asArray(override);
|
|
1607
|
+
const compiledList = asArray(compiledPlugins);
|
|
1608
|
+
return overrideList !== void 0 && compiledList !== void 0 ? [
|
|
1609
|
+
...compiledList,
|
|
1610
|
+
...overrideList
|
|
1611
|
+
] : override;
|
|
1612
|
+
}
|
|
1613
|
+
__name(mergePlugins, "mergePlugins");
|
|
1667
1614
|
function applyStepCeiling(sendOptions, maxIterations) {
|
|
1668
1615
|
if (maxIterations !== void 0) sendOptions.maxIterations = maxIterations;
|
|
1669
1616
|
}
|
|
@@ -1739,6 +1686,27 @@ function buildSdkTools(compiledTools, defineTool, extraSdkTools = [], runContext
|
|
|
1739
1686
|
];
|
|
1740
1687
|
}
|
|
1741
1688
|
__name(buildSdkTools, "buildSdkTools");
|
|
1689
|
+
function createTurnUsageMeter(overrides, model) {
|
|
1690
|
+
if (overrides.exposeUsageToTools !== true) return void 0;
|
|
1691
|
+
return createRunUsageMeter({
|
|
1692
|
+
contextWindowTokens: contextWindowOf(model),
|
|
1693
|
+
delegate: overrides.budgetTracker
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
__name(createTurnUsageMeter, "createTurnUsageMeter");
|
|
1697
|
+
function wireInlineSkillRead(sdkTools, rt, compiled, compiledTools) {
|
|
1698
|
+
const inlineSkills = compiled.skills?.inline;
|
|
1699
|
+
if (inlineSkills !== void 0 && inlineSkills.length > 0 && rt.defineSkillReadTool !== void 0 && !compiledTools.some((t) => t.name === "skill_read")) {
|
|
1700
|
+
sdkTools.push(rt.defineSkillReadTool(inlineSkills));
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
__name(wireInlineSkillRead, "wireInlineSkillRead");
|
|
1704
|
+
function runContextSource(overrides, compiled) {
|
|
1705
|
+
if (overrides.runContext !== void 0) return "per-run";
|
|
1706
|
+
if (compiled.runContext !== void 0) return "agent-level";
|
|
1707
|
+
return "none";
|
|
1708
|
+
}
|
|
1709
|
+
__name(runContextSource, "runContextSource");
|
|
1742
1710
|
var resolverApiKey = /* @__PURE__ */ __name(async (k) => typeof k === "function" ? await k() : k, "resolverApiKey");
|
|
1743
1711
|
function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
|
|
1744
1712
|
const model = overrides.model ?? compiled.model ?? "openai/gpt-4o-mini";
|
|
@@ -1759,25 +1727,11 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
|
|
|
1759
1727
|
};
|
|
1760
1728
|
return;
|
|
1761
1729
|
}
|
|
1762
|
-
const usageMeter = overrides
|
|
1763
|
-
contextWindowTokens: contextWindowOf(model),
|
|
1764
|
-
delegate: overrides.budgetTracker
|
|
1765
|
-
}) : void 0;
|
|
1730
|
+
const usageMeter = createTurnUsageMeter(overrides, model);
|
|
1766
1731
|
const sdkTools = buildSdkTools(compiledTools, rt.defineTool, overrides.sdkTools, runContext, usageMeter);
|
|
1767
|
-
|
|
1768
|
-
if (inlineSkills !== void 0 && inlineSkills.length > 0 && rt.defineSkillReadTool !== void 0 && !compiledTools.some((t) => t.name === "skill_read")) {
|
|
1769
|
-
sdkTools.push(rt.defineSkillReadTool(inlineSkills));
|
|
1770
|
-
}
|
|
1771
|
-
let runContextSource;
|
|
1772
|
-
if (overrides.runContext !== void 0) {
|
|
1773
|
-
runContextSource = "per-run";
|
|
1774
|
-
} else if (compiled.runContext !== void 0) {
|
|
1775
|
-
runContextSource = "agent-level";
|
|
1776
|
-
} else {
|
|
1777
|
-
runContextSource = "none";
|
|
1778
|
-
}
|
|
1732
|
+
wireInlineSkillRead(sdkTools, rt, compiled, compiledTools);
|
|
1779
1733
|
debugLog("[THEO_AGENT_M7_RUN_CONTEXT]", {
|
|
1780
|
-
source: runContextSource,
|
|
1734
|
+
source: runContextSource(overrides, compiled),
|
|
1781
1735
|
keys: runContext !== void 0 ? Object.keys(runContext) : []
|
|
1782
1736
|
});
|
|
1783
1737
|
const turnOpts = {
|
|
@@ -1811,10 +1765,7 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
|
|
|
1811
1765
|
});
|
|
1812
1766
|
}
|
|
1813
1767
|
__name(createSdkAgentStream, "createSdkAgentStream");
|
|
1814
|
-
|
|
1815
|
-
const { Agent } = rt;
|
|
1816
|
-
const { apiKey, model, reasoningEffort, overrides, parseThinkTags, stripToolDialect, sessionId, message, factoryOpts, runId, t0 } = opts;
|
|
1817
|
-
const { options: m8, applied } = assembleM8CreateOptions(compiled);
|
|
1768
|
+
function applyLocalOverrides(m8, overrides) {
|
|
1818
1769
|
if (overrides.cwd !== void 0) m8.local = {
|
|
1819
1770
|
...m8.local,
|
|
1820
1771
|
cwd: overrides.cwd
|
|
@@ -1823,8 +1774,13 @@ async function* streamSdkAgent(rt, compiled, sdkTools, opts) {
|
|
|
1823
1774
|
...m8.local,
|
|
1824
1775
|
baseDir: overrides.baseDir
|
|
1825
1776
|
};
|
|
1777
|
+
}
|
|
1778
|
+
__name(applyLocalOverrides, "applyLocalOverrides");
|
|
1779
|
+
function resolveCreateOptions(compiled, overrides, usageMeter) {
|
|
1780
|
+
const { options: m8, applied } = assembleM8CreateOptions(compiled);
|
|
1781
|
+
applyLocalOverrides(m8, overrides);
|
|
1826
1782
|
const extra = buildExtraCreateOptions(overrides, compiled);
|
|
1827
|
-
if (
|
|
1783
|
+
if (usageMeter !== void 0) extra.budgetTracker = usageMeter.tracker;
|
|
1828
1784
|
if (applied.length > 0) {
|
|
1829
1785
|
debugLog("[THEO_AGENT_M8_RUNTIME_APPLIED]", {
|
|
1830
1786
|
skills: applied.includes("skills"),
|
|
@@ -1832,6 +1788,53 @@ async function* streamSdkAgent(rt, compiled, sdkTools, opts) {
|
|
|
1832
1788
|
projectContext: applied.includes("projectContext")
|
|
1833
1789
|
});
|
|
1834
1790
|
}
|
|
1791
|
+
return {
|
|
1792
|
+
m8,
|
|
1793
|
+
extra
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
__name(resolveCreateOptions, "resolveCreateOptions");
|
|
1797
|
+
function buildSendOptions(overrides, factoryOpts, compiled) {
|
|
1798
|
+
const sendOptions = {};
|
|
1799
|
+
if (factoryOpts?.disableTools === true) sendOptions.toolChoice = "none";
|
|
1800
|
+
applyStepCeiling(sendOptions, compiled.maxIterations);
|
|
1801
|
+
if (overrides.onRunEvent !== void 0) sendOptions.onRunEvent = overrides.onRunEvent;
|
|
1802
|
+
return sendOptions;
|
|
1803
|
+
}
|
|
1804
|
+
__name(buildSendOptions, "buildSendOptions");
|
|
1805
|
+
function buildSendInput(message, overrides) {
|
|
1806
|
+
const sendInput = overrides.images && overrides.images.length > 0 ? {
|
|
1807
|
+
text: message,
|
|
1808
|
+
images: overrides.images
|
|
1809
|
+
} : message;
|
|
1810
|
+
return sendInput;
|
|
1811
|
+
}
|
|
1812
|
+
__name(buildSendInput, "buildSendInput");
|
|
1813
|
+
async function* streamTimeline(sendPromise, runId, state, outcome) {
|
|
1814
|
+
const run = await sendPromise;
|
|
1815
|
+
const seen = createToolSeen();
|
|
1816
|
+
const emit = /* @__PURE__ */ __name(function* (events) {
|
|
1817
|
+
for (const event of events) {
|
|
1818
|
+
if (event.type === "error") state.sawError = true;
|
|
1819
|
+
if (event.type === "done") continue;
|
|
1820
|
+
state.lastEventType = event.type;
|
|
1821
|
+
yield event;
|
|
1822
|
+
}
|
|
1823
|
+
}, "emit");
|
|
1824
|
+
for await (const ev of run.events()) {
|
|
1825
|
+
const translated = translateTimelineEvent(ev, runId, seen);
|
|
1826
|
+
if (outcome !== void 0 && state.lastEventType === "" && translated.some((e) => e.type === "error")) {
|
|
1827
|
+
outcome.failure = (await (await sendPromise).wait()).error?.cause;
|
|
1828
|
+
}
|
|
1829
|
+
yield* emit(translated);
|
|
1830
|
+
}
|
|
1831
|
+
yield* emit(flushPendingToolResults(seen));
|
|
1832
|
+
}
|
|
1833
|
+
__name(streamTimeline, "streamTimeline");
|
|
1834
|
+
async function* streamSdkAgent(rt, compiled, sdkTools, opts) {
|
|
1835
|
+
const { Agent } = rt;
|
|
1836
|
+
const { apiKey, model, reasoningEffort, overrides, parseThinkTags, stripToolDialect, sessionId, message, factoryOpts, runId, t0 } = opts;
|
|
1837
|
+
const { m8, extra } = resolveCreateOptions(compiled, overrides, opts.usageMeter);
|
|
1835
1838
|
const agent = await Agent.getOrCreate(sessionId, {
|
|
1836
1839
|
apiKey,
|
|
1837
1840
|
model: buildModelSelection(model, reasoningEffort),
|
|
@@ -1844,35 +1847,9 @@ async function* streamSdkAgent(rt, compiled, sdkTools, opts) {
|
|
|
1844
1847
|
sawError: false,
|
|
1845
1848
|
lastEventType: ""
|
|
1846
1849
|
};
|
|
1847
|
-
const sendOptions =
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
if (overrides.onRunEvent !== void 0) sendOptions.onRunEvent = overrides.onRunEvent;
|
|
1851
|
-
const sendInput = overrides.images && overrides.images.length > 0 ? {
|
|
1852
|
-
text: message,
|
|
1853
|
-
images: overrides.images
|
|
1854
|
-
} : message;
|
|
1855
|
-
const sendPromise = agent.send(sendInput, sendOptions);
|
|
1856
|
-
const timeline = /* @__PURE__ */ __name(async function* () {
|
|
1857
|
-
const run = await sendPromise;
|
|
1858
|
-
const seen = createToolSeen();
|
|
1859
|
-
const emit = /* @__PURE__ */ __name(function* (events) {
|
|
1860
|
-
for (const event of events) {
|
|
1861
|
-
if (event.type === "error") state.sawError = true;
|
|
1862
|
-
if (event.type === "done") continue;
|
|
1863
|
-
state.lastEventType = event.type;
|
|
1864
|
-
yield event;
|
|
1865
|
-
}
|
|
1866
|
-
}, "emit");
|
|
1867
|
-
for await (const ev of run.events()) {
|
|
1868
|
-
const translated = translateTimelineEvent(ev, runId, seen);
|
|
1869
|
-
if (opts.outcome !== void 0 && state.lastEventType === "" && translated.some((e) => e.type === "error")) {
|
|
1870
|
-
opts.outcome.failure = (await (await sendPromise).wait()).error?.cause;
|
|
1871
|
-
}
|
|
1872
|
-
yield* emit(translated);
|
|
1873
|
-
}
|
|
1874
|
-
yield* emit(flushPendingToolResults(seen));
|
|
1875
|
-
}, "timeline");
|
|
1850
|
+
const sendOptions = buildSendOptions(overrides, factoryOpts, compiled);
|
|
1851
|
+
const sendPromise = agent.send(buildSendInput(message, overrides), sendOptions);
|
|
1852
|
+
const timeline = /* @__PURE__ */ __name(() => streamTimeline(sendPromise, runId, state, opts.outcome), "timeline");
|
|
1876
1853
|
for await (const event of applyTextTransforms(timeline(), {
|
|
1877
1854
|
parseThinkTags,
|
|
1878
1855
|
stripToolDialect
|
|
@@ -1906,19 +1883,9 @@ function toAgentFactory(def, opts) {
|
|
|
1906
1883
|
throw new Error("[@theokit/agents] @theokit/sdk is not installed \u2014 run: pnpm add @theokit/sdk");
|
|
1907
1884
|
}
|
|
1908
1885
|
const sdkTools = buildSdkTools(compiled.tools, rt.defineTool, overrides.sdkTools, runContext);
|
|
1909
|
-
|
|
1910
|
-
if (inlineSkills !== void 0 && inlineSkills.length > 0 && rt.defineSkillReadTool !== void 0 && !compiled.tools.some((t) => t.name === "skill_read")) {
|
|
1911
|
-
sdkTools.push(rt.defineSkillReadTool(inlineSkills));
|
|
1912
|
-
}
|
|
1886
|
+
wireInlineSkillRead(sdkTools, rt, compiled, compiled.tools);
|
|
1913
1887
|
const { options: m8 } = assembleM8CreateOptions(compiled);
|
|
1914
|
-
|
|
1915
|
-
...m8.local,
|
|
1916
|
-
cwd: overrides.cwd
|
|
1917
|
-
};
|
|
1918
|
-
if (overrides.baseDir !== void 0) m8.local = {
|
|
1919
|
-
...m8.local,
|
|
1920
|
-
baseDir: overrides.baseDir
|
|
1921
|
-
};
|
|
1888
|
+
applyLocalOverrides(m8, overrides);
|
|
1922
1889
|
const extra = buildExtraCreateOptions(overrides, compiled);
|
|
1923
1890
|
applyPosture(extra, m8, opts.approvals, compiled.hitl);
|
|
1924
1891
|
const agent = await rt.Agent.getOrCreate(sessionId, {
|
|
@@ -1926,7 +1893,12 @@ function toAgentFactory(def, opts) {
|
|
|
1926
1893
|
model: buildModelSelection(model, reasoningEffort),
|
|
1927
1894
|
tools: sdkTools,
|
|
1928
1895
|
...m8,
|
|
1929
|
-
...extra
|
|
1896
|
+
...extra,
|
|
1897
|
+
...opts.withholdBuiltinShell === true ? {
|
|
1898
|
+
withheldBuiltinTools: [
|
|
1899
|
+
"shell"
|
|
1900
|
+
]
|
|
1901
|
+
} : {}
|
|
1930
1902
|
});
|
|
1931
1903
|
return withGuardrails(withStepCeiling(agent, compiled.maxIterations), compiled.guardrails);
|
|
1932
1904
|
};
|
|
@@ -1960,11 +1932,13 @@ export {
|
|
|
1960
1932
|
buildModelSelection,
|
|
1961
1933
|
reasoningEffortOf,
|
|
1962
1934
|
translateSdkEvent,
|
|
1963
|
-
|
|
1964
|
-
|
|
1935
|
+
translateInteractionUpdate,
|
|
1936
|
+
flushPendingToolResults,
|
|
1937
|
+
createToolSeen,
|
|
1938
|
+
translateTimelineEvent,
|
|
1965
1939
|
createThinkTagExtractor,
|
|
1966
1940
|
extractThinkTagStream,
|
|
1967
1941
|
createSdkAgentStream,
|
|
1968
1942
|
toAgentFactory
|
|
1969
1943
|
};
|
|
1970
|
-
//# sourceMappingURL=chunk-
|
|
1944
|
+
//# sourceMappingURL=chunk-AZ2FOUSN.js.map
|