@nyte-ai/plugin 0.0.0-stage → 0.0.18

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 (134) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD-PARTY-NOTICES.md +800 -0
  3. package/dist/chunks/billing-0y7dfkp2.js +146 -0
  4. package/dist/chunks/billing-2v3g7rd9.js +190 -0
  5. package/dist/chunks/billing-3j77ss7y.js +86 -0
  6. package/dist/chunks/billing-3scqmkzb.js +559 -0
  7. package/dist/chunks/billing-6z2kgtyt.js +51 -0
  8. package/dist/chunks/billing-8rjk35gr.js +444 -0
  9. package/dist/chunks/billing-9mfedmsh.js +373 -0
  10. package/dist/chunks/billing-9nn3yp18.js +176 -0
  11. package/dist/chunks/billing-9qc0eqh4.js +174 -0
  12. package/dist/chunks/billing-a9vqn66p.js +351 -0
  13. package/dist/chunks/billing-bv5zr32b.js +369 -0
  14. package/dist/chunks/billing-cy1rg619.js +302 -0
  15. package/dist/chunks/billing-ejx2hv52.js +323 -0
  16. package/dist/chunks/billing-h13r0byk.js +80 -0
  17. package/dist/chunks/billing-j643d12p.js +197 -0
  18. package/dist/chunks/billing-k2p1t25n.js +109 -0
  19. package/dist/chunks/billing-kn3d30b4.js +276 -0
  20. package/dist/chunks/billing-mvc33pv6.js +36 -0
  21. package/dist/chunks/billing-s4rrspsk.js +7 -0
  22. package/dist/chunks/billing-svrhh5a5.js +307 -0
  23. package/dist/chunks/billing-sxc70w72.js +161 -0
  24. package/dist/chunks/billing-t1qrxe16.js +41 -0
  25. package/dist/chunks/billing-tzr3cebf.js +20 -0
  26. package/dist/chunks/billing-wmcbg6fw.js +52 -0
  27. package/dist/chunks/billing-wmkxkypm.js +527 -0
  28. package/dist/chunks/billing-ye3wk5r3.js +205 -0
  29. package/dist/chunks/billing-zfpm2rt0.js +29 -0
  30. package/dist/examples/claude-code/LICENSE +21 -0
  31. package/dist/examples/claude-code/billing.d.ts +7 -0
  32. package/dist/examples/claude-code/billing.js +11 -0
  33. package/dist/examples/claude-code/claude-cli.d.ts +35 -0
  34. package/dist/examples/claude-code/claude-cli.js +15 -0
  35. package/dist/examples/claude-code/env.d.ts +1 -0
  36. package/dist/examples/claude-code/env.js +6 -0
  37. package/dist/examples/claude-code/index.d.ts +24 -0
  38. package/dist/examples/claude-code/index.js +149 -0
  39. package/dist/examples/claude-code/inert-mcp.d.ts +1 -0
  40. package/dist/examples/claude-code/inert-mcp.js +6 -0
  41. package/dist/examples/claude-code/model-catalog.d.ts +27 -0
  42. package/dist/examples/claude-code/model-catalog.js +12 -0
  43. package/dist/examples/claude-code/process.d.ts +22 -0
  44. package/dist/examples/claude-code/process.js +25 -0
  45. package/dist/examples/claude-code/replay.d.ts +4 -0
  46. package/dist/examples/claude-code/replay.js +11 -0
  47. package/dist/examples/claude-code/stream.d.ts +3 -0
  48. package/dist/examples/claude-code/stream.js +16 -0
  49. package/dist/examples/claude-code/transcript.d.ts +83 -0
  50. package/dist/examples/claude-code/transcript.js +23 -0
  51. package/dist/examples/claude-code/turn-relay.d.ts +48 -0
  52. package/dist/examples/claude-code/turn-relay.js +9 -0
  53. package/dist/examples/claude-code/wire.d.ts +372 -0
  54. package/dist/examples/claude-code/wire.js +18 -0
  55. package/dist/src/acp/connection.d.ts +24 -0
  56. package/dist/src/acp/connection.js +8 -0
  57. package/dist/src/acp/index.d.ts +54 -0
  58. package/dist/src/acp/index.js +1004 -0
  59. package/dist/src/acp/registry.d.ts +18 -0
  60. package/dist/src/acp/registry.js +8 -0
  61. package/dist/src/acp/thread.d.ts +46 -0
  62. package/dist/src/acp/thread.js +7 -0
  63. package/dist/src/acp/transcript.d.ts +8 -0
  64. package/dist/src/acp/transcript.js +11 -0
  65. package/dist/src/acp/translate.d.ts +33 -0
  66. package/dist/src/acp/translate.js +20 -0
  67. package/dist/src/approvals/approvals.d.ts +189 -0
  68. package/dist/src/approvals/approvals.js +143 -0
  69. package/dist/src/approvals/schema.d.ts +169 -0
  70. package/dist/src/approvals/schema.js +18 -0
  71. package/dist/src/bash-description.d.ts +30 -0
  72. package/dist/src/bash-description.js +18 -0
  73. package/dist/src/browser-tools.d.ts +25 -0
  74. package/dist/src/browser-tools.js +246 -0
  75. package/dist/src/canvas/canvas-compile.d.ts +48 -0
  76. package/dist/src/canvas/canvas-compile.js +8 -0
  77. package/dist/src/canvas/canvas-libraries.d.ts +32 -0
  78. package/dist/src/canvas/canvas-libraries.js +6 -0
  79. package/dist/src/canvas/canvas-preview.d.ts +107 -0
  80. package/dist/src/canvas/canvas-preview.js +12 -0
  81. package/dist/src/canvas/canvas-protocol.d.ts +184 -0
  82. package/dist/src/canvas/canvas-protocol.js +75 -0
  83. package/dist/src/canvas/canvas.d.ts +50 -0
  84. package/dist/src/canvas/canvas.js +221 -0
  85. package/dist/src/canvas/schema.d.ts +47 -0
  86. package/dist/src/canvas/schema.js +8 -0
  87. package/dist/src/claude-code-sdk/index.d.ts +35 -0
  88. package/dist/src/claude-code-sdk/index.js +368 -0
  89. package/dist/src/claude-code-sdk/session.d.ts +48 -0
  90. package/dist/src/claude-code-sdk/session.js +7 -0
  91. package/dist/src/claude-code-sdk/transcript.d.ts +19 -0
  92. package/dist/src/claude-code-sdk/transcript.js +15 -0
  93. package/dist/src/claude-code-sdk/translate.d.ts +18 -0
  94. package/dist/src/claude-code-sdk/translate.js +20 -0
  95. package/dist/src/client/mount.d.ts +44 -0
  96. package/dist/src/client/mount.js +252 -0
  97. package/dist/src/client/notifications.d.ts +35 -0
  98. package/dist/src/client/notifications.js +26 -0
  99. package/dist/src/client/presentation.d.ts +336 -0
  100. package/dist/src/client/presentation.js +373 -0
  101. package/dist/src/client/transcript-tui.d.ts +23 -0
  102. package/dist/src/client/transcript-tui.js +20 -0
  103. package/dist/src/client/transcript.d.ts +23 -0
  104. package/dist/src/client/transcript.js +51 -0
  105. package/dist/src/client.d.ts +53 -0
  106. package/dist/src/client.js +22 -0
  107. package/dist/src/codemode-runtime.d.ts +11 -0
  108. package/dist/src/codemode-runtime.js +10 -0
  109. package/dist/src/codemode-worker.d.ts +1 -0
  110. package/dist/src/codemode-worker.js +2 -0
  111. package/dist/src/codemode.d.ts +21 -0
  112. package/dist/src/codemode.js +170 -0
  113. package/dist/src/core.d.ts +43 -0
  114. package/dist/src/core.js +11 -0
  115. package/dist/src/openai-astra-context.d.ts +23 -0
  116. package/dist/src/openai-astra-context.js +14 -0
  117. package/dist/src/openai-compaction.d.ts +15 -0
  118. package/dist/src/openai-compaction.js +55 -0
  119. package/dist/src/question/client/questions-tui.d.ts +9 -0
  120. package/dist/src/question/client/questions-tui.js +19 -0
  121. package/dist/src/question/client/questions.d.ts +9 -0
  122. package/dist/src/question/client/questions.js +160 -0
  123. package/dist/src/question/question.d.ts +63 -0
  124. package/dist/src/question/question.js +9 -0
  125. package/dist/src/question/schema.d.ts +101 -0
  126. package/dist/src/question/schema.js +14 -0
  127. package/dist/src/rename.d.ts +78 -0
  128. package/dist/src/rename.js +78 -0
  129. package/dist/src/telemetry.d.ts +36 -0
  130. package/dist/src/telemetry.js +84 -0
  131. package/dist/src/web-search.d.ts +78 -0
  132. package/dist/src/web-search.js +219 -0
  133. package/package.json +190 -3
  134. package/README.md +0 -3
@@ -0,0 +1,373 @@
1
+ import {
2
+ AcpThread2
3
+ } from "./billing-svrhh5a5.js";
4
+
5
+ // src/acp/connection.ts
6
+ import { randomUUID } from "node:crypto";
7
+ import {
8
+ client,
9
+ methods,
10
+ ndJsonStream,
11
+ PROTOCOL_VERSION,
12
+ RequestError
13
+ } from "@agentclientprotocol/sdk";
14
+ import { processEnvironment } from "@nyte-ai/core";
15
+ // package.json
16
+ var package_default = {
17
+ name: "@nyte-ai/plugin",
18
+ version: "0.0.18",
19
+ private: false,
20
+ license: "MIT",
21
+ repository: {
22
+ type: "git",
23
+ url: "git+https://github.com/interfaces-lab/nyte.git",
24
+ directory: "packages/plugin"
25
+ },
26
+ files: [
27
+ "dist",
28
+ "LICENSE",
29
+ "THIRD-PARTY-NOTICES.md"
30
+ ],
31
+ type: "module",
32
+ exports: {
33
+ "./core": "./src/core.ts",
34
+ "./core/approvals": "./src/approvals/approvals.ts",
35
+ "./core/acp": "./src/acp/index.ts",
36
+ "./core/bash-description": "./src/bash-description.ts",
37
+ "./core/browser-tools": "./src/browser-tools.ts",
38
+ "./core/canvas": "./src/canvas/canvas.ts",
39
+ "./core/canvas-compile": "./src/canvas/canvas-compile.ts",
40
+ "./core/canvas-preview": "./src/canvas/canvas-preview.ts",
41
+ "./core/claude-code": "./examples/claude-code/index.ts",
42
+ "./core/claude-code-sdk": "./src/claude-code-sdk/index.ts",
43
+ "./core/codemode": "./src/codemode.ts",
44
+ "./core/codemode-runtime": "./src/codemode-runtime.ts",
45
+ "./core/codemode-worker": "./src/codemode-worker.ts",
46
+ "./core/openai-astra-context": "./src/openai-astra-context.ts",
47
+ "./core/openai-compaction": "./src/openai-compaction.ts",
48
+ "./core/question": "./src/question/question.ts",
49
+ "./core/rename": "./src/rename.ts",
50
+ "./core/telemetry": "./src/telemetry.ts",
51
+ "./core/web-search": "./src/web-search.ts",
52
+ "./client": "./src/client.ts",
53
+ "./client/mount": "./src/client/mount.ts",
54
+ "./client/notifications": "./src/client/notifications.ts",
55
+ "./client/presentation": "./src/client/presentation.ts",
56
+ "./client/questions": "./src/question/client/questions.tsx",
57
+ "./client/questions-tui": "./src/question/client/questions-tui.ts",
58
+ "./client/transcript": "./src/client/transcript.tsx",
59
+ "./client/transcript-tui": "./src/client/transcript-tui.ts",
60
+ "./approvals/schema": "./src/approvals/schema.ts",
61
+ "./canvas/protocol": "./src/canvas/canvas-protocol.ts",
62
+ "./canvas/schema": "./src/canvas/schema.ts",
63
+ "./question/schema": "./src/question/schema.ts"
64
+ },
65
+ publishConfig: {
66
+ exports: {
67
+ "./core": {
68
+ types: "./dist/src/core.d.ts",
69
+ import: "./dist/src/core.js"
70
+ },
71
+ "./core/approvals": {
72
+ types: "./dist/src/approvals/approvals.d.ts",
73
+ import: "./dist/src/approvals/approvals.js"
74
+ },
75
+ "./core/acp": {
76
+ types: "./dist/src/acp/index.d.ts",
77
+ import: "./dist/src/acp/index.js"
78
+ },
79
+ "./core/bash-description": {
80
+ types: "./dist/src/bash-description.d.ts",
81
+ import: "./dist/src/bash-description.js"
82
+ },
83
+ "./core/browser-tools": {
84
+ types: "./dist/src/browser-tools.d.ts",
85
+ import: "./dist/src/browser-tools.js"
86
+ },
87
+ "./core/canvas": {
88
+ types: "./dist/src/canvas/canvas.d.ts",
89
+ import: "./dist/src/canvas/canvas.js"
90
+ },
91
+ "./core/canvas-compile": {
92
+ types: "./dist/src/canvas/canvas-compile.d.ts",
93
+ import: "./dist/src/canvas/canvas-compile.js"
94
+ },
95
+ "./core/canvas-preview": {
96
+ types: "./dist/src/canvas/canvas-preview.d.ts",
97
+ import: "./dist/src/canvas/canvas-preview.js"
98
+ },
99
+ "./core/claude-code": {
100
+ types: "./dist/examples/claude-code/index.d.ts",
101
+ import: "./dist/examples/claude-code/index.js"
102
+ },
103
+ "./core/claude-code-sdk": {
104
+ types: "./dist/src/claude-code-sdk/index.d.ts",
105
+ import: "./dist/src/claude-code-sdk/index.js"
106
+ },
107
+ "./core/codemode": {
108
+ types: "./dist/src/codemode.d.ts",
109
+ import: "./dist/src/codemode.js"
110
+ },
111
+ "./core/codemode-runtime": {
112
+ types: "./dist/src/codemode-runtime.d.ts",
113
+ import: "./dist/src/codemode-runtime.js"
114
+ },
115
+ "./core/codemode-worker": {
116
+ types: "./dist/src/codemode-worker.d.ts",
117
+ import: "./dist/src/codemode-worker.js"
118
+ },
119
+ "./core/openai-astra-context": {
120
+ types: "./dist/src/openai-astra-context.d.ts",
121
+ import: "./dist/src/openai-astra-context.js"
122
+ },
123
+ "./core/openai-compaction": {
124
+ types: "./dist/src/openai-compaction.d.ts",
125
+ import: "./dist/src/openai-compaction.js"
126
+ },
127
+ "./core/question": {
128
+ types: "./dist/src/question/question.d.ts",
129
+ import: "./dist/src/question/question.js"
130
+ },
131
+ "./core/rename": {
132
+ types: "./dist/src/rename.d.ts",
133
+ import: "./dist/src/rename.js"
134
+ },
135
+ "./core/telemetry": {
136
+ types: "./dist/src/telemetry.d.ts",
137
+ import: "./dist/src/telemetry.js"
138
+ },
139
+ "./core/web-search": {
140
+ types: "./dist/src/web-search.d.ts",
141
+ import: "./dist/src/web-search.js"
142
+ },
143
+ "./client": {
144
+ types: "./dist/src/client.d.ts",
145
+ import: "./dist/src/client.js"
146
+ },
147
+ "./client/mount": {
148
+ types: "./dist/src/client/mount.d.ts",
149
+ import: "./dist/src/client/mount.js"
150
+ },
151
+ "./client/notifications": {
152
+ types: "./dist/src/client/notifications.d.ts",
153
+ import: "./dist/src/client/notifications.js"
154
+ },
155
+ "./client/presentation": {
156
+ types: "./dist/src/client/presentation.d.ts",
157
+ import: "./dist/src/client/presentation.js"
158
+ },
159
+ "./client/questions": {
160
+ types: "./dist/src/question/client/questions.d.ts",
161
+ import: "./dist/src/question/client/questions.js"
162
+ },
163
+ "./client/questions-tui": {
164
+ types: "./dist/src/question/client/questions-tui.d.ts",
165
+ import: "./dist/src/question/client/questions-tui.js"
166
+ },
167
+ "./client/transcript": {
168
+ types: "./dist/src/client/transcript.d.ts",
169
+ import: "./dist/src/client/transcript.js"
170
+ },
171
+ "./client/transcript-tui": {
172
+ types: "./dist/src/client/transcript-tui.d.ts",
173
+ import: "./dist/src/client/transcript-tui.js"
174
+ },
175
+ "./approvals/schema": {
176
+ types: "./dist/src/approvals/schema.d.ts",
177
+ import: "./dist/src/approvals/schema.js"
178
+ },
179
+ "./canvas/protocol": {
180
+ types: "./dist/src/canvas/canvas-protocol.d.ts",
181
+ import: "./dist/src/canvas/canvas-protocol.js"
182
+ },
183
+ "./canvas/schema": {
184
+ types: "./dist/src/canvas/schema.d.ts",
185
+ import: "./dist/src/canvas/schema.js"
186
+ },
187
+ "./question/schema": {
188
+ types: "./dist/src/question/schema.d.ts",
189
+ import: "./dist/src/question/schema.js"
190
+ }
191
+ },
192
+ access: "public",
193
+ provenance: true
194
+ },
195
+ scripts: {
196
+ clean: "rm -rf node_modules .turbo",
197
+ test: "vitest --run",
198
+ typecheck: "tsgo --noEmit",
199
+ "build:package": "bun ../../scripts/sdk-packages.mjs build plugin"
200
+ },
201
+ dependencies: {
202
+ "@agentclientprotocol/sdk": "1.9.0",
203
+ "@anthropic-ai/claude-agent-sdk": "0.3.296",
204
+ "@earendil-works/pi-codemode": "1.0.0",
205
+ "@nyte-ai/ai": "workspace:*",
206
+ "@nyte-ai/core": "workspace:*",
207
+ "@nyte-ai/schema": "workspace:*",
208
+ "@opentelemetry/api": "^1.9.1",
209
+ "@opentelemetry/exporter-trace-otlp-http": "^0.223.0",
210
+ "@opentelemetry/resources": "^2.12.0",
211
+ "@opentelemetry/sdk-trace": "^2.12.0",
212
+ "@opentelemetry/semantic-conventions": "^1.43.0",
213
+ "es-module-lexer": "2.3.2",
214
+ sucrase: "3.35.1",
215
+ typebox: "1.3.36",
216
+ zod: "4.5.4"
217
+ },
218
+ devDependencies: {
219
+ "@opentui/core": "^0.6.6",
220
+ "@types/node": "^26.6.5",
221
+ "@types/react": "19.3.0",
222
+ react: "19.3.0",
223
+ typescript: "6.0.3",
224
+ vitest: "^5.0.5"
225
+ },
226
+ peerDependencies: {
227
+ "@opentui/core": "^0.6.5",
228
+ react: "^19.2.0"
229
+ },
230
+ peerDependenciesMeta: {
231
+ "@opentui/core": {
232
+ optional: true
233
+ },
234
+ react: {
235
+ optional: true
236
+ }
237
+ },
238
+ engines: {
239
+ node: ">=26.4.0"
240
+ }
241
+ };
242
+
243
+ // src/acp/connection.ts
244
+ var AUTH_REQUIRED = -32000;
245
+ var STDERR_TAIL = 4096;
246
+ function protocolStream(job, stderr) {
247
+ return new ReadableStream({
248
+ async start(controller) {
249
+ for await (const frame of job.output()) {
250
+ if (frame.kind === "gap") {
251
+ controller.error(new Error("The agent's output lost bytes, so its protocol stream broke."));
252
+ return;
253
+ }
254
+ if (frame.kind !== "bytes")
255
+ continue;
256
+ if (frame.stream === "stderr")
257
+ stderr(frame.data);
258
+ else
259
+ controller.enqueue(frame.data);
260
+ }
261
+ controller.close();
262
+ }
263
+ });
264
+ }
265
+
266
+ class AcpProcess2 {
267
+ agent;
268
+ #job;
269
+ #connection;
270
+ #threads = new Map;
271
+ #ready;
272
+ #stderr = "";
273
+ #failure;
274
+ constructor(agent, job) {
275
+ this.agent = agent;
276
+ this.#job = job;
277
+ const app = client({ name: "nyte" }).onNotification(methods.client.session.update, (context) => this.#threads.get(context.params.sessionId)?.update(context.params.update)).onRequest(methods.client.session.requestPermission, async (context) => await this.#threads.get(context.params.sessionId)?.permission(context.params) ?? {
278
+ outcome: { outcome: "cancelled" }
279
+ });
280
+ const writable = new WritableStream({ write: (chunk) => job.write(chunk) });
281
+ const decoder = new TextDecoder;
282
+ const readable = protocolStream(job, (bytes) => {
283
+ this.#stderr = (this.#stderr + decoder.decode(bytes, { stream: true })).slice(-STDERR_TAIL);
284
+ });
285
+ this.#connection = app.connect(ndJsonStream(writable, readable));
286
+ this.#connection.closed.then(() => this.close(new Error(`${agent.name} exited.${this.#detail()}`)));
287
+ this.#ready = this.#connection.agent.request(methods.agent.initialize, {
288
+ protocolVersion: PROTOCOL_VERSION,
289
+ clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
290
+ clientInfo: { name: "nyte", title: "Nyte", version: package_default.version }
291
+ });
292
+ this.#ready.catch(() => {
293
+ return;
294
+ });
295
+ }
296
+ static async start(env, agent) {
297
+ await processEnvironment();
298
+ const job = await env.exec([agent.command, ...agent.args], {
299
+ env: { ...agent.env },
300
+ stdio: "protocol"
301
+ });
302
+ return new AcpProcess2(agent, job);
303
+ }
304
+ get closed() {
305
+ return this.#failure !== undefined;
306
+ }
307
+ async images() {
308
+ return (await this.#initialized()).agentCapabilities?.promptCapabilities?.image === true;
309
+ }
310
+ async open(cwd, approve) {
311
+ await this.#initialized();
312
+ let sessionId;
313
+ try {
314
+ ({ sessionId } = await this.#connection.agent.request(methods.agent.session.new, {
315
+ cwd,
316
+ mcpServers: []
317
+ }));
318
+ } catch (error) {
319
+ if (error instanceof RequestError && error.code === AUTH_REQUIRED)
320
+ throw new Error(`Sign in to ${this.agent.name} in a terminal, then send again.`, {
321
+ cause: error
322
+ });
323
+ throw error;
324
+ }
325
+ const thread = new AcpThread2(`acp-${randomUUID().slice(0, 8)}-`, {
326
+ cwd,
327
+ approve,
328
+ prompt: (blocks) => this.#connection.agent.request(methods.agent.session.prompt, {
329
+ sessionId,
330
+ prompt: [...blocks]
331
+ }),
332
+ cancel: () => void this.#connection.agent.notify(methods.agent.session.cancel, { sessionId }).catch(() => {
333
+ return;
334
+ })
335
+ });
336
+ this.#threads.set(sessionId, thread);
337
+ return thread;
338
+ }
339
+ forget(thread) {
340
+ for (const [id, known] of this.#threads)
341
+ if (known === thread) {
342
+ this.#threads.delete(id);
343
+ thread.close();
344
+ }
345
+ }
346
+ close(reason = new Error(`${this.agent.name} closed.`)) {
347
+ if (this.#failure !== undefined)
348
+ return;
349
+ this.#failure = reason;
350
+ for (const thread of this.#threads.values())
351
+ thread.close(reason);
352
+ this.#threads.clear();
353
+ this.#connection.close();
354
+ this.#job.stop().catch(() => {
355
+ return;
356
+ });
357
+ }
358
+ async#initialized() {
359
+ if (this.#failure !== undefined)
360
+ throw this.#failure;
361
+ try {
362
+ return await this.#ready;
363
+ } catch (error) {
364
+ throw this.#failure ?? error;
365
+ }
366
+ }
367
+ #detail() {
368
+ const tail = this.#stderr.trim().slice(-500);
369
+ return tail === "" ? "" : ` (${tail})`;
370
+ }
371
+ }
372
+
373
+ export { AcpProcess2 };
@@ -0,0 +1,176 @@
1
+ // src/acp/translate.ts
2
+ import { calculateCost } from "@nyte-ai/ai";
3
+ import { Type } from "typebox";
4
+ import { Value } from "typebox/value";
5
+ var ACP_PROVIDER2 = "acp";
6
+ var ACP_API2 = "acp";
7
+ var MIRROR_TOOL2 = "acp";
8
+ var mirrorArguments2 = Type.Object({
9
+ thread: Type.String(),
10
+ id: Type.String(),
11
+ title: Type.String(),
12
+ kind: Type.String(),
13
+ input: Type.Record(Type.String(), Type.Unknown()),
14
+ paths: Type.Array(Type.String())
15
+ });
16
+ var command = Type.Union([
17
+ Type.String({ minLength: 1 }),
18
+ Type.Array(Type.String(), { minItems: 1 })
19
+ ]);
20
+ function emptyMessage2(model) {
21
+ return {
22
+ role: "assistant",
23
+ content: [],
24
+ api: model.api,
25
+ provider: model.provider,
26
+ model: model.id,
27
+ usage: {
28
+ input: 0,
29
+ output: 0,
30
+ cacheRead: 0,
31
+ cacheWrite: 0,
32
+ totalTokens: 0,
33
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
34
+ },
35
+ stopReason: "pending",
36
+ timestamp: Date.now()
37
+ };
38
+ }
39
+ function mirrorClass2(args) {
40
+ const path = args.paths[0];
41
+ const shell = args.input.command;
42
+ switch (args.kind) {
43
+ case "read":
44
+ return path === undefined ? { kind: "custom", label: args.title } : { kind: "read", path };
45
+ case "edit":
46
+ case "delete":
47
+ case "move":
48
+ return path === undefined ? { kind: "custom", label: args.title } : { kind: "edit", path };
49
+ case "execute":
50
+ return {
51
+ kind: "shell",
52
+ command: Value.Check(command, shell) ? Array.isArray(shell) ? shell.join(" ") : shell : args.title
53
+ };
54
+ default:
55
+ return { kind: "custom", label: args.title };
56
+ }
57
+ }
58
+ function blockText(block) {
59
+ switch (block.type) {
60
+ case "text":
61
+ return block.text;
62
+ case "resource_link":
63
+ return block.uri;
64
+ case "resource":
65
+ return "text" in block.resource ? block.resource.text : block.resource.uri;
66
+ default:
67
+ return `[${block.type}]`;
68
+ }
69
+ }
70
+ function toolText2(content, rawOutput) {
71
+ const lines = content.map((item) => {
72
+ switch (item.type) {
73
+ case "content":
74
+ return blockText(item.content);
75
+ case "diff":
76
+ return item.oldText === null || item.oldText === undefined ? `Wrote ${item.path}` : `Edited ${item.path}`;
77
+ default:
78
+ return `Terminal ${item.terminalId}`;
79
+ }
80
+ });
81
+ if (lines.length > 0)
82
+ return lines.join(`
83
+ `);
84
+ if (rawOutput === undefined || rawOutput === null)
85
+ return "";
86
+ return (Value.Check(Type.String(), rawOutput) ? rawOutput : JSON.stringify(rawOutput)).slice(0, 8000);
87
+ }
88
+
89
+ class Translator2 {
90
+ #model;
91
+ #output;
92
+ #stream;
93
+ #open;
94
+ constructor(model, output, stream) {
95
+ this.#model = model;
96
+ this.#output = output;
97
+ this.#stream = stream;
98
+ }
99
+ text(delta) {
100
+ const index = this.#start("text");
101
+ const block = this.#output.content[index];
102
+ if (block?.type !== "text")
103
+ return;
104
+ block.text += delta;
105
+ this.#stream.push({ type: "text_delta", contentIndex: index, delta, partial: this.#output });
106
+ }
107
+ thinking(delta) {
108
+ const index = this.#start("thinking");
109
+ const block = this.#output.content[index];
110
+ if (block?.type !== "thinking")
111
+ return;
112
+ block.thinking += delta;
113
+ this.#stream.push({
114
+ type: "thinking_delta",
115
+ contentIndex: index,
116
+ delta,
117
+ partial: this.#output
118
+ });
119
+ }
120
+ call(call) {
121
+ this.end();
122
+ const contentIndex = this.#output.content.push(call) - 1;
123
+ this.#stream.push({ type: "toolcall_start", contentIndex, partial: this.#output });
124
+ this.#stream.push({
125
+ type: "toolcall_end",
126
+ contentIndex,
127
+ toolCall: call,
128
+ partial: this.#output
129
+ });
130
+ }
131
+ usage(usage) {
132
+ const target = this.#output.usage;
133
+ target.input = usage.inputTokens;
134
+ target.output = usage.outputTokens;
135
+ target.cacheRead = usage.cachedReadTokens ?? 0;
136
+ target.cacheWrite = usage.cachedWriteTokens ?? 0;
137
+ target.totalTokens = usage.totalTokens;
138
+ calculateCost(this.#model, target);
139
+ }
140
+ end() {
141
+ const open = this.#open;
142
+ this.#open = undefined;
143
+ if (open === undefined)
144
+ return;
145
+ const block = this.#output.content[open.index];
146
+ if (block?.type === "text")
147
+ this.#stream.push({
148
+ type: "text_end",
149
+ contentIndex: open.index,
150
+ content: block.text,
151
+ partial: this.#output
152
+ });
153
+ else if (block?.type === "thinking")
154
+ this.#stream.push({
155
+ type: "thinking_end",
156
+ contentIndex: open.index,
157
+ content: block.thinking,
158
+ partial: this.#output
159
+ });
160
+ }
161
+ #start(kind) {
162
+ if (this.#open?.kind === kind)
163
+ return this.#open.index;
164
+ this.end();
165
+ const index = this.#output.content.push(kind === "text" ? { type: "text", text: "" } : { type: "thinking", thinking: "" }) - 1;
166
+ this.#open = { kind, index };
167
+ this.#stream.push({
168
+ type: kind === "text" ? "text_start" : "thinking_start",
169
+ contentIndex: index,
170
+ partial: this.#output
171
+ });
172
+ return index;
173
+ }
174
+ }
175
+
176
+ export { ACP_PROVIDER2, ACP_API2, MIRROR_TOOL2, mirrorArguments2, emptyMessage2, mirrorClass2, toolText2, Translator2 };