@workglow/ai 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/dist/browser.js +1422 -397
- package/dist/browser.js.map +64 -58
- package/dist/bun.js +1422 -397
- package/dist/bun.js.map +64 -58
- package/dist/common.d.ts +1 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/execution/DirectExecutionStrategy.d.ts +1 -1
- package/dist/execution/DirectExecutionStrategy.d.ts.map +1 -1
- package/dist/execution/QueuedExecutionStrategy.d.ts +2 -2
- package/dist/execution/QueuedExecutionStrategy.d.ts.map +1 -1
- package/dist/job/AiJob.d.ts +2 -1
- package/dist/job/AiJob.d.ts.map +1 -1
- package/dist/model/ModelRegistry.d.ts.map +1 -1
- package/dist/model/ModelRepository.d.ts +11 -15
- package/dist/model/ModelRepository.d.ts.map +1 -1
- package/dist/node.js +1422 -397
- package/dist/node.js.map +64 -58
- package/dist/provider/AiProvider.d.ts +2 -2
- package/dist/provider/AiProvider.d.ts.map +1 -1
- package/dist/provider/AiProviderRegistry.d.ts +3 -2
- package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
- package/dist/provider/QueuedAiProvider.d.ts +2 -1
- package/dist/provider/QueuedAiProvider.d.ts.map +1 -1
- package/dist/task/AgentTask.d.ts +525 -0
- package/dist/task/AgentTask.d.ts.map +1 -0
- package/dist/task/AgentTypes.d.ts +183 -0
- package/dist/task/AgentTypes.d.ts.map +1 -0
- package/dist/task/AgentUtils.d.ts +55 -0
- package/dist/task/AgentUtils.d.ts.map +1 -0
- package/dist/task/BackgroundRemovalTask.d.ts +6 -4
- package/dist/task/BackgroundRemovalTask.d.ts.map +1 -1
- package/dist/task/ChunkRetrievalTask.d.ts +6 -4
- package/dist/task/ChunkRetrievalTask.d.ts.map +1 -1
- package/dist/task/ChunkToVectorTask.d.ts +6 -4
- package/dist/task/ChunkToVectorTask.d.ts.map +1 -1
- package/dist/task/ChunkVectorHybridSearchTask.d.ts +6 -4
- package/dist/task/ChunkVectorHybridSearchTask.d.ts.map +1 -1
- package/dist/task/ChunkVectorSearchTask.d.ts +6 -4
- package/dist/task/ChunkVectorSearchTask.d.ts.map +1 -1
- package/dist/task/ChunkVectorUpsertTask.d.ts +6 -4
- package/dist/task/ChunkVectorUpsertTask.d.ts.map +1 -1
- package/dist/task/ContextBuilderTask.d.ts +6 -4
- package/dist/task/ContextBuilderTask.d.ts.map +1 -1
- package/dist/task/CountTokensTask.d.ts +6 -4
- package/dist/task/CountTokensTask.d.ts.map +1 -1
- package/dist/task/DocumentEnricherTask.d.ts +6 -4
- package/dist/task/DocumentEnricherTask.d.ts.map +1 -1
- package/dist/task/DownloadModelTask.d.ts +7 -5
- package/dist/task/DownloadModelTask.d.ts.map +1 -1
- package/dist/task/FaceDetectorTask.d.ts +6 -4
- package/dist/task/FaceDetectorTask.d.ts.map +1 -1
- package/dist/task/FaceLandmarkerTask.d.ts +6 -4
- package/dist/task/FaceLandmarkerTask.d.ts.map +1 -1
- package/dist/task/GestureRecognizerTask.d.ts +6 -4
- package/dist/task/GestureRecognizerTask.d.ts.map +1 -1
- package/dist/task/HandLandmarkerTask.d.ts +6 -4
- package/dist/task/HandLandmarkerTask.d.ts.map +1 -1
- package/dist/task/HierarchicalChunkerTask.d.ts +6 -4
- package/dist/task/HierarchicalChunkerTask.d.ts.map +1 -1
- package/dist/task/HierarchyJoinTask.d.ts +6 -4
- package/dist/task/HierarchyJoinTask.d.ts.map +1 -1
- package/dist/task/ImageClassificationTask.d.ts +6 -4
- package/dist/task/ImageClassificationTask.d.ts.map +1 -1
- package/dist/task/ImageEmbeddingTask.d.ts +6 -4
- package/dist/task/ImageEmbeddingTask.d.ts.map +1 -1
- package/dist/task/ImageSegmentationTask.d.ts +6 -4
- package/dist/task/ImageSegmentationTask.d.ts.map +1 -1
- package/dist/task/ImageToTextTask.d.ts +6 -4
- package/dist/task/ImageToTextTask.d.ts.map +1 -1
- package/dist/task/MessageConversion.d.ts +52 -0
- package/dist/task/MessageConversion.d.ts.map +1 -0
- package/dist/task/ModelInfoTask.d.ts +7 -5
- package/dist/task/ModelInfoTask.d.ts.map +1 -1
- package/dist/task/ModelSearchTask.d.ts +6 -4
- package/dist/task/ModelSearchTask.d.ts.map +1 -1
- package/dist/task/ObjectDetectionTask.d.ts +6 -4
- package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
- package/dist/task/PoseLandmarkerTask.d.ts +6 -4
- package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
- package/dist/task/QueryExpanderTask.d.ts +6 -4
- package/dist/task/QueryExpanderTask.d.ts.map +1 -1
- package/dist/task/RerankerTask.d.ts +6 -4
- package/dist/task/RerankerTask.d.ts.map +1 -1
- package/dist/task/StructuralParserTask.d.ts +6 -4
- package/dist/task/StructuralParserTask.d.ts.map +1 -1
- package/dist/task/StructuredGenerationTask.d.ts +6 -4
- package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
- package/dist/task/TextChunkerTask.d.ts +6 -4
- package/dist/task/TextChunkerTask.d.ts.map +1 -1
- package/dist/task/TextClassificationTask.d.ts +6 -4
- package/dist/task/TextClassificationTask.d.ts.map +1 -1
- package/dist/task/TextEmbeddingTask.d.ts +6 -4
- package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
- package/dist/task/TextFillMaskTask.d.ts +6 -4
- package/dist/task/TextFillMaskTask.d.ts.map +1 -1
- package/dist/task/TextGenerationTask.d.ts +6 -4
- package/dist/task/TextGenerationTask.d.ts.map +1 -1
- package/dist/task/TextLanguageDetectionTask.d.ts +6 -4
- package/dist/task/TextLanguageDetectionTask.d.ts.map +1 -1
- package/dist/task/TextNamedEntityRecognitionTask.d.ts +6 -4
- package/dist/task/TextNamedEntityRecognitionTask.d.ts.map +1 -1
- package/dist/task/TextQuestionAnswerTask.d.ts +6 -4
- package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
- package/dist/task/TextRewriterTask.d.ts +6 -4
- package/dist/task/TextRewriterTask.d.ts.map +1 -1
- package/dist/task/TextSummaryTask.d.ts +6 -4
- package/dist/task/TextSummaryTask.d.ts.map +1 -1
- package/dist/task/TextTranslationTask.d.ts +6 -4
- package/dist/task/TextTranslationTask.d.ts.map +1 -1
- package/dist/task/ToolCallingTask.d.ts +348 -0
- package/dist/task/ToolCallingTask.d.ts.map +1 -0
- package/dist/task/ToolCallingUtils.d.ts +75 -0
- package/dist/task/ToolCallingUtils.d.ts.map +1 -0
- package/dist/task/TopicSegmenterTask.d.ts +6 -4
- package/dist/task/TopicSegmenterTask.d.ts.map +1 -1
- package/dist/task/UnloadModelTask.d.ts +6 -4
- package/dist/task/UnloadModelTask.d.ts.map +1 -1
- package/dist/task/VectorQuantizeTask.d.ts +6 -4
- package/dist/task/VectorQuantizeTask.d.ts.map +1 -1
- package/dist/task/VectorSimilarityTask.d.ts +6 -4
- package/dist/task/VectorSimilarityTask.d.ts.map +1 -1
- package/dist/task/base/AiTask.d.ts +8 -5
- package/dist/task/base/AiTask.d.ts.map +1 -1
- package/dist/task/base/AiVisionTask.d.ts +3 -7
- package/dist/task/base/AiVisionTask.d.ts.map +1 -1
- package/dist/task/base/StreamingAiTask.d.ts +4 -7
- package/dist/task/base/StreamingAiTask.d.ts.map +1 -1
- package/dist/task/index.d.ts +9 -1
- package/dist/task/index.d.ts.map +1 -1
- package/dist/worker.d.ts +2 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +247 -25
- package/dist/worker.js.map +9 -7
- package/package.json +16 -11
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
* provider-registered strategy (direct or queued).
|
|
9
9
|
*/
|
|
10
10
|
import { Job } from "@workglow/job-queue";
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
11
|
+
import type { IExecuteContext, IExecuteReactiveContext, TaskConfig, TaskEntitlements, TaskOutput } from "@workglow/task-graph";
|
|
12
|
+
import { Task, TaskInput } from "@workglow/task-graph";
|
|
13
13
|
import type { ServiceRegistry } from "@workglow/util";
|
|
14
|
+
import type { DataPortSchema } from "@workglow/util/schema";
|
|
14
15
|
import { AiJobInput } from "../../job/AiJob";
|
|
15
16
|
import type { ModelConfig } from "../../model/ModelSchema";
|
|
16
|
-
export
|
|
17
|
-
export interface AiSingleTaskInput extends TaskInput {
|
|
17
|
+
export interface AiTaskInput extends TaskInput {
|
|
18
18
|
model: string | ModelConfig;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -24,8 +24,11 @@ export interface AiSingleTaskInput extends TaskInput {
|
|
|
24
24
|
* Model resolution is handled automatically by the TaskRunner before execution.
|
|
25
25
|
* By the time execute() is called, input.model is always a ModelConfig object.
|
|
26
26
|
*/
|
|
27
|
-
export declare class AiTask<Input extends
|
|
27
|
+
export declare class AiTask<Input extends AiTaskInput = AiTaskInput, Output extends TaskOutput = TaskOutput, Config extends TaskConfig<Input> = TaskConfig<Input>> extends Task<Input, Output, Config> {
|
|
28
28
|
static type: string;
|
|
29
|
+
static hasDynamicEntitlements: boolean;
|
|
30
|
+
static entitlements(): TaskEntitlements;
|
|
31
|
+
entitlements(): TaskEntitlements;
|
|
29
32
|
static configSchema(): DataPortSchema;
|
|
30
33
|
execute(input: Input, executeContext: IExecuteContext): Promise<Output | undefined>;
|
|
31
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiTask.d.ts","sourceRoot":"","sources":["../../../src/task/base/AiTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"AiTask.d.ts","sourceRoot":"","sources":["../../../src/task/base/AiTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,UAAU,EAEV,gBAAgB,EAChB,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;;OAEG;IACH,UAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAG7E;IAMD;;;OAGG;IACY,eAAe,CAC5B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAa7B;IAMD;;OAEG;IACmB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CA+ClE;IAEqB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,CAqCzF;CACF"}
|
|
@@ -3,18 +3,14 @@
|
|
|
3
3
|
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import type { TaskConfig, TaskOutput } from "@workglow/task-graph";
|
|
7
7
|
import { AiJobInput } from "../../job/AiJob";
|
|
8
|
-
import
|
|
9
|
-
import { AiTask, type AiTaskConfig } from "./AiTask";
|
|
10
|
-
export interface AiVisionTaskSingleInput extends TaskInput {
|
|
11
|
-
model: string | ModelConfig;
|
|
12
|
-
}
|
|
8
|
+
import { AiTask, AiTaskInput } from "./AiTask";
|
|
13
9
|
/**
|
|
14
10
|
* A base class for AI vision tasks.
|
|
15
11
|
* Handles image format conversion based on the target provider's capabilities.
|
|
16
12
|
*/
|
|
17
|
-
export declare class AiVisionTask<Input extends
|
|
13
|
+
export declare class AiVisionTask<Input extends AiTaskInput = AiTaskInput, Output extends TaskOutput = TaskOutput, Config extends TaskConfig<Input> = TaskConfig<Input>> extends AiTask<Input, Output, Config> {
|
|
18
14
|
static type: string;
|
|
19
15
|
/**
|
|
20
16
|
* Get the input to submit for execution.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiVisionTask.d.ts","sourceRoot":"","sources":["../../../src/task/base/AiVisionTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"AiVisionTask.d.ts","sourceRoot":"","sources":["../../../src/task/base/AiVisionTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE/C;;;GAGG;AACH,qBAAa,YAAY,CACvB,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,MAAM,SAAS,UAAU,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CACpD,SAAQ,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;IACrC,OAAuB,IAAI,EAAE,MAAM,CAAkB;IAErD;;;OAGG;IACH,UAAyB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAoC7E;CACF"}
|
|
@@ -3,12 +3,9 @@
|
|
|
3
3
|
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
import { type IExecuteContext, type StreamEvent, type TaskOutput } from "@workglow/task-graph";
|
|
11
|
-
import { AiSingleTaskInput, AiTask, type AiTaskConfig } from "./AiTask";
|
|
6
|
+
import type { TaskConfig, IExecuteContext, StreamEvent, TaskOutput } from "@workglow/task-graph";
|
|
7
|
+
import { AiTask } from "./AiTask";
|
|
8
|
+
import type { AiTaskInput } from "./AiTask";
|
|
12
9
|
/**
|
|
13
10
|
* A base class for streaming AI tasks.
|
|
14
11
|
* Extends AiTask to provide streaming output via executeStream().
|
|
@@ -25,7 +22,7 @@ import { AiSingleTaskInput, AiTask, type AiTaskConfig } from "./AiTask";
|
|
|
25
22
|
* This class wraps text-delta events with the correct port from the task's
|
|
26
23
|
* output schema before they reach the TaskRunner.
|
|
27
24
|
*/
|
|
28
|
-
export declare class StreamingAiTask<Input extends
|
|
25
|
+
export declare class StreamingAiTask<Input extends AiTaskInput = AiTaskInput, Output extends TaskOutput = TaskOutput, Config extends TaskConfig<Input> = TaskConfig<Input>> extends AiTask<Input, Output, Config> {
|
|
29
26
|
static type: string;
|
|
30
27
|
/**
|
|
31
28
|
* Streaming execution: resolves the provider strategy and yields StreamEvents from it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StreamingAiTask.d.ts","sourceRoot":"","sources":["../../../src/task/base/StreamingAiTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"StreamingAiTask.d.ts","sourceRoot":"","sources":["../../../src/task/base/StreamingAiTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEjG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,eAAe,CAC1B,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,MAAM,SAAS,UAAU,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CACpD,SAAQ,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;IACrC,OAAuB,IAAI,EAAE,MAAM,CAAqB;IAExD;;;;;;;OAOG;IACI,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,GAAG,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAkC/F;CACF"}
|
package/dist/task/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { AgentTask } from "./AgentTask";
|
|
6
7
|
import { BackgroundRemovalTask } from "./BackgroundRemovalTask";
|
|
7
8
|
import { ChunkRetrievalTask } from "./ChunkRetrievalTask";
|
|
8
9
|
import { ChunkToVectorTask } from "./ChunkToVectorTask";
|
|
@@ -37,11 +38,17 @@ import { TextLanguageDetectionTask } from "./TextLanguageDetectionTask";
|
|
|
37
38
|
import { TextNamedEntityRecognitionTask } from "./TextNamedEntityRecognitionTask";
|
|
38
39
|
import { TextQuestionAnswerTask } from "./TextQuestionAnswerTask";
|
|
39
40
|
import { TextSummaryTask } from "./TextSummaryTask";
|
|
41
|
+
import { ToolCallingTask } from "./ToolCallingTask";
|
|
40
42
|
import { TopicSegmenterTask } from "./TopicSegmenterTask";
|
|
41
43
|
import { UnloadModelTask } from "./UnloadModelTask";
|
|
42
44
|
import { VectorQuantizeTask } from "./VectorQuantizeTask";
|
|
43
45
|
import { VectorSimilarityTask } from "./VectorSimilarityTask";
|
|
44
|
-
export declare const registerAiTasks: () => (typeof BackgroundRemovalTask | typeof TextEmbeddingTask | typeof ChunkRetrievalTask | typeof ChunkToVectorTask | typeof ChunkVectorHybridSearchTask | typeof ChunkVectorSearchTask | typeof ChunkVectorUpsertTask | typeof CountTokensTask | typeof ContextBuilderTask | typeof TextNamedEntityRecognitionTask | typeof TextSummaryTask | typeof DocumentEnricherTask | typeof FaceDetectorTask | typeof FaceLandmarkerTask | typeof HandLandmarkerTask | typeof HierarchicalChunkerTask | typeof HierarchyJoinTask | typeof ImageClassificationTask | typeof ImageEmbeddingTask | typeof ImageSegmentationTask | typeof ImageToTextTask | typeof ModelSearchTask | typeof ObjectDetectionTask | typeof PoseLandmarkerTask | typeof QueryExpanderTask | typeof TextClassificationTask | typeof RerankerTask | typeof StructuralParserTask | typeof StructuredGenerationTask | typeof TextChunkerTask | typeof TextFillMaskTask | typeof TextGenerationTask | typeof TextLanguageDetectionTask | typeof TextQuestionAnswerTask | typeof TopicSegmenterTask | typeof UnloadModelTask | typeof VectorQuantizeTask | typeof VectorSimilarityTask)[];
|
|
46
|
+
export declare const registerAiTasks: () => (typeof ToolCallingTask | typeof AgentTask | typeof BackgroundRemovalTask | typeof TextEmbeddingTask | typeof ChunkRetrievalTask | typeof ChunkToVectorTask | typeof ChunkVectorHybridSearchTask | typeof ChunkVectorSearchTask | typeof ChunkVectorUpsertTask | typeof CountTokensTask | typeof ContextBuilderTask | typeof TextNamedEntityRecognitionTask | typeof TextSummaryTask | typeof DocumentEnricherTask | typeof FaceDetectorTask | typeof FaceLandmarkerTask | typeof HandLandmarkerTask | typeof HierarchicalChunkerTask | typeof HierarchyJoinTask | typeof ImageClassificationTask | typeof ImageEmbeddingTask | typeof ImageSegmentationTask | typeof ImageToTextTask | typeof ModelSearchTask | typeof ObjectDetectionTask | typeof PoseLandmarkerTask | typeof QueryExpanderTask | typeof TextClassificationTask | typeof RerankerTask | typeof StructuralParserTask | typeof StructuredGenerationTask | typeof TextChunkerTask | typeof TextFillMaskTask | typeof TextGenerationTask | typeof TextLanguageDetectionTask | typeof TextQuestionAnswerTask | typeof TopicSegmenterTask | typeof UnloadModelTask | typeof VectorQuantizeTask | typeof VectorSimilarityTask)[];
|
|
47
|
+
export * from "./AgentTask";
|
|
48
|
+
export * from "./AgentTypes";
|
|
49
|
+
export * from "./AgentUtils";
|
|
50
|
+
export * from "./MessageConversion";
|
|
51
|
+
export * from "./ToolCallingUtils";
|
|
45
52
|
export * from "./BackgroundRemovalTask";
|
|
46
53
|
export * from "./base/AiTask";
|
|
47
54
|
export * from "./base/AiTaskSchemas";
|
|
@@ -84,6 +91,7 @@ export * from "./TextQuestionAnswerTask";
|
|
|
84
91
|
export * from "./TextRewriterTask";
|
|
85
92
|
export * from "./TextSummaryTask";
|
|
86
93
|
export * from "./TextTranslationTask";
|
|
94
|
+
export * from "./ToolCallingTask";
|
|
87
95
|
export * from "./TopicSegmenterTask";
|
|
88
96
|
export * from "./UnloadModelTask";
|
|
89
97
|
export * from "./VectorQuantizeTask";
|
package/dist/task/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/task/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,k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* from "./provider/AiProvider";
|
|
17
17
|
export * from "./provider/AiProviderRegistry";
|
|
18
|
+
export * from "./task/ToolCallingUtils";
|
|
19
|
+
export * from "./task/MessageConversion";
|
|
18
20
|
export * from "./model/ModelSchema";
|
|
19
21
|
//# sourceMappingURL=worker.d.ts.map
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,qBAAqB,CAAC"}
|
package/dist/worker.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// src/provider/AiProvider.ts
|
|
2
|
-
import {
|
|
3
|
-
globalServiceRegistry as globalServiceRegistry2,
|
|
4
|
-
WORKER_MANAGER as WORKER_MANAGER2
|
|
5
|
-
} from "@workglow/util/worker";
|
|
2
|
+
import { globalServiceRegistry as globalServiceRegistry2, WORKER_MANAGER as WORKER_MANAGER2 } from "@workglow/util/worker";
|
|
6
3
|
|
|
7
4
|
// src/provider/AiProviderRegistry.ts
|
|
8
5
|
import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util/worker";
|
|
@@ -13,20 +10,18 @@ import {
|
|
|
13
10
|
Job,
|
|
14
11
|
JobStatus,
|
|
15
12
|
PermanentJobError,
|
|
16
|
-
RetryableJobError
|
|
13
|
+
RetryableJobError,
|
|
14
|
+
withJobErrorDiagnostics
|
|
17
15
|
} from "@workglow/job-queue";
|
|
18
16
|
import { getLogger } from "@workglow/util/worker";
|
|
19
17
|
var DEFAULT_AI_TIMEOUT_MS = 120000;
|
|
20
|
-
var
|
|
18
|
+
var LOCAL_INFERENCE_DEFAULT_TIMEOUT_MS = 300000;
|
|
21
19
|
function resolveAiJobTimeoutMs(aiProvider, explicitMs) {
|
|
22
20
|
if (explicitMs !== undefined) {
|
|
23
21
|
return explicitMs;
|
|
24
22
|
}
|
|
25
|
-
if (aiProvider === "LOCAL_LLAMACPP") {
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
if (aiProvider === "HF_TRANSFORMERS_ONNX" || aiProvider.startsWith("HF_TRANSFORMERS_ONNX")) {
|
|
29
|
-
return LOCAL_MODEL_DEFAULT_TIMEOUT_MS;
|
|
23
|
+
if (aiProvider === "LOCAL_LLAMACPP" || aiProvider === "HF_TRANSFORMERS_ONNX") {
|
|
24
|
+
return LOCAL_INFERENCE_DEFAULT_TIMEOUT_MS;
|
|
30
25
|
}
|
|
31
26
|
return DEFAULT_AI_TIMEOUT_MS;
|
|
32
27
|
}
|
|
@@ -39,39 +34,39 @@ function classifyProviderError(err, taskType, provider) {
|
|
|
39
34
|
const m = message.match(/\b([45]\d{2})\b/);
|
|
40
35
|
return m ? parseInt(m[1], 10) : undefined;
|
|
41
36
|
})();
|
|
42
|
-
if (err instanceof
|
|
43
|
-
return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider})
|
|
37
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
38
|
+
return new AbortSignalJobError(withJobErrorDiagnostics(`Provider call aborted for ${taskType} (${provider})`, err));
|
|
44
39
|
}
|
|
45
|
-
if (err instanceof
|
|
46
|
-
return new AbortSignalJobError(`Provider call timed out for ${taskType} (${provider})
|
|
40
|
+
if (err instanceof Error && err.name === "TimeoutError") {
|
|
41
|
+
return new AbortSignalJobError(withJobErrorDiagnostics(`Provider call timed out for ${taskType} (${provider})`, err));
|
|
47
42
|
}
|
|
48
43
|
if (message.includes("Pipeline download aborted") || message.includes("Operation aborted") || message.includes("operation was aborted") || message.includes("The operation was aborted")) {
|
|
49
|
-
return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider}): ${message}
|
|
44
|
+
return new AbortSignalJobError(withJobErrorDiagnostics(`Provider call aborted for ${taskType} (${provider}): ${message}`, err));
|
|
50
45
|
}
|
|
51
46
|
if (message.startsWith("HFT_NULL_PROCESSOR:")) {
|
|
52
|
-
return new RetryableJobError(message);
|
|
47
|
+
return new RetryableJobError(withJobErrorDiagnostics(message, err));
|
|
53
48
|
}
|
|
54
49
|
if (status === 429) {
|
|
55
50
|
const retryAfterMatch = message.match(/retry.after[:\s]*(\d+)/i);
|
|
56
51
|
const retryMs = retryAfterMatch ? parseInt(retryAfterMatch[1], 10) * 1000 : 30000;
|
|
57
|
-
return new RetryableJobError(`Rate limited by ${provider} for ${taskType}: ${message}`, new Date(Date.now() + retryMs));
|
|
52
|
+
return new RetryableJobError(withJobErrorDiagnostics(`Rate limited by ${provider} for ${taskType}: ${message}`, err), new Date(Date.now() + retryMs));
|
|
58
53
|
}
|
|
59
54
|
if (status === 401 || status === 403) {
|
|
60
|
-
return new PermanentJobError(`Authentication failed for ${provider} (${taskType}): ${message}
|
|
55
|
+
return new PermanentJobError(withJobErrorDiagnostics(`Authentication failed for ${provider} (${taskType}): ${message}`, err));
|
|
61
56
|
}
|
|
62
57
|
if (status === 400 || status === 404) {
|
|
63
|
-
return new PermanentJobError(`Invalid request to ${provider} for ${taskType}: ${message}
|
|
58
|
+
return new PermanentJobError(withJobErrorDiagnostics(`Invalid request to ${provider} for ${taskType}: ${message}`, err));
|
|
64
59
|
}
|
|
65
60
|
if (status && status >= 500) {
|
|
66
|
-
return new RetryableJobError(`Server error from ${provider} for ${taskType} (HTTP ${status}): ${message}
|
|
61
|
+
return new RetryableJobError(withJobErrorDiagnostics(`Server error from ${provider} for ${taskType} (HTTP ${status}): ${message}`, err));
|
|
67
62
|
}
|
|
68
63
|
if (message.includes("ECONNREFUSED") || message.includes("ECONNRESET") || message.includes("ETIMEDOUT") || message.includes("fetch failed") || message.includes("network") || err instanceof TypeError && message.includes("fetch")) {
|
|
69
|
-
return new RetryableJobError(`Network error calling ${provider} for ${taskType}: ${message}
|
|
64
|
+
return new RetryableJobError(withJobErrorDiagnostics(`Network error calling ${provider} for ${taskType}: ${message}`, err));
|
|
70
65
|
}
|
|
71
66
|
if (message.includes("timed out") || message.includes("timeout")) {
|
|
72
|
-
return new RetryableJobError(`Timeout calling ${provider} for ${taskType}: ${message}
|
|
67
|
+
return new RetryableJobError(withJobErrorDiagnostics(`Timeout calling ${provider} for ${taskType}: ${message}`, err));
|
|
73
68
|
}
|
|
74
|
-
return new PermanentJobError(`Provider ${provider} failed for ${taskType}: ${message}
|
|
69
|
+
return new PermanentJobError(withJobErrorDiagnostics(`Provider ${provider} failed for ${taskType}: ${message}`, err));
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
class AiJob extends Job {
|
|
@@ -401,6 +396,228 @@ class AiProvider {
|
|
|
401
396
|
async dispose() {}
|
|
402
397
|
async afterRegister(_options) {}
|
|
403
398
|
}
|
|
399
|
+
// src/task/ToolCallingUtils.ts
|
|
400
|
+
import { getLogger as getLogger2 } from "@workglow/util/worker";
|
|
401
|
+
function buildToolDescription(tool) {
|
|
402
|
+
let desc = tool.description;
|
|
403
|
+
if (tool.outputSchema && typeof tool.outputSchema === "object") {
|
|
404
|
+
desc += `
|
|
405
|
+
|
|
406
|
+
Returns: ${JSON.stringify(tool.outputSchema)}`;
|
|
407
|
+
}
|
|
408
|
+
return desc;
|
|
409
|
+
}
|
|
410
|
+
function isAllowedToolName(name, allowedTools) {
|
|
411
|
+
return allowedTools.some((t) => t.name === name);
|
|
412
|
+
}
|
|
413
|
+
function filterValidToolCalls(toolCalls, allowedTools) {
|
|
414
|
+
return toolCalls.filter((tc) => {
|
|
415
|
+
if (tc.name && isAllowedToolName(tc.name, allowedTools)) {
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
getLogger2().warn(`Filtered out tool call with unknown name "${tc.name ?? "(missing)"}"`, {
|
|
419
|
+
callId: tc.id,
|
|
420
|
+
toolName: tc.name
|
|
421
|
+
});
|
|
422
|
+
return false;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
// src/task/MessageConversion.ts
|
|
426
|
+
function getInputMessages(input) {
|
|
427
|
+
const messages = input.messages;
|
|
428
|
+
if (!messages || messages.length === 0)
|
|
429
|
+
return;
|
|
430
|
+
return messages;
|
|
431
|
+
}
|
|
432
|
+
function toOpenAIMessages(input) {
|
|
433
|
+
const messages = [];
|
|
434
|
+
if (input.systemPrompt) {
|
|
435
|
+
messages.push({ role: "system", content: input.systemPrompt });
|
|
436
|
+
}
|
|
437
|
+
const inputMessages = getInputMessages(input);
|
|
438
|
+
if (!inputMessages) {
|
|
439
|
+
if (!Array.isArray(input.prompt)) {
|
|
440
|
+
messages.push({ role: "user", content: input.prompt });
|
|
441
|
+
} else if (input.prompt.every((item) => typeof item === "string")) {
|
|
442
|
+
messages.push({ role: "user", content: input.prompt.join(`
|
|
443
|
+
`) });
|
|
444
|
+
} else {
|
|
445
|
+
const parts = [];
|
|
446
|
+
for (const item of input.prompt) {
|
|
447
|
+
if (typeof item === "string") {
|
|
448
|
+
parts.push({ type: "text", text: item });
|
|
449
|
+
} else {
|
|
450
|
+
const b = item;
|
|
451
|
+
if (b.type === "text") {
|
|
452
|
+
parts.push({ type: "text", text: b.text });
|
|
453
|
+
} else if (b.type === "image") {
|
|
454
|
+
parts.push({
|
|
455
|
+
type: "image_url",
|
|
456
|
+
image_url: { url: `data:${b.mimeType};base64,${b.data}` }
|
|
457
|
+
});
|
|
458
|
+
} else if (b.type === "audio") {
|
|
459
|
+
const format = b.mimeType.replace(/^audio\//, "");
|
|
460
|
+
parts.push({
|
|
461
|
+
type: "input_audio",
|
|
462
|
+
input_audio: { data: b.data, format }
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
messages.push({ role: "user", content: parts });
|
|
468
|
+
}
|
|
469
|
+
return messages;
|
|
470
|
+
}
|
|
471
|
+
for (const msg of inputMessages) {
|
|
472
|
+
if (msg.role === "user") {
|
|
473
|
+
if (typeof msg.content === "string") {
|
|
474
|
+
messages.push({ role: "user", content: msg.content });
|
|
475
|
+
} else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
|
|
476
|
+
const parts = [];
|
|
477
|
+
for (const block of msg.content) {
|
|
478
|
+
const b = block;
|
|
479
|
+
if (b.type === "text") {
|
|
480
|
+
parts.push({ type: "text", text: b.text });
|
|
481
|
+
} else if (b.type === "image") {
|
|
482
|
+
parts.push({
|
|
483
|
+
type: "image_url",
|
|
484
|
+
image_url: { url: `data:${b.mimeType};base64,${b.data}` }
|
|
485
|
+
});
|
|
486
|
+
} else if (b.type === "audio") {
|
|
487
|
+
const format = b.mimeType.replace(/^audio\//, "");
|
|
488
|
+
parts.push({
|
|
489
|
+
type: "input_audio",
|
|
490
|
+
input_audio: { data: b.data, format }
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
messages.push({ role: "user", content: parts });
|
|
495
|
+
} else {
|
|
496
|
+
try {
|
|
497
|
+
messages.push({ role: "user", content: JSON.stringify(msg.content) });
|
|
498
|
+
} catch {
|
|
499
|
+
messages.push({ role: "user", content: String(msg.content) });
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
} else if (msg.role === "assistant") {
|
|
503
|
+
if (typeof msg.content === "string") {
|
|
504
|
+
messages.push({ role: "assistant", content: msg.content.length > 0 ? msg.content : null });
|
|
505
|
+
} else if (Array.isArray(msg.content)) {
|
|
506
|
+
const textParts = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
507
|
+
const toolCalls = msg.content.filter((b) => b.type === "tool_use").map((b) => ({
|
|
508
|
+
id: b.id,
|
|
509
|
+
type: "function",
|
|
510
|
+
function: {
|
|
511
|
+
name: b.name,
|
|
512
|
+
arguments: JSON.stringify(b.input)
|
|
513
|
+
}
|
|
514
|
+
}));
|
|
515
|
+
const entry = {
|
|
516
|
+
role: "assistant",
|
|
517
|
+
content: textParts.length > 0 ? textParts : null
|
|
518
|
+
};
|
|
519
|
+
if (toolCalls.length > 0) {
|
|
520
|
+
entry.tool_calls = toolCalls;
|
|
521
|
+
}
|
|
522
|
+
messages.push(entry);
|
|
523
|
+
}
|
|
524
|
+
} else if (msg.role === "tool" && Array.isArray(msg.content)) {
|
|
525
|
+
for (const block of msg.content) {
|
|
526
|
+
const b = block;
|
|
527
|
+
let content;
|
|
528
|
+
if (typeof b.content === "string") {
|
|
529
|
+
content = b.content;
|
|
530
|
+
} else if (Array.isArray(b.content)) {
|
|
531
|
+
const parts = [];
|
|
532
|
+
for (const inner of b.content) {
|
|
533
|
+
if (inner.type === "text") {
|
|
534
|
+
parts.push({ type: "text", text: inner.text });
|
|
535
|
+
} else if (inner.type === "image") {
|
|
536
|
+
parts.push({
|
|
537
|
+
type: "image_url",
|
|
538
|
+
image_url: { url: `data:${inner.mimeType};base64,${inner.data}` }
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
content = parts;
|
|
543
|
+
} else {
|
|
544
|
+
content = "";
|
|
545
|
+
}
|
|
546
|
+
messages.push({
|
|
547
|
+
role: "tool",
|
|
548
|
+
content,
|
|
549
|
+
tool_call_id: b.tool_use_id
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return messages;
|
|
555
|
+
}
|
|
556
|
+
function toTextFlatMessages(input) {
|
|
557
|
+
const messages = [];
|
|
558
|
+
if (input.systemPrompt) {
|
|
559
|
+
messages.push({ role: "system", content: input.systemPrompt });
|
|
560
|
+
}
|
|
561
|
+
const inputMessages = getInputMessages(input);
|
|
562
|
+
if (!inputMessages) {
|
|
563
|
+
let promptContent;
|
|
564
|
+
if (!Array.isArray(input.prompt)) {
|
|
565
|
+
promptContent = input.prompt;
|
|
566
|
+
} else {
|
|
567
|
+
promptContent = input.prompt.map((item) => {
|
|
568
|
+
if (typeof item === "string")
|
|
569
|
+
return item;
|
|
570
|
+
const b = item;
|
|
571
|
+
return b.type === "text" ? b.text : "";
|
|
572
|
+
}).filter((s) => s !== "").join(`
|
|
573
|
+
`);
|
|
574
|
+
}
|
|
575
|
+
messages.push({ role: "user", content: promptContent });
|
|
576
|
+
return messages;
|
|
577
|
+
}
|
|
578
|
+
for (const msg of inputMessages) {
|
|
579
|
+
if (msg.role === "user") {
|
|
580
|
+
let content = "";
|
|
581
|
+
if (typeof msg.content === "string") {
|
|
582
|
+
content = msg.content;
|
|
583
|
+
} else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
|
|
584
|
+
content = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
585
|
+
} else if (msg.content != null) {
|
|
586
|
+
try {
|
|
587
|
+
content = JSON.stringify(msg.content);
|
|
588
|
+
} catch {
|
|
589
|
+
content = String(msg.content);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
messages.push({ role: "user", content });
|
|
593
|
+
} else if (msg.role === "assistant") {
|
|
594
|
+
if (typeof msg.content === "string") {
|
|
595
|
+
if (msg.content) {
|
|
596
|
+
messages.push({ role: "assistant", content: msg.content });
|
|
597
|
+
}
|
|
598
|
+
} else if (Array.isArray(msg.content)) {
|
|
599
|
+
const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
600
|
+
if (text) {
|
|
601
|
+
messages.push({ role: "assistant", content: text });
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
} else if (msg.role === "tool" && Array.isArray(msg.content)) {
|
|
605
|
+
for (const block of msg.content) {
|
|
606
|
+
const b = block;
|
|
607
|
+
let content;
|
|
608
|
+
if (typeof b.content === "string") {
|
|
609
|
+
content = b.content;
|
|
610
|
+
} else if (Array.isArray(b.content)) {
|
|
611
|
+
content = b.content.filter((inner) => inner.type === "text").map((inner) => inner.text).join("");
|
|
612
|
+
} else {
|
|
613
|
+
content = "";
|
|
614
|
+
}
|
|
615
|
+
messages.push({ role: "tool", content });
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return messages;
|
|
620
|
+
}
|
|
404
621
|
// src/model/ModelSchema.ts
|
|
405
622
|
var ModelConfigSchema = {
|
|
406
623
|
type: "object",
|
|
@@ -443,9 +660,14 @@ var ModelRecordSchema = {
|
|
|
443
660
|
};
|
|
444
661
|
var ModelPrimaryKeyNames = ["model_id"];
|
|
445
662
|
export {
|
|
663
|
+
toTextFlatMessages,
|
|
664
|
+
toOpenAIMessages,
|
|
446
665
|
setAiProviderRegistry,
|
|
447
666
|
resolveAiProviderGpuQueueConcurrency,
|
|
667
|
+
isAllowedToolName,
|
|
448
668
|
getAiProviderRegistry,
|
|
669
|
+
filterValidToolCalls,
|
|
670
|
+
buildToolDescription,
|
|
449
671
|
ModelRecordSchema,
|
|
450
672
|
ModelPrimaryKeyNames,
|
|
451
673
|
ModelConfigSchema,
|
|
@@ -453,4 +675,4 @@ export {
|
|
|
453
675
|
AiProvider
|
|
454
676
|
};
|
|
455
677
|
|
|
456
|
-
//# debugId=
|
|
678
|
+
//# debugId=D34633C7196C310D64756E2164756E21
|