@capybara-hq/kernel 0.1.0-rc.115 → 0.1.0-rc.117

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.
Files changed (73) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/agents/agents.controller.d.ts +13 -1
  3. package/dist/agents/agents.controller.js +24 -2
  4. package/dist/catalog/catalog-content.d.ts +11 -0
  5. package/dist/catalog/catalog-content.js +1 -0
  6. package/dist/catalog/catalog.service.d.ts +11 -1
  7. package/dist/catalog/catalog.service.js +36 -2
  8. package/dist/catalog/marketplaces.service.d.ts +1 -1
  9. package/dist/catalog/org-catalog.service.d.ts +1 -0
  10. package/dist/catalog/org-catalog.service.js +44 -2
  11. package/dist/catalog/platform-components.js +13 -0
  12. package/dist/catalog/plugin-connectors.d.ts +35 -0
  13. package/dist/catalog/plugin-connectors.js +81 -0
  14. package/dist/catalog/schema-path.d.ts +4 -6
  15. package/dist/catalog/schema-path.js +48 -21
  16. package/dist/channels/outbound.d.ts +5 -0
  17. package/dist/channels/outbound.js +6 -1
  18. package/dist/channels/supervisor.d.ts +5 -1
  19. package/dist/channels/supervisor.js +20 -1
  20. package/dist/conversations/conversations.controller.d.ts +46 -14
  21. package/dist/conversations/conversations.controller.js +82 -47
  22. package/dist/conversations/conversations.service.d.ts +93 -59
  23. package/dist/conversations/conversations.service.js +255 -72
  24. package/dist/conversations/events.d.ts +32 -0
  25. package/dist/conversations/events.js +47 -3
  26. package/dist/conversations/inline-tokens.d.ts +87 -0
  27. package/dist/conversations/inline-tokens.js +154 -0
  28. package/dist/conversations/permission-profiles.controller.d.ts +14 -7
  29. package/dist/conversations/permission-profiles.controller.js +1 -5
  30. package/dist/conversations/prompt-suggestions.js +2 -4
  31. package/dist/conversations/queue.d.ts +0 -2
  32. package/dist/conversations/queue.service.js +9 -13
  33. package/dist/db/kernel-schema.d.ts +2 -0
  34. package/dist/devices/devices.service.d.ts +8 -0
  35. package/dist/devices/devices.service.js +16 -0
  36. package/dist/errors.d.ts +12 -0
  37. package/dist/errors.js +12 -0
  38. package/dist/evals/snapshot.js +4 -2
  39. package/dist/files/library-files.service.d.ts +13 -0
  40. package/dist/files/library-files.service.js +33 -6
  41. package/dist/net/safe-fetch.js +1 -1
  42. package/dist/platform/exclusions.js +11 -1
  43. package/dist/platform/ops/devices.ops.js +14 -0
  44. package/dist/runtime/context/build.d.ts +7 -2
  45. package/dist/runtime/context/build.js +17 -6
  46. package/dist/runtime/context/compaction.d.ts +3 -3
  47. package/dist/runtime/context/compaction.js +12 -13
  48. package/dist/sandbox/review/classifier.js +5 -1
  49. package/dist/sandbox/sandbox.service.d.ts +13 -0
  50. package/dist/sandbox/sandbox.service.js +51 -4
  51. package/dist/tools/builtins/sandbox/common.d.ts +2 -7
  52. package/dist/tools/builtins/sandbox/common.js +4 -2
  53. package/dist/tools/connector-content.controller.d.ts +6 -2
  54. package/dist/tools/connector-content.controller.js +13 -3
  55. package/dist/tools/connector-content.d.ts +55 -15
  56. package/dist/tools/connector-content.js +112 -54
  57. package/dist/tools/connectors.service.d.ts +3 -2
  58. package/dist/tools/connectors.service.js +6 -20
  59. package/dist/tools/mentionable-connectors.d.ts +88 -0
  60. package/dist/tools/mentionable-connectors.js +218 -0
  61. package/dist/tools/pipeline.d.ts +4 -0
  62. package/dist/tools/pipeline.js +98 -22
  63. package/dist/tools/specs.d.ts +13 -4
  64. package/dist/tools/specs.js +22 -8
  65. package/dist/tools/tools.module.js +7 -0
  66. package/dist/ui/admin-ui.controller.d.ts +5 -2
  67. package/dist/ui/admin-ui.controller.js +14 -1
  68. package/dist/ui/ui.schemas.d.ts +9 -0
  69. package/dist/ui/ui.schemas.js +2 -0
  70. package/dist/ui/views.d.ts +1 -1
  71. package/dist/ui/views.js +4 -5
  72. package/package.json +3 -3
  73. package/src/migrations/0201_tool_specs_text.sql +8 -0
@@ -411,8 +411,13 @@ export declare function buildModelRequest(input: BuildModelRequestInput): {
411
411
  mediaTokens: number;
412
412
  };
413
413
  /**
414
- * 日志里 `ToolSearch` 加载过的工具 key(全部 `tool_result.loadedTools` 的并集,按首次出现顺序)。
415
- * 不看压缩摘要的边界:加载过的工具在摘要之后仍保持加载(模型可能凭摘要继续使用它们,且已发送的工具列表只追加)。
414
+ * The tool keys loaded in the log under tool search, in order of first appearance by seq: the union
415
+ * of every `tool_result.loadedTools` (what `ToolSearch` loaded) and every
416
+ * `user_message.payload.connectorMentions[].loadedTools` (a mentioned connector's offered tools,
417
+ * composer inline tokens spec §3.5). Read only when the step runs with tool search; a key the step
418
+ * does not offer is ignored by the caller. The compaction boundary is not looked at: loaded tools
419
+ * stay loaded after a summary (the model may keep using them from the summary, and the tool list
420
+ * sent is append-only).
416
421
  */
417
422
  export declare function loadedToolKeys(events: readonly ConversationEvent[]): string[];
418
423
  /** system 各块文本的 sha256(hex);按 JSON 数组哈希,避免块边界歧义。 */
@@ -1176,16 +1176,27 @@ export function buildModelRequest(input) {
1176
1176
  return { request, meta, mediaTokens };
1177
1177
  }
1178
1178
  /**
1179
- * 日志里 `ToolSearch` 加载过的工具 key(全部 `tool_result.loadedTools` 的并集,按首次出现顺序)。
1180
- * 不看压缩摘要的边界:加载过的工具在摘要之后仍保持加载(模型可能凭摘要继续使用它们,且已发送的工具列表只追加)。
1179
+ * The tool keys loaded in the log under tool search, in order of first appearance by seq: the union
1180
+ * of every `tool_result.loadedTools` (what `ToolSearch` loaded) and every
1181
+ * `user_message.payload.connectorMentions[].loadedTools` (a mentioned connector's offered tools,
1182
+ * composer inline tokens spec §3.5). Read only when the step runs with tool search; a key the step
1183
+ * does not offer is ignored by the caller. The compaction boundary is not looked at: loaded tools
1184
+ * stay loaded after a summary (the model may keep using them from the summary, and the tool list
1185
+ * sent is append-only).
1181
1186
  */
1182
1187
  export function loadedToolKeys(events) {
1183
1188
  const out = new Set();
1184
1189
  for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
1185
- if (e.type !== "tool_result")
1186
- continue;
1187
- for (const k of e.payload.loadedTools ?? [])
1188
- out.add(k);
1190
+ if (e.type === "tool_result") {
1191
+ for (const k of e.payload.loadedTools ?? [])
1192
+ out.add(k);
1193
+ }
1194
+ else if (e.type === "user_message") {
1195
+ for (const m of e.payload.connectorMentions ?? []) {
1196
+ for (const k of m.loadedTools)
1197
+ out.add(k);
1198
+ }
1199
+ }
1189
1200
  }
1190
1201
  return [...out];
1191
1202
  }
@@ -124,9 +124,9 @@ export declare function openingSeqs(events: readonly ConversationEvent[], runId:
124
124
  /**
125
125
  * The opening messages a manual compaction's summary re-renders (context compaction spec §4.7,
126
126
  * maintainer decision 2026-11-28): a compact run is started by no message, so its own run has none;
127
- * the turn it cuts into is the one the latest run a message started (trigger `message` or
128
- * `schedule`) opened, and {@link openingSeqs} of that run decides which of its opening messages the
129
- * summary covers. None when no such run is in the log.
127
+ * the turn it cuts into is the one the latest run a message started (trigger `message`,
128
+ * `schedule` or `automation_event`) opened, and {@link openingSeqs} of that run decides which of
129
+ * its opening messages the summary covers. None when no such run is in the log.
130
130
  */
131
131
  export declare function manualOpeningSeqs(events: readonly ConversationEvent[], coversUpToSeq: number, absorbedUpToSeq: number): number[];
132
132
  /**
@@ -284,6 +284,13 @@ export function compactionPlan(events, settings, budget, opts = {}) {
284
284
  const parts = prev ? [`[Earlier summary]\n${prev.payload.text}`, ...lines] : lines;
285
285
  return { coversUpToSeq, transcript: parts.join("\n\n") };
286
286
  }
287
+ /** Whether a `run_started.trigger` belongs to a run opened by a user/automation message. */
288
+ function isMessageRunTrigger(trigger) {
289
+ return (trigger === undefined ||
290
+ trigger === "message" ||
291
+ trigger === "schedule" ||
292
+ trigger === "automation_event");
293
+ }
287
294
  /**
288
295
  * The user messages that started run `runId`, among those a summary covering up to
289
296
  * `coversUpToSeq` covers (context compaction spec §4.2, revision 2026-11-15): recorded in the
@@ -301,13 +308,8 @@ export function openingSeqs(events, runId, coversUpToSeq, absorbedUpToSeq = Numb
301
308
  const start = sorted.findLast((e) => e.type === "run_started" && e.runId === runId);
302
309
  if (start?.type !== "run_started")
303
310
  return [];
304
- const trigger = start.payload.trigger;
305
- if (trigger !== undefined &&
306
- trigger !== "message" &&
307
- trigger !== "schedule" &&
308
- trigger !== "automation_event") {
311
+ if (!isMessageRunTrigger(start.payload.trigger))
309
312
  return [];
310
- }
311
313
  const first = sorted.find((e) => e.type === "model_call" && e.runId === runId && e.seq > start.seq);
312
314
  const upTo = first?.type === "model_call"
313
315
  ? Math.min(first.payload.request.absorbedUpToSeq, first.seq)
@@ -329,16 +331,13 @@ export function openingSeqs(events, runId, coversUpToSeq, absorbedUpToSeq = Numb
329
331
  /**
330
332
  * The opening messages a manual compaction's summary re-renders (context compaction spec §4.7,
331
333
  * maintainer decision 2026-11-28): a compact run is started by no message, so its own run has none;
332
- * the turn it cuts into is the one the latest run a message started (trigger `message` or
333
- * `schedule`) opened, and {@link openingSeqs} of that run decides which of its opening messages the
334
- * summary covers. None when no such run is in the log.
334
+ * the turn it cuts into is the one the latest run a message started (trigger `message`,
335
+ * `schedule` or `automation_event`) opened, and {@link openingSeqs} of that run decides which of
336
+ * its opening messages the summary covers. None when no such run is in the log.
335
337
  */
336
338
  export function manualOpeningSeqs(events, coversUpToSeq, absorbedUpToSeq) {
337
339
  const start = events
338
- .filter((e) => e.type === "run_started" &&
339
- (e.payload.trigger === undefined ||
340
- e.payload.trigger === "message" ||
341
- e.payload.trigger === "schedule"))
340
+ .filter((e) => e.type === "run_started" && isMessageRunTrigger(e.payload.trigger))
342
341
  .reduce((a, e) => (a === null || e.seq > a.seq ? e : a), null);
343
342
  if (start?.runId == null)
344
343
  return [];
@@ -296,7 +296,11 @@ export const PERSON_MESSAGES_READ = 20;
296
296
  * blocks `1 .. attachments.length`) are content read from a connector, not the person's
297
297
  * instructions, so they are skipped, like images, documents and uploaded files. So are the
298
298
  * referenced conversations' blocks (`payload.conversationRefs`, after the project file lines):
299
- * quoted material, not the person's intent.
299
+ * quoted material, not the person's intent. A message with inline tokens (composer inline tokens
300
+ * spec §3.3) keeps that layout: its placeholders stand in `content[0]`, and its connector mention
301
+ * blocks and `[file: …]` lines come after the referenced conversations, so they are skipped too.
302
+ * An upload-only message has no typed text: its `content[0]` is the first file's `[file: <name>]`
303
+ * line, which is read as its words (a file name, harmless to the verdict).
300
304
  */
301
305
  function textOfUserMessage(payload) {
302
306
  const p = payload;
@@ -941,6 +941,19 @@ export declare class SandboxService {
941
941
  * rebuilt it the new one is used.
942
942
  */
943
943
  private ensure;
944
+ /**
945
+ * Under the exclusive lease, before the rebuild of an instance its provider answered gone
946
+ * (`SandboxGoneError` during a use, or `resume` answering `gone`): the row's incarnation is
947
+ * destroyed through its provider with this holder's fence token (a no-op where it is really
948
+ * gone; on a provider whose `gone` means "never served again", such as a local machine whose
949
+ * program restarted, it ends what the generation left) and that confirmed destruction is
950
+ * recorded (8.5 evidence) before anything new is created. Its revoked starts and owed revokes
951
+ * then settle against the record once a new incarnation runs, instead of quarantining the
952
+ * device for an incarnation replaced without a recorded destruction. A destroy that fails fails
953
+ * the use with nothing rebuilt: the row still names the gone incarnation, so the next use is
954
+ * told gone again and retries (unavailable for now, never `device.recreate_required`).
955
+ */
956
+ private destroyGone;
944
957
  /**
945
958
  * {@link create} from {@link ensure}, then, for a provider whose limits are fixed at its file
946
959
  * system (the new instance keeps the network its file system enforces, E2B), the installed
@@ -3117,6 +3117,7 @@ let SandboxService = class SandboxService {
3117
3117
  const createdAt = row.created_at.getTime();
3118
3118
  const fsResets = row.fs_resets;
3119
3119
  if (handle && isInstance(row, gone) && row.status === "running") {
3120
+ await this.destroyGone(id, p, held, row, handle, fence, signal);
3120
3121
  const created = await this.createSettled(ctx, p, held, row, fence, signal, want);
3121
3122
  return { ...created, fsResets, info: { fresh: true, restarted: true }, fence };
3122
3123
  }
@@ -3198,6 +3199,7 @@ let SandboxService = class SandboxService {
3198
3199
  this.log.info("sandbox instance is gone at the provider; recreating", {
3199
3200
  deviceId: id,
3200
3201
  });
3202
+ await this.destroyGone(id, p, held, row, handle, fence, signal);
3201
3203
  }
3202
3204
  const created = await this.createSettled(ctx, p, held, row, fence, signal, want);
3203
3205
  // had_instance only ever becomes true: any earlier instance (even if a rebuild failed since)
@@ -3218,6 +3220,39 @@ let SandboxService = class SandboxService {
3218
3220
  throw err;
3219
3221
  }
3220
3222
  }
3223
+ /**
3224
+ * Under the exclusive lease, before the rebuild of an instance its provider answered gone
3225
+ * (`SandboxGoneError` during a use, or `resume` answering `gone`): the row's incarnation is
3226
+ * destroyed through its provider with this holder's fence token (a no-op where it is really
3227
+ * gone; on a provider whose `gone` means "never served again", such as a local machine whose
3228
+ * program restarted, it ends what the generation left) and that confirmed destruction is
3229
+ * recorded (8.5 evidence) before anything new is created. Its revoked starts and owed revokes
3230
+ * then settle against the record once a new incarnation runs, instead of quarantining the
3231
+ * device for an incarnation replaced without a recorded destruction. A destroy that fails fails
3232
+ * the use with nothing rebuilt: the row still names the gone incarnation, so the next use is
3233
+ * told gone again and retries (unavailable for now, never `device.recreate_required`).
3234
+ */
3235
+ async destroyGone(id, p, held, row, handle, fence, signal) {
3236
+ assertOwnRow(row, p);
3237
+ // still the holder (a fenced write), so the destroy's token is this holder's latest
3238
+ await this.fenced(held, id, fence, {});
3239
+ try {
3240
+ await p.impl.destroy(handle, signal, { token: fence.gen });
3241
+ }
3242
+ catch (err) {
3243
+ if (isStaleFenceError(err))
3244
+ throw await this.staleHolder(held, id, p.plugin, fence, "destroy", err);
3245
+ if (!signal.aborted)
3246
+ this.log.warn("cannot destroy the gone sandbox instance; it is rebuilt on a later use", {
3247
+ deviceId: id,
3248
+ err,
3249
+ });
3250
+ throw err;
3251
+ }
3252
+ if (!(await held.renew()))
3253
+ throw new SandboxLockLostError(id);
3254
+ await this.retirement.recordDestruction(id, p.plugin, String(row.created_at.getTime()));
3255
+ }
3221
3256
  /**
3222
3257
  * {@link create} from {@link ensure}, then, for a provider whose limits are fixed at its file
3223
3258
  * system (the new instance keeps the network its file system enforces, E2B), the installed
@@ -3446,12 +3481,17 @@ let SandboxService = class SandboxService {
3446
3481
  return null;
3447
3482
  }
3448
3483
  this.log.info("sandbox limits changed; recreating the instance on the kept files", facts);
3449
- // still the holder (a fenced write), so a holder whose lease ended meanwhile never destroys
3450
- // what a newer one uses; the destroy's token is then this holder's latest
3451
- await this.fenced(held, id, fence, {});
3452
- if (!gone) {
3484
+ // the provider answered gone: destroyed with confirmation and recorded before the rebuild
3485
+ if (gone)
3486
+ await this.destroyGone(id, p, held, row, handle, fence, signal);
3487
+ else {
3488
+ // still the holder (a fenced write), so a holder whose lease ended meanwhile never destroys
3489
+ // what a newer one uses; the destroy's token is then this holder's latest
3490
+ await this.fenced(held, id, fence, {});
3491
+ let destroyed = false;
3453
3492
  try {
3454
3493
  await p.impl.destroy(handle, signal, { token: fence.gen });
3494
+ destroyed = true;
3455
3495
  }
3456
3496
  catch (err) {
3457
3497
  if (isStaleFenceError(err))
@@ -3464,6 +3504,13 @@ let SandboxService = class SandboxService {
3464
3504
  err,
3465
3505
  });
3466
3506
  }
3507
+ // the provider's destroy resolved: confirmed destruction of exactly this incarnation (8.5
3508
+ // evidence, as in destroyRow), so its owed revokes settle once the new one runs
3509
+ if (destroyed) {
3510
+ if (!(await held.renew()))
3511
+ throw new SandboxLockLostError(id);
3512
+ await this.retirement.recordDestruction(id, p.plugin, String(row.created_at.getTime()));
3513
+ }
3467
3514
  }
3468
3515
  return await this.lifecycleStep("recreate", id, p, signal, () => this.create(ctx, p, held, row, fence, signal, want));
3469
3516
  }
@@ -254,13 +254,8 @@ export declare const PLATFORM_OUTSIDE_SANDBOX_OFF_TOOL_TEXT = "Running commands
254
254
  * The device does not allow running outside the sandbox (`device.outside_sandbox_not_allowed`).
255
255
  */
256
256
  export declare const OUTSIDE_SANDBOX_CEILING_TOOL_TEXT = "This device does not allow running commands outside the sandbox, so nothing ran. Run the command inside the sandbox, or ask the device's owner whether its provider can allow it.";
257
- /**
258
- * The legacy retirement gate's refusals (`RetirementPendingError`, permission runtime cutover
259
- * 8.5): the device's earlier instance may still run background work an earlier version started.
260
- * Each says what clears it; the generic `device.unavailable` text would name an inactive provider.
261
- */
262
- export declare const RETIREMENT_PENDING_TOOL_TEXT = "This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device.";
263
- export declare const RETIREMENT_RECREATE_TOOL_TEXT = "Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device.";
257
+ export declare const RETIREMENT_PENDING_TOOL_TEXT = "This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device. Attachments and artifacts of this conversation can still be read without the device: if Read is available to you, Read with file_id.";
258
+ export declare const RETIREMENT_RECREATE_TOOL_TEXT = "Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device. Attachments and artifacts of this conversation can still be read without the device: if Read is available to you, Read with file_id.";
264
259
  /**
265
260
  * A managed operation outside the admitted scope (`SandboxScopeDeniedError`): fixed text, never
266
261
  * the refusal's own message (a provider may write it).
@@ -276,8 +276,10 @@ export const OUTSIDE_SANDBOX_CEILING_TOOL_TEXT = "This device does not allow run
276
276
  * 8.5): the device's earlier instance may still run background work an earlier version started.
277
277
  * Each says what clears it; the generic `device.unavailable` text would name an inactive provider.
278
278
  */
279
- export const RETIREMENT_PENDING_TOOL_TEXT = "This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device.";
280
- export const RETIREMENT_RECREATE_TOOL_TEXT = "Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device.";
279
+ /** What still works without the device: attachments and artifacts are read from file storage. */
280
+ const READ_BY_ID_HINT = "Attachments and artifacts of this conversation can still be read without the device: if Read is available to you, Read with file_id.";
281
+ export const RETIREMENT_PENDING_TOOL_TEXT = `This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device. ${READ_BY_ID_HINT}`;
282
+ export const RETIREMENT_RECREATE_TOOL_TEXT = `Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device. ${READ_BY_ID_HINT}`;
281
283
  /** The model-facing text of a retirement refusal's code (`device.unavailable` for any other). */
282
284
  function retirementToolText(code) {
283
285
  if (code === "device.recreate_required")
@@ -6,6 +6,7 @@ declare const PromptBody: z.ZodObject<{
6
6
  arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
7
7
  }, z.core.$strict>;
8
8
  declare const ResourcesQuery: z.ZodObject<{
9
+ connectorId: z.ZodUUID;
9
10
  query: z.ZodOptional<z.ZodString>;
10
11
  }, z.core.$strip>;
11
12
  /**
@@ -21,10 +22,13 @@ export declare class ConnectorContentController {
21
22
  prompts: ConnectorPromptView[];
22
23
  unavailable: ConnectorUnavailable[];
23
24
  }>;
24
- /** 发起人可用的资源,`query` 按名称 / URI / 描述子串过滤。 */
25
+ /**
26
+ * One connector's resources the sender can use (the `@` menu's second level): one session on
27
+ * that connector, UI templates and empty resources hidden; `query` filters by name, URI or
28
+ * description substring.
29
+ */
25
30
  resources(principal: Principal, org: OrgContext, q: z.infer<typeof ResourcesQuery>): Promise<{
26
31
  resources: ConnectorResourceView[];
27
- unavailable: ConnectorUnavailable[];
28
32
  }>;
29
33
  /** 按参数渲染一个提示模板为文本(放进输入框,由用户发送)。 */
30
34
  renderPrompt(principal: Principal, org: OrgContext, connectorId: string, name: string, body: z.infer<typeof PromptBody>): Promise<{
@@ -22,7 +22,10 @@ const PromptBody = z
22
22
  .default({}),
23
23
  })
24
24
  .strict();
25
- const ResourcesQuery = z.object({ query: z.string().max(200).optional() });
25
+ const ResourcesQuery = z.object({
26
+ connectorId: z.uuid(),
27
+ query: z.string().max(200).optional(),
28
+ });
26
29
  class ConnectorPromptBody extends createZodDto(PromptBody, "ConnectorPromptBody") {
27
30
  }
28
31
  class ConnectorResourcesQuery extends createZodDto(ResourcesQuery, "ConnectorResourcesQuery") {
@@ -42,10 +45,17 @@ let ConnectorContentController = class ConnectorContentController {
42
45
  const p = requireUser(principal);
43
46
  return this.content.listPrompts(org.orgId, p.account.id);
44
47
  }
45
- /** 发起人可用的资源,`query` 按名称 / URI / 描述子串过滤。 */
48
+ /**
49
+ * One connector's resources the sender can use (the `@` menu's second level): one session on
50
+ * that connector, UI templates and empty resources hidden; `query` filters by name, URI or
51
+ * description substring.
52
+ */
46
53
  async resources(principal, org, q) {
47
54
  const p = requireUser(principal);
48
- return this.content.listResources(org.orgId, p.account.id, q.query);
55
+ return this.content.listResources(org.orgId, p.account.id, {
56
+ connectorId: q.connectorId,
57
+ ...(q.query !== undefined && { query: q.query }),
58
+ });
49
59
  }
50
60
  /** 按参数渲染一个提示模板为文本(放进输入框,由用户发送)。 */
51
61
  async renderPrompt(principal, org, connectorId, name, body) {
@@ -25,6 +25,7 @@ export interface ConnectorResourceView {
25
25
  name: string;
26
26
  description?: string;
27
27
  mimeType?: string;
28
+ size?: number;
28
29
  }
29
30
  /** 列表时某个连接器不可用:发起人没有连接个人凭据,或连接 / 列出失败(含熔断打开)。 */
30
31
  export interface ConnectorUnavailable {
@@ -42,6 +43,34 @@ export interface AttachmentMeta {
42
43
  uri: string;
43
44
  name: string;
44
45
  }
46
+ /** An MCP app UI template (not content a person can attach): `ui:` URI or the mcp-app HTML profile. */
47
+ export declare function isUiTemplate(r: {
48
+ uri: string;
49
+ mimeType?: string;
50
+ }): boolean;
51
+ /** Whether a resource is offered to a person: not a UI template, not empty. */
52
+ export declare function listableResource(r: {
53
+ uri: string;
54
+ name?: string;
55
+ mimeType?: string;
56
+ size?: number;
57
+ }): boolean;
58
+ /** One resource a message references, as read for it (the body redacted and capped). */
59
+ export interface ReadResource {
60
+ connectorId: string;
61
+ connectorName: string;
62
+ uri: string;
63
+ /** The listed name, or the URI. */
64
+ name: string;
65
+ body: string;
66
+ }
67
+ /**
68
+ * The model-visible block of a read resource: its placeholder first when it was a token
69
+ * (`[resource: <label> from <connector label>] `), then the English head and the body.
70
+ */
71
+ export declare const resourceBlockText: (r: ReadResource, placeholder?: string) => string;
72
+ /** The `payload.attachments` entry of a read resource (field names kept, C27). */
73
+ export declare const attachmentMeta: (r: ReadResource) => AttachmentMeta;
45
74
  export declare class ConnectorContent {
46
75
  private readonly db;
47
76
  private readonly registry;
@@ -77,25 +106,36 @@ export declare class ConnectorContent {
77
106
  getPrompt(orgId: string, connectorId: string, name: string, args: Record<string, string>, accountId: string): Promise<{
78
107
  text: string;
79
108
  }>;
80
- /** 发起人可用的资源;`query` 按名称 / URI / 描述的子串过滤(不区分大小写),最多 {@link MAX_RESOURCES} 条。 */
81
- listResources(orgId: string, accountId: string, query?: string): Promise<{
109
+ /**
110
+ * One connector's resources the sender can use (the `@` menu's second level, composer inline
111
+ * tokens spec §5): one session on that connector with the sender's credential, UI templates and
112
+ * empty resources hidden, at most {@link MAX_CONNECTOR_RESOURCES}; `query` filters by name, URI
113
+ * or description substring (case insensitive). A connector that is not live and active →
114
+ * `connector.not_found`; one whose `read_resource` is off → `connector.resources_disabled`; a
115
+ * missing credential or a failed connection is thrown (`credential.missing`,
116
+ * `connector.connect_failed`).
117
+ */
118
+ listResources(orgId: string, accountId: string, opts: {
119
+ connectorId: string;
120
+ query?: string;
121
+ }): Promise<{
82
122
  resources: ConnectorResourceView[];
83
- unavailable: ConnectorUnavailable[];
84
123
  }>;
85
124
  /**
86
- * 解析消息附件:以发送者的凭据**并行**读取每个资源(打码、每个限 {@link MAX_ATTACHMENT_CHARS} 字符;总时限
87
- * min(`tools.timeoutMs`, 30s)),按请求顺序返回要追加在用户消息后的文本块与元数据。名称取资源清单里的 name
88
- * (读不到清单时用 URI)。连接器的 `read_resource` 工具被管理员停用 → 409 `connector.resources_disabled`。
89
- * 任一附件失败整条消息失败(不写入)。
125
+ * Reads the resources a message references with the sender's credentials, **in parallel**
126
+ * (redacted, each capped at {@link MAX_ATTACHMENT_CHARS} characters; total time limit
127
+ * min(`tools.timeoutMs`, 30s)), in request order. The name is the one in the resource listing
128
+ * (the URI when the listing does not have it). Refusals, any of which fails the whole message
129
+ * (nothing is written):
130
+ * - the connector is not live and active, or provides no resources → `connector.not_found`;
131
+ * - its `read_resource` tool is switched off by an admin (Ruling A23), or `readOffered` is given
132
+ * and does not hold the connector (the conversation's agent is not offered that tool) →
133
+ * 409 `connector.resources_disabled`;
134
+ * - an MCP Apps UI template, or a body that is empty after trimming → 422
135
+ * `connector.resource_unreadable` (`details: [{ connectorId, uri, reason }]`).
90
136
  */
91
- resolveAttachments(orgId: string, accountId: string, refs: {
137
+ readResources(orgId: string, accountId: string, refs: readonly {
92
138
  connectorId: string;
93
139
  uri: string;
94
- }[]): Promise<{
95
- blocks: {
96
- type: "text";
97
- text: string;
98
- }[];
99
- attachments: AttachmentMeta[];
100
- }>;
140
+ }[], readOffered?: ReadonlySet<string>): Promise<ReadResource[]>;
101
141
  }