@opengeni/worker-bundle 1.0.1 → 1.0.2-canary.37202341988001

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 (244) 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 +4 -0
  4. package/dist/activities/agent-turn/claude-usage-observer.d.ts +58 -0
  5. package/dist/activities/agent-turn/code-search.d.ts +60 -0
  6. package/dist/activities/agent-turn/codex-capacity.d.ts +13 -0
  7. package/dist/activities/agent-turn/codex-plan-entitlement.d.ts +105 -0
  8. package/dist/activities/agent-turn/codex.d.ts +3 -2
  9. package/dist/activities/agent-turn/compaction-prep.d.ts +21 -5
  10. package/dist/activities/agent-turn/credential-leases.d.ts +19 -33
  11. package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
  12. package/dist/activities/agent-turn/errors.d.ts +82 -11
  13. package/dist/activities/agent-turn/failure-settlement.d.ts +6 -3
  14. package/dist/activities/agent-turn/final-reply.d.ts +18 -0
  15. package/dist/activities/agent-turn/finalization-monitor.d.ts +17 -0
  16. package/dist/activities/agent-turn/finalization.d.ts +4 -2
  17. package/dist/activities/agent-turn/github-repository-bindings.d.ts +2 -0
  18. package/dist/activities/agent-turn/governance-model.d.ts +9 -2
  19. package/dist/activities/agent-turn/history-sink.d.ts +2 -0
  20. package/dist/activities/agent-turn/history.d.ts +2 -0
  21. package/dist/activities/agent-turn/input-wait-reply.d.ts +41 -0
  22. package/dist/activities/agent-turn/media-artifacts.d.ts +5 -3
  23. package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
  24. package/dist/activities/agent-turn/model-usage.d.ts +6 -0
  25. package/dist/activities/agent-turn/model-wire-dispatch.d.ts +15 -0
  26. package/dist/activities/agent-turn/optional-repositories.d.ts +59 -0
  27. package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +12 -1
  28. package/dist/activities/agent-turn/quiescence.d.ts +7 -7
  29. package/dist/activities/agent-turn/recovery-warning.d.ts +9 -0
  30. package/dist/activities/agent-turn/refresh-credentials.d.ts +6 -0
  31. package/dist/activities/agent-turn/run-credentials.d.ts +8 -3
  32. package/dist/activities/agent-turn/sandbox-establish.d.ts +2 -1
  33. package/dist/activities/agent-turn/sandbox-provision.d.ts +3 -1
  34. package/dist/activities/agent-turn/sandbox-route.d.ts +3 -20
  35. package/dist/activities/agent-turn/sandbox-runtime.d.ts +2 -2
  36. package/dist/activities/agent-turn/session-title.d.ts +34 -2
  37. package/dist/activities/agent-turn/skill-checkout.d.ts +25 -6
  38. package/dist/activities/agent-turn/skill-read.d.ts +70 -2
  39. package/dist/activities/agent-turn/skill-remove.d.ts +14 -0
  40. package/dist/activities/agent-turn/skill-search.d.ts +3 -1
  41. package/dist/activities/agent-turn/skill-tools.d.ts +15 -2
  42. package/dist/activities/agent-turn/skill-transfer.d.ts +18 -6
  43. package/dist/activities/agent-turn/stream-attempt.d.ts +7 -3
  44. package/dist/activities/agent-turn/subscription-lease.d.ts +38 -0
  45. package/dist/activities/agent-turn/tool-environment.d.ts +56 -6
  46. package/dist/activities/agent-turn/tool-policy.d.ts +43 -0
  47. package/dist/activities/agent-turn/turn-context.d.ts +29 -0
  48. package/dist/activities/agent-turn/turn-sandbox-access.d.ts +3 -0
  49. package/dist/activities/agent-turn/xai-capacity.d.ts +2 -1
  50. package/dist/activities/automations.d.ts +3 -1
  51. package/dist/activities/browser-deadline-checkpoint.d.ts +29 -0
  52. package/dist/activities/codemode-dispatcher.d.ts +9 -2
  53. package/dist/activities/codex-capacity.d.ts +18 -2
  54. package/dist/activities/codex-rotation.d.ts +7 -1
  55. package/dist/activities/context-compaction.d.ts +16 -2
  56. package/dist/activities/gmail-files.d.ts +32 -0
  57. package/dist/activities/goals.d.ts +8 -0
  58. package/dist/activities/knowledge-indexing.d.ts +19 -0
  59. package/dist/activities/mcp-account-routes.d.ts +3 -0
  60. package/dist/activities/mcp-credentials.d.ts +12 -13
  61. package/dist/activities/mcp-operation-authority.d.ts +0 -5
  62. package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
  63. package/dist/activities/open-suffix-resume.d.ts +13 -0
  64. package/dist/activities/parent-wake.d.ts +6 -12
  65. package/dist/activities/retained-screenshots.d.ts +7 -2
  66. package/dist/activities/rig-verification.d.ts +2 -3
  67. package/dist/activities/run-credential-renewal.d.ts +1 -0
  68. package/dist/activities/run-credentials.d.ts +15 -3
  69. package/dist/activities/sandbox-images.d.ts +1 -1
  70. package/dist/activities/sandbox-lease.d.ts +47 -9
  71. package/dist/activities/scheduled-tasks.d.ts +4 -35
  72. package/dist/activities/session-state.d.ts +70 -3
  73. package/dist/activities/types.d.ts +55 -6
  74. package/dist/activities/workspace-capture.d.ts +2 -0
  75. package/dist/activities/workspace-credential-provider.d.ts +46 -0
  76. package/dist/{activities-control-HMFGSKC5.js → activities-control-BNPTRTOE.js} +1896 -418
  77. package/dist/activities-control-BNPTRTOE.js.map +1 -0
  78. package/dist/activities-control.d.ts +182 -4
  79. package/dist/{activities-turn-AP67JADS.js → activities-turn-5LGZOSVU.js} +4476 -1327
  80. package/dist/activities-turn-5LGZOSVU.js.map +1 -0
  81. package/dist/activities.d.ts +182 -4
  82. package/dist/artifact-materializer-entry.js +5 -2
  83. package/dist/artifact-materializer-entry.js.map +1 -1
  84. package/dist/artifact-outbox-entry.js +5 -2
  85. package/dist/artifact-outbox-entry.js.map +1 -1
  86. package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
  87. package/dist/{chunk-A4XQWVZK.js → chunk-3ZTRWDMN.js} +307 -4
  88. package/dist/chunk-3ZTRWDMN.js.map +1 -0
  89. package/dist/{chunk-RAMNYSAW.js → chunk-4ER3YXOT.js} +22 -4
  90. package/dist/chunk-4ER3YXOT.js.map +1 -0
  91. package/dist/{chunk-CYITU5UH.js → chunk-LJX7Z2KP.js} +1445 -343
  92. package/dist/chunk-LJX7Z2KP.js.map +1 -0
  93. package/dist/editable-artifact-materializer-service.d.ts +2 -2
  94. package/dist/editable-artifact-outbox-service.d.ts +2 -2
  95. package/dist/host-export-pump.d.ts +3 -1
  96. package/dist/host-export.d.ts +1 -1
  97. package/dist/host-export.js +1 -1
  98. package/dist/http.d.ts +1 -1
  99. package/dist/index.d.ts +95 -3
  100. package/dist/index.js +137 -43
  101. package/dist/index.js.map +1 -1
  102. package/dist/observability-metrics.d.ts +118 -8
  103. package/dist/retained-process-diagnostics.d.ts +4 -0
  104. package/dist/retained-process-retry.d.ts +7 -0
  105. package/dist/sandbox-resume.d.ts +55 -13
  106. package/dist/sandbox-routing.d.ts +5 -3
  107. package/dist/sandbox-snapshot-diagnostics.d.ts +20 -0
  108. package/dist/session-event-fanout.d.ts +6 -0
  109. package/dist/warm-capture-holder.d.ts +3 -0
  110. package/dist/worker-service-lifecycle.d.ts +12 -0
  111. package/dist/workflow-bundle.js +273 -41
  112. package/dist/workflows/activities.d.ts +1 -1
  113. package/dist/workflows/browser-deadline-checkpoint.d.ts +9 -0
  114. package/dist/workflows/scheduled-tasks.d.ts +4 -0
  115. package/dist/workflows/session.d.ts +36 -0
  116. package/dist/workflows.d.ts +1 -0
  117. package/package.json +21 -19
  118. package/src/activities/agent-run-admission.ts +17 -1
  119. package/src/activities/agent-turn/admission.ts +66 -3
  120. package/src/activities/agent-turn/agent-build.ts +84 -10
  121. package/src/activities/agent-turn/claim.ts +186 -43
  122. package/src/activities/agent-turn/claude-usage-observer.ts +221 -0
  123. package/src/activities/agent-turn/code-search.ts +275 -0
  124. package/src/activities/agent-turn/codex-capacity.ts +172 -8
  125. package/src/activities/agent-turn/codex-plan-entitlement.ts +254 -0
  126. package/src/activities/agent-turn/codex.ts +13 -5
  127. package/src/activities/agent-turn/compaction-prep.ts +170 -102
  128. package/src/activities/agent-turn/credential-leases.ts +122 -216
  129. package/src/activities/agent-turn/credential-restriction.ts +14 -0
  130. package/src/activities/agent-turn/errors.ts +647 -48
  131. package/src/activities/agent-turn/failure-settlement.ts +682 -130
  132. package/src/activities/agent-turn/final-reply.ts +46 -0
  133. package/src/activities/agent-turn/finalization-monitor.ts +120 -0
  134. package/src/activities/agent-turn/finalization.ts +146 -43
  135. package/src/activities/agent-turn/github-repository-bindings.ts +3 -1
  136. package/src/activities/agent-turn/governance-model.ts +69 -28
  137. package/src/activities/agent-turn/history-sink.ts +16 -2
  138. package/src/activities/agent-turn/history.ts +38 -11
  139. package/src/activities/agent-turn/input-wait-reply.ts +103 -0
  140. package/src/activities/agent-turn/knowledge-source-tools.ts +2 -0
  141. package/src/activities/agent-turn/media-artifacts.ts +2 -1
  142. package/src/activities/agent-turn/model-call-admission.ts +94 -0
  143. package/src/activities/agent-turn/model-usage.ts +64 -3
  144. package/src/activities/agent-turn/model-wire-dispatch.ts +27 -0
  145. package/src/activities/agent-turn/optional-repositories.ts +224 -0
  146. package/src/activities/agent-turn/provider-dispatch-barrier.ts +22 -0
  147. package/src/activities/agent-turn/quiescence.ts +10 -7
  148. package/src/activities/agent-turn/recovery-warning.ts +16 -0
  149. package/src/activities/agent-turn/refresh-credentials.ts +44 -0
  150. package/src/activities/agent-turn/run-credentials.ts +116 -55
  151. package/src/activities/agent-turn/run.ts +320 -93
  152. package/src/activities/agent-turn/sandbox-establish.ts +84 -8
  153. package/src/activities/agent-turn/sandbox-provision.ts +3 -1
  154. package/src/activities/agent-turn/sandbox-route.ts +4 -21
  155. package/src/activities/agent-turn/sandbox-runtime.ts +343 -18
  156. package/src/activities/agent-turn/session-title.ts +81 -5
  157. package/src/activities/agent-turn/skill-checkout.ts +111 -24
  158. package/src/activities/agent-turn/skill-install.ts +1 -1
  159. package/src/activities/agent-turn/skill-read.ts +374 -28
  160. package/src/activities/agent-turn/skill-remove.ts +46 -0
  161. package/src/activities/agent-turn/skill-save.ts +1 -1
  162. package/src/activities/agent-turn/skill-search.ts +10 -1
  163. package/src/activities/agent-turn/skill-selection.ts +4 -0
  164. package/src/activities/agent-turn/skill-tools.ts +112 -18
  165. package/src/activities/agent-turn/skill-transfer.ts +68 -23
  166. package/src/activities/agent-turn/stream-attempt.ts +313 -77
  167. package/src/activities/agent-turn/subscription-lease.ts +115 -0
  168. package/src/activities/agent-turn/tool-environment.ts +316 -167
  169. package/src/activities/agent-turn/tool-policy.ts +80 -1
  170. package/src/activities/agent-turn/turn-context.ts +35 -0
  171. package/src/activities/agent-turn/turn-sandbox-access.ts +7 -1
  172. package/src/activities/agent-turn/xai-capacity.ts +94 -51
  173. package/src/activities/automations.ts +76 -4
  174. package/src/activities/browser-deadline-checkpoint.ts +279 -0
  175. package/src/activities/capabilities.ts +108 -11
  176. package/src/activities/codemode-dispatcher.ts +36 -8
  177. package/src/activities/codex-capacity.ts +60 -25
  178. package/src/activities/codex-rotation.ts +39 -17
  179. package/src/activities/context-compaction.ts +75 -18
  180. package/src/activities/gmail-files.ts +88 -0
  181. package/src/activities/goals.ts +116 -121
  182. package/src/activities/google-drive-publication.ts +1 -3
  183. package/src/activities/image-generation-operation.ts +1 -1
  184. package/src/activities/knowledge-indexing.ts +269 -15
  185. package/src/activities/knowledge-source-sync.ts +10 -0
  186. package/src/activities/mcp-account-routes.ts +17 -0
  187. package/src/activities/mcp-credentials.ts +83 -194
  188. package/src/activities/mcp-operation-authority.ts +16 -41
  189. package/src/activities/model-call-fact-reconciler.ts +112 -0
  190. package/src/activities/open-suffix-resume.ts +15 -2
  191. package/src/activities/parent-wake.ts +46 -21
  192. package/src/activities/retained-screenshots.ts +82 -11
  193. package/src/activities/rig-verification.ts +38 -37
  194. package/src/activities/run-credential-renewal.ts +13 -1
  195. package/src/activities/run-credentials.ts +59 -17
  196. package/src/activities/run-input.ts +25 -16
  197. package/src/activities/sandbox-images.ts +0 -1
  198. package/src/activities/sandbox-lease.ts +798 -82
  199. package/src/activities/scheduled-tasks.ts +550 -178
  200. package/src/activities/session-state.ts +245 -6
  201. package/src/activities/site-auth-maintenance.ts +3 -0
  202. package/src/activities/types.ts +72 -5
  203. package/src/activities/workflow-wake.ts +2 -17
  204. package/src/activities/workspace-capture.ts +13 -2
  205. package/src/activities/workspace-credential-provider.ts +283 -0
  206. package/src/activities-control.ts +4 -0
  207. package/src/activities-turn.ts +5 -0
  208. package/src/activities.ts +13 -0
  209. package/src/activity-services.ts +16 -4
  210. package/src/browser-deadline-checkpoint-contract.ts +5 -0
  211. package/src/editable-artifact-hint-broker.ts +3 -0
  212. package/src/editable-artifact-materializer-service.ts +7 -3
  213. package/src/editable-artifact-outbox-service.ts +4 -4
  214. package/src/github-rest-mcp.ts +1 -2
  215. package/src/host-export-pump.ts +26 -4
  216. package/src/host-export.ts +3 -0
  217. package/src/http.ts +4 -2
  218. package/src/index.ts +99 -37
  219. package/src/observability-metrics.ts +510 -5
  220. package/src/personal-github-git-credentials.ts +2 -1
  221. package/src/pr-review-credentials.ts +1 -3
  222. package/src/retained-process-diagnostics.ts +50 -0
  223. package/src/retained-process-retry.ts +36 -0
  224. package/src/sandbox-resume.ts +388 -101
  225. package/src/sandbox-routing.ts +150 -25
  226. package/src/sandbox-snapshot-diagnostics.ts +112 -0
  227. package/src/session-event-fanout.ts +23 -0
  228. package/src/warm-capture-holder.ts +15 -0
  229. package/src/worker-service-lifecycle.ts +53 -0
  230. package/src/workflows/activities.ts +16 -1
  231. package/src/workflows/browser-deadline-checkpoint.ts +50 -0
  232. package/src/workflows/file-upload-reaper.ts +2 -0
  233. package/src/workflows/scheduled-tasks.ts +26 -13
  234. package/src/workflows/session.ts +242 -22
  235. package/src/workflows.ts +4 -0
  236. package/dist/activities/agent-turn/knowledge-sources.d.ts +0 -20
  237. package/dist/activities/packs.d.ts +0 -55
  238. package/dist/activities-control-HMFGSKC5.js.map +0 -1
  239. package/dist/activities-turn-AP67JADS.js.map +0 -1
  240. package/dist/chunk-A4XQWVZK.js.map +0 -1
  241. package/dist/chunk-CYITU5UH.js.map +0 -1
  242. package/dist/chunk-RAMNYSAW.js.map +0 -1
  243. package/src/activities/agent-turn/knowledge-sources.ts +0 -86
  244. package/src/activities/packs.ts +0 -166
@@ -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>;
@@ -13,6 +13,7 @@ import type { loadWorkspaceEnvironmentForRunWithCredentials, sandboxEnvironmentF
13
13
  import type { AttemptIdentityState, EventingState, ProviderTurnState, SandboxRuntimeState } from "./turn-context.js";
14
14
  export type BuildTurnAgentDeps = {
15
15
  skillCatalog: NonNullable<BuildAgentOptions["skillCatalog"]>;
16
+ mcpServers: Settings["mcpServers"];
16
17
  input: RunAgentTurnInput;
17
18
  db: ActivityServices["db"];
18
19
  runtime: ActivityServices["runtime"];
@@ -42,6 +43,7 @@ export type BuildTurnAgentDeps = {
42
43
  supportsImageInput: GovernanceModelOk["supportsImageInput"];
43
44
  agentHumanInputEnabled: GovernanceModelOk["agentHumanInputEnabled"];
44
45
  workspaceAgentInstructions: GovernanceModelOk["workspaceAgentInstructions"];
46
+ workspaceAgentIdentity: GovernanceModelOk["workspaceAgentIdentity"];
45
47
  workspaceGovernance: GovernanceModelOk["workspaceGovernance"];
46
48
  structuredWorkspacePolicyActive: GovernanceModelOk["structuredWorkspacePolicyActive"];
47
49
  workspaceMemory: GovernanceModelOk["workspaceMemory"];
@@ -62,6 +64,8 @@ export type BuildTurnAgentDeps = {
62
64
  connectorActionPolicy: ConnectorActionPolicyHooks;
63
65
  trigger: ClaimTurnOk["trigger"];
64
66
  preparationIndependentToolNames: readonly string[];
67
+ /** The attempt's tool catalog includes the Jev-backed code_search tool. */
68
+ codeSearchAvailable: boolean;
65
69
  videoGenerationAcceptancesByCallId: Map<string, {
66
70
  operationId: string;
67
71
  requestDigest: string;
@@ -0,0 +1,58 @@
1
+ import { type parseModelProvidersJson, type ClaudeUsageObservation } from "@opengeni/config";
2
+ type Scope = "workspace" | "organization";
3
+ type ClaudeRequestCredential = {
4
+ token: string;
5
+ connectionId: string;
6
+ credentialVersion: number;
7
+ };
8
+ export declare class ClaudeSubscriptionConnectionUnavailable extends Error {
9
+ readonly status = 409;
10
+ readonly code = "claude_subscription_connection_changed";
11
+ constructor();
12
+ }
13
+ export type CapturedClaudeUsage = {
14
+ scope: Scope;
15
+ token: string;
16
+ expectedConnectionId: string;
17
+ expectedCredentialVersion: number;
18
+ observation?: ClaudeUsageObservation;
19
+ responseStatus?: number;
20
+ upstreamModelId?: string;
21
+ requestId?: string;
22
+ refresh?: {
23
+ status: "reconnect";
24
+ checkedAt: string;
25
+ };
26
+ };
27
+ /** Capture the exact credential before requests; replacement fences late responses. */
28
+ export declare function createClaudeUsageObserver(providers: ReturnType<typeof parseModelProvidersJson>, latest: Map<string, CapturedClaudeUsage>, readCredential: (scope: Scope) => Promise<{
29
+ token: string;
30
+ connectionId: string;
31
+ credentialVersion: number;
32
+ } | null>): Promise<((providerId: string, response: Response, upstreamModelId?: string, requestToken?: string | null) => void) & {
33
+ prepareRequestWithObserver: (providerId: string, headers: Headers, resolve: (binding: {
34
+ scope: Scope;
35
+ expectedConnectionId: string;
36
+ expectedCredentialVersion: number;
37
+ }) => Promise<ClaudeRequestCredential | null>) => Promise<{
38
+ headers: Headers;
39
+ observe: (providerId: string, response: Response, upstreamModelId?: string, requestToken?: string | null) => void;
40
+ }>;
41
+ prepareRequest(providerId: string, headers: Headers, resolve: (binding: {
42
+ scope: Scope;
43
+ expectedConnectionId: string;
44
+ expectedCredentialVersion: number;
45
+ }) => Promise<ClaudeRequestCredential | null>): Promise<Headers>;
46
+ binding(providerId: string): {
47
+ scope: Scope;
48
+ token: string;
49
+ expectedConnectionId: string;
50
+ expectedCredentialVersion: number;
51
+ } | undefined;
52
+ renew(providerId: string, credential: {
53
+ token: string;
54
+ connectionId: string;
55
+ credentialVersion: number;
56
+ }): void;
57
+ }>;
58
+ export {};
@@ -0,0 +1,60 @@
1
+ import type { AttemptToolDefinition } from "@opengeni/codemode";
2
+ import { type Settings } from "@opengeni/config";
3
+ import { JevCircuitBreaker, type CodeSearchWorkspace } from "@opengeni/jev";
4
+ import type { Observability } from "@opengeni/observability";
5
+ import { type SandboxChannelAService } from "@opengeni/runtime/sandbox";
6
+ /**
7
+ * One breaker per worker process. Repeated Jev outages (including an exhausted
8
+ * account) make `code_search` calls on this worker fail at once for a cooldown
9
+ * instead of each running a full retry cycle. The breaker never changes which
10
+ * tools a turn is offered: the tool list and instructions are the start of the
11
+ * model's cached prompt, and sessions move between workers whose breakers
12
+ * disagree.
13
+ */
14
+ export declare const codeSearchCircuitBreaker: JevCircuitBreaker;
15
+ type CodeSearchChannel = Pick<SandboxChannelAService, "codeSearchRipgrep" | "codeSearchPathKinds" | "fsRead">;
16
+ /** Adapt the turn's sandbox or Connected Machine to the code search engine. */
17
+ export declare function codeSearchWorkspaceFromChannel(channel: CodeSearchChannel): CodeSearchWorkspace;
18
+ /** Jev work done by one completed `code_search` call, for per-workspace usage records. */
19
+ export type CodeSearchUsage = {
20
+ operationId: string;
21
+ jevRequests: number;
22
+ jevInputTokens: number;
23
+ jevCostUsd: number;
24
+ };
25
+ /**
26
+ * The model-facing `code_search` tool. Jev scores candidates inside the worker;
27
+ * the sandbox only runs read-only ripgrep and file reads, so the Jev key never
28
+ * leaves this process. A Jev failure is reported to the model instead of
29
+ * degrading to keyword-only ranking, which lowered answer quality in testing.
30
+ */
31
+ export declare function createCodeSearchAttemptToolDefinition(input: {
32
+ settings: Pick<Settings, "jevApiKey" | "jevBaseUrl" | "jevModel" | "jevRequestTimeoutMs">;
33
+ apiKey: string;
34
+ workspace: () => Promise<CodeSearchWorkspace>;
35
+ observability: Observability;
36
+ /** Records Jev usage against the workspace. Failures are logged, never surfaced. */
37
+ recordUsage?: (usage: CodeSearchUsage) => Promise<void>;
38
+ breaker?: JevCircuitBreaker;
39
+ fetch?: typeof fetch;
40
+ }): AttemptToolDefinition;
41
+ /**
42
+ * The `code_search` definition for one turn, or none. It is offered only when
43
+ * the session's frozen decision and the deployment enable it, a usable Jev key
44
+ * exists, and the turn has compute that can run its POSIX shell commands (not
45
+ * a Windows Connected Machine). Every input is durable, so the tool list stays
46
+ * the same from turn to turn and on every worker. Transient Jev health never
47
+ * hides the tool; the breaker only refuses calls.
48
+ */
49
+ export declare function codeSearchToolDefinitions(input: {
50
+ enabled: boolean;
51
+ settings: Pick<Settings, "jevApiKey" | "jevBaseUrl" | "jevModel" | "jevRequestTimeoutMs">;
52
+ backend: Settings["sandboxBackend"];
53
+ /** The turn's Connected Machine workspace root, when a machine is primary. */
54
+ machineWorkspaceRoot?: string | null;
55
+ observability: Observability;
56
+ workspace: () => Promise<CodeSearchWorkspace>;
57
+ recordUsage?: (usage: CodeSearchUsage) => Promise<void>;
58
+ breaker?: JevCircuitBreaker;
59
+ }): AttemptToolDefinition[];
60
+ export {};
@@ -1,8 +1,21 @@
1
1
  import { type Settings } from "@opengeni/config";
2
2
  import type { TurnActivityServices as ActivityServices, RunAgentTurnInput, RunAgentTurnResult } from "../types.js";
3
3
  import { createTurnCredentialLeases } from "./credential-leases.js";
4
+ import { type LogThrottle } from "@opengeni/observability";
4
5
  import type { ClaimTurnOk } from "./claim.js";
5
6
  import type { AttemptIdentityState, BillingState, ClaimedResult, EventingState, ProviderTurnState, TurnControlState } from "./turn-context.js";
7
+ /** The eligible-pool gauge and `opengeni_codex_pool_low_total` stay per turn;
8
+ * the warning line is the first observation per workspace pool depth, then at
9
+ * most one per interval with the count it hid. The public log projection drops
10
+ * the identifiers and counts, so the closed `reason` keeps the depth visible. */
11
+ export declare const CODEX_POOL_LOW_WARNING_INTERVAL_MS: number;
12
+ export declare function warnCodexPoolLow(observability: Pick<ActivityServices["observability"], "warn">, input: {
13
+ workspaceKey: string;
14
+ workspaceId: string;
15
+ eligibleCount: number;
16
+ connectedCount: number;
17
+ depth: "zero" | "one";
18
+ }, throttle?: LogThrottle): void;
6
19
  export type CapacityPhaseDeps = {
7
20
  input: RunAgentTurnInput;
8
21
  settings: Settings;
@@ -0,0 +1,105 @@
1
+ import { type CodexEntitlementRejection } from "@opengeni/codex";
2
+ import { type CodexCredentialPlanRecheck, type CodexPlanEntitlementExclusion } from "@opengeni/db";
3
+ export declare const CODEX_PLAN_ENTITLEMENT_CODE = "codex_plan_entitlement";
4
+ export declare const CODEX_REQUEST_REJECTED_CODE = "codex_request_rejected";
5
+ export type CodexPlanEntitlementFailurePayload = {
6
+ error: string;
7
+ code: typeof CODEX_PLAN_ENTITLEMENT_CODE;
8
+ retryable: false;
9
+ planType: string | null;
10
+ model: string | null;
11
+ detail?: string;
12
+ };
13
+ export type CodexRequestRejectedFailurePayload = {
14
+ error: string;
15
+ code: typeof CODEX_REQUEST_REJECTED_CODE;
16
+ retryable: false;
17
+ planType: string | null;
18
+ detail?: string;
19
+ };
20
+ /**
21
+ * The user-set label of one connected ChatGPT account. The account email is
22
+ * deliberately never used: this text lands in the durable `turn.failed` event
23
+ * that every session reader (including embedding-host end users) can see, and
24
+ * an inherited organization credential's email may be a member's personal
25
+ * address. Without a label the copy says "The connected ChatGPT account".
26
+ */
27
+ export declare function codexAccountDisplayLabel(account: {
28
+ label: string | null;
29
+ } | null | undefined): string | null;
30
+ /** Terminal copy when the serving account's plan does not include the model. */
31
+ export declare function codexPlanEntitlementFailurePayload(input: {
32
+ accountLabel: string | null;
33
+ planType: string | null;
34
+ planChanged: boolean;
35
+ modelId: string | null;
36
+ rejection?: CodexEntitlementRejection | null;
37
+ /** The same turn waits for another connected account instead of failing. */
38
+ waiting?: boolean;
39
+ }): CodexPlanEntitlementFailurePayload;
40
+ /**
41
+ * Terminal copy for an empty Codex rejection. With `planChecked`, the account's
42
+ * plan was re-read and did not explain it, so OpenGeni kept the account.
43
+ */
44
+ export declare function codexRequestRejectedFailurePayload(input: {
45
+ accountLabel: string | null;
46
+ planType: string | null;
47
+ rejection: CodexEntitlementRejection;
48
+ planChecked?: boolean;
49
+ }): CodexRequestRejectedFailurePayload;
50
+ /**
51
+ * Admission-time refusal: the only accounts that could serve this turn were
52
+ * already proven not to include its model on their current plan.
53
+ */
54
+ export declare class CodexPlanEntitlementError extends Error {
55
+ readonly payload: CodexPlanEntitlementFailurePayload;
56
+ readonly code = "codex_plan_entitlement";
57
+ constructor(payload: CodexPlanEntitlementFailurePayload);
58
+ }
59
+ export type CodexPlanEntitlementAssessment = {
60
+ kind: "entitlement_lost";
61
+ /**
62
+ * Plan the exclusion binds to: the freshly observed plan, or the
63
+ * recorded plan when the provider reported none.
64
+ */
65
+ planType: string | null;
66
+ /** The provider reported the current plan during this re-check. */
67
+ planObserved: boolean;
68
+ /** The observed plan was reached by a recorded (non-upgrade) plan change. */
69
+ planChanged: boolean;
70
+ credentialVersion: number | null;
71
+ } | {
72
+ kind: "unexplained";
73
+ planType: string | null;
74
+ };
75
+ /** Pure decision over one plan re-check (see `codexPlanEntitlementLost`). */
76
+ export declare function assessCodexPlanEntitlement(rejection: CodexEntitlementRejection, recheck: CodexCredentialPlanRecheck, modelId: string | null): CodexPlanEntitlementAssessment;
77
+ type AdmissionAccount = {
78
+ id: string;
79
+ label: string | null;
80
+ planType: string | null;
81
+ allocatorEnabled: boolean;
82
+ allowedModelIds?: string[] | null;
83
+ planEntitlementExclusion?: CodexPlanEntitlementExclusion | null;
84
+ };
85
+ /**
86
+ * Pure admission check after credential selection found no account. Returns
87
+ * the plan-excluded accounts that alone explain it, or null when capacity,
88
+ * health, or policy (not plan entitlement) is the reason:
89
+ *
90
+ * - a manual pin (user intent) whose account's plan excludes the model;
91
+ * - with rotation off, the active account's plan excludes the model;
92
+ * - with rotation on, every allocatable account permitted for the model is
93
+ * plan-excluded.
94
+ */
95
+ export declare function codexPlanEntitlementAdmissionBlock<T extends AdmissionAccount>(input: {
96
+ accounts: readonly T[];
97
+ modelId: string;
98
+ credentialId: string | null;
99
+ rotationEnabled: boolean;
100
+ activeCredentialId: string | null;
101
+ pinnedCredentialId: string | null;
102
+ pinSource: "manual" | "policy" | null;
103
+ now: Date;
104
+ }): T[] | null;
105
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { type CodexAccountStatus } from "@opengeni/db";
2
- import { type ResolvedModelProvider, type Settings } from "@opengeni/config";
2
+ import { type ModelProviderApi, 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. */
@@ -7,6 +7,7 @@ export declare function acceptsPromptCacheKeyForTurn(resolvedModel: {
7
7
  provider: {
8
8
  kind: ResolvedModelProvider["kind"];
9
9
  builtin?: boolean;
10
+ api?: ModelProviderApi;
10
11
  };
11
12
  } | null): boolean;
12
13
  /**
@@ -24,7 +25,7 @@ export declare function acceptsPromptCacheKeyForTurn(resolvedModel: {
24
25
  export declare function refreshCappedCodexUsageRows(db: ActivityServices["db"], settings: Settings, workspaceId: string, accounts: Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">>, capacitySignals: {
25
26
  signalCodexCapacityWorkflow?: ActivityServices["signalCodexCapacityWorkflow"] | undefined;
26
27
  wakeSessionWorkflow: ActivityServices["wakeSessionWorkflow"];
27
- }): Promise<Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">>>;
28
+ }, acceptedTurnId?: string): Promise<Array<Pick<CodexAccountStatus, "id" | "status" | "primaryUsedPercent" | "secondaryUsedPercent" | "exhaustedUntil" | "exhaustedKind">>>;
28
29
  /**
29
30
  * True once the lifetime last confirmed by Postgres is no longer trustworthy.
30
31
  * A missing or malformed deadline fails closed for a holder that claims to be
@@ -1,4 +1,3 @@
1
- import { serializedToolsForRemoteCompaction } from "@opengeni/runtime";
2
1
  import { type Settings } from "@opengeni/config";
3
2
  import { maybeCompactContext } from "../context-compaction.js";
4
3
  import type { CompactionSummarizer, RemoteCompactionV2Requester } from "../context-compaction.js";
@@ -10,10 +9,7 @@ import type { ClaimTurnOk } from "./claim.js";
10
9
  import type { GovernanceModelOk } from "./governance-model.js";
11
10
  import type { AttemptIdentityState, BillingState, ClaimedResult, EventingState, ProviderTurnState, TurnControlState } from "./turn-context.js";
12
11
  export type RemoteCompactionPrefix = {
13
- tools: Awaited<ReturnType<typeof serializedToolsForRemoteCompaction>>;
14
- instructions: string;
15
- toolsReady: boolean;
16
- agent: Parameters<typeof serializedToolsForRemoteCompaction>[0] | null;
12
+ agent: ReturnType<ActivityServices["runtime"]["buildAgent"]> | null;
17
13
  };
18
14
  export type CompactionPrepDeps = {
19
15
  input: RunAgentTurnInput;
@@ -41,6 +37,7 @@ export type CompactionPrepDeps = {
41
37
  turnExecutionPolicy: ClaimTurnOk["turnExecutionPolicy"];
42
38
  resolvedModel: GovernanceModelOk["resolvedModel"];
43
39
  workspaceAgentInstructions: GovernanceModelOk["workspaceAgentInstructions"];
40
+ workspaceAgentIdentity: GovernanceModelOk["workspaceAgentIdentity"];
44
41
  workspaceGovernance: GovernanceModelOk["workspaceGovernance"];
45
42
  structuredWorkspacePolicyActive: GovernanceModelOk["structuredWorkspacePolicyActive"];
46
43
  workspaceMemory: GovernanceModelOk["workspaceMemory"];
@@ -86,5 +83,24 @@ export type PostAgentCompactionOutcome = {
86
83
  } | {
87
84
  ok: PostAgentCompactionOk;
88
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;
89
105
  export declare function prepareCompaction(deps: CompactionPrepDeps): Promise<CompactionPrepOutcome>;
90
106
  export declare function runPostAgentCompaction(deps: PostAgentCompactionDeps): Promise<PostAgentCompactionOutcome>;
@@ -1,6 +1,7 @@
1
+ import { heartbeatXaiCredentialLeaseUntil } from "@opengeni/db";
1
2
  import type { SharedActivityServices } from "../types.js";
2
- export type LeaseRenewReason = "timer" | "runtime_event" | "model_usage";
3
- export type LeaseLossReason = "deadline" | "not_found";
3
+ import { SubscriptionTurnLease, type LeaseRenewReason, type LeaseLossReason } from "./subscription-lease.js";
4
+ export type { LeaseRenewReason, LeaseLossReason } from "./subscription-lease.js";
4
5
  export declare class CodexCredentialLeaseLostError extends Error {
5
6
  readonly reason: LeaseLossReason;
6
7
  readonly code = "codex_credential_lease_lost";
@@ -19,45 +20,30 @@ export type TurnCredentialLeaseDeps = {
19
20
  * cross-replica fairness primitive; the heartbeat here only extends its short
20
21
  * TTL. A killed worker stops heartbeating and the holder self-expires.
21
22
  */
22
- export declare class CodexTurnLease {
23
- private readonly deps;
24
- held: boolean;
25
- lost: boolean;
26
- lossReason: LeaseLossReason | null;
27
- holderId: string | null;
28
- generation: number | null;
29
- confirmedUntilMs: number | null;
30
- private heartbeatInFlight;
31
- private heartbeatTimer;
23
+ export declare class CodexTurnLease extends SubscriptionTurnLease {
32
24
  constructor(deps: TurnCredentialLeaseDeps);
33
- markLost: (reason: LeaseLossReason) => void;
34
- /** Fail closed at the last worker-confirmed lease deadline before dispatch. */
35
- assertUsable: () => void;
36
- renew: (reason: LeaseRenewReason) => Promise<void>;
37
- startHeartbeat: () => void;
38
- stopHeartbeat: () => void;
39
25
  }
40
- /** The xAI/SuperGrok credential holder for one running turn; same shape. */
41
- export declare class XaiTurnLease {
42
- private readonly deps;
43
- held: boolean;
44
- lost: boolean;
26
+ /** Scoped subscriptions share the existing holder and monotonic deadline implementation. */
27
+ declare class ScopedSubscriptionTurnLease extends SubscriptionTurnLease {
45
28
  subjectId: string | null;
46
- holderId: string | null;
47
- generation: number | null;
48
- confirmedUntilMs: number | null;
49
- private heartbeatInFlight;
50
- private heartbeatTimer;
29
+ constructor(deps: TurnCredentialLeaseDeps, provider: {
30
+ name: string;
31
+ code: string;
32
+ ttlMs: number;
33
+ heartbeat: typeof heartbeatXaiCredentialLeaseUntil;
34
+ });
35
+ }
36
+ export declare class XaiTurnLease extends ScopedSubscriptionTurnLease {
37
+ constructor(deps: TurnCredentialLeaseDeps);
38
+ }
39
+ export declare class ClaudeTurnLease extends ScopedSubscriptionTurnLease {
51
40
  constructor(deps: TurnCredentialLeaseDeps);
52
- markLost: (reason: LeaseLossReason) => void;
53
- renew: () => Promise<void>;
54
- startHeartbeat: () => void;
55
- stopHeartbeat: () => void;
56
41
  }
57
- /** Both serving-credential leases for one turn attempt plus their composite views. */
42
+ /** Serving-credential leases for one turn attempt plus their composite views. */
58
43
  export type TurnCredentialLeases = {
59
44
  codex: CodexTurnLease;
60
45
  xai: XaiTurnLease;
46
+ claude: ClaudeTurnLease;
61
47
  renewServing: (reason: LeaseRenewReason) => Promise<void>;
62
48
  servingLost: () => boolean;
63
49
  };
@@ -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;
@@ -1,3 +1,4 @@
1
+ import { type CompactionProviderRejection, type MaterializationVerificationDiagnostic, type ProviderQuotaExhaustion, type ProviderQuotaScope } from "@opengeni/runtime";
1
2
  import { type McpTransportRequestFailureDiagnostic } from "@opengeni/runtime/mcp-network";
2
3
  import { ApplicationFailure } from "@temporalio/activity";
3
4
  import type { CodexAccountStatus } from "@opengeni/db";
@@ -6,6 +7,12 @@ import { type MandatoryHistoryPersistenceStage } from "./quiescence.js";
6
7
  export declare const PROVIDER_BACKPRESSURE_DELAY_MS = 60000;
7
8
  export declare const PROVIDER_CONNECTIVITY_BACKOFF_MS: readonly [2000, 5000, 15000, 30000, 60000];
8
9
  export declare const MAX_AUTOMATIC_PROVIDER_RECOVERIES: 5;
10
+ /**
11
+ * Minimum wait per rate-limited recovery. Providers such as Azure OpenAI often
12
+ * answer a per-minute token limit with a `retry-after` of about a second, which
13
+ * alone would spend every automatic recovery before the window resets.
14
+ */
15
+ export declare const PROVIDER_RATE_LIMIT_BACKOFF_MS: readonly [10000, 20000, 40000, 60000, 120000];
9
16
  export declare const POST_COMPACTION_CONTINUATION_EMPTY_CODE = "post_compaction_continuation_empty";
10
17
  export declare class PostCompactionContinuationEmptyError extends Error {
11
18
  readonly code = "post_compaction_continuation_empty";
@@ -67,23 +74,26 @@ export declare function escapedMcpTimeoutRecoveryFailure(input: {
67
74
  * Convert the atomic claim transaction's failure into a small, stable
68
75
  * Temporal wire contract. The original error remains in activity diagnostics,
69
76
  * but SQL text, parameters, and arbitrary invariant messages never enter
70
- * workflow history. Every database failure is safe to re-read after backoff
71
- * because the claim transaction contains no model/tool effects. Database
72
- * constraints and authorization guards can also be repaired by a deployment or
73
- * authority refresh, so they must preserve pending work. Only a non-database
74
- * claim invariant is terminal.
77
+ * workflow history. Operational failures retry; other persistence rejections
78
+ * retain accepted work behind a durable explicit-recheck fence. Repeating the
79
+ * same rejected transaction without changed conditions is not recovery.
75
80
  */
76
81
  export declare function preClaimAdmissionFailure(error: unknown): ApplicationFailure;
77
82
  /**
78
- * Carry one exact claimed-but-not-started attempt into the workflow's DB-only
79
- * recovery lane. Permanent database/state failures remain terminal; only the
80
- * same operational outage classes that are safe before claim are admitted.
83
+ * Carry one exact claimed attempt into the workflow's DB-only
84
+ * recovery lane. Permanent database/state failures remain terminal. The
85
+ * running-turn lane additionally requires a closed own-client outage class;
86
+ * existing pre-execution recovery classifications are unchanged.
81
87
  */
82
88
  export declare function postClaimDatabaseRecoveryFailure(input: {
83
89
  error: unknown;
84
90
  turnId: string;
85
91
  triggerEventId: string;
86
92
  executionGeneration: number;
93
+ /** Require an actual own-client boundary and the closed running-turn allowlist. */
94
+ requireDatabaseProvenance?: boolean;
95
+ sandboxSetupOutcomeUnknown?: true;
96
+ sandboxSetupRecoveryExhausted?: true;
87
97
  providerRecovery?: {
88
98
  failureCode: string;
89
99
  providerRecoveryCount: number;
@@ -109,8 +119,17 @@ export type SandboxLifecycleTransitionDiagnostic = {
109
119
  * cross-package error object is accepted.
110
120
  */
111
121
  export declare function sandboxLifecycleTransitionDiagnostic(error: unknown): SandboxLifecycleTransitionDiagnostic | null;
122
+ export declare function modelPreparationFailureEventPayload(error: unknown, durationMs: number): {
123
+ phase: string;
124
+ durationMs: number;
125
+ expectedTransition: boolean;
126
+ failureCategory?: string;
127
+ failureStage?: string;
128
+ failureCode?: "capture_in_progress" | "provider_recovery_in_progress" | "rotation_in_progress";
129
+ retryable?: boolean;
130
+ };
112
131
  /**
113
- * Recognize the one active-route transition that cannot finish inside its
132
+ * Recognize active-route transitions that cannot finish inside their
114
133
  * originating attempt. A Modal-home session may start on a Connected Machine
115
134
  * without creating or leasing its managed home box. When an explicit attach
116
135
  * clears the active pointer back to home, the pointer commit is authoritative,
@@ -121,7 +140,7 @@ export declare function sandboxLifecycleTransitionDiagnostic(error: unknown): Sa
121
140
  * only those structural error links with a strict bound; never classify from
122
141
  * message text, which could originate in model or tool content.
123
142
  */
124
- export declare function sandboxRouteTransitionCode(error: unknown): "home_unavailable_this_turn" | "workspace_root_changed_this_turn" | null;
143
+ export declare function sandboxRouteTransitionCode(error: unknown): "home_unavailable_this_turn" | "workspace_root_changed_this_turn" | "native_capabilities_changed_this_attempt" | null;
125
144
  export declare function isSandboxRouteTransitionError(error: unknown): boolean;
126
145
  /** Backward-compatible name for callers/tests that only exercised the original
127
146
  * machine-to-home transition. */
@@ -147,7 +166,30 @@ export type SafeErrorDiagnostic = {
147
166
  */
148
167
  export declare function safeErrorDiagnostic(error: unknown): SafeErrorDiagnostic;
149
168
  export declare function safeErrorForTelemetry(error: unknown): Error;
169
+ /**
170
+ * Guidance appended to a definitive provider rejection. Repeating the exact
171
+ * request cannot succeed, so the generic "send another message to retry"
172
+ * advice is wrong here: a new prompt re-sends the same rejected history.
173
+ */
174
+ export declare const COMPACTION_PROVIDER_REJECTION_GUIDANCE = "The provider refused this exact request, so repeating it fails the same way until the conversation changes. If a new message fails again, start a new session.";
150
175
  export declare function compactionFailureReasonFromError(error: unknown): string;
176
+ /**
177
+ * Exact `turn.failed` payload for a terminal compaction failure. A definitive
178
+ * provider rejection additionally carries its closed identifier record so the
179
+ * timeline, API consumers, and operators can name the rejected field without
180
+ * parsing the message.
181
+ */
182
+ export declare function compactionFailureTurnEventPayload(error: unknown, overrides?: {
183
+ error?: string;
184
+ }): {
185
+ error: string;
186
+ code: "context_compaction_failed";
187
+ retryable: false;
188
+ recovery: "user_message";
189
+ compacted: false;
190
+ providerRejection?: CompactionProviderRejection;
191
+ quotaScope?: ProviderQuotaScope;
192
+ };
151
193
  export declare function isCompactionSummaryFailure(error: unknown): boolean;
152
194
  export declare function shouldRecoverCompactionProviderFailure(error: unknown): boolean;
153
195
  export declare function classifyContextWindowOverflowError(error: unknown): {
@@ -214,6 +256,15 @@ export declare function collectErrorStrings(value: unknown, seen?: WeakSet<objec
214
256
  export declare const STATUSLESS_UPSTREAM_CONNECTIVITY_MESSAGE = "unable to connect. is the computer able to access the url?";
215
257
  export declare function isExactStatuslessUpstreamConnectivityMessage(message: string): boolean;
216
258
  export declare function isTransientProviderError(error: unknown): boolean;
259
+ /**
260
+ * Recognize an exhausted API-key provider quota (a daily or monthly allowance,
261
+ * a free-tier day cap, or an account out of credits) as distinct from an
262
+ * ordinary per-minute rate limit. Retrying within the bounded same-turn budget
263
+ * cannot succeed, so the turn fails promptly instead. Subscription transports
264
+ * own their quota semantics through credential rotation and durable capacity
265
+ * waits, so a Codex or SuperGrok transport error never classifies here.
266
+ */
267
+ export declare function classifyProviderQuotaExhaustionError(error: unknown): ProviderQuotaExhaustion | null;
217
268
  export type XaiCredentialFailure = {
218
269
  kind: "auth" | "forbidden" | "rate_limit";
219
270
  cooldownMs: number | null;
@@ -227,6 +278,11 @@ export type XaiCredentialFailure = {
227
278
  export declare function classifyXaiCredentialFailure(error: unknown): XaiCredentialFailure | null;
228
279
  export declare function agentRunFailurePayload(error: unknown, options?: {
229
280
  isCodexTurn?: boolean;
281
+ }): ReturnType<typeof baseAgentRunFailurePayload>;
282
+ /** Keep Anthropic provider text on terminal failures, never recovery events. */
283
+ export declare function agentRunRecoveryFailurePayload(error: unknown, failure: ReturnType<typeof agentRunFailurePayload>): ReturnType<typeof agentRunFailurePayload>;
284
+ declare function baseAgentRunFailurePayload(error: unknown, options?: {
285
+ isCodexTurn?: boolean;
230
286
  }): {
231
287
  error: string;
232
288
  code?: string;
@@ -246,9 +302,19 @@ export declare function agentRunFailurePayload(error: unknown, options?: {
246
302
  database?: Record<string, string>;
247
303
  historyPersistenceStage?: MandatoryHistoryPersistenceStage;
248
304
  mcpTransportDiagnostic?: McpTransportRequestFailureDiagnostic;
305
+ materializationDiagnostic?: MaterializationVerificationDiagnostic;
306
+ quotaScope?: ProviderQuotaScope;
307
+ /** Closed Codex plan key on `codex_plan_entitlement` / `codex_request_rejected`. */
308
+ planType?: string | null;
309
+ /** Product model id a `codex_plan_entitlement` failure refers to. */
310
+ model?: string | null;
249
311
  };
250
312
  export type CodexCredentialFailure = {
251
- kind: "auth" | "forbidden" | "rate_limit" | "quota";
313
+ /**
314
+ * `plan_entitlement` is produced only after a plan re-check proves the
315
+ * serving account's current plan does not include the requested model.
316
+ */
317
+ kind: "auth" | "forbidden" | "rate_limit" | "quota" | "plan_entitlement";
252
318
  cooldownSeconds: number | null;
253
319
  };
254
320
  export declare const CODEX_ALLOWANCE_FALLBACK_MS: number;
@@ -285,3 +351,8 @@ export declare function codexUsageLimitFailurePayload(info: {
285
351
  detail?: string;
286
352
  };
287
353
  export declare const CODEX_USAGE_LIMIT_MAX_RESUME_MS: number;
354
+ /** Only typed provider backpressure or a verified reconnect requirement can rotate Claude. */
355
+ export declare function classifyClaudeCredentialFailure(error: unknown): (XaiCredentialFailure & {
356
+ requestId?: string;
357
+ }) | null;
358
+ export {};