@sovara/runner 0.1.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 (122) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +331 -0
  3. package/dist/apiTypes.d.ts +4 -0
  4. package/dist/apiTypes.d.ts.map +1 -0
  5. package/dist/apiTypes.js +4 -0
  6. package/dist/apiTypes.js.map +1 -0
  7. package/dist/capture/requestEnvelope.d.ts +10 -0
  8. package/dist/capture/requestEnvelope.d.ts.map +1 -0
  9. package/dist/capture/requestEnvelope.js +79 -0
  10. package/dist/capture/requestEnvelope.js.map +1 -0
  11. package/dist/capture/responseEnvelope.d.ts +14 -0
  12. package/dist/capture/responseEnvelope.d.ts.map +1 -0
  13. package/dist/capture/responseEnvelope.js +43 -0
  14. package/dist/capture/responseEnvelope.js.map +1 -0
  15. package/dist/capture/sseUtils.d.ts +3 -0
  16. package/dist/capture/sseUtils.d.ts.map +1 -0
  17. package/dist/capture/sseUtils.js +69 -0
  18. package/dist/capture/sseUtils.js.map +1 -0
  19. package/dist/capture/streamCapture.d.ts +5 -0
  20. package/dist/capture/streamCapture.d.ts.map +1 -0
  21. package/dist/capture/streamCapture.js +19 -0
  22. package/dist/capture/streamCapture.js.map +1 -0
  23. package/dist/claudeAgentSdk/parseHook.d.ts +20 -0
  24. package/dist/claudeAgentSdk/parseHook.d.ts.map +1 -0
  25. package/dist/claudeAgentSdk/parseHook.js +160 -0
  26. package/dist/claudeAgentSdk/parseHook.js.map +1 -0
  27. package/dist/claudeAgentSdk/wrapper.d.ts +17 -0
  28. package/dist/claudeAgentSdk/wrapper.d.ts.map +1 -0
  29. package/dist/claudeAgentSdk/wrapper.js +219 -0
  30. package/dist/claudeAgentSdk/wrapper.js.map +1 -0
  31. package/dist/constants.d.ts +6 -0
  32. package/dist/constants.d.ts.map +1 -0
  33. package/dist/constants.js +7 -0
  34. package/dist/constants.js.map +1 -0
  35. package/dist/context.d.ts +34 -0
  36. package/dist/context.d.ts.map +1 -0
  37. package/dist/context.js +106 -0
  38. package/dist/context.js.map +1 -0
  39. package/dist/endpointPatterns.json +82 -0
  40. package/dist/endpointWhitelist.d.ts +2 -0
  41. package/dist/endpointWhitelist.d.ts.map +1 -0
  42. package/dist/endpointWhitelist.js +11 -0
  43. package/dist/endpointWhitelist.js.map +1 -0
  44. package/dist/env.d.ts +7 -0
  45. package/dist/env.d.ts.map +1 -0
  46. package/dist/env.js +10 -0
  47. package/dist/env.js.map +1 -0
  48. package/dist/index.d.ts +5 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +9 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/mcpPatch.d.ts +2 -0
  53. package/dist/mcpPatch.d.ts.map +1 -0
  54. package/dist/mcpPatch.js +195 -0
  55. package/dist/mcpPatch.js.map +1 -0
  56. package/dist/payload/editIoExcludePatterns.json +292 -0
  57. package/dist/payload/filterDict.d.ts +3 -0
  58. package/dist/payload/filterDict.d.ts.map +1 -0
  59. package/dist/payload/filterDict.js +26 -0
  60. package/dist/payload/filterDict.js.map +1 -0
  61. package/dist/payload/flatten.d.ts +6 -0
  62. package/dist/payload/flatten.d.ts.map +1 -0
  63. package/dist/payload/flatten.js +79 -0
  64. package/dist/payload/flatten.js.map +1 -0
  65. package/dist/payload/wrap.d.ts +6 -0
  66. package/dist/payload/wrap.d.ts.map +1 -0
  67. package/dist/payload/wrap.js +8 -0
  68. package/dist/payload/wrap.js.map +1 -0
  69. package/dist/priors.d.ts +7 -0
  70. package/dist/priors.d.ts.map +1 -0
  71. package/dist/priors.js +87 -0
  72. package/dist/priors.js.map +1 -0
  73. package/dist/priorsBlockGuidance.json +3 -0
  74. package/dist/projectContext.d.ts +12 -0
  75. package/dist/projectContext.d.ts.map +1 -0
  76. package/dist/projectContext.js +26 -0
  77. package/dist/projectContext.js.map +1 -0
  78. package/dist/runLogCapture.d.ts +10 -0
  79. package/dist/runLogCapture.d.ts.map +1 -0
  80. package/dist/runLogCapture.js +117 -0
  81. package/dist/runLogCapture.js.map +1 -0
  82. package/dist/runtimeClient.d.ts +103 -0
  83. package/dist/runtimeClient.d.ts.map +1 -0
  84. package/dist/runtimeClient.js +202 -0
  85. package/dist/runtimeClient.js.map +1 -0
  86. package/dist/serverLifecycle.d.ts +2 -0
  87. package/dist/serverLifecycle.d.ts.map +1 -0
  88. package/dist/serverLifecycle.js +59 -0
  89. package/dist/serverLifecycle.js.map +1 -0
  90. package/dist/sseListener.d.ts +9 -0
  91. package/dist/sseListener.d.ts.map +1 -0
  92. package/dist/sseListener.js +56 -0
  93. package/dist/sseListener.js.map +1 -0
  94. package/dist/transport/awsSdkHttp2Patch.d.ts +2 -0
  95. package/dist/transport/awsSdkHttp2Patch.d.ts.map +1 -0
  96. package/dist/transport/awsSdkHttp2Patch.js +428 -0
  97. package/dist/transport/awsSdkHttp2Patch.js.map +1 -0
  98. package/dist/transport/fetchPatch.d.ts +3 -0
  99. package/dist/transport/fetchPatch.d.ts.map +1 -0
  100. package/dist/transport/fetchPatch.js +237 -0
  101. package/dist/transport/fetchPatch.js.map +1 -0
  102. package/dist/transport/nodeHttpPatch.d.ts +3 -0
  103. package/dist/transport/nodeHttpPatch.d.ts.map +1 -0
  104. package/dist/transport/nodeHttpPatch.js +522 -0
  105. package/dist/transport/nodeHttpPatch.js.map +1 -0
  106. package/dist/user.d.ts +11 -0
  107. package/dist/user.d.ts.map +1 -0
  108. package/dist/user.js +31 -0
  109. package/dist/user.js.map +1 -0
  110. package/dist/util/logger.d.ts +2 -0
  111. package/dist/util/logger.d.ts.map +1 -0
  112. package/dist/util/logger.js +9 -0
  113. package/dist/util/logger.js.map +1 -0
  114. package/dist/util/stableJson.d.ts +2 -0
  115. package/dist/util/stableJson.d.ts.map +1 -0
  116. package/dist/util/stableJson.js +22 -0
  117. package/dist/util/stableJson.js.map +1 -0
  118. package/dist/util/stackTrace.d.ts +2 -0
  119. package/dist/util/stackTrace.d.ts.map +1 -0
  120. package/dist/util/stackTrace.js +11 -0
  121. package/dist/util/stackTrace.js.map +1 -0
  122. package/package.json +74 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,331 @@
1
+ # @sovara/runner
2
+
3
+ TypeScript runner for [Sovara](https://sovaralabs.github.io/sovara/) — wrap your script in a
4
+ single function and Sovara records every LLM call, tool invocation, and log
5
+ line into a structured run graph.
6
+
7
+ The runner is the TS counterpart to the Python `sovara` runner. It targets
8
+ the same Sovara server, produces the same node shapes, and is safe to mix
9
+ with Python runs in the same project.
10
+
11
+ ## Requirements
12
+
13
+ - Node 18 or newer (built-in `fetch`).
14
+ - A running Sovara server on the same machine. The runner will auto-launch
15
+ it via `so-cli server start` if it's installed and not already running.
16
+ - A Sovara user and project, configured once with `so-cli init`.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install @sovara/runner
22
+ # or
23
+ pnpm add @sovara/runner
24
+ # or
25
+ yarn add @sovara/runner
26
+ ```
27
+
28
+ If you use the [Claude Agent SDK](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk),
29
+ install it as a peer dependency:
30
+
31
+ ```bash
32
+ npm install @anthropic-ai/claude-agent-sdk
33
+ ```
34
+
35
+ ## Quick start
36
+
37
+ ```ts
38
+ import { withSovaraRun } from "@sovara/runner";
39
+ import OpenAI from "openai";
40
+
41
+ const openai = new OpenAI();
42
+
43
+ await withSovaraRun("hello-world", async () => {
44
+ const response = await openai.responses.create({
45
+ model: "gpt-5",
46
+ input: "Say hello.",
47
+ });
48
+
49
+ console.log(response.output_text);
50
+ });
51
+ ```
52
+
53
+ That's the full integration. The call to OpenAI is captured automatically;
54
+ `console.log` output is captured as run logs; the run shows up in the
55
+ Sovara UI.
56
+
57
+ ## How it works
58
+
59
+ Importing `@sovara/runner` patches two transports at module load:
60
+
61
+ - `globalThis.fetch` — wraps every `fetch` call.
62
+ - `node:http` and `node:https` — wraps `http.request` / `http.get` and
63
+ their HTTPS counterparts. This covers `axios` and any library that uses
64
+ Node's HTTP modules directly.
65
+
66
+ Inside `withSovaraRun(...)`, calls to whitelisted endpoints are observed:
67
+ the runner builds a request envelope, posts it to the Sovara server's
68
+ `/internal/runner/llm/prepare` endpoint (which optionally applies
69
+ runtime preparation such as priors injection), executes the prepared
70
+ request on the wire, and records the response or exception. Outside the
71
+ run scope, both patches are no-ops.
72
+
73
+ ### Endpoints captured by default
74
+
75
+ | Provider | Path pattern |
76
+ | ---------------- | ----------------------------------------------------------------------------- |
77
+ | Anthropic | `/v1/messages` |
78
+ | OpenAI Responses | `/v1/responses` |
79
+ | OpenAI Chat | `/v1/chat/completions` |
80
+ | AWS Bedrock | `bedrock-runtime.*.amazonaws.com/model/.../{converse,invoke}` |
81
+ | Google Gemini | `models/...:generateContent`, `:streamGenerateContent` |
82
+ | Ollama | `/api/chat`, `/api/generate`, `/api/embed`, `/api/embeddings` |
83
+ | Tooling | Serper, Brave Search, Jina Reader, BrightData, Patronus, Contextual, Parallel |
84
+
85
+ Streaming responses (SSE, NDJSON, JSONL, chunked text) are tee'd: the user
86
+ gets the bytes unchanged and the runner finalizes after the stream
87
+ completes.
88
+
89
+ ## API
90
+
91
+ ### `withSovaraRun(name | options, fn)`
92
+
93
+ ```ts
94
+ export type WithSovaraRunOptions = {
95
+ name: string; // required run name
96
+ url?: string; // server URL (default: SOVARA_SERVER_URL or http://127.0.0.1:5959)
97
+ captureLogs?: boolean; // default: true
98
+ seedRandom?: boolean; // default: false
99
+ user?: { fullName?: string; email?: string }; // overrides only
100
+ project?: { name?: string; description?: string };
101
+ };
102
+
103
+ export function withSovaraRun<T>(
104
+ input: string | WithSovaraRunOptions,
105
+ fn: () => Promise<T> | T,
106
+ ): Promise<T>;
107
+ ```
108
+
109
+ The string form is shorthand for `{ name: input }`. The runner returns
110
+ whatever `fn` returns.
111
+
112
+ **Top-level call** (no parent run on the stack):
113
+
114
+ 1. Health-checks the server, auto-launching it via `so-cli server start`
115
+ if it's unreachable.
116
+ 2. Resolves the active user. Fails hard with a `so-cli init` hint if
117
+ user setup is missing.
118
+ 3. Resolves the project for `process.cwd()`. Fails hard with a `so-cli init`
119
+ hint if the cwd isn't part of a known Sovara project.
120
+ 4. Registers the run, opens an SSE shutdown listener, runs `fn` inside
121
+ an `AsyncLocalStorage` scope, and deregisters in `finally`.
122
+
123
+ **Nested call** (called from inside another `withSovaraRun`):
124
+
125
+ The nested call is registered as a subrun via `/runner/subrun`, inheriting
126
+ the parent's `client`, `url`, and `seedRandom` settings. It deregisters
127
+ its own subrun when `fn` returns.
128
+
129
+ `fn` exceptions propagate untouched. The run is deregistered in either
130
+ case.
131
+
132
+ ### Subruns
133
+
134
+ ```ts
135
+ await withSovaraRun("pipeline", async () => {
136
+ const docs = await withSovaraRun("retrieve", async () => loadDocs());
137
+ await withSovaraRun("summarize", async () => summarize(docs));
138
+ });
139
+ ```
140
+
141
+ Every nested `withSovaraRun` becomes a subrun under the active scope.
142
+
143
+ ### Logs
144
+
145
+ Standard `console.log`, `console.error`, and any direct writes to
146
+ `process.stdout` / `process.stderr` are captured into the run log
147
+ buffer and flushed to the server every 250ms.
148
+
149
+ Disable with `captureLogs: false`:
150
+
151
+ ```ts
152
+ await withSovaraRun({ name: "noisy", captureLogs: false }, async () => {
153
+ // stdout/stderr will not be tee'd to the server
154
+ });
155
+ ```
156
+
157
+ ### Deterministic seed
158
+
159
+ Set `seedRandom: true` to populate `process.env.SOVARA_SEED` with a
160
+ random integer at the start of the run (only if `SOVARA_SEED` isn't
161
+ already set). Useful when you want the run's UUIDs and stochastic
162
+ choices to be reproducible across replays.
163
+
164
+ ```ts
165
+ await withSovaraRun({ name: "experiment", seedRandom: true }, async () => {
166
+ // process.env.SOVARA_SEED is now a stable string for this run.
167
+ });
168
+ ```
169
+
170
+ ### User and project overrides
171
+
172
+ ```ts
173
+ await withSovaraRun(
174
+ {
175
+ name: "billing-job",
176
+ user: { fullName: "CI Bot", email: "ci@example.com" },
177
+ project: { name: "Billing", description: "Nightly invoice run" },
178
+ },
179
+ async () => doWork(),
180
+ );
181
+ ```
182
+
183
+ Overrides are only applied if user/project are present. They don't bypass
184
+ the `so-cli init` requirement — they just refine the values.
185
+
186
+ ## Claude Agent SDK integration
187
+
188
+ ESM module namespaces in Node are immutable, so the runner cannot
189
+ monkey-patch `@anthropic-ai/claude-agent-sdk` from the outside. Instead,
190
+ `@sovara/runner` ships a drop-in wrapper at `@sovara/runner/claude`:
191
+
192
+ ```ts
193
+ // before
194
+ import { query, startup } from "@anthropic-ai/claude-agent-sdk";
195
+
196
+ // after
197
+ import { query, startup } from "@sovara/runner/claude";
198
+ ```
199
+
200
+ That single import change is the entire integration. The wrapper:
201
+
202
+ - Routes the spawned Claude CLI subprocess through Sovara's local Claude
203
+ proxy by setting `ANTHROPIC_BASE_URL` in the subprocess env, so every
204
+ LLM request the SDK makes shows up in your run graph.
205
+ - Registers a unique proxy client with the server before each `query()` /
206
+ `startup()` so concurrent SDK calls don't collide.
207
+ - Sets `CLAUDE_CODE_ENTRYPOINT=sdk-ts` and `SOVARA_CLAUDE_PROXY_ACTIVE=1`
208
+ to mark the subprocess as running under Sovara.
209
+ - Wraps the returned `AsyncIterable` so each yielded message is parsed
210
+ for `tool_use` / `tool_result` blocks and recorded as nodes on the
211
+ run.
212
+ - Throws if `options.transport` (custom transport) is supplied — this
213
+ matches the Python runner's behavior.
214
+ - Throws if `options.env.ANTHROPIC_BASE_URL` already points at the
215
+ Sovara proxy, to prevent infinite proxy loops.
216
+ - Outside a `withSovaraRun` scope, `query()` and `startup()` are
217
+ pass-throughs to the real SDK with zero overhead.
218
+
219
+ ### Example
220
+
221
+ ```ts
222
+ import { withSovaraRun } from "@sovara/runner";
223
+ import { query } from "@sovara/runner/claude";
224
+
225
+ await withSovaraRun("agent-task", async () => {
226
+ for await (const message of query({
227
+ prompt: "List the largest files in the current directory.",
228
+ })) {
229
+ if (message.type === "assistant") {
230
+ // tool_use blocks here are also recorded as Sovara nodes.
231
+ }
232
+ }
233
+ });
234
+ ```
235
+
236
+ ### `startup()`
237
+
238
+ ```ts
239
+ import { startup } from "@sovara/runner/claude";
240
+
241
+ const handle = await startup({ options: {} });
242
+ for await (const message of handle.query("What did I install last?")) {
243
+ // ...
244
+ }
245
+ ```
246
+
247
+ `startup()` returns a warm handle whose `query()` is also instrumented.
248
+
249
+ ## Configuration
250
+
251
+ ### Environment variables
252
+
253
+ | Variable | Purpose | Default |
254
+ | ---------------------------- | -------------------------------------------------------------------------- | ----------------------- |
255
+ | `SOVARA_SERVER_URL` | Override the Sovara server URL | `http://127.0.0.1:5959` |
256
+ | `HOST` | Server host (used to compute the default URL) | `127.0.0.1` |
257
+ | `PYTHON_PORT` | Server port (used to compute the default URL) | `5959` |
258
+ | `SOVARA_SEED` | Random seed exposed to user code when `seedRandom: true` | unset |
259
+ | `SOVARA_CLAUDE_PROXY_ACTIVE` | Set automatically by `@sovara/runner/claude` to prevent nested proxy loops | unset |
260
+
261
+ ### Server URL
262
+
263
+ Either pass `url` per call:
264
+
265
+ ```ts
266
+ await withSovaraRun({ name: "demo", url: "http://localhost:6000" }, fn);
267
+ ```
268
+
269
+ Or set `SOVARA_SERVER_URL` once for the process.
270
+
271
+ ## Error messages
272
+
273
+ The runner fails fast for misconfiguration. Common ones:
274
+
275
+ - **`Sovara server is not running and 'so-cli' was not found. Start it manually with 'so-cli server start' or install Sovara.`**
276
+ Install the Sovara CLI or start the server yourself.
277
+
278
+ - **``Sovara user setup is missing. Run `so-cli init --user-name <full-name> --user-email <email>` and retry.``**
279
+ Run the suggested `so-cli init` command.
280
+
281
+ - **``Sovara project setup is missing for <cwd>. Run `so-cli init --project-root "<cwd>" --project-name <project-name>` and retry.``**
282
+ Run the suggested `so-cli init` command.
283
+
284
+ - **`Custom Claude Agent SDK transports are not supported yet under sovara.`**
285
+ Remove `options.transport` from your `query()` / `startup()` call.
286
+
287
+ - **`Claude Agent SDK ANTHROPIC_BASE_URL points at the Sovara Claude proxy itself. Nested Claude proxy configuration is not supported.`**
288
+ Don't manually set `ANTHROPIC_BASE_URL` to the Sovara proxy URL — the
289
+ wrapper sets it for you.
290
+
291
+ ## Limitations
292
+
293
+ - Direct `import { request, fetch } from "undici"` calls are not
294
+ intercepted (the runner patches `globalThis.fetch` and `node:http(s)`,
295
+ which covers all common LLM clients today). Open an issue if you
296
+ encounter an SDK that bypasses both.
297
+ - The runner is Node-only. Browser, edge runtimes, and bundled
298
+ environments without Node's `node:http`/`async_hooks` are out of scope.
299
+ - If you import `@anthropic-ai/claude-agent-sdk` directly anywhere in
300
+ your project, those call sites are not instrumented. Use
301
+ `@sovara/runner/claude` everywhere you want Sovara observability.
302
+
303
+ ## Development
304
+
305
+ ```bash
306
+ npm install
307
+ npm test # vitest run, fully hermetic, no real network or server
308
+ npm run typecheck
309
+ npm run build # emit dist/ via tsc -p tsconfig.build.json
310
+ ```
311
+
312
+ ## Releasing
313
+
314
+ Publishing is automated via GitHub Actions using npm trusted publishing (OIDC)
315
+ with provenance attestations. There is no `NPM_TOKEN` secret — the
316
+ `runner-ts-release.yaml` workflow authenticates to npm via OIDC.
317
+
318
+ To cut a release:
319
+
320
+ 1. Bump `version` in `runner_ts/package.json` on a release PR. Land it on
321
+ `main`.
322
+ 2. From `main`, create and push a tag matching the new version:
323
+ ```bash
324
+ git tag runner-ts-v0.2.0
325
+ git push origin runner-ts-v0.2.0
326
+ ```
327
+ 3. The `Runner (TypeScript) — Release` workflow verifies the tag matches
328
+ `package.json`, runs typecheck + tests + build, then publishes with
329
+ `npm publish --provenance --access public`.
330
+
331
+ The tag must match the package version exactly; mismatches fail the workflow.
@@ -0,0 +1,4 @@
1
+ export declare const API_TYPE_HTTPX_CLIENT_SEND = "httpx.Client.send";
2
+ export declare const API_TYPE_HTTPX_ASYNC_CLIENT_SEND = "httpx.AsyncClient.send";
3
+ export declare const API_TYPE_MCP_CLIENT_SESSION_SEND_REQUEST = "MCP.ClientSession.send_request";
4
+ //# sourceMappingURL=apiTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiTypes.d.ts","sourceRoot":"","sources":["../src/apiTypes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,sBAAsB,CAAC;AAC9D,eAAO,MAAM,gCAAgC,2BAA2B,CAAC;AACzE,eAAO,MAAM,wCAAwC,mCAAmC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const API_TYPE_HTTPX_CLIENT_SEND = "httpx.Client.send";
2
+ export const API_TYPE_HTTPX_ASYNC_CLIENT_SEND = "httpx.AsyncClient.send";
3
+ export const API_TYPE_MCP_CLIENT_SESSION_SEND_REQUEST = "MCP.ClientSession.send_request";
4
+ //# sourceMappingURL=apiTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiTypes.js","sourceRoot":"","sources":["../src/apiTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG,mBAAmB,CAAC;AAC9D,MAAM,CAAC,MAAM,gCAAgC,GAAG,wBAAwB,CAAC;AACzE,MAAM,CAAC,MAAM,wCAAwC,GAAG,gCAAgC,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type RequestEnvelope = {
2
+ url: string;
3
+ body: unknown;
4
+ headers: Record<string, string>;
5
+ method: string;
6
+ bodySupported: boolean;
7
+ };
8
+ export declare const UNSUPPORTED_REQUEST_BODY = "<unsupported>";
9
+ export declare function buildRequestEnvelope(input: RequestInfo | URL, init?: RequestInit): Promise<RequestEnvelope>;
10
+ //# sourceMappingURL=requestEnvelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestEnvelope.d.ts","sourceRoot":"","sources":["../../src/capture/requestEnvelope.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,wBAAwB,kBAAkB,CAAC;AA4DxD,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAwBjH"}
@@ -0,0 +1,79 @@
1
+ export const UNSUPPORTED_REQUEST_BODY = "<unsupported>";
2
+ function headersToObject(headers) {
3
+ const out = {};
4
+ for (const [key, value] of headers.entries()) {
5
+ out[key.toLowerCase()] = value;
6
+ }
7
+ return out;
8
+ }
9
+ function mergeHeaders(base, override) {
10
+ const merged = new Headers(base);
11
+ if (!override) {
12
+ return merged;
13
+ }
14
+ const extra = new Headers(override);
15
+ for (const [key, value] of extra.entries()) {
16
+ merged.set(key, value);
17
+ }
18
+ return merged;
19
+ }
20
+ async function bodyInitToText(body) {
21
+ if (body == null) {
22
+ return { bodyText: "", supported: true };
23
+ }
24
+ if (typeof body === "string") {
25
+ return { bodyText: body, supported: true };
26
+ }
27
+ if (body instanceof URLSearchParams) {
28
+ return { bodyText: body.toString(), supported: true };
29
+ }
30
+ if (body instanceof Blob) {
31
+ return { bodyText: await body.text(), supported: true };
32
+ }
33
+ if (body instanceof Uint8Array) {
34
+ return { bodyText: new TextDecoder().decode(body), supported: true };
35
+ }
36
+ if (body instanceof ArrayBuffer) {
37
+ return { bodyText: new TextDecoder().decode(new Uint8Array(body)), supported: true };
38
+ }
39
+ if (ArrayBuffer.isView(body)) {
40
+ return { bodyText: new TextDecoder().decode(new Uint8Array(body.buffer)), supported: true };
41
+ }
42
+ return { bodyText: UNSUPPORTED_REQUEST_BODY, supported: false };
43
+ }
44
+ function parseBody(text) {
45
+ if (!text) {
46
+ return "";
47
+ }
48
+ try {
49
+ return JSON.parse(text);
50
+ }
51
+ catch {
52
+ return text;
53
+ }
54
+ }
55
+ export async function buildRequestEnvelope(input, init) {
56
+ if (input instanceof Request) {
57
+ const mergedHeaders = mergeHeaders(input.headers, init?.headers);
58
+ const bodyFromInit = init?.body != null ? await bodyInitToText(init.body) : null;
59
+ const text = bodyFromInit ? bodyFromInit.bodyText : await input.clone().text();
60
+ return {
61
+ url: input.url,
62
+ body: parseBody(text),
63
+ headers: headersToObject(mergedHeaders),
64
+ method: (init?.method ?? input.method ?? "GET").toUpperCase(),
65
+ bodySupported: bodyFromInit ? bodyFromInit.supported : true,
66
+ };
67
+ }
68
+ const url = String(input);
69
+ const headers = headersToObject(new Headers(init?.headers));
70
+ const { bodyText, supported } = await bodyInitToText(init?.body);
71
+ return {
72
+ url,
73
+ body: parseBody(bodyText),
74
+ headers,
75
+ method: (init?.method ?? "GET").toUpperCase(),
76
+ bodySupported: supported,
77
+ };
78
+ }
79
+ //# sourceMappingURL=requestEnvelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestEnvelope.js","sourceRoot":"","sources":["../../src/capture/requestEnvelope.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,wBAAwB,GAAG,eAAe,CAAC;AAExD,SAAS,eAAe,CAAC,OAAgB;IACvC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7C,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;IACjC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CAAC,IAAa,EAAE,QAAsB;IACzD,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,KAAK,MAAM,CAAC,GAAG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S,CAAC,CAAC,CAAC,IAAI;SAC5D,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjE,OAAO;QACL,GAAG;QACH,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC;QACzB,OAAO;QACP,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE;QAC7C,aAAa,EAAE,SAAS;KACzB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export type ResponseEnvelope = {
2
+ status_code: number;
3
+ reason_phrase: string;
4
+ request_url: string | null;
5
+ headers: Record<string, string>;
6
+ content: unknown;
7
+ _response_format?: "sse";
8
+ sse?: {
9
+ events: Array<Record<string, unknown>>;
10
+ };
11
+ _encoding?: string;
12
+ };
13
+ export declare function buildResponseEnvelope(response: Response): Promise<ResponseEnvelope>;
14
+ //# sourceMappingURL=responseEnvelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responseEnvelope.d.ts","sourceRoot":"","sources":["../../src/capture/responseEnvelope.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,KAAK,CAAC;IACzB,GAAG,CAAC,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;KAAE,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAkBF,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA6BzF"}