@sheepbun/yips 0.1.1

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 (99) hide show
  1. package/dist/agent/commands/command-catalog.js +243 -0
  2. package/dist/agent/commands/commands.js +418 -0
  3. package/dist/agent/conductor.js +118 -0
  4. package/dist/agent/context/code-context.js +68 -0
  5. package/dist/agent/context/memory-store.js +159 -0
  6. package/dist/agent/context/session-store.js +211 -0
  7. package/dist/agent/protocol/tool-protocol.js +160 -0
  8. package/dist/agent/skills/skills.js +327 -0
  9. package/dist/agent/tools/tool-executor.js +415 -0
  10. package/dist/agent/tools/tool-safety.js +52 -0
  11. package/dist/app/index.js +35 -0
  12. package/dist/app/repl.js +105 -0
  13. package/dist/app/update-check.js +132 -0
  14. package/dist/app/version.js +51 -0
  15. package/dist/code-context.js +68 -0
  16. package/dist/colors.js +204 -0
  17. package/dist/command-catalog.js +242 -0
  18. package/dist/commands.js +350 -0
  19. package/dist/conductor.js +94 -0
  20. package/dist/config/config.js +335 -0
  21. package/dist/config/hooks.js +187 -0
  22. package/dist/config.js +335 -0
  23. package/dist/downloader-state.js +302 -0
  24. package/dist/downloader-ui.js +289 -0
  25. package/dist/gateway/adapters/discord.js +108 -0
  26. package/dist/gateway/adapters/formatting.js +96 -0
  27. package/dist/gateway/adapters/telegram.js +106 -0
  28. package/dist/gateway/adapters/types.js +2 -0
  29. package/dist/gateway/adapters/whatsapp.js +124 -0
  30. package/dist/gateway/auth-policy.js +66 -0
  31. package/dist/gateway/core.js +87 -0
  32. package/dist/gateway/headless-conductor.js +328 -0
  33. package/dist/gateway/message-router.js +23 -0
  34. package/dist/gateway/rate-limiter.js +48 -0
  35. package/dist/gateway/runtime/backend-policy.js +18 -0
  36. package/dist/gateway/runtime/discord-bot.js +104 -0
  37. package/dist/gateway/runtime/discord-main.js +69 -0
  38. package/dist/gateway/session-manager.js +77 -0
  39. package/dist/gateway/types.js +2 -0
  40. package/dist/hardware.js +92 -0
  41. package/dist/hooks.js +187 -0
  42. package/dist/index.js +34 -0
  43. package/dist/input-engine.js +250 -0
  44. package/dist/llama-client.js +227 -0
  45. package/dist/llama-server.js +620 -0
  46. package/dist/llm/llama-client.js +227 -0
  47. package/dist/llm/llama-server.js +620 -0
  48. package/dist/llm/token-counter.js +47 -0
  49. package/dist/memory-store.js +159 -0
  50. package/dist/messages.js +59 -0
  51. package/dist/model-downloader.js +382 -0
  52. package/dist/model-manager-state.js +118 -0
  53. package/dist/model-manager-ui.js +194 -0
  54. package/dist/model-manager.js +190 -0
  55. package/dist/models/hardware.js +92 -0
  56. package/dist/models/model-downloader.js +382 -0
  57. package/dist/models/model-manager.js +190 -0
  58. package/dist/prompt-box.js +78 -0
  59. package/dist/prompt-composer.js +498 -0
  60. package/dist/repl.js +105 -0
  61. package/dist/session-store.js +211 -0
  62. package/dist/spinner.js +76 -0
  63. package/dist/title-box.js +388 -0
  64. package/dist/token-counter.js +47 -0
  65. package/dist/tool-executor.js +415 -0
  66. package/dist/tool-protocol.js +121 -0
  67. package/dist/tool-safety.js +52 -0
  68. package/dist/tui/app.js +2553 -0
  69. package/dist/tui/startup.js +56 -0
  70. package/dist/tui-input-routing.js +53 -0
  71. package/dist/tui.js +51 -0
  72. package/dist/types/app-types.js +2 -0
  73. package/dist/types.js +2 -0
  74. package/dist/ui/colors.js +204 -0
  75. package/dist/ui/downloader/downloader-state.js +302 -0
  76. package/dist/ui/downloader/downloader-ui.js +289 -0
  77. package/dist/ui/input/input-engine.js +250 -0
  78. package/dist/ui/input/tui-input-routing.js +53 -0
  79. package/dist/ui/input/vt-session.js +168 -0
  80. package/dist/ui/messages.js +59 -0
  81. package/dist/ui/model-manager/model-manager-state.js +118 -0
  82. package/dist/ui/model-manager/model-manager-ui.js +194 -0
  83. package/dist/ui/prompt/prompt-box.js +78 -0
  84. package/dist/ui/prompt/prompt-composer.js +498 -0
  85. package/dist/ui/spinner.js +76 -0
  86. package/dist/ui/title-box.js +388 -0
  87. package/dist/ui/tui/app.js +6 -0
  88. package/dist/ui/tui/autocomplete.js +85 -0
  89. package/dist/ui/tui/constants.js +18 -0
  90. package/dist/ui/tui/history.js +29 -0
  91. package/dist/ui/tui/layout.js +341 -0
  92. package/dist/ui/tui/runtime-core.js +2584 -0
  93. package/dist/ui/tui/runtime-utils.js +53 -0
  94. package/dist/ui/tui/start-tui.js +54 -0
  95. package/dist/ui/tui/startup.js +56 -0
  96. package/dist/version.js +51 -0
  97. package/dist/vt-session.js +168 -0
  98. package/install.sh +457 -0
  99. package/package.json +128 -0
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LlamaClient = void 0;
4
+ const CHAT_COMPLETIONS_PATH = "/v1/chat/completions";
5
+ const DEFAULT_TIMEOUT_MS = 30_000;
6
+ function isRecord(value) {
7
+ return typeof value === "object" && value !== null;
8
+ }
9
+ function normalizeBaseUrl(baseUrl) {
10
+ return baseUrl.replace(/\/+$/, "");
11
+ }
12
+ function toErrorMessage(error) {
13
+ return error instanceof Error ? error.message : String(error);
14
+ }
15
+ function extractFirstChoice(payload) {
16
+ if (!isRecord(payload)) {
17
+ return null;
18
+ }
19
+ const choices = payload["choices"];
20
+ if (!Array.isArray(choices) || choices.length === 0) {
21
+ return null;
22
+ }
23
+ const first = choices[0];
24
+ return isRecord(first) ? first : null;
25
+ }
26
+ function extractMessageContent(choice) {
27
+ const message = choice["message"];
28
+ if (isRecord(message) && typeof message["content"] === "string") {
29
+ return message["content"];
30
+ }
31
+ return "";
32
+ }
33
+ function extractDeltaContent(choice) {
34
+ const delta = choice["delta"];
35
+ if (isRecord(delta) && typeof delta["content"] === "string") {
36
+ return delta["content"];
37
+ }
38
+ return "";
39
+ }
40
+ function parseStreamLine(line) {
41
+ if (!line.startsWith("data:")) {
42
+ return { done: false, token: "" };
43
+ }
44
+ const payload = line.slice("data:".length).trim();
45
+ if (payload.length === 0) {
46
+ return { done: false, token: "" };
47
+ }
48
+ if (payload === "[DONE]") {
49
+ return { done: true, token: "" };
50
+ }
51
+ let parsed;
52
+ try {
53
+ parsed = JSON.parse(payload);
54
+ }
55
+ catch {
56
+ throw new Error(`Failed to parse streaming payload: ${payload.slice(0, 200)}`);
57
+ }
58
+ const choice = extractFirstChoice(parsed);
59
+ const usage = extractUsageTotals(parsed);
60
+ if (!choice) {
61
+ return { done: false, token: "", usage };
62
+ }
63
+ const token = extractDeltaContent(choice) || extractMessageContent(choice);
64
+ return { done: false, token, usage };
65
+ }
66
+ function extractUsageTotals(payload) {
67
+ if (!isRecord(payload)) {
68
+ return undefined;
69
+ }
70
+ const usage = payload["usage"];
71
+ if (!isRecord(usage)) {
72
+ return undefined;
73
+ }
74
+ const promptTokens = usage["prompt_tokens"];
75
+ const completionTokens = usage["completion_tokens"];
76
+ const totalTokens = usage["total_tokens"];
77
+ if (typeof promptTokens !== "number" ||
78
+ typeof completionTokens !== "number" ||
79
+ typeof totalTokens !== "number") {
80
+ return undefined;
81
+ }
82
+ if (promptTokens < 0 || completionTokens < 0 || totalTokens < 0) {
83
+ return undefined;
84
+ }
85
+ return { promptTokens, completionTokens, totalTokens };
86
+ }
87
+ async function readErrorBody(response) {
88
+ try {
89
+ return (await response.text()).trim();
90
+ }
91
+ catch {
92
+ return "";
93
+ }
94
+ }
95
+ class LlamaClient {
96
+ baseUrl;
97
+ model;
98
+ timeoutMs;
99
+ fetchImpl;
100
+ constructor(options) {
101
+ this.baseUrl = normalizeBaseUrl(options.baseUrl);
102
+ this.model = options.model.trim();
103
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
104
+ this.fetchImpl = options.fetchImpl ?? fetch;
105
+ }
106
+ setModel(model) {
107
+ const next = model.trim();
108
+ if (next.length > 0) {
109
+ this.model = next;
110
+ }
111
+ }
112
+ getModel() {
113
+ return this.model;
114
+ }
115
+ async chat(messages, model = this.model) {
116
+ const payload = this.buildPayload(messages, model, false);
117
+ const response = await this.requestCompletion(payload);
118
+ const parsed = await response.json();
119
+ const choice = extractFirstChoice(parsed);
120
+ if (!choice) {
121
+ throw new Error("Chat completion response did not include choices.");
122
+ }
123
+ const content = extractMessageContent(choice);
124
+ if (content.length === 0) {
125
+ throw new Error("Chat completion response did not include assistant content.");
126
+ }
127
+ return {
128
+ text: content,
129
+ usage: extractUsageTotals(parsed)
130
+ };
131
+ }
132
+ async streamChat(messages, handlers, model = this.model) {
133
+ const payload = this.buildPayload(messages, model, true);
134
+ const response = await this.requestCompletion(payload);
135
+ if (!response.body) {
136
+ throw new Error("Streaming response body is unavailable.");
137
+ }
138
+ const reader = response.body.getReader();
139
+ const decoder = new TextDecoder();
140
+ let buffer = "";
141
+ let content = "";
142
+ let streamDone = false;
143
+ let usage;
144
+ try {
145
+ while (!streamDone) {
146
+ const { value, done } = await reader.read();
147
+ if (done) {
148
+ break;
149
+ }
150
+ buffer += decoder.decode(value, { stream: true });
151
+ const lines = buffer.split(/\r?\n/);
152
+ buffer = lines.pop() ?? "";
153
+ for (const line of lines) {
154
+ const result = parseStreamLine(line.trim());
155
+ if (result.usage) {
156
+ usage = result.usage;
157
+ }
158
+ if (result.token.length > 0) {
159
+ content += result.token;
160
+ handlers.onToken(result.token);
161
+ }
162
+ if (result.done) {
163
+ streamDone = true;
164
+ break;
165
+ }
166
+ }
167
+ }
168
+ const finalChunk = decoder.decode();
169
+ if (finalChunk.length > 0) {
170
+ buffer += finalChunk;
171
+ }
172
+ if (!streamDone && buffer.trim().length > 0) {
173
+ const result = parseStreamLine(buffer.trim());
174
+ if (result.usage) {
175
+ usage = result.usage;
176
+ }
177
+ if (result.token.length > 0) {
178
+ content += result.token;
179
+ handlers.onToken(result.token);
180
+ }
181
+ }
182
+ return { text: content, usage };
183
+ }
184
+ finally {
185
+ reader.releaseLock();
186
+ }
187
+ }
188
+ buildPayload(messages, model, stream) {
189
+ return {
190
+ model: model.trim() || this.model,
191
+ messages,
192
+ stream
193
+ };
194
+ }
195
+ async requestCompletion(payload) {
196
+ const controller = new AbortController();
197
+ const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
198
+ const endpoint = `${this.baseUrl}${CHAT_COMPLETIONS_PATH}`;
199
+ let response;
200
+ try {
201
+ response = await this.fetchImpl(endpoint, {
202
+ method: "POST",
203
+ headers: {
204
+ "content-type": "application/json"
205
+ },
206
+ body: JSON.stringify(payload),
207
+ signal: controller.signal
208
+ });
209
+ }
210
+ catch (error) {
211
+ if (error instanceof Error && error.name === "AbortError") {
212
+ throw new Error(`llama.cpp request timed out after ${this.timeoutMs}ms.`);
213
+ }
214
+ throw new Error(`Failed to connect to llama.cpp at ${this.baseUrl}: ${toErrorMessage(error)}`);
215
+ }
216
+ finally {
217
+ clearTimeout(timeout);
218
+ }
219
+ if (!response.ok) {
220
+ const details = await readErrorBody(response);
221
+ const suffix = details.length > 0 ? `: ${details}` : "";
222
+ throw new Error(`llama.cpp request failed (${response.status} ${response.statusText})${suffix}`);
223
+ }
224
+ return response;
225
+ }
226
+ }
227
+ exports.LlamaClient = LlamaClient;