@workglow/ai 0.0.126 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -47
- package/dist/browser.js +569 -1274
- package/dist/browser.js.map +56 -61
- package/dist/bun.js +569 -1274
- package/dist/bun.js.map +56 -61
- package/dist/common.d.ts +3 -1
- package/dist/common.d.ts.map +1 -1
- package/dist/execution/DirectExecutionStrategy.d.ts +20 -0
- package/dist/execution/DirectExecutionStrategy.d.ts.map +1 -0
- package/dist/execution/IAiExecutionStrategy.d.ts +33 -0
- package/dist/execution/IAiExecutionStrategy.d.ts.map +1 -0
- package/dist/execution/QueuedExecutionStrategy.d.ts +50 -0
- package/dist/execution/QueuedExecutionStrategy.d.ts.map +1 -0
- package/dist/job/AiJob.d.ts +6 -0
- package/dist/job/AiJob.d.ts.map +1 -1
- package/dist/node.js +569 -1274
- package/dist/node.js.map +56 -61
- package/dist/provider/AiProvider.d.ts +16 -2
- package/dist/provider/AiProvider.d.ts.map +1 -1
- package/dist/provider/AiProviderRegistry.d.ts +20 -0
- package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
- package/dist/provider/QueuedAiProvider.d.ts +23 -2
- package/dist/provider/QueuedAiProvider.d.ts.map +1 -1
- package/dist/task/BackgroundRemovalTask.d.ts +3 -3
- package/dist/task/BackgroundRemovalTask.d.ts.map +1 -1
- package/dist/task/ChunkRetrievalTask.d.ts +4 -4
- package/dist/task/ChunkRetrievalTask.d.ts.map +1 -1
- package/dist/task/ChunkToVectorTask.d.ts +4 -4
- package/dist/task/ChunkToVectorTask.d.ts.map +1 -1
- package/dist/task/ChunkVectorHybridSearchTask.d.ts +4 -4
- package/dist/task/ChunkVectorHybridSearchTask.d.ts.map +1 -1
- package/dist/task/ChunkVectorSearchTask.d.ts +4 -4
- package/dist/task/ChunkVectorSearchTask.d.ts.map +1 -1
- package/dist/task/ChunkVectorUpsertTask.d.ts +4 -4
- package/dist/task/ChunkVectorUpsertTask.d.ts.map +1 -1
- package/dist/task/ContextBuilderTask.d.ts +4 -4
- package/dist/task/ContextBuilderTask.d.ts.map +1 -1
- package/dist/task/CountTokensTask.d.ts +11 -29
- package/dist/task/CountTokensTask.d.ts.map +1 -1
- package/dist/task/DocumentEnricherTask.d.ts +4 -4
- package/dist/task/DocumentEnricherTask.d.ts.map +1 -1
- package/dist/task/DownloadModelTask.d.ts +5 -5
- package/dist/task/DownloadModelTask.d.ts.map +1 -1
- package/dist/task/FaceDetectorTask.d.ts +4 -4
- package/dist/task/FaceDetectorTask.d.ts.map +1 -1
- package/dist/task/FaceLandmarkerTask.d.ts +4 -4
- package/dist/task/FaceLandmarkerTask.d.ts.map +1 -1
- package/dist/task/GestureRecognizerTask.d.ts +4 -4
- package/dist/task/GestureRecognizerTask.d.ts.map +1 -1
- package/dist/task/HandLandmarkerTask.d.ts +4 -4
- package/dist/task/HandLandmarkerTask.d.ts.map +1 -1
- package/dist/task/HierarchicalChunkerTask.d.ts +4 -4
- package/dist/task/HierarchicalChunkerTask.d.ts.map +1 -1
- package/dist/task/HierarchyJoinTask.d.ts +4 -4
- package/dist/task/HierarchyJoinTask.d.ts.map +1 -1
- package/dist/task/ImageClassificationTask.d.ts +4 -4
- package/dist/task/ImageClassificationTask.d.ts.map +1 -1
- package/dist/task/ImageEmbeddingTask.d.ts +203 -89
- package/dist/task/ImageEmbeddingTask.d.ts.map +1 -1
- package/dist/task/ImageSegmentationTask.d.ts +4 -4
- package/dist/task/ImageSegmentationTask.d.ts.map +1 -1
- package/dist/task/ImageToTextTask.d.ts +4 -4
- package/dist/task/ImageToTextTask.d.ts.map +1 -1
- package/dist/task/ModelInfoTask.d.ts +5 -5
- package/dist/task/ModelInfoTask.d.ts.map +1 -1
- package/dist/task/ModelSearchTask.d.ts.map +1 -1
- package/dist/task/ObjectDetectionTask.d.ts +4 -4
- package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
- package/dist/task/PoseLandmarkerTask.d.ts +4 -4
- package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
- package/dist/task/QueryExpanderTask.d.ts +4 -4
- package/dist/task/QueryExpanderTask.d.ts.map +1 -1
- package/dist/task/RerankerTask.d.ts +4 -4
- package/dist/task/RerankerTask.d.ts.map +1 -1
- package/dist/task/StructuralParserTask.d.ts +4 -4
- package/dist/task/StructuralParserTask.d.ts.map +1 -1
- package/dist/task/StructuredGenerationTask.d.ts +4 -4
- package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
- package/dist/task/TextChunkerTask.d.ts +4 -4
- package/dist/task/TextChunkerTask.d.ts.map +1 -1
- package/dist/task/TextClassificationTask.d.ts +24 -62
- package/dist/task/TextClassificationTask.d.ts.map +1 -1
- package/dist/task/TextEmbeddingTask.d.ts +3 -3
- package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
- package/dist/task/TextFillMaskTask.d.ts +29 -73
- package/dist/task/TextFillMaskTask.d.ts.map +1 -1
- package/dist/task/TextGenerationTask.d.ts +13 -32
- package/dist/task/TextGenerationTask.d.ts.map +1 -1
- package/dist/task/TextLanguageDetectionTask.d.ts +24 -62
- package/dist/task/TextLanguageDetectionTask.d.ts.map +1 -1
- package/dist/task/TextNamedEntityRecognitionTask.d.ts +29 -73
- package/dist/task/TextNamedEntityRecognitionTask.d.ts.map +1 -1
- package/dist/task/TextQuestionAnswerTask.d.ts +17 -45
- package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
- package/dist/task/TextRewriterTask.d.ts +12 -31
- package/dist/task/TextRewriterTask.d.ts.map +1 -1
- package/dist/task/TextSummaryTask.d.ts +12 -31
- package/dist/task/TextSummaryTask.d.ts.map +1 -1
- package/dist/task/TextTranslationTask.d.ts +12 -31
- package/dist/task/TextTranslationTask.d.ts.map +1 -1
- package/dist/task/TopicSegmenterTask.d.ts +4 -4
- package/dist/task/TopicSegmenterTask.d.ts.map +1 -1
- package/dist/task/UnloadModelTask.d.ts +4 -4
- package/dist/task/UnloadModelTask.d.ts.map +1 -1
- package/dist/task/VectorQuantizeTask.d.ts +4 -4
- package/dist/task/VectorQuantizeTask.d.ts.map +1 -1
- package/dist/task/VectorSimilarityTask.d.ts +4 -4
- package/dist/task/VectorSimilarityTask.d.ts.map +1 -1
- package/dist/task/base/AiTask.d.ts +12 -31
- package/dist/task/base/AiTask.d.ts.map +1 -1
- package/dist/task/base/AiVisionTask.d.ts +7 -12
- package/dist/task/base/AiVisionTask.d.ts.map +1 -1
- package/dist/task/base/StreamingAiTask.d.ts +7 -4
- package/dist/task/base/StreamingAiTask.d.ts.map +1 -1
- package/dist/task/index.d.ts +1 -13
- package/dist/task/index.d.ts.map +1 -1
- package/dist/worker.d.ts +0 -2
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +220 -233
- package/dist/worker.js.map +7 -7
- package/package.json +11 -11
- package/dist/queue/createDefaultQueue.d.ts +0 -17
- package/dist/queue/createDefaultQueue.d.ts.map +0 -1
- package/dist/task/AgentTask.d.ts +0 -524
- package/dist/task/AgentTask.d.ts.map +0 -1
- package/dist/task/AgentTypes.d.ts +0 -181
- package/dist/task/AgentTypes.d.ts.map +0 -1
- package/dist/task/AgentUtils.d.ts +0 -50
- package/dist/task/AgentUtils.d.ts.map +0 -1
- package/dist/task/MessageConversion.d.ts +0 -52
- package/dist/task/MessageConversion.d.ts.map +0 -1
- package/dist/task/ToolCallingTask.d.ts +0 -385
- package/dist/task/ToolCallingTask.d.ts.map +0 -1
- package/dist/task/ToolCallingUtils.d.ts +0 -65
- package/dist/task/ToolCallingUtils.d.ts.map +0 -1
package/dist/browser.js
CHANGED
|
@@ -3,20 +3,36 @@ import {
|
|
|
3
3
|
AbortSignalJobError,
|
|
4
4
|
Job,
|
|
5
5
|
JobStatus,
|
|
6
|
-
PermanentJobError
|
|
6
|
+
PermanentJobError,
|
|
7
|
+
RetryableJobError
|
|
7
8
|
} from "@workglow/job-queue";
|
|
9
|
+
import { getLogger } from "@workglow/util/worker";
|
|
8
10
|
|
|
9
11
|
// src/provider/AiProviderRegistry.ts
|
|
10
12
|
import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util/worker";
|
|
11
|
-
|
|
12
13
|
class AiProviderRegistry {
|
|
13
14
|
runFnRegistry = new Map;
|
|
14
15
|
streamFnRegistry = new Map;
|
|
15
16
|
reactiveRunFnRegistry = new Map;
|
|
16
17
|
providers = new Map;
|
|
18
|
+
strategyResolvers = new Map;
|
|
19
|
+
defaultStrategy;
|
|
17
20
|
registerProvider(provider) {
|
|
18
21
|
this.providers.set(provider.name, provider);
|
|
19
22
|
}
|
|
23
|
+
unregisterProvider(name) {
|
|
24
|
+
this.providers.delete(name);
|
|
25
|
+
this.strategyResolvers.delete(name);
|
|
26
|
+
for (const [, providerMap] of this.runFnRegistry) {
|
|
27
|
+
providerMap.delete(name);
|
|
28
|
+
}
|
|
29
|
+
for (const [, providerMap] of this.streamFnRegistry) {
|
|
30
|
+
providerMap.delete(name);
|
|
31
|
+
}
|
|
32
|
+
for (const [, providerMap] of this.reactiveRunFnRegistry) {
|
|
33
|
+
providerMap.delete(name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
20
36
|
getProvider(name) {
|
|
21
37
|
return this.providers.get(name);
|
|
22
38
|
}
|
|
@@ -26,6 +42,18 @@ class AiProviderRegistry {
|
|
|
26
42
|
getInstalledProviderIds() {
|
|
27
43
|
return [...this.providers.keys()].sort();
|
|
28
44
|
}
|
|
45
|
+
registerStrategyResolver(providerName, resolver) {
|
|
46
|
+
this.strategyResolvers.set(providerName, resolver);
|
|
47
|
+
}
|
|
48
|
+
getStrategy(model) {
|
|
49
|
+
const resolver = this.strategyResolvers.get(model.provider);
|
|
50
|
+
if (resolver)
|
|
51
|
+
return resolver(model);
|
|
52
|
+
if (!this.defaultStrategy) {
|
|
53
|
+
this.defaultStrategy = new DirectExecutionStrategy;
|
|
54
|
+
}
|
|
55
|
+
return this.defaultStrategy;
|
|
56
|
+
}
|
|
29
57
|
getProviderIdsForTask(taskType) {
|
|
30
58
|
const taskMap = this.runFnRegistry.get(taskType);
|
|
31
59
|
if (!taskMap)
|
|
@@ -91,15 +119,16 @@ class AiProviderRegistry {
|
|
|
91
119
|
const taskTypeMap = this.runFnRegistry.get(taskType);
|
|
92
120
|
const runFn = taskTypeMap?.get(modelProvider);
|
|
93
121
|
if (!runFn) {
|
|
94
|
-
|
|
122
|
+
const installedProviders = this.getInstalledProviderIds();
|
|
123
|
+
const providersForTask = this.getProviderIdsForTask(taskType);
|
|
124
|
+
const hint = providersForTask.length > 0 ? ` Providers supporting "${taskType}": [${providersForTask.join(", ")}].` : installedProviders.length > 0 ? ` Installed providers: [${installedProviders.join(", ")}] (none support "${taskType}").` : " No providers are registered. Call provider.register() before running AI tasks.";
|
|
125
|
+
throw new Error(`No run function found for task type "${taskType}" and provider "${modelProvider}".${hint}`);
|
|
95
126
|
}
|
|
96
127
|
return runFn;
|
|
97
128
|
}
|
|
98
129
|
}
|
|
99
|
-
var providerRegistry;
|
|
130
|
+
var providerRegistry = new AiProviderRegistry;
|
|
100
131
|
function getAiProviderRegistry() {
|
|
101
|
-
if (!providerRegistry)
|
|
102
|
-
providerRegistry = new AiProviderRegistry;
|
|
103
132
|
return providerRegistry;
|
|
104
133
|
}
|
|
105
134
|
function setAiProviderRegistry(pr) {
|
|
@@ -107,6 +136,64 @@ function setAiProviderRegistry(pr) {
|
|
|
107
136
|
}
|
|
108
137
|
|
|
109
138
|
// src/job/AiJob.ts
|
|
139
|
+
var DEFAULT_AI_TIMEOUT_MS = 120000;
|
|
140
|
+
var LOCAL_MODEL_DEFAULT_TIMEOUT_MS = 600000;
|
|
141
|
+
function resolveAiJobTimeoutMs(aiProvider, explicitMs) {
|
|
142
|
+
if (explicitMs !== undefined) {
|
|
143
|
+
return explicitMs;
|
|
144
|
+
}
|
|
145
|
+
if (aiProvider === "LOCAL_LLAMACPP") {
|
|
146
|
+
return LOCAL_MODEL_DEFAULT_TIMEOUT_MS;
|
|
147
|
+
}
|
|
148
|
+
if (aiProvider === "HF_TRANSFORMERS_ONNX" || aiProvider.startsWith("HF_TRANSFORMERS_ONNX")) {
|
|
149
|
+
return LOCAL_MODEL_DEFAULT_TIMEOUT_MS;
|
|
150
|
+
}
|
|
151
|
+
return DEFAULT_AI_TIMEOUT_MS;
|
|
152
|
+
}
|
|
153
|
+
function classifyProviderError(err, taskType, provider) {
|
|
154
|
+
if (err instanceof PermanentJobError || err instanceof RetryableJobError || err instanceof AbortSignalJobError) {
|
|
155
|
+
return err;
|
|
156
|
+
}
|
|
157
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
158
|
+
const status = typeof err?.status === "number" ? err.status : typeof err?.statusCode === "number" ? err.statusCode : (() => {
|
|
159
|
+
const m = message.match(/\b([45]\d{2})\b/);
|
|
160
|
+
return m ? parseInt(m[1], 10) : undefined;
|
|
161
|
+
})();
|
|
162
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
163
|
+
return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider})`);
|
|
164
|
+
}
|
|
165
|
+
if (err instanceof DOMException && err.name === "TimeoutError") {
|
|
166
|
+
return new AbortSignalJobError(`Provider call timed out for ${taskType} (${provider})`);
|
|
167
|
+
}
|
|
168
|
+
if (message.includes("Pipeline download aborted") || message.includes("Operation aborted") || message.includes("operation was aborted") || message.includes("The operation was aborted")) {
|
|
169
|
+
return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider}): ${message}`);
|
|
170
|
+
}
|
|
171
|
+
if (message.startsWith("HFT_NULL_PROCESSOR:")) {
|
|
172
|
+
return new RetryableJobError(message);
|
|
173
|
+
}
|
|
174
|
+
if (status === 429) {
|
|
175
|
+
const retryAfterMatch = message.match(/retry.after[:\s]*(\d+)/i);
|
|
176
|
+
const retryMs = retryAfterMatch ? parseInt(retryAfterMatch[1], 10) * 1000 : 30000;
|
|
177
|
+
return new RetryableJobError(`Rate limited by ${provider} for ${taskType}: ${message}`, new Date(Date.now() + retryMs));
|
|
178
|
+
}
|
|
179
|
+
if (status === 401 || status === 403) {
|
|
180
|
+
return new PermanentJobError(`Authentication failed for ${provider} (${taskType}): ${message}`);
|
|
181
|
+
}
|
|
182
|
+
if (status === 400 || status === 404) {
|
|
183
|
+
return new PermanentJobError(`Invalid request to ${provider} for ${taskType}: ${message}`);
|
|
184
|
+
}
|
|
185
|
+
if (status && status >= 500) {
|
|
186
|
+
return new RetryableJobError(`Server error from ${provider} for ${taskType} (HTTP ${status}): ${message}`);
|
|
187
|
+
}
|
|
188
|
+
if (message.includes("ECONNREFUSED") || message.includes("ECONNRESET") || message.includes("ETIMEDOUT") || message.includes("fetch failed") || message.includes("network") || err instanceof TypeError && message.includes("fetch")) {
|
|
189
|
+
return new RetryableJobError(`Network error calling ${provider} for ${taskType}: ${message}`);
|
|
190
|
+
}
|
|
191
|
+
if (message.includes("timed out") || message.includes("timeout")) {
|
|
192
|
+
return new RetryableJobError(`Timeout calling ${provider} for ${taskType}: ${message}`);
|
|
193
|
+
}
|
|
194
|
+
return new PermanentJobError(`Provider ${provider} failed for ${taskType}: ${message}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
110
197
|
class AiJob extends Job {
|
|
111
198
|
async execute(input, context) {
|
|
112
199
|
if (context.signal.aborted || this.status === JobStatus.ABORTING) {
|
|
@@ -123,17 +210,19 @@ class AiJob extends Job {
|
|
|
123
210
|
});
|
|
124
211
|
const runFn = async () => {
|
|
125
212
|
const fn = getAiProviderRegistry().getDirectRunFn(input.aiProvider, input.taskType);
|
|
126
|
-
if (!fn) {
|
|
127
|
-
throw new PermanentJobError(`No run function found for task type ${input.taskType} and model provider ${input.aiProvider}`);
|
|
128
|
-
}
|
|
129
213
|
const model = input.taskInput.model;
|
|
130
|
-
if (context.signal
|
|
214
|
+
if (context.signal.aborted) {
|
|
131
215
|
throw new AbortSignalJobError("Job aborted");
|
|
132
216
|
}
|
|
133
|
-
|
|
217
|
+
const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
|
|
218
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
219
|
+
const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
|
|
220
|
+
return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema);
|
|
134
221
|
};
|
|
135
222
|
const runFnPromise = runFn();
|
|
136
223
|
return await Promise.race([runFnPromise, abortPromise]);
|
|
224
|
+
} catch (err) {
|
|
225
|
+
throw classifyProviderError(err, input.taskType, input.aiProvider);
|
|
137
226
|
} finally {
|
|
138
227
|
if (abortHandler) {
|
|
139
228
|
abortHandler();
|
|
@@ -151,35 +240,172 @@ class AiJob extends Job {
|
|
|
151
240
|
return;
|
|
152
241
|
}
|
|
153
242
|
const model = input.taskInput.model;
|
|
154
|
-
|
|
243
|
+
let lastFinishData;
|
|
244
|
+
const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
|
|
245
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
246
|
+
const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
|
|
247
|
+
try {
|
|
248
|
+
for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema)) {
|
|
249
|
+
if (event.type === "finish") {
|
|
250
|
+
lastFinishData = event.data;
|
|
251
|
+
}
|
|
252
|
+
yield event;
|
|
253
|
+
}
|
|
254
|
+
} catch (err) {
|
|
255
|
+
const logger = getLogger();
|
|
256
|
+
logger.warn(`AiJob: Stream error for ${input.taskType} (${input.aiProvider}): ${err instanceof Error ? err.message : String(err)}`);
|
|
257
|
+
if (lastFinishData === undefined) {
|
|
258
|
+
yield { type: "finish", data: {} };
|
|
259
|
+
}
|
|
260
|
+
throw classifyProviderError(err, input.taskType, input.aiProvider);
|
|
261
|
+
}
|
|
155
262
|
}
|
|
156
263
|
}
|
|
157
264
|
|
|
158
|
-
// src/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
265
|
+
// src/execution/DirectExecutionStrategy.ts
|
|
266
|
+
class DirectExecutionStrategy {
|
|
267
|
+
async execute(jobInput, context, runnerId) {
|
|
268
|
+
const job = new AiJob({
|
|
269
|
+
queueName: jobInput.aiProvider,
|
|
270
|
+
jobRunId: runnerId,
|
|
271
|
+
input: jobInput
|
|
272
|
+
});
|
|
273
|
+
const cleanup = job.onJobProgress((progress, message, details) => {
|
|
274
|
+
context.updateProgress(progress, message, details);
|
|
275
|
+
});
|
|
276
|
+
try {
|
|
277
|
+
return await job.execute(jobInput, {
|
|
278
|
+
signal: context.signal,
|
|
279
|
+
updateProgress: context.updateProgress
|
|
280
|
+
});
|
|
281
|
+
} finally {
|
|
282
|
+
cleanup();
|
|
283
|
+
}
|
|
166
284
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
285
|
+
async* executeStream(jobInput, context, runnerId) {
|
|
286
|
+
const job = new AiJob({
|
|
287
|
+
queueName: jobInput.aiProvider,
|
|
288
|
+
jobRunId: runnerId,
|
|
289
|
+
input: jobInput
|
|
290
|
+
});
|
|
291
|
+
yield* job.executeStream(jobInput, {
|
|
292
|
+
signal: context.signal,
|
|
293
|
+
updateProgress: context.updateProgress
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
abort() {}
|
|
171
297
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
298
|
+
|
|
299
|
+
// src/execution/QueuedExecutionStrategy.ts
|
|
300
|
+
import { ConcurrencyLimiter, JobQueueClient, JobQueueServer } from "@workglow/job-queue";
|
|
301
|
+
import { InMemoryQueueStorage } from "@workglow/storage";
|
|
302
|
+
import {
|
|
303
|
+
getTaskQueueRegistry,
|
|
304
|
+
TaskConfigurationError
|
|
305
|
+
} from "@workglow/task-graph";
|
|
306
|
+
class QueuedExecutionStrategy {
|
|
307
|
+
queueName;
|
|
308
|
+
concurrency;
|
|
309
|
+
autoCreate;
|
|
310
|
+
initPromise = null;
|
|
311
|
+
constructor(queueName, concurrency = 1, autoCreate = true) {
|
|
312
|
+
this.queueName = queueName;
|
|
313
|
+
this.concurrency = concurrency;
|
|
314
|
+
this.autoCreate = autoCreate;
|
|
315
|
+
}
|
|
316
|
+
async execute(jobInput, context, runnerId) {
|
|
317
|
+
if (context.signal.aborted) {
|
|
318
|
+
throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
319
|
+
}
|
|
320
|
+
const registeredQueue = await this.ensureQueue();
|
|
321
|
+
const { client } = registeredQueue;
|
|
322
|
+
const handle = await client.submit(jobInput, {
|
|
323
|
+
jobRunId: runnerId,
|
|
324
|
+
maxRetries: 10
|
|
325
|
+
});
|
|
326
|
+
const onAbort = () => {
|
|
327
|
+
handle.abort().catch((err) => {
|
|
328
|
+
console.warn(`Failed to abort queued job`, err);
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
context.signal.addEventListener("abort", onAbort);
|
|
332
|
+
const cleanupProgress = handle.onProgress((progress, message, details) => {
|
|
333
|
+
context.updateProgress(progress, message, details);
|
|
334
|
+
});
|
|
335
|
+
try {
|
|
336
|
+
if (context.signal.aborted) {
|
|
337
|
+
throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
338
|
+
}
|
|
339
|
+
const output = await handle.waitFor();
|
|
340
|
+
return output;
|
|
341
|
+
} finally {
|
|
342
|
+
cleanupProgress();
|
|
343
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
176
344
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
345
|
+
}
|
|
346
|
+
abort() {}
|
|
347
|
+
async* executeStream(jobInput, context, runnerId) {
|
|
348
|
+
const result = await this.execute(jobInput, context, runnerId);
|
|
349
|
+
yield { type: "finish", data: result };
|
|
350
|
+
}
|
|
351
|
+
ensureQueue() {
|
|
352
|
+
if (!this.initPromise) {
|
|
353
|
+
this.initPromise = this.createQueue().catch((err) => {
|
|
354
|
+
this.initPromise = null;
|
|
355
|
+
throw err;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
return this.initPromise;
|
|
359
|
+
}
|
|
360
|
+
async createQueue() {
|
|
361
|
+
const registry = getTaskQueueRegistry();
|
|
362
|
+
const existing = registry.getQueue(this.queueName);
|
|
363
|
+
if (existing) {
|
|
364
|
+
if (!existing.server.isRunning()) {
|
|
365
|
+
await existing.server.start();
|
|
366
|
+
}
|
|
367
|
+
return existing;
|
|
368
|
+
}
|
|
369
|
+
if (!this.autoCreate) {
|
|
370
|
+
throw new TaskConfigurationError(`Queue "${this.queueName}" is not registered and autoCreate is disabled. ` + `Register the queue before executing tasks with this provider.`);
|
|
371
|
+
}
|
|
372
|
+
const storage = new InMemoryQueueStorage(this.queueName);
|
|
373
|
+
await storage.setupDatabase();
|
|
374
|
+
const server = new JobQueueServer(AiJob, {
|
|
375
|
+
storage,
|
|
376
|
+
queueName: this.queueName,
|
|
377
|
+
limiter: new ConcurrencyLimiter(this.concurrency)
|
|
378
|
+
});
|
|
379
|
+
const client = new JobQueueClient({
|
|
380
|
+
storage,
|
|
381
|
+
queueName: this.queueName
|
|
180
382
|
});
|
|
181
|
-
|
|
182
|
-
|
|
383
|
+
client.attach(server);
|
|
384
|
+
const registeredQueue = {
|
|
385
|
+
server,
|
|
386
|
+
client,
|
|
387
|
+
storage
|
|
388
|
+
};
|
|
389
|
+
try {
|
|
390
|
+
registry.registerQueue(registeredQueue);
|
|
391
|
+
} catch (err) {
|
|
392
|
+
if (err instanceof Error && err.message.includes("already exists")) {
|
|
393
|
+
server.stop().catch((stopErr) => {
|
|
394
|
+
console.warn("QueuedExecutionStrategy: failed to stop raced-out queue server", stopErr);
|
|
395
|
+
});
|
|
396
|
+
const raced = registry.getQueue(this.queueName);
|
|
397
|
+
if (raced) {
|
|
398
|
+
if (!raced.server.isRunning()) {
|
|
399
|
+
await raced.server.start();
|
|
400
|
+
}
|
|
401
|
+
return raced;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
throw err;
|
|
405
|
+
}
|
|
406
|
+
await server.start();
|
|
407
|
+
return registeredQueue;
|
|
408
|
+
}
|
|
183
409
|
}
|
|
184
410
|
|
|
185
411
|
// src/model/InMemoryModelRepository.ts
|
|
@@ -352,6 +578,16 @@ import {
|
|
|
352
578
|
globalServiceRegistry as globalServiceRegistry3,
|
|
353
579
|
WORKER_MANAGER as WORKER_MANAGER2
|
|
354
580
|
} from "@workglow/util/worker";
|
|
581
|
+
function resolveAiProviderGpuQueueConcurrency(concurrency) {
|
|
582
|
+
if (concurrency === undefined) {
|
|
583
|
+
return 1;
|
|
584
|
+
}
|
|
585
|
+
if (typeof concurrency === "number") {
|
|
586
|
+
return concurrency;
|
|
587
|
+
}
|
|
588
|
+
return concurrency.gpu ?? 1;
|
|
589
|
+
}
|
|
590
|
+
|
|
355
591
|
class AiProvider {
|
|
356
592
|
tasks;
|
|
357
593
|
streamTasks;
|
|
@@ -411,7 +647,12 @@ class AiProvider {
|
|
|
411
647
|
}
|
|
412
648
|
}
|
|
413
649
|
registry.registerProvider(this);
|
|
414
|
-
|
|
650
|
+
try {
|
|
651
|
+
await this.afterRegister(options);
|
|
652
|
+
} catch (err) {
|
|
653
|
+
registry.unregisterProvider(this.name);
|
|
654
|
+
throw err;
|
|
655
|
+
}
|
|
415
656
|
}
|
|
416
657
|
registerOnWorkerServer(workerServer) {
|
|
417
658
|
if (!this.tasks) {
|
|
@@ -436,115 +677,28 @@ class AiProvider {
|
|
|
436
677
|
async afterRegister(_options) {}
|
|
437
678
|
}
|
|
438
679
|
|
|
439
|
-
// src/queue/createDefaultQueue.ts
|
|
440
|
-
import { ConcurrencyLimiter, JobQueueClient, JobQueueServer } from "@workglow/job-queue";
|
|
441
|
-
import { InMemoryQueueStorage } from "@workglow/storage";
|
|
442
|
-
import { getTaskQueueRegistry } from "@workglow/task-graph";
|
|
443
|
-
async function createDefaultQueue(providerName, concurrency) {
|
|
444
|
-
const storage = new InMemoryQueueStorage(providerName);
|
|
445
|
-
await storage.setupDatabase();
|
|
446
|
-
const server = new JobQueueServer(AiJob, {
|
|
447
|
-
storage,
|
|
448
|
-
queueName: providerName,
|
|
449
|
-
limiter: new ConcurrencyLimiter(concurrency)
|
|
450
|
-
});
|
|
451
|
-
const client = new JobQueueClient({
|
|
452
|
-
storage,
|
|
453
|
-
queueName: providerName
|
|
454
|
-
});
|
|
455
|
-
client.attach(server);
|
|
456
|
-
getTaskQueueRegistry().registerQueue({ server, client, storage });
|
|
457
|
-
await server.start();
|
|
458
|
-
}
|
|
459
|
-
|
|
460
680
|
// src/provider/QueuedAiProvider.ts
|
|
461
681
|
class QueuedAiProvider extends AiProvider {
|
|
682
|
+
queuedStrategy;
|
|
462
683
|
async afterRegister(options) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
684
|
+
const autoCreate = options.queue?.autoCreate !== false;
|
|
685
|
+
this.queuedStrategy = new QueuedExecutionStrategy(`${this.name}_gpu`, resolveAiProviderGpuQueueConcurrency(options.queue?.concurrency), autoCreate);
|
|
686
|
+
getAiProviderRegistry().registerStrategyResolver(this.name, (model) => this.getStrategyForModel(model));
|
|
687
|
+
}
|
|
688
|
+
createQueuedStrategy(queueName, concurrency, options) {
|
|
689
|
+
const autoCreate = options.queue?.autoCreate !== false;
|
|
690
|
+
return new QueuedExecutionStrategy(queueName, concurrency, autoCreate);
|
|
691
|
+
}
|
|
692
|
+
getStrategyForModel(_model) {
|
|
693
|
+
return this.queuedStrategy;
|
|
466
694
|
}
|
|
467
695
|
}
|
|
468
696
|
|
|
469
697
|
// src/task/index.ts
|
|
470
698
|
import { TaskRegistry } from "@workglow/task-graph";
|
|
471
699
|
|
|
472
|
-
// src/task/
|
|
473
|
-
import {
|
|
474
|
-
CreateWorkflow as CreateWorkflow2,
|
|
475
|
-
Task,
|
|
476
|
-
Workflow as Workflow2
|
|
477
|
-
} from "@workglow/task-graph";
|
|
478
|
-
import { getLogger as getLogger3 } from "@workglow/util";
|
|
479
|
-
|
|
480
|
-
// src/task/AgentTypes.ts
|
|
481
|
-
import { parseDataUri } from "@workglow/util/media";
|
|
482
|
-
function imageBlock(mimeType, data) {
|
|
483
|
-
return { type: "image", mimeType, data };
|
|
484
|
-
}
|
|
485
|
-
function audioBlock(mimeType, data) {
|
|
486
|
-
return { type: "audio", mimeType, data };
|
|
487
|
-
}
|
|
488
|
-
function imageBlockFromDataUri(dataUri) {
|
|
489
|
-
const { mimeType, base64 } = parseDataUri(dataUri);
|
|
490
|
-
return { type: "image", mimeType, data: base64 };
|
|
491
|
-
}
|
|
492
|
-
function audioBlockFromDataUri(dataUri) {
|
|
493
|
-
const { mimeType, base64 } = parseDataUri(dataUri);
|
|
494
|
-
return { type: "audio", mimeType, data: base64 };
|
|
495
|
-
}
|
|
496
|
-
function userMessage(prompt) {
|
|
497
|
-
return { role: "user", content: prompt };
|
|
498
|
-
}
|
|
499
|
-
function assistantMessage(text, toolCalls) {
|
|
500
|
-
const content = [];
|
|
501
|
-
if (text) {
|
|
502
|
-
content.push({ type: "text", text });
|
|
503
|
-
}
|
|
504
|
-
if (toolCalls) {
|
|
505
|
-
for (const tc of toolCalls) {
|
|
506
|
-
content.push({
|
|
507
|
-
type: "tool_use",
|
|
508
|
-
id: tc.id,
|
|
509
|
-
name: tc.name,
|
|
510
|
-
input: tc.input
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return { role: "assistant", content };
|
|
515
|
-
}
|
|
516
|
-
function toolMessage(results) {
|
|
517
|
-
return {
|
|
518
|
-
role: "tool",
|
|
519
|
-
content: results.map((r) => {
|
|
520
|
-
const jsonText = JSON.stringify(r.output);
|
|
521
|
-
const content = r.mediaContent && r.mediaContent.length > 0 ? [{ type: "text", text: jsonText }, ...r.mediaContent] : jsonText;
|
|
522
|
-
return {
|
|
523
|
-
type: "tool_result",
|
|
524
|
-
tool_use_id: r.toolCallId,
|
|
525
|
-
content,
|
|
526
|
-
is_error: r.isError || undefined
|
|
527
|
-
};
|
|
528
|
-
})
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
function toolSourceDefinitions(sources) {
|
|
532
|
-
return sources.map((s) => s.definition);
|
|
533
|
-
}
|
|
534
|
-
function findToolSource(sources, name) {
|
|
535
|
-
return sources.find((s) => s.definition.name === name);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// src/task/AgentUtils.ts
|
|
539
|
-
import { getTaskConstructors as getTaskConstructors2 } from "@workglow/task-graph";
|
|
540
|
-
import { getLogger as getLogger2 } from "@workglow/util";
|
|
541
|
-
|
|
542
|
-
// src/task/ToolCallingTask.ts
|
|
543
|
-
import {
|
|
544
|
-
CreateWorkflow,
|
|
545
|
-
getTaskConstructors,
|
|
546
|
-
Workflow
|
|
547
|
-
} from "@workglow/task-graph";
|
|
700
|
+
// src/task/BackgroundRemovalTask.ts
|
|
701
|
+
import { CreateWorkflow, Workflow } from "@workglow/task-graph";
|
|
548
702
|
|
|
549
703
|
// src/task/base/AiTaskSchemas.ts
|
|
550
704
|
var TypeLanguage = (annotations = {}) => ({
|
|
@@ -703,40 +857,56 @@ var TypeCategory = {
|
|
|
703
857
|
description: "Classification category with label and score"
|
|
704
858
|
};
|
|
705
859
|
|
|
706
|
-
// src/task/base/
|
|
707
|
-
import {
|
|
708
|
-
getStreamingPorts
|
|
709
|
-
} from "@workglow/task-graph";
|
|
860
|
+
// src/task/base/AiVisionTask.ts
|
|
861
|
+
import { convertImageDataToUseableForm } from "@workglow/util/media";
|
|
710
862
|
|
|
711
863
|
// src/task/base/AiTask.ts
|
|
712
864
|
import {
|
|
713
|
-
|
|
714
|
-
|
|
865
|
+
Task,
|
|
866
|
+
TaskConfigSchema,
|
|
867
|
+
TaskConfigurationError as TaskConfigurationError2,
|
|
715
868
|
hasStructuredOutput
|
|
716
869
|
} from "@workglow/task-graph";
|
|
717
870
|
function schemaFormat(schema) {
|
|
718
871
|
return typeof schema === "object" && schema !== null && "format" in schema ? schema.format : undefined;
|
|
719
872
|
}
|
|
873
|
+
var aiTaskConfigSchema = {
|
|
874
|
+
type: "object",
|
|
875
|
+
properties: {
|
|
876
|
+
...TaskConfigSchema["properties"]
|
|
877
|
+
},
|
|
878
|
+
additionalProperties: false
|
|
879
|
+
};
|
|
720
880
|
|
|
721
|
-
class AiTask extends
|
|
881
|
+
class AiTask extends Task {
|
|
722
882
|
static type = "AiTask";
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
this.jobClass = AiJob;
|
|
883
|
+
static configSchema() {
|
|
884
|
+
return aiTaskConfigSchema;
|
|
726
885
|
}
|
|
727
|
-
async
|
|
886
|
+
async execute(input, executeContext) {
|
|
728
887
|
const model = input.model;
|
|
729
888
|
if (!model || typeof model !== "object") {
|
|
730
|
-
throw new
|
|
889
|
+
throw new TaskConfigurationError2("AiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
|
|
731
890
|
}
|
|
891
|
+
const jobInput = await this.getJobInput(input);
|
|
892
|
+
const strategy = getAiProviderRegistry().getStrategy(model);
|
|
893
|
+
const output = await strategy.execute(jobInput, executeContext, this.runConfig.runnerId);
|
|
894
|
+
return output;
|
|
895
|
+
}
|
|
896
|
+
async getJobInput(input) {
|
|
897
|
+
const model = input.model;
|
|
732
898
|
const runtype = this.constructor.runtype ?? this.constructor.type;
|
|
733
899
|
const jobInput = {
|
|
734
900
|
taskType: runtype,
|
|
735
901
|
aiProvider: model.provider,
|
|
736
902
|
taskInput: input
|
|
737
903
|
};
|
|
904
|
+
const taskTimeoutMs = this.config.timeout;
|
|
905
|
+
if (typeof taskTimeoutMs === "number" && taskTimeoutMs > 0) {
|
|
906
|
+
jobInput.timeoutMs = taskTimeoutMs;
|
|
907
|
+
}
|
|
738
908
|
const inputOutputSchema = input.outputSchema;
|
|
739
|
-
if (inputOutputSchema && typeof inputOutputSchema === "object") {
|
|
909
|
+
if (inputOutputSchema && typeof inputOutputSchema === "object" && !Array.isArray(inputOutputSchema) && typeof inputOutputSchema.type === "string") {
|
|
740
910
|
jobInput.outputSchema = inputOutputSchema;
|
|
741
911
|
} else {
|
|
742
912
|
const taskOutputSchema = this.outputSchema();
|
|
@@ -750,7 +920,7 @@ class AiTask extends JobQueueTask {
|
|
|
750
920
|
const jobInput = await this.getJobInput(input);
|
|
751
921
|
const resolvedQueueName = queueName ?? await this.getDefaultQueueName(input);
|
|
752
922
|
if (!resolvedQueueName) {
|
|
753
|
-
throw new
|
|
923
|
+
throw new TaskConfigurationError2("AiTask: Unable to determine queue for AI provider");
|
|
754
924
|
}
|
|
755
925
|
const job = new AiJob({
|
|
756
926
|
queueName: resolvedQueueName,
|
|
@@ -778,7 +948,7 @@ class AiTask extends JobQueueTask {
|
|
|
778
948
|
const inputSchema = this.inputSchema();
|
|
779
949
|
if (typeof inputSchema === "boolean") {
|
|
780
950
|
if (inputSchema === false) {
|
|
781
|
-
throw new
|
|
951
|
+
throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
|
|
782
952
|
}
|
|
783
953
|
return true;
|
|
784
954
|
}
|
|
@@ -788,17 +958,18 @@ class AiTask extends JobQueueTask {
|
|
|
788
958
|
if (typeof model === "object" && model !== null) {
|
|
789
959
|
const tasks = model.tasks;
|
|
790
960
|
if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
|
|
791
|
-
|
|
961
|
+
const modelId = model.model_id ?? "(inline config)";
|
|
962
|
+
throw new TaskConfigurationError2(`AiTask: Model "${modelId}" for '${key}' is not compatible with task '${this.type}'. ` + `Model supports: [${tasks.join(", ")}]`);
|
|
792
963
|
}
|
|
793
964
|
} else if (model !== undefined && model !== null) {
|
|
794
|
-
throw new
|
|
965
|
+
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.`);
|
|
795
966
|
}
|
|
796
967
|
}
|
|
797
968
|
const modelPlainProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema) === "model");
|
|
798
969
|
for (const [key] of modelPlainProperties) {
|
|
799
970
|
const model = input[key];
|
|
800
971
|
if (model !== undefined && model !== null && typeof model !== "object") {
|
|
801
|
-
throw new
|
|
972
|
+
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.`);
|
|
802
973
|
}
|
|
803
974
|
}
|
|
804
975
|
return super.validateInput(input);
|
|
@@ -807,14 +978,14 @@ class AiTask extends JobQueueTask {
|
|
|
807
978
|
const inputSchema = this.inputSchema();
|
|
808
979
|
if (typeof inputSchema === "boolean") {
|
|
809
980
|
if (inputSchema === false) {
|
|
810
|
-
throw new
|
|
981
|
+
throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
|
|
811
982
|
}
|
|
812
983
|
return input;
|
|
813
984
|
}
|
|
814
985
|
const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
|
|
815
986
|
if (modelTaskProperties.length > 0) {
|
|
816
987
|
const modelRepo = registry.get(MODEL_REPOSITORY);
|
|
817
|
-
const taskModels = await modelRepo.findModelsByTask(this.type);
|
|
988
|
+
const taskModels = await modelRepo.findModelsByTask(this.type) ?? [];
|
|
818
989
|
for (const [key, propSchema] of modelTaskProperties) {
|
|
819
990
|
const requestedModel = input[key];
|
|
820
991
|
if (typeof requestedModel === "string") {
|
|
@@ -826,666 +997,29 @@ class AiTask extends JobQueueTask {
|
|
|
826
997
|
const model = requestedModel;
|
|
827
998
|
const tasks = model.tasks;
|
|
828
999
|
if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
|
|
829
|
-
input[key] = undefined;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
return input;
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
// src/task/base/StreamingAiTask.ts
|
|
839
|
-
class StreamingAiTask extends AiTask {
|
|
840
|
-
static type = "StreamingAiTask";
|
|
841
|
-
async* executeStream(input, context) {
|
|
842
|
-
const jobInput = await this.getJobInput(input);
|
|
843
|
-
const queueName = await this.getDefaultQueueName(input);
|
|
844
|
-
const job = new AiJob({
|
|
845
|
-
queueName: queueName ?? this.type,
|
|
846
|
-
jobRunId: this.runConfig.runnerId,
|
|
847
|
-
input: jobInput
|
|
848
|
-
});
|
|
849
|
-
const ports = getStreamingPorts(this.outputSchema());
|
|
850
|
-
const defaultPort = ports.length > 0 ? ports[0].port : "text";
|
|
851
|
-
for await (const event of job.executeStream(jobInput, {
|
|
852
|
-
signal: context.signal,
|
|
853
|
-
updateProgress: context.updateProgress.bind(this)
|
|
854
|
-
})) {
|
|
855
|
-
if (event.type === "text-delta") {
|
|
856
|
-
yield { ...event, port: event.port ?? defaultPort };
|
|
857
|
-
} else if (event.type === "object-delta") {
|
|
858
|
-
yield { ...event, port: event.port ?? defaultPort };
|
|
859
|
-
} else {
|
|
860
|
-
yield event;
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
// src/task/ToolCallingTask.ts
|
|
867
|
-
function taskTypesToTools(taskNames, registry) {
|
|
868
|
-
const constructors = getTaskConstructors(registry);
|
|
869
|
-
return taskNames.map((name) => {
|
|
870
|
-
const ctor = constructors.get(name);
|
|
871
|
-
if (!ctor) {
|
|
872
|
-
throw new Error(`taskTypesToTools: Unknown task type "${name}" — not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
|
|
873
|
-
}
|
|
874
|
-
const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
|
|
875
|
-
return {
|
|
876
|
-
name: ctor.type,
|
|
877
|
-
description: ctor.description ?? "",
|
|
878
|
-
inputSchema: ctor.inputSchema(),
|
|
879
|
-
outputSchema: ctor.outputSchema(),
|
|
880
|
-
...configSchema ? { configSchema } : {},
|
|
881
|
-
taskType: name
|
|
882
|
-
};
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
var ToolDefinitionSchema = {
|
|
886
|
-
type: "object",
|
|
887
|
-
properties: {
|
|
888
|
-
name: {
|
|
889
|
-
type: "string",
|
|
890
|
-
title: "Name",
|
|
891
|
-
description: "The tool name"
|
|
892
|
-
},
|
|
893
|
-
description: {
|
|
894
|
-
type: "string",
|
|
895
|
-
title: "Description",
|
|
896
|
-
description: "A description of what the tool does"
|
|
897
|
-
},
|
|
898
|
-
inputSchema: {
|
|
899
|
-
type: "object",
|
|
900
|
-
title: "Input Schema",
|
|
901
|
-
description: "JSON Schema describing the tool's input parameters",
|
|
902
|
-
additionalProperties: true
|
|
903
|
-
},
|
|
904
|
-
outputSchema: {
|
|
905
|
-
type: "object",
|
|
906
|
-
title: "Output Schema",
|
|
907
|
-
description: "JSON Schema describing what the tool returns",
|
|
908
|
-
additionalProperties: true
|
|
909
|
-
},
|
|
910
|
-
configSchema: {
|
|
911
|
-
type: "object",
|
|
912
|
-
title: "Config Schema",
|
|
913
|
-
description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
|
|
914
|
-
additionalProperties: true
|
|
915
|
-
},
|
|
916
|
-
config: {
|
|
917
|
-
type: "object",
|
|
918
|
-
title: "Config",
|
|
919
|
-
description: "Concrete configuration values for the backing task (not sent to the LLM)",
|
|
920
|
-
additionalProperties: true
|
|
921
|
-
}
|
|
922
|
-
},
|
|
923
|
-
required: ["name", "description", "inputSchema"],
|
|
924
|
-
additionalProperties: true
|
|
925
|
-
};
|
|
926
|
-
var ToolCallSchema = {
|
|
927
|
-
type: "object",
|
|
928
|
-
properties: {
|
|
929
|
-
id: {
|
|
930
|
-
type: "string",
|
|
931
|
-
title: "ID",
|
|
932
|
-
description: "Unique identifier for this tool call"
|
|
933
|
-
},
|
|
934
|
-
name: {
|
|
935
|
-
type: "string",
|
|
936
|
-
title: "Name",
|
|
937
|
-
description: "The name of the tool to invoke"
|
|
938
|
-
},
|
|
939
|
-
input: {
|
|
940
|
-
type: "object",
|
|
941
|
-
title: "Input",
|
|
942
|
-
description: "The input arguments for the tool call",
|
|
943
|
-
additionalProperties: true
|
|
944
|
-
}
|
|
945
|
-
},
|
|
946
|
-
required: ["id", "name", "input"],
|
|
947
|
-
additionalProperties: false
|
|
948
|
-
};
|
|
949
|
-
var modelSchema = TypeModel("model:ToolCallingTask");
|
|
950
|
-
var ToolCallingInputSchema = {
|
|
951
|
-
type: "object",
|
|
952
|
-
properties: {
|
|
953
|
-
model: modelSchema,
|
|
954
|
-
prompt: {
|
|
955
|
-
oneOf: [
|
|
956
|
-
{ type: "string", title: "Prompt", description: "The prompt to send to the model" },
|
|
957
|
-
{
|
|
958
|
-
type: "array",
|
|
959
|
-
title: "Prompt",
|
|
960
|
-
description: "The prompt as an array of strings or content blocks",
|
|
961
|
-
items: {
|
|
962
|
-
oneOf: [
|
|
963
|
-
{ type: "string" },
|
|
964
|
-
{
|
|
965
|
-
type: "object",
|
|
966
|
-
properties: {
|
|
967
|
-
type: { type: "string", enum: ["text", "image", "audio"] }
|
|
968
|
-
},
|
|
969
|
-
required: ["type"],
|
|
970
|
-
additionalProperties: true
|
|
971
|
-
}
|
|
972
|
-
]
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
],
|
|
976
|
-
title: "Prompt",
|
|
977
|
-
description: "The prompt to send to the model"
|
|
978
|
-
},
|
|
979
|
-
systemPrompt: {
|
|
980
|
-
type: "string",
|
|
981
|
-
title: "System Prompt",
|
|
982
|
-
description: "Optional system instructions for the model"
|
|
983
|
-
},
|
|
984
|
-
messages: {
|
|
985
|
-
type: "array",
|
|
986
|
-
title: "Messages",
|
|
987
|
-
description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
|
|
988
|
-
items: {
|
|
989
|
-
type: "object",
|
|
990
|
-
properties: {
|
|
991
|
-
role: { type: "string", enum: ["user", "assistant", "tool"] },
|
|
992
|
-
content: {}
|
|
993
|
-
},
|
|
994
|
-
required: ["role", "content"],
|
|
995
|
-
additionalProperties: true
|
|
996
|
-
}
|
|
997
|
-
},
|
|
998
|
-
tools: {
|
|
999
|
-
type: "array",
|
|
1000
|
-
format: "tasks",
|
|
1001
|
-
title: "Tools",
|
|
1002
|
-
description: "Tool definitions available for the model to call",
|
|
1003
|
-
items: {
|
|
1004
|
-
oneOf: [
|
|
1005
|
-
{ type: "string", format: "tasks", description: "Task type name" },
|
|
1006
|
-
ToolDefinitionSchema
|
|
1007
|
-
]
|
|
1008
|
-
}
|
|
1009
|
-
},
|
|
1010
|
-
toolChoice: {
|
|
1011
|
-
type: "string",
|
|
1012
|
-
title: "Tool Choice",
|
|
1013
|
-
description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
|
|
1014
|
-
"x-ui-group": "Configuration"
|
|
1015
|
-
},
|
|
1016
|
-
maxTokens: {
|
|
1017
|
-
type: "number",
|
|
1018
|
-
title: "Max Tokens",
|
|
1019
|
-
description: "The maximum number of tokens to generate",
|
|
1020
|
-
minimum: 1,
|
|
1021
|
-
"x-ui-group": "Configuration"
|
|
1022
|
-
},
|
|
1023
|
-
temperature: {
|
|
1024
|
-
type: "number",
|
|
1025
|
-
title: "Temperature",
|
|
1026
|
-
description: "The temperature to use for sampling",
|
|
1027
|
-
minimum: 0,
|
|
1028
|
-
maximum: 2,
|
|
1029
|
-
"x-ui-group": "Configuration"
|
|
1030
|
-
}
|
|
1031
|
-
},
|
|
1032
|
-
required: ["model", "prompt", "tools"],
|
|
1033
|
-
additionalProperties: false
|
|
1034
|
-
};
|
|
1035
|
-
var ToolCallingOutputSchema = {
|
|
1036
|
-
type: "object",
|
|
1037
|
-
properties: {
|
|
1038
|
-
text: TypeSingleOrArray({
|
|
1039
|
-
type: "string",
|
|
1040
|
-
title: "Text",
|
|
1041
|
-
description: "Any text content generated by the model",
|
|
1042
|
-
"x-stream": "append"
|
|
1043
|
-
}),
|
|
1044
|
-
toolCalls: TypeSingleOrArray({
|
|
1045
|
-
...ToolCallSchema,
|
|
1046
|
-
"x-stream": "object"
|
|
1047
|
-
})
|
|
1048
|
-
},
|
|
1049
|
-
required: ["text", "toolCalls"],
|
|
1050
|
-
additionalProperties: false
|
|
1051
|
-
};
|
|
1052
|
-
|
|
1053
|
-
class ToolCallingTask extends StreamingAiTask {
|
|
1054
|
-
static type = "ToolCallingTask";
|
|
1055
|
-
static category = "AI Text Model";
|
|
1056
|
-
static title = "Tool Calling";
|
|
1057
|
-
static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
|
|
1058
|
-
static inputSchema() {
|
|
1059
|
-
return ToolCallingInputSchema;
|
|
1060
|
-
}
|
|
1061
|
-
static outputSchema() {
|
|
1062
|
-
return ToolCallingOutputSchema;
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
var toolCalling = (input, config) => {
|
|
1066
|
-
return new ToolCallingTask({}, config).run(input);
|
|
1067
|
-
};
|
|
1068
|
-
Workflow.prototype.toolCalling = CreateWorkflow(ToolCallingTask);
|
|
1069
|
-
|
|
1070
|
-
// src/task/AgentUtils.ts
|
|
1071
|
-
function buildToolSources(tools, registry) {
|
|
1072
|
-
if (!tools || tools.length === 0)
|
|
1073
|
-
return [];
|
|
1074
|
-
const stringNames = tools.filter((t) => typeof t === "string");
|
|
1075
|
-
const resolvedDefs = new Map(taskTypesToTools(stringNames, registry).map((d) => [d.taskType, d]));
|
|
1076
|
-
const constructors = getTaskConstructors2(registry);
|
|
1077
|
-
const sources = [];
|
|
1078
|
-
for (const tool of tools) {
|
|
1079
|
-
if (typeof tool === "string") {
|
|
1080
|
-
const def = resolvedDefs.get(tool);
|
|
1081
|
-
if (def) {
|
|
1082
|
-
const { taskType, ...definition } = def;
|
|
1083
|
-
sources.push({
|
|
1084
|
-
type: "registry",
|
|
1085
|
-
definition,
|
|
1086
|
-
taskType
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
} else if (tool.execute) {
|
|
1090
|
-
const { execute, configSchema: _cs, config: _c, ...definition } = tool;
|
|
1091
|
-
sources.push({
|
|
1092
|
-
type: "function",
|
|
1093
|
-
definition,
|
|
1094
|
-
run: execute
|
|
1095
|
-
});
|
|
1096
|
-
} else {
|
|
1097
|
-
const ctor = constructors.get(tool.name);
|
|
1098
|
-
if (ctor) {
|
|
1099
|
-
const { execute: _e, configSchema: _cs, config: _c, ...definition } = tool;
|
|
1100
|
-
sources.push({
|
|
1101
|
-
type: "registry",
|
|
1102
|
-
definition,
|
|
1103
|
-
taskType: tool.name,
|
|
1104
|
-
config: tool.config
|
|
1105
|
-
});
|
|
1106
|
-
} else {
|
|
1107
|
-
const { execute: _e, configSchema: _cs, config: _c, ...definition } = tool;
|
|
1108
|
-
sources.push({
|
|
1109
|
-
type: "function",
|
|
1110
|
-
definition,
|
|
1111
|
-
run: async () => {
|
|
1112
|
-
throw new Error(`No executor registered for tool "${tool.name}"`);
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
return sources;
|
|
1119
|
-
}
|
|
1120
|
-
async function executeToolCall(toolCall, sources, context, hooks) {
|
|
1121
|
-
const source = findToolSource(sources, toolCall.name);
|
|
1122
|
-
if (!source) {
|
|
1123
|
-
getLogger2().warn(`AgentTask: Unknown tool "${toolCall.name}" — not found in tool sources`);
|
|
1124
|
-
return {
|
|
1125
|
-
toolCallId: toolCall.id,
|
|
1126
|
-
toolName: toolCall.name,
|
|
1127
|
-
output: { error: `Unknown tool: ${toolCall.name}` },
|
|
1128
|
-
isError: true
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
let effectiveCall = toolCall;
|
|
1132
|
-
if (hooks?.beforeToolCall) {
|
|
1133
|
-
const decision = await hooks.beforeToolCall(toolCall, source);
|
|
1134
|
-
if (decision.action === "deny") {
|
|
1135
|
-
return {
|
|
1136
|
-
toolCallId: toolCall.id,
|
|
1137
|
-
toolName: toolCall.name,
|
|
1138
|
-
output: { error: decision.reason ?? "Tool call denied by hook" },
|
|
1139
|
-
isError: true
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
if (decision.action === "modify") {
|
|
1143
|
-
effectiveCall = { ...toolCall, input: decision.input };
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
try {
|
|
1147
|
-
let output;
|
|
1148
|
-
switch (source.type) {
|
|
1149
|
-
case "registry": {
|
|
1150
|
-
const ctor = getTaskConstructors2(context.registry).get(source.taskType);
|
|
1151
|
-
if (!ctor) {
|
|
1152
|
-
throw new Error(`Task type "${source.taskType}" not found in TaskRegistry`);
|
|
1153
|
-
}
|
|
1154
|
-
const taskConfig = source.config ?? {};
|
|
1155
|
-
const task = context.own(new ctor({}, taskConfig));
|
|
1156
|
-
output = await task.run(effectiveCall.input) ?? {};
|
|
1157
|
-
break;
|
|
1158
|
-
}
|
|
1159
|
-
case "function": {
|
|
1160
|
-
output = await source.run(effectiveCall.input);
|
|
1161
|
-
break;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
let result = {
|
|
1165
|
-
toolCallId: toolCall.id,
|
|
1166
|
-
toolName: toolCall.name,
|
|
1167
|
-
output,
|
|
1168
|
-
isError: false
|
|
1169
|
-
};
|
|
1170
|
-
if (hooks?.afterToolCall) {
|
|
1171
|
-
result = await hooks.afterToolCall(toolCall, result);
|
|
1172
|
-
}
|
|
1173
|
-
return result;
|
|
1174
|
-
} catch (err) {
|
|
1175
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
1176
|
-
if (hooks?.onToolError) {
|
|
1177
|
-
const action = await hooks.onToolError(toolCall, error);
|
|
1178
|
-
if (action.action === "result") {
|
|
1179
|
-
return {
|
|
1180
|
-
toolCallId: toolCall.id,
|
|
1181
|
-
toolName: toolCall.name,
|
|
1182
|
-
output: action.output,
|
|
1183
|
-
isError: false
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
getLogger2().warn(`AgentTask: Tool "${toolCall.name}" failed: ${error.message}`);
|
|
1188
|
-
return {
|
|
1189
|
-
toolCallId: toolCall.id,
|
|
1190
|
-
toolName: toolCall.name,
|
|
1191
|
-
output: { error: error.message },
|
|
1192
|
-
isError: true
|
|
1193
|
-
};
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
async function executeToolCalls(toolCalls, sources, context, hooks, maxConcurrency = 5) {
|
|
1197
|
-
const calls = toolCalls;
|
|
1198
|
-
if (calls.length === 0)
|
|
1199
|
-
return [];
|
|
1200
|
-
const concurrency = Math.max(1, Math.min(maxConcurrency, calls.length));
|
|
1201
|
-
const results = new Array(calls.length);
|
|
1202
|
-
let cursor = 0;
|
|
1203
|
-
const workers = Array.from({ length: concurrency }, async () => {
|
|
1204
|
-
while (true) {
|
|
1205
|
-
if (context.signal.aborted) {
|
|
1206
|
-
throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
1207
|
-
}
|
|
1208
|
-
const position = cursor;
|
|
1209
|
-
cursor += 1;
|
|
1210
|
-
if (position >= calls.length)
|
|
1211
|
-
return;
|
|
1212
|
-
results[position] = await executeToolCall(calls[position], sources, context, hooks);
|
|
1213
|
-
}
|
|
1214
|
-
});
|
|
1215
|
-
await Promise.all(workers);
|
|
1216
|
-
return results;
|
|
1217
|
-
}
|
|
1218
|
-
function hasToolCalls(toolCalls) {
|
|
1219
|
-
return toolCalls !== undefined && toolCalls.length > 0;
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
// src/task/AgentTask.ts
|
|
1223
|
-
var modelSchema2 = TypeModel("model:ToolCallingTask");
|
|
1224
|
-
var AgentInputSchema = {
|
|
1225
|
-
type: "object",
|
|
1226
|
-
properties: {
|
|
1227
|
-
model: modelSchema2,
|
|
1228
|
-
prompt: {
|
|
1229
|
-
oneOf: [
|
|
1230
|
-
{ type: "string" },
|
|
1231
|
-
{
|
|
1232
|
-
type: "array",
|
|
1233
|
-
items: {
|
|
1234
|
-
type: "object",
|
|
1235
|
-
properties: {
|
|
1236
|
-
type: { type: "string", enum: ["text", "image", "audio"] }
|
|
1237
|
-
},
|
|
1238
|
-
required: ["type"],
|
|
1239
|
-
additionalProperties: true
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
],
|
|
1243
|
-
title: "Prompt",
|
|
1244
|
-
description: "The user prompt to start the agent loop. Can be a string or an array of content blocks (text, image, audio)."
|
|
1245
|
-
},
|
|
1246
|
-
systemPrompt: {
|
|
1247
|
-
type: "string",
|
|
1248
|
-
title: "System Prompt",
|
|
1249
|
-
description: "Optional system instructions for the agent"
|
|
1250
|
-
},
|
|
1251
|
-
tools: {
|
|
1252
|
-
type: "array",
|
|
1253
|
-
format: "tasks",
|
|
1254
|
-
title: "Tools",
|
|
1255
|
-
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.",
|
|
1256
|
-
items: {
|
|
1257
|
-
oneOf: [
|
|
1258
|
-
{ type: "string", format: "tasks", description: "Task type name" },
|
|
1259
|
-
ToolDefinitionSchema
|
|
1260
|
-
]
|
|
1261
|
-
}
|
|
1262
|
-
},
|
|
1263
|
-
stopTool: {
|
|
1264
|
-
type: "string",
|
|
1265
|
-
title: "Stop Tool",
|
|
1266
|
-
description: "Name of a tool that signals agent completion. When called, the loop ends and the tool input becomes structuredOutput.",
|
|
1267
|
-
"x-ui-group": "Configuration"
|
|
1268
|
-
},
|
|
1269
|
-
maxIterations: {
|
|
1270
|
-
type: "number",
|
|
1271
|
-
title: "Max Iterations",
|
|
1272
|
-
description: "Maximum number of agent loop iterations (default: 10)",
|
|
1273
|
-
minimum: 1,
|
|
1274
|
-
"x-ui-group": "Configuration"
|
|
1275
|
-
},
|
|
1276
|
-
maxContextMessages: {
|
|
1277
|
-
type: "number",
|
|
1278
|
-
title: "Max Context Messages",
|
|
1279
|
-
description: "Maximum messages in conversation history. Older messages are trimmed to prevent context overflow.",
|
|
1280
|
-
minimum: 3,
|
|
1281
|
-
"x-ui-group": "Configuration"
|
|
1282
|
-
},
|
|
1283
|
-
maxTokens: {
|
|
1284
|
-
type: "number",
|
|
1285
|
-
title: "Max Tokens",
|
|
1286
|
-
description: "Maximum tokens per LLM call",
|
|
1287
|
-
minimum: 1,
|
|
1288
|
-
"x-ui-group": "Configuration"
|
|
1289
|
-
},
|
|
1290
|
-
temperature: {
|
|
1291
|
-
type: "number",
|
|
1292
|
-
title: "Temperature",
|
|
1293
|
-
description: "Sampling temperature for LLM calls",
|
|
1294
|
-
minimum: 0,
|
|
1295
|
-
maximum: 2,
|
|
1296
|
-
"x-ui-group": "Configuration"
|
|
1297
|
-
}
|
|
1298
|
-
},
|
|
1299
|
-
required: ["model", "prompt"],
|
|
1300
|
-
additionalProperties: false
|
|
1301
|
-
};
|
|
1302
|
-
var AgentOutputSchema = {
|
|
1303
|
-
type: "object",
|
|
1304
|
-
properties: {
|
|
1305
|
-
text: {
|
|
1306
|
-
type: "string",
|
|
1307
|
-
title: "Text",
|
|
1308
|
-
description: "The final text response from the agent",
|
|
1309
|
-
"x-stream": "append"
|
|
1310
|
-
},
|
|
1311
|
-
messages: {
|
|
1312
|
-
type: "array",
|
|
1313
|
-
title: "Messages",
|
|
1314
|
-
description: "Full conversation history including all tool calls and results",
|
|
1315
|
-
items: {
|
|
1316
|
-
type: "object",
|
|
1317
|
-
additionalProperties: true
|
|
1318
|
-
}
|
|
1319
|
-
},
|
|
1320
|
-
iterations: {
|
|
1321
|
-
type: "number",
|
|
1322
|
-
title: "Iterations",
|
|
1323
|
-
description: "Number of LLM calls made during the agent loop"
|
|
1324
|
-
},
|
|
1325
|
-
toolCallCount: {
|
|
1326
|
-
type: "number",
|
|
1327
|
-
title: "Tool Call Count",
|
|
1328
|
-
description: "Total number of tool calls executed"
|
|
1329
|
-
},
|
|
1330
|
-
structuredOutput: {
|
|
1331
|
-
type: "object",
|
|
1332
|
-
title: "Structured Output",
|
|
1333
|
-
description: "Present when the agent terminated via a stop tool",
|
|
1334
|
-
additionalProperties: true
|
|
1335
|
-
}
|
|
1336
|
-
},
|
|
1337
|
-
required: ["text", "messages", "iterations", "toolCallCount"],
|
|
1338
|
-
additionalProperties: false
|
|
1339
|
-
};
|
|
1340
|
-
|
|
1341
|
-
class AgentTask extends Task {
|
|
1342
|
-
static type = "AgentTask";
|
|
1343
|
-
static category = "AI Agent";
|
|
1344
|
-
static title = "Agent";
|
|
1345
|
-
static description = "Multi-turn agentic loop that calls an LLM with tools, executes tool calls, and iterates until done";
|
|
1346
|
-
static cacheable = false;
|
|
1347
|
-
static inputSchema() {
|
|
1348
|
-
return AgentInputSchema;
|
|
1349
|
-
}
|
|
1350
|
-
static outputSchema() {
|
|
1351
|
-
return AgentOutputSchema;
|
|
1352
|
-
}
|
|
1353
|
-
async execute(input, context) {
|
|
1354
|
-
let result;
|
|
1355
|
-
for await (const event of this.agentLoop(input, context)) {
|
|
1356
|
-
if (event.type === "finish") {
|
|
1357
|
-
result = event.data;
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
if (!result) {
|
|
1361
|
-
throw new Error("AgentTask: loop ended without producing output");
|
|
1362
|
-
}
|
|
1363
|
-
return result;
|
|
1364
|
-
}
|
|
1365
|
-
async* executeStream(input, context) {
|
|
1366
|
-
yield* this.agentLoop(input, context);
|
|
1367
|
-
}
|
|
1368
|
-
async* agentLoop(input, context) {
|
|
1369
|
-
const maxIterations = input.maxIterations ?? 10;
|
|
1370
|
-
const hooks = this.config.hooks;
|
|
1371
|
-
const maxConcurrency = this.config.maxConcurrency ?? 5;
|
|
1372
|
-
const toolSources = this.resolveToolSources(input, context);
|
|
1373
|
-
const toolDefs = this.resolveToolDefs(toolSources, input.stopTool);
|
|
1374
|
-
const messages = [userMessage(input.prompt)];
|
|
1375
|
-
let totalToolCalls = 0;
|
|
1376
|
-
let finalText = "";
|
|
1377
|
-
let structuredOutput;
|
|
1378
|
-
for (let iteration = 0;iteration < maxIterations; iteration++) {
|
|
1379
|
-
if (context.signal.aborted)
|
|
1380
|
-
break;
|
|
1381
|
-
if (hooks?.onIteration) {
|
|
1382
|
-
const action = await hooks.onIteration(iteration, messages, { totalToolCalls });
|
|
1383
|
-
if (action.action === "stop")
|
|
1384
|
-
break;
|
|
1385
|
-
}
|
|
1386
|
-
await context.updateProgress(Math.round(iteration / maxIterations * 100), `Agent iteration ${iteration + 1}`);
|
|
1387
|
-
const contextMessages = this.trimMessages(messages, input.maxContextMessages);
|
|
1388
|
-
const llmTask = context.own(new ToolCallingTask({}, {}));
|
|
1389
|
-
let iterationText = "";
|
|
1390
|
-
let toolCalls = [];
|
|
1391
|
-
for await (const event of llmTask.executeStream({
|
|
1392
|
-
model: input.model,
|
|
1393
|
-
prompt: input.prompt,
|
|
1394
|
-
systemPrompt: input.systemPrompt,
|
|
1395
|
-
tools: toolDefs,
|
|
1396
|
-
messages: contextMessages,
|
|
1397
|
-
maxTokens: input.maxTokens,
|
|
1398
|
-
temperature: input.temperature
|
|
1399
|
-
}, context)) {
|
|
1400
|
-
if (event.type === "text-delta") {
|
|
1401
|
-
yield { type: "text-delta", port: "text", textDelta: event.textDelta };
|
|
1402
|
-
iterationText += event.textDelta;
|
|
1403
|
-
} else if (event.type === "finish") {
|
|
1404
|
-
const data = event.data;
|
|
1405
|
-
iterationText = data?.text ?? iterationText;
|
|
1406
|
-
if (data?.toolCalls) {
|
|
1407
|
-
toolCalls = data.toolCalls ?? [];
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
finalText = iterationText;
|
|
1412
|
-
messages.push(assistantMessage(iterationText, toolCalls));
|
|
1413
|
-
if (input.stopTool) {
|
|
1414
|
-
const stopCall = toolCalls.find((tc) => tc.name === input.stopTool);
|
|
1415
|
-
if (stopCall) {
|
|
1416
|
-
structuredOutput = stopCall.input;
|
|
1417
|
-
break;
|
|
1000
|
+
input[key] = undefined;
|
|
1001
|
+
}
|
|
1418
1002
|
}
|
|
1419
1003
|
}
|
|
1420
|
-
if (!hasToolCalls(toolCalls)) {
|
|
1421
|
-
break;
|
|
1422
|
-
}
|
|
1423
|
-
const results = await executeToolCalls(toolCalls, toolSources, context, hooks, maxConcurrency);
|
|
1424
|
-
totalToolCalls += results.length;
|
|
1425
|
-
messages.push(toolMessage(results));
|
|
1426
|
-
}
|
|
1427
|
-
const output = {
|
|
1428
|
-
text: finalText,
|
|
1429
|
-
messages,
|
|
1430
|
-
iterations: messages.filter((m) => m.role === "assistant").length,
|
|
1431
|
-
toolCallCount: totalToolCalls,
|
|
1432
|
-
...structuredOutput !== undefined ? { structuredOutput } : {}
|
|
1433
|
-
};
|
|
1434
|
-
yield { type: "finish", data: output };
|
|
1435
|
-
}
|
|
1436
|
-
resolveToolSources(input, context) {
|
|
1437
|
-
return buildToolSources(input.tools, context.registry);
|
|
1438
|
-
}
|
|
1439
|
-
resolveToolDefs(toolSources, stopTool) {
|
|
1440
|
-
const defs = toolSourceDefinitions(toolSources);
|
|
1441
|
-
if (stopTool && !defs.some((d) => d.name === stopTool)) {
|
|
1442
|
-
defs.push({
|
|
1443
|
-
name: stopTool,
|
|
1444
|
-
description: "Call this tool when you have completed the task. Pass your final structured result as the input.",
|
|
1445
|
-
inputSchema: { type: "object", additionalProperties: true }
|
|
1446
|
-
});
|
|
1447
1004
|
}
|
|
1448
|
-
return
|
|
1449
|
-
}
|
|
1450
|
-
trimMessages(messages, maxContextMessages) {
|
|
1451
|
-
if (!maxContextMessages || messages.length <= maxContextMessages) {
|
|
1452
|
-
return messages;
|
|
1453
|
-
}
|
|
1454
|
-
getLogger3().debug(`AgentTask: Trimming context from ${messages.length} to ${maxContextMessages} messages`);
|
|
1455
|
-
const tail = messages.slice(1);
|
|
1456
|
-
let startIdx = tail.length - (maxContextMessages - 1);
|
|
1457
|
-
if (startIdx < 0)
|
|
1458
|
-
startIdx = 0;
|
|
1459
|
-
if (startIdx > 0 && startIdx < tail.length && tail[startIdx].role === "tool") {
|
|
1460
|
-
startIdx -= 1;
|
|
1461
|
-
}
|
|
1462
|
-
return [messages[0], ...tail.slice(startIdx)];
|
|
1005
|
+
return input;
|
|
1463
1006
|
}
|
|
1464
1007
|
}
|
|
1465
|
-
var agent = (input, config) => {
|
|
1466
|
-
return new AgentTask({}, config).run(input);
|
|
1467
|
-
};
|
|
1468
|
-
Workflow2.prototype.agent = CreateWorkflow2(AgentTask);
|
|
1469
|
-
|
|
1470
|
-
// src/task/BackgroundRemovalTask.ts
|
|
1471
|
-
import { CreateWorkflow as CreateWorkflow3, Workflow as Workflow3 } from "@workglow/task-graph";
|
|
1472
1008
|
|
|
1473
1009
|
// src/task/base/AiVisionTask.ts
|
|
1474
|
-
import { convertImageDataToUseableForm } from "@workglow/util/media";
|
|
1475
1010
|
class AiVisionTask extends AiTask {
|
|
1476
1011
|
static type = "AiVisionTask";
|
|
1477
1012
|
async getJobInput(input) {
|
|
1478
1013
|
const jobInput = await super.getJobInput(input);
|
|
1479
|
-
const
|
|
1480
|
-
const queueName = registeredQueue?.server.queueName;
|
|
1014
|
+
const providerName = input.model.provider;
|
|
1481
1015
|
const supports = ["Blob"];
|
|
1482
1016
|
if (input.image) {
|
|
1483
|
-
if (typeof
|
|
1017
|
+
if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "ImageBitmap" in globalThis) {
|
|
1484
1018
|
supports.push("ImageBitmap");
|
|
1485
|
-
} else if (typeof
|
|
1019
|
+
} else if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "VideoFrame" in globalThis) {
|
|
1486
1020
|
supports.push("VideoFrame");
|
|
1487
1021
|
}
|
|
1488
|
-
const image = await convertImageDataToUseableForm(input.image, supports);
|
|
1022
|
+
const image = Array.isArray(input.image) ? await Promise.all(input.image.map((img) => convertImageDataToUseableForm(img, supports))) : await convertImageDataToUseableForm(input.image, supports);
|
|
1489
1023
|
jobInput.taskInput.image = image;
|
|
1490
1024
|
}
|
|
1491
1025
|
return jobInput;
|
|
@@ -1493,7 +1027,7 @@ class AiVisionTask extends AiTask {
|
|
|
1493
1027
|
}
|
|
1494
1028
|
|
|
1495
1029
|
// src/task/BackgroundRemovalTask.ts
|
|
1496
|
-
var
|
|
1030
|
+
var modelSchema = TypeModel("model:BackgroundRemovalTask");
|
|
1497
1031
|
var processedImageSchema = {
|
|
1498
1032
|
type: "string",
|
|
1499
1033
|
contentEncoding: "base64",
|
|
@@ -1505,7 +1039,7 @@ var BackgroundRemovalInputSchema = {
|
|
|
1505
1039
|
type: "object",
|
|
1506
1040
|
properties: {
|
|
1507
1041
|
image: TypeImageInput,
|
|
1508
|
-
model:
|
|
1042
|
+
model: modelSchema
|
|
1509
1043
|
},
|
|
1510
1044
|
required: ["image", "model"],
|
|
1511
1045
|
additionalProperties: false
|
|
@@ -1534,26 +1068,22 @@ class BackgroundRemovalTask extends AiVisionTask {
|
|
|
1534
1068
|
var backgroundRemoval = (input, config) => {
|
|
1535
1069
|
return new BackgroundRemovalTask({}, config).run(input);
|
|
1536
1070
|
};
|
|
1537
|
-
|
|
1071
|
+
Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
|
|
1538
1072
|
|
|
1539
1073
|
// src/task/ChunkRetrievalTask.ts
|
|
1540
1074
|
import { TypeKnowledgeBase } from "@workglow/knowledge-base";
|
|
1541
|
-
import {
|
|
1542
|
-
CreateWorkflow as CreateWorkflow5,
|
|
1543
|
-
Task as Task2,
|
|
1544
|
-
Workflow as Workflow5
|
|
1545
|
-
} from "@workglow/task-graph";
|
|
1075
|
+
import { CreateWorkflow as CreateWorkflow3, Task as Task2, Workflow as Workflow3 } from "@workglow/task-graph";
|
|
1546
1076
|
import {
|
|
1547
1077
|
isTypedArray,
|
|
1548
1078
|
TypedArraySchema as TypedArraySchema2
|
|
1549
1079
|
} from "@workglow/util/schema";
|
|
1550
1080
|
|
|
1551
1081
|
// src/task/TextEmbeddingTask.ts
|
|
1552
|
-
import { CreateWorkflow as
|
|
1082
|
+
import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
|
|
1553
1083
|
import {
|
|
1554
1084
|
TypedArraySchema
|
|
1555
1085
|
} from "@workglow/util/schema";
|
|
1556
|
-
var
|
|
1086
|
+
var modelSchema2 = TypeModel("model:TextEmbeddingTask");
|
|
1557
1087
|
var TextEmbeddingInputSchema = {
|
|
1558
1088
|
type: "object",
|
|
1559
1089
|
properties: {
|
|
@@ -1562,7 +1092,7 @@ var TextEmbeddingInputSchema = {
|
|
|
1562
1092
|
title: "Text",
|
|
1563
1093
|
description: "The text to embed"
|
|
1564
1094
|
}),
|
|
1565
|
-
model:
|
|
1095
|
+
model: modelSchema2
|
|
1566
1096
|
},
|
|
1567
1097
|
required: ["text", "model"],
|
|
1568
1098
|
additionalProperties: false
|
|
@@ -1594,7 +1124,7 @@ class TextEmbeddingTask extends AiTask {
|
|
|
1594
1124
|
var textEmbedding = async (input, config) => {
|
|
1595
1125
|
return new TextEmbeddingTask({}, config).run(input);
|
|
1596
1126
|
};
|
|
1597
|
-
|
|
1127
|
+
Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
|
|
1598
1128
|
|
|
1599
1129
|
// src/task/ChunkRetrievalTask.ts
|
|
1600
1130
|
var inputSchema = {
|
|
@@ -1786,15 +1316,11 @@ class ChunkRetrievalTask extends Task2 {
|
|
|
1786
1316
|
var chunkRetrieval = (input, config) => {
|
|
1787
1317
|
return new ChunkRetrievalTask({}, config).run(input);
|
|
1788
1318
|
};
|
|
1789
|
-
|
|
1319
|
+
Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
|
|
1790
1320
|
|
|
1791
1321
|
// src/task/ChunkToVectorTask.ts
|
|
1792
1322
|
import { ChunkRecordSchema } from "@workglow/knowledge-base";
|
|
1793
|
-
import {
|
|
1794
|
-
CreateWorkflow as CreateWorkflow6,
|
|
1795
|
-
Task as Task3,
|
|
1796
|
-
Workflow as Workflow6
|
|
1797
|
-
} from "@workglow/task-graph";
|
|
1323
|
+
import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
|
|
1798
1324
|
import {
|
|
1799
1325
|
TypedArraySchema as TypedArraySchema3
|
|
1800
1326
|
} from "@workglow/util/schema";
|
|
@@ -1920,15 +1446,11 @@ class ChunkToVectorTask extends Task3 {
|
|
|
1920
1446
|
var chunkToVector = (input, config) => {
|
|
1921
1447
|
return new ChunkToVectorTask({}, config).run(input);
|
|
1922
1448
|
};
|
|
1923
|
-
|
|
1449
|
+
Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
|
|
1924
1450
|
|
|
1925
1451
|
// src/task/ChunkVectorHybridSearchTask.ts
|
|
1926
1452
|
import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
|
|
1927
|
-
import {
|
|
1928
|
-
CreateWorkflow as CreateWorkflow7,
|
|
1929
|
-
Task as Task4,
|
|
1930
|
-
Workflow as Workflow7
|
|
1931
|
-
} from "@workglow/task-graph";
|
|
1453
|
+
import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
1932
1454
|
import {
|
|
1933
1455
|
TypedArraySchema as TypedArraySchema4
|
|
1934
1456
|
} from "@workglow/util/schema";
|
|
@@ -2094,15 +1616,11 @@ class ChunkVectorHybridSearchTask extends Task4 {
|
|
|
2094
1616
|
var hybridSearch = async (input, config) => {
|
|
2095
1617
|
return new ChunkVectorHybridSearchTask({}, config).run(input);
|
|
2096
1618
|
};
|
|
2097
|
-
|
|
1619
|
+
Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
|
|
2098
1620
|
|
|
2099
1621
|
// src/task/ChunkVectorSearchTask.ts
|
|
2100
1622
|
import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
|
|
2101
|
-
import {
|
|
2102
|
-
CreateWorkflow as CreateWorkflow8,
|
|
2103
|
-
Task as Task5,
|
|
2104
|
-
Workflow as Workflow8
|
|
2105
|
-
} from "@workglow/task-graph";
|
|
1623
|
+
import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
|
|
2106
1624
|
import {
|
|
2107
1625
|
TypedArraySchema as TypedArraySchema5
|
|
2108
1626
|
} from "@workglow/util/schema";
|
|
@@ -2217,15 +1735,11 @@ class ChunkVectorSearchTask extends Task5 {
|
|
|
2217
1735
|
var vectorStoreSearch = (input, config) => {
|
|
2218
1736
|
return new ChunkVectorSearchTask({}, config).run(input);
|
|
2219
1737
|
};
|
|
2220
|
-
|
|
1738
|
+
Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
|
|
2221
1739
|
|
|
2222
1740
|
// src/task/ChunkVectorUpsertTask.ts
|
|
2223
1741
|
import { TypeKnowledgeBase as TypeKnowledgeBase4 } from "@workglow/knowledge-base";
|
|
2224
|
-
import {
|
|
2225
|
-
CreateWorkflow as CreateWorkflow9,
|
|
2226
|
-
Task as Task6,
|
|
2227
|
-
Workflow as Workflow9
|
|
2228
|
-
} from "@workglow/task-graph";
|
|
1742
|
+
import { CreateWorkflow as CreateWorkflow7, Task as Task6, Workflow as Workflow7 } from "@workglow/task-graph";
|
|
2229
1743
|
import {
|
|
2230
1744
|
TypedArraySchema as TypedArraySchema6
|
|
2231
1745
|
} from "@workglow/util/schema";
|
|
@@ -2339,28 +1853,28 @@ class ChunkVectorUpsertTask extends Task6 {
|
|
|
2339
1853
|
var chunkVectorUpsert = (input, config) => {
|
|
2340
1854
|
return new ChunkVectorUpsertTask({}, config).run(input);
|
|
2341
1855
|
};
|
|
2342
|
-
|
|
1856
|
+
Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
|
|
2343
1857
|
|
|
2344
1858
|
// src/task/ContextBuilderTask.ts
|
|
2345
1859
|
import { estimateTokens } from "@workglow/knowledge-base";
|
|
2346
1860
|
import {
|
|
2347
|
-
CreateWorkflow as
|
|
1861
|
+
CreateWorkflow as CreateWorkflow9,
|
|
2348
1862
|
Task as Task7,
|
|
2349
|
-
Workflow as
|
|
1863
|
+
Workflow as Workflow9
|
|
2350
1864
|
} from "@workglow/task-graph";
|
|
2351
1865
|
|
|
2352
1866
|
// src/task/CountTokensTask.ts
|
|
2353
|
-
import { CreateWorkflow as
|
|
2354
|
-
var
|
|
1867
|
+
import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
|
|
1868
|
+
var modelSchema3 = TypeModel("model");
|
|
2355
1869
|
var CountTokensInputSchema = {
|
|
2356
1870
|
type: "object",
|
|
2357
1871
|
properties: {
|
|
2358
|
-
text:
|
|
1872
|
+
text: {
|
|
2359
1873
|
type: "string",
|
|
2360
1874
|
title: "Text",
|
|
2361
1875
|
description: "The text to count tokens for"
|
|
2362
|
-
}
|
|
2363
|
-
model:
|
|
1876
|
+
},
|
|
1877
|
+
model: modelSchema3
|
|
2364
1878
|
},
|
|
2365
1879
|
required: ["text", "model"],
|
|
2366
1880
|
additionalProperties: false
|
|
@@ -2368,11 +1882,11 @@ var CountTokensInputSchema = {
|
|
|
2368
1882
|
var CountTokensOutputSchema = {
|
|
2369
1883
|
type: "object",
|
|
2370
1884
|
properties: {
|
|
2371
|
-
count:
|
|
1885
|
+
count: {
|
|
2372
1886
|
type: "number",
|
|
2373
1887
|
title: "Token Count",
|
|
2374
1888
|
description: "The number of tokens in the text"
|
|
2375
|
-
}
|
|
1889
|
+
}
|
|
2376
1890
|
},
|
|
2377
1891
|
required: ["count"],
|
|
2378
1892
|
additionalProperties: false
|
|
@@ -2394,7 +1908,7 @@ class CountTokensTask extends AiTask {
|
|
|
2394
1908
|
var countTokens = async (input, config) => {
|
|
2395
1909
|
return new CountTokensTask({}, config).run(input);
|
|
2396
1910
|
};
|
|
2397
|
-
|
|
1911
|
+
Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
|
|
2398
1912
|
|
|
2399
1913
|
// src/task/ContextBuilderTask.ts
|
|
2400
1914
|
var ContextFormat = {
|
|
@@ -2404,7 +1918,7 @@ var ContextFormat = {
|
|
|
2404
1918
|
MARKDOWN: "markdown",
|
|
2405
1919
|
JSON: "json"
|
|
2406
1920
|
};
|
|
2407
|
-
var
|
|
1921
|
+
var modelSchema4 = TypeModel("model", {
|
|
2408
1922
|
title: "Model",
|
|
2409
1923
|
description: "Model to use for token counting (optional, falls back to estimation)"
|
|
2410
1924
|
});
|
|
@@ -2468,7 +1982,7 @@ var inputSchema6 = {
|
|
|
2468
1982
|
|
|
2469
1983
|
`
|
|
2470
1984
|
},
|
|
2471
|
-
model:
|
|
1985
|
+
model: modelSchema4
|
|
2472
1986
|
},
|
|
2473
1987
|
required: ["chunks"],
|
|
2474
1988
|
additionalProperties: false
|
|
@@ -2694,30 +2208,26 @@ class ContextBuilderTask extends Task7 {
|
|
|
2694
2208
|
var contextBuilder = (input, config) => {
|
|
2695
2209
|
return new ContextBuilderTask({}, config).run(input);
|
|
2696
2210
|
};
|
|
2697
|
-
|
|
2211
|
+
Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
|
|
2698
2212
|
|
|
2699
2213
|
// src/task/DocumentEnricherTask.ts
|
|
2700
2214
|
import {
|
|
2701
2215
|
getChildren,
|
|
2702
2216
|
hasChildren
|
|
2703
2217
|
} from "@workglow/knowledge-base";
|
|
2704
|
-
import {
|
|
2705
|
-
CreateWorkflow as CreateWorkflow14,
|
|
2706
|
-
Task as Task8,
|
|
2707
|
-
Workflow as Workflow14
|
|
2708
|
-
} from "@workglow/task-graph";
|
|
2218
|
+
import { CreateWorkflow as CreateWorkflow12, Task as Task8, Workflow as Workflow12 } from "@workglow/task-graph";
|
|
2709
2219
|
|
|
2710
2220
|
// src/task/TextNamedEntityRecognitionTask.ts
|
|
2711
|
-
import { CreateWorkflow as
|
|
2712
|
-
var
|
|
2221
|
+
import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
|
|
2222
|
+
var modelSchema5 = TypeModel("model:TextNamedEntityRecognitionTask");
|
|
2713
2223
|
var TextNamedEntityRecognitionInputSchema = {
|
|
2714
2224
|
type: "object",
|
|
2715
2225
|
properties: {
|
|
2716
|
-
text:
|
|
2226
|
+
text: {
|
|
2717
2227
|
type: "string",
|
|
2718
2228
|
title: "Text",
|
|
2719
2229
|
description: "The text to extract named entities from"
|
|
2720
|
-
}
|
|
2230
|
+
},
|
|
2721
2231
|
blockList: {
|
|
2722
2232
|
type: "array",
|
|
2723
2233
|
items: {
|
|
@@ -2728,7 +2238,7 @@ var TextNamedEntityRecognitionInputSchema = {
|
|
|
2728
2238
|
"x-ui-group": "Configuration",
|
|
2729
2239
|
"x-ui-group-open": false
|
|
2730
2240
|
},
|
|
2731
|
-
model:
|
|
2241
|
+
model: modelSchema5
|
|
2732
2242
|
},
|
|
2733
2243
|
required: ["text", "model"],
|
|
2734
2244
|
additionalProperties: false
|
|
@@ -2736,7 +2246,7 @@ var TextNamedEntityRecognitionInputSchema = {
|
|
|
2736
2246
|
var TextNamedEntityRecognitionOutputSchema = {
|
|
2737
2247
|
type: "object",
|
|
2738
2248
|
properties: {
|
|
2739
|
-
entities:
|
|
2249
|
+
entities: {
|
|
2740
2250
|
type: "array",
|
|
2741
2251
|
items: {
|
|
2742
2252
|
type: "object",
|
|
@@ -2762,7 +2272,7 @@ var TextNamedEntityRecognitionOutputSchema = {
|
|
|
2762
2272
|
},
|
|
2763
2273
|
title: "Entities",
|
|
2764
2274
|
description: "The extracted named entities with their types, scores, and text"
|
|
2765
|
-
}
|
|
2275
|
+
}
|
|
2766
2276
|
},
|
|
2767
2277
|
required: ["entities"],
|
|
2768
2278
|
additionalProperties: false
|
|
@@ -2783,20 +2293,60 @@ class TextNamedEntityRecognitionTask extends AiTask {
|
|
|
2783
2293
|
var textNamedEntityRecognition = (input, config) => {
|
|
2784
2294
|
return new TextNamedEntityRecognitionTask({}, config).run(input);
|
|
2785
2295
|
};
|
|
2786
|
-
|
|
2296
|
+
Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
|
|
2787
2297
|
|
|
2788
2298
|
// src/task/TextSummaryTask.ts
|
|
2789
|
-
import { CreateWorkflow as
|
|
2790
|
-
|
|
2299
|
+
import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
|
|
2300
|
+
|
|
2301
|
+
// src/task/base/StreamingAiTask.ts
|
|
2302
|
+
import {
|
|
2303
|
+
getStreamingPorts,
|
|
2304
|
+
TaskConfigurationError as TaskConfigurationError3
|
|
2305
|
+
} from "@workglow/task-graph";
|
|
2306
|
+
class StreamingAiTask extends AiTask {
|
|
2307
|
+
static type = "StreamingAiTask";
|
|
2308
|
+
async* executeStream(input, context) {
|
|
2309
|
+
const model = input.model;
|
|
2310
|
+
if (!model || typeof model !== "object") {
|
|
2311
|
+
throw new TaskConfigurationError3("StreamingAiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
|
|
2312
|
+
}
|
|
2313
|
+
const jobInput = await this.getJobInput(input);
|
|
2314
|
+
const strategy = getAiProviderRegistry().getStrategy(model);
|
|
2315
|
+
const outSchema = this.outputSchema();
|
|
2316
|
+
const ports = getStreamingPorts(outSchema);
|
|
2317
|
+
let defaultPort = "text";
|
|
2318
|
+
if (ports.length > 0) {
|
|
2319
|
+
defaultPort = ports[0].port;
|
|
2320
|
+
} else {
|
|
2321
|
+
if (typeof outSchema === "object" && outSchema.properties) {
|
|
2322
|
+
const firstProp = Object.keys(outSchema.properties)[0];
|
|
2323
|
+
if (firstProp)
|
|
2324
|
+
defaultPort = firstProp;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
for await (const event of strategy.executeStream(jobInput, context, this.runConfig.runnerId)) {
|
|
2328
|
+
if (event.type === "text-delta") {
|
|
2329
|
+
yield { ...event, port: event.port ?? defaultPort };
|
|
2330
|
+
} else if (event.type === "object-delta") {
|
|
2331
|
+
yield { ...event, port: event.port ?? defaultPort };
|
|
2332
|
+
} else {
|
|
2333
|
+
yield event;
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
// src/task/TextSummaryTask.ts
|
|
2340
|
+
var modelSchema6 = TypeModel("model:TextSummaryTask");
|
|
2791
2341
|
var TextSummaryInputSchema = {
|
|
2792
2342
|
type: "object",
|
|
2793
2343
|
properties: {
|
|
2794
|
-
text:
|
|
2344
|
+
text: {
|
|
2795
2345
|
type: "string",
|
|
2796
2346
|
title: "Text",
|
|
2797
2347
|
description: "The text to summarize"
|
|
2798
|
-
}
|
|
2799
|
-
model:
|
|
2348
|
+
},
|
|
2349
|
+
model: modelSchema6
|
|
2800
2350
|
},
|
|
2801
2351
|
required: ["text", "model"],
|
|
2802
2352
|
additionalProperties: false
|
|
@@ -2804,12 +2354,12 @@ var TextSummaryInputSchema = {
|
|
|
2804
2354
|
var TextSummaryOutputSchema = {
|
|
2805
2355
|
type: "object",
|
|
2806
2356
|
properties: {
|
|
2807
|
-
text:
|
|
2357
|
+
text: {
|
|
2808
2358
|
type: "string",
|
|
2809
2359
|
title: "Text",
|
|
2810
2360
|
description: "The summarized text",
|
|
2811
2361
|
"x-stream": "append"
|
|
2812
|
-
}
|
|
2362
|
+
}
|
|
2813
2363
|
},
|
|
2814
2364
|
required: ["text"],
|
|
2815
2365
|
additionalProperties: false
|
|
@@ -2830,7 +2380,7 @@ class TextSummaryTask extends StreamingAiTask {
|
|
|
2830
2380
|
var textSummary = async (input, config) => {
|
|
2831
2381
|
return new TextSummaryTask({}, config).run(input);
|
|
2832
2382
|
};
|
|
2833
|
-
|
|
2383
|
+
Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
|
|
2834
2384
|
|
|
2835
2385
|
// src/task/DocumentEnricherTask.ts
|
|
2836
2386
|
var inputSchema7 = {
|
|
@@ -3061,15 +2611,15 @@ class DocumentEnricherTask extends Task8 {
|
|
|
3061
2611
|
var documentEnricher = (input, config) => {
|
|
3062
2612
|
return new DocumentEnricherTask({}, config).run(input);
|
|
3063
2613
|
};
|
|
3064
|
-
|
|
2614
|
+
Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
|
|
3065
2615
|
|
|
3066
2616
|
// src/task/DownloadModelTask.ts
|
|
3067
|
-
import { CreateWorkflow as
|
|
3068
|
-
var
|
|
2617
|
+
import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
|
|
2618
|
+
var modelSchema7 = TypeModel("model");
|
|
3069
2619
|
var DownloadModelInputSchema = {
|
|
3070
2620
|
type: "object",
|
|
3071
2621
|
properties: {
|
|
3072
|
-
model:
|
|
2622
|
+
model: modelSchema7
|
|
3073
2623
|
},
|
|
3074
2624
|
required: ["model"],
|
|
3075
2625
|
additionalProperties: false
|
|
@@ -3077,7 +2627,7 @@ var DownloadModelInputSchema = {
|
|
|
3077
2627
|
var DownloadModelOutputSchema = {
|
|
3078
2628
|
type: "object",
|
|
3079
2629
|
properties: {
|
|
3080
|
-
model:
|
|
2630
|
+
model: modelSchema7
|
|
3081
2631
|
},
|
|
3082
2632
|
required: ["model"],
|
|
3083
2633
|
additionalProperties: false
|
|
@@ -3131,11 +2681,11 @@ class DownloadModelTask extends AiTask {
|
|
|
3131
2681
|
var downloadModel = (input, config) => {
|
|
3132
2682
|
return new DownloadModelTask({}, config).run(input);
|
|
3133
2683
|
};
|
|
3134
|
-
|
|
2684
|
+
Workflow13.prototype.downloadModel = CreateWorkflow13(DownloadModelTask);
|
|
3135
2685
|
|
|
3136
2686
|
// src/task/FaceDetectorTask.ts
|
|
3137
|
-
import { CreateWorkflow as
|
|
3138
|
-
var
|
|
2687
|
+
import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
|
|
2688
|
+
var modelSchema8 = TypeModel("model:FaceDetectorTask");
|
|
3139
2689
|
var TypeBoundingBox2 = {
|
|
3140
2690
|
type: "object",
|
|
3141
2691
|
properties: {
|
|
@@ -3208,7 +2758,7 @@ var FaceDetectorInputSchema = {
|
|
|
3208
2758
|
type: "object",
|
|
3209
2759
|
properties: {
|
|
3210
2760
|
image: TypeImageInput,
|
|
3211
|
-
model:
|
|
2761
|
+
model: modelSchema8,
|
|
3212
2762
|
minDetectionConfidence: {
|
|
3213
2763
|
type: "number",
|
|
3214
2764
|
minimum: 0,
|
|
@@ -3262,11 +2812,11 @@ class FaceDetectorTask extends AiVisionTask {
|
|
|
3262
2812
|
var faceDetector = (input, config) => {
|
|
3263
2813
|
return new FaceDetectorTask({}, config).run(input);
|
|
3264
2814
|
};
|
|
3265
|
-
|
|
2815
|
+
Workflow14.prototype.faceDetector = CreateWorkflow14(FaceDetectorTask);
|
|
3266
2816
|
|
|
3267
2817
|
// src/task/FaceLandmarkerTask.ts
|
|
3268
|
-
import { CreateWorkflow as
|
|
3269
|
-
var
|
|
2818
|
+
import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
|
|
2819
|
+
var modelSchema9 = TypeModel("model:FaceLandmarkerTask");
|
|
3270
2820
|
var TypeLandmark = {
|
|
3271
2821
|
type: "object",
|
|
3272
2822
|
properties: {
|
|
@@ -3338,7 +2888,7 @@ var FaceLandmarkerInputSchema = {
|
|
|
3338
2888
|
type: "object",
|
|
3339
2889
|
properties: {
|
|
3340
2890
|
image: TypeImageInput,
|
|
3341
|
-
model:
|
|
2891
|
+
model: modelSchema9,
|
|
3342
2892
|
numFaces: {
|
|
3343
2893
|
type: "number",
|
|
3344
2894
|
minimum: 1,
|
|
@@ -3424,11 +2974,11 @@ class FaceLandmarkerTask extends AiVisionTask {
|
|
|
3424
2974
|
var faceLandmarker = (input, config) => {
|
|
3425
2975
|
return new FaceLandmarkerTask({}, config).run(input);
|
|
3426
2976
|
};
|
|
3427
|
-
|
|
2977
|
+
Workflow15.prototype.faceLandmarker = CreateWorkflow15(FaceLandmarkerTask);
|
|
3428
2978
|
|
|
3429
2979
|
// src/task/GestureRecognizerTask.ts
|
|
3430
|
-
import { CreateWorkflow as
|
|
3431
|
-
var
|
|
2980
|
+
import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
|
|
2981
|
+
var modelSchema10 = TypeModel("model:GestureRecognizerTask");
|
|
3432
2982
|
var TypeLandmark2 = {
|
|
3433
2983
|
type: "object",
|
|
3434
2984
|
properties: {
|
|
@@ -3520,7 +3070,7 @@ var GestureRecognizerInputSchema = {
|
|
|
3520
3070
|
type: "object",
|
|
3521
3071
|
properties: {
|
|
3522
3072
|
image: TypeImageInput,
|
|
3523
|
-
model:
|
|
3073
|
+
model: modelSchema10,
|
|
3524
3074
|
numHands: {
|
|
3525
3075
|
type: "number",
|
|
3526
3076
|
minimum: 1,
|
|
@@ -3592,11 +3142,11 @@ class GestureRecognizerTask extends AiVisionTask {
|
|
|
3592
3142
|
var gestureRecognizer = (input, config) => {
|
|
3593
3143
|
return new GestureRecognizerTask({}, config).run(input);
|
|
3594
3144
|
};
|
|
3595
|
-
|
|
3145
|
+
Workflow16.prototype.gestureRecognizer = CreateWorkflow16(GestureRecognizerTask);
|
|
3596
3146
|
|
|
3597
3147
|
// src/task/HandLandmarkerTask.ts
|
|
3598
|
-
import { CreateWorkflow as
|
|
3599
|
-
var
|
|
3148
|
+
import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
|
|
3149
|
+
var modelSchema11 = TypeModel("model:HandLandmarkerTask");
|
|
3600
3150
|
var TypeLandmark3 = {
|
|
3601
3151
|
type: "object",
|
|
3602
3152
|
properties: {
|
|
@@ -3665,7 +3215,7 @@ var HandLandmarkerInputSchema = {
|
|
|
3665
3215
|
type: "object",
|
|
3666
3216
|
properties: {
|
|
3667
3217
|
image: TypeImageInput,
|
|
3668
|
-
model:
|
|
3218
|
+
model: modelSchema11,
|
|
3669
3219
|
numHands: {
|
|
3670
3220
|
type: "number",
|
|
3671
3221
|
minimum: 1,
|
|
@@ -3737,7 +3287,7 @@ class HandLandmarkerTask extends AiVisionTask {
|
|
|
3737
3287
|
var handLandmarker = (input, config) => {
|
|
3738
3288
|
return new HandLandmarkerTask({}, config).run(input);
|
|
3739
3289
|
};
|
|
3740
|
-
|
|
3290
|
+
Workflow17.prototype.handLandmarker = CreateWorkflow17(HandLandmarkerTask);
|
|
3741
3291
|
|
|
3742
3292
|
// src/task/HierarchicalChunkerTask.ts
|
|
3743
3293
|
import {
|
|
@@ -3746,13 +3296,9 @@ import {
|
|
|
3746
3296
|
getChildren as getChildren2,
|
|
3747
3297
|
hasChildren as hasChildren2
|
|
3748
3298
|
} from "@workglow/knowledge-base";
|
|
3749
|
-
import {
|
|
3750
|
-
CreateWorkflow as CreateWorkflow20,
|
|
3751
|
-
Task as Task9,
|
|
3752
|
-
Workflow as Workflow20
|
|
3753
|
-
} from "@workglow/task-graph";
|
|
3299
|
+
import { CreateWorkflow as CreateWorkflow18, Task as Task9, Workflow as Workflow18 } from "@workglow/task-graph";
|
|
3754
3300
|
import { uuid4 } from "@workglow/util";
|
|
3755
|
-
var
|
|
3301
|
+
var modelSchema12 = TypeModel("model", {
|
|
3756
3302
|
title: "Model",
|
|
3757
3303
|
description: "Model to use for token counting"
|
|
3758
3304
|
});
|
|
@@ -3796,7 +3342,7 @@ var inputSchema8 = {
|
|
|
3796
3342
|
description: "Strategy for chunking",
|
|
3797
3343
|
default: "hierarchical"
|
|
3798
3344
|
},
|
|
3799
|
-
model:
|
|
3345
|
+
model: modelSchema12
|
|
3800
3346
|
},
|
|
3801
3347
|
required: ["doc_id", "documentTree"],
|
|
3802
3348
|
additionalProperties: false
|
|
@@ -3975,18 +3521,14 @@ class HierarchicalChunkerTask extends Task9 {
|
|
|
3975
3521
|
var hierarchicalChunker = (input, config) => {
|
|
3976
3522
|
return new HierarchicalChunkerTask({}, config).run(input);
|
|
3977
3523
|
};
|
|
3978
|
-
|
|
3524
|
+
Workflow18.prototype.hierarchicalChunker = CreateWorkflow18(HierarchicalChunkerTask);
|
|
3979
3525
|
|
|
3980
3526
|
// src/task/HierarchyJoinTask.ts
|
|
3981
3527
|
import {
|
|
3982
3528
|
ChunkRecordArraySchema,
|
|
3983
3529
|
TypeKnowledgeBase as TypeKnowledgeBase5
|
|
3984
3530
|
} from "@workglow/knowledge-base";
|
|
3985
|
-
import {
|
|
3986
|
-
CreateWorkflow as CreateWorkflow21,
|
|
3987
|
-
Task as Task10,
|
|
3988
|
-
Workflow as Workflow21
|
|
3989
|
-
} from "@workglow/task-graph";
|
|
3531
|
+
import { CreateWorkflow as CreateWorkflow19, Task as Task10, Workflow as Workflow19 } from "@workglow/task-graph";
|
|
3990
3532
|
var inputSchema9 = {
|
|
3991
3533
|
type: "object",
|
|
3992
3534
|
properties: {
|
|
@@ -4155,16 +3697,16 @@ class HierarchyJoinTask extends Task10 {
|
|
|
4155
3697
|
var hierarchyJoin = (input, config) => {
|
|
4156
3698
|
return new HierarchyJoinTask({}, config).run(input);
|
|
4157
3699
|
};
|
|
4158
|
-
|
|
3700
|
+
Workflow19.prototype.hierarchyJoin = CreateWorkflow19(HierarchyJoinTask);
|
|
4159
3701
|
|
|
4160
3702
|
// src/task/ImageClassificationTask.ts
|
|
4161
|
-
import { CreateWorkflow as
|
|
4162
|
-
var
|
|
3703
|
+
import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
|
|
3704
|
+
var modelSchema13 = TypeModel("model:ImageClassificationTask");
|
|
4163
3705
|
var ImageClassificationInputSchema = {
|
|
4164
3706
|
type: "object",
|
|
4165
3707
|
properties: {
|
|
4166
3708
|
image: TypeImageInput,
|
|
4167
|
-
model:
|
|
3709
|
+
model: modelSchema13,
|
|
4168
3710
|
categories: {
|
|
4169
3711
|
type: "array",
|
|
4170
3712
|
items: {
|
|
@@ -4218,23 +3760,19 @@ class ImageClassificationTask extends AiVisionTask {
|
|
|
4218
3760
|
var imageClassification = (input, config) => {
|
|
4219
3761
|
return new ImageClassificationTask({}, config).run(input);
|
|
4220
3762
|
};
|
|
4221
|
-
|
|
3763
|
+
Workflow20.prototype.imageClassification = CreateWorkflow20(ImageClassificationTask);
|
|
4222
3764
|
|
|
4223
3765
|
// src/task/ImageEmbeddingTask.ts
|
|
4224
|
-
import { CreateWorkflow as
|
|
3766
|
+
import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
|
|
4225
3767
|
import {
|
|
4226
3768
|
TypedArraySchema as TypedArraySchema7
|
|
4227
3769
|
} from "@workglow/util/schema";
|
|
4228
|
-
var
|
|
4229
|
-
var embeddingSchema = TypedArraySchema7({
|
|
4230
|
-
title: "Embedding",
|
|
4231
|
-
description: "The image embedding vector"
|
|
4232
|
-
});
|
|
3770
|
+
var modelSchema14 = TypeModel("model:ImageEmbeddingTask");
|
|
4233
3771
|
var ImageEmbeddingInputSchema = {
|
|
4234
3772
|
type: "object",
|
|
4235
3773
|
properties: {
|
|
4236
|
-
image: TypeImageInput,
|
|
4237
|
-
model:
|
|
3774
|
+
image: TypeSingleOrArray(TypeImageInput),
|
|
3775
|
+
model: modelSchema14
|
|
4238
3776
|
},
|
|
4239
3777
|
required: ["image", "model"],
|
|
4240
3778
|
additionalProperties: false
|
|
@@ -4242,7 +3780,10 @@ var ImageEmbeddingInputSchema = {
|
|
|
4242
3780
|
var ImageEmbeddingOutputSchema = {
|
|
4243
3781
|
type: "object",
|
|
4244
3782
|
properties: {
|
|
4245
|
-
vector:
|
|
3783
|
+
vector: TypeSingleOrArray(TypedArraySchema7({
|
|
3784
|
+
title: "Embedding",
|
|
3785
|
+
description: "The image embedding vector"
|
|
3786
|
+
}))
|
|
4246
3787
|
},
|
|
4247
3788
|
required: ["vector"],
|
|
4248
3789
|
additionalProperties: false
|
|
@@ -4263,16 +3804,16 @@ class ImageEmbeddingTask extends AiVisionTask {
|
|
|
4263
3804
|
var imageEmbedding = (input, config) => {
|
|
4264
3805
|
return new ImageEmbeddingTask({}, config).run(input);
|
|
4265
3806
|
};
|
|
4266
|
-
|
|
3807
|
+
Workflow21.prototype.imageEmbedding = CreateWorkflow21(ImageEmbeddingTask);
|
|
4267
3808
|
|
|
4268
3809
|
// src/task/ImageSegmentationTask.ts
|
|
4269
|
-
import { CreateWorkflow as
|
|
4270
|
-
var
|
|
3810
|
+
import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
|
|
3811
|
+
var modelSchema15 = TypeModel("model:ImageSegmentationTask");
|
|
4271
3812
|
var ImageSegmentationInputSchema = {
|
|
4272
3813
|
type: "object",
|
|
4273
3814
|
properties: {
|
|
4274
3815
|
image: TypeImageInput,
|
|
4275
|
-
model:
|
|
3816
|
+
model: modelSchema15,
|
|
4276
3817
|
threshold: {
|
|
4277
3818
|
type: "number",
|
|
4278
3819
|
title: "Threshold",
|
|
@@ -4351,11 +3892,11 @@ class ImageSegmentationTask extends AiVisionTask {
|
|
|
4351
3892
|
var imageSegmentation = (input, config) => {
|
|
4352
3893
|
return new ImageSegmentationTask({}, config).run(input);
|
|
4353
3894
|
};
|
|
4354
|
-
|
|
3895
|
+
Workflow22.prototype.imageSegmentation = CreateWorkflow22(ImageSegmentationTask);
|
|
4355
3896
|
|
|
4356
3897
|
// src/task/ImageToTextTask.ts
|
|
4357
|
-
import { CreateWorkflow as
|
|
4358
|
-
var
|
|
3898
|
+
import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
|
|
3899
|
+
var modelSchema16 = TypeModel("model:ImageToTextTask");
|
|
4359
3900
|
var generatedTextSchema = {
|
|
4360
3901
|
type: "string",
|
|
4361
3902
|
title: "Text",
|
|
@@ -4365,7 +3906,7 @@ var ImageToTextInputSchema = {
|
|
|
4365
3906
|
type: "object",
|
|
4366
3907
|
properties: {
|
|
4367
3908
|
image: TypeImageInput,
|
|
4368
|
-
model:
|
|
3909
|
+
model: modelSchema16,
|
|
4369
3910
|
maxTokens: {
|
|
4370
3911
|
type: "number",
|
|
4371
3912
|
title: "Max Tokens",
|
|
@@ -4406,18 +3947,15 @@ class ImageToTextTask extends AiVisionTask {
|
|
|
4406
3947
|
var imageToText = (input, config) => {
|
|
4407
3948
|
return new ImageToTextTask({}, config).run(input);
|
|
4408
3949
|
};
|
|
4409
|
-
|
|
3950
|
+
Workflow23.prototype.imageToText = CreateWorkflow23(ImageToTextTask);
|
|
4410
3951
|
|
|
4411
3952
|
// src/task/ModelInfoTask.ts
|
|
4412
|
-
import {
|
|
4413
|
-
|
|
4414
|
-
Workflow as Workflow26
|
|
4415
|
-
} from "@workglow/task-graph";
|
|
4416
|
-
var modelSchema19 = TypeModel("model");
|
|
3953
|
+
import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
|
|
3954
|
+
var modelSchema17 = TypeModel("model");
|
|
4417
3955
|
var ModelInfoInputSchema = {
|
|
4418
3956
|
type: "object",
|
|
4419
3957
|
properties: {
|
|
4420
|
-
model:
|
|
3958
|
+
model: modelSchema17,
|
|
4421
3959
|
detail: {
|
|
4422
3960
|
type: "string",
|
|
4423
3961
|
enum: ["cached_status", "files", "files_with_metadata"],
|
|
@@ -4430,7 +3968,7 @@ var ModelInfoInputSchema = {
|
|
|
4430
3968
|
var ModelInfoOutputSchema = {
|
|
4431
3969
|
type: "object",
|
|
4432
3970
|
properties: {
|
|
4433
|
-
model:
|
|
3971
|
+
model: modelSchema17,
|
|
4434
3972
|
is_local: { type: "boolean" },
|
|
4435
3973
|
is_remote: { type: "boolean" },
|
|
4436
3974
|
supports_browser: { type: "boolean" },
|
|
@@ -4480,10 +4018,10 @@ class ModelInfoTask extends AiTask {
|
|
|
4480
4018
|
var modelInfo = (input, config) => {
|
|
4481
4019
|
return new ModelInfoTask({}, config).run(input);
|
|
4482
4020
|
};
|
|
4483
|
-
|
|
4021
|
+
Workflow24.prototype.modelInfo = CreateWorkflow24(ModelInfoTask);
|
|
4484
4022
|
|
|
4485
4023
|
// src/task/ModelSearchTask.ts
|
|
4486
|
-
import { CreateWorkflow as
|
|
4024
|
+
import { CreateWorkflow as CreateWorkflow25, Task as Task11, Workflow as Workflow25 } from "@workglow/task-graph";
|
|
4487
4025
|
var ModelSearchInputSchema = {
|
|
4488
4026
|
type: "object",
|
|
4489
4027
|
properties: {
|
|
@@ -4574,11 +4112,11 @@ class ModelSearchTask extends Task11 {
|
|
|
4574
4112
|
var modelSearch = (input, config) => {
|
|
4575
4113
|
return new ModelSearchTask({}, config).run(input);
|
|
4576
4114
|
};
|
|
4577
|
-
|
|
4115
|
+
Workflow25.prototype.modelSearch = CreateWorkflow25(ModelSearchTask);
|
|
4578
4116
|
|
|
4579
4117
|
// src/task/ObjectDetectionTask.ts
|
|
4580
|
-
import { CreateWorkflow as
|
|
4581
|
-
var
|
|
4118
|
+
import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
|
|
4119
|
+
var modelSchema18 = TypeModel("model:ObjectDetectionTask");
|
|
4582
4120
|
var detectionSchema = {
|
|
4583
4121
|
type: "object",
|
|
4584
4122
|
properties: {
|
|
@@ -4603,7 +4141,7 @@ var ObjectDetectionInputSchema = {
|
|
|
4603
4141
|
type: "object",
|
|
4604
4142
|
properties: {
|
|
4605
4143
|
image: TypeImageInput,
|
|
4606
|
-
model:
|
|
4144
|
+
model: modelSchema18,
|
|
4607
4145
|
labels: {
|
|
4608
4146
|
type: "array",
|
|
4609
4147
|
items: {
|
|
@@ -4657,11 +4195,11 @@ class ObjectDetectionTask extends AiVisionTask {
|
|
|
4657
4195
|
var objectDetection = (input, config) => {
|
|
4658
4196
|
return new ObjectDetectionTask({}, config).run(input);
|
|
4659
4197
|
};
|
|
4660
|
-
|
|
4198
|
+
Workflow26.prototype.objectDetection = CreateWorkflow26(ObjectDetectionTask);
|
|
4661
4199
|
|
|
4662
4200
|
// src/task/PoseLandmarkerTask.ts
|
|
4663
|
-
import { CreateWorkflow as
|
|
4664
|
-
var
|
|
4201
|
+
import { CreateWorkflow as CreateWorkflow27, Workflow as Workflow27 } from "@workglow/task-graph";
|
|
4202
|
+
var modelSchema19 = TypeModel("model:PoseLandmarkerTask");
|
|
4665
4203
|
var TypePoseLandmark = {
|
|
4666
4204
|
type: "object",
|
|
4667
4205
|
properties: {
|
|
@@ -4740,7 +4278,7 @@ var PoseLandmarkerInputSchema = {
|
|
|
4740
4278
|
type: "object",
|
|
4741
4279
|
properties: {
|
|
4742
4280
|
image: TypeImageInput,
|
|
4743
|
-
model:
|
|
4281
|
+
model: modelSchema19,
|
|
4744
4282
|
numPoses: {
|
|
4745
4283
|
type: "number",
|
|
4746
4284
|
minimum: 1,
|
|
@@ -4819,14 +4357,10 @@ class PoseLandmarkerTask extends AiVisionTask {
|
|
|
4819
4357
|
var poseLandmarker = (input, config) => {
|
|
4820
4358
|
return new PoseLandmarkerTask({}, config).run(input);
|
|
4821
4359
|
};
|
|
4822
|
-
|
|
4360
|
+
Workflow27.prototype.poseLandmarker = CreateWorkflow27(PoseLandmarkerTask);
|
|
4823
4361
|
|
|
4824
4362
|
// src/task/QueryExpanderTask.ts
|
|
4825
|
-
import {
|
|
4826
|
-
CreateWorkflow as CreateWorkflow30,
|
|
4827
|
-
Task as Task12,
|
|
4828
|
-
Workflow as Workflow30
|
|
4829
|
-
} from "@workglow/task-graph";
|
|
4363
|
+
import { CreateWorkflow as CreateWorkflow28, Task as Task12, Workflow as Workflow28 } from "@workglow/task-graph";
|
|
4830
4364
|
var QueryExpansionMethod = {
|
|
4831
4365
|
MULTI_QUERY: "multi-query",
|
|
4832
4366
|
HYDE: "hyde",
|
|
@@ -5036,26 +4570,22 @@ class QueryExpanderTask extends Task12 {
|
|
|
5036
4570
|
var queryExpander = (input, config) => {
|
|
5037
4571
|
return new QueryExpanderTask({}, config).run(input);
|
|
5038
4572
|
};
|
|
5039
|
-
|
|
4573
|
+
Workflow28.prototype.queryExpander = CreateWorkflow28(QueryExpanderTask);
|
|
5040
4574
|
|
|
5041
4575
|
// src/task/RerankerTask.ts
|
|
5042
|
-
import {
|
|
5043
|
-
CreateWorkflow as CreateWorkflow32,
|
|
5044
|
-
Task as Task13,
|
|
5045
|
-
Workflow as Workflow32
|
|
5046
|
-
} from "@workglow/task-graph";
|
|
4576
|
+
import { CreateWorkflow as CreateWorkflow30, Task as Task13, Workflow as Workflow30 } from "@workglow/task-graph";
|
|
5047
4577
|
|
|
5048
4578
|
// src/task/TextClassificationTask.ts
|
|
5049
|
-
import { CreateWorkflow as
|
|
5050
|
-
var
|
|
4579
|
+
import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
|
|
4580
|
+
var modelSchema20 = TypeModel("model:TextClassificationTask");
|
|
5051
4581
|
var TextClassificationInputSchema = {
|
|
5052
4582
|
type: "object",
|
|
5053
4583
|
properties: {
|
|
5054
|
-
text:
|
|
4584
|
+
text: {
|
|
5055
4585
|
type: "string",
|
|
5056
4586
|
title: "Text",
|
|
5057
4587
|
description: "The text to classify"
|
|
5058
|
-
}
|
|
4588
|
+
},
|
|
5059
4589
|
candidateLabels: {
|
|
5060
4590
|
type: "array",
|
|
5061
4591
|
items: {
|
|
@@ -5074,7 +4604,7 @@ var TextClassificationInputSchema = {
|
|
|
5074
4604
|
description: "The maximum number of categories to return",
|
|
5075
4605
|
"x-ui-group": "Configuration"
|
|
5076
4606
|
},
|
|
5077
|
-
model:
|
|
4607
|
+
model: modelSchema20
|
|
5078
4608
|
},
|
|
5079
4609
|
required: ["text", "model"],
|
|
5080
4610
|
additionalProperties: false
|
|
@@ -5082,7 +4612,7 @@ var TextClassificationInputSchema = {
|
|
|
5082
4612
|
var TextClassificationOutputSchema = {
|
|
5083
4613
|
type: "object",
|
|
5084
4614
|
properties: {
|
|
5085
|
-
categories:
|
|
4615
|
+
categories: {
|
|
5086
4616
|
type: "array",
|
|
5087
4617
|
items: {
|
|
5088
4618
|
type: "object",
|
|
@@ -5103,7 +4633,7 @@ var TextClassificationOutputSchema = {
|
|
|
5103
4633
|
},
|
|
5104
4634
|
title: "Categories",
|
|
5105
4635
|
description: "The classification categories with their scores"
|
|
5106
|
-
}
|
|
4636
|
+
}
|
|
5107
4637
|
},
|
|
5108
4638
|
required: ["categories"],
|
|
5109
4639
|
additionalProperties: false
|
|
@@ -5124,7 +4654,7 @@ class TextClassificationTask extends AiTask {
|
|
|
5124
4654
|
var textClassification = (input, config) => {
|
|
5125
4655
|
return new TextClassificationTask({}, config).run(input);
|
|
5126
4656
|
};
|
|
5127
|
-
|
|
4657
|
+
Workflow29.prototype.textClassification = CreateWorkflow29(TextClassificationTask);
|
|
5128
4658
|
|
|
5129
4659
|
// src/task/RerankerTask.ts
|
|
5130
4660
|
var inputSchema11 = {
|
|
@@ -5348,15 +4878,11 @@ class RerankerTask extends Task13 {
|
|
|
5348
4878
|
var reranker = (input, config) => {
|
|
5349
4879
|
return new RerankerTask({}, config).run(input);
|
|
5350
4880
|
};
|
|
5351
|
-
|
|
4881
|
+
Workflow30.prototype.reranker = CreateWorkflow30(RerankerTask);
|
|
5352
4882
|
|
|
5353
4883
|
// src/task/StructuralParserTask.ts
|
|
5354
4884
|
import { StructuralParser } from "@workglow/knowledge-base";
|
|
5355
|
-
import {
|
|
5356
|
-
CreateWorkflow as CreateWorkflow33,
|
|
5357
|
-
Task as Task14,
|
|
5358
|
-
Workflow as Workflow33
|
|
5359
|
-
} from "@workglow/task-graph";
|
|
4885
|
+
import { CreateWorkflow as CreateWorkflow31, Task as Task14, Workflow as Workflow31 } from "@workglow/task-graph";
|
|
5360
4886
|
import { uuid4 as uuid42 } from "@workglow/util";
|
|
5361
4887
|
var inputSchema12 = {
|
|
5362
4888
|
type: "object",
|
|
@@ -5457,15 +4983,15 @@ class StructuralParserTask extends Task14 {
|
|
|
5457
4983
|
var structuralParser = (input, config) => {
|
|
5458
4984
|
return new StructuralParserTask({}, config).run(input);
|
|
5459
4985
|
};
|
|
5460
|
-
|
|
4986
|
+
Workflow31.prototype.structuralParser = CreateWorkflow31(StructuralParserTask);
|
|
5461
4987
|
|
|
5462
4988
|
// src/task/StructuredGenerationTask.ts
|
|
5463
|
-
import { CreateWorkflow as
|
|
5464
|
-
var
|
|
4989
|
+
import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
|
|
4990
|
+
var modelSchema21 = TypeModel("model:StructuredGenerationTask");
|
|
5465
4991
|
var StructuredGenerationInputSchema = {
|
|
5466
4992
|
type: "object",
|
|
5467
4993
|
properties: {
|
|
5468
|
-
model:
|
|
4994
|
+
model: modelSchema21,
|
|
5469
4995
|
prompt: {
|
|
5470
4996
|
type: "string",
|
|
5471
4997
|
title: "Prompt",
|
|
@@ -5528,14 +5054,10 @@ class StructuredGenerationTask extends StreamingAiTask {
|
|
|
5528
5054
|
var structuredGeneration = (input, config) => {
|
|
5529
5055
|
return new StructuredGenerationTask({}, config).run(input);
|
|
5530
5056
|
};
|
|
5531
|
-
|
|
5057
|
+
Workflow32.prototype.structuredGeneration = CreateWorkflow32(StructuredGenerationTask);
|
|
5532
5058
|
|
|
5533
5059
|
// src/task/TextChunkerTask.ts
|
|
5534
|
-
import {
|
|
5535
|
-
CreateWorkflow as CreateWorkflow35,
|
|
5536
|
-
Task as Task15,
|
|
5537
|
-
Workflow as Workflow35
|
|
5538
|
-
} from "@workglow/task-graph";
|
|
5060
|
+
import { CreateWorkflow as CreateWorkflow33, Task as Task15, Workflow as Workflow33 } from "@workglow/task-graph";
|
|
5539
5061
|
var ChunkingStrategy = {
|
|
5540
5062
|
FIXED: "fixed",
|
|
5541
5063
|
SENTENCE: "sentence",
|
|
@@ -5784,20 +5306,20 @@ class TextChunkerTask extends Task15 {
|
|
|
5784
5306
|
var textChunker = (input, config) => {
|
|
5785
5307
|
return new TextChunkerTask({}, config).run(input);
|
|
5786
5308
|
};
|
|
5787
|
-
|
|
5309
|
+
Workflow33.prototype.textChunker = CreateWorkflow33(TextChunkerTask);
|
|
5788
5310
|
|
|
5789
5311
|
// src/task/TextFillMaskTask.ts
|
|
5790
|
-
import { CreateWorkflow as
|
|
5791
|
-
var
|
|
5312
|
+
import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
|
|
5313
|
+
var modelSchema22 = TypeModel("model:TextFillMaskTask");
|
|
5792
5314
|
var TextFillMaskInputSchema = {
|
|
5793
5315
|
type: "object",
|
|
5794
5316
|
properties: {
|
|
5795
|
-
text:
|
|
5317
|
+
text: {
|
|
5796
5318
|
type: "string",
|
|
5797
5319
|
title: "Text",
|
|
5798
5320
|
description: "The text with a mask token to fill"
|
|
5799
|
-
}
|
|
5800
|
-
model:
|
|
5321
|
+
},
|
|
5322
|
+
model: modelSchema22
|
|
5801
5323
|
},
|
|
5802
5324
|
required: ["text", "model"],
|
|
5803
5325
|
additionalProperties: false
|
|
@@ -5805,7 +5327,7 @@ var TextFillMaskInputSchema = {
|
|
|
5805
5327
|
var TextFillMaskOutputSchema = {
|
|
5806
5328
|
type: "object",
|
|
5807
5329
|
properties: {
|
|
5808
|
-
predictions:
|
|
5330
|
+
predictions: {
|
|
5809
5331
|
type: "array",
|
|
5810
5332
|
items: {
|
|
5811
5333
|
type: "object",
|
|
@@ -5831,7 +5353,7 @@ var TextFillMaskOutputSchema = {
|
|
|
5831
5353
|
},
|
|
5832
5354
|
title: "Predictions",
|
|
5833
5355
|
description: "The predicted tokens to fill the mask with their scores and complete sequences"
|
|
5834
|
-
}
|
|
5356
|
+
}
|
|
5835
5357
|
},
|
|
5836
5358
|
required: ["predictions"],
|
|
5837
5359
|
additionalProperties: false
|
|
@@ -5852,26 +5374,26 @@ class TextFillMaskTask extends AiTask {
|
|
|
5852
5374
|
var textFillMask = (input, config) => {
|
|
5853
5375
|
return new TextFillMaskTask({}, config).run(input);
|
|
5854
5376
|
};
|
|
5855
|
-
|
|
5377
|
+
Workflow34.prototype.textFillMask = CreateWorkflow34(TextFillMaskTask);
|
|
5856
5378
|
|
|
5857
5379
|
// src/task/TextGenerationTask.ts
|
|
5858
|
-
import { CreateWorkflow as
|
|
5859
|
-
var generatedTextSchema2 =
|
|
5380
|
+
import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
|
|
5381
|
+
var generatedTextSchema2 = {
|
|
5860
5382
|
type: "string",
|
|
5861
5383
|
title: "Text",
|
|
5862
5384
|
description: "The generated text",
|
|
5863
5385
|
"x-stream": "append"
|
|
5864
|
-
}
|
|
5865
|
-
var
|
|
5386
|
+
};
|
|
5387
|
+
var modelSchema23 = TypeModel("model:TextGenerationTask");
|
|
5866
5388
|
var TextGenerationInputSchema = {
|
|
5867
5389
|
type: "object",
|
|
5868
5390
|
properties: {
|
|
5869
|
-
model:
|
|
5870
|
-
prompt:
|
|
5391
|
+
model: modelSchema23,
|
|
5392
|
+
prompt: {
|
|
5871
5393
|
type: "string",
|
|
5872
5394
|
title: "Prompt",
|
|
5873
5395
|
description: "The prompt to generate text from"
|
|
5874
|
-
}
|
|
5396
|
+
},
|
|
5875
5397
|
maxTokens: {
|
|
5876
5398
|
type: "number",
|
|
5877
5399
|
title: "Max Tokens",
|
|
@@ -5940,19 +5462,19 @@ class TextGenerationTask extends StreamingAiTask {
|
|
|
5940
5462
|
var textGeneration = (input, config) => {
|
|
5941
5463
|
return new TextGenerationTask({}, config).run(input);
|
|
5942
5464
|
};
|
|
5943
|
-
|
|
5465
|
+
Workflow35.prototype.textGeneration = CreateWorkflow35(TextGenerationTask);
|
|
5944
5466
|
|
|
5945
5467
|
// src/task/TextLanguageDetectionTask.ts
|
|
5946
|
-
import { CreateWorkflow as
|
|
5947
|
-
var
|
|
5468
|
+
import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
|
|
5469
|
+
var modelSchema24 = TypeModel("model:TextLanguageDetectionTask");
|
|
5948
5470
|
var TextLanguageDetectionInputSchema = {
|
|
5949
5471
|
type: "object",
|
|
5950
5472
|
properties: {
|
|
5951
|
-
text:
|
|
5473
|
+
text: {
|
|
5952
5474
|
type: "string",
|
|
5953
5475
|
title: "Text",
|
|
5954
5476
|
description: "The text to detect the language of"
|
|
5955
|
-
}
|
|
5477
|
+
},
|
|
5956
5478
|
maxLanguages: {
|
|
5957
5479
|
type: "number",
|
|
5958
5480
|
minimum: 0,
|
|
@@ -5961,7 +5483,7 @@ var TextLanguageDetectionInputSchema = {
|
|
|
5961
5483
|
title: "Max Languages",
|
|
5962
5484
|
description: "The maximum number of languages to return"
|
|
5963
5485
|
},
|
|
5964
|
-
model:
|
|
5486
|
+
model: modelSchema24
|
|
5965
5487
|
},
|
|
5966
5488
|
required: ["text", "model"],
|
|
5967
5489
|
additionalProperties: false
|
|
@@ -5969,7 +5491,7 @@ var TextLanguageDetectionInputSchema = {
|
|
|
5969
5491
|
var TextLanguageDetectionOutputSchema = {
|
|
5970
5492
|
type: "object",
|
|
5971
5493
|
properties: {
|
|
5972
|
-
languages:
|
|
5494
|
+
languages: {
|
|
5973
5495
|
type: "array",
|
|
5974
5496
|
items: {
|
|
5975
5497
|
type: "object",
|
|
@@ -5990,7 +5512,7 @@ var TextLanguageDetectionOutputSchema = {
|
|
|
5990
5512
|
},
|
|
5991
5513
|
title: "Languages",
|
|
5992
5514
|
description: "The languages with their scores"
|
|
5993
|
-
}
|
|
5515
|
+
}
|
|
5994
5516
|
},
|
|
5995
5517
|
required: ["languages"],
|
|
5996
5518
|
additionalProperties: false
|
|
@@ -6011,33 +5533,33 @@ class TextLanguageDetectionTask extends AiTask {
|
|
|
6011
5533
|
var textLanguageDetection = (input, config) => {
|
|
6012
5534
|
return new TextLanguageDetectionTask({}, config).run(input);
|
|
6013
5535
|
};
|
|
6014
|
-
|
|
5536
|
+
Workflow36.prototype.textLanguageDetection = CreateWorkflow36(TextLanguageDetectionTask);
|
|
6015
5537
|
|
|
6016
5538
|
// src/task/TextQuestionAnswerTask.ts
|
|
6017
|
-
import { CreateWorkflow as
|
|
6018
|
-
var contextSchema =
|
|
5539
|
+
import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
|
|
5540
|
+
var contextSchema = {
|
|
6019
5541
|
type: "string",
|
|
6020
5542
|
title: "Context",
|
|
6021
5543
|
description: "The context of the question"
|
|
6022
|
-
}
|
|
6023
|
-
var questionSchema =
|
|
5544
|
+
};
|
|
5545
|
+
var questionSchema = {
|
|
6024
5546
|
type: "string",
|
|
6025
5547
|
title: "Question",
|
|
6026
5548
|
description: "The question to answer"
|
|
6027
|
-
}
|
|
6028
|
-
var textSchema =
|
|
5549
|
+
};
|
|
5550
|
+
var textSchema = {
|
|
6029
5551
|
type: "string",
|
|
6030
5552
|
title: "Text",
|
|
6031
5553
|
description: "The generated text",
|
|
6032
5554
|
"x-stream": "append"
|
|
6033
|
-
}
|
|
6034
|
-
var
|
|
5555
|
+
};
|
|
5556
|
+
var modelSchema25 = TypeModel("model:TextQuestionAnswerTask");
|
|
6035
5557
|
var TextQuestionAnswerInputSchema = {
|
|
6036
5558
|
type: "object",
|
|
6037
5559
|
properties: {
|
|
6038
5560
|
context: contextSchema,
|
|
6039
5561
|
question: questionSchema,
|
|
6040
|
-
model:
|
|
5562
|
+
model: modelSchema25
|
|
6041
5563
|
},
|
|
6042
5564
|
required: ["context", "question", "model"],
|
|
6043
5565
|
additionalProperties: false
|
|
@@ -6066,25 +5588,25 @@ class TextQuestionAnswerTask extends StreamingAiTask {
|
|
|
6066
5588
|
var textQuestionAnswer = (input, config) => {
|
|
6067
5589
|
return new TextQuestionAnswerTask({}, config).run(input);
|
|
6068
5590
|
};
|
|
6069
|
-
|
|
5591
|
+
Workflow37.prototype.textQuestionAnswer = CreateWorkflow37(TextQuestionAnswerTask);
|
|
6070
5592
|
|
|
6071
5593
|
// src/task/TextRewriterTask.ts
|
|
6072
|
-
import { CreateWorkflow as
|
|
6073
|
-
var
|
|
5594
|
+
import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
|
|
5595
|
+
var modelSchema26 = TypeModel("model:TextRewriterTask");
|
|
6074
5596
|
var TextRewriterInputSchema = {
|
|
6075
5597
|
type: "object",
|
|
6076
5598
|
properties: {
|
|
6077
|
-
text:
|
|
5599
|
+
text: {
|
|
6078
5600
|
type: "string",
|
|
6079
5601
|
title: "Text",
|
|
6080
5602
|
description: "The text to rewrite"
|
|
6081
|
-
}
|
|
5603
|
+
},
|
|
6082
5604
|
prompt: {
|
|
6083
5605
|
type: "string",
|
|
6084
5606
|
title: "Prompt",
|
|
6085
5607
|
description: "The prompt to direct the rewriting"
|
|
6086
5608
|
},
|
|
6087
|
-
model:
|
|
5609
|
+
model: modelSchema26
|
|
6088
5610
|
},
|
|
6089
5611
|
required: ["text", "prompt", "model"],
|
|
6090
5612
|
additionalProperties: false
|
|
@@ -6092,12 +5614,12 @@ var TextRewriterInputSchema = {
|
|
|
6092
5614
|
var TextRewriterOutputSchema = {
|
|
6093
5615
|
type: "object",
|
|
6094
5616
|
properties: {
|
|
6095
|
-
text:
|
|
5617
|
+
text: {
|
|
6096
5618
|
type: "string",
|
|
6097
5619
|
title: "Text",
|
|
6098
5620
|
description: "The rewritten text",
|
|
6099
5621
|
"x-stream": "append"
|
|
6100
|
-
}
|
|
5622
|
+
}
|
|
6101
5623
|
},
|
|
6102
5624
|
required: ["text"],
|
|
6103
5625
|
additionalProperties: false
|
|
@@ -6118,25 +5640,25 @@ class TextRewriterTask extends StreamingAiTask {
|
|
|
6118
5640
|
var textRewriter = (input, config) => {
|
|
6119
5641
|
return new TextRewriterTask({}, config).run(input);
|
|
6120
5642
|
};
|
|
6121
|
-
|
|
5643
|
+
Workflow38.prototype.textRewriter = CreateWorkflow38(TextRewriterTask);
|
|
6122
5644
|
|
|
6123
5645
|
// src/task/TextTranslationTask.ts
|
|
6124
|
-
import { CreateWorkflow as
|
|
6125
|
-
var
|
|
6126
|
-
var translationTextSchema =
|
|
5646
|
+
import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
|
|
5647
|
+
var modelSchema27 = TypeModel("model:TextTranslationTask");
|
|
5648
|
+
var translationTextSchema = {
|
|
6127
5649
|
type: "string",
|
|
6128
5650
|
title: "Text",
|
|
6129
5651
|
description: "The translated text",
|
|
6130
5652
|
"x-stream": "replace"
|
|
6131
|
-
}
|
|
5653
|
+
};
|
|
6132
5654
|
var TextTranslationInputSchema = {
|
|
6133
5655
|
type: "object",
|
|
6134
5656
|
properties: {
|
|
6135
|
-
text:
|
|
5657
|
+
text: {
|
|
6136
5658
|
type: "string",
|
|
6137
5659
|
title: "Text",
|
|
6138
5660
|
description: "The text to translate"
|
|
6139
|
-
}
|
|
5661
|
+
},
|
|
6140
5662
|
source_lang: TypeLanguage({
|
|
6141
5663
|
title: "Source Language",
|
|
6142
5664
|
description: "The source language",
|
|
@@ -6149,7 +5671,7 @@ var TextTranslationInputSchema = {
|
|
|
6149
5671
|
minLength: 2,
|
|
6150
5672
|
maxLength: 2
|
|
6151
5673
|
}),
|
|
6152
|
-
model:
|
|
5674
|
+
model: modelSchema27
|
|
6153
5675
|
},
|
|
6154
5676
|
required: ["text", "source_lang", "target_lang", "model"],
|
|
6155
5677
|
additionalProperties: false
|
|
@@ -6184,14 +5706,10 @@ class TextTranslationTask extends StreamingAiTask {
|
|
|
6184
5706
|
var textTranslation = (input, config) => {
|
|
6185
5707
|
return new TextTranslationTask({}, config).run(input);
|
|
6186
5708
|
};
|
|
6187
|
-
|
|
5709
|
+
Workflow39.prototype.textTranslation = CreateWorkflow39(TextTranslationTask);
|
|
6188
5710
|
|
|
6189
5711
|
// src/task/TopicSegmenterTask.ts
|
|
6190
|
-
import {
|
|
6191
|
-
CreateWorkflow as CreateWorkflow42,
|
|
6192
|
-
Task as Task16,
|
|
6193
|
-
Workflow as Workflow42
|
|
6194
|
-
} from "@workglow/task-graph";
|
|
5712
|
+
import { CreateWorkflow as CreateWorkflow40, Task as Task16, Workflow as Workflow40 } from "@workglow/task-graph";
|
|
6195
5713
|
var SegmentationMethod = {
|
|
6196
5714
|
HEURISTIC: "heuristic",
|
|
6197
5715
|
EMBEDDING_SIMILARITY: "embedding-similarity",
|
|
@@ -6471,15 +5989,15 @@ class TopicSegmenterTask extends Task16 {
|
|
|
6471
5989
|
var topicSegmenter = (input, config) => {
|
|
6472
5990
|
return new TopicSegmenterTask({}, config).run(input);
|
|
6473
5991
|
};
|
|
6474
|
-
|
|
5992
|
+
Workflow40.prototype.topicSegmenter = CreateWorkflow40(TopicSegmenterTask);
|
|
6475
5993
|
|
|
6476
5994
|
// src/task/UnloadModelTask.ts
|
|
6477
|
-
import { CreateWorkflow as
|
|
6478
|
-
var
|
|
5995
|
+
import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
|
|
5996
|
+
var modelSchema28 = TypeModel("model");
|
|
6479
5997
|
var UnloadModelInputSchema = {
|
|
6480
5998
|
type: "object",
|
|
6481
5999
|
properties: {
|
|
6482
|
-
model:
|
|
6000
|
+
model: modelSchema28
|
|
6483
6001
|
},
|
|
6484
6002
|
required: ["model"],
|
|
6485
6003
|
additionalProperties: false
|
|
@@ -6487,7 +6005,7 @@ var UnloadModelInputSchema = {
|
|
|
6487
6005
|
var UnloadModelOutputSchema = {
|
|
6488
6006
|
type: "object",
|
|
6489
6007
|
properties: {
|
|
6490
|
-
model:
|
|
6008
|
+
model: modelSchema28
|
|
6491
6009
|
},
|
|
6492
6010
|
required: ["model"],
|
|
6493
6011
|
additionalProperties: false
|
|
@@ -6509,10 +6027,10 @@ class UnloadModelTask extends AiTask {
|
|
|
6509
6027
|
var unloadModel = (input, config) => {
|
|
6510
6028
|
return new UnloadModelTask({}, config).run(input);
|
|
6511
6029
|
};
|
|
6512
|
-
|
|
6030
|
+
Workflow41.prototype.unloadModel = CreateWorkflow41(UnloadModelTask);
|
|
6513
6031
|
|
|
6514
6032
|
// src/task/VectorQuantizeTask.ts
|
|
6515
|
-
import { CreateWorkflow as
|
|
6033
|
+
import { CreateWorkflow as CreateWorkflow42, Task as Task17, Workflow as Workflow42 } from "@workglow/task-graph";
|
|
6516
6034
|
import {
|
|
6517
6035
|
normalizeNumberArray,
|
|
6518
6036
|
TensorType,
|
|
@@ -6692,10 +6210,10 @@ class VectorQuantizeTask extends Task17 {
|
|
|
6692
6210
|
var vectorQuantize = (input, config) => {
|
|
6693
6211
|
return new VectorQuantizeTask({}, config).run(input);
|
|
6694
6212
|
};
|
|
6695
|
-
|
|
6213
|
+
Workflow42.prototype.vectorQuantize = CreateWorkflow42(VectorQuantizeTask);
|
|
6696
6214
|
|
|
6697
6215
|
// src/task/VectorSimilarityTask.ts
|
|
6698
|
-
import { CreateWorkflow as
|
|
6216
|
+
import { CreateWorkflow as CreateWorkflow43, GraphAsTask, Workflow as Workflow43 } from "@workglow/task-graph";
|
|
6699
6217
|
import {
|
|
6700
6218
|
cosineSimilarity,
|
|
6701
6219
|
hammingSimilarity,
|
|
@@ -6801,208 +6319,11 @@ class VectorSimilarityTask extends GraphAsTask {
|
|
|
6801
6319
|
var similarity = (input, config) => {
|
|
6802
6320
|
return new VectorSimilarityTask({}, config).run(input);
|
|
6803
6321
|
};
|
|
6804
|
-
|
|
6805
|
-
// src/task/MessageConversion.ts
|
|
6806
|
-
function getInputMessages(input) {
|
|
6807
|
-
const messages = input.messages;
|
|
6808
|
-
if (!messages || messages.length === 0)
|
|
6809
|
-
return;
|
|
6810
|
-
return messages;
|
|
6811
|
-
}
|
|
6812
|
-
function toOpenAIMessages(input) {
|
|
6813
|
-
const messages = [];
|
|
6814
|
-
if (input.systemPrompt) {
|
|
6815
|
-
messages.push({ role: "system", content: input.systemPrompt });
|
|
6816
|
-
}
|
|
6817
|
-
const inputMessages = getInputMessages(input);
|
|
6818
|
-
if (!inputMessages) {
|
|
6819
|
-
if (!Array.isArray(input.prompt)) {
|
|
6820
|
-
messages.push({ role: "user", content: input.prompt });
|
|
6821
|
-
} else if (input.prompt.every((item) => typeof item === "string")) {
|
|
6822
|
-
messages.push({ role: "user", content: input.prompt.join(`
|
|
6823
|
-
`) });
|
|
6824
|
-
} else {
|
|
6825
|
-
const parts = [];
|
|
6826
|
-
for (const item of input.prompt) {
|
|
6827
|
-
if (typeof item === "string") {
|
|
6828
|
-
parts.push({ type: "text", text: item });
|
|
6829
|
-
} else {
|
|
6830
|
-
const b = item;
|
|
6831
|
-
if (b.type === "text") {
|
|
6832
|
-
parts.push({ type: "text", text: b.text });
|
|
6833
|
-
} else if (b.type === "image") {
|
|
6834
|
-
parts.push({
|
|
6835
|
-
type: "image_url",
|
|
6836
|
-
image_url: { url: `data:${b.mimeType};base64,${b.data}` }
|
|
6837
|
-
});
|
|
6838
|
-
} else if (b.type === "audio") {
|
|
6839
|
-
const format = b.mimeType.replace(/^audio\//, "");
|
|
6840
|
-
parts.push({
|
|
6841
|
-
type: "input_audio",
|
|
6842
|
-
input_audio: { data: b.data, format }
|
|
6843
|
-
});
|
|
6844
|
-
}
|
|
6845
|
-
}
|
|
6846
|
-
}
|
|
6847
|
-
messages.push({ role: "user", content: parts });
|
|
6848
|
-
}
|
|
6849
|
-
return messages;
|
|
6850
|
-
}
|
|
6851
|
-
for (const msg of inputMessages) {
|
|
6852
|
-
if (msg.role === "user") {
|
|
6853
|
-
if (typeof msg.content === "string") {
|
|
6854
|
-
messages.push({ role: "user", content: msg.content });
|
|
6855
|
-
} else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
|
|
6856
|
-
const parts = [];
|
|
6857
|
-
for (const block of msg.content) {
|
|
6858
|
-
const b = block;
|
|
6859
|
-
if (b.type === "text") {
|
|
6860
|
-
parts.push({ type: "text", text: b.text });
|
|
6861
|
-
} else if (b.type === "image") {
|
|
6862
|
-
parts.push({
|
|
6863
|
-
type: "image_url",
|
|
6864
|
-
image_url: { url: `data:${b.mimeType};base64,${b.data}` }
|
|
6865
|
-
});
|
|
6866
|
-
} else if (b.type === "audio") {
|
|
6867
|
-
const format = b.mimeType.replace(/^audio\//, "");
|
|
6868
|
-
parts.push({
|
|
6869
|
-
type: "input_audio",
|
|
6870
|
-
input_audio: { data: b.data, format }
|
|
6871
|
-
});
|
|
6872
|
-
}
|
|
6873
|
-
}
|
|
6874
|
-
messages.push({ role: "user", content: parts });
|
|
6875
|
-
} else {
|
|
6876
|
-
try {
|
|
6877
|
-
messages.push({ role: "user", content: JSON.stringify(msg.content) });
|
|
6878
|
-
} catch {
|
|
6879
|
-
messages.push({ role: "user", content: String(msg.content) });
|
|
6880
|
-
}
|
|
6881
|
-
}
|
|
6882
|
-
} else if (msg.role === "assistant") {
|
|
6883
|
-
if (typeof msg.content === "string") {
|
|
6884
|
-
messages.push({ role: "assistant", content: msg.content.length > 0 ? msg.content : null });
|
|
6885
|
-
} else if (Array.isArray(msg.content)) {
|
|
6886
|
-
const textParts = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
6887
|
-
const toolCalls = msg.content.filter((b) => b.type === "tool_use").map((b) => ({
|
|
6888
|
-
id: b.id,
|
|
6889
|
-
type: "function",
|
|
6890
|
-
function: {
|
|
6891
|
-
name: b.name,
|
|
6892
|
-
arguments: JSON.stringify(b.input)
|
|
6893
|
-
}
|
|
6894
|
-
}));
|
|
6895
|
-
const entry = {
|
|
6896
|
-
role: "assistant",
|
|
6897
|
-
content: textParts.length > 0 ? textParts : null
|
|
6898
|
-
};
|
|
6899
|
-
if (toolCalls.length > 0) {
|
|
6900
|
-
entry.tool_calls = toolCalls;
|
|
6901
|
-
}
|
|
6902
|
-
messages.push(entry);
|
|
6903
|
-
}
|
|
6904
|
-
} else if (msg.role === "tool" && Array.isArray(msg.content)) {
|
|
6905
|
-
for (const block of msg.content) {
|
|
6906
|
-
const b = block;
|
|
6907
|
-
let content;
|
|
6908
|
-
if (typeof b.content === "string") {
|
|
6909
|
-
content = b.content;
|
|
6910
|
-
} else if (Array.isArray(b.content)) {
|
|
6911
|
-
const parts = [];
|
|
6912
|
-
for (const inner of b.content) {
|
|
6913
|
-
if (inner.type === "text") {
|
|
6914
|
-
parts.push({ type: "text", text: inner.text });
|
|
6915
|
-
} else if (inner.type === "image") {
|
|
6916
|
-
parts.push({
|
|
6917
|
-
type: "image_url",
|
|
6918
|
-
image_url: { url: `data:${inner.mimeType};base64,${inner.data}` }
|
|
6919
|
-
});
|
|
6920
|
-
}
|
|
6921
|
-
}
|
|
6922
|
-
content = parts;
|
|
6923
|
-
} else {
|
|
6924
|
-
content = "";
|
|
6925
|
-
}
|
|
6926
|
-
messages.push({
|
|
6927
|
-
role: "tool",
|
|
6928
|
-
content,
|
|
6929
|
-
tool_call_id: b.tool_use_id
|
|
6930
|
-
});
|
|
6931
|
-
}
|
|
6932
|
-
}
|
|
6933
|
-
}
|
|
6934
|
-
return messages;
|
|
6935
|
-
}
|
|
6936
|
-
function toTextFlatMessages(input) {
|
|
6937
|
-
const messages = [];
|
|
6938
|
-
if (input.systemPrompt) {
|
|
6939
|
-
messages.push({ role: "system", content: input.systemPrompt });
|
|
6940
|
-
}
|
|
6941
|
-
const inputMessages = getInputMessages(input);
|
|
6942
|
-
if (!inputMessages) {
|
|
6943
|
-
let promptContent;
|
|
6944
|
-
if (!Array.isArray(input.prompt)) {
|
|
6945
|
-
promptContent = input.prompt;
|
|
6946
|
-
} else {
|
|
6947
|
-
promptContent = input.prompt.map((item) => {
|
|
6948
|
-
if (typeof item === "string")
|
|
6949
|
-
return item;
|
|
6950
|
-
const b = item;
|
|
6951
|
-
return b.type === "text" ? b.text : "";
|
|
6952
|
-
}).filter((s) => s !== "").join(`
|
|
6953
|
-
`);
|
|
6954
|
-
}
|
|
6955
|
-
messages.push({ role: "user", content: promptContent });
|
|
6956
|
-
return messages;
|
|
6957
|
-
}
|
|
6958
|
-
for (const msg of inputMessages) {
|
|
6959
|
-
if (msg.role === "user") {
|
|
6960
|
-
let content = "";
|
|
6961
|
-
if (typeof msg.content === "string") {
|
|
6962
|
-
content = msg.content;
|
|
6963
|
-
} else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
|
|
6964
|
-
content = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
6965
|
-
} else if (msg.content != null) {
|
|
6966
|
-
try {
|
|
6967
|
-
content = JSON.stringify(msg.content);
|
|
6968
|
-
} catch {
|
|
6969
|
-
content = String(msg.content);
|
|
6970
|
-
}
|
|
6971
|
-
}
|
|
6972
|
-
messages.push({ role: "user", content });
|
|
6973
|
-
} else if (msg.role === "assistant") {
|
|
6974
|
-
if (typeof msg.content === "string") {
|
|
6975
|
-
if (msg.content) {
|
|
6976
|
-
messages.push({ role: "assistant", content: msg.content });
|
|
6977
|
-
}
|
|
6978
|
-
} else if (Array.isArray(msg.content)) {
|
|
6979
|
-
const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
6980
|
-
if (text) {
|
|
6981
|
-
messages.push({ role: "assistant", content: text });
|
|
6982
|
-
}
|
|
6983
|
-
}
|
|
6984
|
-
} else if (msg.role === "tool" && Array.isArray(msg.content)) {
|
|
6985
|
-
for (const block of msg.content) {
|
|
6986
|
-
const b = block;
|
|
6987
|
-
let content;
|
|
6988
|
-
if (typeof b.content === "string") {
|
|
6989
|
-
content = b.content;
|
|
6990
|
-
} else if (Array.isArray(b.content)) {
|
|
6991
|
-
content = b.content.filter((inner) => inner.type === "text").map((inner) => inner.text).join("");
|
|
6992
|
-
} else {
|
|
6993
|
-
content = "";
|
|
6994
|
-
}
|
|
6995
|
-
messages.push({ role: "tool", content });
|
|
6996
|
-
}
|
|
6997
|
-
}
|
|
6998
|
-
}
|
|
6999
|
-
return messages;
|
|
7000
|
-
}
|
|
6322
|
+
Workflow43.prototype.similarity = CreateWorkflow43(VectorSimilarityTask);
|
|
7001
6323
|
|
|
7002
6324
|
// src/task/index.ts
|
|
7003
6325
|
var registerAiTasks = () => {
|
|
7004
6326
|
const tasks = [
|
|
7005
|
-
AgentTask,
|
|
7006
6327
|
BackgroundRemovalTask,
|
|
7007
6328
|
ChunkToVectorTask,
|
|
7008
6329
|
CountTokensTask,
|
|
@@ -7042,7 +6363,6 @@ var registerAiTasks = () => {
|
|
|
7042
6363
|
TextRewriterTask,
|
|
7043
6364
|
TextSummaryTask,
|
|
7044
6365
|
TextTranslationTask,
|
|
7045
|
-
ToolCallingTask,
|
|
7046
6366
|
TopicSegmenterTask,
|
|
7047
6367
|
UnloadModelTask,
|
|
7048
6368
|
VectorQuantizeTask,
|
|
@@ -7054,14 +6374,8 @@ var registerAiTasks = () => {
|
|
|
7054
6374
|
export {
|
|
7055
6375
|
vectorStoreSearch,
|
|
7056
6376
|
vectorQuantize,
|
|
7057
|
-
userMessage,
|
|
7058
6377
|
unloadModel,
|
|
7059
6378
|
topicSegmenter,
|
|
7060
|
-
toolSourceDefinitions,
|
|
7061
|
-
toolMessage,
|
|
7062
|
-
toolCalling,
|
|
7063
|
-
toTextFlatMessages,
|
|
7064
|
-
toOpenAIMessages,
|
|
7065
6379
|
textTranslation,
|
|
7066
6380
|
textSummary,
|
|
7067
6381
|
textRewriter,
|
|
@@ -7073,12 +6387,12 @@ export {
|
|
|
7073
6387
|
textEmbedding,
|
|
7074
6388
|
textClassification,
|
|
7075
6389
|
textChunker,
|
|
7076
|
-
taskTypesToTools,
|
|
7077
6390
|
structuredGeneration,
|
|
7078
6391
|
structuralParser,
|
|
7079
6392
|
similarity,
|
|
7080
6393
|
setGlobalModelRepository,
|
|
7081
6394
|
setAiProviderRegistry,
|
|
6395
|
+
resolveAiProviderGpuQueueConcurrency,
|
|
7082
6396
|
reranker,
|
|
7083
6397
|
registerAiTasks,
|
|
7084
6398
|
queryExpander,
|
|
@@ -7086,27 +6400,19 @@ export {
|
|
|
7086
6400
|
objectDetection,
|
|
7087
6401
|
modelSearch,
|
|
7088
6402
|
modelInfo,
|
|
7089
|
-
isAllowedToolName,
|
|
7090
6403
|
imageToText,
|
|
7091
6404
|
imageSegmentation,
|
|
7092
6405
|
imageEmbedding,
|
|
7093
6406
|
imageClassification,
|
|
7094
|
-
imageBlockFromDataUri,
|
|
7095
|
-
imageBlock,
|
|
7096
6407
|
hybridSearch,
|
|
7097
6408
|
hierarchyJoin,
|
|
7098
6409
|
hierarchicalChunker,
|
|
7099
|
-
hasToolCalls,
|
|
7100
6410
|
handLandmarker,
|
|
7101
6411
|
getGlobalModelRepository,
|
|
7102
6412
|
getAiProviderRegistry,
|
|
7103
6413
|
gestureRecognizer,
|
|
7104
|
-
findToolSource,
|
|
7105
|
-
filterValidToolCalls,
|
|
7106
6414
|
faceLandmarker,
|
|
7107
6415
|
faceDetector,
|
|
7108
|
-
executeToolCalls,
|
|
7109
|
-
executeToolCall,
|
|
7110
6416
|
downloadModel,
|
|
7111
6417
|
documentEnricher,
|
|
7112
6418
|
countTokens,
|
|
@@ -7114,13 +6420,7 @@ export {
|
|
|
7114
6420
|
chunkVectorUpsert,
|
|
7115
6421
|
chunkToVector,
|
|
7116
6422
|
chunkRetrieval,
|
|
7117
|
-
buildToolSources,
|
|
7118
|
-
buildToolDescription,
|
|
7119
6423
|
backgroundRemoval,
|
|
7120
|
-
audioBlockFromDataUri,
|
|
7121
|
-
audioBlock,
|
|
7122
|
-
assistantMessage,
|
|
7123
|
-
agent,
|
|
7124
6424
|
VectorSimilarityTask,
|
|
7125
6425
|
VectorQuantizeTask,
|
|
7126
6426
|
UnloadModelTask,
|
|
@@ -7134,10 +6434,6 @@ export {
|
|
|
7134
6434
|
TypeBoundingBox,
|
|
7135
6435
|
TypeAudioInput,
|
|
7136
6436
|
TopicSegmenterTask,
|
|
7137
|
-
ToolDefinitionSchema,
|
|
7138
|
-
ToolCallingTask,
|
|
7139
|
-
ToolCallingOutputSchema,
|
|
7140
|
-
ToolCallingInputSchema,
|
|
7141
6437
|
TextTranslationTask,
|
|
7142
6438
|
TextTranslationOutputSchema,
|
|
7143
6439
|
TextTranslationInputSchema,
|
|
@@ -7177,6 +6473,7 @@ export {
|
|
|
7177
6473
|
SimilarityFn,
|
|
7178
6474
|
SegmentationMethod,
|
|
7179
6475
|
RerankerTask,
|
|
6476
|
+
QueuedExecutionStrategy,
|
|
7180
6477
|
QueuedAiProvider,
|
|
7181
6478
|
QueryExpansionMethod,
|
|
7182
6479
|
QueryExpanderTask,
|
|
@@ -7222,6 +6519,7 @@ export {
|
|
|
7222
6519
|
FaceDetectorInputSchema,
|
|
7223
6520
|
DownloadModelTask,
|
|
7224
6521
|
DocumentEnricherTask,
|
|
6522
|
+
DirectExecutionStrategy,
|
|
7225
6523
|
CountTokensTask,
|
|
7226
6524
|
CountTokensOutputSchema,
|
|
7227
6525
|
CountTokensInputSchema,
|
|
@@ -7239,10 +6537,7 @@ export {
|
|
|
7239
6537
|
AiTask,
|
|
7240
6538
|
AiProviderRegistry,
|
|
7241
6539
|
AiProvider,
|
|
7242
|
-
AiJob
|
|
7243
|
-
AgentTask,
|
|
7244
|
-
AgentOutputSchema,
|
|
7245
|
-
AgentInputSchema
|
|
6540
|
+
AiJob
|
|
7246
6541
|
};
|
|
7247
6542
|
|
|
7248
|
-
//# debugId=
|
|
6543
|
+
//# debugId=402C8B26C7EE876D64756E2164756E21
|