@tansr/sdk 0.7.0 → 0.7.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.
- package/dist/index.js +27 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32075,10 +32075,30 @@ function validateTokenTierOptions(api, options) {
|
|
|
32075
32075
|
);
|
|
32076
32076
|
}
|
|
32077
32077
|
}
|
|
32078
|
+
async function fetchTwpFeatures(base, token, fetchImpl, sessionId) {
|
|
32079
|
+
try {
|
|
32080
|
+
const response = await fetchImpl(`${base}${TWP_ENDPOINT_PATHS.heartbeat}`, {
|
|
32081
|
+
method: "POST",
|
|
32082
|
+
headers: {
|
|
32083
|
+
"content-type": "application/json",
|
|
32084
|
+
accept: "application/json",
|
|
32085
|
+
[HEADER_APP_TOKEN]: token
|
|
32086
|
+
},
|
|
32087
|
+
body: JSON.stringify({ client: "sdk", ...sessionId !== void 0 ? { sessionId } : {} })
|
|
32088
|
+
});
|
|
32089
|
+
if (!response.ok) return void 0;
|
|
32090
|
+
const raw = await response.json();
|
|
32091
|
+
const features = raw?.features;
|
|
32092
|
+
return Array.isArray(features) ? features.filter((f) => typeof f === "string") : void 0;
|
|
32093
|
+
} catch {
|
|
32094
|
+
return void 0;
|
|
32095
|
+
}
|
|
32096
|
+
}
|
|
32078
32097
|
async function assemblePlatformModel(options) {
|
|
32079
32098
|
const base = options.baseUrl.replace(/\/+$/, "");
|
|
32080
32099
|
const innerFetch = options.fetchImpl ?? fetch;
|
|
32081
32100
|
const url = `${base}${TWP_ENDPOINT_PATHS.config}`;
|
|
32101
|
+
const featuresPromise = fetchTwpFeatures(base, options.token, innerFetch, options.sessionId?.());
|
|
32082
32102
|
let response;
|
|
32083
32103
|
try {
|
|
32084
32104
|
response = await innerFetch(url, {
|
|
@@ -32115,13 +32135,18 @@ async function assemblePlatformModel(options) {
|
|
|
32115
32135
|
`App config bundle from ${url} has an unexpected shape. Check that "baseUrl" points to the tansr API.`
|
|
32116
32136
|
);
|
|
32117
32137
|
}
|
|
32138
|
+
const features = await featuresPromise;
|
|
32118
32139
|
const registry = new ProviderRegistry(appBundleRegistryConfig(bundle, base), {
|
|
32119
32140
|
// 占位哑值:满足装配期 readApiKey 非空校验;真实鉴权恒由 fetch 包装注入
|
|
32120
32141
|
env: { [APP_TOKEN_PLACEHOLDER_ENV]: APP_TOKEN_PLACEHOLDER_VALUE },
|
|
32121
32142
|
fetchImpl: createAppTokenFetch(options.token, options.fetchImpl),
|
|
32122
32143
|
// 拍板⑤:平台会话 id 供给经既有 TwpClientOptions.sessionId 缝出线——
|
|
32123
|
-
// registry 为会话私有(每次装配新建),setModel/Task
|
|
32124
|
-
|
|
32144
|
+
// registry 为会话私有(每次装配新建),setModel/Task 子代理同缝同值。
|
|
32145
|
+
// S-TH3:features 能力串同缝供给(闭包定格;undefined = 门全关同现状)
|
|
32146
|
+
twp: {
|
|
32147
|
+
...options.sessionId !== void 0 ? { sessionId: options.sessionId } : {},
|
|
32148
|
+
features: () => features
|
|
32149
|
+
}
|
|
32125
32150
|
});
|
|
32126
32151
|
const built = buildClientFromRegistry(registry, options.model ?? "main", options.onProviderSelected);
|
|
32127
32152
|
return { ...built, registry, capabilities: bundle.capabilities, platformModels: bundle.platformModels };
|
package/package.json
CHANGED