@opengeni/db 0.27.7 → 0.27.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-IHPCI4GV.js → chunk-2JFRTKTG.js} +1 -1
- package/dist/chunk-2JFRTKTG.js.map +1 -0
- package/dist/{chunk-EX7CDSGH.js → chunk-NX2JNJJP.js} +13 -4
- package/dist/chunk-NX2JNJJP.js.map +1 -0
- package/dist/codex-token-resolver.d.ts +50 -8
- package/dist/connection-token-resolver.d.ts +45 -7
- package/dist/database.d.ts +137 -0
- package/dist/index.d.ts +25 -154
- package/dist/index.js +2796 -2634
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +1 -1
- package/dist/memory-governance.d.ts +1 -1
- package/dist/new-session-drafts.d.ts +1 -1
- package/dist/preference-registry.d.ts +1 -1
- package/dist/provision-roles.d.ts +1 -1
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +1 -1
- package/dist/schema.d.ts +44 -0
- package/dist/schema.js +1 -1
- package/dist/scoped-knowledge.d.ts +1 -1
- package/dist/session-control.d.ts +2 -1
- package/dist/session-queue-commands.d.ts +1 -1
- package/dist/session-realtime-context.d.ts +1 -1
- package/dist/session-realtime-ledger.d.ts +1 -1
- package/dist/session-realtime-mirror.d.ts +1 -1
- package/dist/session-realtime-state.d.ts +1 -1
- package/dist/session-realtime-terminal.d.ts +1 -1
- package/dist/session-realtime.d.ts +1 -1
- package/dist/session-tool-call-settlement.d.ts +1 -1
- package/dist/turn-initiator.d.ts +1 -1
- package/dist/workspace-artifacts.d.ts +1 -1
- package/dist/workspace-instruction-policies.d.ts +1 -1
- package/drizzle/0170_session_control_wake_revision.sql +133 -0
- package/drizzle/0171_social_connection_subject_ownership.sql +53 -0
- package/package.json +3 -3
- package/src/codex-token-resolver.ts +102 -49
- package/src/connection-token-resolver.ts +67 -26
- package/src/database.ts +393 -0
- package/src/index.ts +439 -516
- package/src/insights.ts +2 -2
- package/src/memory-governance.ts +2 -2
- package/src/new-session-drafts.ts +1 -1
- package/src/preference-registry.ts +2 -2
- package/src/provision-roles.ts +1 -1
- package/src/runtime-posture.ts +1 -1
- package/src/schema.ts +16 -3
- package/src/scoped-knowledge.ts +2 -2
- package/src/session-control.ts +12 -5
- package/src/session-queue-commands.ts +4 -1
- package/src/session-realtime-context.ts +1 -1
- package/src/session-realtime-ledger.ts +1 -1
- package/src/session-realtime-mirror.ts +1 -1
- package/src/session-realtime-state.ts +1 -1
- package/src/session-realtime-terminal.ts +1 -1
- package/src/session-realtime.ts +1 -1
- package/src/session-tool-call-settlement.ts +1 -1
- package/src/turn-initiator.ts +1 -1
- package/src/workspace-artifacts.ts +2 -2
- package/src/workspace-instruction-policies.ts +2 -2
- package/dist/chunk-EX7CDSGH.js.map +0 -1
- package/dist/chunk-IHPCI4GV.js.map +0 -1
package/src/insights.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { and, desc, eq, gte, inArray, lt, sql } from "drizzle-orm";
|
|
2
2
|
import { alias } from "drizzle-orm/pg-core";
|
|
3
|
-
import type { Database } from "./
|
|
4
|
-
import { rlsContextForWorkspace, withRlsContext } from "./
|
|
3
|
+
import type { Database } from "./database";
|
|
4
|
+
import { rlsContextForWorkspace, withRlsContext } from "./database";
|
|
5
5
|
import * as schema from "./schema";
|
|
6
6
|
|
|
7
7
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
package/src/memory-governance.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sql } from "drizzle-orm";
|
|
2
|
-
import type { Database } from "./
|
|
3
|
-
import { setSubjectRlsContext, withWorkspaceRls } from "./
|
|
2
|
+
import type { Database } from "./database";
|
|
3
|
+
import { setSubjectRlsContext, withWorkspaceRls } from "./database";
|
|
4
4
|
import {
|
|
5
5
|
hashMemoryOperationPlan,
|
|
6
6
|
hashMemoryRevertPlan,
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
ToolRef,
|
|
8
8
|
} from "@opengeni/contracts";
|
|
9
9
|
import { and, eq } from "drizzle-orm";
|
|
10
|
-
import type { Database } from "./
|
|
10
|
+
import type { Database } from "./database";
|
|
11
11
|
import * as schema from "./schema";
|
|
12
12
|
|
|
13
13
|
export type NewSessionDraftRow = typeof schema.newSessionDrafts.$inferSelect;
|
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
type PreferenceRegistryTrust,
|
|
22
22
|
} from "@opengeni/contracts";
|
|
23
23
|
import { and, asc, desc, eq, gt, inArray, isNull, lte, or, sql, type SQL } from "drizzle-orm";
|
|
24
|
-
import type { Database } from "./
|
|
25
|
-
import { setSubjectRlsContext, withWorkspaceRls, withWorkspaceSubjectRls } from "./
|
|
24
|
+
import type { Database } from "./database";
|
|
25
|
+
import { setSubjectRlsContext, withWorkspaceRls, withWorkspaceSubjectRls } from "./database";
|
|
26
26
|
import { nestedPostgresSqlState, safeDatabaseErrorFacts } from "./persistence-errors";
|
|
27
27
|
import * as schema from "./schema";
|
|
28
28
|
|
package/src/provision-roles.ts
CHANGED
package/src/runtime-posture.ts
CHANGED
package/src/schema.ts
CHANGED
|
@@ -3246,6 +3246,7 @@ export const sessionWorkflowWakeOutbox = pgTable(
|
|
|
3246
3246
|
temporalWorkflowId: text("temporal_workflow_id").notNull(),
|
|
3247
3247
|
wakeRevision: bigint("wake_revision", { mode: "number" }).notNull().default(1),
|
|
3248
3248
|
deliveredRevision: bigint("delivered_revision", { mode: "number" }).notNull().default(0),
|
|
3249
|
+
controlRevision: bigint("control_revision", { mode: "number" }).notNull().default(0),
|
|
3249
3250
|
reason: text("reason").notNull(),
|
|
3250
3251
|
attempts: integer("attempts").notNull().default(0),
|
|
3251
3252
|
nextAttemptAt: timestamp("next_attempt_at", { withTimezone: true }).notNull().defaultNow(),
|
|
@@ -3262,6 +3263,10 @@ export const sessionWorkflowWakeOutbox = pgTable(
|
|
|
3262
3263
|
"session_workflow_wake_outbox_revision_safe_check",
|
|
3263
3264
|
sql`${table.wakeRevision} <= 9007199254740991 and ${table.deliveredRevision} <= 9007199254740991`,
|
|
3264
3265
|
),
|
|
3266
|
+
controlRevisionValid: check(
|
|
3267
|
+
"session_workflow_wake_outbox_control_revision_check",
|
|
3268
|
+
sql`${table.controlRevision} >= 0 and ${table.controlRevision} <= ${table.wakeRevision} and ${table.controlRevision} <= 9007199254740991`,
|
|
3269
|
+
),
|
|
3265
3270
|
workspaceAccount: foreignKey({
|
|
3266
3271
|
name: "session_workflow_wake_outbox_workspace_account_fk",
|
|
3267
3272
|
columns: [table.workspaceId, table.accountId],
|
|
@@ -5823,6 +5828,7 @@ export const socialConnections = pgTable(
|
|
|
5823
5828
|
workspaceId: uuid("workspace_id")
|
|
5824
5829
|
.notNull()
|
|
5825
5830
|
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
5831
|
+
subjectId: text("subject_id"),
|
|
5826
5832
|
provider: text("provider").notNull(),
|
|
5827
5833
|
accountHandle: text("account_handle").notNull(),
|
|
5828
5834
|
accountName: text("account_name"),
|
|
@@ -5840,13 +5846,20 @@ export const socialConnections = pgTable(
|
|
|
5840
5846
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
5841
5847
|
},
|
|
5842
5848
|
(table) => ({
|
|
5843
|
-
workspaceProviderHandle: uniqueIndex("social_connections_workspace_provider_handle_idx")
|
|
5849
|
+
workspaceProviderHandle: uniqueIndex("social_connections_workspace_provider_handle_idx")
|
|
5850
|
+
.on(table.workspaceId, table.provider, table.accountHandle)
|
|
5851
|
+
.where(sql`${table.subjectId} is null`),
|
|
5852
|
+
subjectProviderHandle: uniqueIndex("social_connections_subject_provider_handle_idx")
|
|
5853
|
+
.on(table.workspaceId, table.subjectId, table.provider)
|
|
5854
|
+
.where(sql`${table.subjectId} is not null`),
|
|
5855
|
+
providerStatus: index("social_connections_workspace_provider_status_idx").on(
|
|
5844
5856
|
table.workspaceId,
|
|
5845
5857
|
table.provider,
|
|
5846
|
-
table.
|
|
5858
|
+
table.status,
|
|
5847
5859
|
),
|
|
5848
|
-
|
|
5860
|
+
subjectProviderStatus: index("social_connections_subject_provider_status_idx").on(
|
|
5849
5861
|
table.workspaceId,
|
|
5862
|
+
table.subjectId,
|
|
5850
5863
|
table.provider,
|
|
5851
5864
|
table.status,
|
|
5852
5865
|
),
|
package/src/scoped-knowledge.ts
CHANGED
|
@@ -21,8 +21,8 @@ import type {
|
|
|
21
21
|
ScopedKnowledgeScope,
|
|
22
22
|
} from "@opengeni/contracts";
|
|
23
23
|
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
24
|
-
import type { Database } from "./
|
|
25
|
-
import { setSubjectRlsContext, withRlsContext } from "./
|
|
24
|
+
import type { Database } from "./database";
|
|
25
|
+
import { setSubjectRlsContext, withRlsContext } from "./database";
|
|
26
26
|
import { nestedPostgresSqlState, safeDatabaseErrorFacts } from "./persistence-errors";
|
|
27
27
|
import * as schema from "./schema";
|
|
28
28
|
|
package/src/session-control.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type TurnInitiatorContext,
|
|
8
8
|
} from "@opengeni/contracts";
|
|
9
9
|
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
10
|
-
import type { Database } from "./
|
|
10
|
+
import type { Database } from "./database";
|
|
11
11
|
import * as schema from "./schema";
|
|
12
12
|
import { closePendingSessionToolCallsInTransaction } from "./session-tool-call-settlement";
|
|
13
13
|
import {
|
|
@@ -1494,12 +1494,13 @@ async function registerContinuableWakes(
|
|
|
1494
1494
|
)
|
|
1495
1495
|
), upserted as (
|
|
1496
1496
|
insert into ${schema.sessionWorkflowWakeOutbox} (
|
|
1497
|
-
session_id, account_id, workspace_id, temporal_workflow_id, reason
|
|
1497
|
+
session_id, account_id, workspace_id, temporal_workflow_id, reason, control_revision
|
|
1498
1498
|
)
|
|
1499
|
-
select session_id, account_id, workspace_id, temporal_workflow_id, ${input.reason}
|
|
1499
|
+
select session_id, account_id, workspace_id, temporal_workflow_id, ${input.reason}, 1
|
|
1500
1500
|
from eligible
|
|
1501
1501
|
on conflict (session_id) do update set
|
|
1502
1502
|
wake_revision = ${schema.sessionWorkflowWakeOutbox}.wake_revision + 1,
|
|
1503
|
+
control_revision = ${schema.sessionWorkflowWakeOutbox}.wake_revision + 1,
|
|
1503
1504
|
temporal_workflow_id = excluded.temporal_workflow_id,
|
|
1504
1505
|
reason = excluded.reason,
|
|
1505
1506
|
attempts = 0,
|
|
@@ -1611,12 +1612,13 @@ async function registerCancellationWakes(
|
|
|
1611
1612
|
and session.id in (${sessionIds})
|
|
1612
1613
|
), upserted as (
|
|
1613
1614
|
insert into ${schema.sessionWorkflowWakeOutbox} (
|
|
1614
|
-
session_id, account_id, workspace_id, temporal_workflow_id, reason
|
|
1615
|
+
session_id, account_id, workspace_id, temporal_workflow_id, reason, control_revision
|
|
1615
1616
|
)
|
|
1616
|
-
select session_id, account_id, workspace_id, temporal_workflow_id, 'session_cancelled'
|
|
1617
|
+
select session_id, account_id, workspace_id, temporal_workflow_id, 'session_cancelled', 1
|
|
1617
1618
|
from eligible
|
|
1618
1619
|
on conflict (session_id) do update set
|
|
1619
1620
|
wake_revision = ${schema.sessionWorkflowWakeOutbox}.wake_revision + 1,
|
|
1621
|
+
control_revision = ${schema.sessionWorkflowWakeOutbox}.wake_revision + 1,
|
|
1620
1622
|
temporal_workflow_id = excluded.temporal_workflow_id,
|
|
1621
1623
|
reason = excluded.reason,
|
|
1622
1624
|
attempts = 0,
|
|
@@ -1641,6 +1643,7 @@ export async function registerSessionWorkflowWakeInTransaction(
|
|
|
1641
1643
|
sessionId: string;
|
|
1642
1644
|
temporalWorkflowId: string;
|
|
1643
1645
|
reason: string;
|
|
1646
|
+
controlRequested?: boolean;
|
|
1644
1647
|
},
|
|
1645
1648
|
): Promise<number> {
|
|
1646
1649
|
const [row] = await db
|
|
@@ -1650,6 +1653,7 @@ export async function registerSessionWorkflowWakeInTransaction(
|
|
|
1650
1653
|
workspaceId: input.workspaceId,
|
|
1651
1654
|
sessionId: input.sessionId,
|
|
1652
1655
|
temporalWorkflowId: input.temporalWorkflowId,
|
|
1656
|
+
controlRevision: input.controlRequested ? 1 : 0,
|
|
1653
1657
|
reason: input.reason,
|
|
1654
1658
|
})
|
|
1655
1659
|
.onConflictDoUpdate({
|
|
@@ -1657,6 +1661,9 @@ export async function registerSessionWorkflowWakeInTransaction(
|
|
|
1657
1661
|
set: {
|
|
1658
1662
|
temporalWorkflowId: input.temporalWorkflowId,
|
|
1659
1663
|
wakeRevision: sql`${schema.sessionWorkflowWakeOutbox.wakeRevision} + 1`,
|
|
1664
|
+
controlRevision: input.controlRequested
|
|
1665
|
+
? sql`${schema.sessionWorkflowWakeOutbox.wakeRevision} + 1`
|
|
1666
|
+
: sql`${schema.sessionWorkflowWakeOutbox.controlRevision}`,
|
|
1660
1667
|
reason: input.reason,
|
|
1661
1668
|
attempts: 0,
|
|
1662
1669
|
nextAttemptAt: new Date(),
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type TurnExecutionPolicyV1,
|
|
13
13
|
} from "@opengeni/contracts";
|
|
14
14
|
import { and, asc, eq, inArray, sql } from "drizzle-orm";
|
|
15
|
-
import type { Database } from "./
|
|
15
|
+
import type { Database } from "./database";
|
|
16
16
|
import { sanitizeEventPayload } from "./event-payload-sanitizer";
|
|
17
17
|
import { closePendingSessionToolCallsInTransaction } from "./session-tool-call-settlement";
|
|
18
18
|
import {
|
|
@@ -1180,6 +1180,7 @@ export async function steerQueuedTurnInTransaction(
|
|
|
1180
1180
|
sessionId: input.sessionId,
|
|
1181
1181
|
temporalWorkflowId: session.temporalWorkflowId ?? `session-${input.sessionId}`,
|
|
1182
1182
|
reason: "queue_steer",
|
|
1183
|
+
controlRequested: true,
|
|
1183
1184
|
});
|
|
1184
1185
|
const receipt = await updateSessionCommandReceiptResult(db, reserved.receipt.id, {
|
|
1185
1186
|
controlRevision: resumed.revision,
|
|
@@ -1739,6 +1740,7 @@ export async function submitHumanPromptInTransaction(
|
|
|
1739
1740
|
sessionId: input.sessionId,
|
|
1740
1741
|
temporalWorkflowId: workflowId,
|
|
1741
1742
|
reason: input.delivery === "steer" ? "prompt_steer" : "prompt_send",
|
|
1743
|
+
controlRequested: input.delivery === "steer",
|
|
1742
1744
|
});
|
|
1743
1745
|
await db.insert(schema.auditEvents).values({
|
|
1744
1746
|
accountId: input.accountId,
|
|
@@ -2183,6 +2185,7 @@ export async function steerAgentSessionInTransaction(
|
|
|
2183
2185
|
sessionId: input.targetSessionId,
|
|
2184
2186
|
temporalWorkflowId: workflowId,
|
|
2185
2187
|
reason: "agent_steer",
|
|
2188
|
+
controlRequested: true,
|
|
2186
2189
|
});
|
|
2187
2190
|
await db
|
|
2188
2191
|
.update(schema.sessions)
|
|
@@ -3,7 +3,7 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { ReasoningEffort } from "@opengeni/contracts";
|
|
4
4
|
import { and, asc, desc, eq, inArray, isNull, sql } from "drizzle-orm";
|
|
5
5
|
|
|
6
|
-
import type { Database } from "./
|
|
6
|
+
import type { Database } from "./database";
|
|
7
7
|
import * as schema from "./schema";
|
|
8
8
|
import { submitHumanPromptInTransaction } from "./session-queue-commands";
|
|
9
9
|
|
|
@@ -4,7 +4,7 @@ import { LatencyMode, ReasoningEffort, type SessionRealtimeMode } from "@opengen
|
|
|
4
4
|
import { and, asc, desc, eq, inArray, isNull, or, sql } from "drizzle-orm";
|
|
5
5
|
|
|
6
6
|
import { sanitizeEventPayload } from "./event-payload-sanitizer";
|
|
7
|
-
import type { Database } from "./
|
|
7
|
+
import type { Database } from "./database";
|
|
8
8
|
import * as schema from "./schema";
|
|
9
9
|
import {
|
|
10
10
|
assertSessionRealtimeOwnerInTransaction,
|
|
@@ -4,7 +4,7 @@ import type { HumanInputQuestion, HumanInputResponse } from "@opengeni/contracts
|
|
|
4
4
|
import { and, desc, eq, gt, sql } from "drizzle-orm";
|
|
5
5
|
|
|
6
6
|
import { sanitizeEventPayload } from "./event-payload-sanitizer";
|
|
7
|
-
import type { Database } from "./
|
|
7
|
+
import type { Database } from "./database";
|
|
8
8
|
import * as schema from "./schema";
|
|
9
9
|
|
|
10
10
|
const SESSION_REALTIME_MIRROR_MAX_TEXT_BYTES = 131_072;
|
|
@@ -3,7 +3,7 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
4
4
|
|
|
5
5
|
import { sanitizeEventPayload } from "./event-payload-sanitizer";
|
|
6
|
-
import type { Database } from "./
|
|
6
|
+
import type { Database } from "./database";
|
|
7
7
|
import { mirrorSessionRealtimeContextInTransaction } from "./session-realtime-mirror";
|
|
8
8
|
import * as schema from "./schema";
|
|
9
9
|
|
package/src/session-realtime.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
import { and, asc, eq, gt, inArray, isNull, or } from "drizzle-orm";
|
|
10
10
|
|
|
11
11
|
import { sanitizeEventPayload } from "./event-payload-sanitizer";
|
|
12
|
-
import type { Database } from "./
|
|
12
|
+
import type { Database } from "./database";
|
|
13
13
|
import { flushSessionRealtimeTranscriptTailInTransaction } from "./session-realtime-context";
|
|
14
14
|
import {
|
|
15
15
|
evaluateSessionControl,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SessionEvent } from "@opengeni/contracts";
|
|
2
2
|
import { boundModelToolOutputItem } from "@opengeni/codex";
|
|
3
3
|
import { and, asc, eq, sql } from "drizzle-orm";
|
|
4
|
-
import type { Database } from "./
|
|
4
|
+
import type { Database } from "./database";
|
|
5
5
|
import { sanitizeEventPayload, sanitizeModelPayload } from "./event-payload-sanitizer";
|
|
6
6
|
import * as schema from "./schema";
|
|
7
7
|
|
package/src/turn-initiator.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type TurnInitiatorContext,
|
|
5
5
|
} from "@opengeni/contracts";
|
|
6
6
|
import { and, eq } from "drizzle-orm";
|
|
7
|
-
import type { Database } from "./
|
|
7
|
+
import type { Database } from "./database";
|
|
8
8
|
import type { SessionCommandActor } from "./session-control";
|
|
9
9
|
import * as schema from "./schema";
|
|
10
10
|
|
|
@@ -6,8 +6,8 @@ import type {
|
|
|
6
6
|
WorkspaceArtifactVersion,
|
|
7
7
|
} from "@opengeni/contracts";
|
|
8
8
|
import { and, desc, eq, lt, or, sql } from "drizzle-orm";
|
|
9
|
-
import type { Database } from "./
|
|
10
|
-
import { withRlsContext, withWorkspaceRls } from "./
|
|
9
|
+
import type { Database } from "./database";
|
|
10
|
+
import { withRlsContext, withWorkspaceRls } from "./database";
|
|
11
11
|
import * as schema from "./schema";
|
|
12
12
|
|
|
13
13
|
type ArtifactRow = typeof schema.workspaceArtifacts.$inferSelect;
|
|
@@ -25,8 +25,8 @@ import type {
|
|
|
25
25
|
WorkspaceInstructionPolicyTarget,
|
|
26
26
|
} from "@opengeni/contracts";
|
|
27
27
|
import { and, asc, desc, eq, inArray, isNull, lt, or, sql, type SQL } from "drizzle-orm";
|
|
28
|
-
import type { Database } from "./
|
|
29
|
-
import { withRlsContext, withWorkspaceRls, withWorkspaceSubjectRls } from "./
|
|
28
|
+
import type { Database } from "./database";
|
|
29
|
+
import { withRlsContext, withWorkspaceRls, withWorkspaceSubjectRls } from "./database";
|
|
30
30
|
import { nestedPostgresSqlState } from "./persistence-errors";
|
|
31
31
|
import * as schema from "./schema";
|
|
32
32
|
|