@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,368 @@
1
+ import {
2
+ answerInput2
3
+ } from "../../chunks/billing-6z2kgtyt.js";
4
+ import {
5
+ question2
6
+ } from "../../chunks/billing-3j77ss7y.js";
7
+ import {
8
+ CLAUDE_CODE_PROVIDER2,
9
+ MIRROR_TOOL3,
10
+ BACKGROUND_TOOL2,
11
+ emptyMessage3,
12
+ Translator3
13
+ } from "../../chunks/billing-ye3wk5r3.js";
14
+ import {
15
+ ClaudeCodeSession2
16
+ } from "../../chunks/billing-wmkxkypm.js";
17
+ import {
18
+ mirrorArguments3,
19
+ userBlocks3,
20
+ messageKey3,
21
+ sessionEntries2,
22
+ flatPrompt2
23
+ } from "../../chunks/billing-2v3g7rd9.js";
24
+
25
+ // src/claude-code-sdk/index.ts
26
+ import { randomUUID } from "node:crypto";
27
+ import { access } from "node:fs/promises";
28
+ import { homedir } from "node:os";
29
+ import { join } from "node:path";
30
+ import { query } from "@anthropic-ai/claude-agent-sdk";
31
+ import {
32
+ acquireSessionResources,
33
+ anthropicProvider,
34
+ clampThinkingLevel,
35
+ createAssistantMessageEventStream,
36
+ getCurrentTools,
37
+ getCurrentSystemPrompt,
38
+ lazyStream,
39
+ registerSessionResourceCleanup
40
+ } from "@nyte-ai/ai";
41
+ import { processEnvironment } from "@nyte-ai/core";
42
+ import { standard } from "@nyte-ai/schema";
43
+ import { Type } from "typebox";
44
+ import { Value } from "typebox/value";
45
+ var API = "claude-agent-sdk";
46
+ var EFFORTS = ["low", "medium", "high", "xhigh", "max"];
47
+ var NOT_RUNNING = "Claude Code is no longer running this turn. Send a message to continue.";
48
+ var CLAUDE_CODE_HAS_ITS_OWN = new Set([
49
+ "read",
50
+ "write",
51
+ "edit",
52
+ "list",
53
+ "bash",
54
+ "web_search",
55
+ "question"
56
+ ]);
57
+ var ultracodeSetting = {
58
+ id: "claude_code.ultracode",
59
+ label: "Claude Code ultracode",
60
+ schema: standard(Type.Boolean()),
61
+ choices: [
62
+ { value: false, label: "Off" },
63
+ { value: true, label: "On", badge: "ultracode" }
64
+ ],
65
+ default: false,
66
+ scope: "session"
67
+ };
68
+ function effortFor(model, reasoning) {
69
+ if (reasoning === undefined)
70
+ return;
71
+ const level = clampThinkingLevel(model, reasoning);
72
+ if (level === "off")
73
+ return;
74
+ const mapped = model.thinkingLevelMap?.[level] ?? level;
75
+ return EFFORTS.find((effort) => effort === mapped) ?? (level === "minimal" ? "low" : undefined);
76
+ }
77
+ async function claudeCodeConfigured() {
78
+ try {
79
+ await access(process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude"));
80
+ return true;
81
+ } catch {
82
+ return false;
83
+ }
84
+ }
85
+ function answerOnce(start, model, context, options) {
86
+ const stream = createAssistantMessageEventStream();
87
+ const output = emptyMessage3(model);
88
+ const translator = new Translator3(model, output, stream);
89
+ const controller = new AbortController;
90
+ const abort = () => controller.abort();
91
+ options?.signal?.addEventListener("abort", abort, { once: true });
92
+ (async () => {
93
+ try {
94
+ stream.push({ type: "start", partial: output });
95
+ await processEnvironment();
96
+ for await (const message of start({
97
+ prompt: flatPrompt2(context.messages),
98
+ options: {
99
+ model: model.id,
100
+ abortController: controller,
101
+ systemPrompt: getCurrentSystemPrompt(context.messages),
102
+ tools: [],
103
+ settingSources: [],
104
+ strictMcpConfig: true,
105
+ maxTurns: 1,
106
+ persistSession: false,
107
+ includePartialMessages: true,
108
+ thinking: { type: "disabled" },
109
+ env: { ...process.env, ...options?.env }
110
+ }
111
+ })) {
112
+ if (message.type === "stream_event" && message.parent_tool_use_id === null)
113
+ translator.apply(message.event);
114
+ else if (message.type === "result" && message.subtype !== "success")
115
+ throw new Error(message.errors.join(`
116
+ `) || `Claude Code failed: ${message.subtype}`);
117
+ }
118
+ if (output.stopReason === "pending" || output.stopReason === "aborted")
119
+ throw new Error("Claude Code ended without a response.");
120
+ if (output.stopReason === "error")
121
+ throw new Error(output.errorMessage ?? "Claude Code failed.");
122
+ stream.push({ type: "done", reason: output.stopReason, message: output });
123
+ } catch (error) {
124
+ output.stopReason = options?.signal?.aborted === true ? "aborted" : "error";
125
+ output.errorMessage = error instanceof Error ? error.message : String(error);
126
+ stream.push({ type: "error", reason: output.stopReason, error: output });
127
+ } finally {
128
+ options?.signal?.removeEventListener("abort", abort);
129
+ stream.end();
130
+ }
131
+ })();
132
+ return stream;
133
+ }
134
+ var nonEmpty = Type.String({ minLength: 1 });
135
+ function field(input, key) {
136
+ const value = input[key];
137
+ return Value.Check(nonEmpty, value) ? value : undefined;
138
+ }
139
+ var claudeQuestions = Type.Array(Type.Object({
140
+ question: Type.String(),
141
+ header: Type.String(),
142
+ options: Type.Array(Type.Object({ label: Type.String(), description: Type.String() })),
143
+ multiSelect: Type.Optional(Type.Boolean())
144
+ }));
145
+ async function askUser(session, id, input, invocation) {
146
+ if (!Value.Check(claudeQuestions, input.questions))
147
+ return { answers: null, part: null };
148
+ const questions = input.questions.map((item) => ({
149
+ question: item.question,
150
+ header: item.header.slice(0, 30),
151
+ options: item.options.map(({ label, description }) => ({ label, description })),
152
+ multiple: item.multiSelect === true
153
+ }));
154
+ const part = await invocation.session.parts.create(question2, {
155
+ state: { questions, answers: null },
156
+ placement: { kind: "modal" }
157
+ });
158
+ const outcome = await invocation.wait({ kind: "part", part: part.id });
159
+ const checked = outcome.kind === "part" && outcome.answer?.action === "answer" ? await answerInput2["~standard"].validate(outcome.answer.input) : undefined;
160
+ if (checked === undefined || checked.issues !== undefined)
161
+ return { answers: null, part: part.id };
162
+ const answers = questions.flatMap((item, index) => {
163
+ const chosen = checked.value.answers[index]?.join(", ") ?? "";
164
+ return chosen === "" ? [] : [[item.question, chosen]];
165
+ });
166
+ return { answers: answers.length === 0 ? null : Object.fromEntries(answers), part: part.id };
167
+ }
168
+ function classifyClaudeTool(name, input) {
169
+ const path = field(input, "file_path") ?? field(input, "notebook_path");
170
+ const command = field(input, "command");
171
+ const description = field(input, "description");
172
+ switch (name) {
173
+ case "Read":
174
+ return path === undefined ? { kind: "custom", label: name } : { kind: "read", path };
175
+ case "Edit":
176
+ case "MultiEdit":
177
+ case "Write":
178
+ case "NotebookEdit":
179
+ return path === undefined ? { kind: "custom", label: name } : { kind: "edit", path };
180
+ case "Bash":
181
+ if (command === undefined)
182
+ return { kind: "custom", label: name };
183
+ return description === undefined ? { kind: "shell", command } : { kind: "shell", command, description };
184
+ case "Agent":
185
+ case "Task":
186
+ return {
187
+ kind: "delegate",
188
+ child: null,
189
+ role: "task",
190
+ title: description ?? null
191
+ };
192
+ case "Skill":
193
+ return { kind: "custom", label: `Skill ${field(input, "skill") ?? ""}`.trim() };
194
+ case "Workflow":
195
+ return {
196
+ kind: "custom",
197
+ label: `Workflow ${field(input, "title") ?? field(input, "name") ?? ""}`.trim()
198
+ };
199
+ case "AskUserQuestion": {
200
+ const headers = Value.Check(claudeQuestions, input.questions) ? input.questions.map((item) => item.header).join(", ") : "";
201
+ return { kind: "custom", label: `Asking ${headers}`.trim() };
202
+ }
203
+ case BACKGROUND_TOOL2:
204
+ return { kind: "custom", label: "Waiting for background work" };
205
+ default: {
206
+ const subject = field(input, "pattern") ?? field(input, "url") ?? field(input, "query");
207
+ return { kind: "custom", label: subject === undefined ? name : `${name} ${subject}` };
208
+ }
209
+ }
210
+ }
211
+ function mirrorTool(sessions) {
212
+ return {
213
+ name: MIRROR_TOOL3,
214
+ description: "A tool Claude Code ran. Claude Code reports the result; Nyte records it.",
215
+ parameters: standard(mirrorArguments3),
216
+ exposure: "hidden",
217
+ approval: "runtime",
218
+ replay: "safe",
219
+ class: ({ name, input }) => classifyClaudeTool(name, input),
220
+ async execute({ id, name, input }, invocation) {
221
+ const session = sessions.get(invocation.session.id);
222
+ if (session === undefined || session.closed)
223
+ throw new Error(NOT_RUNNING);
224
+ if (name === BACKGROUND_TOOL2)
225
+ return { content: [{ kind: "text", text: await session.background(invocation.signal) }] };
226
+ session.recording(id);
227
+ let parts = [];
228
+ if (name === "AskUserQuestion") {
229
+ const asked = await askUser(session, id, input, invocation);
230
+ session.answer(id, asked.answers);
231
+ parts = asked.part === null ? [] : [asked.part];
232
+ }
233
+ const output = await session.result(id, invocation.signal);
234
+ if (output.isError)
235
+ throw new Error(output.text);
236
+ return { content: [{ kind: "text", text: output.text }], parts };
237
+ }
238
+ };
239
+ }
240
+ function claudeCodeSdk(start = query) {
241
+ const catalog = anthropicProvider();
242
+ const sessions = new Map;
243
+ const bindings = new Map;
244
+ registerSessionResourceCleanup((id) => {
245
+ for (const [key, session] of sessions) {
246
+ if (id !== undefined && key !== id)
247
+ continue;
248
+ sessions.delete(key);
249
+ session.close();
250
+ }
251
+ });
252
+ async function respond(model, context, options) {
253
+ const id = options?.sessionId;
254
+ const binding = id === undefined ? undefined : bindings.get(id);
255
+ if (id === undefined || binding === undefined)
256
+ throw new Error("Claude Code answers inside a Nyte session with the claude-code-sdk plugin.");
257
+ const effort = effortFor(model, options?.reasoning);
258
+ const ultracode = await binding.ultracode();
259
+ const key = JSON.stringify([model.id, binding.cwd, options?.reasoning !== undefined]);
260
+ const messages = context.messages.filter((message) => message.role !== "system");
261
+ const keys = messages.map(messageKey3);
262
+ const tools = getCurrentTools(context.messages).filter((tool) => !CLAUDE_CODE_HAS_ITS_OWN.has(tool.name));
263
+ let session = sessions.get(id);
264
+ const continues = session !== undefined && !session.closed && !session.asking && session.key === key && session.known.length < keys.length && session.known.every((known, index) => keys[index] === known);
265
+ const prompt = messages.slice(messages.findLastIndex((message) => message.role !== "user") + 1);
266
+ if (!continues) {
267
+ session?.close();
268
+ if (prompt.length === 0)
269
+ throw new Error(NOT_RUNNING);
270
+ await processEnvironment();
271
+ const claudeSession = randomUUID();
272
+ session = new ClaudeCodeSession2({
273
+ key,
274
+ model: model.id,
275
+ cwd: binding.cwd,
276
+ thinking: options?.reasoning !== undefined,
277
+ effort,
278
+ ultracode,
279
+ env: options?.env,
280
+ session: claudeSession,
281
+ history: sessionEntries2(messages.slice(0, -prompt.length), {
282
+ session: claudeSession,
283
+ model: model.id,
284
+ cwd: binding.cwd
285
+ }),
286
+ tools,
287
+ query: start,
288
+ approve: binding.approve
289
+ });
290
+ sessions.set(id, session);
291
+ }
292
+ if (session === undefined)
293
+ throw new Error(NOT_RUNNING);
294
+ session.expose(tools);
295
+ session.deliver(messages);
296
+ await session.configure(effort, ultracode);
297
+ if (prompt.length > 0)
298
+ session.send(prompt.flatMap((message) => message.role === "user" ? userBlocks3(message) : []));
299
+ const live = session;
300
+ const stream = live.respond(model, options?.signal);
301
+ stream.result().then((message) => {
302
+ live.known = message.stopReason === "error" || message.stopReason === "aborted" ? [] : [...keys, messageKey3(message)];
303
+ });
304
+ return stream;
305
+ }
306
+ const stream = (model, context, options) => getCurrentTools(context.messages).length === 0 ? answerOnce(start, model, context, options) : lazyStream(model, () => respond(model, context, options));
307
+ const provider = {
308
+ id: CLAUDE_CODE_PROVIDER2,
309
+ name: "Claude Code",
310
+ baseUrl: "process://claude-code",
311
+ capabilities: { steer: true },
312
+ auth: {
313
+ apiKey: {
314
+ name: "Claude Code login",
315
+ resolve: async ({ signal }) => {
316
+ signal.throwIfAborted();
317
+ return await claudeCodeConfigured() ? { auth: {}, source: "Claude Code login" } : undefined;
318
+ }
319
+ }
320
+ },
321
+ getModels: () => catalog.getModels().map(({ compat: _compat, ...model }) => ({
322
+ ...model,
323
+ provider: CLAUDE_CODE_PROVIDER2,
324
+ api: API,
325
+ baseUrl: "process://claude-code"
326
+ })),
327
+ refreshModels: async (context) => {
328
+ await catalog.refreshModels?.(context);
329
+ },
330
+ stream: (model, context, options) => stream(model, context, {
331
+ signal: options?.signal,
332
+ sessionId: options?.sessionId,
333
+ env: options?.env
334
+ }),
335
+ streamSimple: stream
336
+ };
337
+ const plugin = {
338
+ id: "claude-code-sdk",
339
+ contribute: { tools: [mirrorTool(sessions)], settings: [ultracodeSetting] },
340
+ activate(api) {
341
+ const id = api.session.id;
342
+ const binding = {
343
+ cwd: api.env.cwd,
344
+ ultracode: async () => await api.contribute.settings.value(ultracodeSetting.id) === true,
345
+ approve: async (name, input, signal) => {
346
+ const verdict = await api.approve({ name, class: classifyClaudeTool(name, input) }, signal);
347
+ return verdict.kind === "allow" ? { behavior: "allow" } : { behavior: "deny", message: verdict.reason };
348
+ }
349
+ };
350
+ const release = acquireSessionResources(id);
351
+ bindings.set(id, binding);
352
+ const unbind = () => {
353
+ if (bindings.get(id) === binding)
354
+ bindings.delete(id);
355
+ release();
356
+ };
357
+ if (api.signal.aborted)
358
+ unbind();
359
+ else
360
+ api.signal.addEventListener("abort", unbind, { once: true });
361
+ }
362
+ };
363
+ return { provider, plugin };
364
+ }
365
+ export {
366
+ claudeCodeSdk,
367
+ ultracodeSetting
368
+ };
@@ -0,0 +1,48 @@
1
+ import type { CanUseTool, EffortLevel, PermissionResult, Query, SDKMessage, SessionStoreEntry, query } from "@anthropic-ai/claude-agent-sdk";
2
+ import type { Api, AssistantMessageEventStream, Message, Model, Tool } from "@nyte-ai/ai";
3
+ import type { ContentBlock } from "./transcript.ts";
4
+ interface Launch {
5
+ readonly key: string;
6
+ readonly model: string;
7
+ readonly cwd: string;
8
+ readonly thinking: boolean;
9
+ readonly effort: EffortLevel | undefined;
10
+ readonly ultracode: boolean;
11
+ readonly env: Record<string, string | undefined> | undefined;
12
+ readonly session: string;
13
+ readonly history: readonly SessionStoreEntry[];
14
+ readonly tools: readonly Tool[];
15
+ readonly query: StartQuery;
16
+ readonly approve: Approve;
17
+ }
18
+ /** Decides a call Claude Code asks to run under Nyte's permissions policy, by the tool's own name. */
19
+ export type Approve = (name: string, input: Parameters<CanUseTool>[1], signal: AbortSignal) => Promise<PermissionResult>;
20
+ /** Starts Claude Code: the Agent SDK's `query`, or a stand-in with the parts of its `Query` a session uses. */
21
+ export type StartQuery = (params: Parameters<typeof query>[0]) => AsyncIterable<SDKMessage> & Pick<Query, "applyFlagSettings" | "close">;
22
+ export type QuestionAnswers = Record<string, string> | null;
23
+ interface ClaudeToolOutput {
24
+ readonly text: string;
25
+ readonly isError: boolean;
26
+ }
27
+ export declare class ClaudeCodeSession {
28
+ #private;
29
+ readonly key: string;
30
+ known: readonly string[];
31
+ constructor(launch: Launch);
32
+ get closed(): boolean;
33
+ configure(effort: EffortLevel | undefined, ultracode: boolean): Promise<void>;
34
+ /** Serves `tools` as the Nyte MCP server's tools from now on, telling Claude Code when they changed. */
35
+ expose(tools: readonly Tool[]): void;
36
+ /** Answers Claude Code from Nyte's tool results: a Nyte tool call gets its result, and a call Claude Code asked to run but Nyte settled without running it is denied with that result. */
37
+ deliver(messages: readonly Message[]): void;
38
+ /** Lets Claude Code's call `id` go on to its approval now that Nyte records it (so the workspace snapshot before it is taken), and denies the calls before it in the same message that Nyte settled without running. */
39
+ recording(id: string): void;
40
+ send(content: readonly ContentBlock[]): void;
41
+ respond(model: Model<Api>, signal: AbortSignal | undefined): AssistantMessageEventStream;
42
+ get asking(): boolean;
43
+ answer(id: string, answers: QuestionAnswers): void;
44
+ result(id: string, signal: AbortSignal): Promise<ClaudeToolOutput>;
45
+ background(signal: AbortSignal): Promise<string>;
46
+ close(reason?: Error): void;
47
+ }
48
+ export {};
@@ -0,0 +1,7 @@
1
+ import {
2
+ ClaudeCodeSession2
3
+ } from "../../chunks/billing-wmkxkypm.js";
4
+ import"../../chunks/billing-ye3wk5r3.js";
5
+ export {
6
+ ClaudeCodeSession2 as ClaudeCodeSession
7
+ };
@@ -0,0 +1,19 @@
1
+ import type { SDKUserMessage, SessionStoreEntry } from "@anthropic-ai/claude-agent-sdk";
2
+ import type { Message, UserMessage } from "@nyte-ai/ai";
3
+ import { Type } from "typebox";
4
+ type MessageParam = SDKUserMessage["message"];
5
+ export type ContentBlock = Exclude<MessageParam["content"], string>[number];
6
+ export declare const mirrorArguments: Type.TObject<{
7
+ id: Type.TString;
8
+ name: Type.TString;
9
+ input: Type.TRecord<"^.*$", Type.TUnknown>;
10
+ }>;
11
+ export declare function userBlocks(message: UserMessage): ContentBlock[];
12
+ export declare function messageKey(message: Message): string;
13
+ export declare function sessionEntries(messages: readonly Message[], input: {
14
+ readonly session: string;
15
+ readonly model: string;
16
+ readonly cwd: string;
17
+ }): SessionStoreEntry[];
18
+ export declare function flatPrompt(messages: readonly Message[]): string;
19
+ export {};
@@ -0,0 +1,15 @@
1
+ import {
2
+ mirrorArguments3,
3
+ userBlocks3,
4
+ messageKey3,
5
+ sessionEntries2,
6
+ flatPrompt2
7
+ } from "../../chunks/billing-2v3g7rd9.js";
8
+ import"../../chunks/billing-ye3wk5r3.js";
9
+ export {
10
+ flatPrompt2 as flatPrompt,
11
+ messageKey3 as messageKey,
12
+ mirrorArguments3 as mirrorArguments,
13
+ sessionEntries2 as sessionEntries,
14
+ userBlocks3 as userBlocks
15
+ };
@@ -0,0 +1,18 @@
1
+ import type { SDKPartialAssistantMessage } from "@anthropic-ai/claude-agent-sdk";
2
+ import type { Api, AssistantMessage, AssistantMessageEventStream, Model, ToolCall } from "@nyte-ai/ai";
3
+ type StreamEvent = SDKPartialAssistantMessage["event"];
4
+ export declare const CLAUDE_CODE_PROVIDER = "claude-code";
5
+ export declare const MIRROR_TOOL = "claude_code";
6
+ export declare const BACKGROUND_TOOL = "BackgroundTasks";
7
+ export declare const NYTE_SERVER = "nyte";
8
+ export declare const NYTE_TOOL_PREFIX = "mcp__nyte__";
9
+ export declare function emptyMessage(model: Model<Api>): AssistantMessage;
10
+ export declare function mirrorCall(id: string, name: string, input: Record<string, unknown>): ToolCall;
11
+ export declare class Translator {
12
+ #private;
13
+ constructor(model: Model<Api>, output: AssistantMessage, stream: AssistantMessageEventStream);
14
+ /** Applies one stream event. Returns the raw stop reason at a message's end, and `"tool_use"` as soon as a Nyte tool call's input is complete: Claude Code waits for Nyte to run it before it runs the message's later calls. */
15
+ apply(event: StreamEvent): string | undefined;
16
+ append(call: ToolCall): void;
17
+ }
18
+ export {};
@@ -0,0 +1,20 @@
1
+ import {
2
+ CLAUDE_CODE_PROVIDER2,
3
+ MIRROR_TOOL3,
4
+ BACKGROUND_TOOL2,
5
+ NYTE_SERVER2,
6
+ NYTE_TOOL_PREFIX2,
7
+ emptyMessage3,
8
+ mirrorCall2,
9
+ Translator3
10
+ } from "../../chunks/billing-ye3wk5r3.js";
11
+ export {
12
+ BACKGROUND_TOOL2 as BACKGROUND_TOOL,
13
+ CLAUDE_CODE_PROVIDER2 as CLAUDE_CODE_PROVIDER,
14
+ MIRROR_TOOL3 as MIRROR_TOOL,
15
+ NYTE_SERVER2 as NYTE_SERVER,
16
+ NYTE_TOOL_PREFIX2 as NYTE_TOOL_PREFIX,
17
+ Translator3 as Translator,
18
+ emptyMessage3 as emptyMessage,
19
+ mirrorCall2 as mirrorCall
20
+ };
@@ -0,0 +1,44 @@
1
+ import type { Connection, Session } from "@nyte-ai/core";
2
+ import type { Decision, Placement, SessionInfo, SubmitDraft } from "@nyte-ai/schema";
3
+ import type { Plugin, PluginApi } from "../client.ts";
4
+ import type { PartMessage } from "./presentation.ts";
5
+ type Notification = Parameters<PluginApi["ui"]["notify"]>[0];
6
+ /**
7
+ * What a client hands the plugins it mounts: its connection, the frameworks
8
+ * it draws, the session on screen, and where notices and plugin errors go.
9
+ *
10
+ * @category plugins
11
+ */
12
+ export interface MountOptions {
13
+ readonly connection: Connection;
14
+ readonly plugins: readonly Plugin[];
15
+ readonly client: PluginApi["client"];
16
+ readonly session: () => Session | null;
17
+ readonly notify: (input: Notification) => void;
18
+ readonly report: (plugin: string, message: string) => void;
19
+ }
20
+ /**
21
+ * The mounted client plugins: their renderers and the hooks a client fires.
22
+ *
23
+ * @category plugins
24
+ */
25
+ export interface ClientPlugins {
26
+ readonly ids: readonly string[];
27
+ /** The view a plugin renderer draws for a part, or undefined when none draws its kind. */
28
+ draw(session: Session, message: PartMessage, placement: Placement): unknown;
29
+ /** Feeds the session directory; each run that ends after the first list fires `run_ended_anywhere`. */
30
+ sessionsChanged(sessions: readonly SessionInfo[]): void;
31
+ switched(previous: Session | null, next: Session): Promise<void>;
32
+ beforeSubmit(draft: SubmitDraft): Promise<Decision<SubmitDraft>>;
33
+ dispose(): Promise<void>;
34
+ }
35
+ /**
36
+ * Activates client plugins once per app, all at once: their registries, hooks
37
+ * and the first renderer per part kind, in plugin order, among the frameworks
38
+ * the client draws. A plugin whose activation fails is reported and the rest
39
+ * still mount.
40
+ *
41
+ * @category plugins
42
+ */
43
+ export declare function mountClientPlugins(options: MountOptions): Promise<ClientPlugins>;
44
+ export {};