@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.cjs CHANGED
@@ -8343,6 +8343,14 @@ function buildAssistantEvent(inputs, text) {
8343
8343
  message: { role: "assistant", content: [{ type: "text", text }] }
8344
8344
  };
8345
8345
  }
8346
+ function buildThinkingEvent(inputs, text) {
8347
+ return {
8348
+ type: "thinking",
8349
+ agent_id: inputs.agentId,
8350
+ run_id: inputs.runId,
8351
+ text
8352
+ };
8353
+ }
8346
8354
  function buildAssistantTurn(text, toolCalls) {
8347
8355
  const content = [];
8348
8356
  if (text.length > 0) content.push({ type: "text", text });
@@ -8513,6 +8521,10 @@ ${additions}`;
8513
8521
  function toLlmTool(tool) {
8514
8522
  return { name: tool.name, description: tool.description, inputSchema: tool.inputSchema };
8515
8523
  }
8524
+ function reasoningEffortFromParams(params) {
8525
+ const thinking = params?.find((p) => p.id === "thinking");
8526
+ return thinking !== void 0 && thinking.value.length > 0 ? thinking.value : void 0;
8527
+ }
8516
8528
  async function streamLlmTurn(inputs, ctx) {
8517
8529
  const llmSpan = inputs.telemetry?.startSpan("llm.call", {
8518
8530
  "model.id": inputs.model.id ?? "auto",
@@ -8529,6 +8541,12 @@ async function streamLlmTurn(inputs, ctx) {
8529
8541
  );
8530
8542
  return effective !== void 0 ? { system: effective } : {};
8531
8543
  })(),
8544
+ // issue #47: forward the reasoning effort from ModelSelection.params (the `thinking` param)
8545
+ // so the provider produces reasoning. Absent param ⇒ no `reasoning` field (bare request).
8546
+ ...(() => {
8547
+ const effort = reasoningEffortFromParams(inputs.model.params);
8548
+ return effort !== void 0 ? { reasoning: { effort } } : {};
8549
+ })(),
8532
8550
  messages: ctx.messages,
8533
8551
  tools: ctx.tools.map(toLlmTool)
8534
8552
  },
@@ -8597,6 +8615,7 @@ function registerLoopError(ctx, cause) {
8597
8615
  }
8598
8616
  async function runCollectorLoop(generator, inputs, ctx) {
8599
8617
  let accumulatedText = "";
8618
+ let reasoningText = "";
8600
8619
  let errored = false;
8601
8620
  let finishValue;
8602
8621
  while (true) {
@@ -8609,6 +8628,10 @@ async function runCollectorLoop(generator, inputs, ctx) {
8609
8628
  accumulatedText += next.value.text;
8610
8629
  await emitTextDeltaCallback(inputs, next.value.text);
8611
8630
  }
8631
+ if (next.value.type === "reasoning_delta") {
8632
+ reasoningText += next.value.text;
8633
+ await emitReasoningDeltaCallback(inputs, next.value.text);
8634
+ }
8612
8635
  if (next.value.type === "error") {
8613
8636
  registerLoopError(ctx, next.value);
8614
8637
  ctx.finalText = "";
@@ -8616,6 +8639,9 @@ async function runCollectorLoop(generator, inputs, ctx) {
8616
8639
  break;
8617
8640
  }
8618
8641
  }
8642
+ if (reasoningText.length > 0) {
8643
+ ctx.events.push(buildThinkingEvent(inputs, reasoningText));
8644
+ }
8619
8645
  return { accumulatedText, errored, finishValue };
8620
8646
  }
8621
8647
  async function emitTextDeltaCallback(inputs, text) {
@@ -8627,6 +8653,15 @@ async function emitTextDeltaCallback(inputs, text) {
8627
8653
  "SendOptions.onDelta"
8628
8654
  );
8629
8655
  }
8656
+ async function emitReasoningDeltaCallback(inputs, text) {
8657
+ if (inputs.onDelta === void 0) return;
8658
+ const cb = inputs.onDelta;
8659
+ await safeCall(
8660
+ () => cb({ update: { type: "thinking-delta", text } }),
8661
+ void 0,
8662
+ "SendOptions.onDelta"
8663
+ );
8664
+ }
8630
8665
 
8631
8666
  // src/internal/agent-loop/tool-dispatch.ts
8632
8667
  init_async_local_storage();
@@ -10940,7 +10975,7 @@ var OpenAIClient = class {
10940
10975
  method: "POST",
10941
10976
  signal,
10942
10977
  headers,
10943
- body: JSON.stringify(buildOpenAIBody(request))
10978
+ body: JSON.stringify(buildOpenAIBody(request, providerId))
10944
10979
  });
10945
10980
  } catch (fetchErr) {
10946
10981
  const mapped = mapOllamaTransportError({
@@ -11002,6 +11037,10 @@ var OpenAIStreamAccumulator = class {
11002
11037
  const events = [];
11003
11038
  this.applyUsage(chunk.usage);
11004
11039
  for (const choice of chunk.choices ?? []) {
11040
+ const reasoningEvent = this.applyReasoningDelta(
11041
+ choice.delta?.reasoning ?? choice.delta?.reasoning_content
11042
+ );
11043
+ if (reasoningEvent !== void 0) events.push(reasoningEvent);
11005
11044
  const textEvent = this.applyContentDelta(choice.delta?.content);
11006
11045
  if (textEvent !== void 0) events.push(textEvent);
11007
11046
  this.mergeToolCallDeltas(choice.delta?.tool_calls);
@@ -11009,6 +11048,10 @@ var OpenAIStreamAccumulator = class {
11009
11048
  }
11010
11049
  return events;
11011
11050
  }
11051
+ applyReasoningDelta(reasoning) {
11052
+ if (typeof reasoning !== "string" || reasoning.length === 0) return void 0;
11053
+ return { type: "reasoning_delta", text: reasoning };
11054
+ }
11012
11055
  applyUsage(usage) {
11013
11056
  if (usage?.prompt_tokens !== void 0) this.inputTokens = usage.prompt_tokens;
11014
11057
  if (usage?.completion_tokens !== void 0) this.outputTokens = usage.completion_tokens;
@@ -11071,7 +11114,14 @@ function mapOpenAIFinish(reason) {
11071
11114
  return "end_turn";
11072
11115
  }
11073
11116
  }
11074
- function buildOpenAIBody(request) {
11117
+ function applyReasoningRequest(body, effort, providerName) {
11118
+ if (providerName === "openai") {
11119
+ body.reasoning_effort = effort;
11120
+ return;
11121
+ }
11122
+ body.reasoning = { effort };
11123
+ }
11124
+ function buildOpenAIBody(request, providerName) {
11075
11125
  const messages = [];
11076
11126
  const systemText = openAISystemText(request.system);
11077
11127
  if (systemText.length > 0) {
@@ -11090,6 +11140,8 @@ function buildOpenAIBody(request) {
11090
11140
  };
11091
11141
  if (request.maxTokens !== void 0) body.max_tokens = request.maxTokens;
11092
11142
  if (request.temperature !== void 0) body.temperature = request.temperature;
11143
+ if (request.reasoning?.effort !== void 0)
11144
+ applyReasoningRequest(body, request.reasoning.effort, providerName);
11093
11145
  if (request.tools !== void 0 && request.tools.length > 0) {
11094
11146
  body.tools = request.tools.map((tool) => ({
11095
11147
  type: "function",
@@ -11923,7 +11975,12 @@ function buildLoopInputs(options, runId, userText) {
11923
11975
  return {
11924
11976
  agentId: options.agentId,
11925
11977
  runId,
11926
- model: { id: effectiveModelId },
11978
+ // issue #47: carry ModelSelection.params (the reasoning `thinking` param) into the loop so the
11979
+ // request can forward reasoning. The id is stripped/normalized above; params pass through as-is.
11980
+ model: {
11981
+ id: effectiveModelId,
11982
+ ...options.model?.params !== void 0 ? { params: options.model.params } : {}
11983
+ },
11927
11984
  userMessage: userText,
11928
11985
  llm,
11929
11986
  mcp: buildMcpMap(options),