@opengeni/db 3.4.0-canary.2 → 3.6.0
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/canonical-human-identities.d.ts +20 -0
- package/dist/canonical-human-identities.js +7 -3
- package/dist/{chunk-ZWRIPCTR.js → chunk-2NT476HD.js} +2 -2
- package/dist/{chunk-PYMY3AJW.js → chunk-744DFC65.js} +202 -7
- package/dist/chunk-744DFC65.js.map +1 -0
- package/dist/{chunk-O6FTELKH.js → chunk-CDMMSUWJ.js} +3 -3
- package/dist/chunk-G3732M3T.js +299 -0
- package/dist/chunk-G3732M3T.js.map +1 -0
- package/dist/{chunk-TRBOWUG3.js → chunk-IW6O6G7R.js} +2 -2
- package/dist/{chunk-HY3F5Q4E.js → chunk-Q5YUGQVK.js} +3 -3
- package/dist/{chunk-V3TRUXFJ.js → chunk-UGDVSQ6U.js} +72 -19
- package/dist/chunk-UGDVSQ6U.js.map +1 -0
- package/dist/{chunk-C2AFP7SB.js → chunk-UJ2EW3QI.js} +6664 -6051
- package/dist/chunk-UJ2EW3QI.js.map +1 -0
- package/dist/{chunk-H7MXYG7R.js → chunk-WW7AJ5IC.js} +2 -2
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/index.d.ts +44 -6
- package/dist/index.js +2914 -1535
- package/dist/index.js.map +1 -1
- package/dist/managed-auth-session-set-schema.d.ts +1399 -0
- package/dist/managed-auth-session-sets.d.ts +145 -0
- package/dist/managed-auth-session-sets.js +50 -0
- package/dist/managed-auth-session-sets.js.map +1 -0
- package/dist/organization-recovery-schema.d.ts +2144 -0
- package/dist/organization-recovery.d.ts +186 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +7 -4
- package/dist/schema.d.ts +9 -6
- package/dist/schema.js +43 -1
- package/dist/session-background-commands.js +3 -3
- package/dist/session-control.d.ts +5 -3
- package/dist/session-queue-commands.d.ts +2 -0
- package/dist/session-tenancy.js +3 -3
- package/dist/video-generation.js +3 -3
- package/dist/work-claims-schema.d.ts +975 -0
- package/dist/work-claims.d.ts +83 -0
- package/drizzle/0362_managed_auth_session_sets.sql +2347 -0
- package/drizzle/0363_organization_recovery_custody.sql +2418 -0
- package/drizzle/0364_workspace_learning_policy_snapshot_lock_order.sql +221 -0
- package/drizzle/0365_permission_scoped_work_claims.sql +1306 -0
- package/drizzle/0366_session_discovery_title_search_index.sql +5 -0
- package/drizzle/0367_session_discovery_goal_search_index.sql +5 -0
- package/drizzle/0368_session_discovery_claim_search_index.sql +6 -0
- package/package.json +10 -6
- package/src/canonical-human-identities.ts +105 -27
- package/src/index.ts +1471 -433
- package/src/managed-auth-session-set-schema.ts +176 -0
- package/src/managed-auth-session-sets.ts +430 -0
- package/src/organization-recovery-schema.ts +277 -0
- package/src/organization-recovery.ts +424 -0
- package/src/provision-roles.ts +67 -0
- package/src/runtime-posture.ts +144 -6
- package/src/schema.ts +3 -0
- package/src/session-control.ts +255 -16
- package/src/session-queue-commands.ts +10 -1
- package/src/session-tool-call-settlement.ts +6 -1
- package/src/work-claims-schema.ts +148 -0
- package/src/work-claims.ts +200 -0
- package/dist/chunk-C2AFP7SB.js.map +0 -1
- package/dist/chunk-PYMY3AJW.js.map +0 -1
- package/dist/chunk-V3TRUXFJ.js.map +0 -1
- /package/dist/{chunk-ZWRIPCTR.js.map → chunk-2NT476HD.js.map} +0 -0
- /package/dist/{chunk-O6FTELKH.js.map → chunk-CDMMSUWJ.js.map} +0 -0
- /package/dist/{chunk-TRBOWUG3.js.map → chunk-IW6O6G7R.js.map} +0 -0
- /package/dist/{chunk-HY3F5Q4E.js.map → chunk-Q5YUGQVK.js.map} +0 -0
- /package/dist/{chunk-H7MXYG7R.js.map → chunk-WW7AJ5IC.js.map} +0 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WorkClaim,
|
|
3
|
+
WorkClaimCanonicalKey,
|
|
4
|
+
WorkClaimDisplayLabel,
|
|
5
|
+
WorkClaimMutationKind,
|
|
6
|
+
WorkClaimMutationResult,
|
|
7
|
+
WorkClaimNamespace,
|
|
8
|
+
WorkClaimReleaseReason,
|
|
9
|
+
WorkClaimRole,
|
|
10
|
+
WorkClaimSubjectType,
|
|
11
|
+
WorkClaimVersionKind,
|
|
12
|
+
WorkClaimVersionValue,
|
|
13
|
+
normalizeWorkClaimCanonicalKey,
|
|
14
|
+
normalizeWorkClaimDisplayLabel,
|
|
15
|
+
normalizeWorkClaimNamespace,
|
|
16
|
+
type WorkClaimRole as WorkClaimRoleType,
|
|
17
|
+
type WorkClaimSubjectType as WorkClaimSubjectTypeType,
|
|
18
|
+
type WorkClaimVersionKind as WorkClaimVersionKindType,
|
|
19
|
+
} from "@opengeni/contracts";
|
|
20
|
+
import { sql } from "drizzle-orm";
|
|
21
|
+
import type { Database } from "./database";
|
|
22
|
+
import { rawRows, withSessionActivityRlsContext } from "./database";
|
|
23
|
+
|
|
24
|
+
export type WorkClaimAttemptClaims = {
|
|
25
|
+
accountId: string;
|
|
26
|
+
workspaceId: string;
|
|
27
|
+
sessionId: string;
|
|
28
|
+
turnId: string;
|
|
29
|
+
attemptId: string;
|
|
30
|
+
executionGeneration: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type UpsertWorkClaimInput = WorkClaimAttemptClaims & {
|
|
34
|
+
operationId: string;
|
|
35
|
+
expectedRevision: number;
|
|
36
|
+
subjectNamespace: string;
|
|
37
|
+
subjectType: WorkClaimSubjectTypeType;
|
|
38
|
+
canonicalKey: string;
|
|
39
|
+
displayLabel?: string | null;
|
|
40
|
+
role: WorkClaimRoleType;
|
|
41
|
+
version?: {
|
|
42
|
+
kind: WorkClaimVersionKindType;
|
|
43
|
+
value: string;
|
|
44
|
+
} | null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ReleaseWorkClaimInput = WorkClaimAttemptClaims & {
|
|
48
|
+
operationId: string;
|
|
49
|
+
claimId: string;
|
|
50
|
+
expectedRevision: number;
|
|
51
|
+
reason: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type WorkClaimMutationRow = {
|
|
55
|
+
claim_id: string;
|
|
56
|
+
session_id: string;
|
|
57
|
+
root_session_id: string;
|
|
58
|
+
subject_namespace: string;
|
|
59
|
+
subject_type: string;
|
|
60
|
+
canonical_key: string;
|
|
61
|
+
display_label: string | null;
|
|
62
|
+
role: string;
|
|
63
|
+
state: string;
|
|
64
|
+
revision: number;
|
|
65
|
+
provenance: string;
|
|
66
|
+
version_kind: string | null;
|
|
67
|
+
version_value: string | null;
|
|
68
|
+
observed_at: Date | string;
|
|
69
|
+
created_at: Date | string;
|
|
70
|
+
updated_at: Date | string;
|
|
71
|
+
settled_at: Date | string | null;
|
|
72
|
+
mutation_kind: string;
|
|
73
|
+
replayed: boolean;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
function iso(value: Date | string): string {
|
|
77
|
+
return (value instanceof Date ? value : new Date(value)).toISOString();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function assertAttemptClaims(claims: WorkClaimAttemptClaims): void {
|
|
81
|
+
if (!Number.isSafeInteger(claims.executionGeneration) || claims.executionGeneration < 1) {
|
|
82
|
+
throw new Error("Work claims require a positive exact execution generation");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function mutationResultFromRow(row: WorkClaimMutationRow) {
|
|
87
|
+
const version =
|
|
88
|
+
row.version_kind === null || row.version_value === null
|
|
89
|
+
? null
|
|
90
|
+
: {
|
|
91
|
+
kind: WorkClaimVersionKind.parse(row.version_kind),
|
|
92
|
+
value: WorkClaimVersionValue.parse(row.version_value),
|
|
93
|
+
};
|
|
94
|
+
return WorkClaimMutationResult.parse({
|
|
95
|
+
claim: WorkClaim.parse({
|
|
96
|
+
id: row.claim_id,
|
|
97
|
+
sessionId: row.session_id,
|
|
98
|
+
rootSessionId: row.root_session_id,
|
|
99
|
+
subject: {
|
|
100
|
+
namespace: row.subject_namespace,
|
|
101
|
+
type: row.subject_type,
|
|
102
|
+
canonicalKey: row.canonical_key,
|
|
103
|
+
displayLabel: row.display_label,
|
|
104
|
+
},
|
|
105
|
+
role: row.role,
|
|
106
|
+
state: row.state,
|
|
107
|
+
revision: Number(row.revision),
|
|
108
|
+
provenance: row.provenance,
|
|
109
|
+
version,
|
|
110
|
+
observedAt: iso(row.observed_at),
|
|
111
|
+
createdAt: iso(row.created_at),
|
|
112
|
+
updatedAt: iso(row.updated_at),
|
|
113
|
+
settledAt: row.settled_at === null ? null : iso(row.settled_at),
|
|
114
|
+
}),
|
|
115
|
+
mutation: WorkClaimMutationKind.parse(row.mutation_kind),
|
|
116
|
+
replayed: row.replayed,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function upsertWorkClaim(db: Database, input: UpsertWorkClaimInput) {
|
|
121
|
+
assertAttemptClaims(input);
|
|
122
|
+
if (!Number.isSafeInteger(input.expectedRevision) || input.expectedRevision < 0) {
|
|
123
|
+
throw new Error("Work claim expectedRevision must be a non-negative safe integer");
|
|
124
|
+
}
|
|
125
|
+
const subjectNamespace = WorkClaimNamespace.parse(
|
|
126
|
+
normalizeWorkClaimNamespace(input.subjectNamespace),
|
|
127
|
+
);
|
|
128
|
+
const subjectType = WorkClaimSubjectType.parse(input.subjectType);
|
|
129
|
+
const canonicalKey = WorkClaimCanonicalKey.parse(
|
|
130
|
+
normalizeWorkClaimCanonicalKey(input.canonicalKey),
|
|
131
|
+
);
|
|
132
|
+
const role = WorkClaimRole.parse(input.role);
|
|
133
|
+
const displayLabel =
|
|
134
|
+
input.displayLabel === undefined || input.displayLabel === null
|
|
135
|
+
? null
|
|
136
|
+
: WorkClaimDisplayLabel.parse(normalizeWorkClaimDisplayLabel(input.displayLabel));
|
|
137
|
+
const version = input.version
|
|
138
|
+
? {
|
|
139
|
+
kind: WorkClaimVersionKind.parse(input.version.kind),
|
|
140
|
+
value: WorkClaimVersionValue.parse(normalizeWorkClaimCanonicalKey(input.version.value)),
|
|
141
|
+
}
|
|
142
|
+
: null;
|
|
143
|
+
const rows = await withSessionActivityRlsContext(
|
|
144
|
+
db,
|
|
145
|
+
{ accountId: input.accountId, workspaceId: input.workspaceId },
|
|
146
|
+
async (tx) =>
|
|
147
|
+
await rawRows<WorkClaimMutationRow>(
|
|
148
|
+
tx,
|
|
149
|
+
sql`SELECT * FROM upsert_session_work_claim_for_attempt(
|
|
150
|
+
${input.accountId}::uuid,
|
|
151
|
+
${input.workspaceId}::uuid,
|
|
152
|
+
${input.sessionId}::uuid,
|
|
153
|
+
${input.turnId}::uuid,
|
|
154
|
+
${input.attemptId}::uuid,
|
|
155
|
+
${input.executionGeneration}::integer,
|
|
156
|
+
${input.operationId}::uuid,
|
|
157
|
+
${input.expectedRevision}::integer,
|
|
158
|
+
${subjectNamespace}::text,
|
|
159
|
+
${subjectType}::text,
|
|
160
|
+
${canonicalKey}::text,
|
|
161
|
+
${displayLabel}::text,
|
|
162
|
+
${role}::text,
|
|
163
|
+
${version?.kind ?? null}::text,
|
|
164
|
+
${version?.value ?? null}::text
|
|
165
|
+
)`,
|
|
166
|
+
),
|
|
167
|
+
);
|
|
168
|
+
if (rows.length !== 1) throw new Error("Work claim upsert returned no durable receipt");
|
|
169
|
+
return mutationResultFromRow(rows[0]!);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function releaseWorkClaim(db: Database, input: ReleaseWorkClaimInput) {
|
|
173
|
+
assertAttemptClaims(input);
|
|
174
|
+
if (!Number.isSafeInteger(input.expectedRevision) || input.expectedRevision < 1) {
|
|
175
|
+
throw new Error("Work claim release requires a positive expectedRevision");
|
|
176
|
+
}
|
|
177
|
+
const reason = WorkClaimReleaseReason.parse(input.reason);
|
|
178
|
+
const rows = await withSessionActivityRlsContext(
|
|
179
|
+
db,
|
|
180
|
+
{ accountId: input.accountId, workspaceId: input.workspaceId },
|
|
181
|
+
async (tx) =>
|
|
182
|
+
await rawRows<WorkClaimMutationRow>(
|
|
183
|
+
tx,
|
|
184
|
+
sql`SELECT * FROM release_session_work_claim_for_attempt(
|
|
185
|
+
${input.accountId}::uuid,
|
|
186
|
+
${input.workspaceId}::uuid,
|
|
187
|
+
${input.sessionId}::uuid,
|
|
188
|
+
${input.turnId}::uuid,
|
|
189
|
+
${input.attemptId}::uuid,
|
|
190
|
+
${input.executionGeneration}::integer,
|
|
191
|
+
${input.operationId}::uuid,
|
|
192
|
+
${input.claimId}::uuid,
|
|
193
|
+
${input.expectedRevision}::integer,
|
|
194
|
+
${reason}::text
|
|
195
|
+
)`,
|
|
196
|
+
),
|
|
197
|
+
);
|
|
198
|
+
if (rows.length !== 1) throw new Error("Work claim release returned no durable receipt");
|
|
199
|
+
return mutationResultFromRow(rows[0]!);
|
|
200
|
+
}
|