@nyte-ai/plugin 0.0.25-beta.1 → 0.0.25-nightly.20261101.40

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 (88) hide show
  1. package/THIRD-PARTY-NOTICES.md +49 -32
  2. package/dist/chunks/bash-description-0ah30s12.js +33 -0
  3. package/dist/chunks/bash-description-4h0hnsv4.js +68 -0
  4. package/dist/chunks/{bash-description-dnvgk30y.js → bash-description-4rfavmha.js} +32 -1
  5. package/dist/chunks/bash-description-5dpf5hpt.js +724 -0
  6. package/dist/chunks/{bash-description-yyd9jznf.js → bash-description-94km1hm2.js} +1 -1
  7. package/dist/chunks/{bash-description-svrhh5a5.js → bash-description-99k8z2r7.js} +3 -2
  8. package/dist/chunks/bash-description-9gw9ets8.js +162 -0
  9. package/dist/chunks/{bash-description-h13r0byk.js → bash-description-axnga0jz.js} +3 -3
  10. package/dist/chunks/bash-description-b78pre8c.js +147 -0
  11. package/dist/chunks/{bash-description-ye3wk5r3.js → bash-description-bas41ptb.js} +6 -24
  12. package/dist/chunks/{bash-description-2v3g7rd9.js → bash-description-bj5yh7tr.js} +26 -64
  13. package/dist/chunks/{bash-description-6z2kgtyt.js → bash-description-bkhr9zrz.js} +4 -4
  14. package/dist/chunks/{bash-description-hg64tqf1.js → bash-description-f754ge33.js} +49 -3
  15. package/dist/chunks/{bash-description-zz15raxk.js → bash-description-ff18794t.js} +1 -1
  16. package/dist/chunks/{bash-description-wmcbg6fw.js → bash-description-g7gfy7nw.js} +1 -1
  17. package/dist/chunks/{bash-description-1neewp76.js → bash-description-hp4rb8k4.js} +4 -3
  18. package/dist/chunks/bash-description-myvnmtt2.js +125 -0
  19. package/dist/chunks/{bash-description-9nn3yp18.js → bash-description-q2v8wbn8.js} +9 -1
  20. package/dist/chunks/bash-description-qwyy182r.js +452 -0
  21. package/dist/chunks/bash-description-rxpx004v.js +295 -0
  22. package/dist/chunks/{bash-description-eqp7ap2w.js → bash-description-z1581a29.js} +23 -9
  23. package/dist/src/acp/connection.d.ts +3 -1
  24. package/dist/src/acp/connection.js +3 -3
  25. package/dist/src/acp/index.d.ts +7 -4
  26. package/dist/src/acp/index.js +41 -8
  27. package/dist/src/acp/registry.d.ts +9 -0
  28. package/dist/src/acp/registry.js +5 -3
  29. package/dist/src/acp/thread.js +2 -2
  30. package/dist/src/acp/transcript.js +2 -2
  31. package/dist/src/acp/translate.d.ts +10 -2
  32. package/dist/src/acp/translate.js +3 -1
  33. package/dist/src/approvals/approvals.d.ts +1 -1
  34. package/dist/src/approvals/approvals.js +2 -2
  35. package/dist/src/approvals/schema.d.ts +3 -3
  36. package/dist/src/approvals/schema.js +1 -1
  37. package/dist/src/browser-tools.js +8 -2
  38. package/dist/src/canvas/canvas-compile.js +2 -2
  39. package/dist/src/canvas/canvas-preview.js +2 -2
  40. package/dist/src/canvas/canvas-protocol.d.ts +46 -0
  41. package/dist/src/canvas/canvas-protocol.js +11 -1
  42. package/dist/src/canvas/canvas.d.ts +17 -3
  43. package/dist/src/canvas/canvas.js +75 -31
  44. package/dist/src/canvas/schema.d.ts +28 -7
  45. package/dist/src/canvas/schema.js +2 -2
  46. package/dist/src/claude-code-sdk/index.d.ts +0 -10
  47. package/dist/src/claude-code-sdk/index.js +19 -179
  48. package/dist/src/claude-code-sdk/session.d.ts +22 -23
  49. package/dist/src/claude-code-sdk/session.js +6 -3
  50. package/dist/src/claude-code-sdk/transcript.d.ts +0 -6
  51. package/dist/src/claude-code-sdk/transcript.js +2 -4
  52. package/dist/src/claude-code-sdk/translate.d.ts +1 -5
  53. package/dist/src/claude-code-sdk/translate.js +2 -8
  54. package/dist/src/client/mount.d.ts +4 -2
  55. package/dist/src/client/mount.js +3 -0
  56. package/dist/src/client/notifications.d.ts +12 -4
  57. package/dist/src/client/notifications.js +25 -10
  58. package/dist/src/client/presentation.d.ts +138 -8
  59. package/dist/src/client/presentation.js +86 -371
  60. package/dist/src/codemode.js +151 -46
  61. package/dist/src/core.d.ts +1 -1
  62. package/dist/src/question/client/questions-tui.js +3 -3
  63. package/dist/src/question/client/questions.js +3 -3
  64. package/dist/src/question/question.js +84 -5
  65. package/dist/src/question/schema.js +3 -3
  66. package/dist/src/rename.d.ts +7 -35
  67. package/dist/src/rename.js +115 -48
  68. package/dist/src/subagents.d.ts +30 -0
  69. package/dist/src/subagents.js +323 -0
  70. package/dist/src/tool-search.d.ts +49 -0
  71. package/dist/src/tool-search.js +14 -0
  72. package/dist/src/web/body.d.ts +3 -0
  73. package/dist/src/web/body.js +6 -0
  74. package/dist/src/web/fetch.d.ts +16 -0
  75. package/dist/src/web/fetch.js +8 -0
  76. package/dist/src/web/html-markdown.d.ts +9 -0
  77. package/dist/src/web/html-markdown.js +10 -0
  78. package/dist/src/web/index.d.ts +24 -0
  79. package/dist/src/web/index.js +93 -0
  80. package/dist/src/web/providers.d.ts +60 -0
  81. package/dist/src/web/providers.js +11 -0
  82. package/dist/src/web/search.d.ts +21 -0
  83. package/dist/src/web/search.js +6 -0
  84. package/package.json +16 -7
  85. package/dist/chunks/bash-description-3j77ss7y.js +0 -86
  86. package/dist/chunks/bash-description-wbe8w0te.js +0 -530
  87. package/dist/src/web-search.d.ts +0 -78
  88. package/dist/src/web-search.js +0 -219
@@ -4,7 +4,7 @@ import {
4
4
  initializeResult2,
5
5
  renderNotification2,
6
6
  clampCanvasHeight2
7
- } from "./bash-description-dnvgk30y.js";
7
+ } from "./bash-description-4rfavmha.js";
8
8
 
9
9
  // src/canvas/canvas-preview.ts
10
10
  import { Type } from "typebox";
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  MIRROR_TOOL2,
3
+ agentUsage2,
3
4
  emptyMessage2,
4
5
  mirrorClass2,
5
6
  toolText2,
6
7
  Translator2
7
- } from "./bash-description-9nn3yp18.js";
8
+ } from "./bash-description-q2v8wbn8.js";
8
9
 
9
10
  // src/acp/thread.ts
10
11
  import { posix } from "node:path";
@@ -168,7 +169,7 @@ class AcpThread2 {
168
169
  reason = "toolUse";
169
170
  } else {
170
171
  translator.end();
171
- if (event.response.usage !== undefined && event.response.usage !== null)
172
+ if (Value.Check(agentUsage2, event.response.usage))
172
173
  translator.usage(event.response.usage);
173
174
  output.rawStopReason = event.response.stopReason;
174
175
  const mapped = stopReason(event.response);
@@ -0,0 +1,162 @@
1
+ import {
2
+ readCapped2
3
+ } from "./bash-description-0ah30s12.js";
4
+
5
+ // src/web/providers.ts
6
+ import { Type } from "typebox";
7
+ import { Value } from "typebox/value";
8
+ var PROVIDERS2 = [
9
+ { id: "exa", name: "Exa" },
10
+ { id: "tavily", name: "Tavily" },
11
+ { id: "firecrawl", name: "Firecrawl" },
12
+ { id: "parallel", name: "Parallel" }
13
+ ];
14
+ var MAX_RESPONSE_BYTES = 256 * 1024;
15
+ var textBlocks = Type.Object({
16
+ content: Type.Array(Type.Object({ type: Type.String(), text: Type.Optional(Type.String()) }))
17
+ });
18
+ var tavilyResponse = Type.Object({
19
+ results: Type.Array(Type.Object({ url: Type.String(), title: Type.String(), content: Type.String() }))
20
+ });
21
+ var firecrawlResponse = Type.Object({
22
+ data: Type.Object({
23
+ web: Type.Array(Type.Object({
24
+ url: Type.String(),
25
+ title: Type.Optional(Type.Union([Type.String(), Type.Null()])),
26
+ description: Type.Optional(Type.Union([Type.String(), Type.Null()]))
27
+ }))
28
+ })
29
+ });
30
+ var parallelResponse = Type.Object({
31
+ structuredContent: Type.Object({
32
+ results: Type.Array(Type.Object({
33
+ url: Type.String(),
34
+ title: Type.Optional(Type.Union([Type.String(), Type.Null()])),
35
+ publish_date: Type.Optional(Type.Union([Type.String(), Type.Null()])),
36
+ excerpts: Type.Array(Type.String())
37
+ }))
38
+ })
39
+ });
40
+ var adapters2 = {
41
+ async tavily({ query, key, fetch, signal }) {
42
+ const response = await fetch("https://api.tavily.com/search", {
43
+ method: "POST",
44
+ headers: {
45
+ "Content-Type": "application/json",
46
+ ...key === undefined ? { "X-Tavily-Access-Mode": "keyless" } : { Authorization: `Bearer ${key}` }
47
+ },
48
+ body: JSON.stringify({ query, search_depth: "basic", max_results: 8 }),
49
+ signal
50
+ });
51
+ const body = parse(await answered(response, "tavily"));
52
+ return Value.Check(tavilyResponse, body) ? body.results.map((hit) => ({ url: hit.url, title: hit.title, content: hit.content })) : [];
53
+ },
54
+ async exa({ query, key, fetch, signal }) {
55
+ const endpoint = new URL("https://mcp.exa.ai/mcp");
56
+ if (key !== undefined)
57
+ endpoint.searchParams.set("exaApiKey", key);
58
+ const result = await callTool(fetch, endpoint, "exa", undefined, "web_search_exa", {
59
+ query,
60
+ numResults: 8
61
+ }, signal);
62
+ const text = Value.Check(textBlocks, result) ? result.content.find((block) => block.text !== undefined)?.text ?? "" : "";
63
+ return text.split(/\n\n---\n\n/).flatMap((block) => {
64
+ const url = field(block, "URL");
65
+ const published = field(block, "Published");
66
+ return url === undefined ? [] : [
67
+ {
68
+ url,
69
+ title: field(block, "Title"),
70
+ content: block.match(/^(?:Highlights|Text):\s*\n?([\s\S]*)$/m)?.[1]?.trim(),
71
+ published: published === undefined ? undefined : Date.parse(published)
72
+ }
73
+ ];
74
+ });
75
+ },
76
+ async firecrawl({ query, key, fetch, signal }) {
77
+ const result = await callTool(fetch, new URL("https://mcp.firecrawl.dev/v2/mcp"), "firecrawl", key, "firecrawl_search", { query, limit: 8 }, signal);
78
+ const text = Value.Check(textBlocks, result) ? result.content.find((block) => block.text !== undefined)?.text ?? "" : "";
79
+ const body = parse(text);
80
+ return Value.Check(firecrawlResponse, body) ? body.data.web.map((hit) => ({
81
+ url: hit.url,
82
+ title: hit.title ?? undefined,
83
+ content: hit.description ?? undefined
84
+ })) : [];
85
+ },
86
+ async parallel({ query, key, fetch, signal }) {
87
+ const result = await callTool(fetch, new URL("https://search.parallel.ai/mcp"), "parallel", key, "web_search", { objective: query, search_queries: [query] }, signal);
88
+ return Value.Check(parallelResponse, result) ? result.structuredContent.results.map((hit) => ({
89
+ url: hit.url,
90
+ title: hit.title ?? undefined,
91
+ content: hit.excerpts.length === 0 ? undefined : hit.excerpts.join(`
92
+
93
+ `),
94
+ published: hit.publish_date === undefined || hit.publish_date === null ? undefined : Date.parse(hit.publish_date)
95
+ })) : [];
96
+ }
97
+ };
98
+ function shippedProviders2(fetch, key) {
99
+ return PROVIDERS2.map((provider) => ({
100
+ id: provider.id,
101
+ name: provider.name,
102
+ search: async (input) => adapters2[provider.id]({
103
+ query: input.query,
104
+ key: await key(provider.id),
105
+ fetch,
106
+ signal: input.signal
107
+ })
108
+ }));
109
+ }
110
+ async function callTool(fetch, url, provider, key, tool, args, signal) {
111
+ const response = await fetch(url, {
112
+ method: "POST",
113
+ headers: {
114
+ Accept: "application/json, text/event-stream",
115
+ "Content-Type": "application/json",
116
+ ...key === undefined ? {} : { Authorization: `Bearer ${key}` }
117
+ },
118
+ body: JSON.stringify({
119
+ jsonrpc: "2.0",
120
+ id: 1,
121
+ method: "tools/call",
122
+ params: { name: tool, arguments: args }
123
+ }),
124
+ signal
125
+ });
126
+ const body = await answered(response, provider);
127
+ const frames = [
128
+ body,
129
+ ...body.split(`
130
+ `).flatMap((line) => line.startsWith("data: ") ? [line.slice(6)] : [])
131
+ ];
132
+ for (const frame of frames) {
133
+ const message = parse(frame);
134
+ if (typeof message === "object" && message !== null && "result" in message)
135
+ return message.result;
136
+ }
137
+ return;
138
+ }
139
+ async function answered(response, provider) {
140
+ const body = new TextDecoder().decode(await readCapped2(response, MAX_RESPONSE_BYTES));
141
+ const name = PROVIDERS2.find((known) => known.id === provider)?.name ?? provider;
142
+ if (response.status === 401)
143
+ throw new Error(`${name} refused the search (HTTP 401). Set a key with /websearch-key ${provider} <key>.`);
144
+ if (response.status === 429)
145
+ throw new Error(`${name} is rate limiting searches (HTTP 429). Try again later, or set a key with /websearch-key ${provider} <key>.`);
146
+ if (!response.ok)
147
+ throw new Error(`HTTP ${response.status}: ${body.trim().slice(0, 200) || response.statusText}`);
148
+ return body;
149
+ }
150
+ function parse(text) {
151
+ try {
152
+ return JSON.parse(text);
153
+ } catch {
154
+ return;
155
+ }
156
+ }
157
+ function field(block, name) {
158
+ const value = block.match(new RegExp(`^${name}:\\s*(.+)$`, "m"))?.[1]?.trim();
159
+ return value === undefined || value === "" || value === "N/A" ? undefined : value;
160
+ }
161
+
162
+ export { PROVIDERS2, adapters2, shippedProviders2 };
@@ -5,13 +5,13 @@ var policy = standard(Type.Union([Type.Literal("ask"), Type.Literal("auto-edit")
5
5
  var PERMISSIONS2 = "permissions";
6
6
  var approvalPolicy2 = policy;
7
7
  var APPROVAL_POLICIES2 = [
8
- { value: "ask", label: "Ask first", description: "Asks before every command and file change" },
8
+ { value: "ask", label: "Ask first", badge: "Asks before commands, file edits and other tools" },
9
9
  {
10
10
  value: "auto-edit",
11
11
  label: "Auto-edit",
12
- description: "Edits workspace files, asks before commands and anything outside"
12
+ badge: "Edits workspace files, asks before commands and other tools"
13
13
  },
14
- { value: "full", label: "Full access", description: "Runs every tool without asking" }
14
+ { value: "full", label: "Full access", badge: "Runs every tool without asking" }
15
15
  ];
16
16
  var reasonType = Type.Union([
17
17
  Type.Literal("shell"),
@@ -0,0 +1,147 @@
1
+ // src/tool-search.ts
2
+ import { isJsonObject, standard } from "@nyte-ai/schema";
3
+ import { Type } from "typebox";
4
+ var DEFAULT_SEARCH_LIMIT2 = 8;
5
+ var STOP_WORDS = new Set([
6
+ "a",
7
+ "an",
8
+ "and",
9
+ "are",
10
+ "as",
11
+ "at",
12
+ "be",
13
+ "by",
14
+ "for",
15
+ "from",
16
+ "in",
17
+ "is",
18
+ "it",
19
+ "of",
20
+ "on",
21
+ "or",
22
+ "that",
23
+ "the",
24
+ "this",
25
+ "to",
26
+ "with"
27
+ ]);
28
+ var K1 = 1.2;
29
+ var B = 0.75;
30
+ var DESCRIPTION = `Searches over deferred tool metadata with BM25 and exposes matching tools for the next model call.
31
+
32
+ Some of the tools, such as tools of MCP servers, may not have been provided to you upfront, and you should use this tool (\`tool_search\`) to search for the required tools. For MCP tool discovery, always use \`tool_search\`.`;
33
+ var parameters = standard(Type.Object({
34
+ query: Type.String({ description: "Search query for deferred tools." }),
35
+ limit: Type.Optional(Type.Integer({
36
+ minimum: 1,
37
+ description: `Maximum number of tools to return. Defaults to ${DEFAULT_SEARCH_LIMIT2}.`
38
+ }))
39
+ }));
40
+ var output = standard(Type.Object({ loaded: Type.Array(Type.String()) }));
41
+ var tool_search_default = {
42
+ id: "tool-search",
43
+ activate(api) {
44
+ const namespaces = () => new Map(api.contribute.tools.list().flatMap((definition) => definition.namespace === undefined ? [] : [[definition.name, definition.namespace]]));
45
+ const search = {
46
+ name: "tool_search",
47
+ description: DESCRIPTION,
48
+ parameters,
49
+ output,
50
+ exposure: "model-only",
51
+ class: () => ({ kind: "custom", label: "Searching tools" }),
52
+ effects: "none",
53
+ approval: "never",
54
+ replay: "safe",
55
+ loads: (result) => result.loaded,
56
+ async execute(args, invocation) {
57
+ if (args.query.trim() === "")
58
+ throw new Error("query must not be empty");
59
+ const loaded = new Set(await invocation.tools.loaded());
60
+ const found = namespaces();
61
+ const candidates = invocation.tools.list().filter((info) => (info.exposure === "code" || info.exposure === "deferred") && !loaded.has(info.name));
62
+ const names = rankTools2(args.query, candidates.map((info) => createToolSearchDocument2(info, found.get(info.name))), args.limit ?? DEFAULT_SEARCH_LIMIT2);
63
+ const lines = names.map((name) => {
64
+ const [line = ""] = (candidates.find((info) => info.name === name)?.description ?? "").trim().split(/\r?\n/);
65
+ return `- ${name}: ${line}`;
66
+ });
67
+ return {
68
+ content: [
69
+ {
70
+ kind: "text",
71
+ text: names.length === 0 ? "No matching tools found." : `Loaded ${names.length} tool${names.length === 1 ? "" : "s"}. They are available from your next call:
72
+ ${lines.join(`
73
+ `)}`
74
+ }
75
+ ],
76
+ output: { loaded: [...names] }
77
+ };
78
+ }
79
+ };
80
+ api.contribute.tools.add(search);
81
+ api.hook("transform_transcript", (transcript) => {
82
+ const declared = new Set(transcript.tools.map((info) => info.name));
83
+ const pending = api.contribute.tools.list().some((definition) => definition.exposure === "deferred" && !declared.has(definition.name));
84
+ return pending ? transcript : { ...transcript, tools: transcript.tools.filter((info) => info.name !== search.name) };
85
+ });
86
+ }
87
+ };
88
+ function tokenize2(text) {
89
+ return text.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter((term) => term.length > 0 && !STOP_WORDS.has(term)).map(stem);
90
+ }
91
+ function stem(term) {
92
+ if (term.length > 4 && term.endsWith("ies"))
93
+ return `${term.slice(0, -3)}y`;
94
+ if (term.length > 4 && /(ches|shes|sses|xes|zes)$/.test(term))
95
+ return term.slice(0, -2);
96
+ if (term.length > 3 && term.endsWith("s") && !term.endsWith("ss"))
97
+ return term.slice(0, -1);
98
+ return term;
99
+ }
100
+ function createToolSearchDocument2(tool, namespace) {
101
+ const parts = [
102
+ tool.name,
103
+ tool.name.replaceAll("_", " "),
104
+ tool.description,
105
+ ...describeSchema(tool.parameters),
106
+ ...namespace === undefined ? [] : [namespace.name, namespace.description ?? "", namespace.instructions ?? ""]
107
+ ];
108
+ return { name: tool.name, text: parts.filter((part) => part.trim() !== "").join(" ") };
109
+ }
110
+ function describeSchema(schema) {
111
+ if (schema === undefined || !isJsonObject(schema))
112
+ return [];
113
+ const properties = isJsonObject(schema.properties) ? Object.entries(schema.properties) : [];
114
+ return [
115
+ ...typeof schema.description === "string" ? [schema.description] : [],
116
+ ...properties.flatMap(([name, property]) => [name, ...describeSchema(property)]),
117
+ ...describeSchema(schema.items),
118
+ ...["anyOf", "oneOf", "allOf"].flatMap((key) => {
119
+ const variants = schema[key];
120
+ return Array.isArray(variants) ? variants.flatMap(describeSchema) : [];
121
+ })
122
+ ];
123
+ }
124
+ function rankTools2(query, documents, limit) {
125
+ const terms = [...new Set(tokenize2(query))];
126
+ if (terms.length === 0 || documents.length === 0)
127
+ return [];
128
+ const indexed = documents.map((document) => {
129
+ const tokens = tokenize2(document.text);
130
+ return { name: document.name, length: tokens.length, counts: Map.groupBy(tokens, (t) => t) };
131
+ });
132
+ const average = indexed.reduce((sum, entry) => sum + entry.length, 0) / indexed.length || 1;
133
+ const idf = new Map(terms.map((term) => {
134
+ const frequency = indexed.filter((entry) => entry.counts.has(term)).length;
135
+ return [term, Math.log(1 + (indexed.length - frequency + 0.5) / (frequency + 0.5))];
136
+ }));
137
+ return indexed.map((entry) => ({
138
+ name: entry.name,
139
+ score: terms.reduce((score, term) => {
140
+ const count = entry.counts.get(term)?.length ?? 0;
141
+ const norm = K1 * (1 - B + B * entry.length / average);
142
+ return score + (idf.get(term) ?? 0) * (count * (K1 + 1)) / (count + norm);
143
+ }, 0)
144
+ })).filter((match) => match.score > 0).toSorted((left, right) => right.score - left.score).slice(0, limit).map((match) => match.name);
145
+ }
146
+
147
+ export { DEFAULT_SEARCH_LIMIT2, tool_search_default, tokenize2, createToolSearchDocument2, rankTools2 };
@@ -1,8 +1,6 @@
1
1
  // src/claude-code-sdk/translate.ts
2
2
  import { calculateCost, parseStreamingJson } from "@nyte-ai/ai";
3
3
  var CLAUDE_CODE_PROVIDER2 = "claude-code";
4
- var MIRROR_TOOL3 = "claude_code";
5
- var BACKGROUND_TOOL2 = "BackgroundTasks";
6
4
  var NYTE_SERVER2 = "nyte";
7
5
  var NYTE_TOOL_PREFIX2 = `mcp__${NYTE_SERVER2}__`;
8
6
  function emptyMessage3(model) {
@@ -24,9 +22,6 @@ function emptyMessage3(model) {
24
22
  timestamp: Date.now()
25
23
  };
26
24
  }
27
- function mirrorCall2(id, name, input) {
28
- return { type: "toolCall", id, name: MIRROR_TOOL3, arguments: { id, name, input } };
29
- }
30
25
  function stopReason(reason) {
31
26
  if (reason === "tool_use")
32
27
  return "toolUse";
@@ -85,16 +80,6 @@ class Translator3 {
85
80
  return;
86
81
  }
87
82
  }
88
- append(call) {
89
- const contentIndex = this.#output.content.push(call) - 1;
90
- this.#stream.push({ type: "toolcall_start", contentIndex, partial: this.#output });
91
- this.#stream.push({
92
- type: "toolcall_end",
93
- contentIndex,
94
- toolCall: call,
95
- partial: this.#output
96
- });
97
- }
98
83
  #usage(usage) {
99
84
  const usageOutput = this.#output.usage;
100
85
  if (this.#started) {
@@ -113,12 +98,12 @@ class Translator3 {
113
98
  thinking: "[Reasoning redacted]",
114
99
  thinkingSignature: block.data,
115
100
  redacted: true
116
- } : block.type === "tool_use" ? block.name.startsWith(NYTE_TOOL_PREFIX2) ? {
101
+ } : block.type === "tool_use" && block.name.startsWith(NYTE_TOOL_PREFIX2) ? {
117
102
  type: "toolCall",
118
103
  id: block.id,
119
104
  name: block.name.slice(NYTE_TOOL_PREFIX2.length),
120
105
  arguments: {}
121
- } : mirrorCall2(block.id, block.name, {}) : undefined;
106
+ } : undefined;
122
107
  if (content === undefined)
123
108
  return;
124
109
  const index = this.#output.content.push(content) - 1;
@@ -155,8 +140,7 @@ class Translator3 {
155
140
  content.thinkingSignature = (content.thinkingSignature ?? "") + delta.signature;
156
141
  } else if (delta.type === "input_json_delta" && content?.type === "toolCall") {
157
142
  slot.json += delta.partial_json;
158
- const input = parseStreamingJson(slot.json);
159
- content.arguments = content.name === MIRROR_TOOL3 ? { ...content.arguments, input } : input;
143
+ content.arguments = parseStreamingJson(slot.json);
160
144
  this.#stream.push({
161
145
  type: "toolcall_delta",
162
146
  contentIndex,
@@ -193,13 +177,11 @@ class Translator3 {
193
177
  toolCall: content,
194
178
  partial: this.#output
195
179
  });
196
- if (content.name !== MIRROR_TOOL3) {
197
- this.#output.stopReason = "toolUse";
198
- return "tool_use";
199
- }
180
+ this.#output.stopReason = "toolUse";
181
+ return "tool_use";
200
182
  }
201
183
  return;
202
184
  }
203
185
  }
204
186
 
205
- export { CLAUDE_CODE_PROVIDER2, MIRROR_TOOL3, BACKGROUND_TOOL2, NYTE_SERVER2, NYTE_TOOL_PREFIX2, emptyMessage3, mirrorCall2, Translator3 };
187
+ export { CLAUDE_CODE_PROVIDER2, NYTE_SERVER2, NYTE_TOOL_PREFIX2, emptyMessage3, Translator3 };
@@ -1,24 +1,13 @@
1
1
  import {
2
2
  CLAUDE_CODE_PROVIDER2,
3
- MIRROR_TOOL3,
4
- BACKGROUND_TOOL2,
5
3
  NYTE_TOOL_PREFIX2
6
- } from "./bash-description-ye3wk5r3.js";
4
+ } from "./bash-description-bas41ptb.js";
7
5
 
8
6
  // src/claude-code-sdk/transcript.ts
9
7
  import { randomUUID } from "node:crypto";
10
- import { Type } from "typebox";
11
- import { Value } from "typebox/value";
12
8
  var IMAGE_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp"];
13
- var mirrorArguments3 = Type.Object({
14
- id: Type.String(),
15
- name: Type.String(),
16
- input: Type.Record(Type.String(), Type.Unknown())
17
- });
18
- function readMirrorCall(call) {
19
- if (call.name !== MIRROR_TOOL3 || !Value.Check(mirrorArguments3, call.arguments))
20
- return;
21
- return call.arguments;
9
+ function toolUseId(id) {
10
+ return id.replaceAll(/[^a-zA-Z0-9_-]/g, "_");
22
11
  }
23
12
  function mediaBlock(content) {
24
13
  if (content.type === "text")
@@ -43,9 +32,7 @@ function messageKey3(message) {
43
32
  }
44
33
  function toParams(messages, model) {
45
34
  const params = [];
46
- const claude = new Map;
47
- const foreign = new Map;
48
- const skipped = new Set;
35
+ const open = new Set;
49
36
  const push = (role, content) => {
50
37
  if (content.length === 0)
51
38
  return;
@@ -56,38 +43,27 @@ function toParams(messages, model) {
56
43
  params.push({ role, content: [...content] });
57
44
  };
58
45
  const closeCalls = () => {
59
- push("user", [...claude.values()].map((id) => ({
46
+ push("user", [...open].map((id) => ({
60
47
  type: "tool_result",
61
- tool_use_id: id,
48
+ tool_use_id: toolUseId(id),
62
49
  content: "No result provided",
63
50
  is_error: true
64
51
  })));
65
- claude.clear();
52
+ open.clear();
66
53
  };
67
54
  for (const message of messages) {
68
55
  if (message.role === "system")
69
56
  continue;
70
57
  if (message.role === "toolResult") {
71
- const id = claude.get(message.toolCallId);
72
- const name = foreign.get(message.toolCallId);
73
- if (skipped.has(message.toolCallId))
74
- continue;
75
- if (id !== undefined) {
76
- claude.delete(message.toolCallId);
77
- push("user", [
78
- {
79
- type: "tool_result",
80
- tool_use_id: id,
81
- content: message.content.map(mediaBlock),
82
- is_error: message.isError
83
- }
84
- ]);
85
- } else {
86
- push("user", [
87
- { type: "text", text: `[${name ?? message.toolName} result]
88
- ${text(message.content)}` }
89
- ]);
90
- }
58
+ push("user", open.delete(message.toolCallId) ? [
59
+ {
60
+ type: "tool_result",
61
+ tool_use_id: toolUseId(message.toolCallId),
62
+ content: message.content.map(mediaBlock),
63
+ is_error: message.isError
64
+ }
65
+ ] : [{ type: "text", text: `[${message.toolName} result]
66
+ ${text(message.content)}` }]);
91
67
  continue;
92
68
  }
93
69
  closeCalls();
@@ -106,29 +82,15 @@ ${text(message.content)}` }
106
82
  return [];
107
83
  return block.redacted === true ? [{ type: "redacted_thinking", data: block.thinkingSignature }] : [{ type: "thinking", thinking: block.thinking, signature: block.thinkingSignature }];
108
84
  }
109
- const call = readMirrorCall(block);
110
- if (call?.name === BACKGROUND_TOOL2) {
111
- skipped.add(block.id);
112
- return [];
113
- }
114
- if (call !== undefined) {
115
- claude.set(block.id, call.id);
116
- return [{ type: "tool_use", id: call.id, name: call.name, input: call.input }];
117
- }
118
- if (message.provider === CLAUDE_CODE_PROVIDER2) {
119
- claude.set(block.id, block.id);
120
- return [
121
- {
122
- type: "tool_use",
123
- id: block.id,
124
- name: `${NYTE_TOOL_PREFIX2}${block.name}`,
125
- input: block.arguments
126
- }
127
- ];
128
- }
129
- foreign.set(block.id, block.name);
130
- return [{ type: "text", text: `[${block.name}]
131
- ${JSON.stringify(block.arguments)}` }];
85
+ open.add(block.id);
86
+ return [
87
+ {
88
+ type: "tool_use",
89
+ id: toolUseId(block.id),
90
+ name: `${NYTE_TOOL_PREFIX2}${block.name}`,
91
+ input: block.arguments
92
+ }
93
+ ];
132
94
  }));
133
95
  }
134
96
  closeCalls();
@@ -187,4 +149,4 @@ ${text(message.content)}` : "";
187
149
  `);
188
150
  }
189
151
 
190
- export { mirrorArguments3, userBlocks3, messageKey3, sessionEntries2, flatPrompt2 };
152
+ export { userBlocks3, messageKey3, sessionEntries2, flatPrompt2 };
@@ -25,7 +25,7 @@ var questionOutput2 = standard(Type.Object({ answers: Type.Union([answers, Type.
25
25
  var state = standard(Type.Object({ questions, answers: Type.Union([answers, Type.Null()]) }));
26
26
  var questionParameters2 = standard(Type.Object({ questions }));
27
27
  var actions = { answer: { input: answerInput2 } };
28
- var question3 = {
28
+ var question2 = {
29
29
  kind: "ask/question",
30
30
  state,
31
31
  actions,
@@ -39,13 +39,13 @@ Answered: ${current.answers[index].join(", ") || "Unanswered"}`}`).join(`
39
39
  };
40
40
  function openQuestions2(view) {
41
41
  return (view?.parts ?? []).flatMap((part) => {
42
- if (part.partKind !== question3.kind || part.status.kind !== "live")
42
+ if (part.partKind !== question2.kind || part.status.kind !== "live")
43
43
  return [];
44
- const checked = question3.state["~standard"].validate(part.state);
44
+ const checked = question2.state["~standard"].validate(part.state);
45
45
  if (checked instanceof Promise || checked.issues !== undefined || checked.value.answers !== null)
46
46
  return [];
47
47
  return [{ part: part.id, questions: checked.value.questions }];
48
48
  });
49
49
  }
50
50
 
51
- export { answerInput2, questionOutput2, questionParameters2, question3, openQuestions2 };
51
+ export { answerInput2, questionOutput2, questionParameters2, question2, openQuestions2 };
@@ -12,15 +12,26 @@ var launch = {
12
12
  args: Type.Optional(Type.Array(Type.String())),
13
13
  env: Type.Optional(Type.Record(Type.String(), Type.String()))
14
14
  };
15
+ var mode = Type.Optional(Type.String({ minLength: 1 }));
15
16
  var registryAgent = Type.Object({
16
17
  id: Type.String({ minLength: 1 }),
17
18
  name: Type.String({ minLength: 1 }),
19
+ mode,
18
20
  distribution: Type.Object({
19
21
  binary: Type.Optional(Type.Record(Type.String(), Type.Object({ cmd: Type.String({ minLength: 1 }), ...launch }))),
20
22
  npx: Type.Optional(Type.Object({ package: Type.String({ minLength: 1 }), ...launch }))
21
23
  })
22
24
  });
23
25
  var registry = Type.Object({ agents: Type.Array(Type.Unknown()) });
26
+ var userAgentsFile = Type.Object({
27
+ agents: Type.Array(Type.Object({
28
+ id: Type.String({ minLength: 1 }),
29
+ name: Type.String({ minLength: 1 }),
30
+ command: Type.String({ minLength: 1 }),
31
+ mode,
32
+ ...launch
33
+ }))
34
+ });
24
35
  var packageBin = Type.Object({
25
36
  bin: Type.Union([Type.String(), Type.Record(Type.String(), Type.String())])
26
37
  });
@@ -79,19 +90,54 @@ async function installed(agent, path) {
79
90
  name: agent.name,
80
91
  command,
81
92
  args: binary.args ?? [],
82
- env: binary.env ?? {}
93
+ env: binary.env ?? {},
94
+ mode: agent.mode
83
95
  };
84
96
  }
85
97
  const npx = agent.distribution.npx;
86
98
  if (npx === undefined)
87
99
  return;
88
100
  const command = await globalBin(npx.package, path);
89
- return command === undefined ? undefined : { id: agent.id, name: agent.name, command, args: npx.args ?? [], env: npx.env ?? {} };
101
+ return command === undefined ? undefined : {
102
+ id: agent.id,
103
+ name: agent.name,
104
+ command,
105
+ args: npx.args ?? [],
106
+ env: npx.env ?? {},
107
+ mode: agent.mode
108
+ };
90
109
  }
91
110
  async function installedAgents2(entries, path) {
92
111
  const agents = entries.filter((entry) => Value.Check(registryAgent, entry));
93
112
  const found = await Promise.all(agents.map((agent) => installed(agent, path)));
94
113
  return found.filter((agent) => agent !== undefined);
95
114
  }
115
+ async function userAgents2(file) {
116
+ const text = await readFile(file, "utf8").catch((error) => {
117
+ if (error instanceof Error && "code" in error && error.code === "ENOENT")
118
+ return;
119
+ throw error;
120
+ });
121
+ if (text === undefined)
122
+ return [];
123
+ let document;
124
+ try {
125
+ document = JSON.parse(text);
126
+ } catch (error) {
127
+ throw new Error(`${file} is not valid JSON.`, { cause: error });
128
+ }
129
+ if (!Value.Check(userAgentsFile, document)) {
130
+ const [first] = Value.Errors(userAgentsFile, document);
131
+ throw new Error(`${file}: ${first?.instancePath || "/"} ${first?.message ?? "is invalid"}.`);
132
+ }
133
+ return document.agents.map((agent) => ({
134
+ id: agent.id,
135
+ name: agent.name,
136
+ command: agent.command,
137
+ args: agent.args ?? [],
138
+ env: agent.env ?? {},
139
+ mode: agent.mode
140
+ }));
141
+ }
96
142
 
97
- export { registryEntries2, installedAgents2 };
143
+ export { registryEntries2, installedAgents2, userAgents2 };