@sixb/pg 0.2.4 → 0.2.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAGV,YAAY,EACZ,aAAa,EACb,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAqH3B,OAAO,KAAK,EAAe,GAAG,EAAa,MAAM,aAAa,CAAA;AAG9D,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrC;AAED,eAAO,MAAM,2BAA2B,wBAAwB,CAAA;AAEhE,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC,wBAAwB,CAAC,CAE1F;AAED,wBAAgB,MAAM,CACpB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC/D,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAAC,wBAAwB,CAAC,CAEzC;AAED,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,MAAM,GACjB,SAAS,eAAe,EAAE,CAQ5B;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;IACjB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,wBAAwB,CAAC,CAAA;CAC5D,GAAG,eAAe,CAqBlB;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG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AAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwFtD,OAAO,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA0ClE,KAAK,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC;CAkChE;AAED,gFAAgF;AAChF,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,SAAS,EACd,MAAM,EAAE;IACN,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAA;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACd,QAAQ,CAAC,MAAM,EAAE;YAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;SAAE,CAAA;QAClD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;KACnC,CAAA;CACF,GACA,OAAO,CAAC,iBAAiB,CAAC,CA2B5B;AAED;;;GAGG;AACH,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,qEAAqE;AACrE,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,CAAC,CAyBhC"}
1
+ {"version":3,"file":"replacement-plans.d.ts","sourceRoot":"","sources":["../../src/ontology-storage/replacement-plans.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAM3B,MAAM,qCAAqC,CAAA;AAY5C,OAAO,KAAK,EAEV,mBAAmB,EACnB,8BAA8B,EAC9B,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,EACrB,yBAAyB,EACzB,+BAA+B,EAChC,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAc7C,eAAO,MAAM,kBAAkB,mCAAmC,CAAA;AA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{ ArtifactBoardPreviewRecord, ArtifactCommentKey, ArtifactCommentRecord, ArtifactFrameGrantRecord, ArtifactRecord, ArtifactRestorePointRecord, ArtifactStateEntry, ArtifactStateKeyInput, ArtifactStateScope, ArtifactStorage, ArtifactTurnInput, ArtifactTurnWriteRecord, ArtifactVersionRecord, CopyArtifactInput, CreateArtifactCommentInput, CreateArtifactInput, DeleteArtifactInput, DeleteExpiredArtifactFrameGrantsInput, FindArtifactFrameGrantInput, FreezeArtifactVersionInput, GetArtifactInput, GetArtifactRestorePointInput, GetArtifactVersionInput, ListArtifactBoardPreviewsInput, ListArtifactsInput, ListArtifactsResult, ListArtifactVersionsInput, ListArtifactVersionsResult, ListReferencingVersionsInput, PublishArtifactVersionInput, PublishedArtifactVersion, PutArtifactBoardPreviewsInput, ResolveArtifactCommentInput, RestoreArtifactInput, SetArtifactStateInput, UndoArtifactTurnInput, UndoneArtifactTurn } from "@sixb/core/storage";
1
+ import type { ArtifactBoardPreviewRecord, ArtifactCommentKey, ArtifactCommentRecord, ArtifactFrameGrantRecord, ArtifactPdfKeyInput, ArtifactPdfRecord, ArtifactRecord, ArtifactRestorePointRecord, ArtifactStateEntry, ArtifactStateKeyInput, ArtifactStateScope, ArtifactStorage, ArtifactTurnInput, ArtifactTurnWriteRecord, ArtifactVersionRecord, CopyArtifactInput, CreateArtifactCommentInput, CreateArtifactInput, DeleteArtifactInput, DeleteExpiredArtifactFrameGrantsInput, FindArtifactFrameGrantInput, FreezeArtifactVersionInput, GetArtifactInput, GetArtifactRestorePointInput, GetArtifactVersionInput, ListArtifactBoardPreviewsInput, ListArtifactsInput, ListArtifactsResult, ListArtifactVersionsInput, ListArtifactVersionsResult, ListReferencingVersionsInput, PublishArtifactVersionInput, PublishedArtifactVersion, PutArtifactBoardPreviewsInput, ResolveArtifactCommentInput, RestoreArtifactInput, SetArtifactStateInput, UndoArtifactTurnInput, UndoneArtifactTurn } from "@sixb/core/storage";
2
2
  import { type PgStoreClient } from "./transactions";
3
3
  export declare class PgArtifactStorage implements ArtifactStorage {
4
4
  private readonly sql;
@@ -28,6 +28,9 @@ export declare class PgArtifactStorage implements ArtifactStorage {
28
28
  clearState(input: ArtifactStateScope): Promise<number>;
29
29
  listBoardPreviews(input: ListArtifactBoardPreviewsInput): Promise<ArtifactBoardPreviewRecord[]>;
30
30
  putBoardPreviews(input: PutArtifactBoardPreviewsInput): Promise<void>;
31
+ getPdf(input: ArtifactPdfKeyInput): Promise<ArtifactPdfRecord | null>;
32
+ putPdf(input: ArtifactPdfRecord): Promise<void>;
33
+ clearPdfFailure(input: ArtifactPdfKeyInput): Promise<void>;
31
34
  createComment(input: CreateArtifactCommentInput): Promise<ArtifactCommentRecord>;
32
35
  getComment(input: ArtifactCommentKey): Promise<ArtifactCommentRecord | null>;
33
36
  listComments(input: GetArtifactInput): Promise<ArtifactCommentRecord[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"pg-artifact-storage.d.ts","sourceRoot":"","sources":["../src/pg-artifact-storage.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,0BAA0B,EAE1B,kBAAkB,EAClB,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,EAEd,0BAA0B,EAC1B,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EAEvB,qBAAqB,EACrB,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,qCAAqC,EACrC,2BAA2B,EAC3B,0BAA0B,EAC1B,gBAAgB,EAChB,4BAA4B,EAC5B,uBAAuB,EACvB,8BAA8B,EAC9B,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,wBAAwB,EACxB,6BAA6B,EAC7B,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,E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  "postgres": "^3.4.5"
41
41
  },
42
42
  "peerDependencies": {
43
- "@sixb/core": "0.2.4"
43
+ "@sixb/core": "0.2.5"
44
44
  },
45
45
  "devDependencies": {
46
- "@sixb/core": "0.2.4",
46
+ "@sixb/core": "0.2.5",
47
47
  "@types/bun": "latest",
48
48
  "typescript": "^5.7.0"
49
49
  },
@@ -3,6 +3,7 @@ import type { PgStoreClient } from "../transactions"
3
3
  import { PgAgentApprovalStore } from "./approvals"
4
4
  import { PgAgentContextCheckpointStore } from "./checkpoints"
5
5
  import { PgAgentComputerSessionStore } from "./computers"
6
+ import { PgAgentInboxStore } from "./inbox"
6
7
  import { PgAgentMemoryStore } from "./memory"
7
8
  import { PgAgentMessageStore } from "./messages"
8
9
  import { PgAgentRunStore } from "./runs"
@@ -31,6 +32,7 @@ export class PgAgentStorage implements AgentStorage {
31
32
  readonly approvalModes: PgAgentApprovalModeStore
32
33
  readonly computers: PgAgentComputerSessionStore
33
34
  readonly tokenRates: PgAgentTokenRateStore
35
+ readonly inbox: PgAgentInboxStore
34
36
 
35
37
  constructor(options: PgAgentStorageOptions) {
36
38
  this.threads = new PgAgentThreadStore(options.sql)
@@ -42,5 +44,6 @@ export class PgAgentStorage implements AgentStorage {
42
44
  this.approvalModes = new PgAgentApprovalModeStore(options.sql)
43
45
  this.computers = new PgAgentComputerSessionStore(options.sql)
44
46
  this.tokenRates = new PgAgentTokenRateStore(options.sql)
47
+ this.inbox = new PgAgentInboxStore(options.sql)
45
48
  }
46
49
  }
@@ -0,0 +1,418 @@
1
+ import type { AgentMessagePart, Principal } from "@sixb/core"
2
+ import {
3
+ assertEnqueueAgentInboxItemInput,
4
+ assertInboxRunOwnership,
5
+ assertInboxThreadAcceptsItem,
6
+ assertTakeAgentInboxSteersInput,
7
+ assertUpdateAgentInboxItemInput,
8
+ newAgentInboxItemRecord,
9
+ updatedAgentInboxItemRecord,
10
+ } from "@sixb/core/internal/agent-run-storage-provider"
11
+ import {
12
+ type AgentInboxItemRecord,
13
+ type AgentInboxMode,
14
+ type AgentInboxSpec,
15
+ type AgentInboxStore,
16
+ AgentStorageError,
17
+ type AgentThreadRecord,
18
+ type ConsumeClaimedAgentInboxInput,
19
+ type EnqueueAgentInboxItemInput,
20
+ type EnqueueAgentInboxItemResult,
21
+ type ListAgentInboxItemsInput,
22
+ type ListWaitingAgentInboxThreadsInput,
23
+ type RemoveAgentInboxItemInput,
24
+ type TakeAgentInboxSteersInput,
25
+ type TakeNextQueuedAgentInboxInput,
26
+ type UpdateAgentInboxItemInput,
27
+ } from "@sixb/core/storage"
28
+ import type { SQLClient } from "../pg-client"
29
+ import { isUniqueViolation } from "../storage-errors"
30
+ import { type PgStoreClient, runPgTransaction } from "../transactions"
31
+ import { type AgentRunRow, rowToRunRecord } from "./rows"
32
+
33
+ interface AgentInboxRow {
34
+ readonly project_id: string
35
+ readonly id: string
36
+ readonly thread_id: string
37
+ readonly message_id: string
38
+ readonly seq: number | string
39
+ readonly author_principal_type: Principal["type"]
40
+ readonly author_principal_id: string
41
+ readonly mode: AgentInboxMode
42
+ readonly parts: readonly AgentMessagePart[] | string
43
+ readonly spec: AgentInboxSpec | string | null
44
+ readonly time_zone: string | null
45
+ readonly locale: string | null
46
+ readonly immediate: boolean
47
+ readonly execution_id: string | null
48
+ readonly claimed_by_run_id: string | null
49
+ readonly claimed_by_token: string | null
50
+ readonly claimed_by_step: number | string | null
51
+ readonly claimed_after_answer: boolean | null
52
+ readonly created_at: Date | string
53
+ readonly updated_at: Date | string
54
+ }
55
+
56
+ interface ThreadSummaryRow {
57
+ readonly id: string
58
+ readonly kind: AgentThreadRecord["kind"]
59
+ readonly status: AgentThreadRecord["status"]
60
+ readonly active_run_id: string | null
61
+ }
62
+
63
+ export class PgAgentInboxStore implements AgentInboxStore {
64
+ constructor(private readonly sql: PgStoreClient) {}
65
+
66
+ async enqueue(input: EnqueueAgentInboxItemInput): Promise<EnqueueAgentInboxItemResult> {
67
+ assertEnqueueAgentInboxItemInput(input, "SixbPg")
68
+
69
+ try {
70
+ return await runPgTransaction(this.sql, async (tx) => {
71
+ const [existing] = await tx<AgentInboxRow[]>`
72
+ SELECT * FROM agent_thread_inbox
73
+ WHERE project_id = ${input.projectId} AND id = ${input.id}
74
+ FOR UPDATE
75
+ `
76
+ if (existing) {
77
+ if (existing.thread_id === input.threadId) {
78
+ return { item: rowToInboxItem(existing), created: false }
79
+ }
80
+ throw new AgentStorageError(
81
+ "duplicate_id",
82
+ `[SixbPg] Agent inbox item '${input.id}' already exists on another thread in project '${input.projectId}'.`
83
+ )
84
+ }
85
+
86
+ const [thread] = await tx<ThreadSummaryRow[]>`
87
+ SELECT id, kind, status, active_run_id FROM agent_threads
88
+ WHERE project_id = ${input.projectId} AND id = ${input.threadId}
89
+ FOR UPDATE
90
+ `
91
+ const [counts] = await tx<{ count: number | string; max_seq: number | string }[]>`
92
+ SELECT COUNT(*) AS count, COALESCE(MAX(seq), 0) AS max_seq
93
+ FROM agent_thread_inbox
94
+ WHERE project_id = ${input.projectId} AND thread_id = ${input.threadId}
95
+ `
96
+ assertInboxThreadAcceptsItem(
97
+ thread ?? null,
98
+ input.threadId,
99
+ input.projectId,
100
+ Number(counts?.count ?? 0),
101
+ "SixbPg"
102
+ )
103
+
104
+ const [existingMessage] = await tx<{ id: string }[]>`
105
+ SELECT id FROM agent_messages
106
+ WHERE project_id = ${input.projectId} AND id = ${input.messageId}
107
+ `
108
+ if (existingMessage) {
109
+ throw new AgentStorageError(
110
+ "duplicate_id",
111
+ `[SixbPg] Agent message '${input.messageId}' already exists for project '${input.projectId}'.`
112
+ )
113
+ }
114
+
115
+ const record = newAgentInboxItemRecord(input, Number(counts?.max_seq ?? 0) + 1)
116
+ const [inserted] = await tx<AgentInboxRow[]>`
117
+ INSERT INTO agent_thread_inbox (
118
+ project_id, id, thread_id, message_id, seq,
119
+ author_principal_type, author_principal_id, mode, parts, spec,
120
+ time_zone, locale, immediate, execution_id, created_at, updated_at
121
+ ) VALUES (
122
+ ${record.projectId},
123
+ ${record.id},
124
+ ${record.threadId},
125
+ ${record.messageId},
126
+ ${record.seq},
127
+ ${record.authorPrincipal.type},
128
+ ${record.authorPrincipal.id},
129
+ ${record.mode},
130
+ ${JSON.stringify(record.parts)}::text::jsonb,
131
+ ${record.spec === undefined ? null : JSON.stringify(record.spec)}::text::jsonb,
132
+ ${record.timeZone ?? null},
133
+ ${record.locale ?? null},
134
+ ${Boolean(record.immediate)},
135
+ ${record.executionId ?? null},
136
+ ${record.createdAt},
137
+ ${record.updatedAt}
138
+ )
139
+ RETURNING *
140
+ `
141
+ return { item: rowToInboxItem(inserted!), created: true }
142
+ })
143
+ } catch (error) {
144
+ if (isUniqueViolation(error)) {
145
+ throw new AgentStorageError(
146
+ "duplicate_id",
147
+ `[SixbPg] Agent inbox item or message id already exists for project '${input.projectId}'.`
148
+ )
149
+ }
150
+ throw error
151
+ }
152
+ }
153
+
154
+ async getById(params: { projectId: string; id: string }): Promise<AgentInboxItemRecord | null> {
155
+ const [row] = await this.sql<AgentInboxRow[]>`
156
+ SELECT * FROM agent_thread_inbox
157
+ WHERE project_id = ${params.projectId} AND id = ${params.id}
158
+ `
159
+ return row ? rowToInboxItem(row) : null
160
+ }
161
+
162
+ async list(input: ListAgentInboxItemsInput): Promise<readonly AgentInboxItemRecord[]> {
163
+ const includeClaimed = input.includeClaimed ?? true
164
+ const rows = includeClaimed
165
+ ? await this.sql<AgentInboxRow[]>`
166
+ SELECT * FROM agent_thread_inbox
167
+ WHERE project_id = ${input.projectId} AND thread_id = ${input.threadId}
168
+ ORDER BY seq ASC
169
+ `
170
+ : await this.sql<AgentInboxRow[]>`
171
+ SELECT * FROM agent_thread_inbox
172
+ WHERE project_id = ${input.projectId} AND thread_id = ${input.threadId}
173
+ AND claimed_by_run_id IS NULL
174
+ ORDER BY seq ASC
175
+ `
176
+ return rows.map(rowToInboxItem)
177
+ }
178
+
179
+ async listWaitingThreads(input: ListWaitingAgentInboxThreadsInput): Promise<readonly string[]> {
180
+ const rows = await this.sql<{ thread_id: string }[]>`
181
+ SELECT DISTINCT inbox.thread_id
182
+ FROM agent_thread_inbox inbox
183
+ JOIN agent_threads thread
184
+ ON thread.project_id = inbox.project_id AND thread.id = inbox.thread_id
185
+ WHERE inbox.project_id = ${input.projectId}
186
+ AND inbox.created_at < ${input.createdBefore}
187
+ AND inbox.thread_id > ${input.afterThreadId ?? ""}
188
+ AND thread.active_run_id IS NULL
189
+ ORDER BY inbox.thread_id ASC
190
+ LIMIT ${input.limit}
191
+ `
192
+ return rows.map((row) => row.thread_id)
193
+ }
194
+
195
+ async update(input: UpdateAgentInboxItemInput): Promise<AgentInboxItemRecord | null> {
196
+ assertUpdateAgentInboxItemInput(input, "SixbPg")
197
+
198
+ return runPgTransaction(this.sql, async (tx) => {
199
+ const [current] = await tx<AgentInboxRow[]>`
200
+ SELECT * FROM agent_thread_inbox
201
+ WHERE project_id = ${input.projectId} AND id = ${input.id}
202
+ FOR UPDATE
203
+ `
204
+ if (!current || current.thread_id !== input.threadId) return null
205
+
206
+ const next = updatedAgentInboxItemRecord(rowToInboxItem(current), input)
207
+ const [updated] = await tx<AgentInboxRow[]>`
208
+ UPDATE agent_thread_inbox
209
+ SET
210
+ mode = ${next.mode},
211
+ parts = ${JSON.stringify(next.parts)}::text::jsonb,
212
+ spec = ${next.spec === undefined ? null : JSON.stringify(next.spec)}::text::jsonb,
213
+ immediate = ${Boolean(next.immediate)},
214
+ updated_at = ${next.updatedAt}
215
+ WHERE project_id = ${next.projectId} AND id = ${next.id}
216
+ RETURNING *
217
+ `
218
+ return updated ? rowToInboxItem(updated) : null
219
+ })
220
+ }
221
+
222
+ async remove(input: RemoveAgentInboxItemInput): Promise<AgentInboxItemRecord | null> {
223
+ return runPgTransaction(this.sql, async (tx) => {
224
+ const [current] = await tx<AgentInboxRow[]>`
225
+ SELECT * FROM agent_thread_inbox
226
+ WHERE project_id = ${input.projectId} AND id = ${input.id}
227
+ FOR UPDATE
228
+ `
229
+ if (!current || current.thread_id !== input.threadId) return null
230
+ if (current.claimed_by_run_id !== null) {
231
+ throw new AgentStorageError(
232
+ "invalid_state",
233
+ `[SixbPg] Agent inbox item '${current.id}' was already claimed by run '${current.claimed_by_run_id}'.`
234
+ )
235
+ }
236
+ await tx`
237
+ DELETE FROM agent_thread_inbox
238
+ WHERE project_id = ${input.projectId} AND id = ${input.id}
239
+ `
240
+ return rowToInboxItem(current)
241
+ })
242
+ }
243
+
244
+ async takeSteers(input: TakeAgentInboxSteersInput): Promise<readonly AgentInboxItemRecord[]> {
245
+ assertTakeAgentInboxSteersInput(input, "SixbPg")
246
+
247
+ return runPgTransaction(this.sql, async (tx) => {
248
+ const run = await lockRun(tx, input.projectId, input.runId)
249
+ assertInboxRunOwnership(run, input, "SixbPg")
250
+
251
+ const updatedAt = new Date()
252
+ const rows = await tx<AgentInboxRow[]>`
253
+ UPDATE agent_thread_inbox
254
+ SET
255
+ claimed_by_run_id = ${input.runId},
256
+ claimed_by_token = ${input.executionToken},
257
+ claimed_by_step = ${input.stepIndex},
258
+ claimed_after_answer = ${input.afterAnswer ? true : null}::boolean,
259
+ updated_at = ${updatedAt}
260
+ WHERE project_id = ${input.projectId}
261
+ AND thread_id = ${input.threadId}
262
+ AND (
263
+ claimed_by_run_id IS NULL
264
+ OR claimed_by_run_id <> ${input.runId}
265
+ OR claimed_by_token <> ${input.executionToken}
266
+ )
267
+ AND mode = 'steer'
268
+ AND immediate = FALSE
269
+ AND author_principal_type = ${input.authorPrincipal.type}
270
+ AND author_principal_id = ${input.authorPrincipal.id}
271
+ RETURNING *
272
+ `
273
+ return rows.map(rowToInboxItem).sort((left, right) => left.seq - right.seq)
274
+ })
275
+ }
276
+
277
+ async consumeClaimed(
278
+ input: ConsumeClaimedAgentInboxInput
279
+ ): Promise<readonly AgentInboxItemRecord[]> {
280
+ return runPgTransaction(this.sql, async (tx) => {
281
+ const run = await lockRun(tx, input.projectId, input.runId)
282
+ assertInboxRunOwnership(run, input, "SixbPg")
283
+
284
+ const claimed = await tx<AgentInboxRow[]>`
285
+ SELECT * FROM agent_thread_inbox
286
+ WHERE project_id = ${input.projectId}
287
+ AND thread_id = ${input.threadId}
288
+ AND claimed_by_run_id = ${input.runId}
289
+ AND claimed_by_token = ${input.executionToken}
290
+ ORDER BY seq ASC
291
+ FOR UPDATE
292
+ `
293
+ if (claimed.length === 0) return []
294
+
295
+ const persisted = new Set(input.messageIds)
296
+ const updatedAt = new Date()
297
+ const consumed: AgentInboxItemRecord[] = []
298
+ for (const row of claimed) {
299
+ if (persisted.has(row.message_id)) {
300
+ await tx`
301
+ DELETE FROM agent_thread_inbox
302
+ WHERE project_id = ${row.project_id} AND id = ${row.id}
303
+ `
304
+ consumed.push(rowToInboxItem(row))
305
+ } else {
306
+ await tx`
307
+ UPDATE agent_thread_inbox
308
+ SET
309
+ claimed_by_run_id = NULL,
310
+ claimed_by_token = NULL,
311
+ claimed_by_step = NULL,
312
+ claimed_after_answer = NULL,
313
+ updated_at = ${updatedAt}
314
+ WHERE project_id = ${row.project_id} AND id = ${row.id}
315
+ `
316
+ }
317
+ }
318
+ return consumed
319
+ })
320
+ }
321
+
322
+ async releaseClaimed(input: { projectId: string; runId: string }): Promise<number> {
323
+ const updatedAt = new Date()
324
+ const rows = await this.sql<{ id: string }[]>`
325
+ UPDATE agent_thread_inbox
326
+ SET
327
+ claimed_by_run_id = NULL,
328
+ claimed_by_token = NULL,
329
+ claimed_by_step = NULL,
330
+ claimed_after_answer = NULL,
331
+ updated_at = ${updatedAt}
332
+ WHERE project_id = ${input.projectId} AND claimed_by_run_id = ${input.runId}
333
+ RETURNING id
334
+ `
335
+ return rows.length
336
+ }
337
+
338
+ async takeNextQueued(input: TakeNextQueuedAgentInboxInput): Promise<AgentInboxItemRecord | null> {
339
+ return runPgTransaction(this.sql, async (tx) => {
340
+ const [thread] = await tx<ThreadSummaryRow[]>`
341
+ SELECT id, kind, status, active_run_id FROM agent_threads
342
+ WHERE project_id = ${input.projectId} AND id = ${input.threadId}
343
+ FOR UPDATE
344
+ `
345
+ if (!thread || thread.status !== "active" || thread.active_run_id !== null) return null
346
+
347
+ const [winner] = await tx<AgentInboxRow[]>`
348
+ SELECT * FROM agent_thread_inbox
349
+ WHERE project_id = ${input.projectId}
350
+ AND thread_id = ${input.threadId}
351
+ AND claimed_by_run_id IS NULL
352
+ AND (${!input.onlyImmediate}::boolean OR immediate = TRUE)
353
+ AND (
354
+ ${input.authorPrincipal?.id ?? null}::text IS NULL
355
+ OR (author_principal_type = ${input.authorPrincipal?.type ?? null}
356
+ AND author_principal_id = ${input.authorPrincipal?.id ?? null})
357
+ )
358
+ ORDER BY
359
+ CASE WHEN immediate = TRUE THEN 0 WHEN mode = 'steer' THEN 1 ELSE 2 END ASC,
360
+ seq ASC
361
+ LIMIT 1
362
+ FOR UPDATE
363
+ `
364
+ if (!winner) return null
365
+
366
+ await tx`
367
+ DELETE FROM agent_thread_inbox
368
+ WHERE project_id = ${winner.project_id} AND id = ${winner.id}
369
+ `
370
+ return rowToInboxItem(winner)
371
+ })
372
+ }
373
+ }
374
+
375
+ async function lockRun(tx: SQLClient, projectId: string, id: string) {
376
+ const [row] = await tx<AgentRunRow[]>`
377
+ SELECT * FROM agent_runs WHERE project_id = ${projectId} AND id = ${id} FOR UPDATE
378
+ `
379
+ return row ? rowToRunRecord(row) : null
380
+ }
381
+
382
+ function parseJson<T>(value: T | string): T {
383
+ return typeof value === "string" ? (JSON.parse(value) as T) : value
384
+ }
385
+
386
+ function rowToInboxItem(row: AgentInboxRow): AgentInboxItemRecord {
387
+ const spec = row.spec === null ? undefined : parseJson<AgentInboxSpec>(row.spec)
388
+ const claimedBy =
389
+ row.claimed_by_run_id !== null && row.claimed_by_token !== null && row.claimed_by_step !== null
390
+ ? {
391
+ runId: row.claimed_by_run_id,
392
+ executionToken: row.claimed_by_token,
393
+ stepIndex: Number(row.claimed_by_step),
394
+ ...(row.claimed_after_answer === true ? { afterAnswer: true } : {}),
395
+ }
396
+ : undefined
397
+ return {
398
+ id: row.id,
399
+ projectId: row.project_id,
400
+ threadId: row.thread_id,
401
+ messageId: row.message_id,
402
+ seq: Number(row.seq),
403
+ authorPrincipal: {
404
+ type: row.author_principal_type,
405
+ id: row.author_principal_id,
406
+ },
407
+ mode: row.mode,
408
+ parts: parseJson<readonly AgentMessagePart[]>(row.parts),
409
+ ...(spec ? { spec } : {}),
410
+ ...(row.time_zone ? { timeZone: row.time_zone } : {}),
411
+ ...(row.locale ? { locale: row.locale } : {}),
412
+ ...(row.immediate ? { immediate: true } : {}),
413
+ ...(row.execution_id ? { executionId: row.execution_id } : {}),
414
+ ...(claimedBy ? { claimedBy } : {}),
415
+ createdAt: new Date(row.created_at),
416
+ updatedAt: new Date(row.updated_at),
417
+ }
418
+ }
@@ -58,7 +58,7 @@ export class PgAgentThreadStore implements AgentThreadStore {
58
58
  return runPgTransaction(this.sql, async (tx) => {
59
59
  // Same lock order as run finalization: run, then thread.
60
60
  const runs =
61
- input.action === "recreate"
61
+ input.action === "recreate" || input.action === "restore"
62
62
  ? []
63
63
  : await tx<AgentRunRow[]>`
64
64
  SELECT * FROM agent_runs WHERE project_id = ${input.projectId} AND id = ${input.runId}
@@ -0,0 +1,145 @@
1
+ -- `sixb run` records each script run as an execution: a script executor, the script's path as its
2
+ -- source, and authority that holds nothing beyond the run id the executor already names.
3
+ ALTER TABLE executions
4
+ DROP CONSTRAINT executions_executor_kind_check,
5
+ ADD CONSTRAINT executions_executor_kind_check CHECK (
6
+ executor_kind IN (
7
+ 'request', 'action', 'pipeline', 'projection', 'rule', 'sync', 'webhook', 'workflow',
8
+ 'agent', 'kernel', 'script'
9
+ )
10
+ ),
11
+ DROP CONSTRAINT executions_source_kind_check,
12
+ ADD CONSTRAINT executions_source_kind_check CHECK (
13
+ source_kind IN (
14
+ 'http', 'webhook', 'schedule', 'event', 'datasetVersion', 'execution', 'ontologyCommit',
15
+ 'script'
16
+ )
17
+ ),
18
+ DROP CONSTRAINT executions_authority_kind_check,
19
+ ADD CONSTRAINT executions_authority_kind_check CHECK (
20
+ authority_kind IN ('principal', 'trustedPrimitive', 'delegated', 'kernel', 'script', 'disabled')
21
+ ),
22
+ DROP CONSTRAINT executions_authority_shape_check,
23
+ ADD CONSTRAINT executions_authority_shape_check CHECK (
24
+ (
25
+ authority_kind = 'principal'
26
+ AND num_nonnulls(authority_user_id, authority_service_account_id) = 1
27
+ AND num_nonnulls(authority_session_id, authority_access_token_id) <= 1
28
+ AND (authority_session_id IS NULL OR authority_user_id IS NOT NULL)
29
+ AND authority_primitive_kind IS NULL
30
+ AND authority_primitive_id IS NULL
31
+ AND authority_kernel_operation IS NULL
32
+ AND authority_delegation_kind IS NULL
33
+ AND authority_delegation_id IS NULL
34
+ AND authority_delegation_session_id IS NULL
35
+ )
36
+ OR (
37
+ authority_kind = 'trustedPrimitive'
38
+ AND authority_user_id IS NULL
39
+ AND authority_service_account_id IS NULL
40
+ AND authority_session_id IS NULL
41
+ AND authority_access_token_id IS NULL
42
+ AND authority_primitive_kind IS NOT NULL
43
+ AND authority_primitive_id IS NOT NULL
44
+ AND length(trim(authority_primitive_id)) > 0
45
+ AND authority_kernel_operation IS NULL
46
+ AND authority_delegation_kind IS NULL
47
+ AND authority_delegation_id IS NULL
48
+ AND authority_delegation_session_id IS NULL
49
+ )
50
+ OR (
51
+ authority_kind = 'delegated'
52
+ AND authority_user_id IS NULL
53
+ AND authority_service_account_id IS NULL
54
+ AND authority_session_id IS NULL
55
+ AND authority_access_token_id IS NULL
56
+ AND authority_primitive_kind IS NULL
57
+ AND authority_primitive_id IS NULL
58
+ AND authority_kernel_operation IS NULL
59
+ AND authority_delegation_kind IS NOT NULL
60
+ AND authority_delegation_kind = 'share'
61
+ AND authority_delegation_id IS NOT NULL
62
+ AND length(trim(authority_delegation_id)) > 0
63
+ AND authority_delegation_session_id IS NOT NULL
64
+ AND length(trim(authority_delegation_session_id)) > 0
65
+ )
66
+ OR (
67
+ authority_kind = 'kernel'
68
+ AND authority_user_id IS NULL
69
+ AND authority_service_account_id IS NULL
70
+ AND authority_session_id IS NULL
71
+ AND authority_access_token_id IS NULL
72
+ AND authority_primitive_kind IS NULL
73
+ AND authority_primitive_id IS NULL
74
+ AND authority_kernel_operation IS NOT NULL
75
+ AND authority_delegation_kind IS NULL
76
+ AND authority_delegation_id IS NULL
77
+ AND authority_delegation_session_id IS NULL
78
+ )
79
+ OR (
80
+ -- A script's authority is its run id, which `executor_id` already holds.
81
+ authority_kind IN ('script', 'disabled')
82
+ AND authority_user_id IS NULL
83
+ AND authority_service_account_id IS NULL
84
+ AND authority_session_id IS NULL
85
+ AND authority_access_token_id IS NULL
86
+ AND authority_primitive_kind IS NULL
87
+ AND authority_primitive_id IS NULL
88
+ AND authority_kernel_operation IS NULL
89
+ AND authority_delegation_kind IS NULL
90
+ AND authority_delegation_id IS NULL
91
+ AND authority_delegation_session_id IS NULL
92
+ )
93
+ ),
94
+ DROP CONSTRAINT executions_executor_authority_check,
95
+ ADD CONSTRAINT executions_executor_authority_check CHECK (
96
+ (
97
+ executor_kind = 'request'
98
+ AND source_kind = 'http'
99
+ AND executor_id = source_id
100
+ AND (
101
+ (
102
+ authority_kind = 'principal'
103
+ AND requested_by_user_id IS NOT DISTINCT FROM authority_user_id
104
+ AND requested_by_service_account_id IS NOT DISTINCT FROM authority_service_account_id
105
+ )
106
+ OR (
107
+ authority_kind IN ('delegated', 'disabled')
108
+ AND requested_by_user_id IS NULL
109
+ AND requested_by_service_account_id IS NULL
110
+ )
111
+ )
112
+ )
113
+ OR (
114
+ executor_kind IN ('action', 'pipeline', 'projection', 'rule', 'sync', 'webhook', 'workflow')
115
+ AND source_kind <> 'script'
116
+ AND authority_kind = 'trustedPrimitive'
117
+ AND executor_kind = authority_primitive_kind
118
+ )
119
+ OR (
120
+ executor_kind = 'agent'
121
+ AND source_kind = 'execution'
122
+ AND (
123
+ (
124
+ authority_kind = 'principal'
125
+ AND authority_service_account_id IS NOT NULL
126
+ AND authority_session_id IS NULL
127
+ AND authority_access_token_id IS NULL
128
+ )
129
+ OR (
130
+ authority_kind = 'principal'
131
+ AND authority_user_id IS NOT NULL
132
+ AND num_nonnulls(authority_session_id, authority_access_token_id) = 1
133
+ )
134
+ OR authority_kind = 'disabled'
135
+ )
136
+ )
137
+ OR (executor_kind = 'kernel' AND authority_kind = 'kernel' AND source_kind <> 'script')
138
+ OR (
139
+ executor_kind = 'script'
140
+ AND source_kind = 'script'
141
+ AND authority_kind = 'script'
142
+ AND requested_by_user_id IS NULL
143
+ AND requested_by_service_account_id IS NULL
144
+ )
145
+ );