@cogitator-ai/bridge 0.0.0-stage → 0.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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -2
  3. package/dist/client.d.ts +74 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +202 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/dispatcher.d.ts +246 -0
  8. package/dist/dispatcher.d.ts.map +1 -0
  9. package/dist/dispatcher.js +1301 -0
  10. package/dist/dispatcher.js.map +1 -0
  11. package/dist/errors.d.ts +10 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +16 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/guards.d.ts +36 -0
  16. package/dist/guards.d.ts.map +1 -0
  17. package/dist/guards.js +85 -0
  18. package/dist/guards.js.map +1 -0
  19. package/dist/host.d.ts +49 -0
  20. package/dist/host.d.ts.map +1 -0
  21. package/dist/host.js +150 -0
  22. package/dist/host.js.map +1 -0
  23. package/dist/index.d.ts +39 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +26 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/inputs.d.ts +145 -0
  28. package/dist/inputs.d.ts.map +1 -0
  29. package/dist/inputs.js +93 -0
  30. package/dist/inputs.js.map +1 -0
  31. package/dist/job-record.d.ts +47 -0
  32. package/dist/job-record.d.ts.map +1 -0
  33. package/dist/job-record.js +65 -0
  34. package/dist/job-record.js.map +1 -0
  35. package/dist/letters.d.ts +49 -0
  36. package/dist/letters.d.ts.map +1 -0
  37. package/dist/letters.js +96 -0
  38. package/dist/letters.js.map +1 -0
  39. package/dist/paths.d.ts +32 -0
  40. package/dist/paths.d.ts.map +1 -0
  41. package/dist/paths.js +130 -0
  42. package/dist/paths.js.map +1 -0
  43. package/dist/protocol.d.ts +78 -0
  44. package/dist/protocol.d.ts.map +1 -0
  45. package/dist/protocol.js +66 -0
  46. package/dist/protocol.js.map +1 -0
  47. package/dist/registry.d.ts +62 -0
  48. package/dist/registry.d.ts.map +1 -0
  49. package/dist/registry.js +185 -0
  50. package/dist/registry.js.map +1 -0
  51. package/dist/server.d.ts +31 -0
  52. package/dist/server.d.ts.map +1 -0
  53. package/dist/server.js +249 -0
  54. package/dist/server.js.map +1 -0
  55. package/dist/store/sqlite.d.ts +56 -0
  56. package/dist/store/sqlite.d.ts.map +1 -0
  57. package/dist/store/sqlite.js +737 -0
  58. package/dist/store/sqlite.js.map +1 -0
  59. package/dist/store/store.d.ts +128 -0
  60. package/dist/store/store.d.ts.map +1 -0
  61. package/dist/store/store.js +2 -0
  62. package/dist/store/store.js.map +1 -0
  63. package/dist/types.d.ts +322 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +130 -0
  66. package/dist/types.js.map +1 -0
  67. package/package.json +70 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cogitator Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,183 @@
1
- # Temporary Holding Version
1
+ # @cogitator-ai/bridge
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Experimental.** The API and the protocol may change between minor versions until the package leaves this stage.
4
+
5
+ The agent bridge: Claude Code, Codex and other agents hand each other jobs, ask questions on the way and report back, each staying in its own window.
6
+
7
+ Nobody waits. An agent hands a job over, gets its number at once and ends its turn. Whatever comes later, a question or the result, arrives as a letter. The bridge in the middle is a dispatcher, not a model: it keeps jobs and letters, finds who a letter is for, applies the limits and writes everything down. It never calls a model.
8
+
9
+ This release has the core: the dispatcher, its store, the socket it serves and the commands to run and watch it. A session takes part by reading its inbox through `BridgeClient`. Adapters that wake a session of a harness in its own window, and the MCP tools agents call, build on this core.
10
+
11
+ ```bash
12
+ pnpm add @cogitator-ai/bridge better-sqlite3
13
+ ```
14
+
15
+ ## Run the dispatcher
16
+
17
+ One dispatcher runs per machine and serves every project on it.
18
+
19
+ ```bash
20
+ cogitator bridge serve # in the foreground, until Ctrl+C
21
+ cogitator bridge status # the dispatcher, the sessions it knows, the jobs in progress
22
+ cogitator bridge log --follow # every letter as it goes
23
+ cogitator bridge log --job 12 # everything about one job
24
+ ```
25
+
26
+ `cogitator daemon start --bridge` hosts it inside the assistant daemon instead. Its files live in `~/.cogitator/bridge` (`COGITATOR_BRIDGE_HOME` moves them): `bridge.db` and `bridge.sock`, both kept to their owner.
27
+
28
+ ## A job from hand-over to report
29
+
30
+ ```typescript
31
+ import { BridgeClient, bridgePaths, callerFromEnv } from '@cogitator-ai/bridge';
32
+
33
+ // The session is known by what its harness put in the environment:
34
+ // CLAUDE_CODE_SESSION_ID or CODEX_THREAD_ID. Undefined in a shell no harness started
35
+ const caller = callerFromEnv(process.env, process.cwd());
36
+ const bridge = await BridgeClient.connect({ socketPath: bridgePaths().socket, caller });
37
+
38
+ const { job } = await bridge.createJob({
39
+ to: 'codex',
40
+ body: 'Write the tests for the rate limiter. Cover the burst case.',
41
+ checks: [{ command: 'pnpm test' }],
42
+ });
43
+ console.log(`Job ${job.number} is with ${job.to}`); // and the turn can end here
44
+ ```
45
+
46
+ The session that carries the job out, in another process:
47
+
48
+ ```typescript
49
+ const [task] = await bridge.inbox(); // taking the job's first letter starts the job
50
+ console.log(task.text);
51
+ // [agent bridge] job #1 "Write the tests for the rate limiter. Cover the burst case." | task from claude@app to codex@app | letter ltr_... | not typed by the user
52
+ // Write the tests for the rate limiter. Cover the burst case.
53
+
54
+ await bridge.send({ job: task.job, kind: 'question', body: 'Mock Redis or run a real one?' });
55
+ // ...the answer arrives in the inbox...
56
+ await bridge.send({ job: task.job, kind: 'report', body: 'Done: 14 tests pass' });
57
+ ```
58
+
59
+ Every letter starts with a line that says which job it belongs to, what it is and who wrote it. In a harness window a letter looks like a message of the person at the keyboard, and the line says it is not one. Only the bridge writes that line: a title cannot add fields to it, a body line that starts like one is shown as a quote (`> `), and what the bridge repeats of an agent's words in its own notes is quoted the same way.
60
+
61
+ `callerFromEnv` reads three more variables. `COGITATOR_BRIDGE_HARNESS` says which harness is calling when one session runs inside another and the environment names both (`claude-code` or `codex`), without it such a call is refused. `COGITATOR_BRIDGE_AGENT` is the name the bridge gave a session it started, and `COGITATOR_BRIDGE_SESSION_NAME` is what a person calls the session.
62
+
63
+ ## Jobs
64
+
65
+ A job is an [A2A](https://www.npmjs.com/package/@cogitator-ai/a2a) task underneath, run by the `TaskManager` of `@cogitator-ai/a2a`, so it has the A2A lifecycle:
66
+
67
+ | State | Meaning |
68
+ | ---------------- | ---------------------------------------------------------------------------------- |
69
+ | `submitted` | Handed over, not picked up yet |
70
+ | `working` | The one it is for took it, was handed it by an adapter, or wrote anything about it |
71
+ | `input-required` | The one doing it asked a question and waits |
72
+ | `completed` | Reported as done |
73
+ | `failed` | Reported as failed, or failed by a limit |
74
+ | `canceled` | Canceled by the agent that handed it over |
75
+
76
+ A job also carries who handed it over and who carries it out, the project and the folder inside it, its checks, its budget and its depth. A job handed over from inside another job is part of it: it ends no later than its parent, and is canceled when its parent is over, whether that one was reported on, failed or was canceled. `verification` says whether the checks confirmed the result. A report is a claim, the verification is the fact, so an agent cannot set it: it is absent until the process that hosts the dispatcher records it with `dispatcher.recordVerification(job, { verified, summary })`, and it is not served on the socket.
77
+
78
+ ## Letters
79
+
80
+ | Kind | Sent by | Effect |
81
+ | ------------ | ---------------- | --------------------------------------------------------------------- |
82
+ | `task` | `createJob` | The job itself |
83
+ | `question` | either side | Needs an `answer`. From the one doing the job it puts the job on hold |
84
+ | `permission` | either side | A question that asks for leave to do something |
85
+ | `answer` | the one asked | Answers a question, and resumes the job once none is open |
86
+ | `report` | the one doing it | Ends the job, `outcome: 'completed'` (default) or `'failed'` |
87
+ | `note` | either side | Something to know, needs no answer |
88
+
89
+ A letter moves `queued`, `delivered`, `read`, `handled` and never back. `acknowledge(letterId)` is how a note is put away. A question or a job is not dismissed that way: it is done with once answered or reported on, or when its job is over.
90
+
91
+ A retry is safe when the letter has an id: `send({ id })` and `createJob({ letterId })` change nothing the second time. The same id with other words is refused. A field the bridge does not know is refused too, instead of being dropped in silence.
92
+
93
+ `inbox()` returns 20 letters at most (`limit`, up to 100) and no more text than one answer holds, and marks only the letters it returned: call it again for the rest. `inbox({ unhandled: true })` adds the newest of what was taken before and not answered or put away, for a session that may have missed an answer, and `afterSeq` looks further back or forward than one call returns. `letters()` and `readJournal()` return 200 entries at most, go on from the last one with `afterSeq`. The history of the A2A task under a job keeps the first 4000 characters of a long letter, the letter itself is kept whole.
94
+
95
+ ## Who a letter is for
96
+
97
+ A session enters the address book the first time it calls the bridge, and gets a name: `codex@my-project`, then `codex-2@my-project`. An address is:
98
+
99
+ - an agent's name: `codex-2@my-project`
100
+ - a harness word: `codex` or `claude` reaches the only session of that harness in the caller's project
101
+ - a harness word and a session: `codex:reviewer` picks one by its session name or id
102
+ - `codex:new` asks for a fresh session
103
+
104
+ When no session fits and the harness has an adapter that can start one, the bridge starts it for the job. When several fit, the call is refused with their names and how long ago each was heard from. Every worktree of a repository is one project. A harness name is letters, digits, `.`, `_` and `-`, whatever the case. A session is addressed by whatever it is called, or the start of it, as long as that does not begin with `-`.
105
+
106
+ A session that has not called the bridge for 12 hours and has no job in progress is taken for gone, so yesterday's closed window does not stand in the way of today's. It is back under the same name the moment it calls again.
107
+
108
+ ## Limits
109
+
110
+ Each number is a default that `hostBridge({ limits })` changes.
111
+
112
+ | Limit | Default | What happens |
113
+ | ----------------- | ---------- | ---------------------------------------------------------------------------------------------------- |
114
+ | Depth | 3 | A job handed over from inside a job from inside a job is the deepest. One more is refused |
115
+ | Letters per job | 60 | The job fails, both sides are told. The report that ends the job always goes through |
116
+ | Time per job | 4 hours | The job fails, both sides are told |
117
+ | Reply timeout | 30 minutes | The one who owes an answer, or did not pick a job up, is reminded. After as long again the job fails |
118
+ | Jobs out | 20 | An agent with that many jobs still in progress cannot hand over another |
119
+ | Jobs per hour | 60 | Handing over faster is refused as a loop |
120
+ | Sessions starting | 2 | No more sessions are started at once |
121
+ | Silence | 12 hours | A session with no job in progress is taken for gone |
122
+ | Delivery | 5 attempts | Retried with a growing wait, then left for the inbox |
123
+
124
+ Two more rules have no number. A letter that says what the previous one in the same direction said is not delivered, and neither is a job the same agent already has from the caller and has not finished.
125
+
126
+ A job may ask for its own budget: `createJob({ budget: { letters: 20, durationMs: 30 * 60_000 } })`.
127
+
128
+ ## The journal
129
+
130
+ Every letter, delivery and change of a job, and every job or letter a limit held back, is appended to a journal that cannot be changed afterwards (the database refuses updates and deletes of it). `cogitator bridge log` reads it, `bridge.readJournal({ job })` returns it, and `bridge.subscribe(listener)` follows it as it grows.
131
+
132
+ ## In your own process
133
+
134
+ ```typescript
135
+ import { hostBridge } from '@cogitator-ai/bridge';
136
+
137
+ const host = await hostBridge({ limits: { maxDepth: 2 } });
138
+ // host.dispatcher is the BridgeDispatcher, host.stopped resolves when it stops
139
+ await host.close();
140
+ ```
141
+
142
+ `hostBridge` throws `BridgeError` with the code `already_running` when another dispatcher holds the store. Which dispatcher owns the store is decided by the store itself: a lease row taken in a transaction, renewed on every tick and checked inside every write. A dispatcher whose process is gone is replaced at once, and one that was replaced while its machine slept writes nothing after it wakes. `BridgeDispatcher` and `SqliteBridgeStore` are exported for tests and tools of your own, and on their own they take no lease: it is `hostBridge` that makes sure there is one writer.
143
+
144
+ ### Adapters
145
+
146
+ An adapter tells the bridge how to reach the sessions of one harness:
147
+
148
+ ```typescript
149
+ import type { BridgeAdapter } from '@cogitator-ai/bridge';
150
+
151
+ const adapter: BridgeAdapter = {
152
+ harness: 'my-harness',
153
+ delivery: 'queue',
154
+ capabilities: { createSession: false, push: true, steer: false, nativeWindow: true },
155
+ async deliver({ agent, letter }) {
156
+ await myHarness.send(agent.sessionId, letter.text);
157
+ },
158
+ };
159
+
160
+ const host = await hostBridge({ adapters: [adapter] });
161
+ ```
162
+
163
+ Without an adapter a session still takes part: its letters wait in its inbox.
164
+
165
+ ## Trust
166
+
167
+ The bridge is a tool of one person on one machine. The socket and the database are created for their owner only, a folder or a database that belongs to another user is refused, and every process of that user can connect: read any job and letter, and call as a session by naming its id. A job is done inside the project it is handed over in, or the worktree its caller works in. Do not point `COGITATOR_BRIDGE_HOME` at a folder other users can write to. On Windows the dispatcher listens on a named pipe that other users of the same machine can reach, so run it only on a machine you do not share.
168
+
169
+ ## Errors
170
+
171
+ Every refusal is a `BridgeError` with a `code` to branch on and a message written for the agent that gets it: `not_registered`, `unknown_agent`, `ambiguous_agent`, `no_session`, `unknown_job`, `unknown_letter`, `not_a_party`, `job_finished`, `invalid_letter`, `invalid_input`, `depth_exceeded`, `budget_exhausted`, `loop_detected`, `already_running`, `not_running`, `storage`.
172
+
173
+ ## Documentation
174
+
175
+ Full guide: [cogitator.app/docs/bridge](https://cogitator.app/docs/bridge)
176
+
177
+ ## Part of Cogitator
178
+
179
+ This package is part of the [Cogitator](https://github.com/cogitator-ai/Cogitator-AI) ecosystem, a self-hosted, production-grade AI agent runtime for TypeScript.
180
+
181
+ ## License
182
+
183
+ MIT
@@ -0,0 +1,74 @@
1
+ import type { CreateJobResult, SendLetterResult } from './dispatcher.js';
2
+ import type { CreateJobInput, InboxInput, SendLetterInput } from './inputs.js';
3
+ import { type BridgeStatus, type DispatcherInfo } from './protocol.js';
4
+ import type { AgentFilter, JobTaskFilter, JournalQuery, LetterFilter } from './store/store.js';
5
+ import type { AgentRecord, BridgeJob, CallerIdentity, JournalEntry, Letter, RenderedLetter } from './types.js';
6
+ export interface BridgeClientOptions {
7
+ /** Where the dispatcher listens */
8
+ socketPath: string;
9
+ /** The session calling. Without it the client can read, and cannot act as an agent */
10
+ caller?: CallerIdentity;
11
+ /** How long to wait for the dispatcher to answer a call, 30 s by default */
12
+ timeoutMs?: number;
13
+ }
14
+ /**
15
+ * A connection to the dispatcher of this machine. Created for a session it acts as that agent:
16
+ * the jobs it hands over and the letters it sends are from it, its inbox is that agent's.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const caller = callerFromEnv(process.env, process.cwd());
21
+ * const bridge = await BridgeClient.connect({ socketPath: bridgePaths().socket, caller });
22
+ * const { job } = await bridge.createJob({ to: 'codex', body: 'Write the tests' });
23
+ * await bridge.close();
24
+ * ```
25
+ */
26
+ export declare class BridgeClient {
27
+ private readonly socket;
28
+ private readonly peer;
29
+ private readonly timeoutMs;
30
+ private readonly listeners;
31
+ /** The dispatcher the client reached */
32
+ readonly dispatcher: DispatcherInfo;
33
+ /** The agent the client acts as, when it was created for a session */
34
+ readonly agent: AgentRecord | undefined;
35
+ /** What the dispatcher sends this connection: one job, everything, or nothing */
36
+ private subscribed;
37
+ /** The last change of the subscription: they run one after another, each seeing the listeners as they are then */
38
+ private syncing;
39
+ private constructor();
40
+ /**
41
+ * @throws BridgeError `not_running` when no dispatcher listens on the socket
42
+ */
43
+ static connect(options: BridgeClientOptions): Promise<BridgeClient>;
44
+ /** Whether the connection is gone */
45
+ get closed(): boolean;
46
+ createJob(input: CreateJobInput): Promise<CreateJobResult>;
47
+ send(input: SendLetterInput): Promise<SendLetterResult>;
48
+ inbox(input?: InboxInput): Promise<RenderedLetter[]>;
49
+ acknowledge(letter: string): Promise<Letter>;
50
+ cancel(job: number, reason?: string): Promise<BridgeJob>;
51
+ job(number: number): Promise<BridgeJob>;
52
+ jobs(filter?: JobTaskFilter): Promise<BridgeJob[]>;
53
+ agents(filter?: AgentFilter): Promise<AgentRecord[]>;
54
+ letters(filter?: LetterFilter): Promise<Letter[]>;
55
+ readJournal(query?: JournalQuery): Promise<JournalEntry[]>;
56
+ status(): Promise<BridgeStatus>;
57
+ /**
58
+ * Hears every entry the journal gets from now on, of one job or of all. Each listener has its
59
+ * own filter. Resolves once the dispatcher is sending, with a function that stops it.
60
+ */
61
+ subscribe(listener: (entry: JournalEntry) => void, options?: {
62
+ job?: number;
63
+ }): Promise<() => Promise<void>>;
64
+ /**
65
+ * Asks the dispatcher for what the listeners need between them: one job when they all want the
66
+ * same one, everything otherwise, nothing when none is left. Changes run one after another, so
67
+ * one made while another is on its way is not lost.
68
+ */
69
+ private syncSubscription;
70
+ /** Ends the connection. Calls still waiting for an answer reject */
71
+ close(): Promise<void>;
72
+ private call;
73
+ }
74
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,cAAc,EAEpB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;A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MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAIvC,IAAI,CAAC,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAItD,MAAM,CAAC,MAAM,GAAE,WAAgB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIxD,OAAO,CAAC,MAAM,GAAE,YAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIrD,WAAW,CAAC,KAAK,GAAE,YAAiB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAI9D,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;IAI/B;;;OAGG;IACG,SAAS,CACb,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,EACvC,OAAO,GAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAO,GAC7B,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAc/B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAgBxB,oEAAoE;IAC9D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YASd,IAAI;CAOnB"}
package/dist/client.js ADDED
@@ -0,0 +1,202 @@
1
+ import { connect } from 'node:net';
2
+ import { JsonRpcPeer, encodeNdjsonLine, readNdjson, } from '@cogitator-ai/server-shared';
3
+ import { BridgeError } from './errors.js';
4
+ import { BRIDGE_METHODS, BRIDGE_NOTIFICATIONS, BRIDGE_PROTOCOL_VERSION, fromJsonRpcError, } from './protocol.js';
5
+ const DEFAULT_TIMEOUT_MS = 30_000;
6
+ const NO_DISPATCHER_CODES = new Set(['ENOENT', 'ECONNREFUSED', 'ENOTSOCK']);
7
+ function open(socketPath) {
8
+ return new Promise((resolve, reject) => {
9
+ const socket = connect(socketPath);
10
+ const onError = (error) => {
11
+ reject(error.code && NO_DISPATCHER_CODES.has(error.code)
12
+ ? new BridgeError('not_running', 'No bridge dispatcher is running on this machine. Start one: cogitator bridge serve', { socket: socketPath })
13
+ : error);
14
+ };
15
+ socket.once('error', onError);
16
+ socket.once('connect', () => {
17
+ socket.off('error', onError);
18
+ resolve(socket);
19
+ });
20
+ });
21
+ }
22
+ /**
23
+ * A connection to the dispatcher of this machine. Created for a session it acts as that agent:
24
+ * the jobs it hands over and the letters it sends are from it, its inbox is that agent's.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const caller = callerFromEnv(process.env, process.cwd());
29
+ * const bridge = await BridgeClient.connect({ socketPath: bridgePaths().socket, caller });
30
+ * const { job } = await bridge.createJob({ to: 'codex', body: 'Write the tests' });
31
+ * await bridge.close();
32
+ * ```
33
+ */
34
+ export class BridgeClient {
35
+ socket;
36
+ peer;
37
+ timeoutMs;
38
+ listeners;
39
+ dispatcher;
40
+ agent;
41
+ /** What the dispatcher sends this connection: one job, everything, or nothing */
42
+ subscribed = null;
43
+ /** The last change of the subscription: they run one after another, each seeing the listeners as they are then */
44
+ syncing = Promise.resolve();
45
+ constructor(socket, peer, timeoutMs, listeners,
46
+ /** The dispatcher the client reached */
47
+ dispatcher,
48
+ /** The agent the client acts as, when it was created for a session */
49
+ agent) {
50
+ this.socket = socket;
51
+ this.peer = peer;
52
+ this.timeoutMs = timeoutMs;
53
+ this.listeners = listeners;
54
+ this.dispatcher = dispatcher;
55
+ this.agent = agent;
56
+ }
57
+ /**
58
+ * @throws BridgeError `not_running` when no dispatcher listens on the socket
59
+ */
60
+ static async connect(options) {
61
+ const socket = await open(options.socketPath);
62
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
63
+ const peer = new JsonRpcPeer({
64
+ send: (message) => {
65
+ socket.write(encodeNdjsonLine(message));
66
+ },
67
+ });
68
+ const listeners = new Map();
69
+ peer.onNotification(BRIDGE_NOTIFICATIONS.journalEntry, (value) => {
70
+ const entry = value;
71
+ for (const [listener, job] of [...listeners]) {
72
+ if (job === undefined || job === entry.job)
73
+ listener(entry);
74
+ }
75
+ });
76
+ const closed = new BridgeError('not_running', 'The connection to the bridge dispatcher closed');
77
+ socket.on('error', () => peer.close(closed));
78
+ socket.on('close', () => peer.close(closed));
79
+ void (async () => {
80
+ try {
81
+ for await (const line of readNdjson(socket)) {
82
+ if ('value' in line) {
83
+ void peer.receive(line.value);
84
+ continue;
85
+ }
86
+ peer.close(new BridgeError('storage', `The bridge dispatcher sent an answer the client could not read (${line.error.message}). Ask for less at once with a limit`));
87
+ socket.destroy();
88
+ return;
89
+ }
90
+ }
91
+ catch {
92
+ peer.close(closed);
93
+ }
94
+ })();
95
+ let hello;
96
+ try {
97
+ hello = await peer.request(BRIDGE_METHODS.hello, { protocol: BRIDGE_PROTOCOL_VERSION, ...(options.caller && { caller: options.caller }) }, { timeoutMs });
98
+ }
99
+ catch (error) {
100
+ peer.close();
101
+ socket.destroy();
102
+ throw fromJsonRpcError(error);
103
+ }
104
+ return new BridgeClient(socket, peer, timeoutMs, listeners, hello.dispatcher, hello.agent);
105
+ }
106
+ /** Whether the connection is gone */
107
+ get closed() {
108
+ return this.peer.closed;
109
+ }
110
+ createJob(input) {
111
+ return this.call(BRIDGE_METHODS.createJob, input);
112
+ }
113
+ send(input) {
114
+ return this.call(BRIDGE_METHODS.send, input);
115
+ }
116
+ inbox(input = {}) {
117
+ return this.call(BRIDGE_METHODS.inbox, input);
118
+ }
119
+ acknowledge(letter) {
120
+ return this.call(BRIDGE_METHODS.acknowledge, { letter });
121
+ }
122
+ cancel(job, reason) {
123
+ return this.call(BRIDGE_METHODS.cancelJob, { job, ...(reason !== undefined && { reason }) });
124
+ }
125
+ job(number) {
126
+ return this.call(BRIDGE_METHODS.getJob, { job: number });
127
+ }
128
+ jobs(filter = {}) {
129
+ return this.call(BRIDGE_METHODS.listJobs, filter);
130
+ }
131
+ agents(filter = {}) {
132
+ return this.call(BRIDGE_METHODS.listAgents, filter);
133
+ }
134
+ letters(filter = {}) {
135
+ return this.call(BRIDGE_METHODS.listLetters, filter);
136
+ }
137
+ readJournal(query = {}) {
138
+ return this.call(BRIDGE_METHODS.readJournal, query);
139
+ }
140
+ status() {
141
+ return this.call(BRIDGE_METHODS.status, {});
142
+ }
143
+ /**
144
+ * Hears every entry the journal gets from now on, of one job or of all. Each listener has its
145
+ * own filter. Resolves once the dispatcher is sending, with a function that stops it.
146
+ */
147
+ async subscribe(listener, options = {}) {
148
+ this.listeners.set(listener, options.job);
149
+ try {
150
+ await this.syncSubscription();
151
+ }
152
+ catch (error) {
153
+ this.listeners.delete(listener);
154
+ throw error;
155
+ }
156
+ return async () => {
157
+ if (!this.listeners.delete(listener) || this.peer.closed)
158
+ return;
159
+ await this.syncSubscription();
160
+ };
161
+ }
162
+ /**
163
+ * Asks the dispatcher for what the listeners need between them: one job when they all want the
164
+ * same one, everything otherwise, nothing when none is left. Changes run one after another, so
165
+ * one made while another is on its way is not lost.
166
+ */
167
+ syncSubscription() {
168
+ const sync = this.syncing.then(async () => {
169
+ const jobs = new Set(this.listeners.values());
170
+ const wanted = this.listeners.size === 0 ? null : jobs.size === 1 ? ([...jobs][0] ?? 'all') : 'all';
171
+ if (wanted === this.subscribed)
172
+ return;
173
+ if (wanted === null)
174
+ await this.call(BRIDGE_METHODS.unsubscribeJournal, {});
175
+ else {
176
+ await this.call(BRIDGE_METHODS.subscribeJournal, wanted === 'all' ? {} : { job: wanted });
177
+ }
178
+ this.subscribed = wanted;
179
+ });
180
+ this.syncing = sync.catch(() => undefined);
181
+ return sync;
182
+ }
183
+ /** Ends the connection. Calls still waiting for an answer reject */
184
+ async close() {
185
+ this.peer.close();
186
+ if (this.socket.destroyed)
187
+ return;
188
+ await new Promise((resolve) => {
189
+ this.socket.once('close', () => resolve());
190
+ this.socket.end();
191
+ });
192
+ }
193
+ async call(method, params) {
194
+ try {
195
+ return await this.peer.request(method, params, { timeoutMs: this.timeoutMs });
196
+ }
197
+ catch (error) {
198
+ throw fromJsonRpcError(error);
199
+ }
200
+ }
201
+ }
202
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot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