@opengeni/worker-bundle 2.2.0-canary.36855269964001 → 2.2.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 (44) hide show
  1. package/dist/activities/agent-run-admission.d.ts +1 -3
  2. package/dist/activities/agent-turn/admission.d.ts +3 -24
  3. package/dist/activities/agent-turn/claude-usage-observer.d.ts +1 -13
  4. package/dist/activities/agent-turn/run-credentials.d.ts +0 -2
  5. package/dist/activities/agent-turn/stream-attempt.d.ts +0 -1
  6. package/dist/activities/agent-turn/turn-context.d.ts +0 -1
  7. package/dist/activities/goals.d.ts +0 -8
  8. package/dist/activities/run-credentials.d.ts +2 -4
  9. package/dist/activities/types.d.ts +1 -1
  10. package/dist/{activities-control-YKXRDVMB.js → activities-control-MHNA3CYV.js} +66 -28
  11. package/dist/activities-control-MHNA3CYV.js.map +1 -0
  12. package/dist/{activities-turn-V37B7CQY.js → activities-turn-FQ5OO2WW.js} +197 -540
  13. package/dist/activities-turn-FQ5OO2WW.js.map +1 -0
  14. package/dist/{chunk-ZCCLJK3V.js → chunk-RZAAGRFQ.js} +65 -145
  15. package/dist/chunk-RZAAGRFQ.js.map +1 -0
  16. package/dist/index.js +1 -1
  17. package/dist/workflow-bundle.js +1 -1
  18. package/package.json +20 -20
  19. package/src/activities/agent-run-admission.ts +1 -17
  20. package/src/activities/agent-turn/admission.ts +1 -64
  21. package/src/activities/agent-turn/claim.ts +14 -56
  22. package/src/activities/agent-turn/claude-usage-observer.ts +1 -33
  23. package/src/activities/agent-turn/errors.ts +0 -46
  24. package/src/activities/agent-turn/failure-settlement.ts +0 -5
  25. package/src/activities/agent-turn/run-credentials.ts +3 -15
  26. package/src/activities/agent-turn/run.ts +3 -32
  27. package/src/activities/agent-turn/stream-attempt.ts +35 -138
  28. package/src/activities/agent-turn/tool-environment.ts +20 -13
  29. package/src/activities/agent-turn/turn-context.ts +0 -1
  30. package/src/activities/capabilities.ts +14 -52
  31. package/src/activities/goals.ts +78 -38
  32. package/src/activities/knowledge-indexing.ts +0 -29
  33. package/src/activities/run-credentials.ts +16 -22
  34. package/src/activities/scheduled-tasks.ts +0 -1
  35. package/src/activities/types.ts +0 -1
  36. package/src/activities/workspace-credential-provider.ts +0 -12
  37. package/src/sandbox-routing.ts +2 -4
  38. package/dist/activities/agent-turn/final-reply.d.ts +0 -18
  39. package/dist/activities/agent-turn/model-call-admission.d.ts +0 -15
  40. package/dist/activities-control-YKXRDVMB.js.map +0 -1
  41. package/dist/activities-turn-V37B7CQY.js.map +0 -1
  42. package/dist/chunk-ZCCLJK3V.js.map +0 -1
  43. package/src/activities/agent-turn/final-reply.ts +0 -46
  44. package/src/activities/agent-turn/model-call-admission.ts +0 -94
@@ -4,10 +4,8 @@ import {
4
4
  applyCreditDebitAfterUse,
5
5
  appendKnowledgeIndexChunks,
6
6
  claimKnowledgeIndexJobs,
7
- checkWorkspaceAllowance,
8
7
  completeKnowledgeIndexJob,
9
8
  continueKnowledgeIndexJob,
10
- creditDebitAttributionMetadata,
11
9
  deferKnowledgeIndexJob,
12
10
  freezeKnowledgeIndexBillingMode,
13
11
  getBillingBalance,
@@ -200,16 +198,6 @@ export function createKnowledgeIndexingActivities(
200
198
  return;
201
199
  }
202
200
  const paid = frozenPolicy.mode === "credits";
203
- if (paid && claim.billingAttribution.kind === "unknown") {
204
- // Unknown legacy/source-preparation causality is not service.
205
- // Keep the checkpoint without making an uncountable paid call.
206
- observability.warn("Paid Knowledge indexing awaits initiating attribution", {
207
- errorCode: "knowledge_index_attribution_unavailable",
208
- });
209
- await deferKnowledgeIndexJob(lockedDb, claim);
210
- result.deferred++;
211
- return;
212
- }
213
201
  if (paid && current.nextIndex === 0) {
214
202
  const balance = await getBillingBalance(lockedDb, claim.accountId);
215
203
  if (balance.balanceMicros <= 0) {
@@ -218,22 +206,6 @@ export function createKnowledgeIndexingActivities(
218
206
  return;
219
207
  }
220
208
  }
221
- if (paid) {
222
- const refusal = await checkWorkspaceAllowance(lockedDb, {
223
- accountId: claim.accountId,
224
- workspaceId: current.billingWorkspaceId,
225
- subjectId:
226
- claim.billingAttribution.kind === "turn" ||
227
- claim.billingAttribution.kind === "human"
228
- ? claim.billingAttribution.initiatingHumanSubjectId
229
- : null,
230
- });
231
- if (refusal) {
232
- await deferKnowledgeIndexJob(lockedDb, claim);
233
- result.deferred++;
234
- return;
235
- }
236
- }
237
209
  if (settings.usageLimitsMode === "static" || settings.usageLimitsMode === "managed") {
238
210
  const limit =
239
211
  configuredStaticUsageLimits(settings).maxDocumentIndexedChunksPerWorkspace;
@@ -337,7 +309,6 @@ export function createKnowledgeIndexingActivities(
337
309
  sourceId: claim.revisionId,
338
310
  idempotencyKey: `knowledge.embedding:${claim.revisionId}:${claim.generation}:${current.nextIndex}`,
339
311
  metadata: {
340
- ...creditDebitAttributionMetadata(claim.billingAttribution),
341
312
  model: claim.model,
342
313
  bytes,
343
314
  chunks: chunks.length,
@@ -5,7 +5,6 @@ import type {
5
5
  RunCredentialsRequest,
6
6
  Session,
7
7
  SessionTurn,
8
- ToolRef,
9
8
  } from "@opengeni/contracts";
10
9
  import type { Settings } from "@opengeni/config";
11
10
  import { getSessionRootId, type Database } from "@opengeni/db";
@@ -31,8 +30,6 @@ export type RunCredentialResolutionContext = {
31
30
  initiatingHumanSubjectId?: string | null;
32
31
  /** Installed in-process API routes must never enter a product callback. */
33
32
  localMcpServerIds?: readonly string[];
34
- /** Exact execution selection, resolved once at the turn policy boundary. */
35
- effectiveTools: readonly ToolRef[];
36
33
  };
37
34
 
38
35
  export type BoundRunCredentialResolver = {
@@ -45,7 +42,7 @@ export type BoundRunCredentialResolver = {
45
42
  export function buildRunCredentialsRequest(
46
43
  input: Omit<
47
44
  RunCredentialResolutionContext,
48
- "db" | "connectionCredentials" | "settings" | "initiatingHumanSubjectId" | "effectiveTools"
45
+ "db" | "connectionCredentials" | "settings" | "initiatingHumanSubjectId"
49
46
  > & {
50
47
  rootSessionId: string;
51
48
  purpose: "provision" | "renewal";
@@ -128,7 +125,7 @@ export async function bindRunCredentialResolver(
128
125
  mcpServers: selectedSessionRemoteMcpTargets(
129
126
  input.settings,
130
127
  input.session.mcpServers ?? [],
131
- input.effectiveTools,
128
+ input.turn.tools ?? [],
132
129
  (input.localMcpServerIds ?? []).map((id) => ({ id })),
133
130
  ),
134
131
  },
@@ -149,25 +146,22 @@ export async function bindRunCredentialResolver(
149
146
  workspaceId: input.workspaceId,
150
147
  sessionId: input.session.id,
151
148
  };
152
- // A renewable resolver belongs to one admitted turn, even if its caller
153
- // subsequently replaces or mutates an in-memory session/turn projection.
154
- const frozenRequest = structuredClone(
155
- buildRunCredentialsRequest({
156
- accountId: input.accountId,
157
- workspaceId: input.workspaceId,
158
- session: input.session,
159
- turn: input.turn,
160
- attemptId: input.attemptId,
161
- effectiveSandboxBackend: input.effectiveSandboxBackend,
162
- variableSet: input.variableSet,
163
- rootSessionId,
164
- purpose: "provision",
165
- forceRefresh: false,
166
- }),
167
- );
168
149
  return {
169
150
  resolve: async ({ purpose, forceRefresh }) => {
170
- const resolution = await resolver({ ...frozenRequest, purpose, forceRefresh });
151
+ const resolution = await resolver(
152
+ buildRunCredentialsRequest({
153
+ accountId: input.accountId,
154
+ workspaceId: input.workspaceId,
155
+ session: input.session,
156
+ turn: input.turn,
157
+ attemptId: input.attemptId,
158
+ effectiveSandboxBackend: input.effectiveSandboxBackend,
159
+ variableSet: input.variableSet,
160
+ rootSessionId,
161
+ purpose,
162
+ forceRefresh,
163
+ }),
164
+ );
171
165
  return normalizeRunCredentialsResolution(resolution, scope);
172
166
  },
173
167
  };
@@ -917,7 +917,6 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
917
917
  workspaceId: task.workspaceId,
918
918
  model: targetSessionExecution?.model ?? model,
919
919
  requestedAgentRuns: input.agentRunUsageIdempotencyKey ? 0 : 1,
920
- initiatingHumanSubjectId: causalHumanSubjectId,
921
920
  },
922
921
  );
923
922
  if (admissionDenial) {
@@ -458,7 +458,6 @@ export type DispatchScheduledTaskRunResult =
458
458
  refusal?: import("@opengeni/contracts").ScheduledTaskAdmissionRefusal;
459
459
  reason:
460
460
  | "insufficient_credits"
461
- | "allowance_exhausted"
462
461
  | "monthly_model_cost_limit"
463
462
  | "monthly_agent_run_limit"
464
463
  | "malformed_manual_trigger"
@@ -78,8 +78,6 @@ export function credentialProviderRequestBody(
78
78
  mcpServers: [],
79
79
  },
80
80
  ): CredentialProviderRequest {
81
- const via = input.initiatorContext.via;
82
- const latestHop = Array.isArray(via) ? via.at(-1) : null;
83
81
  return {
84
82
  type: "credentials.request",
85
83
  lane: selection.lane,
@@ -94,16 +92,6 @@ export function credentialProviderRequestBody(
94
92
  turnId: input.turnId,
95
93
  attemptId: input.attemptId,
96
94
  initiator: { kind: input.initiator.kind, subjectId: input.initiator.subjectId },
97
- initiatorContext: {
98
- kind:
99
- latestHop?.kind === "agent"
100
- ? "agent"
101
- : input.initiator.kind === "subject"
102
- ? "human"
103
- : "service",
104
- initiator: input.initiator,
105
- context: input.initiatorContext,
106
- },
107
95
  initiatingHumanSubjectId,
108
96
  initiatingHuman,
109
97
  sandboxBackend: input.effectiveSandboxBackend,
@@ -496,7 +496,7 @@ function afterPersistableHomeMutation(
496
496
  op: string;
497
497
  backend: ResolvedActiveBackend;
498
498
  admission: unknown;
499
- outcome: "resolved" | "rejected" | "outcome_unknown";
499
+ outcome: "resolved" | "rejected";
500
500
  result?: unknown;
501
501
  retainedProcess?: RoutingRetainedProcess;
502
502
  }) => Promise<void | RoutingMutationSettlementResult>)
@@ -523,7 +523,7 @@ function afterPersistableHomeMutation(
523
523
  ) {
524
524
  throw new Error("Persistable home mutation settlement lacked its bound admission");
525
525
  }
526
- if ((outcome === "resolved" || outcome === "outcome_unknown") && retainedProcess) {
526
+ if (outcome === "resolved" && retainedProcess) {
527
527
  try {
528
528
  await retainWorkspaceProviderCommand(services.db, {
529
529
  accountId: fence.accountId,
@@ -582,8 +582,6 @@ function afterPersistableHomeMutation(
582
582
  }
583
583
  return;
584
584
  }
585
- if (outcome === "outcome_unknown")
586
- throw new Error("Outcome-unknown command settlement requires its exact retained invocation");
587
585
  await verifyWorkspaceMutationSettlement(services.db, {
588
586
  accountId: fence.accountId,
589
587
  workspaceId: ids.workspaceId,
@@ -1,18 +0,0 @@
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;
@@ -1,15 +0,0 @@
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
- };