hoomanjs 1.41.1 → 1.42.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.
- package/README.md +1 -1
- package/dist/acp/acp-agent.js +21 -0
- package/dist/acp/acp-agent.js.map +1 -1
- package/dist/chat/app.js +10 -1
- package/dist/chat/app.js.map +1 -1
- package/dist/chat/components/BottomChrome.d.ts +4 -1
- package/dist/chat/components/BottomChrome.js +3 -2
- package/dist/chat/components/BottomChrome.js.map +1 -1
- package/dist/chat/components/DownloadPanel.d.ts +9 -0
- package/dist/chat/components/DownloadPanel.js +16 -0
- package/dist/chat/components/DownloadPanel.js.map +1 -0
- package/dist/cli.js +21 -23
- package/dist/cli.js.map +1 -1
- package/dist/configure/app.js +30 -2
- package/dist/configure/app.js.map +1 -1
- package/dist/core/config.d.ts +57 -0
- package/dist/core/config.js +25 -5
- package/dist/core/config.js.map +1 -1
- package/dist/core/mcp/manager.js.map +1 -1
- package/dist/core/models/download-progress.d.ts +65 -0
- package/dist/core/models/download-progress.js +154 -0
- package/dist/core/models/download-progress.js.map +1 -0
- package/dist/core/models/index.js +1 -0
- package/dist/core/models/index.js.map +1 -1
- package/dist/core/models/llama-cpp/gbnf-schema.d.ts +32 -0
- package/dist/core/models/llama-cpp/gbnf-schema.js +272 -0
- package/dist/core/models/llama-cpp/gbnf-schema.js.map +1 -0
- package/dist/core/models/llama-cpp/index.d.ts +8 -0
- package/dist/core/models/llama-cpp/index.js +37 -0
- package/dist/core/models/llama-cpp/index.js.map +1 -0
- package/dist/core/models/llama-cpp/resolve-model.d.ts +28 -0
- package/dist/core/models/llama-cpp/resolve-model.js +307 -0
- package/dist/core/models/llama-cpp/resolve-model.js.map +1 -0
- package/dist/core/models/llama-cpp/strands-llama-cpp.d.ts +40 -0
- package/dist/core/models/llama-cpp/strands-llama-cpp.js +422 -0
- package/dist/core/models/llama-cpp/strands-llama-cpp.js.map +1 -0
- package/dist/core/models/types.d.ts +115 -1
- package/dist/core/models/types.js +19 -0
- package/dist/core/models/types.js.map +1 -1
- package/dist/core/skills/built-in/hooman-config/SKILL.md +21 -5
- package/dist/core/skills/built-in/hooman-config/providers.md +2 -0
- package/dist/core/utils/logging.d.ts +29 -0
- package/dist/core/utils/logging.js +64 -0
- package/dist/core/utils/logging.js.map +1 -0
- package/dist/daemon/index.js +5 -0
- package/dist/daemon/index.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { ContextWindowOverflowError, Model, ModelError, } from "@strands-agents/sdk";
|
|
2
|
+
import { ModelContentBlockDeltaEvent, ModelContentBlockStartEvent, ModelContentBlockStopEvent, ModelMessageStartEvent, ModelMessageStopEvent, ModelMetadataEvent, } from "@strands-agents/sdk";
|
|
3
|
+
import { jsonSchemaToGbnf, pruneOptionalNulls } from "./gbnf-schema.js";
|
|
4
|
+
import { resolveModelFile } from "./resolve-model.js";
|
|
5
|
+
/**
|
|
6
|
+
* Loaded llama.cpp runtimes are expensive (weights in RAM/VRAM), so share them
|
|
7
|
+
* process-wide keyed by resolved GGUF path. Contexts stay per Strands model
|
|
8
|
+
* instance so concurrent agents (e.g. subagents) get independent sequences.
|
|
9
|
+
*/
|
|
10
|
+
const llamaRuntimePromises = new Map();
|
|
11
|
+
const loadedModelPromises = new Map();
|
|
12
|
+
function extractSystemText(system) {
|
|
13
|
+
if (system === undefined) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (typeof system === "string") {
|
|
17
|
+
return system;
|
|
18
|
+
}
|
|
19
|
+
const parts = [];
|
|
20
|
+
for (const block of system) {
|
|
21
|
+
if (block.type === "textBlock") {
|
|
22
|
+
parts.push(block.text);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const joined = parts.join("\n").trim();
|
|
26
|
+
return joined.length > 0 ? joined : undefined;
|
|
27
|
+
}
|
|
28
|
+
function contentBlockToText(block) {
|
|
29
|
+
if (block.type === "textBlock") {
|
|
30
|
+
return block.text;
|
|
31
|
+
}
|
|
32
|
+
if (block.type === "imageBlock") {
|
|
33
|
+
return "(llama.cpp: image content is not supported by this provider)";
|
|
34
|
+
}
|
|
35
|
+
if (block.type === "videoBlock" || block.type === "documentBlock") {
|
|
36
|
+
return `(llama.cpp: ${block.type} content is not supported by this provider)`;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
function toolResultToText(block) {
|
|
41
|
+
const parts = [];
|
|
42
|
+
for (const c of block.content) {
|
|
43
|
+
if (c.type === "textBlock") {
|
|
44
|
+
parts.push(c.text);
|
|
45
|
+
}
|
|
46
|
+
else if (c.type === "jsonBlock") {
|
|
47
|
+
parts.push(JSON.stringify(c.json));
|
|
48
|
+
}
|
|
49
|
+
else if (c.type === "imageBlock") {
|
|
50
|
+
parts.push("(llama.cpp: image tool results are not supported)");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const joined = parts.join("\n");
|
|
54
|
+
if (joined.length > 0) {
|
|
55
|
+
return joined;
|
|
56
|
+
}
|
|
57
|
+
return block.status === "error" ? "(tool error)" : "";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Convert Strands conversation history to node-llama-cpp `ChatHistoryItem[]`.
|
|
61
|
+
* Tool calls are paired with their results (`ChatModelFunctionCall` requires
|
|
62
|
+
* both) by `toolUseId`: the toolUse blocks live on assistant messages and the
|
|
63
|
+
* matching toolResult blocks on the following user message, so results are
|
|
64
|
+
* folded back into the preceding model response.
|
|
65
|
+
*/
|
|
66
|
+
function strandsMessagesToHistory(messages, systemText) {
|
|
67
|
+
const history = [];
|
|
68
|
+
if (systemText) {
|
|
69
|
+
history.push({ type: "system", text: systemText });
|
|
70
|
+
}
|
|
71
|
+
const pendingToolUses = new Map();
|
|
72
|
+
const lastModelResponse = () => {
|
|
73
|
+
const last = history.at(-1);
|
|
74
|
+
if (last?.type === "model") {
|
|
75
|
+
return last;
|
|
76
|
+
}
|
|
77
|
+
const created = { type: "model", response: [] };
|
|
78
|
+
history.push(created);
|
|
79
|
+
return created;
|
|
80
|
+
};
|
|
81
|
+
const pushUserText = (text) => {
|
|
82
|
+
const last = history.at(-1);
|
|
83
|
+
if (last?.type === "user") {
|
|
84
|
+
last.text = last.text.length > 0 ? `${last.text}\n${text}` : text;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
history.push({ type: "user", text });
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
for (const msg of messages) {
|
|
91
|
+
for (const block of msg.content) {
|
|
92
|
+
if (msg.role === "assistant") {
|
|
93
|
+
if (block.type === "toolUseBlock") {
|
|
94
|
+
const b = block;
|
|
95
|
+
pendingToolUses.set(b.toolUseId, b);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (block.type === "reasoningBlock") {
|
|
99
|
+
// Prior turns' chain of thought is not replayed into the context.
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const text = contentBlockToText(block);
|
|
103
|
+
if (text !== undefined && text.length > 0) {
|
|
104
|
+
lastModelResponse().response.push(text);
|
|
105
|
+
}
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
// user role
|
|
109
|
+
if (block.type === "toolResultBlock") {
|
|
110
|
+
const b = block;
|
|
111
|
+
const use = pendingToolUses.get(b.toolUseId);
|
|
112
|
+
pendingToolUses.delete(b.toolUseId);
|
|
113
|
+
const call = {
|
|
114
|
+
type: "functionCall",
|
|
115
|
+
name: use?.name ?? b.toolUseId,
|
|
116
|
+
params: use?.input ?? {},
|
|
117
|
+
result: toolResultToText(b),
|
|
118
|
+
};
|
|
119
|
+
const model = lastModelResponse();
|
|
120
|
+
if (model.response.filter((item) => typeof item !== "string").length === 0) {
|
|
121
|
+
call.startsNewChunk = true;
|
|
122
|
+
}
|
|
123
|
+
model.response.push(call);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const text = contentBlockToText(block);
|
|
127
|
+
if (text !== undefined && text.length > 0) {
|
|
128
|
+
pushUserText(text);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return history;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Convert Strands tool specs to node-llama-cpp function definitions. Tool
|
|
136
|
+
* inputSchemas are standard JSON Schema (Strands emits them via
|
|
137
|
+
* `z.toJSONSchema`), while node-llama-cpp only accepts its GBNF subset —
|
|
138
|
+
* passing e.g. `anyOf` through unconverted fails generation with
|
|
139
|
+
* `Unknown immutable type undefined`. See `gbnf-schema.ts`.
|
|
140
|
+
*/
|
|
141
|
+
function strandsToolsToFunctions(toolSpecs) {
|
|
142
|
+
if (!toolSpecs?.length) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
const functions = {};
|
|
146
|
+
for (const spec of toolSpecs) {
|
|
147
|
+
functions[spec.name] = {
|
|
148
|
+
...(spec.description ? { description: spec.description } : {}),
|
|
149
|
+
...(spec.inputSchema
|
|
150
|
+
? { params: jsonSchemaToGbnf(spec.inputSchema) }
|
|
151
|
+
: {}),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return functions;
|
|
155
|
+
}
|
|
156
|
+
/** Strands {@link Model} backed by in-process llama.cpp via `node-llama-cpp`. */
|
|
157
|
+
export class StrandsLlamaCppModel extends Model {
|
|
158
|
+
config;
|
|
159
|
+
chatPromise;
|
|
160
|
+
context;
|
|
161
|
+
constructor(config) {
|
|
162
|
+
super();
|
|
163
|
+
this.config = { ...config };
|
|
164
|
+
}
|
|
165
|
+
updateConfig(modelConfig) {
|
|
166
|
+
const chatKey = (c) => JSON.stringify([c.modelId, c.gpu, c.contextSize, c.reasoning ?? null]);
|
|
167
|
+
const before = chatKey(this.config);
|
|
168
|
+
this.config = { ...this.config, ...modelConfig };
|
|
169
|
+
if (chatKey(this.config) !== before) {
|
|
170
|
+
// The chat wrapper bakes in reasoning settings and the context bakes in
|
|
171
|
+
// its size, so drop the lazily-built chat/context and rebuild on the
|
|
172
|
+
// next stream call (loaded weights are cached process-wide).
|
|
173
|
+
this.chatPromise = undefined;
|
|
174
|
+
this.context = undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
getConfig() {
|
|
178
|
+
return { ...this.config };
|
|
179
|
+
}
|
|
180
|
+
getChat() {
|
|
181
|
+
this.chatPromise ??= this.initChat();
|
|
182
|
+
return this.chatPromise;
|
|
183
|
+
}
|
|
184
|
+
async initChat() {
|
|
185
|
+
const modelId = this.config.modelId;
|
|
186
|
+
if (!modelId) {
|
|
187
|
+
throw new ModelError("llama.cpp model is not configured");
|
|
188
|
+
}
|
|
189
|
+
const { getLlama, LlamaChat, LlamaLogLevel, resolveChatWrapper } = await import("node-llama-cpp");
|
|
190
|
+
const modelPath = await resolveModelFile(modelId, this.config.hfToken);
|
|
191
|
+
const gpu = this.config.gpu ?? "auto";
|
|
192
|
+
const runtimeKey = JSON.stringify(gpu);
|
|
193
|
+
let llamaPromise = llamaRuntimePromises.get(runtimeKey);
|
|
194
|
+
if (!llamaPromise) {
|
|
195
|
+
// Keep llama.cpp's native logging out of the TUI transcript.
|
|
196
|
+
llamaPromise = getLlama({ gpu, logLevel: LlamaLogLevel.error });
|
|
197
|
+
llamaRuntimePromises.set(runtimeKey, llamaPromise);
|
|
198
|
+
}
|
|
199
|
+
const llama = await llamaPromise;
|
|
200
|
+
let modelPromise = loadedModelPromises.get(modelPath);
|
|
201
|
+
if (!modelPromise) {
|
|
202
|
+
modelPromise = llama.loadModel({ modelPath });
|
|
203
|
+
loadedModelPromises.set(modelPath, modelPromise);
|
|
204
|
+
}
|
|
205
|
+
const model = await modelPromise;
|
|
206
|
+
this.context = await model.createContext({
|
|
207
|
+
...(this.config.contextSize !== undefined
|
|
208
|
+
? { contextSize: this.config.contextSize }
|
|
209
|
+
: {}),
|
|
210
|
+
});
|
|
211
|
+
// Reasoning on/off lives in the chat template, so resolve the wrapper
|
|
212
|
+
// explicitly (same auto-detection LlamaChat would do) with per-wrapper
|
|
213
|
+
// thinking settings derived from the shared `reasoning` option.
|
|
214
|
+
const reasoningEnabled = this.config.reasoning !== undefined;
|
|
215
|
+
const effort = this.config.reasoning?.effort;
|
|
216
|
+
const harmonyEffort = effort === "high" || effort === "medium" ? effort : "low";
|
|
217
|
+
const chatWrapper = resolveChatWrapper(model, {
|
|
218
|
+
customWrapperSettings: {
|
|
219
|
+
qwen: { thoughts: reasoningEnabled ? "auto" : "discourage" },
|
|
220
|
+
gemma4: { reasoning: reasoningEnabled },
|
|
221
|
+
harmony: {
|
|
222
|
+
reasoningEffort: reasoningEnabled ? harmonyEffort : "low",
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
return new LlamaChat({
|
|
227
|
+
contextSequence: this.context.getSequence(),
|
|
228
|
+
chatWrapper,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
async *stream(messages, options) {
|
|
232
|
+
let chat;
|
|
233
|
+
try {
|
|
234
|
+
chat = await this.getChat();
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
// Let a failed init (bad model spec, download failure) be retried.
|
|
238
|
+
this.chatPromise = undefined;
|
|
239
|
+
if (e instanceof ModelError) {
|
|
240
|
+
throw e;
|
|
241
|
+
}
|
|
242
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
243
|
+
throw new ModelError(`llama.cpp initialization failed: ${msg}`, {
|
|
244
|
+
cause: e,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
const systemText = extractSystemText(options?.systemPrompt);
|
|
248
|
+
const history = strandsMessagesToHistory(messages, systemText);
|
|
249
|
+
if (history.at(-1)?.type === "user") {
|
|
250
|
+
history.push({ type: "model", response: [] });
|
|
251
|
+
}
|
|
252
|
+
const functions = strandsToolsToFunctions(options?.toolSpecs);
|
|
253
|
+
const originalSchemas = new Map((options?.toolSpecs ?? []).map((spec) => [spec.name, spec.inputSchema]));
|
|
254
|
+
yield new ModelMessageStartEvent({
|
|
255
|
+
type: "modelMessageStartEvent",
|
|
256
|
+
role: "assistant",
|
|
257
|
+
});
|
|
258
|
+
const queue = [];
|
|
259
|
+
let wake;
|
|
260
|
+
const push = (event) => {
|
|
261
|
+
queue.push(event);
|
|
262
|
+
wake?.();
|
|
263
|
+
};
|
|
264
|
+
let textBlockOpen = false;
|
|
265
|
+
let reasoningBlockOpen = false;
|
|
266
|
+
const closeOpenBlocks = () => {
|
|
267
|
+
if (reasoningBlockOpen) {
|
|
268
|
+
push(new ModelContentBlockStopEvent({
|
|
269
|
+
type: "modelContentBlockStopEvent",
|
|
270
|
+
}));
|
|
271
|
+
reasoningBlockOpen = false;
|
|
272
|
+
}
|
|
273
|
+
if (textBlockOpen) {
|
|
274
|
+
push(new ModelContentBlockStopEvent({
|
|
275
|
+
type: "modelContentBlockStopEvent",
|
|
276
|
+
}));
|
|
277
|
+
textBlockOpen = false;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
const meterBefore = {
|
|
281
|
+
input: chat.sequence.tokenMeter.usedInputTokens,
|
|
282
|
+
output: chat.sequence.tokenMeter.usedOutputTokens,
|
|
283
|
+
};
|
|
284
|
+
// Budget 0 closes any thought segment as soon as it opens, covering models
|
|
285
|
+
// whose template ignores the wrapper's discourage setting (e.g. DeepSeek
|
|
286
|
+
// R1 distills that always think).
|
|
287
|
+
const thoughtBudget = this.config.reasoning === undefined ? 0 : this.config.thoughtBudgetTokens;
|
|
288
|
+
let done = false;
|
|
289
|
+
let failure;
|
|
290
|
+
const generation = chat
|
|
291
|
+
.generateResponse(history, {
|
|
292
|
+
...(functions ? { functions } : {}),
|
|
293
|
+
...(this.config.maxTokens !== undefined
|
|
294
|
+
? { maxTokens: this.config.maxTokens }
|
|
295
|
+
: {}),
|
|
296
|
+
...(this.config.temperature !== undefined
|
|
297
|
+
? { temperature: this.config.temperature }
|
|
298
|
+
: {}),
|
|
299
|
+
...(this.config.topP !== undefined ? { topP: this.config.topP } : {}),
|
|
300
|
+
...(thoughtBudget !== undefined
|
|
301
|
+
? { budgets: { thoughtTokens: thoughtBudget } }
|
|
302
|
+
: {}),
|
|
303
|
+
onResponseChunk: (chunk) => {
|
|
304
|
+
if (chunk.type === "segment") {
|
|
305
|
+
if (chunk.segmentType !== "thought" || chunk.text.length === 0) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (textBlockOpen) {
|
|
309
|
+
push(new ModelContentBlockStopEvent({
|
|
310
|
+
type: "modelContentBlockStopEvent",
|
|
311
|
+
}));
|
|
312
|
+
textBlockOpen = false;
|
|
313
|
+
}
|
|
314
|
+
if (!reasoningBlockOpen) {
|
|
315
|
+
push(new ModelContentBlockStartEvent({
|
|
316
|
+
type: "modelContentBlockStartEvent",
|
|
317
|
+
}));
|
|
318
|
+
reasoningBlockOpen = true;
|
|
319
|
+
}
|
|
320
|
+
push(new ModelContentBlockDeltaEvent({
|
|
321
|
+
type: "modelContentBlockDeltaEvent",
|
|
322
|
+
delta: { type: "reasoningContentDelta", text: chunk.text },
|
|
323
|
+
}));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (chunk.text.length === 0) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (reasoningBlockOpen) {
|
|
330
|
+
push(new ModelContentBlockStopEvent({
|
|
331
|
+
type: "modelContentBlockStopEvent",
|
|
332
|
+
}));
|
|
333
|
+
reasoningBlockOpen = false;
|
|
334
|
+
}
|
|
335
|
+
if (!textBlockOpen) {
|
|
336
|
+
push(new ModelContentBlockStartEvent({
|
|
337
|
+
type: "modelContentBlockStartEvent",
|
|
338
|
+
}));
|
|
339
|
+
textBlockOpen = true;
|
|
340
|
+
}
|
|
341
|
+
push(new ModelContentBlockDeltaEvent({
|
|
342
|
+
type: "modelContentBlockDeltaEvent",
|
|
343
|
+
delta: { type: "textDelta", text: chunk.text },
|
|
344
|
+
}));
|
|
345
|
+
},
|
|
346
|
+
})
|
|
347
|
+
.then((res) => {
|
|
348
|
+
closeOpenBlocks();
|
|
349
|
+
const functionCalls = res.functionCalls ?? [];
|
|
350
|
+
let toolIndex = 0;
|
|
351
|
+
for (const call of functionCalls) {
|
|
352
|
+
const name = call.functionName;
|
|
353
|
+
const toolUseId = functionCalls.length > 1 ? `${name}_${toolIndex}` : name;
|
|
354
|
+
toolIndex += 1;
|
|
355
|
+
// Drop the `null` markers the GBNF grammar uses for optional keys
|
|
356
|
+
// (see gbnf-schema.ts) so tools receive clean params.
|
|
357
|
+
const params = pruneOptionalNulls(call.params ?? {}, originalSchemas.get(name));
|
|
358
|
+
push(new ModelContentBlockStartEvent({
|
|
359
|
+
type: "modelContentBlockStartEvent",
|
|
360
|
+
start: { type: "toolUseStart", name, toolUseId },
|
|
361
|
+
}));
|
|
362
|
+
push(new ModelContentBlockDeltaEvent({
|
|
363
|
+
type: "modelContentBlockDeltaEvent",
|
|
364
|
+
delta: {
|
|
365
|
+
type: "toolUseInputDelta",
|
|
366
|
+
input: JSON.stringify(params ?? {}),
|
|
367
|
+
},
|
|
368
|
+
}));
|
|
369
|
+
push(new ModelContentBlockStopEvent({
|
|
370
|
+
type: "modelContentBlockStopEvent",
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
373
|
+
const stopReason = functionCalls.length > 0
|
|
374
|
+
? "toolUse"
|
|
375
|
+
: res.metadata.stopReason === "maxTokens"
|
|
376
|
+
? "maxTokens"
|
|
377
|
+
: "endTurn";
|
|
378
|
+
push(new ModelMessageStopEvent({
|
|
379
|
+
type: "modelMessageStopEvent",
|
|
380
|
+
stopReason,
|
|
381
|
+
}));
|
|
382
|
+
const inputTokens = chat.sequence.tokenMeter.usedInputTokens - meterBefore.input;
|
|
383
|
+
const outputTokens = chat.sequence.tokenMeter.usedOutputTokens - meterBefore.output;
|
|
384
|
+
push(new ModelMetadataEvent({
|
|
385
|
+
type: "modelMetadataEvent",
|
|
386
|
+
usage: {
|
|
387
|
+
inputTokens,
|
|
388
|
+
outputTokens,
|
|
389
|
+
totalTokens: inputTokens + outputTokens,
|
|
390
|
+
},
|
|
391
|
+
}));
|
|
392
|
+
})
|
|
393
|
+
.catch((e) => {
|
|
394
|
+
failure = e;
|
|
395
|
+
})
|
|
396
|
+
.finally(() => {
|
|
397
|
+
done = true;
|
|
398
|
+
wake?.();
|
|
399
|
+
});
|
|
400
|
+
while (!done || queue.length > 0) {
|
|
401
|
+
if (queue.length > 0) {
|
|
402
|
+
yield queue.shift();
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
await new Promise((resolve) => {
|
|
406
|
+
wake = resolve;
|
|
407
|
+
});
|
|
408
|
+
wake = undefined;
|
|
409
|
+
}
|
|
410
|
+
await generation;
|
|
411
|
+
if (failure !== undefined) {
|
|
412
|
+
const msg = failure instanceof Error ? failure.message : String(failure);
|
|
413
|
+
if (msg.toLowerCase().includes("context size")) {
|
|
414
|
+
throw new ContextWindowOverflowError(msg);
|
|
415
|
+
}
|
|
416
|
+
throw new ModelError(`llama.cpp generation error: ${msg}`, {
|
|
417
|
+
cause: failure,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
//# sourceMappingURL=strands-llama-cpp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strands-llama-cpp.js","sourceRoot":"","sources":["../../../../src/core/models/llama-cpp/strands-llama-cpp.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,KAAK,EACL,UAAU,GACX,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAa7B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB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}
|
|
@@ -5,6 +5,7 @@ export declare enum LlmProvider {
|
|
|
5
5
|
Bedrock = "bedrock",
|
|
6
6
|
Google = "google",
|
|
7
7
|
Groq = "groq",
|
|
8
|
+
LlamaCpp = "llama-cpp",
|
|
8
9
|
Minimax = "minimax",
|
|
9
10
|
Moonshot = "moonshot",
|
|
10
11
|
Ollama = "ollama",
|
|
@@ -130,6 +131,32 @@ export type GroqProviderOptions = {
|
|
|
130
131
|
*/
|
|
131
132
|
reasoning?: ReasoningOptions;
|
|
132
133
|
};
|
|
134
|
+
export type LlamaCppProviderOptions = {
|
|
135
|
+
/**
|
|
136
|
+
* Hugging Face access token used when downloading GGUF weights from the Hub
|
|
137
|
+
* (gated/private repos). Falls back to the `HF_TOKEN` env var when unset.
|
|
138
|
+
*/
|
|
139
|
+
hfToken?: string;
|
|
140
|
+
/**
|
|
141
|
+
* GPU backend forwarded to node-llama-cpp's `getLlama` (default `"auto"`).
|
|
142
|
+
* Set `false` to force CPU-only inference.
|
|
143
|
+
*/
|
|
144
|
+
gpu?: "auto" | "metal" | "cuda" | "vulkan" | false;
|
|
145
|
+
/**
|
|
146
|
+
* Context size in tokens for the llama.cpp context. When omitted,
|
|
147
|
+
* node-llama-cpp adapts it to the model's training context and free memory.
|
|
148
|
+
*/
|
|
149
|
+
contextSize?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Reasoning controls. Providing `reasoning` enables thinking: the chat
|
|
152
|
+
* template is configured to allow thought segments (Qwen `thoughts: "auto"`,
|
|
153
|
+
* Gemma 4 `reasoning: true`, gpt-oss/Harmony native reasoning-effort) and
|
|
154
|
+
* `effort` caps thought tokens via node-llama-cpp's thought budget
|
|
155
|
+
* (1024/2048/4096/8192, default `medium`). Omit `reasoning` to disable
|
|
156
|
+
* thinking (templates discourage thoughts, thought budget forced to 0).
|
|
157
|
+
*/
|
|
158
|
+
reasoning?: ReasoningOptions;
|
|
159
|
+
};
|
|
133
160
|
export type MinimaxProviderOptions = {
|
|
134
161
|
apiKey?: string;
|
|
135
162
|
baseURL?: string;
|
|
@@ -211,7 +238,7 @@ export type XaiProviderOptions = {
|
|
|
211
238
|
*/
|
|
212
239
|
reasoning?: ReasoningOptions;
|
|
213
240
|
};
|
|
214
|
-
export type ProviderOptions = AnthropicProviderOptions | AzureProviderOptions | BedrockProviderOptions | GoogleProviderOptions | GroqProviderOptions | MinimaxProviderOptions | MoonshotProviderOptions | OllamaProviderOptions | OpenAIProviderOptions | OpenRouterProviderOptions | XaiProviderOptions;
|
|
241
|
+
export type ProviderOptions = AnthropicProviderOptions | AzureProviderOptions | BedrockProviderOptions | GoogleProviderOptions | GroqProviderOptions | LlamaCppProviderOptions | MinimaxProviderOptions | MoonshotProviderOptions | OllamaProviderOptions | OpenAIProviderOptions | OpenRouterProviderOptions | XaiProviderOptions;
|
|
215
242
|
export declare const OpenAIApiSchema: z.ZodEnum<{
|
|
216
243
|
chat: "chat";
|
|
217
244
|
responses: "responses";
|
|
@@ -387,6 +414,34 @@ export declare const GroqProviderOptionsSchema: z.ZodObject<{
|
|
|
387
414
|
}>>;
|
|
388
415
|
}, z.core.$strict>>;
|
|
389
416
|
}, z.core.$strict>;
|
|
417
|
+
export declare const LlamaCppProviderOptionsSchema: z.ZodObject<{
|
|
418
|
+
hfToken: z.ZodOptional<z.ZodString>;
|
|
419
|
+
gpu: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
420
|
+
auto: "auto";
|
|
421
|
+
metal: "metal";
|
|
422
|
+
cuda: "cuda";
|
|
423
|
+
vulkan: "vulkan";
|
|
424
|
+
}>, z.ZodLiteral<false>]>>;
|
|
425
|
+
contextSize: z.ZodOptional<z.ZodNumber>;
|
|
426
|
+
reasoning: z.ZodOptional<z.ZodObject<{
|
|
427
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
428
|
+
minimal: "minimal";
|
|
429
|
+
low: "low";
|
|
430
|
+
medium: "medium";
|
|
431
|
+
high: "high";
|
|
432
|
+
}>>;
|
|
433
|
+
summary: z.ZodOptional<z.ZodEnum<{
|
|
434
|
+
auto: "auto";
|
|
435
|
+
concise: "concise";
|
|
436
|
+
detailed: "detailed";
|
|
437
|
+
none: "none";
|
|
438
|
+
}>>;
|
|
439
|
+
display: z.ZodOptional<z.ZodEnum<{
|
|
440
|
+
summarized: "summarized";
|
|
441
|
+
omitted: "omitted";
|
|
442
|
+
}>>;
|
|
443
|
+
}, z.core.$strict>>;
|
|
444
|
+
}, z.core.$strict>;
|
|
390
445
|
export declare const MinimaxProviderOptionsSchema: z.ZodObject<{
|
|
391
446
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
392
447
|
baseURL: z.ZodOptional<z.ZodString>;
|
|
@@ -646,6 +701,34 @@ export declare const ProviderOptionsSchemas: {
|
|
|
646
701
|
}>>;
|
|
647
702
|
}, z.core.$strict>>;
|
|
648
703
|
}, z.core.$strict>;
|
|
704
|
+
readonly "llama-cpp": z.ZodObject<{
|
|
705
|
+
hfToken: z.ZodOptional<z.ZodString>;
|
|
706
|
+
gpu: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
707
|
+
auto: "auto";
|
|
708
|
+
metal: "metal";
|
|
709
|
+
cuda: "cuda";
|
|
710
|
+
vulkan: "vulkan";
|
|
711
|
+
}>, z.ZodLiteral<false>]>>;
|
|
712
|
+
contextSize: z.ZodOptional<z.ZodNumber>;
|
|
713
|
+
reasoning: z.ZodOptional<z.ZodObject<{
|
|
714
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
715
|
+
minimal: "minimal";
|
|
716
|
+
low: "low";
|
|
717
|
+
medium: "medium";
|
|
718
|
+
high: "high";
|
|
719
|
+
}>>;
|
|
720
|
+
summary: z.ZodOptional<z.ZodEnum<{
|
|
721
|
+
auto: "auto";
|
|
722
|
+
concise: "concise";
|
|
723
|
+
detailed: "detailed";
|
|
724
|
+
none: "none";
|
|
725
|
+
}>>;
|
|
726
|
+
display: z.ZodOptional<z.ZodEnum<{
|
|
727
|
+
summarized: "summarized";
|
|
728
|
+
omitted: "omitted";
|
|
729
|
+
}>>;
|
|
730
|
+
}, z.core.$strict>>;
|
|
731
|
+
}, z.core.$strict>;
|
|
649
732
|
readonly minimax: z.ZodObject<{
|
|
650
733
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
651
734
|
baseURL: z.ZodOptional<z.ZodString>;
|
|
@@ -920,6 +1003,37 @@ export declare const NamedProviderConfigSchema: z.ZodDiscriminatedUnion<[z.ZodOb
|
|
|
920
1003
|
}>>;
|
|
921
1004
|
}, z.core.$strict>>;
|
|
922
1005
|
}, z.core.$strict>;
|
|
1006
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
1007
|
+
name: z.ZodString;
|
|
1008
|
+
provider: z.ZodLiteral<LlmProvider.LlamaCpp>;
|
|
1009
|
+
options: z.ZodObject<{
|
|
1010
|
+
hfToken: z.ZodOptional<z.ZodString>;
|
|
1011
|
+
gpu: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
1012
|
+
auto: "auto";
|
|
1013
|
+
metal: "metal";
|
|
1014
|
+
cuda: "cuda";
|
|
1015
|
+
vulkan: "vulkan";
|
|
1016
|
+
}>, z.ZodLiteral<false>]>>;
|
|
1017
|
+
contextSize: z.ZodOptional<z.ZodNumber>;
|
|
1018
|
+
reasoning: z.ZodOptional<z.ZodObject<{
|
|
1019
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
1020
|
+
minimal: "minimal";
|
|
1021
|
+
low: "low";
|
|
1022
|
+
medium: "medium";
|
|
1023
|
+
high: "high";
|
|
1024
|
+
}>>;
|
|
1025
|
+
summary: z.ZodOptional<z.ZodEnum<{
|
|
1026
|
+
auto: "auto";
|
|
1027
|
+
concise: "concise";
|
|
1028
|
+
detailed: "detailed";
|
|
1029
|
+
none: "none";
|
|
1030
|
+
}>>;
|
|
1031
|
+
display: z.ZodOptional<z.ZodEnum<{
|
|
1032
|
+
summarized: "summarized";
|
|
1033
|
+
omitted: "omitted";
|
|
1034
|
+
}>>;
|
|
1035
|
+
}, z.core.$strict>>;
|
|
1036
|
+
}, z.core.$strict>;
|
|
923
1037
|
}, z.core.$strict>, z.ZodObject<{
|
|
924
1038
|
name: z.ZodString;
|
|
925
1039
|
provider: z.ZodLiteral<LlmProvider.Minimax>;
|
|
@@ -6,6 +6,7 @@ export var LlmProvider;
|
|
|
6
6
|
LlmProvider["Bedrock"] = "bedrock";
|
|
7
7
|
LlmProvider["Google"] = "google";
|
|
8
8
|
LlmProvider["Groq"] = "groq";
|
|
9
|
+
LlmProvider["LlamaCpp"] = "llama-cpp";
|
|
9
10
|
LlmProvider["Minimax"] = "minimax";
|
|
10
11
|
LlmProvider["Moonshot"] = "moonshot";
|
|
11
12
|
LlmProvider["Ollama"] = "ollama";
|
|
@@ -121,6 +122,16 @@ export const GroqProviderOptionsSchema = z
|
|
|
121
122
|
reasoning: ReasoningOptionsSchema.optional(),
|
|
122
123
|
})
|
|
123
124
|
.strict();
|
|
125
|
+
export const LlamaCppProviderOptionsSchema = z
|
|
126
|
+
.object({
|
|
127
|
+
hfToken: NonEmptyStringSchema.optional(),
|
|
128
|
+
gpu: z
|
|
129
|
+
.union([z.enum(["auto", "metal", "cuda", "vulkan"]), z.literal(false)])
|
|
130
|
+
.optional(),
|
|
131
|
+
contextSize: z.number().int().positive().optional(),
|
|
132
|
+
reasoning: ReasoningOptionsSchema.optional(),
|
|
133
|
+
})
|
|
134
|
+
.strict();
|
|
124
135
|
export const MinimaxProviderOptionsSchema = z
|
|
125
136
|
.object({
|
|
126
137
|
apiKey: NonEmptyStringSchema.optional(),
|
|
@@ -174,6 +185,7 @@ export const ProviderOptionsSchemas = {
|
|
|
174
185
|
[LlmProvider.Bedrock]: BedrockProviderOptionsSchema,
|
|
175
186
|
[LlmProvider.Google]: GoogleProviderOptionsSchema,
|
|
176
187
|
[LlmProvider.Groq]: GroqProviderOptionsSchema,
|
|
188
|
+
[LlmProvider.LlamaCpp]: LlamaCppProviderOptionsSchema,
|
|
177
189
|
[LlmProvider.Minimax]: MinimaxProviderOptionsSchema,
|
|
178
190
|
[LlmProvider.Moonshot]: MoonshotProviderOptionsSchema,
|
|
179
191
|
[LlmProvider.Ollama]: OllamaProviderOptionsSchema,
|
|
@@ -217,6 +229,13 @@ export const NamedProviderConfigSchema = z.discriminatedUnion("provider", [
|
|
|
217
229
|
options: GroqProviderOptionsSchema,
|
|
218
230
|
})
|
|
219
231
|
.strict(),
|
|
232
|
+
z
|
|
233
|
+
.object({
|
|
234
|
+
name: NonEmptyStringSchema,
|
|
235
|
+
provider: z.literal(LlmProvider.LlamaCpp),
|
|
236
|
+
options: LlamaCppProviderOptionsSchema,
|
|
237
|
+
})
|
|
238
|
+
.strict(),
|
|
220
239
|
z
|
|
221
240
|
.object({
|
|
222
241
|
name: NonEmptyStringSchema,
|