@tansr/serve 0.3.2 → 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
@@ -60630,7 +60630,8 @@ async function assemblePlatformModel(options) {
60630
60630
  // S-TH3:features 能力串同缝供给(闭包定格;undefined = 门全关同现状)
60631
60631
  twp: {
60632
60632
  ...options.sessionId !== void 0 ? { sessionId: options.sessionId } : {},
60633
- features: () => features
60633
+ features: () => features,
60634
+ ...options.onWarn !== void 0 ? { onWarn: options.onWarn } : {}
60634
60635
  }
60635
60636
  });
60636
60637
  const built = buildClientFromRegistry(registry, options.model ?? "main", options.onProviderSelected);
@@ -60713,6 +60714,13 @@ function createAppTokenMinter(options) {
60713
60714
  };
60714
60715
  }
60715
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
+ });
60716
60724
  return async (input) => {
60717
60725
  const initialToken = await options.minter.tokenFor(input.endUserId);
60718
60726
  const platformSessionId = ulid();
@@ -60729,7 +60737,15 @@ function createPlatformSessionAssembler(options) {
60729
60737
  baseUrl: options.apiBaseUrl,
60730
60738
  ...input.model !== void 0 ? { model: input.model } : {},
60731
60739
  fetchImpl: refreshingFetch,
60732
- 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
+ })
60733
60749
  });
60734
60750
  return (alias, onProviderSelected) => {
60735
60751
  const built = buildClientFromRegistry(platform.registry, alias, onProviderSelected);
@@ -61268,7 +61284,8 @@ function createAgentSessionFactory(options) {
61268
61284
  assembleEndUserModel = createPlatformSessionAssembler({
61269
61285
  minter,
61270
61286
  apiBaseUrl: platform.apiBaseUrl,
61271
- ...platform.fetchImpl !== void 0 ? { fetchImpl: platform.fetchImpl } : {}
61287
+ ...platform.fetchImpl !== void 0 ? { fetchImpl: platform.fetchImpl } : {},
61288
+ ...platform.onPlatformWarning !== void 0 ? { onPlatformWarning: platform.onPlatformWarning } : {}
61272
61289
  });
61273
61290
  innerFactory = createPlatformServeSessionFactory({
61274
61291
  cwd: options.cwd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tansr/serve",
3
- "version": "0.3.2",
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",