@tansr/serve 0.1.0 → 0.2.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.
- package/dist/index.js +53 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38337,6 +38337,26 @@ var AgentSessionRegistry = class {
|
|
|
38337
38337
|
}
|
|
38338
38338
|
};
|
|
38339
38339
|
|
|
38340
|
+
// src/v2/history-projection.ts
|
|
38341
|
+
var REMINDER_OPEN = "<system-reminder>";
|
|
38342
|
+
var REMINDER_CLOSE = "</system-reminder>";
|
|
38343
|
+
function isReminderBlock(block) {
|
|
38344
|
+
return block.t === "text" && block.text.startsWith(REMINDER_OPEN) && block.text.endsWith(REMINDER_CLOSE);
|
|
38345
|
+
}
|
|
38346
|
+
function stripReminderBlocks(messages) {
|
|
38347
|
+
const out = [];
|
|
38348
|
+
for (const message of messages) {
|
|
38349
|
+
if (message.role !== "user" || !message.blocks.some(isReminderBlock)) {
|
|
38350
|
+
out.push(message);
|
|
38351
|
+
continue;
|
|
38352
|
+
}
|
|
38353
|
+
const blocks = message.blocks.filter((block) => !isReminderBlock(block));
|
|
38354
|
+
if (blocks.length === 0) continue;
|
|
38355
|
+
out.push({ ...message, blocks });
|
|
38356
|
+
}
|
|
38357
|
+
return out;
|
|
38358
|
+
}
|
|
38359
|
+
|
|
38340
38360
|
// src/v2/types.ts
|
|
38341
38361
|
var AgentSessionCreateError = class extends Error {
|
|
38342
38362
|
code;
|
|
@@ -38683,7 +38703,11 @@ function createAgentRoutesHandler(deps) {
|
|
|
38683
38703
|
if (record === "forbidden") return;
|
|
38684
38704
|
if (record !== "absent") {
|
|
38685
38705
|
const snapshot = record.handle.historySnapshot();
|
|
38686
|
-
sendJson(res, 200, {
|
|
38706
|
+
sendJson(res, 200, {
|
|
38707
|
+
sessionId,
|
|
38708
|
+
lastSeq: snapshot.lastSeq,
|
|
38709
|
+
messages: stripReminderBlocks(snapshot.messages)
|
|
38710
|
+
});
|
|
38687
38711
|
return;
|
|
38688
38712
|
}
|
|
38689
38713
|
let messages;
|
|
@@ -38699,7 +38723,7 @@ function createAgentRoutesHandler(deps) {
|
|
|
38699
38723
|
notFound(res, sessionId);
|
|
38700
38724
|
return;
|
|
38701
38725
|
}
|
|
38702
|
-
sendJson(res, 200, { sessionId, lastSeq: 0, messages });
|
|
38726
|
+
sendJson(res, 200, { sessionId, lastSeq: 0, messages: stripReminderBlocks(messages) });
|
|
38703
38727
|
};
|
|
38704
38728
|
const handleInterrupt = (res, sessionId, endUserId) => {
|
|
38705
38729
|
const record = ownedRecord(res, sessionId, endUserId);
|
|
@@ -56650,6 +56674,10 @@ var TWP_FEATURE_REASONING_OFF = "reasoning-off";
|
|
|
56650
56674
|
function sendableTwpReasoningOff(features) {
|
|
56651
56675
|
return features !== void 0 && features.includes(TWP_FEATURE_REASONING_OFF);
|
|
56652
56676
|
}
|
|
56677
|
+
var TWP_FEATURE_REASONING_CONTENT = "reasoning-content";
|
|
56678
|
+
function sendableTwpReasoningContent(features) {
|
|
56679
|
+
return features !== void 0 && features.includes(TWP_FEATURE_REASONING_CONTENT);
|
|
56680
|
+
}
|
|
56653
56681
|
|
|
56654
56682
|
// ../providers/src/twp/signing.ts
|
|
56655
56683
|
import { createHash as createHash11, createHmac as createHmac2, randomBytes } from "node:crypto";
|
|
@@ -56760,6 +56788,11 @@ function irMessageToTwp(message, sendImages) {
|
|
|
56760
56788
|
if (blocks.length === 0) return null;
|
|
56761
56789
|
return { role: message.role, blocks };
|
|
56762
56790
|
}
|
|
56791
|
+
function reasoningLevelOfBudget(budget) {
|
|
56792
|
+
if (budget <= 1024) return "low";
|
|
56793
|
+
if (budget <= 4096) return "medium";
|
|
56794
|
+
return "high";
|
|
56795
|
+
}
|
|
56763
56796
|
function irRequestToTwpWire(request, opts = {}) {
|
|
56764
56797
|
const sendImages = opts.sendImages ?? false;
|
|
56765
56798
|
const cacheHints = opts.cacheHints ?? false;
|
|
@@ -56796,7 +56829,12 @@ function irRequestToTwpWire(request, opts = {}) {
|
|
|
56796
56829
|
// ——服务端缺席语义 = 仅既有输出钳制,零行为变化
|
|
56797
56830
|
...request.promptTokensEstimate !== void 0 && Math.ceil(request.promptTokensEstimate) >= 1 ? { promptTokensEstimate: Math.ceil(request.promptTokensEstimate) } : {},
|
|
56798
56831
|
// RFC-M3 B2:思考关断出线(门开 × IR off 双判;门关恒不落键零漂移)
|
|
56799
|
-
...opts.reasoningOff === true && request.thinking?.off === true ? { reasoning: "off" } :
|
|
56832
|
+
...opts.reasoningOff === true && request.thinking?.off === true ? { reasoning: "off" } : (
|
|
56833
|
+
// S-TH1:思考开启出线(门开 × IR budget 双判;off 恒胜 budget)——
|
|
56834
|
+
// budget → 档位反查(EFFORT_THINKING_BUDGET 同族阈值:≤1024 low /
|
|
56835
|
+
// ≤4096 medium / 其余 high),网关按方言翻译
|
|
56836
|
+
opts.reasoningLevels === true && request.thinking?.off !== true && typeof request.thinking?.budget === "number" && request.thinking.budget > 0 ? { reasoning: reasoningLevelOfBudget(request.thinking.budget) } : {}
|
|
56837
|
+
)
|
|
56800
56838
|
},
|
|
56801
56839
|
meta: {
|
|
56802
56840
|
requestId: opts.requestId ?? ulid(),
|
|
@@ -57064,6 +57102,13 @@ var TwpStreamAssembler = class {
|
|
|
57064
57102
|
out.push({ t: "text_delta", index: i, text: v });
|
|
57065
57103
|
return out;
|
|
57066
57104
|
}
|
|
57105
|
+
if (kind === "thinking") {
|
|
57106
|
+
const v = record["v"];
|
|
57107
|
+
if (typeof v !== "string") return out;
|
|
57108
|
+
out.push(...this.#ensureBlock(i, "thinking", record));
|
|
57109
|
+
out.push({ t: "thinking_delta", index: i, text: v });
|
|
57110
|
+
return out;
|
|
57111
|
+
}
|
|
57067
57112
|
if (kind === "tool_use") {
|
|
57068
57113
|
out.push(...this.#ensureBlock(i, "tool_use", record));
|
|
57069
57114
|
const vJson = record["vJson"];
|
|
@@ -57087,6 +57132,8 @@ var TwpStreamAssembler = class {
|
|
|
57087
57132
|
}
|
|
57088
57133
|
if (kind === "text") {
|
|
57089
57134
|
out.push({ t: "block_start", index: i, block: { t: "text", text: "" } });
|
|
57135
|
+
} else if (kind === "thinking") {
|
|
57136
|
+
out.push({ t: "block_start", index: i, block: { t: "thinking", text: "" } });
|
|
57090
57137
|
} else {
|
|
57091
57138
|
out.push({
|
|
57092
57139
|
t: "block_start",
|
|
@@ -57216,6 +57263,7 @@ var TwpAdapter = class {
|
|
|
57216
57263
|
);
|
|
57217
57264
|
const cacheHints = sendableTwpCacheHints(this.#options.features?.());
|
|
57218
57265
|
const reasoningOff = sendableTwpReasoningOff(this.#options.features?.());
|
|
57266
|
+
const reasoningLevels = sendableTwpReasoningContent(this.#options.features?.());
|
|
57219
57267
|
try {
|
|
57220
57268
|
body = JSON.stringify(
|
|
57221
57269
|
irRequestToTwpWire(request, {
|
|
@@ -57227,7 +57275,8 @@ var TwpAdapter = class {
|
|
|
57227
57275
|
...sendImages ? { sendImages } : {},
|
|
57228
57276
|
...cacheHints ? { cacheHints } : {},
|
|
57229
57277
|
...cacheHints && platformSessionId !== void 0 ? { cacheKey: platformSessionId } : {},
|
|
57230
|
-
...reasoningOff ? { reasoningOff } : {}
|
|
57278
|
+
...reasoningOff ? { reasoningOff } : {},
|
|
57279
|
+
...reasoningLevels ? { reasoningLevels } : {}
|
|
57231
57280
|
})
|
|
57232
57281
|
);
|
|
57233
57282
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tansr/serve",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Tansr agent session server: the bare /v2 agent-session protocol engine (REST + SSE) you embed in your own Node service. Session auth is fully yours via the authenticate seam. Published as @tansr/serve (decided 2026-09-01); the pack script stamps the publish name into the tarball.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|