@workglow/ai 0.2.30 → 0.2.32
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 +21 -21
- package/dist/browser.js +39 -22
- package/dist/browser.js.map +5 -5
- package/dist/bun.js +39 -22
- package/dist/bun.js.map +5 -5
- package/dist/model/ModelRegistry.d.ts +14 -6
- package/dist/model/ModelRegistry.d.ts.map +1 -1
- package/dist/node.js +39 -22
- package/dist/node.js.map +5 -5
- package/dist/provider/AiProviderRegistry.d.ts +21 -3
- package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
- package/dist/provider-utils/BaseCloudProvider.d.ts +46 -0
- package/dist/provider-utils/BaseCloudProvider.d.ts.map +1 -0
- package/dist/provider-utils/CloudProviderClient.d.ts +40 -0
- package/dist/provider-utils/CloudProviderClient.d.ts.map +1 -0
- package/dist/provider-utils/HfModelSearch.d.ts +33 -0
- package/dist/provider-utils/HfModelSearch.d.ts.map +1 -0
- package/dist/provider-utils/OpenAIShapedChat.d.ts +71 -0
- package/dist/provider-utils/OpenAIShapedChat.d.ts.map +1 -0
- package/dist/provider-utils/PipelineTaskMapping.d.ts +12 -0
- package/dist/provider-utils/PipelineTaskMapping.d.ts.map +1 -0
- package/dist/provider-utils/ToolCallParsers.d.ts +252 -0
- package/dist/provider-utils/ToolCallParsers.d.ts.map +1 -0
- package/dist/provider-utils/imageOutputHelpers.d.ts +60 -0
- package/dist/provider-utils/imageOutputHelpers.d.ts.map +1 -0
- package/dist/provider-utils/modelSearchQuery.d.ts +23 -0
- package/dist/provider-utils/modelSearchQuery.d.ts.map +1 -0
- package/dist/provider-utils/registerProvider.d.ts +43 -0
- package/dist/provider-utils/registerProvider.d.ts.map +1 -0
- package/dist/provider-utils.d.ts +23 -0
- package/dist/provider-utils.d.ts.map +1 -0
- package/dist/provider-utils.js +1247 -0
- package/dist/provider-utils.js.map +19 -0
- package/dist/task/VectorSimilarityTask.d.ts +1 -1
- package/dist/task/VectorSimilarityTask.d.ts.map +1 -1
- package/dist/worker.js +17 -8
- package/dist/worker.js.map +3 -3
- package/package.json +20 -14
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { TaskInput, TaskOutput } from "@workglow/task-graph";
|
|
7
7
|
import type { StreamEvent } from "@workglow/task-graph";
|
|
8
|
-
import type { JsonSchema } from "@workglow/util/worker";
|
|
8
|
+
import type { JsonSchema, ServiceRegistry } from "@workglow/util/worker";
|
|
9
9
|
import type { IAiExecutionStrategy, AiStrategyResolver } from "../execution/IAiExecutionStrategy";
|
|
10
10
|
import type { ModelConfig } from "../model/ModelSchema";
|
|
11
11
|
import type { AiProvider } from "./AiProvider";
|
|
@@ -185,6 +185,24 @@ export declare class AiProviderRegistry {
|
|
|
185
185
|
title?: string | undefined;
|
|
186
186
|
}>;
|
|
187
187
|
}
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Service token for the AI provider registry.
|
|
190
|
+
*/
|
|
191
|
+
export declare const AI_PROVIDER_REGISTRY: import("@workglow/util").ServiceToken<AiProviderRegistry>;
|
|
192
|
+
/**
|
|
193
|
+
* Returns the AI provider registry from the given registry (defaults to global).
|
|
194
|
+
* Lazy-registers a fresh `AiProviderRegistry` if the token is absent — same
|
|
195
|
+
* pattern as `getLogger`. Makes scoped registries safe to use without an
|
|
196
|
+
* explicit `registerAiProviderDefaults(registry)` call.
|
|
197
|
+
*/
|
|
198
|
+
export declare function getAiProviderRegistry(registry?: ServiceRegistry): AiProviderRegistry;
|
|
199
|
+
/**
|
|
200
|
+
* Replaces the AI provider registry on the given registry (defaults to global).
|
|
201
|
+
*/
|
|
202
|
+
export declare function setAiProviderRegistry(pr: AiProviderRegistry, registry?: ServiceRegistry): void;
|
|
203
|
+
/**
|
|
204
|
+
* Registers the AI provider registry default factory on the given registry.
|
|
205
|
+
* Called by `bootstrapWorkglow` and `createOrchestrationContext`.
|
|
206
|
+
*/
|
|
207
|
+
export declare function registerAiProviderDefaults(registry?: ServiceRegistry): void;
|
|
190
208
|
//# sourceMappingURL=AiProviderRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiProviderRegistry.d.ts","sourceRoot":"","sources":["../../src/provider/AiProviderRegistry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"AiProviderRegistry.d.ts","sourceRoot":"","sources":["../../src/provider/AiProviderRegistry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAClG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,eAAe,CACzB,KAAK,SAAS,SAAS,GAAG,SAAS,EACnC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,KAAK,SAAS,WAAW,GAAG,WAAW,IACrC,CACF,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,GAAG,SAAS,EACxB,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,EAC5E,MAAM,EAAE,WAAW,EACn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H,cAAc,CAAC,KAAK,SAAS,SAAS,GAAG,SAAS,EAAE,MAAM,SAAS,UAAU,GAAG,UAAU,EACxF,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;OAkBjB;CACF;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,2DAAiE,CAAC;AAEnG;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,GAAE,eAAuC,GAChD,kBAAkB,CAKpB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,kBAAkB,EACtB,QAAQ,GAAE,eAAuC,GAChD,IAAI,CAEN;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,GAAE,eAAuC,GAChD,IAAI,CAMN"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AiProvider } from "../provider/AiProvider";
|
|
7
|
+
import type { AiProviderPreviewRunFn, AiProviderRunFn, AiProviderStreamFn } from "../provider/AiProviderRegistry";
|
|
8
|
+
import type { ModelConfig } from "../model/ModelSchema";
|
|
9
|
+
/**
|
|
10
|
+
* Static metadata describing a cloud-backed AI provider.
|
|
11
|
+
*
|
|
12
|
+
* Shared across each provider's worker- and main-thread class shells so the
|
|
13
|
+
* declarations live in one place and only the constructor base differs.
|
|
14
|
+
*/
|
|
15
|
+
export interface CloudProviderMetadata<TaskTypes extends readonly string[] = readonly string[]> {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly displayName: string;
|
|
18
|
+
readonly isLocal?: boolean;
|
|
19
|
+
readonly supportsBrowser?: boolean;
|
|
20
|
+
readonly taskTypes: TaskTypes;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Constructor signature mirroring {@link AiProvider}'s public constructor.
|
|
24
|
+
* Declared structurally so callers can pass either the worker or main-thread
|
|
25
|
+
* `AiProvider` import without forcing this module to import either at runtime.
|
|
26
|
+
*/
|
|
27
|
+
type AiProviderCtor<TModelConfig extends ModelConfig> = abstract new (tasks?: Record<string, AiProviderRunFn<any, any, TModelConfig>>, streamTasks?: Record<string, AiProviderStreamFn<any, any, TModelConfig>>, previewTasks?: Record<string, AiProviderPreviewRunFn<any, any, TModelConfig>>) => AiProvider<TModelConfig>;
|
|
28
|
+
/**
|
|
29
|
+
* Build a concrete provider class by mixing the shared declarations from
|
|
30
|
+
* {@link CloudProviderMetadata} into a caller-supplied {@link AiProvider} base.
|
|
31
|
+
*
|
|
32
|
+
* Each cloud provider package keeps two thin shells (worker + main-thread)
|
|
33
|
+
* and supplies the appropriate `AiProvider` import to this factory. The
|
|
34
|
+
* generated class implements `name`, `displayName`, `isLocal`,
|
|
35
|
+
* `supportsBrowser`, and `taskTypes` from the metadata literal; the
|
|
36
|
+
* constructor is inherited unchanged from the base.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createCloudProviderClass<TModelConfig extends ModelConfig, T extends readonly string[]>(Base: AiProviderCtor<TModelConfig>, meta: CloudProviderMetadata<T>): new (tasks?: Record<string, AiProviderRunFn<any, any, TModelConfig>>, streamTasks?: Record<string, AiProviderStreamFn<any, any, TModelConfig>>, previewTasks?: Record<string, AiProviderPreviewRunFn<any, any, TModelConfig>>) => AiProvider<TModelConfig> & {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly displayName: string;
|
|
41
|
+
readonly isLocal: boolean;
|
|
42
|
+
readonly supportsBrowser: boolean;
|
|
43
|
+
readonly taskTypes: T;
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=BaseCloudProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseCloudProvider.d.ts","sourceRoot":"","sources":["../../src/provider-utils/BaseCloudProvider.ts"],"names":[],"mappings":"A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,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,EAE/D,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,EAExE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,KAC1E,UAAU,CAAC,YAAY,CAAC,GAAG;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;CACvB,CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Shared cloud-provider client utilities: API-key resolution and lazy SDK
|
|
8
|
+
* loading. Used by each provider's `*_Client.ts` so the same fallback chain
|
|
9
|
+
* (provider_config → env var) and the same "package missing" error message
|
|
10
|
+
* live in one place.
|
|
11
|
+
*/
|
|
12
|
+
export interface CloudCredentialConfig {
|
|
13
|
+
readonly credential_key?: string;
|
|
14
|
+
readonly api_key?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ResolveApiKeyArgs {
|
|
17
|
+
readonly config: CloudCredentialConfig | undefined;
|
|
18
|
+
/** Single env var name, or list of alternatives tried in order. */
|
|
19
|
+
readonly envVar: string | readonly string[];
|
|
20
|
+
/** Human-friendly provider label used in the error message. */
|
|
21
|
+
readonly providerLabel: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the API key for a cloud provider.
|
|
25
|
+
*
|
|
26
|
+
* Looks at `config.credential_key`, then `config.api_key`, then each entry in
|
|
27
|
+
* `envVar` (in order). Throws a uniform error if nothing is found.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveApiKey(args: ResolveApiKeyArgs): string;
|
|
30
|
+
/**
|
|
31
|
+
* Dynamically import a provider SDK package, throwing a uniform install hint
|
|
32
|
+
* if the package isn't present.
|
|
33
|
+
*/
|
|
34
|
+
export declare function loadProviderSdk<T = unknown>(packageName: string, friendlyName?: string): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* True when running inside a browser-like environment (window/worker globals
|
|
37
|
+
* present). Cloud SDKs use this to set their `dangerouslyAllowBrowser` flag.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isBrowserLike(): boolean;
|
|
40
|
+
//# sourceMappingURL=CloudProviderClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudProviderClient.d.ts","sourceRoot":"","sources":["../../src/provider-utils/CloudProviderClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,GAAG,SAAS,CAAC;IACnD,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAC5C,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAgB7D;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,CAAC,GAAG,OAAO,EAC/C,WAAW,EAAE,MAAM,EACnB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,CAAC,CAAC,CASZ;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { ModelSearchResultItem } from "../task/ModelSearchTask";
|
|
7
|
+
export interface HfModelEntry {
|
|
8
|
+
id: string;
|
|
9
|
+
modelId: string;
|
|
10
|
+
pipeline_tag?: string;
|
|
11
|
+
library_name?: string;
|
|
12
|
+
likes: number;
|
|
13
|
+
downloads: number;
|
|
14
|
+
tags?: string[];
|
|
15
|
+
siblings?: Array<{
|
|
16
|
+
rfilename: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export declare function formatDownloads(n: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Map an HF model entry to a provider-specific config object.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mapHfProviderConfig(entry: HfModelEntry, provider: string): Record<string, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Map an HF model entry to a ModelSearchResultItem.
|
|
26
|
+
*/
|
|
27
|
+
export declare function mapHfModelResult(entry: HfModelEntry, provider: string): ModelSearchResultItem;
|
|
28
|
+
/**
|
|
29
|
+
* Search HuggingFace models API. Returns all results (limit=500, no pagination).
|
|
30
|
+
* An empty `query` lists top models by sort order (no text filter).
|
|
31
|
+
*/
|
|
32
|
+
export declare function searchHfModels(query: string, extraParams?: Record<string, string>, expandFields?: string[], signal?: AbortSignal, credentialKey?: string): Promise<HfModelEntry[]>;
|
|
33
|
+
//# sourceMappingURL=HfModelSearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HfModelSearch.d.ts","sourceRoot":"","sources":["../../src/provider-utils/HfModelSearch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGrE,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzC;AAID,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,CAmB7F;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,YAAY,CAAC,EAAE,MAAM,EAAE,EACvB,MAAM,CAAC,EAAE,WAAW,EACpB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,YAAY,EAAE,CAAC,CAoBzB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolCallingTaskOutput } from "../task/ToolCallingTask";
|
|
7
|
+
import type { ToolCalls, ToolDefinition } from "../task/ToolCallingUtils";
|
|
8
|
+
import type { StreamEvent } from "@workglow/task-graph";
|
|
9
|
+
/**
|
|
10
|
+
* Shared helpers for providers that expose an OpenAI-compatible chat-completions
|
|
11
|
+
* API (currently OpenAI itself and Hugging Face Inference). They cover:
|
|
12
|
+
*
|
|
13
|
+
* - Building the OpenAI `tools` array from workglow {@link ToolDefinition}s.
|
|
14
|
+
* - Mapping workglow `toolChoice` strings to the OpenAI union, with optional
|
|
15
|
+
* named-function support (HFI accepts only `auto | none | required`).
|
|
16
|
+
* - Streaming a chat-completions response into workglow {@link StreamEvent}s,
|
|
17
|
+
* accumulating fragmented tool-call argument JSON internally and yielding
|
|
18
|
+
* `text-delta` + per-tool-call `object-delta` events. The final `finish`
|
|
19
|
+
* event carries `{}` per the streaming convention in CLAUDE.md — the
|
|
20
|
+
* consumer (`StreamProcessor`) is responsible for accumulating deltas.
|
|
21
|
+
*/
|
|
22
|
+
/** OpenAI-shape tool entry. Kept loose because each SDK names the type differently. */
|
|
23
|
+
export interface OpenAIShapedTool {
|
|
24
|
+
readonly type: "function";
|
|
25
|
+
readonly function: {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly description: string;
|
|
28
|
+
readonly parameters: any;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export type OpenAIShapedToolChoice = "auto" | "none" | "required" | {
|
|
32
|
+
readonly type: "function";
|
|
33
|
+
readonly function: {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare function buildOpenAITools(tools: readonly ToolDefinition[]): OpenAIShapedTool[];
|
|
38
|
+
/**
|
|
39
|
+
* Map workglow `toolChoice` to an OpenAI-shaped tool_choice value.
|
|
40
|
+
*
|
|
41
|
+
* @param toolChoice - One of `"auto" | "none" | "required" | <tool_name>` (or undefined).
|
|
42
|
+
* @param allowNamedFunction - When true, an unrecognized value is treated as a
|
|
43
|
+
* tool name and emitted as `{ type: "function", function: { name } }`. When
|
|
44
|
+
* false (HFI), it falls back to `"auto"` because HFI's API only accepts the
|
|
45
|
+
* three keywords.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mapOpenAIToolChoice(toolChoice: string | undefined, allowNamedFunction: boolean): OpenAIShapedToolChoice;
|
|
48
|
+
/**
|
|
49
|
+
* Parse a non-streaming OpenAI-shape chat completion message into workglow
|
|
50
|
+
* {@link ToolCalls}. Used by the synchronous `*_ToolCalling` runFns.
|
|
51
|
+
*
|
|
52
|
+
* Some providers (HFI) don't always return an `id` per tool call; we
|
|
53
|
+
* auto-generate `call_<index>` in that case.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseOpenAIToolCallMessage(toolCallsRaw: readonly any[] | undefined): ToolCalls;
|
|
56
|
+
/**
|
|
57
|
+
* Adapt an OpenAI-shape streaming response (each chunk has
|
|
58
|
+
* `choices[0].delta.{content?, tool_calls?[]}`) to workglow stream events.
|
|
59
|
+
*
|
|
60
|
+
* Yields:
|
|
61
|
+
* - `text-delta` for each non-empty `delta.content`.
|
|
62
|
+
* - `object-delta` (single-element array) per tool-call delta with the latest
|
|
63
|
+
* parsed input. The downstream `StreamProcessor` upserts by `id`.
|
|
64
|
+
* - `finish` with structural defaults (`{ text: "", toolCalls: [] }`) once the
|
|
65
|
+
* stream ends. The defaults are minimal scaffolding so the final output
|
|
66
|
+
* always satisfies {@link ToolCallingTaskOutput} even when the model
|
|
67
|
+
* streams only `tool_calls` (no `content` deltas) — the consumer's
|
|
68
|
+
* `StreamProcessor` overrides any port for which deltas were accumulated.
|
|
69
|
+
*/
|
|
70
|
+
export declare function accumulateOpenAIStream(stream: AsyncIterable<any>): AsyncGenerator<StreamEvent<ToolCallingTaskOutput>, void, unknown>;
|
|
71
|
+
//# sourceMappingURL=OpenAIShapedChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAIShapedChat.d.ts","sourceRoot":"","sources":["../../src/provider-utils/OpenAIShapedChat.ts"],"names":[],"mappings":"AAAA;;;;GAIG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
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/** Convert an app task type to its primary HuggingFace pipeline name. */
|
|
7
|
+
export declare function taskTypeToPipeline(taskType: string): string | undefined;
|
|
8
|
+
/** Convert an app task type to all matching HuggingFace pipeline names. */
|
|
9
|
+
export declare function taskTypeToPipelines(taskType: string): string[];
|
|
10
|
+
/** Reverse lookup: given a HuggingFace pipeline name, return all matching app task types. */
|
|
11
|
+
export declare function pipelineToTaskTypes(pipeline: string): string[];
|
|
12
|
+
//# sourceMappingURL=PipelineTaskMapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PipelineTaskMapping.d.ts","sourceRoot":"","sources":["../../src/provider-utils/PipelineTaskMapping.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4BH,yEAAyE;AACzE,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEvE;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9D;AAED,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAI9D"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolCallingTaskInput } from "../task/ToolCallingTask";
|
|
7
|
+
import type { ToolCalls } from "../task/ToolCallingUtils";
|
|
8
|
+
export interface ToolCall {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly arguments: Record<string, unknown>;
|
|
11
|
+
readonly id: string | null;
|
|
12
|
+
}
|
|
13
|
+
export interface ToolCallParserResult {
|
|
14
|
+
readonly tool_calls: ReadonlyArray<ToolCall>;
|
|
15
|
+
readonly content: string;
|
|
16
|
+
readonly parser: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ParseToolCallsOptions {
|
|
19
|
+
readonly tokenizer?: TokenizerLike | null;
|
|
20
|
+
readonly model?: string | null;
|
|
21
|
+
readonly parser?: string | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Minimal tokenizer shape used for model-family detection.
|
|
25
|
+
* Compatible with `PreTrainedTokenizer` from `@huggingface/transformers`.
|
|
26
|
+
*/
|
|
27
|
+
export interface TokenizerLike {
|
|
28
|
+
readonly config?: {
|
|
29
|
+
readonly name_or_path?: string;
|
|
30
|
+
readonly _name_or_path?: string;
|
|
31
|
+
readonly model_type?: string;
|
|
32
|
+
};
|
|
33
|
+
readonly name_or_path?: string;
|
|
34
|
+
}
|
|
35
|
+
export type ParserFn = (text: string) => ToolCallParserResult | null;
|
|
36
|
+
/**
|
|
37
|
+
* Strip thinking blocks (`<think>...</think>`) and HFT special tokens
|
|
38
|
+
* (`<|im_end|>`, `<|end_of_turn|>`, etc.) from model output.
|
|
39
|
+
* Used to clean up content text returned alongside tool calls.
|
|
40
|
+
*/
|
|
41
|
+
export declare function stripModelArtifacts(text: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Extract text from a content block that may be a string, array of content
|
|
44
|
+
* blocks, or other structure.
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractMessageText(content: unknown): string;
|
|
47
|
+
export declare function makeToolCall(name: string, args: Record<string, unknown>, id?: string | null): ToolCall;
|
|
48
|
+
export declare function tryParseJson(text: string): unknown | undefined;
|
|
49
|
+
export declare function parseJsonToolCallArray(jsonStr: string, nameKey?: string, argsKeys?: ReadonlyArray<string>): ReadonlyArray<ToolCall> | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Parse key=value argument syntax used by Gorilla, NexusRaven, and Gemma.
|
|
52
|
+
* Handles quoted strings (`"val"`, `'val'`) and bare values.
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseKeyValueArgs(argsStr: string): Record<string, unknown>;
|
|
55
|
+
export declare function coerceArgValue(value: string): unknown;
|
|
56
|
+
export declare function toolChoiceForcesToolCall(toolChoice: ToolCallingTaskInput["toolChoice"]): boolean;
|
|
57
|
+
export declare function forcedToolSelection(input: ToolCallingTaskInput): string | undefined;
|
|
58
|
+
export declare function resolveParsedToolName(name: string, input: ToolCallingTaskInput): string;
|
|
59
|
+
/**
|
|
60
|
+
* Convert a low-level parser result to the workglow `ToolCalls` type.
|
|
61
|
+
* When `input` is provided, tool names are resolved against the available
|
|
62
|
+
* tools list (and forced selection is applied for unrecognized names).
|
|
63
|
+
*/
|
|
64
|
+
export declare function adaptParserResult(result: ToolCallParserResult, input?: ToolCallingTaskInput): {
|
|
65
|
+
text: string;
|
|
66
|
+
toolCalls: ToolCalls;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Llama 3.1/3.2/3.3 (Meta)
|
|
70
|
+
*
|
|
71
|
+
* Formats:
|
|
72
|
+
* - `<|python_tag|>{"name": "func", "parameters": {"arg": "val"}}`
|
|
73
|
+
* - `<function=func>{"arg": "val"}</function>` (3.2 lightweight 1B/3B)
|
|
74
|
+
* - `{"name": "func", "parameters": {...}}` (bare JSON)
|
|
75
|
+
*/
|
|
76
|
+
export declare const parseLlama: ParserFn;
|
|
77
|
+
/**
|
|
78
|
+
* Mistral / Mixtral (Mistral AI)
|
|
79
|
+
*
|
|
80
|
+
* Format: `[TOOL_CALLS] [{"name": "func", "arguments": {...}, "id": "9charID"}]`
|
|
81
|
+
*/
|
|
82
|
+
export declare const parseMistral: ParserFn;
|
|
83
|
+
/**
|
|
84
|
+
* Hermes (NousResearch) — also used by Qwen 2.5, Qwen 3, SOLAR, and others
|
|
85
|
+
*
|
|
86
|
+
* Format: `<tool_call>\n{"name": "func", "arguments": {...}}\n</tool_call>`
|
|
87
|
+
*/
|
|
88
|
+
export declare const parseHermes: ParserFn;
|
|
89
|
+
/**
|
|
90
|
+
* Cohere Command-R / Command-R+
|
|
91
|
+
*
|
|
92
|
+
* Formats:
|
|
93
|
+
* - `Action: ```json\n[{"tool_name": "func", "parameters": {...}}]\n````
|
|
94
|
+
* - `Action: [{"tool_name": ..., "parameters": ...}]`
|
|
95
|
+
*/
|
|
96
|
+
export declare const parseCohere: ParserFn;
|
|
97
|
+
/**
|
|
98
|
+
* DeepSeek V2/V3/V3.1
|
|
99
|
+
*
|
|
100
|
+
* V2 format: `<|tool▁call▁begin|>function_name\n```json\n{...}\n```<|tool▁call▁end|>`
|
|
101
|
+
* V3.1 format: `<|tool▁calls▁begin|><|tool▁call▁begin|>name<|tool▁sep|>{args}<|tool▁call▁end|><|tool▁calls▁end|>`
|
|
102
|
+
*/
|
|
103
|
+
export declare const parseDeepSeek: ParserFn;
|
|
104
|
+
/**
|
|
105
|
+
* Phi-4 / Phi-4-mini (Microsoft)
|
|
106
|
+
*
|
|
107
|
+
* Format: `<|tool_calls|>[{"name": "func", "arguments": {...}}]<|/tool_calls|>`
|
|
108
|
+
*/
|
|
109
|
+
export declare const parsePhi: ParserFn;
|
|
110
|
+
/**
|
|
111
|
+
* Phi-3 functools format (legacy)
|
|
112
|
+
*
|
|
113
|
+
* Format: `functools[{"name": "func", "arguments": {...}}]`
|
|
114
|
+
*/
|
|
115
|
+
export declare const parsePhiFunctools: ParserFn;
|
|
116
|
+
/**
|
|
117
|
+
* InternLM 2 / 2.5 (Shanghai AI Lab)
|
|
118
|
+
*
|
|
119
|
+
* Format: `<|action_start|><|plugin|>\n{"name": "func", "parameters": {...}}<|action_end|>`
|
|
120
|
+
*/
|
|
121
|
+
export declare const parseInternLM: ParserFn;
|
|
122
|
+
/**
|
|
123
|
+
* ChatGLM / GLM-4 (Zhipu AI)
|
|
124
|
+
*
|
|
125
|
+
* Format: function name followed by newline and JSON arguments.
|
|
126
|
+
* `func_name\n{"arg": "val"}`
|
|
127
|
+
*/
|
|
128
|
+
export declare const parseChatGLM: ParserFn;
|
|
129
|
+
/**
|
|
130
|
+
* Functionary (MeetKai)
|
|
131
|
+
*
|
|
132
|
+
* Format: `>>>func_name\n{"arg": "val"}`
|
|
133
|
+
* Uses `all` as a special function name for regular text.
|
|
134
|
+
*/
|
|
135
|
+
export declare const parseFunctionary: ParserFn;
|
|
136
|
+
/**
|
|
137
|
+
* Gorilla (Berkeley)
|
|
138
|
+
*
|
|
139
|
+
* Format: `<<function>>func_name(arg1="val1", arg2=val2)`
|
|
140
|
+
*/
|
|
141
|
+
export declare const parseGorilla: ParserFn;
|
|
142
|
+
/**
|
|
143
|
+
* NexusRaven (Nexusflow)
|
|
144
|
+
*
|
|
145
|
+
* Format: `Call: func_name(arg1="val1", arg2=val2)\nThought: reasoning...`
|
|
146
|
+
*/
|
|
147
|
+
export declare const parseNexusRaven: ParserFn;
|
|
148
|
+
/**
|
|
149
|
+
* xLAM (Salesforce)
|
|
150
|
+
*
|
|
151
|
+
* Format: Raw JSON array of tool calls: `[{"name": "func", "arguments": {...}}]`
|
|
152
|
+
* May be wrapped in ```json code blocks.
|
|
153
|
+
*/
|
|
154
|
+
export declare const parseXLAM: ParserFn;
|
|
155
|
+
/**
|
|
156
|
+
* FireFunction (Fireworks AI)
|
|
157
|
+
*
|
|
158
|
+
* Format: `{"tool_calls": [{"function": {"name": "...", "arguments": "..."}}]}`
|
|
159
|
+
*/
|
|
160
|
+
export declare const parseFireFunction: ParserFn;
|
|
161
|
+
/**
|
|
162
|
+
* Granite (IBM)
|
|
163
|
+
*
|
|
164
|
+
* Format: `<|tool_call|>{"name": "func", "arguments": {...}}<|/tool_call|>` or `<|end_of_text|>`
|
|
165
|
+
*/
|
|
166
|
+
export declare const parseGranite: ParserFn;
|
|
167
|
+
/**
|
|
168
|
+
* Gemma 2/3 (Google) — prompt-based, no dedicated tokens
|
|
169
|
+
*
|
|
170
|
+
* Formats:
|
|
171
|
+
* - ```tool_code\nfunc(arg=val)\n```
|
|
172
|
+
* - `{"name": "func", "parameters": {...}}`
|
|
173
|
+
*/
|
|
174
|
+
export declare const parseGemma: ParserFn;
|
|
175
|
+
/**
|
|
176
|
+
* LiquidAI LFM / LFM2 / LFM2.5
|
|
177
|
+
*
|
|
178
|
+
* Formats:
|
|
179
|
+
* - `<|tool_call_start|>[func_name(key="value", key2=123)]<|tool_call_end|>`
|
|
180
|
+
* - `[func_name(params={"key": "val"})]` (bracket-only, no special tokens)
|
|
181
|
+
* Parallel calls: `<|tool_call_start|>[func1(a="b"), func2(c="d")]<|tool_call_end|>`
|
|
182
|
+
* Uses Pythonic function call syntax.
|
|
183
|
+
*/
|
|
184
|
+
export declare const parseLiquid: ParserFn;
|
|
185
|
+
/**
|
|
186
|
+
* Jamba (AI21)
|
|
187
|
+
*
|
|
188
|
+
* Format: `<tool_calls>[{"name": "func", "arguments": {...}}]</tool_calls>`
|
|
189
|
+
* Also supports OpenAI-compatible format via FireFunction fallback.
|
|
190
|
+
*/
|
|
191
|
+
export declare const parseJamba: ParserFn;
|
|
192
|
+
/**
|
|
193
|
+
* Qwen 3.5 XML format
|
|
194
|
+
*
|
|
195
|
+
* Format:
|
|
196
|
+
* ```
|
|
197
|
+
* <tool_call>
|
|
198
|
+
* <function=function_name>
|
|
199
|
+
* <parameter=param_name>value</parameter>
|
|
200
|
+
* ...
|
|
201
|
+
* </function>
|
|
202
|
+
* </tool_call>
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* The special `params` parameter may contain a JSON object to be spread
|
|
206
|
+
* into the arguments.
|
|
207
|
+
*/
|
|
208
|
+
export declare const parseQwen35Xml: ParserFn;
|
|
209
|
+
/**
|
|
210
|
+
* Parse tool calls from LLM output text.
|
|
211
|
+
*
|
|
212
|
+
* Automatically detects the model family from the tokenizer and applies the
|
|
213
|
+
* appropriate parser(s). Falls back to trying all known formats if the model
|
|
214
|
+
* family cannot be determined.
|
|
215
|
+
*/
|
|
216
|
+
export declare function parseToolCalls(text: string, { tokenizer, model, parser }?: ParseToolCallsOptions): ToolCallParserResult;
|
|
217
|
+
/**
|
|
218
|
+
* Check if text likely contains tool calls without fully parsing them.
|
|
219
|
+
* Faster than `parseToolCalls` when you only need presence detection.
|
|
220
|
+
*/
|
|
221
|
+
export declare function hasToolCalls(text: string): boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Get the list of available parser names.
|
|
224
|
+
*/
|
|
225
|
+
export declare function getAvailableParsers(): ReadonlyArray<string>;
|
|
226
|
+
/**
|
|
227
|
+
* Get a model-family-specific generation prefix that guides the model to
|
|
228
|
+
* produce tool calls. Appended to the prompt before generation and prepended
|
|
229
|
+
* to the decoded output before parsing.
|
|
230
|
+
*
|
|
231
|
+
* @param family - The detected model family (from `getAvailableParsers` / `detectModelFamily`).
|
|
232
|
+
* @param forcedToolName - When a specific tool is forced, include its name in the prefix.
|
|
233
|
+
* @returns The prefix string, or `undefined` if no prefix is needed.
|
|
234
|
+
*/
|
|
235
|
+
export declare function getGenerationPrefix(family: string | null, _forcedToolName: string | undefined): string | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* Parse tool calls from model-generated text, returning the workglow `ToolCalls`
|
|
238
|
+
* type directly (with `input` field instead of `arguments`).
|
|
239
|
+
*
|
|
240
|
+
* Tries, in order:
|
|
241
|
+
* 1. `<tool_call>JSON</tool_call>` tags (Qwen/Hermes)
|
|
242
|
+
* 2. Bare JSON objects with `name` + `arguments`/`parameters` keys
|
|
243
|
+
* 3. `{"function": {"name": ..., "arguments": ...}}` format
|
|
244
|
+
*
|
|
245
|
+
* Returns both the cleaned text (with tool-call markup removed) and the parsed
|
|
246
|
+
* ToolCall array.
|
|
247
|
+
*/
|
|
248
|
+
export declare function parseToolCallsFromText(responseText: string): {
|
|
249
|
+
text: string;
|
|
250
|
+
toolCalls: ToolCalls;
|
|
251
|
+
};
|
|
252
|
+
//# sourceMappingURL=ToolCallParsers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallParsers.d.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MAAM,GAAG,OAAO,CAoBlD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAAC,MAAM,CAAC,CAE3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,eAAe,EAAE,MAAM,GAAG,SAAS,GAClC,MAAM,GAAG,SAAS,CAOpB;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;CACtB,CAmEA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Shared helpers for AI provider run/stream functions that produce image
|
|
8
|
+
* outputs. Each helper takes a wire form delivered by a provider SDK
|
|
9
|
+
* (encoded PNG/JPEG bytes, a base64 data URI, or a Blob) and returns a
|
|
10
|
+
* platform-appropriate {@link ImageValue}:
|
|
11
|
+
*
|
|
12
|
+
* - Node / Bun: a {@link NodeImageValue} wrapping the encoded bytes plus
|
|
13
|
+
* dimensions read from a sharp metadata probe. The encoded buffer is
|
|
14
|
+
* retained as-is — no decode/re-encode round trip.
|
|
15
|
+
* - Browser: a {@link BrowserImageValue} wrapping an `ImageBitmap`
|
|
16
|
+
* created via `createImageBitmap(blob)`.
|
|
17
|
+
*
|
|
18
|
+
* Provider responses are always either PNG or JPEG. WebP and other formats
|
|
19
|
+
* are not produced by the supported endpoints and would need explicit
|
|
20
|
+
* mime detection if added later.
|
|
21
|
+
*/
|
|
22
|
+
import type { ImageValue, NodeImageFormat } from "@workglow/util/media";
|
|
23
|
+
/**
|
|
24
|
+
* Wrap an encoded image buffer in a Node {@link ImageValue}. Reads
|
|
25
|
+
* width/height via a sharp metadata probe; no pixel decode is performed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function pngBytesToImageValue(bytes: Uint8Array, format?: NodeImageFormat): Promise<ImageValue>;
|
|
28
|
+
/**
|
|
29
|
+
* Decode a `data:<mime>;base64,...` URI into an {@link ImageValue}.
|
|
30
|
+
* On node, retains the encoded bytes via {@link pngBytesToImageValue}. In a
|
|
31
|
+
* browser environment, decodes via `createImageBitmap` instead.
|
|
32
|
+
*/
|
|
33
|
+
export declare function dataUriToImageValue(dataUri: string): Promise<ImageValue>;
|
|
34
|
+
/**
|
|
35
|
+
* Convert a `Blob` (e.g. from the HF Inference SDK) into an
|
|
36
|
+
* {@link ImageValue}. On node uses sharp metadata to size the wrapper; in
|
|
37
|
+
* a browser uses `createImageBitmap` directly.
|
|
38
|
+
*/
|
|
39
|
+
export declare function blobToImageValue(blob: Blob): Promise<ImageValue>;
|
|
40
|
+
/**
|
|
41
|
+
* Encode an inbound provider-input image into PNG bytes suitable for upload.
|
|
42
|
+
*
|
|
43
|
+
* Accepts the wire forms an `ImageValue` port may carry into a worker:
|
|
44
|
+
* - {@link NodeImageValue} — encodes via sharp (raw-rgba) or returns bytes
|
|
45
|
+
* directly if already PNG/JPEG.
|
|
46
|
+
* - {@link BrowserImageValue} — encodes via canvas/`OffscreenCanvas`.
|
|
47
|
+
* - `data:` URI string — legacy materialization form; base64-decodes the
|
|
48
|
+
* payload.
|
|
49
|
+
*
|
|
50
|
+
* Always returns PNG bytes. Callers wrap the result in whatever transport
|
|
51
|
+
* shape the SDK expects (Blob, File, OpenAI.toFile, inlineData Part).
|
|
52
|
+
*/
|
|
53
|
+
export declare function imageValueToPngBytes(image: unknown): Promise<Uint8Array>;
|
|
54
|
+
/**
|
|
55
|
+
* Encode an inbound provider-input image into a PNG `Blob` suitable for SDKs
|
|
56
|
+
* that accept Blob/File-shaped inputs (e.g. HuggingFace Transformers.js
|
|
57
|
+
* pipelines). Thin wrapper around {@link imageValueToPngBytes}.
|
|
58
|
+
*/
|
|
59
|
+
export declare function imageValueToBlob(image: unknown): Promise<Blob>;
|
|
60
|
+
//# sourceMappingURL=imageOutputHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageOutputHelpers.d.ts","sourceRoot":"","sources":["../../src/provider-utils/imageOutputHelpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAqBxE;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,UAAU,EACjB,MAAM,GAAE,eAAuB,GAC9B,OAAO,CAAC,UAAU,CAAC,CAOrB;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAwB9E;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAWtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CA4D9E;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAOpE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { ModelSearchResultItem } from "../task/ModelSearchTask";
|
|
7
|
+
/**
|
|
8
|
+
* Normalized search string for model search, or undefined when absent or whitespace-only.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizedModelSearchQuery(query: string | undefined): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Filter static/SDK model rows by optional query (substring match on label, value, or description).
|
|
13
|
+
*/
|
|
14
|
+
export declare function filterLabeledModelsByQuery<T extends {
|
|
15
|
+
label: string;
|
|
16
|
+
value: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
}>(models: ReadonlyArray<T>, query: string | undefined): T[];
|
|
19
|
+
/**
|
|
20
|
+
* Filter {@link ModelSearchResultItem} rows by optional query.
|
|
21
|
+
*/
|
|
22
|
+
export declare function filterModelSearchResultsByQuery(results: ModelSearchResultItem[], query: string | undefined): ModelSearchResultItem[];
|
|
23
|
+
//# sourceMappingURL=modelSearchQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelSearchQuery.d.ts","sourceRoot":"","sources":["../../src/provider-utils/modelSearchQuery.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGxF;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,EAChE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC,EAAE,CAS1D;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,qBAAqB,EAAE,EAChC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,qBAAqB,EAAE,CASzB"}
|