@theokit/sdk 2.11.0 → 2.11.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
@@ -10805,6 +10805,14 @@ function buildAssistantEvent(inputs, text) {
10805
10805
  message: { role: "assistant", content: [{ type: "text", text }] }
10806
10806
  };
10807
10807
  }
10808
+ function buildThinkingEvent(inputs, text) {
10809
+ return {
10810
+ type: "thinking",
10811
+ agent_id: inputs.agentId,
10812
+ run_id: inputs.runId,
10813
+ text
10814
+ };
10815
+ }
10808
10816
  function buildAssistantTurn(text, toolCalls) {
10809
10817
  const content = [];
10810
10818
  if (text.length > 0) content.push({ type: "text", text });
@@ -10975,6 +10983,10 @@ ${additions}`;
10975
10983
  function toLlmTool(tool) {
10976
10984
  return { name: tool.name, description: tool.description, inputSchema: tool.inputSchema };
10977
10985
  }
10986
+ function reasoningEffortFromParams(params) {
10987
+ const thinking = params?.find((p) => p.id === "thinking");
10988
+ return thinking !== void 0 && thinking.value.length > 0 ? thinking.value : void 0;
10989
+ }
10978
10990
  async function streamLlmTurn(inputs, ctx) {
10979
10991
  const llmSpan = inputs.telemetry?.startSpan("llm.call", {
10980
10992
  "model.id": inputs.model.id ?? "auto",
@@ -10991,6 +11003,15 @@ async function streamLlmTurn(inputs, ctx) {
10991
11003
  );
10992
11004
  return effective !== void 0 ? { system: effective } : {};
10993
11005
  })(),
11006
+ // issue #47: forward the reasoning effort from ModelSelection.params (the `thinking` param)
11007
+ // so the provider produces reasoning. Absent param ⇒ no `reasoning` field (bare request).
11008
+ ...(() => {
11009
+ const effort = reasoningEffortFromParams(inputs.model.params);
11010
+ return effort !== void 0 ? { reasoning: { effort } } : {};
11011
+ })(),
11012
+ // Step-cap force-close: forward the per-run tool gate (`"none"` on a ceiling round forces a
11013
+ // text close even though tools are advertised). Absent ⇒ provider default (auto).
11014
+ ...inputs.toolChoice !== void 0 ? { toolChoice: inputs.toolChoice } : {},
10994
11015
  messages: ctx.messages,
10995
11016
  tools: ctx.tools.map(toLlmTool)
10996
11017
  },
@@ -11059,6 +11080,7 @@ function registerLoopError(ctx, cause) {
11059
11080
  }
11060
11081
  async function runCollectorLoop(generator, inputs, ctx) {
11061
11082
  let accumulatedText = "";
11083
+ let reasoningText = "";
11062
11084
  let errored = false;
11063
11085
  let finishValue;
11064
11086
  while (true) {
@@ -11071,6 +11093,10 @@ async function runCollectorLoop(generator, inputs, ctx) {
11071
11093
  accumulatedText += next.value.text;
11072
11094
  await emitTextDeltaCallback(inputs, next.value.text);
11073
11095
  }
11096
+ if (next.value.type === "reasoning_delta") {
11097
+ reasoningText += next.value.text;
11098
+ await emitReasoningDeltaCallback(inputs, next.value.text);
11099
+ }
11074
11100
  if (next.value.type === "error") {
11075
11101
  registerLoopError(ctx, next.value);
11076
11102
  ctx.finalText = "";
@@ -11078,6 +11104,9 @@ async function runCollectorLoop(generator, inputs, ctx) {
11078
11104
  break;
11079
11105
  }
11080
11106
  }
11107
+ if (reasoningText.length > 0) {
11108
+ ctx.events.push(buildThinkingEvent(inputs, reasoningText));
11109
+ }
11081
11110
  return { accumulatedText, errored, finishValue };
11082
11111
  }
11083
11112
  async function emitTextDeltaCallback(inputs, text) {
@@ -11089,6 +11118,15 @@ async function emitTextDeltaCallback(inputs, text) {
11089
11118
  "SendOptions.onDelta"
11090
11119
  );
11091
11120
  }
11121
+ async function emitReasoningDeltaCallback(inputs, text) {
11122
+ if (inputs.onDelta === void 0) return;
11123
+ const cb = inputs.onDelta;
11124
+ await safeCall(
11125
+ () => cb({ update: { type: "thinking-delta", text } }),
11126
+ void 0,
11127
+ "SendOptions.onDelta"
11128
+ );
11129
+ }
11092
11130
 
11093
11131
  // src/internal/agent-loop/tool-dispatch.ts
11094
11132
  init_async_local_storage();
@@ -13417,7 +13455,7 @@ var OpenAIClient = class {
13417
13455
  method: "POST",
13418
13456
  signal,
13419
13457
  headers,
13420
- body: JSON.stringify(buildOpenAIBody(request))
13458
+ body: JSON.stringify(buildOpenAIBody(request, providerId))
13421
13459
  });
13422
13460
  } catch (fetchErr) {
13423
13461
  const mapped = mapOllamaTransportError({
@@ -13479,6 +13517,10 @@ var OpenAIStreamAccumulator = class {
13479
13517
  const events = [];
13480
13518
  this.applyUsage(chunk.usage);
13481
13519
  for (const choice of chunk.choices ?? []) {
13520
+ const reasoningEvent = this.applyReasoningDelta(
13521
+ choice.delta?.reasoning ?? choice.delta?.reasoning_content
13522
+ );
13523
+ if (reasoningEvent !== void 0) events.push(reasoningEvent);
13482
13524
  const textEvent = this.applyContentDelta(choice.delta?.content);
13483
13525
  if (textEvent !== void 0) events.push(textEvent);
13484
13526
  this.mergeToolCallDeltas(choice.delta?.tool_calls);
@@ -13486,6 +13528,10 @@ var OpenAIStreamAccumulator = class {
13486
13528
  }
13487
13529
  return events;
13488
13530
  }
13531
+ applyReasoningDelta(reasoning) {
13532
+ if (typeof reasoning !== "string" || reasoning.length === 0) return void 0;
13533
+ return { type: "reasoning_delta", text: reasoning };
13534
+ }
13489
13535
  applyUsage(usage) {
13490
13536
  if (usage?.prompt_tokens !== void 0) this.inputTokens = usage.prompt_tokens;
13491
13537
  if (usage?.completion_tokens !== void 0) this.outputTokens = usage.completion_tokens;
@@ -13548,7 +13594,22 @@ function mapOpenAIFinish(reason) {
13548
13594
  return "end_turn";
13549
13595
  }
13550
13596
  }
13551
- function buildOpenAIBody(request) {
13597
+ function applyReasoningRequest(body, effort, providerName) {
13598
+ if (providerName === "openai") {
13599
+ body.reasoning_effort = effort;
13600
+ return;
13601
+ }
13602
+ body.reasoning = { effort };
13603
+ }
13604
+ function applyToolsRequest(body, request) {
13605
+ if (request.tools === void 0 || request.tools.length === 0) return;
13606
+ body.tools = request.tools.map((tool) => ({
13607
+ type: "function",
13608
+ function: { name: tool.name, description: tool.description, parameters: tool.inputSchema }
13609
+ }));
13610
+ if (request.toolChoice !== void 0) body.tool_choice = request.toolChoice;
13611
+ }
13612
+ function buildOpenAIBody(request, providerName) {
13552
13613
  const messages = [];
13553
13614
  const systemText = openAISystemText(request.system);
13554
13615
  if (systemText.length > 0) {
@@ -13567,12 +13628,9 @@ function buildOpenAIBody(request) {
13567
13628
  };
13568
13629
  if (request.maxTokens !== void 0) body.max_tokens = request.maxTokens;
13569
13630
  if (request.temperature !== void 0) body.temperature = request.temperature;
13570
- if (request.tools !== void 0 && request.tools.length > 0) {
13571
- body.tools = request.tools.map((tool) => ({
13572
- type: "function",
13573
- function: { name: tool.name, description: tool.description, parameters: tool.inputSchema }
13574
- }));
13575
- }
13631
+ if (request.reasoning?.effort !== void 0)
13632
+ applyReasoningRequest(body, request.reasoning.effort, providerName);
13633
+ applyToolsRequest(body, request);
13576
13634
  const responseFormat = encodeOpenAIResponseFormat(request.responseFormat);
13577
13635
  if (responseFormat !== void 0) body.response_format = responseFormat;
13578
13636
  return body;
@@ -14401,7 +14459,12 @@ function buildLoopInputs(options, runId, userText) {
14401
14459
  return {
14402
14460
  agentId: options.agentId,
14403
14461
  runId,
14404
- model: { id: effectiveModelId },
14462
+ // issue #47: carry ModelSelection.params (the reasoning `thinking` param) into the loop so the
14463
+ // request can forward reasoning. The id is stripped/normalized above; params pass through as-is.
14464
+ model: {
14465
+ id: effectiveModelId,
14466
+ ...options.model?.params !== void 0 ? { params: options.model.params } : {}
14467
+ },
14405
14468
  userMessage: userText,
14406
14469
  llm,
14407
14470
  mcp: buildMcpMap(options),
@@ -14411,6 +14474,7 @@ function buildLoopInputs(options, runId, userText) {
14411
14474
  ...options.systemPrompt !== void 0 ? { systemPrompt: options.systemPrompt } : {},
14412
14475
  ...options.onStep !== void 0 ? { onStep: options.onStep } : {},
14413
14476
  ...options.onDelta !== void 0 ? { onDelta: options.onDelta } : {},
14477
+ ...options.sendOptions.toolChoice !== void 0 ? { toolChoice: options.sendOptions.toolChoice } : {},
14414
14478
  ...options.priorMessages !== void 0 ? { priorMessages: options.priorMessages } : {},
14415
14479
  ...options.memoryTools !== void 0 && options.memoryTools.length > 0 ? { memoryTools: options.memoryTools } : {},
14416
14480
  ...buildCustomToolsInput(