@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,126 @@
|
|
|
1
|
+
import { namedSubjectPersonalWorkspaceId } from "./slack-routing-personal-workspace";
|
|
2
|
+
import { sql } from "drizzle-orm";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { StoredKnowledgeEntryContent } from "@opengeni/contracts";
|
|
5
|
+
import { rawRows, withRlsContext, type Database } from "./database";
|
|
6
|
+
import { fromPostgresLosslessJson, toPostgresLosslessText } from "./lossless-json";
|
|
7
|
+
|
|
8
|
+
const Claim = z.object({
|
|
9
|
+
accountId: z.uuid(),
|
|
10
|
+
entryId: z.uuid(),
|
|
11
|
+
revisionId: z.uuid(),
|
|
12
|
+
leaseId: z.uuid(),
|
|
13
|
+
model: z.string().min(1).max(512),
|
|
14
|
+
dimensions: z.number().int().min(1).max(4096),
|
|
15
|
+
generation: z.number().int().positive(),
|
|
16
|
+
nextIndex: z.number().int().nonnegative(),
|
|
17
|
+
});
|
|
18
|
+
export type KnowledgeIndexClaim = z.infer<typeof Claim>;
|
|
19
|
+
|
|
20
|
+
/** Internal projection dispatcher. No HTTP, MCP or agent tool exposes this capability. */
|
|
21
|
+
export async function claimKnowledgeIndexJobs(
|
|
22
|
+
db: Database,
|
|
23
|
+
input: { model: string; dimensions: number; limit?: number },
|
|
24
|
+
) {
|
|
25
|
+
const request = z
|
|
26
|
+
.object({
|
|
27
|
+
model: Claim.shape.model,
|
|
28
|
+
dimensions: Claim.shape.dimensions,
|
|
29
|
+
limit: z.number().int().min(1).max(20).default(5),
|
|
30
|
+
})
|
|
31
|
+
.parse(input);
|
|
32
|
+
const [row] = await rawRows<{ claims: unknown }>(
|
|
33
|
+
db,
|
|
34
|
+
sql`SELECT knowledge_index_claim(${request.model},${request.dimensions},${request.limit}) AS claims`,
|
|
35
|
+
);
|
|
36
|
+
return z.array(Claim).parse(row?.claims);
|
|
37
|
+
}
|
|
38
|
+
async function work(db: Database, raw: KnowledgeIndexClaim, request: Record<string, unknown>) {
|
|
39
|
+
const claim = Claim.parse(raw);
|
|
40
|
+
return withRlsContext(db, { accountId: claim.accountId }, async (tx) => {
|
|
41
|
+
const [row] = await rawRows<{ result: unknown }>(
|
|
42
|
+
tx,
|
|
43
|
+
sql`SELECT knowledge_index_work(${claim.accountId}::uuid,
|
|
44
|
+
${claim.revisionId}::uuid,${claim.leaseId}::uuid,${JSON.stringify(request)}::jsonb) AS result`,
|
|
45
|
+
);
|
|
46
|
+
return z
|
|
47
|
+
.object({
|
|
48
|
+
status: z.enum(["running", "pending", "obsolete", "ready"]),
|
|
49
|
+
nextIndex: z.number().int().optional(),
|
|
50
|
+
})
|
|
51
|
+
.passthrough()
|
|
52
|
+
.parse(row?.result);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export async function readKnowledgeIndexSource(db: Database, claim: KnowledgeIndexClaim) {
|
|
56
|
+
const result = await work(db, claim, { operation: "read" });
|
|
57
|
+
if (result.status !== "running") return null;
|
|
58
|
+
const scope = z.enum(["workspace", "personal", "organization"]).parse(result.scope);
|
|
59
|
+
const subjectId = z.string().nullable().parse(result.subjectId);
|
|
60
|
+
const originWorkspaceId = z.uuid().parse(result.originWorkspaceId);
|
|
61
|
+
// The lease authorizes this lookup for accounting only. Its canonical owner
|
|
62
|
+
// tuple is not an authenticated human, access grant, or publication authority.
|
|
63
|
+
// Personal retained content survives deletion of its originating workspace.
|
|
64
|
+
const billingWorkspaceId =
|
|
65
|
+
scope === "personal" && subjectId
|
|
66
|
+
? ((await namedSubjectPersonalWorkspaceId(db, { accountId: claim.accountId, subjectId })) ??
|
|
67
|
+
originWorkspaceId)
|
|
68
|
+
: originWorkspaceId;
|
|
69
|
+
return {
|
|
70
|
+
billingWorkspaceId,
|
|
71
|
+
entry: StoredKnowledgeEntryContent.parse(
|
|
72
|
+
fromPostgresLosslessJson(result.body, result.codecVersion as number | null),
|
|
73
|
+
),
|
|
74
|
+
nextIndex: z.number().int().nonnegative().parse(result.nextIndex),
|
|
75
|
+
originWorkspaceId: z.uuid().parse(result.originWorkspaceId),
|
|
76
|
+
scope: z.enum(["workspace", "personal", "organization"]).parse(result.scope),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export type KnowledgeIndexProjectionChunk = {
|
|
80
|
+
index: number;
|
|
81
|
+
field: "content" | "title";
|
|
82
|
+
start: number;
|
|
83
|
+
end: number;
|
|
84
|
+
text: string;
|
|
85
|
+
embedding: number[];
|
|
86
|
+
};
|
|
87
|
+
export async function appendKnowledgeIndexChunks(
|
|
88
|
+
db: Database,
|
|
89
|
+
claim: KnowledgeIndexClaim,
|
|
90
|
+
expectedNextIndex: number,
|
|
91
|
+
chunks: KnowledgeIndexProjectionChunk[],
|
|
92
|
+
) {
|
|
93
|
+
const input = z
|
|
94
|
+
.array(
|
|
95
|
+
z.object({
|
|
96
|
+
index: z.number().int().nonnegative(),
|
|
97
|
+
field: z.enum(["content", "title"]),
|
|
98
|
+
start: z.number().int().nonnegative(),
|
|
99
|
+
end: z.number().int().nonnegative(),
|
|
100
|
+
text: z.string(),
|
|
101
|
+
embedding: z.array(z.number().finite()).length(claim.dimensions),
|
|
102
|
+
}),
|
|
103
|
+
)
|
|
104
|
+
.min(1)
|
|
105
|
+
.max(64)
|
|
106
|
+
.parse(chunks);
|
|
107
|
+
return work(db, claim, {
|
|
108
|
+
operation: "append",
|
|
109
|
+
expectedNextIndex,
|
|
110
|
+
chunks: input.map((chunk) => ({ ...chunk, text: toPostgresLosslessText(chunk.text) })),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
export async function completeKnowledgeIndexJob(
|
|
114
|
+
db: Database,
|
|
115
|
+
claim: KnowledgeIndexClaim,
|
|
116
|
+
expectedNextIndex: number,
|
|
117
|
+
) {
|
|
118
|
+
return work(db, claim, { operation: "complete", expectedNextIndex });
|
|
119
|
+
}
|
|
120
|
+
export async function deferKnowledgeIndexJob(db: Database, claim: KnowledgeIndexClaim) {
|
|
121
|
+
return work(db, claim, { operation: "fail" });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function continueKnowledgeIndexJob(db: Database, claim: KnowledgeIndexClaim) {
|
|
125
|
+
return work(db, claim, { operation: "continue" });
|
|
126
|
+
}
|