@acosmi/sdk-ts 1.3.1 → 1.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/CHANGELOG.md +87 -0
- package/README.md +11 -3
- package/dist/browser/index.mjs +159 -15
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +159 -15
- package/dist/index.mjs.map +1 -1
- package/dist/node/adapters/anthropic.d.cts +1 -1
- package/dist/node/adapters/anthropic.d.ts +1 -1
- package/dist/node/adapters/openai.d.cts +1 -1
- package/dist/node/adapters/openai.d.ts +1 -1
- package/dist/node/{index-28x02ITB.d.cts → index-CbG9NqE-.d.cts} +1 -1
- package/dist/node/{index-28x02ITB.d.ts → index-CbG9NqE-.d.ts} +1 -1
- package/dist/node/index.cjs +166 -14
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +178 -11
- package/dist/node/index.d.ts +178 -11
- package/dist/node/index.mjs +159 -15
- package/dist/node/index.mjs.map +1 -1
- package/docs/compliance.md +36 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProviderAdapter, ak as ProviderFormat, c as ModelCapabilities, d as ChatRequest, e as ChatResponse, f as StreamEvent } from '../index-
|
|
1
|
+
import { P as ProviderAdapter, ak as ProviderFormat, c as ModelCapabilities, d as ChatRequest, e as ChatResponse, f as StreamEvent } from '../index-CbG9NqE-.cjs';
|
|
2
2
|
|
|
3
3
|
/** 实现 ProviderAdapter, 用于 Anthropic 原生模型 */
|
|
4
4
|
declare class AnthropicAdapter implements ProviderAdapter {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProviderAdapter, ak as ProviderFormat, c as ModelCapabilities, d as ChatRequest, e as ChatResponse, f as StreamEvent } from '../index-
|
|
1
|
+
import { P as ProviderAdapter, ak as ProviderFormat, c as ModelCapabilities, d as ChatRequest, e as ChatResponse, f as StreamEvent } from '../index-CbG9NqE-.js';
|
|
2
2
|
|
|
3
3
|
/** 实现 ProviderAdapter, 用于 Anthropic 原生模型 */
|
|
4
4
|
declare class AnthropicAdapter implements ProviderAdapter {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProviderAdapter, ak as ProviderFormat, c as ModelCapabilities, d as ChatRequest, e as ChatResponse, f as StreamEvent, A as AnthropicResponse } from '../index-
|
|
1
|
+
import { P as ProviderAdapter, ak as ProviderFormat, c as ModelCapabilities, d as ChatRequest, e as ChatResponse, f as StreamEvent, A as AnthropicResponse } from '../index-CbG9NqE-.cjs';
|
|
2
2
|
|
|
3
3
|
/** 实现 ProviderAdapter, 用于所有非 Anthropic 厂商 */
|
|
4
4
|
declare class OpenAIAdapter implements ProviderAdapter {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProviderAdapter, ak as ProviderFormat, c as ModelCapabilities, d as ChatRequest, e as ChatResponse, f as StreamEvent, A as AnthropicResponse } from '../index-
|
|
1
|
+
import { P as ProviderAdapter, ak as ProviderFormat, c as ModelCapabilities, d as ChatRequest, e as ChatResponse, f as StreamEvent, A as AnthropicResponse } from '../index-CbG9NqE-.js';
|
|
2
2
|
|
|
3
3
|
/** 实现 ProviderAdapter, 用于所有非 Anthropic 厂商 */
|
|
4
4
|
declare class OpenAIAdapter implements ProviderAdapter {
|
|
@@ -1024,4 +1024,4 @@ declare function getAdapter(provider: string): ProviderAdapter;
|
|
|
1024
1024
|
*/
|
|
1025
1025
|
declare function getAdapterForModel(m: ManagedModel): ProviderAdapter;
|
|
1026
1026
|
|
|
1027
|
-
export { type ChatUsage as $, type AnthropicResponse as A, BusinessError as B, type ClientRegistration as C, type ToolView as D, type EntitlementBalance as E, type DeviceRegistration as F, type GenerateSkillRequest as G, type NotificationPreference as H, type InputModality as I, type WSEvent as J, type APIResponse as K, type AnthropicContentBlock as L, type ManagedModel as M, type NotificationList as N, type Order as O, type ProviderAdapter as P, type QuotaSummary as Q, type AnthropicUsage as R, type ServerMetadata as S, type
|
|
1027
|
+
export { type ChatUsage as $, type AnthropicResponse as A, BusinessError as B, type ClientRegistration as C, type ToolView as D, type EntitlementBalance as E, type DeviceRegistration as F, type GenerateSkillRequest as G, type NotificationPreference as H, type InputModality as I, type WSEvent as J, type APIResponse as K, type AnthropicContentBlock as L, type ManagedModel as M, type NotificationList as N, type Order as O, type ProviderAdapter as P, type QuotaSummary as Q, type AnthropicUsage as R, type ServerMetadata as S, type TokenSet as T, BucketClassCommercial as U, BucketClassGeneric as V, type WalletStats as W, type BucketInfo as X, type BucketRow as Y, type ChatContentBlock as Z, type ChatMessage as _, type TokenResponse as a, type ConsumeRecord as a0, type EffortConfig as a1, type GeoLoc as a2, HTTPError as a3, ModelNotFoundError as a4, NetworkError as a5, type Notification as a6, type NotificationUnreadCount as a7, type OpenAIChatChoice as a8, type OpenAIChatMessage as a9, type YudaoPageResult as aA, anthropicResponseTextContent as aB, anthropicResponseThinkingContent as aC, anthropicResponseToolUseBlocks as aD, apiResponseBusinessError as aE, apiResponseGetMessage as aF, bucketInfoIsCommercial as aG, bucketRowIsCommercial as aH, getAdapter as aI, getAdapterForModel as aJ, newThinkingConfig as aK, newWebSearchTool as aL, parseNotificationEvent as aM, parseSettlement as aN, parseSourcesEvent as aO, tokenSetIsExpired as aP, type OpenAIChatResponse as aa, type OpenAIFunctionCall as ab, type OpenAIStreamChoice as ac, type OpenAIStreamChunk as ad, type OpenAIStreamDelta as ae, type OpenAIStreamToolCall as af, type OpenAIToolCall as ag, type OpenAIUsage as ah, OrderTerminalError as ai, type OutputConfig as aj, ProviderFormat as ak, RateLimitError as al, type ServerTool as am, ServerToolTypeWebSearch as an, type SkillStoreListItem as ao, StreamError as ap, type ThinkingConfig as aq, ThinkingHigh as ar, ThinkingHighMinMaxTokens as as, ThinkingMax as at, ThinkingMaxFallbackMaxTokens as au, ThinkingOff as av, type ToolListResponse as aw, type ToolProvider as ax, type WebSearchConfig as ay, type WebSearchSource as az, type ModelCoefficient as b, type ModelCapabilities as c, type ChatRequest as d, type ChatResponse as e, type StreamEvent as f, type SourcesEvent as g, type StreamSettlement as h, type BalanceDetail as i, type EntitlementItem as j, type ConsumeRecordPage as k, type ModelByQuotaResponse as l, type ModelBucket as m, type TokenPackage as n, type PayPayload as o, type OrderStatus as p, type Transaction as q, type SkillStoreQuery as r, type SkillStoreItem as s, type SkillBrowseResponse as t, type SkillBrowseListResponse as u, type SkillSummary as v, type CertificationStatus as w, type GenerateSkillResult as x, type OptimizeSkillRequest as y, type OptimizeSkillResult as z };
|
|
@@ -1024,4 +1024,4 @@ declare function getAdapter(provider: string): ProviderAdapter;
|
|
|
1024
1024
|
*/
|
|
1025
1025
|
declare function getAdapterForModel(m: ManagedModel): ProviderAdapter;
|
|
1026
1026
|
|
|
1027
|
-
export { type ChatUsage as $, type AnthropicResponse as A, BusinessError as B, type ClientRegistration as C, type ToolView as D, type EntitlementBalance as E, type DeviceRegistration as F, type GenerateSkillRequest as G, type NotificationPreference as H, type InputModality as I, type WSEvent as J, type APIResponse as K, type AnthropicContentBlock as L, type ManagedModel as M, type NotificationList as N, type Order as O, type ProviderAdapter as P, type QuotaSummary as Q, type AnthropicUsage as R, type ServerMetadata as S, type
|
|
1027
|
+
export { type ChatUsage as $, type AnthropicResponse as A, BusinessError as B, type ClientRegistration as C, type ToolView as D, type EntitlementBalance as E, type DeviceRegistration as F, type GenerateSkillRequest as G, type NotificationPreference as H, type InputModality as I, type WSEvent as J, type APIResponse as K, type AnthropicContentBlock as L, type ManagedModel as M, type NotificationList as N, type Order as O, type ProviderAdapter as P, type QuotaSummary as Q, type AnthropicUsage as R, type ServerMetadata as S, type TokenSet as T, BucketClassCommercial as U, BucketClassGeneric as V, type WalletStats as W, type BucketInfo as X, type BucketRow as Y, type ChatContentBlock as Z, type ChatMessage as _, type TokenResponse as a, type ConsumeRecord as a0, type EffortConfig as a1, type GeoLoc as a2, HTTPError as a3, ModelNotFoundError as a4, NetworkError as a5, type Notification as a6, type NotificationUnreadCount as a7, type OpenAIChatChoice as a8, type OpenAIChatMessage as a9, type YudaoPageResult as aA, anthropicResponseTextContent as aB, anthropicResponseThinkingContent as aC, anthropicResponseToolUseBlocks as aD, apiResponseBusinessError as aE, apiResponseGetMessage as aF, bucketInfoIsCommercial as aG, bucketRowIsCommercial as aH, getAdapter as aI, getAdapterForModel as aJ, newThinkingConfig as aK, newWebSearchTool as aL, parseNotificationEvent as aM, parseSettlement as aN, parseSourcesEvent as aO, tokenSetIsExpired as aP, type OpenAIChatResponse as aa, type OpenAIFunctionCall as ab, type OpenAIStreamChoice as ac, type OpenAIStreamChunk as ad, type OpenAIStreamDelta as ae, type OpenAIStreamToolCall as af, type OpenAIToolCall as ag, type OpenAIUsage as ah, OrderTerminalError as ai, type OutputConfig as aj, ProviderFormat as ak, RateLimitError as al, type ServerTool as am, ServerToolTypeWebSearch as an, type SkillStoreListItem as ao, StreamError as ap, type ThinkingConfig as aq, ThinkingHigh as ar, ThinkingHighMinMaxTokens as as, ThinkingMax as at, ThinkingMaxFallbackMaxTokens as au, ThinkingOff as av, type ToolListResponse as aw, type ToolProvider as ax, type WebSearchConfig as ay, type WebSearchSource as az, type ModelCoefficient as b, type ModelCapabilities as c, type ChatRequest as d, type ChatResponse as e, type StreamEvent as f, type SourcesEvent as g, type StreamSettlement as h, type BalanceDetail as i, type EntitlementItem as j, type ConsumeRecordPage as k, type ModelByQuotaResponse as l, type ModelBucket as m, type TokenPackage as n, type PayPayload as o, type OrderStatus as p, type Transaction as q, type SkillStoreQuery as r, type SkillStoreItem as s, type SkillBrowseResponse as t, type SkillBrowseListResponse as u, type SkillSummary as v, type CertificationStatus as w, type GenerateSkillResult as x, type OptimizeSkillRequest as y, type OptimizeSkillResult as z };
|
package/dist/node/index.cjs
CHANGED
|
@@ -1058,7 +1058,7 @@ init_adapters();
|
|
|
1058
1058
|
|
|
1059
1059
|
// src/auth.ts
|
|
1060
1060
|
var authTimeoutMs = 3e4;
|
|
1061
|
-
async function
|
|
1061
|
+
async function discoverWithProfile(serverURL, profile, signal) {
|
|
1062
1062
|
let parsed;
|
|
1063
1063
|
try {
|
|
1064
1064
|
parsed = new URL(serverURL.replace(/\/+$/, ""));
|
|
@@ -1066,7 +1066,7 @@ async function discover(serverURL, signal) {
|
|
|
1066
1066
|
throw new Error(`discover: invalid server URL: ${e instanceof Error ? e.message : String(e)}`);
|
|
1067
1067
|
}
|
|
1068
1068
|
const origin = `${parsed.protocol}//${parsed.host}`;
|
|
1069
|
-
const endpoint = `${origin}/.well-known/oauth-authorization-server
|
|
1069
|
+
const endpoint = `${origin}/.well-known/oauth-authorization-server/${profile}`;
|
|
1070
1070
|
const ctl = withTimeout(authTimeoutMs, signal);
|
|
1071
1071
|
let resp;
|
|
1072
1072
|
try {
|
|
@@ -1092,6 +1092,12 @@ async function discover(serverURL, signal) {
|
|
|
1092
1092
|
}
|
|
1093
1093
|
return meta;
|
|
1094
1094
|
}
|
|
1095
|
+
async function discover(serverURL, signal) {
|
|
1096
|
+
return discoverWithProfile(serverURL, "desktop", signal);
|
|
1097
|
+
}
|
|
1098
|
+
async function discoverWebOAuthMetadata(serverURL, signal) {
|
|
1099
|
+
return discoverWithProfile(serverURL, "web", signal);
|
|
1100
|
+
}
|
|
1095
1101
|
async function register(meta, appName, signal) {
|
|
1096
1102
|
const regReq = {
|
|
1097
1103
|
client_name: appName,
|
|
@@ -1123,12 +1129,50 @@ async function register(meta, appName, signal) {
|
|
|
1123
1129
|
throw new Error(`register: decode: ${e instanceof Error ? e.message : String(e)}`);
|
|
1124
1130
|
}
|
|
1125
1131
|
}
|
|
1126
|
-
async function
|
|
1132
|
+
async function registerWebOAuthClient(meta, opts, signal) {
|
|
1133
|
+
const regReq = {
|
|
1134
|
+
client_name: opts.clientName,
|
|
1135
|
+
token_endpoint_auth_method: "none",
|
|
1136
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
1137
|
+
redirect_uris: opts.redirectURIs,
|
|
1138
|
+
response_types: ["code"],
|
|
1139
|
+
...opts.scopes ? { scope: opts.scopes.join(" ") } : {}
|
|
1140
|
+
};
|
|
1141
|
+
const ctl = withTimeout(authTimeoutMs, signal);
|
|
1142
|
+
let resp;
|
|
1143
|
+
try {
|
|
1144
|
+
resp = await fetch(meta.registration_endpoint, {
|
|
1145
|
+
method: "POST",
|
|
1146
|
+
headers: { "Content-Type": "application/json" },
|
|
1147
|
+
body: JSON.stringify(regReq),
|
|
1148
|
+
signal: ctl.signal
|
|
1149
|
+
});
|
|
1150
|
+
} catch (e) {
|
|
1151
|
+
throw new Error(`register: ${e instanceof Error ? e.message : String(e)}`);
|
|
1152
|
+
} finally {
|
|
1153
|
+
ctl.dispose();
|
|
1154
|
+
}
|
|
1155
|
+
if (resp.status !== 200 && resp.status !== 201) {
|
|
1156
|
+
throw new Error(`register: HTTP ${resp.status}`);
|
|
1157
|
+
}
|
|
1158
|
+
try {
|
|
1159
|
+
return await resp.json();
|
|
1160
|
+
} catch (e) {
|
|
1161
|
+
throw new Error(`register: decode: ${e instanceof Error ? e.message : String(e)}`);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
async function randomBase64Url32() {
|
|
1127
1165
|
const c = await getCrypto();
|
|
1128
1166
|
const b = new Uint8Array(32);
|
|
1129
1167
|
c.getRandomValues(b);
|
|
1130
1168
|
return base64urlNoPad(b);
|
|
1131
1169
|
}
|
|
1170
|
+
async function generateCodeVerifier() {
|
|
1171
|
+
return randomBase64Url32();
|
|
1172
|
+
}
|
|
1173
|
+
async function generateState() {
|
|
1174
|
+
return randomBase64Url32();
|
|
1175
|
+
}
|
|
1132
1176
|
async function codeChallenge(verifier) {
|
|
1133
1177
|
const c = await getCrypto();
|
|
1134
1178
|
const buf = await c.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
|
|
@@ -1162,6 +1206,7 @@ var ErrAuthDenied = "auth_denied";
|
|
|
1162
1206
|
var ErrTimeout = "auth_timeout";
|
|
1163
1207
|
var ErrTokenExchange = "token_exchange_failed";
|
|
1164
1208
|
var ErrSSLProxy = "ssl_proxy_detected";
|
|
1209
|
+
var ErrStateMismatch = "state_mismatch";
|
|
1165
1210
|
function isSSLError(err) {
|
|
1166
1211
|
const msg = err instanceof Error ? err.message : String(err);
|
|
1167
1212
|
return msg.includes("tls:") || msg.includes("x509:") || msg.includes("certificate");
|
|
@@ -1275,6 +1320,51 @@ async function authorize(meta, clientID, scopes, opts = {}) {
|
|
|
1275
1320
|
function htmlEscape(s) {
|
|
1276
1321
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1277
1322
|
}
|
|
1323
|
+
async function createWebAuthorizationRequest(meta, opts) {
|
|
1324
|
+
const verifier = await generateCodeVerifier();
|
|
1325
|
+
const challenge = await codeChallenge(verifier);
|
|
1326
|
+
const state = await generateState();
|
|
1327
|
+
const authURL = new URL(meta.authorization_endpoint);
|
|
1328
|
+
authURL.searchParams.set("response_type", "code");
|
|
1329
|
+
authURL.searchParams.set("client_id", opts.clientID);
|
|
1330
|
+
authURL.searchParams.set("redirect_uri", opts.redirectURI);
|
|
1331
|
+
authURL.searchParams.set("code_challenge", challenge);
|
|
1332
|
+
authURL.searchParams.set("code_challenge_method", "S256");
|
|
1333
|
+
authURL.searchParams.set("state", state);
|
|
1334
|
+
authURL.searchParams.set("scope", opts.scopes.join(" "));
|
|
1335
|
+
if (opts.loginHint) {
|
|
1336
|
+
authURL.searchParams.set("login_hint", opts.loginHint);
|
|
1337
|
+
}
|
|
1338
|
+
return {
|
|
1339
|
+
authUrl: authURL.toString(),
|
|
1340
|
+
state,
|
|
1341
|
+
verifier,
|
|
1342
|
+
clientID: opts.clientID,
|
|
1343
|
+
redirectURI: opts.redirectURI,
|
|
1344
|
+
serverURL: opts.serverURL,
|
|
1345
|
+
createdAt: Date.now()
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
async function completeWebAuthorizationRequest(pending, params, signal) {
|
|
1349
|
+
if (!params.code) {
|
|
1350
|
+
throw new Error("completeWebAuthorizationRequest: missing authorization code");
|
|
1351
|
+
}
|
|
1352
|
+
if (params.state !== pending.state) {
|
|
1353
|
+
throw new Error(
|
|
1354
|
+
`completeWebAuthorizationRequest: ${ErrStateMismatch}: callback state does not match pending state (possible CSRF)`
|
|
1355
|
+
);
|
|
1356
|
+
}
|
|
1357
|
+
const meta = await discoverWebOAuthMetadata(pending.serverURL, signal);
|
|
1358
|
+
const resp = await exchangeCode(
|
|
1359
|
+
meta,
|
|
1360
|
+
pending.clientID,
|
|
1361
|
+
params.code,
|
|
1362
|
+
pending.redirectURI,
|
|
1363
|
+
pending.verifier,
|
|
1364
|
+
signal
|
|
1365
|
+
);
|
|
1366
|
+
return newTokenSet(resp, pending.clientID, pending.serverURL);
|
|
1367
|
+
}
|
|
1278
1368
|
async function exchangeCode(meta, clientID, code, redirectURI, codeVerifier, signal) {
|
|
1279
1369
|
const data = new URLSearchParams({
|
|
1280
1370
|
grant_type: "authorization_code",
|
|
@@ -1441,6 +1531,7 @@ var ScopeComplianceSealApprovalRequest = "compliance:seal_approval:request";
|
|
|
1441
1531
|
var ScopeComplianceSealApprovalApprove = "compliance:seal_approval:approve";
|
|
1442
1532
|
var ScopeComplianceSealUseExecute = "compliance:seal_use:execute";
|
|
1443
1533
|
var ScopeComplianceReportsRead = "compliance:reports:read";
|
|
1534
|
+
var ScopeComplianceReportsWrite = "compliance:reports:write";
|
|
1444
1535
|
var ScopeComplianceReportsPublish = "compliance:reports:publish";
|
|
1445
1536
|
function allScopes() {
|
|
1446
1537
|
return [ScopeAI, ScopeSkills, ScopeAccount];
|
|
@@ -1458,6 +1549,7 @@ function complianceScopes() {
|
|
|
1458
1549
|
ScopeComplianceSealApprovalApprove,
|
|
1459
1550
|
ScopeComplianceSealUseExecute,
|
|
1460
1551
|
ScopeComplianceReportsRead,
|
|
1552
|
+
ScopeComplianceReportsWrite,
|
|
1461
1553
|
ScopeComplianceReportsPublish
|
|
1462
1554
|
];
|
|
1463
1555
|
}
|
|
@@ -2165,6 +2257,8 @@ var Client = class _Client {
|
|
|
2165
2257
|
serverURL;
|
|
2166
2258
|
/** Compliance API 根地址 (已 trim 尾随 /); null = 走默认 ${serverURL}/admin-api */
|
|
2167
2259
|
complianceBaseURL;
|
|
2260
|
+
/** OAuth metadata profile — 刷新 token 时发现 metadata 用 (默认 'desktop') */
|
|
2261
|
+
oauthMetadataProfile;
|
|
2168
2262
|
/** OAuth metadata (lazy loaded) */
|
|
2169
2263
|
meta = null;
|
|
2170
2264
|
/** 当前 token (内存) */
|
|
@@ -2199,6 +2293,7 @@ var Client = class _Client {
|
|
|
2199
2293
|
constructor(cfg = {}) {
|
|
2200
2294
|
this.serverURL = (cfg.serverURL ?? "https://acosmi.com").replace(/\/+$/, "");
|
|
2201
2295
|
this.complianceBaseURL = cfg.complianceBaseURL ? cfg.complianceBaseURL.replace(/\/+$/, "") : null;
|
|
2296
|
+
this.oauthMetadataProfile = cfg.oauthMetadataProfile ?? "desktop";
|
|
2202
2297
|
this.store = cfg.store ?? defaultTokenStore();
|
|
2203
2298
|
this.fetchImpl = cfg.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
2204
2299
|
this.retryPolicy = effectivePolicy(cfg.retryPolicy ?? null);
|
|
@@ -2373,7 +2468,7 @@ var Client = class _Client {
|
|
|
2373
2468
|
if (tokens) {
|
|
2374
2469
|
if (!meta) {
|
|
2375
2470
|
try {
|
|
2376
|
-
meta = await
|
|
2471
|
+
meta = await discoverWithProfile(this.serverURL, this.oauthMetadataProfile, signal);
|
|
2377
2472
|
} catch (e) {
|
|
2378
2473
|
console.warn(`[acosmi-sdk] warning: discover for revocation failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
2379
2474
|
}
|
|
@@ -2444,7 +2539,7 @@ var Client = class _Client {
|
|
|
2444
2539
|
}
|
|
2445
2540
|
if (this.meta == null) {
|
|
2446
2541
|
try {
|
|
2447
|
-
this.meta = await
|
|
2542
|
+
this.meta = await discoverWithProfile(this.serverURL, this.oauthMetadataProfile, signal);
|
|
2448
2543
|
} catch (e) {
|
|
2449
2544
|
throw new Error(
|
|
2450
2545
|
`discover for refresh: ${e instanceof Error ? e.message : String(e)}`
|
|
@@ -2476,7 +2571,7 @@ var Client = class _Client {
|
|
|
2476
2571
|
throw new Error("no tokens to refresh");
|
|
2477
2572
|
}
|
|
2478
2573
|
if (this.meta == null) {
|
|
2479
|
-
this.meta = await
|
|
2574
|
+
this.meta = await discoverWithProfile(this.serverURL, this.oauthMetadataProfile, signal);
|
|
2480
2575
|
}
|
|
2481
2576
|
const tokenResp = await refreshToken(
|
|
2482
2577
|
this.meta,
|
|
@@ -3328,17 +3423,20 @@ var ComplianceClient = class {
|
|
|
3328
3423
|
}
|
|
3329
3424
|
/**
|
|
3330
3425
|
* 公开 verify。隐私边界:返回字段不含 PII / 合同原文 / storage / provider raw。
|
|
3331
|
-
*
|
|
3426
|
+
*
|
|
3427
|
+
* 匿名可调用:未 login 时走匿名请求,不会抛 `not authorized, call login() first`。
|
|
3428
|
+
* 已 login / 已持有 token 时附带 `Authorization` 以保留审计上下文。public 端点不
|
|
3429
|
+
* 应要求认证 — 收到 401 直接抛 HTTPError,不触发 `forceRefresh`,也不做 refresh
|
|
3430
|
+
* replay。
|
|
3332
3431
|
*/
|
|
3333
3432
|
verifyEvidencePublic(params, signal) {
|
|
3334
3433
|
const q = new URLSearchParams();
|
|
3335
3434
|
if (params.evidenceNo) q.set("evidenceNo", params.evidenceNo);
|
|
3336
3435
|
if (params.publicVerifyCode) q.set("publicVerifyCode", params.publicVerifyCode);
|
|
3337
3436
|
const qs = q.toString();
|
|
3338
|
-
return this.
|
|
3437
|
+
return this.publicRead(
|
|
3339
3438
|
"GET",
|
|
3340
3439
|
`/compliance/evidence/verify${qs ? "?" + qs : ""}`,
|
|
3341
|
-
null,
|
|
3342
3440
|
signal
|
|
3343
3441
|
);
|
|
3344
3442
|
}
|
|
@@ -3422,9 +3520,10 @@ var ComplianceClient = class {
|
|
|
3422
3520
|
/**
|
|
3423
3521
|
* 发布报告(写,step-up 必须)。
|
|
3424
3522
|
*
|
|
3425
|
-
*
|
|
3426
|
-
* 1031000013)。SDK
|
|
3427
|
-
*
|
|
3523
|
+
* `@status gated` — step-up 闸门未闭合前服务端会一致返回
|
|
3524
|
+
* `COMPLIANCE_STEP_UP_REQUIRED`(数值码 1031000013)。SDK 不会自动重试、不伪成功;
|
|
3525
|
+
* 调用方需要引导用户重新做 OAuth introspection 或重新登录后再次调用本方法
|
|
3526
|
+
*(使用同一 idempotency-key)。方法状态分级见 `docs/compliance.md` Method Status。
|
|
3428
3527
|
*/
|
|
3429
3528
|
publishReport(id, opts = {}) {
|
|
3430
3529
|
return this.write(
|
|
@@ -3471,7 +3570,7 @@ var ComplianceClient = class {
|
|
|
3471
3570
|
/**
|
|
3472
3571
|
* 正式签署(写,step-up 必须)。
|
|
3473
3572
|
*
|
|
3474
|
-
* 服务端闸门关闭时会一致返回 `ENVELOPE_GATE_CLOSED` (1031004004)。
|
|
3573
|
+
* `@status gated` — 服务端闸门关闭时会一致返回 `ENVELOPE_GATE_CLOSED` (1031004004)。
|
|
3475
3574
|
* SDK 不重试、不伪成功;调用方应该将该错误展示为"功能未开放"。
|
|
3476
3575
|
*/
|
|
3477
3576
|
signEnvelope(envelopeId, req, opts = {}) {
|
|
@@ -3485,7 +3584,7 @@ var ComplianceClient = class {
|
|
|
3485
3584
|
/**
|
|
3486
3585
|
* 创建 H5 签署短链(写,step-up 必须)。
|
|
3487
3586
|
*
|
|
3488
|
-
*
|
|
3587
|
+
* `@status gated` — 同 {@link signEnvelope}:服务端闸门关闭时 SDK 不重试、不伪成功。
|
|
3489
3588
|
*/
|
|
3490
3589
|
createH5SigningUrl(envelopeId, req, opts = {}) {
|
|
3491
3590
|
return this.write(
|
|
@@ -3507,6 +3606,13 @@ var ComplianceClient = class {
|
|
|
3507
3606
|
// =========================================================================
|
|
3508
3607
|
// Seal Approval
|
|
3509
3608
|
// =========================================================================
|
|
3609
|
+
/**
|
|
3610
|
+
* 提交用印审批申请(写)。
|
|
3611
|
+
*
|
|
3612
|
+
* `@status production-ready` — 服务端以 `Idempotency-Key` + 业务请求指纹做重放保护:
|
|
3613
|
+
* 同 key + 同请求 → 返回原审批 id;同 key + 不同请求 → 拒绝复用幂等键。强烈建议调用方
|
|
3614
|
+
* 持久化 `idempotencyKey`,网络重试 / 任务恢复时复用,避免重复创建审批单。
|
|
3615
|
+
*/
|
|
3510
3616
|
submitSealApproval(req, opts = {}) {
|
|
3511
3617
|
return this.write(
|
|
3512
3618
|
"POST",
|
|
@@ -3515,6 +3621,12 @@ var ComplianceClient = class {
|
|
|
3515
3621
|
writeCtx(opts)
|
|
3516
3622
|
);
|
|
3517
3623
|
}
|
|
3624
|
+
/**
|
|
3625
|
+
* 审批通过用印申请(写,step-up 必须)。
|
|
3626
|
+
*
|
|
3627
|
+
* `@status gated` — step-up 未闭合前服务端会返回 `COMPLIANCE_STEP_UP_REQUIRED`。
|
|
3628
|
+
* SDK 不重试、不伪成功。方法状态分级见 `docs/compliance.md` Method Status。
|
|
3629
|
+
*/
|
|
3518
3630
|
approveSealApproval(id, query, opts = {}) {
|
|
3519
3631
|
const q = new URLSearchParams();
|
|
3520
3632
|
if (query.expiresAt) q.set("expiresAt", query.expiresAt);
|
|
@@ -3612,6 +3724,38 @@ var ComplianceClient = class {
|
|
|
3612
3724
|
extraHeaders
|
|
3613
3725
|
});
|
|
3614
3726
|
}
|
|
3727
|
+
/**
|
|
3728
|
+
* 公开读路径:public verify。
|
|
3729
|
+
*
|
|
3730
|
+
* 与 {@link read} 的区别 — public 端点不应要求认证:
|
|
3731
|
+
* - 无 token 时匿名请求:ensureToken 抛 `not authorized` 会被吞掉,继续匿名发送。
|
|
3732
|
+
* - 有 token 时附带 `Authorization`,保留后端审计上下文。
|
|
3733
|
+
* - 不做 401 refresh replay:401 直接抛 HTTPError,不触发 `forceRefresh`。
|
|
3734
|
+
*
|
|
3735
|
+
* URL 仍走 `client.complianceURL(path)`,不复用 `/api/v4`;底层复用
|
|
3736
|
+
* `client.doRequest`,不新增 fetch/axios 直连。
|
|
3737
|
+
*/
|
|
3738
|
+
async publicRead(method, path, signal) {
|
|
3739
|
+
let token = "";
|
|
3740
|
+
try {
|
|
3741
|
+
token = await this.client.ensureToken(signal);
|
|
3742
|
+
} catch {
|
|
3743
|
+
}
|
|
3744
|
+
const url = this.client.complianceURL(path);
|
|
3745
|
+
const headers = { Accept: "application/json" };
|
|
3746
|
+
if (token) headers.Authorization = `Bearer ${token}`;
|
|
3747
|
+
const resp = await this.client.doRequest({ method, url, headers }, signal);
|
|
3748
|
+
if (resp.status < 200 || resp.status >= 300) {
|
|
3749
|
+
const bodyBytes = resp.body ? await readLimited(resp.body, maxErrorBodySize) : new Uint8Array();
|
|
3750
|
+
throw parseHTTPErrorWithHeader(resp.status, bodyBytes, resp.headers);
|
|
3751
|
+
}
|
|
3752
|
+
const text = await resp.text();
|
|
3753
|
+
if (!text) return void 0;
|
|
3754
|
+
const parsed = JSON.parse(text);
|
|
3755
|
+
const bizErr = apiResponseBusinessError(parsed);
|
|
3756
|
+
if (bizErr) throw bizErr;
|
|
3757
|
+
return parsed.data;
|
|
3758
|
+
}
|
|
3615
3759
|
/**
|
|
3616
3760
|
* 写路径:POST。
|
|
3617
3761
|
* - 发送前 ensureToken 一次确保 token fresh。
|
|
@@ -5346,6 +5490,7 @@ exports.ErrSealApprovalNotApproved = ErrSealApprovalNotApproved;
|
|
|
5346
5490
|
exports.ErrSealApprovalSealMismatch = ErrSealApprovalSealMismatch;
|
|
5347
5491
|
exports.ErrSealApprovalTransactorMismatch = ErrSealApprovalTransactorMismatch;
|
|
5348
5492
|
exports.ErrSealUseAlreadyConsumed = ErrSealUseAlreadyConsumed;
|
|
5493
|
+
exports.ErrStateMismatch = ErrStateMismatch;
|
|
5349
5494
|
exports.ErrTimeout = ErrTimeout;
|
|
5350
5495
|
exports.ErrTokenExchange = ErrTokenExchange;
|
|
5351
5496
|
exports.EventAuthURL = EventAuthURL;
|
|
@@ -5371,6 +5516,7 @@ exports.ScopeComplianceEvidenceRead = ScopeComplianceEvidenceRead;
|
|
|
5371
5516
|
exports.ScopeComplianceEvidenceWrite = ScopeComplianceEvidenceWrite;
|
|
5372
5517
|
exports.ScopeComplianceReportsPublish = ScopeComplianceReportsPublish;
|
|
5373
5518
|
exports.ScopeComplianceReportsRead = ScopeComplianceReportsRead;
|
|
5519
|
+
exports.ScopeComplianceReportsWrite = ScopeComplianceReportsWrite;
|
|
5374
5520
|
exports.ScopeComplianceSealApprovalApprove = ScopeComplianceSealApprovalApprove;
|
|
5375
5521
|
exports.ScopeComplianceSealApprovalRequest = ScopeComplianceSealApprovalRequest;
|
|
5376
5522
|
exports.ScopeComplianceSealManage = ScopeComplianceSealManage;
|
|
@@ -5400,17 +5546,22 @@ exports.bucketRowIsCommercial = bucketRowIsCommercial;
|
|
|
5400
5546
|
exports.buildBetas = buildBetas;
|
|
5401
5547
|
exports.classifyComplianceError = classifyComplianceError;
|
|
5402
5548
|
exports.commerceScopes = commerceScopes;
|
|
5549
|
+
exports.completeWebAuthorizationRequest = completeWebAuthorizationRequest;
|
|
5403
5550
|
exports.complianceScopes = complianceScopes;
|
|
5404
5551
|
exports.computeBackoff = computeBackoff;
|
|
5552
|
+
exports.createWebAuthorizationRequest = createWebAuthorizationRequest;
|
|
5405
5553
|
exports.defaultRetryable = defaultRetryable;
|
|
5406
5554
|
exports.defaultSafeToRetry = defaultSafeToRetry;
|
|
5407
5555
|
exports.discover = discover;
|
|
5556
|
+
exports.discoverWebOAuthMetadata = discoverWebOAuthMetadata;
|
|
5557
|
+
exports.discoverWithProfile = discoverWithProfile;
|
|
5408
5558
|
exports.effectivePolicy = effectivePolicy;
|
|
5409
5559
|
exports.exchangeCode = exchangeCode;
|
|
5410
5560
|
exports.extractAnthropicBlockMeta = extractAnthropicBlockMeta;
|
|
5411
5561
|
exports.fileLockDefaults = fileLockDefaults;
|
|
5412
5562
|
exports.findDesktopVisualUnderstandingModel = findDesktopVisualUnderstandingModel;
|
|
5413
5563
|
exports.findFirstModelByInputModality = findFirstModelByInputModality;
|
|
5564
|
+
exports.generateState = generateState;
|
|
5414
5565
|
exports.getAdapter = getAdapter;
|
|
5415
5566
|
exports.getAdapterForModel = getAdapterForModel;
|
|
5416
5567
|
exports.isBillingConfirmable = isBillingConfirmable;
|
|
@@ -5429,6 +5580,7 @@ exports.parseSettlement = parseSettlement;
|
|
|
5429
5580
|
exports.parseSourcesEvent = parseSourcesEvent;
|
|
5430
5581
|
exports.refreshToken = refreshToken;
|
|
5431
5582
|
exports.register = register;
|
|
5583
|
+
exports.registerWebOAuthClient = registerWebOAuthClient;
|
|
5432
5584
|
exports.revokeToken = revokeToken;
|
|
5433
5585
|
exports.sanitize = sanitize_exports;
|
|
5434
5586
|
exports.skillScopes = skillScopes;
|