@sixb/core 0.2.3 → 0.2.4

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 (122) hide show
  1. package/dist/actions/index.js +12 -12
  2. package/dist/agents/cancel.d.ts +1 -1
  3. package/dist/agents/cancel.d.ts.map +1 -1
  4. package/dist/agents/child-question.d.ts +35 -2
  5. package/dist/agents/child-question.d.ts.map +1 -1
  6. package/dist/agents/execution.d.ts +1 -1
  7. package/dist/agents/ids.d.ts +2 -0
  8. package/dist/agents/ids.d.ts.map +1 -1
  9. package/dist/agents/index.d.ts +3 -3
  10. package/dist/agents/index.d.ts.map +1 -1
  11. package/dist/agents/index.js +23 -15
  12. package/dist/agents/index.js.map +1 -1
  13. package/dist/agents/model-loop.d.ts.map +1 -1
  14. package/dist/agents/run-session-children.d.ts +9 -0
  15. package/dist/agents/run-session-children.d.ts.map +1 -1
  16. package/dist/agents/run-session-http.d.ts.map +1 -1
  17. package/dist/agents/run-session-serve.d.ts.map +1 -1
  18. package/dist/agents/tool-files.d.ts +1 -1
  19. package/dist/agents/tool-files.d.ts.map +1 -1
  20. package/dist/agents/tool-input-coercion.d.ts +20 -0
  21. package/dist/agents/tool-input-coercion.d.ts.map +1 -0
  22. package/dist/agents/validation.d.ts +1 -1
  23. package/dist/agents/validation.d.ts.map +1 -1
  24. package/dist/artifacts/frames/index.js +1 -1
  25. package/dist/artifacts/frames/protocol.d.ts +53 -2
  26. package/dist/artifacts/frames/protocol.d.ts.map +1 -1
  27. package/dist/artifacts/frames/runtime.d.ts +8 -1
  28. package/dist/artifacts/frames/runtime.d.ts.map +1 -1
  29. package/dist/artifacts/index.d.ts +1 -1
  30. package/dist/artifacts/index.d.ts.map +1 -1
  31. package/dist/artifacts/index.js +27 -1
  32. package/dist/artifacts/index.js.map +3 -3
  33. package/dist/artifacts/live/server.js +7 -7
  34. package/dist/artifacts/publish/index.js +6 -6
  35. package/dist/bootstrap/index.js +17 -17
  36. package/dist/{chunk-k66rp2hr.js → chunk-2bn6813a.js} +1 -1
  37. package/dist/{chunk-m7b9q5dk.js → chunk-3z1vxzcm.js} +1 -1
  38. package/dist/{chunk-qafng88v.js → chunk-6ef4esq4.js} +1 -1
  39. package/dist/{chunk-38yvdqzd.js → chunk-7kpqntgw.js} +1 -1
  40. package/dist/{chunk-tqa68kj7.js → chunk-8bns0y68.js} +2 -2
  41. package/dist/chunk-8t2ynwg0.js.map +1 -1
  42. package/dist/chunk-az95tsh3.js.map +2 -2
  43. package/dist/{chunk-4j0sagwv.js → chunk-evj5jxz3.js} +1 -1
  44. package/dist/{chunk-z0t4p2sk.js → chunk-gxwy4c3s.js} +41 -11
  45. package/dist/{chunk-z0t4p2sk.js.map → chunk-gxwy4c3s.js.map} +8 -8
  46. package/dist/{chunk-qds484t8.js → chunk-hvbvq7p4.js} +202 -12
  47. package/dist/chunk-hvbvq7p4.js.map +18 -0
  48. package/dist/{chunk-26qet7wh.js → chunk-msyevpp3.js} +1 -1
  49. package/dist/chunk-n4zzaf6q.js.map +1 -1
  50. package/dist/{chunk-s5n9617r.js → chunk-p8pgnq8d.js} +3 -3
  51. package/dist/{chunk-kv0kvknv.js → chunk-r9rtavg9.js} +2 -2
  52. package/dist/{chunk-bkmnd7zq.js → chunk-rsrc7vtw.js} +9 -9
  53. package/dist/{chunk-8p7bze4c.js → chunk-rsxb14an.js} +1 -1
  54. package/dist/{chunk-e9w4mgdh.js → chunk-rtm1jq00.js} +162 -17
  55. package/dist/{chunk-e9w4mgdh.js.map → chunk-rtm1jq00.js.map} +8 -7
  56. package/dist/{chunk-7z5rkf0m.js → chunk-t0s7b3d1.js} +4 -3
  57. package/dist/{chunk-7z5rkf0m.js.map → chunk-t0s7b3d1.js.map} +3 -3
  58. package/dist/{chunk-hkaa807g.js → chunk-td26wjr5.js} +1 -1
  59. package/dist/{chunk-6gtxshcc.js → chunk-vepea5c3.js} +3 -3
  60. package/dist/{chunk-2by73sm2.js → chunk-w1wq7gfr.js} +1 -1
  61. package/dist/{chunk-w9s23r24.js → chunk-yy914zfr.js} +3 -3
  62. package/dist/execution/agent.js +12 -12
  63. package/dist/execution/primitive.js +12 -12
  64. package/dist/execution/request.js +12 -12
  65. package/dist/index.js +19 -19
  66. package/dist/materializer/index.js +3 -3
  67. package/dist/models/execution/index.js +3 -3
  68. package/dist/models/language-model.d.ts +6 -0
  69. package/dist/models/language-model.d.ts.map +1 -1
  70. package/dist/models/tools.d.ts +2 -0
  71. package/dist/models/tools.d.ts.map +1 -1
  72. package/dist/objects/index.js +12 -12
  73. package/dist/objects/query/index.js +3 -3
  74. package/dist/pipelines/index.js +3 -3
  75. package/dist/projections/internal.js +2 -2
  76. package/dist/runtime/internal.js +7 -7
  77. package/dist/shares/internal.js +2 -2
  78. package/dist/storage/agents/provider.js +1 -1
  79. package/dist/storage/agents/types.d.ts +1 -1
  80. package/dist/storage/agents/types.d.ts.map +1 -1
  81. package/dist/storage/index.js +2 -2
  82. package/dist/syncs/index.js +4 -4
  83. package/dist/testing/index.js +19 -19
  84. package/dist/webhooks/internal.js +2 -2
  85. package/dist/workflows/index.js +15 -15
  86. package/package.json +1 -1
  87. package/src/agents/approval-outcome.ts +2 -2
  88. package/src/agents/cancel.ts +2 -2
  89. package/src/agents/child-question.ts +76 -8
  90. package/src/agents/execution.ts +1 -1
  91. package/src/agents/ids.ts +4 -1
  92. package/src/agents/index.ts +9 -2
  93. package/src/agents/model-loop.ts +3 -1
  94. package/src/agents/run-session-children.ts +33 -0
  95. package/src/agents/run-session-http.ts +1 -0
  96. package/src/agents/run-session-serve.ts +1 -0
  97. package/src/agents/tool-files.ts +1 -1
  98. package/src/agents/tool-input-coercion.ts +140 -0
  99. package/src/agents/validation.ts +11 -3
  100. package/src/artifacts/frames/protocol.ts +84 -2
  101. package/src/artifacts/frames/runtime.ts +296 -13
  102. package/src/artifacts/index.ts +3 -0
  103. package/src/http/api-routes.ts +1 -1
  104. package/src/models/language-model.ts +6 -0
  105. package/src/models/tools.ts +2 -0
  106. package/src/storage/agents/types.ts +1 -1
  107. package/dist/chunk-qds484t8.js.map +0 -18
  108. /package/dist/{chunk-k66rp2hr.js.map → chunk-2bn6813a.js.map} +0 -0
  109. /package/dist/{chunk-m7b9q5dk.js.map → chunk-3z1vxzcm.js.map} +0 -0
  110. /package/dist/{chunk-qafng88v.js.map → chunk-6ef4esq4.js.map} +0 -0
  111. /package/dist/{chunk-38yvdqzd.js.map → chunk-7kpqntgw.js.map} +0 -0
  112. /package/dist/{chunk-tqa68kj7.js.map → chunk-8bns0y68.js.map} +0 -0
  113. /package/dist/{chunk-4j0sagwv.js.map → chunk-evj5jxz3.js.map} +0 -0
  114. /package/dist/{chunk-26qet7wh.js.map → chunk-msyevpp3.js.map} +0 -0
  115. /package/dist/{chunk-s5n9617r.js.map → chunk-p8pgnq8d.js.map} +0 -0
  116. /package/dist/{chunk-kv0kvknv.js.map → chunk-r9rtavg9.js.map} +0 -0
  117. /package/dist/{chunk-bkmnd7zq.js.map → chunk-rsrc7vtw.js.map} +0 -0
  118. /package/dist/{chunk-8p7bze4c.js.map → chunk-rsxb14an.js.map} +0 -0
  119. /package/dist/{chunk-hkaa807g.js.map → chunk-td26wjr5.js.map} +0 -0
  120. /package/dist/{chunk-6gtxshcc.js.map → chunk-vepea5c3.js.map} +0 -0
  121. /package/dist/{chunk-2by73sm2.js.map → chunk-w1wq7gfr.js.map} +0 -0
  122. /package/dist/{chunk-w9s23r24.js.map → chunk-yy914zfr.js.map} +0 -0
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/storage/agents/types.ts"],
4
4
  "sourcesContent": [
5
- "import type { ActionSubject } from \"../../actions/types\"\nimport type { AgentMessage, AgentMessagePart, AgentMessageRole } from \"../../agents/message\"\nimport type { AgentReasoning } from \"../../agents/types\"\nimport type { Principal, UserPrincipal } from \"../../auth\"\nimport type { FileRef } from \"../../blob-storage/types\"\nimport type { SixbErrorCode, SixbFailure } from \"../../errors/types\"\nimport type { JsonObject, JsonValue } from \"../../json\"\nimport type {\n LanguageModelRef,\n LanguageModelTier,\n LanguageModelTierProbabilities,\n} from \"../../models\"\nimport type { ActionRunFailure, ActionRunParams } from \"../action-runs/types\"\n\n// ── agent_threads — one conversation with an agent ──────────────────────────────────────────────\n\nexport type AgentThreadStatus = \"active\" | \"archived\"\n\n/** Immutable, non-secret application input. Never store resolved env or credentials here. */\nexport type AgentThreadSandboxParams = Readonly<Record<string, JsonValue>>\n\n/** Worker-owned state, independent from the immutable application binding. */\nexport interface AgentThreadSandboxState {\n /** Exact name passed to the provider. Replacements always receive a fresh name. */\n readonly name: string\n readonly status: \"new\" | \"busy\" | \"ready\" | \"blocked\" | \"unavailable\"\n readonly sourceFingerprint?: string\n readonly initialized: boolean\n /** Durable context boundary: local files from before this reset are no longer available. */\n readonly resetAt?: string\n /** Never expires automatically: a delayed provider operation must not reach a successor. */\n readonly owner?: { readonly runId: string; readonly executionToken: string }\n}\n\nexport type TransitionAgentThreadSandboxInput = {\n readonly projectId: string\n readonly id: string\n} & (\n | {\n readonly action: \"acquire\"\n readonly runId: string\n readonly executionToken: string\n readonly name: string\n readonly sourceFingerprint: string\n }\n | {\n readonly action: \"replace\"\n readonly runId: string\n readonly executionToken: string\n readonly name: string\n readonly nextName: string\n }\n | {\n readonly action: \"settle\"\n readonly runId: string\n readonly executionToken: string\n readonly name: string\n readonly status: \"ready\" | \"blocked\" | \"unavailable\"\n readonly initialized: boolean\n }\n | {\n readonly action: \"recreate\"\n readonly expectedSandboxName: string\n readonly name: string\n }\n)\n\n/**\n * A conversation, or the thread a sub-agent works in. A sub-agent's thread is never listed, and\n * whoever reads its conversation reads it.\n */\nexport type AgentThreadKind = \"conversation\" | \"subagent\"\n\n/** Where a sub-agent's thread comes from: its conversation, the turn that spawned it, and its key. */\nexport interface AgentThreadParent {\n readonly threadId: string\n /** The turn that spawned it. Its later runs work under the turns that go on with it. */\n readonly spawnedBy: string\n readonly key: string\n}\n\n/** The computer a thread runs on, and the folder there its turns work in. */\nexport interface AgentThreadComputer {\n /** The CLI's id for the computer: a thread's turns are claimed by that computer alone. */\n readonly id: string\n /** What its owner calls the computer, such as \"Anthony's MacBook Pro\". */\n readonly name: string\n /** The absolute path its turns work in, on that computer. */\n readonly folder: string\n}\n\n/** Where a thread runs: which of its owner's computers, and the folder there. */\nexport type AgentThreadPlace = Pick<AgentThreadComputer, \"id\" | \"folder\">\n\nexport interface AgentThreadRecord {\n readonly id: string\n readonly projectId: string\n readonly kind: AgentThreadKind\n /** Set exactly on a sub-agent's thread. */\n readonly parent?: AgentThreadParent\n /** Who owns/opened the thread. Reuses the canonical auth principal (gains `agent` later for free). */\n readonly ownerPrincipal: Principal\n readonly title?: string\n readonly sandboxParams?: AgentThreadSandboxParams\n readonly sandboxState?: AgentThreadSandboxState\n /**\n * Where its turns run: on its owner's computer, which claims them, or, when absent, in the cloud.\n * A computer's thread takes turns from its owner alone.\n */\n readonly runsOn?: \"computer\"\n /**\n * Where on its owner's computers a computer's thread runs: set when it is created, and when its\n * owner moves it. Only that computer, open in that folder, claims its turns. A computer's thread\n * created before folders were kept has none until its owner moves it.\n */\n readonly computer?: AgentThreadComputer\n /**\n * When its turns last moved to where they run now, from a computer to the cloud or between\n * folders: the files earlier turns worked on are not here.\n */\n readonly movedAt?: Date\n readonly status: AgentThreadStatus\n /** Single-flight anchor: the id of the one run currently allowed to write, or `null` when idle. */\n readonly activeRunId: string | null\n readonly lastMessageAt?: Date\n readonly messageCount: number\n readonly createdAt: Date\n readonly updatedAt: Date\n}\n\nexport interface CreateAgentThreadInput {\n readonly id: string\n readonly projectId: string\n readonly ownerPrincipal: Principal\n readonly title?: string\n readonly sandboxParams?: AgentThreadSandboxParams\n readonly runsOn?: \"computer\"\n /** Where a computer's thread runs: required with `runsOn: \"computer\"`, refused without it. */\n readonly computer?: AgentThreadComputer\n readonly status?: AgentThreadStatus\n readonly createdAt?: Date\n readonly updatedAt?: Date\n}\n\n/**\n * A new thread holding a copy of another thread's finished messages. A turn still running is left\n * behind: what came from its trigger message on is not copied. Copies keep their `seq`, content,\n * author and `runId`, and get new ids. Runs are not copied, so the fork's runs, usage and cost are\n * its own; copied answers still show their run's diagnostics.\n *\n * Only the latest checkpoint the copy can use comes along, so the markers of earlier compactions\n * are not in the fork. The fork has no `lastMessageAt` until its first new message, so it sorts\n * by its creation.\n */\nexport interface ForkAgentThreadInput {\n readonly projectId: string\n /** The thread whose history is copied. */\n readonly sourceThreadId: string\n readonly id: string\n readonly ownerPrincipal: Principal\n readonly title?: string\n readonly sandboxParams?: AgentThreadSandboxParams\n /** Provider name of the fork's new sandbox; given exactly when `sandboxParams` is. */\n readonly sandboxName?: string\n /**\n * The source's shared artifacts, each id mapped to its copy's: the copied messages and summary\n * name the copies instead.\n */\n readonly artifactCopies?: Readonly<Record<string, string>>\n readonly createdAt?: Date\n}\n\n/** A conversation's sub-agent threads, oldest first. */\nexport interface ListAgentThreadChildrenInput {\n readonly projectId: string\n /** The conversation. */\n readonly parentThreadId: string\n /** Only those this turn spawned. */\n readonly parentRunId?: string\n /** At most this many, 100 by default. */\n readonly limit?: number\n readonly offset?: number\n}\n\n/** Conversations only: a sub-agent's thread is read through its conversation. */\nexport interface ListAgentThreadsInput {\n readonly projectId: string\n readonly statuses?: readonly AgentThreadStatus[]\n readonly ownerPrincipal?: Principal\n /** Only the threads this user takes part in. */\n readonly participantPrincipal?: UserPrincipal\n /** Only the threads that run on this computer, in this folder, with a turn active. */\n readonly activeOnComputer?: AgentThreadPlace\n readonly limit?: number\n readonly offset?: number\n readonly order?: \"asc\" | \"desc\"\n}\n\nexport interface ListAgentThreadsResult {\n readonly threads: readonly AgentThreadRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n// ── agent_thread_participants — the users a thread's owner added to it ─────────────────────────\n\nexport interface AgentThreadParticipantRecord {\n readonly projectId: string\n readonly threadId: string\n readonly principal: UserPrincipal\n readonly addedAt: Date\n readonly addedBy: Principal\n}\n\nexport interface AddAgentThreadParticipantsInput {\n readonly projectId: string\n readonly threadId: string\n /**\n * Distinct users, checked by the caller. Someone already taking part keeps when and by whom they\n * were first added.\n */\n readonly principals: readonly UserPrincipal[]\n readonly addedBy: Principal\n /** Refused with `participant_limit`, adding no one, when the thread would hold more. */\n readonly maxParticipants: number\n readonly addedAt?: Date\n}\n\nexport interface AssignAgentThreadComputerInput {\n readonly projectId: string\n readonly id: string\n /** Where the thread's turns run from now on. */\n readonly computer: AgentThreadComputer\n /** Its `movedAt` when this changes the computer or folder of a thread that had one. */\n readonly movedAt?: Date\n}\n\nexport interface MoveAgentThreadToCloudInput {\n readonly projectId: string\n readonly id: string\n readonly movedAt?: Date\n}\n\n/** A computer's thread, now in the cloud, and its queued turn, now the cloud's to run. */\nexport interface MoveAgentThreadToCloudResult {\n readonly thread: AgentThreadRecord\n readonly queued?: ConversationAgentRunRecord\n}\n\n/**\n * An open `sixb` on its owner's computer: while it is live, the threads that run on that computer\n * in its folder are reachable there. It ends when `sixb` closes, or lapses when it stops renewing.\n */\nexport interface AgentComputerSessionRecord {\n readonly projectId: string\n /** Chosen by the computer, once per open `sixb`; unique among its owner's sessions. */\n readonly id: string\n readonly ownerPrincipal: Principal\n readonly computer: AgentThreadComputer\n readonly expiresAt: Date\n /** Its threads' background commands, as its latest renewal reported them. */\n readonly backgroundCommands?: readonly AgentComputerBackgroundCommand[]\n /** The commands someone asked to stop: each renewal hands back those still running. */\n readonly stopRequests?: readonly AgentBackgroundCommandRef[]\n}\n\n/** How many background commands a computer session reports, and keeps stop requests for. */\nexport const AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX = 64\n\n/**\n * A background command an open `sixb` runs for one of its threads, which outlives the turn that\n * started it: the web shows how it stands between turns.\n */\nexport interface AgentComputerBackgroundCommand {\n readonly threadId: string\n /** `bg_<hex>`, as the agent's tools name it. */\n readonly id: string\n readonly command: string\n readonly status: \"running\" | \"exited\" | \"stopped\"\n readonly exitCode?: number\n /** ISO timestamps. */\n readonly startedAt: string\n readonly endedAt?: string\n}\n\n/** A background command by its start: its id comes again once `sixb` restarts. */\nexport interface AgentBackgroundCommandRef {\n readonly threadId: string\n readonly id: string\n readonly startedAt: string\n}\n\nexport interface RemoveAgentThreadParticipantInput {\n readonly projectId: string\n readonly threadId: string\n readonly principal: UserPrincipal\n}\n\nexport interface ListAgentThreadParticipantsInput {\n readonly projectId: string\n readonly threadIds: readonly string[]\n}\n\n// ── agent_runs — one loop execution (the worker job; attribution + fencing) ───────────────────\n\n/** Lifecycle shared by every durable agent execution, conversational or workflow-owned. */\nexport type AgentExecutionStatus = \"queued\" | \"running\" | \"succeeded\" | \"failed\" | \"cancelled\"\n\nexport type AgentRunStatus = AgentExecutionStatus\nexport type AgentRunKind = \"conversation\" | \"subagent\"\n\n/** Error codes an agent execution can persist and expose through its public contract. */\nexport const AGENT_RUN_FAILURE_CODES = [\n \"internal.unexpected\",\n \"runtime.cancelled\",\n \"agent.context_limit_exceeded\",\n \"agent.execution_failed\",\n \"agent.step_limit_reached\",\n \"ai.usage_limit_exceeded\",\n \"ai.usage_limit_unavailable\",\n] as const satisfies readonly [SixbErrorCode, ...SixbErrorCode[]]\n\nexport type AgentRunFailureCode = (typeof AGENT_RUN_FAILURE_CODES)[number]\n\n/**\n * Why a run ended — Sixb's provider-independent vocabulary. It includes model-loop reasons plus\n * platform-level endings such as `timeout`, `interrupted` for a turn whose worker died before\n * finishing it, `awaiting_approval` for a succeeded turn that paused on calls waiting for its\n * requester, or `awaiting_answer` for a succeeded sub-agent that paused on a question its parent\n * answers in a later turn, so reads remain typed and exhaustive. `other` and `unknown` preserve terminal state\n * when a provider adds a new reason.\n */\nexport const AGENT_RUN_FINISH_REASONS = [\n \"stop\",\n \"length\",\n \"content-filter\",\n \"tool-calls\",\n \"timeout\",\n \"interrupted\",\n \"awaiting_approval\",\n \"awaiting_answer\",\n \"error\",\n \"other\",\n \"unknown\",\n] as const\n\nexport type AgentRunFinishReason = (typeof AGENT_RUN_FINISH_REASONS)[number]\n\n/**\n * Coerce an external finish-reason string — a DB column or an SDK value — to {@link\n * AgentRunFinishReason}. An unrecognised value becomes `\"unknown\"` rather than being dropped.\n */\nexport function coerceAgentRunFinishReason(\n value: string | null | undefined\n): AgentRunFinishReason | undefined {\n if (value === null || value === undefined) {\n return undefined\n }\n return (AGENT_RUN_FINISH_REASONS as readonly string[]).includes(value)\n ? (value as AgentRunFinishReason)\n : \"unknown\"\n}\n\n/** Stable, user-facing diagnostics emitted by the platform while executing a run. */\nexport const AGENT_RUN_DIAGNOSTIC_CODES = [\"step_limit_reached\", \"output_limit_reached\"] as const\n\n/**\n * Closed on purpose, and the wire is closed with it.\n *\n * Sixb writes these codes and the generated client is what reads them, so an open union would only\n * be honest if the HTTP schema were open too — and that costs the OpenAPI enum, the client's\n * autocompletion, and the app's exhaustive `switch`. Sixb owns both ends, so a new code is a minor\n * version bump: cheap here, and a broken `switch` is better than a 500 from `z.enum`.\n */\nexport type AgentRunDiagnosticCode = (typeof AGENT_RUN_DIAGNOSTIC_CODES)[number]\nexport type AgentRunDiagnosticSeverity = \"warning\" | \"error\"\n\nexport interface AgentRunDiagnostic {\n readonly code: AgentRunDiagnosticCode\n readonly severity: AgentRunDiagnosticSeverity\n /** What the diagnostic is about: the turn as a whole. */\n readonly scope: \"run\"\n /** Sanitized, stable copy suitable for display to an end user. */\n readonly message: string\n}\n\n/**\n * Authorization state for the current queue delivery.\n *\n * `queueLeaseExpiresAt` is a persisted projection of `ClaimedQueueJob.leaseExpiresAt`, not an\n * independently managed run lease. It may only be extended from a successful queue lease renewal.\n */\nexport interface AgentRunExecution {\n readonly token: string\n readonly queueLeaseExpiresAt: Date\n}\n\ninterface AgentRunRecordBase {\n readonly id: string\n readonly projectId: string\n readonly executionId: string\n readonly status: AgentRunStatus\n readonly modelId?: string\n /** Why the run ended (our own SDK-independent enum). */\n readonly finishReason?: AgentRunFinishReason\n /** Platform diagnostics are transcript annotations, never agent-authored message content. */\n readonly diagnostics?: readonly AgentRunDiagnostic[]\n /** Portable failure snapshot when the run did not succeed. */\n readonly error?: SixbFailure<AgentRunFailureCode>\n /** Execution attempts: `0` while queued, `1` on first start, incremented on redelivery. */\n readonly attempt: number\n readonly execution?: AgentRunExecution\n /**\n * When someone asked a running run to stop. Its run token stops working at once, and its runner\n * learns of it at its next lease renewal if the broker's cancel never reached it.\n */\n readonly cancelRequestedAt?: Date\n readonly createdAt: Date\n readonly startedAt?: Date\n readonly completedAt?: Date\n}\n\nexport interface ConversationAgentRunRecord extends AgentRunRecordBase {\n readonly kind: \"conversation\"\n readonly threadId: string\n readonly triggerMessageId: string\n /** Immutable model selection captured at admission. Absent only on runs predating this field. */\n readonly spec?: ConversationAgentRunSpec\n}\n\n/** Immutable, serialisable model selection and requester settings for one conversational turn. */\nexport interface ConversationAgentRunSpec {\n readonly model: LanguageModelRef\n /** With tiers, the tier of the model the turn runs on. */\n readonly tier?: LanguageModelTier\n /**\n * How likely the decision model judged each tier, when Sixb picked the turn's model. Kept to\n * calibrate the thresholds the tier is picked from (`heavy` from 0.4, `light` from 0.8).\n */\n readonly tierProbabilities?: LanguageModelTierProbabilities\n readonly reasoning?: AgentReasoning\n /** Canonical IANA time zone of the requester. Absent uses the project time zone. */\n readonly timeZone?: string\n /** Canonical BCP 47 language of the requester. Absent uses the project locale. */\n readonly locale?: string\n /** What the turn may change without asking its requester. Absent on older runs: `auto`. */\n readonly approvalMode?: AgentApprovalMode\n /** Its thread's `runsOn` when it was asked for: a computer's turn never reaches the agent queue. */\n readonly runsOn?: \"computer\"\n}\n\n/** Immutable, serialisable child configuration captured before dispatch. */\nexport interface SubagentRunSpec {\n readonly model: LanguageModelRef\n /** With tiers, the tier of the model the child runs on. Absent on children admitted before it. */\n readonly tier?: LanguageModelTier\n readonly reasoning?: AgentReasoning\n /** Focused task supplied by the parent Agent. */\n readonly task: string\n /** At most this many steps per run, as its parent asked: the project's limit still applies. */\n readonly maxSteps?: number\n /** Project tools available when the child was admitted. Runtime tools are injected separately. */\n readonly toolNames: readonly string[]\n /** The parent turn's mode, copied when the child was admitted. Absent: `auto`. */\n readonly approvalMode?: AgentApprovalMode\n /** The parent turn's requester settings. Absent uses the project's. */\n readonly timeZone?: string\n readonly locale?: string\n /** Files the parent handed over, copied into the child's sandbox at these paths. */\n readonly files?: readonly SubagentRunFile[]\n}\n\n/** A file a parent and its child hand each other, stored once and copied into a sandbox. */\nexport interface SubagentRunFile {\n /** Relative, `/`-separated, without `.` or `..` segments. */\n readonly path: string\n readonly fileRef: FileRef\n}\n\n/** Durable child output returned to its parent by `wait_agent`. */\nexport interface SubagentRunResult {\n /** Empty only for a child that paused on its held calls before it answered. */\n readonly text: string\n /** What the child wrote under `out/`, by path relative to it. */\n readonly files?: readonly SubagentRunFile[]\n /** Why none of what it wrote under `out/` came back, and what to do about it. */\n readonly filesError?: string\n /**\n * What its parent sent a paused child that it had not read: the run that continues it reads it\n * first.\n */\n readonly unread?: readonly { readonly id: string; readonly text: string }[]\n}\n\nexport interface SubagentRunRecord extends AgentRunRecordBase {\n readonly kind: \"subagent\"\n /** The child's own thread, which holds its task and its work. */\n readonly threadId: string\n /** The message of its thread that started the run. */\n readonly triggerMessageId: string\n /** The conversation turn the child runs under: its mode and cancellation. */\n readonly parentRunId: string\n /** Stable parent-selected key that makes repeated tool execution idempotent. */\n readonly spawnKey: string\n readonly spec: SubagentRunSpec\n readonly result?: SubagentRunResult\n}\n\nexport type AgentRunRecord = ConversationAgentRunRecord | SubagentRunRecord\n\nexport interface CreateAgentRunInput {\n readonly id: string\n readonly projectId: string\n readonly executionId: string\n readonly threadId: string\n readonly triggerMessageId: string\n readonly spec: ConversationAgentRunSpec\n readonly createdAt?: Date\n}\n\nexport interface CreateSubagentRunInput {\n readonly id: string\n readonly projectId: string\n readonly executionId: string\n readonly parentRunId: string\n /** Current parent delivery token. New children are admitted only while that delivery owns it. */\n readonly parentExecutionToken: string\n readonly spawnKey: string\n readonly spec: SubagentRunSpec\n /**\n * The child's thread. Its first run creates it, owned by the conversation's owner; a later run\n * goes into it, and is refused while another run of the thread is active.\n */\n readonly thread: { readonly id: string; readonly create: boolean }\n /** The user message that starts the run, appended to the child's thread with the run's id. */\n readonly trigger: Pick<AppendAgentMessageInput, \"id\" | \"parts\" | \"metadata\">\n /** Internal safety bound enforced atomically across worker processes. */\n readonly maxActiveChildren: number\n readonly createdAt?: Date\n}\n\nexport interface StartAgentRunInput {\n readonly id: string\n readonly projectId: string\n readonly modelId?: string\n readonly execution: AgentRunExecution\n readonly startedAt?: Date\n /**\n * Start it only as a computer's turn, there and in that folder: one whose thread moved meanwhile\n * is refused with `invalid_state`, so it never starts where its thread no longer runs.\n */\n readonly onComputer?: AgentThreadPlace\n}\n\nexport interface FinishQueuedAgentRunInput {\n readonly id: string\n readonly projectId: string\n readonly status: \"failed\" | \"cancelled\"\n readonly error?: SixbFailure<AgentRunFailureCode>\n readonly completedAt?: Date\n}\n\nexport interface ReclaimAgentRunInput {\n readonly id: string\n readonly projectId: string\n readonly execution: AgentRunExecution\n /**\n * Take the run over only if the lease last recorded on it ran out by then, checked in the same\n * write: a renewal that lands first keeps it its runner's. Otherwise `invalid_state`.\n */\n readonly ifLapsedBy?: Date\n}\n\nexport interface ConfirmAgentRunExecutionOwnershipInput {\n readonly id: string\n readonly projectId: string\n readonly executionToken: string\n /** Exact expiration returned by the queue claim or its latest successful renewal. */\n readonly queueLeaseExpiresAt: Date\n}\n\nexport interface RequestAgentRunCancelInput {\n readonly id: string\n readonly projectId: string\n readonly at?: Date\n}\n\nexport type FinishAgentRunInput =\n | {\n readonly id: string\n readonly projectId: string\n readonly executionToken: string\n readonly status: \"succeeded\"\n readonly modelId?: string\n readonly finishReason?: AgentRunFinishReason\n readonly diagnostics?: readonly AgentRunDiagnostic[]\n readonly result?: SubagentRunResult\n readonly completedAt?: Date\n }\n | {\n readonly id: string\n readonly projectId: string\n readonly executionToken: string\n readonly status: \"failed\" | \"cancelled\"\n readonly modelId?: string\n /** Only a succeeded run pauses. */\n readonly finishReason?: Exclude<AgentRunFinishReason, \"awaiting_approval\" | \"awaiting_answer\">\n readonly diagnostics?: readonly AgentRunDiagnostic[]\n readonly error?: SixbFailure<AgentRunFailureCode>\n readonly completedAt?: Date\n }\n\nexport interface ListAgentRunsInput {\n readonly projectId: string\n readonly kinds?: readonly AgentRunKind[]\n readonly threadId?: string\n readonly parentRunId?: string\n readonly statuses?: readonly AgentRunStatus[]\n /** Effective start time; runs that never started use `createdAt`. */\n readonly startedAfter?: Date\n /** Effective start time; runs that never started use `createdAt`. */\n readonly startedBefore?: Date\n readonly limit?: number\n readonly offset?: number\n readonly order?: \"asc\" | \"desc\"\n /** Leave out the turns that wait for a computer: only a worker's to run. */\n readonly excludeComputerTurns?: boolean\n}\n\nexport interface ListThreadSubagentsInput {\n readonly projectId: string\n /** The conversation whose turns spawned them. */\n readonly threadId: string\n readonly spawnKey?: string\n readonly finishReason?: AgentRunFinishReason\n /** At most this many, 100 by default. */\n readonly limit?: number\n}\n\nexport interface ListAgentRunsResult {\n readonly runs: readonly AgentRunRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n// ── agent_messages — one message (assistant messages inserted only once finalized) ─────────────\n\nexport type { AgentMessageRole }\n\nexport interface AgentMessageRecord {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n /**\n * The run that produced this message; `null` for user-authored messages. In a sub-agent's thread\n * every message has one, its trigger too, so a run's messages are deleted whole. A message copied\n * by a fork keeps the run that produced it, which belongs to the thread it was copied from.\n */\n readonly runId: string | null\n readonly role: AgentMessageRole\n /** Principal that authored this persisted message: caller for user messages, agent identity later for assistant messages. */\n readonly authorPrincipal?: Principal\n /** Monotonic per thread, assigned by the store. */\n readonly seq: number\n /** Structured message content — text / reasoning / step boundaries / tool calls. */\n readonly parts: readonly AgentMessagePart[]\n /** Message-level metadata (mirrors `UIMessage.metadata`). */\n readonly metadata?: JsonValue\n /** Versions the `parts` shape so it can be migrated; stamped from `AGENT_MESSAGE_CONTENT_VERSION`. */\n readonly contentVersion: number\n readonly createdAt: Date\n readonly completedAt?: Date\n}\n\n/** Append a message: a {@link AgentMessage} (role + parts + metadata) plus its storage identity. */\nexport interface AppendAgentMessageInput extends AgentMessage {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n readonly runId: string | null\n readonly authorPrincipal?: Principal\n readonly createdAt?: Date\n readonly completedAt?: Date\n}\n\nexport interface DeleteAgentMessagesByRunInput {\n readonly projectId: string\n readonly threadId: string\n readonly runId: string\n /**\n * The run that deletes them, when one does: refused with `execution_lost` unless it still runs\n * under this token, checked in the same transaction as the delete.\n */\n readonly fence?: { readonly runId: string; readonly executionToken: string }\n}\n\nexport interface ListAgentMessagesInput {\n readonly projectId: string\n readonly threadId: string\n /** Return only messages whose per-thread sequence is greater than this retained boundary. */\n readonly afterSeq?: number\n readonly roles?: readonly AgentMessageRole[]\n readonly limit?: number\n readonly offset?: number\n readonly order?: \"asc\" | \"desc\"\n}\n\nexport interface ListAgentMessagesResult {\n readonly messages: readonly AgentMessageRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n// ── agent_context_checkpoints — append-only model-context boundaries ──────────────────────────\n\nexport type AgentContextCheckpointReason = \"threshold\" | \"overflow\"\n\n/**\n * A durable summary boundary used only when projecting a thread into model context.\n *\n * Checkpoints never replace or mutate transcript messages. Normal thread reads remain authoritative\n * and complete; the worker reads the latest checkpoint and only the retained message tail.\n */\nexport interface AgentContextCheckpointRecord {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n /** A fork's copy keeps the run that wrote the summary, in the thread it was copied from. */\n readonly createdByRunId: string\n readonly previousCheckpointId?: string\n readonly reason: AgentContextCheckpointReason\n readonly summary: string\n readonly summaryFormatVersion: 1\n readonly summarizedThroughSeq: number\n readonly observedHeadSeq: number\n readonly estimatedInputTokensBefore: number\n readonly estimatedInputTokensAfter: number\n readonly summaryModelId: string\n readonly createdAt: Date\n}\n\nexport interface CreateAgentContextCheckpointInput {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n readonly createdByRunId: string\n /** Compare-and-swap anchor. `null` means the thread must not have a prior checkpoint. */\n readonly expectedPreviousCheckpointId: string | null\n /** Compare-and-swap anchor for the complete transcript observed by the summarizer. */\n readonly expectedHeadSeq: number\n /** Current delivery token for `createdByRunId`; stale redeliveries must not write. */\n readonly executionToken: string\n readonly reason: AgentContextCheckpointReason\n readonly summary: string\n readonly summaryFormatVersion: 1\n readonly summarizedThroughSeq: number\n readonly observedHeadSeq: number\n readonly estimatedInputTokensBefore: number\n readonly estimatedInputTokensAfter: number\n readonly summaryModelId: string\n readonly createdAt?: Date\n}\n\n// ── Store ───────────────────────────────────────────────────────────────────────────────────────\n\nexport interface AgentThreadStore {\n /** Atomic run-fenced transition, or explicit idle-thread recreation. */\n transitionSandbox(input: TransitionAgentThreadSandboxInput): Promise<AgentThreadSandboxState>\n create(input: CreateAgentThreadInput): Promise<AgentThreadRecord>\n /**\n * Create a thread holding a copy of another's finished history, in one transaction. The source's\n * sub-agent threads are not copied, and a sub-agent's thread is refused.\n */\n fork(input: ForkAgentThreadInput): Promise<AgentThreadRecord>\n getById(params: { projectId: string; id: string }): Promise<AgentThreadRecord | null>\n /** The threads found, in first-occurrence input order; a missing one is omitted. */\n getByIds(params: {\n readonly projectId: string\n readonly ids: readonly string[]\n }): Promise<readonly AgentThreadRecord[]>\n list(input: ListAgentThreadsInput): Promise<ListAgentThreadsResult>\n /** The sub-agents' threads of a conversation, by creation and id, all of them or one turn's. */\n listChildren(input: ListAgentThreadChildrenInput): Promise<readonly AgentThreadRecord[]>\n /**\n * Add users atomically and return every participant of the thread afterwards. A sub-agent's\n * thread has none: its readers are its conversation's.\n */\n addParticipants(\n input: AddAgentThreadParticipantsInput\n ): Promise<readonly AgentThreadParticipantRecord[]>\n /** Whether the user took part until now. */\n removeParticipant(input: RemoveAgentThreadParticipantInput): Promise<boolean>\n /**\n * Move a computer's thread to another computer or folder, and return the thread after. A cloud\n * thread runs on none, and is refused.\n */\n assignComputer(input: AssignAgentThreadComputerInput): Promise<AgentThreadRecord>\n /**\n * Move a computer's thread to the cloud, in one transaction with its queued turn, which the cloud\n * runs instead. Refused with `active_run_exists` while a turn runs on the computer, and\n * `invalid_input` for a thread already in the cloud.\n */\n moveToCloud(input: MoveAgentThreadToCloudInput): Promise<MoveAgentThreadToCloudResult>\n /** The participants of these threads, oldest first, then by user id and thread id. */\n listParticipants(\n input: ListAgentThreadParticipantsInput\n ): Promise<readonly AgentThreadParticipantRecord[]>\n}\n\nexport interface AgentRunStore {\n /**\n * Persist a queued turn and atomically claim the thread's single-flight slot. A sub-agent's\n * thread takes only child runs.\n */\n create(input: CreateAgentRunInput): Promise<ConversationAgentRunRecord>\n /**\n * Persist or replay one idempotent child run while atomically enforcing parent fan-out. In one\n * transaction it creates the child's thread or takes it (single-flight, as a conversation), then\n * appends the trigger and the run.\n */\n createSubagent(input: CreateSubagentRunInput): Promise<SubagentRunRecord>\n /** Transition a queued run to running and install the first delivery's execution token. */\n start(input: StartAgentRunInput): Promise<AgentRunRecord>\n /** Finish a queued run before execution and release the thread's single-flight slot. */\n finishQueued(input: FinishQueuedAgentRunInput): Promise<AgentRunRecord>\n /** Rotate the execution token for a redelivered running job (`attempt++`). */\n reclaim(input: ReclaimAgentRunInput): Promise<AgentRunRecord>\n /**\n * Project the queue's latest confirmed ownership expiration onto the current execution.\n * Implementations must fence by token and must never move the expiration backwards.\n */\n confirmExecutionOwnership(input: ConfirmAgentRunExecutionOwnershipInput): Promise<AgentRunRecord>\n /**\n * Record that a running run was asked to stop, keeping the first time it was. A run in any other\n * state is returned as it is: a queued one is cancelled with `finishQueued`.\n */\n requestCancel(input: RequestAgentRunCancelInput): Promise<AgentRunRecord>\n /**\n * Finalize a run and release the thread's `activeRunId`. `finishReason: \"awaiting_approval\"`\n * needs a call the run holds (see `approvals.holdsRun`). A turn that ends any other way cancels\n * its pending approvals and stops resuming on the rest; a child that fails or is cancelled\n * cancels its own pending ones.\n */\n finish(input: FinishAgentRunInput): Promise<AgentRunRecord>\n getById(params: { projectId: string; id: string }): Promise<AgentRunRecord | null>\n getByIds(params: {\n projectId: string\n ids: readonly string[]\n }): Promise<readonly AgentRunRecord[]>\n /**\n * The children of a conversation's turns, the latest turn's first, by its effective start, and\n * within a turn the latest admitted first. Read by key (one per turn) or by finish reason.\n */\n listThreadSubagents(input: ListThreadSubagentsInput): Promise<readonly SubagentRunRecord[]>\n list(input: ListAgentRunsInput): Promise<ListAgentRunsResult>\n}\n\nexport interface AgentMessageStore {\n /** Insert a message (its `parts` are the canonical content) and bump thread stats. */\n append(input: AppendAgentMessageInput): Promise<AgentMessageRecord>\n /** Delete every message produced by one run and repair the thread's message stats. */\n deleteByRunId(input: DeleteAgentMessagesByRunInput): Promise<number>\n getById(params: { projectId: string; id: string }): Promise<AgentMessageRecord | null>\n list(input: ListAgentMessagesInput): Promise<ListAgentMessagesResult>\n}\n\nexport interface AgentContextCheckpointStore {\n /**\n * Append one checkpoint after atomically validating run ownership and both transcript anchors.\n * Repeating the same payload for the same creating run is idempotent.\n */\n create(input: CreateAgentContextCheckpointInput): Promise<AgentContextCheckpointRecord>\n /** The thread's checkpoints created by the requested runs, in first-occurrence input order. */\n getByRunIds(input: {\n readonly projectId: string\n readonly threadId: string\n readonly runIds: readonly string[]\n }): Promise<readonly AgentContextCheckpointRecord[]>\n getLatest(input: {\n readonly projectId: string\n readonly threadId: string\n }): Promise<AgentContextCheckpointRecord | null>\n}\n\n// ── agent_approvals — calls of the Agent that wait for whoever asked ───────────────────────────\n\n/**\n * What the Agent may change without asking its requester: `manual` asks for every action and\n * workflow, `accept-edits` runs the actions that only change Sixb, `auto` runs everything.\n */\nexport const AGENT_APPROVAL_MODES = [\"manual\", \"accept-edits\", \"auto\"] as const\n\nexport type AgentApprovalMode = (typeof AGENT_APPROVAL_MODES)[number]\n\n/** The modes that hold some calls: the one that held a call is recorded on its approval. */\nexport const AGENT_HOLDING_APPROVAL_MODES = [\n \"manual\",\n \"accept-edits\",\n] as const satisfies readonly AgentApprovalMode[]\n\nexport type AgentHoldingApprovalMode = (typeof AGENT_HOLDING_APPROVAL_MODES)[number]\n\nexport const AGENT_APPROVAL_STATUSES = [\n \"pending\",\n \"approved\",\n \"denied\",\n \"cancelled\",\n \"superseded\",\n \"expired\",\n] as const\n\nexport type AgentApprovalStatus = (typeof AGENT_APPROVAL_STATUSES)[number]\n\n/** The statuses a pending approval is settled to without a decision. */\nexport type AgentApprovalSettledStatus = Extract<\n AgentApprovalStatus,\n \"cancelled\" | \"superseded\" | \"expired\"\n>\n\n/**\n * The held call, as it runs once approved. An action's params are normalized: what the user\n * approves is exactly what runs. Its run id is the one the Agent named, so a repeated request finds\n * the same approval and the same run.\n */\nexport type AgentApprovalCall =\n | {\n readonly kind: \"action\"\n readonly actionId: string\n readonly subject: ActionSubject\n readonly params: ActionRunParams\n readonly actionRunId: string\n /** `external` when the action has a writeback or effects: it reaches beyond Sixb. */\n readonly effect: \"ontology\" | \"external\"\n }\n | {\n readonly kind: \"workflow\"\n readonly workflowId: string\n readonly input: JsonObject\n readonly workflowRunId: string\n }\n\n/** What running an approved call gave. */\nexport type AgentApprovalOutcome =\n | {\n readonly kind: \"action-run\"\n readonly runId: string\n readonly status: \"succeeded\" | \"failed\"\n readonly error?: ActionRunFailure\n }\n | { readonly kind: \"workflow-run\"; readonly runId: string; readonly queuedAt: string }\n /** The call was refused when it ran, for example because its requester lost a grant. */\n | { readonly kind: \"error\"; readonly error: SixbFailure }\n\nexport interface AgentApprovalRecord {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n /** The conversation turn the call belongs to. */\n readonly runId: string\n /** The run that made the call: the turn itself, or one of its children. */\n readonly callerRunId: string\n /** Who asked for the turn: the only one who decides, as the call runs with their rights. */\n readonly requestedBy: Principal\n /** The mode that held the call. */\n readonly mode: AgentHoldingApprovalMode\n /** The call's run id, unique among a thread's pending, approved and denied approvals. */\n readonly callKey: string\n readonly call: AgentApprovalCall\n readonly status: AgentApprovalStatus\n readonly createdAt: Date\n readonly expiresAt: Date\n readonly decidedAt?: Date\n readonly decidedBy?: Principal\n /** Set once an approved call ran. */\n readonly outcome?: AgentApprovalOutcome\n /** The user message that told the model how the approval ended. */\n readonly reportedInMessageId?: string\n /** \"Always allow\": the mode its requester raised the turn's calls to when deciding this one. */\n readonly raisedMode?: AgentApprovalMode\n /**\n * The turn will not resume for it: stopped, its requester left, or another of its calls was set\n * aside. The thread's next message still reports it.\n */\n readonly turnStoppedAt?: Date\n /** When a process last took the approved call to run it; a stale claim can be taken again. */\n readonly executionClaimedAt?: Date\n}\n\nexport interface RequestAgentApprovalInput {\n readonly id: string\n readonly projectId: string\n readonly runId: string\n readonly callerRunId: string\n /** The caller run's current delivery token: a stale delivery holds nothing. */\n readonly executionToken: string\n readonly requestedBy: Principal\n readonly mode: AgentHoldingApprovalMode\n readonly call: AgentApprovalCall\n readonly createdAt?: Date\n readonly expiresAt: Date\n}\n\nexport interface RequestAgentApprovalResult {\n readonly approval: AgentApprovalRecord\n /** `false` when a pending, approved or denied approval of the thread had the same call key. */\n readonly created: boolean\n}\n\nexport interface DecideAgentApprovalInput {\n readonly projectId: string\n readonly id: string\n readonly decision: \"approved\" | \"denied\"\n readonly decidedBy: Principal\n readonly decidedAt?: Date\n /** With `approved`: \"Always allow\" raised the turn's mode to this one. */\n readonly raisedMode?: AgentApprovalMode\n}\n\nexport interface DecideAgentApprovalResult {\n /** The approval afterwards: `expired` when its time ran out before this decision. */\n readonly approval: AgentApprovalRecord\n /** Whether this call moved it out of `pending` with the decision. */\n readonly decided: boolean\n}\n\nexport interface SettleAgentApprovalsInput {\n readonly projectId: string\n readonly threadId: string\n readonly status: AgentApprovalSettledStatus\n}\n\n/** Stop a thread's turn, or a requester's turns there, from resuming on their calls. */\nexport interface StopAgentApprovalsInput {\n readonly projectId: string\n readonly threadId: string\n /** Only the calls of this conversation turn. */\n readonly runId?: string\n /** Only the calls this principal asked for. */\n readonly requestedBy?: Principal\n readonly stoppedAt?: Date\n}\n\nexport interface StopAgentApprovalsResult {\n /** The pending approvals it cancelled. */\n readonly cancelled: readonly AgentApprovalRecord[]\n /** How many unreported approvals it stopped, the cancelled ones included. */\n readonly stopped: number\n}\n\n/** Where a keyset listing resumes: after this approval, in the order approvals are listed. */\nexport interface AgentApprovalCursor {\n readonly createdAt: Date\n readonly id: string\n}\n\nexport interface MarkAgentApprovalsReportedInput {\n readonly projectId: string\n readonly threadId: string\n readonly ids: readonly string[]\n readonly messageId: string\n /** A resume: an approval whose turn was stopped is not marked. */\n readonly resuming?: boolean\n}\n\nexport interface ListAgentApprovalsInput {\n readonly projectId: string\n readonly threadId?: string\n readonly runId?: string\n readonly requestedBy?: Principal\n readonly statuses?: readonly AgentApprovalStatus[]\n /** `false`: only the approvals no message reported yet. */\n readonly reported?: boolean\n readonly limit?: number\n readonly offset?: number\n}\n\nexport interface ListAgentApprovalsResult {\n /** Oldest first. */\n readonly approvals: readonly AgentApprovalRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n/**\n * Held calls and their decisions. `runs.finish` settles a run's approvals in its own transaction:\n * a turn that pauses keeps them for their decision, any other ending cancels its pending ones.\n */\nexport interface AgentApprovalStore {\n /**\n * Fenced like a checkpoint: the caller run is running with `executionToken`, and is the\n * conversation turn `runId` or one of its children. Returns the thread's pending, approved or\n * denied approval with the same call key when there is one, and creates one otherwise.\n */\n request(input: RequestAgentApprovalInput): Promise<RequestAgentApprovalResult>\n /** Compare-and-swap from `pending`; `null` when no such approval exists. */\n decide(input: DecideAgentApprovalInput): Promise<DecideAgentApprovalResult | null>\n /** Record what an approved call gave, once: an approval with an outcome is returned unchanged. */\n recordOutcome(input: {\n readonly projectId: string\n readonly id: string\n readonly outcome: AgentApprovalOutcome\n }): Promise<AgentApprovalRecord>\n /** Settle the thread's pending approvals, and return the ones it settled. */\n settle(input: SettleAgentApprovalsInput): Promise<readonly AgentApprovalRecord[]>\n /** Expire the project's pending approvals whose time ran out by `now`, and return them. */\n expireDue(input: {\n readonly projectId: string\n readonly now: Date\n readonly limit?: number\n }): Promise<readonly AgentApprovalRecord[]>\n /**\n * Cancel the matching pending approvals and mark every matching one no message reported yet as\n * stopped: their turn never resumes on them.\n */\n stop(input: StopAgentApprovalsInput): Promise<StopAgentApprovalsResult>\n /** Mark the ones no message reported yet, and return their ids. */\n markReported(input: MarkAgentApprovalsReportedInput): Promise<readonly string[]>\n /**\n * Whether the run holds a call: one of its approvals, or one it made for its turn, pending, or\n * decided and not reported yet. `runs.finish` checks the same before `awaiting_approval`.\n */\n holdsRun(input: { readonly projectId: string; readonly runId: string }): Promise<boolean>\n /**\n * Take an approved call without an outcome to run it, unless another process took it after\n * `staleBefore`; its decision is its first claim. `null` when it is not there to take.\n */\n claimExecution(input: {\n readonly projectId: string\n readonly id: string\n readonly claimedAt: Date\n readonly staleBefore: Date\n }): Promise<AgentApprovalRecord | null>\n /**\n * What a repair pass works on, oldest first: approved calls without an outcome whose claim is\n * older than `claimableBefore`, and decided calls no message reported whose turn is not stopped.\n */\n listRepairable(input: {\n readonly projectId: string\n readonly claimableBefore: Date\n readonly after?: AgentApprovalCursor\n readonly limit: number\n }): Promise<readonly AgentApprovalRecord[]>\n getById(params: {\n readonly projectId: string\n readonly id: string\n }): Promise<AgentApprovalRecord | null>\n list(input: ListAgentApprovalsInput): Promise<ListAgentApprovalsResult>\n}\n\n/** Each user's approval mode: a default, and their own choice in each thread. */\nexport interface AgentApprovalModeStore {\n getDefault(input: {\n readonly projectId: string\n readonly principal: Principal\n }): Promise<AgentApprovalMode | null>\n setDefault(input: {\n readonly projectId: string\n readonly principal: Principal\n readonly mode: AgentApprovalMode\n readonly updatedAt?: Date\n }): Promise<void>\n getForThread(input: {\n readonly projectId: string\n readonly threadId: string\n readonly principal: Principal\n }): Promise<AgentApprovalMode | null>\n /**\n * `null` clears the choice: the user's turns in the thread follow their default again. Throws\n * `thread_not_found` when the thread does not exist.\n */\n setForThread(input: {\n readonly projectId: string\n readonly threadId: string\n readonly principal: Principal\n readonly mode: AgentApprovalMode | null\n readonly updatedAt?: Date\n }): Promise<void>\n}\n\n// ── Memory ──────────────────────────────────────────────────────────────────────────────────────\n\n/** One file of a memory repo, at its path from the repo root. */\nexport interface AgentMemoryFile {\n readonly path: string\n readonly contents: string\n}\n\n/** A memory repo as of its latest revision. */\nexport interface AgentMemoryRepoRecord {\n /** 0 before the first save. */\n readonly revision: number\n /** Ordered by path. */\n readonly files: readonly AgentMemoryFile[]\n}\n\n/** One change of a save: the file's new contents, or `null` to delete it. */\nexport interface AgentMemoryChange {\n readonly path: string\n readonly contents: string | null\n}\n\nexport interface SaveAgentMemoryInput {\n readonly projectId: string\n /** `user:<userId>` or `project`. */\n readonly repoId: string\n /** The revision the caller loaded. */\n readonly baseRevision: number\n readonly message: string\n readonly author: Principal\n /** The conversation the save came from, `/agents/<threadId>`. */\n readonly source?: string\n readonly changes: readonly AgentMemoryChange[]\n readonly createdAt?: Date\n}\n\nexport type SaveAgentMemoryResult =\n | { readonly saved: true; readonly revision: number }\n | {\n readonly saved: false\n /** The repo's latest revision. */\n readonly revision: number\n /** Files in `changes` that another save changed after `baseRevision`, as they are now. */\n readonly conflicts: readonly AgentMemoryChange[]\n }\n\n/** One save: who made it, why, and which paths it wrote. A revision never changes. */\nexport interface AgentMemoryRevisionRecord {\n readonly revision: number\n readonly message: string\n readonly author: Principal\n readonly source?: string\n /** Ordered by path. */\n readonly changes: readonly { readonly path: string; readonly deleted: boolean }[]\n readonly createdAt: Date\n}\n\nexport interface ListAgentMemoryRevisionsInput {\n readonly projectId: string\n readonly repoId: string\n readonly limit?: number\n readonly offset?: number\n}\n\nexport interface ListAgentMemoryRevisionsResult {\n /** Newest first. */\n readonly revisions: readonly AgentMemoryRevisionRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n/**\n * Memory repos as append-only revisions: a save inserts one revision and the files it wrote, and\n * never updates a row. Paths, sizes and who may save are decided in Core before a call reaches\n * storage.\n */\nexport interface AgentMemoryStore {\n /**\n * The repo at its latest revision, or with `asOf` at the latest revision saved by then, and with\n * `revision` at the latest up to that one: revision 0 and no files when none was. File versions\n * pruned from the history are missing from it.\n */\n get(input: {\n readonly projectId: string\n readonly repoId: string\n readonly asOf?: Date\n readonly revision?: number\n }): Promise<AgentMemoryRepoRecord>\n /**\n * In one transaction: reports a conflict when a path in `changes` was written after\n * `baseRevision`, or when the repo is behind `baseRevision` because it was deleted; otherwise\n * stores the next revision. The same transaction removes file versions older than\n * {@link AGENT_MEMORY_HISTORY_DAYS} days that are not their path's latest.\n */\n save(input: SaveAgentMemoryInput): Promise<SaveAgentMemoryResult>\n listRevisions(input: ListAgentMemoryRevisionsInput): Promise<ListAgentMemoryRevisionsResult>\n /** Deletes the repo with its history. */\n delete(input: { readonly projectId: string; readonly repoId: string }): Promise<void>\n}\n\n/** How long a file version that is not its path's latest stays in a repo's history. */\nexport const AGENT_MEMORY_HISTORY_DAYS = 90\n\n/** Each open `sixb` on its owner's computers, as a lease it renews. */\nexport interface AgentComputerSessionStore {\n /**\n * Open the session, or renew it until `expiresAt`; its computer, folder and background commands\n * are kept as given, and its stop requests as they are.\n */\n hold(input: Omit<AgentComputerSessionRecord, \"stopRequests\">): Promise<void>\n /**\n * Record that someone asked to stop one of its commands, once, keeping the newest\n * {@link AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX}. Null when the owner holds no such session.\n */\n requestStop(input: {\n readonly projectId: string\n readonly id: string\n readonly ownerPrincipal: Principal\n readonly command: AgentBackgroundCommandRef\n }): Promise<AgentComputerSessionRecord | null>\n /** End the owner's session; null when it is not open. */\n release(input: {\n readonly projectId: string\n readonly id: string\n readonly ownerPrincipal: Principal\n }): Promise<AgentComputerSessionRecord | null>\n /** The owner's sessions live at `now`. */\n listLive(input: {\n readonly projectId: string\n readonly ownerPrincipal: Principal\n readonly now: Date\n }): Promise<readonly AgentComputerSessionRecord[]>\n /** Remove every session that lapsed before `now`, and return them. */\n removeLapsed(input: {\n readonly projectId: string\n readonly now: Date\n }): Promise<readonly AgentComputerSessionRecord[]>\n}\n\n// ── agent_token_rates — what each model's tokenizer measured on the project's agent runs ──────\n\n/** How many measurements a project keeps per model: its newest. */\nexport const AGENT_TOKEN_RATE_SAMPLES = 20\n\n/**\n * The band of bytes per token a measurement may show. Every tokenizer measured on agent turns\n * reads 2.1 to 4.7; a value outside is a broken measurement, and a single one would set its\n * model's rate for the whole project.\n */\nexport const AGENT_TOKEN_RATE_MIN_BYTES_PER_TOKEN = 1\nexport const AGENT_TOKEN_RATE_MAX_BYTES_PER_TOKEN = 8\n\n/**\n * One run's measurement of its model's tokenizer: the UTF-8 bytes of a request's text, as the\n * Agent's context estimator weighs them, against the text tokens the provider counted for it.\n */\nexport interface AgentTokenRateRecord {\n readonly projectId: string\n readonly providerId: string\n readonly modelId: string\n /** The agent run or workflow step that measured it: one measurement each. */\n readonly runId: string\n readonly bytes: number\n readonly tokens: number\n readonly measuredAt: Date\n}\n\n/**\n * The newest measurements of each model's bytes per token, per project. Agent runs start their\n * context estimate from them; losing them only makes the next estimates more conservative.\n */\nexport interface AgentTokenRateStore {\n /**\n * Keep a run's measurement, in place of one it recorded before, and drop the model's\n * measurements past its newest {@link AGENT_TOKEN_RATE_SAMPLES}.\n */\n record(input: AgentTokenRateRecord): Promise<void>\n /** The model's measurements, newest first: at most {@link AGENT_TOKEN_RATE_SAMPLES}. */\n listLatest(input: {\n readonly projectId: string\n readonly providerId: string\n readonly modelId: string\n }): Promise<readonly AgentTokenRateRecord[]>\n}\n\nexport interface AgentStorage {\n readonly threads: AgentThreadStore\n readonly runs: AgentRunStore\n readonly messages: AgentMessageStore\n readonly checkpoints: AgentContextCheckpointStore\n readonly memory: AgentMemoryStore\n readonly approvals: AgentApprovalStore\n readonly approvalModes: AgentApprovalModeStore\n readonly computers: AgentComputerSessionStore\n readonly tokenRates: AgentTokenRateStore\n}\n"
5
+ "import type { ActionSubject } from \"../../actions/types\"\nimport type { AgentMessage, AgentMessagePart, AgentMessageRole } from \"../../agents/message\"\nimport type { AgentReasoning } from \"../../agents/types\"\nimport type { Principal, UserPrincipal } from \"../../auth\"\nimport type { FileRef } from \"../../blob-storage/types\"\nimport type { SixbErrorCode, SixbFailure } from \"../../errors/types\"\nimport type { JsonObject, JsonValue } from \"../../json\"\nimport type {\n LanguageModelRef,\n LanguageModelTier,\n LanguageModelTierProbabilities,\n} from \"../../models\"\nimport type { ActionRunFailure, ActionRunParams } from \"../action-runs/types\"\n\n// ── agent_threads — one conversation with an agent ──────────────────────────────────────────────\n\nexport type AgentThreadStatus = \"active\" | \"archived\"\n\n/** Immutable, non-secret application input. Never store resolved env or credentials here. */\nexport type AgentThreadSandboxParams = Readonly<Record<string, JsonValue>>\n\n/** Worker-owned state, independent from the immutable application binding. */\nexport interface AgentThreadSandboxState {\n /** Exact name passed to the provider. Replacements always receive a fresh name. */\n readonly name: string\n readonly status: \"new\" | \"busy\" | \"ready\" | \"blocked\" | \"unavailable\"\n readonly sourceFingerprint?: string\n readonly initialized: boolean\n /** Durable context boundary: local files from before this reset are no longer available. */\n readonly resetAt?: string\n /** Never expires automatically: a delayed provider operation must not reach a successor. */\n readonly owner?: { readonly runId: string; readonly executionToken: string }\n}\n\nexport type TransitionAgentThreadSandboxInput = {\n readonly projectId: string\n readonly id: string\n} & (\n | {\n readonly action: \"acquire\"\n readonly runId: string\n readonly executionToken: string\n readonly name: string\n readonly sourceFingerprint: string\n }\n | {\n readonly action: \"replace\"\n readonly runId: string\n readonly executionToken: string\n readonly name: string\n readonly nextName: string\n }\n | {\n readonly action: \"settle\"\n readonly runId: string\n readonly executionToken: string\n readonly name: string\n readonly status: \"ready\" | \"blocked\" | \"unavailable\"\n readonly initialized: boolean\n }\n | {\n readonly action: \"recreate\"\n readonly expectedSandboxName: string\n readonly name: string\n }\n)\n\n/**\n * A conversation, or the thread a sub-agent works in. A sub-agent's thread is never listed, and\n * whoever reads its conversation reads it.\n */\nexport type AgentThreadKind = \"conversation\" | \"subagent\"\n\n/** Where a sub-agent's thread comes from: its conversation, the turn that spawned it, and its key. */\nexport interface AgentThreadParent {\n readonly threadId: string\n /** The turn that spawned it. Its later runs work under the turns that go on with it. */\n readonly spawnedBy: string\n readonly key: string\n}\n\n/** The computer a thread runs on, and the folder there its turns work in. */\nexport interface AgentThreadComputer {\n /** The CLI's id for the computer: a thread's turns are claimed by that computer alone. */\n readonly id: string\n /** What its owner calls the computer, such as \"Anthony's MacBook Pro\". */\n readonly name: string\n /** The absolute path its turns work in, on that computer. */\n readonly folder: string\n}\n\n/** Where a thread runs: which of its owner's computers, and the folder there. */\nexport type AgentThreadPlace = Pick<AgentThreadComputer, \"id\" | \"folder\">\n\nexport interface AgentThreadRecord {\n readonly id: string\n readonly projectId: string\n readonly kind: AgentThreadKind\n /** Set exactly on a sub-agent's thread. */\n readonly parent?: AgentThreadParent\n /** Who owns/opened the thread. Reuses the canonical auth principal (gains `agent` later for free). */\n readonly ownerPrincipal: Principal\n readonly title?: string\n readonly sandboxParams?: AgentThreadSandboxParams\n readonly sandboxState?: AgentThreadSandboxState\n /**\n * Where its turns run: on its owner's computer, which claims them, or, when absent, in the cloud.\n * A computer's thread takes turns from its owner alone.\n */\n readonly runsOn?: \"computer\"\n /**\n * Where on its owner's computers a computer's thread runs: set when it is created, and when its\n * owner moves it. Only that computer, open in that folder, claims its turns. A computer's thread\n * created before folders were kept has none until its owner moves it.\n */\n readonly computer?: AgentThreadComputer\n /**\n * When its turns last moved to where they run now, from a computer to the cloud or between\n * folders: the files earlier turns worked on are not here.\n */\n readonly movedAt?: Date\n readonly status: AgentThreadStatus\n /** Single-flight anchor: the id of the one run currently allowed to write, or `null` when idle. */\n readonly activeRunId: string | null\n readonly lastMessageAt?: Date\n readonly messageCount: number\n readonly createdAt: Date\n readonly updatedAt: Date\n}\n\nexport interface CreateAgentThreadInput {\n readonly id: string\n readonly projectId: string\n readonly ownerPrincipal: Principal\n readonly title?: string\n readonly sandboxParams?: AgentThreadSandboxParams\n readonly runsOn?: \"computer\"\n /** Where a computer's thread runs: required with `runsOn: \"computer\"`, refused without it. */\n readonly computer?: AgentThreadComputer\n readonly status?: AgentThreadStatus\n readonly createdAt?: Date\n readonly updatedAt?: Date\n}\n\n/**\n * A new thread holding a copy of another thread's finished messages. A turn still running is left\n * behind: what came from its trigger message on is not copied. Copies keep their `seq`, content,\n * author and `runId`, and get new ids. Runs are not copied, so the fork's runs, usage and cost are\n * its own; copied answers still show their run's diagnostics.\n *\n * Only the latest checkpoint the copy can use comes along, so the markers of earlier compactions\n * are not in the fork. The fork has no `lastMessageAt` until its first new message, so it sorts\n * by its creation.\n */\nexport interface ForkAgentThreadInput {\n readonly projectId: string\n /** The thread whose history is copied. */\n readonly sourceThreadId: string\n readonly id: string\n readonly ownerPrincipal: Principal\n readonly title?: string\n readonly sandboxParams?: AgentThreadSandboxParams\n /** Provider name of the fork's new sandbox; given exactly when `sandboxParams` is. */\n readonly sandboxName?: string\n /**\n * The source's shared artifacts, each id mapped to its copy's: the copied messages and summary\n * name the copies instead.\n */\n readonly artifactCopies?: Readonly<Record<string, string>>\n readonly createdAt?: Date\n}\n\n/** A conversation's sub-agent threads, oldest first. */\nexport interface ListAgentThreadChildrenInput {\n readonly projectId: string\n /** The conversation. */\n readonly parentThreadId: string\n /** Only those this turn spawned. */\n readonly parentRunId?: string\n /** At most this many, 100 by default. */\n readonly limit?: number\n readonly offset?: number\n}\n\n/** Conversations only: a sub-agent's thread is read through its conversation. */\nexport interface ListAgentThreadsInput {\n readonly projectId: string\n readonly statuses?: readonly AgentThreadStatus[]\n readonly ownerPrincipal?: Principal\n /** Only the threads this user takes part in. */\n readonly participantPrincipal?: UserPrincipal\n /** Only the threads that run on this computer, in this folder, with a turn active. */\n readonly activeOnComputer?: AgentThreadPlace\n readonly limit?: number\n readonly offset?: number\n readonly order?: \"asc\" | \"desc\"\n}\n\nexport interface ListAgentThreadsResult {\n readonly threads: readonly AgentThreadRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n// ── agent_thread_participants — the users a thread's owner added to it ─────────────────────────\n\nexport interface AgentThreadParticipantRecord {\n readonly projectId: string\n readonly threadId: string\n readonly principal: UserPrincipal\n readonly addedAt: Date\n readonly addedBy: Principal\n}\n\nexport interface AddAgentThreadParticipantsInput {\n readonly projectId: string\n readonly threadId: string\n /**\n * Distinct users, checked by the caller. Someone already taking part keeps when and by whom they\n * were first added.\n */\n readonly principals: readonly UserPrincipal[]\n readonly addedBy: Principal\n /** Refused with `participant_limit`, adding no one, when the thread would hold more. */\n readonly maxParticipants: number\n readonly addedAt?: Date\n}\n\nexport interface AssignAgentThreadComputerInput {\n readonly projectId: string\n readonly id: string\n /** Where the thread's turns run from now on. */\n readonly computer: AgentThreadComputer\n /** Its `movedAt` when this changes the computer or folder of a thread that had one. */\n readonly movedAt?: Date\n}\n\nexport interface MoveAgentThreadToCloudInput {\n readonly projectId: string\n readonly id: string\n readonly movedAt?: Date\n}\n\n/** A computer's thread, now in the cloud, and its queued turn, now the cloud's to run. */\nexport interface MoveAgentThreadToCloudResult {\n readonly thread: AgentThreadRecord\n readonly queued?: ConversationAgentRunRecord\n}\n\n/**\n * An open `sixb` on its owner's computer: while it is live, the threads that run on that computer\n * in its folder are reachable there. It ends when `sixb` closes, or lapses when it stops renewing.\n */\nexport interface AgentComputerSessionRecord {\n readonly projectId: string\n /** Chosen by the computer, once per open `sixb`; unique among its owner's sessions. */\n readonly id: string\n readonly ownerPrincipal: Principal\n readonly computer: AgentThreadComputer\n readonly expiresAt: Date\n /** Its threads' background commands, as its latest renewal reported them. */\n readonly backgroundCommands?: readonly AgentComputerBackgroundCommand[]\n /** The commands someone asked to stop: each renewal hands back those still running. */\n readonly stopRequests?: readonly AgentBackgroundCommandRef[]\n}\n\n/** How many background commands a computer session reports, and keeps stop requests for. */\nexport const AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX = 64\n\n/**\n * A background command an open `sixb` runs for one of its threads, which outlives the turn that\n * started it: the web shows how it stands between turns.\n */\nexport interface AgentComputerBackgroundCommand {\n readonly threadId: string\n /** `bg_<hex>`, as the agent's tools name it. */\n readonly id: string\n readonly command: string\n readonly status: \"running\" | \"exited\" | \"stopped\"\n readonly exitCode?: number\n /** ISO timestamps. */\n readonly startedAt: string\n readonly endedAt?: string\n}\n\n/** A background command by its start: its id comes again once `sixb` restarts. */\nexport interface AgentBackgroundCommandRef {\n readonly threadId: string\n readonly id: string\n readonly startedAt: string\n}\n\nexport interface RemoveAgentThreadParticipantInput {\n readonly projectId: string\n readonly threadId: string\n readonly principal: UserPrincipal\n}\n\nexport interface ListAgentThreadParticipantsInput {\n readonly projectId: string\n readonly threadIds: readonly string[]\n}\n\n// ── agent_runs — one loop execution (the worker job; attribution + fencing) ───────────────────\n\n/** Lifecycle shared by every durable agent execution, conversational or workflow-owned. */\nexport type AgentExecutionStatus = \"queued\" | \"running\" | \"succeeded\" | \"failed\" | \"cancelled\"\n\nexport type AgentRunStatus = AgentExecutionStatus\nexport type AgentRunKind = \"conversation\" | \"subagent\"\n\n/** Error codes an agent execution can persist and expose through its public contract. */\nexport const AGENT_RUN_FAILURE_CODES = [\n \"internal.unexpected\",\n \"runtime.cancelled\",\n \"agent.context_limit_exceeded\",\n \"agent.execution_failed\",\n \"agent.step_limit_reached\",\n \"ai.usage_limit_exceeded\",\n \"ai.usage_limit_unavailable\",\n] as const satisfies readonly [SixbErrorCode, ...SixbErrorCode[]]\n\nexport type AgentRunFailureCode = (typeof AGENT_RUN_FAILURE_CODES)[number]\n\n/**\n * Why a run ended — Sixb's provider-independent vocabulary. It includes model-loop reasons plus\n * platform-level endings such as `timeout`, `interrupted` for a turn whose worker died before\n * finishing it, `awaiting_approval` for a succeeded turn that paused on calls waiting for its\n * requester, or `awaiting_answer` for a succeeded sub-agent that paused on a question its parent\n * answers in a later turn, so reads remain typed and exhaustive. `other` and `unknown` preserve terminal state\n * when a provider adds a new reason.\n */\nexport const AGENT_RUN_FINISH_REASONS = [\n \"stop\",\n \"length\",\n \"content-filter\",\n \"tool-calls\",\n \"timeout\",\n \"interrupted\",\n \"awaiting_approval\",\n \"awaiting_answer\",\n \"error\",\n \"other\",\n \"unknown\",\n] as const\n\nexport type AgentRunFinishReason = (typeof AGENT_RUN_FINISH_REASONS)[number]\n\n/**\n * Coerce an external finish-reason string — a DB column or an SDK value — to {@link\n * AgentRunFinishReason}. An unrecognised value becomes `\"unknown\"` rather than being dropped.\n */\nexport function coerceAgentRunFinishReason(\n value: string | null | undefined\n): AgentRunFinishReason | undefined {\n if (value === null || value === undefined) {\n return undefined\n }\n return (AGENT_RUN_FINISH_REASONS as readonly string[]).includes(value)\n ? (value as AgentRunFinishReason)\n : \"unknown\"\n}\n\n/** Stable, user-facing diagnostics emitted by the platform while executing a run. */\nexport const AGENT_RUN_DIAGNOSTIC_CODES = [\"step_limit_reached\", \"output_limit_reached\"] as const\n\n/**\n * Closed on purpose, and the wire is closed with it.\n *\n * Sixb writes these codes and the generated client is what reads them, so an open union would only\n * be honest if the HTTP schema were open too — and that costs the OpenAPI enum, the client's\n * autocompletion, and the app's exhaustive `switch`. Sixb owns both ends, so a new code is a minor\n * version bump: cheap here, and a broken `switch` is better than a 500 from `z.enum`.\n */\nexport type AgentRunDiagnosticCode = (typeof AGENT_RUN_DIAGNOSTIC_CODES)[number]\nexport type AgentRunDiagnosticSeverity = \"warning\" | \"error\"\n\nexport interface AgentRunDiagnostic {\n readonly code: AgentRunDiagnosticCode\n readonly severity: AgentRunDiagnosticSeverity\n /** What the diagnostic is about: the turn as a whole. */\n readonly scope: \"run\"\n /** Sanitized, stable copy suitable for display to an end user. */\n readonly message: string\n}\n\n/**\n * Authorization state for the current queue delivery.\n *\n * `queueLeaseExpiresAt` is a persisted projection of `ClaimedQueueJob.leaseExpiresAt`, not an\n * independently managed run lease. It may only be extended from a successful queue lease renewal.\n */\nexport interface AgentRunExecution {\n readonly token: string\n readonly queueLeaseExpiresAt: Date\n}\n\ninterface AgentRunRecordBase {\n readonly id: string\n readonly projectId: string\n readonly executionId: string\n readonly status: AgentRunStatus\n readonly modelId?: string\n /** Why the run ended (our own SDK-independent enum). */\n readonly finishReason?: AgentRunFinishReason\n /** Platform diagnostics are transcript annotations, never agent-authored message content. */\n readonly diagnostics?: readonly AgentRunDiagnostic[]\n /** Portable failure snapshot when the run did not succeed. */\n readonly error?: SixbFailure<AgentRunFailureCode>\n /** Execution attempts: `0` while queued, `1` on first start, incremented on redelivery. */\n readonly attempt: number\n readonly execution?: AgentRunExecution\n /**\n * When someone asked a running run to stop. Its run token stops working at once, and its runner\n * learns of it at its next lease renewal if the broker's cancel never reached it.\n */\n readonly cancelRequestedAt?: Date\n readonly createdAt: Date\n readonly startedAt?: Date\n readonly completedAt?: Date\n}\n\nexport interface ConversationAgentRunRecord extends AgentRunRecordBase {\n readonly kind: \"conversation\"\n readonly threadId: string\n readonly triggerMessageId: string\n /** Immutable model selection captured at admission. Absent only on runs predating this field. */\n readonly spec?: ConversationAgentRunSpec\n}\n\n/** Immutable, serialisable model selection and requester settings for one conversational turn. */\nexport interface ConversationAgentRunSpec {\n readonly model: LanguageModelRef\n /** With tiers, the tier of the model the turn runs on. */\n readonly tier?: LanguageModelTier\n /**\n * How likely the decision model judged each tier, when Sixb picked the turn's model. Kept to\n * calibrate the thresholds the tier is picked from (`heavy` from 0.4, `light` from 0.8).\n */\n readonly tierProbabilities?: LanguageModelTierProbabilities\n readonly reasoning?: AgentReasoning\n /** Canonical IANA time zone of the requester. Absent uses the project time zone. */\n readonly timeZone?: string\n /** Canonical BCP 47 language of the requester. Absent uses the project locale. */\n readonly locale?: string\n /** What the turn may change without asking its requester. Absent on older runs: `auto`. */\n readonly approvalMode?: AgentApprovalMode\n /** Its thread's `runsOn` when it was asked for: a computer's turn never reaches the agent queue. */\n readonly runsOn?: \"computer\"\n}\n\n/** Immutable, serialisable child configuration captured before dispatch. */\nexport interface SubagentRunSpec {\n readonly model: LanguageModelRef\n /** With tiers, the tier of the model the child runs on. Absent on children admitted before it. */\n readonly tier?: LanguageModelTier\n readonly reasoning?: AgentReasoning\n /** Focused task supplied by the parent Agent. */\n readonly task: string\n /** At most this many steps per run, as its parent asked: the project's limit still applies. */\n readonly maxSteps?: number\n /** Project tools available when the child was admitted. Runtime tools are injected separately. */\n readonly toolNames: readonly string[]\n /** The parent turn's mode, copied when the child was admitted. Absent: `auto`. */\n readonly approvalMode?: AgentApprovalMode\n /** The parent turn's requester settings. Absent uses the project's. */\n readonly timeZone?: string\n readonly locale?: string\n /** Files the parent handed over, copied into the child's sandbox at these paths. */\n readonly files?: readonly SubagentRunFile[]\n}\n\n/** A file a parent and its child hand each other, stored once and copied into a sandbox. */\nexport interface SubagentRunFile {\n /** Relative, `/`-separated, without `.` or `..` segments. */\n readonly path: string\n readonly fileRef: FileRef\n}\n\n/** Durable child output returned to its parent by `wait`. */\nexport interface SubagentRunResult {\n /** Empty only for a child that paused on its held calls before it answered. */\n readonly text: string\n /** What the child wrote under `out/`, by path relative to it. */\n readonly files?: readonly SubagentRunFile[]\n /** Why none of what it wrote under `out/` came back, and what to do about it. */\n readonly filesError?: string\n /**\n * What its parent sent a paused child that it had not read: the run that continues it reads it\n * first.\n */\n readonly unread?: readonly { readonly id: string; readonly text: string }[]\n}\n\nexport interface SubagentRunRecord extends AgentRunRecordBase {\n readonly kind: \"subagent\"\n /** The child's own thread, which holds its task and its work. */\n readonly threadId: string\n /** The message of its thread that started the run. */\n readonly triggerMessageId: string\n /** The conversation turn the child runs under: its mode and cancellation. */\n readonly parentRunId: string\n /** Stable parent-selected key that makes repeated tool execution idempotent. */\n readonly spawnKey: string\n readonly spec: SubagentRunSpec\n readonly result?: SubagentRunResult\n}\n\nexport type AgentRunRecord = ConversationAgentRunRecord | SubagentRunRecord\n\nexport interface CreateAgentRunInput {\n readonly id: string\n readonly projectId: string\n readonly executionId: string\n readonly threadId: string\n readonly triggerMessageId: string\n readonly spec: ConversationAgentRunSpec\n readonly createdAt?: Date\n}\n\nexport interface CreateSubagentRunInput {\n readonly id: string\n readonly projectId: string\n readonly executionId: string\n readonly parentRunId: string\n /** Current parent delivery token. New children are admitted only while that delivery owns it. */\n readonly parentExecutionToken: string\n readonly spawnKey: string\n readonly spec: SubagentRunSpec\n /**\n * The child's thread. Its first run creates it, owned by the conversation's owner; a later run\n * goes into it, and is refused while another run of the thread is active.\n */\n readonly thread: { readonly id: string; readonly create: boolean }\n /** The user message that starts the run, appended to the child's thread with the run's id. */\n readonly trigger: Pick<AppendAgentMessageInput, \"id\" | \"parts\" | \"metadata\">\n /** Internal safety bound enforced atomically across worker processes. */\n readonly maxActiveChildren: number\n readonly createdAt?: Date\n}\n\nexport interface StartAgentRunInput {\n readonly id: string\n readonly projectId: string\n readonly modelId?: string\n readonly execution: AgentRunExecution\n readonly startedAt?: Date\n /**\n * Start it only as a computer's turn, there and in that folder: one whose thread moved meanwhile\n * is refused with `invalid_state`, so it never starts where its thread no longer runs.\n */\n readonly onComputer?: AgentThreadPlace\n}\n\nexport interface FinishQueuedAgentRunInput {\n readonly id: string\n readonly projectId: string\n readonly status: \"failed\" | \"cancelled\"\n readonly error?: SixbFailure<AgentRunFailureCode>\n readonly completedAt?: Date\n}\n\nexport interface ReclaimAgentRunInput {\n readonly id: string\n readonly projectId: string\n readonly execution: AgentRunExecution\n /**\n * Take the run over only if the lease last recorded on it ran out by then, checked in the same\n * write: a renewal that lands first keeps it its runner's. Otherwise `invalid_state`.\n */\n readonly ifLapsedBy?: Date\n}\n\nexport interface ConfirmAgentRunExecutionOwnershipInput {\n readonly id: string\n readonly projectId: string\n readonly executionToken: string\n /** Exact expiration returned by the queue claim or its latest successful renewal. */\n readonly queueLeaseExpiresAt: Date\n}\n\nexport interface RequestAgentRunCancelInput {\n readonly id: string\n readonly projectId: string\n readonly at?: Date\n}\n\nexport type FinishAgentRunInput =\n | {\n readonly id: string\n readonly projectId: string\n readonly executionToken: string\n readonly status: \"succeeded\"\n readonly modelId?: string\n readonly finishReason?: AgentRunFinishReason\n readonly diagnostics?: readonly AgentRunDiagnostic[]\n readonly result?: SubagentRunResult\n readonly completedAt?: Date\n }\n | {\n readonly id: string\n readonly projectId: string\n readonly executionToken: string\n readonly status: \"failed\" | \"cancelled\"\n readonly modelId?: string\n /** Only a succeeded run pauses. */\n readonly finishReason?: Exclude<AgentRunFinishReason, \"awaiting_approval\" | \"awaiting_answer\">\n readonly diagnostics?: readonly AgentRunDiagnostic[]\n readonly error?: SixbFailure<AgentRunFailureCode>\n readonly completedAt?: Date\n }\n\nexport interface ListAgentRunsInput {\n readonly projectId: string\n readonly kinds?: readonly AgentRunKind[]\n readonly threadId?: string\n readonly parentRunId?: string\n readonly statuses?: readonly AgentRunStatus[]\n /** Effective start time; runs that never started use `createdAt`. */\n readonly startedAfter?: Date\n /** Effective start time; runs that never started use `createdAt`. */\n readonly startedBefore?: Date\n readonly limit?: number\n readonly offset?: number\n readonly order?: \"asc\" | \"desc\"\n /** Leave out the turns that wait for a computer: only a worker's to run. */\n readonly excludeComputerTurns?: boolean\n}\n\nexport interface ListThreadSubagentsInput {\n readonly projectId: string\n /** The conversation whose turns spawned them. */\n readonly threadId: string\n readonly spawnKey?: string\n readonly finishReason?: AgentRunFinishReason\n /** At most this many, 100 by default. */\n readonly limit?: number\n}\n\nexport interface ListAgentRunsResult {\n readonly runs: readonly AgentRunRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n// ── agent_messages — one message (assistant messages inserted only once finalized) ─────────────\n\nexport type { AgentMessageRole }\n\nexport interface AgentMessageRecord {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n /**\n * The run that produced this message; `null` for user-authored messages. In a sub-agent's thread\n * every message has one, its trigger too, so a run's messages are deleted whole. A message copied\n * by a fork keeps the run that produced it, which belongs to the thread it was copied from.\n */\n readonly runId: string | null\n readonly role: AgentMessageRole\n /** Principal that authored this persisted message: caller for user messages, agent identity later for assistant messages. */\n readonly authorPrincipal?: Principal\n /** Monotonic per thread, assigned by the store. */\n readonly seq: number\n /** Structured message content — text / reasoning / step boundaries / tool calls. */\n readonly parts: readonly AgentMessagePart[]\n /** Message-level metadata (mirrors `UIMessage.metadata`). */\n readonly metadata?: JsonValue\n /** Versions the `parts` shape so it can be migrated; stamped from `AGENT_MESSAGE_CONTENT_VERSION`. */\n readonly contentVersion: number\n readonly createdAt: Date\n readonly completedAt?: Date\n}\n\n/** Append a message: a {@link AgentMessage} (role + parts + metadata) plus its storage identity. */\nexport interface AppendAgentMessageInput extends AgentMessage {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n readonly runId: string | null\n readonly authorPrincipal?: Principal\n readonly createdAt?: Date\n readonly completedAt?: Date\n}\n\nexport interface DeleteAgentMessagesByRunInput {\n readonly projectId: string\n readonly threadId: string\n readonly runId: string\n /**\n * The run that deletes them, when one does: refused with `execution_lost` unless it still runs\n * under this token, checked in the same transaction as the delete.\n */\n readonly fence?: { readonly runId: string; readonly executionToken: string }\n}\n\nexport interface ListAgentMessagesInput {\n readonly projectId: string\n readonly threadId: string\n /** Return only messages whose per-thread sequence is greater than this retained boundary. */\n readonly afterSeq?: number\n readonly roles?: readonly AgentMessageRole[]\n readonly limit?: number\n readonly offset?: number\n readonly order?: \"asc\" | \"desc\"\n}\n\nexport interface ListAgentMessagesResult {\n readonly messages: readonly AgentMessageRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n// ── agent_context_checkpoints — append-only model-context boundaries ──────────────────────────\n\nexport type AgentContextCheckpointReason = \"threshold\" | \"overflow\"\n\n/**\n * A durable summary boundary used only when projecting a thread into model context.\n *\n * Checkpoints never replace or mutate transcript messages. Normal thread reads remain authoritative\n * and complete; the worker reads the latest checkpoint and only the retained message tail.\n */\nexport interface AgentContextCheckpointRecord {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n /** A fork's copy keeps the run that wrote the summary, in the thread it was copied from. */\n readonly createdByRunId: string\n readonly previousCheckpointId?: string\n readonly reason: AgentContextCheckpointReason\n readonly summary: string\n readonly summaryFormatVersion: 1\n readonly summarizedThroughSeq: number\n readonly observedHeadSeq: number\n readonly estimatedInputTokensBefore: number\n readonly estimatedInputTokensAfter: number\n readonly summaryModelId: string\n readonly createdAt: Date\n}\n\nexport interface CreateAgentContextCheckpointInput {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n readonly createdByRunId: string\n /** Compare-and-swap anchor. `null` means the thread must not have a prior checkpoint. */\n readonly expectedPreviousCheckpointId: string | null\n /** Compare-and-swap anchor for the complete transcript observed by the summarizer. */\n readonly expectedHeadSeq: number\n /** Current delivery token for `createdByRunId`; stale redeliveries must not write. */\n readonly executionToken: string\n readonly reason: AgentContextCheckpointReason\n readonly summary: string\n readonly summaryFormatVersion: 1\n readonly summarizedThroughSeq: number\n readonly observedHeadSeq: number\n readonly estimatedInputTokensBefore: number\n readonly estimatedInputTokensAfter: number\n readonly summaryModelId: string\n readonly createdAt?: Date\n}\n\n// ── Store ───────────────────────────────────────────────────────────────────────────────────────\n\nexport interface AgentThreadStore {\n /** Atomic run-fenced transition, or explicit idle-thread recreation. */\n transitionSandbox(input: TransitionAgentThreadSandboxInput): Promise<AgentThreadSandboxState>\n create(input: CreateAgentThreadInput): Promise<AgentThreadRecord>\n /**\n * Create a thread holding a copy of another's finished history, in one transaction. The source's\n * sub-agent threads are not copied, and a sub-agent's thread is refused.\n */\n fork(input: ForkAgentThreadInput): Promise<AgentThreadRecord>\n getById(params: { projectId: string; id: string }): Promise<AgentThreadRecord | null>\n /** The threads found, in first-occurrence input order; a missing one is omitted. */\n getByIds(params: {\n readonly projectId: string\n readonly ids: readonly string[]\n }): Promise<readonly AgentThreadRecord[]>\n list(input: ListAgentThreadsInput): Promise<ListAgentThreadsResult>\n /** The sub-agents' threads of a conversation, by creation and id, all of them or one turn's. */\n listChildren(input: ListAgentThreadChildrenInput): Promise<readonly AgentThreadRecord[]>\n /**\n * Add users atomically and return every participant of the thread afterwards. A sub-agent's\n * thread has none: its readers are its conversation's.\n */\n addParticipants(\n input: AddAgentThreadParticipantsInput\n ): Promise<readonly AgentThreadParticipantRecord[]>\n /** Whether the user took part until now. */\n removeParticipant(input: RemoveAgentThreadParticipantInput): Promise<boolean>\n /**\n * Move a computer's thread to another computer or folder, and return the thread after. A cloud\n * thread runs on none, and is refused.\n */\n assignComputer(input: AssignAgentThreadComputerInput): Promise<AgentThreadRecord>\n /**\n * Move a computer's thread to the cloud, in one transaction with its queued turn, which the cloud\n * runs instead. Refused with `active_run_exists` while a turn runs on the computer, and\n * `invalid_input` for a thread already in the cloud.\n */\n moveToCloud(input: MoveAgentThreadToCloudInput): Promise<MoveAgentThreadToCloudResult>\n /** The participants of these threads, oldest first, then by user id and thread id. */\n listParticipants(\n input: ListAgentThreadParticipantsInput\n ): Promise<readonly AgentThreadParticipantRecord[]>\n}\n\nexport interface AgentRunStore {\n /**\n * Persist a queued turn and atomically claim the thread's single-flight slot. A sub-agent's\n * thread takes only child runs.\n */\n create(input: CreateAgentRunInput): Promise<ConversationAgentRunRecord>\n /**\n * Persist or replay one idempotent child run while atomically enforcing parent fan-out. In one\n * transaction it creates the child's thread or takes it (single-flight, as a conversation), then\n * appends the trigger and the run.\n */\n createSubagent(input: CreateSubagentRunInput): Promise<SubagentRunRecord>\n /** Transition a queued run to running and install the first delivery's execution token. */\n start(input: StartAgentRunInput): Promise<AgentRunRecord>\n /** Finish a queued run before execution and release the thread's single-flight slot. */\n finishQueued(input: FinishQueuedAgentRunInput): Promise<AgentRunRecord>\n /** Rotate the execution token for a redelivered running job (`attempt++`). */\n reclaim(input: ReclaimAgentRunInput): Promise<AgentRunRecord>\n /**\n * Project the queue's latest confirmed ownership expiration onto the current execution.\n * Implementations must fence by token and must never move the expiration backwards.\n */\n confirmExecutionOwnership(input: ConfirmAgentRunExecutionOwnershipInput): Promise<AgentRunRecord>\n /**\n * Record that a running run was asked to stop, keeping the first time it was. A run in any other\n * state is returned as it is: a queued one is cancelled with `finishQueued`.\n */\n requestCancel(input: RequestAgentRunCancelInput): Promise<AgentRunRecord>\n /**\n * Finalize a run and release the thread's `activeRunId`. `finishReason: \"awaiting_approval\"`\n * needs a call the run holds (see `approvals.holdsRun`). A turn that ends any other way cancels\n * its pending approvals and stops resuming on the rest; a child that fails or is cancelled\n * cancels its own pending ones.\n */\n finish(input: FinishAgentRunInput): Promise<AgentRunRecord>\n getById(params: { projectId: string; id: string }): Promise<AgentRunRecord | null>\n getByIds(params: {\n projectId: string\n ids: readonly string[]\n }): Promise<readonly AgentRunRecord[]>\n /**\n * The children of a conversation's turns, the latest turn's first, by its effective start, and\n * within a turn the latest admitted first. Read by key (one per turn) or by finish reason.\n */\n listThreadSubagents(input: ListThreadSubagentsInput): Promise<readonly SubagentRunRecord[]>\n list(input: ListAgentRunsInput): Promise<ListAgentRunsResult>\n}\n\nexport interface AgentMessageStore {\n /** Insert a message (its `parts` are the canonical content) and bump thread stats. */\n append(input: AppendAgentMessageInput): Promise<AgentMessageRecord>\n /** Delete every message produced by one run and repair the thread's message stats. */\n deleteByRunId(input: DeleteAgentMessagesByRunInput): Promise<number>\n getById(params: { projectId: string; id: string }): Promise<AgentMessageRecord | null>\n list(input: ListAgentMessagesInput): Promise<ListAgentMessagesResult>\n}\n\nexport interface AgentContextCheckpointStore {\n /**\n * Append one checkpoint after atomically validating run ownership and both transcript anchors.\n * Repeating the same payload for the same creating run is idempotent.\n */\n create(input: CreateAgentContextCheckpointInput): Promise<AgentContextCheckpointRecord>\n /** The thread's checkpoints created by the requested runs, in first-occurrence input order. */\n getByRunIds(input: {\n readonly projectId: string\n readonly threadId: string\n readonly runIds: readonly string[]\n }): Promise<readonly AgentContextCheckpointRecord[]>\n getLatest(input: {\n readonly projectId: string\n readonly threadId: string\n }): Promise<AgentContextCheckpointRecord | null>\n}\n\n// ── agent_approvals — calls of the Agent that wait for whoever asked ───────────────────────────\n\n/**\n * What the Agent may change without asking its requester: `manual` asks for every action and\n * workflow, `accept-edits` runs the actions that only change Sixb, `auto` runs everything.\n */\nexport const AGENT_APPROVAL_MODES = [\"manual\", \"accept-edits\", \"auto\"] as const\n\nexport type AgentApprovalMode = (typeof AGENT_APPROVAL_MODES)[number]\n\n/** The modes that hold some calls: the one that held a call is recorded on its approval. */\nexport const AGENT_HOLDING_APPROVAL_MODES = [\n \"manual\",\n \"accept-edits\",\n] as const satisfies readonly AgentApprovalMode[]\n\nexport type AgentHoldingApprovalMode = (typeof AGENT_HOLDING_APPROVAL_MODES)[number]\n\nexport const AGENT_APPROVAL_STATUSES = [\n \"pending\",\n \"approved\",\n \"denied\",\n \"cancelled\",\n \"superseded\",\n \"expired\",\n] as const\n\nexport type AgentApprovalStatus = (typeof AGENT_APPROVAL_STATUSES)[number]\n\n/** The statuses a pending approval is settled to without a decision. */\nexport type AgentApprovalSettledStatus = Extract<\n AgentApprovalStatus,\n \"cancelled\" | \"superseded\" | \"expired\"\n>\n\n/**\n * The held call, as it runs once approved. An action's params are normalized: what the user\n * approves is exactly what runs. Its run id is the one the Agent named, so a repeated request finds\n * the same approval and the same run.\n */\nexport type AgentApprovalCall =\n | {\n readonly kind: \"action\"\n readonly actionId: string\n readonly subject: ActionSubject\n readonly params: ActionRunParams\n readonly actionRunId: string\n /** `external` when the action has a writeback or effects: it reaches beyond Sixb. */\n readonly effect: \"ontology\" | \"external\"\n }\n | {\n readonly kind: \"workflow\"\n readonly workflowId: string\n readonly input: JsonObject\n readonly workflowRunId: string\n }\n\n/** What running an approved call gave. */\nexport type AgentApprovalOutcome =\n | {\n readonly kind: \"action-run\"\n readonly runId: string\n readonly status: \"succeeded\" | \"failed\"\n readonly error?: ActionRunFailure\n }\n | { readonly kind: \"workflow-run\"; readonly runId: string; readonly queuedAt: string }\n /** The call was refused when it ran, for example because its requester lost a grant. */\n | { readonly kind: \"error\"; readonly error: SixbFailure }\n\nexport interface AgentApprovalRecord {\n readonly id: string\n readonly projectId: string\n readonly threadId: string\n /** The conversation turn the call belongs to. */\n readonly runId: string\n /** The run that made the call: the turn itself, or one of its children. */\n readonly callerRunId: string\n /** Who asked for the turn: the only one who decides, as the call runs with their rights. */\n readonly requestedBy: Principal\n /** The mode that held the call. */\n readonly mode: AgentHoldingApprovalMode\n /** The call's run id, unique among a thread's pending, approved and denied approvals. */\n readonly callKey: string\n readonly call: AgentApprovalCall\n readonly status: AgentApprovalStatus\n readonly createdAt: Date\n readonly expiresAt: Date\n readonly decidedAt?: Date\n readonly decidedBy?: Principal\n /** Set once an approved call ran. */\n readonly outcome?: AgentApprovalOutcome\n /** The user message that told the model how the approval ended. */\n readonly reportedInMessageId?: string\n /** \"Always allow\": the mode its requester raised the turn's calls to when deciding this one. */\n readonly raisedMode?: AgentApprovalMode\n /**\n * The turn will not resume for it: stopped, its requester left, or another of its calls was set\n * aside. The thread's next message still reports it.\n */\n readonly turnStoppedAt?: Date\n /** When a process last took the approved call to run it; a stale claim can be taken again. */\n readonly executionClaimedAt?: Date\n}\n\nexport interface RequestAgentApprovalInput {\n readonly id: string\n readonly projectId: string\n readonly runId: string\n readonly callerRunId: string\n /** The caller run's current delivery token: a stale delivery holds nothing. */\n readonly executionToken: string\n readonly requestedBy: Principal\n readonly mode: AgentHoldingApprovalMode\n readonly call: AgentApprovalCall\n readonly createdAt?: Date\n readonly expiresAt: Date\n}\n\nexport interface RequestAgentApprovalResult {\n readonly approval: AgentApprovalRecord\n /** `false` when a pending, approved or denied approval of the thread had the same call key. */\n readonly created: boolean\n}\n\nexport interface DecideAgentApprovalInput {\n readonly projectId: string\n readonly id: string\n readonly decision: \"approved\" | \"denied\"\n readonly decidedBy: Principal\n readonly decidedAt?: Date\n /** With `approved`: \"Always allow\" raised the turn's mode to this one. */\n readonly raisedMode?: AgentApprovalMode\n}\n\nexport interface DecideAgentApprovalResult {\n /** The approval afterwards: `expired` when its time ran out before this decision. */\n readonly approval: AgentApprovalRecord\n /** Whether this call moved it out of `pending` with the decision. */\n readonly decided: boolean\n}\n\nexport interface SettleAgentApprovalsInput {\n readonly projectId: string\n readonly threadId: string\n readonly status: AgentApprovalSettledStatus\n}\n\n/** Stop a thread's turn, or a requester's turns there, from resuming on their calls. */\nexport interface StopAgentApprovalsInput {\n readonly projectId: string\n readonly threadId: string\n /** Only the calls of this conversation turn. */\n readonly runId?: string\n /** Only the calls this principal asked for. */\n readonly requestedBy?: Principal\n readonly stoppedAt?: Date\n}\n\nexport interface StopAgentApprovalsResult {\n /** The pending approvals it cancelled. */\n readonly cancelled: readonly AgentApprovalRecord[]\n /** How many unreported approvals it stopped, the cancelled ones included. */\n readonly stopped: number\n}\n\n/** Where a keyset listing resumes: after this approval, in the order approvals are listed. */\nexport interface AgentApprovalCursor {\n readonly createdAt: Date\n readonly id: string\n}\n\nexport interface MarkAgentApprovalsReportedInput {\n readonly projectId: string\n readonly threadId: string\n readonly ids: readonly string[]\n readonly messageId: string\n /** A resume: an approval whose turn was stopped is not marked. */\n readonly resuming?: boolean\n}\n\nexport interface ListAgentApprovalsInput {\n readonly projectId: string\n readonly threadId?: string\n readonly runId?: string\n readonly requestedBy?: Principal\n readonly statuses?: readonly AgentApprovalStatus[]\n /** `false`: only the approvals no message reported yet. */\n readonly reported?: boolean\n readonly limit?: number\n readonly offset?: number\n}\n\nexport interface ListAgentApprovalsResult {\n /** Oldest first. */\n readonly approvals: readonly AgentApprovalRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n/**\n * Held calls and their decisions. `runs.finish` settles a run's approvals in its own transaction:\n * a turn that pauses keeps them for their decision, any other ending cancels its pending ones.\n */\nexport interface AgentApprovalStore {\n /**\n * Fenced like a checkpoint: the caller run is running with `executionToken`, and is the\n * conversation turn `runId` or one of its children. Returns the thread's pending, approved or\n * denied approval with the same call key when there is one, and creates one otherwise.\n */\n request(input: RequestAgentApprovalInput): Promise<RequestAgentApprovalResult>\n /** Compare-and-swap from `pending`; `null` when no such approval exists. */\n decide(input: DecideAgentApprovalInput): Promise<DecideAgentApprovalResult | null>\n /** Record what an approved call gave, once: an approval with an outcome is returned unchanged. */\n recordOutcome(input: {\n readonly projectId: string\n readonly id: string\n readonly outcome: AgentApprovalOutcome\n }): Promise<AgentApprovalRecord>\n /** Settle the thread's pending approvals, and return the ones it settled. */\n settle(input: SettleAgentApprovalsInput): Promise<readonly AgentApprovalRecord[]>\n /** Expire the project's pending approvals whose time ran out by `now`, and return them. */\n expireDue(input: {\n readonly projectId: string\n readonly now: Date\n readonly limit?: number\n }): Promise<readonly AgentApprovalRecord[]>\n /**\n * Cancel the matching pending approvals and mark every matching one no message reported yet as\n * stopped: their turn never resumes on them.\n */\n stop(input: StopAgentApprovalsInput): Promise<StopAgentApprovalsResult>\n /** Mark the ones no message reported yet, and return their ids. */\n markReported(input: MarkAgentApprovalsReportedInput): Promise<readonly string[]>\n /**\n * Whether the run holds a call: one of its approvals, or one it made for its turn, pending, or\n * decided and not reported yet. `runs.finish` checks the same before `awaiting_approval`.\n */\n holdsRun(input: { readonly projectId: string; readonly runId: string }): Promise<boolean>\n /**\n * Take an approved call without an outcome to run it, unless another process took it after\n * `staleBefore`; its decision is its first claim. `null` when it is not there to take.\n */\n claimExecution(input: {\n readonly projectId: string\n readonly id: string\n readonly claimedAt: Date\n readonly staleBefore: Date\n }): Promise<AgentApprovalRecord | null>\n /**\n * What a repair pass works on, oldest first: approved calls without an outcome whose claim is\n * older than `claimableBefore`, and decided calls no message reported whose turn is not stopped.\n */\n listRepairable(input: {\n readonly projectId: string\n readonly claimableBefore: Date\n readonly after?: AgentApprovalCursor\n readonly limit: number\n }): Promise<readonly AgentApprovalRecord[]>\n getById(params: {\n readonly projectId: string\n readonly id: string\n }): Promise<AgentApprovalRecord | null>\n list(input: ListAgentApprovalsInput): Promise<ListAgentApprovalsResult>\n}\n\n/** Each user's approval mode: a default, and their own choice in each thread. */\nexport interface AgentApprovalModeStore {\n getDefault(input: {\n readonly projectId: string\n readonly principal: Principal\n }): Promise<AgentApprovalMode | null>\n setDefault(input: {\n readonly projectId: string\n readonly principal: Principal\n readonly mode: AgentApprovalMode\n readonly updatedAt?: Date\n }): Promise<void>\n getForThread(input: {\n readonly projectId: string\n readonly threadId: string\n readonly principal: Principal\n }): Promise<AgentApprovalMode | null>\n /**\n * `null` clears the choice: the user's turns in the thread follow their default again. Throws\n * `thread_not_found` when the thread does not exist.\n */\n setForThread(input: {\n readonly projectId: string\n readonly threadId: string\n readonly principal: Principal\n readonly mode: AgentApprovalMode | null\n readonly updatedAt?: Date\n }): Promise<void>\n}\n\n// ── Memory ──────────────────────────────────────────────────────────────────────────────────────\n\n/** One file of a memory repo, at its path from the repo root. */\nexport interface AgentMemoryFile {\n readonly path: string\n readonly contents: string\n}\n\n/** A memory repo as of its latest revision. */\nexport interface AgentMemoryRepoRecord {\n /** 0 before the first save. */\n readonly revision: number\n /** Ordered by path. */\n readonly files: readonly AgentMemoryFile[]\n}\n\n/** One change of a save: the file's new contents, or `null` to delete it. */\nexport interface AgentMemoryChange {\n readonly path: string\n readonly contents: string | null\n}\n\nexport interface SaveAgentMemoryInput {\n readonly projectId: string\n /** `user:<userId>` or `project`. */\n readonly repoId: string\n /** The revision the caller loaded. */\n readonly baseRevision: number\n readonly message: string\n readonly author: Principal\n /** The conversation the save came from, `/agents/<threadId>`. */\n readonly source?: string\n readonly changes: readonly AgentMemoryChange[]\n readonly createdAt?: Date\n}\n\nexport type SaveAgentMemoryResult =\n | { readonly saved: true; readonly revision: number }\n | {\n readonly saved: false\n /** The repo's latest revision. */\n readonly revision: number\n /** Files in `changes` that another save changed after `baseRevision`, as they are now. */\n readonly conflicts: readonly AgentMemoryChange[]\n }\n\n/** One save: who made it, why, and which paths it wrote. A revision never changes. */\nexport interface AgentMemoryRevisionRecord {\n readonly revision: number\n readonly message: string\n readonly author: Principal\n readonly source?: string\n /** Ordered by path. */\n readonly changes: readonly { readonly path: string; readonly deleted: boolean }[]\n readonly createdAt: Date\n}\n\nexport interface ListAgentMemoryRevisionsInput {\n readonly projectId: string\n readonly repoId: string\n readonly limit?: number\n readonly offset?: number\n}\n\nexport interface ListAgentMemoryRevisionsResult {\n /** Newest first. */\n readonly revisions: readonly AgentMemoryRevisionRecord[]\n readonly hasMore: boolean\n readonly total: number\n}\n\n/**\n * Memory repos as append-only revisions: a save inserts one revision and the files it wrote, and\n * never updates a row. Paths, sizes and who may save are decided in Core before a call reaches\n * storage.\n */\nexport interface AgentMemoryStore {\n /**\n * The repo at its latest revision, or with `asOf` at the latest revision saved by then, and with\n * `revision` at the latest up to that one: revision 0 and no files when none was. File versions\n * pruned from the history are missing from it.\n */\n get(input: {\n readonly projectId: string\n readonly repoId: string\n readonly asOf?: Date\n readonly revision?: number\n }): Promise<AgentMemoryRepoRecord>\n /**\n * In one transaction: reports a conflict when a path in `changes` was written after\n * `baseRevision`, or when the repo is behind `baseRevision` because it was deleted; otherwise\n * stores the next revision. The same transaction removes file versions older than\n * {@link AGENT_MEMORY_HISTORY_DAYS} days that are not their path's latest.\n */\n save(input: SaveAgentMemoryInput): Promise<SaveAgentMemoryResult>\n listRevisions(input: ListAgentMemoryRevisionsInput): Promise<ListAgentMemoryRevisionsResult>\n /** Deletes the repo with its history. */\n delete(input: { readonly projectId: string; readonly repoId: string }): Promise<void>\n}\n\n/** How long a file version that is not its path's latest stays in a repo's history. */\nexport const AGENT_MEMORY_HISTORY_DAYS = 90\n\n/** Each open `sixb` on its owner's computers, as a lease it renews. */\nexport interface AgentComputerSessionStore {\n /**\n * Open the session, or renew it until `expiresAt`; its computer, folder and background commands\n * are kept as given, and its stop requests as they are.\n */\n hold(input: Omit<AgentComputerSessionRecord, \"stopRequests\">): Promise<void>\n /**\n * Record that someone asked to stop one of its commands, once, keeping the newest\n * {@link AGENT_COMPUTER_BACKGROUND_COMMANDS_MAX}. Null when the owner holds no such session.\n */\n requestStop(input: {\n readonly projectId: string\n readonly id: string\n readonly ownerPrincipal: Principal\n readonly command: AgentBackgroundCommandRef\n }): Promise<AgentComputerSessionRecord | null>\n /** End the owner's session; null when it is not open. */\n release(input: {\n readonly projectId: string\n readonly id: string\n readonly ownerPrincipal: Principal\n }): Promise<AgentComputerSessionRecord | null>\n /** The owner's sessions live at `now`. */\n listLive(input: {\n readonly projectId: string\n readonly ownerPrincipal: Principal\n readonly now: Date\n }): Promise<readonly AgentComputerSessionRecord[]>\n /** Remove every session that lapsed before `now`, and return them. */\n removeLapsed(input: {\n readonly projectId: string\n readonly now: Date\n }): Promise<readonly AgentComputerSessionRecord[]>\n}\n\n// ── agent_token_rates — what each model's tokenizer measured on the project's agent runs ──────\n\n/** How many measurements a project keeps per model: its newest. */\nexport const AGENT_TOKEN_RATE_SAMPLES = 20\n\n/**\n * The band of bytes per token a measurement may show. Every tokenizer measured on agent turns\n * reads 2.1 to 4.7; a value outside is a broken measurement, and a single one would set its\n * model's rate for the whole project.\n */\nexport const AGENT_TOKEN_RATE_MIN_BYTES_PER_TOKEN = 1\nexport const AGENT_TOKEN_RATE_MAX_BYTES_PER_TOKEN = 8\n\n/**\n * One run's measurement of its model's tokenizer: the UTF-8 bytes of a request's text, as the\n * Agent's context estimator weighs them, against the text tokens the provider counted for it.\n */\nexport interface AgentTokenRateRecord {\n readonly projectId: string\n readonly providerId: string\n readonly modelId: string\n /** The agent run or workflow step that measured it: one measurement each. */\n readonly runId: string\n readonly bytes: number\n readonly tokens: number\n readonly measuredAt: Date\n}\n\n/**\n * The newest measurements of each model's bytes per token, per project. Agent runs start their\n * context estimate from them; losing them only makes the next estimates more conservative.\n */\nexport interface AgentTokenRateStore {\n /**\n * Keep a run's measurement, in place of one it recorded before, and drop the model's\n * measurements past its newest {@link AGENT_TOKEN_RATE_SAMPLES}.\n */\n record(input: AgentTokenRateRecord): Promise<void>\n /** The model's measurements, newest first: at most {@link AGENT_TOKEN_RATE_SAMPLES}. */\n listLatest(input: {\n readonly projectId: string\n readonly providerId: string\n readonly modelId: string\n }): Promise<readonly AgentTokenRateRecord[]>\n}\n\nexport interface AgentStorage {\n readonly threads: AgentThreadStore\n readonly runs: AgentRunStore\n readonly messages: AgentMessageStore\n readonly checkpoints: AgentContextCheckpointStore\n readonly memory: AgentMemoryStore\n readonly approvals: AgentApprovalStore\n readonly approvalModes: AgentApprovalModeStore\n readonly computers: AgentComputerSessionStore\n readonly tokenRates: AgentTokenRateStore\n}\n"
6
6
  ],
7
7
  "mappings": ";;AA2QO,IAAM,0CAAyC;AA6C/C,IAAM,2BAA0B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAYO,IAAM,4BAA2B;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQO,SAAS,2BAA0B,CACxC,OACkC;AAAA,EAClC,IAAI,UAAU,QAAQ,UAAU,WAAW;AAAA,IACzC;AAAA,EACF;AAAA,EACA,OAAQ,0BAA+C,SAAS,KAAK,IAChE,QACD;AAAA;AAIC,IAAM,8BAA6B,CAAC,sBAAsB,sBAAsB;AA8gBhF,IAAM,wBAAuB,CAAC,UAAU,gBAAgB,MAAM;AAK9D,IAAM,gCAA+B;AAAA,EAC1C;AAAA,EACA;AACF;AAIO,IAAM,2BAA0B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAmXO,IAAM,4BAA4B;AAyClC,IAAM,4BAA2B;AAOjC,IAAM,wCAAuC;AAC7C,IAAM,uCAAuC;",
8
8
  "debugId": "FF93B7FDB906D87364756E2164756E21",
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-qttqe1ah.js";
23
23
  import {
24
24
  AGENT_REASONING_LEVELS2
25
- } from "./chunk-7z5rkf0m.js";
25
+ } from "./chunk-t0s7b3d1.js";
26
26
  import {
27
27
  WorkflowDefinitionError2,
28
28
  assertNonEmpty,
@@ -30,10 +30,10 @@ import {
30
30
  isAgentStepDefinition2,
31
31
  isInterventionDefinition2,
32
32
  assertAgentStepSandbox
33
- } from "./chunk-e9w4mgdh.js";
33
+ } from "./chunk-rtm1jq00.js";
34
34
  import {
35
35
  isAgentToolDefinition2
36
- } from "./chunk-z0t4p2sk.js";
36
+ } from "./chunk-gxwy4c3s.js";
37
37
  import {
38
38
  isScheduleDefinition2
39
39
  } from "./chunk-t24yktqr.js";
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-frsz8wxd.js";
17
17
  import {
18
18
  isWorkflowDefinition2
19
- } from "./chunk-e9w4mgdh.js";
19
+ } from "./chunk-rtm1jq00.js";
20
20
  import {
21
21
  isDatasetDefinition2
22
22
  } from "./chunk-wx7smkn2.js";
@@ -34,7 +34,7 @@ import {
34
34
  } from "./chunk-t24yktqr.js";
35
35
  import {
36
36
  isSyncDefinition2
37
- } from "./chunk-hkaa807g.js";
37
+ } from "./chunk-td26wjr5.js";
38
38
  import {
39
39
  compileShareAccessPlan
40
40
  } from "./chunk-n68vz95m.js";
@@ -52,10 +52,10 @@ import {
52
52
  import {
53
53
  isMigrationCapableStorage2,
54
54
  checkStorageSchema2
55
- } from "./chunk-2by73sm2.js";
55
+ } from "./chunk-w1wq7gfr.js";
56
56
  import {
57
57
  createAuthorizedObjectReader
58
- } from "./chunk-26qet7wh.js";
58
+ } from "./chunk-msyevpp3.js";
59
59
  import {
60
60
  ActionRegistry2,
61
61
  createAgentApprovalExecutor,
@@ -71,7 +71,7 @@ import {
71
71
  createBoundSixb,
72
72
  ActionRunExecutor,
73
73
  registerActionRunExecutor
74
- } from "./chunk-e9w4mgdh.js";
74
+ } from "./chunk-rtm1jq00.js";
75
75
  import {
76
76
  attachSixbErrorReporter2,
77
77
  shareSixbErrorReporter2
@@ -81,7 +81,7 @@ import {
81
81
  createOntologyMutationRuntime2,
82
82
  decodeActivityConnectionsCursor,
83
83
  ModelExecutionSession
84
- } from "./chunk-6gtxshcc.js";
84
+ } from "./chunk-vepea5c3.js";
85
85
  import {
86
86
  registerConnectorConnectionCallbackProcess
87
87
  } from "./chunk-5a4a52tq.js";
@@ -104,7 +104,7 @@ import {
104
104
  import {
105
105
  ProjectionRegistry2,
106
106
  createOntologyMaterializer2
107
- } from "./chunk-4j0sagwv.js";
107
+ } from "./chunk-evj5jxz3.js";
108
108
  import {
109
109
  LoggingService2
110
110
  } from "./chunk-1vg43g9q.js";
@@ -121,7 +121,7 @@ import {
121
121
  assertNoProviderWebTools,
122
122
  toolsFromProjectConfig,
123
123
  assertMaxSteps
124
- } from "./chunk-z0t4p2sk.js";
124
+ } from "./chunk-gxwy4c3s.js";
125
125
  import {
126
126
  discoverOntologyFiles,
127
127
  discoverAgentSkills,
@@ -130,7 +130,7 @@ import {
130
130
  validateSharesAtStartup,
131
131
  discoverOntologySources,
132
132
  discoverProjectDefinitions2
133
- } from "./chunk-kv0kvknv.js";
133
+ } from "./chunk-r9rtavg9.js";
134
134
  import {
135
135
  createDatasetIngestRuntime,
136
136
  registerDatasetIngestRuntime,
@@ -143,7 +143,7 @@ import {
143
143
  createVectorIndexingRuntime,
144
144
  registerVectorIndexingRuntime,
145
145
  getApiPublicOrigin
146
- } from "./chunk-tqa68kj7.js";
146
+ } from "./chunk-8bns0y68.js";
147
147
  import {
148
148
  registerProjectionRegistry2
149
149
  } from "./chunk-sysnvjce.js";
@@ -170,7 +170,7 @@ import {
170
170
  } from "./chunk-j0wgh8gv.js";
171
171
  import {
172
172
  SyncValidationError2
173
- } from "./chunk-m7b9q5dk.js";
173
+ } from "./chunk-3z1vxzcm.js";
174
174
  import {
175
175
  SandboxError2,
176
176
  createSandboxDefinition,
@@ -25,7 +25,7 @@ import {
25
25
  compareQueryScalarValues,
26
26
  matchesPredicate,
27
27
  sortTieDirection2
28
- } from "./chunk-2by73sm2.js";
28
+ } from "./chunk-w1wq7gfr.js";
29
29
  import {
30
30
  ObjectQueryValidationError2,
31
31
  ObjectQueryPlanningError2,