@theokit/sdk 3.2.0 → 3.2.3
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 +35 -0
- package/dist/a2a/index.cjs +85 -25
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +85 -25
- package/dist/a2a/index.js.map +1 -1
- package/dist/cron.cjs +85 -25
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.js +85 -25
- package/dist/cron.js.map +1 -1
- package/dist/eval.cjs +85 -40
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +85 -40
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +94 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +94 -26
- package/dist/index.js.map +1 -1
- package/dist/internal/persistence/pagination.d.cts +14 -1
- package/dist/internal/persistence/pagination.d.ts +14 -1
- package/dist/sandbox/index.cjs +8 -9
- package/dist/sandbox/index.cjs.map +1 -1
- package/dist/sandbox/index.js +8 -9
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/types.d.cts +0 -1
- package/dist/sandbox/types.d.ts +0 -1
- package/package.json +2 -2
package/dist/cron.js
CHANGED
|
@@ -4744,7 +4744,14 @@ var init_env_policy = __esm({
|
|
|
4744
4744
|
/[_-]PWD/i,
|
|
4745
4745
|
/CREDENTIAL/i,
|
|
4746
4746
|
/PRIVATE/i,
|
|
4747
|
-
/_AUTH/i
|
|
4747
|
+
/_AUTH/i,
|
|
4748
|
+
// #54-a — value-embedded-secret conventions (no generic `*_URL` — see keep-list test).
|
|
4749
|
+
/DSN/i,
|
|
4750
|
+
/WEBHOOK/i,
|
|
4751
|
+
/COOKIE/i,
|
|
4752
|
+
/CONNECTION[_-]?STRING/i,
|
|
4753
|
+
// Known DB / message-broker connection-string vars (carry `user:pass@`).
|
|
4754
|
+
/(?:^|[_-])(?:DATABASE|DB|REDIS|MONGO(?:DB)?|POSTGRES(?:QL)?|MYSQL|MARIADB|AMQP|RABBITMQ|CLICKHOUSE|ELASTIC(?:SEARCH)?|CASSANDRA|COUCHDB|MEMCACHED|NATS|KAFKA)[_-]?(?:URL|URI|DSN|CONNECTION)/i
|
|
4748
4755
|
];
|
|
4749
4756
|
CORE_VARS = [
|
|
4750
4757
|
"PATH",
|
|
@@ -5153,12 +5160,23 @@ var init_objective_coerce = __esm({
|
|
|
5153
5160
|
// src/internal/persistence/pagination.ts
|
|
5154
5161
|
function paginate(items, opts) {
|
|
5155
5162
|
if (opts === void 0 || opts.offset === void 0 && opts.limit === void 0) return items;
|
|
5156
|
-
const start =
|
|
5157
|
-
const
|
|
5163
|
+
const start = opts.offset === void 0 ? 0 : requireNonNegativeInt(opts.offset, "offset");
|
|
5164
|
+
const limit = opts.limit === void 0 ? void 0 : requireNonNegativeInt(opts.limit, "limit");
|
|
5165
|
+
const end = limit === void 0 ? items.length : start + limit;
|
|
5158
5166
|
return items.slice(start, end);
|
|
5159
5167
|
}
|
|
5168
|
+
function requireNonNegativeInt(value, field) {
|
|
5169
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
5170
|
+
throw new ConfigurationError(
|
|
5171
|
+
`Invalid pagination ${field}: expected a non-negative integer, got ${value}`,
|
|
5172
|
+
{ code: "pagination_invalid" }
|
|
5173
|
+
);
|
|
5174
|
+
}
|
|
5175
|
+
return value;
|
|
5176
|
+
}
|
|
5160
5177
|
var init_pagination = __esm({
|
|
5161
5178
|
"src/internal/persistence/pagination.ts"() {
|
|
5179
|
+
init_errors();
|
|
5162
5180
|
}
|
|
5163
5181
|
});
|
|
5164
5182
|
|
|
@@ -7741,15 +7759,19 @@ async function collectChildToolResults(run) {
|
|
|
7741
7759
|
${lines.join("\n")}
|
|
7742
7760
|
</subagent-tool-results>`;
|
|
7743
7761
|
}
|
|
7744
|
-
|
|
7745
|
-
const { Agent: Agent2 } = await Promise.resolve().then(() => (init_agent(), agent_exports));
|
|
7762
|
+
function buildChildCreateOptions(spec, inherited) {
|
|
7746
7763
|
const model = spec.model ? { id: spec.model } : inherited?.model;
|
|
7747
|
-
|
|
7764
|
+
return {
|
|
7748
7765
|
...inherited?.apiKey !== void 0 ? { apiKey: inherited.apiKey } : {},
|
|
7749
7766
|
...model !== void 0 ? { model } : {},
|
|
7767
|
+
...inherited?.plugins !== void 0 ? { plugins: inherited.plugins } : {},
|
|
7750
7768
|
systemPrompt: spec.instructions,
|
|
7751
7769
|
tools: spec.tools ?? []
|
|
7752
|
-
}
|
|
7770
|
+
};
|
|
7771
|
+
}
|
|
7772
|
+
async function runChildAgent(spec, input, signal, maxSteps, inherited) {
|
|
7773
|
+
const { Agent: Agent2 } = await Promise.resolve().then(() => (init_agent(), agent_exports));
|
|
7774
|
+
const agent = await Agent2.create(buildChildCreateOptions(spec, inherited));
|
|
7753
7775
|
try {
|
|
7754
7776
|
const sendOptions = {
|
|
7755
7777
|
...signal !== void 0 ? { signal } : {},
|
|
@@ -9652,7 +9674,10 @@ async function runAgentLoop(inputs) {
|
|
|
9652
9674
|
}
|
|
9653
9675
|
budget.consume();
|
|
9654
9676
|
inputs.budgetTracker?.nextIteration?.();
|
|
9655
|
-
if (inputs.signal?.aborted === true)
|
|
9677
|
+
if (inputs.signal?.aborted === true) {
|
|
9678
|
+
ctx.finalStatus = "cancelled";
|
|
9679
|
+
break;
|
|
9680
|
+
}
|
|
9656
9681
|
}
|
|
9657
9682
|
if (lastTurnDecision === "continue" && budget.shouldContinue() === false) {
|
|
9658
9683
|
ctx.stoppedAtIterationLimit = true;
|
|
@@ -9837,15 +9862,15 @@ async function guardAndTransformToolResults(inputs, raw, ctx) {
|
|
|
9837
9862
|
}
|
|
9838
9863
|
async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
9839
9864
|
if (llmOutput.errored) return "error";
|
|
9840
|
-
|
|
9841
|
-
|
|
9865
|
+
const tCtx = { agentId: inputs.agentId, runId: inputs.runId };
|
|
9866
|
+
const text = llmOutput.text.length > 0 ? await transformLlmOutputText(inputs, llmOutput.text, tCtx) : llmOutput.text;
|
|
9867
|
+
if (text.length > 0) {
|
|
9868
|
+
await emitAssistantTextStep(inputs, ctx, text);
|
|
9842
9869
|
}
|
|
9843
9870
|
if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
|
|
9844
9871
|
return finishOrReflect(inputs, ctx, llmOutput);
|
|
9845
9872
|
}
|
|
9846
|
-
|
|
9847
|
-
const outText = await transformLlmOutputText(inputs, llmOutput.text, tCtx);
|
|
9848
|
-
ctx.messages.push(buildAssistantTurn(outText, llmOutput.toolCalls));
|
|
9873
|
+
ctx.messages.push(buildAssistantTurn(text, llmOutput.toolCalls));
|
|
9849
9874
|
const rawResults = await dispatchTools(
|
|
9850
9875
|
// SE12 — forward a read-only text projection of the transcript-so-far to tool
|
|
9851
9876
|
// handlers via `ctx.messages` (consumed by defineSubAgent's messageFilter).
|
|
@@ -10309,6 +10334,8 @@ function parseRetryAfter(headers) {
|
|
|
10309
10334
|
if (raw === null) return void 0;
|
|
10310
10335
|
const n = Number(raw);
|
|
10311
10336
|
if (Number.isFinite(n) && n >= 0) return Math.ceil(n);
|
|
10337
|
+
const dateMs = Date.parse(raw);
|
|
10338
|
+
if (Number.isFinite(dateMs)) return Math.max(0, Math.ceil((dateMs - Date.now()) / 1e3));
|
|
10312
10339
|
return void 0;
|
|
10313
10340
|
}
|
|
10314
10341
|
function truncateRaw(body) {
|
|
@@ -10629,6 +10656,7 @@ function buildAnthropicBody(request) {
|
|
|
10629
10656
|
var AnthropicClient, AnthropicStreamAccumulator;
|
|
10630
10657
|
var init_anthropic3 = __esm({
|
|
10631
10658
|
"src/internal/llm/anthropic.ts"() {
|
|
10659
|
+
init_errors();
|
|
10632
10660
|
init_anthropic2();
|
|
10633
10661
|
init_anthropic_shared();
|
|
10634
10662
|
init_finish();
|
|
@@ -10682,12 +10710,23 @@ var init_anthropic3 = __esm({
|
|
|
10682
10710
|
const events = accumulator.consume(parsed);
|
|
10683
10711
|
for (const event of events) yield event;
|
|
10684
10712
|
}
|
|
10713
|
+
if (!accumulator.finishReasonSeen) {
|
|
10714
|
+
throw new NetworkError("Anthropic SSE stream truncated (no stop_reason)", {
|
|
10715
|
+
code: "stream_truncated"
|
|
10716
|
+
});
|
|
10717
|
+
}
|
|
10685
10718
|
return accumulator.finish();
|
|
10686
10719
|
}
|
|
10687
10720
|
};
|
|
10688
10721
|
AnthropicStreamAccumulator = class {
|
|
10689
10722
|
text = "";
|
|
10690
10723
|
stopReason = "end_turn";
|
|
10724
|
+
/**
|
|
10725
|
+
* M2 #61 — whether a `message_delta` carrying a real `stop_reason` was seen.
|
|
10726
|
+
* A stream that closes before it is a truncation (server FIN / proxy hiccup),
|
|
10727
|
+
* not a clean `end_turn` — the caller throws `stream_truncated` on `false`.
|
|
10728
|
+
*/
|
|
10729
|
+
sawStopReason = false;
|
|
10691
10730
|
inputTokens;
|
|
10692
10731
|
outputTokens;
|
|
10693
10732
|
cacheReadTokens;
|
|
@@ -10734,6 +10773,9 @@ var init_anthropic3 = __esm({
|
|
|
10734
10773
|
* spinning the SSE parser.
|
|
10735
10774
|
*/
|
|
10736
10775
|
handleMessageDelta(md) {
|
|
10776
|
+
if (md.delta.stop_reason !== void 0 && md.delta.stop_reason !== null) {
|
|
10777
|
+
this.sawStopReason = true;
|
|
10778
|
+
}
|
|
10737
10779
|
this.stopReason = mapAnthropicStopReason(md.delta.stop_reason);
|
|
10738
10780
|
if (md.usage?.input_tokens !== void 0) this.inputTokens = md.usage.input_tokens;
|
|
10739
10781
|
if (md.usage?.output_tokens !== void 0) this.outputTokens = md.usage.output_tokens;
|
|
@@ -10744,6 +10786,10 @@ var init_anthropic3 = __esm({
|
|
|
10744
10786
|
this.cacheReadTokens = md.usage.cache_read_input_tokens;
|
|
10745
10787
|
}
|
|
10746
10788
|
}
|
|
10789
|
+
/** M2 #61 — whether the terminal `message_delta` (stop_reason) was seen. */
|
|
10790
|
+
get finishReasonSeen() {
|
|
10791
|
+
return this.sawStopReason;
|
|
10792
|
+
}
|
|
10747
10793
|
finish() {
|
|
10748
10794
|
const toolCalls = [];
|
|
10749
10795
|
for (const [index, tool] of this.toolCalls.entries()) {
|
|
@@ -12977,7 +13023,6 @@ var init_client = __esm({
|
|
|
12977
13023
|
// concurrent request so parallel tool dispatch after a drop awaits one handshake
|
|
12978
13024
|
// instead of racing (or spuriously failing with mcp_not_init).
|
|
12979
13025
|
dropped = false;
|
|
12980
|
-
reconnectAttempts = 0;
|
|
12981
13026
|
reconnectPromise;
|
|
12982
13027
|
get timeoutMs() {
|
|
12983
13028
|
return this.config.requestTimeoutMs ?? DEFAULT_MCP_TIMEOUT_MS;
|
|
@@ -13030,15 +13075,22 @@ var init_client = __esm({
|
|
|
13030
13075
|
return this.reconnectPromise;
|
|
13031
13076
|
}
|
|
13032
13077
|
async reconnect() {
|
|
13033
|
-
|
|
13034
|
-
|
|
13078
|
+
let lastErr;
|
|
13079
|
+
for (let attempt = 0; attempt < MAX_RECONNECT_ATTEMPTS; attempt += 1) {
|
|
13080
|
+
await reconnectDelay(attempt);
|
|
13081
|
+
this.spawnChild();
|
|
13082
|
+
try {
|
|
13083
|
+
await super.initialize();
|
|
13084
|
+
this.dropped = false;
|
|
13085
|
+
return;
|
|
13086
|
+
} catch (err) {
|
|
13087
|
+
lastErr = err;
|
|
13088
|
+
}
|
|
13035
13089
|
}
|
|
13036
|
-
|
|
13037
|
-
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
this.dropped = false;
|
|
13041
|
-
this.reconnectAttempts = 0;
|
|
13090
|
+
throw new NetworkError(`MCP ${this.name} reconnect exhausted`, {
|
|
13091
|
+
code: "mcp_disconnected",
|
|
13092
|
+
...lastErr instanceof Error ? { cause: lastErr } : {}
|
|
13093
|
+
});
|
|
13042
13094
|
}
|
|
13043
13095
|
async close() {
|
|
13044
13096
|
this.rejectAllPending(new NetworkError(`MCP ${this.name} closed`, { code: "mcp_closed" }));
|
|
@@ -13169,7 +13221,12 @@ var init_client = __esm({
|
|
|
13169
13221
|
code: "mcp_http_error"
|
|
13170
13222
|
});
|
|
13171
13223
|
}
|
|
13172
|
-
|
|
13224
|
+
try {
|
|
13225
|
+
return await response.json();
|
|
13226
|
+
} catch (cause) {
|
|
13227
|
+
if (isAbortLike(cause)) throw mcpTimeoutError(this.name, timeoutMs);
|
|
13228
|
+
throw cause;
|
|
13229
|
+
}
|
|
13173
13230
|
}
|
|
13174
13231
|
};
|
|
13175
13232
|
}
|
|
@@ -13409,9 +13466,11 @@ function declarativeSubagentTools(agentOptions, parentTools) {
|
|
|
13409
13466
|
return subAgentToolsFromDefinitions(agents2, parentTools);
|
|
13410
13467
|
}
|
|
13411
13468
|
function bindParentCredentials(tools, agentOptions) {
|
|
13469
|
+
const parentPlugins = Array.isArray(agentOptions.plugins) ? agentOptions.plugins : void 0;
|
|
13412
13470
|
const credentials = {
|
|
13413
13471
|
...agentOptions.apiKey !== void 0 ? { apiKey: agentOptions.apiKey } : {},
|
|
13414
|
-
...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {}
|
|
13472
|
+
...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {},
|
|
13473
|
+
...parentPlugins !== void 0 ? { plugins: parentPlugins } : {}
|
|
13415
13474
|
};
|
|
13416
13475
|
for (const tool of tools) inheritSubAgentCredentials(tool, credentials);
|
|
13417
13476
|
}
|
|
@@ -15936,10 +15995,11 @@ var init_local_agent_memory = __esm({
|
|
|
15936
15995
|
}
|
|
15937
15996
|
buildTelemetryRecallArgs(telemetry) {
|
|
15938
15997
|
const userId = typeof this.options.memoryContext?.userId === "string" ? this.options.memoryContext.userId : void 0;
|
|
15998
|
+
const tenantId = typeof this.options.memoryContext?.tenantId === "string" ? this.options.memoryContext.tenantId : void 0;
|
|
15939
15999
|
return {
|
|
15940
16000
|
...telemetry !== void 0 ? { telemetry } : {},
|
|
15941
16001
|
...userId !== void 0 ? { userId } : {},
|
|
15942
|
-
namespace: "default",
|
|
16002
|
+
namespace: tenantId ?? "default",
|
|
15943
16003
|
scope: "session"
|
|
15944
16004
|
};
|
|
15945
16005
|
}
|