@tansr/serve 0.1.0 → 0.3.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.d.ts +42 -2
- package/dist/index.js +68 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4397,7 +4397,24 @@ declare const CreateSessionBodySchema: z.ZodObject<{
|
|
|
4397
4397
|
readOnly?: boolean | undefined;
|
|
4398
4398
|
}>, "many">>;
|
|
4399
4399
|
capabilitiesProfile: z.ZodOptional<z.ZodString>;
|
|
4400
|
+
/**
|
|
4401
|
+
* S-TH2(用户拍板 2026-09-01,doc/98 冻结面加法):思考生成(生成面旋钮)
|
|
4402
|
+
* ——逐轮透传内核 IRRequest.thinking(budget = 思考 token 预算,按模型
|
|
4403
|
+
* 方言映射;平台令牌档经 TWP reasoning 档位出线,S-TH1)。缺席 = 装配面
|
|
4404
|
+
* 缺省(工厂 thinking 选项),两级皆缺席恒不注入(现状零漂移)。思考的
|
|
4405
|
+
* 呈现走客户端 SessionView delivery(呈现面),与本键正交。
|
|
4406
|
+
*/
|
|
4407
|
+
thinking: z.ZodOptional<z.ZodObject<{
|
|
4408
|
+
budget: z.ZodOptional<z.ZodNumber>;
|
|
4409
|
+
}, "strip", z.ZodTypeAny, {
|
|
4410
|
+
budget?: number | undefined;
|
|
4411
|
+
}, {
|
|
4412
|
+
budget?: number | undefined;
|
|
4413
|
+
}>>;
|
|
4400
4414
|
}, "strip", z.ZodTypeAny, {
|
|
4415
|
+
thinking?: {
|
|
4416
|
+
budget?: number | undefined;
|
|
4417
|
+
} | undefined;
|
|
4401
4418
|
model?: string | undefined;
|
|
4402
4419
|
tools?: string[] | undefined;
|
|
4403
4420
|
budget?: {
|
|
@@ -4422,6 +4439,9 @@ declare const CreateSessionBodySchema: z.ZodObject<{
|
|
|
4422
4439
|
}[] | undefined;
|
|
4423
4440
|
capabilitiesProfile?: string | undefined;
|
|
4424
4441
|
}, {
|
|
4442
|
+
thinking?: {
|
|
4443
|
+
budget?: number | undefined;
|
|
4444
|
+
} | undefined;
|
|
4425
4445
|
model?: string | undefined;
|
|
4426
4446
|
tools?: string[] | undefined;
|
|
4427
4447
|
budget?: {
|
|
@@ -4815,6 +4835,10 @@ interface AgentSessionCreateInit {
|
|
|
4815
4835
|
resume?: {
|
|
4816
4836
|
sessionId: string;
|
|
4817
4837
|
};
|
|
4838
|
+
/** S-TH2:思考生成(生成面;缺席 = 装配面缺省,两级皆缺席恒不注入) */
|
|
4839
|
+
thinking?: {
|
|
4840
|
+
budget?: number;
|
|
4841
|
+
};
|
|
4818
4842
|
}
|
|
4819
4843
|
interface AgentSessionCreateResult {
|
|
4820
4844
|
handle: AgentSessionHandle;
|
|
@@ -4916,6 +4940,14 @@ interface SessionInit {
|
|
|
4916
4940
|
maxUsd?: number;
|
|
4917
4941
|
maxTokens?: number;
|
|
4918
4942
|
};
|
|
4943
|
+
/**
|
|
4944
|
+
* S-TH2(2026-09-01):思考生成(生成面旋钮)——逐轮透传 IRRequest.thinking。
|
|
4945
|
+
* 优先级:本键(wire,per-会话)> 装配面缺省(工厂选项/profile effort)>
|
|
4946
|
+
* 恒不注入(现状)。
|
|
4947
|
+
*/
|
|
4948
|
+
thinking?: {
|
|
4949
|
+
budget?: number;
|
|
4950
|
+
};
|
|
4919
4951
|
}
|
|
4920
4952
|
/**
|
|
4921
4953
|
* 会话句柄——装配层对内核会话的最小操控面。
|
|
@@ -9522,8 +9554,9 @@ interface ServeSessionDriverOptions {
|
|
|
9522
9554
|
/** 缺省 8192 */
|
|
9523
9555
|
maxTokens?: number;
|
|
9524
9556
|
/**
|
|
9525
|
-
*
|
|
9526
|
-
*
|
|
9557
|
+
* 思考预算:逐轮透传 runQuery → IRRequest.thinking。取值三级(S-TH2
|
|
9558
|
+
* 用户拍板 2026-09-01):wire thinking 键(per-会话)> 装配面缺省(平台
|
|
9559
|
+
* 形工厂 options.thinking / cli 形 profile effort 档)> 缺席恒不注入。
|
|
9527
9560
|
*/
|
|
9528
9561
|
thinking?: {
|
|
9529
9562
|
budget?: number;
|
|
@@ -9830,6 +9863,13 @@ interface PlatformServeSessionFactoryOptions {
|
|
|
9830
9863
|
maxTokens?: number;
|
|
9831
9864
|
/** 单轮 modelTurns 上限(防失控;缺省不设) */
|
|
9832
9865
|
maxTurnsPerQuery?: number;
|
|
9866
|
+
/**
|
|
9867
|
+
* S-TH2(用户拍板 2026-09-01):装配面思考生成缺省(serve 旋钮)——
|
|
9868
|
+
* 会话未带 wire thinking 键时的兜底;wire 键恒胜。两级皆缺席恒不注入。
|
|
9869
|
+
*/
|
|
9870
|
+
thinking?: {
|
|
9871
|
+
budget?: number;
|
|
9872
|
+
};
|
|
9833
9873
|
/** runQuery 注入缝(测试脚本化;缺省 kernel runQuery) */
|
|
9834
9874
|
runQueryImpl?: typeof runQuery;
|
|
9835
9875
|
}
|
package/dist/index.js
CHANGED
|
@@ -37955,7 +37955,15 @@ var CreateSessionBodySchema = z11.object({
|
|
|
37955
37955
|
endUser: z11.object({ id: z11.string().regex(END_USER_ID_PATTERN) }).optional(),
|
|
37956
37956
|
resume: z11.object({ sessionId: z11.string().min(1) }).optional(),
|
|
37957
37957
|
clientTools: z11.array(ClientToolDeclSchema).max(V2_LIMITS.maxClientTools).optional(),
|
|
37958
|
-
capabilitiesProfile: z11.string().min(1).optional()
|
|
37958
|
+
capabilitiesProfile: z11.string().min(1).optional(),
|
|
37959
|
+
/**
|
|
37960
|
+
* S-TH2(用户拍板 2026-09-01,doc/98 冻结面加法):思考生成(生成面旋钮)
|
|
37961
|
+
* ——逐轮透传内核 IRRequest.thinking(budget = 思考 token 预算,按模型
|
|
37962
|
+
* 方言映射;平台令牌档经 TWP reasoning 档位出线,S-TH1)。缺席 = 装配面
|
|
37963
|
+
* 缺省(工厂 thinking 选项),两级皆缺席恒不注入(现状零漂移)。思考的
|
|
37964
|
+
* 呈现走客户端 SessionView delivery(呈现面),与本键正交。
|
|
37965
|
+
*/
|
|
37966
|
+
thinking: z11.object({ budget: z11.number().int().positive().optional() }).optional()
|
|
37959
37967
|
});
|
|
37960
37968
|
var MessageBlockSchema = z11.discriminatedUnion("t", [
|
|
37961
37969
|
z11.object({ t: z11.literal("text"), text: z11.string().min(1).max(V2_LIMITS.textBlockMaxChars) }),
|
|
@@ -38337,6 +38345,26 @@ var AgentSessionRegistry = class {
|
|
|
38337
38345
|
}
|
|
38338
38346
|
};
|
|
38339
38347
|
|
|
38348
|
+
// src/v2/history-projection.ts
|
|
38349
|
+
var REMINDER_OPEN = "<system-reminder>";
|
|
38350
|
+
var REMINDER_CLOSE = "</system-reminder>";
|
|
38351
|
+
function isReminderBlock(block) {
|
|
38352
|
+
return block.t === "text" && block.text.startsWith(REMINDER_OPEN) && block.text.endsWith(REMINDER_CLOSE);
|
|
38353
|
+
}
|
|
38354
|
+
function stripReminderBlocks(messages) {
|
|
38355
|
+
const out = [];
|
|
38356
|
+
for (const message of messages) {
|
|
38357
|
+
if (message.role !== "user" || !message.blocks.some(isReminderBlock)) {
|
|
38358
|
+
out.push(message);
|
|
38359
|
+
continue;
|
|
38360
|
+
}
|
|
38361
|
+
const blocks = message.blocks.filter((block) => !isReminderBlock(block));
|
|
38362
|
+
if (blocks.length === 0) continue;
|
|
38363
|
+
out.push({ ...message, blocks });
|
|
38364
|
+
}
|
|
38365
|
+
return out;
|
|
38366
|
+
}
|
|
38367
|
+
|
|
38340
38368
|
// src/v2/types.ts
|
|
38341
38369
|
var AgentSessionCreateError = class extends Error {
|
|
38342
38370
|
code;
|
|
@@ -38489,7 +38517,8 @@ function createAgentRoutesHandler(deps) {
|
|
|
38489
38517
|
...init.tools !== void 0 ? { tools: init.tools } : {},
|
|
38490
38518
|
...init.clientTools !== void 0 ? { clientTools: init.clientTools } : {},
|
|
38491
38519
|
...init.capabilitiesProfile !== void 0 ? { capabilitiesProfile: init.capabilitiesProfile } : {},
|
|
38492
|
-
...init.resume !== void 0 ? { resume: init.resume } : {}
|
|
38520
|
+
...init.resume !== void 0 ? { resume: init.resume } : {},
|
|
38521
|
+
...init.thinking !== void 0 ? { thinking: init.thinking } : {}
|
|
38493
38522
|
};
|
|
38494
38523
|
let handle;
|
|
38495
38524
|
let resumed;
|
|
@@ -38683,7 +38712,11 @@ function createAgentRoutesHandler(deps) {
|
|
|
38683
38712
|
if (record === "forbidden") return;
|
|
38684
38713
|
if (record !== "absent") {
|
|
38685
38714
|
const snapshot = record.handle.historySnapshot();
|
|
38686
|
-
sendJson(res, 200, {
|
|
38715
|
+
sendJson(res, 200, {
|
|
38716
|
+
sessionId,
|
|
38717
|
+
lastSeq: snapshot.lastSeq,
|
|
38718
|
+
messages: stripReminderBlocks(snapshot.messages)
|
|
38719
|
+
});
|
|
38687
38720
|
return;
|
|
38688
38721
|
}
|
|
38689
38722
|
let messages;
|
|
@@ -38699,7 +38732,7 @@ function createAgentRoutesHandler(deps) {
|
|
|
38699
38732
|
notFound(res, sessionId);
|
|
38700
38733
|
return;
|
|
38701
38734
|
}
|
|
38702
|
-
sendJson(res, 200, { sessionId, lastSeq: 0, messages });
|
|
38735
|
+
sendJson(res, 200, { sessionId, lastSeq: 0, messages: stripReminderBlocks(messages) });
|
|
38703
38736
|
};
|
|
38704
38737
|
const handleInterrupt = (res, sessionId, endUserId) => {
|
|
38705
38738
|
const record = ownedRecord(res, sessionId, endUserId);
|
|
@@ -56650,6 +56683,10 @@ var TWP_FEATURE_REASONING_OFF = "reasoning-off";
|
|
|
56650
56683
|
function sendableTwpReasoningOff(features) {
|
|
56651
56684
|
return features !== void 0 && features.includes(TWP_FEATURE_REASONING_OFF);
|
|
56652
56685
|
}
|
|
56686
|
+
var TWP_FEATURE_REASONING_CONTENT = "reasoning-content";
|
|
56687
|
+
function sendableTwpReasoningContent(features) {
|
|
56688
|
+
return features !== void 0 && features.includes(TWP_FEATURE_REASONING_CONTENT);
|
|
56689
|
+
}
|
|
56653
56690
|
|
|
56654
56691
|
// ../providers/src/twp/signing.ts
|
|
56655
56692
|
import { createHash as createHash11, createHmac as createHmac2, randomBytes } from "node:crypto";
|
|
@@ -56760,6 +56797,11 @@ function irMessageToTwp(message, sendImages) {
|
|
|
56760
56797
|
if (blocks.length === 0) return null;
|
|
56761
56798
|
return { role: message.role, blocks };
|
|
56762
56799
|
}
|
|
56800
|
+
function reasoningLevelOfBudget(budget) {
|
|
56801
|
+
if (budget <= 1024) return "low";
|
|
56802
|
+
if (budget <= 4096) return "medium";
|
|
56803
|
+
return "high";
|
|
56804
|
+
}
|
|
56763
56805
|
function irRequestToTwpWire(request, opts = {}) {
|
|
56764
56806
|
const sendImages = opts.sendImages ?? false;
|
|
56765
56807
|
const cacheHints = opts.cacheHints ?? false;
|
|
@@ -56796,7 +56838,12 @@ function irRequestToTwpWire(request, opts = {}) {
|
|
|
56796
56838
|
// ——服务端缺席语义 = 仅既有输出钳制,零行为变化
|
|
56797
56839
|
...request.promptTokensEstimate !== void 0 && Math.ceil(request.promptTokensEstimate) >= 1 ? { promptTokensEstimate: Math.ceil(request.promptTokensEstimate) } : {},
|
|
56798
56840
|
// RFC-M3 B2:思考关断出线(门开 × IR off 双判;门关恒不落键零漂移)
|
|
56799
|
-
...opts.reasoningOff === true && request.thinking?.off === true ? { reasoning: "off" } :
|
|
56841
|
+
...opts.reasoningOff === true && request.thinking?.off === true ? { reasoning: "off" } : (
|
|
56842
|
+
// S-TH1:思考开启出线(门开 × IR budget 双判;off 恒胜 budget)——
|
|
56843
|
+
// budget → 档位反查(EFFORT_THINKING_BUDGET 同族阈值:≤1024 low /
|
|
56844
|
+
// ≤4096 medium / 其余 high),网关按方言翻译
|
|
56845
|
+
opts.reasoningLevels === true && request.thinking?.off !== true && typeof request.thinking?.budget === "number" && request.thinking.budget > 0 ? { reasoning: reasoningLevelOfBudget(request.thinking.budget) } : {}
|
|
56846
|
+
)
|
|
56800
56847
|
},
|
|
56801
56848
|
meta: {
|
|
56802
56849
|
requestId: opts.requestId ?? ulid(),
|
|
@@ -57064,6 +57111,13 @@ var TwpStreamAssembler = class {
|
|
|
57064
57111
|
out.push({ t: "text_delta", index: i, text: v });
|
|
57065
57112
|
return out;
|
|
57066
57113
|
}
|
|
57114
|
+
if (kind === "thinking") {
|
|
57115
|
+
const v = record["v"];
|
|
57116
|
+
if (typeof v !== "string") return out;
|
|
57117
|
+
out.push(...this.#ensureBlock(i, "thinking", record));
|
|
57118
|
+
out.push({ t: "thinking_delta", index: i, text: v });
|
|
57119
|
+
return out;
|
|
57120
|
+
}
|
|
57067
57121
|
if (kind === "tool_use") {
|
|
57068
57122
|
out.push(...this.#ensureBlock(i, "tool_use", record));
|
|
57069
57123
|
const vJson = record["vJson"];
|
|
@@ -57087,6 +57141,8 @@ var TwpStreamAssembler = class {
|
|
|
57087
57141
|
}
|
|
57088
57142
|
if (kind === "text") {
|
|
57089
57143
|
out.push({ t: "block_start", index: i, block: { t: "text", text: "" } });
|
|
57144
|
+
} else if (kind === "thinking") {
|
|
57145
|
+
out.push({ t: "block_start", index: i, block: { t: "thinking", text: "" } });
|
|
57090
57146
|
} else {
|
|
57091
57147
|
out.push({
|
|
57092
57148
|
t: "block_start",
|
|
@@ -57216,6 +57272,7 @@ var TwpAdapter = class {
|
|
|
57216
57272
|
);
|
|
57217
57273
|
const cacheHints = sendableTwpCacheHints(this.#options.features?.());
|
|
57218
57274
|
const reasoningOff = sendableTwpReasoningOff(this.#options.features?.());
|
|
57275
|
+
const reasoningLevels = sendableTwpReasoningContent(this.#options.features?.());
|
|
57219
57276
|
try {
|
|
57220
57277
|
body = JSON.stringify(
|
|
57221
57278
|
irRequestToTwpWire(request, {
|
|
@@ -57227,7 +57284,8 @@ var TwpAdapter = class {
|
|
|
57227
57284
|
...sendImages ? { sendImages } : {},
|
|
57228
57285
|
...cacheHints ? { cacheHints } : {},
|
|
57229
57286
|
...cacheHints && platformSessionId !== void 0 ? { cacheKey: platformSessionId } : {},
|
|
57230
|
-
...reasoningOff ? { reasoningOff } : {}
|
|
57287
|
+
...reasoningOff ? { reasoningOff } : {},
|
|
57288
|
+
...reasoningLevels ? { reasoningLevels } : {}
|
|
57231
57289
|
})
|
|
57232
57290
|
);
|
|
57233
57291
|
} catch (err) {
|
|
@@ -61077,6 +61135,8 @@ function createPlatformServeSessionFactory(options) {
|
|
|
61077
61135
|
compaction: assembled.compaction ?? {},
|
|
61078
61136
|
...assembled.compactionManagerOptions !== void 0 ? { compactionManagerOptions: assembled.compactionManagerOptions } : {},
|
|
61079
61137
|
reminders: createReminderProvider({ todoStore }),
|
|
61138
|
+
// S-TH2:思考生成两级取值——wire 键(per-会话)恒胜装配面缺省
|
|
61139
|
+
...init.thinking !== void 0 ? { thinking: init.thinking } : options.thinking !== void 0 ? { thinking: options.thinking } : {},
|
|
61080
61140
|
...extras?.onTurnEnd !== void 0 ? { onTurnEnd: extras.onTurnEnd } : {},
|
|
61081
61141
|
...options.runQueryImpl !== void 0 ? { runQueryImpl: options.runQueryImpl } : {}
|
|
61082
61142
|
});
|
|
@@ -61278,7 +61338,8 @@ function createAgentSessionFactory(options) {
|
|
|
61278
61338
|
...init.profile !== void 0 ? { profile: init.profile } : {},
|
|
61279
61339
|
...init.labels !== void 0 ? { labels: init.labels } : {},
|
|
61280
61340
|
...init.budget !== void 0 ? { budget: init.budget } : {},
|
|
61281
|
-
...effectiveTools !== void 0 ? { tools: [...effectiveTools] } : {}
|
|
61341
|
+
...effectiveTools !== void 0 ? { tools: [...effectiveTools] } : {},
|
|
61342
|
+
...init.thinking !== void 0 ? { thinking: init.thinking } : {}
|
|
61282
61343
|
},
|
|
61283
61344
|
{
|
|
61284
61345
|
sessionId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tansr/serve",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|