@tansr/serve 0.3.0 → 0.3.1

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
@@ -60556,10 +60556,30 @@ function createAppTokenFetch(token, inner) {
60556
60556
  };
60557
60557
  return wrapped;
60558
60558
  }
60559
+ async function fetchTwpFeatures(base, token, fetchImpl, sessionId) {
60560
+ try {
60561
+ const response = await fetchImpl(`${base}${TWP_ENDPOINT_PATHS.heartbeat}`, {
60562
+ method: "POST",
60563
+ headers: {
60564
+ "content-type": "application/json",
60565
+ accept: "application/json",
60566
+ [HEADER_APP_TOKEN]: token
60567
+ },
60568
+ body: JSON.stringify({ client: "sdk", ...sessionId !== void 0 ? { sessionId } : {} })
60569
+ });
60570
+ if (!response.ok) return void 0;
60571
+ const raw = await response.json();
60572
+ const features = raw?.features;
60573
+ return Array.isArray(features) ? features.filter((f) => typeof f === "string") : void 0;
60574
+ } catch {
60575
+ return void 0;
60576
+ }
60577
+ }
60559
60578
  async function assemblePlatformModel(options) {
60560
60579
  const base = options.baseUrl.replace(/\/+$/, "");
60561
60580
  const innerFetch = options.fetchImpl ?? fetch;
60562
60581
  const url = `${base}${TWP_ENDPOINT_PATHS.config}`;
60582
+ const featuresPromise = fetchTwpFeatures(base, options.token, innerFetch, options.sessionId?.());
60563
60583
  let response;
60564
60584
  try {
60565
60585
  response = await innerFetch(url, {
@@ -60596,13 +60616,18 @@ async function assemblePlatformModel(options) {
60596
60616
  `App config bundle from ${url} has an unexpected shape. Check that "baseUrl" points to the tansr API.`
60597
60617
  );
60598
60618
  }
60619
+ const features = await featuresPromise;
60599
60620
  const registry = new ProviderRegistry(appBundleRegistryConfig(bundle, base), {
60600
60621
  // 占位哑值:满足装配期 readApiKey 非空校验;真实鉴权恒由 fetch 包装注入
60601
60622
  env: { [APP_TOKEN_PLACEHOLDER_ENV]: APP_TOKEN_PLACEHOLDER_VALUE },
60602
60623
  fetchImpl: createAppTokenFetch(options.token, options.fetchImpl),
60603
60624
  // 拍板⑤:平台会话 id 供给经既有 TwpClientOptions.sessionId 缝出线——
60604
- // registry 为会话私有(每次装配新建),setModel/Task 子代理同缝同值
60605
- ...options.sessionId !== void 0 ? { twp: { sessionId: options.sessionId } } : {}
60625
+ // registry 为会话私有(每次装配新建),setModel/Task 子代理同缝同值。
60626
+ // S-TH3:features 能力串同缝供给(闭包定格;undefined = 门全关同现状)
60627
+ twp: {
60628
+ ...options.sessionId !== void 0 ? { sessionId: options.sessionId } : {},
60629
+ features: () => features
60630
+ }
60606
60631
  });
60607
60632
  const built = buildClientFromRegistry(registry, options.model ?? "main", options.onProviderSelected);
60608
60633
  return { ...built, registry, capabilities: bundle.capabilities, platformModels: bundle.platformModels };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tansr/serve",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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",