@opengeni/worker-bundle 0.23.3-canary.0 → 0.23.4-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.
Files changed (62) hide show
  1. package/dist/activities/agent-turn/admission.d.ts +10 -2
  2. package/dist/activities/agent-turn/claim.d.ts +1 -0
  3. package/dist/activities/agent-turn/codex.d.ts +2 -2
  4. package/dist/activities/agent-turn/list-models.d.ts +16 -0
  5. package/dist/activities/agent-turn/model-usage.d.ts +10 -1
  6. package/dist/activities/agent-turn/tool-environment.d.ts +1 -0
  7. package/dist/activities/agent-turn/tool-policy.d.ts +36 -5
  8. package/dist/activities/agent-turn/turn-context.d.ts +2 -0
  9. package/dist/activities/automations.d.ts +1 -0
  10. package/dist/activities/capabilities.d.ts +2 -1
  11. package/dist/activities/goals.d.ts +11 -0
  12. package/dist/activities/image-generation-references.d.ts +2 -1
  13. package/dist/activities/scheduled-tasks.d.ts +1 -0
  14. package/dist/activities/types.d.ts +8 -0
  15. package/dist/{activities-control-52W5IDWM.js → activities-control-SGU2WEVB.js} +206 -97
  16. package/dist/activities-control-SGU2WEVB.js.map +1 -0
  17. package/dist/activities-control.d.ts +2 -0
  18. package/dist/{activities-turn-A2G2KLSY.js → activities-turn-7EAQXW6Q.js} +301 -65
  19. package/dist/activities-turn-7EAQXW6Q.js.map +1 -0
  20. package/dist/activities.d.ts +2 -0
  21. package/dist/{chunk-IPVMCAW5.js → chunk-S2QVRVJW.js} +85 -23
  22. package/dist/chunk-S2QVRVJW.js.map +1 -0
  23. package/dist/{chunk-GFNXVZVQ.js → chunk-TJIPCHMP.js} +3 -2
  24. package/dist/chunk-TJIPCHMP.js.map +1 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +29 -6
  27. package/dist/index.js.map +1 -1
  28. package/dist/observability-metrics.d.ts +1 -0
  29. package/dist/workflow-bundle.js +26 -3
  30. package/dist/workflows/activities.d.ts +5 -0
  31. package/dist/workflows/automations.d.ts +5 -0
  32. package/package.json +17 -17
  33. package/src/activities/agent-run-admission.ts +7 -1
  34. package/src/activities/agent-turn/admission.ts +28 -6
  35. package/src/activities/agent-turn/claim.ts +25 -5
  36. package/src/activities/agent-turn/codex.ts +2 -2
  37. package/src/activities/agent-turn/compaction-prep.ts +2 -0
  38. package/src/activities/agent-turn/list-models.ts +101 -0
  39. package/src/activities/agent-turn/model-usage.ts +88 -42
  40. package/src/activities/agent-turn/run.ts +6 -3
  41. package/src/activities/agent-turn/stream-attempt.ts +8 -0
  42. package/src/activities/agent-turn/tool-environment.ts +62 -1
  43. package/src/activities/agent-turn/tool-policy.ts +58 -5
  44. package/src/activities/agent-turn/turn-context.ts +4 -0
  45. package/src/activities/automations.ts +122 -67
  46. package/src/activities/capabilities.ts +72 -2
  47. package/src/activities/goals.ts +107 -31
  48. package/src/activities/image-generation-references.ts +9 -9
  49. package/src/activities/scheduled-tasks.ts +120 -26
  50. package/src/activities/site-auth-maintenance.ts +12 -12
  51. package/src/activities/types.ts +6 -0
  52. package/src/activities.ts +1 -0
  53. package/src/activity-services.ts +4 -1
  54. package/src/github-rest-mcp.ts +2 -1
  55. package/src/index.ts +19 -4
  56. package/src/observability-metrics.ts +2 -0
  57. package/src/workflows/activities.ts +15 -0
  58. package/src/workflows/automations.ts +21 -2
  59. package/dist/activities-control-52W5IDWM.js.map +0 -1
  60. package/dist/activities-turn-A2G2KLSY.js.map +0 -1
  61. package/dist/chunk-GFNXVZVQ.js.map +0 -1
  62. package/dist/chunk-IPVMCAW5.js.map +0 -1
@@ -1,12 +1,19 @@
1
1
  import { resolveTurnExecutionPolicyV1, type Settings } from "@opengeni/config";
2
2
  import type { TurnActivityServices as ActivityServices } from "../types.js";
3
- import { type SessionEvent, type SessionTurn, type ToolAuthNeededPayload, type TurnExecutionPolicyV1 } from "@opengeni/contracts";
3
+ import { type SessionEvent, type SessionTurn, type ToolAuthNeededPayload, type TurnExecutionPolicyV1, type XaiProviderAccountAuthoritySnapshotV1 } from "@opengeni/contracts";
4
4
  export declare class WorkspaceHumanInputDisabledError extends Error {
5
5
  constructor(kind: "resume" | "interruption");
6
6
  }
7
7
  export declare function assertWorkspaceHumanInputAllowed(enabled: boolean, kind: "resume" | "interruption", attempted: boolean): void;
8
8
  /** Broad personal lookup is allowed only for a direct human/API command. */
9
9
  export declare function credentialSubjectIdForTurnInitiator(turn: Pick<SessionTurn, "source" | "initiator" | "initiatorContext">): string | undefined;
10
+ export declare function xaiCatalogReadinessAuthority(turn: {
11
+ initiatingHumanSubjectId: string | null;
12
+ xaiProviderAccountAuthoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
13
+ }, directCredentialSubjectId: string | undefined): {
14
+ subjectId: string;
15
+ authoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
16
+ } | null;
10
17
  /**
11
18
  * Direct authenticated-human work is the persisted human source with subject
12
19
  * authority and no inherited agent or legacy provenance. Use this complete
@@ -24,6 +31,7 @@ export declare function isDirectHumanTurnInitiation(turn: Pick<SessionTurn, "sou
24
31
  export declare function shouldPublishToolAuthNeededForTurn(payload: Pick<ToolAuthNeededPayload, "providerDomain" | "toolName">, trigger: Pick<SessionEvent, "type" | "payload">, turn: Pick<SessionTurn, "source" | "initiator" | "initiatorContext">): boolean;
25
32
  export declare function turnExecutionPolicyBillingIdentity(policy: TurnExecutionPolicyV1): {
26
33
  externallyBilled: boolean;
34
+ countsTowardTokenCap: boolean;
27
35
  codexSubscription: boolean;
28
36
  xaiSubscription: boolean;
29
37
  };
@@ -49,4 +57,4 @@ export declare class BudgetExhaustedError extends Error {
49
57
  readonly serializedRunState: string | null;
50
58
  constructor(message: string, serializedRunState: string | null);
51
59
  }
52
- export declare function ensureRunAllowed(settings: Settings, db: ActivityServices["db"], accountId: string, workspaceId: string, isExternallyBilledTurn: boolean, entitlements?: ActivityServices["entitlements"]): Promise<void>;
60
+ export declare function ensureRunAllowed(settings: Settings, db: ActivityServices["db"], accountId: string, workspaceId: string, isExternallyBilledTurn: boolean, entitlements?: ActivityServices["entitlements"], chargesOpenGeniCredits?: boolean, countsTowardTokenCap?: boolean): Promise<void>;
@@ -10,6 +10,7 @@ import type { AttemptIdentityState, BillingState, ClaimedResult, EventingState,
10
10
  export type ClaimTurnDeps = {
11
11
  input: RunAgentTurnInput;
12
12
  settings: Settings;
13
+ catalogSourceSettings: Settings;
13
14
  db: ActivityServices["db"];
14
15
  bus: ActivityServices["bus"];
15
16
  runtime: ActivityServices["runtime"];
@@ -1,11 +1,11 @@
1
1
  import { type CodexAccountStatus } from "@opengeni/db";
2
- import { type RegistryProviderKind, type Settings } from "@opengeni/config";
2
+ import { type ResolvedModelProvider, type Settings } from "@opengeni/config";
3
3
  import type { TurnActivityServices as ActivityServices } from "../types.js";
4
4
  export declare function codexWorkspaceMetricKey(workspaceId: string): string;
5
5
  /** Stable public request identity across partial resumes and activity retries. */
6
6
  export declare function acceptsPromptCacheKeyForTurn(resolvedModel: {
7
7
  provider: {
8
- kind: RegistryProviderKind;
8
+ kind: ResolvedModelProvider["kind"];
9
9
  builtin?: boolean;
10
10
  };
11
11
  } | null): boolean;
@@ -0,0 +1,16 @@
1
+ import type { AttemptToolDefinition } from "@opengeni/codemode";
2
+ import type { WorkspaceModelSelection } from "@opengeni/core";
3
+ export declare const LIST_MODELS_TOOL_NAME = "list_models";
4
+ export declare const LIST_MODELS_TOOL_DESCRIPTION = "List the models this workspace can select right now, in picker order, with deployment-defined cost and optional guidance. This does not switch the current session model; use an ID with session_create or the human model picker.";
5
+ export declare function renderListModels(input: {
6
+ currentModelId: string | null;
7
+ selections: readonly WorkspaceModelSelection[];
8
+ modelNotes: Readonly<Record<string, string>>;
9
+ }): string;
10
+ export declare function createListModelsAttemptToolDefinition(input: {
11
+ currentModelId: string | null;
12
+ load: () => Promise<{
13
+ selections: readonly WorkspaceModelSelection[];
14
+ modelNotes: Readonly<Record<string, string>>;
15
+ }>;
16
+ }): AttemptToolDefinition;
@@ -89,6 +89,8 @@ export declare function processModelResponseTerminalEvent(input: {
89
89
  latencyMode?: LatencyMode;
90
90
  metricProvider: string;
91
91
  externallyBilled: boolean;
92
+ chargesOpenGeniCredits?: boolean;
93
+ countsTowardTokenCap?: boolean;
92
94
  servingCredentialId: string | null;
93
95
  priorSessionCredentialId: string | null;
94
96
  emittedSourceKeys: Set<string>;
@@ -132,6 +134,8 @@ export declare function processCompactionModelUsageEvent(input: {
132
134
  providerApi: ModelProviderApi;
133
135
  model: string;
134
136
  externallyBilled: boolean;
137
+ chargesOpenGeniCredits?: boolean;
138
+ countsTowardTokenCap?: boolean;
135
139
  servingCredentialId: string | null;
136
140
  priorSessionCredentialId: string | null;
137
141
  emittedSourceKeys: Set<string>;
@@ -162,6 +166,10 @@ export declare function emitModelCallUsage(input: {
162
166
  usage?: unknown | null;
163
167
  } | null;
164
168
  normalizedUsage?: ModelCallUsageNormalization;
169
+ /** Accepted billing authority persisted for Insights repair after a soft fact-write failure. */
170
+ billingPath?: ModelUsageBillingRecord["billingPath"];
171
+ /** Validated Gateway endpoint provider persisted for exact Insights repair. */
172
+ upstreamProvider?: string;
165
173
  servingAccountHash?: string;
166
174
  accountChangedFromPrevCall?: boolean;
167
175
  emittedSourceKeys?: Set<string>;
@@ -190,7 +198,8 @@ export declare function recordModelUsageAndDebitCredits(settings: Settings, db:
190
198
  turnAttemptId: string;
191
199
  model: string;
192
200
  externallyBilled: boolean;
193
- gatewayManaged?: boolean;
201
+ chargesOpenGeniCredits?: boolean;
202
+ countsTowardTokenCap?: boolean;
194
203
  gatewayBilling?: ModelResponseUsage["gatewayBilling"];
195
204
  usage?: ModelUsageInput | ModelCallUsageInput | null;
196
205
  normalizedUsage?: ModelCallUsageNormalization;
@@ -24,6 +24,7 @@ export type PrepareTurnToolPolicyDeps = {
24
24
  };
25
25
  export type PrepareTurnToolRuntimeDeps = {
26
26
  input: RunAgentTurnInput;
27
+ catalogSourceSettings: Settings;
27
28
  db: ActivityServices["db"];
28
29
  bus: ActivityServices["bus"];
29
30
  runtime: ActivityServices["runtime"];
@@ -1,10 +1,41 @@
1
- import { type LazyToolTransport } from "@opengeni/runtime";
2
- import { type ModelProviderApi, type RegistryProviderKind, type Settings } from "@opengeni/config";
1
+ import { type ComputerToolMode, type LazyToolTransport } from "@opengeni/runtime";
2
+ import { type ModelProviderApi, type ResolvedModelProvider, type Settings } from "@opengeni/config";
3
3
  import { type ModelAttachmentInputPolicy } from "../run-input.js";
4
+ export declare function shouldStartOnTurnRecording(params: {
5
+ recordingEnabled: boolean;
6
+ desktopEnabled: boolean;
7
+ establishedBackendId: string;
8
+ effectiveBackend: Settings["sandboxBackend"] | undefined;
9
+ }): boolean;
10
+ /**
11
+ * Decide the EXPLICIT computer-use tool transport for THIS turn.
12
+ *
13
+ * Computer-use is ordinary `computer_*` function tools bound to the live
14
+ * desktop. The worker picks the mode from the resolved provider so the runtime
15
+ * never string-sniffs the model instance:
16
+ * • catalogue `inputModalities` must include `image`, or computer-use is off
17
+ * • Responses wires (Azure/OpenAI, Gateway, Codex, legacy client) →
18
+ * "function-image": screenshot results are structured `{type:'image'}`
19
+ * • Chat Completions → "disabled": tool results on that wire are text, so a
20
+ * screenshot would become a base64 string rather than an image the model sees
21
+ *
22
+ * Pure + exported so the mapping is unit-testable without a live turn.
23
+ */
24
+ export declare function computerToolModeForTurn(resolvedModel: {
25
+ provider: {
26
+ kind: ResolvedModelProvider["kind"];
27
+ api: ModelProviderApi;
28
+ };
29
+ configured: {
30
+ capabilities: {
31
+ inputModalities: string[];
32
+ };
33
+ };
34
+ } | null): ComputerToolMode;
4
35
  /** Chat wires and Gateway models do not advertise OpenAI's hosted sandbox tool types. */
5
36
  export declare function structuredToolTransportForTurn(resolvedModel: {
6
37
  provider: {
7
- kind: RegistryProviderKind;
38
+ kind: ResolvedModelProvider["kind"];
8
39
  api: ModelProviderApi;
9
40
  };
10
41
  } | null): boolean;
@@ -17,7 +48,7 @@ export declare function structuredToolTransportForTurn(resolvedModel: {
17
48
  export declare function lazyToolTransportForTurn(resolvedModel: {
18
49
  provider: {
19
50
  id: string;
20
- kind: RegistryProviderKind;
51
+ kind: ResolvedModelProvider["kind"];
21
52
  api: ModelProviderApi;
22
53
  wireProfile: "openai" | "azure-openai";
23
54
  builtin: boolean;
@@ -60,7 +91,7 @@ export declare function connectedSubscriptionImageGenerationAuthority<T>(credent
60
91
  export declare function openAiHostedImageProviderBindingForTurn(settings: Pick<Settings, "openaiProvider" | "openaiApiKey" | "openaiBaseUrl">, resolvedModel: {
61
92
  provider: {
62
93
  id: string;
63
- kind: RegistryProviderKind;
94
+ kind: ResolvedModelProvider["kind"];
64
95
  builtin: boolean;
65
96
  baseUrl?: string | undefined;
66
97
  };
@@ -46,6 +46,8 @@ export type BillingState = {
46
46
  isCodexTurn: boolean;
47
47
  isXaiTurn: boolean;
48
48
  isExternallyBilledTurn: boolean;
49
+ chargesOpenGeniCredits: boolean;
50
+ countsTowardTokenCap: boolean;
49
51
  };
50
52
  export type SandboxRuntimeState = {
51
53
  resolvedSandbox: ResumedTurnSandbox | null;
@@ -12,5 +12,6 @@ export type AutomationActivityOptions = {
12
12
  recordUsage?: typeof recordWorkspaceUsage;
13
13
  };
14
14
  export declare function createAutomationActivities(services: () => Promise<ControlActivityServices>, options?: AutomationActivityOptions): {
15
+ settleAutomationRunFailure: (input: DispatchAutomationRunInput) => Promise<void>;
15
16
  dispatchAutomationRun: (input: DispatchAutomationRunInput) => Promise<DispatchAutomationRunResult>;
16
17
  };
@@ -22,4 +22,5 @@ export declare function withCodexProvider(settings: Settings): Settings;
22
22
  * authority snapshot, and bearer remain frozen later at turn admission.
23
23
  */
24
24
  export declare function withXaiSubscriptionProvider(settings: Settings): Settings;
25
- export declare function settingsWithWorkspaceGatewayCredential(db: Database, workspaceId: string, settings: Settings): Promise<Settings>;
25
+ export declare function settingsWithWorkspaceGatewayCredential(db: Database, accountId: string, workspaceId: string, settings: Settings, retainedProductModelId?: string | null): Promise<Settings>;
26
+ export declare function settingsWithWorkspaceOpenRouterCredential(db: Database, accountId: string, workspaceId: string, settings: Settings, retainedProductModelId?: string | null): Promise<Settings>;
@@ -1,10 +1,21 @@
1
1
  import { type Settings } from "@opengeni/config";
2
2
  import { type SessionGoal, type ToolRef } from "@opengeni/contracts";
3
+ import { getWorkspaceModelPolicy } from "@opengeni/db";
3
4
  import type { ControlActivityServices, MaybeContinueGoalInput, MaybeContinueGoalResult } from "./types.js";
4
5
  export declare function createGoalActivities(services: () => Promise<ControlActivityServices>): {
5
6
  enqueueGoalRetryWake: (input: MaybeContinueGoalInput) => Promise<void>;
6
7
  maybeContinueGoal: (input: MaybeContinueGoalInput) => Promise<MaybeContinueGoalResult>;
7
8
  };
9
+ export declare function goalContinuationModelDecision(input: {
10
+ settings: Settings;
11
+ workspaceModelPolicy: Awaited<ReturnType<typeof getWorkspaceModelPolicy>>;
12
+ inheritedModel: string;
13
+ sessionModel: string;
14
+ }): {
15
+ model: string;
16
+ blocked: string | null;
17
+ };
18
+ export declare function goalContinuationFundedWithoutCredits(settings: Settings, model: string, codexBilled: boolean): boolean;
8
19
  export declare function goalContinuationPrompt(_goal: SessionGoal, _autoContinuation: number, _cap: number | null, options?: {
9
20
  goalWaitAvailable?: boolean;
10
21
  humanInputRespondAvailable?: boolean;
@@ -1,4 +1,4 @@
1
- import { type ImageGenerationReference } from "@opengeni/contracts";
1
+ import { type ImageGenerationReference, type FileAsset } from "@opengeni/contracts";
2
2
  import { type Database } from "@opengeni/db";
3
3
  import type { ObjectStorage } from "@opengeni/storage";
4
4
  import { type GeneratedImageMediaType } from "./generated-images.js";
@@ -57,3 +57,4 @@ export declare function resolveImageGenerationReferencesForTool(input: ResolveIm
57
57
  * /workspace. Provider adapters receive only validated immutable bytes.
58
58
  */
59
59
  export declare function resolveImageGenerationReferences(input: ResolveImageGenerationReferencesInput): Promise<ResolvedImageGenerationReference[]>;
60
+ export declare function readStoredImageReferenceFile(objectStorage: Pick<ObjectStorage, "getFileBytes">, file: FileAsset): Promise<Uint8Array>;
@@ -10,6 +10,7 @@ type ScheduledTemporalActivityIdentity = {
10
10
  activityId: string;
11
11
  };
12
12
  export declare function scheduledTaskRunProducerKey(input: DispatchScheduledTaskRunInput, suppliedActivityIdentity?: ScheduledTemporalActivityIdentity): string;
13
+ export declare function scheduledTaskGeneratedSessionCreateIdempotencyKey(producerKey: string): string;
13
14
  /**
14
15
  * Display title for a session the scheduler generates for a task.
15
16
  *
@@ -53,6 +53,11 @@ export type InspectSessionAttemptActivity = (input: {
53
53
  * agent runtime and document parser so each process can load only its role. */
54
54
  export type SharedActivityServices = {
55
55
  settings: Settings;
56
+ /**
57
+ * Original environment/host settings retained across live database-catalog
58
+ * refreshes. Older embedded test hosts may omit it and fall back to settings.
59
+ */
60
+ catalogSourceSettings?: Settings;
56
61
  db: Database;
57
62
  bus: EventBus;
58
63
  objectStorage: ObjectStorage | null;
@@ -357,6 +362,9 @@ export type DispatchAutomationRunResult = {
357
362
  } | {
358
363
  action: "skipped";
359
364
  reason: string;
365
+ } | {
366
+ action: "failed";
367
+ reason: string;
360
368
  } | {
361
369
  action: "not_found";
362
370
  };