@opengeni/worker-bundle 2.2.0 → 2.2.1-canary.36927100590001

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 (88) hide show
  1. package/dist/activities/agent-run-admission.d.ts +3 -1
  2. package/dist/activities/agent-turn/admission.d.ts +24 -3
  3. package/dist/activities/agent-turn/agent-build.d.ts +1 -0
  4. package/dist/activities/agent-turn/claude-usage-observer.d.ts +13 -1
  5. package/dist/activities/agent-turn/compaction-prep.d.ts +20 -0
  6. package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
  7. package/dist/activities/agent-turn/final-reply.d.ts +18 -0
  8. package/dist/activities/agent-turn/governance-model.d.ts +6 -0
  9. package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
  10. package/dist/activities/agent-turn/run-credentials.d.ts +4 -0
  11. package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
  12. package/dist/activities/agent-turn/session-title.d.ts +3 -1
  13. package/dist/activities/agent-turn/stream-attempt.d.ts +1 -0
  14. package/dist/activities/agent-turn/turn-context.d.ts +1 -0
  15. package/dist/activities/automations.d.ts +3 -1
  16. package/dist/activities/browser-deadline-checkpoint.d.ts +29 -0
  17. package/dist/activities/goals.d.ts +8 -0
  18. package/dist/activities/run-credentials.d.ts +4 -2
  19. package/dist/activities/scheduled-tasks.d.ts +4 -35
  20. package/dist/activities/types.d.ts +4 -1
  21. package/dist/activities/workspace-capture.d.ts +2 -0
  22. package/dist/{activities-control-MHNA3CYV.js → activities-control-4F2A734B.js} +502 -133
  23. package/dist/activities-control-4F2A734B.js.map +1 -0
  24. package/dist/activities-control.d.ts +30 -0
  25. package/dist/{activities-turn-FQ5OO2WW.js → activities-turn-TESOIOEX.js} +696 -251
  26. package/dist/activities-turn-TESOIOEX.js.map +1 -0
  27. package/dist/activities.d.ts +30 -0
  28. package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
  29. package/dist/{chunk-RZAAGRFQ.js → chunk-4PJTUBWQ.js} +220 -88
  30. package/dist/chunk-4PJTUBWQ.js.map +1 -0
  31. package/dist/{chunk-IJZU752L.js → chunk-YG27NEMX.js} +34 -1
  32. package/dist/chunk-YG27NEMX.js.map +1 -0
  33. package/dist/index.d.ts +15 -0
  34. package/dist/index.js +46 -24
  35. package/dist/index.js.map +1 -1
  36. package/dist/observability-metrics.d.ts +16 -1
  37. package/dist/sandbox-resume.d.ts +4 -1
  38. package/dist/workflow-bundle.js +89 -21
  39. package/dist/workflows/browser-deadline-checkpoint.d.ts +9 -0
  40. package/dist/workflows/scheduled-tasks.d.ts +4 -0
  41. package/dist/workflows.d.ts +1 -0
  42. package/package.json +21 -20
  43. package/src/activities/agent-run-admission.ts +17 -1
  44. package/src/activities/agent-turn/admission.ts +64 -1
  45. package/src/activities/agent-turn/agent-build.ts +24 -3
  46. package/src/activities/agent-turn/claim.ts +69 -15
  47. package/src/activities/agent-turn/claude-usage-observer.ts +33 -1
  48. package/src/activities/agent-turn/compaction-prep.ts +67 -16
  49. package/src/activities/agent-turn/credential-restriction.ts +14 -0
  50. package/src/activities/agent-turn/errors.ts +55 -0
  51. package/src/activities/agent-turn/failure-settlement.ts +26 -6
  52. package/src/activities/agent-turn/final-reply.ts +46 -0
  53. package/src/activities/agent-turn/governance-model.ts +12 -0
  54. package/src/activities/agent-turn/model-call-admission.ts +94 -0
  55. package/src/activities/agent-turn/run-credentials.ts +20 -3
  56. package/src/activities/agent-turn/run.ts +44 -5
  57. package/src/activities/agent-turn/sandbox-establish.ts +9 -5
  58. package/src/activities/agent-turn/session-title.ts +8 -2
  59. package/src/activities/agent-turn/stream-attempt.ts +144 -38
  60. package/src/activities/agent-turn/tool-environment.ts +55 -39
  61. package/src/activities/agent-turn/turn-context.ts +1 -0
  62. package/src/activities/automations.ts +78 -4
  63. package/src/activities/browser-deadline-checkpoint.ts +279 -0
  64. package/src/activities/capabilities.ts +52 -14
  65. package/src/activities/goals.ts +95 -98
  66. package/src/activities/knowledge-indexing.ts +29 -0
  67. package/src/activities/open-suffix-resume.ts +2 -1
  68. package/src/activities/run-credentials.ts +22 -16
  69. package/src/activities/sandbox-lease.ts +22 -0
  70. package/src/activities/scheduled-tasks.ts +172 -38
  71. package/src/activities/site-auth-maintenance.ts +1 -0
  72. package/src/activities/types.ts +4 -0
  73. package/src/activities/workspace-capture.ts +13 -2
  74. package/src/activities/workspace-credential-provider.ts +12 -0
  75. package/src/activities-control.ts +2 -0
  76. package/src/activities.ts +3 -0
  77. package/src/browser-deadline-checkpoint-contract.ts +5 -0
  78. package/src/index.ts +53 -25
  79. package/src/observability-metrics.ts +55 -1
  80. package/src/sandbox-resume.ts +23 -8
  81. package/src/sandbox-routing.ts +4 -2
  82. package/src/workflows/browser-deadline-checkpoint.ts +50 -0
  83. package/src/workflows/scheduled-tasks.ts +26 -13
  84. package/src/workflows.ts +4 -0
  85. package/dist/activities-control-MHNA3CYV.js.map +0 -1
  86. package/dist/activities-turn-FQ5OO2WW.js.map +0 -1
  87. package/dist/chunk-IJZU752L.js.map +0 -1
  88. package/dist/chunk-RZAAGRFQ.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { type Settings } from "@opengeni/config";
2
2
  import type { ControlActivityServices } from "./types.js";
3
- export type AgentRunAdmissionDenial = "insufficient_credits" | "monthly_model_cost_limit" | "monthly_agent_run_limit";
3
+ export type AgentRunAdmissionDenial = "insufficient_credits" | "allowance_exhausted" | "monthly_model_cost_limit" | "monthly_agent_run_limit";
4
4
  /** One worker-side admission boundary for service-authored agent runs. */
5
5
  export declare function agentRunAdmissionDenial(services: Pick<ControlActivityServices, "db" | "entitlements"> & {
6
6
  settings: Settings;
@@ -9,4 +9,6 @@ export declare function agentRunAdmissionDenial(services: Pick<ControlActivitySe
9
9
  workspaceId: string;
10
10
  model: string;
11
11
  requestedAgentRuns: number;
12
+ /** The accepted work's causal human, not the scheduler/service caller. */
13
+ initiatingHumanSubjectId?: string | null;
12
14
  }): Promise<AgentRunAdmissionDenial | null>;
@@ -1,6 +1,6 @@
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, type XaiProviderAccountAuthoritySnapshotV1 } from "@opengeni/contracts";
3
+ import { type AllowanceExhaustedRefusal, 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
  }
@@ -62,6 +62,27 @@ export declare function stableInteractionInterventionUuid(namespace: string, ses
62
62
  */
63
63
  export declare class BudgetExhaustedError extends Error {
64
64
  readonly serializedRunState: string | null;
65
- constructor(message: string, serializedRunState: string | null);
65
+ readonly allowance: AllowanceRefusal | null;
66
+ constructor(message: string, serializedRunState: string | null, allowance?: AllowanceRefusal | null);
66
67
  }
67
- export declare function ensureRunAllowed(settings: Settings, db: ActivityServices["db"], accountId: string, workspaceId: string, isExternallyBilledTurn: boolean, entitlements?: ActivityServices["entitlements"], chargesOpenGeniCredits?: boolean, countsTowardTokenCap?: boolean): Promise<void>;
68
+ export type AllowanceRefusal = AllowanceExhaustedRefusal;
69
+ /** Account allowance exhaustion is recoverable state, never a provider failure. */
70
+ export declare class AllowanceExhaustedError extends Error {
71
+ readonly refusal: AllowanceRefusal;
72
+ readonly code = "allowance_exhausted";
73
+ constructor(refusal: AllowanceRefusal);
74
+ }
75
+ /** Revalidate between paid calls without replaying provider work or reserving credits. */
76
+ export declare function ensureRunAllowedBetweenModelCalls(input: {
77
+ settings: Settings;
78
+ db: ActivityServices["db"];
79
+ accountId: string;
80
+ workspaceId: string;
81
+ isExternallyBilledTurn: boolean;
82
+ entitlements?: ActivityServices["entitlements"];
83
+ chargesOpenGeniCredits: boolean;
84
+ countsTowardTokenCap: boolean;
85
+ initiatingHumanSubjectId: string | null;
86
+ serializedRunState?: () => string | null;
87
+ }): Promise<void>;
88
+ export declare function ensureRunAllowed(settings: Settings, db: ActivityServices["db"], accountId: string, workspaceId: string, isExternallyBilledTurn: boolean, entitlements?: ActivityServices["entitlements"], chargesOpenGeniCredits?: boolean, countsTowardTokenCap?: boolean, initiatingHumanSubjectId?: string | null): Promise<void>;
@@ -43,6 +43,7 @@ export type BuildTurnAgentDeps = {
43
43
  supportsImageInput: GovernanceModelOk["supportsImageInput"];
44
44
  agentHumanInputEnabled: GovernanceModelOk["agentHumanInputEnabled"];
45
45
  workspaceAgentInstructions: GovernanceModelOk["workspaceAgentInstructions"];
46
+ workspaceAgentIdentity: GovernanceModelOk["workspaceAgentIdentity"];
46
47
  workspaceGovernance: GovernanceModelOk["workspaceGovernance"];
47
48
  structuredWorkspacePolicyActive: GovernanceModelOk["structuredWorkspacePolicyActive"];
48
49
  workspaceMemory: GovernanceModelOk["workspaceMemory"];
@@ -15,5 +15,17 @@ export declare function createClaudeUsageObserver(providers: ReturnType<typeof p
15
15
  token: string;
16
16
  connectionId: string;
17
17
  credentialVersion: number;
18
- } | null>): Promise<(providerId: string, response: Response) => void>;
18
+ } | null>): Promise<((providerId: string, response: Response) => void) & {
19
+ binding(providerId: string): {
20
+ readonly scope: Scope;
21
+ readonly token: string;
22
+ readonly expectedConnectionId: string;
23
+ readonly expectedCredentialVersion: number;
24
+ } | undefined;
25
+ renew(providerId: string, credential: {
26
+ token: string;
27
+ connectionId: string;
28
+ credentialVersion: number;
29
+ }): void;
30
+ }>;
19
31
  export {};
@@ -37,6 +37,7 @@ export type CompactionPrepDeps = {
37
37
  turnExecutionPolicy: ClaimTurnOk["turnExecutionPolicy"];
38
38
  resolvedModel: GovernanceModelOk["resolvedModel"];
39
39
  workspaceAgentInstructions: GovernanceModelOk["workspaceAgentInstructions"];
40
+ workspaceAgentIdentity: GovernanceModelOk["workspaceAgentIdentity"];
40
41
  workspaceGovernance: GovernanceModelOk["workspaceGovernance"];
41
42
  structuredWorkspacePolicyActive: GovernanceModelOk["structuredWorkspacePolicyActive"];
42
43
  workspaceMemory: GovernanceModelOk["workspaceMemory"];
@@ -82,5 +83,24 @@ export type PostAgentCompactionOutcome = {
82
83
  } | {
83
84
  ok: PostAgentCompactionOk;
84
85
  };
86
+ /**
87
+ * System instructions for the standalone (chat-provider) compaction request.
88
+ * A session with an agent configuration uses the same modular composer and
89
+ * module selection as its turns; a legacy session keeps the historical
90
+ * persona + CORE + governance + session + memory string byte-for-byte.
91
+ */
92
+ export declare function standaloneCompactionInstructions(input: {
93
+ settings: Settings;
94
+ session: Pick<ClaimTurnOk["session"], "agent" | "instructions" | "resources">;
95
+ workspaceAgentInstructions: string | null | undefined;
96
+ workspaceAgentIdentity: string | null;
97
+ workspaceGovernance: string | null | undefined;
98
+ structuredWorkspacePolicyActive: boolean;
99
+ workspaceMemory: string | null | undefined;
100
+ rig: {
101
+ name: string;
102
+ version: number;
103
+ } | undefined;
104
+ }): string;
85
105
  export declare function prepareCompaction(deps: CompactionPrepDeps): Promise<CompactionPrepOutcome>;
86
106
  export declare function runPostAgentCompaction(deps: PostAgentCompactionDeps): Promise<PostAgentCompactionOutcome>;
@@ -0,0 +1,3 @@
1
+ import { type TurnExecutionPolicyV1 } from "@opengeni/contracts";
2
+ /** Only accepted policies establish the ceiling; ordinary metadata is not authority. */
3
+ export declare function turnCredentialRestriction(acceptedPolicy: TurnExecutionPolicyV1, initialSessionMetadata: unknown): "developer_setup" | undefined;
@@ -0,0 +1,18 @@
1
+ /** One durable, same-logical-turn handoff, not a retry of model/tool effects. */
2
+ export declare function finalReplyNudge(turnId: string): {
3
+ type: "message";
4
+ role: "developer";
5
+ content: {
6
+ type: "input_text";
7
+ text: string;
8
+ }[];
9
+ };
10
+ export declare function hasFinalReplyNudge(history: readonly unknown[], turnId: string): boolean;
11
+ export declare function needsFinalReply(input: {
12
+ output: unknown;
13
+ inputWaitYielded: boolean;
14
+ interrupted: boolean;
15
+ maintenance: boolean;
16
+ toolsExecuted: boolean;
17
+ completedGoal: boolean;
18
+ }): boolean;
@@ -40,6 +40,12 @@ export type GovernanceModelOk = {
40
40
  /** Deployment and workspace allow the Jev-backed code_search tool. */
41
41
  codeSearchEnabled: boolean;
42
42
  workspaceAgentInstructions: string | null | undefined;
43
+ /**
44
+ * Modular composer identity tier: the explicit workspace default identity,
45
+ * else the frozen legacy persona without `{{core}}`. Never dropped by
46
+ * instruction policies (only read for sessions with an agent configuration).
47
+ */
48
+ workspaceAgentIdentity: string | null;
43
49
  workspaceGovernance: ReturnType<typeof renderWorkspaceGovernanceContext>;
44
50
  structuredWorkspacePolicyActive: boolean;
45
51
  workspaceMemory: string | null | undefined;
@@ -0,0 +1,15 @@
1
+ import type { StreamEvent } from "@openai/agents";
2
+ /** SDK producer/consumer rendezvous. Usage stays on the sole consumer writer. */
3
+ export declare function createModelCallAdmission(input: {
4
+ signal: AbortSignal;
5
+ admit: () => Promise<void>;
6
+ }): {
7
+ beforeModelRequest: () => Promise<void>;
8
+ onModelResponse: (event: StreamEvent) => Promise<void>;
9
+ settle: (event: {
10
+ type: string;
11
+ data?: unknown;
12
+ }) => void;
13
+ fail: (error: unknown) => void;
14
+ close: () => void;
15
+ };
@@ -2,6 +2,7 @@ import { type GitCredentialTokenWriterSession, type NormalizedRunCredentialMater
2
2
  import { type Settings } from "@opengeni/config";
3
3
  import { type GitHubTokenMintAuthorization, type MintedRunGitCredentials, type loadWorkspaceEnvironmentForRunWithCredentials } from "../environment.js";
4
4
  import type { mergeResourceRefs } from "../common.js";
5
+ import type { withFirstPartyTools } from "../goals.js";
5
6
  import type { TurnActivityServices as ActivityServices, RunAgentTurnInput } from "../types.js";
6
7
  import { type ResumedTurnSandbox } from "../../sandbox-resume.js";
7
8
  import type { ClaimTurnOk } from "./claim.js";
@@ -10,6 +11,7 @@ import type { SandboxTurnRuntime } from "./sandbox-runtime.js";
10
11
  import type { AttemptIdentityState, EventingState, RenewalState, SandboxRuntimeState } from "./turn-context.js";
11
12
  export type PrepareRunCredentialsDeps = {
12
13
  localMcpServerIds?: readonly string[];
14
+ turnTools: ReturnType<typeof withFirstPartyTools>;
13
15
  input: RunAgentTurnInput;
14
16
  settings: Settings;
15
17
  db: ActivityServices["db"];
@@ -24,6 +26,7 @@ export type PrepareRunCredentialsDeps = {
24
26
  sandboxRuntime: SandboxTurnRuntime;
25
27
  turn: ClaimTurnOk["turn"];
26
28
  session: ClaimTurnOk["session"];
29
+ turnExecutionPolicy: ClaimTurnOk["turnExecutionPolicy"];
27
30
  fileAuthoritySubjectId: ClaimTurnOk["fileAuthoritySubjectId"];
28
31
  runSettings: GovernanceModelOk["runSettings"];
29
32
  workspaceVariableSet: Awaited<ReturnType<typeof loadWorkspaceEnvironmentForRunWithCredentials>>;
@@ -62,6 +65,7 @@ export declare function prepareRunCredentials(deps: PrepareRunCredentialsDeps):
62
65
  turnId: string;
63
66
  attemptId: string;
64
67
  executionGeneration: number;
68
+ credentialRestriction?: "developer_setup";
65
69
  };
66
70
  sandboxArtifactRuntime: Readonly<{
67
71
  available: boolean;
@@ -35,6 +35,7 @@ export type SandboxRouteOk = {
35
35
  machinePrimary: boolean;
36
36
  groupBoxBackend: Settings["sandboxBackend"];
37
37
  groupBoxImage: ReturnType<typeof rigProviderImageSourceImage>;
38
+ groupBoxImagePolicy: "new_creates_only";
38
39
  sandboxCreationBackend: Settings["sandboxBackend"];
39
40
  effectiveRunCredentialBackend: Settings["sandboxBackend"];
40
41
  };
@@ -1,11 +1,12 @@
1
1
  import type { AttemptToolDefinition } from "@opengeni/codemode";
2
2
  import { type ModelCapabilitiesV1 } from "@opengeni/config";
3
3
  import type { GeneratedSessionTitle, GenerateSessionTitleOptions, OpenGeniRuntime } from "@opengeni/runtime";
4
- import { ReasoningEffort, type FirstPartyMcpToolName, type Permission, type ToolRef } from "@opengeni/contracts";
4
+ import { ReasoningEffort, type FirstPartyMcpToolName, type Permission, type ResolvedAgentConfig, type ToolRef } from "@opengeni/contracts";
5
5
  export declare const SESSION_TITLE_MODEL_TOOL_NAME = "opengeni__set_session_title";
6
6
  export declare function shouldRequestMissingSessionTitle(input: {
7
7
  title: string | null;
8
8
  titleSource: "user" | "agent" | null;
9
+ agentConfig?: ResolvedAgentConfig | null;
9
10
  firstPartyMcpTools: readonly FirstPartyMcpToolName[];
10
11
  firstPartyMcpPermissions: readonly Permission[] | null;
11
12
  }): boolean;
@@ -20,6 +21,7 @@ export declare function shouldRequestMissingSessionTitle(input: {
20
21
  export declare function routeAllowsSessionTitleRequests(resolvedModel: ReturnType<OpenGeniRuntime["resolveTurnModel"]>): boolean;
21
22
  export declare function sessionTitleToolPlan(input: {
22
23
  tools: readonly ToolRef[];
24
+ agentConfig?: ResolvedAgentConfig | null;
23
25
  selectedFirstPartyMcpTools: readonly FirstPartyMcpToolName[];
24
26
  shouldRequestTitle: boolean;
25
27
  parallelGenerationAvailable: boolean;
@@ -81,6 +81,7 @@ export type TurnStreamAttemptDeps = {
81
81
  groupBoxBackend: Settings["sandboxBackend"];
82
82
  turnExecutionPolicy: TurnExecutionPolicyV1;
83
83
  turn: Pick<SessionTurn, "initiator" | "initiatorContext"> & {
84
+ initiatingHumanSubjectId: string | null;
84
85
  id: string;
85
86
  executionGeneration: number;
86
87
  model: string;
@@ -25,6 +25,7 @@ export type TurnSettleFn = (input: {
25
25
  sessionStatus: SessionStatus;
26
26
  activeTurnId: string | null;
27
27
  suppressGoalContinuation?: boolean;
28
+ allowanceGoalPause?: ApplySessionTurnSettlementInput["allowanceGoalPause"];
28
29
  consumeRequestedCompactionFailure?: boolean;
29
30
  runState?: ApplySessionTurnSettlementInput["runState"];
30
31
  }) => Promise<boolean>;
@@ -1,5 +1,5 @@
1
1
  import { assertWorkspaceModelPolicyAllows, createAndStartSessionWithOutcome, recordWorkspaceUsage } from "@opengeni/core";
2
- import { assertAutomationRunAuthorityInTransaction, claimAutomationRun, settleAutomationRun } from "@opengeni/db";
2
+ import { assertAutomationRunAuthorityInTransaction, claimAutomationRun, settleAutomationRun, requireWorkspace } from "@opengeni/db";
3
3
  import { agentRunAdmissionDenial } from "./agent-run-admission.js";
4
4
  import type { ControlActivityServices, DispatchAutomationRunInput, DispatchAutomationRunResult } from "./types.js";
5
5
  export type AutomationActivityOptions = {
@@ -7,6 +7,8 @@ export type AutomationActivityOptions = {
7
7
  settle?: typeof settleAutomationRun;
8
8
  assertAuthority?: typeof assertAutomationRunAuthorityInTransaction;
9
9
  createSession?: typeof createAndStartSessionWithOutcome;
10
+ /** Workspace read for agent-configuration defaults (tests inject it). */
11
+ readWorkspace?: typeof requireWorkspace;
10
12
  admit?: typeof agentRunAdmissionDenial;
11
13
  assertModelPolicy?: typeof assertWorkspaceModelPolicyAllows;
12
14
  recordUsage?: typeof recordWorkspaceUsage;
@@ -0,0 +1,29 @@
1
+ import { type Settings } from "@opengeni/config";
2
+ import { readLease, type BrowserDeadlineCheckpointTarget } from "@opengeni/db";
3
+ import { BrowserControlClient } from "@opengeni/runtime";
4
+ import type { ControlActivityServices } from "./types.js";
5
+ type CheckpointController = Pick<BrowserControlClient, "captureState" | "endSession">;
6
+ type CheckpointPlacement = {
7
+ target: BrowserDeadlineCheckpointTarget;
8
+ lease: NonNullable<Awaited<ReturnType<typeof readLease>>>;
9
+ settings: Settings;
10
+ controllerRoot: string;
11
+ };
12
+ export declare function createBrowserDeadlineCheckpointActivities(services: () => Promise<ControlActivityServices>, connectController?: (placement: CheckpointPlacement) => Promise<CheckpointController>): {
13
+ listDueBrowserCheckpoints(): Promise<{
14
+ accountId: string;
15
+ workspaceId: string;
16
+ sandboxGroupId: string;
17
+ leaseId: string;
18
+ leaseEpoch: number;
19
+ instanceId: string;
20
+ browserSessionId: string;
21
+ controllerGeneration: string;
22
+ }[]>;
23
+ checkpointBrowserBeforeDeadline(target: BrowserDeadlineCheckpointTarget): Promise<{
24
+ status: "skipped";
25
+ } | {
26
+ status: "suspended";
27
+ }>;
28
+ };
29
+ export {};
@@ -2,6 +2,7 @@ import { type Settings } from "@opengeni/config";
2
2
  import { type SessionGoal, type ToolRef } from "@opengeni/contracts";
3
3
  import { getWorkspaceModelPolicy } from "@opengeni/db";
4
4
  import type { ControlActivityServices, MaybeContinueGoalInput, MaybeContinueGoalResult } from "./types.js";
5
+ import { agentRunAdmissionDenial } from "./agent-run-admission.js";
5
6
  export declare function createGoalActivities(services: () => Promise<ControlActivityServices>): {
6
7
  enqueueGoalRetryWake: (input: MaybeContinueGoalInput) => Promise<void>;
7
8
  maybeContinueGoal: (input: MaybeContinueGoalInput) => Promise<MaybeContinueGoalResult>;
@@ -27,3 +28,10 @@ export declare function goalContinuationPrompt(_goal: SessionGoal, _autoContinua
27
28
  * lists anywhere else in the pipeline. No-op when the server is not configured.
28
29
  */
29
30
  export declare function withFirstPartyTools(settings: Settings, tools: ToolRef[]): ToolRef[];
31
+ /**
32
+ * Goals share scheduled admission and pause visibly without synthesizing work.
33
+ */
34
+ export declare function goalRunBudgetBlocked(services: Parameters<typeof agentRunAdmissionDenial>[0], input: Omit<Parameters<typeof agentRunAdmissionDenial>[1], "requestedAgentRuns">): Promise<{
35
+ pausedReason: "limits" | "allowance";
36
+ message: string;
37
+ } | null>;
@@ -1,4 +1,4 @@
1
- import type { ConnectionCredentialsPort, CredentialAuthNeededPayload, SandboxBackend, RunCredentialsRequest, Session, SessionTurn } from "@opengeni/contracts";
1
+ import type { ConnectionCredentialsPort, CredentialAuthNeededPayload, SandboxBackend, RunCredentialsRequest, Session, SessionTurn, ToolRef } from "@opengeni/contracts";
2
2
  import type { Settings } from "@opengeni/config";
3
3
  import { type Database } from "@opengeni/db";
4
4
  import { type NormalizedRunCredentialMaterial } from "@opengeni/runtime";
@@ -22,6 +22,8 @@ export type RunCredentialResolutionContext = {
22
22
  initiatingHumanSubjectId?: string | null;
23
23
  /** Installed in-process API routes must never enter a product callback. */
24
24
  localMcpServerIds?: readonly string[];
25
+ /** Exact execution selection, resolved once at the turn policy boundary. */
26
+ effectiveTools: readonly ToolRef[];
25
27
  };
26
28
  export type BoundRunCredentialResolver = {
27
29
  resolve(input: {
@@ -29,7 +31,7 @@ export type BoundRunCredentialResolver = {
29
31
  forceRefresh: boolean;
30
32
  }): Promise<NormalizedRunCredentialMaterial | null>;
31
33
  };
32
- export declare function buildRunCredentialsRequest(input: Omit<RunCredentialResolutionContext, "db" | "connectionCredentials" | "settings" | "initiatingHumanSubjectId"> & {
34
+ export declare function buildRunCredentialsRequest(input: Omit<RunCredentialResolutionContext, "db" | "connectionCredentials" | "settings" | "initiatingHumanSubjectId" | "effectiveTools"> & {
33
35
  rootSessionId: string;
34
36
  purpose: "provision" | "renewal";
35
37
  forceRefresh: boolean;
@@ -1,3 +1,4 @@
1
+ import { TurnExecutionPolicyV1 } from "@opengeni/contracts";
1
2
  import { updateSessionTitleWithEvent } from "@opengeni/db";
2
3
  import type { ControlActivityServices, DispatchScheduledTaskRunInput, DispatchScheduledTaskRunResult } from "./types.js";
3
4
  import type { Database } from "@opengeni/db";
@@ -9,43 +10,11 @@ type ScheduledTemporalActivityIdentity = {
9
10
  };
10
11
  activityId: string;
11
12
  };
13
+ export declare function scheduledTaskRunExecutionPolicy(policy: TurnExecutionPolicyV1, input: DispatchScheduledTaskRunInput, creatorRestriction?: "developer_setup"): TurnExecutionPolicyV1;
14
+ /** Only a creator ceiling is standing; a manual caller ceiling is per-run. */
15
+ export declare function scheduledSessionExecutionPolicyMetadata(policy: unknown, creatorRestriction?: "developer_setup"): Record<string, unknown>;
12
16
  export declare function scheduledTaskRunProducerKey(input: DispatchScheduledTaskRunInput, suppliedActivityIdentity?: ScheduledTemporalActivityIdentity): string;
13
17
  export declare function scheduledTaskGeneratedSessionCreateIdempotencyKey(producerKey: string): string;
14
- /**
15
- * Display title for a session the scheduler generates for a task.
16
- *
17
- * A scheduled session's `initialMessage` is the task prompt, byte-identical for
18
- * every run. The task name is the short human-chosen label that actually
19
- * identifies it, so that is the title.
20
- *
21
- * The title is the task name and NOTHING else. It deliberately does not name the
22
- * run's fire instant, for two independent reasons:
23
- *
24
- * - No run mode guarantees one run per session. `reusable_session` generates
25
- * its session on the first fire and then reuses it forever, and even under
26
- * `new_session_per_run` alert-occurrence redelivery converges several runs
27
- * onto one canonical responder session. `existing_session` never generates a
28
- * session at all, so the scheduler never titles one. A run-specific fact
29
- * frozen into the title is therefore right for the generating run and a lie
30
- * for every run that lands in the same session afterwards.
31
- * - A title is one stored string shown to every viewer, while every surface
32
- * that renders a run's fire instant renders it viewer-local: the rail row
33
- * prints the title beside `relativeTimeLabel(session.updatedAt)`, and the
34
- * Schedules run list prints `formatTimestamp(run.firedAt)`, which is
35
- * `toLocaleString()`. A wall clock stored in the title therefore disagrees
36
- * with the time printed next to it for every viewer outside whichever zone
37
- * it was rendered in. The task's own `timeZone` is no escape: it labels the
38
- * schedule rule ("Mon Wed 09:00 Europe/Oslo"), not the rendering of a run,
39
- * which stays viewer-local. No stored clock can agree with a viewer-local
40
- * one, so the title carries none and the instant stays on the surfaces that
41
- * already render it correctly.
42
- *
43
- * Dropping the clock settles the determinism constraint outright rather than
44
- * working around it: the same run titled by the normal dispatch or by a later
45
- * recovery in a different worker process derives one string from `task.name`
46
- * alone, with no Intl call and so no host ICU or tzdata build to make the two
47
- * texts differ.
48
- */
49
18
  export declare function scheduledTaskSessionTitle(taskName: string): string;
50
19
  /**
51
20
  * Title a session the scheduler generated, and emit the same `session.title_set`
@@ -343,11 +343,14 @@ export type DispatchScheduledTaskRunInput = {
343
343
  triggerType: Extract<ScheduledTaskTriggerType, "scheduled">;
344
344
  agentRunUsageIdempotencyKey?: never;
345
345
  initiator?: never;
346
+ credentialRestriction?: never;
346
347
  } | {
347
348
  triggerType: Extract<ScheduledTaskTriggerType, "manual" | "initial" | "provider_event" | "retry" | "repair">;
348
349
  agentRunUsageIdempotencyKey: string;
349
350
  /** Exact identity used by the API-side charge for this same trigger. */
350
351
  initiator: TurnInitiator;
352
+ /** Trusted API-side caller ceiling for this occurrence, not the schedule. */
353
+ credentialRestriction?: "developer_setup";
351
354
  });
352
355
  export type DispatchScheduledTaskRunResult = {
353
356
  action: "deleted";
@@ -357,7 +360,7 @@ export type DispatchScheduledTaskRunResult = {
357
360
  diagnostic?: import("@opengeni/contracts").ConnectionAccountSelectionDiagnostic;
358
361
  /** Present when the occurrence was refused as a visible run receipt. */
359
362
  refusal?: import("@opengeni/contracts").ScheduledTaskAdmissionRefusal;
360
- reason: "insufficient_credits" | "monthly_model_cost_limit" | "monthly_agent_run_limit" | "malformed_manual_trigger" | "scheduled_task_paused" | "scheduled_authority_exhausted" | "scheduled_run_terminal" | "scheduled_execution_unrepresentable" | "connection_account_unavailable" | "scheduled_authority_unavailable" | "machine_target_unavailable" | "machine_enrollment_inactive" | "variable_set_unavailable" | "rig_version_unavailable" | "knowledge_source_paused" | "legacy_source_schedule_requires_migration" | "incident_preflight_metadata_missing" | "incident_responder_under_capable" | "incident_data_source_unsuitable";
363
+ reason: "insufficient_credits" | "allowance_exhausted" | "monthly_model_cost_limit" | "monthly_agent_run_limit" | "malformed_manual_trigger" | "scheduled_task_paused" | "scheduled_authority_exhausted" | "scheduled_run_terminal" | "scheduled_execution_unrepresentable" | "connection_account_unavailable" | "scheduled_authority_unavailable" | "machine_target_unavailable" | "machine_enrollment_inactive" | "variable_set_unavailable" | "rig_version_unavailable" | "knowledge_source_paused" | "legacy_source_schedule_requires_migration" | "incident_preflight_metadata_missing" | "incident_responder_under_capable" | "incident_data_source_unsuitable";
361
364
  } | {
362
365
  action: "start" | "signal";
363
366
  accountId: string;
@@ -108,6 +108,8 @@ export declare function captureWhileIdle(input: {
108
108
  * to release() regardless.
109
109
  */
110
110
  export declare function captureWorkspaceRevision(input: CaptureWorkspaceRevisionInput): Promise<void>;
111
+ /** Count one committed logical capture and observe its end-to-end duration. */
112
+ export declare function recordWorkspaceCaptureCompleted(observability: Pick<Observability, "incrementCounter" | "observeHistogram">, durationMs: number): void;
111
113
  /**
112
114
  * sha256 over the CHANGE SURFACE only — per-file (path, status, hash, deleted,
113
115
  * tooLarge), exact HEAD identity, the working diff summary, and exact committed