@workglow/ai 0.2.6 → 0.2.8
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 +679 -1036
- package/dist/browser.js.map +14 -16
- package/dist/bun.js +679 -1036
- package/dist/bun.js.map +14 -16
- package/dist/job/AiJob.d.ts +2 -0
- package/dist/job/AiJob.d.ts.map +1 -1
- package/dist/model/ModelRepository.d.ts +2 -0
- package/dist/model/ModelRepository.d.ts.map +1 -1
- package/dist/model/ModelSchema.d.ts +16 -0
- package/dist/model/ModelSchema.d.ts.map +1 -1
- package/dist/node.js +679 -1036
- package/dist/node.js.map +14 -16
- package/dist/provider/AiProvider.d.ts +21 -0
- package/dist/provider/AiProvider.d.ts.map +1 -1
- package/dist/provider/AiProviderRegistry.d.ts +18 -2
- package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
- package/dist/task/BackgroundRemovalTask.d.ts +8 -0
- package/dist/task/BackgroundRemovalTask.d.ts.map +1 -1
- package/dist/task/ChunkRetrievalTask.d.ts +8 -0
- package/dist/task/ChunkRetrievalTask.d.ts.map +1 -1
- package/dist/task/ContextBuilderTask.d.ts +8 -0
- package/dist/task/ContextBuilderTask.d.ts.map +1 -1
- package/dist/task/CountTokensTask.d.ts +8 -0
- package/dist/task/CountTokensTask.d.ts.map +1 -1
- package/dist/task/DocumentEnricherTask.d.ts +16 -0
- package/dist/task/DocumentEnricherTask.d.ts.map +1 -1
- package/dist/task/DownloadModelTask.d.ts +18 -0
- package/dist/task/DownloadModelTask.d.ts.map +1 -1
- package/dist/task/FaceDetectorTask.d.ts +8 -0
- package/dist/task/FaceDetectorTask.d.ts.map +1 -1
- package/dist/task/FaceLandmarkerTask.d.ts +8 -0
- package/dist/task/FaceLandmarkerTask.d.ts.map +1 -1
- package/dist/task/GestureRecognizerTask.d.ts +8 -0
- package/dist/task/GestureRecognizerTask.d.ts.map +1 -1
- package/dist/task/HandLandmarkerTask.d.ts +8 -0
- package/dist/task/HandLandmarkerTask.d.ts.map +1 -1
- package/dist/task/HierarchicalChunkerTask.d.ts +8 -0
- package/dist/task/HierarchicalChunkerTask.d.ts.map +1 -1
- package/dist/task/ImageClassificationTask.d.ts +8 -0
- package/dist/task/ImageClassificationTask.d.ts.map +1 -1
- package/dist/task/ImageEmbeddingTask.d.ts +8 -0
- package/dist/task/ImageEmbeddingTask.d.ts.map +1 -1
- package/dist/task/ImageSegmentationTask.d.ts +8 -0
- package/dist/task/ImageSegmentationTask.d.ts.map +1 -1
- package/dist/task/ImageToTextTask.d.ts +8 -0
- package/dist/task/ImageToTextTask.d.ts.map +1 -1
- package/dist/task/KbToDocumentsTask.d.ts +98 -0
- package/dist/task/KbToDocumentsTask.d.ts.map +1 -0
- package/dist/task/ModelInfoTask.d.ts +29 -1
- package/dist/task/ModelInfoTask.d.ts.map +1 -1
- package/dist/task/ObjectDetectionTask.d.ts +8 -0
- package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
- package/dist/task/PoseLandmarkerTask.d.ts +8 -0
- package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
- package/dist/task/RerankerTask.d.ts +8 -0
- package/dist/task/RerankerTask.d.ts.map +1 -1
- package/dist/task/StructuredGenerationTask.d.ts +8 -0
- package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
- package/dist/task/TextClassificationTask.d.ts +8 -0
- package/dist/task/TextClassificationTask.d.ts.map +1 -1
- package/dist/task/TextEmbeddingTask.d.ts +8 -0
- package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
- package/dist/task/TextFillMaskTask.d.ts +8 -0
- package/dist/task/TextFillMaskTask.d.ts.map +1 -1
- package/dist/task/TextGenerationTask.d.ts +8 -0
- package/dist/task/TextGenerationTask.d.ts.map +1 -1
- package/dist/task/TextLanguageDetectionTask.d.ts +8 -0
- package/dist/task/TextLanguageDetectionTask.d.ts.map +1 -1
- package/dist/task/TextNamedEntityRecognitionTask.d.ts +8 -0
- package/dist/task/TextNamedEntityRecognitionTask.d.ts.map +1 -1
- package/dist/task/TextQuestionAnswerTask.d.ts +8 -0
- package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
- package/dist/task/TextRewriterTask.d.ts +8 -0
- package/dist/task/TextRewriterTask.d.ts.map +1 -1
- package/dist/task/TextSummaryTask.d.ts +8 -0
- package/dist/task/TextSummaryTask.d.ts.map +1 -1
- package/dist/task/TextTranslationTask.d.ts +8 -0
- package/dist/task/TextTranslationTask.d.ts.map +1 -1
- package/dist/task/ToolCallingTask.d.ts +23 -2
- package/dist/task/ToolCallingTask.d.ts.map +1 -1
- package/dist/task/UnloadModelTask.d.ts +18 -0
- package/dist/task/UnloadModelTask.d.ts.map +1 -1
- package/dist/task/base/AiTask.d.ts.map +1 -1
- package/dist/task/base/AiTaskSchemas.d.ts +16 -0
- package/dist/task/base/AiTaskSchemas.d.ts.map +1 -1
- package/dist/task/index.d.ts +3 -5
- package/dist/task/index.d.ts.map +1 -1
- package/dist/worker.js +42 -9
- package/dist/worker.js.map +6 -6
- package/package.json +11 -11
- package/dist/task/AgentTask.d.ts +0 -525
- package/dist/task/AgentTask.d.ts.map +0 -1
- package/dist/task/AgentTypes.d.ts +0 -183
- package/dist/task/AgentTypes.d.ts.map +0 -1
- package/dist/task/AgentUtils.d.ts +0 -55
- package/dist/task/AgentUtils.d.ts.map +0 -1
package/dist/node.js
CHANGED
|
@@ -55,6 +55,19 @@ class AiProviderRegistry {
|
|
|
55
55
|
}
|
|
56
56
|
return this.defaultStrategy;
|
|
57
57
|
}
|
|
58
|
+
createSession(providerName, model) {
|
|
59
|
+
const provider = this.providers.get(providerName);
|
|
60
|
+
if (!provider) {
|
|
61
|
+
throw new Error(`No provider found for "${providerName}". Register the provider before creating sessions.`);
|
|
62
|
+
}
|
|
63
|
+
return provider.createSession(model);
|
|
64
|
+
}
|
|
65
|
+
async disposeSession(providerName, sessionId) {
|
|
66
|
+
const provider = this.providers.get(providerName);
|
|
67
|
+
if (provider) {
|
|
68
|
+
await provider.disposeSession(sessionId);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
getProviderIdsForTask(taskType) {
|
|
59
72
|
const taskMap = this.runFnRegistry.get(taskType);
|
|
60
73
|
if (!taskMap)
|
|
@@ -68,9 +81,9 @@ class AiProviderRegistry {
|
|
|
68
81
|
this.runFnRegistry.get(taskType).set(modelProvider, runFn);
|
|
69
82
|
}
|
|
70
83
|
registerAsWorkerRunFn(modelProvider, taskType) {
|
|
71
|
-
const workerFn = async (input, model, update_progress, signal, outputSchema) => {
|
|
84
|
+
const workerFn = async (input, model, update_progress, signal, outputSchema, sessionId) => {
|
|
72
85
|
const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
|
|
73
|
-
const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema], {
|
|
86
|
+
const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema, sessionId], {
|
|
74
87
|
signal,
|
|
75
88
|
onProgress: update_progress
|
|
76
89
|
});
|
|
@@ -85,9 +98,9 @@ class AiProviderRegistry {
|
|
|
85
98
|
this.streamFnRegistry.get(taskType).set(modelProvider, streamFn);
|
|
86
99
|
}
|
|
87
100
|
registerAsWorkerStreamFn(modelProvider, taskType) {
|
|
88
|
-
const streamFn = async function* (input, model, signal, outputSchema) {
|
|
101
|
+
const streamFn = async function* (input, model, signal, outputSchema, sessionId) {
|
|
89
102
|
const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
|
|
90
|
-
yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema], { signal });
|
|
103
|
+
yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema, sessionId], { signal });
|
|
91
104
|
};
|
|
92
105
|
this.registerStreamFn(modelProvider, taskType, streamFn);
|
|
93
106
|
}
|
|
@@ -215,7 +228,7 @@ class AiJob extends Job {
|
|
|
215
228
|
const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
|
|
216
229
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
217
230
|
const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
|
|
218
|
-
return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema);
|
|
231
|
+
return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema, input.sessionId);
|
|
219
232
|
};
|
|
220
233
|
const runFnPromise = runFn();
|
|
221
234
|
return await Promise.race([runFnPromise, abortPromise]);
|
|
@@ -243,7 +256,7 @@ class AiJob extends Job {
|
|
|
243
256
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
244
257
|
const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
|
|
245
258
|
try {
|
|
246
|
-
for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema)) {
|
|
259
|
+
for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema, input.sessionId)) {
|
|
247
260
|
if (event.type === "finish") {
|
|
248
261
|
lastFinishData = event.data;
|
|
249
262
|
}
|
|
@@ -454,7 +467,15 @@ var ModelConfigSchema = {
|
|
|
454
467
|
provider_config: {
|
|
455
468
|
type: "object",
|
|
456
469
|
properties: {
|
|
457
|
-
credential_key: { type: "string", format: "credential", "x-ui-hidden": true }
|
|
470
|
+
credential_key: { type: "string", format: "credential", "x-ui-hidden": true },
|
|
471
|
+
native_dimensions: {
|
|
472
|
+
type: "integer",
|
|
473
|
+
description: "Native output vector dimensions for embedding models"
|
|
474
|
+
},
|
|
475
|
+
mrl: {
|
|
476
|
+
type: "boolean",
|
|
477
|
+
description: "Whether the model supports Matryoshka Representation Learning"
|
|
478
|
+
}
|
|
458
479
|
},
|
|
459
480
|
additionalProperties: true,
|
|
460
481
|
default: {}
|
|
@@ -648,6 +669,7 @@ registerInputCompactor("model", async (value, _format, registry) => {
|
|
|
648
669
|
|
|
649
670
|
// src/provider/AiProvider.ts
|
|
650
671
|
import { globalServiceRegistry as globalServiceRegistry3, WORKER_MANAGER as WORKER_MANAGER2 } from "@workglow/util/worker";
|
|
672
|
+
var DEFAULT_AI_PROVIDER_WORKER_IDLE_TIMEOUT_MS = 15 * 60 * 1000;
|
|
651
673
|
function resolveAiProviderGpuQueueConcurrency(concurrency) {
|
|
652
674
|
if (concurrency === undefined) {
|
|
653
675
|
return 1;
|
|
@@ -695,7 +717,13 @@ class AiProvider {
|
|
|
695
717
|
const registry = getAiProviderRegistry();
|
|
696
718
|
if (!isInline && options.worker) {
|
|
697
719
|
const workerManager = globalServiceRegistry3.get(WORKER_MANAGER2);
|
|
698
|
-
|
|
720
|
+
if (typeof options.worker === "function") {
|
|
721
|
+
workerManager.registerWorker(this.name, options.worker, {
|
|
722
|
+
idleTimeoutMs: options.workerIdleTimeoutMs ?? DEFAULT_AI_PROVIDER_WORKER_IDLE_TIMEOUT_MS
|
|
723
|
+
});
|
|
724
|
+
} else {
|
|
725
|
+
workerManager.registerWorker(this.name, options.worker);
|
|
726
|
+
}
|
|
699
727
|
for (const taskType of this.taskTypes) {
|
|
700
728
|
registry.registerAsWorkerRunFn(this.name, taskType);
|
|
701
729
|
registry.registerAsWorkerStreamFn(this.name, taskType);
|
|
@@ -744,6 +772,10 @@ class AiProvider {
|
|
|
744
772
|
}
|
|
745
773
|
async onInitialize(_options) {}
|
|
746
774
|
async dispose() {}
|
|
775
|
+
createSession(_model) {
|
|
776
|
+
return crypto.randomUUID();
|
|
777
|
+
}
|
|
778
|
+
async disposeSession(_sessionId) {}
|
|
747
779
|
async afterRegister(_options) {}
|
|
748
780
|
}
|
|
749
781
|
|
|
@@ -767,74 +799,8 @@ class QueuedAiProvider extends AiProvider {
|
|
|
767
799
|
// src/task/index.ts
|
|
768
800
|
import { TaskRegistry } from "@workglow/task-graph";
|
|
769
801
|
|
|
770
|
-
// src/task/
|
|
771
|
-
import { CreateWorkflow
|
|
772
|
-
import { getLogger as getLogger4 } from "@workglow/util";
|
|
773
|
-
|
|
774
|
-
// src/task/AgentTypes.ts
|
|
775
|
-
import { parseDataUri } from "@workglow/util/media";
|
|
776
|
-
function imageBlock(mimeType, data) {
|
|
777
|
-
return { type: "image", mimeType, data };
|
|
778
|
-
}
|
|
779
|
-
function audioBlock(mimeType, data) {
|
|
780
|
-
return { type: "audio", mimeType, data };
|
|
781
|
-
}
|
|
782
|
-
function imageBlockFromDataUri(dataUri) {
|
|
783
|
-
const { mimeType, base64 } = parseDataUri(dataUri);
|
|
784
|
-
return { type: "image", mimeType, data: base64 };
|
|
785
|
-
}
|
|
786
|
-
function audioBlockFromDataUri(dataUri) {
|
|
787
|
-
const { mimeType, base64 } = parseDataUri(dataUri);
|
|
788
|
-
return { type: "audio", mimeType, data: base64 };
|
|
789
|
-
}
|
|
790
|
-
function userMessage(prompt) {
|
|
791
|
-
return { role: "user", content: prompt };
|
|
792
|
-
}
|
|
793
|
-
function assistantMessage(text, toolCalls) {
|
|
794
|
-
const content = [];
|
|
795
|
-
if (text) {
|
|
796
|
-
content.push({ type: "text", text });
|
|
797
|
-
}
|
|
798
|
-
if (toolCalls) {
|
|
799
|
-
for (const tc of toolCalls) {
|
|
800
|
-
content.push({
|
|
801
|
-
type: "tool_use",
|
|
802
|
-
id: tc.id,
|
|
803
|
-
name: tc.name,
|
|
804
|
-
input: tc.input
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
return { role: "assistant", content };
|
|
809
|
-
}
|
|
810
|
-
function toolMessage(results) {
|
|
811
|
-
return {
|
|
812
|
-
role: "tool",
|
|
813
|
-
content: results.map((r) => {
|
|
814
|
-
const jsonText = JSON.stringify(r.output);
|
|
815
|
-
const content = r.mediaContent && r.mediaContent.length > 0 ? [{ type: "text", text: jsonText }, ...r.mediaContent] : jsonText;
|
|
816
|
-
return {
|
|
817
|
-
type: "tool_result",
|
|
818
|
-
tool_use_id: r.toolCallId,
|
|
819
|
-
content,
|
|
820
|
-
is_error: r.isError || undefined
|
|
821
|
-
};
|
|
822
|
-
})
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
function toolSourceDefinitions(sources) {
|
|
826
|
-
return sources.map((s) => s.definition);
|
|
827
|
-
}
|
|
828
|
-
function findToolSource(sources, name) {
|
|
829
|
-
return sources.find((s) => s.definition.name === name);
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// src/task/AgentUtils.ts
|
|
833
|
-
import { getTaskConstructors as getTaskConstructors2, TaskAbortedError } from "@workglow/task-graph";
|
|
834
|
-
import { getLogger as getLogger3 } from "@workglow/util";
|
|
835
|
-
|
|
836
|
-
// src/task/ToolCallingTask.ts
|
|
837
|
-
import { CreateWorkflow, getTaskConstructors, Workflow } from "@workglow/task-graph";
|
|
802
|
+
// src/task/BackgroundRemovalTask.ts
|
|
803
|
+
import { CreateWorkflow, Workflow } from "@workglow/task-graph";
|
|
838
804
|
|
|
839
805
|
// src/task/base/AiTaskSchemas.ts
|
|
840
806
|
var TypeLanguage = (annotations = {}) => ({
|
|
@@ -993,8 +959,8 @@ var TypeCategory = {
|
|
|
993
959
|
description: "Classification category with label and score"
|
|
994
960
|
};
|
|
995
961
|
|
|
996
|
-
// src/task/base/
|
|
997
|
-
import {
|
|
962
|
+
// src/task/base/AiVisionTask.ts
|
|
963
|
+
import { convertImageDataToUseableForm } from "@workglow/util/media";
|
|
998
964
|
|
|
999
965
|
// src/task/base/AiTask.ts
|
|
1000
966
|
import {
|
|
@@ -1049,6 +1015,18 @@ class AiTask extends Task {
|
|
|
1049
1015
|
const jobInput = await this.getJobInput(input);
|
|
1050
1016
|
const strategy = getAiProviderRegistry().getStrategy(model);
|
|
1051
1017
|
const output = await strategy.execute(jobInput, executeContext, this.runConfig.runnerId);
|
|
1018
|
+
if (executeContext.resourceScope) {
|
|
1019
|
+
const registry = getAiProviderRegistry();
|
|
1020
|
+
const provider = registry.getProvider(model.provider);
|
|
1021
|
+
const unloadFn = provider?.getRunFn("UnloadModelTask");
|
|
1022
|
+
if (unloadFn) {
|
|
1023
|
+
const modelPath = model.provider_config?.model_path ?? model.model;
|
|
1024
|
+
const resourceKey = `ai:${model.provider}:${modelPath}`;
|
|
1025
|
+
executeContext.resourceScope.register(resourceKey, async () => {
|
|
1026
|
+
await unloadFn({ model }, model, () => {}, AbortSignal.timeout(30000));
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1052
1030
|
return output;
|
|
1053
1031
|
}
|
|
1054
1032
|
async getJobInput(input) {
|
|
@@ -1072,6 +1050,10 @@ class AiTask extends Task {
|
|
|
1072
1050
|
jobInput.outputSchema = taskOutputSchema;
|
|
1073
1051
|
}
|
|
1074
1052
|
}
|
|
1053
|
+
const sessionId = input.sessionId;
|
|
1054
|
+
if (sessionId) {
|
|
1055
|
+
jobInput.sessionId = sessionId;
|
|
1056
|
+
}
|
|
1075
1057
|
return jobInput;
|
|
1076
1058
|
}
|
|
1077
1059
|
async createJob(input, queueName) {
|
|
@@ -1087,786 +1069,84 @@ class AiTask extends Task {
|
|
|
1087
1069
|
});
|
|
1088
1070
|
return job;
|
|
1089
1071
|
}
|
|
1090
|
-
async getDefaultQueueName(input) {
|
|
1091
|
-
const model = input.model;
|
|
1092
|
-
return model?.provider;
|
|
1093
|
-
}
|
|
1094
|
-
async executeReactive(input, output, context) {
|
|
1095
|
-
const model = input.model;
|
|
1096
|
-
if (model && typeof model === "object" && model.provider) {
|
|
1097
|
-
const taskType = this.constructor.runtype ?? this.constructor.type;
|
|
1098
|
-
const reactiveFn = getAiProviderRegistry().getReactiveRunFn(model.provider, taskType);
|
|
1099
|
-
if (reactiveFn) {
|
|
1100
|
-
return reactiveFn(input, output, model);
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
return super.executeReactive(input, output, context);
|
|
1104
|
-
}
|
|
1105
|
-
async validateInput(input) {
|
|
1106
|
-
const inputSchema = this.inputSchema();
|
|
1107
|
-
if (typeof inputSchema === "boolean") {
|
|
1108
|
-
if (inputSchema === false) {
|
|
1109
|
-
throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
|
|
1110
|
-
}
|
|
1111
|
-
return true;
|
|
1112
|
-
}
|
|
1113
|
-
const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
|
|
1114
|
-
for (const [key] of modelTaskProperties) {
|
|
1115
|
-
const model = input[key];
|
|
1116
|
-
if (typeof model === "object" && model !== null) {
|
|
1117
|
-
const tasks = model.tasks;
|
|
1118
|
-
if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
|
|
1119
|
-
const modelId = model.model_id ?? "(inline config)";
|
|
1120
|
-
throw new TaskConfigurationError2(`AiTask: Model "${modelId}" for '${key}' is not compatible with task '${this.type}'. ` + `Model supports: [${tasks.join(", ")}]`);
|
|
1121
|
-
}
|
|
1122
|
-
} else if (model !== undefined && model !== null) {
|
|
1123
|
-
throw new TaskConfigurationError2(`AiTask: Invalid model for '${key}' - expected ModelConfig object but got ${typeof model}. ` + `Ensure the model ID was registered in the ModelRepository before running the task.`);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
const modelPlainProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema) === "model");
|
|
1127
|
-
for (const [key] of modelPlainProperties) {
|
|
1128
|
-
const model = input[key];
|
|
1129
|
-
if (model !== undefined && model !== null && typeof model !== "object") {
|
|
1130
|
-
throw new TaskConfigurationError2(`AiTask: Invalid model for '${key}' - expected ModelConfig object but got ${typeof model}. ` + `Ensure the model ID was registered in the ModelRepository before running the task.`);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
return super.validateInput(input);
|
|
1134
|
-
}
|
|
1135
|
-
async narrowInput(input, registry) {
|
|
1136
|
-
const inputSchema = this.inputSchema();
|
|
1137
|
-
if (typeof inputSchema === "boolean") {
|
|
1138
|
-
if (inputSchema === false) {
|
|
1139
|
-
throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
|
|
1140
|
-
}
|
|
1141
|
-
return input;
|
|
1142
|
-
}
|
|
1143
|
-
const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
|
|
1144
|
-
if (modelTaskProperties.length > 0) {
|
|
1145
|
-
const modelRepo = registry.get(MODEL_REPOSITORY);
|
|
1146
|
-
const taskModels = await modelRepo.findModelsByTask(this.type) ?? [];
|
|
1147
|
-
for (const [key] of modelTaskProperties) {
|
|
1148
|
-
const requestedModel = input[key];
|
|
1149
|
-
if (typeof requestedModel === "string") {
|
|
1150
|
-
const found = taskModels?.find((m) => m.model_id === requestedModel);
|
|
1151
|
-
if (!found) {
|
|
1152
|
-
input[key] = undefined;
|
|
1153
|
-
}
|
|
1154
|
-
} else if (typeof requestedModel === "object" && requestedModel !== null) {
|
|
1155
|
-
const model = requestedModel;
|
|
1156
|
-
const tasks = model.tasks;
|
|
1157
|
-
if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
|
|
1158
|
-
input[key] = undefined;
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
return input;
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
// src/task/base/StreamingAiTask.ts
|
|
1168
|
-
class StreamingAiTask extends AiTask {
|
|
1169
|
-
static type = "StreamingAiTask";
|
|
1170
|
-
async* executeStream(input, context) {
|
|
1171
|
-
const model = input.model;
|
|
1172
|
-
if (!model || typeof model !== "object") {
|
|
1173
|
-
throw new TaskConfigurationError3("StreamingAiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
|
|
1174
|
-
}
|
|
1175
|
-
const jobInput = await this.getJobInput(input);
|
|
1176
|
-
const strategy = getAiProviderRegistry().getStrategy(model);
|
|
1177
|
-
const outSchema = this.outputSchema();
|
|
1178
|
-
const ports = getStreamingPorts(outSchema);
|
|
1179
|
-
let defaultPort = "text";
|
|
1180
|
-
if (ports.length > 0) {
|
|
1181
|
-
defaultPort = ports[0].port;
|
|
1182
|
-
} else {
|
|
1183
|
-
if (typeof outSchema === "object" && outSchema.properties) {
|
|
1184
|
-
const firstProp = Object.keys(outSchema.properties)[0];
|
|
1185
|
-
if (firstProp)
|
|
1186
|
-
defaultPort = firstProp;
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
for await (const event of strategy.executeStream(jobInput, context, this.runConfig.runnerId)) {
|
|
1190
|
-
if (event.type === "text-delta") {
|
|
1191
|
-
yield { ...event, port: event.port ?? defaultPort };
|
|
1192
|
-
} else if (event.type === "object-delta") {
|
|
1193
|
-
yield { ...event, port: event.port ?? defaultPort };
|
|
1194
|
-
} else {
|
|
1195
|
-
yield event;
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
// src/task/ToolCallingTask.ts
|
|
1202
|
-
function taskTypesToTools(taskNames, registry) {
|
|
1203
|
-
const constructors = getTaskConstructors(registry);
|
|
1204
|
-
return taskNames.map((name) => {
|
|
1205
|
-
const ctor = constructors.get(name);
|
|
1206
|
-
if (!ctor) {
|
|
1207
|
-
throw new Error(`taskTypesToTools: Unknown task type "${name}" — not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
|
|
1208
|
-
}
|
|
1209
|
-
const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
|
|
1210
|
-
return {
|
|
1211
|
-
name: ctor.type,
|
|
1212
|
-
description: ctor.description ?? "",
|
|
1213
|
-
inputSchema: ctor.inputSchema(),
|
|
1214
|
-
outputSchema: ctor.outputSchema(),
|
|
1215
|
-
...configSchema ? { configSchema } : {},
|
|
1216
|
-
taskType: name
|
|
1217
|
-
};
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
var ToolDefinitionSchema = {
|
|
1221
|
-
type: "object",
|
|
1222
|
-
properties: {
|
|
1223
|
-
name: {
|
|
1224
|
-
type: "string",
|
|
1225
|
-
title: "Name",
|
|
1226
|
-
description: "The tool name"
|
|
1227
|
-
},
|
|
1228
|
-
description: {
|
|
1229
|
-
type: "string",
|
|
1230
|
-
title: "Description",
|
|
1231
|
-
description: "A description of what the tool does"
|
|
1232
|
-
},
|
|
1233
|
-
inputSchema: {
|
|
1234
|
-
type: "object",
|
|
1235
|
-
title: "Input Schema",
|
|
1236
|
-
description: "JSON Schema describing the tool's input parameters",
|
|
1237
|
-
additionalProperties: true
|
|
1238
|
-
},
|
|
1239
|
-
outputSchema: {
|
|
1240
|
-
type: "object",
|
|
1241
|
-
title: "Output Schema",
|
|
1242
|
-
description: "JSON Schema describing what the tool returns",
|
|
1243
|
-
additionalProperties: true
|
|
1244
|
-
},
|
|
1245
|
-
configSchema: {
|
|
1246
|
-
type: "object",
|
|
1247
|
-
title: "Config Schema",
|
|
1248
|
-
description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
|
|
1249
|
-
additionalProperties: true
|
|
1250
|
-
},
|
|
1251
|
-
config: {
|
|
1252
|
-
type: "object",
|
|
1253
|
-
title: "Config",
|
|
1254
|
-
description: "Concrete configuration values for the backing task (not sent to the LLM)",
|
|
1255
|
-
additionalProperties: true
|
|
1256
|
-
}
|
|
1257
|
-
},
|
|
1258
|
-
required: ["name", "description", "inputSchema"],
|
|
1259
|
-
additionalProperties: true
|
|
1260
|
-
};
|
|
1261
|
-
var ToolCallSchema = {
|
|
1262
|
-
type: "object",
|
|
1263
|
-
properties: {
|
|
1264
|
-
id: {
|
|
1265
|
-
type: "string",
|
|
1266
|
-
title: "ID",
|
|
1267
|
-
description: "Unique identifier for this tool call"
|
|
1268
|
-
},
|
|
1269
|
-
name: {
|
|
1270
|
-
type: "string",
|
|
1271
|
-
title: "Name",
|
|
1272
|
-
description: "The name of the tool to invoke"
|
|
1273
|
-
},
|
|
1274
|
-
input: {
|
|
1275
|
-
type: "object",
|
|
1276
|
-
title: "Input",
|
|
1277
|
-
description: "The input arguments for the tool call",
|
|
1278
|
-
additionalProperties: true
|
|
1279
|
-
}
|
|
1280
|
-
},
|
|
1281
|
-
required: ["id", "name", "input"],
|
|
1282
|
-
additionalProperties: false
|
|
1283
|
-
};
|
|
1284
|
-
var modelSchema = TypeModel("model:ToolCallingTask");
|
|
1285
|
-
var ToolCallingInputSchema = {
|
|
1286
|
-
type: "object",
|
|
1287
|
-
properties: {
|
|
1288
|
-
model: modelSchema,
|
|
1289
|
-
prompt: {
|
|
1290
|
-
oneOf: [
|
|
1291
|
-
{ type: "string", title: "Prompt", description: "The prompt to send to the model" },
|
|
1292
|
-
{
|
|
1293
|
-
type: "array",
|
|
1294
|
-
title: "Prompt",
|
|
1295
|
-
description: "The prompt as an array of strings or content blocks",
|
|
1296
|
-
items: {
|
|
1297
|
-
oneOf: [
|
|
1298
|
-
{ type: "string" },
|
|
1299
|
-
{
|
|
1300
|
-
type: "object",
|
|
1301
|
-
properties: {
|
|
1302
|
-
type: { type: "string", enum: ["text", "image", "audio"] }
|
|
1303
|
-
},
|
|
1304
|
-
required: ["type"],
|
|
1305
|
-
additionalProperties: true
|
|
1306
|
-
}
|
|
1307
|
-
]
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
],
|
|
1311
|
-
title: "Prompt",
|
|
1312
|
-
description: "The prompt to send to the model"
|
|
1313
|
-
},
|
|
1314
|
-
systemPrompt: {
|
|
1315
|
-
type: "string",
|
|
1316
|
-
title: "System Prompt",
|
|
1317
|
-
description: "Optional system instructions for the model"
|
|
1318
|
-
},
|
|
1319
|
-
messages: {
|
|
1320
|
-
type: "array",
|
|
1321
|
-
title: "Messages",
|
|
1322
|
-
description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
|
|
1323
|
-
items: {
|
|
1324
|
-
type: "object",
|
|
1325
|
-
properties: {
|
|
1326
|
-
role: { type: "string", enum: ["user", "assistant", "tool"] },
|
|
1327
|
-
content: {}
|
|
1328
|
-
},
|
|
1329
|
-
required: ["role", "content"],
|
|
1330
|
-
additionalProperties: true
|
|
1331
|
-
}
|
|
1332
|
-
},
|
|
1333
|
-
tools: {
|
|
1334
|
-
type: "array",
|
|
1335
|
-
format: "tasks",
|
|
1336
|
-
title: "Tools",
|
|
1337
|
-
description: "Tool definitions available for the model to call",
|
|
1338
|
-
items: {
|
|
1339
|
-
oneOf: [
|
|
1340
|
-
{ type: "string", format: "tasks", description: "Task type name" },
|
|
1341
|
-
ToolDefinitionSchema
|
|
1342
|
-
]
|
|
1343
|
-
}
|
|
1344
|
-
},
|
|
1345
|
-
toolChoice: {
|
|
1346
|
-
type: "string",
|
|
1347
|
-
title: "Tool Choice",
|
|
1348
|
-
description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
|
|
1349
|
-
"x-ui-group": "Configuration"
|
|
1350
|
-
},
|
|
1351
|
-
maxTokens: {
|
|
1352
|
-
type: "number",
|
|
1353
|
-
title: "Max Tokens",
|
|
1354
|
-
description: "The maximum number of tokens to generate",
|
|
1355
|
-
minimum: 1,
|
|
1356
|
-
"x-ui-group": "Configuration"
|
|
1357
|
-
},
|
|
1358
|
-
temperature: {
|
|
1359
|
-
type: "number",
|
|
1360
|
-
title: "Temperature",
|
|
1361
|
-
description: "The temperature to use for sampling",
|
|
1362
|
-
minimum: 0,
|
|
1363
|
-
maximum: 2,
|
|
1364
|
-
"x-ui-group": "Configuration"
|
|
1365
|
-
}
|
|
1366
|
-
},
|
|
1367
|
-
required: ["model", "prompt", "tools"],
|
|
1368
|
-
additionalProperties: false
|
|
1369
|
-
};
|
|
1370
|
-
var ToolCallingOutputSchema = {
|
|
1371
|
-
type: "object",
|
|
1372
|
-
properties: {
|
|
1373
|
-
text: {
|
|
1374
|
-
type: "string",
|
|
1375
|
-
title: "Text",
|
|
1376
|
-
description: "Any text content generated by the model",
|
|
1377
|
-
"x-stream": "append"
|
|
1378
|
-
},
|
|
1379
|
-
toolCalls: {
|
|
1380
|
-
type: "array",
|
|
1381
|
-
items: ToolCallSchema,
|
|
1382
|
-
title: "Tool Calls",
|
|
1383
|
-
description: "Tool calls requested by the model",
|
|
1384
|
-
"x-stream": "object"
|
|
1385
|
-
}
|
|
1386
|
-
},
|
|
1387
|
-
required: ["text", "toolCalls"],
|
|
1388
|
-
additionalProperties: false
|
|
1389
|
-
};
|
|
1390
|
-
|
|
1391
|
-
class ToolCallingTask extends StreamingAiTask {
|
|
1392
|
-
static type = "ToolCallingTask";
|
|
1393
|
-
static category = "AI Text Model";
|
|
1394
|
-
static title = "Tool Calling";
|
|
1395
|
-
static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
|
|
1396
|
-
static inputSchema() {
|
|
1397
|
-
return ToolCallingInputSchema;
|
|
1398
|
-
}
|
|
1399
|
-
static outputSchema() {
|
|
1400
|
-
return ToolCallingOutputSchema;
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
var toolCalling = (input, config) => {
|
|
1404
|
-
return new ToolCallingTask(config).run(input);
|
|
1405
|
-
};
|
|
1406
|
-
Workflow.prototype.toolCalling = CreateWorkflow(ToolCallingTask);
|
|
1407
|
-
|
|
1408
|
-
// src/task/AgentUtils.ts
|
|
1409
|
-
function resolveToolConfig(toolName, config, taskConfigSchema) {
|
|
1410
|
-
if (config && !taskConfigSchema) {
|
|
1411
|
-
getLogger3().warn(`AgentTask: Tool "${toolName}" provided config but task has no configSchema — config ignored`);
|
|
1412
|
-
return {};
|
|
1413
|
-
}
|
|
1414
|
-
return config;
|
|
1415
|
-
}
|
|
1416
|
-
function buildToolSources(tools, registry) {
|
|
1417
|
-
if (!tools || tools.length === 0)
|
|
1418
|
-
return [];
|
|
1419
|
-
const stringNames = tools.filter((t) => typeof t === "string");
|
|
1420
|
-
const resolvedDefs = new Map(taskTypesToTools(stringNames, registry).map((d) => [d.taskType, d]));
|
|
1421
|
-
const constructors = getTaskConstructors2(registry);
|
|
1422
|
-
const sources = [];
|
|
1423
|
-
for (const tool of tools) {
|
|
1424
|
-
if (typeof tool === "string") {
|
|
1425
|
-
const def = resolvedDefs.get(tool);
|
|
1426
|
-
if (def) {
|
|
1427
|
-
const { taskType, ...definition } = def;
|
|
1428
|
-
sources.push({
|
|
1429
|
-
type: "registry",
|
|
1430
|
-
definition,
|
|
1431
|
-
taskType
|
|
1432
|
-
});
|
|
1433
|
-
}
|
|
1434
|
-
} else if (tool.type === "function" || !tool.type && tool.execute) {
|
|
1435
|
-
if (!tool.execute) {
|
|
1436
|
-
getLogger3().warn(`AgentTask: Tool "${tool.name}" has type "function" but no execute function — will throw on invocation`);
|
|
1437
|
-
}
|
|
1438
|
-
const { execute, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1439
|
-
sources.push({
|
|
1440
|
-
type: "function",
|
|
1441
|
-
definition,
|
|
1442
|
-
run: execute ?? (async () => {
|
|
1443
|
-
throw new Error(`No execute function for tool "${tool.name}"`);
|
|
1444
|
-
})
|
|
1445
|
-
});
|
|
1446
|
-
} else if (tool.type === "task") {
|
|
1447
|
-
const ctor = constructors.get(tool.name);
|
|
1448
|
-
if (!ctor) {
|
|
1449
|
-
getLogger3().warn(`AgentTask: Tool "${tool.name}" has type "task" but is not in TaskRegistry — will throw on invocation`);
|
|
1450
|
-
const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1451
|
-
sources.push({
|
|
1452
|
-
type: "function",
|
|
1453
|
-
definition,
|
|
1454
|
-
run: async () => {
|
|
1455
|
-
throw new Error(`Task "${tool.name}" not found in TaskRegistry`);
|
|
1456
|
-
}
|
|
1457
|
-
});
|
|
1458
|
-
} else {
|
|
1459
|
-
const safeConfig = resolveToolConfig(tool.name, tool.config, ctor.configSchema?.());
|
|
1460
|
-
const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1461
|
-
sources.push({
|
|
1462
|
-
type: "registry",
|
|
1463
|
-
definition,
|
|
1464
|
-
taskType: tool.name,
|
|
1465
|
-
config: safeConfig
|
|
1466
|
-
});
|
|
1467
|
-
}
|
|
1468
|
-
} else {
|
|
1469
|
-
const ctor = constructors.get(tool.name);
|
|
1470
|
-
if (ctor) {
|
|
1471
|
-
const safeConfig = resolveToolConfig(tool.name, tool.config, ctor.configSchema?.());
|
|
1472
|
-
const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1473
|
-
sources.push({
|
|
1474
|
-
type: "registry",
|
|
1475
|
-
definition,
|
|
1476
|
-
taskType: tool.name,
|
|
1477
|
-
config: safeConfig
|
|
1478
|
-
});
|
|
1479
|
-
} else {
|
|
1480
|
-
const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1481
|
-
sources.push({
|
|
1482
|
-
type: "function",
|
|
1483
|
-
definition,
|
|
1484
|
-
run: async () => {
|
|
1485
|
-
throw new Error(`No executor registered for tool "${tool.name}"`);
|
|
1486
|
-
}
|
|
1487
|
-
});
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
return sources;
|
|
1492
|
-
}
|
|
1493
|
-
async function executeToolCall(toolCall, sources, context, hooks) {
|
|
1494
|
-
const source = findToolSource(sources, toolCall.name);
|
|
1495
|
-
if (!source) {
|
|
1496
|
-
getLogger3().warn(`AgentTask: Unknown tool "${toolCall.name}" — not found in tool sources`);
|
|
1497
|
-
return {
|
|
1498
|
-
toolCallId: toolCall.id,
|
|
1499
|
-
toolName: toolCall.name,
|
|
1500
|
-
output: { error: `Unknown tool: ${toolCall.name}` },
|
|
1501
|
-
isError: true
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
let effectiveCall = toolCall;
|
|
1505
|
-
if (hooks?.beforeToolCall) {
|
|
1506
|
-
const decision = await hooks.beforeToolCall(toolCall, source);
|
|
1507
|
-
if (decision.action === "deny") {
|
|
1508
|
-
return {
|
|
1509
|
-
toolCallId: toolCall.id,
|
|
1510
|
-
toolName: toolCall.name,
|
|
1511
|
-
output: { error: decision.reason ?? "Tool call denied by hook" },
|
|
1512
|
-
isError: true
|
|
1513
|
-
};
|
|
1514
|
-
}
|
|
1515
|
-
if (decision.action === "modify") {
|
|
1516
|
-
effectiveCall = { ...toolCall, input: decision.input };
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
try {
|
|
1520
|
-
let output;
|
|
1521
|
-
switch (source.type) {
|
|
1522
|
-
case "registry": {
|
|
1523
|
-
const ctor = getTaskConstructors2(context.registry).get(source.taskType);
|
|
1524
|
-
if (!ctor) {
|
|
1525
|
-
throw new Error(`Task type "${source.taskType}" not found in TaskRegistry`);
|
|
1526
|
-
}
|
|
1527
|
-
const taskConfig = source.config ?? {};
|
|
1528
|
-
const task = context.own(new ctor({}, taskConfig));
|
|
1529
|
-
output = await task.run(effectiveCall.input) ?? {};
|
|
1530
|
-
break;
|
|
1531
|
-
}
|
|
1532
|
-
case "function": {
|
|
1533
|
-
output = await source.run(effectiveCall.input);
|
|
1534
|
-
break;
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
let result = {
|
|
1538
|
-
toolCallId: toolCall.id,
|
|
1539
|
-
toolName: toolCall.name,
|
|
1540
|
-
output,
|
|
1541
|
-
isError: false
|
|
1542
|
-
};
|
|
1543
|
-
if (hooks?.afterToolCall) {
|
|
1544
|
-
result = await hooks.afterToolCall(toolCall, result);
|
|
1545
|
-
}
|
|
1546
|
-
return result;
|
|
1547
|
-
} catch (err) {
|
|
1548
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
1549
|
-
if (hooks?.onToolError) {
|
|
1550
|
-
const action = await hooks.onToolError(toolCall, error);
|
|
1551
|
-
if (action.action === "result") {
|
|
1552
|
-
return {
|
|
1553
|
-
toolCallId: toolCall.id,
|
|
1554
|
-
toolName: toolCall.name,
|
|
1555
|
-
output: action.output,
|
|
1556
|
-
isError: false
|
|
1557
|
-
};
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
getLogger3().warn(`AgentTask: Tool "${toolCall.name}" failed: ${error.message}`);
|
|
1561
|
-
return {
|
|
1562
|
-
toolCallId: toolCall.id,
|
|
1563
|
-
toolName: toolCall.name,
|
|
1564
|
-
output: { error: error.message },
|
|
1565
|
-
isError: true
|
|
1566
|
-
};
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
async function executeToolCalls(toolCalls, sources, context, hooks, maxConcurrency = 5) {
|
|
1570
|
-
const calls = toolCalls;
|
|
1571
|
-
if (calls.length === 0)
|
|
1572
|
-
return [];
|
|
1573
|
-
const concurrency = Math.max(1, Math.min(maxConcurrency, calls.length));
|
|
1574
|
-
const results = new Array(calls.length);
|
|
1575
|
-
let cursor = 0;
|
|
1576
|
-
const workers = Array.from({ length: concurrency }, async () => {
|
|
1577
|
-
while (true) {
|
|
1578
|
-
if (context.signal.aborted) {
|
|
1579
|
-
throw context.signal.reason ?? new TaskAbortedError("The operation was aborted");
|
|
1580
|
-
}
|
|
1581
|
-
const position = cursor;
|
|
1582
|
-
cursor += 1;
|
|
1583
|
-
if (position >= calls.length)
|
|
1584
|
-
return;
|
|
1585
|
-
results[position] = await executeToolCall(calls[position], sources, context, hooks);
|
|
1586
|
-
}
|
|
1587
|
-
});
|
|
1588
|
-
await Promise.all(workers);
|
|
1589
|
-
return results;
|
|
1590
|
-
}
|
|
1591
|
-
function hasToolCalls(toolCalls) {
|
|
1592
|
-
return toolCalls !== undefined && toolCalls.length > 0;
|
|
1593
|
-
}
|
|
1594
|
-
function countAssistantToolUses(messages) {
|
|
1595
|
-
let n = 0;
|
|
1596
|
-
for (const m of messages) {
|
|
1597
|
-
if (m.role !== "assistant")
|
|
1598
|
-
continue;
|
|
1599
|
-
for (const block of m.content) {
|
|
1600
|
-
if (block.type === "tool_use")
|
|
1601
|
-
n += 1;
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
return n;
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
// src/task/AgentTask.ts
|
|
1608
|
-
var MAX_CONTEXT_MESSAGES = 1000;
|
|
1609
|
-
var modelSchema2 = TypeModel("model:ToolCallingTask");
|
|
1610
|
-
var AgentInputSchema = {
|
|
1611
|
-
type: "object",
|
|
1612
|
-
properties: {
|
|
1613
|
-
model: modelSchema2,
|
|
1614
|
-
prompt: {
|
|
1615
|
-
oneOf: [
|
|
1616
|
-
{ type: "string" },
|
|
1617
|
-
{
|
|
1618
|
-
type: "array",
|
|
1619
|
-
items: {
|
|
1620
|
-
type: "object",
|
|
1621
|
-
properties: {
|
|
1622
|
-
type: { type: "string", enum: ["text", "image", "audio"] }
|
|
1623
|
-
},
|
|
1624
|
-
required: ["type"],
|
|
1625
|
-
additionalProperties: true
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
],
|
|
1629
|
-
title: "Prompt",
|
|
1630
|
-
description: "The user prompt to start the agent loop. Can be a string or an array of content blocks (text, image, audio)."
|
|
1631
|
-
},
|
|
1632
|
-
systemPrompt: {
|
|
1633
|
-
type: "string",
|
|
1634
|
-
title: "System Prompt",
|
|
1635
|
-
description: "Optional system instructions for the agent"
|
|
1636
|
-
},
|
|
1637
|
-
tools: {
|
|
1638
|
-
type: "array",
|
|
1639
|
-
format: "tasks",
|
|
1640
|
-
title: "Tools",
|
|
1641
|
-
description: "Tools available to the agent. Each entry is a task type name (string, resolved from TaskRegistry) or a full ToolDefinition object with optional config for configurable tasks.",
|
|
1642
|
-
items: {
|
|
1643
|
-
oneOf: [
|
|
1644
|
-
{ type: "string", format: "tasks", description: "Task type name" },
|
|
1645
|
-
ToolDefinitionSchema
|
|
1646
|
-
]
|
|
1647
|
-
}
|
|
1648
|
-
},
|
|
1649
|
-
stopTool: {
|
|
1650
|
-
type: "string",
|
|
1651
|
-
title: "Stop Tool",
|
|
1652
|
-
description: "Name of a tool that signals agent completion. When called, the loop ends and the tool input becomes structuredOutput.",
|
|
1653
|
-
"x-ui-group": "Configuration"
|
|
1654
|
-
},
|
|
1655
|
-
maxIterations: {
|
|
1656
|
-
type: "number",
|
|
1657
|
-
title: "Max Iterations",
|
|
1658
|
-
description: "Maximum number of agent loop iterations (default: 10)",
|
|
1659
|
-
minimum: 1,
|
|
1660
|
-
"x-ui-group": "Configuration"
|
|
1661
|
-
},
|
|
1662
|
-
maxContextMessages: {
|
|
1663
|
-
type: "number",
|
|
1664
|
-
title: "Max Context Messages",
|
|
1665
|
-
description: "Maximum messages in conversation history. Older messages are trimmed to prevent context overflow.",
|
|
1666
|
-
minimum: 3,
|
|
1667
|
-
"x-ui-group": "Configuration"
|
|
1668
|
-
},
|
|
1669
|
-
maxTokens: {
|
|
1670
|
-
type: "number",
|
|
1671
|
-
title: "Max Tokens",
|
|
1672
|
-
description: "Maximum tokens per LLM call",
|
|
1673
|
-
minimum: 1,
|
|
1674
|
-
"x-ui-group": "Configuration"
|
|
1675
|
-
},
|
|
1676
|
-
temperature: {
|
|
1677
|
-
type: "number",
|
|
1678
|
-
title: "Temperature",
|
|
1679
|
-
description: "Sampling temperature for LLM calls",
|
|
1680
|
-
minimum: 0,
|
|
1681
|
-
maximum: 2,
|
|
1682
|
-
"x-ui-group": "Configuration"
|
|
1683
|
-
}
|
|
1684
|
-
},
|
|
1685
|
-
required: ["model", "prompt"],
|
|
1686
|
-
additionalProperties: false
|
|
1687
|
-
};
|
|
1688
|
-
var AgentOutputSchema = {
|
|
1689
|
-
type: "object",
|
|
1690
|
-
properties: {
|
|
1691
|
-
text: {
|
|
1692
|
-
type: "string",
|
|
1693
|
-
title: "Text",
|
|
1694
|
-
description: "The final text response from the agent",
|
|
1695
|
-
"x-stream": "append"
|
|
1696
|
-
},
|
|
1697
|
-
messages: {
|
|
1698
|
-
type: "array",
|
|
1699
|
-
title: "Messages",
|
|
1700
|
-
description: "Full conversation history including all tool calls and results",
|
|
1701
|
-
items: {
|
|
1702
|
-
type: "object",
|
|
1703
|
-
additionalProperties: true
|
|
1704
|
-
}
|
|
1705
|
-
},
|
|
1706
|
-
iterations: {
|
|
1707
|
-
type: "number",
|
|
1708
|
-
title: "Iterations",
|
|
1709
|
-
description: "Number of LLM calls made during the agent loop"
|
|
1710
|
-
},
|
|
1711
|
-
toolCallCount: {
|
|
1712
|
-
type: "number",
|
|
1713
|
-
title: "Tool Call Count",
|
|
1714
|
-
description: "Total number of tool calls the assistant requested (tool_use blocks in assistant messages)"
|
|
1715
|
-
},
|
|
1716
|
-
structuredOutput: {
|
|
1717
|
-
type: "object",
|
|
1718
|
-
title: "Structured Output",
|
|
1719
|
-
description: "Present when the agent terminated via a stop tool",
|
|
1720
|
-
additionalProperties: true
|
|
1721
|
-
}
|
|
1722
|
-
},
|
|
1723
|
-
required: ["text", "messages", "iterations", "toolCallCount"],
|
|
1724
|
-
additionalProperties: false
|
|
1725
|
-
};
|
|
1726
|
-
|
|
1727
|
-
class AgentTask extends Task2 {
|
|
1728
|
-
static type = "AgentTask";
|
|
1729
|
-
static category = "AI Agent";
|
|
1730
|
-
static title = "Agent";
|
|
1731
|
-
static description = "Multi-turn agentic loop that calls an LLM with tools, executes tool calls, and iterates until done";
|
|
1732
|
-
static cacheable = false;
|
|
1733
|
-
static inputSchema() {
|
|
1734
|
-
return AgentInputSchema;
|
|
1735
|
-
}
|
|
1736
|
-
static outputSchema() {
|
|
1737
|
-
return AgentOutputSchema;
|
|
1072
|
+
async getDefaultQueueName(input) {
|
|
1073
|
+
const model = input.model;
|
|
1074
|
+
return model?.provider;
|
|
1738
1075
|
}
|
|
1739
|
-
async
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1076
|
+
async executeReactive(input, output, context) {
|
|
1077
|
+
const model = input.model;
|
|
1078
|
+
if (model && typeof model === "object" && model.provider) {
|
|
1079
|
+
const taskType = this.constructor.runtype ?? this.constructor.type;
|
|
1080
|
+
const reactiveFn = getAiProviderRegistry().getReactiveRunFn(model.provider, taskType);
|
|
1081
|
+
if (reactiveFn) {
|
|
1082
|
+
return reactiveFn(input, output, model);
|
|
1744
1083
|
}
|
|
1745
1084
|
}
|
|
1746
|
-
|
|
1747
|
-
throw new Error("AgentTask: loop ended without producing output");
|
|
1748
|
-
}
|
|
1749
|
-
return result;
|
|
1085
|
+
return super.executeReactive(input, output, context);
|
|
1750
1086
|
}
|
|
1751
|
-
async
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
const hooks = this.config.hooks;
|
|
1757
|
-
const maxConcurrency = this.config.maxConcurrency ?? 5;
|
|
1758
|
-
const toolSources = this.resolveToolSources(input, context);
|
|
1759
|
-
const toolDefs = this.resolveToolDefs(toolSources, input.stopTool);
|
|
1760
|
-
const messages = [userMessage(input.prompt)];
|
|
1761
|
-
let finalText = "";
|
|
1762
|
-
let structuredOutput;
|
|
1763
|
-
for (let iteration = 0;iteration < maxIterations; iteration++) {
|
|
1764
|
-
if (context.signal.aborted)
|
|
1765
|
-
break;
|
|
1766
|
-
if (hooks?.onIteration) {
|
|
1767
|
-
const action = await hooks.onIteration(iteration, messages, {
|
|
1768
|
-
totalToolCalls: countAssistantToolUses(messages)
|
|
1769
|
-
});
|
|
1770
|
-
if (action.action === "stop")
|
|
1771
|
-
break;
|
|
1772
|
-
}
|
|
1773
|
-
await context.updateProgress(Math.round(iteration / maxIterations * 100), `Agent iteration ${iteration + 1}`);
|
|
1774
|
-
const contextMessages = this.trimMessages(messages, input.maxContextMessages ?? MAX_CONTEXT_MESSAGES);
|
|
1775
|
-
const llmTask = context.own(new ToolCallingTask);
|
|
1776
|
-
let iterationText = "";
|
|
1777
|
-
let toolCalls = [];
|
|
1778
|
-
for await (const event of llmTask.executeStream({
|
|
1779
|
-
model: input.model,
|
|
1780
|
-
prompt: input.prompt,
|
|
1781
|
-
systemPrompt: input.systemPrompt,
|
|
1782
|
-
tools: toolDefs,
|
|
1783
|
-
messages: contextMessages,
|
|
1784
|
-
maxTokens: input.maxTokens,
|
|
1785
|
-
temperature: input.temperature
|
|
1786
|
-
}, context)) {
|
|
1787
|
-
if (event.type === "text-delta") {
|
|
1788
|
-
yield { type: "text-delta", port: "text", textDelta: event.textDelta };
|
|
1789
|
-
iterationText += event.textDelta;
|
|
1790
|
-
} else if (event.type === "object-delta" && event.port === "toolCalls") {
|
|
1791
|
-
const items = event.objectDelta;
|
|
1792
|
-
for (const item of items) {
|
|
1793
|
-
const idx = toolCalls.findIndex((tc) => tc.id === item.id);
|
|
1794
|
-
if (idx >= 0)
|
|
1795
|
-
toolCalls[idx] = item;
|
|
1796
|
-
else
|
|
1797
|
-
toolCalls.push(item);
|
|
1798
|
-
}
|
|
1799
|
-
} else if (event.type === "finish") {
|
|
1800
|
-
const data = event.data;
|
|
1801
|
-
iterationText = data?.text ?? iterationText;
|
|
1802
|
-
if (data?.toolCalls && data.toolCalls.length > 0) {
|
|
1803
|
-
toolCalls = data.toolCalls;
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1087
|
+
async validateInput(input) {
|
|
1088
|
+
const inputSchema = this.inputSchema();
|
|
1089
|
+
if (typeof inputSchema === "boolean") {
|
|
1090
|
+
if (inputSchema === false) {
|
|
1091
|
+
throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
|
|
1806
1092
|
}
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1093
|
+
return true;
|
|
1094
|
+
}
|
|
1095
|
+
const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
|
|
1096
|
+
for (const [key] of modelTaskProperties) {
|
|
1097
|
+
const model = input[key];
|
|
1098
|
+
if (typeof model === "object" && model !== null) {
|
|
1099
|
+
const tasks = model.tasks;
|
|
1100
|
+
if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
|
|
1101
|
+
const modelId = model.model_id ?? "(inline config)";
|
|
1102
|
+
throw new TaskConfigurationError2(`AiTask: Model "${modelId}" for '${key}' is not compatible with task '${this.type}'. ` + `Model supports: [${tasks.join(", ")}]`);
|
|
1814
1103
|
}
|
|
1104
|
+
} else if (model !== undefined && model !== null) {
|
|
1105
|
+
throw new TaskConfigurationError2(`AiTask: Invalid model for '${key}' - expected ModelConfig object but got ${typeof model}. ` + `Ensure the model ID was registered in the ModelRepository before running the task.`);
|
|
1815
1106
|
}
|
|
1816
|
-
if (!hasToolCalls(toolCalls)) {
|
|
1817
|
-
break;
|
|
1818
|
-
}
|
|
1819
|
-
const results = await executeToolCalls(toolCalls, toolSources, context, hooks, maxConcurrency);
|
|
1820
|
-
messages.push(toolMessage(results));
|
|
1821
1107
|
}
|
|
1822
|
-
const
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
};
|
|
1829
|
-
yield { type: "finish", data: output };
|
|
1830
|
-
}
|
|
1831
|
-
resolveToolSources(input, context) {
|
|
1832
|
-
return buildToolSources(input.tools, context.registry);
|
|
1833
|
-
}
|
|
1834
|
-
resolveToolDefs(toolSources, stopTool) {
|
|
1835
|
-
const defs = toolSourceDefinitions(toolSources);
|
|
1836
|
-
if (stopTool && !defs.some((d) => d.name === stopTool)) {
|
|
1837
|
-
defs.push({
|
|
1838
|
-
name: stopTool,
|
|
1839
|
-
description: "Call this tool when you have completed the task. Pass your final structured result as the input.",
|
|
1840
|
-
inputSchema: { type: "object", additionalProperties: true }
|
|
1841
|
-
});
|
|
1108
|
+
const modelPlainProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema) === "model");
|
|
1109
|
+
for (const [key] of modelPlainProperties) {
|
|
1110
|
+
const model = input[key];
|
|
1111
|
+
if (model !== undefined && model !== null && typeof model !== "object") {
|
|
1112
|
+
throw new TaskConfigurationError2(`AiTask: Invalid model for '${key}' - expected ModelConfig object but got ${typeof model}. ` + `Ensure the model ID was registered in the ModelRepository before running the task.`);
|
|
1113
|
+
}
|
|
1842
1114
|
}
|
|
1843
|
-
return
|
|
1115
|
+
return super.validateInput(input);
|
|
1844
1116
|
}
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1117
|
+
async narrowInput(input, registry) {
|
|
1118
|
+
const inputSchema = this.inputSchema();
|
|
1119
|
+
if (typeof inputSchema === "boolean") {
|
|
1120
|
+
if (inputSchema === false) {
|
|
1121
|
+
throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
|
|
1122
|
+
}
|
|
1123
|
+
return input;
|
|
1848
1124
|
}
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1125
|
+
const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
|
|
1126
|
+
if (modelTaskProperties.length > 0) {
|
|
1127
|
+
const modelRepo = registry.get(MODEL_REPOSITORY);
|
|
1128
|
+
const taskModels = await modelRepo.findModelsByTask(this.type) ?? [];
|
|
1129
|
+
for (const [key] of modelTaskProperties) {
|
|
1130
|
+
const requestedModel = input[key];
|
|
1131
|
+
if (typeof requestedModel === "string") {
|
|
1132
|
+
const found = taskModels?.find((m) => m.model_id === requestedModel);
|
|
1133
|
+
if (!found) {
|
|
1134
|
+
input[key] = undefined;
|
|
1135
|
+
}
|
|
1136
|
+
} else if (typeof requestedModel === "object" && requestedModel !== null) {
|
|
1137
|
+
const model = requestedModel;
|
|
1138
|
+
const tasks = model.tasks;
|
|
1139
|
+
if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
|
|
1140
|
+
input[key] = undefined;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1856
1144
|
}
|
|
1857
|
-
return
|
|
1145
|
+
return input;
|
|
1858
1146
|
}
|
|
1859
1147
|
}
|
|
1860
|
-
var agent = (input, config) => {
|
|
1861
|
-
return new AgentTask(config).run(input);
|
|
1862
|
-
};
|
|
1863
|
-
Workflow2.prototype.agent = CreateWorkflow2(AgentTask);
|
|
1864
|
-
|
|
1865
|
-
// src/task/BackgroundRemovalTask.ts
|
|
1866
|
-
import { CreateWorkflow as CreateWorkflow3, Workflow as Workflow3 } from "@workglow/task-graph";
|
|
1867
1148
|
|
|
1868
1149
|
// src/task/base/AiVisionTask.ts
|
|
1869
|
-
import { convertImageDataToUseableForm } from "@workglow/util/media";
|
|
1870
1150
|
class AiVisionTask extends AiTask {
|
|
1871
1151
|
static type = "AiVisionTask";
|
|
1872
1152
|
async getJobInput(input) {
|
|
@@ -1887,7 +1167,7 @@ class AiVisionTask extends AiTask {
|
|
|
1887
1167
|
}
|
|
1888
1168
|
|
|
1889
1169
|
// src/task/BackgroundRemovalTask.ts
|
|
1890
|
-
var
|
|
1170
|
+
var modelSchema = TypeModel("model:BackgroundRemovalTask");
|
|
1891
1171
|
var processedImageSchema = {
|
|
1892
1172
|
type: "string",
|
|
1893
1173
|
contentEncoding: "base64",
|
|
@@ -1899,7 +1179,7 @@ var BackgroundRemovalInputSchema = {
|
|
|
1899
1179
|
type: "object",
|
|
1900
1180
|
properties: {
|
|
1901
1181
|
image: TypeImageInput,
|
|
1902
|
-
model:
|
|
1182
|
+
model: modelSchema
|
|
1903
1183
|
},
|
|
1904
1184
|
required: ["image", "model"],
|
|
1905
1185
|
additionalProperties: false
|
|
@@ -1928,22 +1208,22 @@ class BackgroundRemovalTask extends AiVisionTask {
|
|
|
1928
1208
|
var backgroundRemoval = (input, config) => {
|
|
1929
1209
|
return new BackgroundRemovalTask(config).run(input);
|
|
1930
1210
|
};
|
|
1931
|
-
|
|
1211
|
+
Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
|
|
1932
1212
|
|
|
1933
1213
|
// src/task/ChunkRetrievalTask.ts
|
|
1934
1214
|
import { TypeKnowledgeBase } from "@workglow/knowledge-base";
|
|
1935
|
-
import { CreateWorkflow as
|
|
1215
|
+
import { CreateWorkflow as CreateWorkflow3, Task as Task2, Workflow as Workflow3 } from "@workglow/task-graph";
|
|
1936
1216
|
import {
|
|
1937
1217
|
isTypedArray,
|
|
1938
1218
|
TypedArraySchema as TypedArraySchema2
|
|
1939
1219
|
} from "@workglow/util/schema";
|
|
1940
1220
|
|
|
1941
1221
|
// src/task/TextEmbeddingTask.ts
|
|
1942
|
-
import { CreateWorkflow as
|
|
1222
|
+
import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
|
|
1943
1223
|
import {
|
|
1944
1224
|
TypedArraySchema
|
|
1945
1225
|
} from "@workglow/util/schema";
|
|
1946
|
-
var
|
|
1226
|
+
var modelSchema2 = TypeModel("model:TextEmbeddingTask");
|
|
1947
1227
|
var TextEmbeddingInputSchema = {
|
|
1948
1228
|
type: "object",
|
|
1949
1229
|
properties: {
|
|
@@ -1952,7 +1232,7 @@ var TextEmbeddingInputSchema = {
|
|
|
1952
1232
|
title: "Text",
|
|
1953
1233
|
description: "The text to embed"
|
|
1954
1234
|
}),
|
|
1955
|
-
model:
|
|
1235
|
+
model: modelSchema2
|
|
1956
1236
|
},
|
|
1957
1237
|
required: ["text", "model"],
|
|
1958
1238
|
additionalProperties: false
|
|
@@ -1984,7 +1264,7 @@ class TextEmbeddingTask extends AiTask {
|
|
|
1984
1264
|
var textEmbedding = async (input, config) => {
|
|
1985
1265
|
return new TextEmbeddingTask(config).run(input);
|
|
1986
1266
|
};
|
|
1987
|
-
|
|
1267
|
+
Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
|
|
1988
1268
|
|
|
1989
1269
|
// src/task/ChunkRetrievalTask.ts
|
|
1990
1270
|
var inputSchema = {
|
|
@@ -2109,7 +1389,7 @@ var outputSchema = {
|
|
|
2109
1389
|
additionalProperties: false
|
|
2110
1390
|
};
|
|
2111
1391
|
|
|
2112
|
-
class ChunkRetrievalTask extends
|
|
1392
|
+
class ChunkRetrievalTask extends Task2 {
|
|
2113
1393
|
static type = "ChunkRetrievalTask";
|
|
2114
1394
|
static category = "RAG";
|
|
2115
1395
|
static title = "Chunk Retrieval";
|
|
@@ -2176,11 +1456,11 @@ class ChunkRetrievalTask extends Task3 {
|
|
|
2176
1456
|
var chunkRetrieval = (input, config) => {
|
|
2177
1457
|
return new ChunkRetrievalTask(config).run(input);
|
|
2178
1458
|
};
|
|
2179
|
-
|
|
1459
|
+
Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
|
|
2180
1460
|
|
|
2181
1461
|
// src/task/ChunkToVectorTask.ts
|
|
2182
1462
|
import { ChunkRecordSchema } from "@workglow/knowledge-base";
|
|
2183
|
-
import { CreateWorkflow as
|
|
1463
|
+
import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
|
|
2184
1464
|
import {
|
|
2185
1465
|
TypedArraySchema as TypedArraySchema3
|
|
2186
1466
|
} from "@workglow/util/schema";
|
|
@@ -2255,7 +1535,7 @@ var outputSchema2 = {
|
|
|
2255
1535
|
additionalProperties: false
|
|
2256
1536
|
};
|
|
2257
1537
|
|
|
2258
|
-
class ChunkToVectorTask extends
|
|
1538
|
+
class ChunkToVectorTask extends Task3 {
|
|
2259
1539
|
static type = "ChunkToVectorTask";
|
|
2260
1540
|
static category = "Document";
|
|
2261
1541
|
static title = "Chunk to Vector";
|
|
@@ -2306,11 +1586,11 @@ class ChunkToVectorTask extends Task4 {
|
|
|
2306
1586
|
var chunkToVector = (input, config) => {
|
|
2307
1587
|
return new ChunkToVectorTask(config).run(input);
|
|
2308
1588
|
};
|
|
2309
|
-
|
|
1589
|
+
Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
|
|
2310
1590
|
|
|
2311
1591
|
// src/task/ChunkVectorHybridSearchTask.ts
|
|
2312
1592
|
import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
|
|
2313
|
-
import { CreateWorkflow as
|
|
1593
|
+
import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
2314
1594
|
import {
|
|
2315
1595
|
TypedArraySchema as TypedArraySchema4
|
|
2316
1596
|
} from "@workglow/util/schema";
|
|
@@ -2423,7 +1703,7 @@ var outputSchema3 = {
|
|
|
2423
1703
|
additionalProperties: false
|
|
2424
1704
|
};
|
|
2425
1705
|
|
|
2426
|
-
class ChunkVectorHybridSearchTask extends
|
|
1706
|
+
class ChunkVectorHybridSearchTask extends Task4 {
|
|
2427
1707
|
static type = "ChunkVectorHybridSearchTask";
|
|
2428
1708
|
static category = "RAG";
|
|
2429
1709
|
static title = "Hybrid Search";
|
|
@@ -2476,11 +1756,11 @@ class ChunkVectorHybridSearchTask extends Task5 {
|
|
|
2476
1756
|
var hybridSearch = async (input, config) => {
|
|
2477
1757
|
return new ChunkVectorHybridSearchTask(config).run(input);
|
|
2478
1758
|
};
|
|
2479
|
-
|
|
1759
|
+
Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
|
|
2480
1760
|
|
|
2481
1761
|
// src/task/ChunkVectorSearchTask.ts
|
|
2482
1762
|
import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
|
|
2483
|
-
import { CreateWorkflow as
|
|
1763
|
+
import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
|
|
2484
1764
|
import {
|
|
2485
1765
|
TypedArraySchema as TypedArraySchema5
|
|
2486
1766
|
} from "@workglow/util/schema";
|
|
@@ -2563,7 +1843,7 @@ var outputSchema4 = {
|
|
|
2563
1843
|
additionalProperties: false
|
|
2564
1844
|
};
|
|
2565
1845
|
|
|
2566
|
-
class ChunkVectorSearchTask extends
|
|
1846
|
+
class ChunkVectorSearchTask extends Task5 {
|
|
2567
1847
|
static type = "ChunkVectorSearchTask";
|
|
2568
1848
|
static category = "Vector Store";
|
|
2569
1849
|
static title = "Vector Store Search";
|
|
@@ -2595,11 +1875,11 @@ class ChunkVectorSearchTask extends Task6 {
|
|
|
2595
1875
|
var vectorStoreSearch = (input, config) => {
|
|
2596
1876
|
return new ChunkVectorSearchTask(config).run(input);
|
|
2597
1877
|
};
|
|
2598
|
-
|
|
1878
|
+
Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
|
|
2599
1879
|
|
|
2600
1880
|
// src/task/ChunkVectorUpsertTask.ts
|
|
2601
1881
|
import { TypeKnowledgeBase as TypeKnowledgeBase4 } from "@workglow/knowledge-base";
|
|
2602
|
-
import { CreateWorkflow as
|
|
1882
|
+
import { CreateWorkflow as CreateWorkflow7, Task as Task6, Workflow as Workflow7 } from "@workglow/task-graph";
|
|
2603
1883
|
import {
|
|
2604
1884
|
TypedArraySchema as TypedArraySchema6
|
|
2605
1885
|
} from "@workglow/util/schema";
|
|
@@ -2653,7 +1933,7 @@ var outputSchema5 = {
|
|
|
2653
1933
|
additionalProperties: false
|
|
2654
1934
|
};
|
|
2655
1935
|
|
|
2656
|
-
class ChunkVectorUpsertTask extends
|
|
1936
|
+
class ChunkVectorUpsertTask extends Task6 {
|
|
2657
1937
|
static type = "ChunkVectorUpsertTask";
|
|
2658
1938
|
static category = "Vector Store";
|
|
2659
1939
|
static title = "Add to Vector Store";
|
|
@@ -2713,15 +1993,15 @@ class ChunkVectorUpsertTask extends Task7 {
|
|
|
2713
1993
|
var chunkVectorUpsert = (input, config) => {
|
|
2714
1994
|
return new ChunkVectorUpsertTask(config).run(input);
|
|
2715
1995
|
};
|
|
2716
|
-
|
|
1996
|
+
Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
|
|
2717
1997
|
|
|
2718
1998
|
// src/task/ContextBuilderTask.ts
|
|
2719
1999
|
import { estimateTokens } from "@workglow/knowledge-base";
|
|
2720
|
-
import { CreateWorkflow as
|
|
2000
|
+
import { CreateWorkflow as CreateWorkflow9, Task as Task7, Workflow as Workflow9 } from "@workglow/task-graph";
|
|
2721
2001
|
|
|
2722
2002
|
// src/task/CountTokensTask.ts
|
|
2723
|
-
import { CreateWorkflow as
|
|
2724
|
-
var
|
|
2003
|
+
import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
|
|
2004
|
+
var modelSchema3 = TypeModel("model");
|
|
2725
2005
|
var CountTokensInputSchema = {
|
|
2726
2006
|
type: "object",
|
|
2727
2007
|
properties: {
|
|
@@ -2730,7 +2010,7 @@ var CountTokensInputSchema = {
|
|
|
2730
2010
|
title: "Text",
|
|
2731
2011
|
description: "The text to count tokens for"
|
|
2732
2012
|
},
|
|
2733
|
-
model:
|
|
2013
|
+
model: modelSchema3
|
|
2734
2014
|
},
|
|
2735
2015
|
required: ["text", "model"],
|
|
2736
2016
|
additionalProperties: false
|
|
@@ -2764,7 +2044,7 @@ class CountTokensTask extends AiTask {
|
|
|
2764
2044
|
var countTokens = async (input, config) => {
|
|
2765
2045
|
return new CountTokensTask(config).run(input);
|
|
2766
2046
|
};
|
|
2767
|
-
|
|
2047
|
+
Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
|
|
2768
2048
|
|
|
2769
2049
|
// src/task/ContextBuilderTask.ts
|
|
2770
2050
|
var ContextFormat = {
|
|
@@ -2774,7 +2054,7 @@ var ContextFormat = {
|
|
|
2774
2054
|
MARKDOWN: "markdown",
|
|
2775
2055
|
JSON: "json"
|
|
2776
2056
|
};
|
|
2777
|
-
var
|
|
2057
|
+
var modelSchema4 = TypeModel("model", {
|
|
2778
2058
|
title: "Model",
|
|
2779
2059
|
description: "Model to use for token counting (optional, falls back to estimation)"
|
|
2780
2060
|
});
|
|
@@ -2838,7 +2118,7 @@ var inputSchema6 = {
|
|
|
2838
2118
|
|
|
2839
2119
|
`
|
|
2840
2120
|
},
|
|
2841
|
-
model:
|
|
2121
|
+
model: modelSchema4
|
|
2842
2122
|
},
|
|
2843
2123
|
required: ["chunks"],
|
|
2844
2124
|
additionalProperties: false
|
|
@@ -2871,7 +2151,7 @@ var outputSchema6 = {
|
|
|
2871
2151
|
additionalProperties: false
|
|
2872
2152
|
};
|
|
2873
2153
|
|
|
2874
|
-
class ContextBuilderTask extends
|
|
2154
|
+
class ContextBuilderTask extends Task7 {
|
|
2875
2155
|
static type = "ContextBuilderTask";
|
|
2876
2156
|
static category = "RAG";
|
|
2877
2157
|
static title = "Context Builder";
|
|
@@ -3064,15 +2344,15 @@ class ContextBuilderTask extends Task8 {
|
|
|
3064
2344
|
var contextBuilder = (input, config) => {
|
|
3065
2345
|
return new ContextBuilderTask(config).run(input);
|
|
3066
2346
|
};
|
|
3067
|
-
|
|
2347
|
+
Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
|
|
3068
2348
|
|
|
3069
2349
|
// src/task/DocumentEnricherTask.ts
|
|
3070
2350
|
import { getChildren, hasChildren } from "@workglow/knowledge-base";
|
|
3071
|
-
import { CreateWorkflow as
|
|
2351
|
+
import { CreateWorkflow as CreateWorkflow12, Task as Task8, Workflow as Workflow12 } from "@workglow/task-graph";
|
|
3072
2352
|
|
|
3073
2353
|
// src/task/TextNamedEntityRecognitionTask.ts
|
|
3074
|
-
import { CreateWorkflow as
|
|
3075
|
-
var
|
|
2354
|
+
import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
|
|
2355
|
+
var modelSchema5 = TypeModel("model:TextNamedEntityRecognitionTask");
|
|
3076
2356
|
var TextNamedEntityRecognitionInputSchema = {
|
|
3077
2357
|
type: "object",
|
|
3078
2358
|
properties: {
|
|
@@ -3091,7 +2371,7 @@ var TextNamedEntityRecognitionInputSchema = {
|
|
|
3091
2371
|
"x-ui-group": "Configuration",
|
|
3092
2372
|
"x-ui-group-open": false
|
|
3093
2373
|
},
|
|
3094
|
-
model:
|
|
2374
|
+
model: modelSchema5
|
|
3095
2375
|
},
|
|
3096
2376
|
required: ["text", "model"],
|
|
3097
2377
|
additionalProperties: false
|
|
@@ -3146,11 +2426,48 @@ class TextNamedEntityRecognitionTask extends AiTask {
|
|
|
3146
2426
|
var textNamedEntityRecognition = (input, config) => {
|
|
3147
2427
|
return new TextNamedEntityRecognitionTask(config).run(input);
|
|
3148
2428
|
};
|
|
3149
|
-
|
|
2429
|
+
Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
|
|
2430
|
+
|
|
2431
|
+
// src/task/TextSummaryTask.ts
|
|
2432
|
+
import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
|
|
2433
|
+
|
|
2434
|
+
// src/task/base/StreamingAiTask.ts
|
|
2435
|
+
import { getStreamingPorts, TaskConfigurationError as TaskConfigurationError3 } from "@workglow/task-graph";
|
|
2436
|
+
class StreamingAiTask extends AiTask {
|
|
2437
|
+
static type = "StreamingAiTask";
|
|
2438
|
+
async* executeStream(input, context) {
|
|
2439
|
+
const model = input.model;
|
|
2440
|
+
if (!model || typeof model !== "object") {
|
|
2441
|
+
throw new TaskConfigurationError3("StreamingAiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
|
|
2442
|
+
}
|
|
2443
|
+
const jobInput = await this.getJobInput(input);
|
|
2444
|
+
const strategy = getAiProviderRegistry().getStrategy(model);
|
|
2445
|
+
const outSchema = this.outputSchema();
|
|
2446
|
+
const ports = getStreamingPorts(outSchema);
|
|
2447
|
+
let defaultPort = "text";
|
|
2448
|
+
if (ports.length > 0) {
|
|
2449
|
+
defaultPort = ports[0].port;
|
|
2450
|
+
} else {
|
|
2451
|
+
if (typeof outSchema === "object" && outSchema.properties) {
|
|
2452
|
+
const firstProp = Object.keys(outSchema.properties)[0];
|
|
2453
|
+
if (firstProp)
|
|
2454
|
+
defaultPort = firstProp;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
for await (const event of strategy.executeStream(jobInput, context, this.runConfig.runnerId)) {
|
|
2458
|
+
if (event.type === "text-delta") {
|
|
2459
|
+
yield { ...event, port: event.port ?? defaultPort };
|
|
2460
|
+
} else if (event.type === "object-delta") {
|
|
2461
|
+
yield { ...event, port: event.port ?? defaultPort };
|
|
2462
|
+
} else {
|
|
2463
|
+
yield event;
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
3150
2468
|
|
|
3151
2469
|
// src/task/TextSummaryTask.ts
|
|
3152
|
-
|
|
3153
|
-
var modelSchema8 = TypeModel("model:TextSummaryTask");
|
|
2470
|
+
var modelSchema6 = TypeModel("model:TextSummaryTask");
|
|
3154
2471
|
var TextSummaryInputSchema = {
|
|
3155
2472
|
type: "object",
|
|
3156
2473
|
properties: {
|
|
@@ -3159,7 +2476,7 @@ var TextSummaryInputSchema = {
|
|
|
3159
2476
|
title: "Text",
|
|
3160
2477
|
description: "The text to summarize"
|
|
3161
2478
|
},
|
|
3162
|
-
model:
|
|
2479
|
+
model: modelSchema6
|
|
3163
2480
|
},
|
|
3164
2481
|
required: ["text", "model"],
|
|
3165
2482
|
additionalProperties: false
|
|
@@ -3193,7 +2510,7 @@ class TextSummaryTask extends StreamingAiTask {
|
|
|
3193
2510
|
var textSummary = async (input, config) => {
|
|
3194
2511
|
return new TextSummaryTask(config).run(input);
|
|
3195
2512
|
};
|
|
3196
|
-
|
|
2513
|
+
Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
|
|
3197
2514
|
|
|
3198
2515
|
// src/task/DocumentEnricherTask.ts
|
|
3199
2516
|
var inputSchema7 = {
|
|
@@ -3267,7 +2584,7 @@ var outputSchema7 = {
|
|
|
3267
2584
|
additionalProperties: false
|
|
3268
2585
|
};
|
|
3269
2586
|
|
|
3270
|
-
class DocumentEnricherTask extends
|
|
2587
|
+
class DocumentEnricherTask extends Task8 {
|
|
3271
2588
|
static type = "DocumentEnricherTask";
|
|
3272
2589
|
static category = "Document";
|
|
3273
2590
|
static title = "Document Enricher";
|
|
@@ -3426,12 +2743,12 @@ class DocumentEnricherTask extends Task9 {
|
|
|
3426
2743
|
var documentEnricher = (input, config) => {
|
|
3427
2744
|
return new DocumentEnricherTask(config).run(input);
|
|
3428
2745
|
};
|
|
3429
|
-
|
|
2746
|
+
Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
|
|
3430
2747
|
|
|
3431
2748
|
// src/task/DocumentUpsertTask.ts
|
|
3432
2749
|
import { Document, TypeKnowledgeBase as TypeKnowledgeBase5 } from "@workglow/knowledge-base";
|
|
3433
2750
|
import { DocumentMetadataSchema } from "@workglow/knowledge-base";
|
|
3434
|
-
import { CreateWorkflow as
|
|
2751
|
+
import { CreateWorkflow as CreateWorkflow13, Task as Task9, Workflow as Workflow13 } from "@workglow/task-graph";
|
|
3435
2752
|
var inputSchema8 = {
|
|
3436
2753
|
type: "object",
|
|
3437
2754
|
properties: {
|
|
@@ -3476,7 +2793,7 @@ var outputSchema8 = {
|
|
|
3476
2793
|
additionalProperties: false
|
|
3477
2794
|
};
|
|
3478
2795
|
|
|
3479
|
-
class DocumentUpsertTask extends
|
|
2796
|
+
class DocumentUpsertTask extends Task9 {
|
|
3480
2797
|
static type = "DocumentUpsertTask";
|
|
3481
2798
|
static category = "Vector Store";
|
|
3482
2799
|
static title = "Add Document";
|
|
@@ -3509,15 +2826,15 @@ class DocumentUpsertTask extends Task10 {
|
|
|
3509
2826
|
var documentUpsert = (input, config) => {
|
|
3510
2827
|
return new DocumentUpsertTask(config).run(input);
|
|
3511
2828
|
};
|
|
3512
|
-
|
|
2829
|
+
Workflow13.prototype.documentUpsert = CreateWorkflow13(DocumentUpsertTask);
|
|
3513
2830
|
|
|
3514
2831
|
// src/task/DownloadModelTask.ts
|
|
3515
|
-
import { CreateWorkflow as
|
|
3516
|
-
var
|
|
2832
|
+
import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
|
|
2833
|
+
var modelSchema7 = TypeModel("model");
|
|
3517
2834
|
var DownloadModelInputSchema = {
|
|
3518
2835
|
type: "object",
|
|
3519
2836
|
properties: {
|
|
3520
|
-
model:
|
|
2837
|
+
model: modelSchema7
|
|
3521
2838
|
},
|
|
3522
2839
|
required: ["model"],
|
|
3523
2840
|
additionalProperties: false
|
|
@@ -3525,7 +2842,7 @@ var DownloadModelInputSchema = {
|
|
|
3525
2842
|
var DownloadModelOutputSchema = {
|
|
3526
2843
|
type: "object",
|
|
3527
2844
|
properties: {
|
|
3528
|
-
model:
|
|
2845
|
+
model: modelSchema7
|
|
3529
2846
|
},
|
|
3530
2847
|
required: ["model"],
|
|
3531
2848
|
additionalProperties: false
|
|
@@ -3579,11 +2896,11 @@ class DownloadModelTask extends AiTask {
|
|
|
3579
2896
|
var downloadModel = (input, config) => {
|
|
3580
2897
|
return new DownloadModelTask(config).run(input);
|
|
3581
2898
|
};
|
|
3582
|
-
|
|
2899
|
+
Workflow14.prototype.downloadModel = CreateWorkflow14(DownloadModelTask);
|
|
3583
2900
|
|
|
3584
2901
|
// src/task/FaceDetectorTask.ts
|
|
3585
|
-
import { CreateWorkflow as
|
|
3586
|
-
var
|
|
2902
|
+
import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
|
|
2903
|
+
var modelSchema8 = TypeModel("model:FaceDetectorTask");
|
|
3587
2904
|
var TypeBoundingBox2 = {
|
|
3588
2905
|
type: "object",
|
|
3589
2906
|
properties: {
|
|
@@ -3656,7 +2973,7 @@ var FaceDetectorInputSchema = {
|
|
|
3656
2973
|
type: "object",
|
|
3657
2974
|
properties: {
|
|
3658
2975
|
image: TypeImageInput,
|
|
3659
|
-
model:
|
|
2976
|
+
model: modelSchema8,
|
|
3660
2977
|
minDetectionConfidence: {
|
|
3661
2978
|
type: "number",
|
|
3662
2979
|
minimum: 0,
|
|
@@ -3710,11 +3027,11 @@ class FaceDetectorTask extends AiVisionTask {
|
|
|
3710
3027
|
var faceDetector = (input, config) => {
|
|
3711
3028
|
return new FaceDetectorTask(config).run(input);
|
|
3712
3029
|
};
|
|
3713
|
-
|
|
3030
|
+
Workflow15.prototype.faceDetector = CreateWorkflow15(FaceDetectorTask);
|
|
3714
3031
|
|
|
3715
3032
|
// src/task/FaceLandmarkerTask.ts
|
|
3716
|
-
import { CreateWorkflow as
|
|
3717
|
-
var
|
|
3033
|
+
import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
|
|
3034
|
+
var modelSchema9 = TypeModel("model:FaceLandmarkerTask");
|
|
3718
3035
|
var TypeLandmark = {
|
|
3719
3036
|
type: "object",
|
|
3720
3037
|
properties: {
|
|
@@ -3786,7 +3103,7 @@ var FaceLandmarkerInputSchema = {
|
|
|
3786
3103
|
type: "object",
|
|
3787
3104
|
properties: {
|
|
3788
3105
|
image: TypeImageInput,
|
|
3789
|
-
model:
|
|
3106
|
+
model: modelSchema9,
|
|
3790
3107
|
numFaces: {
|
|
3791
3108
|
type: "number",
|
|
3792
3109
|
minimum: 1,
|
|
@@ -3872,11 +3189,11 @@ class FaceLandmarkerTask extends AiVisionTask {
|
|
|
3872
3189
|
var faceLandmarker = (input, config) => {
|
|
3873
3190
|
return new FaceLandmarkerTask(config).run(input);
|
|
3874
3191
|
};
|
|
3875
|
-
|
|
3192
|
+
Workflow16.prototype.faceLandmarker = CreateWorkflow16(FaceLandmarkerTask);
|
|
3876
3193
|
|
|
3877
3194
|
// src/task/GestureRecognizerTask.ts
|
|
3878
|
-
import { CreateWorkflow as
|
|
3879
|
-
var
|
|
3195
|
+
import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
|
|
3196
|
+
var modelSchema10 = TypeModel("model:GestureRecognizerTask");
|
|
3880
3197
|
var TypeLandmark2 = {
|
|
3881
3198
|
type: "object",
|
|
3882
3199
|
properties: {
|
|
@@ -3968,7 +3285,7 @@ var GestureRecognizerInputSchema = {
|
|
|
3968
3285
|
type: "object",
|
|
3969
3286
|
properties: {
|
|
3970
3287
|
image: TypeImageInput,
|
|
3971
|
-
model:
|
|
3288
|
+
model: modelSchema10,
|
|
3972
3289
|
numHands: {
|
|
3973
3290
|
type: "number",
|
|
3974
3291
|
minimum: 1,
|
|
@@ -4040,11 +3357,11 @@ class GestureRecognizerTask extends AiVisionTask {
|
|
|
4040
3357
|
var gestureRecognizer = (input, config) => {
|
|
4041
3358
|
return new GestureRecognizerTask(config).run(input);
|
|
4042
3359
|
};
|
|
4043
|
-
|
|
3360
|
+
Workflow17.prototype.gestureRecognizer = CreateWorkflow17(GestureRecognizerTask);
|
|
4044
3361
|
|
|
4045
3362
|
// src/task/HandLandmarkerTask.ts
|
|
4046
|
-
import { CreateWorkflow as
|
|
4047
|
-
var
|
|
3363
|
+
import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
|
|
3364
|
+
var modelSchema11 = TypeModel("model:HandLandmarkerTask");
|
|
4048
3365
|
var TypeLandmark3 = {
|
|
4049
3366
|
type: "object",
|
|
4050
3367
|
properties: {
|
|
@@ -4113,7 +3430,7 @@ var HandLandmarkerInputSchema = {
|
|
|
4113
3430
|
type: "object",
|
|
4114
3431
|
properties: {
|
|
4115
3432
|
image: TypeImageInput,
|
|
4116
|
-
model:
|
|
3433
|
+
model: modelSchema11,
|
|
4117
3434
|
numHands: {
|
|
4118
3435
|
type: "number",
|
|
4119
3436
|
minimum: 1,
|
|
@@ -4185,7 +3502,7 @@ class HandLandmarkerTask extends AiVisionTask {
|
|
|
4185
3502
|
var handLandmarker = (input, config) => {
|
|
4186
3503
|
return new HandLandmarkerTask(config).run(input);
|
|
4187
3504
|
};
|
|
4188
|
-
|
|
3505
|
+
Workflow18.prototype.handLandmarker = CreateWorkflow18(HandLandmarkerTask);
|
|
4189
3506
|
|
|
4190
3507
|
// src/task/HierarchicalChunkerTask.ts
|
|
4191
3508
|
import {
|
|
@@ -4194,9 +3511,9 @@ import {
|
|
|
4194
3511
|
getChildren as getChildren2,
|
|
4195
3512
|
hasChildren as hasChildren2
|
|
4196
3513
|
} from "@workglow/knowledge-base";
|
|
4197
|
-
import { CreateWorkflow as
|
|
3514
|
+
import { CreateWorkflow as CreateWorkflow19, Task as Task10, Workflow as Workflow19 } from "@workglow/task-graph";
|
|
4198
3515
|
import { uuid4 } from "@workglow/util";
|
|
4199
|
-
var
|
|
3516
|
+
var modelSchema12 = TypeModel("model", {
|
|
4200
3517
|
title: "Model",
|
|
4201
3518
|
description: "Model to use for token counting"
|
|
4202
3519
|
});
|
|
@@ -4242,7 +3559,7 @@ var inputSchema9 = {
|
|
|
4242
3559
|
description: "Strategy for chunking",
|
|
4243
3560
|
default: "hierarchical"
|
|
4244
3561
|
},
|
|
4245
|
-
model:
|
|
3562
|
+
model: modelSchema12
|
|
4246
3563
|
},
|
|
4247
3564
|
required: ["doc_id", "documentTree"],
|
|
4248
3565
|
additionalProperties: false
|
|
@@ -4277,7 +3594,7 @@ var outputSchema9 = {
|
|
|
4277
3594
|
additionalProperties: false
|
|
4278
3595
|
};
|
|
4279
3596
|
|
|
4280
|
-
class HierarchicalChunkerTask extends
|
|
3597
|
+
class HierarchicalChunkerTask extends Task10 {
|
|
4281
3598
|
static type = "HierarchicalChunkerTask";
|
|
4282
3599
|
static category = "Document";
|
|
4283
3600
|
static title = "Hierarchical Chunker";
|
|
@@ -4421,11 +3738,11 @@ class HierarchicalChunkerTask extends Task11 {
|
|
|
4421
3738
|
var hierarchicalChunker = (input, config) => {
|
|
4422
3739
|
return new HierarchicalChunkerTask(config).run(input);
|
|
4423
3740
|
};
|
|
4424
|
-
|
|
3741
|
+
Workflow19.prototype.hierarchicalChunker = CreateWorkflow19(HierarchicalChunkerTask);
|
|
4425
3742
|
|
|
4426
3743
|
// src/task/HierarchyJoinTask.ts
|
|
4427
3744
|
import { ChunkRecordArraySchema, TypeKnowledgeBase as TypeKnowledgeBase6 } from "@workglow/knowledge-base";
|
|
4428
|
-
import { CreateWorkflow as
|
|
3745
|
+
import { CreateWorkflow as CreateWorkflow20, Task as Task11, Workflow as Workflow20 } from "@workglow/task-graph";
|
|
4429
3746
|
var inputSchema10 = {
|
|
4430
3747
|
type: "object",
|
|
4431
3748
|
properties: {
|
|
@@ -4500,7 +3817,7 @@ var outputSchema10 = {
|
|
|
4500
3817
|
additionalProperties: false
|
|
4501
3818
|
};
|
|
4502
3819
|
|
|
4503
|
-
class HierarchyJoinTask extends
|
|
3820
|
+
class HierarchyJoinTask extends Task11 {
|
|
4504
3821
|
static type = "HierarchyJoinTask";
|
|
4505
3822
|
static category = "RAG";
|
|
4506
3823
|
static title = "Hierarchy Join";
|
|
@@ -4594,16 +3911,105 @@ class HierarchyJoinTask extends Task12 {
|
|
|
4594
3911
|
var hierarchyJoin = (input, config) => {
|
|
4595
3912
|
return new HierarchyJoinTask(config).run(input);
|
|
4596
3913
|
};
|
|
4597
|
-
|
|
3914
|
+
Workflow20.prototype.hierarchyJoin = CreateWorkflow20(HierarchyJoinTask);
|
|
3915
|
+
|
|
3916
|
+
// src/task/KbToDocumentsTask.ts
|
|
3917
|
+
import { TypeKnowledgeBase as TypeKnowledgeBase7 } from "@workglow/knowledge-base";
|
|
3918
|
+
import { CreateWorkflow as CreateWorkflow21, Task as Task12, Workflow as Workflow21 } from "@workglow/task-graph";
|
|
3919
|
+
var inputSchema11 = {
|
|
3920
|
+
type: "object",
|
|
3921
|
+
properties: {
|
|
3922
|
+
knowledgeBase: TypeKnowledgeBase7({
|
|
3923
|
+
title: "Knowledge Base",
|
|
3924
|
+
description: "The knowledge base instance to list documents from"
|
|
3925
|
+
}),
|
|
3926
|
+
onlyStale: {
|
|
3927
|
+
type: "boolean",
|
|
3928
|
+
title: "Only Stale",
|
|
3929
|
+
description: "If true, only return documents that have no chunks (need embedding)",
|
|
3930
|
+
default: true
|
|
3931
|
+
}
|
|
3932
|
+
},
|
|
3933
|
+
required: ["knowledgeBase"],
|
|
3934
|
+
additionalProperties: false
|
|
3935
|
+
};
|
|
3936
|
+
var outputSchema11 = {
|
|
3937
|
+
type: "object",
|
|
3938
|
+
properties: {
|
|
3939
|
+
doc_id: {
|
|
3940
|
+
type: "array",
|
|
3941
|
+
items: { type: "string" },
|
|
3942
|
+
title: "Document IDs",
|
|
3943
|
+
description: "Array of document IDs"
|
|
3944
|
+
},
|
|
3945
|
+
documentTree: {
|
|
3946
|
+
type: "array",
|
|
3947
|
+
items: { type: "object", additionalProperties: true },
|
|
3948
|
+
title: "Document Trees",
|
|
3949
|
+
description: "Array of document root nodes (parallel to doc_id)"
|
|
3950
|
+
},
|
|
3951
|
+
title: {
|
|
3952
|
+
type: "array",
|
|
3953
|
+
items: { type: "string" },
|
|
3954
|
+
title: "Titles",
|
|
3955
|
+
description: "Array of document titles (parallel to doc_id)"
|
|
3956
|
+
}
|
|
3957
|
+
},
|
|
3958
|
+
required: ["doc_id", "documentTree", "title"],
|
|
3959
|
+
additionalProperties: false
|
|
3960
|
+
};
|
|
3961
|
+
|
|
3962
|
+
class KbToDocumentsTask extends Task12 {
|
|
3963
|
+
static type = "KbToDocumentsTask";
|
|
3964
|
+
static category = "Vector Store";
|
|
3965
|
+
static title = "Knowledge Base to Documents";
|
|
3966
|
+
static description = "List documents from a knowledge base, optionally filtering to only those that need embedding";
|
|
3967
|
+
static cacheable = false;
|
|
3968
|
+
static inputSchema() {
|
|
3969
|
+
return inputSchema11;
|
|
3970
|
+
}
|
|
3971
|
+
static outputSchema() {
|
|
3972
|
+
return outputSchema11;
|
|
3973
|
+
}
|
|
3974
|
+
async execute(input, context) {
|
|
3975
|
+
const { knowledgeBase, onlyStale = true } = input;
|
|
3976
|
+
const kb = knowledgeBase;
|
|
3977
|
+
await context.updateProgress(1, "Listing documents");
|
|
3978
|
+
const allDocIds = await kb.listDocuments();
|
|
3979
|
+
const doc_id = [];
|
|
3980
|
+
const documentTree = [];
|
|
3981
|
+
const title = [];
|
|
3982
|
+
for (const id of allDocIds) {
|
|
3983
|
+
if (onlyStale) {
|
|
3984
|
+
const chunks = await kb.getChunksForDocument(id);
|
|
3985
|
+
if (chunks.length > 0) {
|
|
3986
|
+
continue;
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
const doc = await kb.getDocument(id);
|
|
3990
|
+
if (!doc) {
|
|
3991
|
+
continue;
|
|
3992
|
+
}
|
|
3993
|
+
doc_id.push(id);
|
|
3994
|
+
documentTree.push(doc.root);
|
|
3995
|
+
title.push(doc.metadata.title);
|
|
3996
|
+
}
|
|
3997
|
+
return { doc_id, documentTree, title };
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
var kbToDocuments = (input, config) => {
|
|
4001
|
+
return new KbToDocumentsTask(config).run(input);
|
|
4002
|
+
};
|
|
4003
|
+
Workflow21.prototype.kbToDocuments = CreateWorkflow21(KbToDocumentsTask);
|
|
4598
4004
|
|
|
4599
4005
|
// src/task/ImageClassificationTask.ts
|
|
4600
|
-
import { CreateWorkflow as
|
|
4601
|
-
var
|
|
4006
|
+
import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
|
|
4007
|
+
var modelSchema13 = TypeModel("model:ImageClassificationTask");
|
|
4602
4008
|
var ImageClassificationInputSchema = {
|
|
4603
4009
|
type: "object",
|
|
4604
4010
|
properties: {
|
|
4605
4011
|
image: TypeImageInput,
|
|
4606
|
-
model:
|
|
4012
|
+
model: modelSchema13,
|
|
4607
4013
|
categories: {
|
|
4608
4014
|
type: "array",
|
|
4609
4015
|
items: {
|
|
@@ -4657,19 +4063,19 @@ class ImageClassificationTask extends AiVisionTask {
|
|
|
4657
4063
|
var imageClassification = (input, config) => {
|
|
4658
4064
|
return new ImageClassificationTask(config).run(input);
|
|
4659
4065
|
};
|
|
4660
|
-
|
|
4066
|
+
Workflow22.prototype.imageClassification = CreateWorkflow22(ImageClassificationTask);
|
|
4661
4067
|
|
|
4662
4068
|
// src/task/ImageEmbeddingTask.ts
|
|
4663
|
-
import { CreateWorkflow as
|
|
4069
|
+
import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
|
|
4664
4070
|
import {
|
|
4665
4071
|
TypedArraySchema as TypedArraySchema7
|
|
4666
4072
|
} from "@workglow/util/schema";
|
|
4667
|
-
var
|
|
4073
|
+
var modelSchema14 = TypeModel("model:ImageEmbeddingTask");
|
|
4668
4074
|
var ImageEmbeddingInputSchema = {
|
|
4669
4075
|
type: "object",
|
|
4670
4076
|
properties: {
|
|
4671
4077
|
image: TypeSingleOrArray(TypeImageInput),
|
|
4672
|
-
model:
|
|
4078
|
+
model: modelSchema14
|
|
4673
4079
|
},
|
|
4674
4080
|
required: ["image", "model"],
|
|
4675
4081
|
additionalProperties: false
|
|
@@ -4701,16 +4107,16 @@ class ImageEmbeddingTask extends AiVisionTask {
|
|
|
4701
4107
|
var imageEmbedding = (input, config) => {
|
|
4702
4108
|
return new ImageEmbeddingTask(config).run(input);
|
|
4703
4109
|
};
|
|
4704
|
-
|
|
4110
|
+
Workflow23.prototype.imageEmbedding = CreateWorkflow23(ImageEmbeddingTask);
|
|
4705
4111
|
|
|
4706
4112
|
// src/task/ImageSegmentationTask.ts
|
|
4707
|
-
import { CreateWorkflow as
|
|
4708
|
-
var
|
|
4113
|
+
import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
|
|
4114
|
+
var modelSchema15 = TypeModel("model:ImageSegmentationTask");
|
|
4709
4115
|
var ImageSegmentationInputSchema = {
|
|
4710
4116
|
type: "object",
|
|
4711
4117
|
properties: {
|
|
4712
4118
|
image: TypeImageInput,
|
|
4713
|
-
model:
|
|
4119
|
+
model: modelSchema15,
|
|
4714
4120
|
threshold: {
|
|
4715
4121
|
type: "number",
|
|
4716
4122
|
title: "Threshold",
|
|
@@ -4789,11 +4195,11 @@ class ImageSegmentationTask extends AiVisionTask {
|
|
|
4789
4195
|
var imageSegmentation = (input, config) => {
|
|
4790
4196
|
return new ImageSegmentationTask(config).run(input);
|
|
4791
4197
|
};
|
|
4792
|
-
|
|
4198
|
+
Workflow24.prototype.imageSegmentation = CreateWorkflow24(ImageSegmentationTask);
|
|
4793
4199
|
|
|
4794
4200
|
// src/task/ImageToTextTask.ts
|
|
4795
|
-
import { CreateWorkflow as
|
|
4796
|
-
var
|
|
4201
|
+
import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
|
|
4202
|
+
var modelSchema16 = TypeModel("model:ImageToTextTask");
|
|
4797
4203
|
var generatedTextSchema = {
|
|
4798
4204
|
type: "string",
|
|
4799
4205
|
title: "Text",
|
|
@@ -4803,7 +4209,7 @@ var ImageToTextInputSchema = {
|
|
|
4803
4209
|
type: "object",
|
|
4804
4210
|
properties: {
|
|
4805
4211
|
image: TypeImageInput,
|
|
4806
|
-
model:
|
|
4212
|
+
model: modelSchema16,
|
|
4807
4213
|
maxTokens: {
|
|
4808
4214
|
type: "number",
|
|
4809
4215
|
title: "Max Tokens",
|
|
@@ -4844,18 +4250,18 @@ class ImageToTextTask extends AiVisionTask {
|
|
|
4844
4250
|
var imageToText = (input, config) => {
|
|
4845
4251
|
return new ImageToTextTask(config).run(input);
|
|
4846
4252
|
};
|
|
4847
|
-
|
|
4253
|
+
Workflow25.prototype.imageToText = CreateWorkflow25(ImageToTextTask);
|
|
4848
4254
|
|
|
4849
4255
|
// src/task/ModelInfoTask.ts
|
|
4850
|
-
import { CreateWorkflow as
|
|
4851
|
-
var
|
|
4256
|
+
import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
|
|
4257
|
+
var modelSchema17 = TypeModel("model");
|
|
4852
4258
|
var ModelInfoInputSchema = {
|
|
4853
4259
|
type: "object",
|
|
4854
4260
|
properties: {
|
|
4855
|
-
model:
|
|
4261
|
+
model: modelSchema17,
|
|
4856
4262
|
detail: {
|
|
4857
4263
|
type: "string",
|
|
4858
|
-
enum: ["cached_status", "files", "files_with_metadata"],
|
|
4264
|
+
enum: ["cached_status", "files", "files_with_metadata", "dimensions"],
|
|
4859
4265
|
default: "files_with_metadata"
|
|
4860
4266
|
}
|
|
4861
4267
|
},
|
|
@@ -4865,7 +4271,7 @@ var ModelInfoInputSchema = {
|
|
|
4865
4271
|
var ModelInfoOutputSchema = {
|
|
4866
4272
|
type: "object",
|
|
4867
4273
|
properties: {
|
|
4868
|
-
model:
|
|
4274
|
+
model: modelSchema17,
|
|
4869
4275
|
is_local: { type: "boolean" },
|
|
4870
4276
|
is_remote: { type: "boolean" },
|
|
4871
4277
|
supports_browser: { type: "boolean" },
|
|
@@ -4877,6 +4283,14 @@ var ModelInfoOutputSchema = {
|
|
|
4877
4283
|
type: "array",
|
|
4878
4284
|
items: { type: "string" },
|
|
4879
4285
|
description: "Available quantization variants (e.g. fp32, fp16, q8). Only present for models with quantization options."
|
|
4286
|
+
},
|
|
4287
|
+
native_dimensions: {
|
|
4288
|
+
type: "integer",
|
|
4289
|
+
description: "Native output vector dimensions. Only present when detail is 'dimensions' and the provider can determine them."
|
|
4290
|
+
},
|
|
4291
|
+
mrl: {
|
|
4292
|
+
type: "boolean",
|
|
4293
|
+
description: "Whether the model supports Matryoshka Representation Learning. Only present when detail is 'dimensions'."
|
|
4880
4294
|
}
|
|
4881
4295
|
},
|
|
4882
4296
|
required: [
|
|
@@ -4915,10 +4329,10 @@ class ModelInfoTask extends AiTask {
|
|
|
4915
4329
|
var modelInfo = (input, config) => {
|
|
4916
4330
|
return new ModelInfoTask(config).run(input);
|
|
4917
4331
|
};
|
|
4918
|
-
|
|
4332
|
+
Workflow26.prototype.modelInfo = CreateWorkflow26(ModelInfoTask);
|
|
4919
4333
|
|
|
4920
4334
|
// src/task/ModelSearchTask.ts
|
|
4921
|
-
import { CreateWorkflow as
|
|
4335
|
+
import { CreateWorkflow as CreateWorkflow27, Task as Task13, Workflow as Workflow27 } from "@workglow/task-graph";
|
|
4922
4336
|
var ModelSearchInputSchema = {
|
|
4923
4337
|
type: "object",
|
|
4924
4338
|
properties: {
|
|
@@ -5009,11 +4423,11 @@ class ModelSearchTask extends Task13 {
|
|
|
5009
4423
|
var modelSearch = (input, config) => {
|
|
5010
4424
|
return new ModelSearchTask(config).run(input);
|
|
5011
4425
|
};
|
|
5012
|
-
|
|
4426
|
+
Workflow27.prototype.modelSearch = CreateWorkflow27(ModelSearchTask);
|
|
5013
4427
|
|
|
5014
4428
|
// src/task/ObjectDetectionTask.ts
|
|
5015
|
-
import { CreateWorkflow as
|
|
5016
|
-
var
|
|
4429
|
+
import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
|
|
4430
|
+
var modelSchema18 = TypeModel("model:ObjectDetectionTask");
|
|
5017
4431
|
var detectionSchema = {
|
|
5018
4432
|
type: "object",
|
|
5019
4433
|
properties: {
|
|
@@ -5038,7 +4452,7 @@ var ObjectDetectionInputSchema = {
|
|
|
5038
4452
|
type: "object",
|
|
5039
4453
|
properties: {
|
|
5040
4454
|
image: TypeImageInput,
|
|
5041
|
-
model:
|
|
4455
|
+
model: modelSchema18,
|
|
5042
4456
|
labels: {
|
|
5043
4457
|
type: "array",
|
|
5044
4458
|
items: {
|
|
@@ -5092,11 +4506,11 @@ class ObjectDetectionTask extends AiVisionTask {
|
|
|
5092
4506
|
var objectDetection = (input, config) => {
|
|
5093
4507
|
return new ObjectDetectionTask(config).run(input);
|
|
5094
4508
|
};
|
|
5095
|
-
|
|
4509
|
+
Workflow28.prototype.objectDetection = CreateWorkflow28(ObjectDetectionTask);
|
|
5096
4510
|
|
|
5097
4511
|
// src/task/PoseLandmarkerTask.ts
|
|
5098
|
-
import { CreateWorkflow as
|
|
5099
|
-
var
|
|
4512
|
+
import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
|
|
4513
|
+
var modelSchema19 = TypeModel("model:PoseLandmarkerTask");
|
|
5100
4514
|
var TypePoseLandmark = {
|
|
5101
4515
|
type: "object",
|
|
5102
4516
|
properties: {
|
|
@@ -5175,7 +4589,7 @@ var PoseLandmarkerInputSchema = {
|
|
|
5175
4589
|
type: "object",
|
|
5176
4590
|
properties: {
|
|
5177
4591
|
image: TypeImageInput,
|
|
5178
|
-
model:
|
|
4592
|
+
model: modelSchema19,
|
|
5179
4593
|
numPoses: {
|
|
5180
4594
|
type: "number",
|
|
5181
4595
|
minimum: 1,
|
|
@@ -5254,17 +4668,17 @@ class PoseLandmarkerTask extends AiVisionTask {
|
|
|
5254
4668
|
var poseLandmarker = (input, config) => {
|
|
5255
4669
|
return new PoseLandmarkerTask(config).run(input);
|
|
5256
4670
|
};
|
|
5257
|
-
|
|
4671
|
+
Workflow29.prototype.poseLandmarker = CreateWorkflow29(PoseLandmarkerTask);
|
|
5258
4672
|
|
|
5259
4673
|
// src/task/QueryExpanderTask.ts
|
|
5260
|
-
import { CreateWorkflow as
|
|
4674
|
+
import { CreateWorkflow as CreateWorkflow30, Task as Task14, Workflow as Workflow30 } from "@workglow/task-graph";
|
|
5261
4675
|
var QueryExpansionMethod = {
|
|
5262
4676
|
MULTI_QUERY: "multi-query",
|
|
5263
4677
|
HYDE: "hyde",
|
|
5264
4678
|
SYNONYMS: "synonyms",
|
|
5265
4679
|
PARAPHRASE: "paraphrase"
|
|
5266
4680
|
};
|
|
5267
|
-
var
|
|
4681
|
+
var inputSchema12 = {
|
|
5268
4682
|
type: "object",
|
|
5269
4683
|
properties: {
|
|
5270
4684
|
query: {
|
|
@@ -5296,7 +4710,7 @@ var inputSchema11 = {
|
|
|
5296
4710
|
required: ["query"],
|
|
5297
4711
|
additionalProperties: false
|
|
5298
4712
|
};
|
|
5299
|
-
var
|
|
4713
|
+
var outputSchema12 = {
|
|
5300
4714
|
type: "object",
|
|
5301
4715
|
properties: {
|
|
5302
4716
|
query: {
|
|
@@ -5332,10 +4746,10 @@ class QueryExpanderTask extends Task14 {
|
|
|
5332
4746
|
static description = "Expand queries to improve retrieval coverage";
|
|
5333
4747
|
static cacheable = true;
|
|
5334
4748
|
static inputSchema() {
|
|
5335
|
-
return
|
|
4749
|
+
return inputSchema12;
|
|
5336
4750
|
}
|
|
5337
4751
|
static outputSchema() {
|
|
5338
|
-
return
|
|
4752
|
+
return outputSchema12;
|
|
5339
4753
|
}
|
|
5340
4754
|
async execute(input, context) {
|
|
5341
4755
|
const { query, method = QueryExpansionMethod.MULTI_QUERY, numVariations = 3 } = input;
|
|
@@ -5467,14 +4881,14 @@ class QueryExpanderTask extends Task14 {
|
|
|
5467
4881
|
var queryExpander = (input, config) => {
|
|
5468
4882
|
return new QueryExpanderTask(config).run(input);
|
|
5469
4883
|
};
|
|
5470
|
-
|
|
4884
|
+
Workflow30.prototype.queryExpander = CreateWorkflow30(QueryExpanderTask);
|
|
5471
4885
|
|
|
5472
4886
|
// src/task/RerankerTask.ts
|
|
5473
|
-
import { CreateWorkflow as
|
|
4887
|
+
import { CreateWorkflow as CreateWorkflow32, Task as Task15, Workflow as Workflow32 } from "@workglow/task-graph";
|
|
5474
4888
|
|
|
5475
4889
|
// src/task/TextClassificationTask.ts
|
|
5476
|
-
import { CreateWorkflow as
|
|
5477
|
-
var
|
|
4890
|
+
import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
|
|
4891
|
+
var modelSchema20 = TypeModel("model:TextClassificationTask");
|
|
5478
4892
|
var TextClassificationInputSchema = {
|
|
5479
4893
|
type: "object",
|
|
5480
4894
|
properties: {
|
|
@@ -5501,7 +4915,7 @@ var TextClassificationInputSchema = {
|
|
|
5501
4915
|
description: "The maximum number of categories to return",
|
|
5502
4916
|
"x-ui-group": "Configuration"
|
|
5503
4917
|
},
|
|
5504
|
-
model:
|
|
4918
|
+
model: modelSchema20
|
|
5505
4919
|
},
|
|
5506
4920
|
required: ["text", "model"],
|
|
5507
4921
|
additionalProperties: false
|
|
@@ -5551,10 +4965,10 @@ class TextClassificationTask extends AiTask {
|
|
|
5551
4965
|
var textClassification = (input, config) => {
|
|
5552
4966
|
return new TextClassificationTask(config).run(input);
|
|
5553
4967
|
};
|
|
5554
|
-
|
|
4968
|
+
Workflow31.prototype.textClassification = CreateWorkflow31(TextClassificationTask);
|
|
5555
4969
|
|
|
5556
4970
|
// src/task/RerankerTask.ts
|
|
5557
|
-
var
|
|
4971
|
+
var inputSchema13 = {
|
|
5558
4972
|
type: "object",
|
|
5559
4973
|
properties: {
|
|
5560
4974
|
query: {
|
|
@@ -5605,7 +5019,7 @@ var inputSchema12 = {
|
|
|
5605
5019
|
required: ["query", "chunks"],
|
|
5606
5020
|
additionalProperties: false
|
|
5607
5021
|
};
|
|
5608
|
-
var
|
|
5022
|
+
var outputSchema13 = {
|
|
5609
5023
|
type: "object",
|
|
5610
5024
|
properties: {
|
|
5611
5025
|
chunks: {
|
|
@@ -5653,10 +5067,10 @@ class RerankerTask extends Task15 {
|
|
|
5653
5067
|
static description = "Rerank retrieved chunks to improve relevance";
|
|
5654
5068
|
static cacheable = true;
|
|
5655
5069
|
static inputSchema() {
|
|
5656
|
-
return
|
|
5070
|
+
return inputSchema13;
|
|
5657
5071
|
}
|
|
5658
5072
|
static outputSchema() {
|
|
5659
|
-
return
|
|
5073
|
+
return outputSchema13;
|
|
5660
5074
|
}
|
|
5661
5075
|
async execute(input, context) {
|
|
5662
5076
|
const { query, chunks, scores = [], metadata = [], topK, method = "simple", model } = input;
|
|
@@ -5774,13 +5188,13 @@ class RerankerTask extends Task15 {
|
|
|
5774
5188
|
var reranker = (input, config) => {
|
|
5775
5189
|
return new RerankerTask(config).run(input);
|
|
5776
5190
|
};
|
|
5777
|
-
|
|
5191
|
+
Workflow32.prototype.reranker = CreateWorkflow32(RerankerTask);
|
|
5778
5192
|
|
|
5779
5193
|
// src/task/StructuralParserTask.ts
|
|
5780
5194
|
import { StructuralParser } from "@workglow/knowledge-base";
|
|
5781
|
-
import { CreateWorkflow as
|
|
5195
|
+
import { CreateWorkflow as CreateWorkflow33, Task as Task16, Workflow as Workflow33 } from "@workglow/task-graph";
|
|
5782
5196
|
import { uuid4 as uuid42 } from "@workglow/util";
|
|
5783
|
-
var
|
|
5197
|
+
var inputSchema14 = {
|
|
5784
5198
|
type: "object",
|
|
5785
5199
|
properties: {
|
|
5786
5200
|
text: {
|
|
@@ -5814,7 +5228,7 @@ var inputSchema13 = {
|
|
|
5814
5228
|
required: ["text", "title"],
|
|
5815
5229
|
additionalProperties: false
|
|
5816
5230
|
};
|
|
5817
|
-
var
|
|
5231
|
+
var outputSchema14 = {
|
|
5818
5232
|
type: "object",
|
|
5819
5233
|
properties: {
|
|
5820
5234
|
doc_id: {
|
|
@@ -5845,10 +5259,10 @@ class StructuralParserTask extends Task16 {
|
|
|
5845
5259
|
static description = "Parse documents into hierarchical tree structure";
|
|
5846
5260
|
static cacheable = true;
|
|
5847
5261
|
static inputSchema() {
|
|
5848
|
-
return
|
|
5262
|
+
return inputSchema14;
|
|
5849
5263
|
}
|
|
5850
5264
|
static outputSchema() {
|
|
5851
|
-
return
|
|
5265
|
+
return outputSchema14;
|
|
5852
5266
|
}
|
|
5853
5267
|
async execute(input, context) {
|
|
5854
5268
|
const { text, title, format = "auto", sourceUri, doc_id: providedDocId } = input;
|
|
@@ -5881,15 +5295,15 @@ class StructuralParserTask extends Task16 {
|
|
|
5881
5295
|
var structuralParser = (input, config) => {
|
|
5882
5296
|
return new StructuralParserTask(config).run(input);
|
|
5883
5297
|
};
|
|
5884
|
-
|
|
5298
|
+
Workflow33.prototype.structuralParser = CreateWorkflow33(StructuralParserTask);
|
|
5885
5299
|
|
|
5886
5300
|
// src/task/StructuredGenerationTask.ts
|
|
5887
|
-
import { CreateWorkflow as
|
|
5888
|
-
var
|
|
5301
|
+
import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
|
|
5302
|
+
var modelSchema21 = TypeModel("model:StructuredGenerationTask");
|
|
5889
5303
|
var StructuredGenerationInputSchema = {
|
|
5890
5304
|
type: "object",
|
|
5891
5305
|
properties: {
|
|
5892
|
-
model:
|
|
5306
|
+
model: modelSchema21,
|
|
5893
5307
|
prompt: {
|
|
5894
5308
|
type: "string",
|
|
5895
5309
|
title: "Prompt",
|
|
@@ -5952,17 +5366,17 @@ class StructuredGenerationTask extends StreamingAiTask {
|
|
|
5952
5366
|
var structuredGeneration = (input, config) => {
|
|
5953
5367
|
return new StructuredGenerationTask(config).run(input);
|
|
5954
5368
|
};
|
|
5955
|
-
|
|
5369
|
+
Workflow34.prototype.structuredGeneration = CreateWorkflow34(StructuredGenerationTask);
|
|
5956
5370
|
|
|
5957
5371
|
// src/task/TextChunkerTask.ts
|
|
5958
|
-
import { CreateWorkflow as
|
|
5372
|
+
import { CreateWorkflow as CreateWorkflow35, Task as Task17, Workflow as Workflow35 } from "@workglow/task-graph";
|
|
5959
5373
|
var ChunkingStrategy = {
|
|
5960
5374
|
FIXED: "fixed",
|
|
5961
5375
|
SENTENCE: "sentence",
|
|
5962
5376
|
PARAGRAPH: "paragraph",
|
|
5963
5377
|
SEMANTIC: "semantic"
|
|
5964
5378
|
};
|
|
5965
|
-
var
|
|
5379
|
+
var inputSchema15 = {
|
|
5966
5380
|
type: "object",
|
|
5967
5381
|
properties: {
|
|
5968
5382
|
text: {
|
|
@@ -5995,7 +5409,7 @@ var inputSchema14 = {
|
|
|
5995
5409
|
required: ["text"],
|
|
5996
5410
|
additionalProperties: false
|
|
5997
5411
|
};
|
|
5998
|
-
var
|
|
5412
|
+
var outputSchema15 = {
|
|
5999
5413
|
type: "object",
|
|
6000
5414
|
properties: {
|
|
6001
5415
|
chunks: {
|
|
@@ -6031,10 +5445,10 @@ class TextChunkerTask extends Task17 {
|
|
|
6031
5445
|
static description = "Splits text into chunks using various strategies (fixed, sentence, paragraph)";
|
|
6032
5446
|
static cacheable = true;
|
|
6033
5447
|
static inputSchema() {
|
|
6034
|
-
return
|
|
5448
|
+
return inputSchema15;
|
|
6035
5449
|
}
|
|
6036
5450
|
static outputSchema() {
|
|
6037
|
-
return
|
|
5451
|
+
return outputSchema15;
|
|
6038
5452
|
}
|
|
6039
5453
|
async execute(input, context) {
|
|
6040
5454
|
const { text, chunkSize = 512, chunkOverlap = 50, strategy = ChunkingStrategy.FIXED } = input;
|
|
@@ -6204,11 +5618,11 @@ class TextChunkerTask extends Task17 {
|
|
|
6204
5618
|
var textChunker = (input, config) => {
|
|
6205
5619
|
return new TextChunkerTask(config).run(input);
|
|
6206
5620
|
};
|
|
6207
|
-
|
|
5621
|
+
Workflow35.prototype.textChunker = CreateWorkflow35(TextChunkerTask);
|
|
6208
5622
|
|
|
6209
5623
|
// src/task/TextFillMaskTask.ts
|
|
6210
|
-
import { CreateWorkflow as
|
|
6211
|
-
var
|
|
5624
|
+
import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
|
|
5625
|
+
var modelSchema22 = TypeModel("model:TextFillMaskTask");
|
|
6212
5626
|
var TextFillMaskInputSchema = {
|
|
6213
5627
|
type: "object",
|
|
6214
5628
|
properties: {
|
|
@@ -6217,7 +5631,7 @@ var TextFillMaskInputSchema = {
|
|
|
6217
5631
|
title: "Text",
|
|
6218
5632
|
description: "The text with a mask token to fill"
|
|
6219
5633
|
},
|
|
6220
|
-
model:
|
|
5634
|
+
model: modelSchema22
|
|
6221
5635
|
},
|
|
6222
5636
|
required: ["text", "model"],
|
|
6223
5637
|
additionalProperties: false
|
|
@@ -6272,21 +5686,21 @@ class TextFillMaskTask extends AiTask {
|
|
|
6272
5686
|
var textFillMask = (input, config) => {
|
|
6273
5687
|
return new TextFillMaskTask(config).run(input);
|
|
6274
5688
|
};
|
|
6275
|
-
|
|
5689
|
+
Workflow36.prototype.textFillMask = CreateWorkflow36(TextFillMaskTask);
|
|
6276
5690
|
|
|
6277
5691
|
// src/task/TextGenerationTask.ts
|
|
6278
|
-
import { CreateWorkflow as
|
|
5692
|
+
import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
|
|
6279
5693
|
var generatedTextSchema2 = {
|
|
6280
5694
|
type: "string",
|
|
6281
5695
|
title: "Text",
|
|
6282
5696
|
description: "The generated text",
|
|
6283
5697
|
"x-stream": "append"
|
|
6284
5698
|
};
|
|
6285
|
-
var
|
|
5699
|
+
var modelSchema23 = TypeModel("model:TextGenerationTask");
|
|
6286
5700
|
var TextGenerationInputSchema = {
|
|
6287
5701
|
type: "object",
|
|
6288
5702
|
properties: {
|
|
6289
|
-
model:
|
|
5703
|
+
model: modelSchema23,
|
|
6290
5704
|
prompt: {
|
|
6291
5705
|
type: "string",
|
|
6292
5706
|
title: "Prompt",
|
|
@@ -6360,11 +5774,11 @@ class TextGenerationTask extends StreamingAiTask {
|
|
|
6360
5774
|
var textGeneration = (input, config) => {
|
|
6361
5775
|
return new TextGenerationTask(config).run(input);
|
|
6362
5776
|
};
|
|
6363
|
-
|
|
5777
|
+
Workflow37.prototype.textGeneration = CreateWorkflow37(TextGenerationTask);
|
|
6364
5778
|
|
|
6365
5779
|
// src/task/TextLanguageDetectionTask.ts
|
|
6366
|
-
import { CreateWorkflow as
|
|
6367
|
-
var
|
|
5780
|
+
import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
|
|
5781
|
+
var modelSchema24 = TypeModel("model:TextLanguageDetectionTask");
|
|
6368
5782
|
var TextLanguageDetectionInputSchema = {
|
|
6369
5783
|
type: "object",
|
|
6370
5784
|
properties: {
|
|
@@ -6381,7 +5795,7 @@ var TextLanguageDetectionInputSchema = {
|
|
|
6381
5795
|
title: "Max Languages",
|
|
6382
5796
|
description: "The maximum number of languages to return"
|
|
6383
5797
|
},
|
|
6384
|
-
model:
|
|
5798
|
+
model: modelSchema24
|
|
6385
5799
|
},
|
|
6386
5800
|
required: ["text", "model"],
|
|
6387
5801
|
additionalProperties: false
|
|
@@ -6431,10 +5845,10 @@ class TextLanguageDetectionTask extends AiTask {
|
|
|
6431
5845
|
var textLanguageDetection = (input, config) => {
|
|
6432
5846
|
return new TextLanguageDetectionTask(config).run(input);
|
|
6433
5847
|
};
|
|
6434
|
-
|
|
5848
|
+
Workflow38.prototype.textLanguageDetection = CreateWorkflow38(TextLanguageDetectionTask);
|
|
6435
5849
|
|
|
6436
5850
|
// src/task/TextQuestionAnswerTask.ts
|
|
6437
|
-
import { CreateWorkflow as
|
|
5851
|
+
import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
|
|
6438
5852
|
var contextSchema = {
|
|
6439
5853
|
type: "string",
|
|
6440
5854
|
title: "Context",
|
|
@@ -6451,13 +5865,13 @@ var textSchema = {
|
|
|
6451
5865
|
description: "The generated text",
|
|
6452
5866
|
"x-stream": "append"
|
|
6453
5867
|
};
|
|
6454
|
-
var
|
|
5868
|
+
var modelSchema25 = TypeModel("model:TextQuestionAnswerTask");
|
|
6455
5869
|
var TextQuestionAnswerInputSchema = {
|
|
6456
5870
|
type: "object",
|
|
6457
5871
|
properties: {
|
|
6458
5872
|
context: contextSchema,
|
|
6459
5873
|
question: questionSchema,
|
|
6460
|
-
model:
|
|
5874
|
+
model: modelSchema25
|
|
6461
5875
|
},
|
|
6462
5876
|
required: ["context", "question", "model"],
|
|
6463
5877
|
additionalProperties: false
|
|
@@ -6486,11 +5900,11 @@ class TextQuestionAnswerTask extends StreamingAiTask {
|
|
|
6486
5900
|
var textQuestionAnswer = (input, config) => {
|
|
6487
5901
|
return new TextQuestionAnswerTask(config).run(input);
|
|
6488
5902
|
};
|
|
6489
|
-
|
|
5903
|
+
Workflow39.prototype.textQuestionAnswer = CreateWorkflow39(TextQuestionAnswerTask);
|
|
6490
5904
|
|
|
6491
5905
|
// src/task/TextRewriterTask.ts
|
|
6492
|
-
import { CreateWorkflow as
|
|
6493
|
-
var
|
|
5906
|
+
import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
|
|
5907
|
+
var modelSchema26 = TypeModel("model:TextRewriterTask");
|
|
6494
5908
|
var TextRewriterInputSchema = {
|
|
6495
5909
|
type: "object",
|
|
6496
5910
|
properties: {
|
|
@@ -6504,7 +5918,7 @@ var TextRewriterInputSchema = {
|
|
|
6504
5918
|
title: "Prompt",
|
|
6505
5919
|
description: "The prompt to direct the rewriting"
|
|
6506
5920
|
},
|
|
6507
|
-
model:
|
|
5921
|
+
model: modelSchema26
|
|
6508
5922
|
},
|
|
6509
5923
|
required: ["text", "prompt", "model"],
|
|
6510
5924
|
additionalProperties: false
|
|
@@ -6538,11 +5952,11 @@ class TextRewriterTask extends StreamingAiTask {
|
|
|
6538
5952
|
var textRewriter = (input, config) => {
|
|
6539
5953
|
return new TextRewriterTask(config).run(input);
|
|
6540
5954
|
};
|
|
6541
|
-
|
|
5955
|
+
Workflow40.prototype.textRewriter = CreateWorkflow40(TextRewriterTask);
|
|
6542
5956
|
|
|
6543
5957
|
// src/task/TextTranslationTask.ts
|
|
6544
|
-
import { CreateWorkflow as
|
|
6545
|
-
var
|
|
5958
|
+
import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
|
|
5959
|
+
var modelSchema27 = TypeModel("model:TextTranslationTask");
|
|
6546
5960
|
var translationTextSchema = {
|
|
6547
5961
|
type: "string",
|
|
6548
5962
|
title: "Text",
|
|
@@ -6569,7 +5983,7 @@ var TextTranslationInputSchema = {
|
|
|
6569
5983
|
minLength: 2,
|
|
6570
5984
|
maxLength: 2
|
|
6571
5985
|
}),
|
|
6572
|
-
model:
|
|
5986
|
+
model: modelSchema27
|
|
6573
5987
|
},
|
|
6574
5988
|
required: ["text", "source_lang", "target_lang", "model"],
|
|
6575
5989
|
additionalProperties: false
|
|
@@ -6604,7 +6018,250 @@ class TextTranslationTask extends StreamingAiTask {
|
|
|
6604
6018
|
var textTranslation = (input, config) => {
|
|
6605
6019
|
return new TextTranslationTask(config).run(input);
|
|
6606
6020
|
};
|
|
6607
|
-
|
|
6021
|
+
Workflow41.prototype.textTranslation = CreateWorkflow41(TextTranslationTask);
|
|
6022
|
+
|
|
6023
|
+
// src/task/ToolCallingTask.ts
|
|
6024
|
+
import { CreateWorkflow as CreateWorkflow42, getTaskConstructors, Workflow as Workflow42 } from "@workglow/task-graph";
|
|
6025
|
+
import { makeFingerprint } from "@workglow/util";
|
|
6026
|
+
function taskTypesToTools(taskNames, registry) {
|
|
6027
|
+
const constructors = getTaskConstructors(registry);
|
|
6028
|
+
return taskNames.map((name) => {
|
|
6029
|
+
const ctor = constructors.get(name);
|
|
6030
|
+
if (!ctor) {
|
|
6031
|
+
throw new Error(`taskTypesToTools: Unknown task type "${name}" — not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
|
|
6032
|
+
}
|
|
6033
|
+
const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
|
|
6034
|
+
return {
|
|
6035
|
+
name: ctor.type,
|
|
6036
|
+
description: ctor.description ?? "",
|
|
6037
|
+
inputSchema: ctor.inputSchema(),
|
|
6038
|
+
outputSchema: ctor.outputSchema(),
|
|
6039
|
+
...configSchema ? { configSchema } : {},
|
|
6040
|
+
taskType: name
|
|
6041
|
+
};
|
|
6042
|
+
});
|
|
6043
|
+
}
|
|
6044
|
+
var ToolDefinitionSchema = {
|
|
6045
|
+
type: "object",
|
|
6046
|
+
properties: {
|
|
6047
|
+
name: {
|
|
6048
|
+
type: "string",
|
|
6049
|
+
title: "Name",
|
|
6050
|
+
description: "The tool name"
|
|
6051
|
+
},
|
|
6052
|
+
description: {
|
|
6053
|
+
type: "string",
|
|
6054
|
+
title: "Description",
|
|
6055
|
+
description: "A description of what the tool does"
|
|
6056
|
+
},
|
|
6057
|
+
inputSchema: {
|
|
6058
|
+
type: "object",
|
|
6059
|
+
title: "Input Schema",
|
|
6060
|
+
description: "JSON Schema describing the tool's input parameters",
|
|
6061
|
+
additionalProperties: true
|
|
6062
|
+
},
|
|
6063
|
+
outputSchema: {
|
|
6064
|
+
type: "object",
|
|
6065
|
+
title: "Output Schema",
|
|
6066
|
+
description: "JSON Schema describing what the tool returns",
|
|
6067
|
+
additionalProperties: true
|
|
6068
|
+
},
|
|
6069
|
+
configSchema: {
|
|
6070
|
+
type: "object",
|
|
6071
|
+
title: "Config Schema",
|
|
6072
|
+
description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
|
|
6073
|
+
additionalProperties: true
|
|
6074
|
+
},
|
|
6075
|
+
config: {
|
|
6076
|
+
type: "object",
|
|
6077
|
+
title: "Config",
|
|
6078
|
+
description: "Concrete configuration values for the backing task (not sent to the LLM)",
|
|
6079
|
+
additionalProperties: true
|
|
6080
|
+
}
|
|
6081
|
+
},
|
|
6082
|
+
required: ["name", "description", "inputSchema"],
|
|
6083
|
+
additionalProperties: true
|
|
6084
|
+
};
|
|
6085
|
+
var ToolCallSchema = {
|
|
6086
|
+
type: "object",
|
|
6087
|
+
properties: {
|
|
6088
|
+
id: {
|
|
6089
|
+
type: "string",
|
|
6090
|
+
title: "ID",
|
|
6091
|
+
description: "Unique identifier for this tool call"
|
|
6092
|
+
},
|
|
6093
|
+
name: {
|
|
6094
|
+
type: "string",
|
|
6095
|
+
title: "Name",
|
|
6096
|
+
description: "The name of the tool to invoke"
|
|
6097
|
+
},
|
|
6098
|
+
input: {
|
|
6099
|
+
type: "object",
|
|
6100
|
+
title: "Input",
|
|
6101
|
+
description: "The input arguments for the tool call",
|
|
6102
|
+
additionalProperties: true
|
|
6103
|
+
}
|
|
6104
|
+
},
|
|
6105
|
+
required: ["id", "name", "input"],
|
|
6106
|
+
additionalProperties: false
|
|
6107
|
+
};
|
|
6108
|
+
var modelSchema28 = TypeModel("model:ToolCallingTask");
|
|
6109
|
+
var ToolCallingInputSchema = {
|
|
6110
|
+
type: "object",
|
|
6111
|
+
properties: {
|
|
6112
|
+
model: modelSchema28,
|
|
6113
|
+
prompt: {
|
|
6114
|
+
oneOf: [
|
|
6115
|
+
{ type: "string", title: "Prompt", description: "The prompt to send to the model" },
|
|
6116
|
+
{
|
|
6117
|
+
type: "array",
|
|
6118
|
+
title: "Prompt",
|
|
6119
|
+
description: "The prompt as an array of strings or content blocks",
|
|
6120
|
+
items: {
|
|
6121
|
+
oneOf: [
|
|
6122
|
+
{ type: "string" },
|
|
6123
|
+
{
|
|
6124
|
+
type: "object",
|
|
6125
|
+
properties: {
|
|
6126
|
+
type: { type: "string", enum: ["text", "image", "audio"] }
|
|
6127
|
+
},
|
|
6128
|
+
required: ["type"],
|
|
6129
|
+
additionalProperties: true
|
|
6130
|
+
}
|
|
6131
|
+
]
|
|
6132
|
+
}
|
|
6133
|
+
}
|
|
6134
|
+
],
|
|
6135
|
+
title: "Prompt",
|
|
6136
|
+
description: "The prompt to send to the model"
|
|
6137
|
+
},
|
|
6138
|
+
systemPrompt: {
|
|
6139
|
+
type: "string",
|
|
6140
|
+
title: "System Prompt",
|
|
6141
|
+
description: "Optional system instructions for the model"
|
|
6142
|
+
},
|
|
6143
|
+
messages: {
|
|
6144
|
+
type: "array",
|
|
6145
|
+
title: "Messages",
|
|
6146
|
+
description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
|
|
6147
|
+
items: {
|
|
6148
|
+
type: "object",
|
|
6149
|
+
properties: {
|
|
6150
|
+
role: { type: "string", enum: ["user", "assistant", "tool"] },
|
|
6151
|
+
content: {}
|
|
6152
|
+
},
|
|
6153
|
+
required: ["role", "content"],
|
|
6154
|
+
additionalProperties: true
|
|
6155
|
+
}
|
|
6156
|
+
},
|
|
6157
|
+
tools: {
|
|
6158
|
+
type: "array",
|
|
6159
|
+
format: "tasks",
|
|
6160
|
+
title: "Tools",
|
|
6161
|
+
description: "Tool definitions available for the model to call",
|
|
6162
|
+
items: {
|
|
6163
|
+
oneOf: [
|
|
6164
|
+
{ type: "string", format: "tasks", description: "Task type name" },
|
|
6165
|
+
ToolDefinitionSchema
|
|
6166
|
+
]
|
|
6167
|
+
}
|
|
6168
|
+
},
|
|
6169
|
+
toolChoice: {
|
|
6170
|
+
type: "string",
|
|
6171
|
+
title: "Tool Choice",
|
|
6172
|
+
description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
|
|
6173
|
+
"x-ui-group": "Configuration"
|
|
6174
|
+
},
|
|
6175
|
+
maxTokens: {
|
|
6176
|
+
type: "number",
|
|
6177
|
+
title: "Max Tokens",
|
|
6178
|
+
description: "The maximum number of tokens to generate",
|
|
6179
|
+
minimum: 1,
|
|
6180
|
+
"x-ui-group": "Configuration"
|
|
6181
|
+
},
|
|
6182
|
+
temperature: {
|
|
6183
|
+
type: "number",
|
|
6184
|
+
title: "Temperature",
|
|
6185
|
+
description: "The temperature to use for sampling",
|
|
6186
|
+
minimum: 0,
|
|
6187
|
+
maximum: 2,
|
|
6188
|
+
"x-ui-group": "Configuration"
|
|
6189
|
+
}
|
|
6190
|
+
},
|
|
6191
|
+
required: ["model", "prompt", "tools"],
|
|
6192
|
+
additionalProperties: false
|
|
6193
|
+
};
|
|
6194
|
+
var ToolCallingOutputSchema = {
|
|
6195
|
+
type: "object",
|
|
6196
|
+
properties: {
|
|
6197
|
+
text: {
|
|
6198
|
+
type: "string",
|
|
6199
|
+
title: "Text",
|
|
6200
|
+
description: "Any text content generated by the model",
|
|
6201
|
+
"x-stream": "append"
|
|
6202
|
+
},
|
|
6203
|
+
toolCalls: {
|
|
6204
|
+
type: "array",
|
|
6205
|
+
items: ToolCallSchema,
|
|
6206
|
+
title: "Tool Calls",
|
|
6207
|
+
description: "Tool calls requested by the model",
|
|
6208
|
+
"x-stream": "object"
|
|
6209
|
+
}
|
|
6210
|
+
},
|
|
6211
|
+
required: ["text", "toolCalls"],
|
|
6212
|
+
additionalProperties: false
|
|
6213
|
+
};
|
|
6214
|
+
|
|
6215
|
+
class ToolCallingTask extends StreamingAiTask {
|
|
6216
|
+
static type = "ToolCallingTask";
|
|
6217
|
+
static category = "AI Text Model";
|
|
6218
|
+
static title = "Tool Calling";
|
|
6219
|
+
static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
|
|
6220
|
+
static inputSchema() {
|
|
6221
|
+
return ToolCallingInputSchema;
|
|
6222
|
+
}
|
|
6223
|
+
static outputSchema() {
|
|
6224
|
+
return ToolCallingOutputSchema;
|
|
6225
|
+
}
|
|
6226
|
+
_computedSessionId;
|
|
6227
|
+
async getJobInput(input) {
|
|
6228
|
+
const jobInput = await super.getJobInput(input);
|
|
6229
|
+
if (!jobInput.sessionId && input.tools && input.tools.length > 0) {
|
|
6230
|
+
jobInput.sessionId = await makeFingerprint({
|
|
6231
|
+
tools: input.tools,
|
|
6232
|
+
systemPrompt: input.systemPrompt,
|
|
6233
|
+
runnerId: this.runConfig.runnerId
|
|
6234
|
+
});
|
|
6235
|
+
this._computedSessionId = jobInput.sessionId;
|
|
6236
|
+
}
|
|
6237
|
+
return jobInput;
|
|
6238
|
+
}
|
|
6239
|
+
registerSessionDispose(input, context) {
|
|
6240
|
+
const sessionId = this._computedSessionId;
|
|
6241
|
+
if (!sessionId || !context.resourceScope)
|
|
6242
|
+
return;
|
|
6243
|
+
const model = input.model;
|
|
6244
|
+
if (!model || typeof model !== "object")
|
|
6245
|
+
return;
|
|
6246
|
+
const providerName = model.provider;
|
|
6247
|
+
context.resourceScope.register(`ai:session:${sessionId}`, async () => {
|
|
6248
|
+
await getAiProviderRegistry().disposeSession(providerName, sessionId);
|
|
6249
|
+
});
|
|
6250
|
+
}
|
|
6251
|
+
async execute(input, executeContext) {
|
|
6252
|
+
const result = await super.execute(input, executeContext);
|
|
6253
|
+
this.registerSessionDispose(input, executeContext);
|
|
6254
|
+
return result;
|
|
6255
|
+
}
|
|
6256
|
+
async* executeStream(input, context) {
|
|
6257
|
+
yield* super.executeStream(input, context);
|
|
6258
|
+
this.registerSessionDispose(input, context);
|
|
6259
|
+
}
|
|
6260
|
+
}
|
|
6261
|
+
var toolCalling = (input, config) => {
|
|
6262
|
+
return new ToolCallingTask(config).run(input);
|
|
6263
|
+
};
|
|
6264
|
+
Workflow42.prototype.toolCalling = CreateWorkflow42(ToolCallingTask);
|
|
6608
6265
|
|
|
6609
6266
|
// src/task/TopicSegmenterTask.ts
|
|
6610
6267
|
import { CreateWorkflow as CreateWorkflow43, Task as Task18, Workflow as Workflow43 } from "@workglow/task-graph";
|
|
@@ -6613,7 +6270,7 @@ var SegmentationMethod = {
|
|
|
6613
6270
|
EMBEDDING_SIMILARITY: "embedding-similarity",
|
|
6614
6271
|
HYBRID: "hybrid"
|
|
6615
6272
|
};
|
|
6616
|
-
var
|
|
6273
|
+
var inputSchema16 = {
|
|
6617
6274
|
type: "object",
|
|
6618
6275
|
properties: {
|
|
6619
6276
|
text: {
|
|
@@ -6654,7 +6311,7 @@ var inputSchema15 = {
|
|
|
6654
6311
|
required: ["text"],
|
|
6655
6312
|
additionalProperties: false
|
|
6656
6313
|
};
|
|
6657
|
-
var
|
|
6314
|
+
var outputSchema16 = {
|
|
6658
6315
|
type: "object",
|
|
6659
6316
|
properties: {
|
|
6660
6317
|
segments: {
|
|
@@ -6690,10 +6347,10 @@ class TopicSegmenterTask extends Task18 {
|
|
|
6690
6347
|
static cacheable = true;
|
|
6691
6348
|
static EMBEDDING_DIMENSIONS = 256;
|
|
6692
6349
|
static inputSchema() {
|
|
6693
|
-
return
|
|
6350
|
+
return inputSchema16;
|
|
6694
6351
|
}
|
|
6695
6352
|
static outputSchema() {
|
|
6696
|
-
return
|
|
6353
|
+
return outputSchema16;
|
|
6697
6354
|
}
|
|
6698
6355
|
async execute(input, context) {
|
|
6699
6356
|
const {
|
|
@@ -6891,11 +6548,11 @@ Workflow43.prototype.topicSegmenter = CreateWorkflow43(TopicSegmenterTask);
|
|
|
6891
6548
|
|
|
6892
6549
|
// src/task/UnloadModelTask.ts
|
|
6893
6550
|
import { CreateWorkflow as CreateWorkflow44, Workflow as Workflow44 } from "@workglow/task-graph";
|
|
6894
|
-
var
|
|
6551
|
+
var modelSchema29 = TypeModel("model");
|
|
6895
6552
|
var UnloadModelInputSchema = {
|
|
6896
6553
|
type: "object",
|
|
6897
6554
|
properties: {
|
|
6898
|
-
model:
|
|
6555
|
+
model: modelSchema29
|
|
6899
6556
|
},
|
|
6900
6557
|
required: ["model"],
|
|
6901
6558
|
additionalProperties: false
|
|
@@ -6903,7 +6560,7 @@ var UnloadModelInputSchema = {
|
|
|
6903
6560
|
var UnloadModelOutputSchema = {
|
|
6904
6561
|
type: "object",
|
|
6905
6562
|
properties: {
|
|
6906
|
-
model:
|
|
6563
|
+
model: modelSchema29
|
|
6907
6564
|
},
|
|
6908
6565
|
required: ["model"],
|
|
6909
6566
|
additionalProperties: false
|
|
@@ -6934,7 +6591,7 @@ import {
|
|
|
6934
6591
|
TensorType,
|
|
6935
6592
|
TypedArraySchema as TypedArraySchema8
|
|
6936
6593
|
} from "@workglow/util/schema";
|
|
6937
|
-
var
|
|
6594
|
+
var inputSchema17 = {
|
|
6938
6595
|
type: "object",
|
|
6939
6596
|
properties: {
|
|
6940
6597
|
vector: {
|
|
@@ -6971,7 +6628,7 @@ var inputSchema16 = {
|
|
|
6971
6628
|
required: ["vector", "targetType"],
|
|
6972
6629
|
additionalProperties: false
|
|
6973
6630
|
};
|
|
6974
|
-
var
|
|
6631
|
+
var outputSchema17 = {
|
|
6975
6632
|
type: "object",
|
|
6976
6633
|
properties: {
|
|
6977
6634
|
vector: {
|
|
@@ -7015,10 +6672,10 @@ class VectorQuantizeTask extends Task19 {
|
|
|
7015
6672
|
static description = "Quantize vectors to reduce storage and improve performance";
|
|
7016
6673
|
static cacheable = true;
|
|
7017
6674
|
static inputSchema() {
|
|
7018
|
-
return
|
|
6675
|
+
return inputSchema17;
|
|
7019
6676
|
}
|
|
7020
6677
|
static outputSchema() {
|
|
7021
|
-
return
|
|
6678
|
+
return outputSchema17;
|
|
7022
6679
|
}
|
|
7023
6680
|
async executeReactive(input) {
|
|
7024
6681
|
const { vector, targetType, normalize = true } = input;
|
|
@@ -7218,6 +6875,7 @@ var similarity = (input, config) => {
|
|
|
7218
6875
|
return new VectorSimilarityTask(config).run(input);
|
|
7219
6876
|
};
|
|
7220
6877
|
Workflow46.prototype.similarity = CreateWorkflow46(VectorSimilarityTask);
|
|
6878
|
+
|
|
7221
6879
|
// src/task/MessageConversion.ts
|
|
7222
6880
|
function getInputMessages(input) {
|
|
7223
6881
|
const messages = input.messages;
|
|
@@ -7418,7 +7076,6 @@ function toTextFlatMessages(input) {
|
|
|
7418
7076
|
// src/task/index.ts
|
|
7419
7077
|
var registerAiTasks = () => {
|
|
7420
7078
|
const tasks = [
|
|
7421
|
-
AgentTask,
|
|
7422
7079
|
BackgroundRemovalTask,
|
|
7423
7080
|
ChunkToVectorTask,
|
|
7424
7081
|
CountTokensTask,
|
|
@@ -7436,6 +7093,7 @@ var registerAiTasks = () => {
|
|
|
7436
7093
|
HandLandmarkerTask,
|
|
7437
7094
|
HierarchicalChunkerTask,
|
|
7438
7095
|
HierarchyJoinTask,
|
|
7096
|
+
KbToDocumentsTask,
|
|
7439
7097
|
ImageClassificationTask,
|
|
7440
7098
|
ImageEmbeddingTask,
|
|
7441
7099
|
ImageSegmentationTask,
|
|
@@ -7471,11 +7129,8 @@ var registerAiTasks = () => {
|
|
|
7471
7129
|
export {
|
|
7472
7130
|
vectorStoreSearch,
|
|
7473
7131
|
vectorQuantize,
|
|
7474
|
-
userMessage,
|
|
7475
7132
|
unloadModel,
|
|
7476
7133
|
topicSegmenter,
|
|
7477
|
-
toolSourceDefinitions,
|
|
7478
|
-
toolMessage,
|
|
7479
7134
|
toolCalling,
|
|
7480
7135
|
toTextFlatMessages,
|
|
7481
7136
|
toOpenAIMessages,
|
|
@@ -7504,43 +7159,32 @@ export {
|
|
|
7504
7159
|
objectDetection,
|
|
7505
7160
|
modelSearch,
|
|
7506
7161
|
modelInfo,
|
|
7162
|
+
kbToDocuments,
|
|
7507
7163
|
isAllowedToolName,
|
|
7508
7164
|
imageToText,
|
|
7509
7165
|
imageSegmentation,
|
|
7510
7166
|
imageEmbedding,
|
|
7511
7167
|
imageClassification,
|
|
7512
|
-
imageBlockFromDataUri,
|
|
7513
|
-
imageBlock,
|
|
7514
7168
|
hybridSearch,
|
|
7515
7169
|
hierarchyJoin,
|
|
7516
7170
|
hierarchicalChunker,
|
|
7517
|
-
hasToolCalls,
|
|
7518
7171
|
handLandmarker,
|
|
7519
7172
|
getGlobalModelRepository,
|
|
7520
7173
|
getAiProviderRegistry,
|
|
7521
7174
|
gestureRecognizer,
|
|
7522
|
-
findToolSource,
|
|
7523
7175
|
filterValidToolCalls,
|
|
7524
7176
|
faceLandmarker,
|
|
7525
7177
|
faceDetector,
|
|
7526
|
-
executeToolCalls,
|
|
7527
|
-
executeToolCall,
|
|
7528
7178
|
downloadModel,
|
|
7529
7179
|
documentUpsert,
|
|
7530
7180
|
documentEnricher,
|
|
7531
7181
|
countTokens,
|
|
7532
|
-
countAssistantToolUses,
|
|
7533
7182
|
contextBuilder,
|
|
7534
7183
|
chunkVectorUpsert,
|
|
7535
7184
|
chunkToVector,
|
|
7536
7185
|
chunkRetrieval,
|
|
7537
|
-
buildToolSources,
|
|
7538
7186
|
buildToolDescription,
|
|
7539
7187
|
backgroundRemoval,
|
|
7540
|
-
audioBlockFromDataUri,
|
|
7541
|
-
audioBlock,
|
|
7542
|
-
assistantMessage,
|
|
7543
|
-
agent,
|
|
7544
7188
|
VectorSimilarityTask,
|
|
7545
7189
|
VectorQuantizeTask,
|
|
7546
7190
|
UnloadModelTask,
|
|
@@ -7614,6 +7258,7 @@ export {
|
|
|
7614
7258
|
ModelInfoTask,
|
|
7615
7259
|
ModelConfigSchema,
|
|
7616
7260
|
MODEL_REPOSITORY,
|
|
7261
|
+
KbToDocumentsTask,
|
|
7617
7262
|
InMemoryModelRepository,
|
|
7618
7263
|
ImageToTextTask,
|
|
7619
7264
|
ImageToTextOutputSchema,
|
|
@@ -7645,6 +7290,7 @@ export {
|
|
|
7645
7290
|
DocumentUpsertTask,
|
|
7646
7291
|
DocumentEnricherTask,
|
|
7647
7292
|
DirectExecutionStrategy,
|
|
7293
|
+
DEFAULT_AI_PROVIDER_WORKER_IDLE_TIMEOUT_MS,
|
|
7648
7294
|
CountTokensTask,
|
|
7649
7295
|
CountTokensOutputSchema,
|
|
7650
7296
|
CountTokensInputSchema,
|
|
@@ -7662,10 +7308,7 @@ export {
|
|
|
7662
7308
|
AiTask,
|
|
7663
7309
|
AiProviderRegistry,
|
|
7664
7310
|
AiProvider,
|
|
7665
|
-
AiJob
|
|
7666
|
-
AgentTask,
|
|
7667
|
-
AgentOutputSchema,
|
|
7668
|
-
AgentInputSchema
|
|
7311
|
+
AiJob
|
|
7669
7312
|
};
|
|
7670
7313
|
|
|
7671
|
-
//# debugId=
|
|
7314
|
+
//# debugId=44C200F7AF4AF24D64756E2164756E21
|