@acosmi/sdk-ts 2.6.0 → 2.7.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 +20 -0
- package/README.md +74 -11
- package/dist/browser/index.mjs +307 -2
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +307 -2
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +310 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +228 -3
- package/dist/node/index.d.ts +228 -3
- package/dist/node/index.mjs +307 -2
- 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 +6 -4
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -4765,6 +4765,8 @@ async function sleepWithSignal2(ms, signal) {
|
|
|
4765
4765
|
}
|
|
4766
4766
|
|
|
4767
4767
|
// src/agent-runs/types.ts
|
|
4768
|
+
var AGENT_RUN_META_TITLE = "title";
|
|
4769
|
+
var AGENT_RUN_META_WORKSPACE = "workspace";
|
|
4768
4770
|
var AgentRunStreamError = class extends Error {
|
|
4769
4771
|
event;
|
|
4770
4772
|
code;
|
|
@@ -4940,6 +4942,33 @@ var AgentRunsClient = class {
|
|
|
4940
4942
|
);
|
|
4941
4943
|
return fromWireCreateResponse(resp);
|
|
4942
4944
|
}
|
|
4945
|
+
/**
|
|
4946
|
+
* List the caller's own agent runs, newest first (GET /agent-runs, Phase 5C
|
|
4947
|
+
* console). Returns view metadata only — never session tokens, policies or
|
|
4948
|
+
* messages (contract §6). Filter remote-control runs with
|
|
4949
|
+
* `{ runtime: 'crabcode_remote' }`.
|
|
4950
|
+
*/
|
|
4951
|
+
async list(opts = {}, signal) {
|
|
4952
|
+
const params = new URLSearchParams();
|
|
4953
|
+
if (opts.runtime) params.set("runtime", opts.runtime);
|
|
4954
|
+
if (opts.status) params.set("status", opts.status);
|
|
4955
|
+
if (opts.page != null) params.set("page", String(opts.page));
|
|
4956
|
+
if (opts.pageSize != null) params.set("page_size", String(opts.pageSize));
|
|
4957
|
+
const qs = params.toString();
|
|
4958
|
+
const resp = await this.requestAPI(
|
|
4959
|
+
"GET",
|
|
4960
|
+
`/agent-runs${qs ? `?${qs}` : ""}`,
|
|
4961
|
+
null,
|
|
4962
|
+
signal,
|
|
4963
|
+
{ retryOn401: true }
|
|
4964
|
+
);
|
|
4965
|
+
return {
|
|
4966
|
+
records: (resp.records ?? []).map(fromWireRun),
|
|
4967
|
+
total: typeof resp.total === "number" ? resp.total : 0,
|
|
4968
|
+
page: typeof resp.page === "number" ? resp.page : 1,
|
|
4969
|
+
pageSize: typeof resp.pageSize === "number" ? resp.pageSize : 20
|
|
4970
|
+
};
|
|
4971
|
+
}
|
|
4943
4972
|
get(runId, signal) {
|
|
4944
4973
|
return this.requestAPI(
|
|
4945
4974
|
"GET",
|
|
@@ -5001,6 +5030,73 @@ var AgentRunsClient = class {
|
|
|
5001
5030
|
[Symbol.asyncIterator]: () => this.streamRemoteControlGen(runId, signal)
|
|
5002
5031
|
};
|
|
5003
5032
|
}
|
|
5033
|
+
/**
|
|
5034
|
+
* Submit a permission decision for a pending `permission_request` event
|
|
5035
|
+
* (POST /agent-runs/:runId/permission-results, contract §4/§9/§14).
|
|
5036
|
+
*
|
|
5037
|
+
* Only `approved` | `rejected` may be submitted by clients — `timeout` /
|
|
5038
|
+
* `cancelled` are produced server-side. Requires an OAuth token with the
|
|
5039
|
+
* explicit `remote_control` scope (or a web JWT). 409 means the remote
|
|
5040
|
+
* session is gone (e.g. already terminated).
|
|
5041
|
+
*/
|
|
5042
|
+
async submitPermissionResult(runId, result, signal) {
|
|
5043
|
+
await this.requestAPI(
|
|
5044
|
+
"POST",
|
|
5045
|
+
`/agent-runs/${encodeURIComponent(runId)}/permission-results`,
|
|
5046
|
+
{
|
|
5047
|
+
request_id: result.requestId,
|
|
5048
|
+
decision: result.decision,
|
|
5049
|
+
reason: result.reason
|
|
5050
|
+
},
|
|
5051
|
+
signal,
|
|
5052
|
+
{ retryOn401: false }
|
|
5053
|
+
);
|
|
5054
|
+
}
|
|
5055
|
+
/**
|
|
5056
|
+
* Append a mid-session user message to a remote run
|
|
5057
|
+
* (POST /agent-runs/:runId/messages, Phase 5C). The message role is
|
|
5058
|
+
* hard-coded to 'user' server-side (contract §6 #5 prompt-injection
|
|
5059
|
+
* defence); content is limited to 64KB. Requires the explicit
|
|
5060
|
+
* `remote_control` scope (or a web JWT).
|
|
5061
|
+
*/
|
|
5062
|
+
async submitUserMessage(runId, message, signal) {
|
|
5063
|
+
const resp = await this.requestAPI(
|
|
5064
|
+
"POST",
|
|
5065
|
+
`/agent-runs/${encodeURIComponent(runId)}/messages`,
|
|
5066
|
+
{ request_id: message.requestId, content: message.content },
|
|
5067
|
+
signal,
|
|
5068
|
+
{ retryOn401: false }
|
|
5069
|
+
);
|
|
5070
|
+
return {
|
|
5071
|
+
ok: resp?.ok === true,
|
|
5072
|
+
requestId: resp?.request_id ?? message.requestId ?? ""
|
|
5073
|
+
};
|
|
5074
|
+
}
|
|
5075
|
+
/**
|
|
5076
|
+
* Reveal the one-shot remote session token for a desktop-runner run
|
|
5077
|
+
* (POST /agent-runs/:runId/remote-token, Phase 5B; contract §18.1).
|
|
5078
|
+
*
|
|
5079
|
+
* Desktop launcher only: the token is single-consumption (a second call
|
|
5080
|
+
* returns 409) and must never touch browser storage — receive it in the
|
|
5081
|
+
* native layer and inject it into the CrabCode child-process env only
|
|
5082
|
+
* (contract §6). Cloud / local_embedded runners never expose tokens over
|
|
5083
|
+
* HTTP (403). Requires the explicit `remote_control` scope.
|
|
5084
|
+
*/
|
|
5085
|
+
async revealRemoteToken(runId, signal) {
|
|
5086
|
+
const resp = await this.requestAPI(
|
|
5087
|
+
"POST",
|
|
5088
|
+
`/agent-runs/${encodeURIComponent(runId)}/remote-token`,
|
|
5089
|
+
{},
|
|
5090
|
+
signal,
|
|
5091
|
+
{ retryOn401: false }
|
|
5092
|
+
);
|
|
5093
|
+
return {
|
|
5094
|
+
accessToken: resp?.access_token ?? "",
|
|
5095
|
+
sessionUrl: resp?.session_url ?? "",
|
|
5096
|
+
tenantId: resp?.tenant_id ?? "",
|
|
5097
|
+
workspace: resp?.workspace || void 0
|
|
5098
|
+
};
|
|
5099
|
+
}
|
|
5004
5100
|
async *streamRemoteControlGen(runId, signal) {
|
|
5005
5101
|
const resp = await this.requestRaw(
|
|
5006
5102
|
"GET",
|
|
@@ -5251,6 +5347,7 @@ function toWireCreateRequest(req) {
|
|
|
5251
5347
|
adapter: req.adapter,
|
|
5252
5348
|
permission_policy: req.permissionPolicy ? toWirePermissionPolicy(req.permissionPolicy) : void 0,
|
|
5253
5349
|
workspace_policy: req.workspacePolicy ? toWireWorkspacePolicy(req.workspacePolicy) : void 0,
|
|
5350
|
+
byok_credential_ref: req.byokCredentialRef,
|
|
5254
5351
|
artifact_policy: req.artifactPolicy ? {
|
|
5255
5352
|
enabled: req.artifactPolicy.enabled,
|
|
5256
5353
|
max_files: req.artifactPolicy.maxFiles
|
|
@@ -5283,7 +5380,10 @@ function fromWireRun(resp) {
|
|
|
5283
5380
|
startedAt: resp.started_at,
|
|
5284
5381
|
completedAt: resp.completed_at,
|
|
5285
5382
|
error: normalizeError(resp.error),
|
|
5286
|
-
metadata: resp.metadata
|
|
5383
|
+
metadata: resp.metadata,
|
|
5384
|
+
runtime: resp.runtime,
|
|
5385
|
+
runner: resp.runner,
|
|
5386
|
+
adapter: resp.adapter
|
|
5287
5387
|
};
|
|
5288
5388
|
}
|
|
5289
5389
|
function fromWireArtifact(resp) {
|
|
@@ -5541,6 +5641,87 @@ function errorMessage(e) {
|
|
|
5541
5641
|
return e instanceof Error ? e.message : String(e);
|
|
5542
5642
|
}
|
|
5543
5643
|
|
|
5644
|
+
// src/agent-runs/byok.ts
|
|
5645
|
+
function fromWireByok(v) {
|
|
5646
|
+
return {
|
|
5647
|
+
credentialRef: v.credential_ref ?? "",
|
|
5648
|
+
provider: v.provider ?? "",
|
|
5649
|
+
name: v.name || void 0,
|
|
5650
|
+
baseUrl: v.base_url || void 0,
|
|
5651
|
+
fingerprint: v.fingerprint || void 0,
|
|
5652
|
+
status: v.status ?? "",
|
|
5653
|
+
createdAt: v.created_at || void 0,
|
|
5654
|
+
lastUsedAt: v.last_used_at || void 0
|
|
5655
|
+
};
|
|
5656
|
+
}
|
|
5657
|
+
var byokByClient = /* @__PURE__ */ new WeakMap();
|
|
5658
|
+
Object.defineProperty(Client.prototype, "crabcodeByok", {
|
|
5659
|
+
configurable: true,
|
|
5660
|
+
enumerable: false,
|
|
5661
|
+
get() {
|
|
5662
|
+
let existing = byokByClient.get(this);
|
|
5663
|
+
if (!existing) {
|
|
5664
|
+
existing = new CrabCodeByokClient(this);
|
|
5665
|
+
byokByClient.set(this, existing);
|
|
5666
|
+
}
|
|
5667
|
+
return existing;
|
|
5668
|
+
}
|
|
5669
|
+
});
|
|
5670
|
+
var CrabCodeByokClient = class {
|
|
5671
|
+
constructor(client) {
|
|
5672
|
+
this.client = client;
|
|
5673
|
+
}
|
|
5674
|
+
client;
|
|
5675
|
+
/** 列出调用者自己的密钥 (masked; 新→旧, 服务端上限 100 条)。 */
|
|
5676
|
+
async list(signal) {
|
|
5677
|
+
const resp = await this.client.doJSON(
|
|
5678
|
+
"GET",
|
|
5679
|
+
"/crabcode/byok-credentials",
|
|
5680
|
+
null,
|
|
5681
|
+
signal
|
|
5682
|
+
);
|
|
5683
|
+
return (resp.data?.items ?? []).map(fromWireByok);
|
|
5684
|
+
}
|
|
5685
|
+
/**
|
|
5686
|
+
* 创建密钥 — 明文一次性提交, 返回 masked 视图。
|
|
5687
|
+
* 单用户上限 20 把; provider='custom' 必须带 https:// baseUrl。
|
|
5688
|
+
*/
|
|
5689
|
+
async create(req, signal) {
|
|
5690
|
+
const resp = await this.client.doJSON(
|
|
5691
|
+
"POST",
|
|
5692
|
+
"/crabcode/byok-credentials",
|
|
5693
|
+
{
|
|
5694
|
+
provider: req.provider,
|
|
5695
|
+
name: req.name,
|
|
5696
|
+
base_url: req.baseUrl,
|
|
5697
|
+
plaintext: req.plaintext
|
|
5698
|
+
},
|
|
5699
|
+
signal
|
|
5700
|
+
);
|
|
5701
|
+
return fromWireByok(resp.data ?? {});
|
|
5702
|
+
}
|
|
5703
|
+
/** 轮换密钥明文 — credentialRef 不变, fingerprint 更新。已吊销的密钥不可轮换 (400)。 */
|
|
5704
|
+
async rotate(credentialRef, newPlaintext, signal) {
|
|
5705
|
+
const resp = await this.client.doJSON(
|
|
5706
|
+
"POST",
|
|
5707
|
+
`/crabcode/byok-credentials/${encodeURIComponent(credentialRef)}/rotate`,
|
|
5708
|
+
{ new_plaintext: newPlaintext },
|
|
5709
|
+
signal
|
|
5710
|
+
);
|
|
5711
|
+
return fromWireByok(resp.data ?? {});
|
|
5712
|
+
}
|
|
5713
|
+
/** 吊销密钥 (软状态 + 服务端抹密文, 不可恢复; 幂等 — 重复吊销返回当前视图)。 */
|
|
5714
|
+
async revoke(credentialRef, signal) {
|
|
5715
|
+
const resp = await this.client.doJSON(
|
|
5716
|
+
"POST",
|
|
5717
|
+
`/crabcode/byok-credentials/${encodeURIComponent(credentialRef)}/revoke`,
|
|
5718
|
+
{},
|
|
5719
|
+
signal
|
|
5720
|
+
);
|
|
5721
|
+
return fromWireByok(resp.data ?? {});
|
|
5722
|
+
}
|
|
5723
|
+
};
|
|
5724
|
+
|
|
5544
5725
|
// src/compliance/scopes.ts
|
|
5545
5726
|
var ScopeComplianceEvidenceRead = "compliance:evidence:read";
|
|
5546
5727
|
var ScopeComplianceEvidenceWrite = "compliance:evidence:write";
|
|
@@ -7194,6 +7375,132 @@ function asCredentialRef(s) {
|
|
|
7194
7375
|
return s;
|
|
7195
7376
|
}
|
|
7196
7377
|
|
|
7378
|
+
// src/chatbridge/client.ts
|
|
7379
|
+
var chatBridgeByClient = /* @__PURE__ */ new WeakMap();
|
|
7380
|
+
Object.defineProperty(Client.prototype, "chatBridge", {
|
|
7381
|
+
configurable: true,
|
|
7382
|
+
enumerable: false,
|
|
7383
|
+
get() {
|
|
7384
|
+
let existing = chatBridgeByClient.get(this);
|
|
7385
|
+
if (!existing) {
|
|
7386
|
+
existing = new ChatBridgeClient(this);
|
|
7387
|
+
chatBridgeByClient.set(this, existing);
|
|
7388
|
+
}
|
|
7389
|
+
return existing;
|
|
7390
|
+
}
|
|
7391
|
+
});
|
|
7392
|
+
var ChatBridgeClient = class {
|
|
7393
|
+
constructor(client) {
|
|
7394
|
+
this.client = client;
|
|
7395
|
+
}
|
|
7396
|
+
client;
|
|
7397
|
+
// ---------------------------------------------------------------------------
|
|
7398
|
+
// Integration 管理面
|
|
7399
|
+
// ---------------------------------------------------------------------------
|
|
7400
|
+
/** 创建平台集成 (chat_bridge:write)。云端控制台与下游 (CrabCode) 调的是同一端点/同一份数据。 */
|
|
7401
|
+
async createIntegration(req, signal) {
|
|
7402
|
+
const resp = await this.client.doJSON(
|
|
7403
|
+
"POST",
|
|
7404
|
+
"/chat-bridge/integrations",
|
|
7405
|
+
{
|
|
7406
|
+
app_id: req.appId,
|
|
7407
|
+
platform: req.platform,
|
|
7408
|
+
region: req.region,
|
|
7409
|
+
workspace_id: req.workspaceId,
|
|
7410
|
+
bot_id: req.botId,
|
|
7411
|
+
config_json: req.configJson
|
|
7412
|
+
},
|
|
7413
|
+
signal
|
|
7414
|
+
);
|
|
7415
|
+
return resp.data;
|
|
7416
|
+
}
|
|
7417
|
+
/** 列出本租户集成 (chat_bridge:read; masked 视图)。可按 appId 过滤。 */
|
|
7418
|
+
async listIntegrations(appId, signal) {
|
|
7419
|
+
const qs = appId ? `?app_id=${encodeURIComponent(appId)}` : "";
|
|
7420
|
+
const resp = await this.client.doJSON(
|
|
7421
|
+
"GET",
|
|
7422
|
+
`/chat-bridge/integrations${qs}`,
|
|
7423
|
+
null,
|
|
7424
|
+
signal
|
|
7425
|
+
);
|
|
7426
|
+
return resp.data?.items ?? [];
|
|
7427
|
+
}
|
|
7428
|
+
/** 取单个集成 (chat_bridge:read)。不存在/跨租户一律 404。 */
|
|
7429
|
+
async getIntegration(id, signal) {
|
|
7430
|
+
const resp = await this.client.doJSON(
|
|
7431
|
+
"GET",
|
|
7432
|
+
`/chat-bridge/integrations/${encodeURIComponent(id)}`,
|
|
7433
|
+
null,
|
|
7434
|
+
signal
|
|
7435
|
+
);
|
|
7436
|
+
return resp.data;
|
|
7437
|
+
}
|
|
7438
|
+
/** 更新集成状态 (chat_bridge:write): pending | active | suspended | revoked。 */
|
|
7439
|
+
async updateIntegrationStatus(id, status, signal) {
|
|
7440
|
+
await this.client.doJSON(
|
|
7441
|
+
"PATCH",
|
|
7442
|
+
`/chat-bridge/integrations/${encodeURIComponent(id)}/status`,
|
|
7443
|
+
{ status },
|
|
7444
|
+
signal
|
|
7445
|
+
);
|
|
7446
|
+
}
|
|
7447
|
+
// ---------------------------------------------------------------------------
|
|
7448
|
+
// Credential 管理面 (vault)
|
|
7449
|
+
// ---------------------------------------------------------------------------
|
|
7450
|
+
/** 存凭证 (chat_bridge:write) — 明文一次性提交, 返回 masked 记录 (ref+fingerprint)。 */
|
|
7451
|
+
async storeCredential(integrationId, req, signal) {
|
|
7452
|
+
const resp = await this.client.doJSON(
|
|
7453
|
+
"POST",
|
|
7454
|
+
`/chat-bridge/integrations/${encodeURIComponent(integrationId)}/credentials`,
|
|
7455
|
+
{
|
|
7456
|
+
secret_kind: req.secretKind,
|
|
7457
|
+
plaintext: req.plaintext,
|
|
7458
|
+
region: req.region,
|
|
7459
|
+
platform: req.platform
|
|
7460
|
+
},
|
|
7461
|
+
signal
|
|
7462
|
+
);
|
|
7463
|
+
return brandCredential(resp.data);
|
|
7464
|
+
}
|
|
7465
|
+
/** 列出集成的凭证 (chat_bridge:read; masked, 永不含明文/密文)。 */
|
|
7466
|
+
async listCredentials(integrationId, signal) {
|
|
7467
|
+
const resp = await this.client.doJSON(
|
|
7468
|
+
"GET",
|
|
7469
|
+
`/chat-bridge/integrations/${encodeURIComponent(integrationId)}/credentials`,
|
|
7470
|
+
null,
|
|
7471
|
+
signal
|
|
7472
|
+
);
|
|
7473
|
+
return (resp.data?.items ?? []).map(brandCredential);
|
|
7474
|
+
}
|
|
7475
|
+
/** 轮换凭证 (chat_bridge:rotate, 高风险) — ref 不变, fingerprint 更新。 */
|
|
7476
|
+
async rotateCredential(integrationId, secretKind, newPlaintext, signal) {
|
|
7477
|
+
const resp = await this.client.doJSON(
|
|
7478
|
+
"POST",
|
|
7479
|
+
`/chat-bridge/integrations/${encodeURIComponent(integrationId)}/credentials/rotate`,
|
|
7480
|
+
{ secret_kind: secretKind, new_plaintext: newPlaintext },
|
|
7481
|
+
signal
|
|
7482
|
+
);
|
|
7483
|
+
return brandCredential(resp.data);
|
|
7484
|
+
}
|
|
7485
|
+
/** 吊销凭证 (chat_bridge:rotate) — 软吊销 + 服务端抹密文。 */
|
|
7486
|
+
async revokeCredential(credentialRef, signal) {
|
|
7487
|
+
await this.client.doJSON(
|
|
7488
|
+
"POST",
|
|
7489
|
+
`/chat-bridge/credentials/${encodeURIComponent(credentialRef)}/revoke`,
|
|
7490
|
+
{},
|
|
7491
|
+
signal
|
|
7492
|
+
);
|
|
7493
|
+
}
|
|
7494
|
+
};
|
|
7495
|
+
function brandCredential(c) {
|
|
7496
|
+
if (c && typeof c.credentialRef === "string") {
|
|
7497
|
+
return { ...c, credentialRef: asCredentialRef(c.credentialRef) };
|
|
7498
|
+
}
|
|
7499
|
+
return c;
|
|
7500
|
+
}
|
|
7501
|
+
|
|
7502
|
+
exports.AGENT_RUN_META_TITLE = AGENT_RUN_META_TITLE;
|
|
7503
|
+
exports.AGENT_RUN_META_WORKSPACE = AGENT_RUN_META_WORKSPACE;
|
|
7197
7504
|
exports.ALL_INTEGRATION_STATUS = ALL_INTEGRATION_STATUS;
|
|
7198
7505
|
exports.ALL_PLATFORMS = ALL_PLATFORMS;
|
|
7199
7506
|
exports.ALL_REGIONS = ALL_REGIONS;
|
|
@@ -7201,9 +7508,11 @@ exports.AgentRunStreamError = AgentRunStreamError;
|
|
|
7201
7508
|
exports.AgentRunsClient = AgentRunsClient;
|
|
7202
7509
|
exports.AudienceEnum = AudienceEnum;
|
|
7203
7510
|
exports.BillingModeEnum = BillingModeEnum;
|
|
7511
|
+
exports.ChatBridgeClient = ChatBridgeClient;
|
|
7204
7512
|
exports.Client = Client;
|
|
7205
7513
|
exports.ComplianceClient = ComplianceClient;
|
|
7206
7514
|
exports.CompliancePollError = CompliancePollError;
|
|
7515
|
+
exports.CrabCodeByokClient = CrabCodeByokClient;
|
|
7207
7516
|
exports.DEFAULT_API_TIMEOUT_MS = DEFAULT_API_TIMEOUT_MS;
|
|
7208
7517
|
exports.DEFAULT_GATEWAY_BASE_URL = DEFAULT_GATEWAY_BASE_URL;
|
|
7209
7518
|
exports.DefaultRetryPolicy = DefaultRetryPolicy;
|