@tansr/serve 0.3.1 → 0.4.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 CHANGED
@@ -9825,6 +9825,62 @@ interface ServeSessionFactory extends SessionFactory {
9825
9825
  create(init: SessionInit, extras?: ServeSessionExtras): ServeSessionDriver;
9826
9826
  }
9827
9827
 
9828
+ interface CreateAppTokenMinterOptions {
9829
+ /** 平台 API 基址(尾斜杠归一) */
9830
+ apiBaseUrl: string;
9831
+ /** 平台「应用」公开标识(= api_keys.public_id;AK 头) */
9832
+ appId: string;
9833
+ /** 平台「应用」主密钥(SK 头 + 签名钥派生;恒不出本闭包) */
9834
+ appKey: string;
9835
+ /** 换发令牌 TTL(秒;缺省 3600,契约边界 60–86400 钳制) */
9836
+ ttlSeconds?: number;
9837
+ fetchImpl?: typeof fetch;
9838
+ now?: () => number;
9839
+ }
9840
+ interface AppTokenMinter {
9841
+ /** 取 endUserId 的现值令牌(缓存命中直返;临期/缺席铸新,在飞去重) */
9842
+ tokenFor(endUserId: string): Promise<string>;
9843
+ }
9844
+ /**
9845
+ * per-endUser app_user 令牌铸造器:appkey 双头 + TWP 签名三头(providers
9846
+ * 签名件原样复用)POST /v1/app-tokens;失败结构化上抛(状态码 + 平台错误
9847
+ * 码,恒不携凭据与令牌本体)。
9848
+ */
9849
+ declare function createAppTokenMinter(options: CreateAppTokenMinterOptions): AppTokenMinter;
9850
+ interface CreatePlatformSessionAssemblerOptions {
9851
+ minter: AppTokenMinter;
9852
+ /** 平台 API 基址(bundle 拉取与 twp 消费同基址) */
9853
+ apiBaseUrl: string;
9854
+ fetchImpl?: typeof fetch;
9855
+ /**
9856
+ * S-ARCH P2 — 平台提示帧承接(t.warn:thinking_unavailable_on_face/
9857
+ * balance_low 等;SDK onPlatformWarning 同源语义)。缺席缺省 console.warn
9858
+ * 每 (endUser, code) 一次(告知恒不静默蒸发);在场即全量接管。
9859
+ * 注:向端上(/v2 SSE)转发需新控制帧,系 doc/98 冻结面增笔——候拍,
9860
+ * 本缝先保证服务端可观测与宿主可编程。
9861
+ */
9862
+ onPlatformWarning?: (warning: {
9863
+ endUserId: string;
9864
+ sessionId: string;
9865
+ code: string;
9866
+ message: string;
9867
+ }) => void;
9868
+ }
9869
+ interface PlatformSessionAssemblerInput {
9870
+ endUserId: string;
9871
+ sessionId: string;
9872
+ /** 会话请求的模型别名(bundle aliases/目录 handle;缺省 'main') */
9873
+ model?: string;
9874
+ }
9875
+ /**
9876
+ * per-endUser 平台令牌档装配缝实现(agent-session-factory
9877
+ * assembleEndUserModel 消费):铸/取该 endUser 现值令牌 → SDK
9878
+ * assemblePlatformModel(bundle → registry;per-会话平台 ULID 经既有
9879
+ * twp sessionId 缝出线)→ 返回逐会话装配器(别名解析走 bundle registry;
9880
+ * Task 三档降档同表)。刷新 fetch 覆写令牌头,跨时效长会话自续。
9881
+ */
9882
+ declare function createPlatformSessionAssembler(options: CreatePlatformSessionAssemblerOptions): (input: PlatformSessionAssemblerInput) => Promise<SessionModelAssembler>;
9883
+
9828
9884
  /**
9829
9885
  * A 案 — 平台内置形 serve 内层工厂(用户拍板 2026-09-01:真平台装配内置
9830
9886
  * 进 serve,做实五形态边界)。
@@ -9906,6 +9962,12 @@ interface PlatformAgentSessionOptions {
9906
9962
  maxTurnsPerQuery?: number;
9907
9963
  /** runQuery 注入缝(测试脚本化;透传平台内层工厂) */
9908
9964
  runQueryImpl?: Parameters<typeof createPlatformServeSessionFactory>[0]['runQueryImpl'];
9965
+ /**
9966
+ * S-ARCH P2 — 平台提示帧承接(t.warn;透传装配缝,语义同 SDK
9967
+ * onPlatformWarning):缺席缺省 console.warn 每 (endUser, code) 一次。
9968
+ * 向 /v2 端上转发需新控制帧(doc/98 冻结面增笔),候拍不代拍。
9969
+ */
9970
+ onPlatformWarning?: Parameters<typeof createPlatformSessionAssembler>[0]['onPlatformWarning'];
9909
9971
  }
9910
9972
  interface CreateAgentSessionFactoryOptions {
9911
9973
  /**
@@ -10000,49 +10062,6 @@ interface RemoteToolBuild {
10000
10062
  */
10001
10063
  declare function buildRemoteTool(decl: ClientToolDecl, bridge: AgentSessionBridge, now?: () => number): RemoteToolBuild;
10002
10064
 
10003
- interface CreateAppTokenMinterOptions {
10004
- /** 平台 API 基址(尾斜杠归一) */
10005
- apiBaseUrl: string;
10006
- /** 平台「应用」公开标识(= api_keys.public_id;AK 头) */
10007
- appId: string;
10008
- /** 平台「应用」主密钥(SK 头 + 签名钥派生;恒不出本闭包) */
10009
- appKey: string;
10010
- /** 换发令牌 TTL(秒;缺省 3600,契约边界 60–86400 钳制) */
10011
- ttlSeconds?: number;
10012
- fetchImpl?: typeof fetch;
10013
- now?: () => number;
10014
- }
10015
- interface AppTokenMinter {
10016
- /** 取 endUserId 的现值令牌(缓存命中直返;临期/缺席铸新,在飞去重) */
10017
- tokenFor(endUserId: string): Promise<string>;
10018
- }
10019
- /**
10020
- * per-endUser app_user 令牌铸造器:appkey 双头 + TWP 签名三头(providers
10021
- * 签名件原样复用)POST /v1/app-tokens;失败结构化上抛(状态码 + 平台错误
10022
- * 码,恒不携凭据与令牌本体)。
10023
- */
10024
- declare function createAppTokenMinter(options: CreateAppTokenMinterOptions): AppTokenMinter;
10025
- interface CreatePlatformSessionAssemblerOptions {
10026
- minter: AppTokenMinter;
10027
- /** 平台 API 基址(bundle 拉取与 twp 消费同基址) */
10028
- apiBaseUrl: string;
10029
- fetchImpl?: typeof fetch;
10030
- }
10031
- interface PlatformSessionAssemblerInput {
10032
- endUserId: string;
10033
- sessionId: string;
10034
- /** 会话请求的模型别名(bundle aliases/目录 handle;缺省 'main') */
10035
- model?: string;
10036
- }
10037
- /**
10038
- * per-endUser 平台令牌档装配缝实现(agent-session-factory
10039
- * assembleEndUserModel 消费):铸/取该 endUser 现值令牌 → SDK
10040
- * assemblePlatformModel(bundle → registry;per-会话平台 ULID 经既有
10041
- * twp sessionId 缝出线)→ 返回逐会话装配器(别名解析走 bundle registry;
10042
- * Task 三档降档同表)。刷新 fetch 覆写令牌头,跨时效长会话自续。
10043
- */
10044
- declare function createPlatformSessionAssembler(options: CreatePlatformSessionAssemblerOptions): (input: PlatformSessionAssemblerInput) => Promise<SessionModelAssembler>;
10045
-
10046
10065
  /**
10047
10066
  * /v2 装配半场 i18n 消息键(A 案下沉 2026-09-01)。
10048
10067
  *
package/dist/index.js CHANGED
@@ -56935,7 +56935,11 @@ function twpErrorToIR(code, message, detail) {
56935
56935
  return {
56936
56936
  kind: mapped.kind,
56937
56937
  message: text,
56938
- recoverable: mapped.recoverable,
56938
+ // S-TH4(2026-09-01):服务端确定性拒绝声明恒胜码表——detail.retryable
56939
+ // === false 即不可恢复(上游 4xx 同参重发恒同拒;gpt-5.6-sol 实证
56940
+ // reasoning_effort×tools 400 被 upstream_error 码表重试 14 次的风暴止血)。
56941
+ // 加法容忍:键缺席/异型恒走码表现状。
56942
+ recoverable: detail?.["retryable"] === false ? false : mapped.recoverable,
56939
56943
  ...retryAfterMs !== void 0 ? { retryAfterMs } : {}
56940
56944
  };
56941
56945
  }
@@ -60626,7 +60630,8 @@ async function assemblePlatformModel(options) {
60626
60630
  // S-TH3:features 能力串同缝供给(闭包定格;undefined = 门全关同现状)
60627
60631
  twp: {
60628
60632
  ...options.sessionId !== void 0 ? { sessionId: options.sessionId } : {},
60629
- features: () => features
60633
+ features: () => features,
60634
+ ...options.onWarn !== void 0 ? { onWarn: options.onWarn } : {}
60630
60635
  }
60631
60636
  });
60632
60637
  const built = buildClientFromRegistry(registry, options.model ?? "main", options.onProviderSelected);
@@ -60709,6 +60714,13 @@ function createAppTokenMinter(options) {
60709
60714
  };
60710
60715
  }
60711
60716
  function createPlatformSessionAssembler(options) {
60717
+ const warnedDefault = /* @__PURE__ */ new Set();
60718
+ const deliverWarning = options.onPlatformWarning ?? ((w) => {
60719
+ const key2 = `${w.endUserId}\0${w.code}`;
60720
+ if (warnedDefault.has(key2)) return;
60721
+ warnedDefault.add(key2);
60722
+ console.warn(`[tansr-serve] platform warning ${w.code} (endUser=${w.endUserId}): ${w.message}`);
60723
+ });
60712
60724
  return async (input) => {
60713
60725
  const initialToken = await options.minter.tokenFor(input.endUserId);
60714
60726
  const platformSessionId = ulid();
@@ -60725,7 +60737,15 @@ function createPlatformSessionAssembler(options) {
60725
60737
  baseUrl: options.apiBaseUrl,
60726
60738
  ...input.model !== void 0 ? { model: input.model } : {},
60727
60739
  fetchImpl: refreshingFetch,
60728
- sessionId: () => platformSessionId
60740
+ sessionId: () => platformSessionId,
60741
+ // S-ARCH P2:平台提示帧经 SDK onWarn 缝出线,携会话归属(serve 面
60742
+ // per-会话装配,归属天然可判——CLI 进程级电台的「无从归属」不适用此径)
60743
+ onWarn: (warn) => deliverWarning({
60744
+ endUserId: input.endUserId,
60745
+ sessionId: input.sessionId,
60746
+ code: warn.code,
60747
+ message: warn.message
60748
+ })
60729
60749
  });
60730
60750
  return (alias, onProviderSelected) => {
60731
60751
  const built = buildClientFromRegistry(platform.registry, alias, onProviderSelected);
@@ -61264,7 +61284,8 @@ function createAgentSessionFactory(options) {
61264
61284
  assembleEndUserModel = createPlatformSessionAssembler({
61265
61285
  minter,
61266
61286
  apiBaseUrl: platform.apiBaseUrl,
61267
- ...platform.fetchImpl !== void 0 ? { fetchImpl: platform.fetchImpl } : {}
61287
+ ...platform.fetchImpl !== void 0 ? { fetchImpl: platform.fetchImpl } : {},
61288
+ ...platform.onPlatformWarning !== void 0 ? { onPlatformWarning: platform.onPlatformWarning } : {}
61268
61289
  });
61269
61290
  innerFactory = createPlatformServeSessionFactory({
61270
61291
  cwd: options.cwd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tansr/serve",
3
- "version": "0.3.1",
3
+ "version": "0.4.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",