@capybara-hq/kernel 0.1.0-rc.59 → 0.1.0-rc.60

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 (139) hide show
  1. package/dist/admin/admin.controller.d.ts +10 -5
  2. package/dist/admin/admin.controller.js +16 -7
  3. package/dist/admin/admin.schemas.js +2 -1
  4. package/dist/admin/audit-log.service.d.ts +1 -0
  5. package/dist/admin/audit-log.service.js +4 -1
  6. package/dist/admin/extensions.schemas.js +2 -0
  7. package/dist/agents/admin-agents.d.ts +1 -0
  8. package/dist/agents/admin-agents.js +4 -1
  9. package/dist/agents/agents.controller.d.ts +1 -10
  10. package/dist/agents/agents.controller.js +2 -14
  11. package/dist/agents/agents.schemas.d.ts +10 -0
  12. package/dist/agents/agents.schemas.js +19 -0
  13. package/dist/background/tasks.service.d.ts +5 -0
  14. package/dist/background/tasks.service.js +10 -3
  15. package/dist/catalog/admin-catalog.schemas.js +2 -0
  16. package/dist/catalog/component-scope.schemas.js +2 -0
  17. package/dist/catalog/marketplaces.service.d.ts +1 -1
  18. package/dist/catalog/org-plugin-uploads.schemas.js +2 -0
  19. package/dist/catalog/requests.service.d.ts +2 -0
  20. package/dist/catalog/requests.service.js +4 -1
  21. package/dist/channels/cards.d.ts +9 -0
  22. package/dist/channels/cards.js +32 -1
  23. package/dist/channels/phrases.d.ts +5 -0
  24. package/dist/channels/phrases.js +5 -0
  25. package/dist/conversations/attachments.service.d.ts +34 -0
  26. package/dist/conversations/attachments.service.js +124 -21
  27. package/dist/conversations/conversations.controller.d.ts +5 -1
  28. package/dist/conversations/conversations.controller.js +11 -5
  29. package/dist/conversations/conversations.service.d.ts +5 -0
  30. package/dist/conversations/conversations.service.js +10 -0
  31. package/dist/conversations/event-people.d.ts +12 -0
  32. package/dist/conversations/event-people.js +28 -0
  33. package/dist/db/kernel-schema.d.ts +18 -0
  34. package/dist/devices/devices.service.d.ts +3 -2
  35. package/dist/devices/devices.service.js +17 -2
  36. package/dist/errors.d.ts +1 -0
  37. package/dist/errors.js +1 -0
  38. package/dist/evals/trajectory.service.d.ts +3 -0
  39. package/dist/evals/trajectory.service.js +2 -0
  40. package/dist/extensions/installs.d.ts +3 -0
  41. package/dist/extensions/installs.js +1 -0
  42. package/dist/http/api.module.js +2 -0
  43. package/dist/http/meta.controller.d.ts +1 -0
  44. package/dist/http/meta.controller.js +6 -1
  45. package/dist/identity/account-avatar.controller.d.ts +30 -0
  46. package/dist/identity/account-avatar.controller.js +117 -0
  47. package/dist/identity/account-avatar.d.ts +67 -0
  48. package/dist/identity/account-avatar.js +136 -0
  49. package/dist/identity/account-avatars.service.d.ts +77 -0
  50. package/dist/identity/account-avatars.service.js +321 -0
  51. package/dist/identity/accounts.d.ts +26 -0
  52. package/dist/identity/accounts.js +70 -2
  53. package/dist/identity/app-auth.controller.d.ts +2 -1
  54. package/dist/identity/app-auth.controller.js +2 -1
  55. package/dist/identity/app-auth.d.ts +24 -7
  56. package/dist/identity/app-auth.js +19 -9
  57. package/dist/identity/app-auth.schemas.d.ts +16 -3
  58. package/dist/identity/app-auth.schemas.js +5 -2
  59. package/dist/identity/external.js +7 -1
  60. package/dist/identity/identity.module.d.ts +2 -1
  61. package/dist/identity/identity.module.js +7 -1
  62. package/dist/identity/me.controller.d.ts +29 -5
  63. package/dist/identity/me.controller.js +57 -6
  64. package/dist/identity/me.schemas.d.ts +36 -0
  65. package/dist/identity/me.schemas.js +30 -0
  66. package/dist/identity/principal.d.ts +2 -2
  67. package/dist/identity/principal.js +2 -2
  68. package/dist/local-devices/local-device-gateway.d.ts +2 -0
  69. package/dist/local-devices/local-device-gateway.js +8 -1
  70. package/dist/local-devices/relay.d.ts +10 -9
  71. package/dist/local-devices/relay.js +32 -9
  72. package/dist/local-devices/targets.d.ts +12 -0
  73. package/dist/local-devices/targets.js +18 -2
  74. package/dist/orgs/members.service.d.ts +3 -1
  75. package/dist/orgs/members.service.js +9 -2
  76. package/dist/platform/exclusions.js +33 -57
  77. package/dist/platform/file-ref.d.ts +87 -0
  78. package/dist/platform/file-ref.js +164 -0
  79. package/dist/platform/operation.d.ts +26 -0
  80. package/dist/platform/ops/agent-skills.ops.d.ts +2 -0
  81. package/dist/platform/ops/agent-skills.ops.js +156 -4
  82. package/dist/platform/ops/agents.ops.d.ts +3 -1
  83. package/dist/platform/ops/agents.ops.js +75 -17
  84. package/dist/platform/ops/approvals.ops.js +5 -0
  85. package/dist/platform/ops/catalog-admin.ops.d.ts +9 -1
  86. package/dist/platform/ops/catalog-admin.ops.js +86 -3
  87. package/dist/platform/ops/components.ops.d.ts +3 -1
  88. package/dist/platform/ops/components.ops.js +61 -2
  89. package/dist/platform/ops/connectors.ops.js +15 -1
  90. package/dist/platform/ops/devices.ops.js +6 -1
  91. package/dist/platform/ops/extensions-admin.ops.d.ts +6 -4
  92. package/dist/platform/ops/extensions-admin.ops.js +109 -6
  93. package/dist/platform/ops/inbox.ops.js +10 -0
  94. package/dist/platform/ops/list-handoff.d.ts +10 -0
  95. package/dist/platform/ops/list-handoff.js +11 -0
  96. package/dist/platform/ops/marketplaces.ops.js +2 -1
  97. package/dist/platform/ops/org-plugins.ops.d.ts +12 -3
  98. package/dist/platform/ops/org-plugins.ops.js +97 -6
  99. package/dist/platform/ops/requests.ops.js +9 -0
  100. package/dist/platform/ops/skills.ops.d.ts +5 -1
  101. package/dist/platform/ops/skills.ops.js +98 -4
  102. package/dist/platform/ops/summary.d.ts +5 -0
  103. package/dist/platform/ops/summary.js +10 -0
  104. package/dist/platform/parity.d.ts +6 -4
  105. package/dist/platform/parity.js +94 -68
  106. package/dist/roles/worker.module.js +5 -0
  107. package/dist/sandbox/request-not-sent.d.ts +13 -0
  108. package/dist/sandbox/request-not-sent.js +18 -0
  109. package/dist/schedules/scheduled-tasks.service.d.ts +10 -6
  110. package/dist/schedules/scheduled-tasks.service.js +13 -16
  111. package/dist/shares/shares.service.d.ts +1 -0
  112. package/dist/shares/shares.service.js +9 -3
  113. package/dist/skills/changes.service.d.ts +1 -0
  114. package/dist/skills/changes.service.js +4 -7
  115. package/dist/skills/skills.controller.d.ts +3 -7
  116. package/dist/skills/skills.controller.js +3 -16
  117. package/dist/skills/skills.schemas.d.ts +5 -0
  118. package/dist/skills/skills.schemas.js +17 -0
  119. package/dist/skills/skills.service.d.ts +3 -1
  120. package/dist/skills/skills.service.js +13 -4
  121. package/dist/tools/admin-connectors.d.ts +1 -0
  122. package/dist/tools/admin-connectors.js +4 -1
  123. package/dist/tools/approvals.service.d.ts +16 -2
  124. package/dist/tools/approvals.service.js +13 -0
  125. package/dist/tools/builtins/builtin-tools.d.ts +3 -0
  126. package/dist/tools/builtins/builtin-tools.js +29 -9
  127. package/dist/tools/builtins/platform.d.ts +23 -0
  128. package/dist/tools/builtins/platform.js +95 -6
  129. package/dist/tools/builtins/sandbox/common.d.ts +5 -0
  130. package/dist/tools/builtins/sandbox/common.js +11 -0
  131. package/dist/tools/builtins/skill-load.js +4 -4
  132. package/dist/tools/pipeline.js +10 -3
  133. package/dist/tools/questions.controller.js +2 -2
  134. package/dist/tools/questions.service.d.ts +7 -1
  135. package/dist/tools/questions.service.js +9 -2
  136. package/dist/tools/registry.d.ts +6 -0
  137. package/dist/tools/tools.module.js +3 -0
  138. package/package.json +3 -3
  139. package/src/migrations/0171_account_avatar.sql +26 -0
@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
  import { ToolViewSchema } from "../../conversations/events.js";
4
4
  import { availability, PLATFORM_UNAVAILABLE_OFF, } from "../../platform/availability.js";
5
5
  import { errorRoleOf, errorsFor, nextStepFor, OPERATION_ERROR_NEXT, resolveNext, sentence, toToolError, } from "../../platform/errors.js";
6
+ import { FILE_CHANGED_TEXT, fileCardDetail, } from "../../platform/file-ref.js";
6
7
  import { PLATFORM_METHOD } from "../../platform/method.js";
7
8
  import { OPERATION_ID, operationDomain, PRECHECK_TIMEOUT_MS, } from "../../platform/operation.js";
8
9
  import { PersonFieldsRefused, planPersonFields, } from "../../platform/person-fields.js";
@@ -26,6 +27,10 @@ import { BUILTIN } from "../builtin-names.js";
26
27
  * card through {@link CallPolicy.personFields} (never remembered). The approved call reads the
27
28
  * person's sealed values through `personInputs` and its result names each entered path, never a
28
29
  * value.
30
+ * - A write that takes a file in place of an upload (spec §5: `op.fileRef`) resolves it at the
31
+ * policy step: a file over the limit or of another type is denied before the card; the card
32
+ * shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256. Right before
33
+ * `op.run` the file is read again, and bytes with another sha256 are refused.
29
34
  * - Results are JSON text; a list an operation returns is capped at {@link LIST_MAX} entries.
30
35
  */
31
36
  /** The most entries of a list in one result (operations that page return `next`). */
@@ -185,6 +190,33 @@ function withReviewUrl(out, view) {
185
190
  return { ...out, reviewUrl: view.target.url };
186
191
  }
187
192
  /** An operation's result as a JSON object: a bare list is capped, nothing becomes `{ ok: true }`. */
193
+ /** A key that carries a person's avatar: `avatarUrl`, `ownerAvatarUrl`, `createdByAvatarUrl`, … */
194
+ const AVATAR_KEY = /^(avatarUrl|[a-z][A-Za-z]*AvatarUrl)$/;
195
+ /** The prefix of every person avatar URL (`accountAvatarUrl`). */
196
+ const PERSON_AVATAR_PREFIX = "/api/v1/accounts/";
197
+ /**
198
+ * An operation's result without people's avatars (account profile spec §3, §5.4: a person's
199
+ * avatar is never model-visible). Drops every avatar key whose value is a person avatar URL or
200
+ * null (a person shape without an image); an agent's own avatar URL stays. Names stay.
201
+ */
202
+ export function withoutPersonAvatars(value) {
203
+ if (Array.isArray(value))
204
+ return value.map(withoutPersonAvatars);
205
+ if (typeof value !== "object" || value === null)
206
+ return value;
207
+ // a value that serializes itself (a Date) is not a record of fields
208
+ if (typeof value.toJSON === "function")
209
+ return value;
210
+ const out = {};
211
+ for (const [k, v] of Object.entries(value)) {
212
+ if (AVATAR_KEY.test(k) &&
213
+ (v === null || (typeof v === "string" && v.startsWith(PERSON_AVATAR_PREFIX)))) {
214
+ continue;
215
+ }
216
+ out[k] = withoutPersonAvatars(v);
217
+ }
218
+ return out;
219
+ }
188
220
  function asResult(value) {
189
221
  if (Array.isArray(value))
190
222
  return capped(value);
@@ -218,6 +250,8 @@ const PERSON_FIELDS_CHANGED_TEXT = "The target changed after the person confirme
218
250
  const unusedValuesText = (id) => `The values the person entered were not used by ${id}.`;
219
251
  /** The result line of one field the person entered (never its value). */
220
252
  const enteredLine = (path) => `\`${path}\`: entered by the person`;
253
+ /** Model-visible: an operation takes a file, and this kernel has no resolver wired (a bug). */
254
+ const filesUnavailableText = (id) => `Operation ${id} takes a file, which this deployment cannot read right now; tell the person to use the web page instead.`;
221
255
  const outputRefText = (id) => `Operation ${id} writes, and its params hold a {"$output": ...} reference, which the person confirming would see instead of the content. Pass the content inline in params and call again.`;
222
256
  /** Whether a value holds a `{"$output": …}` reference anywhere (the pipeline's form). */
223
257
  function hasOutputRef(v) {
@@ -330,20 +364,40 @@ export function platformTool(deps) {
330
364
  const next = resolveNext(failed.next, role) ?? nextStepFor(op.errors, failed.code, role);
331
365
  return deny(precheckText(op.id, failed.code, failed.message, next));
332
366
  }
367
+ // the file the write takes: read, checked and hashed before the card (spec §5)
368
+ let file;
369
+ let card = null;
370
+ try {
371
+ file = await fileOf(op, params, deps, octx, ctx.signal);
372
+ if (file !== null)
373
+ card = await fileCardDetail(file);
374
+ }
375
+ catch (e) {
376
+ if (e instanceof ToolError)
377
+ return deny(e.message);
378
+ return deny(toToolError(e, (code) => nextStepFor(op.errors, code, role)).message);
379
+ }
380
+ const sctx = {
381
+ ...octx,
382
+ ...(op.personFields !== undefined && {
383
+ personAsk: personFields?.fields.map((f) => f.path) ?? [],
384
+ }),
385
+ ...(file !== null && { file }),
386
+ };
333
387
  const [cls, summary] = await Promise.all([
334
388
  classOf(op, params, octx),
335
- summaryOf(op, params, op.personFields === undefined
336
- ? octx
337
- : { ...octx, personAsk: personFields?.fields.map((f) => f.path) ?? [] }),
389
+ summaryOf(op, params, sctx),
338
390
  ]);
339
391
  return {
340
392
  key,
341
393
  policy: "ask",
342
394
  // org / platform writes are confirmed every time (spec §6.2); so is a write with person
343
- // fields, whatever its class (spec §4.2, R6)
344
- remember: personFields === null && cls === "personal" && op.rememberable !== false,
395
+ // fields, whatever its class (spec §4.2, R6), and one whose card shows a file (§5: the
396
+ // person confirms these bytes)
397
+ remember: personFields === null && card === null && cls === "personal" && op.rememberable !== false,
345
398
  summary,
346
399
  ...(personFields !== null && { personFields }),
400
+ ...(card !== null && { file: card }),
347
401
  // its result is shown once to the approver: only the person may confirm it
348
402
  ...(op.revealsToApprover === true && { personOnly: true }),
349
403
  };
@@ -442,6 +496,24 @@ export function platformTool(deps) {
442
496
  let applied = false;
443
497
  let result;
444
498
  try {
499
+ // the file is read again, and must be the bytes the person confirmed (Review Focus 5)
500
+ const file = await fileOf(op, params, deps, octx, ctx.signal);
501
+ if (file !== null) {
502
+ // fails closed: bytes run only under this call's approval whose card showed them (no
503
+ // approval, one whose card showed no file or another one does not cover these bytes)
504
+ const bound = ctx.approvalId === undefined ||
505
+ ctx.runId === undefined ||
506
+ deps.approvalFileSha256 === undefined
507
+ ? null
508
+ : await deps.approvalFileSha256(ctx.approvalId, {
509
+ orgId: ctx.orgId,
510
+ runId: ctx.runId,
511
+ callId: ctx.callId,
512
+ });
513
+ if (bound === null || bound !== file.sha256)
514
+ throw new ToolError(FILE_CHANGED_TEXT);
515
+ octx.file = file;
516
+ }
445
517
  const person = await personFieldsOf(op, params, octx);
446
518
  // what the card showed (the approval's stored specs) binds what runs: the run-time plan
447
519
  // must ask exactly those fields, and the sealed values must carry exactly them
@@ -509,7 +581,7 @@ export function platformTool(deps) {
509
581
  lines.push(unusedValuesText(op.id));
510
582
  }
511
583
  const view = handoffOf(op, params, result, octx, deps.log);
512
- const out = withReviewUrl(asResult(result), view);
584
+ const out = withReviewUrl(asResult(withoutPersonAvatars(result)), view);
513
585
  return {
514
586
  content: [
515
587
  { type: "text", text: JSON.stringify(out) },
@@ -542,6 +614,23 @@ export function platformTool(deps) {
542
614
  },
543
615
  };
544
616
  }
617
+ /**
618
+ * The file one call takes (spec §5): `op.fileRef` of the validated input, resolved and checked
619
+ * against its limits; null when the operation takes none for this input. Refusals are
620
+ * model-visible `ToolError`s; other errors propagate.
621
+ */
622
+ async function fileOf(op, params, deps, ctx, signal) {
623
+ const wanted = op.fileRef?.(params) ?? null;
624
+ if (wanted === null)
625
+ return null;
626
+ if (deps.files === undefined)
627
+ throw new ToolError(filesUnavailableText(op.id));
628
+ return deps.files.resolve(wanted.ref, wanted.limits, {
629
+ orgId: ctx.orgId,
630
+ conversationId: ctx.conversationId,
631
+ signal: signal ?? ctx.signal,
632
+ });
633
+ }
545
634
  /** The fields to enter differ from what the person confirmed ({@link PERSON_FIELDS_CHANGED_TEXT}). */
546
635
  class PersonFieldsChanged extends Error {
547
636
  }
@@ -278,6 +278,11 @@ export declare const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device cannot enfo
278
278
  * model's doing; whether anything ran is not proven.
279
279
  */
280
280
  export declare const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in Capybara itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
281
+ /**
282
+ * A device request whose machine came back as a new run of capybara-device before answering
283
+ * (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
284
+ */
285
+ export declare const DEVICE_PROGRAM_RESTARTED_TOOL_TEXT = "The capybara-device program restarted on the device's machine while this operation was in progress, so its result is lost and whether it ran, or how far, is unknown. Check the device's state (for example with Read, Glob or TaskList), then run it again if it is still needed; do not repeat an operation that must not run twice.";
281
286
  /** A managed operation whose outcome could not be confirmed (`SandboxOperationOutcomeUnknownError`). */
282
287
  export declare const OUTCOME_UNKNOWN_TOOL_TEXT = "The device may or may not have run this operation: its outcome could not be confirmed. Check the device's state (for example with Read, Glob or TaskList) before retrying, and do not repeat an operation that must not run twice.";
283
288
  export { DEVICE_OF_ANOTHER_ACCOUNT_TEXT } from "./device-owner.js";
@@ -9,6 +9,7 @@ import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot, } from "../../../san
9
9
  import { SandboxPathBusyError } from "../../../sandbox/leases.js";
10
10
  import { MANAGED_DEVICE_CONTEXT_FAILED_TEXT, MANAGED_DEVICE_CONTEXT_STALE_TEXT, MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT, ManagedDeviceContextFailed, ManagedDeviceContextStale, ManagedDeviceContextUnavailable, } from "../../../sandbox/managed-device-context.js";
11
11
  import { isEscalationGrantMissing } from "../../../sandbox/operation-authority-types.js";
12
+ import { isDeviceProgramRestarted } from "../../../sandbox/request-not-sent.js";
12
13
  import { RetirementPendingError, SandboxLockLostError, } from "../../../sandbox/sandbox.service.js";
13
14
  import { providerConnectionFailure, SandboxProviderUnreachableError, } from "../../../sandbox/unreachable.js";
14
15
  import { assertDeviceOfRunAccount } from "./device-owner.js";
@@ -319,6 +320,11 @@ export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device cannot enforce this
319
320
  * model's doing; whether anything ran is not proven.
320
321
  */
321
322
  export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in Capybara itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
323
+ /**
324
+ * A device request whose machine came back as a new run of capybara-device before answering
325
+ * (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
326
+ */
327
+ export const DEVICE_PROGRAM_RESTARTED_TOOL_TEXT = "The capybara-device program restarted on the device's machine while this operation was in progress, so its result is lost and whether it ran, or how far, is unknown. Check the device's state (for example with Read, Glob or TaskList), then run it again if it is still needed; do not repeat an operation that must not run twice.";
322
328
  /** A managed operation whose outcome could not be confirmed (`SandboxOperationOutcomeUnknownError`). */
323
329
  export const OUTCOME_UNKNOWN_TOOL_TEXT = "The device may or may not have run this operation: its outcome could not be confirmed. Check the device's state (for example with Read, Glob or TaskList) before retrying, and do not repeat an operation that must not run twice.";
324
330
  /**
@@ -345,6 +351,11 @@ export function mapSandboxError(e, log) {
345
351
  return new ToolError(MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT, { kind: "unavailable" });
346
352
  if (e instanceof ManagedDeviceContextFailed)
347
353
  return new ToolError(MANAGED_DEVICE_CONTEXT_FAILED_TEXT, { kind: "unavailable" });
354
+ // the machine came back as a new program run: the request's result can never arrive
355
+ if (isDeviceProgramRestarted(e)) {
356
+ log?.warn("device program restarted before answering", { err: e, outcome: "unknown" });
357
+ return new ToolError(DEVICE_PROGRAM_RESTARTED_TOOL_TEXT, { kind: "unavailable" });
358
+ }
348
359
  // the managed route's typed refusals (unknown first: it never proves the operation had no effect)
349
360
  if (isSandboxOperationOutcomeUnknownError(e)) {
350
361
  // the provider could not be reached after the durable dispatch: the ledger keeps the outcome
@@ -621,10 +621,10 @@ export function skillLoadTool(deps) {
621
621
  }
622
622
  else {
623
623
  // the skill's marker is read, compared and written: one holder at a time per skill
624
- const r = await inSandboxPreparation(deps, ctx, "skills", (roots) => [
625
- skillSandboxDir(name, digest, roots.skills),
626
- skillMarkerPath(name, digest, roots.skills),
627
- ], (s) => withPathLease(deps, s, skillMarkerPath(name, digest, s.roots.skills), s.signal, (signal) => copySkill({ ...s, signal }, v).then(() => s.roots)));
624
+ const r = await inSandboxPreparation(deps, ctx, "skills",
625
+ // directories only: a device pins each write root as a directory, so the marker's
626
+ // own path (a file once written) is granted through the marker directory
627
+ (roots) => [skillSandboxDir(name, digest, roots.skills), skillsMarkerDir(roots.skills)], (s) => withPathLease(deps, s, skillMarkerPath(name, digest, s.roots.skills), s.signal, (signal) => copySkill({ ...s, signal }, v).then(() => s.roots)));
628
628
  notices = r.notices;
629
629
  skillsRoot = r.value.skills;
630
630
  const dir = `${skillSandboxDir(name, digest, skillsRoot)}/`;
@@ -824,9 +824,16 @@ let ToolPipeline = class ToolPipeline {
824
824
  ...((personFields !== undefined || (callPolicy !== null && !callPolicy.remember)) && {
825
825
  scopes: ["once"],
826
826
  }),
827
- // the specs of the asked fields, never a value (the card draws its inputs from them)
828
- ...(personFields !== undefined && {
829
- detail: { personFields: personFields.fields, target: personFields.target },
827
+ // the specs of the asked fields, never a value (the card draws its inputs from them), and
828
+ // the referenced file the approval binds by its sha256
829
+ ...((personFields !== undefined || callPolicy?.file !== undefined) && {
830
+ detail: {
831
+ ...(personFields !== undefined && {
832
+ personFields: personFields.fields,
833
+ target: personFields.target,
834
+ }),
835
+ ...(callPolicy?.file !== undefined && { file: callPolicy.file }),
836
+ },
830
837
  }),
831
838
  });
832
839
  }
@@ -34,8 +34,8 @@ let QuestionsController = class QuestionsController {
34
34
  }
35
35
  async answer(principal, org, id, body) {
36
36
  const p = requireUser(principal);
37
- const { state: _state, ...view } = await this.questions.answer(id, p.account.id, body.answer, org.orgId);
38
- return { question: view };
37
+ const answered = await this.questions.answer(id, p.account.id, body.answer, org.orgId);
38
+ return { question: await this.questions.view(answered) };
39
39
  }
40
40
  };
41
41
  __decorate([
@@ -1,5 +1,6 @@
1
1
  import { type FormAnswer, type InputForm } from "@capybara-hq/plugin-sdk";
2
2
  import { EventLog } from "../conversations/event-log.js";
3
+ import { type PersonRef } from "../identity/account-avatar.js";
3
4
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
5
  import { KernelDb } from "../infra/database/kernel-db.js";
5
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
@@ -39,7 +40,10 @@ export interface QuestionAskInput {
39
40
  state: unknown;
40
41
  }
41
42
  /** 网页读取输入请求的视图(不含插件 state:那是工具内部的续跑数据)。 */
42
- export type QuestionView = Omit<QuestionRecord, "state">;
43
+ export type QuestionView = Omit<QuestionRecord, "state"> & {
44
+ /** Who answered (next to `answeredBy`); null while open or when the account is gone. */
45
+ answeredByPerson: PersonRef | null;
46
+ };
43
47
  /**
44
48
  * 输入请求:新建(tools 节点)、回答(只有对话发起人)、超时与取消(等待机制)。
45
49
  * 状态全部在 PG:回答 / 超时 / 取消都在事务里 `SELECT … FOR UPDATE` 该行,多副本并发时恰好一个生效,
@@ -73,6 +77,8 @@ export declare class QuestionsService {
73
77
  * 不属于该组织 / 不存在 → `question.not_found`。
74
78
  */
75
79
  get(orgId: string, questionId: string, accountId: string): Promise<QuestionView>;
80
+ /** The web's view of a question: no plugin state, plus the answerer as a person. */
81
+ view({ state: _state, ...rest }: QuestionRecord): Promise<QuestionView>;
76
82
  /** 某个调用的全部输入请求(按轮次升序)。 */
77
83
  forCall(runId: string, callId: string): Promise<QuestionRecord[]>;
78
84
  /**
@@ -13,6 +13,7 @@ import { Inject, Injectable } from "@nestjs/common";
13
13
  import { sql } from "kysely";
14
14
  import { EventLog } from "../conversations/event-log.js";
15
15
  import { ApiError } from "../errors.js";
16
+ import { loadPeople } from "../identity/account-avatar.js";
16
17
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
17
18
  import { KernelDb } from "../infra/database/kernel-db.js";
18
19
  import { TransactionHost } from "../infra/database/transaction-host.js";
@@ -21,7 +22,6 @@ import { KernelEvents } from "../infra/events/kernel-events.js";
21
22
  import { RunResume } from "../runtime/run-jobs.js";
22
23
  const notFound = () => new ApiError("question.not_found", "Question not found");
23
24
  const notInitiator = () => new ApiError("forbidden", "Only the user who started the run can answer this question");
24
- const toView = ({ state: _state, ...rest }) => rest;
25
25
  const iso = (v) => new Date(v).toISOString();
26
26
  function toRecord(r) {
27
27
  const spec = r.spec;
@@ -148,7 +148,14 @@ let QuestionsService = class QuestionsService {
148
148
  throw notFound();
149
149
  if (row.trigger_account_id !== accountId)
150
150
  throw notInitiator();
151
- return toView(toRecord(row));
151
+ return this.view(toRecord(row));
152
+ }
153
+ /** The web's view of a question: no plugin state, plus the answerer as a person. */
154
+ async view({ state: _state, ...rest }) {
155
+ const answeredByPerson = rest.answeredBy === null
156
+ ? null
157
+ : ((await loadPeople(this.db.db, [rest.answeredBy])).get(rest.answeredBy) ?? null);
158
+ return { ...rest, answeredByPerson };
152
159
  }
153
160
  /** 某个调用的全部输入请求(按轮次升序)。 */
154
161
  async forCall(runId, callId) {
@@ -7,6 +7,7 @@ import { ExtensionRegistry } from "../extensions/registry.js";
7
7
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
8
8
  import { KernelDb } from "../infra/database/kernel-db.js";
9
9
  import type { OrgRole } from "../orgs/roles.js";
10
+ import type { FileCardDetail } from "../platform/file-ref.js";
10
11
  import type { PersonFieldSpec } from "../platform/person-fields.js";
11
12
  import type { ConversationKindForHooks } from "../runtime/hook-calls.js";
12
13
  import type { ExecutionClaim } from "../runtime/run-execution.js";
@@ -234,6 +235,11 @@ export interface CallPolicy {
234
235
  * refused in an unattended run and when the ask would go to a role instead of the person.
235
236
  */
236
237
  personOnly?: true;
238
+ /**
239
+ * The file the call takes in place of an upload, as the card shows it (platform web parity spec
240
+ * §5): stored in the approval's `detail.file`, so the approval binds its sha256. Never the bytes.
241
+ */
242
+ file?: FileCardDetail;
237
243
  }
238
244
  export type ToolPolicy = "allow" | "ask" | "deny";
239
245
  export interface ResolvedTool {
@@ -16,6 +16,7 @@ import { QueueModule } from "../infra/queue/queue.module.js";
16
16
  import { LocalDevicesModule } from "../local-devices/local-devices.module.js";
17
17
  import { ModelsModule } from "../models/models.module.js";
18
18
  import { OrgLockModule } from "../orgs/org-lock.js";
19
+ import { FileRefs } from "../platform/file-ref.js";
19
20
  import { PlatformModule } from "../platform/platform.module.js";
20
21
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
21
22
  import { ProvidersModule } from "../runtime/providers.js";
@@ -106,6 +107,8 @@ ToolsModule = __decorate([
106
107
  PermissionApprovalJobs,
107
108
  ToolOutputs,
108
109
  BuiltinTools,
110
+ // a Platform write's file reference (a conversation file)
111
+ FileRefs,
109
112
  // `ScheduleUpdate`'s write in one transaction (scheduled tasks spec §11)
110
113
  ScheduleUpdates,
111
114
  // where `SchedulesModule` binds the task service for the schedule tools (no provider cycle)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.59",
3
+ "version": "0.1.0-rc.60",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yaml": "^2.9.1",
67
67
  "yauzl": "3.4.0",
68
68
  "zod": "^4.6.7",
69
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.43"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.44"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -75,7 +75,7 @@
75
75
  "@types/ws": "^8.18.2",
76
76
  "@types/yauzl": "3.4.0",
77
77
  "ws": "^8.22.0",
78
- "@capybara-hq/device": "0.1.0-rc.23",
78
+ "@capybara-hq/device": "0.1.0-rc.24",
79
79
  "@capybara-hq/testing": "0.1.0-rc.29"
80
80
  },
81
81
  "scripts": {
@@ -0,0 +1,26 @@
1
+ -- Account profile (spec 2026-11-20-account-profile-design §5.1): a person's own avatar and the
2
+ -- uploads behind it. Expand-only.
3
+
4
+ -- null: no own avatar (the SSO avatar or the initial shows); else {"kind":"upload","uploadId":…}
5
+ ALTER TABLE accounts ADD COLUMN IF NOT EXISTS avatar jsonb;
6
+
7
+ -- Avatar uploads of an account. Not `attachments`: an attachment needs an org, an account has
8
+ -- none of its own. An unbound upload carries `expires_at`; the bound one has none.
9
+ CREATE TABLE IF NOT EXISTS account_avatar_uploads (
10
+ id text PRIMARY KEY,
11
+ account_id text NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
12
+ storage_key text NOT NULL,
13
+ content_type text NOT NULL,
14
+ size bigint,
15
+ status text NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'ready')),
16
+ expires_at timestamptz,
17
+ created_at timestamptz NOT NULL DEFAULT now()
18
+ );
19
+ CREATE INDEX IF NOT EXISTS account_avatar_uploads_account_idx
20
+ ON account_avatar_uploads (account_id);
21
+ CREATE INDEX IF NOT EXISTS account_avatar_uploads_expires_idx
22
+ ON account_avatar_uploads (expires_at) WHERE expires_at IS NOT NULL;
23
+
24
+ -- When an identity row was last written (insert or login refresh): the SSO avatar shown is the
25
+ -- one of the most recently refreshed identity. Null for rows written before this migration.
26
+ ALTER TABLE identities ADD COLUMN IF NOT EXISTS updated_at timestamptz;