@opengeni/worker-bundle 0.17.2 → 0.20.1
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/activities/agent-run-admission.d.ts +12 -0
- package/dist/activities/agent-turn.d.ts +49 -1
- package/dist/activities/browser-state-artifact-reaper.d.ts +29 -0
- package/dist/activities/capabilities.d.ts +6 -0
- package/dist/activities/codex-capacity.d.ts +1 -0
- package/dist/activities/environment.d.ts +7 -1
- package/dist/activities/packs.d.ts +8 -10
- package/dist/activities/run-input.d.ts +8 -0
- package/dist/activities/session-state.d.ts +7 -3
- package/dist/activities/site-auth-maintenance.d.ts +27 -0
- package/dist/activities/types.d.ts +43 -0
- package/dist/activities/video-generation-admission.d.ts +9 -4
- package/dist/activities/video-generation-credential.d.ts +17 -0
- package/dist/activities/video-reference-staging.d.ts +7 -1
- package/dist/activities/xai-auth.d.ts +23 -0
- package/dist/activities/xai-image-generation.d.ts +26 -0
- package/dist/activities/xai-video-generation.d.ts +18 -0
- package/dist/{activities-control-44KBWLSM.js → activities-control-SMKF2OBE.js} +438 -55
- package/dist/activities-control-SMKF2OBE.js.map +1 -0
- package/dist/activities-control.d.ts +10 -2
- package/dist/{activities-turn-K4CEDEGJ.js → activities-turn-IDS3WEHA.js} +6704 -4847
- package/dist/activities-turn-IDS3WEHA.js.map +1 -0
- package/dist/activities.d.ts +11 -3
- package/dist/{chunk-E3RI3I33.js → chunk-N5TJIFCE.js} +156 -10
- package/dist/chunk-N5TJIFCE.js.map +1 -0
- package/dist/{chunk-KKCRGAGZ.js → chunk-P6Z2SLAA.js} +99 -98
- package/dist/chunk-P6Z2SLAA.js.map +1 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +49 -2
- package/dist/index.js.map +1 -1
- package/dist/model-checkpoint-memory-collector.d.ts +1 -0
- package/dist/model-context-contributions.d.ts +40 -0
- package/dist/observability-metrics.d.ts +57 -1
- package/dist/sandbox-routing.d.ts +4 -0
- package/dist/workflow-bundle.js +232 -18
- package/dist/workflows/activities.d.ts +1 -1
- package/dist/workflows/session.d.ts +17 -1
- package/dist/workflows/site-auth-maintenance.d.ts +2 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +16 -15
- package/src/activities/agent-run-admission.ts +76 -0
- package/src/activities/agent-turn.ts +2777 -1241
- package/src/activities/browser-state-artifact-reaper.ts +120 -0
- package/src/activities/capabilities.ts +10 -0
- package/src/activities/codex-capacity.ts +48 -1
- package/src/activities/environment.ts +14 -8
- package/src/activities/goals.ts +2 -1
- package/src/activities/packs.ts +45 -122
- package/src/activities/parent-wake.ts +13 -1
- package/src/activities/run-input.ts +137 -45
- package/src/activities/scheduled-tasks.ts +30 -73
- package/src/activities/session-state.ts +87 -5
- package/src/activities/site-auth-maintenance.ts +269 -0
- package/src/activities/types.ts +44 -0
- package/src/activities/video-generation-admission.ts +37 -4
- package/src/activities/video-generation-credential.ts +84 -6
- package/src/activities/video-generation-reconciliation.ts +212 -19
- package/src/activities/video-media-validation.ts +8 -2
- package/src/activities/video-reference-staging.ts +121 -34
- package/src/activities/xai-auth.ts +122 -0
- package/src/activities/xai-image-generation.ts +86 -0
- package/src/activities/xai-video-generation.ts +69 -0
- package/src/activities-control.ts +4 -0
- package/src/activities.ts +7 -0
- package/src/index.ts +51 -0
- package/src/model-checkpoint-memory-collector.ts +8 -1
- package/src/model-context-contributions.ts +159 -0
- package/src/observability-metrics.ts +282 -12
- package/src/sandbox-routing.ts +13 -0
- package/src/workflows/activities.ts +1 -0
- package/src/workflows/file-upload-reaper.ts +8 -2
- package/src/workflows/session.ts +219 -14
- package/src/workflows/site-auth-maintenance.ts +14 -0
- package/src/workflows.ts +1 -0
- package/dist/activities-control-44KBWLSM.js.map +0 -1
- package/dist/activities-turn-K4CEDEGJ.js.map +0 -1
- package/dist/chunk-E3RI3I33.js.map +0 -1
- package/dist/chunk-KKCRGAGZ.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Settings } from "@opengeni/config";
|
|
2
|
+
import type { ControlActivityServices } from "./types.js";
|
|
3
|
+
export type AgentRunAdmissionDenial = "insufficient_credits" | "monthly_model_cost_limit" | "monthly_agent_run_limit";
|
|
4
|
+
/** One worker-side admission boundary for service-authored agent runs. */
|
|
5
|
+
export declare function agentRunAdmissionDenial(services: Pick<ControlActivityServices, "db" | "entitlements"> & {
|
|
6
|
+
settings: Settings;
|
|
7
|
+
}, input: {
|
|
8
|
+
accountId: string;
|
|
9
|
+
workspaceId: string;
|
|
10
|
+
model: string;
|
|
11
|
+
requestedAgentRuns: number;
|
|
12
|
+
}): Promise<AgentRunAdmissionDenial | null>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AppendEventInput, type ActiveSandboxPointer, type SandboxRecord, type SessionAttemptQuiescenceCommit } from "@opengeni/db";
|
|
2
|
-
import { modelResponseServiceTierFromSdkEvent, modelTerminalResponseFromSdkEvent, type SandboxFileDownload, type ComputerToolMode, type ModelResponseUsage, type ModelCallUsageInput, type ModelCallUsageNormalization, type TurnToolCancellationFence, type BackendUnresolvableCode, type LazyToolTransport } from "@opengeni/runtime";
|
|
2
|
+
import { modelResponseServiceTierFromSdkEvent, modelTerminalResponseFromSdkEvent, type SandboxFileDownload, type SandboxFileDownloadFailure, type ComputerToolMode, type ModelResponseUsage, type ModelCallUsageInput, type ModelCallUsageNormalization, type TurnToolCancellationFence, type BackendUnresolvableCode, type LazyToolTransport } from "@opengeni/runtime";
|
|
3
3
|
import { resolveTurnExecutionPolicyV1, type ModelUsageInput, type ModelProviderApi, type RegistryProviderKind, type Settings } from "@opengeni/config";
|
|
4
4
|
import { ApplicationFailure, CancelledFailure } from "@temporalio/activity";
|
|
5
5
|
import type { CodexAccountStatus } from "@opengeni/db";
|
|
@@ -9,6 +9,7 @@ import { type CodemodeTokenRenewalController } from "./codemode-token-renewal.js
|
|
|
9
9
|
import { type ModelAttachmentInputPolicy } from "./run-input.js";
|
|
10
10
|
import type { TurnActivityServices as ActivityServices, EscapedMcpTimeoutRecoveryDetail, RunAgentTurnInput, RunAgentTurnResult, SessionAttemptQuiescenceProof } from "./types.js";
|
|
11
11
|
import { type ResumedTurnSandbox, type TurnSandboxLeaseHolderId } from "../sandbox-resume.js";
|
|
12
|
+
import { type TurnSandboxEstablishReason } from "../observability-metrics.js";
|
|
12
13
|
import { type LatencyMode, type SessionEvent, type SessionEventType, type SessionTurn, type ToolAuthNeededPayload, type TurnExecutionPolicyV1 } from "@opengeni/contracts";
|
|
13
14
|
export declare const PROVIDER_BACKPRESSURE_DELAY_MS = 60000;
|
|
14
15
|
export declare class WorkspaceHumanInputDisabledError extends Error {
|
|
@@ -35,6 +36,7 @@ export declare function shouldPublishToolAuthNeededForTurn(payload: Pick<ToolAut
|
|
|
35
36
|
export declare function turnExecutionPolicyBillingIdentity(policy: TurnExecutionPolicyV1): {
|
|
36
37
|
externallyBilled: boolean;
|
|
37
38
|
codexSubscription: boolean;
|
|
39
|
+
xaiSubscription: boolean;
|
|
38
40
|
};
|
|
39
41
|
export declare function legacyTurnExecutionPolicyInput(turn: Pick<SessionTurn, "source" | "model" | "reasoningEffort" | "latencyMode">): Parameters<typeof resolveTurnExecutionPolicyV1>[1];
|
|
40
42
|
/** A retryable provider fault recovers the accepted turn itself. Goal state is
|
|
@@ -74,6 +76,16 @@ export declare function escapedMcpTimeoutRecoveryFailure(input: {
|
|
|
74
76
|
modelRequestStarted: boolean;
|
|
75
77
|
detail: EscapedMcpTimeoutRecoveryDetail;
|
|
76
78
|
}): ApplicationFailure | null;
|
|
79
|
+
/**
|
|
80
|
+
* Convert the atomic claim transaction's failure into a small, stable
|
|
81
|
+
* Temporal wire contract. The original error remains in activity diagnostics,
|
|
82
|
+
* but SQL text, parameters, and arbitrary invariant messages never enter
|
|
83
|
+
* workflow history. Contention and operational database unavailability are
|
|
84
|
+
* safe to re-read after backoff because the claim transaction contains no
|
|
85
|
+
* model/tool effects; permanent database and state failures require terminal
|
|
86
|
+
* settlement.
|
|
87
|
+
*/
|
|
88
|
+
export declare function preClaimAdmissionFailure(error: unknown): ApplicationFailure;
|
|
77
89
|
/**
|
|
78
90
|
* Resolve which Codex account a turn runs on (multi-account P1): session-pin >
|
|
79
91
|
* workspace-active. No rotation in P1. The selected id must still be in the
|
|
@@ -87,10 +99,13 @@ export declare function selectCodexCredentialForTurn(args: {
|
|
|
87
99
|
connectedIds: Set<string>;
|
|
88
100
|
}): string | null;
|
|
89
101
|
export declare function filterUnmaterializedSandboxFileDownloads(downloads: SandboxFileDownload[], materializedFileIds: Set<string>): SandboxFileDownload[];
|
|
102
|
+
export declare function sandboxFileMaterializationOutcome(failures: readonly SandboxFileDownloadFailure[]): "completed" | "failed";
|
|
90
103
|
/** Fixed-length one-way tenant correlation for metrics/alerts; never a raw id. */
|
|
91
104
|
export declare function codexWorkspaceMetricKey(workspaceId: string): string;
|
|
92
105
|
/** Stable public request identity across partial resumes and activity retries. */
|
|
93
106
|
export declare function stableHumanInputRequestId(sessionId: string, turnId: string, toolCallId: string): string;
|
|
107
|
+
export declare function stableInteractionInterventionId(sessionId: string, turnId: string, toolCallId: string): string;
|
|
108
|
+
export declare function stableInteractionInterventionOperationId(sessionId: string, turnId: string, toolCallId: string): string;
|
|
94
109
|
/**
|
|
95
110
|
* True when this activity attempt was cancelled because its hosting worker is
|
|
96
111
|
* shutting down gracefully (SIGTERM during a deploy), as opposed to a
|
|
@@ -506,6 +521,19 @@ export declare function managedSandboxOwnershipForTurn(machinePrimary: boolean,
|
|
|
506
521
|
holderId: TurnSandboxLeaseHolderId;
|
|
507
522
|
sandboxGroupId: string;
|
|
508
523
|
} | null;
|
|
524
|
+
/** A sandboxless home still establishes an explicitly attached Connected Machine. */
|
|
525
|
+
export declare function shouldEstablishSandboxForTurn(sandboxOwnershipEnabled: boolean, homeBackend: Settings["sandboxBackend"], machinePrimary: boolean): boolean;
|
|
526
|
+
export declare function sandboxEstablishPolicyDecision(input: {
|
|
527
|
+
lazyEnabled: boolean;
|
|
528
|
+
machinePrimary: boolean;
|
|
529
|
+
sandboxBackend: Settings["sandboxBackend"];
|
|
530
|
+
hasInitialRunCredentialMaterial: boolean;
|
|
531
|
+
generatedVideoFileCount: number;
|
|
532
|
+
hasSignedFileResources: boolean;
|
|
533
|
+
}): {
|
|
534
|
+
policy: "eager" | "on-demand";
|
|
535
|
+
reason: TurnSandboxEstablishReason;
|
|
536
|
+
};
|
|
509
537
|
/**
|
|
510
538
|
* Classify a persisted active-sandbox pointer for TURN-START RECONCILE (issue #341
|
|
511
539
|
* invariant B). Returns the typed reason to RESET the pointer to the session HOME,
|
|
@@ -680,6 +708,16 @@ export declare function hostedWebSearchForTurn(resolvedModel: {
|
|
|
680
708
|
hostedWebSearch: boolean;
|
|
681
709
|
};
|
|
682
710
|
} | null, deploymentWebSearchEnabled: boolean): boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Image generation is an optional connected-account capability. A delegated
|
|
713
|
+
* subscription may still authorize the text model without carrying the local
|
|
714
|
+
* credential identity required for paid image operations; that must narrow the
|
|
715
|
+
* tool catalog, not reject an otherwise valid turn.
|
|
716
|
+
*/
|
|
717
|
+
export declare function connectedSubscriptionImageGenerationAuthority<T>(credentialContext: T | null | undefined, credentialId: string | null | undefined): {
|
|
718
|
+
credentialContext: T;
|
|
719
|
+
credentialId: string;
|
|
720
|
+
} | null;
|
|
683
721
|
/** Direct OpenAI hosted image IDs are reusable only by the exact API credential. */
|
|
684
722
|
export declare function openAiHostedImageProviderBindingForTurn(settings: Pick<Settings, "openaiProvider" | "openaiApiKey" | "openaiBaseUrl">, resolvedModel: {
|
|
685
723
|
provider: {
|
|
@@ -793,6 +831,16 @@ type OpStreamFinalizer = {
|
|
|
793
831
|
export declare function finalizeDurableTurnOpStreams(sessions: readonly unknown[], fallback: OpStreamFinalizer | null): Promise<void>;
|
|
794
832
|
export declare function createRunAgentTurnActivity(services: () => Promise<ActivityServices>): (input: RunAgentTurnInput) => Promise<RunAgentTurnResult>;
|
|
795
833
|
export declare function isTransientProviderError(error: unknown): boolean;
|
|
834
|
+
export type XaiCredentialFailure = {
|
|
835
|
+
kind: "auth" | "forbidden" | "rate_limit";
|
|
836
|
+
cooldownMs: number | null;
|
|
837
|
+
};
|
|
838
|
+
/**
|
|
839
|
+
* Only definitive SuperGrok account refusals may move the same logical turn to
|
|
840
|
+
* another credential. The marked transport response proves inference was
|
|
841
|
+
* rejected before a stream began; refresh relogin is equally definitive.
|
|
842
|
+
*/
|
|
843
|
+
export declare function classifyXaiCredentialFailure(error: unknown): XaiCredentialFailure | null;
|
|
796
844
|
export declare function agentRunFailurePayload(error: unknown, options?: {
|
|
797
845
|
isCodexTurn?: boolean;
|
|
798
846
|
}): {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { claimBrowserStateArtifactCleanup, claimBrowserStateUploadCleanup, completeBrowserStateArtifactCleanup, completeBrowserStateUploadCleanup, type BrowserStateArtifactCleanupClaim, type BrowserStateUploadCleanupClaim } from "@opengeni/db";
|
|
2
|
+
import type { ObjectStorage } from "@opengeni/storage";
|
|
3
|
+
import type { ControlActivityServices } from "./types.js";
|
|
4
|
+
export declare const BROWSER_STATE_ARTIFACT_CLAIM_TIMEOUT_MS: number;
|
|
5
|
+
export declare const BROWSER_STATE_ARTIFACT_CLEANUP_BATCH_SIZE = 100;
|
|
6
|
+
export type MaintainBrowserStateArtifactsResult = {
|
|
7
|
+
claimed: number;
|
|
8
|
+
deleted: number;
|
|
9
|
+
retryable: number;
|
|
10
|
+
};
|
|
11
|
+
export type BrowserStateArtifactMaintenanceOptions = {
|
|
12
|
+
claimTimeoutMs?: number;
|
|
13
|
+
batchSize?: number;
|
|
14
|
+
claimArtifacts?: typeof claimBrowserStateArtifactCleanup;
|
|
15
|
+
completeArtifact?: typeof completeBrowserStateArtifactCleanup;
|
|
16
|
+
claimUploads?: typeof claimBrowserStateUploadCleanup;
|
|
17
|
+
completeUpload?: typeof completeBrowserStateUploadCleanup;
|
|
18
|
+
/** Failure-injection seam; production uses the configured provider delete. */
|
|
19
|
+
deleteObject?: (storage: ObjectStorage, key: string) => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Reap retired encrypted private browser checkpoints. Provider deletion happens
|
|
23
|
+
* before terminal settlement; a crash or provider failure leaves the durable
|
|
24
|
+
* claim reclaimable and an already-deleted provider key is safe to retry.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createBrowserStateArtifactMaintenanceActivities(services: () => Promise<ControlActivityServices>, options?: BrowserStateArtifactMaintenanceOptions): {
|
|
27
|
+
maintainBrowserStateArtifacts: () => Promise<MaintainBrowserStateArtifactsResult>;
|
|
28
|
+
};
|
|
29
|
+
export type { BrowserStateArtifactCleanupClaim, BrowserStateUploadCleanupClaim };
|
|
@@ -16,4 +16,10 @@ export declare function settingsWithSessionMcpServers(settings: Settings, server
|
|
|
16
16
|
export declare function settingsWithCodexCredential(db: Database, workspaceId: string, settings: Settings, activeOverride?: boolean): Promise<Settings>;
|
|
17
17
|
/** Pure: append the synthetic codex-subscription provider, idempotently. */
|
|
18
18
|
export declare function withCodexProvider(settings: Settings): Settings;
|
|
19
|
+
/**
|
|
20
|
+
* Pure: append the synthetic SuperGrok/xAI subscription provider,
|
|
21
|
+
* idempotently. The overlay is catalogue metadata only; the exact account,
|
|
22
|
+
* authority snapshot, and bearer remain frozen later at turn admission.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withXaiSubscriptionProvider(settings: Settings): Settings;
|
|
19
25
|
export declare function settingsWithWorkspaceGatewayCredential(db: Database, workspaceId: string, settings: Settings): Promise<Settings>;
|
|
@@ -21,6 +21,7 @@ export declare function signalPendingCodexCapacityWakeTargets(services: CodexCap
|
|
|
21
21
|
export declare function codexCapacityDecision(context: CodexCapacitySelectionContext, settings: Settings): ReturnType<Parameters<typeof reconcileCodexCapacityWaitDb>[2]>;
|
|
22
22
|
export declare function createCodexCapacityActivities(services: () => Promise<ControlActivityServices>): {
|
|
23
23
|
getCodexCapacityWait: (input: GetCodexCapacityWaitInput) => Promise<{
|
|
24
|
+
provider?: "xai";
|
|
24
25
|
waiterId: string;
|
|
25
26
|
generation: number;
|
|
26
27
|
nextCheckAt: string;
|
|
@@ -61,7 +61,13 @@ type RunGitCredentialOptions = {
|
|
|
61
61
|
export declare function loadWorkspaceEnvironmentForRunWithCredentials(db: Database, settings: Settings, scope: ConnectionScope, environmentId: string | null, sandboxSecrets?: ConnectionCredentialsPort["sandboxSecrets"]): Promise<WorkspaceEnvironmentForRun | null>;
|
|
62
62
|
export declare function sandboxEnvironmentForRun(settings: Settings, resources: ResourceRef[], workspaceEnvironment?: Record<string, string>, options?: RunGitCredentialOptions & {
|
|
63
63
|
skipGitHubToken?: boolean;
|
|
64
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Codemode credential delivery for this attempt. Managed sandboxes receive
|
|
66
|
+
* stable URL/file pointers in their manifest and the bearer through the
|
|
67
|
+
* lifecycle file writer. Connected Machines receive no manifest pointers;
|
|
68
|
+
* the worker injects the minted bearer only into exact exec requests.
|
|
69
|
+
*/
|
|
70
|
+
codemodeDelivery?: "managed_file" | "transient_exec" | "none";
|
|
65
71
|
deferGitHubToken?: boolean;
|
|
66
72
|
codemodeAuthority?: SandboxCodemodeAuthority;
|
|
67
73
|
}): Promise<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CapabilityPack, type PackInstallation } from "@opengeni/contracts";
|
|
2
2
|
import { type Database } from "@opengeni/db";
|
|
3
|
-
import { type
|
|
3
|
+
import { type InstalledSkillActivation, type PackSkillActivation } from "@opengeni/runtime";
|
|
4
4
|
export { resolveRigProviderImageSelection, rigProviderImageSourceImage, settingsWithPackSandboxImage, settingsWithRigImage, settingsWithRigProviderImage, } from "./sandbox-images.js";
|
|
5
5
|
/**
|
|
6
6
|
* Legacy pack-scoped runtime compatibility. V2 Pack installations own ordinary
|
|
@@ -9,11 +9,10 @@ export { resolveRigProviderImageSelection, rigProviderImageSourceImage, settings
|
|
|
9
9
|
export type WorkspacePackRuntime = {
|
|
10
10
|
sandboxImage: string | null;
|
|
11
11
|
sandboxProviderImages: CapabilityPack["sandboxProviderImages"] | null;
|
|
12
|
-
|
|
12
|
+
skillActivations: PackSkillActivation[];
|
|
13
13
|
};
|
|
14
|
-
export type
|
|
15
|
-
|
|
16
|
-
skillLibrarySelections: EffectiveSkillSelection[];
|
|
14
|
+
export type WorkspaceInstalledSkillRuntime = {
|
|
15
|
+
activations: InstalledSkillActivation[];
|
|
17
16
|
};
|
|
18
17
|
/**
|
|
19
18
|
* Resolves only pre-V2 active Pack installations. A frozen manifest/digest is
|
|
@@ -25,12 +24,11 @@ export type WorkspaceSkillLibraryRuntime = {
|
|
|
25
24
|
export declare function resolveWorkspacePackRuntime(db: Database, workspaceId: string): Promise<WorkspacePackRuntime>;
|
|
26
25
|
export declare function packInstallationUsesLegacyRuntime(installation: Pick<PackInstallation, "manifestSnapshot" | "manifestDigest">): boolean;
|
|
27
26
|
/**
|
|
28
|
-
* Resolves active immutable
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* the pinned artifact hash before any content is materialized.
|
|
27
|
+
* Resolves every active immutable Skill through the normalized Plugin/Skill-
|
|
28
|
+
* Facet ledger. The data layer has already filtered ineffective owner edges;
|
|
29
|
+
* this boundary independently verifies exact files before runtime activation.
|
|
32
30
|
*/
|
|
33
|
-
export declare function
|
|
31
|
+
export declare function resolveWorkspaceInstalledSkillRuntime(db: Database, workspaceId: string): Promise<WorkspaceInstalledSkillRuntime>;
|
|
34
32
|
/**
|
|
35
33
|
* Pure pre-V2 compatibility rule for enabled Pack manifests. At most one
|
|
36
34
|
* legacy Pack may declare a sandbox image, and legacy Skill names must be
|
|
@@ -32,6 +32,14 @@ export type TurnInputOptions = {
|
|
|
32
32
|
materializeSerializedRunState?: (serialized: string) => Promise<string>;
|
|
33
33
|
projectModelHistory?: ModelHistoryAttachmentProjector;
|
|
34
34
|
loadActiveHistory?: typeof getActiveSessionHistoryItemsPaged;
|
|
35
|
+
/** Bounded critical-path timings; telemetry failures never affect preparation. */
|
|
36
|
+
onPreparationPhase?: (measurement: HistoryPreparationPhaseMeasurement) => void;
|
|
37
|
+
};
|
|
38
|
+
export type HistoryPreparationPhase = "system_update_load" | "current_attachment_resolution" | "durable_history_load" | "sandbox_envelope_load" | "canonical_projection" | "provider_projection" | "attachment_ref_projection" | "screenshot_materialization" | "model_attachment_projection" | "runtime_input_assembly" | "artifact_candidate_scan";
|
|
39
|
+
export type HistoryPreparationPhaseMeasurement = {
|
|
40
|
+
phase: HistoryPreparationPhase;
|
|
41
|
+
outcome: "completed" | "failed";
|
|
42
|
+
durationSeconds: number;
|
|
35
43
|
};
|
|
36
44
|
export declare const MAX_INLINE_MODEL_ATTACHMENT_BYTES: number;
|
|
37
45
|
export type ModelAttachmentContent = {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { settleSessionAttemptInterruptions, applySessionTurnSettlement, requestSessionTurnRecovery, recoverSessionDispatch, reconcileSessionAttemptQuiescence, peekSessionWork as peekSessionWorkDb, countQueuedTurns, getSessionAttemptActivityRef, getSessionEvent, getSessionTurnForAttempt, expireSessionHumanInputRequest, markSessionAttemptQuiesced, requireSession, settleSessionIdleWithParentOutbox } from "@opengeni/db";
|
|
1
|
+
import { settleSessionAttemptInterruptions, applySessionTurnSettlement, enqueueSessionWorkflowWake, failSessionWorkBeforeAttemptClaim, requestSessionTurnRecovery, recoverSessionDispatch, reconcileSessionAttemptQuiescence, peekSessionWork as peekSessionWorkDb, countQueuedTurns, getSessionAttemptActivityRef, getSessionEvent, getSessionTurnForAttempt, expireSessionInteractionIntervention as expireSessionInteractionInterventionDb, expireSessionHumanInputRequest, markSessionAttemptQuiesced, requireSession, settleSessionIdleWithParentOutbox } from "@opengeni/db";
|
|
2
2
|
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
3
3
|
import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake.js";
|
|
4
4
|
import { recordTurnsQueuedGauge } from "../observability-metrics.js";
|
|
5
|
-
import type { ControlActivityServices, ExpireSessionHumanInputInput, ExpireSessionHumanInputResult, PeekSessionWorkInput, FailSessionAttemptInput, SettleSessionInterruptionsInput, MarkSessionIdleInput, PersistSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceResult, RecoverDispatchInput, RecoverDispatchResult, RecoverEscapedMcpTimeoutInput, RecoverEscapedMcpTimeoutResult } from "./types.js";
|
|
5
|
+
import type { ControlActivityServices, ExpireSessionHumanInputInput, ExpireSessionHumanInputResult, ExpireSessionInteractionInterventionInput, ExpireSessionInteractionInterventionResult, PeekSessionWorkInput, FailSessionAttemptInput, FailSessionAttemptResult, SettleSessionInterruptionsInput, MarkSessionIdleInput, PersistSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceInput, ReconcileSessionAttemptQuiescenceResult, RecoverDispatchInput, RecoverDispatchResult, RecoverEscapedMcpTimeoutInput, RecoverEscapedMcpTimeoutResult } from "./types.js";
|
|
6
6
|
export type SessionStateActivityOverrides = Partial<{
|
|
7
7
|
settleSessionAttemptInterruptions: typeof settleSessionAttemptInterruptions;
|
|
8
8
|
applySessionTurnSettlement: typeof applySessionTurnSettlement;
|
|
9
|
+
enqueueSessionWorkflowWake: typeof enqueueSessionWorkflowWake;
|
|
10
|
+
failSessionWorkBeforeAttemptClaim: typeof failSessionWorkBeforeAttemptClaim;
|
|
9
11
|
requestSessionTurnRecovery: typeof requestSessionTurnRecovery;
|
|
10
12
|
recoverSessionDispatch: typeof recoverSessionDispatch;
|
|
11
13
|
reconcileSessionAttemptQuiescence: typeof reconcileSessionAttemptQuiescence;
|
|
@@ -15,6 +17,7 @@ export type SessionStateActivityOverrides = Partial<{
|
|
|
15
17
|
getSessionEvent: typeof getSessionEvent;
|
|
16
18
|
getSessionTurnForAttempt: typeof getSessionTurnForAttempt;
|
|
17
19
|
expireSessionHumanInputRequest: typeof expireSessionHumanInputRequest;
|
|
20
|
+
expireSessionInteractionIntervention: typeof expireSessionInteractionInterventionDb;
|
|
18
21
|
requireSession: typeof requireSession;
|
|
19
22
|
settleSessionIdleWithParentOutbox: typeof settleSessionIdleWithParentOutbox;
|
|
20
23
|
markSessionAttemptQuiesced: typeof markSessionAttemptQuiesced;
|
|
@@ -25,7 +28,7 @@ export type SessionStateActivityOverrides = Partial<{
|
|
|
25
28
|
}>;
|
|
26
29
|
export declare const WORKER_DEATH_MAX_REDISPATCHES = 3;
|
|
27
30
|
export declare function createSessionStateActivities(services: () => Promise<ControlActivityServices>, overrides?: SessionStateActivityOverrides): {
|
|
28
|
-
failSessionAttempt: (input: FailSessionAttemptInput) => Promise<
|
|
31
|
+
failSessionAttempt: (input: FailSessionAttemptInput) => Promise<FailSessionAttemptResult>;
|
|
29
32
|
settleSessionInterruptions: (input: SettleSessionInterruptionsInput) => Promise<{
|
|
30
33
|
action: "paused" | "continue" | "stale";
|
|
31
34
|
}>;
|
|
@@ -35,5 +38,6 @@ export declare function createSessionStateActivities(services: () => Promise<Con
|
|
|
35
38
|
recoverEscapedMcpTimeout: (input: RecoverEscapedMcpTimeoutInput) => Promise<RecoverEscapedMcpTimeoutResult>;
|
|
36
39
|
peekSessionWork: (input: PeekSessionWorkInput) => Promise<import("@opengeni/db").SessionWorkPeek>;
|
|
37
40
|
expireSessionHumanInput: (input: ExpireSessionHumanInputInput) => Promise<ExpireSessionHumanInputResult>;
|
|
41
|
+
expireSessionInteractionIntervention: (input: ExpireSessionInteractionInterventionInput) => Promise<ExpireSessionInteractionInterventionResult>;
|
|
38
42
|
markSessionIdle: (input: MarkSessionIdleInput) => Promise<void>;
|
|
39
43
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { assertWorkspaceModelPolicyAllows, createAndStartSessionWithOutcome, recordWorkspaceUsage } from "@opengeni/core";
|
|
2
|
+
import { claimSiteAuthMaintenance, confirmSiteAuthMaintenanceSessionInTransaction, deferSiteAuthMaintenance } from "@opengeni/db";
|
|
3
|
+
import { agentRunAdmissionDenial } from "./agent-run-admission.js";
|
|
4
|
+
import type { ControlActivityServices } from "./types.js";
|
|
5
|
+
export declare const SITE_AUTH_MAINTENANCE_CLAIM_TIMEOUT_MS: number;
|
|
6
|
+
export declare const SITE_AUTH_MAINTENANCE_BATCH_SIZE = 16;
|
|
7
|
+
export type MaintainSiteAuthConnectionsResult = {
|
|
8
|
+
claimed: number;
|
|
9
|
+
started: number;
|
|
10
|
+
deferred: number;
|
|
11
|
+
};
|
|
12
|
+
export type SiteAuthMaintenanceOptions = {
|
|
13
|
+
claimTimeoutMs?: number;
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
claim?: typeof claimSiteAuthMaintenance;
|
|
16
|
+
confirm?: typeof confirmSiteAuthMaintenanceSessionInTransaction;
|
|
17
|
+
defer?: typeof deferSiteAuthMaintenance;
|
|
18
|
+
createSession?: typeof createAndStartSessionWithOutcome;
|
|
19
|
+
admit?: typeof agentRunAdmissionDenial;
|
|
20
|
+
recordUsage?: typeof recordWorkspaceUsage;
|
|
21
|
+
assertModelPolicy?: typeof assertWorkspaceModelPolicyAllows;
|
|
22
|
+
};
|
|
23
|
+
/** Dispatch bounded, auditable agent sessions for due authentication checks.
|
|
24
|
+
* A hidden claim id/session id pair makes every crash point replayable. */
|
|
25
|
+
export declare function createSiteAuthMaintenanceActivities(services: () => Promise<ControlActivityServices>, options?: SiteAuthMaintenanceOptions): {
|
|
26
|
+
maintainSiteAuthConnections: () => Promise<MaintainSiteAuthConnectionsResult>;
|
|
27
|
+
};
|
|
@@ -87,11 +87,16 @@ export type ActivityServices = ControlActivityServices & TurnActivityServices &
|
|
|
87
87
|
documentServices: DocumentServices;
|
|
88
88
|
};
|
|
89
89
|
export type CodexCapacityWaitRef = {
|
|
90
|
+
/** Absent only for Temporal histories written before provider-tagged waits. */
|
|
91
|
+
provider?: "codex" | "xai";
|
|
90
92
|
waiterId: string;
|
|
91
93
|
generation: number;
|
|
92
94
|
nextCheckAt: string;
|
|
93
95
|
wakeRevision: number;
|
|
94
96
|
};
|
|
97
|
+
export type XaiCapacityWaitRef = CodexCapacityWaitRef & {
|
|
98
|
+
provider: "xai";
|
|
99
|
+
};
|
|
95
100
|
export type GetCodexCapacityWaitInput = {
|
|
96
101
|
workspaceId: string;
|
|
97
102
|
sessionId: string;
|
|
@@ -103,6 +108,8 @@ export type ReconcileCodexCapacityWaitInput = {
|
|
|
103
108
|
waiterId: string;
|
|
104
109
|
generation: number;
|
|
105
110
|
cause: "timer" | "signal" | "queue" | "recovery";
|
|
111
|
+
/** Absent only for Codex waits and pre-provider-tagged workflow histories. */
|
|
112
|
+
provider?: "codex" | "xai";
|
|
106
113
|
};
|
|
107
114
|
export type ReconcileCodexCapacityWaitResult = ({
|
|
108
115
|
action: "waiting";
|
|
@@ -163,8 +170,35 @@ export type FailSessionAttemptInput = {
|
|
|
163
170
|
workspaceId: string;
|
|
164
171
|
sessionId: string;
|
|
165
172
|
attemptId: string;
|
|
173
|
+
/** Added in v2; old Temporal histories derive the session's canonical id. */
|
|
174
|
+
workflowId?: string;
|
|
175
|
+
/** Added in v2; old Temporal histories use the bounded 60-second floor. */
|
|
176
|
+
retryDelayMs?: number;
|
|
177
|
+
/** Added in v3. Upgraded turn workers classify failures from the atomic
|
|
178
|
+
* admission transaction; omission is a rolling-deploy/legacy unknown and
|
|
179
|
+
* deliberately keeps the recoverable wake behavior. */
|
|
180
|
+
preClaimFailureDisposition?: PreClaimFailureDisposition;
|
|
181
|
+
/** The workflow admission trigger is required to re-evaluate the same
|
|
182
|
+
* durable admission branch before terminally settling a permanent failure. */
|
|
183
|
+
trigger?: RunAgentTurnInput["trigger"];
|
|
166
184
|
error?: string;
|
|
167
185
|
};
|
|
186
|
+
export type FailSessionAttemptResult = {
|
|
187
|
+
action: "failed";
|
|
188
|
+
} | {
|
|
189
|
+
action: "unclaimed";
|
|
190
|
+
} | {
|
|
191
|
+
action: "terminal";
|
|
192
|
+
} | {
|
|
193
|
+
action: "stale";
|
|
194
|
+
};
|
|
195
|
+
export type PreClaimFailureDisposition = "retryable" | "permanent";
|
|
196
|
+
export type PreClaimFailureDetail = {
|
|
197
|
+
disposition: PreClaimFailureDisposition;
|
|
198
|
+
code: "db_deadlock" | "db_serialization_failure" | "db_failure" | "claim_invariant";
|
|
199
|
+
};
|
|
200
|
+
export declare const PRE_CLAIM_FAILURE_TYPE = "OpenGeniPreClaimFailure";
|
|
201
|
+
export declare const PRE_CLAIM_FAILURE_MESSAGE = "Agent turn admission failed before attempt claim.";
|
|
168
202
|
export type RecoverDispatchInput = {
|
|
169
203
|
accountId: string;
|
|
170
204
|
workspaceId: string;
|
|
@@ -214,6 +248,15 @@ export type ExpireSessionHumanInputInput = {
|
|
|
214
248
|
export type ExpireSessionHumanInputResult = {
|
|
215
249
|
action: "expired" | "stale" | "not_found";
|
|
216
250
|
};
|
|
251
|
+
export type ExpireSessionInteractionInterventionInput = {
|
|
252
|
+
accountId: string;
|
|
253
|
+
workspaceId: string;
|
|
254
|
+
sessionId: string;
|
|
255
|
+
interventionId: string;
|
|
256
|
+
};
|
|
257
|
+
export type ExpireSessionInteractionInterventionResult = {
|
|
258
|
+
action: "expired" | "stale" | "not_found";
|
|
259
|
+
};
|
|
217
260
|
export type MarkSessionIdleInput = {
|
|
218
261
|
workspaceId: string;
|
|
219
262
|
sessionId: string;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { VideoGenerationAcceptedReceipt, type GenerateVideoToolInput, type VideoGenerationCapabilities, type VideoGenerationPolicy } from "@opengeni/contracts";
|
|
2
|
-
import { type Database } from "@opengeni/db";
|
|
1
|
+
import { VideoGenerationAcceptedReceipt, type GenerateVideoToolInput, type VideoGenerationCapabilities, type VideoGenerationPolicy, type XaiProviderAccountAuthoritySnapshotV1 } from "@opengeni/contracts";
|
|
2
|
+
import { type Database, type XaiCredentialForRun } from "@opengeni/db";
|
|
3
3
|
import { type Settings } from "@opengeni/config";
|
|
4
4
|
import type { ObjectStorage } from "@opengeni/storage";
|
|
5
5
|
import { type SandboxCommandRunner } from "./video-reference-staging.js";
|
|
6
6
|
export type VideoGenerationCredentialLease = Readonly<{
|
|
7
|
-
fundingSource: "opengeni_credits" | "workspace_gateway";
|
|
7
|
+
fundingSource: "opengeni_credits" | "workspace_gateway" | "supergrok_subscription";
|
|
8
8
|
connectionId: string | null;
|
|
9
9
|
version: number;
|
|
10
10
|
credentialEncrypted: string;
|
|
11
|
-
apiKey: string;
|
|
12
11
|
}>;
|
|
13
12
|
export type AcceptedVideoGeneration = Readonly<{
|
|
14
13
|
receipt: ReturnType<typeof VideoGenerationAcceptedReceipt.parse>;
|
|
@@ -20,6 +19,12 @@ export declare function videoCapabilitiesForTurn(input: {
|
|
|
20
19
|
credential: VideoGenerationCredentialLease;
|
|
21
20
|
}): VideoGenerationCapabilities;
|
|
22
21
|
export declare function managedVideoGenerationCredentialLease(settings: Settings): VideoGenerationCredentialLease | null;
|
|
22
|
+
export declare function xaiVideoGenerationCredentialLease(input: {
|
|
23
|
+
settings: Settings;
|
|
24
|
+
credential: XaiCredentialForRun;
|
|
25
|
+
subjectId: string;
|
|
26
|
+
authoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
|
|
27
|
+
}): VideoGenerationCredentialLease;
|
|
23
28
|
export declare function admitVideoGenerationRequest(input: {
|
|
24
29
|
db: Database;
|
|
25
30
|
storage: ObjectStorage;
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
import type { XaiProviderAccountAuthoritySnapshotV1 } from "@opengeni/contracts";
|
|
2
|
+
export type VideoGenerationProviderCredential = Readonly<{
|
|
3
|
+
kind: "api-key";
|
|
4
|
+
apiKey: string;
|
|
5
|
+
}> | Readonly<{
|
|
6
|
+
kind: "xai-subscription";
|
|
7
|
+
accessToken: string;
|
|
8
|
+
refreshToken: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
credentialId: string;
|
|
11
|
+
subjectId: string;
|
|
12
|
+
authoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
|
|
13
|
+
}>;
|
|
1
14
|
/** One frozen, provider-neutral credential envelope for every video funding route. */
|
|
2
15
|
export declare function encryptVideoGenerationApiKey(key: Uint8Array, apiKey: string): string;
|
|
16
|
+
export declare function encryptVideoGenerationXaiCredential(key: Uint8Array, credential: Omit<Extract<VideoGenerationProviderCredential, {
|
|
17
|
+
kind: "xai-subscription";
|
|
18
|
+
}>, "kind">): string;
|
|
3
19
|
/**
|
|
4
20
|
* Decrypt without ever attaching parser/decryption errors: JSON parser errors
|
|
5
21
|
* may quote plaintext and must not enter Temporal failure payloads or logs.
|
|
6
22
|
*/
|
|
23
|
+
export declare function decryptVideoGenerationCredential(key: Uint8Array, stored: string): VideoGenerationProviderCredential;
|
|
7
24
|
export declare function decryptVideoGenerationApiKey(key: Uint8Array, stored: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GenerateVideoToolInput } from "@opengeni/contracts";
|
|
1
|
+
import { type GenerateVideoToolInput, type VideoGenerationRejectedCode } from "@opengeni/contracts";
|
|
2
2
|
import type { SealedVideoReference, SealedVideoReferenceRole } from "@opengeni/core";
|
|
3
3
|
import type { ObjectStorage } from "@opengeni/storage";
|
|
4
4
|
export type SandboxCommandRunner = (input: {
|
|
@@ -18,6 +18,12 @@ export type InspectedSandboxVideoReference = Readonly<{
|
|
|
18
18
|
sizeBytes: number;
|
|
19
19
|
sha256: string;
|
|
20
20
|
}>;
|
|
21
|
+
export type VideoReferenceInputErrorCode = VideoGenerationRejectedCode;
|
|
22
|
+
/** A deterministic, pre-admission tool-input error. No video operation exists yet. */
|
|
23
|
+
export declare class VideoReferenceInputError extends Error {
|
|
24
|
+
readonly code: VideoReferenceInputErrorCode;
|
|
25
|
+
constructor(code: VideoReferenceInputErrorCode, message: string);
|
|
26
|
+
}
|
|
21
27
|
export declare function videoReferencePaths(request: GenerateVideoToolInput): Array<{
|
|
22
28
|
role: SealedVideoReferenceRole;
|
|
23
29
|
path: string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Settings } from "@opengeni/config";
|
|
2
|
+
import { type Database } from "@opengeni/db";
|
|
3
|
+
import type { XaiProviderAccountAuthoritySnapshotV1 } from "@opengeni/contracts";
|
|
4
|
+
import { type XaiFetch, type XaiSubscriptionRequestContext } from "@opengeni/xai-subscription";
|
|
5
|
+
export type XaiTurnRequestAuthorization = {
|
|
6
|
+
context: XaiSubscriptionRequestContext;
|
|
7
|
+
credentialId: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function buildXaiTurnRequestAuthorization(input: {
|
|
10
|
+
db: Database;
|
|
11
|
+
settings: Settings;
|
|
12
|
+
accountId: string;
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
subjectId: string;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
turnId: string;
|
|
17
|
+
credentialId: string;
|
|
18
|
+
authoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
|
|
19
|
+
fetch?: XaiFetch;
|
|
20
|
+
hostedSearch?: XaiSubscriptionRequestContext["hostedSearch"];
|
|
21
|
+
onFinalContextUsage?: XaiSubscriptionRequestContext["onFinalContextUsage"];
|
|
22
|
+
nextRequestId?: XaiSubscriptionRequestContext["nextRequestId"];
|
|
23
|
+
}): Promise<XaiTurnRequestAuthorization>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { generateXaiSubscriptionImage, type XaiSubscriptionRequestContext } from "@opengeni/xai-subscription";
|
|
2
|
+
import type { Database } from "@opengeni/db";
|
|
3
|
+
import type { ObjectStorage } from "@opengeni/storage";
|
|
4
|
+
import type { GeneratedImageReceipt } from "./generated-images.js";
|
|
5
|
+
import { executeImageGenerationOperation } from "./image-generation-operation.js";
|
|
6
|
+
import type { ResolvedImageGenerationReference } from "./image-generation-references.js";
|
|
7
|
+
export type XaiImageGenerationPorts = {
|
|
8
|
+
execute: typeof executeImageGenerationOperation;
|
|
9
|
+
generate: typeof generateXaiSubscriptionImage;
|
|
10
|
+
};
|
|
11
|
+
/** Execute xAI's standalone subscription image path under the durable paid-operation fence. */
|
|
12
|
+
export declare function executeXaiSubscriptionImageGeneration(input: {
|
|
13
|
+
db: Database;
|
|
14
|
+
objectStorage: ObjectStorage | null;
|
|
15
|
+
accountId: string;
|
|
16
|
+
workspaceId: string;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
turnId: string;
|
|
19
|
+
attemptId: string;
|
|
20
|
+
toolCallId: string;
|
|
21
|
+
prompt: string;
|
|
22
|
+
references?: readonly ResolvedImageGenerationReference[];
|
|
23
|
+
credentialId: string;
|
|
24
|
+
xaiContext: Pick<XaiSubscriptionRequestContext, "getToken" | "refresh">;
|
|
25
|
+
abortSignal?: AbortSignal;
|
|
26
|
+
}, ports?: XaiImageGenerationPorts): Promise<GeneratedImageReceipt>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CanonicalVideoGenerationRequest } from "@opengeni/core";
|
|
2
|
+
import { type XaiFetch, type XaiSubscriptionRequestContext, type XaiVideoStatus } from "@opengeni/xai-subscription";
|
|
3
|
+
import type { GatewayVideoReferenceGrant } from "./gateway-video-generation.js";
|
|
4
|
+
export declare function buildXaiVideoStartBody(request: CanonicalVideoGenerationRequest, referenceGrants: readonly GatewayVideoReferenceGrant[]): Record<string, unknown>;
|
|
5
|
+
export declare function startXaiVideoGeneration(input: {
|
|
6
|
+
body: Record<string, unknown>;
|
|
7
|
+
sessionId: string | null;
|
|
8
|
+
auth: Pick<XaiSubscriptionRequestContext, "getToken" | "refresh">;
|
|
9
|
+
fetch?: XaiFetch;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
providerJobId: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function getXaiVideoGenerationStatus(input: {
|
|
14
|
+
providerJobId: string;
|
|
15
|
+
sessionId: string | null;
|
|
16
|
+
auth: Pick<XaiSubscriptionRequestContext, "getToken" | "refresh">;
|
|
17
|
+
fetch?: XaiFetch;
|
|
18
|
+
}): Promise<XaiVideoStatus>;
|