@ultrst-armada/kloks 1.21.0 → 1.22.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/.krusbl-release-attestation.json +3 -3
- package/package.json +4 -4
- package/packages/audio-midi/dist/{audioClipEngine-BOT33JKI.js → audioClipEngine-E5ODQNYR.js} +3 -2
- package/packages/audio-midi/dist/{audioInputManager-BLDGGLAR.js → audioInputManager-OOH3TOJ6.js} +2 -1
- package/packages/audio-midi/dist/{chunk-N55BWOC6.js → chunk-2U7VIADS.js} +1 -1
- package/packages/audio-midi/dist/{chunk-3GRGELA4.js → chunk-3FXNT6PF.js} +2 -2
- package/packages/audio-midi/dist/chunk-QGM4M3NI.js +37 -0
- package/packages/audio-midi/dist/dist-XMSSRYDR.js +899 -0
- package/packages/audio-midi/dist/index.js +534 -75
- package/packages/audio-midi/dist/transformers.node-HWHOAE4H.js +43879 -0
- package/packages/audio-midi/package.json +1 -1
- package/packages/backend/dist/ai-inference/index.js +1 -0
- package/packages/backend/dist/ai-keys/index.d.ts +1 -0
- package/packages/backend/dist/ai-keys/index.js +2 -1
- package/packages/backend/dist/ai-models/index.js +3 -2
- package/packages/backend/dist/ai-provider/index.js +1 -0
- package/packages/backend/dist/ai-routing/index.js +4 -3
- package/packages/backend/dist/ai-tools/index.js +1 -0
- package/packages/backend/dist/api/index.js +1 -0
- package/packages/backend/dist/auth/index.js +1 -0
- package/packages/backend/dist/{chunk-RBF2OGMC.js → chunk-B3VJ4HDV.js} +4 -15
- package/packages/backend/dist/{chunk-OYVHKYJW.js → chunk-IJ5QNZCY.js} +1 -1
- package/packages/backend/dist/{chunk-4WUVDLIQ.js → chunk-LMWXONZG.js} +1 -1
- package/packages/backend/dist/chunk-MWSYNRNZ.js +871 -0
- package/packages/backend/dist/{chunk-4ONX56XS.js → chunk-NB2X3HEX.js} +26 -14
- package/packages/backend/dist/{chunk-RSKFM7AC.js → chunk-OB65KZ2M.js} +8 -5
- package/packages/backend/dist/{chunk-F7JDIU2C.js → chunk-P7H6TIEA.js} +3 -0
- package/packages/backend/dist/{chunk-UYXROZPP.js → chunk-PT6J6UEU.js} +2 -2
- package/packages/backend/dist/chunk-QGM4M3NI.js +37 -0
- package/packages/backend/dist/client/index.js +1 -0
- package/packages/backend/dist/connectivity/index.js +1 -0
- package/packages/backend/dist/control-plane/index.js +1 -0
- package/packages/backend/dist/development/index.js +3 -2
- package/packages/backend/dist/dist-XMSSRYDR.js +899 -0
- package/packages/backend/dist/index.js +77 -76
- package/packages/backend/dist/krnl-ai-services.d.ts +12 -2
- package/packages/backend/dist/krnl-ai-services.js +6 -5
- package/packages/backend/dist/krnl-services.d.ts +8 -0
- package/packages/backend/dist/krnl-services.js +7 -6
- package/packages/backend/dist/services/index.d.ts +2 -3
- package/packages/backend/dist/services/index.js +4 -3
- package/packages/backend/dist/srkl/index.js +1 -0
- package/packages/backend/dist/storage/index.js +8 -7
- package/packages/backend/dist/transformers.node-HWHOAE4H.js +43879 -0
- package/packages/backend/dist/workspace/index.js +3 -2
- package/packages/backend/package.json +5 -5
- package/packages/client/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/fod/dist/index.js +2 -2
- package/packages/fod/package.json +24 -13
- package/packages/functions/dist/chunk-QGM4M3NI.js +37 -0
- package/packages/functions/dist/dist-XMSSRYDR.js +899 -0
- package/packages/functions/dist/index.d.ts +2 -0
- package/packages/functions/dist/index.js +581 -94
- package/packages/functions/dist/transformers.node-HWHOAE4H.js +43879 -0
- package/packages/functions/package.json +1 -1
- package/packages/orchestrations/package.json +3 -3
- package/packages/services/dist/chunk-QGM4M3NI.js +37 -0
- package/packages/services/dist/dist-XMSSRYDR.js +899 -0
- package/packages/services/dist/index.d.ts +55 -8
- package/packages/services/dist/index.js +640 -85
- package/packages/services/dist/transformers.node-HWHOAE4H.js +43879 -0
- package/packages/services/package.json +1 -1
- package/packages/state-graph/dist/chunk-QGM4M3NI.js +37 -0
- package/packages/state-graph/dist/dist-XMSSRYDR.js +899 -0
- package/packages/state-graph/dist/domain/index.js +1 -0
- package/packages/state-graph/dist/index.js +602 -119
- package/packages/state-graph/dist/rules/index.js +1 -0
- package/packages/state-graph/dist/spatial/index.js +1 -0
- package/packages/state-graph/dist/state/index.js +1 -0
- package/packages/state-graph/dist/store/index.js +1 -0
- package/packages/state-graph/dist/transformers.node-HWHOAE4H.js +43879 -0
- package/packages/state-graph/package.json +1 -1
- package/packages/backend/dist/chunk-TY32TUNI.js +0 -376
- package/packages/backend/dist/{chunk-2XTHJI4I.js → chunk-6DNGLKAV.js} +3 -3
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
import "./chunk-QGM4M3NI.js";
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/errors.js
|
|
4
|
+
var NeedleError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
name = "NeedleError";
|
|
7
|
+
constructor(code, message, options) {
|
|
8
|
+
super(message, options);
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var ExtractionValidationError = class extends NeedleError {
|
|
13
|
+
name = "ExtractionValidationError";
|
|
14
|
+
constructor(message = "The model returned values that are not grounded in the input.") {
|
|
15
|
+
super("INVALID_RESPONSE", message);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function errorMessage(error) {
|
|
19
|
+
return error instanceof Error ? error.message : String(error);
|
|
20
|
+
}
|
|
21
|
+
function validateText(value, label) {
|
|
22
|
+
if (typeof value !== "string" || value.includes("\0")) throw new NeedleError("INVALID_ARGUMENT", `${label} must be a string without null bytes.`);
|
|
23
|
+
}
|
|
24
|
+
function validateInteger(value, label, min, max) {
|
|
25
|
+
if (!Number.isSafeInteger(value) || value < min || value > max) throw new NeedleError("INVALID_ARGUMENT", `${label} must be an integer between ${min} and ${max}.`);
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/tools.js
|
|
30
|
+
var validators = /* @__PURE__ */ new WeakMap();
|
|
31
|
+
async function validateToolInput(definition, input) {
|
|
32
|
+
const validate = validators.get(definition);
|
|
33
|
+
if (validate && (await validate(input)).issues) throw new NeedleError("INVALID_ARGUMENT", "Tool input failed schema validation.");
|
|
34
|
+
}
|
|
35
|
+
function tool(options) {
|
|
36
|
+
let schema = options.inputSchema;
|
|
37
|
+
let validate;
|
|
38
|
+
if (!schema || typeof schema !== "object") throw new NeedleError("INVALID_ARGUMENT", "inputSchema must be an object schema.");
|
|
39
|
+
if ("~standard" in schema) {
|
|
40
|
+
const standard = schema["~standard"];
|
|
41
|
+
if (standard?.version !== 1 || typeof standard.jsonSchema?.input !== "function") throw new NeedleError("INVALID_ARGUMENT", "Use a Standard JSON Schema library (such as Zod 4.2+) or a plain JSON Schema.");
|
|
42
|
+
try {
|
|
43
|
+
schema = standard.jsonSchema.input({ target: "draft-07" });
|
|
44
|
+
if (standard.validate) validate = standard.validate.bind(standard);
|
|
45
|
+
} catch (cause) {
|
|
46
|
+
throw new NeedleError("INVALID_ARGUMENT", `Cannot convert inputSchema: ${errorMessage(cause)}`, { cause });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (schema.type !== "object") throw new NeedleError("INVALID_ARGUMENT", "A tool inputSchema must describe an object.");
|
|
50
|
+
if (options.execute !== void 0 && typeof options.execute !== "function") throw new NeedleError("INVALID_ARGUMENT", "execute must be a function.");
|
|
51
|
+
const definition = Object.freeze({
|
|
52
|
+
inputSchema: schema,
|
|
53
|
+
...options.description === void 0 ? {} : { description: options.description },
|
|
54
|
+
...options.triggers === void 0 ? {} : { triggers: options.triggers },
|
|
55
|
+
...options.execute === void 0 ? {} : { execute: options.execute }
|
|
56
|
+
});
|
|
57
|
+
if (validate) validators.set(definition, validate);
|
|
58
|
+
return definition;
|
|
59
|
+
}
|
|
60
|
+
function normalizeTools(tools) {
|
|
61
|
+
if (Array.isArray(tools)) return tools;
|
|
62
|
+
if (!tools || typeof tools !== "object") throw new NeedleError("INVALID_ARGUMENT", "tools must be a named tool object or an array of schemas.");
|
|
63
|
+
return Object.entries(tools).map(([name, value]) => {
|
|
64
|
+
if (!value || typeof value !== "object" || !value.inputSchema) throw new NeedleError("INVALID_ARGUMENT", `Tool ${name} needs inputSchema. Use tool({ inputSchema, description }).`);
|
|
65
|
+
return {
|
|
66
|
+
name,
|
|
67
|
+
parameters: value.inputSchema,
|
|
68
|
+
...value.description === void 0 ? {} : { description: value.description },
|
|
69
|
+
...value.triggers === void 0 ? {} : { triggers: value.triggers }
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/vendor/manifest.js
|
|
75
|
+
var repository = "Cactus-Compute/needle3";
|
|
76
|
+
var revision = "2ae11323dc000f5e70c49f7403efa6af12ba9e67";
|
|
77
|
+
var files = {
|
|
78
|
+
"needle.cjs": {
|
|
79
|
+
"path": "wasm/needle.js",
|
|
80
|
+
"size": 63072,
|
|
81
|
+
"sha256": "964681b2a5ec3c4db2f06e45a5b60c8981a7d4ab4cac16ef6bf5b1988657a5f1"
|
|
82
|
+
},
|
|
83
|
+
"needle.wasm": {
|
|
84
|
+
"path": "wasm/needle.wasm",
|
|
85
|
+
"size": 923348,
|
|
86
|
+
"sha256": "c43f48e11f302087250d1e406024956781cd2f02595a5e343b3d7ddd5ef707fa"
|
|
87
|
+
},
|
|
88
|
+
"LICENSE": {
|
|
89
|
+
"path": "LICENSE",
|
|
90
|
+
"size": 11358,
|
|
91
|
+
"sha256": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var speechModel = {
|
|
95
|
+
"repository": "Cactus-Compute/whistle",
|
|
96
|
+
"revision": "b358ddadd89b7a713b5aa131f23032d3cca1b251",
|
|
97
|
+
"path": "whistle.cact",
|
|
98
|
+
"size": 16919407,
|
|
99
|
+
"sha256": "b6e02f048568ac5d01a2042556c658061e699acbc0aa2a1439f52f3d461dffeb"
|
|
100
|
+
};
|
|
101
|
+
var model = {
|
|
102
|
+
"path": "needle3.cact",
|
|
103
|
+
"size": 35335380,
|
|
104
|
+
"sha256": "c9d915eca282ed42d1a09b143b592adb4cc6744ffe2d294adf5cfc5548170c38"
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/runtime/artifacts.js
|
|
108
|
+
var DEFAULT_MODEL = Object.freeze({
|
|
109
|
+
name: "needle3",
|
|
110
|
+
revision,
|
|
111
|
+
size: model.size,
|
|
112
|
+
sha256: model.sha256,
|
|
113
|
+
url: `https://huggingface.co/${repository}/resolve/${revision}/${model.path}`
|
|
114
|
+
});
|
|
115
|
+
var MODEL_FILE = model.path;
|
|
116
|
+
var DEFAULT_SPEECH_MODEL = Object.freeze({
|
|
117
|
+
name: "whistle",
|
|
118
|
+
revision: speechModel.revision,
|
|
119
|
+
size: speechModel.size,
|
|
120
|
+
sha256: speechModel.sha256,
|
|
121
|
+
url: `https://huggingface.co/${speechModel.repository}/resolve/${speechModel.revision}/${speechModel.path}`
|
|
122
|
+
});
|
|
123
|
+
var SPEECH_MODEL_FILE = speechModel.path;
|
|
124
|
+
Object.freeze(files["needle.wasm"]);
|
|
125
|
+
|
|
126
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/node/model.js
|
|
127
|
+
import { mkdir, rename, rm, stat } from "fs/promises";
|
|
128
|
+
import { createHash, randomUUID } from "crypto";
|
|
129
|
+
import { createReadStream, createWriteStream } from "fs";
|
|
130
|
+
import { homedir } from "os";
|
|
131
|
+
import { dirname, join, resolve } from "path";
|
|
132
|
+
import { Readable, Transform } from "stream";
|
|
133
|
+
import { pipeline } from "stream/promises";
|
|
134
|
+
var DEFAULT_MODEL2 = DEFAULT_MODEL;
|
|
135
|
+
function modelFor(name) {
|
|
136
|
+
if (name === "needle3") return DEFAULT_MODEL2;
|
|
137
|
+
if (name === "whistle") return DEFAULT_SPEECH_MODEL;
|
|
138
|
+
throw new NeedleError("INVALID_ARGUMENT", "model must be needle3 or whistle.");
|
|
139
|
+
}
|
|
140
|
+
function getModelPath(cacheDir, model2 = "needle3") {
|
|
141
|
+
const artifact = modelFor(model2);
|
|
142
|
+
const root = cacheDir ?? join(process.env.XDG_CACHE_HOME || process.platform === "win32" && process.env.LOCALAPPDATA || join(homedir(), ".cache"), "cactus-needle-node");
|
|
143
|
+
return resolve(root, artifact.revision, model2 === "needle3" ? MODEL_FILE : SPEECH_MODEL_FILE);
|
|
144
|
+
}
|
|
145
|
+
async function verifiedCache(path, artifact) {
|
|
146
|
+
let info;
|
|
147
|
+
try {
|
|
148
|
+
info = await stat(path);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (error.code === "ENOENT") return false;
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
if (!info.isFile() || info.size !== artifact.size) throw new NeedleError("INTEGRITY_ERROR", `Cached model has the wrong size. Remove ${path} and download it again.`);
|
|
154
|
+
const hash = createHash("sha256");
|
|
155
|
+
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
|
156
|
+
if (hash.digest("hex") !== artifact.sha256) throw new NeedleError("INTEGRITY_ERROR", `Cached model failed SHA-256 verification. Remove ${path} and download it again.`);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
async function downloadModel(options = {}) {
|
|
160
|
+
options.signal?.throwIfAborted();
|
|
161
|
+
const model2 = options.model ?? "needle3";
|
|
162
|
+
const artifact = modelFor(model2);
|
|
163
|
+
const timeout = validateInteger(options.timeoutMs ?? 3e5, "timeoutMs", 1, 2147483647);
|
|
164
|
+
const target = getModelPath(options.cacheDir, model2);
|
|
165
|
+
if (await verifiedCache(target, artifact)) return target;
|
|
166
|
+
await mkdir(dirname(target), { recursive: true });
|
|
167
|
+
const temporary = `${target}.${randomUUID()}.part`;
|
|
168
|
+
const signal = AbortSignal.any([AbortSignal.timeout(timeout), ...options.signal ? [options.signal] : []]);
|
|
169
|
+
try {
|
|
170
|
+
const response = await fetch(artifact.url, { signal });
|
|
171
|
+
if (!response.ok || !response.body) throw new NeedleError("DOWNLOAD_FAILED", `Model download failed: HTTP ${response.status}.`);
|
|
172
|
+
const hash = createHash("sha256");
|
|
173
|
+
let received = 0;
|
|
174
|
+
const verify = new Transform({ transform(chunk, _encoding, callback) {
|
|
175
|
+
try {
|
|
176
|
+
received += chunk.length;
|
|
177
|
+
if (received > artifact.size) throw new NeedleError("INTEGRITY_ERROR", "Downloaded model exceeds its pinned size.");
|
|
178
|
+
hash.update(chunk);
|
|
179
|
+
options.onProgress?.({
|
|
180
|
+
receivedBytes: received,
|
|
181
|
+
totalBytes: artifact.size
|
|
182
|
+
});
|
|
183
|
+
callback(null, chunk);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
callback(error);
|
|
186
|
+
}
|
|
187
|
+
} });
|
|
188
|
+
await pipeline(Readable.fromWeb(response.body), verify, createWriteStream(temporary, {
|
|
189
|
+
flags: "wx",
|
|
190
|
+
mode: 384
|
|
191
|
+
}), { signal });
|
|
192
|
+
if (received !== artifact.size || hash.digest("hex") !== artifact.sha256) throw new NeedleError("INTEGRITY_ERROR", "Downloaded model failed size or SHA-256 verification.");
|
|
193
|
+
await rename(temporary, target);
|
|
194
|
+
return target;
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (signal.aborted) throw signal.reason;
|
|
197
|
+
if (error instanceof NeedleError) throw error;
|
|
198
|
+
throw new NeedleError("DOWNLOAD_FAILED", `Model download failed: ${errorMessage(error)}`, { cause: error });
|
|
199
|
+
} finally {
|
|
200
|
+
await rm(temporary, { force: true });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/runtime/configuration.js
|
|
205
|
+
function configuration(options) {
|
|
206
|
+
const system = options.system ?? "";
|
|
207
|
+
validateText(system, "system");
|
|
208
|
+
if (options.stateless !== void 0 && typeof options.stateless !== "boolean") throw new NeedleError("INVALID_ARGUMENT", "stateless must be a boolean.");
|
|
209
|
+
return {
|
|
210
|
+
system,
|
|
211
|
+
toolsJson: serializeTools(options.tools ?? []),
|
|
212
|
+
stateless: options.stateless ?? false,
|
|
213
|
+
bufferSize: validateInteger(options.bufferSize ?? 262144, "bufferSize", 1024, 16777216)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function serializeTools(collection) {
|
|
217
|
+
const tools = normalizeTools(collection);
|
|
218
|
+
const names = /* @__PURE__ */ new Set();
|
|
219
|
+
for (const entry of tools) {
|
|
220
|
+
if (!entry || typeof entry !== "object") throw new NeedleError("INVALID_ARGUMENT", "Each tool must be a schema object.");
|
|
221
|
+
const schema = entry && "type" in entry && entry.type === "function" ? entry.function : entry;
|
|
222
|
+
if (!schema || typeof schema !== "object" || !("name" in schema)) throw new NeedleError("INVALID_ARGUMENT", "Each tool must be a schema object.");
|
|
223
|
+
validateText(schema.name, "Tool name");
|
|
224
|
+
if (!schema.name.trim() || names.has(schema.name)) throw new NeedleError("INVALID_ARGUMENT", "Tool names must be nonempty and unique.");
|
|
225
|
+
if (!schema.parameters || typeof schema.parameters !== "object" || Array.isArray(schema.parameters)) throw new NeedleError("INVALID_ARGUMENT", `Tool ${schema.name} must have a parameters schema.`);
|
|
226
|
+
names.add(schema.name);
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
return JSON.stringify(tools, (_key, value) => {
|
|
230
|
+
if (typeof value === "function" || typeof value === "symbol" || typeof value === "number" && !Number.isFinite(value)) throw new Error("Tool definitions must contain JSON values.");
|
|
231
|
+
return value;
|
|
232
|
+
});
|
|
233
|
+
} catch (cause) {
|
|
234
|
+
throw new NeedleError("INVALID_ARGUMENT", `Tools must be JSON-serializable: ${errorMessage(cause)}`, { cause });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/runtime/resident.js
|
|
239
|
+
var Resident = class {
|
|
240
|
+
load;
|
|
241
|
+
#lifetime = new AbortController();
|
|
242
|
+
#session;
|
|
243
|
+
#tail = Promise.resolve();
|
|
244
|
+
#closing;
|
|
245
|
+
constructor(load2) {
|
|
246
|
+
this.load = load2;
|
|
247
|
+
}
|
|
248
|
+
assertOpen() {
|
|
249
|
+
this.#lifetime.signal.throwIfAborted();
|
|
250
|
+
}
|
|
251
|
+
use(run, signal) {
|
|
252
|
+
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
253
|
+
if (this.#lifetime.signal.aborted) return Promise.reject(this.#lifetime.signal.reason);
|
|
254
|
+
const cancel = () => {
|
|
255
|
+
this.close();
|
|
256
|
+
};
|
|
257
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
258
|
+
const stopped = this.#lifetime.signal;
|
|
259
|
+
let rejectClosed;
|
|
260
|
+
const closed = new Promise((_resolve, reject) => {
|
|
261
|
+
rejectClosed = reject;
|
|
262
|
+
});
|
|
263
|
+
const onClose = () => rejectClosed(signal?.aborted ? signal.reason : stopped.reason);
|
|
264
|
+
stopped.addEventListener("abort", onClose, { once: true });
|
|
265
|
+
const operation = this.#tail.then(async () => {
|
|
266
|
+
stopped.throwIfAborted();
|
|
267
|
+
if (!this.#session) this.#session = this.load(stopped).catch((error) => {
|
|
268
|
+
this.#session = void 0;
|
|
269
|
+
throw error;
|
|
270
|
+
});
|
|
271
|
+
const session = await this.#session;
|
|
272
|
+
stopped.throwIfAborted();
|
|
273
|
+
const result = await run(session, stopped);
|
|
274
|
+
stopped.throwIfAborted();
|
|
275
|
+
return result;
|
|
276
|
+
});
|
|
277
|
+
this.#tail = operation.catch(() => {
|
|
278
|
+
});
|
|
279
|
+
return Promise.race([operation, closed]).finally(() => {
|
|
280
|
+
signal?.removeEventListener("abort", cancel);
|
|
281
|
+
stopped.removeEventListener("abort", onClose);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/** Eager factories return a ready model or dispose of a failed initialization. */
|
|
285
|
+
async ready(signal) {
|
|
286
|
+
try {
|
|
287
|
+
await this.use(async () => {
|
|
288
|
+
}, signal);
|
|
289
|
+
return this;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
await this.close();
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
close() {
|
|
296
|
+
if (!this.#closing) {
|
|
297
|
+
this.#lifetime.abort(new NeedleError("CLOSED", "This model session was closed."));
|
|
298
|
+
this.#closing = this.#session?.then((session) => session.close(), () => {
|
|
299
|
+
}) ?? Promise.resolve();
|
|
300
|
+
}
|
|
301
|
+
return this.#closing;
|
|
302
|
+
}
|
|
303
|
+
[Symbol.asyncDispose]() {
|
|
304
|
+
return this.close();
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/client.js
|
|
309
|
+
function strictOption(strict) {
|
|
310
|
+
if (strict !== void 0 && typeof strict !== "boolean") throw new NeedleError("INVALID_ARGUMENT", "strict must be a boolean.");
|
|
311
|
+
return strict ?? true;
|
|
312
|
+
}
|
|
313
|
+
function checkSuccess(result) {
|
|
314
|
+
if (!result.success) throw new NeedleError("ENGINE_ERROR", result.error ?? "Generation failed.");
|
|
315
|
+
}
|
|
316
|
+
var Agent = class extends Resident {
|
|
317
|
+
options;
|
|
318
|
+
constructor(load2, options) {
|
|
319
|
+
super(load2);
|
|
320
|
+
this.options = options;
|
|
321
|
+
configuration(options);
|
|
322
|
+
}
|
|
323
|
+
generate(options) {
|
|
324
|
+
return this.use(async (session) => {
|
|
325
|
+
if (this.options.stateless) await session.reset();
|
|
326
|
+
return session.generate(options);
|
|
327
|
+
}, options.abortSignal);
|
|
328
|
+
}
|
|
329
|
+
complete(input = "", options) {
|
|
330
|
+
return this.use(async (session) => {
|
|
331
|
+
if (this.options.stateless) await session.reset();
|
|
332
|
+
return session.complete(input, options);
|
|
333
|
+
}, options?.abortSignal);
|
|
334
|
+
}
|
|
335
|
+
embed(input = "", options) {
|
|
336
|
+
return this.use((session) => session.embed(input), options?.abortSignal);
|
|
337
|
+
}
|
|
338
|
+
reset() {
|
|
339
|
+
return this.use((session) => session.reset());
|
|
340
|
+
}
|
|
341
|
+
async run(query = "", options = {}) {
|
|
342
|
+
validateText(query, "query");
|
|
343
|
+
const maxSteps = validateInteger(options.maxSteps ?? 8, "maxSteps", 1, 32);
|
|
344
|
+
const strict = strictOption(options.strict);
|
|
345
|
+
const completion = options.maxNewTokens === void 0 ? {} : { maxNewTokens: options.maxNewTokens };
|
|
346
|
+
return this.use(async (session, signal) => {
|
|
347
|
+
if (this.options.stateless) await session.reset();
|
|
348
|
+
let response = await session.complete(query, completion);
|
|
349
|
+
const executed = [];
|
|
350
|
+
for (let step = 0; step < maxSteps; step++) {
|
|
351
|
+
checkSuccess(response);
|
|
352
|
+
if (response.type !== "call" || !response.function_calls.length) break;
|
|
353
|
+
const results = [];
|
|
354
|
+
for (const call of response.function_calls) {
|
|
355
|
+
signal.throwIfAborted();
|
|
356
|
+
const ungrounded = response.validation?.ungrounded?.some((path) => path === call.name || path.startsWith(`${call.name}.`));
|
|
357
|
+
if (strict && (ungrounded || response.validation?.negation)) {
|
|
358
|
+
results.push({ error: "The model flagged this call as ungrounded." });
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const tools = this.options.tools;
|
|
362
|
+
const definition = tools && !Array.isArray(tools) && Object.hasOwn(tools, call.name) ? tools[call.name] : void 0;
|
|
363
|
+
if (!definition?.execute) {
|
|
364
|
+
results.push({ error: `No execute function registered for ${call.name}.` });
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
try {
|
|
368
|
+
await validateToolInput(definition, call.arguments);
|
|
369
|
+
signal.throwIfAborted();
|
|
370
|
+
const value = await definition.execute(call.arguments, { abortSignal: signal });
|
|
371
|
+
results.push(JSON.parse(JSON.stringify(value ?? null, (_key, item) => typeof item === "bigint" ? String(item) : item)));
|
|
372
|
+
} catch (error) {
|
|
373
|
+
signal.throwIfAborted();
|
|
374
|
+
results.push({ error: errorMessage(error) });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
executed.push(...results);
|
|
378
|
+
signal.throwIfAborted();
|
|
379
|
+
response = await session.complete(JSON.stringify(results), completion);
|
|
380
|
+
}
|
|
381
|
+
checkSuccess(response);
|
|
382
|
+
return {
|
|
383
|
+
...response,
|
|
384
|
+
results: executed
|
|
385
|
+
};
|
|
386
|
+
}, options.abortSignal);
|
|
387
|
+
}
|
|
388
|
+
async extract(text, schema, options = {}) {
|
|
389
|
+
validateText(text, "text");
|
|
390
|
+
const strict = strictOption(options.strict);
|
|
391
|
+
const definition = tool({ inputSchema: schema });
|
|
392
|
+
return this.use(async (session) => {
|
|
393
|
+
await session.reset();
|
|
394
|
+
const result = await session.complete(text, {
|
|
395
|
+
tools: { extract: definition },
|
|
396
|
+
...options.maxNewTokens === void 0 ? {} : { maxNewTokens: options.maxNewTokens }
|
|
397
|
+
});
|
|
398
|
+
checkSuccess(result);
|
|
399
|
+
if (strict && (result.validation?.ungrounded?.length || result.validation?.negation)) throw new ExtractionValidationError();
|
|
400
|
+
const call = result.function_calls.find((call2) => call2.name === "extract");
|
|
401
|
+
if (!call) return null;
|
|
402
|
+
await validateToolInput(definition, call.arguments);
|
|
403
|
+
return call.arguments;
|
|
404
|
+
}, options.abortSignal);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/runtime/audio.js
|
|
409
|
+
var SPEECH_LANGUAGES = [
|
|
410
|
+
"en",
|
|
411
|
+
"de",
|
|
412
|
+
"fr",
|
|
413
|
+
"es",
|
|
414
|
+
"it",
|
|
415
|
+
"nl",
|
|
416
|
+
"pl"
|
|
417
|
+
];
|
|
418
|
+
function invalid(message) {
|
|
419
|
+
throw new NeedleError("INVALID_ARGUMENT", message);
|
|
420
|
+
}
|
|
421
|
+
function transcriptionSettings(options) {
|
|
422
|
+
const { language, keywords, wordTimestamps } = options;
|
|
423
|
+
if (language !== void 0 && !SPEECH_LANGUAGES.includes(language)) invalid(`language must be one of ${SPEECH_LANGUAGES.join(", ")}.`);
|
|
424
|
+
if (wordTimestamps !== void 0 && typeof wordTimestamps !== "boolean") invalid("wordTimestamps must be a boolean.");
|
|
425
|
+
if (keywords !== void 0) {
|
|
426
|
+
if (!Array.isArray(keywords) || keywords.length > 100) invalid("keywords must be an array of at most 100 phrases.");
|
|
427
|
+
for (const keyword of keywords) {
|
|
428
|
+
validateText(keyword, "keyword");
|
|
429
|
+
if (!keyword.trim() || keyword.length > 256 || /[\r\n]/.test(keyword)) invalid("Each keyword must be a nonempty phrase of at most 256 characters without newlines.");
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return {
|
|
433
|
+
...language === void 0 ? {} : { language },
|
|
434
|
+
...keywords === void 0 ? {} : { keywords: [...keywords] },
|
|
435
|
+
...wordTimestamps === void 0 ? {} : { wordTimestamps }
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/speech-client.js
|
|
440
|
+
var SpeechClient = class extends Resident {
|
|
441
|
+
read;
|
|
442
|
+
#stream;
|
|
443
|
+
constructor(load2, read) {
|
|
444
|
+
super(load2);
|
|
445
|
+
this.read = read;
|
|
446
|
+
}
|
|
447
|
+
async transcribe(audio, options = {}) {
|
|
448
|
+
options.abortSignal?.throwIfAborted();
|
|
449
|
+
this.#available();
|
|
450
|
+
const settings = transcriptionSettings(options);
|
|
451
|
+
return this.use(async (session, signal) => {
|
|
452
|
+
const input = await this.read(audio, signal);
|
|
453
|
+
signal.throwIfAborted();
|
|
454
|
+
return session.transcribe(input, settings);
|
|
455
|
+
}, options.abortSignal);
|
|
456
|
+
}
|
|
457
|
+
async embed(audio, options = {}) {
|
|
458
|
+
options.abortSignal?.throwIfAborted();
|
|
459
|
+
this.#available();
|
|
460
|
+
return this.use(async (session, signal) => {
|
|
461
|
+
const input = await this.read(audio, signal);
|
|
462
|
+
signal.throwIfAborted();
|
|
463
|
+
return session.embedAudio(input);
|
|
464
|
+
}, options.abortSignal);
|
|
465
|
+
}
|
|
466
|
+
#available() {
|
|
467
|
+
this.assertOpen();
|
|
468
|
+
if (this.#stream) throw new NeedleError("INVALID_ARGUMENT", "Finish or close the active transcription stream first.");
|
|
469
|
+
}
|
|
470
|
+
async *stream(chunks, options = {}) {
|
|
471
|
+
options.abortSignal?.throwIfAborted();
|
|
472
|
+
this.#available();
|
|
473
|
+
const settings = transcriptionSettings(options);
|
|
474
|
+
const controller = new AbortController();
|
|
475
|
+
this.#stream = controller;
|
|
476
|
+
const signal = options.abortSignal ? AbortSignal.any([controller.signal, options.abortSignal]) : controller.signal;
|
|
477
|
+
const abort = () => {
|
|
478
|
+
this.close();
|
|
479
|
+
};
|
|
480
|
+
options.abortSignal?.addEventListener("abort", abort, { once: true });
|
|
481
|
+
let rejectCancelled;
|
|
482
|
+
const cancelled = new Promise((_resolve, reject) => {
|
|
483
|
+
rejectCancelled = reject;
|
|
484
|
+
});
|
|
485
|
+
cancelled.catch(() => {
|
|
486
|
+
});
|
|
487
|
+
const onCancel = () => rejectCancelled(options.abortSignal?.aborted ? options.abortSignal.reason : signal.reason);
|
|
488
|
+
signal.addEventListener("abort", onCancel, { once: true });
|
|
489
|
+
let iterator;
|
|
490
|
+
let started = false;
|
|
491
|
+
let finished = false;
|
|
492
|
+
try {
|
|
493
|
+
iterator = Symbol.asyncIterator in chunks ? chunks[Symbol.asyncIterator]() : chunks[Symbol.iterator]();
|
|
494
|
+
while (true) {
|
|
495
|
+
signal.throwIfAborted();
|
|
496
|
+
const next = await Promise.race([iterator.next(), cancelled]);
|
|
497
|
+
if (next.done) break;
|
|
498
|
+
started = true;
|
|
499
|
+
yield await this.use((session) => session.streamTranscribe(next.value, settings), signal);
|
|
500
|
+
}
|
|
501
|
+
if (started) {
|
|
502
|
+
const tail = await this.use((session) => session.streamTranscribe(void 0, settings), signal);
|
|
503
|
+
finished = true;
|
|
504
|
+
yield tail;
|
|
505
|
+
}
|
|
506
|
+
} finally {
|
|
507
|
+
options.abortSignal?.removeEventListener("abort", abort);
|
|
508
|
+
signal.removeEventListener("abort", onCancel);
|
|
509
|
+
if (started && !finished && !signal.aborted) try {
|
|
510
|
+
await this.use((session) => session.streamTranscribe(void 0, settings));
|
|
511
|
+
} catch {
|
|
512
|
+
await this.close();
|
|
513
|
+
}
|
|
514
|
+
this.#stream = void 0;
|
|
515
|
+
if (iterator?.return) {
|
|
516
|
+
const cleanup = Promise.resolve().then(() => iterator?.return?.());
|
|
517
|
+
if (signal.aborted) cleanup.catch(() => {
|
|
518
|
+
});
|
|
519
|
+
else await cleanup;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
close() {
|
|
524
|
+
this.#stream?.abort(new NeedleError("CLOSED", "This transcription stream was closed."));
|
|
525
|
+
return super.close();
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/node/audio.js
|
|
530
|
+
import { readFile } from "fs/promises";
|
|
531
|
+
var readAudio = async (source, signal) => {
|
|
532
|
+
signal.throwIfAborted();
|
|
533
|
+
if (typeof source === "string" || source instanceof URL) {
|
|
534
|
+
if (source instanceof URL && source.protocol !== "file:") throw new NeedleError("INVALID_ARGUMENT", "Node audio must be a local path or file: URL.");
|
|
535
|
+
return readFile(source, { signal });
|
|
536
|
+
}
|
|
537
|
+
if (source instanceof Blob) return new Uint8Array(await source.arrayBuffer());
|
|
538
|
+
return source;
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/runtime/rpc-session.js
|
|
542
|
+
var RpcSession = class {
|
|
543
|
+
transport;
|
|
544
|
+
maxNewTokens;
|
|
545
|
+
ready;
|
|
546
|
+
#pending = /* @__PURE__ */ new Map();
|
|
547
|
+
#rejectReady;
|
|
548
|
+
#nextId = 0;
|
|
549
|
+
#closed = false;
|
|
550
|
+
#closing;
|
|
551
|
+
constructor(transport, maxNewTokens) {
|
|
552
|
+
this.transport = transport;
|
|
553
|
+
this.maxNewTokens = maxNewTokens;
|
|
554
|
+
this.ready = new Promise((resolveReady, rejectReady) => {
|
|
555
|
+
this.#rejectReady = rejectReady;
|
|
556
|
+
transport.listen((message) => {
|
|
557
|
+
if (this.#closed) return;
|
|
558
|
+
if (message.type === "ready") resolveReady();
|
|
559
|
+
else if (message.type === "error" && message.id === void 0) this.#fail(new NeedleError(message.code, message.message));
|
|
560
|
+
else if ("id" in message && message.id !== void 0) {
|
|
561
|
+
const pending = this.#pending.get(message.id);
|
|
562
|
+
this.#pending.delete(message.id);
|
|
563
|
+
if (message.type === "error") pending?.reject(new NeedleError(message.code, message.message));
|
|
564
|
+
else if (message.type === "result") pending?.resolve(message.value);
|
|
565
|
+
}
|
|
566
|
+
if (!this.#closed && this.#pending.size === 0) transport.unref?.();
|
|
567
|
+
}, (cause) => {
|
|
568
|
+
if (!this.#closed) this.#fail(new NeedleError("WORKER_ERROR", `Inference worker failed: ${cause.message}`, { cause }));
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
#fail(error) {
|
|
573
|
+
this.#closed = true;
|
|
574
|
+
this.#rejectReady(error);
|
|
575
|
+
for (const pending of this.#pending.values()) pending.reject(error);
|
|
576
|
+
this.#pending.clear();
|
|
577
|
+
this.transport.ref?.();
|
|
578
|
+
this.#closing ??= this.transport.terminate();
|
|
579
|
+
return this.#closing;
|
|
580
|
+
}
|
|
581
|
+
async #request(command, signal) {
|
|
582
|
+
signal?.throwIfAborted();
|
|
583
|
+
if (this.#closed) throw new NeedleError("CLOSED", "This model session is closed.");
|
|
584
|
+
const abort = () => {
|
|
585
|
+
this.close();
|
|
586
|
+
};
|
|
587
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
588
|
+
try {
|
|
589
|
+
const result = await new Promise((resolveResult, reject) => {
|
|
590
|
+
const id = this.#nextId++;
|
|
591
|
+
this.#pending.set(id, {
|
|
592
|
+
resolve: resolveResult,
|
|
593
|
+
reject
|
|
594
|
+
});
|
|
595
|
+
this.transport.ref?.();
|
|
596
|
+
try {
|
|
597
|
+
this.transport.send({
|
|
598
|
+
...command,
|
|
599
|
+
id
|
|
600
|
+
});
|
|
601
|
+
} catch (cause) {
|
|
602
|
+
this.#fail(new NeedleError("WORKER_ERROR", errorMessage(cause), { cause }));
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
signal?.throwIfAborted();
|
|
606
|
+
return result;
|
|
607
|
+
} catch (error) {
|
|
608
|
+
if (signal?.aborted) throw signal.reason;
|
|
609
|
+
throw error;
|
|
610
|
+
} finally {
|
|
611
|
+
signal?.removeEventListener("abort", abort);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
async generate({ prompt, tools, maxOutputTokens, abortSignal }) {
|
|
615
|
+
abortSignal?.throwIfAborted();
|
|
616
|
+
const raw = await this.complete(prompt, {
|
|
617
|
+
...tools === void 0 ? {} : { tools },
|
|
618
|
+
...maxOutputTokens === void 0 ? {} : { maxNewTokens: maxOutputTokens },
|
|
619
|
+
...abortSignal === void 0 ? {} : { abortSignal }
|
|
620
|
+
});
|
|
621
|
+
abortSignal?.throwIfAborted();
|
|
622
|
+
if (!raw.success) throw new NeedleError("ENGINE_ERROR", raw.error ?? "Generation failed.");
|
|
623
|
+
const convert = (calls) => calls.map((call) => ({
|
|
624
|
+
toolName: call.name,
|
|
625
|
+
input: call.arguments
|
|
626
|
+
}));
|
|
627
|
+
return {
|
|
628
|
+
toolCalls: convert(raw.function_calls),
|
|
629
|
+
suppressedToolCalls: convert(raw.suppressed_calls),
|
|
630
|
+
confidence: raw.confidence,
|
|
631
|
+
reasoning: raw.reasoning,
|
|
632
|
+
raw
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
async complete(input = "", options = {}) {
|
|
636
|
+
options.abortSignal?.throwIfAborted();
|
|
637
|
+
validateText(input, "input");
|
|
638
|
+
const maxNewTokens = validateInteger(options.maxNewTokens ?? this.maxNewTokens, "maxNewTokens", 1, 65536);
|
|
639
|
+
return await this.#request({
|
|
640
|
+
method: "complete",
|
|
641
|
+
input,
|
|
642
|
+
maxNewTokens,
|
|
643
|
+
...options.tools === void 0 ? {} : { toolsJson: serializeTools(options.tools) }
|
|
644
|
+
}, options.abortSignal);
|
|
645
|
+
}
|
|
646
|
+
async embed(input = "", options = {}) {
|
|
647
|
+
options.abortSignal?.throwIfAborted();
|
|
648
|
+
validateText(input, "input");
|
|
649
|
+
return await this.#request({
|
|
650
|
+
method: "embed",
|
|
651
|
+
input
|
|
652
|
+
}, options.abortSignal);
|
|
653
|
+
}
|
|
654
|
+
async transcribe(audio, { abortSignal, ...options } = {}) {
|
|
655
|
+
abortSignal?.throwIfAborted();
|
|
656
|
+
const settings = transcriptionSettings(options);
|
|
657
|
+
return await this.#request({
|
|
658
|
+
method: "transcribe",
|
|
659
|
+
audio,
|
|
660
|
+
settings
|
|
661
|
+
}, abortSignal);
|
|
662
|
+
}
|
|
663
|
+
async embedAudio(audio) {
|
|
664
|
+
return await this.#request({
|
|
665
|
+
method: "embedAudio",
|
|
666
|
+
audio
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
async streamTranscribe(audio, settings) {
|
|
670
|
+
return await this.#request({
|
|
671
|
+
method: "streamTranscribe",
|
|
672
|
+
audio,
|
|
673
|
+
settings
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
async reset() {
|
|
677
|
+
await this.#request({ method: "reset" });
|
|
678
|
+
}
|
|
679
|
+
close() {
|
|
680
|
+
return this.#closing ?? this.#fail(new NeedleError("CLOSED", "This Needle instance was closed."));
|
|
681
|
+
}
|
|
682
|
+
[Symbol.asyncDispose]() {
|
|
683
|
+
return this.close();
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/node/session.js
|
|
688
|
+
import { resolve as resolve2 } from "path";
|
|
689
|
+
import { fileURLToPath } from "url";
|
|
690
|
+
import { Worker } from "worker_threads";
|
|
691
|
+
async function createNeedle(options = {}) {
|
|
692
|
+
return new Agent((signal) => loadSession({
|
|
693
|
+
...options,
|
|
694
|
+
stateless: false,
|
|
695
|
+
abortSignal: signal
|
|
696
|
+
}, "needle3"), options).ready(options.abortSignal);
|
|
697
|
+
}
|
|
698
|
+
async function createWhistle(options = {}) {
|
|
699
|
+
return new SpeechClient((signal) => loadSession({
|
|
700
|
+
...options,
|
|
701
|
+
abortSignal: signal
|
|
702
|
+
}, "whistle"), readAudio).ready(options.abortSignal);
|
|
703
|
+
}
|
|
704
|
+
async function loadSession(options, modelKind) {
|
|
705
|
+
options.abortSignal?.throwIfAborted();
|
|
706
|
+
const artifact = modelKind === "needle3" ? DEFAULT_MODEL : DEFAULT_SPEECH_MODEL;
|
|
707
|
+
const config = configuration(options);
|
|
708
|
+
const tokens = validateInteger(options.maxOutputTokens ?? options.maxNewTokens ?? 512, "maxOutputTokens", 1, 65536);
|
|
709
|
+
let modelPath;
|
|
710
|
+
try {
|
|
711
|
+
modelPath = options.modelPath instanceof URL ? fileURLToPath(options.modelPath) : options.modelPath ?? getModelPath(options.cacheDir, modelKind);
|
|
712
|
+
validateText(modelPath, "modelPath");
|
|
713
|
+
if (!modelPath) throw new Error("The path is empty.");
|
|
714
|
+
modelPath = resolve2(modelPath);
|
|
715
|
+
} catch (cause) {
|
|
716
|
+
throw new NeedleError("INVALID_ARGUMENT", "modelPath must be a local file path or a file: URL.", { cause });
|
|
717
|
+
}
|
|
718
|
+
const workerData = {
|
|
719
|
+
...config,
|
|
720
|
+
modelKind,
|
|
721
|
+
modelPath,
|
|
722
|
+
...options.modelPath === void 0 ? { expectedSha256: artifact.sha256 } : {}
|
|
723
|
+
};
|
|
724
|
+
const execArgv = process.execArgv.filter((arg, index, args) => !arg.startsWith("--input-type=") && arg !== "--input-type" && args[index - 1] !== "--input-type");
|
|
725
|
+
const worker = new Worker(new URL("./worker.js", import.meta.url), {
|
|
726
|
+
workerData,
|
|
727
|
+
env: {
|
|
728
|
+
NEEDLE_TELEMETRY: "0",
|
|
729
|
+
DO_NOT_TRACK: "1"
|
|
730
|
+
},
|
|
731
|
+
...execArgv.length === process.execArgv.length ? {} : { execArgv }
|
|
732
|
+
});
|
|
733
|
+
const session = new RpcSession({
|
|
734
|
+
send: (request) => worker.postMessage(request),
|
|
735
|
+
terminate: async () => {
|
|
736
|
+
await worker.terminate();
|
|
737
|
+
},
|
|
738
|
+
ref: () => worker.ref(),
|
|
739
|
+
unref: () => worker.unref(),
|
|
740
|
+
listen(onMessage, onError) {
|
|
741
|
+
worker.on("message", onMessage);
|
|
742
|
+
worker.on("error", onError);
|
|
743
|
+
worker.on("messageerror", onError);
|
|
744
|
+
worker.once("exit", (code) => onError(/* @__PURE__ */ new Error(`Inference worker exited (${code}).`)));
|
|
745
|
+
}
|
|
746
|
+
}, tokens);
|
|
747
|
+
const abort = () => {
|
|
748
|
+
session.close();
|
|
749
|
+
};
|
|
750
|
+
options.abortSignal?.addEventListener("abort", abort, { once: true });
|
|
751
|
+
try {
|
|
752
|
+
await session.ready;
|
|
753
|
+
options.abortSignal?.throwIfAborted();
|
|
754
|
+
return session;
|
|
755
|
+
} catch (error) {
|
|
756
|
+
await session.close();
|
|
757
|
+
if (options.abortSignal?.aborted) throw options.abortSignal.reason;
|
|
758
|
+
throw error;
|
|
759
|
+
} finally {
|
|
760
|
+
options.abortSignal?.removeEventListener("abort", abort);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/shortcuts.js
|
|
765
|
+
var DefaultModel = class {
|
|
766
|
+
create;
|
|
767
|
+
#model;
|
|
768
|
+
constructor(create) {
|
|
769
|
+
this.create = create;
|
|
770
|
+
}
|
|
771
|
+
#acquire(options, signal) {
|
|
772
|
+
signal?.throwIfAborted();
|
|
773
|
+
const custom = Object.values(options).some((value) => value !== void 0);
|
|
774
|
+
const model2 = custom ? this.create(options) : this.#model ?? this.create();
|
|
775
|
+
if (!custom) this.#model = model2;
|
|
776
|
+
return {
|
|
777
|
+
model: model2,
|
|
778
|
+
release: async (error) => {
|
|
779
|
+
const closed = signal?.aborted || error instanceof NeedleError && (error.code === "CLOSED" || error.code === "WORKER_ERROR");
|
|
780
|
+
if (custom) await model2.close();
|
|
781
|
+
else if (closed && this.#model === model2) {
|
|
782
|
+
this.#model = void 0;
|
|
783
|
+
await model2.close();
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
async use(options, signal, run) {
|
|
789
|
+
const { model: model2, release } = this.#acquire(options, signal);
|
|
790
|
+
let failure;
|
|
791
|
+
try {
|
|
792
|
+
return await run(model2);
|
|
793
|
+
} catch (error) {
|
|
794
|
+
failure = error;
|
|
795
|
+
throw error;
|
|
796
|
+
} finally {
|
|
797
|
+
await release(failure);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
async *stream(options, signal, run) {
|
|
801
|
+
const { model: model2, release } = this.#acquire(options, signal);
|
|
802
|
+
let failure;
|
|
803
|
+
try {
|
|
804
|
+
yield* run(model2);
|
|
805
|
+
} catch (error) {
|
|
806
|
+
failure = error;
|
|
807
|
+
throw error;
|
|
808
|
+
} finally {
|
|
809
|
+
await release(failure);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
async close() {
|
|
813
|
+
const model2 = this.#model;
|
|
814
|
+
this.#model = void 0;
|
|
815
|
+
await model2?.close();
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
function shortcuts(textModel, speechModel2) {
|
|
819
|
+
const text = new DefaultModel(textModel);
|
|
820
|
+
const speech = new DefaultModel(speechModel2);
|
|
821
|
+
return {
|
|
822
|
+
stream(chunks, options) {
|
|
823
|
+
const { language, keywords, abortSignal, ...loading } = options ?? {};
|
|
824
|
+
return speech.stream(loading, abortSignal, (model2) => model2.stream(chunks, {
|
|
825
|
+
...language === void 0 ? {} : { language },
|
|
826
|
+
...keywords === void 0 ? {} : { keywords },
|
|
827
|
+
...abortSignal === void 0 ? {} : { abortSignal }
|
|
828
|
+
}));
|
|
829
|
+
},
|
|
830
|
+
async transcribe(audio, options) {
|
|
831
|
+
const { language, keywords, wordTimestamps, abortSignal, ...loading } = options ?? {};
|
|
832
|
+
return speech.use(loading, abortSignal, (model2) => model2.transcribe(audio, {
|
|
833
|
+
...language === void 0 ? {} : { language },
|
|
834
|
+
...keywords === void 0 ? {} : { keywords },
|
|
835
|
+
...wordTimestamps === void 0 ? {} : { wordTimestamps },
|
|
836
|
+
...abortSignal === void 0 ? {} : { abortSignal }
|
|
837
|
+
}));
|
|
838
|
+
},
|
|
839
|
+
async extract(input, schema, options) {
|
|
840
|
+
const { strict, maxNewTokens, abortSignal, ...loading } = options ?? {};
|
|
841
|
+
return text.use(loading, abortSignal, (model2) => model2.extract(input, schema, {
|
|
842
|
+
...strict === void 0 ? {} : { strict },
|
|
843
|
+
...maxNewTokens === void 0 ? {} : { maxNewTokens },
|
|
844
|
+
...abortSignal === void 0 ? {} : { abortSignal }
|
|
845
|
+
}));
|
|
846
|
+
},
|
|
847
|
+
async close() {
|
|
848
|
+
await Promise.all([text.close(), speech.close()]);
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// ../../node_modules/.pnpm/cactus-needle@0.3.0/node_modules/cactus-needle/dist/node/api.js
|
|
854
|
+
async function load(options, model2, signal) {
|
|
855
|
+
signal = options.abortSignal ? AbortSignal.any([signal, options.abortSignal]) : signal;
|
|
856
|
+
signal.throwIfAborted();
|
|
857
|
+
if (options.weights !== void 0 && options.modelPath !== void 0) throw new NeedleError("INVALID_ARGUMENT", "Supply weights or modelPath, not both.");
|
|
858
|
+
if (options.download !== void 0 && typeof options.download !== "boolean") throw new NeedleError("INVALID_ARGUMENT", "download must be a boolean.");
|
|
859
|
+
const modelPath = options.weights ?? options.modelPath;
|
|
860
|
+
if (modelPath === void 0 && options.download !== false) await downloadModel({
|
|
861
|
+
model: model2,
|
|
862
|
+
signal,
|
|
863
|
+
...options.cacheDir === void 0 ? {} : { cacheDir: options.cacheDir }
|
|
864
|
+
});
|
|
865
|
+
return loadSession({
|
|
866
|
+
...options,
|
|
867
|
+
stateless: false,
|
|
868
|
+
abortSignal: signal,
|
|
869
|
+
...modelPath === void 0 ? {} : { modelPath }
|
|
870
|
+
}, model2);
|
|
871
|
+
}
|
|
872
|
+
var Needle = class extends Agent {
|
|
873
|
+
constructor(options = {}) {
|
|
874
|
+
super((signal) => load(options, "needle3", signal), options);
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
var Whistle = class extends SpeechClient {
|
|
878
|
+
constructor(options = {}) {
|
|
879
|
+
super((signal) => load(options, "whistle", signal), readAudio);
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
var { transcribe, stream, extract, close } = shortcuts((options) => new Needle(options), (options) => new Whistle(options));
|
|
883
|
+
export {
|
|
884
|
+
DEFAULT_MODEL2 as DEFAULT_MODEL,
|
|
885
|
+
DEFAULT_SPEECH_MODEL,
|
|
886
|
+
ExtractionValidationError,
|
|
887
|
+
Needle,
|
|
888
|
+
NeedleError,
|
|
889
|
+
Whistle,
|
|
890
|
+
close,
|
|
891
|
+
createNeedle,
|
|
892
|
+
createWhistle,
|
|
893
|
+
downloadModel,
|
|
894
|
+
extract,
|
|
895
|
+
getModelPath,
|
|
896
|
+
stream,
|
|
897
|
+
tool,
|
|
898
|
+
transcribe
|
|
899
|
+
};
|