@theokit/sdk 3.2.0 → 3.2.2

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/index.js CHANGED
@@ -4754,7 +4754,14 @@ var init_env_policy = __esm({
4754
4754
  /[_-]PWD/i,
4755
4755
  /CREDENTIAL/i,
4756
4756
  /PRIVATE/i,
4757
- /_AUTH/i
4757
+ /_AUTH/i,
4758
+ // #54-a — value-embedded-secret conventions (no generic `*_URL` — see keep-list test).
4759
+ /DSN/i,
4760
+ /WEBHOOK/i,
4761
+ /COOKIE/i,
4762
+ /CONNECTION[_-]?STRING/i,
4763
+ // Known DB / message-broker connection-string vars (carry `user:pass@`).
4764
+ /(?:^|[_-])(?:DATABASE|DB|REDIS|MONGO(?:DB)?|POSTGRES(?:QL)?|MYSQL|MARIADB|AMQP|RABBITMQ|CLICKHOUSE|ELASTIC(?:SEARCH)?|CASSANDRA|COUCHDB|MEMCACHED|NATS|KAFKA)[_-]?(?:URL|URI|DSN|CONNECTION)/i
4758
4765
  ];
4759
4766
  CORE_VARS = [
4760
4767
  "PATH",
@@ -7751,15 +7758,19 @@ async function collectChildToolResults(run) {
7751
7758
  ${lines.join("\n")}
7752
7759
  </subagent-tool-results>`;
7753
7760
  }
7754
- async function runChildAgent(spec, input, signal, maxSteps, inherited) {
7755
- const { Agent: Agent2 } = await Promise.resolve().then(() => (init_agent(), agent_exports));
7761
+ function buildChildCreateOptions(spec, inherited) {
7756
7762
  const model = spec.model ? { id: spec.model } : inherited?.model;
7757
- const agent = await Agent2.create({
7763
+ return {
7758
7764
  ...inherited?.apiKey !== void 0 ? { apiKey: inherited.apiKey } : {},
7759
7765
  ...model !== void 0 ? { model } : {},
7766
+ ...inherited?.plugins !== void 0 ? { plugins: inherited.plugins } : {},
7760
7767
  systemPrompt: spec.instructions,
7761
7768
  tools: spec.tools ?? []
7762
- });
7769
+ };
7770
+ }
7771
+ async function runChildAgent(spec, input, signal, maxSteps, inherited) {
7772
+ const { Agent: Agent2 } = await Promise.resolve().then(() => (init_agent(), agent_exports));
7773
+ const agent = await Agent2.create(buildChildCreateOptions(spec, inherited));
7763
7774
  try {
7764
7775
  const sendOptions = {
7765
7776
  ...signal !== void 0 ? { signal } : {},
@@ -9662,7 +9673,10 @@ async function runAgentLoop(inputs) {
9662
9673
  }
9663
9674
  budget.consume();
9664
9675
  inputs.budgetTracker?.nextIteration?.();
9665
- if (inputs.signal?.aborted === true) break;
9676
+ if (inputs.signal?.aborted === true) {
9677
+ ctx.finalStatus = "cancelled";
9678
+ break;
9679
+ }
9666
9680
  }
9667
9681
  if (lastTurnDecision === "continue" && budget.shouldContinue() === false) {
9668
9682
  ctx.stoppedAtIterationLimit = true;
@@ -9847,15 +9861,15 @@ async function guardAndTransformToolResults(inputs, raw, ctx) {
9847
9861
  }
9848
9862
  async function continueOrTerminate(inputs, ctx, llmOutput) {
9849
9863
  if (llmOutput.errored) return "error";
9850
- if (llmOutput.text.length > 0) {
9851
- await emitAssistantTextStep(inputs, ctx, llmOutput.text);
9864
+ const tCtx = { agentId: inputs.agentId, runId: inputs.runId };
9865
+ const text = llmOutput.text.length > 0 ? await transformLlmOutputText(inputs, llmOutput.text, tCtx) : llmOutput.text;
9866
+ if (text.length > 0) {
9867
+ await emitAssistantTextStep(inputs, ctx, text);
9852
9868
  }
9853
9869
  if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
9854
9870
  return finishOrReflect(inputs, ctx, llmOutput);
9855
9871
  }
9856
- const tCtx = { agentId: inputs.agentId, runId: inputs.runId };
9857
- const outText = await transformLlmOutputText(inputs, llmOutput.text, tCtx);
9858
- ctx.messages.push(buildAssistantTurn(outText, llmOutput.toolCalls));
9872
+ ctx.messages.push(buildAssistantTurn(text, llmOutput.toolCalls));
9859
9873
  const rawResults = await dispatchTools(
9860
9874
  // SE12 — forward a read-only text projection of the transcript-so-far to tool
9861
9875
  // handlers via `ctx.messages` (consumed by defineSubAgent's messageFilter).
@@ -13193,7 +13207,12 @@ var init_client = __esm({
13193
13207
  code: "mcp_http_error"
13194
13208
  });
13195
13209
  }
13196
- return await response.json();
13210
+ try {
13211
+ return await response.json();
13212
+ } catch (cause) {
13213
+ if (isAbortLike(cause)) throw mcpTimeoutError(this.name, timeoutMs);
13214
+ throw cause;
13215
+ }
13197
13216
  }
13198
13217
  };
13199
13218
  }
@@ -13433,9 +13452,11 @@ function declarativeSubagentTools(agentOptions, parentTools) {
13433
13452
  return subAgentToolsFromDefinitions(agents2, parentTools);
13434
13453
  }
13435
13454
  function bindParentCredentials(tools, agentOptions) {
13455
+ const parentPlugins = Array.isArray(agentOptions.plugins) ? agentOptions.plugins : void 0;
13436
13456
  const credentials = {
13437
13457
  ...agentOptions.apiKey !== void 0 ? { apiKey: agentOptions.apiKey } : {},
13438
- ...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {}
13458
+ ...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {},
13459
+ ...parentPlugins !== void 0 ? { plugins: parentPlugins } : {}
13439
13460
  };
13440
13461
  for (const tool of tools) inheritSubAgentCredentials(tool, credentials);
13441
13462
  }
@@ -15969,10 +15990,11 @@ var init_local_agent_memory = __esm({
15969
15990
  }
15970
15991
  buildTelemetryRecallArgs(telemetry) {
15971
15992
  const userId = typeof this.options.memoryContext?.userId === "string" ? this.options.memoryContext.userId : void 0;
15993
+ const tenantId = typeof this.options.memoryContext?.tenantId === "string" ? this.options.memoryContext.tenantId : void 0;
15972
15994
  return {
15973
15995
  ...telemetry !== void 0 ? { telemetry } : {},
15974
15996
  ...userId !== void 0 ? { userId } : {},
15975
- namespace: "default",
15997
+ namespace: tenantId ?? "default",
15976
15998
  scope: "session"
15977
15999
  };
15978
16000
  }
@@ -22242,8 +22264,10 @@ var JobQueue = class {
22242
22264
  const job = this.jobs.get(id);
22243
22265
  if (!job) return false;
22244
22266
  if (job.status === "pending" || job.status === "running") {
22267
+ const wasRunning = job.status === "running";
22245
22268
  job.status = "cancelled";
22246
22269
  this.controllers.get(id)?.abort();
22270
+ if (wasRunning) this.#release(id);
22247
22271
  return true;
22248
22272
  }
22249
22273
  return false;
@@ -22261,8 +22285,14 @@ var JobQueue = class {
22261
22285
  });
22262
22286
  });
22263
22287
  }
22264
- /** Release a slot + clean up the controller; start the next waiting job. */
22288
+ /**
22289
+ * Release a slot + clean up the controller; start the next waiting job.
22290
+ * Idempotent — keyed on the controller's presence, so a running job that was
22291
+ * cancelled (released early) does not double-decrement when its `.finally`
22292
+ * eventually fires.
22293
+ */
22265
22294
  #release(id) {
22295
+ if (!this.controllers.has(id)) return;
22266
22296
  this.controllers.delete(id);
22267
22297
  this.running -= 1;
22268
22298
  const next = this.waiting.shift();