@theokit/sdk 2.10.0 → 2.11.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/eval.js CHANGED
@@ -8340,6 +8340,14 @@ function buildAssistantEvent(inputs, text) {
8340
8340
  message: { role: "assistant", content: [{ type: "text", text }] }
8341
8341
  };
8342
8342
  }
8343
+ function buildThinkingEvent(inputs, text) {
8344
+ return {
8345
+ type: "thinking",
8346
+ agent_id: inputs.agentId,
8347
+ run_id: inputs.runId,
8348
+ text
8349
+ };
8350
+ }
8343
8351
  function buildAssistantTurn(text, toolCalls) {
8344
8352
  const content = [];
8345
8353
  if (text.length > 0) content.push({ type: "text", text });
@@ -8510,6 +8518,10 @@ ${additions}`;
8510
8518
  function toLlmTool(tool) {
8511
8519
  return { name: tool.name, description: tool.description, inputSchema: tool.inputSchema };
8512
8520
  }
8521
+ function reasoningEffortFromParams(params) {
8522
+ const thinking = params?.find((p) => p.id === "thinking");
8523
+ return thinking !== void 0 && thinking.value.length > 0 ? thinking.value : void 0;
8524
+ }
8513
8525
  async function streamLlmTurn(inputs, ctx) {
8514
8526
  const llmSpan = inputs.telemetry?.startSpan("llm.call", {
8515
8527
  "model.id": inputs.model.id ?? "auto",
@@ -8526,6 +8538,12 @@ async function streamLlmTurn(inputs, ctx) {
8526
8538
  );
8527
8539
  return effective !== void 0 ? { system: effective } : {};
8528
8540
  })(),
8541
+ // issue #47: forward the reasoning effort from ModelSelection.params (the `thinking` param)
8542
+ // so the provider produces reasoning. Absent param ⇒ no `reasoning` field (bare request).
8543
+ ...(() => {
8544
+ const effort = reasoningEffortFromParams(inputs.model.params);
8545
+ return effort !== void 0 ? { reasoning: { effort } } : {};
8546
+ })(),
8529
8547
  messages: ctx.messages,
8530
8548
  tools: ctx.tools.map(toLlmTool)
8531
8549
  },
@@ -8594,6 +8612,7 @@ function registerLoopError(ctx, cause) {
8594
8612
  }
8595
8613
  async function runCollectorLoop(generator, inputs, ctx) {
8596
8614
  let accumulatedText = "";
8615
+ let reasoningText = "";
8597
8616
  let errored = false;
8598
8617
  let finishValue;
8599
8618
  while (true) {
@@ -8606,6 +8625,10 @@ async function runCollectorLoop(generator, inputs, ctx) {
8606
8625
  accumulatedText += next.value.text;
8607
8626
  await emitTextDeltaCallback(inputs, next.value.text);
8608
8627
  }
8628
+ if (next.value.type === "reasoning_delta") {
8629
+ reasoningText += next.value.text;
8630
+ await emitReasoningDeltaCallback(inputs, next.value.text);
8631
+ }
8609
8632
  if (next.value.type === "error") {
8610
8633
  registerLoopError(ctx, next.value);
8611
8634
  ctx.finalText = "";
@@ -8613,6 +8636,9 @@ async function runCollectorLoop(generator, inputs, ctx) {
8613
8636
  break;
8614
8637
  }
8615
8638
  }
8639
+ if (reasoningText.length > 0) {
8640
+ ctx.events.push(buildThinkingEvent(inputs, reasoningText));
8641
+ }
8616
8642
  return { accumulatedText, errored, finishValue };
8617
8643
  }
8618
8644
  async function emitTextDeltaCallback(inputs, text) {
@@ -8624,6 +8650,15 @@ async function emitTextDeltaCallback(inputs, text) {
8624
8650
  "SendOptions.onDelta"
8625
8651
  );
8626
8652
  }
8653
+ async function emitReasoningDeltaCallback(inputs, text) {
8654
+ if (inputs.onDelta === void 0) return;
8655
+ const cb = inputs.onDelta;
8656
+ await safeCall(
8657
+ () => cb({ update: { type: "thinking-delta", text } }),
8658
+ void 0,
8659
+ "SendOptions.onDelta"
8660
+ );
8661
+ }
8627
8662
 
8628
8663
  // src/internal/agent-loop/tool-dispatch.ts
8629
8664
  init_async_local_storage();
@@ -10937,7 +10972,7 @@ var OpenAIClient = class {
10937
10972
  method: "POST",
10938
10973
  signal,
10939
10974
  headers,
10940
- body: JSON.stringify(buildOpenAIBody(request))
10975
+ body: JSON.stringify(buildOpenAIBody(request, providerId))
10941
10976
  });
10942
10977
  } catch (fetchErr) {
10943
10978
  const mapped = mapOllamaTransportError({
@@ -10999,6 +11034,10 @@ var OpenAIStreamAccumulator = class {
10999
11034
  const events = [];
11000
11035
  this.applyUsage(chunk.usage);
11001
11036
  for (const choice of chunk.choices ?? []) {
11037
+ const reasoningEvent = this.applyReasoningDelta(
11038
+ choice.delta?.reasoning ?? choice.delta?.reasoning_content
11039
+ );
11040
+ if (reasoningEvent !== void 0) events.push(reasoningEvent);
11002
11041
  const textEvent = this.applyContentDelta(choice.delta?.content);
11003
11042
  if (textEvent !== void 0) events.push(textEvent);
11004
11043
  this.mergeToolCallDeltas(choice.delta?.tool_calls);
@@ -11006,6 +11045,10 @@ var OpenAIStreamAccumulator = class {
11006
11045
  }
11007
11046
  return events;
11008
11047
  }
11048
+ applyReasoningDelta(reasoning) {
11049
+ if (typeof reasoning !== "string" || reasoning.length === 0) return void 0;
11050
+ return { type: "reasoning_delta", text: reasoning };
11051
+ }
11009
11052
  applyUsage(usage) {
11010
11053
  if (usage?.prompt_tokens !== void 0) this.inputTokens = usage.prompt_tokens;
11011
11054
  if (usage?.completion_tokens !== void 0) this.outputTokens = usage.completion_tokens;
@@ -11068,7 +11111,14 @@ function mapOpenAIFinish(reason) {
11068
11111
  return "end_turn";
11069
11112
  }
11070
11113
  }
11071
- function buildOpenAIBody(request) {
11114
+ function applyReasoningRequest(body, effort, providerName) {
11115
+ if (providerName === "openai") {
11116
+ body.reasoning_effort = effort;
11117
+ return;
11118
+ }
11119
+ body.reasoning = { effort };
11120
+ }
11121
+ function buildOpenAIBody(request, providerName) {
11072
11122
  const messages = [];
11073
11123
  const systemText = openAISystemText(request.system);
11074
11124
  if (systemText.length > 0) {
@@ -11087,6 +11137,8 @@ function buildOpenAIBody(request) {
11087
11137
  };
11088
11138
  if (request.maxTokens !== void 0) body.max_tokens = request.maxTokens;
11089
11139
  if (request.temperature !== void 0) body.temperature = request.temperature;
11140
+ if (request.reasoning?.effort !== void 0)
11141
+ applyReasoningRequest(body, request.reasoning.effort, providerName);
11090
11142
  if (request.tools !== void 0 && request.tools.length > 0) {
11091
11143
  body.tools = request.tools.map((tool) => ({
11092
11144
  type: "function",
@@ -11920,7 +11972,12 @@ function buildLoopInputs(options, runId, userText) {
11920
11972
  return {
11921
11973
  agentId: options.agentId,
11922
11974
  runId,
11923
- model: { id: effectiveModelId },
11975
+ // issue #47: carry ModelSelection.params (the reasoning `thinking` param) into the loop so the
11976
+ // request can forward reasoning. The id is stripped/normalized above; params pass through as-is.
11977
+ model: {
11978
+ id: effectiveModelId,
11979
+ ...options.model?.params !== void 0 ? { params: options.model.params } : {}
11980
+ },
11924
11981
  userMessage: userText,
11925
11982
  llm,
11926
11983
  mcp: buildMcpMap(options),