@workglow/ai 0.2.16 → 0.2.18
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/browser.js +70 -120
- package/dist/browser.js.map +12 -12
- package/dist/bun.js +70 -120
- package/dist/bun.js.map +12 -12
- package/dist/node.js +70 -120
- package/dist/node.js.map +12 -12
- package/dist/provider/AiProvider.d.ts +8 -8
- package/dist/provider/AiProvider.d.ts.map +1 -1
- package/dist/provider/AiProviderRegistry.d.ts +16 -16
- package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
- package/dist/task/BackgroundRemovalTask.d.ts +3 -83
- package/dist/task/BackgroundRemovalTask.d.ts.map +1 -1
- package/dist/task/ChunkVectorUpsertTask.d.ts.map +1 -1
- package/dist/task/ContextBuilderTask.d.ts +3 -2
- package/dist/task/ContextBuilderTask.d.ts.map +1 -1
- package/dist/task/FaceDetectorTask.d.ts +3 -83
- package/dist/task/FaceDetectorTask.d.ts.map +1 -1
- package/dist/task/FaceLandmarkerTask.d.ts +3 -83
- package/dist/task/FaceLandmarkerTask.d.ts.map +1 -1
- package/dist/task/GestureRecognizerTask.d.ts +3 -83
- package/dist/task/GestureRecognizerTask.d.ts.map +1 -1
- package/dist/task/HandLandmarkerTask.d.ts +3 -83
- package/dist/task/HandLandmarkerTask.d.ts.map +1 -1
- package/dist/task/ImageClassificationTask.d.ts +3 -83
- package/dist/task/ImageClassificationTask.d.ts.map +1 -1
- package/dist/task/ImageEmbeddingTask.d.ts +6 -166
- package/dist/task/ImageEmbeddingTask.d.ts.map +1 -1
- package/dist/task/ImageSegmentationTask.d.ts +3 -83
- package/dist/task/ImageSegmentationTask.d.ts.map +1 -1
- package/dist/task/ImageToTextTask.d.ts +3 -83
- package/dist/task/ImageToTextTask.d.ts.map +1 -1
- package/dist/task/ObjectDetectionTask.d.ts +3 -83
- package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
- package/dist/task/PoseLandmarkerTask.d.ts +3 -83
- package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
- package/dist/task/TextChunkerTask.d.ts.map +1 -1
- package/dist/task/VectorQuantizeTask.d.ts +2 -1
- package/dist/task/VectorQuantizeTask.d.ts.map +1 -1
- package/dist/task/VectorSimilarityTask.d.ts +2 -4
- package/dist/task/VectorSimilarityTask.d.ts.map +1 -1
- package/dist/task/base/AiTask.d.ts +4 -4
- package/dist/task/base/AiTask.d.ts.map +1 -1
- package/dist/task/base/AiTaskSchemas.d.ts +4 -84
- package/dist/task/base/AiTaskSchemas.d.ts.map +1 -1
- package/dist/task/base/AiVisionTask.d.ts +2 -5
- package/dist/task/base/AiVisionTask.d.ts.map +1 -1
- package/dist/worker.js +25 -26
- package/dist/worker.js.map +4 -4
- package/package.json +11 -11
package/dist/bun.js
CHANGED
|
@@ -15,7 +15,7 @@ import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util/worker";
|
|
|
15
15
|
class AiProviderRegistry {
|
|
16
16
|
runFnRegistry = new Map;
|
|
17
17
|
streamFnRegistry = new Map;
|
|
18
|
-
|
|
18
|
+
previewRunFnRegistry = new Map;
|
|
19
19
|
providers = new Map;
|
|
20
20
|
strategyResolvers = new Map;
|
|
21
21
|
defaultStrategy;
|
|
@@ -31,7 +31,7 @@ class AiProviderRegistry {
|
|
|
31
31
|
for (const [, providerMap] of this.streamFnRegistry) {
|
|
32
32
|
providerMap.delete(name);
|
|
33
33
|
}
|
|
34
|
-
for (const [, providerMap] of this.
|
|
34
|
+
for (const [, providerMap] of this.previewRunFnRegistry) {
|
|
35
35
|
providerMap.delete(name);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -109,25 +109,24 @@ class AiProviderRegistry {
|
|
|
109
109
|
const taskTypeMap = this.streamFnRegistry.get(taskType);
|
|
110
110
|
return taskTypeMap?.get(modelProvider);
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
const
|
|
112
|
+
registerAsWorkerPreviewRunFn(modelProvider, taskType) {
|
|
113
|
+
const previewFn = async (input, model) => {
|
|
114
114
|
const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
|
|
115
|
-
return workerManager.
|
|
115
|
+
return workerManager.callWorkerPreviewFunction(modelProvider, taskType, [
|
|
116
116
|
input,
|
|
117
|
-
output,
|
|
118
117
|
model
|
|
119
118
|
]);
|
|
120
119
|
};
|
|
121
|
-
this.
|
|
120
|
+
this.registerPreviewRunFn(modelProvider, taskType, previewFn);
|
|
122
121
|
}
|
|
123
|
-
|
|
124
|
-
if (!this.
|
|
125
|
-
this.
|
|
122
|
+
registerPreviewRunFn(modelProvider, taskType, previewRunFn) {
|
|
123
|
+
if (!this.previewRunFnRegistry.has(taskType)) {
|
|
124
|
+
this.previewRunFnRegistry.set(taskType, new Map);
|
|
126
125
|
}
|
|
127
|
-
this.
|
|
126
|
+
this.previewRunFnRegistry.get(taskType).set(modelProvider, previewRunFn);
|
|
128
127
|
}
|
|
129
|
-
|
|
130
|
-
const taskTypeMap = this.
|
|
128
|
+
getPreviewRunFn(modelProvider, taskType) {
|
|
129
|
+
const taskTypeMap = this.previewRunFnRegistry.get(taskType);
|
|
131
130
|
return taskTypeMap?.get(modelProvider);
|
|
132
131
|
}
|
|
133
132
|
getDirectRunFn(modelProvider, taskType) {
|
|
@@ -722,11 +721,11 @@ function resolveAiProviderGpuQueueConcurrency(concurrency) {
|
|
|
722
721
|
class AiProvider {
|
|
723
722
|
tasks;
|
|
724
723
|
streamTasks;
|
|
725
|
-
|
|
726
|
-
constructor(tasks, streamTasks,
|
|
724
|
+
previewTasks;
|
|
725
|
+
constructor(tasks, streamTasks, previewTasks) {
|
|
727
726
|
this.tasks = tasks;
|
|
728
727
|
this.streamTasks = streamTasks;
|
|
729
|
-
this.
|
|
728
|
+
this.previewTasks = previewTasks;
|
|
730
729
|
}
|
|
731
730
|
get supportedTaskTypes() {
|
|
732
731
|
return this.taskTypes;
|
|
@@ -737,8 +736,8 @@ class AiProvider {
|
|
|
737
736
|
getStreamFn(taskType) {
|
|
738
737
|
return this.streamTasks?.[taskType];
|
|
739
738
|
}
|
|
740
|
-
|
|
741
|
-
return this.
|
|
739
|
+
getPreviewRunFn(taskType) {
|
|
740
|
+
return this.previewTasks?.[taskType];
|
|
742
741
|
}
|
|
743
742
|
async register(options = {}) {
|
|
744
743
|
const isInline = !!this.tasks;
|
|
@@ -766,7 +765,7 @@ class AiProvider {
|
|
|
766
765
|
for (const taskType of this.taskTypes) {
|
|
767
766
|
registry.registerAsWorkerRunFn(this.name, taskType);
|
|
768
767
|
registry.registerAsWorkerStreamFn(this.name, taskType);
|
|
769
|
-
registry.
|
|
768
|
+
registry.registerAsWorkerPreviewRunFn(this.name, taskType);
|
|
770
769
|
}
|
|
771
770
|
} else {
|
|
772
771
|
for (const [taskType, fn] of Object.entries(this.tasks)) {
|
|
@@ -778,9 +777,9 @@ class AiProvider {
|
|
|
778
777
|
}
|
|
779
778
|
}
|
|
780
779
|
}
|
|
781
|
-
if (this.
|
|
782
|
-
for (const [taskType, fn] of Object.entries(this.
|
|
783
|
-
registry.
|
|
780
|
+
if (this.previewTasks) {
|
|
781
|
+
for (const [taskType, fn] of Object.entries(this.previewTasks)) {
|
|
782
|
+
registry.registerPreviewRunFn(this.name, taskType, fn);
|
|
784
783
|
}
|
|
785
784
|
}
|
|
786
785
|
registry.registerProvider(this);
|
|
@@ -803,9 +802,9 @@ class AiProvider {
|
|
|
803
802
|
workerServer.registerStreamFunction(taskType, fn);
|
|
804
803
|
}
|
|
805
804
|
}
|
|
806
|
-
if (this.
|
|
807
|
-
for (const [taskType, fn] of Object.entries(this.
|
|
808
|
-
workerServer.
|
|
805
|
+
if (this.previewTasks) {
|
|
806
|
+
for (const [taskType, fn] of Object.entries(this.previewTasks)) {
|
|
807
|
+
workerServer.registerPreviewFunction(taskType, fn);
|
|
809
808
|
}
|
|
810
809
|
}
|
|
811
810
|
}
|
|
@@ -886,80 +885,11 @@ function TypeSingleOrArray(type) {
|
|
|
886
885
|
};
|
|
887
886
|
}
|
|
888
887
|
var TypeImageInput = {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
type: "string",
|
|
892
|
-
title: "Image Data",
|
|
893
|
-
description: "Image as data-uri",
|
|
894
|
-
format: "image:data-uri"
|
|
895
|
-
},
|
|
896
|
-
{
|
|
897
|
-
type: "object",
|
|
898
|
-
additionalProperties: false,
|
|
899
|
-
properties: {
|
|
900
|
-
data: {
|
|
901
|
-
oneOf: [
|
|
902
|
-
{
|
|
903
|
-
type: "object",
|
|
904
|
-
format: "image:ImageBitmap",
|
|
905
|
-
title: "ImageBitmap"
|
|
906
|
-
},
|
|
907
|
-
{
|
|
908
|
-
type: "object",
|
|
909
|
-
format: "image:OffscreenCanvas",
|
|
910
|
-
title: "OffscreenCanvas"
|
|
911
|
-
},
|
|
912
|
-
{
|
|
913
|
-
type: "object",
|
|
914
|
-
format: "image:VideoFrame",
|
|
915
|
-
title: "VideoFrame"
|
|
916
|
-
},
|
|
917
|
-
{
|
|
918
|
-
type: "object",
|
|
919
|
-
properties: {
|
|
920
|
-
data: {
|
|
921
|
-
type: "array",
|
|
922
|
-
items: { type: "number", format: "Uint8Clamped" },
|
|
923
|
-
format: "Uint8ClampedArray",
|
|
924
|
-
title: "Data",
|
|
925
|
-
description: "Data of the image"
|
|
926
|
-
},
|
|
927
|
-
width: { type: "number", title: "Width", description: "Width of the image" },
|
|
928
|
-
height: { type: "number", title: "Height", description: "Height of the image" },
|
|
929
|
-
channels: {
|
|
930
|
-
type: "number",
|
|
931
|
-
title: "Channels",
|
|
932
|
-
description: "Channels of the image"
|
|
933
|
-
},
|
|
934
|
-
rawChannels: {
|
|
935
|
-
type: "number",
|
|
936
|
-
title: "Raw Channels",
|
|
937
|
-
description: "Raw channels of the image"
|
|
938
|
-
}
|
|
939
|
-
},
|
|
940
|
-
additionalProperties: false,
|
|
941
|
-
required: ["data", "width", "height", "channels"],
|
|
942
|
-
format: "image:ImageBinary",
|
|
943
|
-
title: "ImageBinary"
|
|
944
|
-
}
|
|
945
|
-
]
|
|
946
|
-
},
|
|
947
|
-
width: { type: "number", title: "Width", description: "Width of the image" },
|
|
948
|
-
height: { type: "number", title: "Height", description: "Height of the image" },
|
|
949
|
-
channels: {
|
|
950
|
-
type: "number",
|
|
951
|
-
title: "Channels",
|
|
952
|
-
description: "Channels of the image",
|
|
953
|
-
minimum: 1,
|
|
954
|
-
maximum: 4
|
|
955
|
-
}
|
|
956
|
-
},
|
|
957
|
-
required: ["data", "width", "height", "channels"]
|
|
958
|
-
}
|
|
959
|
-
],
|
|
888
|
+
type: "object",
|
|
889
|
+
properties: {},
|
|
960
890
|
title: "Image",
|
|
961
|
-
|
|
962
|
-
|
|
891
|
+
description: "Image as data URI, Blob, ImageBitmap, ImageBinary, or GpuImage \u2014 hydrated to GpuImage by the runner",
|
|
892
|
+
format: "image"
|
|
963
893
|
};
|
|
964
894
|
var TypeAudioInput = {
|
|
965
895
|
type: "string",
|
|
@@ -1112,16 +1042,16 @@ class AiTask extends Task {
|
|
|
1112
1042
|
const model = input.model;
|
|
1113
1043
|
return model?.provider;
|
|
1114
1044
|
}
|
|
1115
|
-
async
|
|
1045
|
+
async executePreview(input, context) {
|
|
1116
1046
|
const model = input.model;
|
|
1117
1047
|
if (model && typeof model === "object" && model.provider) {
|
|
1118
1048
|
const taskType = this.constructor.runtype ?? this.constructor.type;
|
|
1119
|
-
const
|
|
1120
|
-
if (
|
|
1121
|
-
return
|
|
1049
|
+
const previewFn = getAiProviderRegistry().getPreviewRunFn(model.provider, taskType);
|
|
1050
|
+
if (previewFn) {
|
|
1051
|
+
return previewFn(input, model);
|
|
1122
1052
|
}
|
|
1123
1053
|
}
|
|
1124
|
-
return super.
|
|
1054
|
+
return super.executePreview(input, context);
|
|
1125
1055
|
}
|
|
1126
1056
|
async validateInput(input) {
|
|
1127
1057
|
const inputSchema = this.inputSchema();
|
|
@@ -1579,23 +1509,25 @@ class AiChatTask extends StreamingAiTask {
|
|
|
1579
1509
|
import { CreateWorkflow, Workflow } from "@workglow/task-graph";
|
|
1580
1510
|
|
|
1581
1511
|
// src/task/base/AiVisionTask.ts
|
|
1582
|
-
import { Image } from "@workglow/util/media";
|
|
1583
1512
|
class AiVisionTask extends AiTask {
|
|
1584
1513
|
static type = "AiVisionTask";
|
|
1585
1514
|
async getJobInput(input) {
|
|
1586
1515
|
const jobInput = await super.getJobInput(input);
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1516
|
+
if (!input.image)
|
|
1517
|
+
return jobInput;
|
|
1518
|
+
const provider = input.model.provider;
|
|
1519
|
+
const wantsBitmap = typeof provider === "string" && provider.startsWith("TENSORFLOW_MEDIAPIPE") && typeof ImageBitmap !== "undefined";
|
|
1520
|
+
const materializeOne = async (img) => {
|
|
1521
|
+
if (wantsBitmap) {
|
|
1522
|
+
const bin = await img.materialize();
|
|
1523
|
+
const id = new ImageData(bin.data, bin.width, bin.height);
|
|
1524
|
+
return createImageBitmap(id);
|
|
1594
1525
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1526
|
+
return img.materialize();
|
|
1527
|
+
};
|
|
1528
|
+
const value = input.image;
|
|
1529
|
+
const materialized = Array.isArray(value) ? await Promise.all(value.map(materializeOne)) : await materializeOne(value);
|
|
1530
|
+
jobInput.taskInput.image = materialized;
|
|
1599
1531
|
return jobInput;
|
|
1600
1532
|
}
|
|
1601
1533
|
}
|
|
@@ -2031,7 +1963,11 @@ Workflow4.prototype.chunkVectorUpsert = CreateWorkflow4(ChunkVectorUpsertTask);
|
|
|
2031
1963
|
|
|
2032
1964
|
// src/task/ContextBuilderTask.ts
|
|
2033
1965
|
import { estimateTokens } from "@workglow/knowledge-base";
|
|
2034
|
-
import {
|
|
1966
|
+
import {
|
|
1967
|
+
CreateWorkflow as CreateWorkflow6,
|
|
1968
|
+
Task as Task4,
|
|
1969
|
+
Workflow as Workflow6
|
|
1970
|
+
} from "@workglow/task-graph";
|
|
2035
1971
|
|
|
2036
1972
|
// src/task/CountTokensTask.ts
|
|
2037
1973
|
import { CreateWorkflow as CreateWorkflow5, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
@@ -2197,7 +2133,10 @@ class ContextBuilderTask extends Task4 {
|
|
|
2197
2133
|
static outputSchema() {
|
|
2198
2134
|
return outputSchema3;
|
|
2199
2135
|
}
|
|
2200
|
-
async
|
|
2136
|
+
async execute(input, context) {
|
|
2137
|
+
return this.executePreview(input, context);
|
|
2138
|
+
}
|
|
2139
|
+
async executePreview(input, context) {
|
|
2201
2140
|
const {
|
|
2202
2141
|
chunks,
|
|
2203
2142
|
metadata = [],
|
|
@@ -6675,7 +6614,10 @@ class VectorQuantizeTask extends Task16 {
|
|
|
6675
6614
|
static outputSchema() {
|
|
6676
6615
|
return outputSchema14;
|
|
6677
6616
|
}
|
|
6678
|
-
async
|
|
6617
|
+
async execute(input) {
|
|
6618
|
+
return this.executePreview(input);
|
|
6619
|
+
}
|
|
6620
|
+
async executePreview(input) {
|
|
6679
6621
|
const { vector, targetType, normalize = true } = input;
|
|
6680
6622
|
const isArray = Array.isArray(vector);
|
|
6681
6623
|
const vectors = isArray ? vector : [vector];
|
|
@@ -6850,7 +6792,15 @@ class VectorSimilarityTask extends GraphAsTask {
|
|
|
6850
6792
|
static outputSchema() {
|
|
6851
6793
|
return SimilarityOutputSchema;
|
|
6852
6794
|
}
|
|
6853
|
-
async
|
|
6795
|
+
async execute(input) {
|
|
6796
|
+
return this.executePreview(input);
|
|
6797
|
+
}
|
|
6798
|
+
async executePreview({
|
|
6799
|
+
query,
|
|
6800
|
+
vectors,
|
|
6801
|
+
method,
|
|
6802
|
+
topK
|
|
6803
|
+
}) {
|
|
6854
6804
|
let similarities = [];
|
|
6855
6805
|
const fnName = method;
|
|
6856
6806
|
const fn = similarityFunctions[fnName];
|
|
@@ -7261,4 +7211,4 @@ export {
|
|
|
7261
7211
|
AiChatInputSchema
|
|
7262
7212
|
};
|
|
7263
7213
|
|
|
7264
|
-
//# debugId=
|
|
7214
|
+
//# debugId=54021044A3C741C364756E2164756E21
|