@tansr/sdk 0.6.0 → 0.7.0

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.
Files changed (2) hide show
  1. package/dist/index.js +27 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -28554,6 +28554,10 @@ var TWP_FEATURE_REASONING_OFF = "reasoning-off";
28554
28554
  function sendableTwpReasoningOff(features) {
28555
28555
  return features !== void 0 && features.includes(TWP_FEATURE_REASONING_OFF);
28556
28556
  }
28557
+ var TWP_FEATURE_REASONING_CONTENT = "reasoning-content";
28558
+ function sendableTwpReasoningContent(features) {
28559
+ return features !== void 0 && features.includes(TWP_FEATURE_REASONING_CONTENT);
28560
+ }
28557
28561
 
28558
28562
  // ../providers/src/twp/signing.ts
28559
28563
  import { createHash as createHash11, createHmac, randomBytes } from "node:crypto";
@@ -28664,6 +28668,11 @@ function irMessageToTwp(message, sendImages) {
28664
28668
  if (blocks.length === 0) return null;
28665
28669
  return { role: message.role, blocks };
28666
28670
  }
28671
+ function reasoningLevelOfBudget(budget) {
28672
+ if (budget <= 1024) return "low";
28673
+ if (budget <= 4096) return "medium";
28674
+ return "high";
28675
+ }
28667
28676
  function irRequestToTwpWire(request, opts = {}) {
28668
28677
  const sendImages = opts.sendImages ?? false;
28669
28678
  const cacheHints = opts.cacheHints ?? false;
@@ -28700,7 +28709,12 @@ function irRequestToTwpWire(request, opts = {}) {
28700
28709
  // ——服务端缺席语义 = 仅既有输出钳制,零行为变化
28701
28710
  ...request.promptTokensEstimate !== void 0 && Math.ceil(request.promptTokensEstimate) >= 1 ? { promptTokensEstimate: Math.ceil(request.promptTokensEstimate) } : {},
28702
28711
  // RFC-M3 B2:思考关断出线(门开 × IR off 双判;门关恒不落键零漂移)
28703
- ...opts.reasoningOff === true && request.thinking?.off === true ? { reasoning: "off" } : {}
28712
+ ...opts.reasoningOff === true && request.thinking?.off === true ? { reasoning: "off" } : (
28713
+ // S-TH1:思考开启出线(门开 × IR budget 双判;off 恒胜 budget)——
28714
+ // budget → 档位反查(EFFORT_THINKING_BUDGET 同族阈值:≤1024 low /
28715
+ // ≤4096 medium / 其余 high),网关按方言翻译
28716
+ opts.reasoningLevels === true && request.thinking?.off !== true && typeof request.thinking?.budget === "number" && request.thinking.budget > 0 ? { reasoning: reasoningLevelOfBudget(request.thinking.budget) } : {}
28717
+ )
28704
28718
  },
28705
28719
  meta: {
28706
28720
  requestId: opts.requestId ?? ulid(),
@@ -28968,6 +28982,13 @@ var TwpStreamAssembler = class {
28968
28982
  out.push({ t: "text_delta", index: i, text: v });
28969
28983
  return out;
28970
28984
  }
28985
+ if (kind === "thinking") {
28986
+ const v = record["v"];
28987
+ if (typeof v !== "string") return out;
28988
+ out.push(...this.#ensureBlock(i, "thinking", record));
28989
+ out.push({ t: "thinking_delta", index: i, text: v });
28990
+ return out;
28991
+ }
28971
28992
  if (kind === "tool_use") {
28972
28993
  out.push(...this.#ensureBlock(i, "tool_use", record));
28973
28994
  const vJson = record["vJson"];
@@ -28991,6 +29012,8 @@ var TwpStreamAssembler = class {
28991
29012
  }
28992
29013
  if (kind === "text") {
28993
29014
  out.push({ t: "block_start", index: i, block: { t: "text", text: "" } });
29015
+ } else if (kind === "thinking") {
29016
+ out.push({ t: "block_start", index: i, block: { t: "thinking", text: "" } });
28994
29017
  } else {
28995
29018
  out.push({
28996
29019
  t: "block_start",
@@ -29120,6 +29143,7 @@ var TwpAdapter = class {
29120
29143
  );
29121
29144
  const cacheHints = sendableTwpCacheHints(this.#options.features?.());
29122
29145
  const reasoningOff = sendableTwpReasoningOff(this.#options.features?.());
29146
+ const reasoningLevels = sendableTwpReasoningContent(this.#options.features?.());
29123
29147
  try {
29124
29148
  body = JSON.stringify(
29125
29149
  irRequestToTwpWire(request, {
@@ -29131,7 +29155,8 @@ var TwpAdapter = class {
29131
29155
  ...sendImages ? { sendImages } : {},
29132
29156
  ...cacheHints ? { cacheHints } : {},
29133
29157
  ...cacheHints && platformSessionId !== void 0 ? { cacheKey: platformSessionId } : {},
29134
- ...reasoningOff ? { reasoningOff } : {}
29158
+ ...reasoningOff ? { reasoningOff } : {},
29159
+ ...reasoningLevels ? { reasoningLevels } : {}
29135
29160
  })
29136
29161
  );
29137
29162
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tansr/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Tansr public TypeScript SDK: headless agent API (query / createSession / runAgent) + pure protocol type re-exports (public, MIT).",
5
5
  "license": "MIT",
6
6
  "type": "module",