@acosmi/sdk-ts 2.0.1 → 2.1.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 +17 -0
- package/README.md +240 -54
- package/dist/browser/index.mjs +403 -3
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +403 -3
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +421 -2
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +447 -3
- package/dist/node/index.d.ts +447 -3
- package/dist/node/index.mjs +403 -3
- package/dist/node/index.mjs.map +1 -1
- package/docs//345/274/200/345/217/221/344/270/216/345/217/221/345/270/203/346/211/213/345/206/214.md +115 -20
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -1012,6 +1012,21 @@ function apiResponseBusinessError(r) {
|
|
|
1012
1012
|
|
|
1013
1013
|
// src/auth/auth.ts
|
|
1014
1014
|
var authTimeoutMs = 3e4;
|
|
1015
|
+
var OAuthTokenEndpointError = class extends Error {
|
|
1016
|
+
status;
|
|
1017
|
+
oauthError;
|
|
1018
|
+
errorDescription;
|
|
1019
|
+
constructor(status, oauthError, errorDescription) {
|
|
1020
|
+
super(`token: HTTP ${status}: ${errorDescription || oauthError}`);
|
|
1021
|
+
this.name = "OAuthTokenEndpointError";
|
|
1022
|
+
this.status = status;
|
|
1023
|
+
this.oauthError = oauthError;
|
|
1024
|
+
this.errorDescription = errorDescription;
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
function isInvalidGrantError(err) {
|
|
1028
|
+
return err instanceof OAuthTokenEndpointError && err.oauthError === "invalid_grant";
|
|
1029
|
+
}
|
|
1015
1030
|
async function discoverWithProfile(serverURL, profile, signal) {
|
|
1016
1031
|
let parsed;
|
|
1017
1032
|
try {
|
|
@@ -1388,7 +1403,9 @@ async function postToken(endpoint, data, signal) {
|
|
|
1388
1403
|
errBody = await resp.json();
|
|
1389
1404
|
} catch {
|
|
1390
1405
|
}
|
|
1391
|
-
|
|
1406
|
+
const oauthError = typeof errBody.error === "string" ? errBody.error : "";
|
|
1407
|
+
const errorDescription = typeof errBody.error_description === "string" ? errBody.error_description : "";
|
|
1408
|
+
throw new OAuthTokenEndpointError(resp.status, oauthError, errorDescription);
|
|
1392
1409
|
}
|
|
1393
1410
|
try {
|
|
1394
1411
|
return await resp.json();
|
|
@@ -1998,6 +2015,53 @@ var FilterStatusFallbackTkdistSkew = "fallback-tkdist-deployment-skew";
|
|
|
1998
2015
|
var FilterStatusFallbackNoBuckets = "fallback-no-buckets";
|
|
1999
2016
|
var FilterStatusFallbackMissingUser = "fallback-missing-userid";
|
|
2000
2017
|
var FilterStatusUnknown = "";
|
|
2018
|
+
var DEFAULT_GATEWAY_BASE_URL = "https://acosmi.com";
|
|
2019
|
+
function normalizeGatewayBaseURL(input) {
|
|
2020
|
+
if (typeof input !== "string") {
|
|
2021
|
+
throw new TypeError(
|
|
2022
|
+
"Acosmi Gateway URL must be a string (see docs/audit/sdk-remote-control-contract-2026-05-27.md \xA72)"
|
|
2023
|
+
);
|
|
2024
|
+
}
|
|
2025
|
+
const trimmed = input.trim();
|
|
2026
|
+
if (trimmed.length === 0) {
|
|
2027
|
+
throw new Error("Acosmi Gateway URL is empty");
|
|
2028
|
+
}
|
|
2029
|
+
let parsed;
|
|
2030
|
+
try {
|
|
2031
|
+
parsed = new URL(trimmed);
|
|
2032
|
+
} catch {
|
|
2033
|
+
throw new Error(`Acosmi Gateway URL is not a valid URL: ${trimmed}`);
|
|
2034
|
+
}
|
|
2035
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
2036
|
+
throw new Error(
|
|
2037
|
+
`Acosmi Gateway URL only allows http/https, got ${parsed.protocol} (${trimmed}). CrabCode --sdk-url (ws/wss) is the RemoteIO session channel, not a SDK gateway URL \u2014 see docs/audit/sdk-remote-control-contract-2026-05-27.md \xA71.`
|
|
2038
|
+
);
|
|
2039
|
+
}
|
|
2040
|
+
if (!parsed.host) {
|
|
2041
|
+
throw new Error(`Acosmi Gateway URL has empty host: ${trimmed}`);
|
|
2042
|
+
}
|
|
2043
|
+
if (parsed.search.length > 0 || parsed.hash.length > 0) {
|
|
2044
|
+
throw new Error(`Acosmi Gateway URL must not contain query or hash: ${trimmed}`);
|
|
2045
|
+
}
|
|
2046
|
+
const path = parsed.pathname.replace(/\/+$/, "");
|
|
2047
|
+
return path ? `${parsed.origin}${path}` : parsed.origin;
|
|
2048
|
+
}
|
|
2049
|
+
function pickAndNormalizeGatewayURL(cfg) {
|
|
2050
|
+
const inputs = [];
|
|
2051
|
+
if (cfg.serverURL !== void 0) inputs.push(["serverURL", cfg.serverURL]);
|
|
2052
|
+
if (cfg.baseURL !== void 0) inputs.push(["baseURL", cfg.baseURL]);
|
|
2053
|
+
if (cfg.baseUrl !== void 0) inputs.push(["baseUrl", cfg.baseUrl]);
|
|
2054
|
+
if (inputs.length === 0) return null;
|
|
2055
|
+
const normalized = inputs.map(([n, v]) => [n, normalizeGatewayBaseURL(v)]);
|
|
2056
|
+
for (let i = 1; i < normalized.length; i++) {
|
|
2057
|
+
if (normalized[i][1] !== normalized[0][1]) {
|
|
2058
|
+
throw new Error(
|
|
2059
|
+
`Acosmi Gateway URL conflict: Config.${normalized[0][0]}=${normalized[0][1]} vs Config.${normalized[i][0]}=${normalized[i][1]} \u2014 pass only one field.`
|
|
2060
|
+
);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
return normalized[0][1];
|
|
2064
|
+
}
|
|
2001
2065
|
var ErrOAuthCORSBlocked = "oauth_cors_blocked";
|
|
2002
2066
|
var ErrRefreshProxyFailed = "refresh_proxy_failed";
|
|
2003
2067
|
var ErrTokenExpired = "token_expired";
|
|
@@ -2055,7 +2119,8 @@ var Client = class _Client {
|
|
|
2055
2119
|
/** 串行化锁 (替代 Go sync.Mutex) */
|
|
2056
2120
|
coefMu = Promise.resolve();
|
|
2057
2121
|
constructor(cfg = {}) {
|
|
2058
|
-
|
|
2122
|
+
const picked = pickAndNormalizeGatewayURL(cfg);
|
|
2123
|
+
this.serverURL = picked ?? DEFAULT_GATEWAY_BASE_URL;
|
|
2059
2124
|
this.complianceBaseURL = cfg.complianceBaseURL ? cfg.complianceBaseURL.replace(/\/+$/, "") : null;
|
|
2060
2125
|
this.oauthMetadataProfile = cfg.oauthMetadataProfile ?? "desktop";
|
|
2061
2126
|
this.browserRefreshMode = cfg.browserRefreshMode ?? "direct";
|
|
@@ -2090,6 +2155,20 @@ var Client = class _Client {
|
|
|
2090
2155
|
isAuthorized() {
|
|
2091
2156
|
return this.tokens != null;
|
|
2092
2157
|
}
|
|
2158
|
+
/**
|
|
2159
|
+
* 返回归一化后的 Acosmi Gateway URL (= `serverURL` 字段). readonly helper.
|
|
2160
|
+
*
|
|
2161
|
+
* Phase 0 §2 红线:
|
|
2162
|
+
* - 不要 mutate `client.serverURL` 字段实现 base 切换; 用 per-base Client 实例.
|
|
2163
|
+
* - 该值仅供日志/排查/上层缓存键使用, 不重新 normalize 它 (构造期已 normalize).
|
|
2164
|
+
*/
|
|
2165
|
+
getServerURL() {
|
|
2166
|
+
return this.serverURL;
|
|
2167
|
+
}
|
|
2168
|
+
/** `getServerURL()` 的 alias — Phase 0 §2 baseURL 与 serverURL 同义. */
|
|
2169
|
+
getBaseURL() {
|
|
2170
|
+
return this.serverURL;
|
|
2171
|
+
}
|
|
2093
2172
|
/** 当前 token 信息 (用于 CLI whoami 显示) */
|
|
2094
2173
|
getTokenSet() {
|
|
2095
2174
|
return this.tokens;
|
|
@@ -2356,6 +2435,10 @@ var Client = class _Client {
|
|
|
2356
2435
|
);
|
|
2357
2436
|
} catch (e) {
|
|
2358
2437
|
const message = e instanceof Error ? e.message : String(e);
|
|
2438
|
+
if (isInvalidGrantError(e)) {
|
|
2439
|
+
await this.clearInvalidRefreshToken();
|
|
2440
|
+
throw new Error(`refresh token invalid; local tokens cleared: ${message}`);
|
|
2441
|
+
}
|
|
2359
2442
|
if (isLikelyBrowserOAuthCORSError(message)) {
|
|
2360
2443
|
throw new Error(`${ErrOAuthCORSBlocked}: refresh token: ${message}`);
|
|
2361
2444
|
}
|
|
@@ -2390,11 +2473,18 @@ var Client = class _Client {
|
|
|
2390
2473
|
}
|
|
2391
2474
|
if (!resp.ok) {
|
|
2392
2475
|
let message = "";
|
|
2476
|
+
let oauthError = "";
|
|
2393
2477
|
try {
|
|
2394
2478
|
const body2 = await resp.json();
|
|
2395
2479
|
if (typeof body2.error === "string") message = body2.error;
|
|
2480
|
+
if (typeof body2.error === "string") oauthError = body2.error;
|
|
2481
|
+
if (typeof body2.error_description === "string") message = body2.error_description;
|
|
2396
2482
|
} catch {
|
|
2397
2483
|
}
|
|
2484
|
+
if (oauthError === "invalid_grant") {
|
|
2485
|
+
await this.clearInvalidRefreshToken();
|
|
2486
|
+
throw new Error(`${ErrRefreshProxyFailed}: refresh token invalid; local tokens cleared`);
|
|
2487
|
+
}
|
|
2398
2488
|
throw new Error(`${ErrRefreshProxyFailed}: HTTP ${resp.status}: ${message}`);
|
|
2399
2489
|
}
|
|
2400
2490
|
let body;
|
|
@@ -2421,6 +2511,20 @@ var Client = class _Client {
|
|
|
2421
2511
|
);
|
|
2422
2512
|
}
|
|
2423
2513
|
}
|
|
2514
|
+
async clearInvalidRefreshToken() {
|
|
2515
|
+
this.tokens = null;
|
|
2516
|
+
this.meta = null;
|
|
2517
|
+
this.loginInFlight = false;
|
|
2518
|
+
this.tokenReady = newDeferred();
|
|
2519
|
+
this.tokenReadyResolved = false;
|
|
2520
|
+
try {
|
|
2521
|
+
await this.store.clear();
|
|
2522
|
+
} catch (e) {
|
|
2523
|
+
console.warn(
|
|
2524
|
+
`[acosmi-sdk] warning: clear invalid token failed: ${e instanceof Error ? e.message : String(e)}`
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2424
2528
|
/** 互斥锁 helper (替代 Go sync.Mutex) */
|
|
2425
2529
|
withMu(fn) {
|
|
2426
2530
|
const next = this.mu.then(fn, fn);
|
|
@@ -3619,6 +3723,10 @@ function complianceErrorToRetryAdvice(info) {
|
|
|
3619
3723
|
var ScopeAI = "ai";
|
|
3620
3724
|
var ScopeSkills = "skills";
|
|
3621
3725
|
var ScopeAccount = "account";
|
|
3726
|
+
var ScopeRemoteControl = "remote_control";
|
|
3727
|
+
var ScopeRemoteControlAgentRun = "remote_control:agent-run";
|
|
3728
|
+
var ScopeRemoteControlSessionControl = "remote_control:session-control";
|
|
3729
|
+
var ScopeRemoteControlPermissionResponse = "remote_control:permission-response";
|
|
3622
3730
|
var ScopeModels = "models";
|
|
3623
3731
|
var ScopeModelsChat = "models:chat";
|
|
3624
3732
|
var ScopeEntitlements = "entitlements";
|
|
@@ -3641,6 +3749,9 @@ function commerceScopes() {
|
|
|
3641
3749
|
function skillScopes() {
|
|
3642
3750
|
return [ScopeSkills];
|
|
3643
3751
|
}
|
|
3752
|
+
function remoteControlScopes() {
|
|
3753
|
+
return [ScopeRemoteControl];
|
|
3754
|
+
}
|
|
3644
3755
|
|
|
3645
3756
|
// src/models/index.ts
|
|
3646
3757
|
init_types();
|
|
@@ -4486,6 +4597,136 @@ var AgentRunStreamError = class extends Error {
|
|
|
4486
4597
|
}
|
|
4487
4598
|
};
|
|
4488
4599
|
|
|
4600
|
+
// src/agent-runs/remote-control.ts
|
|
4601
|
+
function asRecord(v) {
|
|
4602
|
+
if (v === null || typeof v !== "object" || Array.isArray(v)) return null;
|
|
4603
|
+
return v;
|
|
4604
|
+
}
|
|
4605
|
+
function str(rec, key) {
|
|
4606
|
+
const v = rec[key];
|
|
4607
|
+
return typeof v === "string" ? v : void 0;
|
|
4608
|
+
}
|
|
4609
|
+
function num(rec, key) {
|
|
4610
|
+
const v = rec[key];
|
|
4611
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
4612
|
+
}
|
|
4613
|
+
function bool(rec, key) {
|
|
4614
|
+
const v = rec[key];
|
|
4615
|
+
return typeof v === "boolean" ? v : void 0;
|
|
4616
|
+
}
|
|
4617
|
+
function parseRemoteControlEvent(raw) {
|
|
4618
|
+
const rec = asRecord(raw);
|
|
4619
|
+
if (!rec) return null;
|
|
4620
|
+
const type = str(rec, "type");
|
|
4621
|
+
if (!type) return null;
|
|
4622
|
+
switch (type) {
|
|
4623
|
+
case "text_delta": {
|
|
4624
|
+
const index = num(rec, "index");
|
|
4625
|
+
const text = str(rec, "text");
|
|
4626
|
+
if (typeof index !== "number" || typeof text !== "string") return null;
|
|
4627
|
+
return { type: "text_delta", index, text };
|
|
4628
|
+
}
|
|
4629
|
+
case "reasoning_delta": {
|
|
4630
|
+
const index = num(rec, "index");
|
|
4631
|
+
const text = str(rec, "text");
|
|
4632
|
+
if (typeof index !== "number" || typeof text !== "string") return null;
|
|
4633
|
+
return { type: "reasoning_delta", index, text };
|
|
4634
|
+
}
|
|
4635
|
+
case "tool_call": {
|
|
4636
|
+
const toolCallId = str(rec, "tool_call_id") ?? str(rec, "toolCallId");
|
|
4637
|
+
const name = str(rec, "name");
|
|
4638
|
+
if (!toolCallId || !name) return null;
|
|
4639
|
+
return {
|
|
4640
|
+
type: "tool_call",
|
|
4641
|
+
toolCallId,
|
|
4642
|
+
name,
|
|
4643
|
+
input: rec["input"],
|
|
4644
|
+
source: str(rec, "source")
|
|
4645
|
+
};
|
|
4646
|
+
}
|
|
4647
|
+
case "tool_result": {
|
|
4648
|
+
const toolCallId = str(rec, "tool_call_id") ?? str(rec, "toolCallId");
|
|
4649
|
+
const ok = bool(rec, "ok");
|
|
4650
|
+
if (!toolCallId || typeof ok !== "boolean") return null;
|
|
4651
|
+
return {
|
|
4652
|
+
type: "tool_result",
|
|
4653
|
+
toolCallId,
|
|
4654
|
+
ok,
|
|
4655
|
+
output: rec["output"],
|
|
4656
|
+
error: str(rec, "error")
|
|
4657
|
+
};
|
|
4658
|
+
}
|
|
4659
|
+
case "permission_request": {
|
|
4660
|
+
const requestId = str(rec, "request_id") ?? str(rec, "requestId");
|
|
4661
|
+
const kind = str(rec, "kind");
|
|
4662
|
+
if (!requestId || !kind) return null;
|
|
4663
|
+
return {
|
|
4664
|
+
type: "permission_request",
|
|
4665
|
+
requestId,
|
|
4666
|
+
kind,
|
|
4667
|
+
payload: rec["payload"],
|
|
4668
|
+
deadlineMs: num(rec, "deadline_ms") ?? num(rec, "deadlineMs")
|
|
4669
|
+
};
|
|
4670
|
+
}
|
|
4671
|
+
case "permission_result": {
|
|
4672
|
+
const requestId = str(rec, "request_id") ?? str(rec, "requestId");
|
|
4673
|
+
const decision = str(rec, "decision");
|
|
4674
|
+
if (!requestId || !decision) return null;
|
|
4675
|
+
return {
|
|
4676
|
+
type: "permission_result",
|
|
4677
|
+
requestId,
|
|
4678
|
+
decision,
|
|
4679
|
+
actor: str(rec, "actor"),
|
|
4680
|
+
decidedAt: str(rec, "decided_at") ?? str(rec, "decidedAt")
|
|
4681
|
+
};
|
|
4682
|
+
}
|
|
4683
|
+
case "usage": {
|
|
4684
|
+
return {
|
|
4685
|
+
type: "usage",
|
|
4686
|
+
inputTokens: num(rec, "input_tokens") ?? num(rec, "inputTokens"),
|
|
4687
|
+
outputTokens: num(rec, "output_tokens") ?? num(rec, "outputTokens"),
|
|
4688
|
+
cacheRead: num(rec, "cache_read") ?? num(rec, "cacheRead"),
|
|
4689
|
+
cacheCreate: num(rec, "cache_create") ?? num(rec, "cacheCreate"),
|
|
4690
|
+
exact: bool(rec, "exact")
|
|
4691
|
+
};
|
|
4692
|
+
}
|
|
4693
|
+
case "settle": {
|
|
4694
|
+
const status = str(rec, "status");
|
|
4695
|
+
if (!status) return null;
|
|
4696
|
+
return { type: "settle", status, billed: bool(rec, "billed") };
|
|
4697
|
+
}
|
|
4698
|
+
case "status": {
|
|
4699
|
+
const phase = str(rec, "phase");
|
|
4700
|
+
if (!phase) return null;
|
|
4701
|
+
return { type: "status", phase, message: str(rec, "message") };
|
|
4702
|
+
}
|
|
4703
|
+
case "error": {
|
|
4704
|
+
const code = str(rec, "code");
|
|
4705
|
+
const message = str(rec, "message");
|
|
4706
|
+
if (!code || !message) return null;
|
|
4707
|
+
return {
|
|
4708
|
+
type: "error",
|
|
4709
|
+
code,
|
|
4710
|
+
message,
|
|
4711
|
+
retryable: bool(rec, "retryable"),
|
|
4712
|
+
kind: str(rec, "kind")
|
|
4713
|
+
};
|
|
4714
|
+
}
|
|
4715
|
+
case "done": {
|
|
4716
|
+
const reason = str(rec, "reason");
|
|
4717
|
+
const runId = str(rec, "run_id") ?? str(rec, "runId");
|
|
4718
|
+
const finalStatus = str(rec, "final_status") ?? str(rec, "finalStatus");
|
|
4719
|
+
if (!reason || !runId || !finalStatus) return null;
|
|
4720
|
+
return { type: "done", reason, runId, finalStatus };
|
|
4721
|
+
}
|
|
4722
|
+
default:
|
|
4723
|
+
return null;
|
|
4724
|
+
}
|
|
4725
|
+
}
|
|
4726
|
+
function isTerminalRemoteEvent(ev) {
|
|
4727
|
+
return ev.type === "done" || ev.type === "settle";
|
|
4728
|
+
}
|
|
4729
|
+
|
|
4489
4730
|
// src/agent-runs/client.ts
|
|
4490
4731
|
var agentRunsByClient = /* @__PURE__ */ new WeakMap();
|
|
4491
4732
|
Object.defineProperty(Client.prototype, "agentRuns", {
|
|
@@ -4538,6 +4779,62 @@ var AgentRunsClient = class {
|
|
|
4538
4779
|
{ retryOn401: false }
|
|
4539
4780
|
).then(fromWireRun);
|
|
4540
4781
|
}
|
|
4782
|
+
/**
|
|
4783
|
+
* Create a CrabCode remote-control agent run (contract §3, ADR-2 + ADR-5).
|
|
4784
|
+
*
|
|
4785
|
+
* Equivalent to `create()` with `runtime: 'crabcode_remote'` and the required
|
|
4786
|
+
* `runner` + `adapter` fields set. Per-session policies (permission/workspace)
|
|
4787
|
+
* are forwarded to the gateway, which is the only side allowed to enforce
|
|
4788
|
+
* them (contract §6). The SDK never enforces remote permissions client-side.
|
|
4789
|
+
*
|
|
4790
|
+
* The corresponding stream uses `streamRemoteControl(runId)`, NOT `stream()`,
|
|
4791
|
+
* because the event union is different (contract §4).
|
|
4792
|
+
*/
|
|
4793
|
+
async createRemoteRun(req, signal) {
|
|
4794
|
+
if (req.runtime !== "crabcode_remote") {
|
|
4795
|
+
throw new Error('createRemoteRun: runtime must be "crabcode_remote"');
|
|
4796
|
+
}
|
|
4797
|
+
if (!req.runner) throw new Error("createRemoteRun: runner is required");
|
|
4798
|
+
if (!req.adapter) throw new Error("createRemoteRun: adapter is required");
|
|
4799
|
+
return this.create(req, signal);
|
|
4800
|
+
}
|
|
4801
|
+
/**
|
|
4802
|
+
* Stream remote-control events for a CrabCode remote run (contract §4).
|
|
4803
|
+
*
|
|
4804
|
+
* Yields the canonical 11-event union: text_delta / reasoning_delta /
|
|
4805
|
+
* tool_call / tool_result / permission_request / permission_result /
|
|
4806
|
+
* usage / settle / status / error / done.
|
|
4807
|
+
*
|
|
4808
|
+
* Iteration ends naturally when a terminal event (`done` or `settle`) is
|
|
4809
|
+
* observed. Per contract §4, `error` alone is non-terminal — terminal errors
|
|
4810
|
+
* are carried by `done.reason` / `done.final_status`.
|
|
4811
|
+
*
|
|
4812
|
+
* Unknown event types and malformed frames are silently skipped (warn-only),
|
|
4813
|
+
* matching `parseRemoteControlEvent`'s null-return contract.
|
|
4814
|
+
*/
|
|
4815
|
+
streamRemoteControl(runId, signal) {
|
|
4816
|
+
return {
|
|
4817
|
+
[Symbol.asyncIterator]: () => this.streamRemoteControlGen(runId, signal)
|
|
4818
|
+
};
|
|
4819
|
+
}
|
|
4820
|
+
async *streamRemoteControlGen(runId, signal) {
|
|
4821
|
+
const resp = await this.requestRaw(
|
|
4822
|
+
"GET",
|
|
4823
|
+
`/agent-runs/${encodeURIComponent(runId)}/stream`,
|
|
4824
|
+
null,
|
|
4825
|
+
signal,
|
|
4826
|
+
{ retryOn401: true, accept: "text/event-stream" }
|
|
4827
|
+
);
|
|
4828
|
+
if (!resp.body) {
|
|
4829
|
+
throw new Error("remote-control stream: empty response body");
|
|
4830
|
+
}
|
|
4831
|
+
for await (const rawEvent of readAgentRunSSEFrames(resp.body)) {
|
|
4832
|
+
const ev = parseRemoteControlEvent(rawEvent);
|
|
4833
|
+
if (!ev) continue;
|
|
4834
|
+
yield ev;
|
|
4835
|
+
if (isTerminalRemoteEvent(ev)) return;
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4541
4838
|
listArtifacts(runId, signal) {
|
|
4542
4839
|
return this.requestAPI(
|
|
4543
4840
|
"GET",
|
|
@@ -4697,6 +4994,24 @@ var AgentRunsClient = class {
|
|
|
4697
4994
|
return resp;
|
|
4698
4995
|
}
|
|
4699
4996
|
};
|
|
4997
|
+
function toWirePermissionPolicy(p) {
|
|
4998
|
+
return {
|
|
4999
|
+
shell_allowed: p.shellAllowed,
|
|
5000
|
+
shell_deny_list: p.shellDenyList,
|
|
5001
|
+
network_allowed: p.networkAllowed,
|
|
5002
|
+
write_allowed: p.writeAllowed,
|
|
5003
|
+
approval_timeout_ms: p.approvalTimeoutMs,
|
|
5004
|
+
required_actors: p.requiredActors
|
|
5005
|
+
};
|
|
5006
|
+
}
|
|
5007
|
+
function toWireWorkspacePolicy(p) {
|
|
5008
|
+
return {
|
|
5009
|
+
read_only: p.readOnly,
|
|
5010
|
+
allowed_paths: p.allowedPaths,
|
|
5011
|
+
denied_paths: p.deniedPaths,
|
|
5012
|
+
max_bytes: p.maxBytes
|
|
5013
|
+
};
|
|
5014
|
+
}
|
|
4700
5015
|
function toWireCreateRequest(req) {
|
|
4701
5016
|
return {
|
|
4702
5017
|
app_id: req.appId,
|
|
@@ -4714,6 +5029,11 @@ function toWireCreateRequest(req) {
|
|
|
4714
5029
|
max_bytes: req.localContextPolicy.maxBytes,
|
|
4715
5030
|
allowed_tools: req.localContextPolicy.allowedTools
|
|
4716
5031
|
} : void 0,
|
|
5032
|
+
runtime: req.runtime,
|
|
5033
|
+
runner: req.runner,
|
|
5034
|
+
adapter: req.adapter,
|
|
5035
|
+
permission_policy: req.permissionPolicy ? toWirePermissionPolicy(req.permissionPolicy) : void 0,
|
|
5036
|
+
workspace_policy: req.workspacePolicy ? toWireWorkspacePolicy(req.workspacePolicy) : void 0,
|
|
4717
5037
|
artifact_policy: req.artifactPolicy ? {
|
|
4718
5038
|
enabled: req.artifactPolicy.enabled,
|
|
4719
5039
|
max_files: req.artifactPolicy.maxFiles
|
|
@@ -4759,6 +5079,46 @@ function fromWireArtifact(resp) {
|
|
|
4759
5079
|
metadata: resp.metadata
|
|
4760
5080
|
};
|
|
4761
5081
|
}
|
|
5082
|
+
async function* readAgentRunSSEFrames(body) {
|
|
5083
|
+
let eventName = "";
|
|
5084
|
+
let dataLines = [];
|
|
5085
|
+
const flush = () => {
|
|
5086
|
+
if (dataLines.length === 0) return null;
|
|
5087
|
+
const data = dataLines.join("\n");
|
|
5088
|
+
dataLines = [];
|
|
5089
|
+
if (data === "[DONE]") return null;
|
|
5090
|
+
try {
|
|
5091
|
+
const parsed = JSON.parse(data);
|
|
5092
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
5093
|
+
const obj = parsed;
|
|
5094
|
+
if (!("type" in obj) && eventName) {
|
|
5095
|
+
obj.type = eventName;
|
|
5096
|
+
}
|
|
5097
|
+
return obj;
|
|
5098
|
+
}
|
|
5099
|
+
} catch {
|
|
5100
|
+
}
|
|
5101
|
+
return null;
|
|
5102
|
+
};
|
|
5103
|
+
for await (const line of iterSSELines(body)) {
|
|
5104
|
+
if (line === "") {
|
|
5105
|
+
const frame2 = flush();
|
|
5106
|
+
eventName = "";
|
|
5107
|
+
if (frame2) yield frame2;
|
|
5108
|
+
continue;
|
|
5109
|
+
}
|
|
5110
|
+
if (line.startsWith(":")) continue;
|
|
5111
|
+
if (line.startsWith("event:")) {
|
|
5112
|
+
eventName = line.slice("event:".length).trim();
|
|
5113
|
+
continue;
|
|
5114
|
+
}
|
|
5115
|
+
if (line.startsWith("data:")) {
|
|
5116
|
+
dataLines.push(line.slice("data:".length).trimStart());
|
|
5117
|
+
}
|
|
5118
|
+
}
|
|
5119
|
+
const frame = flush();
|
|
5120
|
+
if (frame) yield frame;
|
|
5121
|
+
}
|
|
4762
5122
|
async function* readAgentRunEvents(body) {
|
|
4763
5123
|
let eventName = "";
|
|
4764
5124
|
let dataLines = [];
|
|
@@ -6148,6 +6508,11 @@ Client.prototype.listUserSubscriptions = async function(signal) {
|
|
|
6148
6508
|
);
|
|
6149
6509
|
return Array.isArray(resp.data) ? resp.data : [];
|
|
6150
6510
|
};
|
|
6511
|
+
Client.prototype.getPlanByCode = async function(planCode, signal) {
|
|
6512
|
+
if (!planCode) return null;
|
|
6513
|
+
const plans = await this.listPlans(void 0, signal);
|
|
6514
|
+
return plans.find((p) => p.planCode === planCode) ?? null;
|
|
6515
|
+
};
|
|
6151
6516
|
|
|
6152
6517
|
// src/pricing/client.ts
|
|
6153
6518
|
Client.prototype.getPricingConfig = async function(key, signal) {
|
|
@@ -6521,6 +6886,44 @@ Client.prototype.listMyCorporateTransfers = async function(signal) {
|
|
|
6521
6886
|
return resp.data ?? [];
|
|
6522
6887
|
};
|
|
6523
6888
|
|
|
6889
|
+
// src/chatbridge/types.ts
|
|
6890
|
+
var ALL_PLATFORMS = [
|
|
6891
|
+
"feishu",
|
|
6892
|
+
"wecom",
|
|
6893
|
+
"dingtalk",
|
|
6894
|
+
"slack",
|
|
6895
|
+
"teams",
|
|
6896
|
+
"telegram",
|
|
6897
|
+
"whatsapp"
|
|
6898
|
+
];
|
|
6899
|
+
var ALL_REGIONS = ["cn", "intl"];
|
|
6900
|
+
var ALL_INTEGRATION_STATUS = [
|
|
6901
|
+
"pending",
|
|
6902
|
+
"active",
|
|
6903
|
+
"suspended",
|
|
6904
|
+
"revoked"
|
|
6905
|
+
];
|
|
6906
|
+
function isPlatform(v) {
|
|
6907
|
+
return typeof v === "string" && ALL_PLATFORMS.includes(v);
|
|
6908
|
+
}
|
|
6909
|
+
function isRegion(v) {
|
|
6910
|
+
return typeof v === "string" && ALL_REGIONS.includes(v);
|
|
6911
|
+
}
|
|
6912
|
+
function isIntegrationStatus(v) {
|
|
6913
|
+
return typeof v === "string" && ALL_INTEGRATION_STATUS.includes(v);
|
|
6914
|
+
}
|
|
6915
|
+
function isChannelInboundEvent(v) {
|
|
6916
|
+
if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
|
|
6917
|
+
const r = v;
|
|
6918
|
+
return isPlatform(r.platform) && typeof r.threadHash === "string" && r.threadHash.length > 0 && typeof r.content === "string";
|
|
6919
|
+
}
|
|
6920
|
+
function asCredentialRef(s) {
|
|
6921
|
+
return s;
|
|
6922
|
+
}
|
|
6923
|
+
|
|
6924
|
+
exports.ALL_INTEGRATION_STATUS = ALL_INTEGRATION_STATUS;
|
|
6925
|
+
exports.ALL_PLATFORMS = ALL_PLATFORMS;
|
|
6926
|
+
exports.ALL_REGIONS = ALL_REGIONS;
|
|
6524
6927
|
exports.AgentRunStreamError = AgentRunStreamError;
|
|
6525
6928
|
exports.AgentRunsClient = AgentRunsClient;
|
|
6526
6929
|
exports.AudienceEnum = AudienceEnum;
|
|
@@ -6528,6 +6931,7 @@ exports.BillingModeEnum = BillingModeEnum;
|
|
|
6528
6931
|
exports.Client = Client;
|
|
6529
6932
|
exports.ComplianceClient = ComplianceClient;
|
|
6530
6933
|
exports.CompliancePollError = CompliancePollError;
|
|
6934
|
+
exports.DEFAULT_GATEWAY_BASE_URL = DEFAULT_GATEWAY_BASE_URL;
|
|
6531
6935
|
exports.DefaultRetryPolicy = DefaultRetryPolicy;
|
|
6532
6936
|
exports.ErrAuthDenied = ErrAuthDenied;
|
|
6533
6937
|
exports.ErrBillingCallbackCannotCommit = ErrBillingCallbackCannotCommit;
|
|
@@ -6571,6 +6975,7 @@ exports.FilterStatusUnknown = FilterStatusUnknown;
|
|
|
6571
6975
|
exports.IdempotencyKeyHeader = IdempotencyKeyHeader;
|
|
6572
6976
|
exports.InMemoryTokenStore = InMemoryTokenStore;
|
|
6573
6977
|
exports.LocalStorageTokenStore = LocalStorageTokenStore;
|
|
6978
|
+
exports.OAuthTokenEndpointError = OAuthTokenEndpointError;
|
|
6574
6979
|
exports.ProductFamilyEnum = ProductFamilyEnum;
|
|
6575
6980
|
exports.RETRY_ADVICE_REASONS = RETRY_ADVICE_REASONS;
|
|
6576
6981
|
exports.RegionScopeEnum = RegionScopeEnum;
|
|
@@ -6595,6 +7000,10 @@ exports.ScopeEntitlements = ScopeEntitlements;
|
|
|
6595
7000
|
exports.ScopeModels = ScopeModels;
|
|
6596
7001
|
exports.ScopeModelsChat = ScopeModelsChat;
|
|
6597
7002
|
exports.ScopeProfile = ScopeProfile;
|
|
7003
|
+
exports.ScopeRemoteControl = ScopeRemoteControl;
|
|
7004
|
+
exports.ScopeRemoteControlAgentRun = ScopeRemoteControlAgentRun;
|
|
7005
|
+
exports.ScopeRemoteControlPermissionResponse = ScopeRemoteControlPermissionResponse;
|
|
7006
|
+
exports.ScopeRemoteControlSessionControl = ScopeRemoteControlSessionControl;
|
|
6598
7007
|
exports.ScopeSkillStore = ScopeSkillStore;
|
|
6599
7008
|
exports.ScopeSkills = ScopeSkills;
|
|
6600
7009
|
exports.ScopeTokenPackages = ScopeTokenPackages;
|
|
@@ -6608,6 +7017,7 @@ exports.anthropicResponseThinkingContent = anthropicResponseThinkingContent;
|
|
|
6608
7017
|
exports.anthropicResponseToolUseBlocks = anthropicResponseToolUseBlocks;
|
|
6609
7018
|
exports.apiResponseBusinessError = apiResponseBusinessError;
|
|
6610
7019
|
exports.apiResponseGetMessage = apiResponseGetMessage;
|
|
7020
|
+
exports.asCredentialRef = asCredentialRef;
|
|
6611
7021
|
exports.authorize = authorize;
|
|
6612
7022
|
exports.bucketInfoIsCommercial = bucketInfoIsCommercial;
|
|
6613
7023
|
exports.bucketRowIsCommercial = bucketRowIsCommercial;
|
|
@@ -6634,10 +7044,16 @@ exports.generateState = generateState;
|
|
|
6634
7044
|
exports.getAdapter = getAdapter;
|
|
6635
7045
|
exports.getAdapterForModel = getAdapterForModel;
|
|
6636
7046
|
exports.isBillingConfirmable = isBillingConfirmable;
|
|
7047
|
+
exports.isChannelInboundEvent = isChannelInboundEvent;
|
|
6637
7048
|
exports.isComplianceBusinessError = isComplianceBusinessError;
|
|
6638
7049
|
exports.isComplianceTerminalError = isComplianceTerminalError;
|
|
7050
|
+
exports.isIntegrationStatus = isIntegrationStatus;
|
|
7051
|
+
exports.isInvalidGrantError = isInvalidGrantError;
|
|
7052
|
+
exports.isPlatform = isPlatform;
|
|
7053
|
+
exports.isRegion = isRegion;
|
|
6639
7054
|
exports.isSSECommentLine = isSSECommentLine;
|
|
6640
7055
|
exports.isSSLError = isSSLError;
|
|
7056
|
+
exports.isTerminalRemoteEvent = isTerminalRemoteEvent;
|
|
6641
7057
|
exports.maxEndUserIdLength = maxEndUserIdLength;
|
|
6642
7058
|
exports.modelScopes = modelScopes;
|
|
6643
7059
|
exports.modelSupportsImageInput = modelSupportsImageInput;
|
|
@@ -6646,12 +7062,15 @@ exports.newFileTokenStore = newFileTokenStore;
|
|
|
6646
7062
|
exports.newThinkingConfig = newThinkingConfig;
|
|
6647
7063
|
exports.newTokenSet = newTokenSet;
|
|
6648
7064
|
exports.newWebSearchTool = newWebSearchTool;
|
|
7065
|
+
exports.normalizeGatewayBaseURL = normalizeGatewayBaseURL;
|
|
6649
7066
|
exports.parseNotificationEvent = parseNotificationEvent;
|
|
7067
|
+
exports.parseRemoteControlEvent = parseRemoteControlEvent;
|
|
6650
7068
|
exports.parseSettlement = parseSettlement;
|
|
6651
7069
|
exports.parseSourcesEvent = parseSourcesEvent;
|
|
6652
7070
|
exports.refreshToken = refreshToken;
|
|
6653
7071
|
exports.register = register;
|
|
6654
7072
|
exports.registerWebOAuthClient = registerWebOAuthClient;
|
|
7073
|
+
exports.remoteControlScopes = remoteControlScopes;
|
|
6655
7074
|
exports.retryReasonForComplianceKey = retryReasonForComplianceKey;
|
|
6656
7075
|
exports.retryReasonForOAuthError = retryReasonForOAuthError;
|
|
6657
7076
|
exports.revokeToken = revokeToken;
|