@workglow/cactus 0.3.3 → 0.3.4
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/dist/ai/CactusProvider.browser.d.ts +23 -0
- package/dist/ai/CactusProvider.browser.d.ts.map +1 -0
- package/dist/ai/CactusQueuedProvider.browser.d.ts +23 -0
- package/dist/ai/CactusQueuedProvider.browser.d.ts.map +1 -0
- package/dist/ai/common/Cactus_Download.browser.d.ts +9 -0
- package/dist/ai/common/Cactus_Download.browser.d.ts.map +1 -0
- package/dist/ai/common/Cactus_DownloadRemove.browser.d.ts +9 -0
- package/dist/ai/common/Cactus_DownloadRemove.browser.d.ts.map +1 -0
- package/dist/ai/common/Cactus_JobRunFns.browser.d.ts +12 -0
- package/dist/ai/common/Cactus_JobRunFns.browser.d.ts.map +1 -0
- package/dist/ai/common/Cactus_ModelInfo.browser.d.ts +9 -0
- package/dist/ai/common/Cactus_ModelInfo.browser.d.ts.map +1 -0
- package/dist/ai/common/Cactus_ToolCalling.browser.d.ts +9 -0
- package/dist/ai/common/Cactus_ToolCalling.browser.d.ts.map +1 -0
- package/dist/ai/registerCactus.browser.d.ts +10 -0
- package/dist/ai/registerCactus.browser.d.ts.map +1 -0
- package/dist/ai/registerCactusInline.browser.d.ts +8 -0
- package/dist/ai/registerCactusInline.browser.d.ts.map +1 -0
- package/dist/ai/registerCactusWorker.browser.d.ts +7 -0
- package/dist/ai/registerCactusWorker.browser.d.ts.map +1 -0
- package/dist/ai-runtime.browser.d.ts +2 -2
- package/dist/ai-runtime.browser.d.ts.map +1 -1
- package/dist/ai-runtime.browser.js +21 -181
- package/dist/ai-runtime.browser.js.map +12 -13
- package/dist/ai.browser.d.ts +5 -5
- package/dist/ai.browser.d.ts.map +1 -1
- package/dist/ai.browser.js +28 -188
- package/dist/ai.browser.js.map +13 -14
- package/package.json +11 -11
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderPreviewRunFn, AiProviderRunFnRegistration, Capability, ModelConfig, ModelRecord } from "@workglow/ai/worker";
|
|
7
|
+
import { AiProvider } from "@workglow/ai/worker";
|
|
8
|
+
import type { CactusModelConfig } from "./common/Cactus_ModelSchema";
|
|
9
|
+
/** Browser worker-server registration for Cactus. */
|
|
10
|
+
export declare class CactusProvider extends AiProvider<CactusModelConfig> {
|
|
11
|
+
readonly name = "LOCAL_CACTUS";
|
|
12
|
+
readonly displayName = "Cactus (Needle)";
|
|
13
|
+
readonly isLocal = true;
|
|
14
|
+
readonly supportsBrowser = true;
|
|
15
|
+
constructor(promiseRunFns?: readonly AiProviderRunFnRegistration<any, any, CactusModelConfig>[], previewTasks?: Record<string, AiProviderPreviewRunFn<any, any, CactusModelConfig>>);
|
|
16
|
+
inferCapabilities(model: ModelRecord): readonly Capability[];
|
|
17
|
+
protected workerRunFnSpecs(): readonly {
|
|
18
|
+
serves: readonly Capability[];
|
|
19
|
+
}[];
|
|
20
|
+
createSession(_model: ModelConfig): string;
|
|
21
|
+
disposeSession(sessionId: string): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=CactusProvider.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CactusProvider.browser.d.ts","sourceRoot":"","sources":["../../src/ai/CactusProvider.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,2BAA2B,EAC3B,UAAU,EACV,WAAW,EACX,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,qDAAqD;AACrD,qBAAa,cAAe,SAAQ,UAAU,CAAC,iBAAiB,CAAC;IAC/D,QAAQ,CAAC,IAAI,kBAAgB;IAC7B,QAAQ,CAAC,WAAW,qBAAqB;IACzC,QAAQ,CAAC,OAAO,QAAQ;IACxB,QAAQ,CAAC,eAAe,QAAQ;IAEhC,YACE,aAAa,CAAC,EAAE,SAAS,2BAA2B,CAElD,GAAG,EAEH,GAAG,EACH,iBAAiB,CAClB,EAAE,EACH,YAAY,CAAC,EAAE,MAAM,CACnB,MAAM,EAEN,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CACpD,EAGF;IAEQ,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,UAAU,EAAE,CAEpE;IAED,UAAmB,gBAAgB,IAAI,SAAS;QAAE,MAAM,EAAE,SAAS,UAAU,EAAE,CAAA;KAAE,EAAE,CAElF;IAEQ,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAElD;IAEc,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderPreviewRunFn, AiProviderRunFnRegistration, Capability, ModelConfig, ModelRecord } from "@workglow/ai";
|
|
7
|
+
import { QueuedAiProvider } from "@workglow/ai";
|
|
8
|
+
import type { CactusModelConfig } from "./common/Cactus_ModelSchema";
|
|
9
|
+
/** Browser main-thread registration (inline or worker-backed); creates the default job queue. */
|
|
10
|
+
export declare class CactusQueuedProvider extends QueuedAiProvider<CactusModelConfig> {
|
|
11
|
+
readonly name = "LOCAL_CACTUS";
|
|
12
|
+
readonly displayName = "Cactus (Needle)";
|
|
13
|
+
readonly isLocal = true;
|
|
14
|
+
readonly supportsBrowser = true;
|
|
15
|
+
constructor(promiseRunFns?: readonly AiProviderRunFnRegistration<any, any, CactusModelConfig>[], previewTasks?: Record<string, AiProviderPreviewRunFn<any, any, CactusModelConfig>>);
|
|
16
|
+
inferCapabilities(model: ModelRecord): readonly Capability[];
|
|
17
|
+
protected workerRunFnSpecs(): readonly {
|
|
18
|
+
serves: readonly Capability[];
|
|
19
|
+
}[];
|
|
20
|
+
createSession(_model: ModelConfig): string;
|
|
21
|
+
disposeSession(sessionId: string): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=CactusQueuedProvider.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CactusQueuedProvider.browser.d.ts","sourceRoot":"","sources":["../../src/ai/CactusQueuedProvider.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,2BAA2B,EAC3B,UAAU,EACV,WAAW,EACX,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,iGAAiG;AACjG,qBAAa,oBAAqB,SAAQ,gBAAgB,CAAC,iBAAiB,CAAC;IAC3E,QAAQ,CAAC,IAAI,kBAAgB;IAC7B,QAAQ,CAAC,WAAW,qBAAqB;IACzC,QAAQ,CAAC,OAAO,QAAQ;IACxB,QAAQ,CAAC,eAAe,QAAQ;IAEhC,YACE,aAAa,CAAC,EAAE,SAAS,2BAA2B,CAElD,GAAG,EAEH,GAAG,EACH,iBAAiB,CAClB,EAAE,EACH,YAAY,CAAC,EAAE,MAAM,CACnB,MAAM,EAEN,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CACpD,EAGF;IAEQ,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,UAAU,EAAE,CAEpE;IAED,UAAmB,gBAAgB,IAAI,SAAS;QAAE,MAAM,EAAE,SAAS,UAAU,EAAE,CAAA;KAAE,EAAE,CAElF;IAEQ,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAElD;IAEc,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderRunFn, ModelDownloadTaskRunInput, ModelDownloadTaskRunOutput } from "@workglow/ai";
|
|
7
|
+
import type { CactusModelConfig } from "./Cactus_ModelSchema";
|
|
8
|
+
export declare const Cactus_Download: AiProviderRunFn<ModelDownloadTaskRunInput, ModelDownloadTaskRunOutput, CactusModelConfig>;
|
|
9
|
+
//# sourceMappingURL=Cactus_Download.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cactus_Download.browser.d.ts","sourceRoot":"","sources":["../../../src/ai/common/Cactus_Download.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,yBAAyB,EACzB,0BAA0B,EAC3B,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,eAAO,MAAM,eAAe,EAAE,eAAe,CAC3C,yBAAyB,EACzB,0BAA0B,EAC1B,iBAAiB,CAkBlB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderRunFn, ModelDownloadRemoveTaskRunInput, ModelDownloadRemoveTaskRunOutput } from "@workglow/ai";
|
|
7
|
+
import type { CactusModelConfig } from "./Cactus_ModelSchema";
|
|
8
|
+
export declare const Cactus_DownloadRemove: AiProviderRunFn<ModelDownloadRemoveTaskRunInput, ModelDownloadRemoveTaskRunOutput, CactusModelConfig>;
|
|
9
|
+
//# sourceMappingURL=Cactus_DownloadRemove.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cactus_DownloadRemove.browser.d.ts","sourceRoot":"","sources":["../../../src/ai/common/Cactus_DownloadRemove.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,+BAA+B,EAC/B,gCAAgC,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,eAAO,MAAM,qBAAqB,EAAE,eAAe,CACjD,+BAA+B,EAC/B,gCAAgC,EAChC,iBAAiB,CAKlB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderRunFnRegistration } from "@workglow/ai";
|
|
7
|
+
import type { CactusModelConfig } from "./Cactus_ModelSchema";
|
|
8
|
+
export { cactusConfigJson, cactusEngines, deleteCactusSession, disposeCactusResources, getOrLoadEngine, loadSdk, removeCachedAssets, } from "./Cactus_Runtime.browser";
|
|
9
|
+
export declare const CACTUS_RUN_FNS: readonly AiProviderRunFnRegistration<any, any, CactusModelConfig>[];
|
|
10
|
+
/** No preview-only tasks for Cactus today. */
|
|
11
|
+
export declare const CACTUS_PREVIEW_TASKS: {};
|
|
12
|
+
//# sourceMappingURL=Cactus_JobRunFns.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cactus_JobRunFns.browser.d.ts","sourceRoot":"","sources":["../../../src/ai/common/Cactus_JobRunFns.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAWhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,OAAO,EACP,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAElC,eAAO,MAAM,cAAc,EAAE,SAAS,2BAA2B,CAE/D,GAAG,EAEH,GAAG,EACH,iBAAiB,CAClB,EAMA,CAAC;AAEF,8CAA8C;AAC9C,eAAO,MAAM,oBAAoB,IAAc,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderRunFn, ModelInfoTaskInput, ModelInfoTaskOutput } from "@workglow/ai";
|
|
7
|
+
import type { CactusModelConfig } from "./Cactus_ModelSchema";
|
|
8
|
+
export declare const Cactus_ModelInfo: AiProviderRunFn<ModelInfoTaskInput, ModelInfoTaskOutput, CactusModelConfig>;
|
|
9
|
+
//# sourceMappingURL=Cactus_ModelInfo.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cactus_ModelInfo.browser.d.ts","sourceRoot":"","sources":["../../../src/ai/common/Cactus_ModelInfo.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAE7F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAC5C,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,CAuBlB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderRunFn, ToolCallingTaskInput, ToolCallingTaskOutput } from "@workglow/ai";
|
|
7
|
+
import type { CactusModelConfig } from "./Cactus_ModelSchema";
|
|
8
|
+
export declare const Cactus_ToolCalling: AiProviderRunFn<ToolCallingTaskInput, ToolCallingTaskOutput, CactusModelConfig>;
|
|
9
|
+
//# sourceMappingURL=Cactus_ToolCalling.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cactus_ToolCalling.browser.d.ts","sourceRoot":"","sources":["../../../src/ai/common/Cactus_ToolCalling.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EAGtB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAiD9D,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,CA8BlB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderRegisterOptions } from "@workglow/ai";
|
|
7
|
+
export declare function registerCactus(options: AiProviderRegisterOptions & {
|
|
8
|
+
worker: Worker | (() => Worker);
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=registerCactus.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerCactus.browser.d.ts","sourceRoot":"","sources":["../../src/ai/registerCactus.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAI9D,wBAAsB,cAAc,CAClC,OAAO,EAAE,yBAAyB,GAAG;IACnC,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;CACjC,GACA,OAAO,CAAC,IAAI,CAAC,CAEf"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProviderRegisterOptions } from "@workglow/ai";
|
|
7
|
+
export declare function registerCactusInline(options?: AiProviderRegisterOptions): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=registerCactusInline.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerCactusInline.browser.d.ts","sourceRoot":"","sources":["../../src/ai/registerCactusInline.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAK9D,wBAAsB,oBAAoB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerCactusWorker.browser.d.ts","sourceRoot":"","sources":["../../src/ai/registerCactusWorker.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAK1D"}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
export * from "./ai/common/Cactus_Runtime.browser";
|
|
7
|
-
export * from "./ai/registerCactusInline";
|
|
8
|
-
export * from "./ai/registerCactusWorker";
|
|
7
|
+
export * from "./ai/registerCactusInline.browser";
|
|
8
|
+
export * from "./ai/registerCactusWorker.browser";
|
|
9
9
|
//# sourceMappingURL=ai-runtime.browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-runtime.browser.d.ts","sourceRoot":"","sources":["../src/ai-runtime.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,oCAAoC,CAAC;AACnD,cAAc,
|
|
1
|
+
{"version":3,"file":"ai-runtime.browser.d.ts","sourceRoot":"","sources":["../src/ai-runtime.browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC"}
|
|
@@ -173,10 +173,10 @@ async function disposeCactusResources() {
|
|
|
173
173
|
cactusCachedModelIds.clear();
|
|
174
174
|
cactusSessions.clear();
|
|
175
175
|
}
|
|
176
|
-
// src/ai/registerCactusInline.ts
|
|
176
|
+
// src/ai/registerCactusInline.browser.ts
|
|
177
177
|
import { registerProviderInline } from "@workglow/ai/provider-utils";
|
|
178
178
|
|
|
179
|
-
// src/ai/CactusQueuedProvider.ts
|
|
179
|
+
// src/ai/CactusQueuedProvider.browser.ts
|
|
180
180
|
import { QueuedAiProvider } from "@workglow/ai";
|
|
181
181
|
|
|
182
182
|
// src/ai/common/Cactus_CapabilitySets.ts
|
|
@@ -204,167 +204,7 @@ function inferCactusCapabilities(_model) {
|
|
|
204
204
|
return ["tool-use", "model.download", "model.download-remove", "model.search", "model.info"];
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
// src/ai/
|
|
208
|
-
import fs from "node:fs/promises";
|
|
209
|
-
import path from "node:path";
|
|
210
|
-
var _sdk2;
|
|
211
|
-
var _sdkInitPromise2;
|
|
212
|
-
async function loadSdk2() {
|
|
213
|
-
_sdkInitPromise2 ??= import("needle-rs").then(async (mod) => {
|
|
214
|
-
const init = mod.default;
|
|
215
|
-
if (typeof init === "function") {
|
|
216
|
-
await init();
|
|
217
|
-
}
|
|
218
|
-
_sdk2 = mod;
|
|
219
|
-
return mod;
|
|
220
|
-
}).catch((err) => {
|
|
221
|
-
_sdkInitPromise2 = undefined;
|
|
222
|
-
_sdk2 = undefined;
|
|
223
|
-
throw new Error(`needle-rs is required for LOCAL_CACTUS tasks. Install it with: bun add needle-rs (cause: ${String(err)})`);
|
|
224
|
-
});
|
|
225
|
-
return _sdkInitPromise2;
|
|
226
|
-
}
|
|
227
|
-
function hasBrowserCacheStorage() {
|
|
228
|
-
return typeof globalThis !== "undefined" && "caches" in globalThis && typeof globalThis.caches?.open === "function";
|
|
229
|
-
}
|
|
230
|
-
function modelsDirOf(model) {
|
|
231
|
-
return model.provider_config.models_dir ?? CACTUS_DEFAULT_MODELS_DIR;
|
|
232
|
-
}
|
|
233
|
-
async function fetchAssetBytesBrowser2(url) {
|
|
234
|
-
const cachesApi = globalThis.caches;
|
|
235
|
-
const cache = await cachesApi.open(CACTUS_CACHE_NAME);
|
|
236
|
-
const hit = await cache.match(url);
|
|
237
|
-
if (hit) {
|
|
238
|
-
return new Uint8Array(await hit.arrayBuffer());
|
|
239
|
-
}
|
|
240
|
-
const resp = await fetch(url);
|
|
241
|
-
if (!resp.ok)
|
|
242
|
-
throw new Error(`Cactus asset fetch failed (${resp.status}) for ${url}`);
|
|
243
|
-
await cache.put(url, resp.clone());
|
|
244
|
-
return new Uint8Array(await resp.arrayBuffer());
|
|
245
|
-
}
|
|
246
|
-
async function fetchAssetBytesNode(url, models_dir, model_id, filename) {
|
|
247
|
-
const resolvedDir = models_dir.startsWith("~/") ? path.join(process.env.HOME ?? process.env.USERPROFILE ?? ".", models_dir.slice(2), model_id) : path.resolve(models_dir, model_id);
|
|
248
|
-
const filePath = path.join(resolvedDir, filename);
|
|
249
|
-
try {
|
|
250
|
-
const buf = await fs.readFile(filePath);
|
|
251
|
-
return new Uint8Array(buf);
|
|
252
|
-
} catch {}
|
|
253
|
-
const resp = await fetch(url);
|
|
254
|
-
if (!resp.ok)
|
|
255
|
-
throw new Error(`Cactus asset fetch failed (${resp.status}) for ${url}`);
|
|
256
|
-
const bytes = new Uint8Array(await resp.arrayBuffer());
|
|
257
|
-
await fs.mkdir(resolvedDir, { recursive: true });
|
|
258
|
-
const tmpPath = `${filePath}.tmp`;
|
|
259
|
-
await fs.writeFile(tmpPath, bytes);
|
|
260
|
-
await fs.rename(tmpPath, filePath);
|
|
261
|
-
return bytes;
|
|
262
|
-
}
|
|
263
|
-
async function fetchAssetBytes2(model, filename) {
|
|
264
|
-
const model_id = model.provider_config.model_id;
|
|
265
|
-
const entry = getCactusCatalogEntry(model_id);
|
|
266
|
-
if (!entry)
|
|
267
|
-
throw new Error(`Unknown Cactus model_id: ${model_id}`);
|
|
268
|
-
const url = cactusAssetUrl(entry, filename);
|
|
269
|
-
if (hasBrowserCacheStorage()) {
|
|
270
|
-
return fetchAssetBytesBrowser2(url);
|
|
271
|
-
}
|
|
272
|
-
return fetchAssetBytesNode(url, modelsDirOf(model), model_id, filename);
|
|
273
|
-
}
|
|
274
|
-
var cactusEngines2 = new Map;
|
|
275
|
-
var cactusConfigJson2 = new Map;
|
|
276
|
-
var cactusCachedModelIds2 = new Set;
|
|
277
|
-
var cactusEngineLoadsInFlight2 = new Map;
|
|
278
|
-
async function getOrLoadEngine2(model) {
|
|
279
|
-
const model_id = model.provider_config.model_id;
|
|
280
|
-
const cached = cactusEngines2.get(model_id);
|
|
281
|
-
if (cached)
|
|
282
|
-
return cached;
|
|
283
|
-
const inFlight = cactusEngineLoadsInFlight2.get(model_id);
|
|
284
|
-
if (inFlight)
|
|
285
|
-
return inFlight;
|
|
286
|
-
const loadPromise = (async () => {
|
|
287
|
-
const sdk = await loadSdk2();
|
|
288
|
-
const entry = getCactusCatalogEntry(model_id);
|
|
289
|
-
if (!entry)
|
|
290
|
-
throw new Error(`Unknown Cactus model_id: ${model_id}`);
|
|
291
|
-
const [weightsBytes, vocabBytes, configBytes] = await Promise.all([
|
|
292
|
-
fetchAssetBytes2(model, entry.assets.weights),
|
|
293
|
-
fetchAssetBytes2(model, entry.assets.vocab),
|
|
294
|
-
fetchAssetBytes2(model, entry.assets.config)
|
|
295
|
-
]);
|
|
296
|
-
try {
|
|
297
|
-
const text = new TextDecoder().decode(configBytes);
|
|
298
|
-
cactusConfigJson2.set(model_id, JSON.parse(text));
|
|
299
|
-
} catch {
|
|
300
|
-
cactusConfigJson2.set(model_id, null);
|
|
301
|
-
}
|
|
302
|
-
const vocabText = new TextDecoder().decode(vocabBytes);
|
|
303
|
-
const engine = sdk.NeedleWasm.load(weightsBytes, vocabText);
|
|
304
|
-
if (!engine) {
|
|
305
|
-
throw new Error(`needle-rs NeedleWasm.load returned undefined for model ${model_id}`);
|
|
306
|
-
}
|
|
307
|
-
cactusEngines2.set(model_id, engine);
|
|
308
|
-
return engine;
|
|
309
|
-
})().finally(() => {
|
|
310
|
-
cactusEngineLoadsInFlight2.delete(model_id);
|
|
311
|
-
});
|
|
312
|
-
cactusEngineLoadsInFlight2.set(model_id, loadPromise);
|
|
313
|
-
return loadPromise;
|
|
314
|
-
}
|
|
315
|
-
function isModelLoaded2(model_id) {
|
|
316
|
-
return cactusEngines2.has(model_id);
|
|
317
|
-
}
|
|
318
|
-
function markModelCached2(model_id) {
|
|
319
|
-
cactusCachedModelIds2.add(model_id);
|
|
320
|
-
}
|
|
321
|
-
function isModelCached2(model_id) {
|
|
322
|
-
return cactusEngines2.has(model_id) || cactusCachedModelIds2.has(model_id);
|
|
323
|
-
}
|
|
324
|
-
var cactusSessions2 = new Map;
|
|
325
|
-
async function deleteCactusSession2(id) {
|
|
326
|
-
return cactusSessions2.delete(id);
|
|
327
|
-
}
|
|
328
|
-
async function removeBrowserCacheEntries2(entry) {
|
|
329
|
-
if (!hasBrowserCacheStorage())
|
|
330
|
-
return;
|
|
331
|
-
const cachesApi = globalThis.caches;
|
|
332
|
-
const cache = await cachesApi.open(CACTUS_CACHE_NAME);
|
|
333
|
-
for (const filename of [entry.assets.weights, entry.assets.vocab, entry.assets.config]) {
|
|
334
|
-
const url = cactusAssetUrl(entry, filename);
|
|
335
|
-
try {
|
|
336
|
-
await cache.delete(url);
|
|
337
|
-
} catch {}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
async function removeNodeCacheDir(model, model_id) {
|
|
341
|
-
if (hasBrowserCacheStorage())
|
|
342
|
-
return;
|
|
343
|
-
const models_dir = modelsDirOf(model);
|
|
344
|
-
const resolvedDir = models_dir.startsWith("~/") ? path.join(process.env.HOME ?? process.env.USERPROFILE ?? ".", models_dir.slice(2), model_id) : path.resolve(models_dir, model_id);
|
|
345
|
-
await fs.rm(resolvedDir, { recursive: true, force: true });
|
|
346
|
-
}
|
|
347
|
-
function disposeCactusEngine2(model_id) {
|
|
348
|
-
const engine = cactusEngines2.get(model_id);
|
|
349
|
-
if (engine) {
|
|
350
|
-
try {
|
|
351
|
-
engine.free?.();
|
|
352
|
-
} catch {}
|
|
353
|
-
}
|
|
354
|
-
cactusEngines2.delete(model_id);
|
|
355
|
-
cactusConfigJson2.delete(model_id);
|
|
356
|
-
cactusCachedModelIds2.delete(model_id);
|
|
357
|
-
}
|
|
358
|
-
async function removeCachedAssets2(model) {
|
|
359
|
-
const model_id = model.provider_config.model_id;
|
|
360
|
-
const entry = getCactusCatalogEntry(model_id);
|
|
361
|
-
if (!entry)
|
|
362
|
-
return;
|
|
363
|
-
await Promise.all([removeBrowserCacheEntries2(entry), removeNodeCacheDir(model, model_id)]);
|
|
364
|
-
disposeCactusEngine2(model_id);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// src/ai/CactusQueuedProvider.ts
|
|
207
|
+
// src/ai/CactusQueuedProvider.browser.ts
|
|
368
208
|
class CactusQueuedProvider extends QueuedAiProvider {
|
|
369
209
|
name = LOCAL_CACTUS;
|
|
370
210
|
displayName = "Cactus (Needle)";
|
|
@@ -383,11 +223,11 @@ class CactusQueuedProvider extends QueuedAiProvider {
|
|
|
383
223
|
return crypto.randomUUID();
|
|
384
224
|
}
|
|
385
225
|
async disposeSession(sessionId) {
|
|
386
|
-
await
|
|
226
|
+
await deleteCactusSession(sessionId);
|
|
387
227
|
}
|
|
388
228
|
}
|
|
389
229
|
|
|
390
|
-
// src/ai/common/Cactus_Download.ts
|
|
230
|
+
// src/ai/common/Cactus_Download.browser.ts
|
|
391
231
|
var Cactus_Download = async (input, model, _signal, emit) => {
|
|
392
232
|
if (!model)
|
|
393
233
|
throw new Error("Model config is required for ModelDownloadTask.");
|
|
@@ -402,21 +242,21 @@ var Cactus_Download = async (input, model, _signal, emit) => {
|
|
|
402
242
|
message: `Downloading ${assets[i]}`,
|
|
403
243
|
progress: Math.round((i + 0.5) / assets.length * 99)
|
|
404
244
|
});
|
|
405
|
-
await
|
|
245
|
+
await fetchAssetBytes(model, assets[i]);
|
|
406
246
|
}
|
|
407
|
-
|
|
247
|
+
markModelCached(model_id);
|
|
408
248
|
emit({ type: "finish", data: { model: input.model } });
|
|
409
249
|
};
|
|
410
250
|
|
|
411
|
-
// src/ai/common/Cactus_DownloadRemove.ts
|
|
251
|
+
// src/ai/common/Cactus_DownloadRemove.browser.ts
|
|
412
252
|
var Cactus_DownloadRemove = async (input, model, _signal, emit) => {
|
|
413
253
|
if (!model)
|
|
414
254
|
throw new Error("Model config is required for ModelDownloadRemoveTask.");
|
|
415
|
-
await
|
|
255
|
+
await removeCachedAssets(model);
|
|
416
256
|
emit({ type: "finish", data: { model: input.model } });
|
|
417
257
|
};
|
|
418
258
|
|
|
419
|
-
// src/ai/common/Cactus_ModelInfo.ts
|
|
259
|
+
// src/ai/common/Cactus_ModelInfo.browser.ts
|
|
420
260
|
var Cactus_ModelInfo = async (input, model, _signal, emit) => {
|
|
421
261
|
if (!model)
|
|
422
262
|
throw new Error("Model config is required for ModelInfoTask.");
|
|
@@ -424,8 +264,8 @@ var Cactus_ModelInfo = async (input, model, _signal, emit) => {
|
|
|
424
264
|
const entry = getCactusCatalogEntry(model_id);
|
|
425
265
|
if (!entry)
|
|
426
266
|
throw new Error(`Unknown Cactus model_id: ${model_id}`);
|
|
427
|
-
const is_loaded =
|
|
428
|
-
const is_cached =
|
|
267
|
+
const is_loaded = isModelLoaded(model_id);
|
|
268
|
+
const is_cached = isModelCached(model_id);
|
|
429
269
|
emit({
|
|
430
270
|
type: "finish",
|
|
431
271
|
data: {
|
|
@@ -462,7 +302,7 @@ var Cactus_ModelSearch = async (input, _model, _signal, emit) => {
|
|
|
462
302
|
emit({ type: "finish", data: { results } });
|
|
463
303
|
};
|
|
464
304
|
|
|
465
|
-
// src/ai/common/Cactus_ToolCalling.ts
|
|
305
|
+
// src/ai/common/Cactus_ToolCalling.browser.ts
|
|
466
306
|
import { extractMessageText } from "@workglow/ai/provider-utils";
|
|
467
307
|
import { filterValidToolCalls } from "@workglow/ai/worker";
|
|
468
308
|
function buildToolsJson(tools) {
|
|
@@ -512,7 +352,7 @@ var Cactus_ToolCalling = async (input, model, signal, emit) => {
|
|
|
512
352
|
throw new Error("Model config is required for ToolCallingTask.");
|
|
513
353
|
if (signal.aborted)
|
|
514
354
|
throw signal.reason ?? new Error("The operation was aborted");
|
|
515
|
-
const engine = await
|
|
355
|
+
const engine = await getOrLoadEngine(model);
|
|
516
356
|
const query = promptText(input);
|
|
517
357
|
const toolsJson = buildToolsJson(input.tools);
|
|
518
358
|
let raw = "";
|
|
@@ -533,7 +373,7 @@ var Cactus_ToolCalling = async (input, model, signal, emit) => {
|
|
|
533
373
|
emit({ type: "finish", data: { text: raw, toolCalls: validToolCalls } });
|
|
534
374
|
};
|
|
535
375
|
|
|
536
|
-
// src/ai/common/Cactus_JobRunFns.ts
|
|
376
|
+
// src/ai/common/Cactus_JobRunFns.browser.ts
|
|
537
377
|
var CACTUS_RUN_FNS = [
|
|
538
378
|
{ serves: CACTUS_TOOL_USE, runFn: Cactus_ToolCalling },
|
|
539
379
|
{ serves: CACTUS_MODEL_DOWNLOAD, runFn: Cactus_Download },
|
|
@@ -543,14 +383,14 @@ var CACTUS_RUN_FNS = [
|
|
|
543
383
|
];
|
|
544
384
|
var CACTUS_PREVIEW_TASKS = {};
|
|
545
385
|
|
|
546
|
-
// src/ai/registerCactusInline.ts
|
|
386
|
+
// src/ai/registerCactusInline.browser.ts
|
|
547
387
|
async function registerCactusInline(options) {
|
|
548
388
|
await registerProviderInline(new CactusQueuedProvider(CACTUS_RUN_FNS, CACTUS_PREVIEW_TASKS), "Cactus", options);
|
|
549
389
|
}
|
|
550
|
-
// src/ai/registerCactusWorker.ts
|
|
390
|
+
// src/ai/registerCactusWorker.browser.ts
|
|
551
391
|
import { registerProviderWorker } from "@workglow/ai/provider-utils";
|
|
552
392
|
|
|
553
|
-
// src/ai/CactusProvider.ts
|
|
393
|
+
// src/ai/CactusProvider.browser.ts
|
|
554
394
|
import { AiProvider } from "@workglow/ai/worker";
|
|
555
395
|
class CactusProvider extends AiProvider {
|
|
556
396
|
name = LOCAL_CACTUS;
|
|
@@ -570,11 +410,11 @@ class CactusProvider extends AiProvider {
|
|
|
570
410
|
return crypto.randomUUID();
|
|
571
411
|
}
|
|
572
412
|
async disposeSession(sessionId) {
|
|
573
|
-
await
|
|
413
|
+
await deleteCactusSession(sessionId);
|
|
574
414
|
}
|
|
575
415
|
}
|
|
576
416
|
|
|
577
|
-
// src/ai/registerCactusWorker.ts
|
|
417
|
+
// src/ai/registerCactusWorker.browser.ts
|
|
578
418
|
async function registerCactusWorker() {
|
|
579
419
|
await registerProviderWorker((ws) => new CactusProvider(CACTUS_RUN_FNS, CACTUS_PREVIEW_TASKS).registerOnWorkerServer(ws), "Cactus");
|
|
580
420
|
}
|
|
@@ -596,4 +436,4 @@ export {
|
|
|
596
436
|
cactusConfigJson
|
|
597
437
|
};
|
|
598
438
|
|
|
599
|
-
//# debugId=
|
|
439
|
+
//# debugId=67D13FB5B6D17CB364756E2164756E21
|