@opengeni/worker-bundle 0.28.3-canary.0 → 0.28.4-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/activities/agent-turn/mcp-operation-read-tool.d.ts +16 -0
  2. package/dist/activities/mcp-operation-authority.d.ts +16 -0
  3. package/dist/activities/mcp-operation-observer.d.ts +14 -0
  4. package/dist/activities/mcp-operation-reader.d.ts +45 -0
  5. package/dist/activities/mcp-operation-store.d.ts +6 -0
  6. package/dist/{activities-control-JUBMDBDZ.js → activities-control-J5QNRWVH.js} +2 -1
  7. package/dist/{activities-control-JUBMDBDZ.js.map → activities-control-J5QNRWVH.js.map} +1 -1
  8. package/dist/{activities-turn-I2ZKGZE6.js → activities-turn-ZJBY3W5D.js} +15685 -792
  9. package/dist/activities-turn-ZJBY3W5D.js.map +1 -0
  10. package/dist/artifact-materializer-entry.js +2 -0
  11. package/dist/artifact-materializer-entry.js.map +1 -1
  12. package/dist/artifact-outbox-entry.js +2 -0
  13. package/dist/artifact-outbox-entry.js.map +1 -1
  14. package/dist/chunk-PZ5AY32C.js +10 -0
  15. package/dist/chunk-PZ5AY32C.js.map +1 -0
  16. package/dist/host-export.js +1 -0
  17. package/dist/index.js +2 -1
  18. package/dist/index.js.map +1 -1
  19. package/package.json +18 -17
  20. package/src/activities/agent-turn/mcp-operation-read-tool.ts +61 -0
  21. package/src/activities/agent-turn/tool-environment.ts +65 -0
  22. package/src/activities/mcp-credentials.ts +94 -40
  23. package/src/activities/mcp-operation-authority.ts +76 -0
  24. package/src/activities/mcp-operation-observer.ts +86 -0
  25. package/src/activities/mcp-operation-reader.ts +108 -0
  26. package/src/activities/mcp-operation-store.ts +98 -0
  27. package/dist/activities-turn-I2ZKGZE6.js.map +0 -1
@@ -0,0 +1,98 @@
1
+ import { AttemptToolResult } from "@opengeni/contracts";
2
+ import type { Database } from "@opengeni/db";
3
+ import {
4
+ readMcpOperation as readStoredMcpOperation,
5
+ claimMcpOperationObservation,
6
+ releaseMcpOperationObservation,
7
+ settleMcpOperationObservation,
8
+ type McpOperationAttempt,
9
+ type McpOperationRecord,
10
+ } from "@opengeni/db/mcp-operations";
11
+ import type {
12
+ McpOperationReaderDependencies,
13
+ McpOperationReadRecord,
14
+ } from "./mcp-operation-reader";
15
+
16
+ /** All DB calls remain bound to the actual accepted worker attempt. Locators
17
+ * supplied to operation_read cannot replace this scope or its principal. */
18
+ export function createMcpOperationReadStore(
19
+ db: Database,
20
+ attempt: McpOperationAttempt,
21
+ ): Pick<McpOperationReaderDependencies, "load" | "claim" | "release" | "settle"> {
22
+ const current = { ...attempt };
23
+ const load: McpOperationReaderDependencies["load"] = async (selector) => {
24
+ const found = await readStoredMcpOperation(db, current, selector);
25
+ if (found.status === "ambiguous") {
26
+ throw new Error("MCP source call matches multiple operations; select an exact operationId");
27
+ }
28
+ return found.status === "found" ? projectRecord(found.operation) : null;
29
+ };
30
+ return {
31
+ load,
32
+ claim: async (operationId) => {
33
+ const result = await claimMcpOperationObservation(db, current, operationId);
34
+ return result.status === "claimed" ? result.claimId : null;
35
+ },
36
+ release: async (operationId, claimId) => {
37
+ await releaseMcpOperationObservation(db, current, { operationId, claimId });
38
+ },
39
+ settle: async (operationId, claimId, receipt) => {
40
+ const outcome = await settleMcpOperationObservation(db, current, {
41
+ operationId,
42
+ claimId,
43
+ receiptRevision: receipt.receiptRevision,
44
+ result: receipt.result,
45
+ });
46
+ if (outcome.status === "conflict") {
47
+ throw new Error(
48
+ "MCP provider returned conflicting terminal receipts; the first receipt is preserved",
49
+ );
50
+ }
51
+ if (
52
+ outcome.status !== "settled" &&
53
+ outcome.status !== "existing" &&
54
+ outcome.status !== "original_completed"
55
+ ) {
56
+ throw new Error(
57
+ "MCP observation claim is no longer current; read the existing operation again",
58
+ );
59
+ }
60
+ const recorded = await load({ operationId });
61
+ if (!recorded) throw new Error("MCP operation is unavailable");
62
+ return recorded;
63
+ },
64
+ };
65
+ }
66
+
67
+ function projectRecord(record: McpOperationRecord): McpOperationReadRecord {
68
+ if (record.observationResult !== null && record.receiptRevision === null) {
69
+ throw new Error("Stored MCP operation receipt is incomplete");
70
+ }
71
+ return {
72
+ operationId: record.operationId,
73
+ sourceTurnId: record.sourceTurnId,
74
+ sourceCallId: record.sourceCallId,
75
+ serverId: record.serverId,
76
+ originalTool: record.originalTool,
77
+ observerTool: record.observerTool,
78
+ argumentDigest: record.argumentDigest,
79
+ destinationDigest: record.destinationDigest,
80
+ authorityDigest: record.authorityDigest,
81
+ // Capture precedes the physical request; after a crash it is not proof
82
+ // that the mutation was or was not sent. It never authorizes a replay.
83
+ originalOutcome: record.originalOutcome,
84
+ originalResult:
85
+ record.originalResult === null ? null : AttemptToolResult.parse(record.originalResult),
86
+ receipt:
87
+ record.observationResult === null
88
+ ? null
89
+ : {
90
+ version: 1,
91
+ operationRef: record.operationId,
92
+ fingerprint: { version: 1, algorithm: "sha256", value: record.argumentDigest },
93
+ status: "completed",
94
+ receiptRevision: record.receiptRevision!,
95
+ result: AttemptToolResult.parse(record.observationResult),
96
+ },
97
+ };
98
+ }