code-ollama 0.1.0 → 0.2.0

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.
@@ -1,559 +0,0 @@
1
- import { a as e, c as t, d as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./utils-DBXrYZEs.js";
2
- import { homedir as u } from "node:os";
3
- import { Box as d, Text as f, render as p, useInput as m } from "ink";
4
- import { useCallback as h, useEffect as g, useState as _ } from "react";
5
- import { Select as v, Spinner as y, TextInput as b } from "@inkjs/ui";
6
- //#region \0rolldown/runtime.js
7
- var x = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), S = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
8
- if (typeof require < "u") return require.apply(this, arguments);
9
- throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
10
- }), C = [{
11
- name: "/model",
12
- description: "switch the model"
13
- }], w = "🦙", T = /* @__PURE__ */ x(((e) => {
14
- var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
15
- function r(e, n, r) {
16
- var i = null;
17
- if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
18
- else r = n;
19
- return n = r.ref, {
20
- $$typeof: t,
21
- type: e,
22
- key: i,
23
- ref: n === void 0 ? null : n,
24
- props: r
25
- };
26
- }
27
- e.Fragment = n, e.jsx = r, e.jsxs = r;
28
- })), E = /* @__PURE__ */ x(((e) => {
29
- process.env.NODE_ENV !== "production" && (function() {
30
- function t(e) {
31
- if (e == null) return null;
32
- if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
33
- if (typeof e == "string") return e;
34
- switch (e) {
35
- case _: return "Fragment";
36
- case y: return "Profiler";
37
- case v: return "StrictMode";
38
- case w: return "Suspense";
39
- case T: return "SuspenseList";
40
- case O: return "Activity";
41
- }
42
- if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
43
- case g: return "Portal";
44
- case x: return e.displayName || "Context";
45
- case b: return (e._context.displayName || "Context") + ".Consumer";
46
- case C:
47
- var n = e.render;
48
- return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
49
- case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
50
- case D:
51
- n = e._payload, e = e._init;
52
- try {
53
- return t(e(n));
54
- } catch {}
55
- }
56
- return null;
57
- }
58
- function n(e) {
59
- return "" + e;
60
- }
61
- function r(e) {
62
- try {
63
- n(e);
64
- var t = !1;
65
- } catch {
66
- t = !0;
67
- }
68
- if (t) {
69
- t = console;
70
- var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
71
- return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
72
- }
73
- }
74
- function i(e) {
75
- if (e === _) return "<>";
76
- if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
77
- try {
78
- var n = t(e);
79
- return n ? "<" + n + ">" : "<...>";
80
- } catch {
81
- return "<...>";
82
- }
83
- }
84
- function a() {
85
- var e = A.A;
86
- return e === null ? null : e.getOwner();
87
- }
88
- function o() {
89
- return Error("react-stack-top-frame");
90
- }
91
- function s(e) {
92
- if (j.call(e, "key")) {
93
- var t = Object.getOwnPropertyDescriptor(e, "key").get;
94
- if (t && t.isReactWarning) return !1;
95
- }
96
- return e.key !== void 0;
97
- }
98
- function c(e, t) {
99
- function n() {
100
- P || (P = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
101
- }
102
- n.isReactWarning = !0, Object.defineProperty(e, "key", {
103
- get: n,
104
- configurable: !0
105
- });
106
- }
107
- function l() {
108
- var e = t(this.type);
109
- return F[e] || (F[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
110
- }
111
- function u(e, t, n, r, i, a) {
112
- var o = n.ref;
113
- return e = {
114
- $$typeof: h,
115
- type: e,
116
- key: t,
117
- props: n,
118
- _owner: r
119
- }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
120
- enumerable: !1,
121
- value: null
122
- }) : Object.defineProperty(e, "ref", {
123
- enumerable: !1,
124
- get: l
125
- }), e._store = {}, Object.defineProperty(e._store, "validated", {
126
- configurable: !1,
127
- enumerable: !1,
128
- writable: !0,
129
- value: 0
130
- }), Object.defineProperty(e, "_debugInfo", {
131
- configurable: !1,
132
- enumerable: !1,
133
- writable: !0,
134
- value: null
135
- }), Object.defineProperty(e, "_debugStack", {
136
- configurable: !1,
137
- enumerable: !1,
138
- writable: !0,
139
- value: i
140
- }), Object.defineProperty(e, "_debugTask", {
141
- configurable: !1,
142
- enumerable: !1,
143
- writable: !0,
144
- value: a
145
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
146
- }
147
- function d(e, n, i, o, l, d) {
148
- var p = n.children;
149
- if (p !== void 0) if (o) if (M(p)) {
150
- for (o = 0; o < p.length; o++) f(p[o]);
151
- Object.freeze && Object.freeze(p);
152
- } else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
153
- else f(p);
154
- if (j.call(n, "key")) {
155
- p = t(e);
156
- var m = Object.keys(n).filter(function(e) {
157
- return e !== "key";
158
- });
159
- o = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[p + o] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", o, p, m, p), R[p + o] = !0);
160
- }
161
- if (p = null, i !== void 0 && (r(i), p = "" + i), s(n) && (r(n.key), p = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
162
- else i = n;
163
- return p && c(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), u(e, p, i, a(), l, d);
164
- }
165
- function f(e) {
166
- p(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? p(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
167
- }
168
- function p(e) {
169
- return typeof e == "object" && !!e && e.$$typeof === h;
170
- }
171
- var m = S("react"), h = Symbol.for("react.transitional.element"), g = Symbol.for("react.portal"), _ = Symbol.for("react.fragment"), v = Symbol.for("react.strict_mode"), y = Symbol.for("react.profiler"), b = Symbol.for("react.consumer"), x = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
172
- return null;
173
- };
174
- m = { react_stack_bottom_frame: function(e) {
175
- return e();
176
- } };
177
- var P, F = {}, I = m.react_stack_bottom_frame.bind(m, o)(), L = N(i(o)), R = {};
178
- e.Fragment = _, e.jsx = function(e, t, n) {
179
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
180
- return d(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
181
- }, e.jsxs = function(e, t, n) {
182
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
183
- return d(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
184
- };
185
- })();
186
- })), D = (/* @__PURE__ */ x(((e, t) => {
187
- process.env.NODE_ENV === "production" ? t.exports = T() : t.exports = E();
188
- })))();
189
- function O(e) {
190
- return e.startsWith("/") ? C.filter((t) => t.name.startsWith(e)) : [];
191
- }
192
- function k({ isDisabled: e = !1, onSubmit: t }) {
193
- let [n, r] = _(""), [i, a] = _(0), [o, s] = _(0), c = O(n), l = n.startsWith("/");
194
- m((e, t) => {
195
- if (l) {
196
- if (t.upArrow) {
197
- a((e) => Math.max(0, e - 1));
198
- return;
199
- }
200
- if (t.downArrow) {
201
- a((e) => Math.min(c.length - 1, e + 1));
202
- return;
203
- }
204
- if (t.tab && c.length > 0) {
205
- r((c[i] ?? c[0]).name), a(0), s((e) => e + 1);
206
- return;
207
- }
208
- }
209
- }, { isActive: !e && l });
210
- let u = h((e) => {
211
- let n = (l && c.length > 0 && c[i] ? c[i].name : e).trim();
212
- n && (t(n), r(""), a(0), s((e) => e + 1));
213
- }, [
214
- l,
215
- c,
216
- t,
217
- i
218
- ]);
219
- return /* @__PURE__ */ (0, D.jsxs)(d, {
220
- flexDirection: "column",
221
- children: [/* @__PURE__ */ (0, D.jsxs)(d, { children: [/* @__PURE__ */ (0, D.jsx)(f, { children: "> " }), /* @__PURE__ */ (0, D.jsx)(b, {
222
- isDisabled: e,
223
- defaultValue: n,
224
- onChange: r,
225
- onSubmit: u
226
- }, o)] }), l && c.length > 0 && /* @__PURE__ */ (0, D.jsx)(d, {
227
- flexDirection: "column",
228
- marginLeft: 2,
229
- children: c.map((e, t) => {
230
- let n = t === i;
231
- return /* @__PURE__ */ (0, D.jsxs)(d, {
232
- gap: 3,
233
- children: [/* @__PURE__ */ (0, D.jsx)(f, {
234
- color: n ? "cyan" : void 0,
235
- bold: n,
236
- children: e.name
237
- }), /* @__PURE__ */ (0, D.jsx)(f, {
238
- dimColor: !0,
239
- children: e.description
240
- })]
241
- }, e.name);
242
- })
243
- })]
244
- });
245
- }
246
- //#endregion
247
- //#region src/components/Messages.tsx
248
- function A(e) {
249
- switch (e) {
250
- case l.USER: return "black";
251
- case l.ASSISTANT: return "blue";
252
- case l.SYSTEM: return "gray";
253
- default: return;
254
- }
255
- }
256
- function j({ messages: e, isLoading: t }) {
257
- return /* @__PURE__ */ (0, D.jsxs)(d, {
258
- flexDirection: "column",
259
- children: [e.map((e, t) => /* @__PURE__ */ (0, D.jsx)(d, {
260
- marginBottom: 1,
261
- children: /* @__PURE__ */ (0, D.jsxs)(f, {
262
- color: A(e.role),
263
- dimColor: e.role === l.SYSTEM,
264
- children: [e.role === l.USER ? "> " : "", e.content]
265
- })
266
- }, t)), t && e[e.length - 1]?.content === "" && /* @__PURE__ */ (0, D.jsx)(d, {
267
- marginTop: -1,
268
- marginBottom: 1,
269
- children: /* @__PURE__ */ (0, D.jsx)(y, { label: "Thinking..." })
270
- })]
271
- });
272
- }
273
- //#endregion
274
- //#region src/components/ToolApproval.tsx
275
- function M({ toolCall: e, onApprove: t, onReject: n }) {
276
- let [r, i] = _("yes");
277
- m((e, a) => {
278
- a.return ? r === "yes" ? t() : n() : (a.leftArrow || a.rightArrow) && i((e) => e === "yes" ? "no" : "yes");
279
- // v8 ignore stop
280
- });
281
- let a = JSON.stringify(e.function.arguments, null, 2);
282
- return /* @__PURE__ */ (0, D.jsxs)(d, {
283
- flexDirection: "column",
284
- marginY: 1,
285
- children: [
286
- /* @__PURE__ */ (0, D.jsx)(f, {
287
- color: "yellow",
288
- bold: !0,
289
- children: "⚠️ Tool requires approval:"
290
- }),
291
- /* @__PURE__ */ (0, D.jsxs)(d, {
292
- marginX: 2,
293
- flexDirection: "column",
294
- children: [/* @__PURE__ */ (0, D.jsxs)(f, { children: [
295
- /* @__PURE__ */ (0, D.jsx)(f, {
296
- bold: !0,
297
- children: "Tool:"
298
- }),
299
- " ",
300
- e.function.name
301
- ] }), /* @__PURE__ */ (0, D.jsxs)(f, { children: [
302
- /* @__PURE__ */ (0, D.jsx)(f, {
303
- bold: !0,
304
- children: "Arguments:"
305
- }),
306
- " ",
307
- a
308
- ] })]
309
- }),
310
- /* @__PURE__ */ (0, D.jsxs)(d, {
311
- marginTop: 1,
312
- gap: 2,
313
- children: [/* @__PURE__ */ (0, D.jsx)(f, { children: /* @__PURE__ */ (0, D.jsxs)(f, {
314
- color: r === "yes" ? "green" : void 0,
315
- children: [r === "yes" ? "▶ " : " ", "✓ Yes (Enter)"]
316
- }) }), /* @__PURE__ */ (0, D.jsx)(f, { children: /* @__PURE__ */ (0, D.jsxs)(f, {
317
- color: r === "no" ? "red" : void 0,
318
- children: [r === "no" ? "▶ " : " ", "✗ No (Esc)"]
319
- }) })]
320
- })
321
- ]
322
- });
323
- }
324
- //#endregion
325
- //#region src/components/Chat.tsx
326
- function N({ model: e, onCommand: t, autoExecute: n }) {
327
- let [s, u] = _([r()]), [f, p] = _(0), [m, g] = _(!1), [v, y] = _(null), b = h(async (t) => {
328
- let r = {
329
- role: l.ASSISTANT,
330
- content: ""
331
- };
332
- u((e) => [...e, r]);
333
- try {
334
- for await (let s of a(t, e, c)) if (s.type === "content") r.content += s.content, u((e) => {
335
- let t = [...e];
336
- return t[t.length - 1] = { ...r }, t;
337
- });
338
- else if (s.type === "tool_calls") for (let e of s.tool_calls) {
339
- let a = i.has(e.function.name);
340
- if (!n && a) {
341
- y(e), g(!1);
342
- return;
343
- }
344
- let s = await o(e.function.name, e.function.arguments), c = {
345
- role: l.SYSTEM,
346
- content: `Tool ${e.function.name} result:\n${s.content}${s.error ? `\nError: ${s.error}` : ""}`
347
- }, d = [
348
- ...t,
349
- r,
350
- c
351
- ];
352
- u((e) => [...e, c]), await b(d);
353
- return;
354
- }
355
- } catch (e) {
356
- r.content = `Error: ${e instanceof Error ? e.message : String(e)}`, u((e) => {
357
- let t = [...e];
358
- return t[t.length - 1] = { ...r }, t;
359
- });
360
- } finally {
361
- g(!1);
362
- }
363
- }, [e, n]), x = h(async (e) => {
364
- // v8 ignore next
365
- if (!v) return;
366
- let t = v;
367
- if (y(null), g(!0), e) {
368
- let e = await o(t.function.name, t.function.arguments), n = {
369
- role: l.SYSTEM,
370
- content: `Tool ${t.function.name} result:\n${e.content}${e.error ? `\nError: ${e.error}` : ""}`
371
- }, r = [...s, n];
372
- u((e) => [...e, n]), await b(r);
373
- } else {
374
- let e = {
375
- role: l.SYSTEM,
376
- content: `User declined to execute tool ${t.function.name}`
377
- }, n = [...s, e];
378
- u((t) => [...t, e]), await b(n);
379
- }
380
- }, [
381
- v,
382
- s,
383
- b
384
- ]), S = h(async (e) => {
385
- let n = e.trim();
386
- if (!n) return;
387
- if (p((e) => e + 1), n.startsWith("/")) {
388
- t(n);
389
- return;
390
- }
391
- g(!0);
392
- let r = {
393
- role: l.USER,
394
- content: n
395
- };
396
- u((e) => [...e, r]), await b([...s, r]);
397
- }, [
398
- s,
399
- t,
400
- b
401
- ]);
402
- return /* @__PURE__ */ (0, D.jsxs)(d, {
403
- flexDirection: "column",
404
- children: [
405
- /* @__PURE__ */ (0, D.jsx)(j, {
406
- messages: s.slice(1),
407
- isLoading: m
408
- }),
409
- v && /* @__PURE__ */ (0, D.jsx)(M, {
410
- toolCall: v,
411
- onApprove: () => void x(!0),
412
- onReject: () => void x(!1)
413
- }),
414
- !v && /* @__PURE__ */ (0, D.jsx)(k, {
415
- isDisabled: m,
416
- onSubmit: (e) => {
417
- S(e);
418
- }
419
- }, f)
420
- ]
421
- });
422
- }
423
- //#endregion
424
- //#region src/components/Footer.tsx
425
- function P({ autoExecute: e, onToggleMode: t }) {
426
- return m((e, n) => {
427
- n.tab && n.shift && t();
428
- }), /* @__PURE__ */ (0, D.jsx)(d, {
429
- justifyContent: "space-between",
430
- marginTop: 1,
431
- children: /* @__PURE__ */ (0, D.jsxs)(f, {
432
- dimColor: !0,
433
- children: [
434
- "Mode: ",
435
- e ? "Auto" : "Safe",
436
- " (Shift+Tab to toggle)"
437
- ]
438
- })
439
- });
440
- }
441
- //#endregion
442
- //#region src/components/Header.tsx
443
- function F(e) {
444
- let t = u();
445
- return e.startsWith(t) ? `~${e.slice(t.length)}` : e;
446
- }
447
- function I({ model: e }) {
448
- let t = F(process.cwd());
449
- return /* @__PURE__ */ (0, D.jsxs)(d, {
450
- borderStyle: "round",
451
- flexDirection: "column",
452
- paddingX: 1,
453
- children: [
454
- /* @__PURE__ */ (0, D.jsxs)(f, { children: [/* @__PURE__ */ (0, D.jsxs)(f, {
455
- bold: !0,
456
- children: [w, "Code Ollama"]
457
- }), /* @__PURE__ */ (0, D.jsxs)(f, {
458
- dimColor: !0,
459
- children: [
460
- " (v",
461
- n,
462
- ")"
463
- ]
464
- })] }),
465
- /* @__PURE__ */ (0, D.jsx)(f, { children: " " }),
466
- /* @__PURE__ */ (0, D.jsxs)(d, { children: [
467
- /* @__PURE__ */ (0, D.jsx)(f, {
468
- dimColor: !0,
469
- children: "model:".padEnd(11)
470
- }),
471
- /* @__PURE__ */ (0, D.jsxs)(f, { children: [e, " "] }),
472
- /* @__PURE__ */ (0, D.jsx)(f, {
473
- color: "cyan",
474
- children: "/model"
475
- }),
476
- /* @__PURE__ */ (0, D.jsx)(f, {
477
- dimColor: !0,
478
- children: " to switch"
479
- })
480
- ] }),
481
- /* @__PURE__ */ (0, D.jsxs)(d, { children: [/* @__PURE__ */ (0, D.jsx)(f, {
482
- dimColor: !0,
483
- children: "directory:".padEnd(11)
484
- }), /* @__PURE__ */ (0, D.jsx)(f, { children: t })] })
485
- ]
486
- });
487
- }
488
- //#endregion
489
- //#region src/components/ModelPicker.tsx
490
- function L({ currentModel: t, onSelect: n, onCancel: r }) {
491
- let [i, a] = _([]), [o, s] = _(null);
492
- return g(() => {
493
- async function t() {
494
- try {
495
- a((await e()).map((e) => ({
496
- label: e,
497
- value: e
498
- })));
499
- } catch (e) {
500
- s(e instanceof Error ? e.message : String(e));
501
- }
502
- }
503
- t();
504
- }, []), m((e, t) => {
505
- t.escape && r();
506
- }), o ? /* @__PURE__ */ (0, D.jsxs)(f, {
507
- color: "red",
508
- children: ["Error loading models: ", o]
509
- }) : i.length ? /* @__PURE__ */ (0, D.jsxs)(d, {
510
- flexDirection: "column",
511
- children: [/* @__PURE__ */ (0, D.jsx)(f, {
512
- dimColor: !0,
513
- children: "Select a model (↑↓ + Enter to confirm, Esc to cancel)"
514
- }), /* @__PURE__ */ (0, D.jsx)(v, {
515
- options: i,
516
- defaultValue: t,
517
- onChange: n
518
- })]
519
- }) : /* @__PURE__ */ (0, D.jsx)(y, { label: "Loading models..." });
520
- }
521
- //#endregion
522
- //#region src/components/App.tsx
523
- function R() {
524
- let [e, n] = _(() => s().model), [r, i] = _(!1), [a, o] = _(!1), c = h((e) => {
525
- e === "/model" && i(!0);
526
- }, []), l = h((e) => {
527
- n(e), t({ model: e }), i(!1);
528
- }, []), u = h(() => {
529
- i(!1);
530
- }, []);
531
- return /* @__PURE__ */ (0, D.jsxs)(d, {
532
- flexDirection: "column",
533
- children: [
534
- /* @__PURE__ */ (0, D.jsx)(I, { model: e }),
535
- r ? /* @__PURE__ */ (0, D.jsx)(L, {
536
- currentModel: e,
537
- onSelect: l,
538
- onCancel: u
539
- }) : /* @__PURE__ */ (0, D.jsx)(N, {
540
- model: e,
541
- onCommand: c,
542
- autoExecute: a
543
- }),
544
- /* @__PURE__ */ (0, D.jsx)(P, {
545
- autoExecute: a,
546
- onToggleMode: () => {
547
- o((e) => !e);
548
- }
549
- })
550
- ]
551
- });
552
- }
553
- //#endregion
554
- //#region src/tui.tsx
555
- function z() {
556
- p(/* @__PURE__ */ (0, D.jsx)(R, {}));
557
- }
558
- //#endregion
559
- export { z as renderApp };