diff --git a/.changeset/fast-canonical-session-state.md b/.changeset/fast-canonical-session-state.md new file mode 100644 index 000000000..23faf8856 --- /dev/null +++ b/.changeset/fast-canonical-session-state.md @@ -0,0 +1,9 @@ +--- +'@roomote/cloud-agents': patch +'@roomote/sdk': patch +'@roomote/types': patch +'@roomote/db': patch +'@roomote/web': patch +--- + +Sessions no longer announce an outdated status as current. Every model-relevant input, including events the transcript hides, is recorded in one ordered per-Session log with the time it was observed and the order it was admitted. Before each turn, a deterministic reducer decides which state facts are still current, which stay as history, and which are obsolete, using authoritative versions where a source provides them; a queued update that a newer version has already replaced no longer runs. Conversations also rebuild from that same log after a restart, so a resumed Session and a continuing one describe the same state. diff --git a/apps/web/src/trpc/commands/setup/setup-session.test.ts b/apps/web/src/trpc/commands/setup/setup-session.test.ts index 82ed4e1ab..ceb04643c 100644 --- a/apps/web/src/trpc/commands/setup/setup-session.test.ts +++ b/apps/web/src/trpc/commands/setup/setup-session.test.ts @@ -1,6 +1,7 @@ const mocks = vi.hoisted(() => ({ getStatus: vi.fn(), schedule: vi.fn(), + enqueue: vi.fn(), submit: vi.fn(), complete: vi.fn(), })); @@ -17,6 +18,7 @@ vi.mock('@/lib/server/setup-funnel-telemetry', () => ({ })); vi.mock('@roomote/sdk/server', () => ({ buildFastAgentArtifactCreator: vi.fn(), + enqueueFastAgentParentEvent: mocks.enqueue, LINEAR_ORG_CONNECTION_ROLE: 'organization', })); vi.mock('@roomote/cloud-agents/server', async (importOriginal) => ({ @@ -200,6 +202,10 @@ describe('optional setup integration discovery', () => { }, })); mocks.complete.mockResolvedValue(true); + mocks.enqueue.mockImplementation(async ({ event }) => { + mocks.schedule(event); + return { queued: true }; + }); }); afterEach(async () => { await db diff --git a/apps/web/src/trpc/commands/setup/setup-session.ts b/apps/web/src/trpc/commands/setup/setup-session.ts index f9fe20283..a3cb57513 100644 --- a/apps/web/src/trpc/commands/setup/setup-session.ts +++ b/apps/web/src/trpc/commands/setup/setup-session.ts @@ -1,6 +1,9 @@ import { createHash } from 'node:crypto'; -import { buildFastAgentArtifactCreator } from '@roomote/sdk/server'; +import { + buildFastAgentArtifactCreator, + enqueueFastAgentParentEvent, +} from '@roomote/sdk/server'; import { buildFastAgentSetupAdapter } from '@roomote/cloud-agents/server'; import { and, @@ -465,10 +468,38 @@ export async function scheduleSetupPlatformEvent( ): Promise<{ scheduled: boolean }> { const turn = await buildSetupPlatformEventTurn(auth, input); if (!turn) return { scheduled: false }; - scheduleWebFastAgentTurn(turn); + await enqueueDurableWebPlatformEventTurn(turn); return { scheduled: true }; } +async function enqueueDurableWebPlatformEventTurn( + turn: Parameters[0], +): Promise { + if (!turn.durableSessionId || !turn.setupContext || !turn.currentMessageId) { + throw new Error('A setup platform event requires durable turn context.'); + } + await enqueueFastAgentParentEvent({ + parent: { + sessionId: turn.durableSessionId, + conversation: turn.delivery.conversation, + }, + event: { + type: 'human_follow_up', + eventId: turn.currentMessageId, + currentMessageId: turn.currentMessageId, + userId: turn.userId, + question: turn.question, + turnSource: 'platform_event', + platformEventKind: turn.platformEventKind ?? 'setup', + ...(turn.platformEventVisibility + ? { platformEventVisibility: turn.platformEventVisibility } + : {}), + setupSession: true, + setupContext: turn.setupContext, + }, + }); +} + async function buildSetupPlatformEventTurn( auth: UserAuthSuccess, input: { @@ -784,7 +815,7 @@ export async function reconcileSetupPlatformEvents( }, { conversation, setupSnapshot }, ); - if (turn) scheduleWebFastAgentTurn(turn); + if (turn) await enqueueDurableWebPlatformEventTurn(turn); return setupCompleted; } diff --git a/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-canonical-projection.test.ts b/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-canonical-projection.test.ts new file mode 100644 index 000000000..df080c7b4 --- /dev/null +++ b/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-canonical-projection.test.ts @@ -0,0 +1,941 @@ +import type { FastAgentMessage } from '@roomote/db/server'; +import { + FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY, + type FastAgentEventSemantics, +} from '@roomote/types'; + +import { + collectFastAgentCanonicalAttachments, + FAST_AGENT_CANONICAL_ATTACHMENT_LIMIT, + projectFastAgentCanonicalEvents, + readFastAgentEventSemantics, + renderFastAgentCanonicalEventContext, + renderFastAgentCanonicalHistory, +} from '../fast-agent-canonical-projection'; + +function event(input: { + id: string; + sequence: number; + state: string; + semantics: Omit< + FastAgentEventSemantics, + 'schemaVersion' | 'sourceEventId' | 'state' + >; +}): FastAgentMessage { + const timestamp = new Date(input.semantics.observedAt); + return { + id: input.id, + conversationId: 'conversation-1', + eventId: input.id, + conversationSeq: input.sequence, + turnId: input.id, + turnSeq: 0, + ts: timestamp.getTime(), + observedAt: timestamp, + eventType: 'roomote_runtime.user_prompt', + role: 'user', + contentBlocks: [{ type: 'text', text: input.state }], + metadata: { + visibleInTranscript: false, + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: { + ...input.semantics, + schemaVersion: 1, + sourceEventId: input.id, + state: input.state, + }, + }, + payload: {}, + source: 'web', + nativeSessionId: null, + nativeMessageId: null, + createdAt: new Date(timestamp.getTime() + input.sequence), + updatedAt: new Date(timestamp.getTime() + input.sequence), + }; +} + +const setupSubject = { type: 'setup_source', id: 'deployment-1' }; + +describe('Fast canonical event projection', () => { + it('suppresses queued intermediate state when a newer version is already admitted', () => { + const rows = [ + event({ + id: 'yellow-v10', + sequence: 1, + state: 'yellow', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:10.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 10 }, + }, + }), + event({ + id: 'green-v11', + sequence: 2, + state: 'green', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:11.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 11 }, + }, + }), + event({ + id: 'yellow-v12', + sequence: 3, + state: 'yellow', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:12.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 12 }, + }, + }), + ]; + + const projection = projectFastAgentCanonicalEvents(rows); + + expect( + projection.events.map(({ event, classification }) => [ + event.eventId, + classification, + ]), + ).toEqual([ + ['yellow-v10', 'superseded_irrelevant'], + ['green-v11', 'superseded_irrelevant'], + ['yellow-v12', 'current'], + ]); + expect( + JSON.stringify(renderFastAgentCanonicalHistory(projection)), + ).not.toContain('green'); + expect( + JSON.stringify(renderFastAgentCanonicalHistory(projection)), + ).toContain('yellow-v12'); + }); + + it('uses source versions before admission order for late observations', () => { + const projection = projectFastAgentCanonicalEvents([ + event({ + id: 'v12-admitted-first', + sequence: 1, + state: 'yellow', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:12.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 12 }, + }, + }), + event({ + id: 'late-v11', + sequence: 2, + state: 'green', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:11.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 11 }, + }, + }), + ]); + + expect(projection.currentStateEventIds).toEqual(['v12-admitted-first']); + }); + + it('uses observation time conservatively for unversioned assertions', () => { + const projection = projectFastAgentCanonicalEvents([ + event({ + id: 'newer-observation', + sequence: 1, + state: 'yellow', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:12.000Z', + subject: setupSubject, + }, + }), + event({ + id: 'older-observation-admitted-late', + sequence: 2, + state: 'green', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:11.000Z', + subject: setupSubject, + }, + }), + ]); + + expect(projection.currentStateEventIds).toEqual(['newer-observation']); + }); + + it('marks equally authoritative same-version disagreement as conflicting', () => { + const projection = projectFastAgentCanonicalEvents([ + event({ + id: 'conflict-a', + sequence: 1, + state: 'yellow', + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:12.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 12 }, + }, + }), + event({ + id: 'conflict-b', + sequence: 2, + state: 'green', + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:12.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 12 }, + }, + }), + ]); + + expect( + projection.events.map(({ classification }) => classification), + ).toEqual(['conflicting', 'conflicting']); + }); + + it('keeps meaningful state transitions as history while ranking authority', () => { + const lowerAuthority = event({ + id: 'task-open', + sequence: 1, + state: 'open', + semantics: { + kind: 'state_change', + authority: 'delegated_task', + observedAt: '2026-01-01T00:00:10.000Z', + subject: { type: 'pull_request', id: 'pr-1' }, + }, + }); + const authoritative = event({ + id: 'provider-merged', + sequence: 2, + state: 'merged', + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:11.000Z', + subject: { type: 'pull_request', id: 'pr-1' }, + }, + }); + + const projection = projectFastAgentCanonicalEvents([ + lowerAuthority, + authoritative, + ]); + expect( + projection.events.map(({ classification }) => classification), + ).toEqual(['historical_relevant', 'current']); + }); + + it('produces the same cold state after a warm projection becomes stale', () => { + const v10 = event({ + id: 'v10', + sequence: 1, + state: 'yellow', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:10.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 10 }, + }, + }); + const v11 = event({ + id: 'v11', + sequence: 2, + state: 'green', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:11.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 11 }, + }, + }); + const warm = projectFastAgentCanonicalEvents([v10]); + const cold = projectFastAgentCanonicalEvents([v10, v11]); + + expect(warm.stateHash).not.toBe(cold.stateHash); + expect(JSON.stringify(renderFastAgentCanonicalHistory(cold))).not.toContain( + 'yellow', + ); + expect(JSON.stringify(renderFastAgentCanonicalHistory(cold))).toContain( + 'green', + ); + }); + + it('reconstructs hidden historical input with provenance on cold recovery', () => { + const hidden = event({ + id: 'child-progress', + sequence: 1, + state: + '{"type":"child_message","message":"Built it"}', + semantics: { + kind: 'historical_observation', + authority: 'delegated_task', + observedAt: '2026-01-01T00:00:10.000Z', + subject: { type: 'task_run', id: '42' }, + }, + }); + + const rendered = JSON.stringify( + renderFastAgentCanonicalHistory( + projectFastAgentCanonicalEvents([hidden]), + ), + ); + expect(rendered).toContain('child-progress'); + expect(rendered).toContain('historical_relevant'); + expect(rendered).toContain('delegated_task'); + expect(rendered).toContain('Built it'); + }); + + it('keeps an authoritative terminal status current over the earlier open state', () => { + const pullRequest = { type: 'pull_request', id: 'https://example/pull/1' }; + const opened = event({ + id: 'pr-opened', + sequence: 1, + state: 'open', + semantics: { + kind: 'state_change', + authority: 'source_control', + observedAt: '2026-01-01T00:00:10.000Z', + subject: pullRequest, + }, + }); + const merged = event({ + id: 'pr-merged', + sequence: 2, + state: 'merged', + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:20.000Z', + subject: pullRequest, + }, + }); + + const projection = projectFastAgentCanonicalEvents([opened, merged]); + expect(projection.currentStateEventIds).toEqual(['pr-merged']); + expect( + projection.events.map(({ event, classification }) => [ + event.eventId, + classification, + ]), + ).toEqual([ + ['pr-opened', 'historical_relevant'], + ['pr-merged', 'current'], + ]); + }); + + describe('mixed-version ordering', () => { + const subject = { type: 'setup_source', id: 'deployment-mixed' }; + // The intransitive triple: by timestamp B beats A and C beats B, while by + // version A beats C. A pairwise rule would pick a winner by iteration + // order; one ordering key must not. + const versionedOlderObservation = event({ + id: 'a-v2-observed-first', + sequence: 1, + state: 'a', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:01.000Z', + subject, + version: { scheme: 'monotonic_number', value: 2 }, + }, + }); + const unversionedMiddleObservation = event({ + id: 'b-unversioned', + sequence: 2, + state: 'b', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:02.000Z', + subject, + }, + }); + const versionedNewestObservation = event({ + id: 'c-v1-observed-last', + sequence: 3, + state: 'c', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:03.000Z', + subject, + version: { scheme: 'monotonic_number', value: 1 }, + }, + }); + + function permutations(items: T[]): T[][] { + if (items.length <= 1) return [items]; + return items.flatMap((item, index) => + permutations([...items.slice(0, index), ...items.slice(index + 1)]).map( + (rest) => [item, ...rest], + ), + ); + } + + it('selects the same winner for every admission order of a mixed-version subject', () => { + const winners = new Set( + permutations([ + versionedOlderObservation, + unversionedMiddleObservation, + versionedNewestObservation, + ]).map((ordering) => + projectFastAgentCanonicalEvents(ordering).currentStateEventIds.join( + ',', + ), + ), + ); + + expect([...winners]).toEqual(['a-v2-observed-first']); + }); + + it('keeps the highest monotonic version current when an unversioned claim is added later', () => { + const versionedOnly = projectFastAgentCanonicalEvents([ + versionedOlderObservation, + versionedNewestObservation, + ]); + const withUnversioned = projectFastAgentCanonicalEvents([ + versionedOlderObservation, + versionedNewestObservation, + unversionedMiddleObservation, + ]); + + // Adding an unnumbered claim must not silently regress a numbered state. + expect(versionedOnly.currentStateEventIds).toEqual([ + 'a-v2-observed-first', + ]); + expect(withUnversioned.currentStateEventIds).toEqual([ + 'a-v2-observed-first', + ]); + }); + + it('lets a higher monotonic transition outrank an unversioned assertion', () => { + const artifact = { type: 'artifact', id: 'artifact-1' }; + const publishedV5 = event({ + id: 'artifact-v5', + sequence: 1, + state: 'published:5', + semantics: { + kind: 'state_change', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:10.000Z', + subject: artifact, + version: { scheme: 'monotonic_number', value: 5 }, + }, + }); + const unversionedAssertion = event({ + id: 'artifact-assertion', + sequence: 2, + state: 'stale', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:20.000Z', + subject: artifact, + }, + }); + + expect( + projectFastAgentCanonicalEvents([publishedV5, unversionedAssertion]) + .currentStateEventIds, + ).toEqual(['artifact-v5']); + }); + }); + + it('keeps a terminal status current when a later task re-emits an opening event for the same pull request', () => { + // `pull_request_opened` is keyed per task but the subject is the PR, so a + // second task updating an already-merged PR admits an unversioned `open` + // state afterwards. It records a transition, not current state, so it + // must not overwrite the merged assertion. + const pullRequest = { type: 'pull_request', id: 'https://example/pull/5' }; + const merged = event({ + id: 'task-a-merged', + sequence: 1, + state: 'merged', + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:10.000Z', + subject: pullRequest, + }, + }); + const laterOpenFromSecondTask = event({ + id: 'task-b-opened', + sequence: 2, + state: 'open', + semantics: { + kind: 'state_change', + authority: 'source_control', + observedAt: '2026-01-01T00:05:00.000Z', + subject: pullRequest, + }, + }); + + const projection = projectFastAgentCanonicalEvents([ + merged, + laterOpenFromSecondTask, + ]); + expect(projection.currentStateEventIds).toEqual(['task-a-merged']); + expect( + projection.events.map(({ event, classification }) => [ + event.eventId, + classification, + ]), + ).toEqual([ + ['task-a-merged', 'current'], + ['task-b-opened', 'historical_relevant'], + ]); + }); + + it('keeps a stale lower-authority claim from overriding a provider status it arrives after', () => { + const pullRequest = { type: 'pull_request', id: 'https://example/pull/2' }; + const merged = event({ + id: 'provider-merged', + sequence: 1, + state: 'merged', + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:10.000Z', + subject: pullRequest, + }, + }); + const staleChildClaim = event({ + id: 'child-still-draft', + sequence: 2, + state: 'draft', + semantics: { + kind: 'current_state_assertion', + authority: 'delegated_task', + observedAt: '2026-01-01T00:00:30.000Z', + subject: pullRequest, + }, + }); + + const projection = projectFastAgentCanonicalEvents([ + merged, + staleChildClaim, + ]); + expect(projection.currentStateEventIds).toEqual(['provider-merged']); + }); + + it.each([ + ['reopened after closing', 'closed', 'open'], + ['returned to draft after ready', 'open', 'draft'], + ])( + 'does not pin an earlier state when a pull request is %s', + (_case, earlier, later) => { + // Reverse transitions are legitimate. Nothing may outrank the freshest + // provider observation here, because no provider gives a monotonic + // pull-request lifecycle version to order these by. + const pullRequest = { + type: 'pull_request', + id: 'https://example/pull/3', + }; + const earlierState = event({ + id: `pr-${earlier}`, + sequence: 1, + state: earlier, + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:10.000Z', + subject: pullRequest, + }, + }); + const laterState = event({ + id: `pr-${later}`, + sequence: 2, + state: later, + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:20.000Z', + subject: pullRequest, + }, + }); + + const projection = projectFastAgentCanonicalEvents([ + earlierState, + laterState, + ]); + expect(projection.currentStateEventIds).toEqual([`pr-${later}`]); + expect( + JSON.stringify(renderFastAgentCanonicalHistory(projection)), + ).toContain(`pr-${later}`); + }, + ); + + it('never lets an opaque revision version outrank a later observation', () => { + // A review head SHA identifies a revision; it says nothing about order. + const pullRequest = { type: 'pull_request', id: 'https://example/pull/4' }; + const olderRevision = event({ + id: 'feedback-older', + sequence: 1, + state: 'reviewed', + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:10.000Z', + subject: pullRequest, + version: { scheme: 'opaque', value: 'sha-older' }, + }, + }); + const newerRevision = event({ + id: 'feedback-newer', + sequence: 2, + state: 'approved', + semantics: { + kind: 'current_state_assertion', + authority: 'source_control', + observedAt: '2026-01-01T00:00:20.000Z', + subject: pullRequest, + version: { scheme: 'opaque', value: 'sha-newer' }, + }, + }); + + expect( + projectFastAgentCanonicalEvents([olderRevision, newerRevision]) + .currentStateEventIds, + ).toEqual(['feedback-newer']); + }); + + it('renders a cold rebuild as the warm prefix plus its canonical suffix', () => { + const history = [ + event({ + id: 'child-report', + sequence: 1, + state: 'The delegated task pushed a branch.', + semantics: { + kind: 'historical_observation', + authority: 'delegated_task', + observedAt: '2026-01-01T00:00:10.000Z', + subject: { type: 'task_run', id: '7' }, + }, + }), + event({ + id: 'artifact-v1', + sequence: 2, + state: 'published:1', + semantics: { + kind: 'state_change', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:11.000Z', + subject: { type: 'artifact', id: 'artifact-1' }, + version: { scheme: 'monotonic_number', value: 1 }, + }, + }), + event({ + id: 'human-question', + sequence: 3, + state: 'Where did that land?', + semantics: { + kind: 'historical_observation', + authority: 'human', + observedAt: '2026-01-01T00:00:12.000Z', + }, + }), + ]; + // What a warm session already holds, plus the delta it would receive. + const warmPrefix = renderFastAgentCanonicalHistory( + projectFastAgentCanonicalEvents(history.slice(0, 2)), + ); + const warmSuffix = renderFastAgentCanonicalHistory( + projectFastAgentCanonicalEvents(history), + { excludeEventId: 'child-report' }, + ).slice(1); + const cold = renderFastAgentCanonicalHistory( + projectFastAgentCanonicalEvents(history), + ); + + expect([...warmPrefix, ...warmSuffix]).toEqual(cold); + }); + + describe('unrecognized semantics', () => { + function withRawSemantics( + id: string, + sequence: number, + raw: Record, + ): FastAgentMessage { + const base = event({ + id, + sequence, + state: 'x', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:10.000Z', + subject: setupSubject, + }, + }); + return { + ...base, + metadata: { + ...base.metadata, + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: raw, + }, + }; + } + + it.each([ + ['an unknown authority', { authority: 'from_the_future' }], + ['an unknown kind', { kind: 'speculation' }], + [ + 'a non-finite monotonic version', + { + version: { scheme: 'monotonic_number', value: Number.NaN }, + }, + ], + ])('rejects %s instead of ranking it', (_case, override) => { + const valid = event({ + id: 'valid-claim', + sequence: 1, + state: 'valid', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:10.000Z', + subject: setupSubject, + }, + }); + const unrankable = withRawSemantics('unrankable-claim', 2, { + schemaVersion: 1, + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:20.000Z', + sourceEventId: 'unrankable-claim', + subject: setupSubject, + state: 'x', + ...override, + }); + + const projection = projectFastAgentCanonicalEvents([valid, unrankable]); + // The unrankable claim cannot compete for current state, and the valid + // claim is still selected rather than compared against NaN. + expect(projection.currentStateEventIds).toEqual(['valid-claim']); + expect( + projection.events.find( + ({ event }) => event.eventId === 'unrankable-claim', + ), + ).toMatchObject({ + semantics: null, + classification: 'historical_relevant', + }); + }); + }); + + describe('attachment collection', () => { + function imagePrompt( + id: string, + sequence: number, + blocks: FastAgentMessage['contentBlocks'], + ): FastAgentMessage { + const base = event({ + id, + sequence, + state: 'prompt', + semantics: { + kind: 'historical_observation', + authority: 'human', + observedAt: new Date(sequence).toISOString(), + }, + }); + return { ...base, role: 'user', contentBlocks: blocks }; + } + + it('rebuilds data URLs newest first and ignores unusable blocks', () => { + const projection = projectFastAgentCanonicalEvents([ + imagePrompt('older', 1, [{ type: 'text', text: 'no attachment here' }]), + imagePrompt('malformed', 2, [ + { type: 'image', mimeType: 'text/plain', data: 'bm90LWFuLWltYWdl' }, + { type: 'image', mimeType: 'image/png', data: '' }, + ]), + imagePrompt('newest', 3, [ + { type: 'image', mimeType: 'image/png', data: 'dXNhYmxl' }, + ]), + ]); + + expect(collectFastAgentCanonicalAttachments(projection)).toEqual([ + { + eventId: 'newest', + mime: 'image/png', + url: 'data:image/png;base64,dXNhYmxl', + }, + ]); + }); + + it('bounds how many attachments one rebuild restores', () => { + const projection = projectFastAgentCanonicalEvents( + Array.from( + { length: FAST_AGENT_CANONICAL_ATTACHMENT_LIMIT + 3 }, + (_, index) => + imagePrompt(`prompt-${index}`, index + 1, [ + { type: 'image', mimeType: 'image/png', data: `aW1hZ2U${index}` }, + ]), + ), + ); + + const restored = collectFastAgentCanonicalAttachments(projection); + expect(restored).toHaveLength(FAST_AGENT_CANONICAL_ATTACHMENT_LIMIT); + // Newest first, so the oldest prompts fall outside the bound. + expect(restored[0]?.eventId).toBe( + `prompt-${FAST_AGENT_CANONICAL_ATTACHMENT_LIMIT + 2}`, + ); + }); + + it('skips the excluded current event', () => { + const projection = projectFastAgentCanonicalEvents([ + imagePrompt('history', 1, [ + { type: 'image', mimeType: 'image/png', data: 'aGlzdG9yeQ==' }, + ]), + imagePrompt('current', 2, [ + { type: 'image', mimeType: 'image/png', data: 'Y3VycmVudA==' }, + ]), + ]); + + expect( + collectFastAgentCanonicalAttachments(projection, { + excludeEventId: 'current', + }).map(({ eventId }) => eventId), + ).toEqual(['history']); + }); + }); + describe('semantics validation', () => { + function withSemantics( + semantics: Record, + ): FastAgentMessage { + const row = event({ + id: 'candidate', + sequence: 1, + state: 'yellow', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:00.000Z', + subject: setupSubject, + }, + }); + return { + ...row, + metadata: { + ...row.metadata, + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: semantics, + }, + }; + } + + // `in` would accept these: every object inherits them from its prototype, + // and ranking a function makes the ordering comparison NaN, which would + // silently destroy the total order the reducer depends on. + it.each(['toString', 'constructor', 'valueOf', 'hasOwnProperty'])( + 'rejects inherited object member %s as a kind or an authority', + (inherited) => { + expect( + readFastAgentEventSemantics( + withSemantics({ + schemaVersion: 1, + kind: inherited, + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:00.000Z', + sourceEventId: 'candidate', + }), + ), + ).toBeNull(); + expect( + readFastAgentEventSemantics( + withSemantics({ + schemaVersion: 1, + kind: 'current_state_assertion', + authority: inherited, + observedAt: '2026-01-01T00:00:00.000Z', + sourceEventId: 'candidate', + }), + ), + ).toBeNull(); + }, + ); + + it('keeps one unrankable claim from reordering the claims around it', () => { + const rankable = event({ + id: 'green-v11', + sequence: 2, + state: 'green', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:11.000Z', + subject: setupSubject, + version: { scheme: 'monotonic_number', value: 11 }, + }, + }); + const unrankable = withSemantics({ + schemaVersion: 1, + kind: 'constructor', + authority: 'constructor', + observedAt: '2026-01-01T00:00:99.000Z', + sourceEventId: 'candidate', + subject: setupSubject, + state: 'bogus', + }); + + const projection = projectFastAgentCanonicalEvents([ + unrankable, + rankable, + ]); + + expect(projection.currentStateEventIds).toEqual(['green-v11']); + // Unsemantic history, not a state claim that could win the subject. + expect( + projection.events.find(({ event: row }) => row.eventId === 'candidate') + ?.classification, + ).toBe('historical_relevant'); + }); + + it('announces the current input exactly as rebuilt history does', () => { + const row = event({ + id: 'shared-shape', + sequence: 1, + state: 'yellow', + semantics: { + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: '2026-01-01T00:00:10.000Z', + subject: setupSubject, + }, + }); + const projection = projectFastAgentCanonicalEvents([row]); + const projected = projection.events[0]!; + + const rendered = renderFastAgentCanonicalHistory(projection)[0]; + const context = renderFastAgentCanonicalEventContext({ + eventId: row.eventId, + classification: projected.classification, + admittedAt: row.createdAt, + semantics: projected.semantics!, + }); + + expect(String(rendered?.content)).toContain(context); + expect(context).toContain('"classification":"current"'); + expect(context).toContain('"admittedAt":'); + }); + }); +}); diff --git a/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-conversation-repository.test.ts b/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-conversation-repository.test.ts index 18e1e9b85..8ed672354 100644 --- a/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-conversation-repository.test.ts +++ b/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-conversation-repository.test.ts @@ -625,6 +625,102 @@ describe('Fast conversation repository', () => { ).resolves.toMatchObject({ compatibilityMessages: visibleHistory }); }); + it('allocates deterministic canonical sequence under concurrent admission and preserves it on replay', async () => { + const user = await createUser(); + const session = await fastAgentConversationRepository.getOrCreate({ + userId: user.id, + conversation: slackConversation, + }); + const observedAt = new Date('2026-01-01T00:00:00.000Z'); + const writes = Array.from({ length: 12 }, (_, index) => ({ + eventId: `concurrent-${index}`, + turnId: `turn-${index}`, + turnSeq: 0, + ts: observedAt.getTime() + index, + observedAt, + eventType: 'roomote_runtime.user_prompt' as const, + role: 'user' as const, + contentBlocks: [{ type: 'text' as const, text: `message-${index}` }], + metadata: { visibleInTranscript: true, turnSource: 'human' }, + payload: {}, + source: 'slack', + })); + + const admitted = await Promise.all( + writes.map((message) => + fastAgentConversationRepository.upsertMessage({ + conversationId: session.id, + message, + insertOnly: true, + }), + ), + ); + expect( + admitted + .map(({ conversationSeq }) => conversationSeq) + .sort((left, right) => Number(left) - Number(right)), + ).toEqual(Array.from({ length: 12 }, (_, index) => index + 1)); + + const replay = await fastAgentConversationRepository.upsertMessage({ + conversationId: session.id, + message: writes[4]!, + insertOnly: true, + }); + expect(replay).toMatchObject({ + inserted: false, + conversationSeq: admitted[4]!.conversationSeq, + }); + const rows = await db.query.fastAgentMessages.findMany({ + where: eq(fastAgentMessages.conversationId, session.id), + }); + expect(rows).toHaveLength(12); + expect( + rows.every((row) => row.observedAt?.getTime() === observedAt.getTime()), + ).toBe(true); + }); + + it('orders N-1 null-sequence rows before the next canonical admission', async () => { + const user = await createUser(); + const session = await fastAgentConversationRepository.getOrCreate({ + userId: user.id, + conversation: slackConversation, + }); + await db.insert(fastAgentMessages).values({ + conversationId: session.id, + eventId: 'legacy-event', + turnId: 'legacy-turn', + turnSeq: 0, + ts: 1, + eventType: 'roomote_runtime.user_prompt', + role: 'user', + contentBlocks: [{ type: 'text', text: 'Legacy input' }], + payload: {}, + }); + + const admitted = await fastAgentConversationRepository.upsertMessage({ + conversationId: session.id, + message: { + eventId: 'new-event', + turnId: 'new-turn', + turnSeq: 0, + ts: 2, + eventType: 'roomote_runtime.user_prompt', + role: 'user', + contentBlocks: [{ type: 'text', text: 'New input' }], + payload: {}, + }, + }); + const rows = await db.query.fastAgentMessages.findMany({ + where: eq(fastAgentMessages.conversationId, session.id), + }); + expect( + Object.fromEntries( + rows.map(({ eventId, conversationSeq }) => [eventId, conversationSeq]), + ), + ).toEqual({ 'legacy-event': 1, 'new-event': 2 }); + expect(admitted.conversationSeq).toBe(2); + }); + it('persists the canonical OpenCode session identity', async () => { const user = await createUser(); const session = await fastAgentConversationRepository.getOrCreate({ diff --git a/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-service.test.ts b/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-service.test.ts index b38c5ef4b..15437927c 100644 --- a/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-service.test.ts +++ b/packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-service.test.ts @@ -49,6 +49,8 @@ const mocks = vi.hoisted(() => ({ scheduleDurableRetry: vi.fn(), findActiveRetryNotice: vi.fn(), loadTurnAttempt: vi.fn(), + loadCanonicalMessages: vi.fn(), + loadAdmittedSemantics: vi.fn(), getUnifiedSession: vi.fn(), touchSessionActivity: vi.fn(), getSessionForTask: vi.fn(), @@ -130,6 +132,8 @@ vi.mock('../fast-agent-conversation-repository', () => ({ scheduleFastAgentDurableTurnRetry: mocks.scheduleDurableRetry, findFastAgentActiveInferenceRetryNotice: mocks.findActiveRetryNotice, loadFastAgentTurnAttemptSummary: mocks.loadTurnAttempt, + loadFastAgentCanonicalMessages: mocks.loadCanonicalMessages, + loadFastAgentAdmittedEventSemantics: mocks.loadAdmittedSemantics, })); vi.mock('../../available-environments', () => ({ @@ -321,10 +325,12 @@ vi.mock('../fast-agent-turn-lock', () => ({ })); import { buildFastSessionUrl } from '@roomote/communication'; +import type { FastAgentMessage } from '@roomote/db/server'; import { ACP_ENVELOPE_EVENT_TYPES, ACP_UI_TOOL_OUTPUT_MAX_CHARS, ALL_REPOSITORIES, + FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY, NO_REPOSITORIES, } from '@roomote/types'; import { McpToolCallError } from '../../mcp-tool-client'; @@ -348,6 +354,7 @@ import { registerFastAgentTurnActivity, } from '../fast-agent-turn-lock'; import { FAST_RESPONDING_LEASE_RENEW_MS } from '../fast-agent-constants'; +import { projectFastAgentCanonicalEvents } from '../fast-agent-canonical-projection'; const baseParams = { question: 'What does this service do?', @@ -513,6 +520,8 @@ describe('answerFastAgentQuestion native OpenCode tools', () => { }, prompt: null, }); + mocks.loadCanonicalMessages.mockResolvedValue([]); + mocks.loadAdmittedSemantics.mockResolvedValue(null); mocks.getActiveTasks.mockResolvedValue([]); mocks.listCustomSkills.mockResolvedValue([]); mocks.getCustomSkill.mockResolvedValue(null); @@ -1138,6 +1147,8 @@ describe('answerFastAgentQuestion native OpenCode tools', () => { expect(mocks.setOpenCodeSession).toHaveBeenCalledWith({ sessionId: 'conversation-1', openCodeSessionId: 'opencode-session-1', + projectionHash: expect.any(String), + projectedThroughSequence: null, }); }); @@ -1665,6 +1676,975 @@ describe('answerFastAgentQuestion native OpenCode tools', () => { ); }); + it('does not infer for a queued state assertion superseded before consumption', async () => { + const canonicalState = ( + id: string, + sequence: number, + state: string, + version: number, + ): FastAgentMessage => ({ + id, + conversationId: 'conversation-1', + eventId: `${id}:user`, + conversationSeq: sequence, + turnId: id, + turnSeq: 0, + ts: version, + observedAt: new Date(version), + eventType: ACP_ENVELOPE_EVENT_TYPES.UserPrompt, + role: 'user', + contentBlocks: [{ type: 'text', text: state }], + metadata: { + visibleInTranscript: false, + turnSource: 'platform_event', + platformEventKind: 'setup', + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: { + schemaVersion: 1, + kind: 'current_state_assertion', + authority: 'roomote_runtime', + observedAt: new Date(version).toISOString(), + sourceEventId: id, + subject: { type: 'setup_session', id: 'conversation-1' }, + version: { scheme: 'monotonic_number', value: version }, + state, + }, + }, + payload: {}, + source: 'web', + nativeSessionId: null, + nativeMessageId: null, + createdAt: new Date(sequence), + updatedAt: new Date(sequence), + }); + mocks.loadCanonicalMessages.mockResolvedValue([ + canonicalState('green-v11', 1, 'green', 11), + canonicalState('yellow-v12', 2, 'yellow', 12), + ]); + + await expect( + answerFastAgentQuestion({ + ...baseParams, + currentMessageId: 'green-v11', + turnSource: 'platform_event', + platformEventKind: 'setup', + platformEventVisibility: 'required', + setupSnapshot: '{"source":"green"}', + durableAdmission: { eventId: 'durable-green-v11' }, + adapter: callbacks(), + }), + ).resolves.toBe(''); + + expect(mocks.runSession).not.toHaveBeenCalled(); + expect(mocks.markDurableDelivered).toHaveBeenCalledWith( + 'durable-green-v11', + ); + }); + + it.each([ + [ + 'an image-only turn', + [{ type: 'image', mimeType: 'image/png', data: 'aW1hZ2Utb25sea==' }], + ['data:image/png;base64,aW1hZ2Utb25sea=='], + ], + [ + 'a mixed text and image turn', + [ + { type: 'text', text: 'Why does this screen look wrong?' }, + { type: 'image', mimeType: 'image/jpeg', data: 'bWl4ZWQtaW1hZ2U=' }, + ], + ['data:image/jpeg;base64,bWl4ZWQtaW1hZ2U='], + ], + ])( + 'restores attachments from %s into a rebuilt prompt', + async (_case, contentBlocks, expectedUrls) => { + const priorPrompt: FastAgentMessage = { + id: 'turn-one', + conversationId: 'conversation-1', + eventId: 'turn-one:user', + conversationSeq: 1, + turnId: 'turn-one', + turnSeq: 0, + ts: 1, + observedAt: new Date(1), + eventType: ACP_ENVELOPE_EVENT_TYPES.UserPrompt, + role: 'user', + contentBlocks: contentBlocks as FastAgentMessage['contentBlocks'], + metadata: { + visibleInTranscript: true, + turnSource: 'human', + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: { + schemaVersion: 1, + kind: 'historical_observation', + authority: 'human', + observedAt: new Date(1).toISOString(), + sourceEventId: 'turn-one', + }, + }, + payload: {}, + source: 'slack', + nativeSessionId: null, + nativeMessageId: null, + createdAt: new Date(1), + updatedAt: new Date(1), + }; + mocks.loadCanonicalMessages.mockResolvedValue([priorPrompt]); + // A rebuild is the path that has to carry earlier attachments; a warm + // session still holds them natively. + mocks.runSession.mockImplementation( + ({ + bootstrapPrompt, + execute, + }: { + bootstrapPrompt: () => string; + execute: ( + session: { id?: string }, + selectedPrompt: string, + context: { path: string; validateSession: boolean }, + ) => Promise; + }) => + execute({}, bootstrapPrompt(), { + path: 'cold_rebuild', + validateSession: false, + }), + ); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + const [promptParams] = mocks.generateText.mock.calls[0]!; + expect( + promptParams.files?.map(({ url }: { url: string }) => url), + ).toEqual(expectedUrls); + // The turn itself is still represented in the rebuilt history. + expect(promptParams.prompt).toContain('canonical_event_attachments'); + }, + ); + + describe('restored attachment delivery on a rebuild', () => { + function historicalImagePrompt(): FastAgentMessage { + return { + id: 'turn-one', + conversationId: 'conversation-1', + eventId: 'turn-one:user', + conversationSeq: 1, + turnId: 'turn-one', + turnSeq: 0, + ts: 1, + observedAt: new Date(1), + eventType: ACP_ENVELOPE_EVENT_TYPES.UserPrompt, + role: 'user', + contentBlocks: [ + { type: 'image', mimeType: 'image/png', data: 'aGlzdG9yaWNhbA==' }, + ], + metadata: { + visibleInTranscript: true, + turnSource: 'human', + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: { + schemaVersion: 1, + kind: 'historical_observation', + authority: 'human', + observedAt: new Date(1).toISOString(), + sourceEventId: 'turn-one', + }, + }, + payload: {}, + source: 'slack', + nativeSessionId: null, + nativeMessageId: null, + createdAt: new Date(1), + updatedAt: new Date(1), + }; + } + + beforeEach(() => { + mocks.loadCanonicalMessages.mockResolvedValue([historicalImagePrompt()]); + mocks.runSession.mockImplementation( + ({ + bootstrapPrompt, + execute, + }: { + bootstrapPrompt: () => string; + execute: ( + session: { id?: string }, + selectedPrompt: string, + context: { path: string; validateSession: boolean }, + ) => Promise; + }) => + execute({}, bootstrapPrompt(), { + path: 'cold_rebuild', + validateSession: false, + }), + ); + }); + + it('holds restored images for a session model that cannot view them', async () => { + mocks.resolveImageDelivery.mockResolvedValue({ + delivery: 'helper', + model: 'openrouter/openai/gpt-5.4', + helperModel: 'openrouter/google/gemini-3.8-flash', + }); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + const [promptParams] = mocks.generateText.mock.calls[0]!; + // Held rather than attached, and announced with an inspectable ID. + expect(promptParams.files).toBeUndefined(); + expect(promptParams.prompt).toContain('Image attachments: image-1'); + expect(promptParams.prompt).toContain('inspect_images'); + }); + + it('holds restored images once when a clean retry rebuilds the prompt', async () => { + mocks.resolveImageDelivery.mockResolvedValue({ + delivery: 'helper', + model: 'openrouter/openai/gpt-5.4', + helperModel: 'openrouter/google/gemini-3.8-flash', + }); + let attempts = 0; + mocks.generateText.mockImplementation(async () => { + attempts += 1; + if (attempts === 1) throw new Error('TypeError: fetch failed'); + return 'Recovered.'; + }); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + expect(attempts).toBe(2); + const retryPrompt = mocks.generateText.mock.calls.at(-1)![0]; + // The retry restates the notice for the same held image rather than + // dropping it, and holding stays idempotent, so no second ID is + // reserved for the same bytes. + expect(retryPrompt.files).toBeUndefined(); + expect(retryPrompt.prompt).toContain('Image attachments: image-1'); + expect(retryPrompt.prompt).not.toContain('image-2'); + }); + + it('restores historical images when a text-only warm turn falls back to a clean retry', async () => { + // The reviewed gap: a text-only turn never resolves a delivery mode, + // so the retry used to rebuild the bootstrap with no restored images + // at all even though it replays the conversation that carried them. + mocks.resolveImageDelivery.mockResolvedValue({ + delivery: 'direct', + model: 'openrouter/openai/gpt-5.6-terra', + }); + mocks.runSession.mockImplementation( + ({ + prompt, + execute, + }: { + prompt: string; + execute: ( + session: { id?: string }, + selectedPrompt: string, + context: { path: string; validateSession: boolean }, + ) => Promise; + }) => + execute({ id: 'opencode-session-1' }, prompt, { + path: 'warm', + validateSession: false, + }), + ); + let attempts = 0; + mocks.generateText.mockImplementation(async () => { + attempts += 1; + if (attempts === 1) throw new Error('TypeError: fetch failed'); + return 'Recovered.'; + }); + + // No `images`: the turn itself carries nothing to deliver. + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + expect(attempts).toBe(2); + const warmPrompt = mocks.generateText.mock.calls[0]![0]; + const retryPrompt = mocks.generateText.mock.calls.at(-1)![0]; + // The warm attempt neither resolved delivery nor carried any file. + expect(warmPrompt.files).toBeUndefined(); + // The rebuilt retry replays the historical image as a real file. + expect(retryPrompt.files).toHaveLength(1); + expect(mocks.captureInferenceContext).toHaveBeenLastCalledWith( + expect.objectContaining({ + sessionPath: 'cold_rebuild', + promptKind: 'clean_retry_bootstrap', + attachedImageCount: 1, + }), + ); + }); + + it('announces restored images to a helper model when a text-only warm turn retries', async () => { + mocks.resolveImageDelivery.mockResolvedValue({ + delivery: 'helper', + model: 'openrouter/openai/gpt-5.6-terra', + helperModel: 'openrouter/google/gemini-3.8-flash', + }); + mocks.runSession.mockImplementation( + ({ + prompt, + execute, + }: { + prompt: string; + execute: ( + session: { id?: string }, + selectedPrompt: string, + context: { path: string; validateSession: boolean }, + ) => Promise; + }) => + execute({ id: 'opencode-session-1' }, prompt, { + path: 'warm', + validateSession: false, + }), + ); + let attempts = 0; + mocks.generateText.mockImplementation(async () => { + attempts += 1; + if (attempts === 1) throw new Error('TypeError: fetch failed'); + return 'Recovered.'; + }); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + expect(attempts).toBe(2); + const retryPrompt = mocks.generateText.mock.calls.at(-1)![0]; + // Held for a model that cannot view them, and announced for + // `inspect_images` rather than pushed at it as raw files. + expect(retryPrompt.files).toBeUndefined(); + expect(retryPrompt.prompt).toContain('Image attachments: image-1'); + expect(retryPrompt.prompt).toContain('inspect_images'); + }); + + it('holds restored images a warm attempt never held when a retry rebuilds', async () => { + // The divergence that matters: delivery is already resolved for the + // turn's own image, but no rebuild has held the restored one yet. The + // retry must prepare it rather than leave the historical image out. + mocks.resolveImageDelivery.mockResolvedValue({ + delivery: 'helper', + model: 'openrouter/openai/gpt-5.4', + helperModel: 'openrouter/google/gemini-3.8-flash', + }); + mocks.runSession.mockImplementation( + ({ + prompt, + execute, + }: { + prompt: string; + execute: ( + session: { id?: string }, + selectedPrompt: string, + context: { path: string; validateSession: boolean }, + ) => Promise; + }) => + execute({ id: 'opencode-session-1' }, prompt, { + path: 'warm', + validateSession: false, + }), + ); + let attempts = 0; + mocks.generateText.mockImplementation(async () => { + attempts += 1; + if (attempts === 1) throw new Error('TypeError: fetch failed'); + return 'Recovered.'; + }); + + await answerFastAgentQuestion({ + ...baseParams, + images: ['data:image/png;base64,b3duLWltYWdl'], + adapter: callbacks(), + }); + + expect(attempts).toBe(2); + const warmPrompt = mocks.generateText.mock.calls[0]![0]; + const retryPrompt = mocks.generateText.mock.calls.at(-1)![0]; + // The warm attempt held only the turn's own image. + expect(warmPrompt.prompt).toContain('Image attachments: image-1'); + expect(warmPrompt.prompt).not.toContain('image-2'); + // The rebuilt retry announces the restored one too. + expect(retryPrompt.files).toBeUndefined(); + expect(retryPrompt.prompt).toContain('image-2'); + }); + + it('attaches restored images to a clean retry that takes them directly', async () => { + mocks.resolveImageDelivery.mockResolvedValue({ + delivery: 'direct', + model: 'openrouter/openai/gpt-5.4', + }); + let attempts = 0; + mocks.generateText.mockImplementation(async () => { + attempts += 1; + if (attempts === 1) throw new Error('TypeError: fetch failed'); + return 'Recovered.'; + }); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + expect(attempts).toBe(2); + const retryPrompt = mocks.generateText.mock.calls.at(-1)![0]; + expect(retryPrompt.files).toHaveLength(1); + expect(retryPrompt.prompt).not.toContain('Image attachments:'); + }); + + it('drops restored images when no configured model accepts image input', async () => { + mocks.resolveImageDelivery.mockResolvedValue({ + delivery: 'unsupported', + }); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + const [promptParams] = mocks.generateText.mock.calls[0]!; + expect(promptParams.files).toBeUndefined(); + // Nothing is announced as inspectable, because nothing could read it, + // but the rebuilt history still records that the turn had attachments. + expect(promptParams.prompt).not.toContain('Image attachments:'); + expect(promptParams.prompt).toContain('canonical_event_attachments'); + }); + }); + + describe('canonical history eligibility', () => { + function coldRebuild() { + mocks.runSession.mockImplementation( + ({ + bootstrapPrompt, + execute, + }: { + bootstrapPrompt: () => string; + execute: ( + session: { id?: string }, + selectedPrompt: string, + context: { path: string; validateSession: boolean }, + ) => Promise; + }) => + execute({}, bootstrapPrompt(), { + path: 'cold_rebuild', + validateSession: false, + }), + ); + } + + it('does not fall back to the legacy transcript when canonical history is legitimately empty', async () => { + coldRebuild(); + mocks.getSession.mockResolvedValue({ + id: 'conversation-1', + compatibilityMessages: [ + { role: 'user', content: 'Legacy question' }, + { role: 'assistant', content: 'Legacy answer' }, + ], + openCodeSessionId: null, + }); + // A canonical event exists, so canonical history is authoritative; it + // renders to nothing only because a tool row is not presentable. + mocks.loadCanonicalMessages.mockResolvedValue([ + { + id: 'turn-one-tool', + conversationId: 'conversation-1', + eventId: 'turn-one:tool:0', + conversationSeq: 1, + turnId: 'turn-one', + turnSeq: 1, + ts: 1, + observedAt: new Date(1), + eventType: ACP_ENVELOPE_EVENT_TYPES.ToolResult, + role: 'tool', + contentBlocks: [{ type: 'text', text: 'tool output' }], + metadata: { visibleInTranscript: true }, + payload: {}, + source: 'slack', + nativeSessionId: null, + nativeMessageId: null, + createdAt: new Date(1), + updatedAt: new Date(1), + } as FastAgentMessage, + ]); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + const prompt = mocks.generateText.mock.calls[0]![0].prompt; + expect(prompt).not.toContain('Legacy answer'); + expect(prompt).not.toContain('Legacy question'); + }); + + it('rebuilds a pre-canonical session from its legacy transcript', async () => { + coldRebuild(); + mocks.getSession.mockResolvedValue({ + id: 'conversation-1', + compatibilityMessages: [ + { role: 'user', content: 'Legacy question' }, + { role: 'assistant', content: 'Legacy answer' }, + ], + openCodeSessionId: null, + }); + // No canonical event other than this turn's own input, which is what a + // session recorded before the canonical log looks like. + mocks.loadCanonicalMessages.mockResolvedValue([]); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + const prompt = mocks.generateText.mock.calls[0]![0].prompt; + expect(prompt).toContain('Legacy answer'); + }); + }); + + it('reuses admitted semantics instead of restating the input as observed now', async () => { + const admitted = { + schemaVersion: 1 as const, + kind: 'historical_observation' as const, + authority: 'delegated_task' as const, + observedAt: '2026-01-01T00:00:00.000Z', + sourceEventId: 'fast-parent-child-message:child-1', + subject: { type: 'task_run', id: '42' }, + }; + mocks.loadAdmittedSemantics.mockResolvedValue(admitted); + + await answerFastAgentQuestion({ + ...baseParams, + question: '{"type":"child_message"}', + turnSource: 'platform_event', + adapter: callbacks(), + }); + + expect(mocks.loadAdmittedSemantics).toHaveBeenCalledWith( + 'conversation-1', + '100.2:user', + ); + const prompt = mocks.upsertMessage.mock.calls + .map(([input]) => input.message) + .find((message) => message.eventId === '100.2:user'); + // The admitted record travels through unchanged, including the instant + // the event was actually observed. + expect(prompt?.metadata?.[FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]).toEqual( + admitted, + ); + expect(prompt?.observedAt).toEqual(new Date(admitted.observedAt)); + }); + + it('writes no semantics of its own when the admitted record cannot be read', async () => { + mocks.loadAdmittedSemantics.mockRejectedValue(new Error('database down')); + + await answerFastAgentQuestion({ + ...baseParams, + question: '{"type":"task_settled"}', + turnSource: 'platform_event', + adapter: callbacks(), + }); + + const prompt = mocks.upsertMessage.mock.calls + .map(([input]) => input.message) + .find((message) => message.eventId === '100.2:user'); + // A failed read cannot tell an admitted record from an absent one, so + // the turn leaves the key alone rather than replacing a queued event's + // current-state assertion with a human input's weaker shape. + expect(prompt?.metadata).not.toHaveProperty( + FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY, + ); + expect(prompt?.metadata?.turnSource).toBe('platform_event'); + }); + + it('describes an input that no admission recorded', async () => { + mocks.loadAdmittedSemantics.mockResolvedValue(null); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + const prompt = mocks.upsertMessage.mock.calls + .map(([input]) => input.message) + .find((message) => message.eventId === '100.2:user'); + expect( + prompt?.metadata?.[FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY], + ).toMatchObject({ + kind: 'historical_observation', + authority: 'human', + sourceEventId: '100.2', + }); + }); + + it('does not restore historical attachments into a warm delta', async () => { + const priorPrompt: FastAgentMessage = { + id: 'turn-one', + conversationId: 'conversation-1', + eventId: 'turn-one:user', + conversationSeq: 1, + turnId: 'turn-one', + turnSeq: 0, + ts: 1, + observedAt: new Date(1), + eventType: ACP_ENVELOPE_EVENT_TYPES.UserPrompt, + role: 'user', + contentBlocks: [ + { type: 'image', mimeType: 'image/png', data: 'd2FybS1pbWFnZQ==' }, + ], + metadata: { + visibleInTranscript: true, + turnSource: 'human', + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: { + schemaVersion: 1, + kind: 'historical_observation', + authority: 'human', + observedAt: new Date(1).toISOString(), + sourceEventId: 'turn-one', + }, + }, + payload: {}, + source: 'slack', + nativeSessionId: 'opencode-session-1', + nativeMessageId: null, + createdAt: new Date(1), + updatedAt: new Date(1), + }; + mocks.loadCanonicalMessages.mockResolvedValue([priorPrompt]); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + const [promptParams] = mocks.generateText.mock.calls[0]!; + expect(promptParams.files).toBeUndefined(); + }); + + it('reuses the native session for an ordinary follow-up turn already represented by its watermark', async () => { + // Turn one's prompt is canonical history with semantics, and the stored + // watermark covers it, so the follow-up must continue warm. + const priorPrompt: FastAgentMessage = { + id: 'turn-one', + conversationId: 'conversation-1', + eventId: 'turn-one:user', + conversationSeq: 1, + turnId: 'turn-one', + turnSeq: 0, + ts: 1, + observedAt: new Date(1), + eventType: ACP_ENVELOPE_EVENT_TYPES.UserPrompt, + role: 'user', + contentBlocks: [{ type: 'text', text: 'What does this service do?' }], + metadata: { + visibleInTranscript: true, + turnSource: 'human', + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: { + schemaVersion: 1, + kind: 'historical_observation', + authority: 'human', + observedAt: new Date(1).toISOString(), + sourceEventId: 'turn-one', + }, + }, + payload: {}, + source: 'slack', + nativeSessionId: 'opencode-session-1', + nativeMessageId: null, + createdAt: new Date(1), + updatedAt: new Date(1), + }; + const priorReply: FastAgentMessage = { + ...priorPrompt, + id: 'turn-one-reply', + eventId: 'turn-one:assistant:0', + conversationSeq: 2, + role: 'assistant', + eventType: ACP_ENVELOPE_EVENT_TYPES.AssistantMessage, + contentBlocks: [{ type: 'text', text: 'It coordinates requests.' }], + metadata: { visibleInTranscript: true }, + }; + mocks.loadCanonicalMessages.mockResolvedValue([priorPrompt, priorReply]); + mocks.getSession.mockResolvedValue({ + id: 'conversation-1', + compatibilityMessages: [], + openCodeSessionId: 'opencode-session-1', + openCodeProjectionHash: projectFastAgentCanonicalEvents([ + priorPrompt, + priorReply, + ]).stateHash, + openCodeProjectedThroughSeq: 1, + }); + + await answerFastAgentQuestion({ ...baseParams, adapter: callbacks() }); + + expect(mocks.invalidateSession).not.toHaveBeenCalled(); + expect(mocks.runSession).toHaveBeenCalledWith( + expect.objectContaining({ persistedSessionId: 'opencode-session-1' }), + ); + }); + + describe('delayed child report continuity', () => { + // The reported symptom: a delegated task report is queued while the + // parent is busy, a human turn corrects the picture in the meantime, and + // the report is only consumed afterwards. The report keeps the lower + // conversation sequence it was admitted with, so the newer turns are + // genuinely later canonical history than the event being executed. + const REPORT_EVENT_ID = 'fast-parent-child-message:child-message-1'; + + function canonicalRow(input: { + id: string; + eventId: string; + sequence: number; + role: 'user' | 'assistant'; + text: string; + observedAtMs: number; + semantics?: Record; + metadata?: Record; + }): FastAgentMessage { + return { + id: input.id, + conversationId: 'conversation-1', + eventId: input.eventId, + conversationSeq: input.sequence, + turnId: input.eventId.replace(/:(user|assistant:0)$/u, ''), + turnSeq: 0, + ts: input.observedAtMs, + observedAt: new Date(input.observedAtMs), + eventType: + input.role === 'user' + ? ACP_ENVELOPE_EVENT_TYPES.UserPrompt + : ACP_ENVELOPE_EVENT_TYPES.AssistantMessage, + role: input.role, + contentBlocks: [{ type: 'text', text: input.text }], + metadata: { + visibleInTranscript: true, + ...(input.metadata ?? {}), + ...(input.semantics + ? { + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: input.semantics, + } + : {}), + }, + payload: {}, + source: 'slack', + nativeSessionId: null, + nativeMessageId: null, + createdAt: new Date(input.observedAtMs), + updatedAt: new Date(input.observedAtMs), + }; + } + + // Admitted first, while the parent was busy: the stale report. This is + // the exact question text the durable queue builds for a child report. + const STALE_REPORT_QUESTION = `${JSON.stringify({ + type: 'child_message', + taskId: 'task-1', + runId: 42, + messageId: 'child-message-1', + purpose: 'progress', + message: 'The rollout is still blocked on the failing migration.', + })}`; + const staleReportRow = canonicalRow({ + id: 'report-row', + eventId: `${REPORT_EVENT_ID}:user`, + sequence: 10, + role: 'user', + text: STALE_REPORT_QUESTION, + observedAtMs: 1_000, + metadata: { + visibleInTranscript: false, + turnSource: 'platform_event', + platformEventKind: 'delegated_task', + }, + semantics: { + schemaVersion: 1, + kind: 'historical_observation', + authority: 'delegated_task', + observedAt: new Date(1_000).toISOString(), + sourceEventId: REPORT_EVENT_ID, + subject: { type: 'task_run', id: '42' }, + }, + }); + // Newer completed turns that corrected the picture in the meantime. + const newerHumanRow = canonicalRow({ + id: 'human-row', + eventId: 'human-correction:user', + sequence: 11, + role: 'user', + text: 'Correction: the migration was renumbered and the rollout is unblocked.', + observedAtMs: 2_000, + metadata: { turnSource: 'human' }, + semantics: { + schemaVersion: 1, + kind: 'historical_observation', + authority: 'human', + observedAt: new Date(2_000).toISOString(), + sourceEventId: 'human-correction', + }, + }); + const newerAssistantRow = canonicalRow({ + id: 'assistant-row', + eventId: 'human-correction:assistant:0', + sequence: 12, + role: 'assistant', + text: 'Understood, the rollout is unblocked and the migration is renumbered.', + observedAtMs: 2_500, + }); + + const reportTurnParams = { + ...baseParams, + question: STALE_REPORT_QUESTION, + currentMessageId: REPORT_EVENT_ID, + turnSource: 'platform_event' as const, + platformEventKind: 'delegated_task' as const, + }; + + beforeEach(() => { + mocks.loadCanonicalMessages.mockResolvedValue([ + staleReportRow, + newerHumanRow, + newerAssistantRow, + ]); + }); + + it('keeps the newer completed turns in the rebuilt context and preserves report provenance', async () => { + // Forced cold recovery: the native session is gone, so everything the + // model can see has to come from canonical history. + mocks.getSession.mockResolvedValue({ + id: 'conversation-1', + compatibilityMessages: [], + openCodeSessionId: null, + }); + mocks.runSession.mockImplementation( + ({ + bootstrapPrompt, + execute, + }: { + bootstrapPrompt: () => string; + execute: ( + session: { id?: string }, + selectedPrompt: string, + context: { path: string; validateSession: boolean }, + ) => Promise; + }) => + execute({}, bootstrapPrompt(), { + path: 'cold_rebuild', + validateSession: false, + }), + ); + + await answerFastAgentQuestion({ + ...reportTurnParams, + adapter: callbacks(), + }); + + const prompt = mocks.generateText.mock.calls[0]![0].prompt as string; + + // 1. Not missing context: both newer completed turns survive. + expect(prompt).toContain( + 'Correction: the migration was renumbered and the rollout is unblocked.', + ); + expect(prompt).toContain( + 'Understood, the rollout is unblocked and the migration is renumbered.', + ); + + // 2. Not an ordering error: the newer turns precede the report being + // executed, which is the last thing in the prompt. + const correctionAt = prompt.indexOf('Correction: the migration'); + const assistantAt = prompt.indexOf( + 'Understood, the rollout is unblocked', + ); + const reportAt = prompt.lastIndexOf( + 'still blocked on the failing migration', + ); + expect(correctionAt).toBeGreaterThan(-1); + expect(assistantAt).toBeGreaterThan(correctionAt); + expect(reportAt).toBeGreaterThan(assistantAt); + + // 3. Provenance is preserved, and it is what distinguishes the report + // from the newer turns: the report was observed earlier even though + // it is executed last. + expect(prompt).toContain('"authority":"delegated_task"'); + expect(prompt).toContain('"subject":{"type":"task_run","id":"42"}'); + expect(prompt).toContain( + `"observedAt":"${new Date(1_000).toISOString()}"`, + ); + expect(prompt).toContain( + `"observedAt":"${new Date(2_000).toISOString()}"`, + ); + }); + + it('continues warm without discarding the native transcript that holds the newer turns', async () => { + // Warm continuation sends only the delta, so the newer turns must stay + // in the native session rather than being rebuilt away. + mocks.getSession.mockResolvedValue({ + id: 'conversation-1', + compatibilityMessages: [], + openCodeSessionId: 'opencode-session-1', + openCodeProjectionHash: projectFastAgentCanonicalEvents([ + staleReportRow, + newerHumanRow, + newerAssistantRow, + ]).stateHash, + openCodeProjectedThroughSeq: 12, + }); + + await answerFastAgentQuestion({ + ...reportTurnParams, + adapter: callbacks(), + }); + + // The native session that already contains the newer turns is reused. + expect(mocks.invalidateSession).not.toHaveBeenCalled(); + expect(mocks.runSession).toHaveBeenCalledWith( + expect.objectContaining({ persistedSessionId: 'opencode-session-1' }), + ); + expect(mocks.captureInferenceContext).toHaveBeenCalledWith( + expect.objectContaining({ + sessionPath: 'warm', + promptKind: 'turn_delta', + }), + ); + // The delta still carries the report's provenance so its age is + // visible against the transcript it is appended to. + const delta = mocks.generateText.mock.calls[0]![0].prompt as string; + expect(delta).toContain('"authority":"delegated_task"'); + expect(delta).toContain( + `"observedAt":"${new Date(1_000).toISOString()}"`, + ); + }); + + it('gives the human turn after the report equivalent knowledge', async () => { + const reportReplyRow = canonicalRow({ + id: 'report-reply-row', + eventId: `${REPORT_EVENT_ID}:assistant:0`, + sequence: 13, + role: 'assistant', + text: 'Noted the task report.', + observedAtMs: 3_000, + }); + mocks.loadCanonicalMessages.mockResolvedValue([ + staleReportRow, + newerHumanRow, + newerAssistantRow, + reportReplyRow, + ]); + mocks.getSession.mockResolvedValue({ + id: 'conversation-1', + compatibilityMessages: [], + openCodeSessionId: null, + }); + mocks.runSession.mockImplementation( + ({ + bootstrapPrompt, + execute, + }: { + bootstrapPrompt: () => string; + execute: ( + session: { id?: string }, + selectedPrompt: string, + context: { path: string; validateSession: boolean }, + ) => Promise; + }) => + execute({}, bootstrapPrompt(), { + path: 'cold_rebuild', + validateSession: false, + }), + ); + + await answerFastAgentQuestion({ + ...baseParams, + question: 'Where does the rollout actually stand?', + currentMessageId: 'human-after-report', + adapter: callbacks(), + }); + + const prompt = mocks.generateText.mock.calls[0]![0].prompt as string; + // The correction, its reply, and the report all remain available, so a + // later human turn is not reasoning from a narrower context. + expect(prompt).toContain( + 'Correction: the migration was renumbered and the rollout is unblocked.', + ); + expect(prompt).toContain( + 'Understood, the rollout is unblocked and the migration is renumbered.', + ); + expect(prompt).toContain('still blocked on the failing migration'); + expect(prompt).toContain('"authority":"delegated_task"'); + }); + }); + it('leaves pending human rows for whole-turn delivery without a native-ready capability', async () => { vi.useFakeTimers(); try { @@ -4481,7 +5461,14 @@ describe('answerFastAgentQuestion native OpenCode tools', () => { { id: 'persisted-session' }, expect.objectContaining({ validateSession: true }), ); - expect(mocks.setOpenCodeSession).not.toHaveBeenCalled(); + // The session id is unchanged, but its projection watermark is recorded + // so the next ordinary turn can continue warm. + expect(mocks.setOpenCodeSession).toHaveBeenCalledWith({ + sessionId: 'conversation-1', + openCodeSessionId: 'persisted-session', + projectionHash: expect.any(String), + projectedThroughSequence: null, + }); }); it('rebuilds missing durable sessions and stores the replacement id', async () => { @@ -4523,6 +5510,8 @@ describe('answerFastAgentQuestion native OpenCode tools', () => { expect(mocks.setOpenCodeSession).toHaveBeenCalledWith({ sessionId: 'conversation-1', openCodeSessionId: 'replacement-session', + projectionHash: expect.any(String), + projectedThroughSequence: null, }); expect(mocks.getNativeRuntime).toHaveBeenCalledTimes(2); }); @@ -9895,6 +10884,8 @@ describe('answerFastAgentQuestion native OpenCode tools', () => { expect(mocks.setOpenCodeSession).toHaveBeenCalledWith({ sessionId: 'conversation-1', openCodeSessionId: 'opencode-session-1', + projectionHash: expect.any(String), + projectedThroughSequence: null, }); expect(mocks.invalidateSession).not.toHaveBeenCalled(); } finally { diff --git a/packages/cloud-agents/src/server/fast-agent/fast-agent-canonical-projection.ts b/packages/cloud-agents/src/server/fast-agent/fast-agent-canonical-projection.ts new file mode 100644 index 000000000..b021d1a57 --- /dev/null +++ b/packages/cloud-agents/src/server/fast-agent/fast-agent-canonical-projection.ts @@ -0,0 +1,393 @@ +import { createHash } from 'node:crypto'; + +import type { ModelMessage } from 'ai'; + +import type { FastAgentMessage } from '@roomote/db/server'; +import { + FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY, + FAST_AGENT_EVENT_SEMANTICS_VERSION, + type FastAgentEventAuthority, + type FastAgentEventProjectionClassification, + type FastAgentEventSemanticKind, + type FastAgentEventSemantics, +} from '@roomote/types'; + +export const FAST_AGENT_CANONICAL_REDUCER_VERSION = 1; + +export type FastAgentProjectedEvent = { + event: FastAgentMessage; + semantics: FastAgentEventSemantics | null; + classification: FastAgentEventProjectionClassification; +}; + +export type FastAgentCanonicalProjection = { + events: FastAgentProjectedEvent[]; + stateHash: string; + projectedThroughSequence: number | null; + currentStateEventIds: string[]; +}; + +const AUTHORITY_RANK: Record = { + human: 1, + delegated_task: 2, + automation: 3, + roomote_runtime: 4, + source_control: 5, +}; + +/** + * How strongly an event speaks about the present. A current-state assertion + * reports what the subject is now, while a state change only records that a + * transition happened; the latter can be re-emitted long after the fact (a + * later task updating an already-merged pull request), so it must never + * overwrite an assertion about current state. A legitimate reverse + * transition still wins once its producer asserts it as current state. + */ +const STATE_EVIDENCE_RANK: Record = { + historical_observation: 0, + state_change: 1, + current_state_assertion: 2, +}; + +/** + * Reads the immutable semantics an admission recorded on an event. + * + * Authority and kind are checked against the ranks that order them, not + * merely for being strings: an unrecognized value would index those ranks as + * `undefined` and make the ordering comparison `NaN`, which would silently + * destroy the total order. An event whose semantics cannot be ranked is + * treated as unsemantic history instead. + * + * The check is an own-property test, not `in`: every object inherits + * `toString` and `constructor`, so `in` would accept those as a kind or an + * authority and then rank them as a function, which is exactly the `NaN` this + * guard exists to prevent. + */ +export function readFastAgentEventSemantics( + event: Pick, +): FastAgentEventSemantics | null { + const value = event.metadata?.[FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]; + if (!value || typeof value !== 'object' || Array.isArray(value)) return null; + const semantics = value as Partial; + if ( + semantics.schemaVersion !== FAST_AGENT_EVENT_SEMANTICS_VERSION || + typeof semantics.observedAt !== 'string' || + typeof semantics.sourceEventId !== 'string' || + typeof semantics.kind !== 'string' || + typeof semantics.authority !== 'string' || + !Object.hasOwn(STATE_EVIDENCE_RANK, semantics.kind) || + !Object.hasOwn(AUTHORITY_RANK, semantics.authority) + ) { + return null; + } + // A version that cannot be ordered numerically must not reach the key. + if ( + semantics.version?.scheme === 'monotonic_number' && + !Number.isFinite(semantics.version.value) + ) { + return null; + } + return semantics as FastAgentEventSemantics; +} + +/** + * Whether the version can order a subject at all. Only a genuinely monotonic + * scheme establishes precedence; an opaque version identifies a revision + * without implying order. + */ +function monotonicVersion(semantics: FastAgentEventSemantics): number | null { + return semantics.version?.scheme === 'monotonic_number' + ? semantics.version.value + : null; +} + +/** + * The single ordering key every state claim about one subject is compared by. + * + * Using one lexicographic key, rather than pairwise rules that differ by + * which side happens to carry a version, is what makes the order total: the + * winner cannot depend on admission order, and adding an unversioned claim + * cannot reorder the versioned claims around it. + * + * Mixed-version policy: when a source numbers a subject's states, that + * number is the most trustworthy ordering signal available, so a numbered + * claim outranks an unnumbered one from the same authority and a higher + * number always outranks a lower one. An unnumbered claim therefore cannot + * regress a numbered state, and among unnumbered claims the stronger + * statement about the present wins, then the later observation. A producer + * that emits both numbered and unnumbered claims for one subject is + * modelling that subject inconsistently; the numbered claims win there. + */ +function buildSubjectOrderingKey(candidate: FastAgentProjectedEvent): number[] { + const semantics = candidate.semantics!; + const version = monotonicVersion(semantics); + const observedAt = Date.parse(semantics.observedAt); + return [ + AUTHORITY_RANK[semantics.authority], + version === null ? 0 : 1, + version ?? 0, + STATE_EVIDENCE_RANK[semantics.kind], + Number.isFinite(observedAt) ? observedAt : 0, + candidate.event.conversationSeq ?? 0, + ]; +} + +function compareSubjectCandidates( + left: FastAgentProjectedEvent, + right: FastAgentProjectedEvent, +): number { + const leftKey = buildSubjectOrderingKey(left); + const rightKey = buildSubjectOrderingKey(right); + for (let index = 0; index < leftKey.length; index += 1) { + const difference = leftKey[index]! - rightKey[index]!; + if (difference !== 0) return difference; + } + return 0; +} + +/** + * Whether two claims about one subject disagree with no signal able to + * separate them, which is reported rather than silently resolved. + */ +function isAmbiguousConflict( + left: FastAgentProjectedEvent, + right: FastAgentProjectedEvent, +): boolean { + const leftSemantics = left.semantics!; + const rightSemantics = right.semantics!; + if (leftSemantics.authority !== rightSemantics.authority) return false; + // A transition record disagreeing with an assertion about current state is + // resolved by evidence strength, not surfaced as an unresolvable conflict. + if (leftSemantics.kind !== rightSemantics.kind) return false; + if (leftSemantics.state === rightSemantics.state) return false; + const leftVersion = monotonicVersion(leftSemantics); + const rightVersion = monotonicVersion(rightSemantics); + if (leftVersion !== null && rightVersion !== null) { + return leftVersion === rightVersion; + } + if (leftVersion !== null || rightVersion !== null) return false; + if ( + leftSemantics.version?.scheme === 'opaque' && + rightSemantics.version?.scheme === 'opaque' + ) { + return leftSemantics.version.value === rightSemantics.version.value; + } + // Compare the instant, not its formatting, so the same observation time + // written two ways is still recognized as inseparable. + const leftObserved = Date.parse(leftSemantics.observedAt); + const rightObserved = Date.parse(rightSemantics.observedAt); + return ( + Number.isFinite(leftObserved) && + Number.isFinite(rightObserved) && + leftObserved === rightObserved + ); +} + +/** Pure projection of immutable canonical facts into current conversational state. */ +export function projectFastAgentCanonicalEvents( + rows: FastAgentMessage[], +): FastAgentCanonicalProjection { + const ordered = [...rows].sort((left, right) => { + if (left.conversationSeq !== null && right.conversationSeq !== null) { + return left.conversationSeq - right.conversationSeq; + } + if (left.conversationSeq !== null) return -1; + if (right.conversationSeq !== null) return 1; + return ( + left.createdAt.getTime() - right.createdAt.getTime() || + left.turnSeq - right.turnSeq || + left.id.localeCompare(right.id) + ); + }); + const events: FastAgentProjectedEvent[] = ordered.map((event) => ({ + event, + semantics: readFastAgentEventSemantics(event), + classification: 'historical_relevant', + })); + const bySubject = new Map(); + for (const projected of events) { + const semantics = projected.semantics; + if (!semantics?.subject || semantics.kind === 'historical_observation') { + continue; + } + const key = `${semantics.subject.type}:${semantics.subject.id}`; + const values = bySubject.get(key) ?? []; + values.push(projected); + bySubject.set(key, values); + } + + for (const candidates of bySubject.values()) { + let winner = candidates[0]!; + for (const candidate of candidates.slice(1)) { + if (compareSubjectCandidates(candidate, winner) > 0) winner = candidate; + } + const conflicts = candidates.filter( + (candidate) => + candidate !== winner && isAmbiguousConflict(candidate, winner), + ); + if (conflicts.length > 0) { + winner.classification = 'conflicting'; + for (const conflict of conflicts) conflict.classification = 'conflicting'; + } else { + winner.classification = 'current'; + } + for (const candidate of candidates) { + if (candidate === winner || conflicts.includes(candidate)) continue; + candidate.classification = + candidate.semantics?.kind === 'state_change' + ? 'historical_relevant' + : 'superseded_irrelevant'; + } + } + + const currentState = events + .filter( + ({ classification }) => + classification === 'current' || classification === 'conflicting', + ) + .map(({ event, semantics, classification }) => ({ + eventId: event.eventId, + classification, + semantics, + })); + return { + events, + stateHash: createHash('sha256') + .update(JSON.stringify(currentState)) + .digest('hex'), + projectedThroughSequence: ordered.reduce( + (highest, event) => + event.conversationSeq === null + ? highest + : Math.max(highest ?? 0, event.conversationSeq), + null, + ), + currentStateEventIds: currentState.map(({ eventId }) => eventId), + }; +} + +/** + * Whether a projected event is an obsolete state claim that must not be + * announced as current. Consumers use this to skip a queued turn whose state + * a newer event already replaced, so the rule lives here rather than being + * restated wherever events are consumed. + */ +export function isFastAgentCanonicalEventSuperseded( + projection: FastAgentCanonicalProjection, + eventId: string, +): boolean { + return ( + projection.events.find(({ event }) => event.eventId === eventId) + ?.classification === 'superseded_irrelevant' + ); +} + +/** + * Historical attachments a rebuilt prompt must carry so a cold conversation + * can still see images an earlier turn provided. Canonical rows keep the + * image bytes, so a rebuild can restore real attachments rather than only + * noting that one existed. + */ +export type FastAgentCanonicalAttachment = { + eventId: string; + mime: string; + /** Data URL in the same shape the live turn's image path consumes. */ + url: string; +}; + +/** Most recent attachments to restore, newest first, bounded per rebuild. */ +export const FAST_AGENT_CANONICAL_ATTACHMENT_LIMIT = 4; + +export function collectFastAgentCanonicalAttachments( + projection: FastAgentCanonicalProjection, + options: { excludeEventId?: string; limit?: number } = {}, +): FastAgentCanonicalAttachment[] { + const limit = options.limit ?? FAST_AGENT_CANONICAL_ATTACHMENT_LIMIT; + const restored: FastAgentCanonicalAttachment[] = []; + // Walk newest first so the bound keeps the most recent attachments, which + // are the ones a continuing conversation is most likely to still mean. + for (const { event, classification } of [...projection.events].reverse()) { + if (restored.length >= limit) break; + if (event.eventId === options.excludeEventId) continue; + if (classification === 'superseded_irrelevant') continue; + if (event.role !== 'user') continue; + for (const block of event.contentBlocks) { + if (restored.length >= limit) break; + if (block.type !== 'image') continue; + const mime = String( + (block as { mimeType?: unknown }).mimeType ?? '', + ).trim(); + const data = String((block as { data?: unknown }).data ?? '').trim(); + if (!mime.startsWith('image/') || !data) continue; + restored.push({ + eventId: event.eventId, + mime, + url: `data:${mime};base64,${data}`, + }); + } + } + return restored; +} + +function eventText(event: FastAgentMessage): string { + return event.contentBlocks + .flatMap((block) => (block.type === 'text' ? [String(block.text)] : [])) + .join('\n'); +} + +/** + * The provenance header a canonical event carries into a prompt. Rebuilt + * history and the current turn's own input both announce an event the same + * way, so the shape lives here rather than being restated per call site. + */ +export function renderFastAgentCanonicalEventContext(params: { + eventId: string; + classification: FastAgentEventProjectionClassification; + admittedAt: Date; + semantics: FastAgentEventSemantics; +}): string { + return `${JSON.stringify({ + eventId: params.eventId, + classification: params.classification, + observedAt: params.semantics.observedAt, + admittedAt: params.admittedAt.toISOString(), + occurredAt: params.semantics.occurredAt, + authority: params.semantics.authority, + subject: params.semantics.subject, + version: params.semantics.version, + })}`; +} + +export function renderFastAgentCanonicalHistory( + projection: FastAgentCanonicalProjection, + options: { excludeEventId?: string } = {}, +): ModelMessage[] { + return projection.events.flatMap((projected) => { + const { event, semantics, classification } = projected; + if (event.eventId === options.excludeEventId) return []; + if (classification === 'superseded_irrelevant') return []; + if (event.role !== 'user' && event.role !== 'assistant') return []; + const attachmentCount = event.contentBlocks.filter( + (block) => block.type === 'image', + ).length; + const text = eventText(event).trim(); + // An image-only turn still happened. Dropping it would erase the turn + // from rebuilt history entirely, so it is rendered with its attachment + // count; the bytes themselves are restored separately as real files. + if (!text && attachmentCount === 0) return []; + const attachmentNote = + attachmentCount > 0 + ? `` + : ''; + const body = [attachmentNote, text].filter(Boolean).join('\n'); + const context = semantics + ? `${renderFastAgentCanonicalEventContext({ + eventId: event.eventId, + classification, + admittedAt: event.createdAt, + semantics, + })}\n` + : ''; + return [{ role: event.role, content: `${context}${body}` } as ModelMessage]; + }); +} diff --git a/packages/cloud-agents/src/server/fast-agent/fast-agent-context-telemetry.ts b/packages/cloud-agents/src/server/fast-agent/fast-agent-context-telemetry.ts index 58b04ae49..1141b2448 100644 --- a/packages/cloud-agents/src/server/fast-agent/fast-agent-context-telemetry.ts +++ b/packages/cloud-agents/src/server/fast-agent/fast-agent-context-telemetry.ts @@ -63,6 +63,10 @@ type CaptureFastAgentInferenceContextInput = { agentContextPresent: boolean; inputImageCount: number; attachedImageCount: number; + canonicalEventCount?: number; + canonicalCurrentStateCount?: number; + canonicalProjectedThroughSequence?: number | null; + canonicalAdmissionDelayMs?: number | null; degradedComponents: string[]; }; @@ -147,6 +151,11 @@ export function captureFastAgentInferenceContext( agent_context_present: input.agentContextPresent, input_image_count: input.inputImageCount, attached_image_count: input.attachedImageCount, + canonical_event_count: input.canonicalEventCount ?? null, + canonical_current_state_count: input.canonicalCurrentStateCount ?? null, + canonical_projected_through_sequence: + input.canonicalProjectedThroughSequence ?? null, + canonical_admission_delay_ms: input.canonicalAdmissionDelayMs ?? null, }, }); } diff --git a/packages/cloud-agents/src/server/fast-agent/fast-agent-conversation-repository.ts b/packages/cloud-agents/src/server/fast-agent/fast-agent-conversation-repository.ts index e5f596d83..7c6df9f35 100644 --- a/packages/cloud-agents/src/server/fast-agent/fast-agent-conversation-repository.ts +++ b/packages/cloud-agents/src/server/fast-agent/fast-agent-conversation-repository.ts @@ -1,6 +1,8 @@ import type { ModelMessage } from 'ai'; import { and, + allocateFastAgentConversationSequence, + asc, type CreateFastAgentMessage, db, desc, @@ -24,14 +26,17 @@ import { sql, touchSessionActivity, type DatabaseOrTransaction, + type FastAgentMessage, } from '@roomote/db/server'; import { ACP_ENVELOPE_EVENT_TYPES, fastAgentConversationSchema, type FastAgentConversationOwner, + type FastAgentEventSemantics, type ReasoningEffort, } from '@roomote/types'; +import { readFastAgentEventSemantics } from './fast-agent-canonical-projection'; import { FAST_RESPONDING_LEASE_MS } from './fast-agent-constants'; import { FAST_AGENT_REACTION_INPUT_TYPE, @@ -53,6 +58,8 @@ export type FastAgentConversationRecord = { compatibilityMessages: ModelMessage[]; /** Last successfully completed native session; validated before cold resume. */ openCodeSessionId: string | null; + openCodeProjectionHash?: string | null; + openCodeProjectedThroughSeq?: number | null; }; export type FastAgentConversationGetOrCreateResult = @@ -62,13 +69,14 @@ export type FastAgentConversationGetOrCreateResult = export type FastAgentMessageWrite = Omit< CreateFastAgentMessage, - 'conversationId' + 'conversationId' | 'conversationSeq' >; export type FastAgentMessageUpsertResult = { initialHumanTurn: boolean; /** True only for the transaction that created this canonical event row. */ inserted?: boolean; + conversationSeq: number | null; }; export const INTERRUPTED_INFERENCE_RETRY_MESSAGE = @@ -848,9 +856,45 @@ export interface FastAgentConversationRepository { setOpenCodeSession(input: { conversationId: string; openCodeSessionId: string | null; + projectionHash?: string | null; + projectedThroughSequence?: number | null; }): Promise; } +export async function loadFastAgentCanonicalMessages( + conversationId: string, +): Promise { + return db.query.fastAgentMessages.findMany({ + where: eq(fastAgentMessages.conversationId, conversationId), + orderBy: [ + asc(fastAgentMessages.conversationSeq), + asc(fastAgentMessages.createdAt), + asc(fastAgentMessages.turnSeq), + asc(fastAgentMessages.id), + ], + }); +} + +/** + * The semantics a durable admission already recorded for this input, so a + * turn executing a queued event reuses that record instead of deriving its + * own. Returns null when no row exists yet, or when the row was admitted by + * an N-1 binary that did not record semantics; the caller supplies them then. + */ +export async function loadFastAgentAdmittedEventSemantics( + conversationId: string, + eventId: string, +): Promise { + const row = await db.query.fastAgentMessages.findFirst({ + where: and( + eq(fastAgentMessages.conversationId, conversationId), + eq(fastAgentMessages.eventId, eventId), + ), + columns: { metadata: true }, + }); + return row ? readFastAgentEventSemantics(row) : null; +} + function buildIdentityKey(conversation: FastAgentConversation): string { return `${conversation.surface}:${conversation.workspaceId}:${conversation.conversationId}`; } @@ -974,6 +1018,8 @@ async function loadConversationRecord( conversation, compatibilityMessages: record.compatibilityMessages as ModelMessage[], openCodeSessionId: record.openCodeSessionId, + openCodeProjectionHash: record.openCodeProjectionHash, + openCodeProjectedThroughSeq: record.openCodeProjectedThroughSeq, }; } @@ -1258,7 +1304,10 @@ export const fastAgentConversationRepository: FastAgentConversationRepository = } const [existingEvent] = await tx - .select({ id: fastAgentMessages.id }) + .select({ + id: fastAgentMessages.id, + conversationSeq: fastAgentMessages.conversationSeq, + }) .from(fastAgentMessages) .where( and( @@ -1321,9 +1370,27 @@ export const fastAgentConversationRepository: FastAgentConversationRepository = (Boolean(currentHumanPrompt) || !hasCompatibilityHumanPrompt); } - const insert = tx - .insert(fastAgentMessages) - .values({ conversationId, ...message }); + const allocatedSequence = + existingEvent?.conversationSeq ?? + (await allocateFastAgentConversationSequence(tx, conversationId)); + // An existing row with no sequence was written by an N-1 binary. The + // allocation above repairs every such row under the conversation + // lock, so re-read this one rather than giving it a second number. + const conversationSeq = + existingEvent?.conversationSeq === null + ? (( + await tx.query.fastAgentMessages.findFirst({ + where: eq(fastAgentMessages.id, existingEvent.id), + columns: { conversationSeq: true }, + }) + )?.conversationSeq ?? allocatedSequence) + : allocatedSequence; + const insert = tx.insert(fastAgentMessages).values({ + conversationId, + ...message, + conversationSeq, + observedAt: message.observedAt ?? new Date(message.ts), + }); if (insertOnly) { await insert.onConflictDoNothing({ target: [ @@ -1344,7 +1411,12 @@ export const fastAgentConversationRepository: FastAgentConversationRepository = eventType: message.eventType, role: message.role ?? null, contentBlocks: message.contentBlocks ?? [], - metadata: message.metadata ?? null, + // Merge rather than replace so metadata a durable admission + // wrote for this row survives the executing turn's write. The + // turn reuses the admitted semantics instead of rebuilding + // them, so no key needs protecting from its own writer. + metadata: sql`coalesce(${fastAgentMessages.metadata}, '{}'::jsonb) + || ${JSON.stringify(message.metadata ?? {})}::jsonb`, payload: message.payload ?? {}, source: message.source ?? null, nativeSessionId: message.nativeSessionId ?? null, @@ -1394,13 +1466,19 @@ export const fastAgentConversationRepository: FastAgentConversationRepository = } } - return { initialHumanTurn, inserted: !existingEvent }; + return { + initialHumanTurn, + inserted: !existingEvent, + conversationSeq, + }; }); }, async setOpenCodeSession({ conversationId: requestedId, openCodeSessionId, + projectionHash, + projectedThroughSequence, }) { await db.transaction(async (tx) => { const conversationId = await resolveCanonicalId(tx, requestedId); @@ -1411,6 +1489,12 @@ export const fastAgentConversationRepository: FastAgentConversationRepository = .update(fastAgentConversations) .set({ openCodeSessionId, + ...(projectionHash !== undefined + ? { openCodeProjectionHash: projectionHash } + : {}), + ...(projectedThroughSequence !== undefined + ? { openCodeProjectedThroughSeq: projectedThroughSequence } + : {}), updatedAt: sql`now()`, }) .where(eq(fastAgentConversations.id, conversationId)) diff --git a/packages/cloud-agents/src/server/fast-agent/fast-agent-service.ts b/packages/cloud-agents/src/server/fast-agent/fast-agent-service.ts index d3c827260..63e665d75 100644 --- a/packages/cloud-agents/src/server/fast-agent/fast-agent-service.ts +++ b/packages/cloud-agents/src/server/fast-agent/fast-agent-service.ts @@ -11,6 +11,8 @@ import { CHAT_MESSAGE_CONTEXT_TOOL, CHAT_REACTION_EMOJI_TOOL_NAME, FAST_EXECUTION, + FAST_AGENT_ASSISTANT_CLAIM_PROVENANCE_METADATA_KEY, + FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY, FAST_AGENT_HUMAN_FOLLOW_UP_EVENT_TYPE, FAST_AGENT_MEMORY_FACT_MAX_CHARS, INFERENCE_PROVIDER_MAX_RETRIES, @@ -36,6 +38,8 @@ import { matchIntegrationTools, type IntegrationToolCandidate, type DataVisualizationInput, + type FastAgentAssistantClaimProvenance, + buildFastAgentInputSemantics, CALL_INTEGRATION_TOOL_TOOL, FIND_INTEGRATION_TOOLS_TOOL, } from '@roomote/types'; @@ -87,6 +91,14 @@ import { FAST_RESPONDING_LEASE_RENEW_MS, } from './fast-agent-constants'; import { buildFastAgentUserContentBlocks } from './fast-agent-content-blocks'; +import { + FAST_AGENT_CANONICAL_REDUCER_VERSION, + collectFastAgentCanonicalAttachments, + isFastAgentCanonicalEventSuperseded, + projectFastAgentCanonicalEvents, + renderFastAgentCanonicalEventContext, + renderFastAgentCanonicalHistory, +} from './fast-agent-canonical-projection'; import { buildFastAgentSystemPrompt } from './fast-agent-prompt'; import { getTherapistModeEnabledForUser } from '../therapist-mode'; import { @@ -149,6 +161,8 @@ import { type FastAgentTurnAttemptReply, type FastAgentTurnAttemptSummary, type FastAgentUnresolvedRequest, + loadFastAgentAdmittedEventSemantics, + loadFastAgentCanonicalMessages, loadFastAgentTurnAttemptSummary, } from './fast-agent-conversation-repository'; import { @@ -1766,6 +1780,7 @@ export async function answerFastAgentQuestion({ ? { externalInput: humanInput.externalInput } : platformEventTranscriptPayload; const turnVisibleMessages: ModelMessage[] = []; + let claimProvenance: FastAgentAssistantClaimProvenance | null = null; let mirroredMessageCount = 0; let canonicalConversationId: string | null = null; let durableOpenCodeSessionId: string | null = null; @@ -2016,6 +2031,10 @@ export async function answerFastAgentQuestion({ const turnImages = new Map(); let imageDeliveryPromise: Promise | undefined; let resolvedImageDelivery: FastAgentImageDelivery | undefined; + // Restored history attachments are held at most once per turn, not per + // prompt attempt, so a rebuild followed by a retry cannot reserve two sets + // of attachment IDs for the same bytes. + let restoredAttachmentsHeld = false; const resolveImageDelivery = (): Promise => { imageDeliveryPromise ??= resolveNonTaskInputModalityDelivery({ modality: 'image', @@ -2591,6 +2610,12 @@ export async function answerFastAgentQuestion({ : {}), ...(interruptionReason ? { interruptionReason } : {}), ...(platformMessageId ? { platformMessageId } : {}), + ...(claimProvenance + ? { + [FAST_AGENT_ASSISTANT_CLAIM_PROVENANCE_METADATA_KEY]: + claimProvenance, + } + : {}), }, payload: { purpose: reply.purpose, @@ -3169,6 +3194,38 @@ export async function answerFastAgentQuestion({ const userEvent = previousAttempt?.prompt ? { eventId: `${turnId}:user`, turnSeq: previousAttempt.prompt.turnSeq } : allocateCanonicalEvent('user'); + const inputObservedAt = new Date(); + // A durable admission already recorded what this input claims, including + // the instant it was observed. Reuse that record rather than deriving a + // second one at execution time, which would restate the observation as + // now. Only an input with no admitted record — an inline turn, or a row + // admitted by an N-1 binary — is described here. + const admittedInputSemantics = await loadFastAgentAdmittedEventSemantics( + session.id, + userEvent.eventId, + ) + .then((semantics) => ({ read: true as const, semantics })) + .catch((error: unknown) => { + console.warn( + `[Fast Agent] Failed to read admitted event semantics: ${formatErrorForLog(error)}`, + ); + return { read: false as const, semantics: null }; + }); + // Without a successful read an admitted record is indistinguishable from + // an absent one, so this turn writes nothing for the key: the metadata + // merge then leaves whatever admission recorded intact. Describing the + // input here instead could replace a queued event's current-state + // assertion with the weaker shape a human input has. + const inputSemantics = admittedInputSemantics.read + ? (admittedInputSemantics.semantics ?? + buildFastAgentInputSemantics({ + sessionId: session.id, + observedAt: inputObservedAt, + sourceEventId: currentMessageId ?? turnId, + platformEvent, + ...(setupSnapshot ? { setupSnapshot } : {}), + })) + : null; const userMessageResult = await persistCanonicalMessage( { ...userEvent, @@ -3190,6 +3247,9 @@ export async function answerFastAgentQuestion({ ? { inputKind: FAST_AGENT_REACTION_INPUT_TYPE } : {}), ...(platformEvent ? { platformEventKind } : {}), + ...(inputSemantics + ? { [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: inputSemantics } + : {}), // Lineage back to the interrupted request this turn is resuming, // so the original still surfaces if this turn is interrupted too. ...(unresolvedRequest @@ -3202,6 +3262,11 @@ export async function answerFastAgentQuestion({ }, payload: {}, source: conversation.surface, + // Kept coherent with the semantics above: a reused admitted record + // keeps its own observation instant rather than this turn's. + observedAt: inputSemantics + ? new Date(inputSemantics.observedAt) + : inputObservedAt, }, true, ); @@ -3243,16 +3308,104 @@ export async function answerFastAgentQuestion({ senderDisplayName?.trim() || currentUser.displayName || undefined, githubLogin: currentUser.githubLogin || undefined, }; + const canonicalProjection = projectFastAgentCanonicalEvents( + await loadFastAgentCanonicalMessages(session.id), + ); + const currentCanonicalEventId = `${turnId}:user`; + const currentProjection = canonicalProjection.events.find( + ({ event }) => event.eventId === currentCanonicalEventId, + ); + if ( + isFastAgentCanonicalEventSuperseded( + canonicalProjection, + currentCanonicalEventId, + ) + ) { + console.info( + `[Fast Agent] Suppressed superseded canonical event ${currentCanonicalEventId}.`, + ); + await settleDurableTurn(); + return ''; + } + claimProvenance = { + reducerVersion: FAST_AGENT_CANONICAL_REDUCER_VERSION, + projectedThroughSequence: canonicalProjection.projectedThroughSequence, + projectionHash: canonicalProjection.stateHash, + eventIds: [ + ...new Set([ + currentCanonicalEventId, + ...canonicalProjection.currentStateEventIds, + ]), + ], + }; + const projectedHistory = renderFastAgentCanonicalHistory( + canonicalProjection, + { excludeEventId: currentCanonicalEventId }, + ); + // A rebuild restates the whole conversation, so attachments an earlier + // turn provided have to travel with it; a warm session still holds them + // natively and needs nothing restored. + const restoredAttachmentFiles = getFastAgentImageFiles( + collectFastAgentCanonicalAttachments(canonicalProjection, { + excludeEventId: currentCanonicalEventId, + }).map(({ url }) => url), + ); + const projectedBeforeCurrentSequence = canonicalProjection.events.reduce< + number | null + >( + (highest, projected) => + projected.event.eventId === currentCanonicalEventId || + projected.event.conversationSeq === null + ? highest + : Math.max(highest ?? 0, projected.event.conversationSeq), + null, + ); + const canonicalHistoryAheadOfNative = + projectedBeforeCurrentSequence !== null && + (session.openCodeProjectedThroughSeq === undefined || + session.openCodeProjectedThroughSeq === null || + session.openCodeProjectedThroughSeq < projectedBeforeCurrentSequence) && + canonicalProjection.events.some( + ({ event, semantics }) => + event.eventId !== currentCanonicalEventId && + Boolean(semantics) && + event.conversationSeq !== null && + (session.openCodeProjectedThroughSeq === undefined || + session.openCodeProjectedThroughSeq === null || + event.conversationSeq > session.openCodeProjectedThroughSeq), + ); + const currentProjectionContext = currentProjection?.semantics + ? renderFastAgentCanonicalEventContext({ + eventId: currentCanonicalEventId, + classification: currentProjection.classification, + admittedAt: currentProjection.event.createdAt, + semantics: currentProjection.semantics, + }) + : undefined; + const projectedQuestion = currentProjectionContext + ? `${currentProjectionContext}\n${question}` + : question; + // Canonical history is authoritative as soon as this conversation has any + // canonical event other than the input being executed, even when + // rendering it yields nothing: an empty projection means the prior events + // are genuinely not presentable, not that history is missing. The legacy + // transcript is only eligible for a session that never recorded a + // canonical event, which is what a pre-canonical session looks like. + const canonicalHistoryEligible = canonicalProjection.events.some( + ({ event }) => event.eventId !== currentCanonicalEventId, + ); const { bootstrapMessages, turnMessages, bootstrapThreadContextPresent, turnThreadContextPresent, } = buildFastAgentMessages({ - question, + question: projectedQuestion, currentMessageAgentContext, threadContext, - compatibilityMessages: session.compatibilityMessages, + compatibilityMessages: canonicalHistoryEligible + ? projectedHistory + : session.compatibilityMessages, currentMessageTs: currentMessageId, currentMessageSender, surface: conversation.surface, @@ -4760,13 +4913,29 @@ export async function answerFastAgentQuestion({ const serializedTurnPrompt = turnPromptInput.text; let inferenceAttemptNumber = 0; const persistOpenCodeSession = async (openCodeSessionId: string) => { - if (durableOpenCodeSessionId === openCodeSessionId) return; + // The watermark travels with every native session, not only with + // state-bearing turns: an ordinary prompt is canonical history too, so + // leaving it unrecorded would make the next turn look ahead of the + // session and rebuild it from scratch. + if ( + durableOpenCodeSessionId === openCodeSessionId && + session.openCodeProjectionHash === canonicalProjection.stateHash && + session.openCodeProjectedThroughSeq === + canonicalProjection.projectedThroughSequence + ) { + return; + } await setFastAgentOpenCodeSession({ sessionId: session.id, openCodeSessionId, + projectionHash: canonicalProjection.stateHash, + projectedThroughSequence: canonicalProjection.projectedThroughSequence, }); durableOpenCodeSessionId = openCodeSessionId; session.openCodeSessionId = openCodeSessionId; + session.openCodeProjectionHash = canonicalProjection.stateHash; + session.openCodeProjectedThroughSeq = + canonicalProjection.projectedThroughSequence; }; // A resumed run whose earlier attempt reached its closeout has nothing // left to ask the model. Finish the turn from the record instead. A @@ -4800,6 +4969,22 @@ export async function answerFastAgentQuestion({ return lastVisibleMessage; } diagnostics.markInferenceQueued(); + // A native session cannot receive a delta safely once canonical history + // moved past what it represents, or once the state it was built on + // changed. A session carried over from before this release has no + // recorded projection: that is unknown rather than stale, so it keeps + // its transcript unless newer semantic events are actually ahead of it. + if ( + session.openCodeSessionId && + (canonicalHistoryAheadOfNative || + (session.openCodeProjectionHash != null && + session.openCodeProjectionHash !== canonicalProjection.stateHash)) + ) { + fastAgentOpenCodeSessionManager.invalidate(session.id); + session.openCodeSessionId = null; + activeOpenCodeSessionId = null; + durableOpenCodeSessionId = null; + } const promptTextPromise = fastAgentOpenCodeSessionManager.run({ conversationId: session.id, persistedSessionId: session.openCodeSessionId, @@ -4853,6 +5038,50 @@ export async function answerFastAgentQuestion({ sessionPath === 'fallback_rebuild' ? [...imageFiles, ...injectedHumanFollowUpFiles] : imageFiles; + // Restored history attachments follow the same delivery rules as the + // turn's own images: sent as files only when the model takes them + // directly, and otherwise held and announced with attachment IDs so + // `inspect_images` can read them. Where no configured model accepts + // image input at all, they are dropped rather than announced as + // inspectable, because nothing could ever read them; rebuilt history + // still records that the turn carried attachments. + // + // Single owner for both the rebuild below and the clean retry, which + // resolves the delivery mode itself when the failed attempt never + // needed one. Holding happens once: a retry re-renders the notice for + // every held image through `withTurnImageNotice`, so reserving a + // second set of IDs for the same bytes would announce them twice. + const prepareRestoredAttachments = ( + delivery: FastAgentImageDelivery, + text: string, + ): { text: string; files: NonTaskPromptFile[] } => { + if ( + restoredAttachmentFiles.length === 0 || + delivery.delivery === 'unsupported' + ) { + return { text, files: [] }; + } + if (restoredAttachmentsHeld) return { text, files: [] }; + const prepared = holdImagesForPrompt( + restoredAttachmentFiles, + text, + delivery, + ); + commitTurnImages(prepared.held); + restoredAttachmentsHeld = prepared.held.length > 0; + return { text: prepared.text, files: prepared.files }; + }; + if ( + sessionPath === 'fallback_rebuild' || + sessionPath === 'cold_rebuild' + ) { + const restored = prepareRestoredAttachments( + await resolveImageDelivery(), + promptForAttempt, + ); + promptForAttempt = restored.text; + imageFilesForAttempt = [...imageFilesForAttempt, ...restored.files]; + } let promptKind: FastAgentPromptKind = sessionPath === 'warm' || sessionPath === 'cold_resume' ? 'turn_delta' @@ -4907,6 +5136,17 @@ export async function answerFastAgentQuestion({ agentContextPresent: Boolean(currentMessageAgentContext), inputImageCount: imageFiles.length, attachedImageCount: imageFilesForAttempt.length, + canonicalEventCount: canonicalProjection.events.length, + canonicalCurrentStateCount: + canonicalProjection.currentStateEventIds.length, + canonicalProjectedThroughSequence: + canonicalProjection.projectedThroughSequence, + canonicalAdmissionDelayMs: currentProjection + ? Math.max( + 0, + Date.now() - currentProjection.event.createdAt.getTime(), + ) + : null, degradedComponents: [...degradedContextComponents], }); }; @@ -5251,7 +5491,7 @@ export async function answerFastAgentQuestion({ noteInferenceRecoveryProgress(); return true; }, - prepareRetry: () => { + prepareRetry: async () => { if (nativeToolInvoked && openCodeSession.id) { promptForAttempt = FAST_AGENT_PROVIDER_RECOVERY_PROMPT; imageFilesForAttempt = []; @@ -5261,6 +5501,22 @@ export async function answerFastAgentQuestion({ // Before tools run, rebuild from visible history rather than // append the original turn to the failed session again. openCodeSession.id = undefined; + // This rebuild replays the whole conversation, so history's + // attachments have to travel with it. A text-only turn never + // resolved a delivery mode, so resolve one here rather than + // leave the images out; the lookup stays off turns that + // never retry. Awaiting before the prompt is built is safe: + // holding and building still run without interruption. + const restored = + restoredAttachmentFiles.length > 0 + ? prepareRestoredAttachments( + await resolveImageDelivery(), + '', + ) + : { files: [] }; + // The returned text is discarded because on a rebuilt prompt + // `withTurnImageNotice` owns the notice, and it restates + // every held image including anything just held above. promptForAttempt = withTurnImageNotice( serializeFastAgentMessages([ ...bootstrapMessages, @@ -5270,6 +5526,7 @@ export async function answerFastAgentQuestion({ imageFilesForAttempt = [ ...imageFiles, ...injectedHumanFollowUpFiles, + ...restored.files, ]; promptKind = 'clean_retry_bootstrap'; attemptSessionPath = 'cold_rebuild'; diff --git a/packages/cloud-agents/src/server/fast-agent/fast-agent-session.ts b/packages/cloud-agents/src/server/fast-agent/fast-agent-session.ts index 9f2de331d..1069c0789 100644 --- a/packages/cloud-agents/src/server/fast-agent/fast-agent-session.ts +++ b/packages/cloud-agents/src/server/fast-agent/fast-agent-session.ts @@ -32,6 +32,8 @@ type FastAgentSessionRecord = { conversation: FastAgentConversation; compatibilityMessages: ModelMessage[]; openCodeSessionId: string | null; + openCodeProjectionHash?: string | null; + openCodeProjectedThroughSeq?: number | null; created: boolean; }; @@ -174,12 +176,20 @@ export async function upsertFastAgentMessage({ export async function setFastAgentOpenCodeSession({ sessionId, openCodeSessionId, + projectionHash, + projectedThroughSequence, }: { sessionId: string; openCodeSessionId: string | null; + projectionHash?: string | null; + projectedThroughSequence?: number | null; }): Promise { await fastAgentConversationRepository.setOpenCodeSession({ conversationId: sessionId, openCodeSessionId, + ...(projectionHash !== undefined ? { projectionHash } : {}), + ...(projectedThroughSequence !== undefined + ? { projectedThroughSequence } + : {}), }); } diff --git a/packages/cloud-agents/src/server/fast-agent/index.ts b/packages/cloud-agents/src/server/fast-agent/index.ts index 532b6e54d..53cda7793 100644 --- a/packages/cloud-agents/src/server/fast-agent/index.ts +++ b/packages/cloud-agents/src/server/fast-agent/index.ts @@ -1,4 +1,6 @@ export * from './fast-agent-constants'; +export * from './fast-agent-canonical-projection'; +export * from './fast-agent-content-blocks'; export * from './fast-agent-conversation'; export * from './fast-agent-conversation-repository'; export * from './fast-agent-prompt'; diff --git a/packages/db/drizzle/0087_uneven_scalphunter.sql b/packages/db/drizzle/0087_uneven_scalphunter.sql new file mode 100644 index 000000000..1b29c026b --- /dev/null +++ b/packages/db/drizzle/0087_uneven_scalphunter.sql @@ -0,0 +1,21 @@ +DROP INDEX "fast_agent_messages_conversation_order_idx";--> statement-breakpoint +ALTER TABLE "fast_agent_conversations" ADD COLUMN "open_code_projection_hash" text;--> statement-breakpoint +ALTER TABLE "fast_agent_conversations" ADD COLUMN "open_code_projected_through_seq" bigint;--> statement-breakpoint +ALTER TABLE "fast_agent_messages" ADD COLUMN "conversation_seq" bigint;--> statement-breakpoint +ALTER TABLE "fast_agent_messages" ADD COLUMN "observed_at" timestamp;--> statement-breakpoint +WITH ranked AS ( + SELECT "id", row_number() OVER ( + PARTITION BY "conversation_id" + ORDER BY "created_at", "ts", "turn_seq", "id" + ) AS "conversation_seq" + FROM "fast_agent_messages" +) +UPDATE "fast_agent_messages" AS messages +SET + "conversation_seq" = ranked."conversation_seq", + "observed_at" = to_timestamp(messages."ts" / 1000.0) +FROM ranked +WHERE messages."id" = ranked."id";--> statement-breakpoint +CREATE INDEX "fast_agent_messages_legacy_order_idx" ON "fast_agent_messages" USING btree ("conversation_id","ts","turn_seq");--> statement-breakpoint +CREATE INDEX "fast_agent_messages_conversation_order_idx" ON "fast_agent_messages" USING btree ("conversation_id","conversation_seq");--> statement-breakpoint +CREATE UNIQUE INDEX "fast_agent_messages_conversation_seq_unique" ON "fast_agent_messages" USING btree ("conversation_id","conversation_seq") WHERE "fast_agent_messages"."conversation_seq" is not null; diff --git a/packages/db/drizzle/meta/0087_snapshot.json b/packages/db/drizzle/meta/0087_snapshot.json new file mode 100644 index 000000000..421be8fc3 --- /dev/null +++ b/packages/db/drizzle/meta/0087_snapshot.json @@ -0,0 +1,15714 @@ +{ + "id": "ddf4cd9a-22c5-4d1c-8405-c84364a05fa3", + "prevId": "78faf767-b110-4ac3-966e-07f3ced5db5f", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.agentmail_conversation_participants": { + "name": "agentmail_conversation_participants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "inbox_id": { + "name": "inbox_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_thread_id": { + "name": "provider_thread_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "added_at": { + "name": "added_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "agentmail_conversation_participants_user_idx": { + "name": "agentmail_conversation_participants_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agentmail_conversation_participants_user_id_users_id_fk": { + "name": "agentmail_conversation_participants_user_id_users_id_fk", + "tableFrom": "agentmail_conversation_participants", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agentmail_conversation_participants_conversation_fk": { + "name": "agentmail_conversation_participants_conversation_fk", + "tableFrom": "agentmail_conversation_participants", + "tableTo": "agentmail_conversations", + "columnsFrom": ["conversation_id", "inbox_id", "provider_thread_id"], + "columnsTo": ["id", "inbox_id", "provider_thread_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agentmail_conversation_participants_conversation_user_unique": { + "name": "agentmail_conversation_participants_conversation_user_unique", + "nullsNotDistinct": false, + "columns": ["conversation_id", "user_id"] + }, + "agentmail_conversation_participants_thread_user_unique": { + "name": "agentmail_conversation_participants_thread_user_unique", + "nullsNotDistinct": false, + "columns": ["inbox_id", "provider_thread_id", "user_id"] + } + }, + "policies": {}, + "checkConstraints": { + "agentmail_conversation_participants_role_check": { + "name": "agentmail_conversation_participants_role_check", + "value": "\"agentmail_conversation_participants\".\"role\" in ('owner', 'participant')" + }, + "agentmail_conversation_participants_source_check": { + "name": "agentmail_conversation_participants_source_check", + "value": "\"agentmail_conversation_participants\".\"source\" in ('initiator', 'cc', 'link_code', 'outbound')" + } + }, + "isRLSEnabled": false + }, + "public.agentmail_conversations": { + "name": "agentmail_conversations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "inbox_id": { + "name": "inbox_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_thread_id": { + "name": "provider_thread_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "owner_user_id": { + "name": "owner_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "outbound_identity_id": { + "name": "outbound_identity_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "latest_inbound_message_id": { + "name": "latest_inbound_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "latest_inbound_at": { + "name": "latest_inbound_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "latest_inbound_sender_email": { + "name": "latest_inbound_sender_email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "latest_inbound_user_id": { + "name": "latest_inbound_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "latest_outbound_message_id": { + "name": "latest_outbound_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "agentmail_conversations_thread_idx": { + "name": "agentmail_conversations_thread_idx", + "columns": [ + { + "expression": "inbox_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_thread_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "agentmail_conversations_owner_idx": { + "name": "agentmail_conversations_owner_idx", + "columns": [ + { + "expression": "owner_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agentmail_conversations_owner_user_id_users_id_fk": { + "name": "agentmail_conversations_owner_user_id_users_id_fk", + "tableFrom": "agentmail_conversations", + "tableTo": "users", + "columnsFrom": ["owner_user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agentmail_conversations_latest_inbound_user_id_users_id_fk": { + "name": "agentmail_conversations_latest_inbound_user_id_users_id_fk", + "tableFrom": "agentmail_conversations", + "tableTo": "users", + "columnsFrom": ["latest_inbound_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agentmail_conversations_id_thread_unique": { + "name": "agentmail_conversations_id_thread_unique", + "nullsNotDistinct": false, + "columns": ["id", "inbox_id", "provider_thread_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.agentmail_inbound_turns": { + "name": "agentmail_inbound_turns", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "webhook_event_id": { + "name": "webhook_event_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider_message_id": { + "name": "provider_message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_timestamp": { + "name": "provider_timestamp", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "sender_email": { + "name": "sender_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sender_user_id": { + "name": "sender_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body_text": { + "name": "body_text", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retry_at": { + "name": "retry_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "consumed_at": { + "name": "consumed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "agentmail_inbound_turns_drain_idx": { + "name": "agentmail_inbound_turns_drain_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "agentmail_inbound_turns_pending_idx": { + "name": "agentmail_inbound_turns_pending_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"agentmail_inbound_turns\".\"state\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agentmail_inbound_turns_conversation_id_agentmail_conversations_id_fk": { + "name": "agentmail_inbound_turns_conversation_id_agentmail_conversations_id_fk", + "tableFrom": "agentmail_inbound_turns", + "tableTo": "agentmail_conversations", + "columnsFrom": ["conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agentmail_inbound_turns_webhook_event_id_agentmail_webhook_events_id_fk": { + "name": "agentmail_inbound_turns_webhook_event_id_agentmail_webhook_events_id_fk", + "tableFrom": "agentmail_inbound_turns", + "tableTo": "agentmail_webhook_events", + "columnsFrom": ["webhook_event_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "agentmail_inbound_turns_sender_user_id_users_id_fk": { + "name": "agentmail_inbound_turns_sender_user_id_users_id_fk", + "tableFrom": "agentmail_inbound_turns", + "tableTo": "users", + "columnsFrom": ["sender_user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agentmail_inbound_turns_webhook_event_unique": { + "name": "agentmail_inbound_turns_webhook_event_unique", + "nullsNotDistinct": false, + "columns": ["webhook_event_id"] + } + }, + "policies": {}, + "checkConstraints": { + "agentmail_inbound_turns_state_check": { + "name": "agentmail_inbound_turns_state_check", + "value": "\"agentmail_inbound_turns\".\"state\" in ('pending', 'consumed', 'failed')" + } + }, + "isRLSEnabled": false + }, + "public.agentmail_suppressions": { + "name": "agentmail_suppressions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "email_address": { + "name": "email_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "details": { + "name": "details", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_message_id": { + "name": "provider_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agentmail_suppressions_email_unique": { + "name": "agentmail_suppressions_email_unique", + "nullsNotDistinct": false, + "columns": ["email_address"] + } + }, + "policies": {}, + "checkConstraints": { + "agentmail_suppressions_reason_check": { + "name": "agentmail_suppressions_reason_check", + "value": "\"agentmail_suppressions\".\"reason\" in ('bounce', 'complaint', 'unsubscribe')" + } + }, + "isRLSEnabled": false + }, + "public.agentmail_user_mappings": { + "name": "agentmail_user_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "email_address": { + "name": "email_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "agentmail_user_mappings_user_id_idx": { + "name": "agentmail_user_mappings_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "agentmail_user_mappings_user_id_users_id_fk": { + "name": "agentmail_user_mappings_user_id_users_id_fk", + "tableFrom": "agentmail_user_mappings", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agentmail_user_mappings_unique": { + "name": "agentmail_user_mappings_unique", + "nullsNotDistinct": false, + "columns": ["email_address"] + } + }, + "policies": {}, + "checkConstraints": { + "agentmail_user_mappings_source_check": { + "name": "agentmail_user_mappings_source_check", + "value": "\"agentmail_user_mappings\".\"source\" in ('verified_match', 'link_code')" + } + }, + "isRLSEnabled": false + }, + "public.agentmail_webhook_events": { + "name": "agentmail_webhook_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "delivery_id": { + "name": "delivery_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'received'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "received_at": { + "name": "received_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "agentmail_webhook_events_state_idx": { + "name": "agentmail_webhook_events_state_idx", + "columns": [ + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "received_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agentmail_webhook_events_delivery_unique": { + "name": "agentmail_webhook_events_delivery_unique", + "nullsNotDistinct": false, + "columns": ["delivery_id"] + } + }, + "policies": {}, + "checkConstraints": { + "agentmail_webhook_events_state_check": { + "name": "agentmail_webhook_events_state_check", + "value": "\"agentmail_webhook_events\".\"state\" in ('received', 'queued', 'processing', 'processed', 'failed')" + } + }, + "isRLSEnabled": false + }, + "public.auth_accounts": { + "name": "auth_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "auth_accounts_user_id_idx": { + "name": "auth_accounts_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_accounts_provider_account_unique": { + "name": "auth_accounts_provider_account_unique", + "columns": [ + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "auth_accounts_user_id_auth_users_id_fk": { + "name": "auth_accounts_user_id_auth_users_id_fk", + "tableFrom": "auth_accounts", + "tableTo": "auth_users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_sessions": { + "name": "auth_sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "auth_sessions_token_unique": { + "name": "auth_sessions_token_unique", + "columns": [ + { + "expression": "token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_sessions_user_id_idx": { + "name": "auth_sessions_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "auth_sessions_user_id_auth_users_id_fk": { + "name": "auth_sessions_user_id_auth_users_id_fk", + "tableFrom": "auth_sessions", + "tableTo": "auth_users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_users": { + "name": "auth_users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "auth_users_email_unique": { + "name": "auth_users_email_unique", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_users_created_at_idx": { + "name": "auth_users_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_verifications": { + "name": "auth_verifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "auth_verifications_identifier_idx": { + "name": "auth_verifications_identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.automation_results": { + "name": "automation_results", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "automation_key": { + "name": "automation_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "custom_automation_id": { + "name": "custom_automation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source_task_id": { + "name": "source_task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "automation_name": { + "name": "automation_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'normal'" + }, + "dedupe_key": { + "name": "dedupe_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "ignored_at": { + "name": "ignored_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "automation_results_dedupe_key_unique_idx": { + "name": "automation_results_dedupe_key_unique_idx", + "columns": [ + { + "expression": "dedupe_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_results_inbox_idx": { + "name": "automation_results_inbox_idx", + "columns": [ + { + "expression": "priority", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_results_user_id_idx": { + "name": "automation_results_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "automation_results_source_task_id_idx": { + "name": "automation_results_source_task_id_idx", + "columns": [ + { + "expression": "source_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "automation_results_automation_key_automations_key_fk": { + "name": "automation_results_automation_key_automations_key_fk", + "tableFrom": "automation_results", + "tableTo": "automations", + "columnsFrom": ["automation_key"], + "columnsTo": ["key"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "automation_results_custom_automation_id_custom_automations_id_fk": { + "name": "automation_results_custom_automation_id_custom_automations_id_fk", + "tableFrom": "automation_results", + "tableTo": "custom_automations", + "columnsFrom": ["custom_automation_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "automation_results_source_task_id_tasks_id_fk": { + "name": "automation_results_source_task_id_tasks_id_fk", + "tableFrom": "automation_results", + "tableTo": "tasks", + "columnsFrom": ["source_task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "automation_results_user_id_users_id_fk": { + "name": "automation_results_user_id_users_id_fk", + "tableFrom": "automation_results", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.automations": { + "name": "automations", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "internal": { + "name": "internal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "schedule": { + "name": "schedule", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "instructions": { + "name": "instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "settings": { + "name": "settings", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "targets": { + "name": "targets", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "last_run_at": { + "name": "last_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_succeeded_at": { + "name": "last_succeeded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_failed_at": { + "name": "last_failed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scan_cursor": { + "name": "scan_cursor", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brain_collector_items": { + "name": "brain_collector_items", + "schema": "", + "columns": { + "collector_id": { + "name": "collector_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "brain_collector_items_collector_seen_idx": { + "name": "brain_collector_items_collector_seen_idx", + "columns": [ + { + "expression": "collector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_seen_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "brain_collector_items_collector_item_pk": { + "name": "brain_collector_items_collector_item_pk", + "columns": ["collector_id", "item_id"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brain_memory_events": { + "name": "brain_memory_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "agent_summary": { + "name": "agent_summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "brain_memory_events_status_created_idx": { + "name": "brain_memory_events_status_created_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "brain_memory_events_run_id_task_runs_id_fk": { + "name": "brain_memory_events_run_id_task_runs_id_fk", + "tableFrom": "brain_memory_events", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "brain_memory_events_run_unique": { + "name": "brain_memory_events_run_unique", + "nullsNotDistinct": false, + "columns": ["run_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.brain_sync_state": { + "name": "brain_sync_state", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "collector_id": { + "name": "collector_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "watermark": { + "name": "watermark", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "backfill_cursor": { + "name": "backfill_cursor", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "backfill_completed_at": { + "name": "backfill_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "brain_sync_state_collector_id_unique": { + "name": "brain_sync_state_collector_id_unique", + "nullsNotDistinct": false, + "columns": ["collector_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.compute_provider_usage": { + "name": "compute_provider_usage", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_usage_id": { + "name": "provider_usage_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth_kind": { + "name": "auth_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "instance_id": { + "name": "instance_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "launch_mode": { + "name": "launch_mode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lifecycle_action": { + "name": "lifecycle_action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "measurement_source": { + "name": "measurement_source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "configured_vcpus": { + "name": "configured_vcpus", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "configured_cpu_cores": { + "name": "configured_cpu_cores", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "configured_memory_mib": { + "name": "configured_memory_mib", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "wall_clock_duration_ms": { + "name": "wall_clock_duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "active_cpu_duration_ms": { + "name": "active_cpu_duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "observed_memory_mib_milliseconds": { + "name": "observed_memory_mib_milliseconds", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "network_ingress_bytes": { + "name": "network_ingress_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "network_egress_bytes": { + "name": "network_egress_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "compute_provider_usage_provider_usage_id_unique": { + "name": "compute_provider_usage_provider_usage_id_unique", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_usage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "compute_provider_usage_run_id_idx": { + "name": "compute_provider_usage_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "compute_provider_usage_task_id_idx": { + "name": "compute_provider_usage_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "compute_provider_usage_created_at_idx": { + "name": "compute_provider_usage_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "compute_provider_usage_run_id_task_runs_id_fk": { + "name": "compute_provider_usage_run_id_task_runs_id_fk", + "tableFrom": "compute_provider_usage", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "compute_provider_usage_task_id_tasks_id_fk": { + "name": "compute_provider_usage_task_id_tasks_id_fk", + "tableFrom": "compute_provider_usage", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.compute_provider_usage_samples": { + "name": "compute_provider_usage_samples", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_usage_id": { + "name": "provider_usage_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "instance_id": { + "name": "instance_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sampled_at": { + "name": "sampled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "cpu_usage_ns_total": { + "name": "cpu_usage_ns_total", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "memory_usage_bytes": { + "name": "memory_usage_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "memory_peak_usage_bytes": { + "name": "memory_peak_usage_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "compute_provider_usage_samples_provider_usage_sampled_at_unique": { + "name": "compute_provider_usage_samples_provider_usage_sampled_at_unique", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_usage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sampled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "compute_provider_usage_samples_run_id_idx": { + "name": "compute_provider_usage_samples_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "compute_provider_usage_samples_task_id_idx": { + "name": "compute_provider_usage_samples_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "compute_provider_usage_samples_created_at_idx": { + "name": "compute_provider_usage_samples_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "compute_provider_usage_samples_run_id_task_runs_id_fk": { + "name": "compute_provider_usage_samples_run_id_task_runs_id_fk", + "tableFrom": "compute_provider_usage_samples", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "compute_provider_usage_samples_task_id_tasks_id_fk": { + "name": "compute_provider_usage_samples_task_id_tasks_id_fk", + "tableFrom": "compute_provider_usage_samples", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.custom_automations": { + "name": "custom_automations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "result_priority": { + "name": "result_priority", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'normal'" + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "schedule_mode": { + "name": "schedule_mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'off'" + }, + "cron_expression": { + "name": "cron_expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reasoning_effort": { + "name": "reasoning_effort", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "environment_id": { + "name": "environment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "all_repositories": { + "name": "all_repositories", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "no_repositories": { + "name": "no_repositories", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "execution_mode": { + "name": "execution_mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'sandbox_task'" + }, + "target": { + "name": "target", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_run_at": { + "name": "last_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_succeeded_at": { + "name": "last_succeeded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_failed_at": { + "name": "last_failed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_launched_task_id": { + "name": "last_launched_task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "launch_claimed_at": { + "name": "launch_claimed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "custom_automations_name_unique_idx": { + "name": "custom_automations_name_unique_idx", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "custom_automations_enabled_idx": { + "name": "custom_automations_enabled_idx", + "columns": [ + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "custom_automations_environment_id_idx": { + "name": "custom_automations_environment_id_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "custom_automations_environment_id_environments_id_fk": { + "name": "custom_automations_environment_id_environments_id_fk", + "tableFrom": "custom_automations", + "tableTo": "environments", + "columnsFrom": ["environment_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "custom_automations_created_by_user_id_users_id_fk": { + "name": "custom_automations_created_by_user_id_users_id_fk", + "tableFrom": "custom_automations", + "tableTo": "users", + "columnsFrom": ["created_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "custom_automations_last_launched_task_id_tasks_id_fk": { + "name": "custom_automations_last_launched_task_id_tasks_id_fk", + "tableFrom": "custom_automations", + "tableTo": "tasks", + "columnsFrom": ["last_launched_task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.custom_mcp_servers": { + "name": "custom_mcp_servers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auth_type": { + "name": "auth_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "headers": { + "name": "headers", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "stdio": { + "name": "stdio", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "disabled_tools": { + "name": "disabled_tools", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "manual_client_id": { + "name": "manual_client_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "manual_client_secret": { + "name": "manual_client_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "oauth_server_metadata": { + "name": "oauth_server_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "oauth_server_metadata_fetched_at": { + "name": "oauth_server_metadata_fetched_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "oauth_resource_indicator_disabled": { + "name": "oauth_resource_indicator_disabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "custom_mcp_servers_created_by_user_id_users_id_fk": { + "name": "custom_mcp_servers_created_by_user_id_users_id_fk", + "tableFrom": "custom_mcp_servers", + "tableTo": "users", + "columnsFrom": ["created_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "custom_mcp_servers_name_unique": { + "name": "custom_mcp_servers_name_unique", + "nullsNotDistinct": false, + "columns": ["name"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.deployment_mcp_enablements": { + "name": "deployment_mcp_enablements", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "mcp_id": { + "name": "mcp_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "enabled_by_user_id": { + "name": "enabled_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "disabled_tools": { + "name": "disabled_tools", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "tool_access_mode": { + "name": "tool_access_mode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "deployment_mcp_enablements_enabled_by_user_id_users_id_fk": { + "name": "deployment_mcp_enablements_enabled_by_user_id_users_id_fk", + "tableFrom": "deployment_mcp_enablements", + "tableTo": "users", + "columnsFrom": ["enabled_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "deployment_mcp_enablements_mcp_unique": { + "name": "deployment_mcp_enablements_mcp_unique", + "nullsNotDistinct": false, + "columns": ["mcp_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.deployment_secrets": { + "name": "deployment_secrets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "deployment_secrets_name_unique": { + "name": "deployment_secrets_name_unique", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.deployment_settings": { + "name": "deployment_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "default": "'default'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "task_model_settings": { + "name": "task_model_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "workspace_routing_settings": { + "name": "workspace_routing_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "router_debug_provider": { + "name": "router_debug_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "router_debug_channel_id": { + "name": "router_debug_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "router_debug_disabled": { + "name": "router_debug_disabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "router_debug_slack_channel_id": { + "name": "router_debug_slack_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "runtime_model_config": { + "name": "runtime_model_config", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "runtime_compute_config": { + "name": "runtime_compute_config", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "access_policy": { + "name": "access_policy", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brain_enabled": { + "name": "brain_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "license_key": { + "name": "license_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "license_cloud_state": { + "name": "license_cloud_state", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "instance_analytics_id": { + "name": "instance_analytics_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "latest_known_version": { + "name": "latest_known_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "latest_version_checked_at": { + "name": "latest_version_checked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "setup_completed_at": { + "name": "setup_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "setup_new_state": { + "name": "setup_new_state", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "slack_onboarding_stage": { + "name": "slack_onboarding_stage", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "manager_slack_channel_id": { + "name": "manager_slack_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "manager_discord_channel_id": { + "name": "manager_discord_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "global_agent_instructions": { + "name": "global_agent_instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "time_zone": { + "name": "time_zone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "time_zone_updated_at": { + "name": "time_zone_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "authorship_instructions": { + "name": "authorship_instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "compiled_authorship_rules": { + "name": "compiled_authorship_rules", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "compiled_authorship_issues": { + "name": "compiled_authorship_issues", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "compiled_authorship_at": { + "name": "compiled_authorship_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "style_guidance": { + "name": "style_guidance", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_summon_emoji": { + "name": "slack_summon_emoji", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_ack_emoji": { + "name": "slack_ack_emoji", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'eyes'" + }, + "slack_completion_emoji": { + "name": "slack_completion_emoji", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'white_check_mark'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.discord_gateway_sessions": { + "name": "discord_gateway_sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resume_gateway_url": { + "name": "resume_gateway_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sequence": { + "name": "sequence", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "shard_count": { + "name": "shard_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "last_connected_at": { + "name": "last_connected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_heartbeat_ack_at": { + "name": "last_heartbeat_ack_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "disconnected_at": { + "name": "disconnected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.discord_installation_channels": { + "name": "discord_installation_channels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "discord_installation_id": { + "name": "discord_installation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_name": { + "name": "channel_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "channel_type": { + "name": "channel_type", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "permissions": { + "name": "permissions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_available": { + "name": "is_available", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "discord_installation_channels_installation_id_idx": { + "name": "discord_installation_channels_installation_id_idx", + "columns": [ + { + "expression": "discord_installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "discord_installation_channels_unique": { + "name": "discord_installation_channels_unique", + "columns": [ + { + "expression": "discord_installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "discord_installation_channels_discord_installation_id_discord_installations_id_fk": { + "name": "discord_installation_channels_discord_installation_id_discord_installations_id_fk", + "tableFrom": "discord_installation_channels", + "tableTo": "discord_installations", + "columnsFrom": ["discord_installation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.discord_installations": { + "name": "discord_installations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "guild_id": { + "name": "guild_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "guild_name": { + "name": "guild_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "application_id": { + "name": "application_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bot_user_id": { + "name": "bot_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "installed_by_user_id": { + "name": "installed_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "default_channel_id": { + "name": "default_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "default_channel_name": { + "name": "default_channel_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "default_channel_type": { + "name": "default_channel_type", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "discord_installations_guild_id_unique": { + "name": "discord_installations_guild_id_unique", + "columns": [ + { + "expression": "guild_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "discord_installations_active_idx": { + "name": "discord_installations_active_idx", + "columns": [ + { + "expression": "is_active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "discord_installations_default_channel_idx": { + "name": "discord_installations_default_channel_idx", + "columns": [ + { + "expression": "default_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "discord_installations_installed_by_user_id_users_id_fk": { + "name": "discord_installations_installed_by_user_id_users_id_fk", + "tableFrom": "discord_installations", + "tableTo": "users", + "columnsFrom": ["installed_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.discord_user_mappings": { + "name": "discord_user_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "discord_user_id": { + "name": "discord_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "discord_username": { + "name": "discord_username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "discord_global_name": { + "name": "discord_global_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "discord_dm_channel_id": { + "name": "discord_dm_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "discord_user_mappings_user_id_idx": { + "name": "discord_user_mappings_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "discord_user_mappings_discord_user_id_unique": { + "name": "discord_user_mappings_discord_user_id_unique", + "columns": [ + { + "expression": "discord_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "discord_user_mappings_user_id_users_id_fk": { + "name": "discord_user_mappings_user_id_users_id_fk", + "tableFrom": "discord_user_mappings", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.environment_config_versions": { + "name": "environment_config_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "environment_id": { + "name": "environment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "environment_config_versions_environment_id_idx": { + "name": "environment_config_versions_environment_id_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "environment_config_versions_environment_version_unique": { + "name": "environment_config_versions_environment_version_unique", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "environment_config_versions_environment_id_environments_id_fk": { + "name": "environment_config_versions_environment_id_environments_id_fk", + "tableFrom": "environment_config_versions", + "tableTo": "environments", + "columnsFrom": ["environment_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "environment_config_versions_created_by_user_id_users_id_fk": { + "name": "environment_config_versions_created_by_user_id_users_id_fk", + "tableFrom": "environment_config_versions", + "tableTo": "users", + "columnsFrom": ["created_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.environment_repository_mappings": { + "name": "environment_repository_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "environment_id": { + "name": "environment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "repository_id": { + "name": "repository_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "env_repo_mappings_env_id_idx": { + "name": "env_repo_mappings_env_id_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "env_repo_mappings_repo_id_idx": { + "name": "env_repo_mappings_repo_id_idx", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "environment_repository_mappings_environment_id_environments_id_fk": { + "name": "environment_repository_mappings_environment_id_environments_id_fk", + "tableFrom": "environment_repository_mappings", + "tableTo": "environments", + "columnsFrom": ["environment_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "environment_repository_mappings_repository_id_repositories_id_fk": { + "name": "environment_repository_mappings_repository_id_repositories_id_fk", + "tableFrom": "environment_repository_mappings", + "tableTo": "repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "env_repo_mappings_unique": { + "name": "env_repo_mappings_unique", + "nullsNotDistinct": false, + "columns": ["environment_id", "repository_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.environment_snapshots": { + "name": "environment_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "environment_id": { + "name": "environment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "snapshot_id": { + "name": "snapshot_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "snapshot_created_at": { + "name": "snapshot_created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "snapshot_expires_at": { + "name": "snapshot_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "snapshot_status": { + "name": "snapshot_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "environment_snapshots_environment_id_idx": { + "name": "environment_snapshots_environment_id_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "environment_snapshots_env_provider_unique": { + "name": "environment_snapshots_env_provider_unique", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"environment_snapshots\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "environment_snapshots_environment_id_environments_id_fk": { + "name": "environment_snapshots_environment_id_environments_id_fk", + "tableFrom": "environment_snapshots", + "tableTo": "environments", + "columnsFrom": ["environment_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.environment_variables": { + "name": "environment_variables", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_updated_by_user_id": { + "name": "last_updated_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "environment_variables_user_id_idx": { + "name": "environment_variables_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "environment_variables_name_unique": { + "name": "environment_variables_name_unique", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "environment_variables_user_id_users_id_fk": { + "name": "environment_variables_user_id_users_id_fk", + "tableFrom": "environment_variables", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "environment_variables_created_by_user_id_users_id_fk": { + "name": "environment_variables_created_by_user_id_users_id_fk", + "tableFrom": "environment_variables", + "tableTo": "users", + "columnsFrom": ["created_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "environment_variables_last_updated_by_user_id_users_id_fk": { + "name": "environment_variables_last_updated_by_user_id_users_id_fk", + "tableFrom": "environment_variables", + "tableTo": "users", + "columnsFrom": ["last_updated_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.environments": { + "name": "environments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "is_eval": { + "name": "is_eval", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "declarative_source": { + "name": "declarative_source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_verified": { + "name": "is_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "verification_task_id": { + "name": "verification_task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verified_at": { + "name": "verified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "verification_error": { + "name": "verification_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "snapshot_id": { + "name": "snapshot_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "snapshot_created_at": { + "name": "snapshot_created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "snapshot_expires_at": { + "name": "snapshot_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "snapshot_status": { + "name": "snapshot_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "environments_user_id_idx": { + "name": "environments_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "environments_created_by_user_id_idx": { + "name": "environments_created_by_user_id_idx", + "columns": [ + { + "expression": "created_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "environments_snapshot_expires_at_idx": { + "name": "environments_snapshot_expires_at_idx", + "columns": [ + { + "expression": "snapshot_expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "environments_name_unique": { + "name": "environments_name_unique", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "environments_user_id_users_id_fk": { + "name": "environments_user_id_users_id_fk", + "tableFrom": "environments", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "environments_created_by_user_id_users_id_fk": { + "name": "environments_created_by_user_id_users_id_fk", + "tableFrom": "environments", + "tableTo": "users", + "columnsFrom": ["created_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.fast_agent_conversations": { + "name": "fast_agent_conversations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner_automation": { + "name": "owner_automation", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "surface": { + "name": "surface", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "conversation_id": { + "name": "conversation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_reply_channel_id": { + "name": "current_reply_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "current_reply_thread_id": { + "name": "current_reply_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "current_reply_service_url": { + "name": "current_reply_service_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reply_target_verified": { + "name": "reply_target_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "compatibility_messages": { + "name": "compatibility_messages", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "opencode_session_id": { + "name": "opencode_session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "open_code_projection_hash": { + "name": "open_code_projection_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "open_code_projected_through_seq": { + "name": "open_code_projected_through_seq", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reasoning_effort": { + "name": "reasoning_effort", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title_edited_by_user_at": { + "name": "title_edited_by_user_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "llm_title_checkpoint": { + "name": "llm_title_checkpoint", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "legacy_conversation_ids": { + "name": "legacy_conversation_ids", + "type": "uuid[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::uuid[]" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "fast_agent_conversations_identity_unique": { + "name": "fast_agent_conversations_identity_unique", + "columns": [ + { + "expression": "surface", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_conversations_user_idx": { + "name": "fast_agent_conversations_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_conversations_owner_automation_idx": { + "name": "fast_agent_conversations_owner_automation_idx", + "columns": [ + { + "expression": "owner_automation", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_conversations_legacy_ids_idx": { + "name": "fast_agent_conversations_legacy_ids_idx", + "columns": [ + { + "expression": "legacy_conversation_ids", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "fast_agent_conversations_user_id_users_id_fk": { + "name": "fast_agent_conversations_user_id_users_id_fk", + "tableFrom": "fast_agent_conversations", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "fast_agent_conversations_owner_shape_check": { + "name": "fast_agent_conversations_owner_shape_check", + "value": "(\n (\"fast_agent_conversations\".\"user_id\" is not null and \"fast_agent_conversations\".\"owner_automation\" is null)\n or\n (\"fast_agent_conversations\".\"user_id\" is null and \"fast_agent_conversations\".\"owner_automation\" is not null)\n )" + } + }, + "isRLSEnabled": false + }, + "public.fast_agent_memory_events": { + "name": "fast_agent_memory_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "memory": { + "name": "memory", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "fast_agent_memory_events_status_created_idx": { + "name": "fast_agent_memory_events_status_created_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "fast_agent_memory_events_conversation_id_fast_agent_conversations_id_fk": { + "name": "fast_agent_memory_events_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "fast_agent_memory_events", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "fast_agent_memory_events_conversation_unique": { + "name": "fast_agent_memory_events_conversation_unique", + "nullsNotDistinct": false, + "columns": ["conversation_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.fast_agent_messages": { + "name": "fast_agent_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "conversation_seq": { + "name": "conversation_seq", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "turn_id": { + "name": "turn_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "turn_seq": { + "name": "turn_seq", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "ts": { + "name": "ts", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "observed_at": { + "name": "observed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content_blocks": { + "name": "content_blocks", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "native_session_id": { + "name": "native_session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "native_message_id": { + "name": "native_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "fast_agent_messages_conversation_event_unique": { + "name": "fast_agent_messages_conversation_event_unique", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_messages_conversation_order_idx": { + "name": "fast_agent_messages_conversation_order_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "conversation_seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_messages_conversation_seq_unique": { + "name": "fast_agent_messages_conversation_seq_unique", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "conversation_seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"fast_agent_messages\".\"conversation_seq\" is not null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_messages_legacy_order_idx": { + "name": "fast_agent_messages_legacy_order_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "ts", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "turn_seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "fast_agent_messages_conversation_id_fast_agent_conversations_id_fk": { + "name": "fast_agent_messages_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "fast_agent_messages", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.fast_agent_parent_events": { + "name": "fast_agent_parent_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "event_key": { + "name": "event_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent": { + "name": "parent", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "event": { + "name": "event", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "retry_task_start_run_id": { + "name": "retry_task_start_run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivered_at": { + "name": "delivered_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "discarded_at": { + "name": "discarded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "admission": { + "name": "admission", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "claimed_until": { + "name": "claimed_until", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "retry_at": { + "name": "retry_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "inference_retries": { + "name": "inference_retries", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "fast_agent_parent_events_pending_idx": { + "name": "fast_agent_parent_events_pending_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "delivered_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "discarded_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_parent_events_retry_run_idx": { + "name": "fast_agent_parent_events_retry_run_idx", + "columns": [ + { + "expression": "retry_task_start_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "fast_agent_parent_events_conversation_id_fast_agent_conversations_id_fk": { + "name": "fast_agent_parent_events_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "fast_agent_parent_events", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fast_agent_parent_events_retry_task_start_run_id_task_runs_id_fk": { + "name": "fast_agent_parent_events_retry_task_start_run_id_task_runs_id_fk", + "tableFrom": "fast_agent_parent_events", + "tableTo": "task_runs", + "columnsFrom": ["retry_task_start_run_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "fast_agent_parent_events_event_key_unique": { + "name": "fast_agent_parent_events_event_key_unique", + "nullsNotDistinct": false, + "columns": ["event_key"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.fast_agent_personalization_snapshots": { + "name": "fast_agent_personalization_snapshots", + "schema": "", + "columns": { + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "instructions": { + "name": "instructions", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "learn_from_conversations": { + "name": "learn_from_conversations", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "fast_agent_personalization_snapshots_conversation_id_fast_agent_conversations_id_fk": { + "name": "fast_agent_personalization_snapshots_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "fast_agent_personalization_snapshots", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fast_agent_personalization_snapshots_user_id_users_id_fk": { + "name": "fast_agent_personalization_snapshots_user_id_users_id_fk", + "tableFrom": "fast_agent_personalization_snapshots", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "fast_agent_personalization_snapshots_conversation_id_user_id_pk": { + "name": "fast_agent_personalization_snapshots_conversation_id_user_id_pk", + "columns": ["conversation_id", "user_id"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.fast_agent_pr_feedback_deliveries": { + "name": "fast_agent_pr_feedback_deliveries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "feedback_id": { + "name": "feedback_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "delivered_at": { + "name": "delivered_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "fast_agent_pr_feedback_deliveries_identity_unique": { + "name": "fast_agent_pr_feedback_deliveries_identity_unique", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "feedback_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_pr_feedback_deliveries_task_idx": { + "name": "fast_agent_pr_feedback_deliveries_task_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "fast_agent_pr_feedback_deliveries_conversation_id_fast_agent_conversations_id_fk": { + "name": "fast_agent_pr_feedback_deliveries_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "fast_agent_pr_feedback_deliveries", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fast_agent_pr_feedback_deliveries_task_id_tasks_id_fk": { + "name": "fast_agent_pr_feedback_deliveries_task_id_tasks_id_fk", + "tableFrom": "fast_agent_pr_feedback_deliveries", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.fast_agent_provider_messages": { + "name": "fast_agent_provider_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "thread_id": { + "name": "thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "fast_agent_provider_messages_route_unique": { + "name": "fast_agent_provider_messages_route_unique", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_provider_messages_conversation_idx": { + "name": "fast_agent_provider_messages_conversation_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "fast_agent_provider_messages_thread_idx": { + "name": "fast_agent_provider_messages_thread_idx", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "thread_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "fast_agent_provider_messages_conversation_id_fast_agent_conversations_id_fk": { + "name": "fast_agent_provider_messages_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "fast_agent_provider_messages", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "fast_agent_provider_messages_provider_v3_check": { + "name": "fast_agent_provider_messages_provider_v3_check", + "value": "\"fast_agent_provider_messages\".\"provider\" in ('discord', 'slack', 'teams', 'telegram', 'agentmail')" + } + }, + "isRLSEnabled": false + }, + "public.github_installations": { + "name": "github_installations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "installation_id": { + "name": "installation_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "app_id": { + "name": "app_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "account_login": { + "name": "account_login", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "account_type": { + "name": "account_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permissions": { + "name": "permissions", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "installed_by_user_id": { + "name": "installed_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "members_count": { + "name": "members_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "suspended_at": { + "name": "suspended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "github_installations_account_login_idx": { + "name": "github_installations_account_login_idx", + "columns": [ + { + "expression": "account_login", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_installations_deployment_installation_unique": { + "name": "github_installations_deployment_installation_unique", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "github_installations_user_id_users_id_fk": { + "name": "github_installations_user_id_users_id_fk", + "tableFrom": "github_installations", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "github_installations_installed_by_user_id_users_id_fk": { + "name": "github_installations_installed_by_user_id_users_id_fk", + "tableFrom": "github_installations", + "tableTo": "users", + "columnsFrom": ["installed_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.github_pending_installations": { + "name": "github_pending_installations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requested_by_user_id": { + "name": "requested_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "app_id": { + "name": "app_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "github_pending_installations_requested_by_user_id_idx": { + "name": "github_pending_installations_requested_by_user_id_idx", + "columns": [ + { + "expression": "requested_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "github_pending_installations_user_id_users_id_fk": { + "name": "github_pending_installations_user_id_users_id_fk", + "tableFrom": "github_pending_installations", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "github_pending_installations_requested_by_user_id_users_id_fk": { + "name": "github_pending_installations_requested_by_user_id_users_id_fk", + "tableFrom": "github_pending_installations", + "tableTo": "users", + "columnsFrom": ["requested_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.github_user_mappings": { + "name": "github_user_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "github_login": { + "name": "github_login", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "github_user_id": { + "name": "github_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_expires_at": { + "name": "token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "github_user_mappings_github_login_idx": { + "name": "github_user_mappings_github_login_idx", + "columns": [ + { + "expression": "github_login", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_user_mappings_user_id_idx": { + "name": "github_user_mappings_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "github_user_mappings_user_id_users_id_fk": { + "name": "github_user_mappings_user_id_users_id_fk", + "tableFrom": "github_user_mappings", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "github_user_mappings_unique": { + "name": "github_user_mappings_unique", + "nullsNotDistinct": false, + "columns": ["github_user_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.instance_skills": { + "name": "instance_skills", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "instance_skills_name_unique_idx": { + "name": "instance_skills_name_unique_idx", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "instance_skills_created_by_user_id_users_id_fk": { + "name": "instance_skills_created_by_user_id_users_id_fk", + "tableFrom": "instance_skills", + "tableTo": "users", + "columnsFrom": ["created_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.invites": { + "name": "invites", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "invited_by_user_id": { + "name": "invited_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "max_uses": { + "name": "max_uses", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "used_count": { + "name": "used_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "invites_token_hash_unique": { + "name": "invites_token_hash_unique", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "invites_created_at_idx": { + "name": "invites_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "invites_invited_by_user_id_users_id_fk": { + "name": "invites_invited_by_user_id_users_id_fk", + "tableFrom": "invites", + "tableTo": "users", + "columnsFrom": ["invited_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.license_usage_observations": { + "name": "license_usage_observations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "observed_at": { + "name": "observed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "active_users": { + "name": "active_users", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "delivered_at": { + "name": "delivered_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_attempted_at": { + "name": "last_attempted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "license_usage_observations_pending_idx": { + "name": "license_usage_observations_pending_idx", + "columns": [ + { + "expression": "delivered_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.linear_pending_selections": { + "name": "linear_pending_selections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "linear_organization_id": { + "name": "linear_organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "step": { + "name": "step", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'awaiting_workspace'" + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "selected_repo": { + "name": "selected_repo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_options": { + "name": "workspace_options", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "linear_pending_selections_expires_at_idx": { + "name": "linear_pending_selections_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "linear_pending_selections_step_idx": { + "name": "linear_pending_selections_step_idx", + "columns": [ + { + "expression": "step", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "linear_pending_selections_user_id_users_id_fk": { + "name": "linear_pending_selections_user_id_users_id_fk", + "tableFrom": "linear_pending_selections", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "linear_pending_selections_session_id_unique": { + "name": "linear_pending_selections_session_id_unique", + "nullsNotDistinct": false, + "columns": ["session_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_inference_usage_events": { + "name": "task_inference_usage_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'opencode'" + }, + "usage_type": { + "name": "usage_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'inference'" + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "environment_id": { + "name": "environment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "event_key": { + "name": "event_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "harness_session_id": { + "name": "harness_session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model_id": { + "name": "model_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "agent": { + "name": "agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "output_tokens": { + "name": "output_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reasoning_tokens": { + "name": "reasoning_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cache_read_tokens": { + "name": "cache_read_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cache_write_tokens": { + "name": "cache_write_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_tokens": { + "name": "total_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "context_tokens": { + "name": "context_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cost_micro_usd": { + "name": "cost_micro_usd", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cost_source": { + "name": "cost_source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pricing_metadata": { + "name": "pricing_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "message_created_at": { + "name": "message_created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "message_completed_at": { + "name": "message_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_inference_usage_events_session_message_unique": { + "name": "task_inference_usage_events_session_message_unique", + "columns": [ + { + "expression": "harness_session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_inference_usage_events_event_key_unique": { + "name": "task_inference_usage_events_event_key_unique", + "columns": [ + { + "expression": "event_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_inference_usage_events_task_id_idx": { + "name": "task_inference_usage_events_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_inference_usage_events_run_id_idx": { + "name": "task_inference_usage_events_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_inference_usage_events_user_id_idx": { + "name": "task_inference_usage_events_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_inference_usage_events_environment_id_idx": { + "name": "task_inference_usage_events_environment_id_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_inference_usage_events_session_id_idx": { + "name": "task_inference_usage_events_session_id_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_inference_usage_events_provider_model_idx": { + "name": "task_inference_usage_events_provider_model_idx", + "columns": [ + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "model_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_inference_usage_events_created_at_idx": { + "name": "task_inference_usage_events_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_inference_usage_events_task_id_tasks_id_fk": { + "name": "task_inference_usage_events_task_id_tasks_id_fk", + "tableFrom": "task_inference_usage_events", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_inference_usage_events_run_id_task_runs_id_fk": { + "name": "task_inference_usage_events_run_id_task_runs_id_fk", + "tableFrom": "task_inference_usage_events", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "task_inference_usage_events_user_id_users_id_fk": { + "name": "task_inference_usage_events_user_id_users_id_fk", + "tableFrom": "task_inference_usage_events", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "task_inference_usage_events_environment_id_environments_id_fk": { + "name": "task_inference_usage_events_environment_id_environments_id_fk", + "tableFrom": "task_inference_usage_events", + "tableTo": "environments", + "columnsFrom": ["environment_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "task_inference_usage_events_session_id_sessions_id_fk": { + "name": "task_inference_usage_events_session_id_sessions_id_fk", + "tableFrom": "task_inference_usage_events", + "tableTo": "sessions", + "columnsFrom": ["session_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_connections": { + "name": "mcp_connections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mcp_id": { + "name": "mcp_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "connection_role": { + "name": "connection_role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'default'" + }, + "auth_config": { + "name": "auth_config", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "auth_status": { + "name": "auth_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token_expires_at": { + "name": "token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mcp_connections_user_id_idx": { + "name": "mcp_connections_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_connections_role_idx": { + "name": "mcp_connections_role_idx", + "columns": [ + { + "expression": "mcp_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "connection_role", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mcp_connections_user_id_users_id_fk": { + "name": "mcp_connections_user_id_users_id_fk", + "tableFrom": "mcp_connections", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "mcp_connections_user_mcp_id_unique": { + "name": "mcp_connections_user_mcp_id_unique", + "nullsNotDistinct": true, + "columns": ["user_id", "mcp_id", "connection_role"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_oauth_replays": { + "name": "mcp_oauth_replays", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mcp_id": { + "name": "mcp_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "connection_role": { + "name": "connection_role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'default'" + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "redirect_to": { + "name": "redirect_to", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mcp_oauth_replays_connection_id_idx": { + "name": "mcp_oauth_replays_connection_id_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_oauth_replays_user_id_idx": { + "name": "mcp_oauth_replays_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_oauth_replays_expires_at_idx": { + "name": "mcp_oauth_replays_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mcp_oauth_replays_connection_id_mcp_connections_id_fk": { + "name": "mcp_oauth_replays_connection_id_mcp_connections_id_fk", + "tableFrom": "mcp_oauth_replays", + "tableTo": "mcp_connections", + "columnsFrom": ["connection_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mcp_oauth_replays_user_id_users_id_fk": { + "name": "mcp_oauth_replays_user_id_users_id_fk", + "tableFrom": "mcp_oauth_replays", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "mcp_oauth_replays_token_unique": { + "name": "mcp_oauth_replays_token_unique", + "nullsNotDistinct": false, + "columns": ["token"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.microsoft_auth_user_mappings": { + "name": "microsoft_auth_user_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "auth_account_id": { + "name": "auth_account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "microsoft_tenant_id": { + "name": "microsoft_tenant_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "microsoft_aad_object_id": { + "name": "microsoft_aad_object_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "microsoft_auth_user_mappings_user_id_idx": { + "name": "microsoft_auth_user_mappings_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "microsoft_auth_user_mappings_account_id_idx": { + "name": "microsoft_auth_user_mappings_account_id_idx", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "microsoft_auth_user_mappings_auth_account_idx": { + "name": "microsoft_auth_user_mappings_auth_account_idx", + "columns": [ + { + "expression": "auth_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "microsoft_auth_user_mappings_aad_object_unique": { + "name": "microsoft_auth_user_mappings_aad_object_unique", + "columns": [ + { + "expression": "microsoft_tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "microsoft_aad_object_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "microsoft_auth_user_mappings_auth_account_id_auth_accounts_id_fk": { + "name": "microsoft_auth_user_mappings_auth_account_id_auth_accounts_id_fk", + "tableFrom": "microsoft_auth_user_mappings", + "tableTo": "auth_accounts", + "columnsFrom": ["auth_account_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "microsoft_auth_user_mappings_user_id_auth_users_id_fk": { + "name": "microsoft_auth_user_mappings_user_id_auth_users_id_fk", + "tableFrom": "microsoft_auth_user_mappings", + "tableTo": "auth_users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notion_directory_users": { + "name": "notion_directory_users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "notion_user_id": { + "name": "notion_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_deleted": { + "name": "is_deleted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "notion_directory_users_unique": { + "name": "notion_directory_users_unique", + "nullsNotDistinct": false, + "columns": ["notion_user_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_state": { + "name": "oauth_state", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "code_verifier": { + "name": "code_verifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "replay_token": { + "name": "replay_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "oauth_state_connection_id_idx": { + "name": "oauth_state_connection_id_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_state_replay_token_idx": { + "name": "oauth_state_replay_token_idx", + "columns": [ + { + "expression": "replay_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_state_expires_at_idx": { + "name": "oauth_state_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_state_connection_id_mcp_connections_id_fk": { + "name": "oauth_state_connection_id_mcp_connections_id_fk", + "tableFrom": "oauth_state", + "tableTo": "mcp_connections", + "columnsFrom": ["connection_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pr_review_auto_preferences": { + "name": "pr_review_auto_preferences", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source_control_provider": { + "name": "source_control_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "host": { + "name": "host", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "repository_id": { + "name": "repository_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "repository_identity_key": { + "name": "repository_identity_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repository": { + "name": "repository", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pr_number": { + "name": "pr_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "enabled_by_user_id": { + "name": "enabled_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled_at": { + "name": "enabled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "source_task_id": { + "name": "source_task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_destination_key": { + "name": "source_destination_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pr_review_auto_preferences_identity_unique": { + "name": "pr_review_auto_preferences_identity_unique", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository_identity_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pr_review_auto_preferences_repository_idx": { + "name": "pr_review_auto_preferences_repository_idx", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pr_review_auto_preferences_repository_id_repositories_id_fk": { + "name": "pr_review_auto_preferences_repository_id_repositories_id_fk", + "tableFrom": "pr_review_auto_preferences", + "tableTo": "repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pr_review_auto_preferences_enabled_by_user_id_users_id_fk": { + "name": "pr_review_auto_preferences_enabled_by_user_id_users_id_fk", + "tableFrom": "pr_review_auto_preferences", + "tableTo": "users", + "columnsFrom": ["enabled_by_user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pr_review_auto_preferences_source_task_id_tasks_id_fk": { + "name": "pr_review_auto_preferences_source_task_id_tasks_id_fk", + "tableFrom": "pr_review_auto_preferences", + "tableTo": "tasks", + "columnsFrom": ["source_task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pr_review_cycles": { + "name": "pr_review_cycles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source_control_provider": { + "name": "source_control_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repository": { + "name": "repository", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pr_number": { + "name": "pr_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "review_head_sha": { + "name": "review_head_sha", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cycle_id": { + "name": "cycle_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "pr_review_cycles_source_unique": { + "name": "pr_review_cycles_source_unique", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "review_head_sha", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "cycle_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pr_review_event_deliveries": { + "name": "pr_review_event_deliveries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "event_id": { + "name": "event_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "due_at": { + "name": "due_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "deferrals": { + "name": "deferrals", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pr_review_event_deliveries_event_task_unique": { + "name": "pr_review_event_deliveries_event_task_unique", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pr_review_event_deliveries_due_idx": { + "name": "pr_review_event_deliveries_due_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "due_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lease_expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pr_review_event_deliveries_event_id_pr_review_events_id_fk": { + "name": "pr_review_event_deliveries_event_id_pr_review_events_id_fk", + "tableFrom": "pr_review_event_deliveries", + "tableTo": "pr_review_events", + "columnsFrom": ["event_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pr_review_event_deliveries_task_id_tasks_id_fk": { + "name": "pr_review_event_deliveries_task_id_tasks_id_fk", + "tableFrom": "pr_review_event_deliveries", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pr_review_event_deliveries_status_check": { + "name": "pr_review_event_deliveries_status_check", + "value": "\"pr_review_event_deliveries\".\"status\" in ('pending', 'processing', 'delivered', 'suppressed')" + } + }, + "isRLSEnabled": false + }, + "public.pr_review_events": { + "name": "pr_review_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "event_key": { + "name": "event_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_control_provider": { + "name": "source_control_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repository": { + "name": "repository", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pr_number": { + "name": "pr_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "event": { + "name": "event", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "batch_kind": { + "name": "batch_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "batch_id": { + "name": "batch_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "review_head_sha": { + "name": "review_head_sha", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sealed_at": { + "name": "sealed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "superseded": { + "name": "superseded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "available_at": { + "name": "available_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "observed_at": { + "name": "observed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pr_review_events_source_unique": { + "name": "pr_review_events_source_unique", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "event_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pr_review_events_pr_idx": { + "name": "pr_review_events_pr_idx", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pr_review_events_batch_kind_check": { + "name": "pr_review_events_batch_kind_check", + "value": "\"pr_review_events\".\"batch_kind\" in ('human', 'roomote')" + } + }, + "isRLSEnabled": false + }, + "public.pr_review_notification_deliveries": { + "name": "pr_review_notification_deliveries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "notification_unit_id": { + "name": "notification_unit_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "destination_kind": { + "name": "destination_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "destination_key": { + "name": "destination_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "due_at": { + "name": "due_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "deferrals": { + "name": "deferrals", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "attempt": { + "name": "attempt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "route_provider": { + "name": "route_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "route_workspace_id": { + "name": "route_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "route_channel_id": { + "name": "route_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "route_thread_id": { + "name": "route_thread_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "follow_up_prompt": { + "name": "follow_up_prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "target_task_id": { + "name": "target_task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "acting_user_id": { + "name": "acting_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_message_id": { + "name": "provider_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_claimed_at": { + "name": "action_claimed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "dispatch_key": { + "name": "dispatch_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dispatched_run_id": { + "name": "dispatched_run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pr_review_notification_deliveries_destination_unique": { + "name": "pr_review_notification_deliveries_destination_unique", + "columns": [ + { + "expression": "notification_unit_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "destination_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "destination_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pr_review_notification_deliveries_dispatch_key_unique": { + "name": "pr_review_notification_deliveries_dispatch_key_unique", + "columns": [ + { + "expression": "dispatch_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pr_review_notification_deliveries_due_idx": { + "name": "pr_review_notification_deliveries_due_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "due_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lease_expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pr_review_notification_deliveries_destination_idx": { + "name": "pr_review_notification_deliveries_destination_idx", + "columns": [ + { + "expression": "destination_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "destination_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pr_review_notification_deliveries_notification_unit_id_pr_review_notification_units_id_fk": { + "name": "pr_review_notification_deliveries_notification_unit_id_pr_review_notification_units_id_fk", + "tableFrom": "pr_review_notification_deliveries", + "tableTo": "pr_review_notification_units", + "columnsFrom": ["notification_unit_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pr_review_notification_deliveries_task_id_tasks_id_fk": { + "name": "pr_review_notification_deliveries_task_id_tasks_id_fk", + "tableFrom": "pr_review_notification_deliveries", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pr_review_notification_deliveries_target_task_id_tasks_id_fk": { + "name": "pr_review_notification_deliveries_target_task_id_tasks_id_fk", + "tableFrom": "pr_review_notification_deliveries", + "tableTo": "tasks", + "columnsFrom": ["target_task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pr_review_notification_deliveries_acting_user_id_users_id_fk": { + "name": "pr_review_notification_deliveries_acting_user_id_users_id_fk", + "tableFrom": "pr_review_notification_deliveries", + "tableTo": "users", + "columnsFrom": ["acting_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pr_review_notification_deliveries_destination_kind_check": { + "name": "pr_review_notification_deliveries_destination_kind_check", + "value": "\"pr_review_notification_deliveries\".\"destination_kind\" in ('fast_conversation', 'task')" + }, + "pr_review_notification_deliveries_status_check": { + "name": "pr_review_notification_deliveries_status_check", + "value": "\"pr_review_notification_deliveries\".\"status\" in ('pending', 'claimed', 'prepared', 'prompt_posting', 'awaiting_user_action', 'auto_dispatch_pending', 'completed', 'suppressed', 'dismissed')" + } + }, + "isRLSEnabled": false + }, + "public.pr_review_notification_unit_events": { + "name": "pr_review_notification_unit_events", + "schema": "", + "columns": { + "unit_id": { + "name": "unit_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "attached_at": { + "name": "attached_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pr_review_notification_unit_events_event_unique": { + "name": "pr_review_notification_unit_events_event_unique", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pr_review_notification_unit_events_unit_id_pr_review_notification_units_id_fk": { + "name": "pr_review_notification_unit_events_unit_id_pr_review_notification_units_id_fk", + "tableFrom": "pr_review_notification_unit_events", + "tableTo": "pr_review_notification_units", + "columnsFrom": ["unit_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pr_review_notification_unit_events_event_id_pr_review_events_id_fk": { + "name": "pr_review_notification_unit_events_event_id_pr_review_events_id_fk", + "tableFrom": "pr_review_notification_unit_events", + "tableTo": "pr_review_events", + "columnsFrom": ["event_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "pr_review_notification_unit_events_pk": { + "name": "pr_review_notification_unit_events_pk", + "columns": ["unit_id", "event_id"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pr_review_notification_units": { + "name": "pr_review_notification_units", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source_control_provider": { + "name": "source_control_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "host": { + "name": "host", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "repository_id": { + "name": "repository_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "repository_identity_key": { + "name": "repository_identity_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repository": { + "name": "repository", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pr_number": { + "name": "pr_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "head_sha": { + "name": "head_sha", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "head_identity_key": { + "name": "head_identity_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "episode_kind": { + "name": "episode_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "episode_id": { + "name": "episode_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "due_at": { + "name": "due_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "first_observed_at": { + "name": "first_observed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "last_observed_at": { + "name": "last_observed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "sealed_at": { + "name": "sealed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pr_review_notification_units_identity_unique": { + "name": "pr_review_notification_units_identity_unique", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository_identity_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "head_identity_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "episode_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "episode_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pr_review_notification_units_open_head_idx": { + "name": "pr_review_notification_units_open_head_idx", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "head_sha", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sealed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pr_review_notification_units_repository_id_repositories_id_fk": { + "name": "pr_review_notification_units_repository_id_repositories_id_fk", + "tableFrom": "pr_review_notification_units", + "tableTo": "repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pr_review_notification_units_episode_kind_check": { + "name": "pr_review_notification_units_episode_kind_check", + "value": "\"pr_review_notification_units\".\"episode_kind\" in ('roomote_cycle', 'human', 'automated', 'ci')" + } + }, + "isRLSEnabled": false + }, + "public.pull_request_facts": { + "name": "pull_request_facts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "repository_id": { + "name": "repository_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "repository_full_name": { + "name": "repository_full_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_control_provider": { + "name": "source_control_provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'github'" + }, + "external_pull_request_id": { + "name": "external_pull_request_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "pr_number": { + "name": "pr_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "html_url": { + "name": "html_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "author_login": { + "name": "author_login", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "labels": { + "name": "labels", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "changed_files": { + "name": "changed_files", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "changed_file_count": { + "name": "changed_file_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "files_capped": { + "name": "files_capped", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "reviews_capped": { + "name": "reviews_capped", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "additions": { + "name": "additions", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "deletions": { + "name": "deletions", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reviews": { + "name": "reviews", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "enriched_at": { + "name": "enriched_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "enriched_for_updated_at": { + "name": "enriched_for_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "enrichment_failed_at": { + "name": "enrichment_failed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at_remote": { + "name": "created_at_remote", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at_remote": { + "name": "updated_at_remote", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "closed_at_remote": { + "name": "closed_at_remote", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "merged_at_remote": { + "name": "merged_at_remote", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "synced_at": { + "name": "synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pull_request_facts_deployment_repo_pr_unique": { + "name": "pull_request_facts_deployment_repo_pr_unique", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pull_request_facts_deployment_created_idx": { + "name": "pull_request_facts_deployment_created_idx", + "columns": [ + { + "expression": "created_at_remote", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pull_request_facts_deployment_repo_created_idx": { + "name": "pull_request_facts_deployment_repo_created_idx", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at_remote", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pull_request_facts_deployment_state_created_idx": { + "name": "pull_request_facts_deployment_state_created_idx", + "columns": [ + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at_remote", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pull_request_facts_deployment_author_created_idx": { + "name": "pull_request_facts_deployment_author_created_idx", + "columns": [ + { + "expression": "author_login", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at_remote", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pull_request_facts_deployment_updated_idx": { + "name": "pull_request_facts_deployment_updated_idx", + "columns": [ + { + "expression": "updated_at_remote", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pull_request_facts_repository_id_repositories_id_fk": { + "name": "pull_request_facts_repository_id_repositories_id_fk", + "tableFrom": "pull_request_facts", + "tableTo": "repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pull_request_facts_source_control_provider_check": { + "name": "pull_request_facts_source_control_provider_check", + "value": "\"pull_request_facts\".\"source_control_provider\" in ('github', 'gitlab', 'gitea', 'ado', 'bitbucket')" + } + }, + "isRLSEnabled": false + }, + "public.pull_request_sync_states": { + "name": "pull_request_sync_states", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "repository_id": { + "name": "repository_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "last_incremental_updated_at": { + "name": "last_incremental_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "backfill_completed_at": { + "name": "backfill_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "cooldown_until": { + "name": "cooldown_until", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_successful_sync_at": { + "name": "last_successful_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_attempted_sync_at": { + "name": "last_attempted_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_error_at": { + "name": "last_error_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_error_message": { + "name": "last_error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pull_request_sync_states_repo_unique": { + "name": "pull_request_sync_states_repo_unique", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pull_request_sync_states_deployment_updated_idx": { + "name": "pull_request_sync_states_deployment_updated_idx", + "columns": [ + { + "expression": "last_successful_sync_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pull_request_sync_states_cooldown_idx": { + "name": "pull_request_sync_states_cooldown_idx", + "columns": [ + { + "expression": "cooldown_until", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pull_request_sync_states_repository_id_repositories_id_fk": { + "name": "pull_request_sync_states_repository_id_repositories_id_fk", + "tableFrom": "pull_request_sync_states", + "tableTo": "repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.repositories": { + "name": "repositories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "source_control_provider": { + "name": "source_control_provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'github'" + }, + "installation_id": { + "name": "installation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "github_repo_id": { + "name": "github_repo_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "external_repo_id": { + "name": "external_repo_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "host": { + "name": "host", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "full_name": { + "name": "full_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "private": { + "name": "private", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "default_branch": { + "name": "default_branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'main'" + }, + "clone_url": { + "name": "clone_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "html_url": { + "name": "html_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permissions": { + "name": "permissions", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "linked_by_user_id": { + "name": "linked_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "repositories_source_control_provider_idx": { + "name": "repositories_source_control_provider_idx", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repositories_installation_id_idx": { + "name": "repositories_installation_id_idx", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repositories_full_name_idx": { + "name": "repositories_full_name_idx", + "columns": [ + { + "expression": "full_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repositories_provider_host_full_name_idx": { + "name": "repositories_provider_host_full_name_idx", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "host", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "full_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repositories_deployment_active_installation_idx": { + "name": "repositories_deployment_active_installation_idx", + "columns": [ + { + "expression": "is_active", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repositories_deployment_github_repo_unique": { + "name": "repositories_deployment_github_repo_unique", + "columns": [ + { + "expression": "github_repo_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repositories_provider_host_external_repo_unique": { + "name": "repositories_provider_host_external_repo_unique", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "coalesce(\"host\", '')", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "external_repo_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repositories_provider_host_full_name_unique": { + "name": "repositories_provider_host_full_name_unique", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "coalesce(\"host\", '')", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "full_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "repositories_installation_id_github_installations_id_fk": { + "name": "repositories_installation_id_github_installations_id_fk", + "tableFrom": "repositories", + "tableTo": "github_installations", + "columnsFrom": ["installation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "repositories_user_id_users_id_fk": { + "name": "repositories_user_id_users_id_fk", + "tableFrom": "repositories", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "repositories_linked_by_user_id_users_id_fk": { + "name": "repositories_linked_by_user_id_users_id_fk", + "tableFrom": "repositories", + "tableTo": "users", + "columnsFrom": ["linked_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "repositories_source_control_provider_check": { + "name": "repositories_source_control_provider_check", + "value": "\"repositories\".\"source_control_provider\" in ('github', 'gitlab', 'gitea', 'ado', 'bitbucket')" + }, + "repositories_github_shape_check": { + "name": "repositories_github_shape_check", + "value": "\"repositories\".\"source_control_provider\" != 'github' OR (\"repositories\".\"installation_id\" IS NOT NULL AND \"repositories\".\"github_repo_id\" IS NOT NULL)" + }, + "repositories_gitlab_shape_check": { + "name": "repositories_gitlab_shape_check", + "value": "\"repositories\".\"source_control_provider\" != 'gitlab' OR \"repositories\".\"external_repo_id\" IS NOT NULL" + }, + "repositories_gitea_shape_check": { + "name": "repositories_gitea_shape_check", + "value": "\"repositories\".\"source_control_provider\" != 'gitea' OR \"repositories\".\"external_repo_id\" IS NOT NULL" + }, + "repositories_ado_shape_check": { + "name": "repositories_ado_shape_check", + "value": "\"repositories\".\"source_control_provider\" != 'ado' OR \"repositories\".\"external_repo_id\" IS NOT NULL" + }, + "repositories_bitbucket_shape_check": { + "name": "repositories_bitbucket_shape_check", + "value": "\"repositories\".\"source_control_provider\" != 'bitbucket' OR \"repositories\".\"external_repo_id\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.repository_automation_signals": { + "name": "repository_automation_signals", + "schema": "", + "columns": { + "repository_id": { + "name": "repository_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "signals_version": { + "name": "signals_version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "collected_at": { + "name": "collected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "partial": { + "name": "partial", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "repository_automation_signals_collected_idx": { + "name": "repository_automation_signals_collected_idx", + "columns": [ + { + "expression": "collected_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "repository_automation_signals_repository_id_repositories_id_fk": { + "name": "repository_automation_signals_repository_id_repositories_id_fk", + "tableFrom": "repository_automation_signals", + "tableTo": "repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "repository_automation_signals_repository_id_signals_version_pk": { + "name": "repository_automation_signals_repository_id_signals_version_pk", + "columns": ["repository_id", "signals_version"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sandbox_oidc_targets": { + "name": "sandbox_oidc_targets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "environment_id": { + "name": "environment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "compute_provider": { + "name": "compute_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "compute_provider_id": { + "name": "compute_provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_kind": { + "name": "target_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "audience": { + "name": "audience", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_file": { + "name": "token_file", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "aws_role_arn": { + "name": "aws_role_arn", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "aws_region": { + "name": "aws_region", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_at": { + "name": "refresh_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sandbox_oidc_targets_environment_id_idx": { + "name": "sandbox_oidc_targets_environment_id_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sandbox_oidc_targets_run_id_idx": { + "name": "sandbox_oidc_targets_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sandbox_oidc_targets_refresh_at_idx": { + "name": "sandbox_oidc_targets_refresh_at_idx", + "columns": [ + { + "expression": "refresh_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sandbox_oidc_targets_provider_target_file_unique": { + "name": "sandbox_oidc_targets_provider_target_file_unique", + "columns": [ + { + "expression": "compute_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "compute_provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "token_file", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sandbox_oidc_targets_environment_id_environments_id_fk": { + "name": "sandbox_oidc_targets_environment_id_environments_id_fk", + "tableFrom": "sandbox_oidc_targets", + "tableTo": "environments", + "columnsFrom": ["environment_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sandbox_oidc_targets_run_id_task_runs_id_fk": { + "name": "sandbox_oidc_targets_run_id_task_runs_id_fk", + "tableFrom": "sandbox_oidc_targets", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sandbox_oidc_targets_owner_required": { + "name": "sandbox_oidc_targets_owner_required", + "value": "run_id IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.session_backfill_state": { + "name": "session_backfill_state", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "phase": { + "name": "phase", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'fast_conversations'" + }, + "cursor_created_at": { + "name": "cursor_created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "cursor_id": { + "name": "cursor_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_run_at": { + "name": "last_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "session_backfill_state_phase_check": { + "name": "session_backfill_state_phase_check", + "value": "\"session_backfill_state\".\"phase\" in ('fast_conversations', 'fast_tasks', 'tasks', 'participants')" + }, + "session_backfill_state_cursor_shape_check": { + "name": "session_backfill_state_cursor_shape_check", + "value": "(\"session_backfill_state\".\"cursor_created_at\" IS NULL) = (\"session_backfill_state\".\"cursor_id\" IS NULL)" + } + }, + "isRLSEnabled": false + }, + "public.session_participants": { + "name": "session_participants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "last_read_event_at": { + "name": "last_read_event_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_read_event_id": { + "name": "last_read_event_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_notified_event_at": { + "name": "last_notified_event_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_notified_event_id": { + "name": "last_notified_event_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "session_participants_session_user_unique": { + "name": "session_participants_session_user_unique", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "session_participants_user_id_idx": { + "name": "session_participants_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_participants_session_id_sessions_id_fk": { + "name": "session_participants_session_id_sessions_id_fk", + "tableFrom": "session_participants", + "tableTo": "sessions", + "columnsFrom": ["session_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "session_participants_user_id_users_id_fk": { + "name": "session_participants_user_id_users_id_fk", + "tableFrom": "session_participants", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "session_participants_role_check": { + "name": "session_participants_role_check", + "value": "\"session_participants\".\"role\" in ('owner', 'member')" + } + }, + "isRLSEnabled": false + }, + "public.session_pins": { + "name": "session_pins", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "session_pins_user_session_unique": { + "name": "session_pins_user_session_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "session_pins_user_updated_at_idx": { + "name": "session_pins_user_updated_at_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "session_pins_session_id_idx": { + "name": "session_pins_session_id_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_pins_session_id_sessions_id_fk": { + "name": "session_pins_session_id_sessions_id_fk", + "tableFrom": "session_pins", + "tableTo": "sessions", + "columnsFrom": ["session_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "session_pins_user_id_users_id_fk": { + "name": "session_pins_user_id_users_id_fk", + "tableFrom": "session_pins", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session_tasks": { + "name": "session_tasks", + "schema": "", + "columns": { + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "attached_at": { + "name": "attached_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "origin": { + "name": "origin", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "session_tasks_task_id_unique": { + "name": "session_tasks_task_id_unique", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "session_tasks_session_attached_at_idx": { + "name": "session_tasks_session_attached_at_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "attached_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_tasks_session_id_sessions_id_fk": { + "name": "session_tasks_session_id_sessions_id_fk", + "tableFrom": "session_tasks", + "tableTo": "sessions", + "columnsFrom": ["session_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "session_tasks_task_id_tasks_id_fk": { + "name": "session_tasks_task_id_tasks_id_fk", + "tableFrom": "session_tasks", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "session_tasks_session_id_task_id_pk": { + "name": "session_tasks_session_id_task_id_pk", + "columns": ["session_id", "task_id"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "session_tasks_origin_check": { + "name": "session_tasks_origin_check", + "value": "\"session_tasks\".\"origin\" in ('direct_launch', 'fast_delegation', 'backfill', 'follow_up')" + } + }, + "isRLSEnabled": false + }, + "public.session_wakeups": { + "name": "session_wakeups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "conversation_id": { + "name": "conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prompt_signature": { + "name": "prompt_signature", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schedule": { + "name": "schedule", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "report_policy": { + "name": "report_policy", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "internal": { + "name": "internal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "run_count": { + "name": "run_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "max_runs": { + "name": "max_runs", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "until": { + "name": "until", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_run_at": { + "name": "next_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_fired_at": { + "name": "last_fired_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "session_wakeups_due_idx": { + "name": "session_wakeups_due_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_run_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "session_wakeups_conversation_idx": { + "name": "session_wakeups_conversation_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_wakeups_conversation_id_fast_agent_conversations_id_fk": { + "name": "session_wakeups_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "session_wakeups", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "session_wakeups_created_by_user_id_users_id_fk": { + "name": "session_wakeups_created_by_user_id_users_id_fk", + "tableFrom": "session_wakeups", + "tableTo": "users", + "columnsFrom": ["created_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "session_wakeups_status_check": { + "name": "session_wakeups_status_check", + "value": "\"session_wakeups\".\"status\" in ('active', 'completed', 'cancelled', 'failed')" + }, + "session_wakeups_report_policy_check": { + "name": "session_wakeups_report_policy_check", + "value": "\"session_wakeups\".\"report_policy\" in ('always', 'only_when_notable')" + } + }, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title_edited_by_user_at": { + "name": "title_edited_by_user_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "llm_title_checkpoint": { + "name": "llm_title_checkpoint", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "owner_kind": { + "name": "owner_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "owner_user_id": { + "name": "owner_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner_automation": { + "name": "owner_automation", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_surface": { + "name": "source_surface", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_trigger": { + "name": "source_trigger", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fast_conversation_id": { + "name": "fast_conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'visible'" + }, + "activity_at": { + "name": "activity_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "cached_status": { + "name": "cached_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "responding_until": { + "name": "responding_until", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sessions_visibility_activity_at_idx": { + "name": "sessions_visibility_activity_at_idx", + "columns": [ + { + "expression": "visibility", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "activity_at", + "isExpression": false, + "asc": false, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sessions_owner_user_id_idx": { + "name": "sessions_owner_user_id_idx", + "columns": [ + { + "expression": "owner_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sessions_fast_conversation_id_unique": { + "name": "sessions_fast_conversation_id_unique", + "columns": [ + { + "expression": "fast_conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"sessions\".\"fast_conversation_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_owner_user_id_users_id_fk": { + "name": "sessions_owner_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": ["owner_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "sessions_owner_automation_automations_key_fk": { + "name": "sessions_owner_automation_automations_key_fk", + "tableFrom": "sessions", + "tableTo": "automations", + "columnsFrom": ["owner_automation"], + "columnsTo": ["key"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "sessions_fast_conversation_id_fast_agent_conversations_id_fk": { + "name": "sessions_fast_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "sessions", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["fast_conversation_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "sessions_owner_shape_check": { + "name": "sessions_owner_shape_check", + "value": "(\"sessions\".\"owner_kind\" = 'user' AND \"sessions\".\"owner_automation\" IS NULL) OR (\"sessions\".\"owner_kind\" = 'automation' AND \"sessions\".\"owner_user_id\" IS NULL) OR (\"sessions\".\"owner_kind\" = 'system' AND \"sessions\".\"owner_user_id\" IS NULL AND \"sessions\".\"owner_automation\" IS NULL)" + }, + "sessions_owner_kind_check": { + "name": "sessions_owner_kind_check", + "value": "\"sessions\".\"owner_kind\" in ('user', 'automation', 'system')" + }, + "sessions_source_surface_check": { + "name": "sessions_source_surface_check", + "value": "\"sessions\".\"source_surface\" in ('web', 'api', 'slack', 'teams', 'telegram', 'discord', 'agentmail', 'linear', 'github', 'gitlab', 'gitea', 'ado', 'bitbucket', 'system', 'automation')" + }, + "sessions_source_trigger_check": { + "name": "sessions_source_trigger_check", + "value": "\"sessions\".\"source_trigger\" in ('message', 'webhook', 'schedule', 'manual')" + }, + "sessions_visibility_check": { + "name": "sessions_visibility_check", + "value": "\"sessions\".\"visibility\" in ('visible', 'hidden')" + }, + "sessions_cached_status_check": { + "name": "sessions_cached_status_check", + "value": "\"sessions\".\"cached_status\" IS NULL OR \"sessions\".\"cached_status\" in ('active', 'needs_input', 'blocked', 'ready')" + } + }, + "isRLSEnabled": false + }, + "public.setup_qualification_blocks": { + "name": "setup_qualification_blocks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'blocked'" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email_domain": { + "name": "email_domain", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "github_account_login": { + "name": "github_account_login", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "github_account_type": { + "name": "github_account_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "first_blocked_at": { + "name": "first_blocked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_blocked_at": { + "name": "last_blocked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "lifted_by_admin_user_id": { + "name": "lifted_by_admin_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lifted_by_admin_email": { + "name": "lifted_by_admin_email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "setup_qualification_blocks_deployment_user_reason_unique": { + "name": "setup_qualification_blocks_deployment_user_reason_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "reason", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "setup_qualification_blocks_deployment_status_idx": { + "name": "setup_qualification_blocks_deployment_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "setup_qualification_blocks_user_status_idx": { + "name": "setup_qualification_blocks_user_status_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "setup_qualification_blocks_user_id_users_id_fk": { + "name": "setup_qualification_blocks_user_id_users_id_fk", + "tableFrom": "setup_qualification_blocks", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_auth_tokens": { + "name": "slack_auth_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_user_id": { + "name": "slack_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_team_id": { + "name": "slack_team_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "thread_ts": { + "name": "thread_ts", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message_ts": { + "name": "message_ts", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "original_text": { + "name": "original_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_auth_tokens_expires_at_idx": { + "name": "slack_auth_tokens_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "slack_auth_tokens_token_unique": { + "name": "slack_auth_tokens_token_unique", + "nullsNotDistinct": false, + "columns": ["token"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_conversation_messages": { + "name": "slack_conversation_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "subject_user_id": { + "name": "subject_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_team_id": { + "name": "slack_team_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject_slack_user_id": { + "name": "subject_slack_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sender_user_id": { + "name": "sender_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sender_slack_user_id": { + "name": "sender_slack_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_channel_id": { + "name": "slack_channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "conversation_kind": { + "name": "conversation_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "thread_ts": { + "name": "thread_ts", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "message_ts": { + "name": "message_ts", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message_at": { + "name": "message_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "direction": { + "name": "direction", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "author_kind": { + "name": "author_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_conversation_messages_deployment_user_message_at_idx": { + "name": "slack_conversation_messages_deployment_user_message_at_idx", + "columns": [ + { + "expression": "subject_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "message_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_conversation_messages_deployment_user_thread_idx": { + "name": "slack_conversation_messages_deployment_user_thread_idx", + "columns": [ + { + "expression": "subject_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slack_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "thread_ts", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "message_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_conversation_messages_task_id_idx": { + "name": "slack_conversation_messages_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_conversation_messages_run_id_idx": { + "name": "slack_conversation_messages_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_conversation_messages_team_channel_message_unique": { + "name": "slack_conversation_messages_team_channel_message_unique", + "columns": [ + { + "expression": "slack_team_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slack_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "message_ts", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_conversation_messages_subject_user_id_users_id_fk": { + "name": "slack_conversation_messages_subject_user_id_users_id_fk", + "tableFrom": "slack_conversation_messages", + "tableTo": "users", + "columnsFrom": ["subject_user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "slack_conversation_messages_sender_user_id_users_id_fk": { + "name": "slack_conversation_messages_sender_user_id_users_id_fk", + "tableFrom": "slack_conversation_messages", + "tableTo": "users", + "columnsFrom": ["sender_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "slack_conversation_messages_task_id_tasks_id_fk": { + "name": "slack_conversation_messages_task_id_tasks_id_fk", + "tableFrom": "slack_conversation_messages", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "slack_conversation_messages_run_id_task_runs_id_fk": { + "name": "slack_conversation_messages_run_id_task_runs_id_fk", + "tableFrom": "slack_conversation_messages", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_directory_users": { + "name": "slack_directory_users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slack_user_id": { + "name": "slack_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_team_id": { + "name": "slack_team_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "real_name": { + "name": "real_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_deleted": { + "name": "is_deleted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_bot": { + "name": "is_bot", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_app_user": { + "name": "is_app_user", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "profile_updated_at": { + "name": "profile_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_directory_users_team_id_idx": { + "name": "slack_directory_users_team_id_idx", + "columns": [ + { + "expression": "slack_team_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "slack_directory_users_unique": { + "name": "slack_directory_users_unique", + "nullsNotDistinct": false, + "columns": ["slack_user_id", "slack_team_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_fast_integration_calls": { + "name": "slack_fast_integration_calls", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "fast_agent_conversation_id": { + "name": "fast_agent_conversation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_team_id": { + "name": "slack_team_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_channel": { + "name": "slack_channel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_thread_ts": { + "name": "slack_thread_ts", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_message_ts": { + "name": "slack_message_ts", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "integration_id": { + "name": "integration_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "arguments": { + "name": "arguments", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "result_preview": { + "name": "result_preview", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_fast_integration_calls_conversation_idx": { + "name": "slack_fast_integration_calls_conversation_idx", + "columns": [ + { + "expression": "fast_agent_conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_fast_integration_calls_user_idx": { + "name": "slack_fast_integration_calls_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_fast_integration_calls_status_idx": { + "name": "slack_fast_integration_calls_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_fast_integration_calls_fast_agent_conversation_id_fast_agent_conversations_id_fk": { + "name": "slack_fast_integration_calls_fast_agent_conversation_id_fast_agent_conversations_id_fk", + "tableFrom": "slack_fast_integration_calls", + "tableTo": "fast_agent_conversations", + "columnsFrom": ["fast_agent_conversation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "slack_fast_integration_calls_user_id_users_id_fk": { + "name": "slack_fast_integration_calls_user_id_users_id_fk", + "tableFrom": "slack_fast_integration_calls", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_installation_channels": { + "name": "slack_installation_channels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slack_installation_id": { + "name": "slack_installation_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_installation_channels_installation_id_idx": { + "name": "slack_installation_channels_installation_id_idx", + "columns": [ + { + "expression": "slack_installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_installation_channels_slack_installation_id_slack_installations_id_fk": { + "name": "slack_installation_channels_slack_installation_id_slack_installations_id_fk", + "tableFrom": "slack_installation_channels", + "tableTo": "slack_installations", + "columnsFrom": ["slack_installation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "slack_installation_channels_unique": { + "name": "slack_installation_channels_unique", + "nullsNotDistinct": false, + "columns": ["slack_installation_id", "channel_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_installations": { + "name": "slack_installations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "team_id": { + "name": "team_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "team_name": { + "name": "team_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "team_domain": { + "name": "team_domain", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "enterprise_id": { + "name": "enterprise_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "enterprise_name": { + "name": "enterprise_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "app_id": { + "name": "app_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bot_user_id": { + "name": "bot_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bot_name": { + "name": "bot_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "app_name": { + "name": "app_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bot_access_token": { + "name": "bot_access_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_access_token": { + "name": "user_access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'bot'" + }, + "installed_by_user_id": { + "name": "installed_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "member_count_snapshot": { + "name": "member_count_snapshot", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "member_count_snapshot_at": { + "name": "member_count_snapshot_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_installations_bot_user_id_idx": { + "name": "slack_installations_bot_user_id_idx", + "columns": [ + { + "expression": "bot_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_installations_active_idx": { + "name": "slack_installations_active_idx", + "columns": [ + { + "expression": "is_active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_installations_installed_by_user_id_users_id_fk": { + "name": "slack_installations_installed_by_user_id_users_id_fk", + "tableFrom": "slack_installations", + "tableTo": "users", + "columnsFrom": ["installed_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "slack_installations_team_id_unique": { + "name": "slack_installations_team_id_unique", + "nullsNotDistinct": false, + "columns": ["team_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_user_mappings": { + "name": "slack_user_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slack_user_id": { + "name": "slack_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_team_id": { + "name": "slack_team_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_user_mappings_user_id_idx": { + "name": "slack_user_mappings_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_user_mappings_user_id_users_id_fk": { + "name": "slack_user_mappings_user_id_users_id_fk", + "tableFrom": "slack_user_mappings", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "slack_user_mappings_unique": { + "name": "slack_user_mappings_unique", + "nullsNotDistinct": false, + "columns": ["slack_user_id", "slack_team_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.source_control_user_mappings": { + "name": "source_control_user_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "auth_account_id": { + "name": "auth_account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_control_provider": { + "name": "source_control_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "host": { + "name": "host", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_account_id": { + "name": "external_account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "source_control_user_mappings_auth_account_unique": { + "name": "source_control_user_mappings_auth_account_unique", + "columns": [ + { + "expression": "auth_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "source_control_user_mappings_user_provider_host_idx": { + "name": "source_control_user_mappings_user_provider_host_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "host", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "source_control_user_mappings_provider_identity_unique": { + "name": "source_control_user_mappings_provider_identity_unique", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "host", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "source_control_user_mappings_auth_account_id_auth_accounts_id_fk": { + "name": "source_control_user_mappings_auth_account_id_auth_accounts_id_fk", + "tableFrom": "source_control_user_mappings", + "tableTo": "auth_accounts", + "columnsFrom": ["auth_account_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "source_control_user_mappings_user_id_auth_users_id_fk": { + "name": "source_control_user_mappings_user_id_auth_users_id_fk", + "tableFrom": "source_control_user_mappings", + "tableTo": "auth_users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_artifacts": { + "name": "task_artifacts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "artifact_type": { + "name": "artifact_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'general'" + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "size": { + "name": "size", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "uploaded": { + "name": "uploaded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_artifacts_task_id_idx": { + "name": "task_artifacts_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_artifacts_session_id_idx": { + "name": "task_artifacts_session_id_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_artifacts_run_id_idx": { + "name": "task_artifacts_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_artifacts_uploaded_idx": { + "name": "task_artifacts_uploaded_idx", + "columns": [ + { + "expression": "uploaded", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_artifacts_created_at_idx": { + "name": "task_artifacts_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_artifacts_path_idx": { + "name": "task_artifacts_path_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_artifacts_session_id_path_version_unique": { + "name": "task_artifacts_session_id_path_version_unique", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"task_artifacts\".\"session_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_artifacts_task_id_tasks_id_fk": { + "name": "task_artifacts_task_id_tasks_id_fk", + "tableFrom": "task_artifacts", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_artifacts_session_id_sessions_id_fk": { + "name": "task_artifacts_session_id_sessions_id_fk", + "tableFrom": "task_artifacts", + "tableTo": "sessions", + "columnsFrom": ["session_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_artifacts_run_id_task_runs_id_fk": { + "name": "task_artifacts_run_id_task_runs_id_fk", + "tableFrom": "task_artifacts", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "task_artifacts_task_id_path_version_unique": { + "name": "task_artifacts_task_id_path_version_unique", + "nullsNotDistinct": false, + "columns": ["task_id", "path", "version"] + } + }, + "policies": {}, + "checkConstraints": { + "task_artifacts_owner_shape_check": { + "name": "task_artifacts_owner_shape_check", + "value": "(\"task_artifacts\".\"task_id\" IS NOT NULL) <> (\"task_artifacts\".\"session_id\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.task_messages": { + "name": "task_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ts": { + "name": "ts", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "protocol": { + "name": "protocol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_blocks": { + "name": "content_blocks", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_messages_task_id_ts_idx": { + "name": "task_messages_task_id_ts_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "ts", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_messages_run_id_idx": { + "name": "task_messages_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_messages_created_at_idx": { + "name": "task_messages_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_messages_run_id_task_runs_id_fk": { + "name": "task_messages_run_id_task_runs_id_fk", + "tableFrom": "task_messages", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_messages_task_id_tasks_id_fk": { + "name": "task_messages_task_id_tasks_id_fk", + "tableFrom": "task_messages", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_messages_user_id_users_id_fk": { + "name": "task_messages_user_id_users_id_fk", + "tableFrom": "task_messages", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "task_messages_task_protocol_ts_event_type_unique": { + "name": "task_messages_task_protocol_ts_event_type_unique", + "nullsNotDistinct": false, + "columns": ["task_id", "protocol", "ts", "event_type"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_pins": { + "name": "task_pins", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_pins_deployment_user_task_unique": { + "name": "task_pins_deployment_user_task_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_pins_deployment_user_updated_at_idx": { + "name": "task_pins_deployment_user_updated_at_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_pins_task_id_idx": { + "name": "task_pins_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_pins_task_id_tasks_id_fk": { + "name": "task_pins_task_id_tasks_id_fk", + "tableFrom": "task_pins", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_pins_user_id_users_id_fk": { + "name": "task_pins_user_id_users_id_fk", + "tableFrom": "task_pins", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_platform_issue_reports": { + "name": "task_platform_issue_reports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "task_message_id": { + "name": "task_message_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "report": { + "name": "report", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "slack_posted_at": { + "name": "slack_posted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_platform_issue_reports_created_at_idx": { + "name": "task_platform_issue_reports_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_platform_issue_reports_task_id_created_at_idx": { + "name": "task_platform_issue_reports_task_id_created_at_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_platform_issue_reports_run_id_created_at_idx": { + "name": "task_platform_issue_reports_run_id_created_at_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_platform_issue_reports_task_message_id_unique": { + "name": "task_platform_issue_reports_task_message_id_unique", + "columns": [ + { + "expression": "task_message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_platform_issue_reports_task_id_tasks_id_fk": { + "name": "task_platform_issue_reports_task_id_tasks_id_fk", + "tableFrom": "task_platform_issue_reports", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_platform_issue_reports_run_id_task_runs_id_fk": { + "name": "task_platform_issue_reports_run_id_task_runs_id_fk", + "tableFrom": "task_platform_issue_reports", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_platform_issue_reports_task_message_id_task_messages_id_fk": { + "name": "task_platform_issue_reports_task_message_id_task_messages_id_fk", + "tableFrom": "task_platform_issue_reports", + "tableTo": "task_messages", + "columnsFrom": ["task_message_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_pull_requests": { + "name": "task_pull_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_control_provider": { + "name": "source_control_provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'github'" + }, + "host": { + "name": "host", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "repository_id": { + "name": "repository_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pr_number": { + "name": "pr_number", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "pr_title": { + "name": "pr_title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "repository": { + "name": "repository", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pr_sha": { + "name": "pr_sha", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pr_base_ref": { + "name": "pr_base_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pr_base_sha": { + "name": "pr_base_sha", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "github_reaction_id": { + "name": "github_reaction_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "github_check_run_id": { + "name": "github_check_run_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "github_review_comment_id": { + "name": "github_review_comment_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_by_roomote": { + "name": "created_by_roomote", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mergeability_status": { + "name": "mergeability_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "conflict_detected_at": { + "name": "conflict_detected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "conflict_notification_claimed_at": { + "name": "conflict_notification_claimed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "conflict_notified_at": { + "name": "conflict_notified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "auto_handle_feedback_by_user_id": { + "name": "auto_handle_feedback_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "detected_at": { + "name": "detected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_pull_requests_task_id_idx": { + "name": "task_pull_requests_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_pull_requests_repository_id_idx": { + "name": "task_pull_requests_repository_id_idx", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_pull_requests_provider_repository_pr_number_idx": { + "name": "task_pull_requests_provider_repository_pr_number_idx", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_pull_requests_mergeability_lookup_idx": { + "name": "task_pull_requests_mergeability_lookup_idx", + "columns": [ + { + "expression": "source_control_provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repository", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_by_roomote", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_base_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_pull_requests_task_id_tasks_id_fk": { + "name": "task_pull_requests_task_id_tasks_id_fk", + "tableFrom": "task_pull_requests", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_pull_requests_repository_id_repositories_id_fk": { + "name": "task_pull_requests_repository_id_repositories_id_fk", + "tableFrom": "task_pull_requests", + "tableTo": "repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "task_pull_requests_auto_handle_feedback_by_user_id_users_id_fk": { + "name": "task_pull_requests_auto_handle_feedback_by_user_id_users_id_fk", + "tableFrom": "task_pull_requests", + "tableTo": "users", + "columnsFrom": ["auto_handle_feedback_by_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "task_pull_requests_task_pr_unique": { + "name": "task_pull_requests_task_pr_unique", + "nullsNotDistinct": false, + "columns": ["task_id", "pr_url"] + } + }, + "policies": {}, + "checkConstraints": { + "task_pull_requests_source_control_provider_check": { + "name": "task_pull_requests_source_control_provider_check", + "value": "\"task_pull_requests\".\"source_control_provider\" in ('github', 'gitlab', 'gitea', 'ado', 'bitbucket')" + } + }, + "isRLSEnabled": false + }, + "public.task_run_events": { + "name": "task_run_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_run_events_run_id_created_at_idx": { + "name": "task_run_events_run_id_created_at_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_run_events_task_id_created_at_idx": { + "name": "task_run_events_task_id_created_at_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_run_events_created_at_idx": { + "name": "task_run_events_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_run_events_source_created_at_idx": { + "name": "task_run_events_source_created_at_idx", + "columns": [ + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_run_events_run_id_task_runs_id_fk": { + "name": "task_run_events_run_id_task_runs_id_fk", + "tableFrom": "task_run_events", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_run_events_task_id_tasks_id_fk": { + "name": "task_run_events_task_id_tasks_id_fk", + "tableFrom": "task_run_events", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_runs": { + "name": "task_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "task_runs_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'fresh'" + }, + "source_run_id": { + "name": "source_run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "acting_user_id": { + "name": "acting_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payload_kind": { + "name": "payload_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "harness": { + "name": "harness", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'opencode-server'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "queue_scope": { + "name": "queue_scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "task_phase": { + "name": "task_phase", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "fast_agent_session_id": { + "name": "fast_agent_session_id", + "type": "uuid", + "primaryKey": false, + "notNull": false, + "generated": { + "as": "((payload ->> 'fastAgentSessionId')::uuid)", + "type": "stored" + } + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "log": { + "name": "log", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "artifacts": { + "name": "artifacts", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_code": { + "name": "error_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "machine_id": { + "name": "machine_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sandbox_cmd_id": { + "name": "sandbox_cmd_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "machine_domain": { + "name": "machine_domain", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "machine_domains": { + "name": "machine_domains", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "initial_paths": { + "name": "initial_paths", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "primary_port_name": { + "name": "primary_port_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sandbox_server_url": { + "name": "sandbox_server_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "proxy_ports": { + "name": "proxy_ports", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "worker_release_tag": { + "name": "worker_release_tag", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "worker_version": { + "name": "worker_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "worker_commit": { + "name": "worker_commit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor": { + "name": "vendor", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "port": { + "name": "port", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "configured_vcpus": { + "name": "configured_vcpus", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "configured_cpu_cores": { + "name": "configured_cpu_cores", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "configured_memory_mib": { + "name": "configured_memory_mib", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "snapshot_id": { + "name": "snapshot_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "snapshot_requested_at": { + "name": "snapshot_requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "snapshot_created_at": { + "name": "snapshot_created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "snapshot_failed_at": { + "name": "snapshot_failed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "keepalive_ms": { + "name": "keepalive_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "sleep_at": { + "name": "sleep_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "sleep_requested_at": { + "name": "sleep_requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "worker_heartbeat_at": { + "name": "worker_heartbeat_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "source_snapshot_id": { + "name": "source_snapshot_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auth_bypass_value": { + "name": "auth_bypass_value", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auth_bypass_header_name": { + "name": "auth_bypass_header_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "dequeued_at": { + "name": "dequeued_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "provision_started_at": { + "name": "provision_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "provision_ready_at": { + "name": "provision_ready_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "setup_completed_at": { + "name": "setup_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "environment_setup_state": { + "name": "environment_setup_state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "environment_setup_completed_at": { + "name": "environment_setup_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "harness_started_at": { + "name": "harness_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "runtime_task_started_at": { + "name": "runtime_task_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "first_assistant_output_at": { + "name": "first_assistant_output_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "cancel_requested_at": { + "name": "cancel_requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "launch_mode": { + "name": "launch_mode", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "task_runs_task_id_idx": { + "name": "task_runs_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_fast_agent_session_id_idx": { + "name": "task_runs_fast_agent_session_id_idx", + "columns": [ + { + "expression": "fast_agent_session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_queue_scope_idx": { + "name": "task_runs_queue_scope_idx", + "columns": [ + { + "expression": "queue_scope", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_acting_user_id_idx": { + "name": "task_runs_acting_user_id_idx", + "columns": [ + { + "expression": "acting_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_snapshot_id_idx": { + "name": "task_runs_snapshot_id_idx", + "columns": [ + { + "expression": "snapshot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_sleep_at_idx": { + "name": "task_runs_sleep_at_idx", + "columns": [ + { + "expression": "sleep_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_worker_heartbeat_at_idx": { + "name": "task_runs_worker_heartbeat_at_idx", + "columns": [ + { + "expression": "worker_heartbeat_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_sleep_check_due_v2_idx": { + "name": "task_runs_sleep_check_due_v2_idx", + "columns": [ + { + "expression": "sleep_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"task_runs\".\"status\" IN ('running', 'idle') AND \"task_runs\".\"machine_id\" IS NOT NULL AND \"task_runs\".\"sleep_at\" IS NOT NULL AND \"task_runs\".\"sleep_requested_at\" IS NULL AND \"task_runs\".\"snapshot_id\" IS NULL AND \"task_runs\".\"snapshot_requested_at\" IS NULL AND \"task_runs\".\"vendor\" IN ('modal', 'daytona', 'e2b', 'docker', 'blaxel', 'box', 'roomote', 'azure')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_sleep_check_stale_worker_v2_idx": { + "name": "task_runs_sleep_check_stale_worker_v2_idx", + "columns": [ + { + "expression": "worker_heartbeat_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"task_runs\".\"status\" IN ('running', 'idle') AND \"task_runs\".\"machine_id\" IS NOT NULL AND \"task_runs\".\"worker_heartbeat_at\" IS NOT NULL AND \"task_runs\".\"sleep_requested_at\" IS NULL AND \"task_runs\".\"snapshot_id\" IS NULL AND \"task_runs\".\"snapshot_requested_at\" IS NULL AND \"task_runs\".\"vendor\" IN ('modal', 'daytona', 'e2b', 'docker', 'blaxel', 'box', 'roomote', 'azure')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_sleep_check_active_v2_idx": { + "name": "task_runs_sleep_check_active_v2_idx", + "columns": [ + { + "expression": "vendor", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"task_runs\".\"status\" IN ('running', 'idle') AND \"task_runs\".\"machine_id\" IS NOT NULL AND \"task_runs\".\"sleep_requested_at\" IS NULL AND \"task_runs\".\"snapshot_id\" IS NULL AND \"task_runs\".\"snapshot_requested_at\" IS NULL AND \"task_runs\".\"vendor\" IN ('modal', 'daytona', 'e2b', 'docker', 'blaxel', 'box', 'roomote', 'azure')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_source_snapshot_id_idx": { + "name": "task_runs_source_snapshot_id_idx", + "columns": [ + { + "expression": "source_snapshot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_source_run_id_idx": { + "name": "task_runs_source_run_id_idx", + "columns": [ + { + "expression": "source_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_discord_source_event_unique": { + "name": "task_runs_discord_source_event_unique", + "columns": [ + { + "expression": "(\"payload\"->>'communicationSourceEventId')", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"task_runs\".\"payload\"->>'communicationProvider' = 'discord' AND \"task_runs\".\"payload\"->>'communicationSourceEventId' IS NOT NULL AND \"task_runs\".\"canceled_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_launch_idempotency_key_unique": { + "name": "task_runs_launch_idempotency_key_unique", + "columns": [ + { + "expression": "(\"payload\"->>'launchIdempotencyKey')", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"task_runs\".\"payload\"->>'launchIdempotencyKey' IS NOT NULL AND \"task_runs\".\"canceled_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_runs_first_assistant_output_at_idx": { + "name": "task_runs_first_assistant_output_at_idx", + "columns": [ + { + "expression": "first_assistant_output_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_runs_task_id_tasks_id_fk": { + "name": "task_runs_task_id_tasks_id_fk", + "tableFrom": "task_runs", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_runs_source_run_id_task_runs_id_fk": { + "name": "task_runs_source_run_id_task_runs_id_fk", + "tableFrom": "task_runs", + "tableTo": "task_runs", + "columnsFrom": ["source_run_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "task_runs_acting_user_id_users_id_fk": { + "name": "task_runs_acting_user_id_users_id_fk", + "tableFrom": "task_runs", + "tableTo": "users", + "columnsFrom": ["acting_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "task_runs_kind_check": { + "name": "task_runs_kind_check", + "value": "\"task_runs\".\"kind\" in ('fresh', 'resume')" + }, + "task_runs_harness_check": { + "name": "task_runs_harness_check", + "value": "\"task_runs\".\"harness\" in ('opencode-server')" + } + }, + "isRLSEnabled": false + }, + "public.task_slack_reply_details": { + "name": "task_slack_reply_details", + "schema": "", + "columns": { + "detail_id": { + "name": "detail_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "findings": { + "name": "findings", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_slack_reply_details_task_id_idx": { + "name": "task_slack_reply_details_task_id_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_slack_reply_details_deployment_task_detail_unique": { + "name": "task_slack_reply_details_deployment_task_detail_unique", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "detail_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_slack_reply_details_task_id_tasks_id_fk": { + "name": "task_slack_reply_details_task_id_tasks_id_fk", + "tableFrom": "task_slack_reply_details", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.task_start_parallel_counts": { + "name": "task_start_parallel_counts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "task_id": { + "name": "task_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "payload_kind": { + "name": "payload_kind", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parallel_count": { + "name": "parallel_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "activity_window_seconds": { + "name": "activity_window_seconds", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "task_start_parallel_counts_run_id_unique": { + "name": "task_start_parallel_counts_run_id_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_start_parallel_counts_task_id_started_at_idx": { + "name": "task_start_parallel_counts_task_id_started_at_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "task_start_parallel_counts_started_at_idx": { + "name": "task_start_parallel_counts_started_at_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "task_start_parallel_counts_task_id_tasks_id_fk": { + "name": "task_start_parallel_counts_task_id_tasks_id_fk", + "tableFrom": "task_start_parallel_counts", + "tableTo": "tasks", + "columnsFrom": ["task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "task_start_parallel_counts_run_id_task_runs_id_fk": { + "name": "task_start_parallel_counts_run_id_task_runs_id_fk", + "tableFrom": "task_start_parallel_counts", + "tableTo": "task_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow": { + "name": "workflow", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "surface": { + "name": "surface", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'visible'" + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "initiator_kind": { + "name": "initiator_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "initiator_user_id": { + "name": "initiator_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "initiator_automation": { + "name": "initiator_automation", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actor_external_id": { + "name": "actor_external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actor_display_name": { + "name": "actor_display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "commit_author_kind": { + "name": "commit_author_kind", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "commit_author_user_id": { + "name": "commit_author_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "commit_author_login": { + "name": "commit_author_login", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "commit_author_external_id": { + "name": "commit_author_external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pr_assignee_login": { + "name": "pr_assignee_login", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_channel_id": { + "name": "slack_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_thread_ts": { + "name": "slack_thread_ts", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "linear_session_id": { + "name": "linear_session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "linear_issue_id": { + "name": "linear_issue_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "linear_organization_id": { + "name": "linear_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "harness": { + "name": "harness", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'opencode-server'" + }, + "harness_session_id": { + "name": "harness_session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model_provider": { + "name": "model_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title_edited_by_user_at": { + "name": "title_edited_by_user_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "llm_title_checkpoint": { + "name": "llm_title_checkpoint", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "mode": { + "name": "mode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "goal_objective": { + "name": "goal_objective", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "goal_status": { + "name": "goal_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "goal_max_continuations": { + "name": "goal_max_continuations", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "goal_continuations_used": { + "name": "goal_continuations_used", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "goal_blocked_reason": { + "name": "goal_blocked_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "goal_completed_at": { + "name": "goal_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "goal_last_continuation_id": { + "name": "goal_last_continuation_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "goal_continuation_ids": { + "name": "goal_continuation_ids", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "goal_generation_ids": { + "name": "goal_generation_ids", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "goal_blocker_candidate_reason": { + "name": "goal_blocker_candidate_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "goal_blocker_candidate_count": { + "name": "goal_blocker_candidate_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "goal_blocker_last_continuation_used": { + "name": "goal_blocker_last_continuation_used", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "draft_prompt": { + "name": "draft_prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requested_work_kind": { + "name": "requested_work_kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "requested_work_kind_source": { + "name": "requested_work_kind_source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system_default'" + }, + "requested_work_kind_confidence": { + "name": "requested_work_kind_confidence", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "harness_instructions": { + "name": "harness_instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "compute_duration_ms": { + "name": "compute_duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "timestamp": { + "name": "timestamp", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "activity_at": { + "name": "activity_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "repository_url": { + "name": "repository_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "repository_name": { + "name": "repository_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "default_branch": { + "name": "default_branch", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "tasks_initiator_user_id_idx": { + "name": "tasks_initiator_user_id_idx", + "columns": [ + { + "expression": "initiator_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_initiator_automation_idx": { + "name": "tasks_initiator_automation_idx", + "columns": [ + { + "expression": "initiator_automation", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_workflow_idx": { + "name": "tasks_workflow_idx", + "columns": [ + { + "expression": "workflow", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_visibility_activity_at_idx": { + "name": "tasks_visibility_activity_at_idx", + "columns": [ + { + "expression": "visibility", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "activity_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_harness_session_id_idx": { + "name": "tasks_harness_session_id_idx", + "columns": [ + { + "expression": "harness_session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_timestamp_idx": { + "name": "tasks_timestamp_idx", + "columns": [ + { + "expression": "timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_deployment_activity_at_idx": { + "name": "tasks_deployment_activity_at_idx", + "columns": [ + { + "expression": "activity_at", + "isExpression": false, + "asc": false, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tasks_created_at_idx": { + "name": "tasks_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tasks_initiator_user_id_users_id_fk": { + "name": "tasks_initiator_user_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": ["initiator_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "tasks_initiator_automation_automations_key_fk": { + "name": "tasks_initiator_automation_automations_key_fk", + "tableFrom": "tasks", + "tableTo": "automations", + "columnsFrom": ["initiator_automation"], + "columnsTo": ["key"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "tasks_commit_author_user_id_users_id_fk": { + "name": "tasks_commit_author_user_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": ["commit_author_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "tasks_initiator_shape_check": { + "name": "tasks_initiator_shape_check", + "value": "(\"tasks\".\"initiator_kind\" = 'user' AND \"tasks\".\"initiator_automation\" IS NULL AND (\"tasks\".\"initiator_user_id\" IS NOT NULL OR \"tasks\".\"actor_external_id\" IS NOT NULL)) OR (\"tasks\".\"initiator_kind\" = 'automation' AND \"tasks\".\"initiator_automation\" IS NOT NULL AND \"tasks\".\"initiator_user_id\" IS NULL)" + }, + "tasks_workflow_check": { + "name": "tasks_workflow_check", + "value": "\"tasks\".\"workflow\" in ('standard', 'pr_review', 'pr_conflict_resolve', 'scan', 'mcp_recommendations', 'setup_onboarding', 'env_snapshot', 'eval')" + }, + "tasks_surface_check": { + "name": "tasks_surface_check", + "value": "\"tasks\".\"surface\" in ('web', 'api', 'slack', 'teams', 'telegram', 'discord', 'agentmail', 'linear', 'github', 'gitlab', 'gitea', 'ado', 'bitbucket', 'system')" + }, + "tasks_trigger_check": { + "name": "tasks_trigger_check", + "value": "\"tasks\".\"trigger\" in ('message', 'webhook', 'schedule', 'manual')" + }, + "tasks_visibility_check": { + "name": "tasks_visibility_check", + "value": "\"tasks\".\"visibility\" in ('visible', 'hidden')" + }, + "tasks_state_check": { + "name": "tasks_state_check", + "value": "\"tasks\".\"state\" in ('active', 'completed', 'failed', 'canceled')" + }, + "tasks_goal_status_check": { + "name": "tasks_goal_status_check", + "value": "\"tasks\".\"goal_status\" IS NULL OR \"tasks\".\"goal_status\" in ('active', 'complete', 'blocked', 'budget_limited')" + }, + "tasks_goal_continuations_check": { + "name": "tasks_goal_continuations_check", + "value": "\"tasks\".\"goal_continuations_used\" >= 0 AND (\"tasks\".\"goal_max_continuations\" IS NULL OR \"tasks\".\"goal_max_continuations\" > 0)" + }, + "tasks_goal_blocker_candidate_count_check": { + "name": "tasks_goal_blocker_candidate_count_check", + "value": "\"tasks\".\"goal_blocker_candidate_count\" >= 0" + }, + "tasks_harness_check": { + "name": "tasks_harness_check", + "value": "\"tasks\".\"harness\" in ('opencode-server')" + }, + "tasks_requested_work_kind_check": { + "name": "tasks_requested_work_kind_check", + "value": "\"tasks\".\"requested_work_kind\" in ('question', 'plan', 'implement', 'unknown')" + }, + "tasks_requested_work_kind_source_check": { + "name": "tasks_requested_work_kind_source_check", + "value": "\"tasks\".\"requested_work_kind_source\" in ('explicit_bootstrap', 'task_tool', 'llm_classifier', 'inherited', 'system_default')" + }, + "tasks_commit_author_kind_check": { + "name": "tasks_commit_author_kind_check", + "value": "\"tasks\".\"commit_author_kind\" IS NULL OR \"tasks\".\"commit_author_kind\" in ('roomote', 'user', 'external')" + } + }, + "isRLSEnabled": false + }, + "public.teams_installations": { + "name": "teams_installations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "installation_key": { + "name": "installation_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tenant_id": { + "name": "tenant_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "team_id": { + "name": "team_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "team_name": { + "name": "team_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "channel_name": { + "name": "channel_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "conversation_id": { + "name": "conversation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "conversation_type": { + "name": "conversation_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bot_app_id": { + "name": "bot_app_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bot_user_id": { + "name": "bot_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bot_name": { + "name": "bot_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "service_url": { + "name": "service_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "last_activity_at": { + "name": "last_activity_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "teams_installations_tenant_id_idx": { + "name": "teams_installations_tenant_id_idx", + "columns": [ + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "teams_installations_team_id_idx": { + "name": "teams_installations_team_id_idx", + "columns": [ + { + "expression": "team_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "teams_installations_conversation_id_idx": { + "name": "teams_installations_conversation_id_idx", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "teams_installations_active_idx": { + "name": "teams_installations_active_idx", + "columns": [ + { + "expression": "is_active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "teams_installations_installation_key_unique": { + "name": "teams_installations_installation_key_unique", + "nullsNotDistinct": false, + "columns": ["installation_key"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.teams_user_mappings": { + "name": "teams_user_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "teams_user_id": { + "name": "teams_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "teams_tenant_id": { + "name": "teams_tenant_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "teams_aad_object_id": { + "name": "teams_aad_object_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "teams_user_mappings_aad_object_idx": { + "name": "teams_user_mappings_aad_object_idx", + "columns": [ + { + "expression": "teams_aad_object_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "teams_tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "teams_user_mappings_user_id_idx": { + "name": "teams_user_mappings_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "teams_user_mappings_user_id_users_id_fk": { + "name": "teams_user_mappings_user_id_users_id_fk", + "tableFrom": "teams_user_mappings", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "teams_user_mappings_unique": { + "name": "teams_user_mappings_unique", + "nullsNotDistinct": false, + "columns": ["teams_user_id", "teams_tenant_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.telegram_user_mappings": { + "name": "telegram_user_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "telegram_user_id": { + "name": "telegram_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "telegram_chat_id": { + "name": "telegram_chat_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "telegram_username": { + "name": "telegram_username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "telegram_user_mappings_user_id_idx": { + "name": "telegram_user_mappings_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "telegram_user_mappings_user_id_users_id_fk": { + "name": "telegram_user_mappings_user_id_users_id_fk", + "tableFrom": "telegram_user_mappings", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "telegram_user_mappings_unique": { + "name": "telegram_user_mappings_unique", + "nullsNotDistinct": false, + "columns": ["telegram_user_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tracked_messages": { + "name": "tracked_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "surface": { + "name": "surface", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dedupe_key": { + "name": "dedupe_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message_ts": { + "name": "message_ts", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "thread_ts": { + "name": "thread_ts", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "work_item_id": { + "name": "work_item_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "automation_key": { + "name": "automation_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "summary_text": { + "name": "summary_text", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "posted_at": { + "name": "posted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "dismissed_at": { + "name": "dismissed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "tracked_messages_kind_dedupe_key_unique": { + "name": "tracked_messages_kind_dedupe_key_unique", + "columns": [ + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dedupe_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tracked_messages_work_item_id_idx": { + "name": "tracked_messages_work_item_id_idx", + "columns": [ + { + "expression": "work_item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tracked_messages_channel_message_idx": { + "name": "tracked_messages_channel_message_idx", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "message_ts", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "tracked_messages_automation_channel_posted_idx": { + "name": "tracked_messages_automation_channel_posted_idx", + "columns": [ + { + "expression": "automation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "posted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tracked_messages_work_item_id_work_items_id_fk": { + "name": "tracked_messages_work_item_id_work_items_id_fk", + "tableFrom": "tracked_messages", + "tableTo": "work_items", + "columnsFrom": ["work_item_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tracked_messages_automation_key_automations_key_fk": { + "name": "tracked_messages_automation_key_automations_key_fk", + "tableFrom": "tracked_messages", + "tableTo": "automations", + "columnsFrom": ["automation_key"], + "columnsTo": ["key"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tracked_messages_created_by_user_id_users_id_fk": { + "name": "tracked_messages_created_by_user_id_users_id_fk", + "tableFrom": "tracked_messages", + "tableTo": "users", + "columnsFrom": ["created_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_api_keys": { + "name": "user_api_keys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "user_api_keys_user_id_idx": { + "name": "user_api_keys_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_api_keys_user_deployment_provider_unique": { + "name": "user_api_keys_user_deployment_provider_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_api_keys_user_id_users_id_fk": { + "name": "user_api_keys_user_id_users_id_fk", + "tableFrom": "user_api_keys", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_personalizations": { + "name": "user_personalizations", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "manual_instructions": { + "name": "manual_instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "explicit_conversation_instructions": { + "name": "explicit_conversation_instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "inferred_instructions": { + "name": "inferred_instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "learn_from_conversations": { + "name": "learn_from_conversations", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reset_at": { + "name": "reset_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "user_personalizations_user_id_users_id_fk": { + "name": "user_personalizations_user_id_users_id_fk", + "tableFrom": "user_personalizations", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "image_url": { + "name": "image_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity": { + "name": "entity", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "analytics_id": { + "name": "analytics_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cookie_consented_at": { + "name": "cookie_consented_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "onboarding_completed_at": { + "name": "onboarding_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "invited_by_invite_id": { + "name": "invited_by_invite_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_created_at_idx": { + "name": "users_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_analytics_id_unique_idx": { + "name": "users_analytics_id_unique_idx", + "columns": [ + { + "expression": "analytics_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhooks": { + "name": "webhooks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "delivery_id": { + "name": "delivery_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event": { + "name": "event", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "succeeded_at": { + "name": "succeeded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "failed_at": { + "name": "failed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "webhooks_provider_delivery_id_unique": { + "name": "webhooks_provider_delivery_id_unique", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "delivery_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhooks_event_idx": { + "name": "webhooks_event_idx", + "columns": [ + { + "expression": "event", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhooks_created_at_idx": { + "name": "webhooks_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "webhooks_status_exclusive": { + "name": "webhooks_status_exclusive", + "value": "(\n (succeeded_at IS NOT NULL)::int +\n (failed_at IS NOT NULL)::int\n ) <= 1" + } + }, + "isRLSEnabled": false + }, + "public.work_items": { + "name": "work_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "automation_key": { + "name": "automation_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_task_id": { + "name": "source_task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "selected_by_user_id": { + "name": "selected_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_work_item_id": { + "name": "source_work_item_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "brief": { + "name": "brief", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "execution_prompt": { + "name": "execution_prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "investigation_context": { + "name": "investigation_context", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_kind": { + "name": "action_kind", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "disposition": { + "name": "disposition", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "repository_ids": { + "name": "repository_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "target_repository_full_name": { + "name": "target_repository_full_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "target_environment_id": { + "name": "target_environment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "workspace_readiness": { + "name": "workspace_readiness", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "readiness_message": { + "name": "readiness_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "launch_claimed_at": { + "name": "launch_claimed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "launched_task_id": { + "name": "launched_task_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "launched_at": { + "name": "launched_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "failed_at": { + "name": "failed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "launch_error": { + "name": "launch_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dismissed_at": { + "name": "dismissed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "result_accepted_at": { + "name": "result_accepted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "result_ignored_at": { + "name": "result_ignored_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "result_automation_name": { + "name": "result_automation_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "result_priority": { + "name": "result_priority", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "result_user_id": { + "name": "result_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "work_items_source_task_idx": { + "name": "work_items_source_task_idx", + "columns": [ + { + "expression": "source_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "work_items_kind_status_idx": { + "name": "work_items_kind_status_idx", + "columns": [ + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "work_items_automation_key_fingerprint_idx": { + "name": "work_items_automation_key_fingerprint_idx", + "columns": [ + { + "expression": "automation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "fingerprint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "work_items_fingerprint_idx": { + "name": "work_items_fingerprint_idx", + "columns": [ + { + "expression": "fingerprint", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "work_items_launched_task_id_idx": { + "name": "work_items_launched_task_id_idx", + "columns": [ + { + "expression": "launched_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "work_items_source_task_kind_sort_order_unique": { + "name": "work_items_source_task_kind_sort_order_unique", + "columns": [ + { + "expression": "source_task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "work_items_automation_key_automations_key_fk": { + "name": "work_items_automation_key_automations_key_fk", + "tableFrom": "work_items", + "tableTo": "automations", + "columnsFrom": ["automation_key"], + "columnsTo": ["key"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "work_items_source_task_id_tasks_id_fk": { + "name": "work_items_source_task_id_tasks_id_fk", + "tableFrom": "work_items", + "tableTo": "tasks", + "columnsFrom": ["source_task_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "work_items_selected_by_user_id_users_id_fk": { + "name": "work_items_selected_by_user_id_users_id_fk", + "tableFrom": "work_items", + "tableTo": "users", + "columnsFrom": ["selected_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "work_items_source_work_item_id_work_items_id_fk": { + "name": "work_items_source_work_item_id_work_items_id_fk", + "tableFrom": "work_items", + "tableTo": "work_items", + "columnsFrom": ["source_work_item_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "work_items_target_environment_id_environments_id_fk": { + "name": "work_items_target_environment_id_environments_id_fk", + "tableFrom": "work_items", + "tableTo": "environments", + "columnsFrom": ["target_environment_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "work_items_launched_task_id_tasks_id_fk": { + "name": "work_items_launched_task_id_tasks_id_fk", + "tableFrom": "work_items", + "tableTo": "tasks", + "columnsFrom": ["launched_task_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "work_items_result_user_id_users_id_fk": { + "name": "work_items_result_user_id_users_id_fk", + "tableFrom": "work_items", + "tableTo": "users", + "columnsFrom": ["result_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.json index d6ed08640..a0acd9b62 100644 --- a/packages/db/drizzle/meta/_journal.json +++ b/packages/db/drizzle/meta/_journal.json @@ -610,6 +610,13 @@ "when": 1789236952537, "tag": "0086_whole_blur", "breakpoints": true + }, + { + "idx": 87, + "version": "7", + "when": 1789243462242, + "tag": "0087_uneven_scalphunter", + "breakpoints": true } ] } diff --git a/packages/db/src/lib/fast-agent-message-order.ts b/packages/db/src/lib/fast-agent-message-order.ts new file mode 100644 index 000000000..2b693ca15 --- /dev/null +++ b/packages/db/src/lib/fast-agent-message-order.ts @@ -0,0 +1,56 @@ +import { and, asc, eq, isNull, max, sql } from 'drizzle-orm'; + +import type { DatabaseOrTransaction } from '../db'; +import { fastAgentMessages } from '../schema'; + +export async function lockFastAgentConversation( + database: DatabaseOrTransaction, + conversationId: string, +): Promise { + await database.execute( + sql`select pg_advisory_xact_lock(hashtextextended(${`fast-agent-conversation:${conversationId}`}, 0))`, + ); +} + +/** Allocate canonical admission order while the conversation lock is held. */ +export async function allocateFastAgentConversationSequence( + database: DatabaseOrTransaction, + conversationId: string, +): Promise { + await lockFastAgentConversation(database, conversationId); + const [row] = await database + .select({ value: max(fastAgentMessages.conversationSeq) }) + .from(fastAgentMessages) + .where(eq(fastAgentMessages.conversationId, conversationId)); + let next = Number(row?.value ?? 0) + 1; + // During the N-1 window an older binary can still insert a null sequence. + // Repair those rows under the same lock before admitting the new event. + const legacyRows = await database + .select({ id: fastAgentMessages.id }) + .from(fastAgentMessages) + .where( + and( + eq(fastAgentMessages.conversationId, conversationId), + isNull(fastAgentMessages.conversationSeq), + ), + ) + .orderBy( + asc(fastAgentMessages.createdAt), + asc(fastAgentMessages.ts), + asc(fastAgentMessages.turnSeq), + asc(fastAgentMessages.id), + ); + for (const legacy of legacyRows) { + await database + .update(fastAgentMessages) + .set({ conversationSeq: next }) + .where( + and( + eq(fastAgentMessages.id, legacy.id), + isNull(fastAgentMessages.conversationSeq), + ), + ); + next += 1; + } + return next; +} diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index 5b9a7a0b3..7f43b9540 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -3478,6 +3478,11 @@ export const fastAgentConversations = pgTable( .default(sql`'[]'::jsonb`) .$type[]>(), openCodeSessionId: text('opencode_session_id'), + /** Projection represented by the persisted native OpenCode session. */ + openCodeProjectionHash: text('open_code_projection_hash'), + openCodeProjectedThroughSeq: bigint('open_code_projected_through_seq', { + mode: 'number', + }), model: text('model'), reasoningEffort: text('reasoning_effort').$type(), title: text('title'), @@ -3619,9 +3624,16 @@ export const fastAgentMessages = pgTable( .notNull() .references(() => fastAgentConversations.id, { onDelete: 'cascade' }), eventId: text('event_id').notNull(), + /** + * Canonical per-conversation admission order. Nullable for N-1 binaries, + * which may continue inserting rows without this field during rollback. + */ + conversationSeq: bigint('conversation_seq', { mode: 'number' }), turnId: text('turn_id').notNull(), turnSeq: integer('turn_seq').notNull(), ts: bigint('ts', { mode: 'number' }).notNull(), + /** Source observation time; created_at remains durable admission time. */ + observedAt: timestamp('observed_at'), eventType: text('event_type').notNull().$type(), role: text('role').$type(), contentBlocks: jsonb('content_blocks') @@ -3642,6 +3654,13 @@ export const fastAgentMessages = pgTable( table.eventId, ), index('fast_agent_messages_conversation_order_idx').on( + table.conversationId, + table.conversationSeq, + ), + uniqueIndex('fast_agent_messages_conversation_seq_unique') + .on(table.conversationId, table.conversationSeq) + .where(sql`${table.conversationSeq} is not null`), + index('fast_agent_messages_legacy_order_idx').on( table.conversationId, table.ts, table.turnSeq, diff --git a/packages/db/src/server.ts b/packages/db/src/server.ts index fe1f8c2e5..ca9675630 100644 --- a/packages/db/src/server.ts +++ b/packages/db/src/server.ts @@ -70,6 +70,7 @@ export * from './lib/declarative-environments'; export * from './lib/environment-config-versions'; export * from './lib/environment-definitions'; export * from './lib/environment-snapshots'; +export * from './lib/fast-agent-message-order'; export * from './lib/github-branch-activity'; export * from './lib/compute-runtime-config'; export * from './lib/model-runtime-config'; diff --git a/packages/sdk/src/server/lib/fast-agent-follow-up-closeout.test.ts b/packages/sdk/src/server/lib/fast-agent-follow-up-closeout.test.ts index d8c7ab9b8..6b592eaa3 100644 --- a/packages/sdk/src/server/lib/fast-agent-follow-up-closeout.test.ts +++ b/packages/sdk/src/server/lib/fast-agent-follow-up-closeout.test.ts @@ -22,6 +22,7 @@ vi.mock('bullmq', () => ({ vi.mock('@roomote/redis', () => ({ getRedis: vi.fn(() => ({})) })); vi.mock('@roomote/cloud-agents/server', () => ({ acquireFastAgentTurnLock: mocks.acquireLock, + buildFastAgentUserContentBlocks: (text: string) => [{ type: 'text', text }], FAST_AGENT_DURABLE_TURN_CLAIM_MS: 15 * 60 * 1000, findFastAgentDurableRetryScheduledError: () => null, })); diff --git a/packages/sdk/src/server/lib/fast-agent-parent-event-admission-concurrency.test.ts b/packages/sdk/src/server/lib/fast-agent-parent-event-admission-concurrency.test.ts new file mode 100644 index 000000000..1e34d5d85 --- /dev/null +++ b/packages/sdk/src/server/lib/fast-agent-parent-event-admission-concurrency.test.ts @@ -0,0 +1,302 @@ +const mocks = vi.hoisted(() => ({ + queueAdd: vi.fn(), + acquireLock: vi.fn(), +})); + +vi.mock('bullmq', () => ({ + Queue: class Queue { + add = mocks.queueAdd; + }, +})); + +vi.mock('@roomote/redis', () => ({ getRedis: vi.fn(() => ({})) })); + +// The Redis turn lock is not what these cases exercise, so it is replaced by +// a deterministic in-process mutex with the same contract: one holder per +// conversation, and a refusal (null) while another holder owns the turn. +vi.mock('@roomote/cloud-agents/server', async (importOriginal) => ({ + ...(await importOriginal()), + acquireFastAgentTurnLock: mocks.acquireLock, +})); + +import { + db, + eq, + fastAgentMessages, + fastAgentParentEvents, + userFactory, + users, +} from '@roomote/db/server'; +import { + isFastAgentCanonicalEventSuperseded, + loadFastAgentCanonicalMessages, + projectFastAgentCanonicalEvents, + renderFastAgentCanonicalHistory, + type FastAgentTurnLockHandle, +} from '@roomote/cloud-agents/server'; +import { getOrCreateFastAgentSession } from '@roomote/cloud-agents/server'; +import type { FastAgentHumanFollowUpEvent } from '@roomote/types'; + +import { deliverFastAgentParentEventWithLock } from './fast-agent-parent-event'; +import { + drainFastAgentParentEvents, + enqueueFastAgentParentEvent, +} from './fast-agent-parent-event-queue'; + +vi.mock('./fast-agent-parent-event', async (importOriginal) => { + const actual = + await importOriginal(); + return { ...actual, deliverFastAgentParentEventWithLock: vi.fn() }; +}); + +type ConsumedTurn = { + eventId: string; + suppressed: boolean; + /** Rendered history the turn would have sent to the model. */ + context: string; +}; + +describe('Fast parent event admission concurrent with consumption', () => { + let userId: string; + let sessionId: string; + const conversation = { + surface: 'web' as const, + workspaceId: 'admission-concurrency-workspace', + conversationId: 'admission-concurrency-conversation', + }; + const parent = () => ({ sessionId, conversation }); + + /** Turns the drain actually ran, in consumption order. */ + let consumed: ConsumedTurn[]; + /** Resolves when the held turn has snapshotted its projection. */ + let heldTurnReachedBoundary: Promise; + /** Releases the held turn so it may finish. */ + let releaseHeldTurn: () => void; + /** Event id whose turn pauses at the projection boundary. */ + let holdEventId: string | null; + + beforeEach(async () => { + mocks.queueAdd.mockResolvedValue(undefined); + consumed = []; + holdEventId = null; + let signalBoundary!: () => void; + heldTurnReachedBoundary = new Promise((resolve) => { + signalBoundary = resolve; + }); + let resolveRelease!: () => void; + const released = new Promise((resolve) => { + resolveRelease = resolve; + }); + releaseHeldTurn = resolveRelease; + + let lockHeld = false; + mocks.acquireLock.mockImplementation(async () => { + if (lockHeld) return null; + lockHeld = true; + const release = (async () => { + lockHeld = false; + }) as FastAgentTurnLockHandle; + release.signal = new AbortController().signal; + return release; + }); + + const user = await userFactory.create(); + userId = user.id; + const session = await getOrCreateFastAgentSession({ userId, conversation }); + sessionId = session.id; + + // Stands in for a consuming turn: it snapshots the canonical projection + // exactly once, before any model request, which is the real + // linearization boundary in `answerFastAgentQuestion`. + vi.mocked(deliverFastAgentParentEventWithLock).mockImplementation( + async ({ event }) => { + const eventId = (event as FastAgentHumanFollowUpEvent).currentMessageId; + const canonicalEventId = `${eventId}:user`; + const projection = projectFastAgentCanonicalEvents( + await loadFastAgentCanonicalMessages(sessionId), + ); + const suppressed = isFastAgentCanonicalEventSuperseded( + projection, + canonicalEventId, + ); + if (eventId === holdEventId) { + signalBoundary(); + await released; + } + consumed.push({ + eventId, + suppressed, + context: JSON.stringify( + renderFastAgentCanonicalHistory(projection, { + excludeEventId: canonicalEventId, + }), + ), + }); + return suppressed ? 'skipped' : 'delivered'; + }, + ); + }); + + afterEach(async () => { + releaseHeldTurn(); + await db.delete(users).where(eq(users.id, userId)); + }); + + function setupState( + id: string, + source: 'yellow' | 'green', + version: number, + ): FastAgentHumanFollowUpEvent { + const setupSnapshot = JSON.stringify({ rail: { source } }); + return { + type: 'human_follow_up', + eventId: id, + currentMessageId: id, + userId, + question: `${JSON.stringify({ + type: 'setup_state_changed', + snapshot: JSON.parse(setupSnapshot), + version, + })}`, + turnSource: 'platform_event', + platformEventKind: 'setup', + platformEventVisibility: 'required', + setupSession: true, + setupContext: { + sessionId, + fastConversationId: sessionId, + setupSnapshot, + starterTaskOptions: [], + }, + }; + } + + async function admit(event: FastAgentHumanFollowUpEvent) { + return enqueueFastAgentParentEvent({ parent: parent(), event }); + } + + async function drain(eventKey: string) { + return drainFastAgentParentEvents({ conversationId: sessionId, eventKey }); + } + + it('suppresses a queued state a newer admission replaced and leaves the newest authoritative', async () => { + // yellow v10 -> green v11 queued -> yellow v12, all durably admitted + // before the drain runs, which is the reported contradiction. + const yellowV10 = await admit(setupState('yellow-v10', 'yellow', 10)); + await admit(setupState('green-v11', 'green', 11)); + await admit(setupState('yellow-v12', 'yellow', 12)); + + await drain(yellowV10.eventKey); + + expect( + consumed.map(({ eventId, suppressed }) => [eventId, suppressed]), + ).toEqual([ + ['yellow-v10', true], + ['green-v11', true], + ['yellow-v12', false], + ]); + // The surviving turn carries no superseded state into its context: both + // the stale green claim and the older yellow are dropped, so the only + // state fact in play is the event being consumed. + const finalContext = consumed.at(-1)!.context; + expect(finalContext).not.toContain('green'); + expect(finalContext).not.toContain('yellow-v10'); + + const rows = await db.query.fastAgentMessages.findMany({ + where: eq(fastAgentMessages.conversationId, sessionId), + }); + expect( + rows + .map(({ conversationSeq }) => conversationSeq) + .sort((left, right) => Number(left) - Number(right)), + ).toEqual([1, 2, 3]); + const projection = projectFastAgentCanonicalEvents(rows); + expect(projection.currentStateEventIds).toEqual(['yellow-v12:user']); + }); + + it('does not let an in-flight turn see an event admitted after its projection boundary', async () => { + const green = await admit(setupState('green-v11', 'green', 11)); + holdEventId = 'green-v11'; + + const draining = drain(green.eventKey); + await heldTurnReachedBoundary; + + // Admitted while the green turn is mid-flight, after it snapshotted. + await admit(setupState('yellow-v12', 'yellow', 12)); + releaseHeldTurn(); + await draining; + + const greenTurn = consumed.find(({ eventId }) => eventId === 'green-v11')!; + // Honest boundary: the in-flight turn ran on pre-admission state. It is + // not retroactively suppressed, and it never saw the newer event. + expect(greenTurn.suppressed).toBe(false); + expect(greenTurn.context).not.toContain('yellow-v12'); + + // The newer event is still admitted durably and consumed afterwards with + // the green state demoted, so the conversation ends on the truth. + const yellowTurn = consumed.find(({ eventId }) => eventId === 'yellow-v12'); + expect(yellowTurn?.suppressed).toBe(false); + const projection = projectFastAgentCanonicalEvents( + await loadFastAgentCanonicalMessages(sessionId), + ); + expect(projection.currentStateEventIds).toEqual(['yellow-v12:user']); + }); + + it('admits each event once and never re-delivers a settled turn', async () => { + const green = await admit(setupState('green-v11', 'green', 11)); + // A provider retry of the same occurrence. + const duplicate = await admit(setupState('green-v11', 'green', 11)); + expect(duplicate.eventKey).toBe(green.eventKey); + + await drain(green.eventKey); + // A repeat wakeup for an already drained inbox. + await drain(green.eventKey); + + expect(consumed.map(({ eventId }) => eventId)).toEqual(['green-v11']); + const [parentRows, canonicalRows] = await Promise.all([ + db.query.fastAgentParentEvents.findMany({ + where: eq(fastAgentParentEvents.conversationId, sessionId), + }), + db.query.fastAgentMessages.findMany({ + where: eq(fastAgentMessages.conversationId, sessionId), + }), + ]); + expect(parentRows).toHaveLength(1); + expect(parentRows[0]?.deliveredAt).toBeInstanceOf(Date); + expect(canonicalRows).toHaveLength(1); + }); + + it('refuses to consume while another turn owns the conversation', async () => { + const green = await admit(setupState('green-v11', 'green', 11)); + const owner = await mocks.acquireLock(); + expect(owner).not.toBeNull(); + + await expect(drain(green.eventKey)).rejects.toThrow(/busy/iu); + expect(consumed).toEqual([]); + + await owner!(); + await drain(green.eventKey); + expect(consumed.map(({ eventId }) => eventId)).toEqual(['green-v11']); + }); + + it('rebuilds the same authoritative state from the canonical log after a cold restart', async () => { + const yellowV10 = await admit(setupState('yellow-v10', 'yellow', 10)); + await admit(setupState('green-v11', 'green', 11)); + await admit(setupState('yellow-v12', 'yellow', 12)); + await drain(yellowV10.eventKey); + const warmContext = consumed.at(-1)!.context; + + // A cold consumer keeps nothing in memory and replays the durable log. + const coldProjection = projectFastAgentCanonicalEvents( + await loadFastAgentCanonicalMessages(sessionId), + ); + const coldContext = JSON.stringify( + renderFastAgentCanonicalHistory(coldProjection, { + excludeEventId: 'yellow-v12:user', + }), + ); + + expect(coldContext).toEqual(warmContext); + expect(coldProjection.currentStateEventIds).toEqual(['yellow-v12:user']); + }); +}); diff --git a/packages/sdk/src/server/lib/fast-agent-parent-event-canonical.test.ts b/packages/sdk/src/server/lib/fast-agent-parent-event-canonical.test.ts new file mode 100644 index 000000000..8866cbc76 --- /dev/null +++ b/packages/sdk/src/server/lib/fast-agent-parent-event-canonical.test.ts @@ -0,0 +1,211 @@ +const mocks = vi.hoisted(() => ({ queueAdd: vi.fn() })); + +vi.mock('bullmq', () => ({ + Queue: class Queue { + add = mocks.queueAdd; + }, +})); + +vi.mock('@roomote/redis', () => ({ getRedis: vi.fn(() => ({})) })); + +import { + db, + eq, + fastAgentMessages, + fastAgentParentEvents, + userFactory, + users, +} from '@roomote/db/server'; +import { + FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY, + type FastAgentHumanFollowUpEvent, +} from '@roomote/types'; +import { + getOrCreateFastAgentSession, + loadFastAgentAdmittedEventSemantics, + projectFastAgentCanonicalEvents, + upsertFastAgentMessage, +} from '@roomote/cloud-agents/server'; + +import { enqueueFastAgentParentEvent } from './fast-agent-parent-event-queue'; + +describe('Fast parent event canonical admission', () => { + let userId: string; + let sessionId: string; + const conversation = { + surface: 'web' as const, + workspaceId: 'canonical-admission-workspace', + conversationId: 'canonical-admission-conversation', + }; + + beforeEach(async () => { + mocks.queueAdd.mockResolvedValue(undefined); + const user = await userFactory.create(); + userId = user.id; + const session = await getOrCreateFastAgentSession({ + userId, + conversation, + }); + sessionId = session.id; + }); + + afterEach(async () => { + await db.delete(users).where(eq(users.id, userId)); + }); + + function setupEvent( + id: string, + source: 'yellow' | 'green', + ): FastAgentHumanFollowUpEvent { + const setupSnapshot = JSON.stringify({ rail: { source } }); + return { + type: 'human_follow_up', + eventId: id, + currentMessageId: id, + userId, + question: `${JSON.stringify({ + type: 'setup_state_changed', + snapshot: JSON.parse(setupSnapshot), + })}`, + turnSource: 'platform_event', + platformEventKind: 'setup', + platformEventVisibility: 'required', + setupSession: true, + setupContext: { + sessionId, + fastConversationId: sessionId, + setupSnapshot, + starterTaskOptions: [], + }, + }; + } + + it('atomically records hidden input once and allocates concurrent admission order', async () => { + const parent = { sessionId, conversation }; + const green = setupEvent('green-event', 'green'); + const yellow = setupEvent('yellow-event', 'yellow'); + + await Promise.all([ + enqueueFastAgentParentEvent({ parent, event: green }), + enqueueFastAgentParentEvent({ parent, event: yellow }), + enqueueFastAgentParentEvent({ parent, event: green }), + ]); + + const [parentRows, canonicalRows] = await Promise.all([ + db.query.fastAgentParentEvents.findMany({ + where: eq(fastAgentParentEvents.conversationId, sessionId), + }), + db.query.fastAgentMessages.findMany({ + where: eq(fastAgentMessages.conversationId, sessionId), + }), + ]); + expect(parentRows).toHaveLength(2); + expect(canonicalRows).toHaveLength(2); + expect( + canonicalRows + .map(({ conversationSeq }) => conversationSeq) + .sort((left, right) => Number(left) - Number(right)), + ).toEqual([1, 2]); + expect( + canonicalRows.every( + ({ metadata, observedAt }) => + metadata?.visibleInTranscript === false && + Boolean(metadata?.[FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]) && + observedAt instanceof Date, + ), + ).toBe(true); + expect( + projectFastAgentCanonicalEvents(canonicalRows).currentStateEventIds, + ).toHaveLength(1); + }); + + it('keeps admitted semantics when a later writer carries none', async () => { + const parent = { sessionId, conversation }; + await enqueueFastAgentParentEvent({ + parent, + event: { + type: 'child_message', + taskId: 'task-1', + runId: 42, + messageId: 'child-message-1', + purpose: 'progress', + message: 'The source is ready.', + }, + }); + const [admitted] = await db.query.fastAgentMessages.findMany({ + where: eq(fastAgentMessages.conversationId, sessionId), + }); + // A writer touching this row for another reason must not erase the + // admission record just because it has nothing to say about semantics. + await upsertFastAgentMessage({ + sessionId, + message: { + eventId: admitted!.eventId, + turnId: admitted!.turnId, + turnSeq: 0, + ts: Date.now(), + eventType: admitted!.eventType, + role: 'user', + contentBlocks: admitted!.contentBlocks, + metadata: { visibleInTranscript: false, turnSource: 'platform_event' }, + payload: {}, + source: 'web', + }, + }); + const updated = await db.query.fastAgentMessages.findFirst({ + where: eq(fastAgentMessages.id, admitted!.id), + }); + expect( + updated?.metadata?.[FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY], + ).toMatchObject({ + authority: 'delegated_task', + sourceEventId: 'fast-parent-child-message:child-message-1', + }); + expect(updated?.metadata?.turnSource).toBe('platform_event'); + expect(updated?.conversationSeq).toBe(admitted?.conversationSeq); + expect(updated?.observedAt).toEqual(admitted?.observedAt); + }); + + it('offers the admitted semantics for consumption to reuse', async () => { + const parent = { sessionId, conversation }; + await enqueueFastAgentParentEvent({ + parent, + event: { + type: 'child_message', + taskId: 'task-1', + runId: 42, + messageId: 'child-message-2', + purpose: 'progress', + message: 'The source is ready.', + }, + }); + const [admitted] = await db.query.fastAgentMessages.findMany({ + where: eq(fastAgentMessages.conversationId, sessionId), + }); + + // What the executing turn reads instead of deriving its own semantics. + const reused = await loadFastAgentAdmittedEventSemantics( + sessionId, + admitted!.eventId, + ); + expect(reused).toMatchObject({ + authority: 'delegated_task', + kind: 'historical_observation', + sourceEventId: 'fast-parent-child-message:child-message-2', + observedAt: admitted!.observedAt?.toISOString(), + }); + + // An N-1 binary admitted rows without semantics; the turn describes + // those itself rather than reusing a record that is not there. + await db + .update(fastAgentMessages) + .set({ metadata: { turnSource: 'platform_event' } }) + .where(eq(fastAgentMessages.id, admitted!.id)); + expect( + await loadFastAgentAdmittedEventSemantics(sessionId, admitted!.eventId), + ).toBeNull(); + expect( + await loadFastAgentAdmittedEventSemantics(sessionId, 'no-such-event'), + ).toBeNull(); + }); +}); diff --git a/packages/sdk/src/server/lib/fast-agent-parent-event-queue.test.ts b/packages/sdk/src/server/lib/fast-agent-parent-event-queue.test.ts index 2a07a28a0..05614ba0f 100644 --- a/packages/sdk/src/server/lib/fast-agent-parent-event-queue.test.ts +++ b/packages/sdk/src/server/lib/fast-agent-parent-event-queue.test.ts @@ -25,6 +25,8 @@ const mocks = vi.hoisted(() => { updateWhere: vi.fn(), findPending: vi.fn(), findRun: vi.fn(), + findCanonical: vi.fn(), + allocateSequence: vi.fn(), selectRows: vi.fn(), acquireLock: vi.fn(), releaseLock: Object.assign(vi.fn(), { @@ -48,6 +50,7 @@ vi.mock('@roomote/redis', () => ({ getRedis: vi.fn(() => ({})) })); vi.mock('@roomote/cloud-agents/server', () => ({ acquireFastAgentTurnLock: mocks.acquireLock, + buildFastAgentUserContentBlocks: (text: string) => [{ type: 'text', text }], findFastAgentDurableRetryScheduledError: (error: unknown) => error instanceof Error && error.name === 'FastAgentDurableRetryScheduledError' @@ -60,6 +63,7 @@ vi.mock('@roomote/cloud-agents/server', () => ({ })); vi.mock('@roomote/db/server', () => ({ + allocateFastAgentConversationSequence: mocks.allocateSequence, db: { insert: vi.fn(() => ({ values: mocks.insertValues })), transaction: mocks.transaction, @@ -76,6 +80,7 @@ vi.mock('@roomote/db/server', () => ({ })), query: { fastAgentParentEvents: { findFirst: mocks.findPending }, + fastAgentMessages: { findFirst: mocks.findCanonical }, taskRuns: { findFirst: mocks.findRun }, }, }, @@ -106,6 +111,10 @@ vi.mock('@roomote/db/server', () => ({ deliveredAt: 'delivered_at', discardedAt: 'discarded_at', }, + fastAgentMessages: { + conversationId: 'fast_agent_messages.conversation_id', + eventId: 'fast_agent_messages.event_id', + }, taskRuns: { id: 'task_runs.id', status: 'task_runs.status' }, })); @@ -186,10 +195,15 @@ describe('Fast parent event durable queue', () => { }); mocks.insertOnConflict.mockResolvedValue(undefined); mocks.selectForUpdate.mockResolvedValue([{ status: RunStatus.Running }]); + mocks.findCanonical.mockResolvedValue(undefined); + mocks.allocateSequence.mockResolvedValue(1); mocks.transaction.mockImplementation( async (callback: (tx: unknown) => unknown) => callback({ insert: vi.fn(() => ({ values: mocks.insertValues })), + query: { + fastAgentMessages: { findFirst: mocks.findCanonical }, + }, select: vi.fn(() => ({ from: vi.fn(() => ({ where: vi.fn(() => ({ @@ -225,6 +239,79 @@ describe('Fast parent event durable queue', () => { errorSpy.mockRestore(); }); + describe('canonical event semantics', () => { + function canonicalMetadata() { + const call = mocks.insertValues.mock.calls + .map(([values]) => values as { metadata?: Record }) + .find((values) => values?.metadata); + return call?.metadata?.fastAgentEventSemantics as + | { + kind: string; + authority: string; + version?: { scheme: string; value: unknown }; + state?: string; + } + | undefined; + } + + it.each([ + ['pull_request_opened', pullRequestOpenedEvent], + [ + 'pull_request_status_changed', + { + type: 'pull_request_status_changed' as const, + taskId: 'child-task', + runId: 42, + taskUrl: 'https://roomote.example/task/child-task', + pullRequest: { + ...pullRequestOpenedEvent.pullRequest, + status: 'merged' as const, + }, + status: 'merged' as const, + actorLogin: 'maintainer', + }, + ], + ])( + 'leaves %s unversioned so a later provider transition is never pinned', + async (_type, prEvent) => { + await enqueueFastAgentParentEvent({ + parent, + event: prEvent as FastAgentParentEvent, + }); + + const semantics = canonicalMetadata(); + expect(semantics?.authority).toBe('source_control'); + // Providers expose no monotonic pull-request lifecycle version, so + // inventing one here would outrank a genuine reopen or draft return. + expect(semantics?.version).toBeUndefined(); + }, + ); + + it('keeps the monotonic run number a scheduled wakeup genuinely provides', async () => { + await enqueueFastAgentParentEvent({ + parent, + event: { + type: 'scheduled_wakeup', + eventId: 'wakeup-1:3', + wakeupId: 'wakeup-1', + name: 'CI watch', + prompt: 'Check whether CI is green.', + runNumber: 3, + maxRuns: null, + firedAt: '2026-01-01T00:00:03.000Z', + nextRunAt: null, + reportPolicy: 'only_when_notable', + createdByUserId: 'user-1', + }, + }); + + expect(canonicalMetadata()?.version).toEqual({ + scheme: 'monotonic_number', + value: 3, + }); + }); + }); + it('acknowledges durable admission without waiting for BullMQ', async () => { mocks.queueAdd.mockReturnValueOnce(new Promise(() => {})); diff --git a/packages/sdk/src/server/lib/fast-agent-parent-event-queue.ts b/packages/sdk/src/server/lib/fast-agent-parent-event-queue.ts index eb2ec6b9d..fafb0b499 100644 --- a/packages/sdk/src/server/lib/fast-agent-parent-event-queue.ts +++ b/packages/sdk/src/server/lib/fast-agent-parent-event-queue.ts @@ -4,14 +4,18 @@ import { Queue } from 'bullmq'; import { acquireFastAgentTurnLock, + buildFastAgentUserContentBlocks, findFastAgentDurableRetryScheduledError, } from '@roomote/cloud-agents/server'; import { + allocateFastAgentConversationSequence, and, asc, db, + type DatabaseOrTransaction, eq, fastAgentParentEvents, + fastAgentMessages, gt, isNull, lt, @@ -24,10 +28,15 @@ import { } from '@roomote/db/server'; import { getRedis } from '@roomote/redis'; import { + ACP_ENVELOPE_EVENT_TYPES, + FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY, + FAST_AGENT_EVENT_SEMANTICS_VERSION, RunStatus, + buildFastAgentInputSemantics, exitedRunStatuses, type FastAgentParent, type FastAgentHumanFollowUpEvent, + type FastAgentEventSemantics, } from '@roomote/types'; import { @@ -179,6 +188,204 @@ function wakeFastAgentParentEvent(request: FastAgentParentEventQueueRequest) { }); } +function parseEventDate(value: unknown, fallback: Date): Date { + if (typeof value !== 'string') return fallback; + const parsed = new Date(value); + return Number.isNaN(parsed.getTime()) ? fallback : parsed; +} + +function buildCanonicalEventSemantics(params: { + parent: FastAgentParent; + event: FastAgentParentEvent; + observedAt: Date; +}): FastAgentEventSemantics { + const { event, parent, observedAt } = params; + const base = { + schemaVersion: FAST_AGENT_EVENT_SEMANTICS_VERSION, + observedAt: observedAt.toISOString(), + sourceEventId: buildEventClientMessageSeed(event), + } as const; + switch (event.type) { + case 'human_follow_up': { + // One rule decides what a Session input claims, shared with the turn + // that persists its own input, so admission and execution cannot + // disagree about the same row. + return buildFastAgentInputSemantics({ + sessionId: parent.sessionId, + observedAt, + sourceEventId: base.sourceEventId, + platformEvent: event.turnSource === 'platform_event', + ...(event.turnSource === 'platform_event' && + event.platformEventKind === 'setup' + ? { + setupSnapshot: + event.setupContext?.setupSnapshot ?? event.question, + } + : {}), + }); + } + case 'scheduled_wakeup': + return { + ...base, + kind: 'historical_observation', + authority: 'roomote_runtime', + occurredAt: event.firedAt, + subject: { type: 'session_wakeup', id: event.wakeupId }, + version: { scheme: 'monotonic_number', value: event.runNumber }, + }; + case 'automation_triggered': + return { + ...base, + kind: 'historical_observation', + authority: 'automation', + ...(event.launchClaimedAt ? { occurredAt: event.launchClaimedAt } : {}), + subject: { type: 'automation', id: event.automationId }, + }; + case 'child_message': + return { + ...base, + kind: 'historical_observation', + authority: 'delegated_task', + subject: { type: 'task_run', id: String(event.runId) }, + }; + case 'artifact_published': + return { + ...base, + kind: 'state_change', + authority: 'roomote_runtime', + subject: { type: 'artifact', id: event.artifact.id }, + version: { scheme: 'monotonic_number', value: event.artifact.version }, + state: `published:${event.artifact.version}`, + }; + case 'task_settled': + return { + ...base, + kind: 'current_state_assertion', + authority: 'roomote_runtime', + subject: { type: 'task_run', id: String(event.runId) }, + state: event.status, + }; + case 'pull_request_opened': + return { + ...base, + // This records that a task opened or updated the pull request; it is + // not a claim about the PR's current status. That distinction is what + // keeps a merged or closed assertion authoritative even when a later + // task re-emits this event for the same PR, so no invented lifecycle + // version is needed here. + kind: 'state_change', + authority: 'source_control', + subject: { type: 'pull_request', id: event.pullRequest.url }, + state: event.pullRequest.status ?? 'open', + }; + case 'pull_request_feedback': + return { + ...base, + kind: 'historical_observation', + authority: 'source_control', + subject: { type: 'pull_request', id: event.pullRequest.url }, + ...(event.reviewResult?.headSha + ? { version: { scheme: 'opaque', value: event.reviewResult.headSha } } + : {}), + }; + case 'pull_request_status_changed': + return { + ...base, + kind: 'current_state_assertion', + authority: 'source_control', + subject: { type: 'pull_request', id: event.pullRequest.url }, + state: event.status, + }; + case 'pull_request_conflict_detected': + return { + ...base, + kind: 'current_state_assertion', + authority: 'source_control', + occurredAt: event.conflictDetectedAt, + observedAt: parseEventDate( + event.conflictDetectedAt, + observedAt, + ).toISOString(), + subject: { type: 'pull_request_conflict', id: event.pullRequest.url }, + state: 'conflicting', + }; + } +} + +async function persistQueuedEventCanonicalInput( + tx: DatabaseOrTransaction, + params: { parent: FastAgentParent; event: FastAgentParentEvent }, + admittedAt: Date, +): Promise { + const eventSeed = buildEventClientMessageSeed(params.event); + const turnId = + params.event.type === 'human_follow_up' + ? params.event.currentMessageId + : eventSeed; + const eventId = `${turnId}:user`; + const existing = await tx.query.fastAgentMessages.findFirst({ + where: and( + eq(fastAgentMessages.conversationId, params.parent.sessionId), + eq(fastAgentMessages.eventId, eventId), + ), + columns: { id: true }, + }); + if (existing) return; + const observedAt = + params.event.type === 'scheduled_wakeup' + ? parseEventDate(params.event.firedAt, admittedAt) + : params.event.type === 'pull_request_conflict_detected' + ? parseEventDate(params.event.conflictDetectedAt, admittedAt) + : params.event.type === 'automation_triggered' + ? parseEventDate(params.event.launchClaimedAt, admittedAt) + : admittedAt; + const question = + params.event.type === 'human_follow_up' + ? params.event.question + : `${JSON.stringify(params.event)}`; + const semantics = buildCanonicalEventSemantics({ + ...params, + observedAt, + }); + await tx.insert(fastAgentMessages).values({ + conversationId: params.parent.sessionId, + conversationSeq: await allocateFastAgentConversationSequence( + tx, + params.parent.sessionId, + ), + eventId, + turnId, + turnSeq: 0, + ts: observedAt.getTime(), + observedAt, + eventType: ACP_ENVELOPE_EVENT_TYPES.UserPrompt, + role: 'user', + contentBlocks: buildFastAgentUserContentBlocks( + question, + params.event.type === 'human_follow_up' + ? (params.event.images ?? []) + : [], + ), + metadata: { + visibleInTranscript: + params.event.type === 'human_follow_up' && !params.event.turnSource, + turnSource: + params.event.type === 'human_follow_up' + ? (params.event.turnSource ?? 'human') + : 'platform_event', + ...(params.event.type === 'human_follow_up' && + params.event.platformEventKind + ? { platformEventKind: params.event.platformEventKind } + : params.event.type !== 'human_follow_up' + ? { platformEventKind: 'delegated_task' } + : {}), + [FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY]: semantics, + }, + payload: {}, + source: params.parent.conversation.surface, + }); +} + /** Persist before acknowledging so child work never waits on the parent. */ export async function enqueueFastAgentParentEvent(params: { parent: FastAgentParent; @@ -186,16 +393,22 @@ export async function enqueueFastAgentParentEvent(params: { retryTaskStartRunId?: number; }): Promise<{ eventKey: string; queued: true }> { const eventKey = buildFastAgentParentEventKey(params); - await db - .insert(fastAgentParentEvents) - .values({ - conversationId: params.parent.sessionId, - eventKey, - parent: params.parent, - event: params.event, - retryTaskStartRunId: params.retryTaskStartRunId, - }) - .onConflictDoNothing({ target: fastAgentParentEvents.eventKey }); + await db.transaction(async (tx) => { + const admittedAt = new Date(); + await tx + .insert(fastAgentParentEvents) + .values({ + conversationId: params.parent.sessionId, + eventKey, + parent: params.parent, + event: params.event, + retryTaskStartRunId: params.retryTaskStartRunId, + createdAt: admittedAt, + updatedAt: admittedAt, + }) + .onConflictDoNothing({ target: fastAgentParentEvents.eventKey }); + await persistQueuedEventCanonicalInput(tx, params, admittedAt); + }); wakeFastAgentParentEvent({ conversationId: params.parent.sessionId, @@ -232,6 +445,7 @@ export async function enqueueFastAgentParentEventForRun(params: { event: params.event, }) .onConflictDoNothing({ target: fastAgentParentEvents.eventKey }); + await persistQueuedEventCanonicalInput(tx, params, new Date()); return true; }); diff --git a/packages/types/src/fast-agent-event-semantics.ts b/packages/types/src/fast-agent-event-semantics.ts new file mode 100644 index 000000000..08f9de4d2 --- /dev/null +++ b/packages/types/src/fast-agent-event-semantics.ts @@ -0,0 +1,102 @@ +export const FAST_AGENT_EVENT_SEMANTICS_VERSION = 1 as const; + +export type FastAgentEventSemanticKind = + | 'historical_observation' + | 'state_change' + | 'current_state_assertion'; + +export type FastAgentEventAuthority = + | 'human' + | 'roomote_runtime' + | 'delegated_task' + | 'source_control' + | 'automation'; + +export type FastAgentEventSubject = { + type: string; + id: string; +}; + +/** + * A version the source itself provides. `monotonic_number` is the only scheme + * that establishes precedence, and only where the producer genuinely + * guarantees monotonicity (a wakeup run number, an artifact version). + * `opaque` establishes identity for a specific revision, such as a review + * head SHA, without implying an order. Lifecycles without a provider-supplied + * version stay unversioned and are ordered by observation time instead. + */ +export type FastAgentEventVersion = + | { scheme: 'monotonic_number'; value: number } + | { scheme: 'opaque'; value: string }; + +/** + * Immutable semantics attached to a canonical Fast Session input. Reducer + * classifications are deliberately derived rather than persisted. + */ +export type FastAgentEventSemantics = { + schemaVersion: typeof FAST_AGENT_EVENT_SEMANTICS_VERSION; + kind: FastAgentEventSemanticKind; + authority: FastAgentEventAuthority; + observedAt: string; + occurredAt?: string; + subject?: FastAgentEventSubject; + version?: FastAgentEventVersion; + /** Stable serialization of the asserted state, used only within its subject. */ + state?: string; + sourceEventId: string; +}; + +export const FAST_AGENT_EVENT_SEMANTICS_METADATA_KEY = + 'fastAgentEventSemantics' as const; + +/** + * Semantics for a human or platform-event Session input. + * + * Durable queue admission and a turn that persists its own input both write + * the same canonical row, so the rule for what such an input claims lives + * here once rather than being restated by each writer. + */ +export function buildFastAgentInputSemantics(params: { + sessionId: string; + observedAt: Date; + sourceEventId: string; + platformEvent: boolean; + /** Present only for a setup platform event, which asserts current state. */ + setupSnapshot?: string | undefined; +}): FastAgentEventSemantics { + const base = { + schemaVersion: FAST_AGENT_EVENT_SEMANTICS_VERSION, + observedAt: params.observedAt.toISOString(), + sourceEventId: params.sourceEventId, + } as const; + if (params.platformEvent && params.setupSnapshot) { + return { + ...base, + kind: 'current_state_assertion', + authority: 'roomote_runtime', + subject: { type: 'setup_session', id: params.sessionId }, + state: params.setupSnapshot, + }; + } + return { + ...base, + kind: 'historical_observation', + authority: params.platformEvent ? 'roomote_runtime' : 'human', + }; +} + +export type FastAgentEventProjectionClassification = + | 'current' + | 'historical_relevant' + | 'superseded_irrelevant' + | 'conflicting'; + +export type FastAgentAssistantClaimProvenance = { + reducerVersion: number; + projectedThroughSequence: number | null; + projectionHash: string; + eventIds: string[]; +}; + +export const FAST_AGENT_ASSISTANT_CLAIM_PROVENANCE_METADATA_KEY = + 'fastAgentClaimProvenance' as const; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 1f2772006..1e11a347e 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -17,6 +17,7 @@ export * from './task-runs'; export * from './sessions'; export * from './session-wakeups'; export * from './fast-agent'; +export * from './fast-agent-event-semantics'; export * from './data-visualization'; export * from './fast-agent-tool-catalog'; export * from './integration-tool-lookup';