@nyte-ai/plugin 0.0.23 → 0.0.24

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 (79) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -38
  2. package/dist/chunks/{billing-2v3g7rd9.js → bash-description-2v3g7rd9.js} +1 -1
  3. package/dist/chunks/{billing-3j77ss7y.js → bash-description-3j77ss7y.js} +1 -1
  4. package/dist/chunks/{billing-bv5zr32b.js → bash-description-dnvgk30y.js} +2 -2
  5. package/dist/chunks/{billing-hg64tqf1.js → bash-description-hg64tqf1.js} +1 -1
  6. package/dist/chunks/{billing-r2ftaajy.js → bash-description-necnb2k7.js} +2 -7
  7. package/dist/chunks/{billing-mvc33pv6.js → bash-description-qnwggxq3.js} +1 -1
  8. package/dist/chunks/{billing-svrhh5a5.js → bash-description-svrhh5a5.js} +1 -1
  9. package/dist/chunks/{billing-wbe8w0te.js → bash-description-wbe8w0te.js} +1 -1
  10. package/dist/chunks/{billing-wmcbg6fw.js → bash-description-wmcbg6fw.js} +1 -1
  11. package/dist/chunks/{billing-sxc70w72.js → bash-description-yyd9jznf.js} +1 -1
  12. package/dist/chunks/{billing-gs2h17jb.js → bash-description-zz15raxk.js} +1 -1
  13. package/dist/src/acp/connection.js +3 -3
  14. package/dist/src/acp/index.js +6 -6
  15. package/dist/src/acp/registry.js +2 -2
  16. package/dist/src/acp/thread.js +2 -2
  17. package/dist/src/acp/transcript.js +2 -2
  18. package/dist/src/acp/translate.js +1 -1
  19. package/dist/src/approvals/approvals.js +1 -1
  20. package/dist/src/approvals/schema.js +1 -1
  21. package/dist/src/canvas/canvas-compile.js +3 -3
  22. package/dist/src/canvas/canvas-libraries.js +1 -1
  23. package/dist/src/canvas/canvas-preview.js +3 -3
  24. package/dist/src/canvas/canvas-protocol.d.ts +1 -1
  25. package/dist/src/canvas/canvas-protocol.js +2 -2
  26. package/dist/src/canvas/canvas.js +5 -5
  27. package/dist/src/canvas/schema.js +3 -3
  28. package/dist/src/claude-code-sdk/index.js +6 -6
  29. package/dist/src/claude-code-sdk/session.js +2 -2
  30. package/dist/src/claude-code-sdk/transcript.js +2 -2
  31. package/dist/src/claude-code-sdk/translate.js +1 -1
  32. package/dist/src/find-on-path.js +1 -1
  33. package/dist/src/question/client/questions-tui.js +1 -1
  34. package/dist/src/question/client/questions.js +1 -1
  35. package/dist/src/question/question.js +2 -2
  36. package/dist/src/question/schema.js +1 -1
  37. package/package.json +4 -8
  38. package/dist/chunks/billing-0y7dfkp2.js +0 -146
  39. package/dist/chunks/billing-3scqmkzb.js +0 -559
  40. package/dist/chunks/billing-8rjk35gr.js +0 -444
  41. package/dist/chunks/billing-9qc0eqh4.js +0 -174
  42. package/dist/chunks/billing-a9vqn66p.js +0 -351
  43. package/dist/chunks/billing-cy1rg619.js +0 -302
  44. package/dist/chunks/billing-ejx2hv52.js +0 -323
  45. package/dist/chunks/billing-j643d12p.js +0 -197
  46. package/dist/chunks/billing-s4rrspsk.js +0 -7
  47. package/dist/chunks/billing-t1qrxe16.js +0 -41
  48. package/dist/chunks/billing-tzr3cebf.js +0 -20
  49. package/dist/examples/claude-code/LICENSE +0 -21
  50. package/dist/examples/claude-code/billing.d.ts +0 -7
  51. package/dist/examples/claude-code/billing.js +0 -11
  52. package/dist/examples/claude-code/claude-cli.d.ts +0 -35
  53. package/dist/examples/claude-code/claude-cli.js +0 -15
  54. package/dist/examples/claude-code/env.d.ts +0 -1
  55. package/dist/examples/claude-code/env.js +0 -6
  56. package/dist/examples/claude-code/index.d.ts +0 -24
  57. package/dist/examples/claude-code/index.js +0 -149
  58. package/dist/examples/claude-code/inert-mcp.d.ts +0 -1
  59. package/dist/examples/claude-code/inert-mcp.js +0 -6
  60. package/dist/examples/claude-code/model-catalog.d.ts +0 -27
  61. package/dist/examples/claude-code/model-catalog.js +0 -12
  62. package/dist/examples/claude-code/process.d.ts +0 -22
  63. package/dist/examples/claude-code/process.js +0 -25
  64. package/dist/examples/claude-code/replay.d.ts +0 -4
  65. package/dist/examples/claude-code/replay.js +0 -11
  66. package/dist/examples/claude-code/stream.d.ts +0 -3
  67. package/dist/examples/claude-code/stream.js +0 -16
  68. package/dist/examples/claude-code/transcript.d.ts +0 -83
  69. package/dist/examples/claude-code/transcript.js +0 -23
  70. package/dist/examples/claude-code/turn-relay.d.ts +0 -48
  71. package/dist/examples/claude-code/turn-relay.js +0 -9
  72. package/dist/examples/claude-code/wire.d.ts +0 -372
  73. package/dist/examples/claude-code/wire.js +0 -18
  74. /package/dist/chunks/{billing-4vz9pxyx.js → bash-description-4vz9pxyx.js} +0 -0
  75. /package/dist/chunks/{billing-6z2kgtyt.js → bash-description-6z2kgtyt.js} +0 -0
  76. /package/dist/chunks/{billing-9nn3yp18.js → bash-description-9nn3yp18.js} +0 -0
  77. /package/dist/chunks/{billing-h13r0byk.js → bash-description-h13r0byk.js} +0 -0
  78. /package/dist/chunks/{billing-ye3wk5r3.js → bash-description-ye3wk5r3.js} +0 -0
  79. /package/dist/chunks/{billing-zfpm2rt0.js → bash-description-zfpm2rt0.js} +0 -0
@@ -1,323 +0,0 @@
1
- import {
2
- messageSchema2,
3
- matchesRecord2
4
- } from "./billing-0y7dfkp2.js";
5
-
6
- // examples/claude-code/transcript.ts
7
- import { Type } from "typebox";
8
- import { Value } from "typebox/value";
9
- import {
10
- getDeclaredTools,
11
- getInitialSystemMessage,
12
- hasToolRedefinitions,
13
- renderSystemMessageUpdate
14
- } from "@nyte-ai/ai";
15
- var TOOL_PREFIX2 = "mcp__nyte__";
16
- var NATIVE_REPLAY_DIAGNOSTIC = "claude-code.native-assistant.v1";
17
- var NATIVE_TOOL_CHANGES_BETA2 = "mid-conversation-tool-changes-2026-07-01";
18
- var DEFERRED_TOOL_PLACEHOLDER = {
19
- name: "__nyte_deferred_placeholder__",
20
- description: "Reserved placeholder. Never available. Never call this.",
21
- input_schema: { type: "object", properties: {}, required: [] },
22
- defer_loading: true
23
- };
24
- function sanitizeSurrogates(text) {
25
- return text.replace(/[\uD800-\uDFFF]/gu, "�");
26
- }
27
- function assistantProjection(message) {
28
- const text = message.content.filter((block) => block.type === "text").map((block) => block.text).join("").trim();
29
- const toolCalls = message.content.filter((block) => block.type === "toolCall").map((block) => ({ id: block.id, name: block.name, input: structuredClone(block.arguments) }));
30
- return { text, toolCalls };
31
- }
32
- var projectionSchema = Type.Object({
33
- text: Type.String(),
34
- toolCalls: Type.Array(Type.Object({
35
- id: Type.String(),
36
- name: Type.String(),
37
- input: Type.Record(Type.String(), Type.Unknown())
38
- }))
39
- });
40
- var replayCarrierSchema = Type.Object({
41
- version: Type.Literal(1),
42
- message: messageSchema2,
43
- projection: projectionSchema,
44
- initialUserPrefix: Type.Optional(Type.Array(Type.Unknown())),
45
- initialSystemMessages: Type.Optional(Type.Array(Type.Unknown()))
46
- });
47
- function replayCarrier(message) {
48
- const diagnostic = message.diagnostics?.find((item) => item.type === NATIVE_REPLAY_DIAGNOSTIC);
49
- const candidate = diagnostic?.details?.carrier;
50
- return Value.Check(replayCarrierSchema, candidate) ? candidate : undefined;
51
- }
52
- function replayMetadata(messages, key) {
53
- for (let index = messages.length - 1;index >= 0; index--) {
54
- const message = messages[index];
55
- if (message?.role !== "assistant")
56
- continue;
57
- const value = replayCarrier(message)?.[key];
58
- if (value)
59
- return structuredClone(value);
60
- }
61
- return;
62
- }
63
- function getInitialUserPrefix2(messages) {
64
- return replayMetadata(messages, "initialUserPrefix");
65
- }
66
- function getInitialSystemMessages2(messages) {
67
- return replayMetadata(messages, "initialSystemMessages");
68
- }
69
- function imageBlock(block) {
70
- return {
71
- type: "image",
72
- source: { type: "base64", media_type: block.mimeType, data: block.data }
73
- };
74
- }
75
- function userContent(content) {
76
- if (typeof content === "string")
77
- return content ? [{ type: "text", text: sanitizeSurrogates(content) }] : [];
78
- return content.map((block) => block.type === "text" ? { type: "text", text: sanitizeSurrogates(block.text) } : imageBlock(block));
79
- }
80
- function toolResultContent(message) {
81
- const hasImages = message.content.some((block) => block.type === "image");
82
- if (!hasImages) {
83
- return sanitizeSurrogates(message.content.filter((block) => block.type === "text").map((block) => block.text).join(`
84
- `));
85
- }
86
- return message.content.map((block) => block.type === "text" ? { type: "text", text: sanitizeSurrogates(block.text) } : imageBlock(block));
87
- }
88
- function canonicalAssistantContent(message) {
89
- const blocks = [];
90
- for (const block of message.content) {
91
- if (block.type === "text" && block.text.trim()) {
92
- blocks.push({ type: "text", text: sanitizeSurrogates(block.text) });
93
- } else if (block.type === "thinking" && block.thinking.trim() && block.thinkingSignature) {
94
- if (block.redacted) {
95
- blocks.push({ type: "redacted_thinking", data: block.thinkingSignature });
96
- } else {
97
- blocks.push({
98
- type: "thinking",
99
- thinking: sanitizeSurrogates(block.thinking),
100
- signature: block.thinkingSignature
101
- });
102
- }
103
- } else if (block.type === "toolCall") {
104
- blocks.push({
105
- type: "tool_use",
106
- id: block.id,
107
- name: `${TOOL_PREFIX2}${block.name}`,
108
- input: structuredClone(block.arguments)
109
- });
110
- }
111
- }
112
- return blocks;
113
- }
114
- function assistantContent(message) {
115
- const carrier = replayCarrier(message);
116
- if (carrier && JSON.stringify(assistantProjection(message)) === JSON.stringify(carrier.projection)) {
117
- return structuredClone(carrier.message.content);
118
- }
119
- if (carrier) {
120
- return canonicalAssistantContent({
121
- ...message,
122
- content: message.content.filter((block) => block.type !== "thinking")
123
- });
124
- }
125
- return canonicalAssistantContent(message);
126
- }
127
- function prepareFrames2(messages) {
128
- const frames = [];
129
- for (const message of messages) {
130
- if (message.role === "system")
131
- continue;
132
- let role;
133
- let blocks;
134
- if (message.role === "user") {
135
- role = "user";
136
- blocks = userContent(message.content);
137
- } else if (message.role === "assistant") {
138
- role = "assistant";
139
- blocks = assistantContent(message);
140
- } else {
141
- role = "user";
142
- blocks = [
143
- {
144
- type: "tool_result",
145
- tool_use_id: message.toolCallId,
146
- content: toolResultContent(message),
147
- is_error: message.isError
148
- }
149
- ];
150
- }
151
- if (blocks.length === 0)
152
- continue;
153
- const previous = frames.at(-1);
154
- if (role === "user" && previous?.type === "user") {
155
- previous.message.content.push(...blocks);
156
- } else {
157
- frames.push({ type: role, message: { role, content: blocks } });
158
- }
159
- }
160
- const final = frames.at(-1);
161
- if (!final || final.type !== "user" || final.message.content.length === 0) {
162
- throw new Error("Claude Code history must end in a non-empty user or tool-result message");
163
- }
164
- for (let index = 0;index < frames.length - 1; index++) {
165
- const frame = frames[index];
166
- if (frame?.type === "user")
167
- frame.shouldQuery = false;
168
- }
169
- return frames;
170
- }
171
- function withoutNullVariant(schema) {
172
- if (Array.isArray(schema))
173
- return schema.map(withoutNullVariant);
174
- if (!matchesRecord2(schema))
175
- return schema;
176
- const output = {};
177
- for (const [key, value] of Object.entries(schema))
178
- output[key] = withoutNullVariant(value);
179
- if (Array.isArray(output.type) && output.type.includes("null")) {
180
- const remaining = output.type.filter((value) => value !== "null");
181
- output.type = remaining.length === 1 ? remaining[0] : remaining;
182
- }
183
- if (Array.isArray(output.anyOf)) {
184
- const nonNull = output.anyOf.filter((branch) => !(matchesRecord2(branch) && branch.type === "null"));
185
- if (nonNull.length === 1 && nonNull.length !== output.anyOf.length) {
186
- const replacement = nonNull[0];
187
- delete output.anyOf;
188
- if (replacement && typeof replacement === "object")
189
- Object.assign(output, replacement);
190
- }
191
- }
192
- return output;
193
- }
194
- function normalizeInputSchema(schema) {
195
- const normalized = withoutNullVariant(schema);
196
- if (!matchesRecord2(normalized))
197
- throw new Error("Tool input schema must be an object");
198
- for (const key of ["oneOf", "allOf", "anyOf"])
199
- delete normalized[key];
200
- if (!normalized.type)
201
- normalized.type = "object";
202
- if (normalized.type === "object" && (!normalized.properties || typeof normalized.properties !== "object")) {
203
- normalized.properties = {};
204
- }
205
- return normalized;
206
- }
207
- function prepareTools2(tools) {
208
- const names = new Set;
209
- const manifest = [];
210
- const nativeTools = [];
211
- for (const tool of tools) {
212
- if (!/^[A-Za-z0-9_-]{1,50}$/u.test(tool.name) || names.has(tool.name)) {
213
- throw new Error("Claude Code tool names must be unique ASCII identifiers of at most 50 characters");
214
- }
215
- names.add(tool.name);
216
- const schema = normalizeInputSchema(tool.parameters);
217
- manifest.push({ name: tool.name, description: tool.description, inputSchema: schema });
218
- nativeTools.push({
219
- name: `${TOOL_PREFIX2}${tool.name}`,
220
- description: tool.description,
221
- input_schema: schema
222
- });
223
- }
224
- return { manifest, nativeTools, names };
225
- }
226
- function nativeSystemBlocks(message) {
227
- const blocks = [];
228
- const text = renderSystemMessageUpdate(message);
229
- if (text)
230
- blocks.push({ type: "text", text: sanitizeSurrogates(text) });
231
- for (const tool of message.toolsRemoved ?? []) {
232
- blocks.push({
233
- type: "tool_removal",
234
- tool: { type: "tool_reference", name: `${TOOL_PREFIX2}${tool.name}` }
235
- });
236
- }
237
- for (const tool of message.toolsAdded ?? []) {
238
- blocks.push({
239
- type: "tool_addition",
240
- tool: { type: "tool_reference", name: `${TOOL_PREFIX2}${tool.name}` }
241
- });
242
- }
243
- return blocks;
244
- }
245
- function prepareNativeTranscript2(messages, supported) {
246
- const initial = getInitialSystemMessage(messages);
247
- const initialTools = initial?.toolsAdded ?? [];
248
- if (!supported || initialTools.length === 0 || hasToolRedefinitions(messages))
249
- return;
250
- const declared = getDeclaredTools(messages);
251
- const prepared = prepareTools2(declared);
252
- const nativeByName = new Map(prepared.nativeTools.map((tool) => [String(tool.name).slice(TOOL_PREFIX2.length), tool]));
253
- const initialNames = new Set(initialTools.map((tool) => tool.name));
254
- const initialNative = initialTools.map((tool) => {
255
- const native = nativeByName.get(tool.name);
256
- if (native === undefined)
257
- throw new Error(`Missing declared tool ${tool.name}`);
258
- return structuredClone(native);
259
- });
260
- const final = initialNative.at(-1);
261
- if (final)
262
- final.cache_control = { type: "ephemeral", ttl: "1h" };
263
- const laterNative = declared.filter((tool) => !initialNames.has(tool.name)).map((tool) => ({ ...structuredClone(nativeByName.get(tool.name)), defer_loading: true }));
264
- const systemInjections = [];
265
- let pending = [];
266
- let assistantOrdinal = 0;
267
- const flush = (beforeAssistant) => {
268
- for (const content of pending)
269
- systemInjections.push({ beforeAssistant, content });
270
- pending = [];
271
- };
272
- for (let index = 1;index < messages.length; index++) {
273
- const message = messages[index];
274
- if (message === undefined)
275
- continue;
276
- if (message.role === "system") {
277
- const blocks = nativeSystemBlocks(message);
278
- if (blocks.length)
279
- pending.push(blocks);
280
- } else if (message.role === "assistant" && assistantContent(message).length > 0) {
281
- flush(assistantOrdinal);
282
- assistantOrdinal += 1;
283
- }
284
- }
285
- flush(null);
286
- return {
287
- requestTools: [...initialNative, structuredClone(DEFERRED_TOOL_PLACEHOLDER), ...laterNative],
288
- systemInjections
289
- };
290
- }
291
- function buildExtraBody2(nativeTools, options, adaptive) {
292
- const body = { tools: nativeTools };
293
- if (options?.maxTokens !== undefined)
294
- body.max_tokens = options.maxTokens;
295
- if (options?.reasoning) {
296
- if (adaptive)
297
- body.thinking = { type: "adaptive" };
298
- body.output_config = {
299
- effort: options.reasoning === "minimal" ? "low" : options.reasoning
300
- };
301
- } else {
302
- body.thinking = { type: "disabled" };
303
- body.context_management = { edits: [] };
304
- }
305
- return body;
306
- }
307
- function makeReplayDiagnostic2(message, output, initialUserPrefix, initialSystemMessages) {
308
- return {
309
- type: NATIVE_REPLAY_DIAGNOSTIC,
310
- timestamp: Date.now(),
311
- details: {
312
- carrier: {
313
- version: 1,
314
- message: structuredClone(message),
315
- projection: assistantProjection(output),
316
- ...initialUserPrefix ? { initialUserPrefix: structuredClone(initialUserPrefix) } : {},
317
- ...initialSystemMessages ? { initialSystemMessages: structuredClone(initialSystemMessages) } : {}
318
- }
319
- }
320
- };
321
- }
322
-
323
- export { TOOL_PREFIX2, NATIVE_TOOL_CHANGES_BETA2, getInitialUserPrefix2, getInitialSystemMessages2, prepareFrames2, prepareTools2, prepareNativeTranscript2, buildExtraBody2, makeReplayDiagnostic2 };
@@ -1,197 +0,0 @@
1
- import {
2
- matchesRecord2,
3
- parseRequest2,
4
- parseRequestMessages2
5
- } from "./billing-0y7dfkp2.js";
6
-
7
- // examples/claude-code/replay.ts
8
- function withoutCacheControl(value) {
9
- if (Array.isArray(value))
10
- return value.map(withoutCacheControl);
11
- if (!matchesRecord2(value))
12
- return value;
13
- const output = {};
14
- for (const [key, child] of Object.entries(value)) {
15
- if (key !== "cache_control")
16
- output[key] = withoutCacheControl(child);
17
- }
18
- return output;
19
- }
20
- function requestMessages(body) {
21
- if (!body)
22
- return;
23
- try {
24
- return parseRequest2(body).messages;
25
- } catch {
26
- return;
27
- }
28
- }
29
- function deriveInitialUserPrefix2(body, canonicalContent) {
30
- if (canonicalContent.length === 0)
31
- return;
32
- const actual = requestMessages(body)?.[0];
33
- if (actual?.role !== "user" || !Array.isArray(actual.content) || actual.content.length < canonicalContent.length) {
34
- return;
35
- }
36
- const suffix = actual.content.slice(-canonicalContent.length).map(withoutCacheControl);
37
- if (JSON.stringify(suffix) !== JSON.stringify(canonicalContent.map(withoutCacheControl)))
38
- return;
39
- return structuredClone(actual.content.slice(0, -canonicalContent.length));
40
- }
41
- function deriveInitialSystemMessages2(body) {
42
- const messages = requestMessages(body);
43
- if (messages?.[0]?.role !== "user")
44
- return;
45
- let end = 1;
46
- while (messages[end]?.role === "system")
47
- end += 1;
48
- const systems = messages.slice(1, end);
49
- let trailingStart = messages.length;
50
- while (trailingStart > end && messages[trailingStart - 1]?.role === "system")
51
- trailingStart -= 1;
52
- if (trailingStart < messages.length)
53
- systems.push(...messages.slice(trailingStart));
54
- return systems.length ? structuredClone(systems) : undefined;
55
- }
56
- function contentText(content) {
57
- if (typeof content === "string")
58
- return content;
59
- if (!Array.isArray(content))
60
- return "";
61
- return content.map((block) => matchesRecord2(block) && typeof block.text === "string" ? block.text : "").join("");
62
- }
63
- function setCacheBreakpoint(message) {
64
- if (typeof message.content === "string") {
65
- message.content = [
66
- { type: "text", text: message.content, cache_control: { type: "ephemeral", ttl: "1h" } }
67
- ];
68
- return;
69
- }
70
- if (!Array.isArray(message.content) || message.content.length === 0)
71
- return;
72
- const last = message.content.at(-1);
73
- if (!matchesRecord2(last))
74
- return;
75
- last.cache_control = { type: "ephemeral", ttl: "1h" };
76
- }
77
- function setReplayCacheBreakpoints(messages) {
78
- const userIndexes = messages.map((message, index) => message.role === "user" ? index : -1).filter((index) => index >= 0);
79
- if (userIndexes.length >= 3) {
80
- for (const message of messages) {
81
- if (message.role === "system")
82
- message.content = withoutCacheControl(message.content);
83
- }
84
- const previousIndex = userIndexes.at(-2);
85
- const previous = previousIndex === undefined ? undefined : messages[previousIndex];
86
- if (previous)
87
- setCacheBreakpoint(previous);
88
- }
89
- const final = messages.at(-1);
90
- if (final)
91
- setCacheBreakpoint(final);
92
- }
93
- function removeRepeatedUserReminders(messages, prefix) {
94
- const reminder = contentText(prefix).trimEnd();
95
- if (!reminder || !prefix)
96
- return;
97
- const normalizedPrefix = JSON.stringify(prefix.map(withoutCacheControl));
98
- for (let index = 1;index < messages.length; index++) {
99
- const message = messages[index];
100
- if (message?.role !== "user" || !Array.isArray(message.content))
101
- continue;
102
- const leading = message.content.slice(0, prefix.length).map(withoutCacheControl);
103
- if (JSON.stringify(leading) === normalizedPrefix)
104
- message.content.splice(0, prefix.length);
105
- const toolResult = message.content.findLast((block) => matchesRecord2(block) && block.type === "tool_result");
106
- if (!matchesRecord2(toolResult))
107
- continue;
108
- const suffix = `
109
- ${reminder}`;
110
- if (typeof toolResult.content === "string" && toolResult.content.endsWith(suffix)) {
111
- toolResult.content = toolResult.content.slice(0, -suffix.length);
112
- } else if (Array.isArray(toolResult.content)) {
113
- const final = toolResult.content.at(-1);
114
- if (matchesRecord2(final) && final.type === "text" && typeof final.text === "string") {
115
- if (final.text === reminder)
116
- toolResult.content.pop();
117
- else if (final.text.endsWith(suffix))
118
- final.text = final.text.slice(0, -suffix.length);
119
- }
120
- }
121
- }
122
- }
123
- function injectNativeSystemMessages(messages, injections) {
124
- const byAssistant = new Map;
125
- const trailing = [];
126
- for (const injection of injections) {
127
- const message = { role: "system", content: structuredClone(injection.content) };
128
- if (injection.beforeAssistant === null)
129
- trailing.push(message);
130
- else {
131
- const pending = byAssistant.get(injection.beforeAssistant) ?? [];
132
- pending.push(message);
133
- byAssistant.set(injection.beforeAssistant, pending);
134
- }
135
- }
136
- const output = [];
137
- let assistantOrdinal = 0;
138
- for (const message of messages) {
139
- if (message.role === "assistant") {
140
- output.push(...byAssistant.get(assistantOrdinal) ?? []);
141
- byAssistant.delete(assistantOrdinal);
142
- assistantOrdinal += 1;
143
- }
144
- output.push(message);
145
- }
146
- if (byAssistant.size > 0)
147
- throw new Error("Claude Code request lost an assistant boundary needed by system history");
148
- output.push(...trailing);
149
- return output;
150
- }
151
- function normalizeLeadingSystemCache(system) {
152
- if (!Array.isArray(system))
153
- return;
154
- for (const block of system) {
155
- if (matchesRecord2(block))
156
- delete block.cache_control;
157
- }
158
- const last = system.at(-1);
159
- if (matchesRecord2(last)) {
160
- last.cache_control = { type: "ephemeral", ttl: "1h" };
161
- }
162
- }
163
- function rewriteInitialRequest2(body, prefix, canonicalContent, initialSystemMessages, nativeSystemInjections) {
164
- const payload = parseRequest2(body);
165
- let messages = payload.messages;
166
- const first = messages?.[0];
167
- if (first?.role !== "user" || !Array.isArray(first.content)) {
168
- throw new Error("Claude Code request is missing its initial user message");
169
- }
170
- if (prefix)
171
- first.content = [...structuredClone(prefix), ...structuredClone(canonicalContent)];
172
- if (initialSystemMessages?.length && messages) {
173
- let systemEnd = 1;
174
- while (messages[systemEnd]?.role === "system")
175
- systemEnd += 1;
176
- messages.splice(1, systemEnd - 1, ...parseRequestMessages2(structuredClone(initialSystemMessages)));
177
- const initialText = initialSystemMessages.map((message) => matchesRecord2(message) ? contentText(message.content) : "").join(`
178
- `);
179
- while (messages.at(-1)?.role === "system") {
180
- const trailingText = contentText(messages.at(-1)?.content);
181
- if (!trailingText || !initialText.includes(trailingText))
182
- break;
183
- messages.pop();
184
- }
185
- removeRepeatedUserReminders(messages, prefix);
186
- }
187
- if (nativeSystemInjections) {
188
- messages = injectNativeSystemMessages(messages, nativeSystemInjections);
189
- payload.messages = messages;
190
- normalizeLeadingSystemCache(payload.system);
191
- }
192
- if (initialSystemMessages?.length || nativeSystemInjections)
193
- setReplayCacheBreakpoints(messages);
194
- return Buffer.from(JSON.stringify(payload));
195
- }
196
-
197
- export { deriveInitialUserPrefix2, deriveInitialSystemMessages2, rewriteInitialRequest2 };
@@ -1,7 +0,0 @@
1
- // examples/claude-code/env.ts
2
- function envFlagEnabled2(value) {
3
- const normalized = value?.trim().toLowerCase();
4
- return !!normalized && !["0", "false", "no", "off"].includes(normalized);
5
- }
6
-
7
- export { envFlagEnabled2 };
@@ -1,41 +0,0 @@
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 };
@@ -1,20 +0,0 @@
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 };
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Armin Ronacher
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.
@@ -1,7 +0,0 @@
1
- import type { NativeOutputEvent } from "./wire.ts";
2
- export type RateLimitInfo = NonNullable<Extract<NativeOutputEvent, {
3
- type: "rate_limit_event";
4
- }>["rate_limit_info"]>;
5
- export declare function usageCreditsAllowed(env: Record<string, string | undefined>): boolean;
6
- export declare function usageCreditsChargeError(info: RateLimitInfo): Error;
7
- export declare function describeUsageCreditsRejection(message: string): string | undefined;
@@ -1,11 +0,0 @@
1
- import {
2
- usageCreditsAllowed2,
3
- usageCreditsChargeError2,
4
- describeUsageCreditsRejection2
5
- } from "../../chunks/billing-tzr3cebf.js";
6
- import"../../chunks/billing-s4rrspsk.js";
7
- export {
8
- describeUsageCreditsRejection2 as describeUsageCreditsRejection,
9
- usageCreditsAllowed2 as usageCreditsAllowed,
10
- usageCreditsChargeError2 as usageCreditsChargeError
11
- };
@@ -1,35 +0,0 @@
1
- import type { RateLimitInfo } from "./billing.ts";
2
- import type { AnthropicStreamEvent, JsonRecord, NativeFrame, NativeMessage, NativeUsage } from "./wire.ts";
3
- import type { NativeSystemInjection, ToolManifestEntry } from "./transcript.ts";
4
- export interface RunClaudeInput {
5
- model: string;
6
- cwd?: string;
7
- frames: NativeFrame[];
8
- systemPrompt: string;
9
- manifest: ToolManifestEntry[];
10
- extraBody: JsonRecord;
11
- toolNames: Set<string>;
12
- signal?: AbortSignal;
13
- timeoutMs?: number;
14
- env?: Record<string, string | undefined>;
15
- upstreamUrl?: string;
16
- initialUserPrefix?: unknown[];
17
- initialSystemMessages?: unknown[];
18
- nativeSystemInjections?: NativeSystemInjection[];
19
- betas?: string[];
20
- onEvent?: (event: AnthropicStreamEvent) => void;
21
- sessionId?: string;
22
- }
23
- export interface RunClaudeOutput {
24
- message: NativeMessage;
25
- usage: NativeUsage;
26
- relay: {
27
- upstreamRequests: number;
28
- blockedRequests: number;
29
- requestId?: string;
30
- };
31
- initialUserPrefix?: unknown[];
32
- initialSystemMessages?: unknown[];
33
- rateLimit?: RateLimitInfo;
34
- }
35
- export declare function runClaudeRequest(input: RunClaudeInput): Promise<RunClaudeOutput>;
@@ -1,15 +0,0 @@
1
- import {
2
- runClaudeRequest2
3
- } from "../../chunks/billing-3scqmkzb.js";
4
- import"../../chunks/billing-ejx2hv52.js";
5
- import"../../chunks/billing-a9vqn66p.js";
6
- import"../../chunks/billing-tzr3cebf.js";
7
- import"../../chunks/billing-t1qrxe16.js";
8
- import"../../chunks/billing-cy1rg619.js";
9
- import"../../chunks/billing-s4rrspsk.js";
10
- import"../../chunks/billing-9qc0eqh4.js";
11
- import"../../chunks/billing-j643d12p.js";
12
- import"../../chunks/billing-0y7dfkp2.js";
13
- export {
14
- runClaudeRequest2 as runClaudeRequest
15
- };
@@ -1 +0,0 @@
1
- export declare function envFlagEnabled(value: string | undefined): boolean;