@acosmi/sdk-ts 2.5.1 → 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.
@@ -3894,6 +3894,10 @@ var ScopeRemoteControl = "remote_control";
3894
3894
  var ScopeRemoteControlAgentRun = "remote_control:agent-run";
3895
3895
  var ScopeRemoteControlSessionControl = "remote_control:session-control";
3896
3896
  var ScopeRemoteControlPermissionResponse = "remote_control:permission-response";
3897
+ var ScopeChatBridge = "chat_bridge";
3898
+ var ScopeChatBridgeRead = "chat_bridge:read";
3899
+ var ScopeChatBridgeWrite = "chat_bridge:write";
3900
+ var ScopeChatBridgeRotate = "chat_bridge:rotate";
3897
3901
  var ScopeModels = "models";
3898
3902
  var ScopeModelsChat = "models:chat";
3899
3903
  var ScopeEntitlements = "entitlements";
@@ -3919,6 +3923,9 @@ function skillScopes() {
3919
3923
  function remoteControlScopes() {
3920
3924
  return [ScopeRemoteControl];
3921
3925
  }
3926
+ function chatBridgeScopes() {
3927
+ return [ScopeChatBridge];
3928
+ }
3922
3929
 
3923
3930
  // src/models/index.ts
3924
3931
  init_types();
@@ -4110,9 +4117,10 @@ Client.prototype.waitForPayment = async function(orderID, pollIntervalMs, signal
4110
4117
  if (pollIntervalMs <= 0) pollIntervalMs = 2e3;
4111
4118
  while (true) {
4112
4119
  const status = await this.getOrderStatus(orderID, signal);
4113
- if (isOrderTerminal(status.status)) {
4114
- if (isOrderSuccess(status.status)) return status;
4115
- throw new exports.OrderTerminalError(orderID, status.status);
4120
+ const st = status.paymentStatus ?? status.orderStatus;
4121
+ if (isOrderTerminal(st)) {
4122
+ if (isOrderSuccess(st)) return status;
4123
+ throw new exports.OrderTerminalError(orderID, st);
4116
4124
  }
4117
4125
  await sleepWithSignal(pollIntervalMs, signal);
4118
4126
  }
@@ -4564,11 +4572,17 @@ function getWebSocketCtor() {
4564
4572
  return WSCtor;
4565
4573
  }
4566
4574
  async function wsConnectOnce(c, ws) {
4567
- const token = await c.ensureToken(ws.abort.signal);
4568
4575
  const url = wsURL(c);
4569
4576
  const WSCtor = getWebSocketCtor();
4577
+ const ticketResp = await c.doJSON(
4578
+ "POST",
4579
+ "/ws/stream-ticket",
4580
+ null,
4581
+ ws.abort.signal
4582
+ );
4583
+ const ticket = ticketResp.data.ticket;
4570
4584
  const u = new URL(url);
4571
- u.searchParams.set("token", token);
4585
+ u.searchParams.set("ticket", ticket);
4572
4586
  let conn;
4573
4587
  try {
4574
4588
  conn = new WSCtor(u.toString());
@@ -4751,6 +4765,8 @@ async function sleepWithSignal2(ms, signal) {
4751
4765
  }
4752
4766
 
4753
4767
  // src/agent-runs/types.ts
4768
+ var AGENT_RUN_META_TITLE = "title";
4769
+ var AGENT_RUN_META_WORKSPACE = "workspace";
4754
4770
  var AgentRunStreamError = class extends Error {
4755
4771
  event;
4756
4772
  code;
@@ -4926,6 +4942,33 @@ var AgentRunsClient = class {
4926
4942
  );
4927
4943
  return fromWireCreateResponse(resp);
4928
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
+ }
4929
4972
  get(runId, signal) {
4930
4973
  return this.requestAPI(
4931
4974
  "GET",
@@ -4987,6 +5030,73 @@ var AgentRunsClient = class {
4987
5030
  [Symbol.asyncIterator]: () => this.streamRemoteControlGen(runId, signal)
4988
5031
  };
4989
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
+ }
4990
5100
  async *streamRemoteControlGen(runId, signal) {
4991
5101
  const resp = await this.requestRaw(
4992
5102
  "GET",
@@ -5237,6 +5347,7 @@ function toWireCreateRequest(req) {
5237
5347
  adapter: req.adapter,
5238
5348
  permission_policy: req.permissionPolicy ? toWirePermissionPolicy(req.permissionPolicy) : void 0,
5239
5349
  workspace_policy: req.workspacePolicy ? toWireWorkspacePolicy(req.workspacePolicy) : void 0,
5350
+ byok_credential_ref: req.byokCredentialRef,
5240
5351
  artifact_policy: req.artifactPolicy ? {
5241
5352
  enabled: req.artifactPolicy.enabled,
5242
5353
  max_files: req.artifactPolicy.maxFiles
@@ -5269,7 +5380,10 @@ function fromWireRun(resp) {
5269
5380
  startedAt: resp.started_at,
5270
5381
  completedAt: resp.completed_at,
5271
5382
  error: normalizeError(resp.error),
5272
- metadata: resp.metadata
5383
+ metadata: resp.metadata,
5384
+ runtime: resp.runtime,
5385
+ runner: resp.runner,
5386
+ adapter: resp.adapter
5273
5387
  };
5274
5388
  }
5275
5389
  function fromWireArtifact(resp) {
@@ -5527,6 +5641,87 @@ function errorMessage(e) {
5527
5641
  return e instanceof Error ? e.message : String(e);
5528
5642
  }
5529
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
+
5530
5725
  // src/compliance/scopes.ts
5531
5726
  var ScopeComplianceEvidenceRead = "compliance:evidence:read";
5532
5727
  var ScopeComplianceEvidenceWrite = "compliance:evidence:write";
@@ -6736,14 +6931,36 @@ Client.prototype.listPlans = async function(audience, signal) {
6736
6931
  );
6737
6932
  return Array.isArray(resp.data) ? resp.data : [];
6738
6933
  };
6739
- Client.prototype.listUserSubscriptions = async function(signal) {
6934
+ Client.prototype.getMembership = async function(signal) {
6740
6935
  const resp = await this.doJSON(
6741
6936
  "GET",
6742
- "/distribution/user/subscriptions",
6937
+ "/entitlements/membership",
6743
6938
  null,
6744
6939
  signal
6745
6940
  );
6746
- return Array.isArray(resp.data) ? resp.data : [];
6941
+ return resp.data;
6942
+ };
6943
+ Client.prototype.getSubscriptionTier = async function(signal) {
6944
+ const resp = await this.doJSON(
6945
+ "GET",
6946
+ "/entitlements/subscription",
6947
+ null,
6948
+ signal
6949
+ );
6950
+ return resp.data;
6951
+ };
6952
+ Client.prototype.subscriptionPrecheck = async function(signal) {
6953
+ const resp = await this.doJSON(
6954
+ "GET",
6955
+ "/consumer/subscriptions/precheck",
6956
+ null,
6957
+ signal
6958
+ );
6959
+ return resp.data;
6960
+ };
6961
+ Client.prototype.listUserSubscriptions = async function(signal) {
6962
+ const m = await this.getMembership(signal);
6963
+ return m.hasActive ? [m] : [];
6747
6964
  };
6748
6965
  Client.prototype.getPlanByCode = async function(planCode, signal) {
6749
6966
  if (!planCode) return null;
@@ -7158,6 +7375,132 @@ function asCredentialRef(s) {
7158
7375
  return s;
7159
7376
  }
7160
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;
7161
7504
  exports.ALL_INTEGRATION_STATUS = ALL_INTEGRATION_STATUS;
7162
7505
  exports.ALL_PLATFORMS = ALL_PLATFORMS;
7163
7506
  exports.ALL_REGIONS = ALL_REGIONS;
@@ -7165,9 +7508,11 @@ exports.AgentRunStreamError = AgentRunStreamError;
7165
7508
  exports.AgentRunsClient = AgentRunsClient;
7166
7509
  exports.AudienceEnum = AudienceEnum;
7167
7510
  exports.BillingModeEnum = BillingModeEnum;
7511
+ exports.ChatBridgeClient = ChatBridgeClient;
7168
7512
  exports.Client = Client;
7169
7513
  exports.ComplianceClient = ComplianceClient;
7170
7514
  exports.CompliancePollError = CompliancePollError;
7515
+ exports.CrabCodeByokClient = CrabCodeByokClient;
7171
7516
  exports.DEFAULT_API_TIMEOUT_MS = DEFAULT_API_TIMEOUT_MS;
7172
7517
  exports.DEFAULT_GATEWAY_BASE_URL = DEFAULT_GATEWAY_BASE_URL;
7173
7518
  exports.DefaultRetryPolicy = DefaultRetryPolicy;
@@ -7219,6 +7564,10 @@ exports.RETRY_ADVICE_REASONS = RETRY_ADVICE_REASONS;
7219
7564
  exports.RegionScopeEnum = RegionScopeEnum;
7220
7565
  exports.ScopeAI = ScopeAI;
7221
7566
  exports.ScopeAccount = ScopeAccount;
7567
+ exports.ScopeChatBridge = ScopeChatBridge;
7568
+ exports.ScopeChatBridgeRead = ScopeChatBridgeRead;
7569
+ exports.ScopeChatBridgeRotate = ScopeChatBridgeRotate;
7570
+ exports.ScopeChatBridgeWrite = ScopeChatBridgeWrite;
7222
7571
  exports.ScopeComplianceContractSigningRead = ScopeComplianceContractSigningRead;
7223
7572
  exports.ScopeComplianceContractSigningWrite = ScopeComplianceContractSigningWrite;
7224
7573
  exports.ScopeComplianceContractTemplateRead = ScopeComplianceContractTemplateRead;
@@ -7260,6 +7609,7 @@ exports.authorize = authorize;
7260
7609
  exports.bucketInfoIsCommercial = bucketInfoIsCommercial;
7261
7610
  exports.bucketRowIsCommercial = bucketRowIsCommercial;
7262
7611
  exports.buildBetas = buildBetas;
7612
+ exports.chatBridgeScopes = chatBridgeScopes;
7263
7613
  exports.classifyComplianceError = classifyComplianceError;
7264
7614
  exports.commerceScopes = commerceScopes;
7265
7615
  exports.completeWebAuthorizationRequest = completeWebAuthorizationRequest;