@dharma-ai-labs/agent-fabric 0.2.107 → 0.2.109

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 (41) hide show
  1. package/README.md +15 -0
  2. package/dist/codexBoundSession.d.ts +42 -0
  3. package/dist/codexBoundSession.d.ts.map +1 -0
  4. package/dist/codexBoundSession.js +108 -0
  5. package/dist/codexBoundSession.js.map +1 -0
  6. package/dist/codexBoundSession.test.d.ts +2 -0
  7. package/dist/codexBoundSession.test.d.ts.map +1 -0
  8. package/dist/codexBoundSession.test.js +636 -0
  9. package/dist/codexBoundSession.test.js.map +1 -0
  10. package/dist/codexInboxSession.d.ts +75 -0
  11. package/dist/codexInboxSession.d.ts.map +1 -0
  12. package/dist/codexInboxSession.js +157 -0
  13. package/dist/codexInboxSession.js.map +1 -0
  14. package/dist/cooperativeInboxSession.d.ts +89 -0
  15. package/dist/cooperativeInboxSession.d.ts.map +1 -0
  16. package/dist/cooperativeInboxSession.js +195 -0
  17. package/dist/cooperativeInboxSession.js.map +1 -0
  18. package/dist/cooperativeInboxSession.test.d.ts +2 -0
  19. package/dist/cooperativeInboxSession.test.d.ts.map +1 -0
  20. package/dist/cooperativeInboxSession.test.js +354 -0
  21. package/dist/cooperativeInboxSession.test.js.map +1 -0
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.test.js +3 -2
  27. package/dist/index.test.js.map +1 -1
  28. package/dist/providerSessionChannel.d.ts +129 -0
  29. package/dist/providerSessionChannel.d.ts.map +1 -0
  30. package/dist/providerSessionChannel.js +249 -0
  31. package/dist/providerSessionChannel.js.map +1 -0
  32. package/dist/providerSessionChannel.test.d.ts +2 -0
  33. package/dist/providerSessionChannel.test.d.ts.map +1 -0
  34. package/dist/providerSessionChannel.test.js +246 -0
  35. package/dist/providerSessionChannel.test.js.map +1 -0
  36. package/dist/providerSessionReplyRecovery.d.ts +33 -0
  37. package/dist/providerSessionReplyRecovery.d.ts.map +1 -0
  38. package/dist/providerSessionReplyRecovery.js +58 -0
  39. package/dist/providerSessionReplyRecovery.js.map +1 -0
  40. package/dist/schemas/provider-session-completion.schema.json +22 -0
  41. package/package.json +7 -7
package/README.md CHANGED
@@ -210,5 +210,20 @@ or unavailable evidence.
210
210
  - [CLI command contract](https://github.com/dharma-ai-labs/dharma-agent-fabric/blob/main/docs/22-cli-command-contract.md)
211
211
  - [Security boundary](https://github.com/dharma-ai-labs/dharma-agent-fabric/blob/main/docs/10-security-privacy-and-threat-model.md)
212
212
 
213
+ ## Owning-runtime session integration
214
+
215
+ The library exports `openCooperativeInboxSession` for an integration running in
216
+ the intended Codex session. It requires that runtime's exact active-session hook,
217
+ an enrolled identity, encrypted cooperative binding, signed channel, durable
218
+ single-use replay claim, disclosure authorization and budget reservation. The
219
+ runtime handles each bounded read-only question within its own existing turn.
220
+ It must enforce the question's authorized paths and network limits.
221
+
222
+ This consumer does not create/resume another thread or wake an idle desktop chat.
223
+ It is not an installed native host hook or a CLI/MCP attachment command. Session
224
+ IDs from environment variables or historical transcripts are not ownership proof.
225
+ See [session routing](../../docs/24-provider-session-routing.md) for the exact
226
+ contract, failure recovery and remaining live qualification boundaries.
227
+
213
228
  Licensed under MIT. Do not report security vulnerabilities in a public issue;
214
229
  use the private security-reporting channel in the GitHub repository.
@@ -0,0 +1,42 @@
1
+ import { type SessionQuestionVerifier } from '@dharma-ai-labs/agent-fabric-contracts';
2
+ import type { LocalProviderSessionIdentity, LocalVault } from '@dharma-ai-labs/agent-fabric-local-vault';
3
+ import { type CodexSessionBudget } from '@dharma-ai-labs/agent-fabric-provider-adapters/experimental/codex-session';
4
+ import type { CodexStdioTransport } from '@dharma-ai-labs/agent-fabric-provider-adapters/experimental/codex-transport';
5
+ interface CodexBoundSessionInput {
6
+ vault: LocalVault;
7
+ bindingId: string;
8
+ identity: LocalProviderSessionIdentity;
9
+ openTransport(): Promise<CodexStdioTransport>;
10
+ verifier: SessionQuestionVerifier;
11
+ budget: CodexSessionBudget;
12
+ }
13
+ export declare function openCodexBoundSession(input: CodexBoundSessionInput): Promise<{
14
+ close: () => Promise<void>;
15
+ assertActive(): Promise<boolean>;
16
+ runQuestion(request: {
17
+ question: unknown;
18
+ now?: Date;
19
+ timeoutMs?: number;
20
+ }): Promise<{
21
+ questionId: string;
22
+ taskId: string;
23
+ bindingId: string;
24
+ targetEndpointId: string;
25
+ answer: string;
26
+ answerHash: string;
27
+ }>;
28
+ }>;
29
+ export declare function runCodexBoundSessionQuestion(input: CodexBoundSessionInput & {
30
+ question: unknown;
31
+ now?: Date;
32
+ timeoutMs?: number;
33
+ }): Promise<{
34
+ questionId: string;
35
+ taskId: string;
36
+ bindingId: string;
37
+ targetEndpointId: string;
38
+ answer: string;
39
+ answerHash: string;
40
+ }>;
41
+ export {};
42
+ //# sourceMappingURL=codexBoundSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codexBoundSession.d.ts","sourceRoot":"","sources":["../src/codexBoundSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACxH,OAAO,KAAK,EAAE,4BAA4B,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACzG,OAAO,EAA0B,KAAK,kBAAkB,EAAE,MAAM,2EAA2E,CAAC;AAC5I,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6EAA6E,CAAC;AAEvH,UAAU,sBAAsB;IAC9B,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,4BAA4B,CAAC;IAEvC,aAAa,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC9C,QAAQ,EAAE,uBAAuB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,sBAAsB;;;yBAmC1C;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,GAAG,CAAC,EAAE,IAAI,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;GA0BnF;AAED,wBAAsB,4BAA4B,CAAC,KAAK,EAAE,sBAAsB,GAAG;IACjF,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;;;;;;GAmBA"}
@@ -0,0 +1,108 @@
1
+ import { inspectSessionQuestionForBinding } from '@dharma-ai-labs/agent-fabric-contracts';
2
+ import { runCodexBridgeQuestion } from '@dharma-ai-labs/agent-fabric-provider-adapters/experimental/codex-session';
3
+ export async function openCodexBoundSession(input) {
4
+ const binding = input.vault.getProviderSessionBinding(input.bindingId, input.identity);
5
+ if (!binding || binding.provider !== 'codex' || binding.owner !== 'dharma_bridge') {
6
+ throw new Error('codex_session_binding_unavailable');
7
+ }
8
+ if (process.platform !== 'linux')
9
+ throw new Error('codex_session_sandbox_unqualified');
10
+ const codexBinding = { ...binding, threadId: binding.sessionId };
11
+ const lease = input.vault.tryAcquireProviderSessionLease(input.bindingId, input.identity);
12
+ if (!lease)
13
+ throw new Error('codex_session_lease_unavailable');
14
+ const heldLease = lease;
15
+ let transport;
16
+ try {
17
+ transport = await input.openTransport();
18
+ }
19
+ catch (error) {
20
+ lease.release();
21
+ throw error;
22
+ }
23
+ let running = false;
24
+ let closing = false;
25
+ let closed = false;
26
+ let shutdown = null;
27
+ async function close() {
28
+ closing = true;
29
+ if (closed)
30
+ return;
31
+ if (shutdown)
32
+ return shutdown;
33
+ shutdown = (async () => {
34
+ // Never release the fence while a provider child could still accept turns.
35
+ await transport.close();
36
+ heldLease.release();
37
+ closed = true;
38
+ })();
39
+ try {
40
+ await shutdown;
41
+ }
42
+ finally {
43
+ shutdown = null;
44
+ }
45
+ }
46
+ return {
47
+ close,
48
+ async assertActive() { return !closing && !closed && await heldLease.assertHeld(); },
49
+ async runQuestion(request) {
50
+ if (closing)
51
+ throw new Error('codex_session_closed');
52
+ if (running)
53
+ throw new Error('codex_session_busy');
54
+ const inspected = inspectSessionQuestionForBinding(request.question, codexBinding, input.verifier, request.now ?? new Date());
55
+ if (!inspected.ok)
56
+ throw new Error(inspected.reason);
57
+ running = true;
58
+ try {
59
+ const result = await runCodexBridgeQuestion({
60
+ transport, binding: codexBinding, question: request.question,
61
+ verifier: input.verifier, exclusiveLease: lease, budget: input.budget,
62
+ now: request.now, timeoutMs: request.timeoutMs,
63
+ });
64
+ if (closing)
65
+ throw new Error('codex_session_closed');
66
+ return result;
67
+ }
68
+ catch (error) {
69
+ // Both failures happen before turn/start; retain an empty thread for retry.
70
+ const reason = error instanceof Error ? error.message : '';
71
+ if (!['codex_session_budget_unavailable', 'replayed'].includes(reason)) {
72
+ try {
73
+ await close();
74
+ }
75
+ catch { /* Keep the fence and disable dispatch until shutdown is confirmed. */ }
76
+ }
77
+ throw error;
78
+ }
79
+ finally {
80
+ running = false;
81
+ }
82
+ },
83
+ };
84
+ }
85
+ export async function runCodexBoundSessionQuestion(input) {
86
+ const binding = input.vault.getProviderSessionBinding(input.bindingId, input.identity);
87
+ if (!binding || binding.provider !== 'codex' || binding.owner !== 'dharma_bridge') {
88
+ throw new Error('codex_session_binding_unavailable');
89
+ }
90
+ const codexBinding = { ...binding, threadId: binding.sessionId };
91
+ const inspected = inspectSessionQuestionForBinding(input.question, codexBinding, input.verifier, input.now ?? new Date());
92
+ if (!inspected.ok)
93
+ throw new Error(inspected.reason);
94
+ const owner = await openCodexBoundSession(input);
95
+ try {
96
+ const result = await owner.runQuestion(input);
97
+ await owner.close();
98
+ return result;
99
+ }
100
+ catch (error) {
101
+ try {
102
+ await owner.close();
103
+ }
104
+ catch { /* Retain ownership if process termination cannot be confirmed. */ }
105
+ throw error;
106
+ }
107
+ }
108
+ //# sourceMappingURL=codexBoundSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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AAS,EAAE,CAAC;IACjE,MAAM,SAAS,GAAG,gCAAgC,CAAC,KAAK,CAAC,QAAQ,EAAE,YAAY,EAC7E,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,SAAS,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,MAAM,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC;YAAC,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAAC,CAAC;QAC5B,MAAM,CAAC,CAAC,kEAAkE,CAAC,CAAC;QAC5E,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=codexBoundSession.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codexBoundSession.test.d.ts","sourceRoot":"","sources":["../src/codexBoundSession.test.ts"],"names":[],"mappings":""}