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