@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,369 @@
1
+ import {
2
+ CANVAS_LIBRARIES2
3
+ } from "./billing-zfpm2rt0.js";
4
+
5
+ // src/canvas/canvas-protocol.ts
6
+ var CANVAS_RUNTIME2 = 2;
7
+ var CANVAS_GLOBAL2 = "__nyteCanvas";
8
+ var KIT_SPECIFIER2 = "nyte/canvas";
9
+ var CANVAS_ENTRY2 = "main.tsx";
10
+ var CANVAS_SOURCE_LIMIT2 = 65536;
11
+ var CANVAS_CODE_LIMIT2 = 196608;
12
+ var CANVAS_MIN_HEIGHT2 = 48;
13
+ var CANVAS_MAX_HEIGHT2 = 2000;
14
+ var CANVAS_MIN_HEIGHT_HINT2 = 80;
15
+ var CANVAS_DEFAULT_HEIGHT2 = 80;
16
+ var REACT_EXPORTS2 = [
17
+ "Activity",
18
+ "Children",
19
+ "Component",
20
+ "Fragment",
21
+ "Profiler",
22
+ "PureComponent",
23
+ "StrictMode",
24
+ "Suspense",
25
+ "ViewTransition",
26
+ "addTransitionType",
27
+ "cache",
28
+ "cloneElement",
29
+ "createContext",
30
+ "createElement",
31
+ "createRef",
32
+ "forwardRef",
33
+ "isValidElement",
34
+ "lazy",
35
+ "memo",
36
+ "startTransition",
37
+ "use",
38
+ "useActionState",
39
+ "useCallback",
40
+ "useContext",
41
+ "useDebugValue",
42
+ "useDeferredValue",
43
+ "useEffect",
44
+ "useEffectEvent",
45
+ "useId",
46
+ "useImperativeHandle",
47
+ "useInsertionEffect",
48
+ "useLayoutEffect",
49
+ "useMemo",
50
+ "useOptimistic",
51
+ "useReducer",
52
+ "useRef",
53
+ "useState",
54
+ "useSyncExternalStore",
55
+ "useTransition"
56
+ ];
57
+ var JSX_RUNTIME_EXPORTS2 = ["Fragment", "jsx", "jsxs"];
58
+ var REACT_DOM_EXPORTS2 = ["createPortal", "flushSync"];
59
+ var LIBRARY_EXPORTS2 = Object.fromEntries(Object.entries(CANVAS_LIBRARIES2).map(([name, library]) => [name, library.exports.split(" ")]));
60
+ var LIBRARY_VERSIONS2 = Object.fromEntries(Object.entries(CANVAS_LIBRARIES2).map(([name, library]) => [name, library.version]));
61
+ var FILES_COMMENT = /^\/\*nyte-canvas-files:(\[[^\n]*?\])\*\//u;
62
+ function canvasFilesComment2(spans) {
63
+ return `/*nyte-canvas-files:${JSON.stringify(spans)}*/`;
64
+ }
65
+ function locateCanvasStack2(code, stack) {
66
+ const comment = FILES_COMMENT.exec(code);
67
+ if (comment === null)
68
+ return;
69
+ const spans = parseSpans(comment[1] ?? "");
70
+ for (const frame of stack.matchAll(/blob:[^\s)]+:(\d+):\d+/gu)) {
71
+ const line = Number(frame[1]);
72
+ const span = spans.find(([, start, lines]) => line >= start && line < start + lines);
73
+ if (span !== undefined)
74
+ return `${span[0]}:${line - span[1] + 1}`;
75
+ }
76
+ return;
77
+ }
78
+ function parseSpans(text) {
79
+ try {
80
+ const parsed = JSON.parse(text);
81
+ return Array.isArray(parsed) ? parsed.flatMap((entry) => Array.isArray(entry) && typeof entry[0] === "string" && typeof entry[1] === "number" && typeof entry[2] === "number" ? [[entry[0], entry[1], entry[2]]] : []) : [];
82
+ } catch {
83
+ return [];
84
+ }
85
+ }
86
+ var TINTS2 = [
87
+ "blue",
88
+ "pink",
89
+ "orange",
90
+ "teal",
91
+ "red",
92
+ "yellow",
93
+ "purple",
94
+ "green",
95
+ "gray",
96
+ "brown"
97
+ ];
98
+ var KIT2 = {
99
+ Stack: '{ direction?: "row" | "column" = "column", gap?: 0 | 1 | 2 | 3 | 4 | 6 = 2 (×4 px), align?: "start" | "center" | "end" | "stretch", justify?: "start" | "center" | "end" | "between", wrap?: boolean, children }: flex layout',
100
+ Grid: '{ columns?: number | "auto" = "auto", minWidth?: number = 160 (px, with "auto"), gap?: 0 | 1 | 2 | 3 | 4 | 6 = 2, children }: equal columns',
101
+ Divider: "{}: a hairline",
102
+ Heading: "{ level?: 1 | 2 | 3 = 2, children }",
103
+ Text: '{ size?: "xs" | "sm" | "base" | "lg", tone?: "primary" | "secondary" | "tertiary", weight?: "normal" | "medium" | "semibold", mono?: boolean, truncate?: boolean, align?: "start" | "center" | "end", children }',
104
+ Code: "{ block?: boolean, children: string }: monospace, inline or a block",
105
+ Stat: '{ label: string, value: ReactNode, detail?: ReactNode, tone?: "neutral" | "success" | "warning" | "danger" }: a labelled number',
106
+ Badge: '{ tone?: "neutral" | "info" | "success" | "warning" | "danger", children }',
107
+ Meter: '{ value: number, max?: number = 100, label?: string, tone?: "primary" | "success" | "warning" | "danger" = "primary" }: a thin filled bar with the value beside the label',
108
+ Table: '{ columns: { key: string, label: ReactNode, align?: "start" | "end", width?: number | string }[], rows: Record<string, ReactNode>[], caption?: string }: rows are keyed by column key; a cell can hold a Sparkline or a Badge',
109
+ Callout: '{ tone?: "info" | "success" | "warning" | "danger", title?: string, children }',
110
+ Card: "{ title?: ReactNode, actions?: ReactNode, padding?: 0 | 2 | 3 | 4 = 4, children }: an elevated bordered surface",
111
+ StackedBars: "{ label: string, series: { key: string, label: string, tint: Tint }[], buckets: { key: string, label: string, values: number[] }[], format: (value: number) => string, height?: number = 88, ticks?: number = 5 }: compact stacked bars without axes, a readout on pointer or arrow keys; the numbers live in the copy around it. Preferred beside a Stat or a heading figure",
112
+ Sparkline: "{ values: number[], tint?: Tint, label?: string, width?: number = 72, height?: number = 20 }: a row's trend scaled to its own peak, for a Table cell beside the row's number",
113
+ LineChart: '{ series: { id: string, data: { x: number | string, y: number }[], tint?: Tint }[], height?: number = 240, xFormat?: (x) => string, yFormat?: (y) => string, curve?: "linear" | "monotone" | "step", area?: boolean, legend?: boolean }: a full chart with axes and a readout',
114
+ BarChart: '{ data: Record<string, number | string>[], keys: (string | { key: string, label?: string, tint?: Tint })[], indexBy: string, height?: number = 240, layout?: "vertical" | "horizontal", mode?: "grouped" | "stacked" = "stacked", valueFormat?: (value: number) => string, legend?: boolean }: a full chart with axes and a readout with the total',
115
+ PieChart: "{ data: { id: string, value: number, label?: string, tint?: Tint }[], height?: number = 240, donut?: boolean, valueFormat?: (value: number) => string, legend?: boolean }",
116
+ Button: '{ variant?: "solid" | "outline" | "ghost" | "pill" | "chip", size?: "2xs" | "xs" | "sm" | "md" | "lg" | "xl", tone?: "neutral" | "primary" | "success" | "warning" | "danger", loading?: boolean, disabled?: boolean, onClick, children }',
117
+ Tabs: "Tabs.Root { value?, defaultValue?, onValueChange? } > Tabs.List { children: Tabs.Tab { value, children }[] } + Tabs.Panel { value, children }",
118
+ Select: "Select { value?, defaultValue?, onValueChange? } > SelectTrigger { children: <SelectValue /> } + SelectContent { children: SelectItem[] }",
119
+ SelectTrigger: "see Select",
120
+ SelectValue: "see Select",
121
+ SelectContent: "see Select",
122
+ SelectItem: "{ value: string, children }",
123
+ ToggleGroup: "{ value?: string[], defaultValue?: string[], onValueChange?: (value: string[]) => void, multiple?: boolean, children: Toggle[] }",
124
+ Toggle: "{ value: string, size?: as Button, tone?: as Button, children }",
125
+ Switch: "{ label: string, checked?, defaultChecked?, onCheckedChange?: (checked: boolean) => void, disabled? }",
126
+ Checkbox: "{ checked?, defaultChecked?, indeterminate?, onCheckedChange?: (checked: boolean) => void, disabled? }",
127
+ Slider: "Slider.Root { value?, defaultValue?, onValueChange?, min?, max?, step? } > Slider.Control > Slider.Track > Slider.Indicator + Slider.Thumb",
128
+ Tooltip: "Tooltip > TooltipTrigger { render?: ReactElement, children } + TooltipContent { side?, children }",
129
+ TooltipTrigger: "see Tooltip",
130
+ TooltipContent: "see Tooltip",
131
+ Collapsible: "Collapsible.Root { open?, defaultOpen?, onOpenChange? } > Collapsible.Trigger { children } + Collapsible.Panel { children }",
132
+ Kbd: "{ keys: string[] }",
133
+ Spinner: "{}",
134
+ useColorScheme: '(): "light" | "dark"'
135
+ };
136
+ var KIT_EXPORTS2 = Object.keys(KIT2);
137
+ var CANVAS_VARIABLES2 = [
138
+ "--nyte-custom-hue",
139
+ "--nyte-custom-chroma-scale",
140
+ "--nyte-font-family-sans",
141
+ "--nyte-font-family-mono",
142
+ "--nyte-font-size-base",
143
+ "--nyte-font-size-code",
144
+ "--nyte-letter-spacing-lg",
145
+ "--nyte-font-smoothing",
146
+ "--nyte-moz-font-smoothing",
147
+ "--nyte-reduce-transparency"
148
+ ];
149
+ var CANVAS_PROTOCOL_VERSION2 = "2026-01-26";
150
+ var INITIALIZE = "ui/initialize";
151
+ var INITIALIZED = "ui/notifications/initialized";
152
+ var SIZE_CHANGED = "ui/notifications/size-changed";
153
+ var OPEN_LINK = "ui/open-link";
154
+ var LOG_MESSAGE = "notifications/message";
155
+ var HOST_CONTEXT_CHANGED = "ui/notifications/host-context-changed";
156
+ var RENDER = "nyte/notifications/render";
157
+ function initializeRequest2(id, runtime) {
158
+ return {
159
+ jsonrpc: "2.0",
160
+ id,
161
+ method: INITIALIZE,
162
+ params: {
163
+ protocolVersion: CANVAS_PROTOCOL_VERSION2,
164
+ appInfo: { name: "nyte-canvas", version: String(runtime) },
165
+ appCapabilities: {}
166
+ }
167
+ };
168
+ }
169
+ function initializedNotification2() {
170
+ return { jsonrpc: "2.0", method: INITIALIZED, params: {} };
171
+ }
172
+ function sizeChangedNotification2(height) {
173
+ return { jsonrpc: "2.0", method: SIZE_CHANGED, params: { height } };
174
+ }
175
+ function openLinkRequest2(id, url) {
176
+ return { jsonrpc: "2.0", id, method: OPEN_LINK, params: { url } };
177
+ }
178
+ function errorNotification2(error) {
179
+ return {
180
+ jsonrpc: "2.0",
181
+ method: LOG_MESSAGE,
182
+ params: {
183
+ level: "error",
184
+ logger: "nyte-canvas",
185
+ data: {
186
+ phase: error.phase,
187
+ message: error.message,
188
+ ...error.stack === undefined ? {} : { stack: error.stack }
189
+ }
190
+ }
191
+ };
192
+ }
193
+ function initializeResult2(id, hostInfo, hostContext) {
194
+ return {
195
+ jsonrpc: "2.0",
196
+ id,
197
+ result: {
198
+ protocolVersion: CANVAS_PROTOCOL_VERSION2,
199
+ hostInfo,
200
+ hostCapabilities: {},
201
+ hostContext: contextJson(hostContext)
202
+ }
203
+ };
204
+ }
205
+ function renderNotification2(module) {
206
+ return {
207
+ jsonrpc: "2.0",
208
+ method: RENDER,
209
+ params: { runtime: module.runtime, code: module.code, title: module.title }
210
+ };
211
+ }
212
+ function hostContextChangedNotification2(context) {
213
+ return { jsonrpc: "2.0", method: HOST_CONTEXT_CHANGED, params: contextJson(context) };
214
+ }
215
+ function openLinkResult2(id, isError = false) {
216
+ return { jsonrpc: "2.0", id, result: isError ? { isError: true } : {} };
217
+ }
218
+ function readShellMessage2(data) {
219
+ const message = envelope(data);
220
+ if (message === undefined)
221
+ return;
222
+ const { id, method, params } = message;
223
+ if (method === INITIALIZE && id !== undefined) {
224
+ const info = record(params?.["appInfo"]);
225
+ const runtime = info === undefined ? NaN : Number(info["version"]);
226
+ return Number.isInteger(runtime) && runtime > 0 ? { kind: "initialize", id, runtime } : undefined;
227
+ }
228
+ if (method === INITIALIZED)
229
+ return { kind: "initialized" };
230
+ if (method === SIZE_CHANGED) {
231
+ const height = params?.["height"];
232
+ return typeof height === "number" && Number.isFinite(height) && height > 0 ? { kind: "size", height } : undefined;
233
+ }
234
+ if (method === OPEN_LINK && id !== undefined) {
235
+ const url = linkHref(params?.["url"]);
236
+ return url === undefined ? undefined : { kind: "open-link", id, url };
237
+ }
238
+ if (method === LOG_MESSAGE) {
239
+ const payload = record(params?.["data"]);
240
+ const phase = payload?.["phase"];
241
+ const text = payload?.["message"];
242
+ const stack = payload?.["stack"];
243
+ if (params?.["level"] !== "error" || phase !== "load" && phase !== "render" || typeof text !== "string")
244
+ return;
245
+ return { kind: "error", phase, message: text, stack: typeof stack === "string" ? stack : null };
246
+ }
247
+ return;
248
+ }
249
+ function readHostMessage2(data) {
250
+ const message = envelope(data);
251
+ if (message === undefined)
252
+ return;
253
+ const { id, method, params, result } = message;
254
+ if (method === undefined && id !== undefined && result !== undefined) {
255
+ if (result["hostContext"] === undefined)
256
+ return { kind: "open-link-result", id, isError: result["isError"] === true };
257
+ const info = record(result["hostInfo"]);
258
+ const context = readContext(result["hostContext"]);
259
+ const name = info?.["name"];
260
+ const version = info?.["version"];
261
+ if (context === undefined || typeof version !== "string" || name !== "nyte-desktop" && name !== "nyte-web" && name !== "nyte-ios" && name !== "nyte-preview")
262
+ return;
263
+ return { kind: "initialize-result", id, hostInfo: { name, version }, hostContext: context };
264
+ }
265
+ if (method === RENDER) {
266
+ const runtime = params?.["runtime"];
267
+ const code = params?.["code"];
268
+ const title = params?.["title"];
269
+ return Number.isInteger(runtime) && typeof runtime === "number" && runtime > 0 && typeof code === "string" && typeof title === "string" ? { kind: "render", module: { runtime, code, title } } : undefined;
270
+ }
271
+ if (method === HOST_CONTEXT_CHANGED) {
272
+ const context = readPartialContext(params);
273
+ return context === undefined ? undefined : { kind: "context-changed", context };
274
+ }
275
+ return;
276
+ }
277
+ function clampCanvasHeight2(height) {
278
+ return Math.min(CANVAS_MAX_HEIGHT2, Math.max(CANVAS_MIN_HEIGHT2, Math.round(height)));
279
+ }
280
+ function sanitizeCanvasVariables2(variables) {
281
+ const allowed = CANVAS_VARIABLES2;
282
+ return Object.fromEntries(Object.entries(variables).filter(([name]) => allowed.includes(name)).map(([name, value]) => [name, value.replace(/[;{}<>]/g, "")]));
283
+ }
284
+ function contextJson(context) {
285
+ return {
286
+ ...context.theme === undefined ? {} : { theme: context.theme },
287
+ ...context.styles === undefined ? {} : { styles: { variables: context.styles.variables } },
288
+ ...context.displayMode === undefined ? {} : { displayMode: context.displayMode },
289
+ ...context.platform === undefined ? {} : { platform: context.platform },
290
+ ...context.deviceCapabilities === undefined ? {} : {
291
+ deviceCapabilities: {
292
+ touch: context.deviceCapabilities.touch,
293
+ hover: context.deviceCapabilities.hover
294
+ }
295
+ }
296
+ };
297
+ }
298
+ function readPartialContext(value) {
299
+ const params = record(value);
300
+ if (params === undefined)
301
+ return;
302
+ const theme = params["theme"];
303
+ const styles = record(params["styles"]);
304
+ const variables = styles === undefined ? undefined : record(styles["variables"]);
305
+ const platform = params["platform"];
306
+ const capabilities = record(params["deviceCapabilities"]);
307
+ const touch = capabilities?.["touch"];
308
+ const hover = capabilities?.["hover"];
309
+ if (theme !== undefined && theme !== "light" && theme !== "dark")
310
+ return;
311
+ if (styles !== undefined && variables === undefined)
312
+ return;
313
+ if (params["displayMode"] !== undefined && params["displayMode"] !== "inline")
314
+ return;
315
+ if (platform !== undefined && platform !== "desktop" && platform !== "web" && platform !== "mobile")
316
+ return;
317
+ if (capabilities !== undefined && (typeof touch !== "boolean" || typeof hover !== "boolean"))
318
+ return;
319
+ return {
320
+ ...theme === undefined ? {} : { theme },
321
+ ...variables === undefined ? {} : { styles: { variables: sanitizeCanvasVariables2(stringEntries(variables)) } },
322
+ ...params["displayMode"] === undefined ? {} : { displayMode: "inline" },
323
+ ...platform === undefined ? {} : { platform },
324
+ ...typeof touch !== "boolean" || typeof hover !== "boolean" ? {} : { deviceCapabilities: { touch, hover } }
325
+ };
326
+ }
327
+ function readContext(value) {
328
+ const partial = readPartialContext(value);
329
+ return partial?.theme !== undefined && partial.styles !== undefined && partial.displayMode !== undefined && partial.platform !== undefined && partial.deviceCapabilities !== undefined ? {
330
+ theme: partial.theme,
331
+ styles: partial.styles,
332
+ displayMode: partial.displayMode,
333
+ platform: partial.platform,
334
+ deviceCapabilities: partial.deviceCapabilities
335
+ } : undefined;
336
+ }
337
+ function envelope(data) {
338
+ const message = record(data);
339
+ if (message === undefined || message["jsonrpc"] !== "2.0")
340
+ return;
341
+ const id = message["id"];
342
+ const method = message["method"];
343
+ if (method !== undefined && typeof method !== "string")
344
+ return;
345
+ return {
346
+ id: typeof id === "string" || typeof id === "number" ? id : undefined,
347
+ method,
348
+ params: record(message["params"]),
349
+ result: record(message["result"])
350
+ };
351
+ }
352
+ function record(value) {
353
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? Object.fromEntries(Object.entries(value)) : undefined;
354
+ }
355
+ function stringEntries(value) {
356
+ return Object.fromEntries(Object.entries(value).flatMap(([name, text]) => typeof text === "string" ? [[name, text]] : []));
357
+ }
358
+ function linkHref(value) {
359
+ if (typeof value !== "string" || value === "")
360
+ return;
361
+ const scheme = /^([a-z][a-z\d+-]*):/iu.exec(value)?.[1]?.toLowerCase();
362
+ if (scheme === undefined)
363
+ return value;
364
+ if (scheme !== "http" && scheme !== "https")
365
+ return;
366
+ return URL.parse(value)?.href;
367
+ }
368
+
369
+ export { CANVAS_RUNTIME2, CANVAS_GLOBAL2, KIT_SPECIFIER2, CANVAS_ENTRY2, CANVAS_SOURCE_LIMIT2, CANVAS_CODE_LIMIT2, CANVAS_MIN_HEIGHT2, CANVAS_MAX_HEIGHT2, CANVAS_MIN_HEIGHT_HINT2, CANVAS_DEFAULT_HEIGHT2, REACT_EXPORTS2, JSX_RUNTIME_EXPORTS2, REACT_DOM_EXPORTS2, LIBRARY_EXPORTS2, LIBRARY_VERSIONS2, canvasFilesComment2, locateCanvasStack2, TINTS2, KIT2, KIT_EXPORTS2, CANVAS_VARIABLES2, CANVAS_PROTOCOL_VERSION2, initializeRequest2, initializedNotification2, sizeChangedNotification2, openLinkRequest2, errorNotification2, initializeResult2, renderNotification2, hostContextChangedNotification2, openLinkResult2, readShellMessage2, readHostMessage2, clampCanvasHeight2, sanitizeCanvasVariables2 };
@@ -0,0 +1,302 @@
1
+ import {
2
+ envFlagEnabled2
3
+ } from "./billing-s4rrspsk.js";
4
+ import {
5
+ discoveredModelSchema2
6
+ } from "./billing-9qc0eqh4.js";
7
+ import {
8
+ matchesRecord2,
9
+ parseRecord2
10
+ } from "./billing-0y7dfkp2.js";
11
+
12
+ // examples/claude-code/process.ts
13
+ import { spawn } from "node:child_process";
14
+ import { constants } from "node:fs";
15
+ import { access } from "node:fs/promises";
16
+ import { delimiter, extname, isAbsolute, join, resolve as resolvePath } from "node:path";
17
+ import { createInterface } from "node:readline";
18
+ import { Value } from "typebox/value";
19
+ var INSTALL_HINT = "Claude Code is not installed. Install it with `npm install -g @anthropic-ai/claude-code` " + "or set NYTE_CLAUDE_CODE_COMMAND to the executable.";
20
+ var LOGIN_HINT2 = "Claude Code is installed but not logged in. Run `claude auth login` and try again.";
21
+ function configuredCommand2(env) {
22
+ return env.NYTE_CLAUDE_CODE_COMMAND || "claude";
23
+ }
24
+ async function executable(path) {
25
+ try {
26
+ await access(path, process.platform === "win32" ? constants.F_OK : constants.X_OK);
27
+ return true;
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
32
+ async function resolveClaudeExecutable(env = process.env) {
33
+ const command = configuredCommand2(env);
34
+ if (isAbsolute(command) || command.includes("/") || command.includes("\\")) {
35
+ const candidate = resolvePath(command);
36
+ return await executable(candidate) ? candidate : undefined;
37
+ }
38
+ const extensions = process.platform === "win32" ? (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").flatMap((suffix) => [suffix, suffix.toLowerCase()]) : [""];
39
+ for (const directory of (env.PATH || "").split(delimiter)) {
40
+ if (!directory)
41
+ continue;
42
+ for (const suffix of extensions) {
43
+ const candidate = join(directory, process.platform === "win32" && extname(command) ? command : command + suffix);
44
+ if (await executable(candidate))
45
+ return candidate;
46
+ }
47
+ }
48
+ return;
49
+ }
50
+ function withConfigDirectory(env) {
51
+ const output = {};
52
+ for (const [key, value] of Object.entries(env))
53
+ if (value !== undefined)
54
+ output[key] = value;
55
+ if (output.NYTE_CLAUDE_CODE_CONFIG_DIR)
56
+ output.CLAUDE_CONFIG_DIR = output.NYTE_CLAUDE_CODE_CONFIG_DIR;
57
+ return output;
58
+ }
59
+ async function captureProcess(command, args, env, signal, timeoutMs = 20000) {
60
+ signal?.throwIfAborted();
61
+ const child = spawnCommand2(command, args, { env, stdio: ["ignore", "pipe", "pipe"] });
62
+ let stdout = "";
63
+ let stderr = "";
64
+ child.stdout?.setEncoding("utf8");
65
+ child.stderr?.setEncoding("utf8");
66
+ child.stdout?.on("data", (chunk) => stdout = (stdout + chunk).slice(-1e6));
67
+ child.stderr?.on("data", (chunk) => stderr = (stderr + chunk).slice(-65536));
68
+ const abort = () => killProcessTree2(child);
69
+ signal?.addEventListener("abort", abort, { once: true });
70
+ const timer = setTimeout(abort, timeoutMs);
71
+ try {
72
+ const code = await childExit2(child);
73
+ signal?.throwIfAborted();
74
+ return { code, stdout, stderr };
75
+ } finally {
76
+ clearTimeout(timer);
77
+ signal?.removeEventListener("abort", abort);
78
+ }
79
+ }
80
+ async function getClaudeStatus2(envInput = process.env, signal) {
81
+ const env = withConfigDirectory(envInput);
82
+ const command = await resolveClaudeExecutable(env);
83
+ if (!command)
84
+ return { available: false, loggedIn: false, subscription: false, detail: INSTALL_HINT };
85
+ try {
86
+ const result = await captureProcess(command, ["auth", "status"], env, signal);
87
+ const payload = result.stdout.trim().startsWith("{") ? parseRecord2(result.stdout) : {};
88
+ const loggedIn = payload.loggedIn === true;
89
+ const plan = typeof payload.subscriptionType === "string" ? payload.subscriptionType : undefined;
90
+ return {
91
+ available: true,
92
+ loggedIn,
93
+ subscription: loggedIn && !!plan,
94
+ command,
95
+ authMethod: typeof payload.authMethod === "string" ? payload.authMethod : undefined,
96
+ plan,
97
+ detail: loggedIn ? undefined : LOGIN_HINT2
98
+ };
99
+ } catch (error) {
100
+ if (signal?.aborted)
101
+ throw error;
102
+ return { available: true, loggedIn: false, subscription: false, command, detail: LOGIN_HINT2 };
103
+ }
104
+ }
105
+ var READY_STATUS_TTL_MS = 60000;
106
+ var readyStatusCache = new Map;
107
+ async function readyClaudeCommand2(envInput, signal) {
108
+ const env = withConfigDirectory(envInput);
109
+ const key = JSON.stringify([configuredCommand2(env), env.PATH, env.HOME, env.CLAUDE_CONFIG_DIR]);
110
+ const cached = readyStatusCache.get(key);
111
+ if (cached && cached.expires > Date.now())
112
+ return cached.command;
113
+ const status = await getClaudeStatus2(env, signal);
114
+ if (!status.available || !status.command)
115
+ throw new Error(INSTALL_HINT);
116
+ if (!status.loggedIn) {
117
+ readyStatusCache.delete(key);
118
+ throw new Error(LOGIN_HINT2);
119
+ }
120
+ readyStatusCache.set(key, { command: status.command, expires: Date.now() + READY_STATUS_TTL_MS });
121
+ return status.command;
122
+ }
123
+ async function discoverClaudeModels2(envInput = process.env, signal, timeoutMs = 20000) {
124
+ signal?.throwIfAborted();
125
+ const env = processEnvironment2(envInput, {});
126
+ const command = await resolveClaudeExecutable(env);
127
+ if (!command)
128
+ throw new Error(INSTALL_HINT);
129
+ const args = [
130
+ "-p",
131
+ "--input-format",
132
+ "stream-json",
133
+ "--output-format",
134
+ "stream-json",
135
+ "--verbose",
136
+ "--model",
137
+ "default",
138
+ "--tools",
139
+ "",
140
+ "--setting-sources",
141
+ "",
142
+ "--strict-mcp-config",
143
+ "--disable-slash-commands",
144
+ "--permission-mode",
145
+ "dontAsk",
146
+ "--permission-prompts",
147
+ "none",
148
+ "--no-session-persistence",
149
+ "--mcp-config",
150
+ JSON.stringify({ mcpServers: {} })
151
+ ];
152
+ const child = spawnCommand2(command, args, {
153
+ cwd: process.cwd(),
154
+ env,
155
+ detached: process.platform !== "win32",
156
+ windowsHide: true,
157
+ stdio: ["pipe", "pipe", "pipe"]
158
+ });
159
+ let stderr = "";
160
+ child.stderr?.setEncoding("utf8");
161
+ child.stderr?.on("data", (chunk) => stderr = (stderr + chunk).slice(-65536));
162
+ const abort = () => killProcessTree2(child);
163
+ signal?.addEventListener("abort", abort, { once: true });
164
+ let timedOut = false;
165
+ const timer = setTimeout(() => {
166
+ timedOut = true;
167
+ killProcessTree2(child);
168
+ }, timeoutMs);
169
+ const requestId = `nyte-models-${Date.now()}`;
170
+ child.stdin?.write(`${JSON.stringify({ type: "control_request", request_id: requestId, request: { subtype: "initialize" } })}
171
+ `);
172
+ child.stdin?.end(`${JSON.stringify({
173
+ type: "user",
174
+ message: { role: "user", content: [{ type: "text", text: "model-catalog-probe" }] },
175
+ shouldQuery: false
176
+ })}
177
+ `);
178
+ let models;
179
+ try {
180
+ if (child.stdout === null)
181
+ throw new Error("Claude Code stdout is unavailable");
182
+ const reader = createInterface({ input: child.stdout, crlfDelay: Infinity });
183
+ for await (const line of reader) {
184
+ if (!line.trim())
185
+ continue;
186
+ let event;
187
+ try {
188
+ event = parseRecord2(line);
189
+ } catch {
190
+ continue;
191
+ }
192
+ if (event.type !== "control_response")
193
+ continue;
194
+ const envelope = event.response;
195
+ if (!matchesRecord2(envelope))
196
+ continue;
197
+ if (envelope.request_id !== requestId || envelope.subtype !== "success")
198
+ continue;
199
+ const response = envelope.response;
200
+ if (matchesRecord2(response) && Array.isArray(response.models))
201
+ models = response.models.filter((model) => Value.Check(discoveredModelSchema2, model));
202
+ }
203
+ const exitCode = await childExit2(child);
204
+ signal?.throwIfAborted();
205
+ if (timedOut)
206
+ throw new Error("Claude Code model discovery timed out");
207
+ if (exitCode !== 0)
208
+ throw new Error(`Claude Code model discovery failed${stderr ? `: ${stderr.trim().slice(-500)}` : ""}`);
209
+ if (!models?.length)
210
+ throw new Error("Claude Code returned no selectable models");
211
+ return models;
212
+ } catch (error) {
213
+ if (timedOut)
214
+ throw new Error("Claude Code model discovery timed out", { cause: error });
215
+ throw error;
216
+ } finally {
217
+ clearTimeout(timer);
218
+ signal?.removeEventListener("abort", abort);
219
+ if (child.exitCode === null)
220
+ killProcessTree2(child);
221
+ }
222
+ }
223
+ function quote(value) {
224
+ return `"${value.replace(/"/gu, '""')}"`;
225
+ }
226
+ function spawnCommand2(command, args, options) {
227
+ if (process.platform === "win32" && /\.(?:cmd|bat)$/iu.test(command)) {
228
+ const comspec = options?.env?.COMSPEC || process.env.COMSPEC || "cmd.exe";
229
+ return spawn(comspec, ["/d", "/s", "/c", [quote(command), ...args.map(quote)].join(" ")], options);
230
+ }
231
+ return spawn(command, args, options);
232
+ }
233
+ function childExit2(child) {
234
+ return new Promise((resolve, reject) => {
235
+ child.once("error", reject);
236
+ child.once("exit", (code, signal) => {
237
+ if (code !== null)
238
+ resolve(code);
239
+ else
240
+ reject(new Error(`Claude Code exited from signal ${signal ?? "unknown"}`));
241
+ });
242
+ });
243
+ }
244
+ function killProcessTree2(child) {
245
+ if (child.exitCode !== null || child.pid === undefined)
246
+ return;
247
+ if (process.platform === "win32") {
248
+ const killer = spawn("taskkill", ["/F", "/T", "/PID", String(child.pid)], {
249
+ stdio: "ignore",
250
+ windowsHide: true
251
+ });
252
+ killer.unref();
253
+ return;
254
+ }
255
+ try {
256
+ process.kill(-child.pid, "SIGKILL");
257
+ } catch {
258
+ try {
259
+ child.kill("SIGKILL");
260
+ } catch {}
261
+ }
262
+ }
263
+ function conflictingEnvironment(env) {
264
+ const conflicts = [
265
+ "ANTHROPIC_API_KEY",
266
+ "ANTHROPIC_AUTH_TOKEN",
267
+ "ANTHROPIC_BASE_URL",
268
+ "ANTHROPIC_FOUNDRY_API_KEY"
269
+ ].filter((key) => !!env[key]);
270
+ for (const key of [
271
+ "CLAUDE_CODE_USE_BEDROCK",
272
+ "CLAUDE_CODE_USE_VERTEX",
273
+ "CLAUDE_CODE_USE_FOUNDRY"
274
+ ]) {
275
+ if (envFlagEnabled2(env[key]))
276
+ conflicts.push(key);
277
+ }
278
+ return conflicts;
279
+ }
280
+ function processEnvironment2(input, extraBody) {
281
+ const env = withConfigDirectory({ ...process.env, ...input });
282
+ const conflicts = conflictingEnvironment(env);
283
+ if (conflicts.length) {
284
+ throw new Error(`Claude Code subscription provider refuses conflicting auth/backend overrides: ${conflicts.join(", ")}`);
285
+ }
286
+ delete env.CLAUDE_CODE_EXTRA_BODY;
287
+ Object.assign(env, {
288
+ ENABLE_TOOL_SEARCH: "false",
289
+ CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
290
+ CLAUDE_CODE_MAX_RETRIES: "0",
291
+ DISABLE_AUTO_COMPACT: "1",
292
+ DISABLE_COMPACT: "1",
293
+ CLAUDE_CODE_TOTAL_TOKENS_REMINDER: "off",
294
+ DISABLE_TELEMETRY: "1",
295
+ DISABLE_ERROR_REPORTING: "1"
296
+ });
297
+ if (typeof extraBody.max_tokens === "number")
298
+ env.CLAUDE_CODE_MAX_OUTPUT_TOKENS = String(extraBody.max_tokens);
299
+ return env;
300
+ }
301
+
302
+ export { LOGIN_HINT2, configuredCommand2, getClaudeStatus2, readyClaudeCommand2, discoverClaudeModels2, spawnCommand2, childExit2, killProcessTree2, processEnvironment2 };