@opengeni/db 5.0.1 → 6.0.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/automations.d.ts +0 -2
- package/dist/canonical-human-identities.d.ts +4 -0
- package/dist/canonical-human-identities.js +3 -3
- package/dist/capability-components.d.ts +5 -13
- package/dist/capability-integrations.d.ts +23 -8
- package/dist/capability-reconciliation.d.ts +5 -0
- package/dist/capability-reconciliation.js +21 -0
- package/dist/capability-reconciliation.js.map +1 -0
- package/dist/{chunk-6T2GGYWE.js → chunk-4UJCXBR2.js} +4 -5800
- package/dist/chunk-4UJCXBR2.js.map +1 -0
- package/dist/{chunk-MWMXWHJD.js → chunk-7JCDSMX2.js} +2 -2
- package/dist/chunk-AJA2ZIUW.js +219 -0
- package/dist/chunk-AJA2ZIUW.js.map +1 -0
- package/dist/chunk-CDAT6EKW.js +247 -0
- package/dist/chunk-CDAT6EKW.js.map +1 -0
- package/dist/{chunk-DPONPYJD.js → chunk-CJI6G254.js} +70 -18
- package/dist/chunk-CJI6G254.js.map +1 -0
- package/dist/chunk-G32NVMRJ.js +276 -0
- package/dist/chunk-G32NVMRJ.js.map +1 -0
- package/dist/chunk-GABXCG3N.js +5811 -0
- package/dist/chunk-GABXCG3N.js.map +1 -0
- package/dist/{chunk-ERKVSPDX.js → chunk-LVY33EWL.js} +3 -3
- package/dist/{chunk-45CP2YKY.js → chunk-MAMBI2HR.js} +9 -3
- package/dist/{chunk-45CP2YKY.js.map → chunk-MAMBI2HR.js.map} +1 -1
- package/dist/{chunk-F73UKJY6.js → chunk-MN5PZMEK.js} +91 -108
- package/dist/chunk-MN5PZMEK.js.map +1 -0
- package/dist/chunk-PJI4MUZ7.js +131 -0
- package/dist/chunk-PJI4MUZ7.js.map +1 -0
- package/dist/{chunk-T6BWIGWJ.js → chunk-RIYHP2WU.js} +2 -2
- package/dist/{chunk-7HMK3B45.js → chunk-RL2MUXM3.js} +16 -7
- package/dist/chunk-RL2MUXM3.js.map +1 -0
- package/dist/{chunk-HQDVI2DB.js → chunk-SYKHLPTK.js} +4 -3
- package/dist/{chunk-HQDVI2DB.js.map → chunk-SYKHLPTK.js.map} +1 -1
- package/dist/{chunk-T6YLHJLS.js → chunk-XIXVVBW2.js} +198 -51
- package/dist/chunk-XIXVVBW2.js.map +1 -0
- package/dist/chunk-ZPJ6V2VG.js +156 -0
- package/dist/chunk-ZPJ6V2VG.js.map +1 -0
- package/dist/codex-capacity-recovery.d.ts +12 -0
- package/dist/codex-failure-eligibility.d.ts +9 -0
- package/dist/company-profile-schema.d.ts +4 -2
- package/dist/connect-attempts.d.ts +15 -0
- package/dist/connect-attempts.js +25 -0
- package/dist/connect-attempts.js.map +1 -0
- package/dist/connection-authority.d.ts +7 -63
- package/dist/connection-refresh-lock.d.ts +4 -0
- package/dist/connection-token-resolver.d.ts +8 -43
- package/dist/database-timing.d.ts +10 -0
- package/dist/database.d.ts +4 -0
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.d.ts +9 -0
- package/dist/editable-artifacts.js +7 -5
- package/dist/index.d.ts +447 -78
- package/dist/index.js +12705 -12872
- package/dist/index.js.map +1 -1
- package/dist/insights-usage-bundle.d.ts +3 -0
- package/dist/integration-bindings.d.ts +1 -1
- package/dist/integration-facets.d.ts +18 -1
- package/dist/knowledge-entries-schema.d.ts +2 -0
- package/dist/knowledge-entries.d.ts +1 -0
- package/dist/knowledge-indexing.d.ts +1 -0
- package/dist/live-session-attempt.d.ts +35 -137
- package/dist/managed-auth-session-sets.js +3 -3
- package/dist/mcp-account-bindings.d.ts +4 -0
- package/dist/mcp-oauth.d.ts +11 -0
- package/dist/mcp-operations.js +2 -2
- package/dist/migrate.js +1 -1
- package/dist/organization-integration-policy.d.ts +51 -0
- package/dist/organization-integration-policy.js +18 -0
- package/dist/organization-integration-policy.js.map +1 -0
- package/dist/organization-usage.d.ts +20 -0
- package/dist/plugin-packages.d.ts +9 -12
- package/dist/pr-review.d.ts +0 -11
- package/dist/preference-registry-schema.d.ts +17 -0
- package/dist/provision-roles.js +1 -1
- package/dist/retained-provider-commands.d.ts +124 -6
- package/dist/retained-provider-commands.js +29 -97
- package/dist/retained-provider-commands.js.map +1 -1
- package/dist/retired-session-create-metadata.d.ts +4 -0
- package/dist/runtime-posture.d.ts +7 -5
- package/dist/schema.d.ts +876 -656
- package/dist/schema.js +5 -7
- package/dist/session-admission-block.d.ts +32 -0
- package/dist/session-attempt-writers.d.ts +4 -0
- package/dist/session-background-commands.js +5 -4
- package/dist/session-command-output.js +8 -126
- package/dist/session-command-output.js.map +1 -1
- package/dist/session-control.d.ts +5 -1
- package/dist/session-event-slices.d.ts +10 -0
- package/dist/session-event-slices.js +8 -222
- package/dist/session-event-slices.js.map +1 -1
- package/dist/session-file-attachments.d.ts +28 -0
- package/dist/session-goal-reports.d.ts +43 -0
- package/dist/session-mcp-approval.d.ts +4 -0
- package/dist/session-mcp-credential-rotation.js +5 -4
- package/dist/session-mcp-credential-rotation.js.map +1 -1
- package/dist/session-message-search.d.ts +22 -0
- package/dist/session-queue-commands.d.ts +2 -6
- package/dist/session-retry.d.ts +36 -0
- package/dist/session-tenancy.js +3 -3
- package/dist/skill-source-release-impact.d.ts +18 -0
- package/dist/skill-source-release.d.ts +9 -0
- package/dist/skills.d.ts +7 -1
- package/dist/user-resource-authority.d.ts +0 -8
- package/dist/video-generation.js +3 -3
- package/dist/workspace-tool-defaults.js +5 -4
- package/dist/workspace-tool-defaults.js.map +1 -1
- package/drizzle/0468_knowledge_relationship_projection.sql +30 -0
- package/drizzle/0469_knowledge_source_discovery.sql +85 -0
- package/drizzle/0470_organization_integration_policy.sql +151 -0
- package/drizzle/0471_usage_events_account_recent_index.sql +4 -0
- package/drizzle/0472_usage_events_workspace_recent_index.sql +4 -0
- package/drizzle/0473_organization_usage_analytical_capability.sql +237 -0
- package/drizzle/0474_goal_report_requirements.sql +156 -0
- package/drizzle/0475_session_event_history_statistics.sql +15 -0
- package/drizzle/0476_session_event_history_policy_planning.sql +29 -0
- package/drizzle/0477_managed_sign_in_methods.sql +303 -0
- package/drizzle/0478_sender_owned_connections.sql +2772 -0
- package/drizzle/0479_connection_create_idempotency.sql +16 -0
- package/drizzle/0480_private_session_organization_key_administration.sql +154 -0
- package/drizzle/0481_personal_connection_visibility_cleanup.sql +45 -0
- package/drizzle/0482_remove_packs.sql +417 -0
- package/drizzle/0483_preclaim_admission_block.sql +85 -0
- package/drizzle/0484_insights_usage_projection.sql +211 -0
- package/drizzle/0485_inherited_mcp_approval_policies.sql +6 -0
- package/drizzle/0486_reasoning_configuration_message_forks.sql +35 -0
- package/drizzle/0487_skill_catalog_message_forks.sql +26 -0
- package/drizzle/0488_permanent_skill_removal.sql +207 -0
- package/drizzle/0489_modal_command_byte_offsets.sql +17 -0
- package/drizzle/0490_periodic_capture_attempt_cadence.sql +6 -0
- package/drizzle/0491_warm_capture_holder_reclamation.sql +57 -0
- package/drizzle/0492_codex_accepted_source_authority.sql +249 -0
- package/drizzle/0493_stopping_command_error_containment.sql +58 -0
- package/drizzle/0494_mcp_account_bindings.sql +334 -0
- package/drizzle/0495_consented_sandbox_recovery.sql +220 -0
- package/drizzle/0496_supervised_command_settlement.sql +386 -0
- package/drizzle/0497_modal_inventory_owner_read_capability.sql +112 -0
- package/drizzle/0498_enrollment_membership_fence.sql +87 -0
- package/drizzle/0499_session_attachment_access.sql +224 -0
- package/drizzle/0500_session_execution_epoch.sql +37 -0
- package/drizzle/0501_session_sharing_execution.sql +591 -0
- package/drizzle/0502_active_message_boundary_forks.sql +30 -0
- package/package.json +17 -5
- package/src/automations.ts +17 -73
- package/src/canonical-human-identities.ts +17 -5
- package/src/capability-components.ts +7 -24
- package/src/capability-integrations.ts +301 -21
- package/src/capability-reconciliation.ts +19 -0
- package/src/codex-capacity-recovery.ts +47 -0
- package/src/codex-failure-eligibility.ts +93 -0
- package/src/connect-attempts.ts +49 -18
- package/src/connection-authority.ts +12 -158
- package/src/connection-refresh-lock.ts +22 -0
- package/src/connection-token-resolver.ts +58 -530
- package/src/database-timing.ts +43 -0
- package/src/database.ts +61 -26
- package/src/editable-artifacts.ts +1 -1
- package/src/index.ts +3578 -1273
- package/src/insights-model-bundle.ts +19 -7
- package/src/insights-usage-bundle.ts +16 -19
- package/src/integration-bindings.ts +2 -7
- package/src/integration-facets.ts +73 -6
- package/src/knowledge-entries.ts +8 -1
- package/src/live-session-attempt.ts +0 -22
- package/src/mcp-account-bindings.ts +12 -0
- package/src/mcp-oauth.ts +26 -0
- package/src/organization-integration-policy.ts +235 -0
- package/src/organization-usage.ts +83 -0
- package/src/plugin-packages.ts +226 -42
- package/src/pr-review.ts +7 -69
- package/src/preference-registry-schema.ts +1 -0
- package/src/provision-roles.ts +50 -37
- package/src/retained-provider-commands.ts +286 -9
- package/src/retired-session-create-metadata.ts +16 -0
- package/src/runtime-posture.ts +217 -13
- package/src/schema.ts +104 -120
- package/src/session-admission-block.ts +29 -0
- package/src/session-attempt-writers.ts +48 -0
- package/src/session-control.ts +21 -5
- package/src/session-event-slices.ts +76 -26
- package/src/session-file-attachments.ts +66 -0
- package/src/session-goal-reports.ts +255 -0
- package/src/session-mcp-approval.ts +30 -0
- package/src/session-message-search.ts +348 -0
- package/src/session-queue-commands.ts +60 -36
- package/src/session-retry.ts +319 -0
- package/src/skill-config-migration.ts +11 -2
- package/src/skill-source-release-impact.ts +33 -0
- package/src/skill-source-release.ts +67 -26
- package/src/skills.ts +44 -6
- package/src/user-resource-authority.ts +0 -56
- package/dist/chunk-6T2GGYWE.js.map +0 -1
- package/dist/chunk-7HMK3B45.js.map +0 -1
- package/dist/chunk-DPONPYJD.js.map +0 -1
- package/dist/chunk-F73UKJY6.js.map +0 -1
- package/dist/chunk-T6YLHJLS.js.map +0 -1
- package/dist/host-mcp-binding-match.d.ts +0 -5
- package/dist/host-mcp-bindings.d.ts +0 -79
- package/dist/host-mcp-resolvers.d.ts +0 -47
- package/dist/host-mcp-task-authority.d.ts +0 -43
- package/dist/host-selection-identity.d.ts +0 -6
- package/dist/pack-components.d.ts +0 -83
- package/dist/pack-installations.d.ts +0 -86
- package/src/host-mcp-binding-match.ts +0 -34
- package/src/host-mcp-bindings.ts +0 -777
- package/src/host-mcp-resolvers.ts +0 -266
- package/src/host-mcp-task-authority.ts +0 -384
- package/src/host-selection-identity.ts +0 -29
- package/src/pack-components.ts +0 -980
- package/src/pack-installations.ts +0 -950
- /package/dist/{chunk-MWMXWHJD.js.map → chunk-7JCDSMX2.js.map} +0 -0
- /package/dist/{chunk-ERKVSPDX.js.map → chunk-LVY33EWL.js.map} +0 -0
- /package/dist/{chunk-T6BWIGWJ.js.map → chunk-RIYHP2WU.js.map} +0 -0
package/dist/schema.js
CHANGED
|
@@ -189,6 +189,8 @@ import {
|
|
|
189
189
|
organizationCodexRotationSettings,
|
|
190
190
|
organizationCompanyProfileAgentPolicies,
|
|
191
191
|
organizationCompanyProfileAgentPolicyEvents,
|
|
192
|
+
organizationIntegrationPolicies,
|
|
193
|
+
organizationIntegrationPolicyOperations,
|
|
192
194
|
organizationInvitationBindingEvents,
|
|
193
195
|
organizationMembershipInvitations,
|
|
194
196
|
organizationMembershipLifecycleEvents,
|
|
@@ -217,8 +219,6 @@ import {
|
|
|
217
219
|
organizationUserRetentionObjectDeletionReceipts,
|
|
218
220
|
organizationUserRetentionObjectObligations,
|
|
219
221
|
organizationUserRetentionPolicies,
|
|
220
|
-
packInstallationComponents,
|
|
221
|
-
packInstallations,
|
|
222
222
|
personalGitHubRepositorySelectionHeads,
|
|
223
223
|
personalGitHubRepositorySelectionOperations,
|
|
224
224
|
personalGitHubRepositorySelections,
|
|
@@ -360,7 +360,6 @@ import {
|
|
|
360
360
|
workspaceLearningPolicySnapshots,
|
|
361
361
|
workspaceMemberships,
|
|
362
362
|
workspaceModelPolicies,
|
|
363
|
-
workspacePacks,
|
|
364
363
|
workspaceScreenshotQuotas,
|
|
365
364
|
workspaceSessionActivityRevisions,
|
|
366
365
|
workspaceVariableSetVariables,
|
|
@@ -373,7 +372,7 @@ import {
|
|
|
373
372
|
xaiRotationSettings,
|
|
374
373
|
xaiSessionAccountPins,
|
|
375
374
|
xaiSubscriptionCredentials
|
|
376
|
-
} from "./chunk-
|
|
375
|
+
} from "./chunk-MN5PZMEK.js";
|
|
377
376
|
import "./chunk-S2TZ3F4L.js";
|
|
378
377
|
import "./chunk-PZ5AY32C.js";
|
|
379
378
|
export {
|
|
@@ -567,6 +566,8 @@ export {
|
|
|
567
566
|
organizationCodexRotationSettings,
|
|
568
567
|
organizationCompanyProfileAgentPolicies,
|
|
569
568
|
organizationCompanyProfileAgentPolicyEvents,
|
|
569
|
+
organizationIntegrationPolicies,
|
|
570
|
+
organizationIntegrationPolicyOperations,
|
|
570
571
|
organizationInvitationBindingEvents,
|
|
571
572
|
organizationMembershipInvitations,
|
|
572
573
|
organizationMembershipLifecycleEvents,
|
|
@@ -595,8 +596,6 @@ export {
|
|
|
595
596
|
organizationUserRetentionObjectDeletionReceipts,
|
|
596
597
|
organizationUserRetentionObjectObligations,
|
|
597
598
|
organizationUserRetentionPolicies,
|
|
598
|
-
packInstallationComponents,
|
|
599
|
-
packInstallations,
|
|
600
599
|
personalGitHubRepositorySelectionHeads,
|
|
601
600
|
personalGitHubRepositorySelectionOperations,
|
|
602
601
|
personalGitHubRepositorySelections,
|
|
@@ -738,7 +737,6 @@ export {
|
|
|
738
737
|
workspaceLearningPolicySnapshots,
|
|
739
738
|
workspaceMemberships,
|
|
740
739
|
workspaceModelPolicies,
|
|
741
|
-
workspacePacks,
|
|
742
740
|
workspaceScreenshotQuotas,
|
|
743
741
|
workspaceSessionActivityRevisions,
|
|
744
742
|
workspaceVariableSetVariables,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SessionAdmissionBlock } from "@opengeni/contracts";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export type SessionAdmissionFence = {
|
|
4
|
+
lastSequence: number;
|
|
5
|
+
controlVersion: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const StoredSessionAdmissionBlock: z.ZodObject<{
|
|
8
|
+
reason: z.ZodEnum<{
|
|
9
|
+
database_claim_rejected: "database_claim_rejected";
|
|
10
|
+
initiator_membership_required: "initiator_membership_required";
|
|
11
|
+
personal_resource_grant_required: "personal_resource_grant_required";
|
|
12
|
+
}>;
|
|
13
|
+
sqlState: z.ZodNullable<z.ZodString>;
|
|
14
|
+
retryPolicy: z.ZodLiteral<"explicit_recheck">;
|
|
15
|
+
blockedAt: z.ZodString;
|
|
16
|
+
attemptId: z.ZodString;
|
|
17
|
+
fence: z.ZodObject<{
|
|
18
|
+
lastSequence: z.ZodNumber;
|
|
19
|
+
controlVersion: z.ZodNumber;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
previousStatus: z.ZodEnum<{
|
|
22
|
+
idle: "idle";
|
|
23
|
+
queued: "queued";
|
|
24
|
+
recovering: "recovering";
|
|
25
|
+
requires_action: "requires_action";
|
|
26
|
+
running: "running";
|
|
27
|
+
waiting_capacity: "waiting_capacity";
|
|
28
|
+
}>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
export type StoredSessionAdmissionBlock = z.infer<typeof StoredSessionAdmissionBlock>;
|
|
31
|
+
/** Never expose internal attempt/fence identities through the public projection. */
|
|
32
|
+
export declare function projectSessionAdmissionBlock(value: StoredSessionAdmissionBlock | null | undefined): SessionAdmissionBlock | null;
|
|
@@ -22,10 +22,11 @@ import {
|
|
|
22
22
|
settleClaimedConnectedMachineBackgroundCommandWithMutation,
|
|
23
23
|
settleConnectedMachineSessionBackgroundCommandWithMutation,
|
|
24
24
|
settleSessionBackgroundCommandForRetainedProcessInTransaction
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
28
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-GABXCG3N.js";
|
|
26
|
+
import "./chunk-LVY33EWL.js";
|
|
27
|
+
import "./chunk-4UJCXBR2.js";
|
|
28
|
+
import "./chunk-CJI6G254.js";
|
|
29
|
+
import "./chunk-MN5PZMEK.js";
|
|
29
30
|
import "./chunk-S2TZ3F4L.js";
|
|
30
31
|
import "./chunk-PZ5AY32C.js";
|
|
31
32
|
export {
|
|
@@ -1,131 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
sessionBackgroundCommands,
|
|
11
|
-
sessionEvents,
|
|
12
|
-
sessions
|
|
13
|
-
} from "./chunk-F73UKJY6.js";
|
|
14
|
-
import {
|
|
15
|
-
fromPostgresLosslessJson,
|
|
16
|
-
withLosslessContentWriteVersion
|
|
17
|
-
} from "./chunk-S2TZ3F4L.js";
|
|
2
|
+
appendSessionCommandOutput
|
|
3
|
+
} from "./chunk-PJI4MUZ7.js";
|
|
4
|
+
import "./chunk-GABXCG3N.js";
|
|
5
|
+
import "./chunk-LVY33EWL.js";
|
|
6
|
+
import "./chunk-4UJCXBR2.js";
|
|
7
|
+
import "./chunk-CJI6G254.js";
|
|
8
|
+
import "./chunk-MN5PZMEK.js";
|
|
9
|
+
import "./chunk-S2TZ3F4L.js";
|
|
18
10
|
import "./chunk-PZ5AY32C.js";
|
|
19
|
-
|
|
20
|
-
// src/session-command-output.ts
|
|
21
|
-
import { and, eq } from "drizzle-orm";
|
|
22
|
-
async function appendSessionCommandOutput(db, input) {
|
|
23
|
-
if (!input.chunkId || input.chunkId.length > 200)
|
|
24
|
-
throw new Error("Invalid command output chunk ID");
|
|
25
|
-
if (!input.chunk) return [];
|
|
26
|
-
return await withSessionActivityRlsContext(db, input, async (tx) => {
|
|
27
|
-
const events = [];
|
|
28
|
-
const locks = await lockSessionEventWriteRows(tx, {
|
|
29
|
-
workspaceId: input.workspaceId,
|
|
30
|
-
controlLock: "share",
|
|
31
|
-
sessionIds: [input.sessionId]
|
|
32
|
-
});
|
|
33
|
-
const session = locks.sessions[0];
|
|
34
|
-
if (!session || session.accountId !== input.accountId)
|
|
35
|
-
throw new Error("Command output session not found");
|
|
36
|
-
const [command] = await tx.select({ id: sessionBackgroundCommands.id }).from(sessionBackgroundCommands).where(
|
|
37
|
-
and(
|
|
38
|
-
eq(sessionBackgroundCommands.accountId, input.accountId),
|
|
39
|
-
eq(sessionBackgroundCommands.workspaceId, input.workspaceId),
|
|
40
|
-
eq(sessionBackgroundCommands.sessionId, input.sessionId),
|
|
41
|
-
eq(sessionBackgroundCommands.id, input.commandId)
|
|
42
|
-
)
|
|
43
|
-
).limit(1);
|
|
44
|
-
if (!command) {
|
|
45
|
-
const [process] = await tx.select({ id: sandboxRetainedProcesses.id }).from(sandboxRetainedProcesses).where(
|
|
46
|
-
and(
|
|
47
|
-
eq(sandboxRetainedProcesses.accountId, input.accountId),
|
|
48
|
-
eq(sandboxRetainedProcesses.workspaceId, input.workspaceId),
|
|
49
|
-
eq(sandboxRetainedProcesses.sessionId, input.sessionId),
|
|
50
|
-
eq(sandboxRetainedProcesses.id, input.commandId)
|
|
51
|
-
)
|
|
52
|
-
).limit(1);
|
|
53
|
-
if (!process) throw new Error("Command output has no retained command identity");
|
|
54
|
-
}
|
|
55
|
-
let sequence = session.lastSequence;
|
|
56
|
-
let part = 0;
|
|
57
|
-
for (let offset = 0; offset < input.chunk.length; ) {
|
|
58
|
-
let end = Math.min(offset + 16384, input.chunk.length);
|
|
59
|
-
if (end < input.chunk.length && /[\uD800-\uDBFF]/u.test(input.chunk[end - 1])) end -= 1;
|
|
60
|
-
const clientEventId = `command-output:${input.commandId}:${input.chunkId}:${input.stream}:${part++}`;
|
|
61
|
-
const chunk = input.chunk.slice(offset, end);
|
|
62
|
-
offset = end;
|
|
63
|
-
const [existing] = await tx.select({
|
|
64
|
-
payload: sessionEvents.payload,
|
|
65
|
-
version: sessionEvents.payloadCodecVersion
|
|
66
|
-
}).from(sessionEvents).where(
|
|
67
|
-
and(
|
|
68
|
-
eq(sessionEvents.workspaceId, input.workspaceId),
|
|
69
|
-
eq(sessionEvents.sessionId, input.sessionId),
|
|
70
|
-
eq(sessionEvents.clientEventId, clientEventId)
|
|
71
|
-
)
|
|
72
|
-
).limit(1);
|
|
73
|
-
if (existing) {
|
|
74
|
-
const payload = fromPostgresLosslessJson(existing.payload, existing.version);
|
|
75
|
-
if (payload.chunk !== chunk || payload.commandId !== input.commandId || payload.stream !== input.stream) {
|
|
76
|
-
throw new Error("Command output retry changed the captured chunk");
|
|
77
|
-
}
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
const [inserted] = await tx.insert(sessionEvents).values(
|
|
81
|
-
withLosslessContentWriteVersion(
|
|
82
|
-
{
|
|
83
|
-
accountId: input.accountId,
|
|
84
|
-
workspaceId: input.workspaceId,
|
|
85
|
-
sessionId: input.sessionId,
|
|
86
|
-
sequence: ++sequence,
|
|
87
|
-
type: "sandbox.command.output.delta",
|
|
88
|
-
clientEventId,
|
|
89
|
-
payload: {
|
|
90
|
-
commandId: input.commandId,
|
|
91
|
-
stream: input.stream,
|
|
92
|
-
streamFidelity: input.streamFidelity ?? "separate",
|
|
93
|
-
chunk
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
"payload",
|
|
97
|
-
"payloadCodecVersion"
|
|
98
|
-
)
|
|
99
|
-
).returning();
|
|
100
|
-
if (inserted)
|
|
101
|
-
events.push({
|
|
102
|
-
id: inserted.id,
|
|
103
|
-
workspaceId: input.workspaceId,
|
|
104
|
-
sessionId: input.sessionId,
|
|
105
|
-
sequence: inserted.sequence,
|
|
106
|
-
type: "sandbox.command.output.delta",
|
|
107
|
-
payload: fromPostgresLosslessJson(inserted.payload, inserted.payloadCodecVersion),
|
|
108
|
-
occurredAt: inserted.occurredAt.toISOString(),
|
|
109
|
-
clientEventId,
|
|
110
|
-
turnId: null,
|
|
111
|
-
turnGeneration: null,
|
|
112
|
-
turnAttemptId: null,
|
|
113
|
-
turnAssociation: null,
|
|
114
|
-
duplicateOfEventId: null,
|
|
115
|
-
duplicateReason: null
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
if (sequence !== session.lastSequence) {
|
|
119
|
-
await tx.update(sessions).set({ lastSequence: sequence }).where(
|
|
120
|
-
and(
|
|
121
|
-
eq(sessions.workspaceId, input.workspaceId),
|
|
122
|
-
eq(sessions.id, input.sessionId)
|
|
123
|
-
)
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
return events;
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
11
|
export {
|
|
130
12
|
appendSessionCommandOutput
|
|
131
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -223,6 +223,8 @@ export type WorkspaceControlLockOptions = {
|
|
|
223
223
|
/** Share an already running budget (used by the admission helper). */
|
|
224
224
|
budget?: WorkspaceControlLockBudget;
|
|
225
225
|
};
|
|
226
|
+
/** Run one lock-acquiring statement under the remaining budget. */
|
|
227
|
+
export declare function boundedLockStep<T>(db: Database, workspaceId: string, budget: WorkspaceControlLockBudget | null, step: () => Promise<T>): Promise<T>;
|
|
226
228
|
/**
|
|
227
229
|
* Lock the mandatory workspace inference-control row.
|
|
228
230
|
*
|
|
@@ -381,7 +383,9 @@ export declare function assertSessionAuthoritySnapshot(input: {
|
|
|
381
383
|
authorityVisibility: unknown;
|
|
382
384
|
authorityOwnerOrganizationMembershipId: unknown;
|
|
383
385
|
}): SessionAuthoritySnapshot;
|
|
384
|
-
export declare function sessionAuthoritySnapshotMatchesSession(snapshot: SessionAuthoritySnapshot, session: Pick<typeof schema.sessions.$inferSelect, "authorityEpoch" | "visibility" | "ownerOrganizationMembershipId">
|
|
386
|
+
export declare function sessionAuthoritySnapshotMatchesSession(snapshot: SessionAuthoritySnapshot, session: Pick<typeof schema.sessions.$inferSelect, "authorityEpoch" | "visibility" | "ownerOrganizationMembershipId"> & {
|
|
387
|
+
executionAuthorityEpoch?: number;
|
|
388
|
+
}): boolean;
|
|
385
389
|
export declare function sessionAuthoritySnapshotsEqual(left: Pick<SessionAuthoritySnapshot, "authorityEpoch" | "authorityVisibility" | "authorityOwnerOrganizationMembershipId">, right: Pick<SessionAuthoritySnapshot, "authorityEpoch" | "authorityVisibility" | "authorityOwnerOrganizationMembershipId">): boolean;
|
|
386
390
|
/**
|
|
387
391
|
* Close the exact first-class owner while the caller still holds the owning
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SessionEvent } from "@opengeni/contracts";
|
|
1
2
|
import { type Database } from "./database.js";
|
|
2
3
|
type ListSessionEventPageOptions = import("./index.js").ListSessionEventPageOptions;
|
|
3
4
|
type SessionEventPage = import("./index.js").SessionEventPage;
|
|
@@ -19,6 +20,15 @@ export type SessionEventSlice = {
|
|
|
19
20
|
export type SessionEventSlicePage = SessionEventPage & {
|
|
20
21
|
slices?: Record<number, SessionEventSlice>;
|
|
21
22
|
};
|
|
23
|
+
type SliceIdentity = Pick<SessionEvent, "id" | "sequence" | "type" | "turnId" | "turnAssociation" | "duplicateOfEventId">;
|
|
24
|
+
/** Internal search projection, NOT authorization. The scanner has selected this
|
|
25
|
+
* exact identity under its subject RLS/list filters and still holds that same
|
|
26
|
+
* transaction and tenancy/membership fences. Reuse them rather than creating
|
|
27
|
+
* two nested scopes and rediscovering the identity for every scalar window.
|
|
28
|
+
* The scalar query still checks the exact workspace/session/event and RLS.
|
|
29
|
+
* Keep the codec/window implementation shared with the conversation reader.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readSessionMessageSliceInScope(db: Database, workspaceId: string, sessionId: string, identity: SliceIdentity, offset: number, windows?: number): Promise<SessionEventSlice | undefined>;
|
|
22
32
|
/** Bounded transfer over retained scalar truth. JSONB extraction/detoasting still
|
|
23
33
|
* costs PostgreSQL work proportional to the individual source value, not history.
|
|
24
34
|
* This is a read projection, not authorization: the MCP caller must authorize the
|
|
@@ -1,227 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./chunk-F73UKJY6.js";
|
|
9
|
-
import {
|
|
10
|
-
LOSSLESS_JSON_STRING_PREFIX,
|
|
11
|
-
fromPostgresLosslessJson
|
|
12
|
-
} from "./chunk-S2TZ3F4L.js";
|
|
2
|
+
listSessionEventSlices,
|
|
3
|
+
readSessionMessageSliceInScope
|
|
4
|
+
} from "./chunk-CDAT6EKW.js";
|
|
5
|
+
import "./chunk-CJI6G254.js";
|
|
6
|
+
import "./chunk-MN5PZMEK.js";
|
|
7
|
+
import "./chunk-S2TZ3F4L.js";
|
|
13
8
|
import "./chunk-PZ5AY32C.js";
|
|
14
|
-
|
|
15
|
-
// src/session-event-slices.ts
|
|
16
|
-
import { and, asc, desc, eq, gt, inArray, lt, notInArray, sql } from "drizzle-orm";
|
|
17
|
-
import { resolveSessionEventTypeFilters } from "@opengeni/contracts";
|
|
18
|
-
var WINDOW = 8192;
|
|
19
|
-
var STRUCTURED_BYTES = 1024 * 1024;
|
|
20
|
-
async function listSessionEventSlices(db, workspaceId, sessionId, options, legacyRead) {
|
|
21
|
-
if (options.legacyUtf16) {
|
|
22
|
-
if (!legacyRead) throw new Error("Legacy continuation requires its original bounded reader");
|
|
23
|
-
return legacyRead({
|
|
24
|
-
...options,
|
|
25
|
-
limit: 1,
|
|
26
|
-
maxBytes: 1024 * 1024
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
const offset = options.sourceOffset ?? 0;
|
|
30
|
-
if (!Number.isSafeInteger(offset) || offset < 0 || offset > 2147483647)
|
|
31
|
-
throw new Error("Invalid message continuation offset");
|
|
32
|
-
const direction = options.direction ?? (options.before === void 0 ? "after" : "before");
|
|
33
|
-
const limit = options.sourceSequence ? 1 : Math.max(1, Math.min(options.limit ?? 8, 8));
|
|
34
|
-
const filters = resolveSessionEventTypeFilters(options);
|
|
35
|
-
const predicates = [
|
|
36
|
-
eq(sessionEvents.workspaceId, workspaceId),
|
|
37
|
-
eq(sessionEvents.sessionId, sessionId),
|
|
38
|
-
gt(sessionEvents.sequence, Math.min(options.after ?? 0, 2147483647)),
|
|
39
|
-
// Same indexed exclusion as the audit/discovery reader. Do not substitute
|
|
40
|
-
// turn status: terminal-before-claim prompts must remain excluded too.
|
|
41
|
-
sql`(${sessionEvents.type} <> 'user.message' or not exists (
|
|
42
|
-
select 1 from ${sessionTurns} unclaimed_prompt_turn
|
|
43
|
-
where unclaimed_prompt_turn.workspace_id = ${workspaceId}
|
|
44
|
-
and unclaimed_prompt_turn.workspace_id = ${sessionEvents.workspaceId}
|
|
45
|
-
and unclaimed_prompt_turn.session_id = ${sessionEvents.sessionId}
|
|
46
|
-
and unclaimed_prompt_turn.trigger_event_id = ${sessionEvents.id}
|
|
47
|
-
and unclaimed_prompt_turn.source in ('user', 'api')
|
|
48
|
-
and unclaimed_prompt_turn.started_at is null
|
|
49
|
-
))`
|
|
50
|
-
];
|
|
51
|
-
if (options.before !== void 0 && options.before <= 2147483647)
|
|
52
|
-
predicates.push(lt(sessionEvents.sequence, options.before));
|
|
53
|
-
if (filters.includeTypes.length)
|
|
54
|
-
predicates.push(inArray(sessionEvents.type, filters.includeTypes));
|
|
55
|
-
if (filters.excludeTypes.length)
|
|
56
|
-
predicates.push(notInArray(sessionEvents.type, filters.excludeTypes));
|
|
57
|
-
const identities = await withWorkspaceRls(
|
|
58
|
-
db,
|
|
59
|
-
workspaceId,
|
|
60
|
-
(tx) => tx.select({
|
|
61
|
-
id: sessionEvents.id,
|
|
62
|
-
sequence: sessionEvents.sequence,
|
|
63
|
-
type: sql`case when octet_length(${sessionEvents.type}) <= 256 then ${sessionEvents.type} else 'session.event.envelope_omitted' end`,
|
|
64
|
-
turnId: sessionEvents.turnId,
|
|
65
|
-
turnAssociation: sql`case when ${sessionEvents.turnAssociation} is null then null when ${sessionEvents.turnAssociation} = 'current' then 'current' else 'late_rejected' end`,
|
|
66
|
-
duplicateOfEventId: sessionEvents.duplicateOfEventId
|
|
67
|
-
}).from(sessionEvents).where(and(...predicates)).orderBy(
|
|
68
|
-
direction === "before" ? desc(sessionEvents.sequence) : asc(sessionEvents.sequence)
|
|
69
|
-
).limit(limit + 1)
|
|
70
|
-
);
|
|
71
|
-
const ordered = identities.slice(0, limit).map(
|
|
72
|
-
(identity) => ({
|
|
73
|
-
...identity,
|
|
74
|
-
workspaceId,
|
|
75
|
-
sessionId,
|
|
76
|
-
payload: {},
|
|
77
|
-
occurredAt: ""
|
|
78
|
-
})
|
|
79
|
-
);
|
|
80
|
-
const page = {
|
|
81
|
-
events: [],
|
|
82
|
-
hasMore: identities.length > limit,
|
|
83
|
-
bytes: 2,
|
|
84
|
-
fullPayloadsExact: true,
|
|
85
|
-
direction,
|
|
86
|
-
coveredSequence: null,
|
|
87
|
-
nextAfter: null,
|
|
88
|
-
nextBefore: null,
|
|
89
|
-
truncatedBy: identities.length > limit ? "count" : null
|
|
90
|
-
};
|
|
91
|
-
const slices = {};
|
|
92
|
-
const events = [];
|
|
93
|
-
let consumed = 0;
|
|
94
|
-
await withWorkspaceRls(db, workspaceId, async (tx) => {
|
|
95
|
-
for (const event of ordered) {
|
|
96
|
-
consumed++;
|
|
97
|
-
if (event.duplicateOfEventId || event.turnAssociation && event.turnAssociation !== "current")
|
|
98
|
-
continue;
|
|
99
|
-
const p = sessionEvents.payload;
|
|
100
|
-
const output = event.type === "agent.toolCall.output";
|
|
101
|
-
let value = sql`${p}->'text'`;
|
|
102
|
-
if (options.view === "tools")
|
|
103
|
-
value = output ? sql`${p}->'output'` : sql`coalesce(nullif(${p}->'arguments', 'null'::jsonb), ${p}->'args')`;
|
|
104
|
-
else if (options.view === "results")
|
|
105
|
-
value = event.type === "turn.completed" ? sql`coalesce(nullif(${p}->'output', 'null'::jsonb), ${p}->'result')` : sql`${p}`;
|
|
106
|
-
const include = options.view !== "tools" || (output ? options.includeOutput : options.includeArguments);
|
|
107
|
-
if (!include) value = sql`null::jsonb`;
|
|
108
|
-
const start = options.sourceSequence === event.sequence ? offset : 0;
|
|
109
|
-
const prefix = LOSSLESS_JSON_STRING_PREFIX;
|
|
110
|
-
const raw = sql`raw`;
|
|
111
|
-
const encoded = sql`encoded`;
|
|
112
|
-
const tagged = sql`case when version = 1
|
|
113
|
-
and left(${raw}, ${prefix.length}) = ${prefix}
|
|
114
|
-
and length(${encoded}) > 0
|
|
115
|
-
and ${encoded} ~ '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$'
|
|
116
|
-
then (length(${encoded}) / 4 * 3 - case when right(${encoded}, 2) = '==' then 2 when right(${encoded}, 1) = '=' then 1 else 0 end) % 2 = 0
|
|
117
|
-
and encode(decode(right(${encoded}, 4), 'base64'), 'base64') = right(${encoded}, 4)
|
|
118
|
-
else false end`;
|
|
119
|
-
const group = Math.floor(Math.max(0, start - 1) / 3);
|
|
120
|
-
const safeMetadata = (key) => sql`case when octet_length((${p}->${key})::text) <= 4096 then ${p}->${key} else null end`;
|
|
121
|
-
const callId = sql`coalesce(nullif(${p}->'callId', 'null'::jsonb), nullif(${p}->'call_id', 'null'::jsonb), ${p}->'id')`;
|
|
122
|
-
const metadataSql = options.view === "tools" ? sql`jsonb_strip_nulls(jsonb_build_object(
|
|
123
|
-
'callId', case when octet_length((${callId})::text) <= 4096 then ${callId} else null end,
|
|
124
|
-
'identityOmitted', case when octet_length((${callId})::text) > 4096 or octet_length((${p}->'name')::text) > 4096 then true else null end,
|
|
125
|
-
'name', ${safeMetadata("name")}, 'isError', case when ${p}->'isError' = 'true'::jsonb or (${output} and ${p}->'output'->'isError' = 'true'::jsonb) then true else null end,
|
|
126
|
-
'maintenance', case when ${p} ? 'maintenance' then true else null end,
|
|
127
|
-
'segmentLimit', case when ${p} ? 'segmentLimit' then true else null end))` : options.view === "results" && event.type === "turn.completed" ? sql`jsonb_strip_nulls(jsonb_build_object(
|
|
128
|
-
'maintenance', case when ${p} ? 'maintenance' then true else null end,
|
|
129
|
-
'segmentLimit', case when ${p} ? 'segmentLimit' then true else null end))` : sql`'{}'::jsonb`;
|
|
130
|
-
const [row] = await rawRows(
|
|
131
|
-
tx,
|
|
132
|
-
sql`with source as (
|
|
133
|
-
select ${value} as value, ${metadataSql} as metadata,
|
|
134
|
-
${sessionEvents.payloadCodecVersion} as version
|
|
135
|
-
from ${sessionEvents}
|
|
136
|
-
where ${sessionEvents.workspaceId} = ${workspaceId}
|
|
137
|
-
and ${sessionEvents.sessionId} = ${sessionId}
|
|
138
|
-
and ${sessionEvents.id} = ${event.id}
|
|
139
|
-
and (${sessionEvents.turnAssociation} is null or ${sessionEvents.turnAssociation} = 'current')
|
|
140
|
-
and ${sessionEvents.duplicateOfEventId} is null
|
|
141
|
-
limit 1
|
|
142
|
-
), scalar as (
|
|
143
|
-
select *, jsonb_typeof(value) as kind,
|
|
144
|
-
case when jsonb_typeof(value) = 'string' then value #>> '{}' else null end as raw,
|
|
145
|
-
case when jsonb_typeof(value) <> 'string' then octet_length(value::text) else 0 end as structured_bytes
|
|
146
|
-
from source offset 0
|
|
147
|
-
), encoding as (
|
|
148
|
-
select *, case when version = 1 and left(raw, ${prefix.length}) = ${prefix}
|
|
149
|
-
then substring(raw from ${prefix.length + 1}::integer) else null end as encoded
|
|
150
|
-
from scalar offset 0
|
|
151
|
-
), validated as (
|
|
152
|
-
select *, ${tagged} as tagged from encoding offset 0
|
|
153
|
-
)
|
|
154
|
-
select metadata, version, kind, tagged,
|
|
155
|
-
case when kind = 'string' then
|
|
156
|
-
case when tagged then (length(encoded) / 4 * 3 - case when right(encoded, 2) = '==' then 2 when right(encoded, 1) = '=' then 1 else 0 end) / 2
|
|
157
|
-
else length(raw) end else 0 end as total,
|
|
158
|
-
case when kind = 'string' then
|
|
159
|
-
case when tagged then substring(encoded from ${Math.min(group * 8 + 1, 2147483647)}::integer for ${Math.ceil((WINDOW + 6) / 3) * 8}::integer)
|
|
160
|
-
else substring(raw from ${Math.min(start + 1, 2147483647)}::integer for ${WINDOW}::integer) end else null end as window,
|
|
161
|
-
case when kind <> 'string' and structured_bytes <= ${STRUCTURED_BYTES} then value else null end as structured,
|
|
162
|
-
coalesce(kind <> 'string' and structured_bytes > ${STRUCTURED_BYTES}, false) as omitted
|
|
163
|
-
from validated`
|
|
164
|
-
);
|
|
165
|
-
if (!row) continue;
|
|
166
|
-
const metadata = fromPostgresLosslessJson(row.metadata, row.version);
|
|
167
|
-
for (const [key, budget] of [
|
|
168
|
-
["callId", 4096],
|
|
169
|
-
["name", 1024]
|
|
170
|
-
]) {
|
|
171
|
-
if (metadata[key] !== void 0 && Buffer.byteLength(JSON.stringify(metadata[key]), "utf8") > budget) {
|
|
172
|
-
delete metadata[key];
|
|
173
|
-
metadata.identityOmitted = true;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
let text = row.window ?? "";
|
|
177
|
-
if (row.tagged) {
|
|
178
|
-
text = fromPostgresLosslessJson(prefix + text, 1);
|
|
179
|
-
const local = start - group * 3;
|
|
180
|
-
if (local > 0 && /[\uD800-\uDBFF]/.test(text[local - 1]) && /[\uDC00-\uDFFF]/.test(text[local] ?? ""))
|
|
181
|
-
throw new Error("Invalid message continuation offset: splits a surrogate pair");
|
|
182
|
-
text = text.slice(local, local + WINDOW);
|
|
183
|
-
if (start + text.length < row.total && /[\uD800-\uDBFF]/.test(text.at(-1)))
|
|
184
|
-
text = text.slice(0, -1);
|
|
185
|
-
}
|
|
186
|
-
if (start > row.total && row.kind === "string")
|
|
187
|
-
throw new Error("Invalid message continuation offset");
|
|
188
|
-
const logical = row.omitted ? {} : row.kind === "string" ? text : fromPostgresLosslessJson(row.structured, row.version);
|
|
189
|
-
let payload = { ...metadata };
|
|
190
|
-
if (options.view === "tools") {
|
|
191
|
-
if (row.kind !== null) payload[output ? "output" : "arguments"] = logical;
|
|
192
|
-
} else if (options.view === "results") {
|
|
193
|
-
if (event.type === "turn.completed") payload.output = logical;
|
|
194
|
-
else payload = logical ?? {};
|
|
195
|
-
} else payload.text = logical;
|
|
196
|
-
if (row.omitted) payload = { ...payload, sourceOmitted: true };
|
|
197
|
-
if (row.kind === "string" || row.omitted)
|
|
198
|
-
slices[event.sequence] = {
|
|
199
|
-
offset: start,
|
|
200
|
-
total: row.total,
|
|
201
|
-
unit: row.tagged ? "utf16" : "codepoint",
|
|
202
|
-
text,
|
|
203
|
-
omitted: row.omitted
|
|
204
|
-
};
|
|
205
|
-
events.push({ ...event, payload });
|
|
206
|
-
if (row.kind !== "string" && Buffer.byteLength(JSON.stringify(payload)) > WINDOW) break;
|
|
207
|
-
if (row.kind === "string" && start + (row.tagged ? text.length : Array.from(text).length) < row.total)
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
return {
|
|
212
|
-
...page,
|
|
213
|
-
events: events.sort((a, b) => a.sequence - b.sequence),
|
|
214
|
-
hasMore: page.hasMore || consumed < ordered.length,
|
|
215
|
-
coveredSequence: consumed ? {
|
|
216
|
-
first: Math.min(ordered[0].sequence, ordered[consumed - 1].sequence),
|
|
217
|
-
last: Math.max(ordered[0].sequence, ordered[consumed - 1].sequence)
|
|
218
|
-
} : null,
|
|
219
|
-
bytes: Buffer.byteLength(JSON.stringify(events), "utf8"),
|
|
220
|
-
fullPayloadsExact: !Object.values(slices).some((slice) => slice.omitted),
|
|
221
|
-
slices
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
9
|
export {
|
|
225
|
-
listSessionEventSlices
|
|
10
|
+
listSessionEventSlices,
|
|
11
|
+
readSessionMessageSliceInScope
|
|
226
12
|
};
|
|
227
13
|
//# sourceMappingURL=session-event-slices.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/session-event-slices.ts"],"sourcesContent":["import { and, asc, desc, eq, gt, inArray, lt, notInArray, sql, type SQL } from \"drizzle-orm\";\nimport { resolveSessionEventTypeFilters, type SessionEvent } from \"@opengeni/contracts\";\nimport { rawRows, withWorkspaceRls, type Database } from \"./database\";\ntype ListSessionEventPageOptions = import(\"./index\").ListSessionEventPageOptions;\ntype SessionEventPage = import(\"./index\").SessionEventPage;\nimport { fromPostgresLosslessJson, LOSSLESS_JSON_STRING_PREFIX } from \"./lossless-json\";\nimport * as schema from \"./schema\";\n\nexport type SessionEventSliceOptions = ListSessionEventPageOptions & {\n sourceSequence?: number;\n sourceOffset?: number;\n view?: \"conversation\" | \"results\" | \"tools\";\n includeArguments?: boolean;\n includeOutput?: boolean;\n legacyUtf16?: boolean;\n};\nexport type SessionEventSlice = {\n offset: number;\n total: number;\n unit: \"codepoint\" | \"utf16\";\n text: string;\n omitted: boolean;\n};\nexport type SessionEventSlicePage = SessionEventPage & {\n slices?: Record<number, SessionEventSlice>;\n};\nconst WINDOW = 8192;\nconst STRUCTURED_BYTES = 1024 * 1024;\n\n/** Bounded transfer over retained scalar truth. JSONB extraction/detoasting still\n * costs PostgreSQL work proportional to the individual source value, not history.\n * This is a read projection, not authorization: the MCP caller must authorize the\n * target on every request. Both metadata and scalar reads retain workspace RLS.\n */\nexport async function listSessionEventSlices(\n db: Database,\n workspaceId: string,\n sessionId: string,\n options: SessionEventSliceOptions,\n legacyRead?: (options: ListSessionEventPageOptions) => Promise<SessionEventPage>,\n): Promise<SessionEventSlicePage> {\n // Finish an already-issued UTF-16 cursor using its original bounded reader.\n // New messages use source slices; no cursor offset is silently reinterpreted.\n if (options.legacyUtf16) {\n if (!legacyRead) throw new Error(\"Legacy continuation requires its original bounded reader\");\n return legacyRead({\n ...options,\n limit: 1,\n maxBytes: 1024 * 1024,\n });\n }\n const offset = options.sourceOffset ?? 0;\n if (!Number.isSafeInteger(offset) || offset < 0 || offset > 2_147_483_647)\n throw new Error(\"Invalid message continuation offset\");\n const direction = options.direction ?? (options.before === undefined ? \"after\" : \"before\");\n const limit = options.sourceSequence ? 1 : Math.max(1, Math.min(options.limit ?? 8, 8));\n const filters = resolveSessionEventTypeFilters(options);\n const predicates: SQL[] = [\n eq(schema.sessionEvents.workspaceId, workspaceId),\n eq(schema.sessionEvents.sessionId, sessionId),\n gt(schema.sessionEvents.sequence, Math.min(options.after ?? 0, 2_147_483_647)),\n // Same indexed exclusion as the audit/discovery reader. Do not substitute\n // turn status: terminal-before-claim prompts must remain excluded too.\n sql`(${schema.sessionEvents.type} <> 'user.message' or not exists (\n select 1 from ${schema.sessionTurns} unclaimed_prompt_turn\n where unclaimed_prompt_turn.workspace_id = ${workspaceId}\n and unclaimed_prompt_turn.workspace_id = ${schema.sessionEvents.workspaceId}\n and unclaimed_prompt_turn.session_id = ${schema.sessionEvents.sessionId}\n and unclaimed_prompt_turn.trigger_event_id = ${schema.sessionEvents.id}\n and unclaimed_prompt_turn.source in ('user', 'api')\n and unclaimed_prompt_turn.started_at is null\n ))`,\n ];\n if (options.before !== undefined && options.before <= 2_147_483_647)\n predicates.push(lt(schema.sessionEvents.sequence, options.before));\n if (filters.includeTypes.length)\n predicates.push(inArray(schema.sessionEvents.type, filters.includeTypes));\n if (filters.excludeTypes.length)\n predicates.push(notInArray(schema.sessionEvents.type, filters.excludeTypes));\n // Unlike audit `none` mode, this identity query does not compute a payload\n // projection merely to report its size. Only the selected scalar is extracted.\n const identities = await withWorkspaceRls(db, workspaceId, (tx) =>\n tx\n .select({\n id: schema.sessionEvents.id,\n sequence: schema.sessionEvents.sequence,\n type: sql<string>`case when octet_length(${schema.sessionEvents.type}) <= 256 then ${schema.sessionEvents.type} else 'session.event.envelope_omitted' end`,\n turnId: schema.sessionEvents.turnId,\n turnAssociation: sql<\n string | null\n >`case when ${schema.sessionEvents.turnAssociation} is null then null when ${schema.sessionEvents.turnAssociation} = 'current' then 'current' else 'late_rejected' end`,\n duplicateOfEventId: schema.sessionEvents.duplicateOfEventId,\n })\n .from(schema.sessionEvents)\n .where(and(...predicates))\n .orderBy(\n direction === \"before\"\n ? desc(schema.sessionEvents.sequence)\n : asc(schema.sessionEvents.sequence),\n )\n .limit(limit + 1),\n );\n const ordered = identities.slice(0, limit).map(\n (identity) =>\n ({\n ...identity,\n workspaceId,\n sessionId,\n payload: {},\n occurredAt: \"\",\n }) as SessionEvent,\n );\n const page: SessionEventPage = {\n events: [],\n hasMore: identities.length > limit,\n bytes: 2,\n fullPayloadsExact: true,\n direction,\n coveredSequence: null,\n nextAfter: null,\n nextBefore: null,\n truncatedBy: identities.length > limit ? \"count\" : null,\n };\n const slices: Record<number, SessionEventSlice> = {};\n const events: SessionEvent[] = [];\n let consumed = 0;\n await withWorkspaceRls(db, workspaceId, async (tx) => {\n for (const event of ordered) {\n consumed++;\n if (\n event.duplicateOfEventId ||\n (event.turnAssociation && event.turnAssociation !== \"current\")\n )\n continue;\n const p = schema.sessionEvents.payload;\n const output = event.type === \"agent.toolCall.output\";\n let value: SQL = sql`${p}->'text'`;\n if (options.view === \"tools\")\n value = output\n ? sql`${p}->'output'`\n : sql`coalesce(nullif(${p}->'arguments', 'null'::jsonb), ${p}->'args')`;\n else if (options.view === \"results\")\n value =\n event.type === \"turn.completed\"\n ? sql`coalesce(nullif(${p}->'output', 'null'::jsonb), ${p}->'result')`\n : sql`${p}`;\n const include =\n options.view !== \"tools\" || (output ? options.includeOutput : options.includeArguments);\n if (!include) value = sql`null::jsonb`;\n const start = options.sourceSequence === event.sequence ? offset : 0;\n const prefix = LOSSLESS_JSON_STRING_PREFIX;\n const raw = sql`raw`;\n const encoded = sql`encoded`;\n // Match exactly the JS codec's canonical-base64/even-byte acceptance.\n // A malformed active marker remains literal, just like the shared codec.\n const tagged = sql`case when version = 1\n and left(${raw}, ${prefix.length}) = ${prefix}\n and length(${encoded}) > 0\n and ${encoded} ~ '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$'\n then (length(${encoded}) / 4 * 3 - case when right(${encoded}, 2) = '==' then 2 when right(${encoded}, 1) = '=' then 1 else 0 end) % 2 = 0\n and encode(decode(right(${encoded}, 4), 'base64'), 'base64') = right(${encoded}, 4)\n else false end`;\n // Aligned base64 windows represent groups of three UTF-16 units. Include\n // one preceding and one following unit to validate/avoid pair splits.\n const group = Math.floor(Math.max(0, start - 1) / 3);\n const safeMetadata = (key: string) =>\n sql`case when octet_length((${p}->${key})::text) <= 4096 then ${p}->${key} else null end`;\n const callId = sql`coalesce(nullif(${p}->'callId', 'null'::jsonb), nullif(${p}->'call_id', 'null'::jsonb), ${p}->'id')`;\n const metadataSql =\n options.view === \"tools\"\n ? sql`jsonb_strip_nulls(jsonb_build_object(\n 'callId', case when octet_length((${callId})::text) <= 4096 then ${callId} else null end,\n 'identityOmitted', case when octet_length((${callId})::text) > 4096 or octet_length((${p}->'name')::text) > 4096 then true else null end,\n 'name', ${safeMetadata(\"name\")}, 'isError', case when ${p}->'isError' = 'true'::jsonb or (${output} and ${p}->'output'->'isError' = 'true'::jsonb) then true else null end,\n 'maintenance', case when ${p} ? 'maintenance' then true else null end,\n 'segmentLimit', case when ${p} ? 'segmentLimit' then true else null end))`\n : options.view === \"results\" && event.type === \"turn.completed\"\n ? sql`jsonb_strip_nulls(jsonb_build_object(\n 'maintenance', case when ${p} ? 'maintenance' then true else null end,\n 'segmentLimit', case when ${p} ? 'segmentLimit' then true else null end))`\n : sql`'{}'::jsonb`;\n const [row] = await rawRows<{\n metadata: unknown;\n version: number | null;\n kind: string | null;\n tagged: boolean;\n total: number;\n window: string | null;\n structured: unknown;\n omitted: boolean;\n }>(\n tx,\n sql`with source as (\n select ${value} as value, ${metadataSql} as metadata,\n ${schema.sessionEvents.payloadCodecVersion} as version\n from ${schema.sessionEvents}\n where ${schema.sessionEvents.workspaceId} = ${workspaceId}\n and ${schema.sessionEvents.sessionId} = ${sessionId}\n and ${schema.sessionEvents.id} = ${event.id}\n and (${schema.sessionEvents.turnAssociation} is null or ${schema.sessionEvents.turnAssociation} = 'current')\n and ${schema.sessionEvents.duplicateOfEventId} is null\n limit 1\n ), scalar as (\n select *, jsonb_typeof(value) as kind,\n case when jsonb_typeof(value) = 'string' then value #>> '{}' else null end as raw,\n case when jsonb_typeof(value) <> 'string' then octet_length(value::text) else 0 end as structured_bytes\n from source offset 0\n ), encoding as (\n select *, case when version = 1 and left(raw, ${prefix.length}) = ${prefix}\n then substring(raw from ${prefix.length + 1}::integer) else null end as encoded\n from scalar offset 0\n ), validated as (\n select *, ${tagged} as tagged from encoding offset 0\n )\n select metadata, version, kind, tagged,\n case when kind = 'string' then\n case when tagged then (length(encoded) / 4 * 3 - case when right(encoded, 2) = '==' then 2 when right(encoded, 1) = '=' then 1 else 0 end) / 2\n else length(raw) end else 0 end as total,\n case when kind = 'string' then\n case when tagged then substring(encoded from ${Math.min(group * 8 + 1, 2_147_483_647)}::integer for ${Math.ceil((WINDOW + 6) / 3) * 8}::integer)\n else substring(raw from ${Math.min(start + 1, 2_147_483_647)}::integer for ${WINDOW}::integer) end else null end as window,\n case when kind <> 'string' and structured_bytes <= ${STRUCTURED_BYTES} then value else null end as structured,\n coalesce(kind <> 'string' and structured_bytes > ${STRUCTURED_BYTES}, false) as omitted\n from validated`,\n );\n if (!row) continue;\n const metadata = fromPostgresLosslessJson(row.metadata, row.version) as Record<\n string,\n unknown\n >;\n // Codec decoding can expand JSON escaping (notably NUL/lone surrogates).\n // Keep identities bounded too, without falling back to a different alias.\n for (const [key, budget] of [\n [\"callId\", 4096],\n [\"name\", 1024],\n ] as const) {\n if (\n metadata[key] !== undefined &&\n Buffer.byteLength(JSON.stringify(metadata[key]), \"utf8\") > budget\n ) {\n delete metadata[key];\n metadata.identityOmitted = true;\n }\n }\n let text = row.window ?? \"\";\n if (row.tagged) {\n // Window lengths are multiples of eight, so each partial block is also\n // a complete canonical encoding accepted by the existing lossless codec.\n text = fromPostgresLosslessJson(prefix + text, 1);\n const local = start - group * 3;\n if (\n local > 0 &&\n /[\\uD800-\\uDBFF]/.test(text[local - 1]!) &&\n /[\\uDC00-\\uDFFF]/.test(text[local] ?? \"\")\n )\n throw new Error(\"Invalid message continuation offset: splits a surrogate pair\");\n text = text.slice(local, local + WINDOW);\n if (start + text.length < row.total && /[\\uD800-\\uDBFF]/.test(text.at(-1)!))\n text = text.slice(0, -1);\n }\n if (start > row.total && row.kind === \"string\")\n throw new Error(\"Invalid message continuation offset\");\n const logical = row.omitted\n ? {}\n : row.kind === \"string\"\n ? text\n : fromPostgresLosslessJson(row.structured, row.version);\n let payload: Record<string, unknown> = { ...metadata };\n if (options.view === \"tools\") {\n if (row.kind !== null) payload[output ? \"output\" : \"arguments\"] = logical;\n } else if (options.view === \"results\") {\n if (event.type === \"turn.completed\") payload.output = logical;\n else payload = (logical as Record<string, unknown>) ?? {};\n } else payload.text = logical;\n if (row.omitted) payload = { ...payload, sourceOmitted: true };\n if (row.kind === \"string\" || row.omitted)\n slices[event.sequence] = {\n offset: start,\n total: row.total,\n unit: row.tagged ? \"utf16\" : \"codepoint\",\n text,\n omitted: row.omitted,\n };\n events.push({ ...event, payload });\n // One large structured value preserves the previous bounded JSON path,\n // without accumulating several megabyte-sized values in one source page.\n if (row.kind !== \"string\" && Buffer.byteLength(JSON.stringify(payload)) > WINDOW) break;\n if (\n row.kind === \"string\" &&\n start + (row.tagged ? text.length : Array.from(text).length) < row.total\n )\n break;\n }\n });\n // Preserve scan advancement even when every identity was excluded above.\n return {\n ...page,\n events: events.sort((a, b) => a.sequence - b.sequence),\n hasMore: page.hasMore || consumed < ordered.length,\n coveredSequence: consumed\n ? {\n first: Math.min(ordered[0]!.sequence, ordered[consumed - 1]!.sequence),\n last: Math.max(ordered[0]!.sequence, ordered[consumed - 1]!.sequence),\n }\n : null,\n bytes: Buffer.byteLength(JSON.stringify(events), \"utf8\"),\n fullPayloadsExact: !Object.values(slices).some((slice) => slice.omitted),\n slices,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,KAAK,KAAK,MAAM,IAAI,IAAI,SAAS,IAAI,YAAY,WAAqB;AAC/E,SAAS,sCAAyD;AAyBlE,IAAM,SAAS;AACf,IAAM,mBAAm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b;AAAA,MACE,OAAO,KAAK,IAAI,QAAQ,CAAC,EAAG,UAAU,QAAQ,WAAW,CAAC,EAAG,QAAQ;AAAA,MACrE,MAAM,KAAK,IAAI,QAAQ,CAAC,EAAG,UAAU,QAAQ,WAAW,CAAC,EAAG,QAAQ;AAAA,IACtE,IACA;AAAA,IACJ,OAAO,OAAO,WAAW,KAAK,UAAU,MAAM,GAAG,MAAM;AAAA,IACvD,mBAAmB,CAAC,OAAO,OAAO,MAAM,EAAE,KAAK,CAAC,UAAU,MAAM,OAAO;AAAA,IACvE;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FileAsset, ResourceRef, SessionAuthorizationActor } from "@opengeni/contracts";
|
|
2
|
+
import { type Database } from "./database.js";
|
|
3
|
+
/** Only call during verified human initial/Send/Steer acceptance, in its transaction. */
|
|
4
|
+
export declare function acceptSessionFileAttachments(db: Database, input: {
|
|
5
|
+
accountId: string;
|
|
6
|
+
workspaceId: string;
|
|
7
|
+
sessionId: string;
|
|
8
|
+
turnId: string;
|
|
9
|
+
subjectId: string;
|
|
10
|
+
resources: ResourceRef[];
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
export type SessionAttachmentReadAccess = {
|
|
13
|
+
sessionId: string;
|
|
14
|
+
authorityEpoch: number;
|
|
15
|
+
actor: Pick<SessionAuthorizationActor, "kind" | "subjectId"> & Partial<{
|
|
16
|
+
callerSessionId: string;
|
|
17
|
+
turnId: string;
|
|
18
|
+
attemptId: string;
|
|
19
|
+
executionGeneration: number;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
/** Core must prove session authorization; workers supply their live own-session attempt. */
|
|
23
|
+
export declare function readSessionFileAttachments(db: Database, input: {
|
|
24
|
+
accountId: string;
|
|
25
|
+
workspaceId: string;
|
|
26
|
+
fileIds: readonly string[];
|
|
27
|
+
access: SessionAttachmentReadAccess;
|
|
28
|
+
}): Promise<FileAsset[]>;
|