@opengeni/db 0.36.1 → 3.1.0-canary.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/attached-browser-devices.d.ts +7 -0
- package/dist/automations.d.ts +154 -0
- package/dist/canonical-human-identities.js +3 -3
- package/dist/capability-integrations.d.ts +13 -0
- package/dist/child-lifecycle-notices.d.ts +68 -0
- package/dist/{chunk-GYO7ED2Q.js → chunk-EULAN2NP.js} +2 -2
- package/dist/{chunk-VTPRIXKG.js → chunk-NJVZPWXY.js} +3 -3
- package/dist/{chunk-HSOWSYOX.js → chunk-NMUBV7Z5.js} +19 -11
- package/dist/chunk-NMUBV7Z5.js.map +1 -0
- package/dist/chunk-OF5OBB76.js +4457 -0
- package/dist/chunk-OF5OBB76.js.map +1 -0
- package/dist/{chunk-5KTIEDX7.js → chunk-PR2WMLOQ.js} +7714 -4443
- package/dist/chunk-PR2WMLOQ.js.map +1 -0
- package/dist/{chunk-Z7VYMNPZ.js → chunk-SCPUJS53.js} +41 -4
- package/dist/chunk-SCPUJS53.js.map +1 -0
- package/dist/{chunk-SK7YYHBI.js → chunk-SIBYBA2D.js} +46 -1
- package/dist/chunk-SIBYBA2D.js.map +1 -0
- package/dist/chunk-TIKF3KTI.js +383 -0
- package/dist/chunk-TIKF3KTI.js.map +1 -0
- package/dist/chunk-ZZ5LJEFX.js +516 -0
- package/dist/chunk-ZZ5LJEFX.js.map +1 -0
- package/dist/codemode-operations.d.ts +1 -6
- package/dist/company-brain-context-selection-schema.d.ts +705 -0
- package/dist/company-brain-context-selection.d.ts +94 -0
- package/dist/company-brain-governed-writes.d.ts +24 -0
- package/dist/company-brain.d.ts +55 -0
- package/dist/company-profile-agent-admin.d.ts +15 -0
- package/dist/company-profile-schema.d.ts +619 -2
- package/dist/company-profile.d.ts +9 -4
- package/dist/connection-authority.d.ts +95 -0
- package/dist/connection-scopes.d.ts +8 -0
- package/dist/connection-tenancy-backfill.d.ts +41 -0
- package/dist/connection-token-resolver.d.ts +30 -1
- package/dist/database.d.ts +19 -0
- package/dist/editable-artifact-durable-export.d.ts +10 -0
- package/dist/editable-artifact-durable-export.js +18 -3
- package/dist/editable-artifact-durable-export.js.map +1 -1
- package/dist/editable-artifacts.d.ts +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/governed-learning-activation-schema.d.ts +984 -0
- package/dist/governed-learning-activation.d.ts +98 -0
- package/dist/governed-learning-evaluator-schema.d.ts +633 -0
- package/dist/governed-learning-evaluator.d.ts +28 -0
- package/dist/index.d.ts +1633 -87
- package/dist/index.js +22004 -8109
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +18 -0
- package/dist/integration-bindings.d.ts +1 -0
- package/dist/integration-facets.d.ts +30 -0
- package/dist/interaction-placement-loss.d.ts +22 -0
- package/dist/knowledge-source-sync-schema.d.ts +730 -0
- package/dist/knowledge-source-sync.d.ts +60 -0
- package/dist/managed-human-provisioning.d.ts +25 -0
- package/dist/memory-domain.d.ts +3 -3
- package/dist/migrate.d.ts +11 -1
- package/dist/migrate.js +1 -1
- package/dist/new-session-drafts.d.ts +43 -5
- package/dist/organization-membership-backfill.d.ts +174 -0
- package/dist/organization-membership-lifecycle.d.ts +162 -0
- package/dist/pr-review.d.ts +107 -0
- package/dist/preference-registry-schema.d.ts +2 -0
- package/dist/preference-registry.d.ts +2 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +23 -9
- package/dist/schema.d.ts +24925 -13697
- package/dist/schema.js +103 -1
- package/dist/scoped-knowledge-schema.d.ts +52 -1
- package/dist/session-background-commands.d.ts +125 -0
- package/dist/session-background-commands.js +34 -0
- package/dist/session-background-commands.js.map +1 -0
- package/dist/session-control.d.ts +156 -3
- package/dist/session-goal-pacing.d.ts +68 -0
- package/dist/session-queue-commands.d.ts +42 -5
- package/dist/session-realtime-ledger.d.ts +3 -0
- package/dist/session-tenancy.d.ts +71 -1
- package/dist/session-tenancy.js +25 -3
- package/dist/session-tool-call-settlement.d.ts +9 -4
- package/dist/slack-routing-personal-workspace.d.ts +23 -0
- package/dist/slack-routing.d.ts +153 -0
- package/dist/slack-task-policy-schema.d.ts +34 -0
- package/dist/slack-task-policy.d.ts +8 -0
- package/dist/slack-user-link-access.d.ts +1 -0
- package/dist/task-notes-schema.d.ts +594 -0
- package/dist/task-notes.d.ts +39 -0
- package/dist/turn-initiator.d.ts +2 -0
- package/dist/user-resource-authority.d.ts +109 -0
- package/dist/video-generation.js +3 -3
- package/dist/workspace-authority.d.ts +81 -0
- package/dist/workspace-instruction-policies-schema.d.ts +279 -0
- package/dist/workspace-instruction-policies.d.ts +62 -0
- package/dist/workspace-learning-policy.d.ts +1 -0
- package/dist/workspace-membership-permissions.d.ts +2 -0
- package/drizzle/0240_enrollment_connection_authority.sql +39 -0
- package/drizzle/0240_model_context_user_messages.sql +204 -0
- package/drizzle/0241_atomic_personal_resource_delegation.sql +1000 -0
- package/drizzle/0241_enrollment_agent_runtime.sql +70 -0
- package/drizzle/0243_google_drive_object_acl_authority.sql +554 -0
- package/drizzle/0244_slack_app_home_refresh_queue.sql +120 -0
- package/drizzle/0245_model_context_contribution_facts.sql +88 -0
- package/drizzle/0246_integration_personal_instance_authority.sql +70 -0
- package/drizzle/0247_terraform_stacks_provenance_repair.sql +428 -0
- package/drizzle/0248_terraform_stacks_component_resolution_fence.sql +83 -0
- package/drizzle/0249_personal_resource_delegation_authority_correction.sql +662 -0
- package/drizzle/0250_direct_retained_process_owner_liveness.sql +199 -0
- package/drizzle/0251_connected_machine_operation_policy.sql +45 -0
- package/drizzle/0252_scheduled_personal_resource_delegation.sql +1867 -0
- package/drizzle/0253_common_user_resource_authority_lifecycle.sql +1555 -0
- package/drizzle/0254_scoped_variable_set_authority.sql +1255 -0
- package/drizzle/0255_company_brain_governed_write_proposals.sql +524 -0
- package/drizzle/0256_connection_authority_delegation.sql +703 -0
- package/drizzle/0257_goal_revision_decisions_and_root_constraints.sql +436 -0
- package/drizzle/0258_three_scope_document_knowledge_authority.sql +1273 -0
- package/drizzle/0259_company_brain_context_selection_receipts.sql +869 -0
- package/drizzle/0260_task_note_knowledge_promotion.sql +820 -0
- package/drizzle/0261_preference_knowledge_proposal_actor_binding.sql +471 -0
- package/drizzle/0262_scoped_connected_machines_and_rigs.sql +1700 -0
- package/drizzle/0263_organization_membership_lifecycle.sql +3284 -0
- package/drizzle/0264_connection_authority_runtime_activation.sql +1084 -0
- package/drizzle/0266_company_brain_context_receipt_inspection.sql +156 -0
- package/drizzle/0268_governed_learning_decision_receipts.sql +825 -0
- package/drizzle/0269_governed_learning_activation_controller.sql +1874 -0
- package/drizzle/0270_governed_learning_history_inspection.sql +170 -0
- package/drizzle/0271_company_brain_retrieval_only_default.sql +524 -0
- package/drizzle/0272_human_confirmed_learning_activation.sql +591 -0
- package/drizzle/0273_scheduled_variable_set_materialization.sql +268 -0
- package/drizzle/0274_human_confirmed_knowledge_review.sql +310 -0
- package/drizzle/0275_scheduled_connection_authority.sql +5527 -0
- package/drizzle/0276_onboarding_proposal_initiating_human_guc.sql +198 -0
- package/drizzle/0277_workspace_writer_authority_attribution.sql +393 -0
- package/drizzle/0278_workspace_membership_removal_fencing.sql +1174 -0
- package/drizzle/0279_workspace_connection_use_lane.sql +343 -0
- package/drizzle/0280_connection_and_variable_set_audit_attribution.sql +773 -0
- package/drizzle/0281_viewer_holder_authority_claims.sql +52 -0
- package/drizzle/0282_variable_set_session_attach_attribution.sql +178 -0
- package/drizzle/0283_editable_spreadsheet_authored_state.sql +82 -0
- package/drizzle/0284_truthful_human_confirmed_review_reason.sql +930 -0
- package/drizzle/0285_organization_tenancy_inventory.sql +329 -0
- package/drizzle/0286_widen_task_note_expiry_ceiling.sql +391 -0
- package/drizzle/0287_open_suffix_pending_tool_calls.sql +18 -0
- package/drizzle/0288_attached_browser_reenrollment.sql +64 -0
- package/drizzle/0289_session_composer_policy_authority.sql +597 -0
- package/drizzle/0290_organization_membership_backfill.sql +268 -0
- package/drizzle/0291_resource_authority_classification_assertion.sql +371 -0
- package/drizzle/0292_truthful_tenancy_inventory_counters.sql +291 -0
- package/drizzle/0293_confirm_time_rule_rebaseline.sql +615 -0
- package/drizzle/0294_preference_activation_authority.sql +237 -0
- package/drizzle/0295_retire_legacy_standing_memory_mode.sql +476 -0
- package/drizzle/0296_force_rls_backfill_noop_repair.sql +215 -0
- package/drizzle/0297_session_ownership_classification_and_backfill.sql +752 -0
- package/drizzle/0298_organization_tenancy_parity.sql +609 -0
- package/drizzle/0299_organization_membership_lock_order.sql +291 -0
- package/drizzle/0300_tenancy_backfill_ledger.sql +459 -0
- package/drizzle/0301_session_snapshot_and_pin_visibility.sql +181 -0
- package/drizzle/0302_personal_workspace_session_ownership.sql +303 -0
- package/drizzle/0303_session_tenancy_product_activation.sql +919 -0
- package/drizzle/0304_personal_workspace_private_session_reads.sql +97 -0
- package/drizzle/0305_personal_resource_grant_management.sql +584 -0
- package/drizzle/0306_atomic_personal_resource_attachments.sql +1374 -0
- package/drizzle/0307_session_attention_state.sql +51 -0
- package/drizzle/0308_session_archives.sql +35 -0
- package/drizzle/0309_channel_project_pins.sql +6 -0
- package/drizzle/0310_channel_project_order.sql +27 -0
- package/drizzle/0311_company_scope_and_private_session_create.sql +656 -0
- package/drizzle/0312_quiescent_session_tree_deletion.sql +39 -0
- package/drizzle/0313_private_child_session_authority.sql +365 -0
- package/drizzle/0314_unregistered_organization_invitations.sql +606 -0
- package/drizzle/0315_personal_github_repository_selection.sql +624 -0
- package/drizzle/0316_human_confirmed_activation_resumed_generation.sql +869 -0
- package/drizzle/0317_session_goal_continuation_hold.sql +64 -0
- package/drizzle/0318_session_turn_startup_milestones.sql +115 -0
- package/drizzle/0319_event_triggered_automations.sql +254 -0
- package/drizzle/0320_pr_review_pack.sql +113 -0
- package/drizzle/0321_slack_bot_environment_display_name.sql +15 -0
- package/drizzle/0322_session_turns_unclaimed_prompt_trigger_index.sql +5 -0
- package/drizzle/0323_organization_private_session_enablement.sql +489 -0
- package/drizzle/0324_human_confirmed_company_profile_agent_admin.sql +856 -0
- package/drizzle/0325_child_lifecycle_notices.sql +44 -0
- package/drizzle/0326_interaction_operation_error_codes.sql +62 -0
- package/drizzle/0327_slack_first_task_hint.sql +29 -0
- package/drizzle/0328_session_background_commands.sql +590 -0
- package/drizzle/0329_slack_orchestration_delivery_events.sql +91 -0
- package/drizzle/0330_api_key_descriptions.sql +20 -0
- package/drizzle/0331_managed_organization_creation.sql +163 -0
- package/drizzle/0332_organization_shared_workspace_control_plane.sql +539 -0
- package/drizzle/0333_session_turn_prompt_routing.sql +45 -0
- package/drizzle/0334_connected_machine_workspace_root.sql +99 -0
- package/drizzle/0335_slack_workspace_routing.sql +460 -0
- package/drizzle/0336_atomic_session_fork_visibility.sql +667 -0
- package/drizzle/0337_slack_routed_action_handles.sql +189 -0
- package/drizzle/0338_atomic_connected_machine_attachments.sql +410 -0
- package/drizzle/0339_document_authority_reclassification.sql +1153 -0
- package/drizzle/0340_tenancy_backfill_activation_evidence.sql +1347 -0
- package/drizzle/0341_slack_routing_probe_organization_fence.sql +109 -0
- package/package.json +10 -6
- package/src/attached-browser-devices.ts +233 -5
- package/src/automations.ts +911 -0
- package/src/browser-sessions.ts +10 -0
- package/src/capability-integrations.ts +175 -1
- package/src/child-lifecycle-notices.ts +241 -0
- package/src/codemode-operations.ts +1 -35
- package/src/company-brain-context-selection-schema.ts +100 -0
- package/src/company-brain-context-selection.ts +359 -0
- package/src/company-brain-governed-writes.ts +1170 -0
- package/src/company-brain.ts +309 -0
- package/src/company-profile-agent-admin.ts +225 -0
- package/src/company-profile-schema.ts +121 -1
- package/src/company-profile.ts +21 -0
- package/src/computer-sessions.ts +10 -1
- package/src/connection-authority.ts +290 -0
- package/src/connection-scopes.ts +20 -0
- package/src/connection-tenancy-backfill.ts +81 -0
- package/src/connection-token-resolver.ts +263 -31
- package/src/database.ts +75 -2
- package/src/editable-artifact-durable-export.ts +27 -0
- package/src/editable-artifacts-schema.ts +10 -5
- package/src/editable-artifacts.ts +21 -11
- package/src/governed-learning-activation-schema.ts +121 -0
- package/src/governed-learning-activation.ts +588 -0
- package/src/governed-learning-evaluator-schema.ts +72 -0
- package/src/governed-learning-evaluator.ts +217 -0
- package/src/index.ts +12001 -1699
- package/src/insights.ts +107 -0
- package/src/integration-bindings.ts +88 -6
- package/src/integration-facets.ts +287 -84
- package/src/interaction-placement-loss.ts +234 -0
- package/src/knowledge-source-sync-schema.ts +83 -0
- package/src/knowledge-source-sync.ts +530 -0
- package/src/managed-human-provisioning.ts +116 -0
- package/src/memory-domain.ts +27 -32
- package/src/migrate.ts +77 -1
- package/src/new-session-drafts.ts +229 -35
- package/src/organization-membership-backfill.ts +735 -0
- package/src/organization-membership-lifecycle.ts +985 -0
- package/src/pr-review.ts +890 -0
- package/src/preference-registry.ts +31 -1
- package/src/provision-roles.ts +931 -24
- package/src/runtime-posture-cli.ts +2 -0
- package/src/runtime-posture.ts +1315 -52
- package/src/schema.ts +3336 -438
- package/src/scoped-knowledge-schema.ts +16 -8
- package/src/scoped-knowledge.ts +1 -1
- package/src/session-background-commands.ts +759 -0
- package/src/session-control.ts +640 -74
- package/src/session-goal-pacing.ts +126 -0
- package/src/session-queue-commands.ts +450 -98
- package/src/session-realtime-context.ts +19 -3
- package/src/session-realtime-ledger.ts +75 -12
- package/src/session-realtime-mirror.ts +1 -1
- package/src/session-tenancy.ts +403 -49
- package/src/session-tool-call-settlement.ts +38 -29
- package/src/slack-routing-personal-workspace.ts +67 -0
- package/src/slack-routing.ts +469 -0
- package/src/slack-task-policy-schema.ts +5 -0
- package/src/slack-task-policy.ts +18 -0
- package/src/slack-user-link-access.ts +17 -1
- package/src/task-notes-schema.ts +74 -0
- package/src/task-notes.ts +124 -2
- package/src/turn-initiator.ts +8 -0
- package/src/user-resource-authority.ts +377 -0
- package/src/workspace-authority.ts +160 -0
- package/src/workspace-instruction-policies-schema.ts +53 -1
- package/src/workspace-instruction-policies.ts +528 -77
- package/src/workspace-learning-policy.ts +21 -5
- package/src/workspace-membership-permissions.ts +9 -0
- package/dist/chunk-5KTIEDX7.js.map +0 -1
- package/dist/chunk-FPVAD4CO.js +0 -117
- package/dist/chunk-FPVAD4CO.js.map +0 -1
- package/dist/chunk-HSOWSYOX.js.map +0 -1
- package/dist/chunk-SK7YYHBI.js.map +0 -1
- package/dist/chunk-VKLB2ZGI.js +0 -2389
- package/dist/chunk-VKLB2ZGI.js.map +0 -1
- package/dist/chunk-Z7VYMNPZ.js.map +0 -1
- /package/dist/{chunk-GYO7ED2Q.js.map → chunk-EULAN2NP.js.map} +0 -0
- /package/dist/{chunk-VTPRIXKG.js.map → chunk-NJVZPWXY.js.map} +0 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
2
|
+
import { type Database, withRlsContext } from "./database";
|
|
3
|
+
import {
|
|
4
|
+
advanceWorkspaceInteractionRevision,
|
|
5
|
+
readWorkspaceInteractionRevision,
|
|
6
|
+
} from "./interaction-revisions";
|
|
7
|
+
import * as schema from "./schema";
|
|
8
|
+
|
|
9
|
+
export const SOURCE_PLACEMENT_CHANGED = "source_placement_changed";
|
|
10
|
+
|
|
11
|
+
const CONNECTED_PLACEMENT_LIVE_LIFECYCLES = [
|
|
12
|
+
"starting",
|
|
13
|
+
"active",
|
|
14
|
+
"suspending",
|
|
15
|
+
"restoring",
|
|
16
|
+
"ending",
|
|
17
|
+
] as const;
|
|
18
|
+
|
|
19
|
+
export type TerminalizeStaleConnectedInteractionPlacementResult = {
|
|
20
|
+
sourcePlacementChanged: boolean;
|
|
21
|
+
changed: boolean;
|
|
22
|
+
browserSessionIds: string[];
|
|
23
|
+
computerSessionIds: string[];
|
|
24
|
+
revision: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Reconcile interaction resources after their source task moves away from a
|
|
29
|
+
* Connected Machine. The source row is the race fence: a stale route lookup
|
|
30
|
+
* may never retire resources while that machine is still the active placement.
|
|
31
|
+
* Browser and Desktop resources are settled together because headed browsers
|
|
32
|
+
* can share one physical controller with a linked Desktop.
|
|
33
|
+
*/
|
|
34
|
+
export async function terminalizeStaleConnectedInteractionPlacement(
|
|
35
|
+
db: Database,
|
|
36
|
+
input: {
|
|
37
|
+
accountId: string;
|
|
38
|
+
workspaceId: string;
|
|
39
|
+
sourceSessionId: string;
|
|
40
|
+
connectedSandboxId: string;
|
|
41
|
+
},
|
|
42
|
+
): Promise<TerminalizeStaleConnectedInteractionPlacementResult> {
|
|
43
|
+
return await withRlsContext(
|
|
44
|
+
db,
|
|
45
|
+
{ accountId: input.accountId, workspaceId: input.workspaceId },
|
|
46
|
+
async (scopedDb) =>
|
|
47
|
+
await scopedDb.transaction(async (tx) => {
|
|
48
|
+
const [source] = await tx
|
|
49
|
+
.select({ activeSandboxId: schema.sessions.activeSandboxId })
|
|
50
|
+
.from(schema.sessions)
|
|
51
|
+
.where(
|
|
52
|
+
and(
|
|
53
|
+
eq(schema.sessions.accountId, input.accountId),
|
|
54
|
+
eq(schema.sessions.workspaceId, input.workspaceId),
|
|
55
|
+
eq(schema.sessions.id, input.sourceSessionId),
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
.for("update")
|
|
59
|
+
.limit(1);
|
|
60
|
+
|
|
61
|
+
const sourcePlacementChanged =
|
|
62
|
+
source !== undefined && source.activeSandboxId !== input.connectedSandboxId;
|
|
63
|
+
if (!sourcePlacementChanged) {
|
|
64
|
+
return {
|
|
65
|
+
sourcePlacementChanged: false,
|
|
66
|
+
changed: false,
|
|
67
|
+
browserSessionIds: [],
|
|
68
|
+
computerSessionIds: [],
|
|
69
|
+
revision: await readWorkspaceInteractionRevision(tx, input.workspaceId),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const browserRows = await tx
|
|
74
|
+
.select({ id: schema.browserSessions.id })
|
|
75
|
+
.from(schema.browserSessions)
|
|
76
|
+
.innerJoin(
|
|
77
|
+
schema.browserSessionAssociations,
|
|
78
|
+
and(
|
|
79
|
+
eq(schema.browserSessionAssociations.browserSessionId, schema.browserSessions.id),
|
|
80
|
+
eq(schema.browserSessionAssociations.workspaceId, input.workspaceId),
|
|
81
|
+
eq(schema.browserSessionAssociations.sessionId, input.sourceSessionId),
|
|
82
|
+
eq(schema.browserSessionAssociations.relationship, "created"),
|
|
83
|
+
),
|
|
84
|
+
)
|
|
85
|
+
.where(
|
|
86
|
+
and(
|
|
87
|
+
eq(schema.browserSessions.accountId, input.accountId),
|
|
88
|
+
eq(schema.browserSessions.workspaceId, input.workspaceId),
|
|
89
|
+
eq(schema.browserSessions.placementKind, "connected_machine"),
|
|
90
|
+
eq(schema.browserSessions.connectedSandboxId, input.connectedSandboxId),
|
|
91
|
+
inArray(schema.browserSessions.lifecycle, [...CONNECTED_PLACEMENT_LIVE_LIFECYCLES]),
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
const computerRows = await tx
|
|
95
|
+
.select({ id: schema.computerSessions.id })
|
|
96
|
+
.from(schema.computerSessions)
|
|
97
|
+
.innerJoin(
|
|
98
|
+
schema.computerSessionAssociations,
|
|
99
|
+
and(
|
|
100
|
+
eq(schema.computerSessionAssociations.computerSessionId, schema.computerSessions.id),
|
|
101
|
+
eq(schema.computerSessionAssociations.workspaceId, input.workspaceId),
|
|
102
|
+
eq(schema.computerSessionAssociations.sessionId, input.sourceSessionId),
|
|
103
|
+
eq(schema.computerSessionAssociations.relationship, "created"),
|
|
104
|
+
),
|
|
105
|
+
)
|
|
106
|
+
.where(
|
|
107
|
+
and(
|
|
108
|
+
eq(schema.computerSessions.accountId, input.accountId),
|
|
109
|
+
eq(schema.computerSessions.workspaceId, input.workspaceId),
|
|
110
|
+
eq(schema.computerSessions.placementKind, "connected_machine"),
|
|
111
|
+
eq(schema.computerSessions.connectedSandboxId, input.connectedSandboxId),
|
|
112
|
+
inArray(schema.computerSessions.lifecycle, [...CONNECTED_PLACEMENT_LIVE_LIFECYCLES]),
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const browserSessionIds = [...new Set(browserRows.map((row) => row.id))].sort();
|
|
117
|
+
const computerSessionIds = [...new Set(computerRows.map((row) => row.id))].sort();
|
|
118
|
+
const resourceIds = [...browserSessionIds, ...computerSessionIds];
|
|
119
|
+
if (resourceIds.length === 0) {
|
|
120
|
+
return {
|
|
121
|
+
sourcePlacementChanged: true,
|
|
122
|
+
changed: false,
|
|
123
|
+
browserSessionIds,
|
|
124
|
+
computerSessionIds,
|
|
125
|
+
revision: await readWorkspaceInteractionRevision(tx, input.workspaceId),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const operationRows = await tx
|
|
130
|
+
.select({ operationId: schema.interactionOperations.operationId })
|
|
131
|
+
.from(schema.interactionOperations)
|
|
132
|
+
.where(
|
|
133
|
+
and(
|
|
134
|
+
eq(schema.interactionOperations.accountId, input.accountId),
|
|
135
|
+
eq(schema.interactionOperations.workspaceId, input.workspaceId),
|
|
136
|
+
inArray(schema.interactionOperations.resourceId, resourceIds),
|
|
137
|
+
inArray(schema.interactionOperations.state, ["prepared", "dispatched"]),
|
|
138
|
+
),
|
|
139
|
+
);
|
|
140
|
+
const operationIds = operationRows.map((row) => row.operationId).sort();
|
|
141
|
+
|
|
142
|
+
// Stable lock order matches the attached-device generation-loss path.
|
|
143
|
+
for (const operationId of operationIds) {
|
|
144
|
+
await tx.execute(sql`
|
|
145
|
+
select operation_id from interaction_operations
|
|
146
|
+
where workspace_id = ${input.workspaceId} and operation_id = ${operationId}
|
|
147
|
+
for update
|
|
148
|
+
`);
|
|
149
|
+
}
|
|
150
|
+
for (const browserSessionId of browserSessionIds) {
|
|
151
|
+
await tx.execute(sql`
|
|
152
|
+
select id from browser_sessions
|
|
153
|
+
where workspace_id = ${input.workspaceId} and id = ${browserSessionId}
|
|
154
|
+
for update
|
|
155
|
+
`);
|
|
156
|
+
}
|
|
157
|
+
for (const computerSessionId of computerSessionIds) {
|
|
158
|
+
await tx.execute(sql`
|
|
159
|
+
select id from computer_sessions
|
|
160
|
+
where workspace_id = ${input.workspaceId} and id = ${computerSessionId}
|
|
161
|
+
for update
|
|
162
|
+
`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const now = new Date();
|
|
166
|
+
if (operationIds.length > 0) {
|
|
167
|
+
await tx
|
|
168
|
+
.update(schema.interactionOperations)
|
|
169
|
+
.set({
|
|
170
|
+
state: "outcome_unknown",
|
|
171
|
+
errorCode: "outcome_unknown",
|
|
172
|
+
errorMessage: "The source task moved to another placement",
|
|
173
|
+
errorRetryable: false,
|
|
174
|
+
errorDetails: { reason: SOURCE_PLACEMENT_CHANGED },
|
|
175
|
+
settledAt: now,
|
|
176
|
+
updatedAt: now,
|
|
177
|
+
})
|
|
178
|
+
.where(
|
|
179
|
+
and(
|
|
180
|
+
eq(schema.interactionOperations.workspaceId, input.workspaceId),
|
|
181
|
+
inArray(schema.interactionOperations.operationId, operationIds),
|
|
182
|
+
inArray(schema.interactionOperations.state, ["prepared", "dispatched"]),
|
|
183
|
+
),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
if (browserSessionIds.length > 0) {
|
|
187
|
+
await tx
|
|
188
|
+
.update(schema.browserSessions)
|
|
189
|
+
.set({
|
|
190
|
+
lifecycle: "lost",
|
|
191
|
+
failureCode: SOURCE_PLACEMENT_CHANGED,
|
|
192
|
+
updatedAt: now,
|
|
193
|
+
})
|
|
194
|
+
.where(
|
|
195
|
+
and(
|
|
196
|
+
eq(schema.browserSessions.workspaceId, input.workspaceId),
|
|
197
|
+
inArray(schema.browserSessions.id, browserSessionIds),
|
|
198
|
+
inArray(schema.browserSessions.lifecycle, [...CONNECTED_PLACEMENT_LIVE_LIFECYCLES]),
|
|
199
|
+
),
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
if (computerSessionIds.length > 0) {
|
|
203
|
+
await tx
|
|
204
|
+
.update(schema.computerSessions)
|
|
205
|
+
.set({
|
|
206
|
+
lifecycle: "lost",
|
|
207
|
+
failureCode: SOURCE_PLACEMENT_CHANGED,
|
|
208
|
+
updatedAt: now,
|
|
209
|
+
})
|
|
210
|
+
.where(
|
|
211
|
+
and(
|
|
212
|
+
eq(schema.computerSessions.workspaceId, input.workspaceId),
|
|
213
|
+
inArray(schema.computerSessions.id, computerSessionIds),
|
|
214
|
+
inArray(schema.computerSessions.lifecycle, [
|
|
215
|
+
...CONNECTED_PLACEMENT_LIVE_LIFECYCLES,
|
|
216
|
+
]),
|
|
217
|
+
),
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
const revision = await advanceWorkspaceInteractionRevision(
|
|
221
|
+
tx,
|
|
222
|
+
input.accountId,
|
|
223
|
+
input.workspaceId,
|
|
224
|
+
);
|
|
225
|
+
return {
|
|
226
|
+
sourcePlacementChanged: true,
|
|
227
|
+
changed: true,
|
|
228
|
+
browserSessionIds,
|
|
229
|
+
computerSessionIds,
|
|
230
|
+
revision,
|
|
231
|
+
};
|
|
232
|
+
}),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
integer,
|
|
6
6
|
jsonb,
|
|
7
7
|
pgTable,
|
|
8
|
+
primaryKey,
|
|
8
9
|
text,
|
|
9
10
|
timestamp,
|
|
10
11
|
uniqueIndex,
|
|
@@ -173,6 +174,7 @@ export const knowledgeSourceSyncIndexObligations = pgTable(
|
|
|
173
174
|
objectLifecycleGeneration: bigint("object_lifecycle_generation", { mode: "number" }).notNull(),
|
|
174
175
|
objectVersionGeneration: bigint("object_version_generation", { mode: "number" }).notNull(),
|
|
175
176
|
citationLocator: jsonb("citation_locator").$type<Record<string, unknown>>().notNull(),
|
|
177
|
+
googleDriveAclEvidenceId: uuid("google_drive_acl_evidence_id"),
|
|
176
178
|
aclEligibility: text("acl_eligibility").notNull().default("pending"),
|
|
177
179
|
status: text("status").notNull().default("pending"),
|
|
178
180
|
failureCode: text("failure_code"),
|
|
@@ -190,3 +192,84 @@ export const knowledgeSourceSyncIndexObligations = pgTable(
|
|
|
190
192
|
),
|
|
191
193
|
}),
|
|
192
194
|
);
|
|
195
|
+
|
|
196
|
+
export const googleDriveObjectAclEvidence = pgTable(
|
|
197
|
+
"google_drive_object_acl_evidence",
|
|
198
|
+
{
|
|
199
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
200
|
+
accountId: uuid("account_id").notNull(),
|
|
201
|
+
workspaceId: uuid("workspace_id").notNull(),
|
|
202
|
+
sourceId: uuid("source_id").notNull(),
|
|
203
|
+
knowledgeSourceObjectId: uuid("knowledge_source_object_id").notNull(),
|
|
204
|
+
knowledgeDocumentVersionId: uuid("knowledge_document_version_id").notNull(),
|
|
205
|
+
documentId: uuid("document_id").notNull(),
|
|
206
|
+
fileId: uuid("file_id").notNull(),
|
|
207
|
+
indexObligationId: uuid("index_obligation_id").notNull(),
|
|
208
|
+
connectionId: uuid("connection_id").notNull(),
|
|
209
|
+
connectionVersion: bigint("connection_version", { mode: "number" }).notNull(),
|
|
210
|
+
sourcePrincipalHash: text("source_principal_hash").notNull(),
|
|
211
|
+
sourceSyncGeneration: bigint("source_sync_generation", { mode: "number" }).notNull(),
|
|
212
|
+
sourceConfigGeneration: bigint("source_config_generation", { mode: "number" }).notNull(),
|
|
213
|
+
sourceLifecycleGeneration: bigint("source_lifecycle_generation", { mode: "number" }).notNull(),
|
|
214
|
+
objectLifecycleGeneration: bigint("object_lifecycle_generation", {
|
|
215
|
+
mode: "number",
|
|
216
|
+
}).notNull(),
|
|
217
|
+
objectVersionGeneration: bigint("object_version_generation", { mode: "number" }).notNull(),
|
|
218
|
+
providerRevision: text("provider_revision"),
|
|
219
|
+
driveId: text("drive_id"),
|
|
220
|
+
aclRevision: text("acl_revision").notNull(),
|
|
221
|
+
aclHash: text("acl_hash").notNull(),
|
|
222
|
+
eligibility: text("eligibility").notNull(),
|
|
223
|
+
observedAt: timestamp("observed_at", { withTimezone: true }).notNull(),
|
|
224
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
225
|
+
citationLocator: jsonb("citation_locator").$type<Record<string, unknown>>().notNull(),
|
|
226
|
+
operationId: text("operation_id").notNull(),
|
|
227
|
+
inputHash: text("input_hash").notNull(),
|
|
228
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
229
|
+
},
|
|
230
|
+
(table) => ({
|
|
231
|
+
obligationOperation: uniqueIndex("google_drive_object_acl_evidence_obligation_uq").on(
|
|
232
|
+
table.indexObligationId,
|
|
233
|
+
table.operationId,
|
|
234
|
+
),
|
|
235
|
+
version: index("google_drive_object_acl_evidence_version_idx").on(
|
|
236
|
+
table.knowledgeDocumentVersionId,
|
|
237
|
+
table.expiresAt,
|
|
238
|
+
table.createdAt,
|
|
239
|
+
),
|
|
240
|
+
file: index("google_drive_object_acl_evidence_file_idx").on(
|
|
241
|
+
table.accountId,
|
|
242
|
+
table.fileId,
|
|
243
|
+
table.expiresAt,
|
|
244
|
+
),
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
export const googleDriveObjectAclPrincipals = pgTable(
|
|
249
|
+
"google_drive_object_acl_principals",
|
|
250
|
+
{
|
|
251
|
+
evidenceId: uuid("evidence_id").notNull(),
|
|
252
|
+
ordinal: integer("ordinal").notNull(),
|
|
253
|
+
accountId: uuid("account_id").notNull(),
|
|
254
|
+
workspaceId: uuid("workspace_id").notNull(),
|
|
255
|
+
principalType: text("principal_type").notNull(),
|
|
256
|
+
permissionIdHash: text("permission_id_hash"),
|
|
257
|
+
emailHash: text("email_hash"),
|
|
258
|
+
domainHash: text("domain_hash"),
|
|
259
|
+
role: text("role").notNull(),
|
|
260
|
+
inherited: boolean("inherited").notNull().default(false),
|
|
261
|
+
allowFileDiscovery: boolean("allow_file_discovery"),
|
|
262
|
+
expirationTime: timestamp("expiration_time", { withTimezone: true }),
|
|
263
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
264
|
+
},
|
|
265
|
+
(table) => ({
|
|
266
|
+
identity: primaryKey({ columns: [table.evidenceId, table.ordinal] }),
|
|
267
|
+
match: index("google_drive_object_acl_principals_match_idx").on(
|
|
268
|
+
table.evidenceId,
|
|
269
|
+
table.principalType,
|
|
270
|
+
table.permissionIdHash,
|
|
271
|
+
table.emailHash,
|
|
272
|
+
table.domainHash,
|
|
273
|
+
),
|
|
274
|
+
}),
|
|
275
|
+
);
|