@opengeni/db 4.4.0-canary.0 → 4.4.0-canary.2
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.js +4 -3
- package/dist/{chunk-2ZMTQVTR.js → chunk-2KOLL33E.js} +2 -2
- package/dist/chunk-45CP2YKY.js +1062 -0
- package/dist/chunk-45CP2YKY.js.map +1 -0
- package/dist/{chunk-6TKL3GQO.js → chunk-5UUWZDAV.js} +6531 -6480
- package/dist/chunk-5UUWZDAV.js.map +1 -0
- package/dist/{chunk-QLA3UQNX.js → chunk-6IJD3XXF.js} +17 -3
- package/dist/chunk-6IJD3XXF.js.map +1 -0
- package/dist/{chunk-232VC2LW.js → chunk-6V3HDEMR.js} +2 -2
- package/dist/{chunk-M7PSMVFF.js → chunk-CHBLBEU6.js} +2 -2
- package/dist/chunk-M4PKBJRS.js +20318 -0
- package/dist/chunk-M4PKBJRS.js.map +1 -0
- package/dist/chunk-S2TZ3F4L.js +237 -0
- package/dist/chunk-S2TZ3F4L.js.map +1 -0
- package/dist/{chunk-UK57QA2H.js → chunk-UOXWVP3T.js} +2 -2
- package/dist/{chunk-GVZJ7XSR.js → chunk-WFU6PS54.js} +11 -4
- package/dist/chunk-WFU6PS54.js.map +1 -0
- package/dist/{chunk-THJGMEK5.js → chunk-XJP7KJ6U.js} +121 -66
- package/dist/chunk-XJP7KJ6U.js.map +1 -0
- package/dist/connection-token-resolver.d.ts +2 -0
- package/dist/database.d.ts +2 -0
- package/dist/editable-artifact-durable-export.js +3 -2
- package/dist/editable-artifact-durable-export.js.map +1 -1
- package/dist/editable-artifacts.js +4 -3
- package/dist/external-identities.d.ts +1 -0
- package/dist/external-membership-operations.d.ts +44 -0
- package/dist/governed-learning-evaluator.d.ts +1 -14
- package/dist/host-mcp-bindings.d.ts +4 -0
- package/dist/host-mcp-resolvers.d.ts +47 -0
- package/dist/host-mcp-task-authority.d.ts +2 -6
- package/dist/index.d.ts +29 -31
- package/dist/index.js +8616 -8321
- package/dist/index.js.map +1 -1
- package/dist/knowledge-document-preparation.d.ts +56 -0
- package/dist/knowledge-entries-schema.d.ts +2479 -0
- package/dist/knowledge-entries.d.ts +421 -0
- package/dist/knowledge-indexing.d.ts +99 -0
- package/dist/knowledge-migration.d.ts +6 -0
- package/dist/managed-auth-session-sets.js +4 -3
- package/dist/mcp-operations.js +3 -2
- package/dist/mcp-operations.js.map +1 -1
- package/dist/migrate.js +2 -1
- package/dist/provision-roles.js +1 -1
- package/dist/retained-provider-commands.js +3 -2
- package/dist/retained-provider-commands.js.map +1 -1
- package/dist/runtime-posture.d.ts +7 -7
- package/dist/schema.d.ts +115 -12
- package/dist/schema.js +26 -1
- package/dist/session-background-commands.js +5 -4
- package/dist/session-command-output.js +8 -6
- package/dist/session-command-output.js.map +1 -1
- package/dist/session-event-slices.js +6 -4
- package/dist/session-event-slices.js.map +1 -1
- package/dist/session-mcp-credential-rotation.js +5 -4
- package/dist/session-mcp-credential-rotation.js.map +1 -1
- package/dist/session-tenancy.js +4 -3
- package/dist/video-generation.js +4 -3
- package/dist/workspace-artifacts.d.ts +1 -0
- package/dist/workspace-instruction-policies-schema.d.ts +21 -2
- package/dist/workspace-instruction-policies.d.ts +1 -1
- package/dist/workspace-membership-access.d.ts +11 -0
- package/dist/workspace-tool-defaults.js +5 -4
- package/dist/workspace-tool-defaults.js.map +1 -1
- package/drizzle/0461_unified_knowledge.sql +2859 -0
- package/drizzle/0462_agent_instruction_non_destructive_edits.sql +212 -0
- package/drizzle/0463_host_mcp_resolver_registration.sql +111 -0
- package/drizzle/0464_external_workspace_membership_operations.sql +166 -0
- package/package.json +6 -6
- package/src/connection-token-resolver.ts +75 -6
- package/src/database.ts +12 -1
- package/src/external-identities.ts +1 -0
- package/src/external-membership-operations.ts +134 -0
- package/src/governed-learning-evaluator.ts +0 -69
- package/src/host-mcp-binding-match.ts +1 -0
- package/src/host-mcp-bindings.ts +24 -1
- package/src/host-mcp-resolvers.ts +266 -0
- package/src/host-mcp-task-authority.ts +11 -10
- package/src/index.ts +307 -128
- package/src/knowledge-document-preparation.ts +90 -0
- package/src/knowledge-entries-schema.ts +264 -0
- package/src/knowledge-entries.ts +860 -0
- package/src/knowledge-indexing.ts +126 -0
- package/src/knowledge-migration.ts +761 -0
- package/src/knowledge-source-sync.ts +46 -7
- package/src/migrate.ts +19 -0
- package/src/provision-roles.ts +23 -57
- package/src/runtime-posture.ts +103 -7
- package/src/schema.ts +15 -3
- package/src/skills.ts +4 -0
- package/src/video-generation.ts +14 -0
- package/src/workspace-artifacts.ts +2 -0
- package/src/workspace-instruction-policies-schema.ts +1 -0
- package/src/workspace-membership-access.ts +61 -0
- package/dist/chunk-6TKL3GQO.js.map +0 -1
- package/dist/chunk-EYF6MH6C.js +0 -4772
- package/dist/chunk-EYF6MH6C.js.map +0 -1
- package/dist/chunk-GSBONN55.js +0 -533
- package/dist/chunk-GSBONN55.js.map +0 -1
- package/dist/chunk-GVZJ7XSR.js.map +0 -1
- package/dist/chunk-QLA3UQNX.js.map +0 -1
- package/dist/chunk-THJGMEK5.js.map +0 -1
- /package/dist/{chunk-2ZMTQVTR.js.map → chunk-2KOLL33E.js.map} +0 -0
- /package/dist/{chunk-232VC2LW.js.map → chunk-6V3HDEMR.js.map} +0 -0
- /package/dist/{chunk-M7PSMVFF.js.map → chunk-CHBLBEU6.js.map} +0 -0
- /package/dist/{chunk-UK57QA2H.js.map → chunk-UOXWVP3T.js.map} +0 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { FileAsset, AgentLearningOverridePatch, AgentInstructionSaveRequest, AgentInstructionReviewRequest, WorkspaceInstructionPolicyTarget, KnowledgeEntryListRequest, KnowledgeReviewBatchListRequest, KnowledgeEntryBatchReviewRequest, KnowledgeTaskNotePromotionRequest, KnowledgeEntryRecord, KnowledgeEntryReviewRequest, KnowledgeEntryRestoreRequest, KnowledgeEntrySaveRequest, type AgentLearningContext, type KnowledgeEntryScope } from "@opengeni/contracts";
|
|
2
|
+
import { type Database } from "./database.js";
|
|
3
|
+
/** Trusted host claims. Never deserialize this context from tool/request input. */
|
|
4
|
+
export type KnowledgeActor = {
|
|
5
|
+
kind: "service";
|
|
6
|
+
principalKind: "service" | "api_key" | "configured_key" | "mcp_gateway";
|
|
7
|
+
subjectId: string;
|
|
8
|
+
writeScopes: Array<"workspace" | "organization">;
|
|
9
|
+
review: false;
|
|
10
|
+
settingsScopes: [];
|
|
11
|
+
} | {
|
|
12
|
+
kind: "human";
|
|
13
|
+
principalKind: "human_session";
|
|
14
|
+
subjectId: string;
|
|
15
|
+
writeScopes: KnowledgeEntryScope[];
|
|
16
|
+
settingsScopes: Array<"workspace" | "personal">;
|
|
17
|
+
review: boolean;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "agent";
|
|
20
|
+
sessionId: string;
|
|
21
|
+
turnId: string;
|
|
22
|
+
attemptId: string;
|
|
23
|
+
executionGeneration: number;
|
|
24
|
+
};
|
|
25
|
+
export type KnowledgeContext = {
|
|
26
|
+
accountId: string;
|
|
27
|
+
workspaceId: string;
|
|
28
|
+
actor: KnowledgeActor;
|
|
29
|
+
};
|
|
30
|
+
/** Freeze before model execution; retries of the logical turn recover the same policy. */
|
|
31
|
+
export declare function freezeAgentLearningPolicy(db: Database, context: KnowledgeContext): Promise<{
|
|
32
|
+
[x: string]: unknown;
|
|
33
|
+
defaultScope: "personal" | "workspace";
|
|
34
|
+
subjectId: string | null;
|
|
35
|
+
effective: {
|
|
36
|
+
knowledge: "automatic" | "off" | "review_first";
|
|
37
|
+
instructions: "automatic" | "off" | "review_first";
|
|
38
|
+
skills: "automatic" | "off" | "review_first";
|
|
39
|
+
};
|
|
40
|
+
}>;
|
|
41
|
+
export declare function saveKnowledgeEntry(db: Database, context: KnowledgeContext, input: KnowledgeEntrySaveRequest): Promise<{
|
|
42
|
+
operationId: string;
|
|
43
|
+
entryId: string;
|
|
44
|
+
revisionId: string;
|
|
45
|
+
version: number;
|
|
46
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
47
|
+
reviewBatchId: string | null;
|
|
48
|
+
replayed: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
export declare function promoteTaskNoteToKnowledge(db: Database, context: KnowledgeContext, input: KnowledgeTaskNotePromotionRequest): Promise<{
|
|
51
|
+
operationId: string;
|
|
52
|
+
entryId: string;
|
|
53
|
+
revisionId: string;
|
|
54
|
+
version: number;
|
|
55
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
56
|
+
reviewBatchId: string | null;
|
|
57
|
+
replayed: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
export declare function reviewKnowledgeEntry(db: Database, context: KnowledgeContext, input: KnowledgeEntryReviewRequest): Promise<{
|
|
60
|
+
operationId: string;
|
|
61
|
+
entryId: string;
|
|
62
|
+
revisionId: string;
|
|
63
|
+
version: number;
|
|
64
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
65
|
+
reviewBatchId: string | null;
|
|
66
|
+
replayed: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
/** Atomic review of exact revisions; dependencies publish before their findings. */
|
|
69
|
+
export declare function reviewKnowledgeEntries(db: Database, context: KnowledgeContext, input: KnowledgeEntryBatchReviewRequest): Promise<{
|
|
70
|
+
receipts: {
|
|
71
|
+
operationId: string;
|
|
72
|
+
entryId: string;
|
|
73
|
+
revisionId: string;
|
|
74
|
+
version: number;
|
|
75
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
76
|
+
reviewBatchId: string | null;
|
|
77
|
+
replayed: boolean;
|
|
78
|
+
}[];
|
|
79
|
+
}>;
|
|
80
|
+
export declare function restoreKnowledgeEntry(db: Database, context: KnowledgeContext, input: KnowledgeEntryRestoreRequest): Promise<{
|
|
81
|
+
operationId: string;
|
|
82
|
+
entryId: string;
|
|
83
|
+
revisionId: string;
|
|
84
|
+
version: number;
|
|
85
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
86
|
+
reviewBatchId: string | null;
|
|
87
|
+
replayed: boolean;
|
|
88
|
+
}>;
|
|
89
|
+
export declare function archiveKnowledgeEntry(db: Database, context: KnowledgeContext, input: {
|
|
90
|
+
operationId: string;
|
|
91
|
+
entryId: string;
|
|
92
|
+
expectedVersion: number;
|
|
93
|
+
}): Promise<{
|
|
94
|
+
operationId: string;
|
|
95
|
+
entryId: string;
|
|
96
|
+
revisionId: string;
|
|
97
|
+
version: number;
|
|
98
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
99
|
+
reviewBatchId: string | null;
|
|
100
|
+
replayed: boolean;
|
|
101
|
+
}>;
|
|
102
|
+
export declare function getKnowledgeEntry(db: Database, context: KnowledgeContext, entryId: string, options?: {
|
|
103
|
+
revisionId?: string | undefined;
|
|
104
|
+
view?: "published" | "needs_review" | "archived" | "rejected" | undefined;
|
|
105
|
+
}): Promise<KnowledgeEntryRecord | null>;
|
|
106
|
+
export declare function listKnowledgeEntries(db: Database, context: KnowledgeContext, input?: KnowledgeEntryListRequest, embedding?: {
|
|
107
|
+
model: string;
|
|
108
|
+
values: number[];
|
|
109
|
+
} | undefined): Promise<{
|
|
110
|
+
entries: {
|
|
111
|
+
id: string;
|
|
112
|
+
scope: "organization" | "personal" | "workspace";
|
|
113
|
+
version: number;
|
|
114
|
+
publishedRevisionId: string | null;
|
|
115
|
+
latestRevisionId: string;
|
|
116
|
+
archived: boolean;
|
|
117
|
+
createdAt: string;
|
|
118
|
+
updatedAt: string;
|
|
119
|
+
score?: number | undefined;
|
|
120
|
+
excerpts: {
|
|
121
|
+
field: "content" | "title";
|
|
122
|
+
start: number;
|
|
123
|
+
end: number;
|
|
124
|
+
text: string;
|
|
125
|
+
}[];
|
|
126
|
+
revision: {
|
|
127
|
+
id: string;
|
|
128
|
+
entryId: string;
|
|
129
|
+
number: number;
|
|
130
|
+
change: "archive" | "upsert";
|
|
131
|
+
previousRevisionId: string | null;
|
|
132
|
+
restoredFromRevisionId: string | null;
|
|
133
|
+
createdAt: string;
|
|
134
|
+
createdBySessionId: string | null;
|
|
135
|
+
reviewBatchId: string | null;
|
|
136
|
+
outcome: "pending" | "published" | "rejected" | "superseded";
|
|
137
|
+
title: string;
|
|
138
|
+
kind: "decision" | "fact" | "group" | "incident" | "note" | "requirement" | "source";
|
|
139
|
+
preview: string;
|
|
140
|
+
groupIds: string[];
|
|
141
|
+
sourceKind: "connector" | "conversation" | "file" | "manual" | "repository" | "slack" | "task_note" | "web" | null;
|
|
142
|
+
};
|
|
143
|
+
}[];
|
|
144
|
+
nextCursor: string | null;
|
|
145
|
+
}>;
|
|
146
|
+
export declare function listKnowledgeReviewBatches(db: Database, context: KnowledgeContext, input?: KnowledgeReviewBatchListRequest): Promise<{
|
|
147
|
+
batches: {
|
|
148
|
+
id: string;
|
|
149
|
+
sessionId: string | null;
|
|
150
|
+
scheduledTaskId: string | null;
|
|
151
|
+
scheduledTaskRunId: string | null;
|
|
152
|
+
title: string | null;
|
|
153
|
+
scope: "organization" | "personal" | "workspace";
|
|
154
|
+
pendingCount: number;
|
|
155
|
+
createdAt: string;
|
|
156
|
+
}[];
|
|
157
|
+
nextCursor: string | null;
|
|
158
|
+
}>;
|
|
159
|
+
export declare function listKnowledgeEntryHistory(db: Database, context: KnowledgeContext, entryId: string, beforeRevision?: number): Promise<{
|
|
160
|
+
entries: {
|
|
161
|
+
id: string;
|
|
162
|
+
scope: "organization" | "personal" | "workspace";
|
|
163
|
+
version: number;
|
|
164
|
+
publishedRevisionId: string | null;
|
|
165
|
+
latestRevisionId: string;
|
|
166
|
+
archived: boolean;
|
|
167
|
+
createdAt: string;
|
|
168
|
+
updatedAt: string;
|
|
169
|
+
score?: number | undefined;
|
|
170
|
+
excerpts: {
|
|
171
|
+
field: "content" | "title";
|
|
172
|
+
start: number;
|
|
173
|
+
end: number;
|
|
174
|
+
text: string;
|
|
175
|
+
}[];
|
|
176
|
+
revision: {
|
|
177
|
+
id: string;
|
|
178
|
+
entryId: string;
|
|
179
|
+
number: number;
|
|
180
|
+
change: "archive" | "upsert";
|
|
181
|
+
previousRevisionId: string | null;
|
|
182
|
+
restoredFromRevisionId: string | null;
|
|
183
|
+
createdAt: string;
|
|
184
|
+
createdBySessionId: string | null;
|
|
185
|
+
reviewBatchId: string | null;
|
|
186
|
+
outcome: "pending" | "published" | "rejected" | "superseded";
|
|
187
|
+
title: string;
|
|
188
|
+
kind: "decision" | "fact" | "group" | "incident" | "note" | "requirement" | "source";
|
|
189
|
+
preview: string;
|
|
190
|
+
groupIds: string[];
|
|
191
|
+
sourceKind: "connector" | "conversation" | "file" | "manual" | "repository" | "slack" | "task_note" | "web" | null;
|
|
192
|
+
};
|
|
193
|
+
}[];
|
|
194
|
+
beforeRevision: number | null;
|
|
195
|
+
}>;
|
|
196
|
+
export declare function getAgentLearningSettings(db: Database, context: KnowledgeContext, scope: "workspace" | "personal" | "context", source?: AgentLearningContext): Promise<{
|
|
197
|
+
ownerKey: string;
|
|
198
|
+
contextKey: string;
|
|
199
|
+
version: number;
|
|
200
|
+
settings: {
|
|
201
|
+
knowledge?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
202
|
+
instructions?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
203
|
+
skills?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
204
|
+
};
|
|
205
|
+
}>;
|
|
206
|
+
export declare function saveAgentLearningSettings(db: Database, context: KnowledgeContext, input: {
|
|
207
|
+
scope: "workspace" | "personal";
|
|
208
|
+
source?: AgentLearningContext | undefined;
|
|
209
|
+
operationId: string;
|
|
210
|
+
expectedVersion: number;
|
|
211
|
+
settings: AgentLearningOverridePatch;
|
|
212
|
+
}): Promise<{
|
|
213
|
+
ownerKey: string;
|
|
214
|
+
contextKey: string;
|
|
215
|
+
version: number;
|
|
216
|
+
settings: {
|
|
217
|
+
knowledge?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
218
|
+
instructions?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
219
|
+
skills?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
220
|
+
};
|
|
221
|
+
}>;
|
|
222
|
+
export declare function listAgentLearningOverrides(db: Database, context: KnowledgeContext, scope: "workspace" | "personal"): Promise<{
|
|
223
|
+
contextKey: string;
|
|
224
|
+
version: number;
|
|
225
|
+
settings: {
|
|
226
|
+
knowledge?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
227
|
+
instructions?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
228
|
+
skills?: "automatic" | "inherit" | "off" | "review_first" | undefined;
|
|
229
|
+
};
|
|
230
|
+
updatedAt: string;
|
|
231
|
+
label: string;
|
|
232
|
+
}[]>;
|
|
233
|
+
export declare function saveAgentInstruction(db: Database, context: KnowledgeContext, input: AgentInstructionSaveRequest): Promise<{
|
|
234
|
+
operationId: string;
|
|
235
|
+
revisionId: string;
|
|
236
|
+
outcome: "pending" | "published" | "rejected";
|
|
237
|
+
reviewBatchId: string | null;
|
|
238
|
+
replayed: boolean;
|
|
239
|
+
}>;
|
|
240
|
+
export declare function getAgentInstruction(db: Database, context: KnowledgeContext, target: WorkspaceInstructionPolicyTarget): Promise<{
|
|
241
|
+
target: {
|
|
242
|
+
kind: "charter" | "policy";
|
|
243
|
+
scope: "global" | "role";
|
|
244
|
+
roleKey: string | null;
|
|
245
|
+
};
|
|
246
|
+
expectedCurrentRevisionId: string | null;
|
|
247
|
+
expectedActivationVersion: number;
|
|
248
|
+
content: string | null;
|
|
249
|
+
}>;
|
|
250
|
+
export declare function reviewAgentInstruction(db: Database, context: KnowledgeContext, input: AgentInstructionReviewRequest): Promise<{
|
|
251
|
+
operationId: string;
|
|
252
|
+
revisionId: string;
|
|
253
|
+
outcome: "pending" | "published" | "rejected";
|
|
254
|
+
reviewBatchId: string | null;
|
|
255
|
+
replayed: boolean;
|
|
256
|
+
}>;
|
|
257
|
+
export declare function listAgentInstructionReviews(db: Database, context: KnowledgeContext, cursor?: string): Promise<{
|
|
258
|
+
entries: {
|
|
259
|
+
revisionId: string;
|
|
260
|
+
content: string;
|
|
261
|
+
target: {
|
|
262
|
+
kind: "charter" | "policy";
|
|
263
|
+
scope: "global" | "role";
|
|
264
|
+
roleKey: string | null;
|
|
265
|
+
};
|
|
266
|
+
reviewBatchId: string | null;
|
|
267
|
+
sessionId: string | null;
|
|
268
|
+
reason: string;
|
|
269
|
+
createdAt: string;
|
|
270
|
+
}[];
|
|
271
|
+
nextCursor: string | null;
|
|
272
|
+
}>;
|
|
273
|
+
/** Host-only parser boundary. The file metadata is never returned by agent tools. */
|
|
274
|
+
export declare function inspectKnowledgeFilePreparation(db: Database, context: KnowledgeContext, fileId: string): Promise<{
|
|
275
|
+
status: "retained";
|
|
276
|
+
fileId: string;
|
|
277
|
+
filename: string;
|
|
278
|
+
receipt: {
|
|
279
|
+
operationId: string;
|
|
280
|
+
entryId: string;
|
|
281
|
+
revisionId: string;
|
|
282
|
+
version: number;
|
|
283
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
284
|
+
reviewBatchId: string | null;
|
|
285
|
+
replayed: boolean;
|
|
286
|
+
};
|
|
287
|
+
} | {
|
|
288
|
+
status: "disabled";
|
|
289
|
+
fileId: string;
|
|
290
|
+
} | {
|
|
291
|
+
status: "prepare";
|
|
292
|
+
file: {
|
|
293
|
+
scope?: "personal" | "workspace" | undefined;
|
|
294
|
+
id: string;
|
|
295
|
+
workspaceId: string;
|
|
296
|
+
status: "deleted" | "expired" | "failed" | "pending_upload" | "ready";
|
|
297
|
+
filename: string;
|
|
298
|
+
safeFilename: string;
|
|
299
|
+
contentType: string;
|
|
300
|
+
sizeBytes: number;
|
|
301
|
+
sha256: string | null;
|
|
302
|
+
bucket: string;
|
|
303
|
+
objectKey: string;
|
|
304
|
+
createdAt: string;
|
|
305
|
+
updatedAt: string;
|
|
306
|
+
};
|
|
307
|
+
}>;
|
|
308
|
+
/** Concurrent/recovered preparations converge on the first exact saved source. */
|
|
309
|
+
export declare function completeKnowledgeFilePreparation(db: Database, context: KnowledgeContext, input: {
|
|
310
|
+
fileId: string;
|
|
311
|
+
title: string;
|
|
312
|
+
content: string;
|
|
313
|
+
sourceVersion?: string;
|
|
314
|
+
}): Promise<{
|
|
315
|
+
status: "retained";
|
|
316
|
+
fileId: string;
|
|
317
|
+
filename: string;
|
|
318
|
+
receipt: {
|
|
319
|
+
operationId: string;
|
|
320
|
+
entryId: string;
|
|
321
|
+
revisionId: string;
|
|
322
|
+
version: number;
|
|
323
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
324
|
+
reviewBatchId: string | null;
|
|
325
|
+
replayed: boolean;
|
|
326
|
+
};
|
|
327
|
+
} | {
|
|
328
|
+
status: "disabled";
|
|
329
|
+
fileId: string;
|
|
330
|
+
}>;
|
|
331
|
+
export declare function knowledgeOriginalFileAsset(raw: Record<string, unknown>): FileAsset;
|
|
332
|
+
/** Exact entry visibility first; origin workspace metadata is not an access grant. */
|
|
333
|
+
export declare function getKnowledgeOriginalFile(db: Database, context: KnowledgeContext, entryId: string, revisionId?: string): Promise<{
|
|
334
|
+
scope?: "personal" | "workspace" | undefined;
|
|
335
|
+
id: string;
|
|
336
|
+
workspaceId: string;
|
|
337
|
+
status: "deleted" | "expired" | "failed" | "pending_upload" | "ready";
|
|
338
|
+
filename: string;
|
|
339
|
+
safeFilename: string;
|
|
340
|
+
contentType: string;
|
|
341
|
+
sizeBytes: number;
|
|
342
|
+
sha256: string | null;
|
|
343
|
+
bucket: string;
|
|
344
|
+
objectKey: string;
|
|
345
|
+
createdAt: string;
|
|
346
|
+
updatedAt: string;
|
|
347
|
+
} | null>;
|
|
348
|
+
/** Finish only a pre-cutover, human-answered remember confirmation. */
|
|
349
|
+
export declare function confirmLegacyKnowledge(db: Database, context: KnowledgeContext, request: {
|
|
350
|
+
operationId: string;
|
|
351
|
+
claimId: string;
|
|
352
|
+
humanInputRequestId: string;
|
|
353
|
+
}): Promise<{
|
|
354
|
+
operationId: string;
|
|
355
|
+
entryId: string;
|
|
356
|
+
revisionId: string;
|
|
357
|
+
version: number;
|
|
358
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
359
|
+
reviewBatchId: string | null;
|
|
360
|
+
replayed: boolean;
|
|
361
|
+
}>;
|
|
362
|
+
/** Compatibility only: finish an imported native instruction without rebaselining. */
|
|
363
|
+
export declare function confirmLegacyInstruction(db: Database, context: KnowledgeContext, request: {
|
|
364
|
+
operationId: string;
|
|
365
|
+
proposalId: string;
|
|
366
|
+
decisionReceiptId: string;
|
|
367
|
+
humanInputRequestId: string;
|
|
368
|
+
}): Promise<{
|
|
369
|
+
operationId: string;
|
|
370
|
+
revisionId: string;
|
|
371
|
+
outcome: "pending" | "published" | "rejected";
|
|
372
|
+
reviewBatchId: string | null;
|
|
373
|
+
replayed: boolean;
|
|
374
|
+
}>;
|
|
375
|
+
/** Protocol recovery runs before the model, including when the retired tool is no longer selected. */
|
|
376
|
+
export declare function recoverLegacyKnowledgeConfirmations(db: Database, context: KnowledgeContext): Promise<{
|
|
377
|
+
receipts: {
|
|
378
|
+
operationId: string;
|
|
379
|
+
entryId: string;
|
|
380
|
+
revisionId: string;
|
|
381
|
+
version: number;
|
|
382
|
+
outcome: "archived" | "pending" | "published" | "rejected";
|
|
383
|
+
reviewBatchId: string | null;
|
|
384
|
+
replayed: boolean;
|
|
385
|
+
}[];
|
|
386
|
+
instructionReceipts: {
|
|
387
|
+
operationId: string;
|
|
388
|
+
revisionId: string;
|
|
389
|
+
outcome: "pending" | "published" | "rejected";
|
|
390
|
+
reviewBatchId: string | null;
|
|
391
|
+
replayed: boolean;
|
|
392
|
+
}[];
|
|
393
|
+
unavailable: number;
|
|
394
|
+
}>;
|
|
395
|
+
/** Explicit content from this agent's bound source, including its own pending batch.
|
|
396
|
+
* Ambient retrieval continues to return published knowledge only. */
|
|
397
|
+
export declare function readScheduledKnowledgeSource(db: Database, context: KnowledgeContext, input: {
|
|
398
|
+
entryId?: string;
|
|
399
|
+
afterId?: string;
|
|
400
|
+
offset?: number;
|
|
401
|
+
}): Promise<{
|
|
402
|
+
items: ({
|
|
403
|
+
entryId: string;
|
|
404
|
+
revisionId: string;
|
|
405
|
+
content?: string | undefined;
|
|
406
|
+
codecVersion: number;
|
|
407
|
+
pending: boolean;
|
|
408
|
+
title: string;
|
|
409
|
+
} | {
|
|
410
|
+
entryId: string;
|
|
411
|
+
revisionId: string;
|
|
412
|
+
codecVersion: number;
|
|
413
|
+
pending: boolean;
|
|
414
|
+
title: string;
|
|
415
|
+
content: string;
|
|
416
|
+
offset: number;
|
|
417
|
+
totalCharacters: number;
|
|
418
|
+
nextOffset: number | null;
|
|
419
|
+
})[];
|
|
420
|
+
nextCursor: string | null;
|
|
421
|
+
}>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Database } from "./database.js";
|
|
3
|
+
declare const Claim: z.ZodObject<{
|
|
4
|
+
accountId: z.ZodUUID;
|
|
5
|
+
entryId: z.ZodUUID;
|
|
6
|
+
revisionId: z.ZodUUID;
|
|
7
|
+
leaseId: z.ZodUUID;
|
|
8
|
+
model: z.ZodString;
|
|
9
|
+
dimensions: z.ZodNumber;
|
|
10
|
+
generation: z.ZodNumber;
|
|
11
|
+
nextIndex: z.ZodNumber;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export type KnowledgeIndexClaim = z.infer<typeof Claim>;
|
|
14
|
+
/** Internal projection dispatcher. No HTTP, MCP or agent tool exposes this capability. */
|
|
15
|
+
export declare function claimKnowledgeIndexJobs(db: Database, input: {
|
|
16
|
+
model: string;
|
|
17
|
+
dimensions: number;
|
|
18
|
+
limit?: number;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
accountId: string;
|
|
21
|
+
entryId: string;
|
|
22
|
+
revisionId: string;
|
|
23
|
+
leaseId: string;
|
|
24
|
+
model: string;
|
|
25
|
+
dimensions: number;
|
|
26
|
+
generation: number;
|
|
27
|
+
nextIndex: number;
|
|
28
|
+
}[]>;
|
|
29
|
+
export declare function readKnowledgeIndexSource(db: Database, claim: KnowledgeIndexClaim): Promise<{
|
|
30
|
+
billingWorkspaceId: string;
|
|
31
|
+
entry: {
|
|
32
|
+
title: string;
|
|
33
|
+
kind: "decision" | "fact" | "group" | "incident" | "note" | "requirement" | "source";
|
|
34
|
+
content: string;
|
|
35
|
+
source?: {
|
|
36
|
+
kind: "connector" | "conversation" | "file" | "manual" | "repository" | "slack" | "task_note" | "web";
|
|
37
|
+
noteId?: string | undefined;
|
|
38
|
+
fileId?: string | undefined;
|
|
39
|
+
documentId?: string | undefined;
|
|
40
|
+
sessionId?: string | undefined;
|
|
41
|
+
uri?: string | undefined;
|
|
42
|
+
externalId?: string | undefined;
|
|
43
|
+
version?: string | undefined;
|
|
44
|
+
capturedAt?: string | undefined;
|
|
45
|
+
retention?: "full_text" | "passages" | "reference" | undefined;
|
|
46
|
+
} | undefined;
|
|
47
|
+
evidence: {
|
|
48
|
+
entryId: string;
|
|
49
|
+
revisionId: string;
|
|
50
|
+
location: {
|
|
51
|
+
page?: number | undefined;
|
|
52
|
+
passage?: string | undefined;
|
|
53
|
+
messageIds?: string[] | undefined;
|
|
54
|
+
path?: string | undefined;
|
|
55
|
+
commit?: string | undefined;
|
|
56
|
+
lineStart?: number | undefined;
|
|
57
|
+
lineEnd?: number | undefined;
|
|
58
|
+
};
|
|
59
|
+
quote?: string | undefined;
|
|
60
|
+
}[];
|
|
61
|
+
groupIds: string[];
|
|
62
|
+
relationships: {
|
|
63
|
+
entryId: string;
|
|
64
|
+
relation: "applies_to" | "conflicts_with" | "depends_on" | "related_to" | "supersedes";
|
|
65
|
+
}[];
|
|
66
|
+
};
|
|
67
|
+
nextIndex: number;
|
|
68
|
+
originWorkspaceId: string;
|
|
69
|
+
scope: "organization" | "personal" | "workspace";
|
|
70
|
+
} | null>;
|
|
71
|
+
export type KnowledgeIndexProjectionChunk = {
|
|
72
|
+
index: number;
|
|
73
|
+
field: "content" | "title";
|
|
74
|
+
start: number;
|
|
75
|
+
end: number;
|
|
76
|
+
text: string;
|
|
77
|
+
embedding: number[];
|
|
78
|
+
};
|
|
79
|
+
export declare function appendKnowledgeIndexChunks(db: Database, claim: KnowledgeIndexClaim, expectedNextIndex: number, chunks: KnowledgeIndexProjectionChunk[]): Promise<{
|
|
80
|
+
[x: string]: unknown;
|
|
81
|
+
status: "obsolete" | "pending" | "ready" | "running";
|
|
82
|
+
nextIndex?: number | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
export declare function completeKnowledgeIndexJob(db: Database, claim: KnowledgeIndexClaim, expectedNextIndex: number): Promise<{
|
|
85
|
+
[x: string]: unknown;
|
|
86
|
+
status: "obsolete" | "pending" | "ready" | "running";
|
|
87
|
+
nextIndex?: number | undefined;
|
|
88
|
+
}>;
|
|
89
|
+
export declare function deferKnowledgeIndexJob(db: Database, claim: KnowledgeIndexClaim): Promise<{
|
|
90
|
+
[x: string]: unknown;
|
|
91
|
+
status: "obsolete" | "pending" | "ready" | "running";
|
|
92
|
+
nextIndex?: number | undefined;
|
|
93
|
+
}>;
|
|
94
|
+
export declare function continueKnowledgeIndexJob(db: Database, claim: KnowledgeIndexClaim): Promise<{
|
|
95
|
+
[x: string]: unknown;
|
|
96
|
+
status: "obsolete" | "pending" | "ready" | "running";
|
|
97
|
+
nextIndex?: number | undefined;
|
|
98
|
+
}>;
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type postgres from "postgres";
|
|
2
|
+
/** Maintenance-only conversion. It is not a runtime fallback or a second writer. */
|
|
3
|
+
export declare const KNOWLEDGE_MIGRATION_MARKER = "-- opengeni:unified-knowledge-copy-v1";
|
|
4
|
+
export declare function knowledgeMigrationId(kind: string, id: string): string;
|
|
5
|
+
/** All source and destination FORCE-RLS windows are explicit in the SQL file. */
|
|
6
|
+
export declare function migrateRetainedKnowledge(tx: postgres.TransactionSql): Promise<void>;
|
|
@@ -20,9 +20,10 @@ import {
|
|
|
20
20
|
reapManagedAuthIsolatedSessions,
|
|
21
21
|
releaseManagedAuthActorMutationLease,
|
|
22
22
|
validateManagedAuthActorMutationLease
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
25
|
-
import "./chunk-
|
|
23
|
+
} from "./chunk-UOXWVP3T.js";
|
|
24
|
+
import "./chunk-WFU6PS54.js";
|
|
25
|
+
import "./chunk-5UUWZDAV.js";
|
|
26
|
+
import "./chunk-S2TZ3F4L.js";
|
|
26
27
|
import "./chunk-PZ5AY32C.js";
|
|
27
28
|
export {
|
|
28
29
|
ManagedAuthActorMutationInFlightError,
|
package/dist/mcp-operations.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
withRlsContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WFU6PS54.js";
|
|
4
|
+
import "./chunk-5UUWZDAV.js";
|
|
4
5
|
import {
|
|
5
6
|
LOSSLESS_CONTENT_CODEC_VERSION,
|
|
6
7
|
fromPostgresLosslessJson,
|
|
7
8
|
toPostgresLosslessJson
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-S2TZ3F4L.js";
|
|
9
10
|
import "./chunk-PZ5AY32C.js";
|
|
10
11
|
|
|
11
12
|
// src/mcp-operations.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mcp-operations.ts"],"sourcesContent":["import { AttemptToolResult } from \"@opengeni/contracts\";\nimport { sql } from \"drizzle-orm\";\nimport { type Database, withRlsContext } from \"./database\";\nimport {\n fromPostgresLosslessJson,\n toPostgresLosslessJson,\n LOSSLESS_CONTENT_CODEC_VERSION,\n} from \"./lossless-json\";\n\n/** Worker-authenticated invocation identity, never model/HTTP/request JSON.\n * Possessing a DB handle or matching GUCs does NOT authenticate a caller.\n * Bind this tuple only after verifying the worker invocation credential. SQL\n * then derives the principal and rechecks canonical live disclosure authority. */\nexport type McpOperationAttempt = {\n accountId: string;\n workspaceId: string;\n sessionId: string;\n turnId: string;\n attemptId: string;\n executionGeneration: number;\n};\n\n/** Structurally aligned with runtime CapturedMcpOperation, without a runtime dependency. */\nexport type CaptureMcpOperationInput = {\n operationId: string;\n sourceCallId?: string;\n serverId: string;\n originalTool: string;\n observerTool: string;\n destinationDigest: string;\n argumentDigest: string;\n authorityDigest: string;\n};\nexport type McpOperationSelector =\n | { operationId: string }\n | { sourceTurnId: string; sourceCallId: string };\nexport type McpOperationRecord = Omit<CaptureMcpOperationInput, \"sourceCallId\"> & {\n sourceCallId: string | null;\n accountId: string;\n workspaceId: string;\n sessionId: string;\n sourceTurnId: string;\n sourceAttemptId: string;\n sourceExecutionGeneration: number;\n principalKind: \"subject\" | \"service\";\n principalId: string;\n /** captured means possibly dispatched, NEVER permission to replay a mutation. */\n originalOutcome: \"captured\" | \"completed\" | \"outcome_unknown\";\n originalResult: AttemptToolResult | null;\n observationResult: AttemptToolResult | null;\n receiptRevision: string | null;\n receiptDigest: string | null;\n};\nexport type McpOperationLookup =\n | { status: \"found\"; operation: McpOperationRecord }\n | { status: \"not_found\" | \"ambiguous\" };\n\nasync function command<T>(\n db: Database,\n attempt: McpOperationAttempt,\n action: string,\n payload: object,\n): Promise<T> {\n return withRlsContext(\n db,\n { accountId: attempt.accountId, workspaceId: attempt.workspaceId },\n async (tx) => {\n const result =\n await tx.execute(sql`select mcp_operation_command(${JSON.stringify(attempt)}::jsonb,\n ${action}::text, ${JSON.stringify(payload)}::jsonb) as value`);\n const rows = Array.isArray(result) ? result : result.rows;\n if (!rows?.[0]) throw new Error(\"MCP operation command returned no receipt\");\n return rows[0].value as T;\n },\n undefined,\n \"none\", // SQL owns membership -> tenancy -> control -> session lock order.\n );\n}\n\nexport function captureMcpOperation(\n db: Database,\n attempt: McpOperationAttempt,\n operation: CaptureMcpOperationInput,\n) {\n return command<\"created\" | \"existing\">(db, attempt, \"capture\", operation);\n}\nexport async function settleOriginalMcpOperation(\n db: Database,\n attempt: McpOperationAttempt,\n input:\n | { operationId: string; outcome: \"completed\"; result: AttemptToolResult }\n | { operationId: string; outcome: \"outcome_unknown\" },\n): Promise<void> {\n const payload =\n input.outcome === \"completed\"\n ? {\n ...input,\n result: toPostgresLosslessJson(AttemptToolResult.parse(input.result)),\n resultCodecVersion: LOSSLESS_CONTENT_CODEC_VERSION,\n }\n : input;\n const result = await command<{ status: string }>(db, attempt, \"settle_original\", payload);\n if (result.status !== \"settled\") throw new Error(\"Original MCP operation not found\");\n}\nexport async function readMcpOperation(\n db: Database,\n attempt: McpOperationAttempt,\n selector: McpOperationSelector,\n): Promise<McpOperationLookup> {\n const result = await command<McpOperationLookup>(db, attempt, \"read\", selector);\n if (result.status !== \"found\") return result;\n const { originalResultCodecVersion, observationResultCodecVersion, ...operation } =\n result.operation as McpOperationRecord & {\n originalResultCodecVersion: number | null;\n observationResultCodecVersion: number | null;\n };\n return {\n status: \"found\",\n operation: {\n ...operation,\n originalResult: fromPostgresLosslessJson(\n operation.originalResult,\n originalResultCodecVersion,\n ),\n observationResult: fromPostgresLosslessJson(\n operation.observationResult,\n observationResultCodecVersion,\n ),\n },\n };\n}\n/** Claims authorize only the read observer; expiry never authorizes a mutation. */\nexport function claimMcpOperationObservation(\n db: Database,\n attempt: McpOperationAttempt,\n operationId: string,\n) {\n return command<\n { status: \"claimed\"; claimId: string } | { status: \"busy\" | \"terminal\" | \"not_found\" }\n >(db, attempt, \"claim_read\", { operationId });\n}\nexport function settleMcpOperationObservation(\n db: Database,\n attempt: McpOperationAttempt,\n input: {\n operationId: string;\n claimId: string;\n receiptRevision: string;\n result: AttemptToolResult;\n },\n) {\n // This atomically stores one receipt, not an autonomous session notification.\n // Explicit operation_read is a new ordinary tool call: its existing result\n // lifecycle delivers the evidence. Repeated explicit reads legitimately have\n // distinct call outputs while the original timeout and receipt stay immutable.\n return command<\n | { status: \"settled\" | \"existing\" | \"conflict\"; receiptDigest: string }\n | { status: \"stale_claim\" | \"not_found\" | \"original_completed\" }\n >(db, attempt, \"settle_observation\", {\n ...input,\n result: toPostgresLosslessJson(AttemptToolResult.parse(input.result)),\n resultCodecVersion: LOSSLESS_CONTENT_CODEC_VERSION,\n });\n}\n\n/** Unknown/pending/error cleanup only; never releases or replaces a receipt. */\nexport function releaseMcpOperationObservation(\n db: Database,\n attempt: McpOperationAttempt,\n input: { operationId: string; claimId: string },\n) {\n return command<{ status: \"released\" | \"stale_claim\" | \"terminal\" | \"not_found\" }>(\n db,\n attempt,\n \"release_read\",\n input,\n );\n}\n\n/** Bind only inside the trusted worker, after exact invocation authentication.\n * Provider authorization and immutable binding fences remain the broker's job. */\nexport function createMcpOperationPersistence(db: Database, attempt: McpOperationAttempt) {\n const frozen = { ...attempt };\n return {\n capture: (operation: CaptureMcpOperationInput) => captureMcpOperation(db, frozen, operation),\n settleOriginal: (input: Parameters<typeof settleOriginalMcpOperation>[2]) =>\n settleOriginalMcpOperation(db, frozen, input),\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/mcp-operations.ts"],"sourcesContent":["import { AttemptToolResult } from \"@opengeni/contracts\";\nimport { sql } from \"drizzle-orm\";\nimport { type Database, withRlsContext } from \"./database\";\nimport {\n fromPostgresLosslessJson,\n toPostgresLosslessJson,\n LOSSLESS_CONTENT_CODEC_VERSION,\n} from \"./lossless-json\";\n\n/** Worker-authenticated invocation identity, never model/HTTP/request JSON.\n * Possessing a DB handle or matching GUCs does NOT authenticate a caller.\n * Bind this tuple only after verifying the worker invocation credential. SQL\n * then derives the principal and rechecks canonical live disclosure authority. */\nexport type McpOperationAttempt = {\n accountId: string;\n workspaceId: string;\n sessionId: string;\n turnId: string;\n attemptId: string;\n executionGeneration: number;\n};\n\n/** Structurally aligned with runtime CapturedMcpOperation, without a runtime dependency. */\nexport type CaptureMcpOperationInput = {\n operationId: string;\n sourceCallId?: string;\n serverId: string;\n originalTool: string;\n observerTool: string;\n destinationDigest: string;\n argumentDigest: string;\n authorityDigest: string;\n};\nexport type McpOperationSelector =\n | { operationId: string }\n | { sourceTurnId: string; sourceCallId: string };\nexport type McpOperationRecord = Omit<CaptureMcpOperationInput, \"sourceCallId\"> & {\n sourceCallId: string | null;\n accountId: string;\n workspaceId: string;\n sessionId: string;\n sourceTurnId: string;\n sourceAttemptId: string;\n sourceExecutionGeneration: number;\n principalKind: \"subject\" | \"service\";\n principalId: string;\n /** captured means possibly dispatched, NEVER permission to replay a mutation. */\n originalOutcome: \"captured\" | \"completed\" | \"outcome_unknown\";\n originalResult: AttemptToolResult | null;\n observationResult: AttemptToolResult | null;\n receiptRevision: string | null;\n receiptDigest: string | null;\n};\nexport type McpOperationLookup =\n | { status: \"found\"; operation: McpOperationRecord }\n | { status: \"not_found\" | \"ambiguous\" };\n\nasync function command<T>(\n db: Database,\n attempt: McpOperationAttempt,\n action: string,\n payload: object,\n): Promise<T> {\n return withRlsContext(\n db,\n { accountId: attempt.accountId, workspaceId: attempt.workspaceId },\n async (tx) => {\n const result =\n await tx.execute(sql`select mcp_operation_command(${JSON.stringify(attempt)}::jsonb,\n ${action}::text, ${JSON.stringify(payload)}::jsonb) as value`);\n const rows = Array.isArray(result) ? result : result.rows;\n if (!rows?.[0]) throw new Error(\"MCP operation command returned no receipt\");\n return rows[0].value as T;\n },\n undefined,\n \"none\", // SQL owns membership -> tenancy -> control -> session lock order.\n );\n}\n\nexport function captureMcpOperation(\n db: Database,\n attempt: McpOperationAttempt,\n operation: CaptureMcpOperationInput,\n) {\n return command<\"created\" | \"existing\">(db, attempt, \"capture\", operation);\n}\nexport async function settleOriginalMcpOperation(\n db: Database,\n attempt: McpOperationAttempt,\n input:\n | { operationId: string; outcome: \"completed\"; result: AttemptToolResult }\n | { operationId: string; outcome: \"outcome_unknown\" },\n): Promise<void> {\n const payload =\n input.outcome === \"completed\"\n ? {\n ...input,\n result: toPostgresLosslessJson(AttemptToolResult.parse(input.result)),\n resultCodecVersion: LOSSLESS_CONTENT_CODEC_VERSION,\n }\n : input;\n const result = await command<{ status: string }>(db, attempt, \"settle_original\", payload);\n if (result.status !== \"settled\") throw new Error(\"Original MCP operation not found\");\n}\nexport async function readMcpOperation(\n db: Database,\n attempt: McpOperationAttempt,\n selector: McpOperationSelector,\n): Promise<McpOperationLookup> {\n const result = await command<McpOperationLookup>(db, attempt, \"read\", selector);\n if (result.status !== \"found\") return result;\n const { originalResultCodecVersion, observationResultCodecVersion, ...operation } =\n result.operation as McpOperationRecord & {\n originalResultCodecVersion: number | null;\n observationResultCodecVersion: number | null;\n };\n return {\n status: \"found\",\n operation: {\n ...operation,\n originalResult: fromPostgresLosslessJson(\n operation.originalResult,\n originalResultCodecVersion,\n ),\n observationResult: fromPostgresLosslessJson(\n operation.observationResult,\n observationResultCodecVersion,\n ),\n },\n };\n}\n/** Claims authorize only the read observer; expiry never authorizes a mutation. */\nexport function claimMcpOperationObservation(\n db: Database,\n attempt: McpOperationAttempt,\n operationId: string,\n) {\n return command<\n { status: \"claimed\"; claimId: string } | { status: \"busy\" | \"terminal\" | \"not_found\" }\n >(db, attempt, \"claim_read\", { operationId });\n}\nexport function settleMcpOperationObservation(\n db: Database,\n attempt: McpOperationAttempt,\n input: {\n operationId: string;\n claimId: string;\n receiptRevision: string;\n result: AttemptToolResult;\n },\n) {\n // This atomically stores one receipt, not an autonomous session notification.\n // Explicit operation_read is a new ordinary tool call: its existing result\n // lifecycle delivers the evidence. Repeated explicit reads legitimately have\n // distinct call outputs while the original timeout and receipt stay immutable.\n return command<\n | { status: \"settled\" | \"existing\" | \"conflict\"; receiptDigest: string }\n | { status: \"stale_claim\" | \"not_found\" | \"original_completed\" }\n >(db, attempt, \"settle_observation\", {\n ...input,\n result: toPostgresLosslessJson(AttemptToolResult.parse(input.result)),\n resultCodecVersion: LOSSLESS_CONTENT_CODEC_VERSION,\n });\n}\n\n/** Unknown/pending/error cleanup only; never releases or replaces a receipt. */\nexport function releaseMcpOperationObservation(\n db: Database,\n attempt: McpOperationAttempt,\n input: { operationId: string; claimId: string },\n) {\n return command<{ status: \"released\" | \"stale_claim\" | \"terminal\" | \"not_found\" }>(\n db,\n attempt,\n \"release_read\",\n input,\n );\n}\n\n/** Bind only inside the trusted worker, after exact invocation authentication.\n * Provider authorization and immutable binding fences remain the broker's job. */\nexport function createMcpOperationPersistence(db: Database, attempt: McpOperationAttempt) {\n const frozen = { ...attempt };\n return {\n capture: (operation: CaptureMcpOperationInput) => captureMcpOperation(db, frozen, operation),\n settleOriginal: (input: Parameters<typeof settleOriginalMcpOperation>[2]) =>\n settleOriginalMcpOperation(db, frozen, input),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,yBAAyB;AAClC,SAAS,WAAW;AAwDpB,eAAe,QACb,IACA,SACA,QACA,SACY;AACZ,SAAO;AAAA,IACL;AAAA,IACA,EAAE,WAAW,QAAQ,WAAW,aAAa,QAAQ,YAAY;AAAA,IACjE,OAAO,OAAO;AACZ,YAAM,SACJ,MAAM,GAAG,QAAQ,mCAAmC,KAAK,UAAU,OAAO,CAAC;AAAA,QAC3E,MAAM,WAAW,KAAK,UAAU,OAAO,CAAC,mBAAmB;AAC7D,YAAM,OAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,OAAO;AACrD,UAAI,CAAC,OAAO,CAAC,EAAG,OAAM,IAAI,MAAM,2CAA2C;AAC3E,aAAO,KAAK,CAAC,EAAE;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EACF;AACF;AAEO,SAAS,oBACd,IACA,SACA,WACA;AACA,SAAO,QAAgC,IAAI,SAAS,WAAW,SAAS;AAC1E;AACA,eAAsB,2BACpB,IACA,SACA,OAGe;AACf,QAAM,UACJ,MAAM,YAAY,cACd;AAAA,IACE,GAAG;AAAA,IACH,QAAQ,uBAAuB,kBAAkB,MAAM,MAAM,MAAM,CAAC;AAAA,IACpE,oBAAoB;AAAA,EACtB,IACA;AACN,QAAM,SAAS,MAAM,QAA4B,IAAI,SAAS,mBAAmB,OAAO;AACxF,MAAI,OAAO,WAAW,UAAW,OAAM,IAAI,MAAM,kCAAkC;AACrF;AACA,eAAsB,iBACpB,IACA,SACA,UAC6B;AAC7B,QAAM,SAAS,MAAM,QAA4B,IAAI,SAAS,QAAQ,QAAQ;AAC9E,MAAI,OAAO,WAAW,QAAS,QAAO;AACtC,QAAM,EAAE,4BAA4B,+BAA+B,GAAG,UAAU,IAC9E,OAAO;AAIT,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,WAAW;AAAA,MACT,GAAG;AAAA,MACH,gBAAgB;AAAA,QACd,UAAU;AAAA,QACV;AAAA,MACF;AAAA,MACA,mBAAmB;AAAA,QACjB,UAAU;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,6BACd,IACA,SACA,aACA;AACA,SAAO,QAEL,IAAI,SAAS,cAAc,EAAE,YAAY,CAAC;AAC9C;AACO,SAAS,8BACd,IACA,SACA,OAMA;AAKA,SAAO,QAGL,IAAI,SAAS,sBAAsB;AAAA,IACnC,GAAG;AAAA,IACH,QAAQ,uBAAuB,kBAAkB,MAAM,MAAM,MAAM,CAAC;AAAA,IACpE,oBAAoB;AAAA,EACtB,CAAC;AACH;AAGO,SAAS,+BACd,IACA,SACA,OACA;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAIO,SAAS,8BAA8B,IAAc,SAA8B;AACxF,QAAM,SAAS,EAAE,GAAG,QAAQ;AAC5B,SAAO;AAAA,IACL,SAAS,CAAC,cAAwC,oBAAoB,IAAI,QAAQ,SAAS;AAAA,IAC3F,gBAAgB,CAAC,UACf,2BAA2B,IAAI,QAAQ,KAAK;AAAA,EAChD;AACF;","names":[]}
|
package/dist/migrate.js
CHANGED
package/dist/provision-roles.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
withRlsContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WFU6PS54.js";
|
|
4
4
|
import {
|
|
5
5
|
sandboxRetainedProcesses
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5UUWZDAV.js";
|
|
7
|
+
import "./chunk-S2TZ3F4L.js";
|
|
7
8
|
import "./chunk-PZ5AY32C.js";
|
|
8
9
|
|
|
9
10
|
// src/retained-provider-commands.ts
|