@acosmi/sdk-ts 2.7.0 → 2.9.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.
@@ -1261,10 +1261,17 @@ async function authorize(meta, clientID, scopes, opts = {}) {
1261
1261
  codeRejecter(new Error(`authorization denied: ${errMsg}`));
1262
1262
  return;
1263
1263
  }
1264
- res.setHeader("Content-Type", "text/html; charset=utf-8");
1265
- res.end(
1266
- `<!DOCTYPE html><html><head><meta charset="utf-8"><title>\u6388\u6743\u6210\u529F</title></head><body style="font-family:system-ui,sans-serif;text-align:center;padding:60px 20px"><h2>\u6388\u6743\u6210\u529F</h2><p>\u5DF2\u5B8C\u6210\u8EAB\u4EFD\u8BA4\u8BC1, \u8BF7\u8FD4\u56DE\u5E94\u7528\u7EE7\u7EED\u4F7F\u7528\u3002</p><p style="color:#888;font-size:14px">\u6B64\u7A97\u53E3\u5C06\u5728 3 \u79D2\u540E\u81EA\u52A8\u5173\u95ED\u2026</p><script>setTimeout(function(){window.close()},3000)</script></body></html>`
1267
- );
1264
+ const successRedirect = resolveSuccessRedirect(opts.successRedirectURL);
1265
+ if (successRedirect) {
1266
+ res.statusCode = 302;
1267
+ res.setHeader("Location", successRedirect);
1268
+ res.end();
1269
+ } else {
1270
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
1271
+ res.end(
1272
+ `<!DOCTYPE html><html><head><meta charset="utf-8"><title>\u6388\u6743\u6210\u529F</title></head><body style="font-family:system-ui,sans-serif;text-align:center;padding:60px 20px"><h2>\u6388\u6743\u6210\u529F</h2><p>\u5DF2\u5B8C\u6210\u8EAB\u4EFD\u8BA4\u8BC1, \u8BF7\u8FD4\u56DE\u5E94\u7528\u7EE7\u7EED\u4F7F\u7528\u3002</p><p style="color:#888;font-size:14px">\u6B64\u7A97\u53E3\u5C06\u5728 3 \u79D2\u540E\u81EA\u52A8\u5173\u95ED\u2026</p><script>setTimeout(function(){window.close()},3000)</script></body></html>`
1273
+ );
1274
+ }
1268
1275
  codeResolver(code);
1269
1276
  });
1270
1277
  const authURL = new URL(meta.authorization_endpoint);
@@ -1326,6 +1333,16 @@ async function authorize(meta, clientID, scopes, opts = {}) {
1326
1333
  function htmlEscape(s) {
1327
1334
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1328
1335
  }
1336
+ function resolveSuccessRedirect(raw) {
1337
+ if (!raw) return null;
1338
+ try {
1339
+ const u = new URL(raw);
1340
+ if (u.protocol !== "http:" && u.protocol !== "https:") return null;
1341
+ return u.toString();
1342
+ } catch {
1343
+ return null;
1344
+ }
1345
+ }
1329
1346
  async function createWebAuthorizationRequest(meta, opts) {
1330
1347
  const verifier = await generateCodeVerifier();
1331
1348
  const challenge = await codeChallenge(verifier);
@@ -2664,8 +2681,8 @@ var Client = class _Client {
2664
2681
  * V30 二轮审计 D-P1-2: 此方法不返回 entitlement-filter-status header.
2665
2682
  * UI 想根据 fallback 状态显示降级提示, 请改调 listModelsWithStatus.
2666
2683
  */
2667
- async listModels(signal) {
2668
- const r = await this.listModelsWithStatus(signal);
2684
+ async listModels(signal, opts) {
2685
+ const r = await this.listModelsWithStatus(signal, opts);
2669
2686
  return r.models;
2670
2687
  }
2671
2688
  /**
@@ -2678,16 +2695,20 @@ var Client = class _Client {
2678
2695
  * - status === 'disabled-by-flag' → 不显示余量 (运维灰度中)
2679
2696
  * - status === '' (Unknown) → 老 nexus, 按老 v0.17 行为 (不显示 BucketInfo)
2680
2697
  */
2681
- async listModelsWithStatus(signal) {
2698
+ async listModelsWithStatus(signal, opts) {
2699
+ const includeLocked = opts?.includeLocked === true;
2700
+ const path = includeLocked ? "/managed-models?picker=1" : "/managed-models";
2682
2701
  const { result, headers } = await this.doJSONFull(
2683
2702
  "GET",
2684
- "/managed-models",
2703
+ path,
2685
2704
  null,
2686
2705
  signal
2687
2706
  );
2688
2707
  const normalized = normalizeInputModalities(result.data);
2689
- this.modelCache = normalized;
2690
- this.modelCacheTimeMs = Date.now();
2708
+ if (!includeLocked) {
2709
+ this.modelCache = normalized;
2710
+ this.modelCacheTimeMs = Date.now();
2711
+ }
2691
2712
  let status = "";
2692
2713
  if (headers) {
2693
2714
  const h = headers.get("X-Entitlement-Filter-Status");
@@ -2882,6 +2903,34 @@ var Client = class _Client {
2882
2903
  const { result } = await this.doJSONFullRaw("GET", endpoint, null, signal);
2883
2904
  return this.unwrapAPIResponse(result);
2884
2905
  }
2906
+ /**
2907
+ * 向量 (同步)。POST /managed-models/:id/embeddings
2908
+ *
2909
+ * 仅 capabilities.supports_embedding=true 的托管模型可用 (上游接 DashScope)。
2910
+ * 响应为 OpenAI /v1/embeddings 标准格式 (网关直通, 无 response.Success 包装)。
2911
+ *
2912
+ * @param modelID 向量托管模型 ID
2913
+ */
2914
+ async embeddings(modelID, req, signal) {
2915
+ const endpoint = `/managed-models/${encodeURIComponent(modelID)}/embeddings`;
2916
+ const { result } = await this.doJSONFullRaw("POST", endpoint, req, signal, CHAT_REQUEST_TIMEOUT_MS);
2917
+ return JSON.parse(new TextDecoder().decode(result));
2918
+ }
2919
+ /**
2920
+ * 重排序 (同步)。POST /managed-models/:id/rerank
2921
+ *
2922
+ * 仅 capabilities.supports_rerank=true 的托管模型可用 (上游接 DashScope)。
2923
+ * 统一扁平契约: { query, documents[], top_n?, return_documents?, instruct? };
2924
+ * 响应 { results: [{ index, relevance_score, document? }], usage, model }
2925
+ * (网关已把上游原生/OpenAI 兼容两线路归一化, 无 response.Success 包装)。
2926
+ *
2927
+ * @param modelID 重排序托管模型 ID
2928
+ */
2929
+ async rerank(modelID, req, signal) {
2930
+ const endpoint = `/managed-models/${encodeURIComponent(modelID)}/rerank`;
2931
+ const { result } = await this.doJSONFullRaw("POST", endpoint, req, signal, CHAT_REQUEST_TIMEOUT_MS);
2932
+ return JSON.parse(new TextDecoder().decode(result));
2933
+ }
2885
2934
  /**
2886
2935
  * Anthropic 原生格式同步聊天
2887
2936
  * v0.5.0: 根据 provider 自动路由