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