@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,307 @@
1
+ import {
2
+ MIRROR_TOOL2,
3
+ emptyMessage2,
4
+ mirrorClass2,
5
+ toolText2,
6
+ Translator2
7
+ } from "./billing-9nn3yp18.js";
8
+
9
+ // src/acp/thread.ts
10
+ import { posix } from "node:path";
11
+ import { createAssistantMessageEventStream } from "@nyte-ai/ai";
12
+ import { Type } from "typebox";
13
+ import { Value } from "typebox/value";
14
+ class Inbox {
15
+ #items = [];
16
+ #waiter;
17
+ #ended = false;
18
+ push(item) {
19
+ this.#items.push(item);
20
+ this.#wake();
21
+ }
22
+ end() {
23
+ this.#ended = true;
24
+ this.#wake();
25
+ }
26
+ async next() {
27
+ while (this.#items.length === 0 && !this.#ended)
28
+ await new Promise((resolve) => this.#waiter = resolve);
29
+ return this.#items.shift();
30
+ }
31
+ #wake() {
32
+ const waiter = this.#waiter;
33
+ this.#waiter = undefined;
34
+ waiter?.();
35
+ }
36
+ }
37
+ var input = Type.Record(Type.String(), Type.Unknown());
38
+ function answer(choice, options) {
39
+ const kinds = choice === "allow" ? ["allow_once"] : choice === "reject" ? ["reject_once", "reject_always"] : [];
40
+ const option = kinds.flatMap((kind) => options.filter((entry) => entry.kind === kind))[0];
41
+ return option === undefined ? { outcome: { outcome: "cancelled" } } : { outcome: { outcome: "selected", optionId: option.optionId } };
42
+ }
43
+ function guardedFirst(cwd, paths) {
44
+ const root = posix.resolve(cwd);
45
+ const inside = (path) => {
46
+ const target = posix.resolve(root, path);
47
+ return target === root || target.startsWith(`${root}/`);
48
+ };
49
+ return [...paths.filter((path) => !inside(path)), ...paths.filter(inside)];
50
+ }
51
+ function stopReason(response) {
52
+ switch (response.stopReason) {
53
+ case "max_tokens":
54
+ case "max_turn_requests":
55
+ return "length";
56
+ case "refusal":
57
+ return "error";
58
+ case "cancelled":
59
+ return "aborted";
60
+ default:
61
+ return "stop";
62
+ }
63
+ }
64
+
65
+ class AcpThread2 {
66
+ prefix;
67
+ #channel;
68
+ #events = new Inbox;
69
+ #tools = new Map;
70
+ #permissions = new Map;
71
+ #recordings = new Map;
72
+ #changes = new Set;
73
+ #queue = [];
74
+ #running = false;
75
+ #failure;
76
+ constructor(prefix, channel) {
77
+ this.prefix = prefix;
78
+ this.#channel = channel;
79
+ }
80
+ get closed() {
81
+ return this.#failure !== undefined;
82
+ }
83
+ send(blocks) {
84
+ if (this.#running)
85
+ this.#queue.push(blocks);
86
+ else
87
+ this.#start(blocks);
88
+ }
89
+ update(update) {
90
+ switch (update.sessionUpdate) {
91
+ case "agent_message_chunk":
92
+ if (update.content.type === "text")
93
+ this.#events.push({ kind: "text", text: update.content.text });
94
+ break;
95
+ case "agent_thought_chunk":
96
+ if (update.content.type === "text")
97
+ this.#events.push({ kind: "thinking", text: update.content.text });
98
+ break;
99
+ case "tool_call":
100
+ case "tool_call_update":
101
+ this.#see(update);
102
+ break;
103
+ default:
104
+ break;
105
+ }
106
+ this.#changed();
107
+ }
108
+ async permission(request) {
109
+ const id = request.toolCall.toolCallId;
110
+ this.#see(request.toolCall);
111
+ if (this.#failure !== undefined)
112
+ return answer("cancelled", request.options);
113
+ const asking = new AbortController;
114
+ this.#permissions.set(id, asking);
115
+ this.#changed();
116
+ try {
117
+ const recorded = await Promise.race([
118
+ this.#recording(id).promise,
119
+ new Promise((resolve) => asking.signal.addEventListener("abort", () => resolve("cancelled"), { once: true }))
120
+ ]);
121
+ if (recorded !== "recording")
122
+ return answer(recorded === "skipped" ? "reject" : "cancelled", request.options);
123
+ const args = this.#arguments(id);
124
+ const name = args.kind === "other" ? args.title : args.kind;
125
+ const verdict = await this.#channel.approve({ name, class: mirrorClass2(args) }, asking.signal);
126
+ if (asking.signal.aborted)
127
+ return answer("cancelled", request.options);
128
+ return answer(verdict.kind === "allow" ? "allow" : "reject", request.options);
129
+ } finally {
130
+ this.#permissions.delete(id);
131
+ this.#changed();
132
+ }
133
+ }
134
+ recording(id) {
135
+ this.#recording(id).resolve("recording");
136
+ }
137
+ skip(id) {
138
+ if (this.#tools.has(id))
139
+ this.#recording(id).resolve("skipped");
140
+ }
141
+ respond(model, signal, tools = true) {
142
+ const stream = createAssistantMessageEventStream();
143
+ const output = emptyMessage2(model);
144
+ const translator = new Translator2(model, output, stream);
145
+ const abort = () => {
146
+ this.cancel();
147
+ this.#events.push({ kind: "aborted" });
148
+ };
149
+ signal?.addEventListener("abort", abort, { once: true });
150
+ (async () => {
151
+ try {
152
+ stream.push({ type: "start", partial: output });
153
+ let reason;
154
+ while (reason === undefined) {
155
+ const event = await this.#events.next();
156
+ if (event === undefined)
157
+ throw this.#failure ?? new Error("The agent stopped.");
158
+ if (event.kind === "aborted")
159
+ throw new Error("Request was aborted");
160
+ if (event.kind === "text")
161
+ translator.text(event.text);
162
+ else if (event.kind === "thinking")
163
+ translator.thinking(event.text);
164
+ else if (event.kind === "tool" && !tools)
165
+ this.skip(event.id);
166
+ else if (event.kind === "tool") {
167
+ translator.call(this.#mirror(event.id));
168
+ reason = "toolUse";
169
+ } else {
170
+ translator.end();
171
+ if (event.response.usage !== undefined && event.response.usage !== null)
172
+ translator.usage(event.response.usage);
173
+ output.rawStopReason = event.response.stopReason;
174
+ const mapped = stopReason(event.response);
175
+ if (mapped === "aborted")
176
+ throw new Error("Request was aborted");
177
+ if (mapped === "error")
178
+ throw new Error("The agent refused to complete the request.");
179
+ reason = mapped;
180
+ }
181
+ }
182
+ output.stopReason = reason;
183
+ stream.push({ type: "done", reason, message: output });
184
+ } catch (error) {
185
+ output.stopReason = signal?.aborted === true ? "aborted" : "error";
186
+ output.errorMessage = error instanceof Error ? error.message : String(error);
187
+ stream.push({ type: "error", reason: output.stopReason, error: output });
188
+ } finally {
189
+ signal?.removeEventListener("abort", abort);
190
+ stream.end();
191
+ }
192
+ })();
193
+ return stream;
194
+ }
195
+ async result(id, signal) {
196
+ const settled = () => {
197
+ const status = this.#tools.get(id)?.status;
198
+ return status === "completed" || status === "failed" || !this.#running || [...this.#permissions.keys()].some((other) => other !== id);
199
+ };
200
+ while (!settled() && this.#failure === undefined) {
201
+ if (signal.aborted) {
202
+ this.cancel();
203
+ signal.throwIfAborted();
204
+ }
205
+ await new Promise((resolve) => {
206
+ const done = () => {
207
+ this.#changes.delete(done);
208
+ signal.removeEventListener("abort", done);
209
+ resolve();
210
+ };
211
+ this.#changes.add(done);
212
+ signal.addEventListener("abort", done, { once: true });
213
+ });
214
+ }
215
+ const tool = this.#tools.get(id);
216
+ if (tool === undefined)
217
+ throw this.#failure ?? new Error("The agent did not report this call.");
218
+ return { text: toolText2(tool.content, tool.rawOutput), failed: tool.status === "failed" };
219
+ }
220
+ cancel() {
221
+ this.#queue.length = 0;
222
+ for (const asking of this.#permissions.values())
223
+ asking.abort();
224
+ if (this.#running)
225
+ this.#channel.cancel();
226
+ }
227
+ close(reason = new Error("The agent's session closed.")) {
228
+ if (this.#failure !== undefined)
229
+ return;
230
+ this.cancel();
231
+ this.#failure = reason;
232
+ this.#events.end();
233
+ this.#changed();
234
+ }
235
+ #start(blocks) {
236
+ this.#running = true;
237
+ this.#channel.prompt(blocks).then((response) => {
238
+ const next = response.stopReason === "cancelled" ? undefined : this.#queue.shift();
239
+ if (next !== undefined) {
240
+ this.#start(next);
241
+ return;
242
+ }
243
+ this.#running = false;
244
+ this.#events.push({ kind: "stop", response });
245
+ this.#changed();
246
+ }, (error) => {
247
+ this.#running = false;
248
+ this.close(error instanceof Error ? error : new Error(String(error)));
249
+ });
250
+ }
251
+ #see(update) {
252
+ const known = this.#tools.get(update.toolCallId);
253
+ const tool = known ?? {
254
+ title: "Tool",
255
+ kind: "other",
256
+ status: "pending",
257
+ input: {},
258
+ paths: [],
259
+ content: [],
260
+ rawOutput: undefined
261
+ };
262
+ tool.title = update.title ?? tool.title;
263
+ tool.kind = update.kind ?? tool.kind;
264
+ tool.status = update.status ?? tool.status;
265
+ tool.input = Value.Check(input, update.rawInput) ? update.rawInput : tool.input;
266
+ tool.paths = update.locations?.map((location) => location.path) ?? tool.paths;
267
+ tool.content = update.content ?? tool.content;
268
+ tool.rawOutput = update.rawOutput ?? tool.rawOutput;
269
+ if (known !== undefined)
270
+ return;
271
+ this.#tools.set(update.toolCallId, tool);
272
+ this.#events.push({ kind: "tool", id: update.toolCallId });
273
+ }
274
+ #arguments(id) {
275
+ const tool = this.#tools.get(id);
276
+ return {
277
+ thread: this.prefix,
278
+ id,
279
+ title: tool?.title ?? "Tool",
280
+ kind: tool?.kind ?? "other",
281
+ input: tool?.input ?? {},
282
+ paths: guardedFirst(this.#channel.cwd, tool?.paths ?? [])
283
+ };
284
+ }
285
+ #mirror(id) {
286
+ return {
287
+ type: "toolCall",
288
+ id: `${this.prefix}${id}`,
289
+ name: MIRROR_TOOL2,
290
+ arguments: this.#arguments(id)
291
+ };
292
+ }
293
+ #recording(id) {
294
+ const known = this.#recordings.get(id);
295
+ if (known !== undefined)
296
+ return known;
297
+ const created = Promise.withResolvers();
298
+ this.#recordings.set(id, created);
299
+ return created;
300
+ }
301
+ #changed() {
302
+ for (const change of this.#changes)
303
+ change();
304
+ }
305
+ }
306
+
307
+ export { AcpThread2 };
@@ -0,0 +1,161 @@
1
+ import {
2
+ CANVAS_RUNTIME2,
3
+ CANVAS_MAX_HEIGHT2,
4
+ initializeResult2,
5
+ renderNotification2,
6
+ clampCanvasHeight2
7
+ } from "./billing-bv5zr32b.js";
8
+
9
+ // src/canvas/canvas-preview.ts
10
+ import { Type } from "typebox";
11
+ import { Value } from "typebox/value";
12
+ var CANVAS_PREVIEW_WIDTHS2 = { chat: 808, phone: 358 };
13
+ var WIDTH_NAMES = { chat: "the chat column", phone: "a phone" };
14
+ var SETTLE_TIMEOUT_MS = 8000;
15
+ var SETTLE_QUIET_MS = 400;
16
+ var CONSOLE_KEPT = 40;
17
+ var settled = Type.Object({
18
+ height: Type.Number(),
19
+ errors: Type.Array(Type.Object({
20
+ phase: Type.Union([Type.Literal("load"), Type.Literal("render")]),
21
+ message: Type.String(),
22
+ stack: Type.Optional(Type.String())
23
+ })),
24
+ console: Type.Array(Type.Object({ level: Type.String(), text: Type.String() }))
25
+ });
26
+ function hostContext(theme) {
27
+ return {
28
+ theme,
29
+ styles: { variables: { "--nyte-custom-hue": "250", "--nyte-custom-chroma-scale": "0" } },
30
+ displayMode: "inline",
31
+ platform: "desktop",
32
+ deviceCapabilities: { touch: false, hover: true }
33
+ };
34
+ }
35
+ function installHarness(setup) {
36
+ if ("__nytePreview" in globalThis)
37
+ return true;
38
+ if (!("__nyteCanvas" in globalThis))
39
+ return false;
40
+ const state = {
41
+ height: 0,
42
+ changed: 0,
43
+ errors: new Array,
44
+ console: new Array
45
+ };
46
+ const text = (value) => {
47
+ if (typeof value === "string")
48
+ return value;
49
+ if (value instanceof Error)
50
+ return value.stack ?? String(value);
51
+ try {
52
+ return JSON.stringify(value) ?? String(value);
53
+ } catch {
54
+ return String(value);
55
+ }
56
+ };
57
+ for (const level of ["log", "info", "warn", "error", "debug"]) {
58
+ const original = console[level].bind(console);
59
+ console[level] = (...values) => {
60
+ if (state.console.length < setup.consoleKept)
61
+ state.console.push({ level, text: values.map(text).join(" ").slice(0, 2000) });
62
+ original(...values);
63
+ };
64
+ }
65
+ this.addEventListener("message", (event) => {
66
+ const data = event.data;
67
+ if (typeof data !== "object" || data === null || !("method" in data))
68
+ return;
69
+ const params = "params" in data && typeof data.params === "object" ? data.params : null;
70
+ if (data.method === "ui/notifications/initialized")
71
+ this.postMessage(setup.render, "*");
72
+ if (data.method === "ui/notifications/size-changed" && params !== null && "height" in params && typeof params.height === "number") {
73
+ state.height = params.height;
74
+ state.changed = performance.now();
75
+ }
76
+ if (data.method === "notifications/message" && params !== null && "data" in params)
77
+ state.errors.push(params.data);
78
+ });
79
+ Object.defineProperty(globalThis, "__nytePreview", {
80
+ value: {
81
+ settle: () => new Promise((resolve) => {
82
+ const since = performance.now();
83
+ const check = () => {
84
+ const now = performance.now();
85
+ const quiet = now - Math.max(state.changed, since) > setup.quietMs;
86
+ if (quiet && (state.height > 0 || state.errors.length > 0) || now - since > setup.timeoutMs)
87
+ resolve({ height: state.height, errors: state.errors, console: state.console });
88
+ else
89
+ setTimeout(check, 50);
90
+ };
91
+ check();
92
+ })
93
+ }
94
+ });
95
+ this.postMessage(setup.initialize, "*");
96
+ return true;
97
+ }
98
+ function harness(request) {
99
+ const setup = {
100
+ initialize: initializeResult2(1, { name: "nyte-preview", version: String(CANVAS_RUNTIME2) }, hostContext(request.theme)),
101
+ render: renderNotification2(request.module),
102
+ quietMs: SETTLE_QUIET_MS,
103
+ timeoutMs: SETTLE_TIMEOUT_MS,
104
+ consoleKept: CONSOLE_KEPT
105
+ };
106
+ return `(${installHarness.toString()}).call(globalThis, ${JSON.stringify(setup)})`;
107
+ }
108
+ async function settle(page) {
109
+ const answer = await page.evaluate("globalThis.__nytePreview.settle()");
110
+ if (!Value.Check(settled, answer))
111
+ throw new Error("The canvas preview harness answered something unreadable.");
112
+ return answer;
113
+ }
114
+ async function runCanvasPreview2(page, request) {
115
+ const { chat, phone } = CANVAS_PREVIEW_WIDTHS2;
116
+ await page.resize(chat, 900);
117
+ const install = harness(request);
118
+ let attempts = 0;
119
+ while (await page.evaluate(install) !== true) {
120
+ attempts += 1;
121
+ if (attempts > 50)
122
+ throw new Error("The canvas shell did not start in the preview.");
123
+ await new Promise((resolve) => setTimeout(resolve, 100));
124
+ }
125
+ const wide = await settle(page);
126
+ await page.resize(chat, clampCanvasHeight2(wide.height > 0 ? wide.height : 240));
127
+ const narrow = await settle(page);
128
+ const png = await page.capture();
129
+ await page.resize(phone, 900);
130
+ const last = await settle(page);
131
+ return {
132
+ png,
133
+ heights: { chat: narrow.height, phone: last.height },
134
+ errors: last.errors.map((error) => ({ ...error, stack: error.stack ?? null })),
135
+ console: last.console
136
+ };
137
+ }
138
+ function describeCanvasPreview2(report) {
139
+ const heights = ["chat", "phone"].map((width) => {
140
+ const height = report.heights[width];
141
+ const scrolls = height > CANVAS_MAX_HEIGHT2 ? `, so it scrolls past ${CANVAS_MAX_HEIGHT2} px` : "";
142
+ return `At ${CANVAS_PREVIEW_WIDTHS2[width]} px wide (${WIDTH_NAMES[width]}) it is ${height} px tall${scrolls}.`;
143
+ });
144
+ const errors = report.errors.length === 0 ? ["No errors."] : [
145
+ `Errors (${report.errors.length}):`,
146
+ ...report.errors.map((error) => `- ${error.phase}: ${error.message}`)
147
+ ];
148
+ const logs = report.console.length === 0 ? [] : [
149
+ `Console (${report.console.length}):`,
150
+ ...report.console.map((entry) => `- [${entry.level}] ${entry.text}`)
151
+ ];
152
+ return [
153
+ "Preview only; the user has not seen it. The screenshot is the chat-column render.",
154
+ ...heights,
155
+ ...errors,
156
+ ...logs
157
+ ].join(`
158
+ `);
159
+ }
160
+
161
+ export { CANVAS_PREVIEW_WIDTHS2, runCanvasPreview2, describeCanvasPreview2 };
@@ -0,0 +1,41 @@
1
+ // examples/claude-code/inert-mcp.ts
2
+ var INERT_MCP_SOURCE2 = `#!/usr/bin/env node
3
+ import { readFile } from "node:fs/promises";
4
+ import { createInterface } from "node:readline";
5
+
6
+ const manifestPath = process.argv[2];
7
+ if (!manifestPath) process.exit(2);
8
+ const tools = JSON.parse(await readFile(manifestPath, "utf8"));
9
+ const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
10
+
11
+ for await (const line of lines) {
12
+ let request;
13
+ try {
14
+ request = JSON.parse(line);
15
+ } catch {
16
+ continue;
17
+ }
18
+
19
+ let result = {};
20
+ if (request.method === "initialize") {
21
+ result = {
22
+ protocolVersion: "2024-11-05",
23
+ capabilities: { tools: {} },
24
+ serverInfo: { name: "nyte-inert-tool-inventory", version: "1" },
25
+ };
26
+ } else if (request.method === "tools/list") {
27
+ result = { tools };
28
+ } else if (request.method === "tools/call") {
29
+ result = {
30
+ isError: true,
31
+ content: [{ type: "text", text: "Denied: Claude Code tools are inert; only Nyte executes tools." }],
32
+ };
33
+ }
34
+
35
+ if (request.id !== undefined) {
36
+ process.stdout.write(\`\${JSON.stringify({ jsonrpc: "2.0", id: request.id, result })}\\n\`);
37
+ }
38
+ }
39
+ `;
40
+
41
+ export { INERT_MCP_SOURCE2 };
@@ -0,0 +1,20 @@
1
+ import {
2
+ envFlagEnabled2
3
+ } from "./billing-s4rrspsk.js";
4
+
5
+ // examples/claude-code/billing.ts
6
+ var ALLOW_USAGE_CREDITS_ENV = "NYTE_CLAUDE_CODE_ALLOW_USAGE_CREDITS";
7
+ var USAGE_CREDITS_REJECTION = /third-party apps now draw from your extra usage|out of extra usage|draws? from your usage credits/iu;
8
+ function usageCreditsAllowed2(env) {
9
+ return envFlagEnabled2(env[ALLOW_USAGE_CREDITS_ENV]);
10
+ }
11
+ function usageCreditsChargeError2(info) {
12
+ return new Error("Claude Code billing: this request was charged to Claude usage credits instead of your plan limits " + `(rate limit status ${info.status ?? "unknown"}${info.rateLimitType ? `, ${info.rateLimitType}` : ""}). ` + "Nyte stopped so further requests are not charged. To stay on plan limits only, turn off usage credits at " + `claude.ai/settings/usage. To allow usage credits, set ${ALLOW_USAGE_CREDITS_ENV}=1.`);
13
+ }
14
+ function describeUsageCreditsRejection2(message) {
15
+ if (!USAGE_CREDITS_REJECTION.test(message))
16
+ return;
17
+ return "Claude Code billing: Anthropic did not accept this request on your Claude plan limits and wants to charge " + "it to usage credits. This happens when your plan limit is used up, or when Anthropic classifies the " + "request as third-party app usage. Nyte will not retry it. Original error: " + message;
18
+ }
19
+
20
+ export { usageCreditsAllowed2, usageCreditsChargeError2, describeUsageCreditsRejection2 };
@@ -0,0 +1,52 @@
1
+ import {
2
+ MIRROR_TOOL2
3
+ } from "./billing-9nn3yp18.js";
4
+
5
+ // src/acp/transcript.ts
6
+ var RESULT_LIMIT = 2000;
7
+ function text(content) {
8
+ return typeof content === "string" ? content : content.map((block) => block.type === "text" ? block.text : `[${block.mimeType}]`).join("");
9
+ }
10
+ function messageKey2(message) {
11
+ if (message.role === "user")
12
+ return `u:${text(message.content)}`;
13
+ if (message.role === "toolResult")
14
+ return `t:${message.toolCallId}`;
15
+ if (message.role === "system")
16
+ return "s";
17
+ return `a:${message.content.flatMap((block) => block.type === "toolCall" ? [block.id] : []).join(",")}`;
18
+ }
19
+ function userBlocks2(message, images) {
20
+ if (typeof message.content === "string")
21
+ return [{ type: "text", text: message.content }];
22
+ return message.content.map((block) => block.type === "text" ? { type: "text", text: block.text } : images ? { type: "image", data: block.data, mimeType: block.mimeType } : { type: "text", text: `(${block.mimeType} image omitted)` });
23
+ }
24
+ function transcriptText2(messages) {
25
+ return messages.flatMap((message) => {
26
+ if (message.role === "user")
27
+ return [`User:
28
+ ${text(message.content)}`];
29
+ if (message.role === "toolResult")
30
+ return [
31
+ `Tool result (${message.toolName}):
32
+ ${text(message.content).slice(0, RESULT_LIMIT)}`
33
+ ];
34
+ if (message.role !== "assistant" || message.stopReason === "error")
35
+ return [];
36
+ const said = message.content.flatMap((block) => {
37
+ if (block.type === "text")
38
+ return [block.text];
39
+ if (block.type !== "toolCall")
40
+ return [];
41
+ const title = block.name === MIRROR_TOOL2 ? block.arguments.title : undefined;
42
+ return [`[${typeof title === "string" ? title : block.name}]`];
43
+ });
44
+ return said.length === 0 ? [] : [`Assistant:
45
+ ${said.join(`
46
+ `)}`];
47
+ }).join(`
48
+
49
+ `);
50
+ }
51
+
52
+ export { messageKey2, userBlocks2, transcriptText2 };