@workglow/ai 0.0.125 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -47
- package/dist/browser.d.ts +7 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +565 -1277
- package/dist/browser.js.map +56 -61
- package/dist/{types.d.ts → bun.d.ts} +1 -1
- package/dist/bun.d.ts.map +1 -0
- package/dist/bun.js +565 -1277
- 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.d.ts +7 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +565 -1277
- 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 +3 -3
- 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 +217 -233
- package/dist/worker.js.map +7 -7
- package/package.json +24 -15
- 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/types.d.ts.map +0 -1
package/dist/node.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,61 @@ function setAiProviderRegistry(pr) {
|
|
|
107
136
|
}
|
|
108
137
|
|
|
109
138
|
// src/job/AiJob.ts
|
|
139
|
+
var DEFAULT_AI_TIMEOUT_MS = 120000;
|
|
140
|
+
var LOCAL_LLAMACPP_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_LLAMACPP_DEFAULT_TIMEOUT_MS;
|
|
147
|
+
}
|
|
148
|
+
return DEFAULT_AI_TIMEOUT_MS;
|
|
149
|
+
}
|
|
150
|
+
function classifyProviderError(err, taskType, provider) {
|
|
151
|
+
if (err instanceof PermanentJobError || err instanceof RetryableJobError || err instanceof AbortSignalJobError) {
|
|
152
|
+
return err;
|
|
153
|
+
}
|
|
154
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
155
|
+
const status = typeof err?.status === "number" ? err.status : typeof err?.statusCode === "number" ? err.statusCode : (() => {
|
|
156
|
+
const m = message.match(/\b([45]\d{2})\b/);
|
|
157
|
+
return m ? parseInt(m[1], 10) : undefined;
|
|
158
|
+
})();
|
|
159
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
160
|
+
return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider})`);
|
|
161
|
+
}
|
|
162
|
+
if (err instanceof DOMException && err.name === "TimeoutError") {
|
|
163
|
+
return new AbortSignalJobError(`Provider call timed out for ${taskType} (${provider})`);
|
|
164
|
+
}
|
|
165
|
+
if (message.includes("Pipeline download aborted") || message.includes("Operation aborted") || message.includes("operation was aborted") || message.includes("The operation was aborted")) {
|
|
166
|
+
return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider}): ${message}`);
|
|
167
|
+
}
|
|
168
|
+
if (message.startsWith("HFT_NULL_PROCESSOR:")) {
|
|
169
|
+
return new RetryableJobError(message);
|
|
170
|
+
}
|
|
171
|
+
if (status === 429) {
|
|
172
|
+
const retryAfterMatch = message.match(/retry.after[:\s]*(\d+)/i);
|
|
173
|
+
const retryMs = retryAfterMatch ? parseInt(retryAfterMatch[1], 10) * 1000 : 30000;
|
|
174
|
+
return new RetryableJobError(`Rate limited by ${provider} for ${taskType}: ${message}`, new Date(Date.now() + retryMs));
|
|
175
|
+
}
|
|
176
|
+
if (status === 401 || status === 403) {
|
|
177
|
+
return new PermanentJobError(`Authentication failed for ${provider} (${taskType}): ${message}`);
|
|
178
|
+
}
|
|
179
|
+
if (status === 400 || status === 404) {
|
|
180
|
+
return new PermanentJobError(`Invalid request to ${provider} for ${taskType}: ${message}`);
|
|
181
|
+
}
|
|
182
|
+
if (status && status >= 500) {
|
|
183
|
+
return new RetryableJobError(`Server error from ${provider} for ${taskType} (HTTP ${status}): ${message}`);
|
|
184
|
+
}
|
|
185
|
+
if (message.includes("ECONNREFUSED") || message.includes("ECONNRESET") || message.includes("ETIMEDOUT") || message.includes("fetch failed") || message.includes("network") || err instanceof TypeError && message.includes("fetch")) {
|
|
186
|
+
return new RetryableJobError(`Network error calling ${provider} for ${taskType}: ${message}`);
|
|
187
|
+
}
|
|
188
|
+
if (message.includes("timed out") || message.includes("timeout")) {
|
|
189
|
+
return new RetryableJobError(`Timeout calling ${provider} for ${taskType}: ${message}`);
|
|
190
|
+
}
|
|
191
|
+
return new PermanentJobError(`Provider ${provider} failed for ${taskType}: ${message}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
110
194
|
class AiJob extends Job {
|
|
111
195
|
async execute(input, context) {
|
|
112
196
|
if (context.signal.aborted || this.status === JobStatus.ABORTING) {
|
|
@@ -123,17 +207,19 @@ class AiJob extends Job {
|
|
|
123
207
|
});
|
|
124
208
|
const runFn = async () => {
|
|
125
209
|
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
210
|
const model = input.taskInput.model;
|
|
130
|
-
if (context.signal
|
|
211
|
+
if (context.signal.aborted) {
|
|
131
212
|
throw new AbortSignalJobError("Job aborted");
|
|
132
213
|
}
|
|
133
|
-
|
|
214
|
+
const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
|
|
215
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
216
|
+
const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
|
|
217
|
+
return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema);
|
|
134
218
|
};
|
|
135
219
|
const runFnPromise = runFn();
|
|
136
220
|
return await Promise.race([runFnPromise, abortPromise]);
|
|
221
|
+
} catch (err) {
|
|
222
|
+
throw classifyProviderError(err, input.taskType, input.aiProvider);
|
|
137
223
|
} finally {
|
|
138
224
|
if (abortHandler) {
|
|
139
225
|
abortHandler();
|
|
@@ -151,35 +237,172 @@ class AiJob extends Job {
|
|
|
151
237
|
return;
|
|
152
238
|
}
|
|
153
239
|
const model = input.taskInput.model;
|
|
154
|
-
|
|
240
|
+
let lastFinishData;
|
|
241
|
+
const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
|
|
242
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
243
|
+
const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
|
|
244
|
+
try {
|
|
245
|
+
for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema)) {
|
|
246
|
+
if (event.type === "finish") {
|
|
247
|
+
lastFinishData = event.data;
|
|
248
|
+
}
|
|
249
|
+
yield event;
|
|
250
|
+
}
|
|
251
|
+
} catch (err) {
|
|
252
|
+
const logger = getLogger();
|
|
253
|
+
logger.warn(`AiJob: Stream error for ${input.taskType} (${input.aiProvider}): ${err instanceof Error ? err.message : String(err)}`);
|
|
254
|
+
if (lastFinishData === undefined) {
|
|
255
|
+
yield { type: "finish", data: {} };
|
|
256
|
+
}
|
|
257
|
+
throw classifyProviderError(err, input.taskType, input.aiProvider);
|
|
258
|
+
}
|
|
155
259
|
}
|
|
156
260
|
}
|
|
157
261
|
|
|
158
|
-
// src/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
262
|
+
// src/execution/DirectExecutionStrategy.ts
|
|
263
|
+
class DirectExecutionStrategy {
|
|
264
|
+
async execute(jobInput, context, runnerId) {
|
|
265
|
+
const job = new AiJob({
|
|
266
|
+
queueName: jobInput.aiProvider,
|
|
267
|
+
jobRunId: runnerId,
|
|
268
|
+
input: jobInput
|
|
269
|
+
});
|
|
270
|
+
const cleanup = job.onJobProgress((progress, message, details) => {
|
|
271
|
+
context.updateProgress(progress, message, details);
|
|
272
|
+
});
|
|
273
|
+
try {
|
|
274
|
+
return await job.execute(jobInput, {
|
|
275
|
+
signal: context.signal,
|
|
276
|
+
updateProgress: context.updateProgress
|
|
277
|
+
});
|
|
278
|
+
} finally {
|
|
279
|
+
cleanup();
|
|
280
|
+
}
|
|
166
281
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
282
|
+
async* executeStream(jobInput, context, runnerId) {
|
|
283
|
+
const job = new AiJob({
|
|
284
|
+
queueName: jobInput.aiProvider,
|
|
285
|
+
jobRunId: runnerId,
|
|
286
|
+
input: jobInput
|
|
287
|
+
});
|
|
288
|
+
yield* job.executeStream(jobInput, {
|
|
289
|
+
signal: context.signal,
|
|
290
|
+
updateProgress: context.updateProgress
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
abort() {}
|
|
171
294
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
295
|
+
|
|
296
|
+
// src/execution/QueuedExecutionStrategy.ts
|
|
297
|
+
import { ConcurrencyLimiter, JobQueueClient, JobQueueServer } from "@workglow/job-queue";
|
|
298
|
+
import { InMemoryQueueStorage } from "@workglow/storage";
|
|
299
|
+
import {
|
|
300
|
+
getTaskQueueRegistry,
|
|
301
|
+
TaskConfigurationError
|
|
302
|
+
} from "@workglow/task-graph";
|
|
303
|
+
class QueuedExecutionStrategy {
|
|
304
|
+
queueName;
|
|
305
|
+
concurrency;
|
|
306
|
+
autoCreate;
|
|
307
|
+
initPromise = null;
|
|
308
|
+
constructor(queueName, concurrency = 1, autoCreate = true) {
|
|
309
|
+
this.queueName = queueName;
|
|
310
|
+
this.concurrency = concurrency;
|
|
311
|
+
this.autoCreate = autoCreate;
|
|
312
|
+
}
|
|
313
|
+
async execute(jobInput, context, runnerId) {
|
|
314
|
+
if (context.signal.aborted) {
|
|
315
|
+
throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
316
|
+
}
|
|
317
|
+
const registeredQueue = await this.ensureQueue();
|
|
318
|
+
const { client } = registeredQueue;
|
|
319
|
+
const handle = await client.submit(jobInput, {
|
|
320
|
+
jobRunId: runnerId,
|
|
321
|
+
maxRetries: 10
|
|
322
|
+
});
|
|
323
|
+
const onAbort = () => {
|
|
324
|
+
handle.abort().catch((err) => {
|
|
325
|
+
console.warn(`Failed to abort queued job`, err);
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
context.signal.addEventListener("abort", onAbort);
|
|
329
|
+
const cleanupProgress = handle.onProgress((progress, message, details) => {
|
|
330
|
+
context.updateProgress(progress, message, details);
|
|
331
|
+
});
|
|
332
|
+
try {
|
|
333
|
+
if (context.signal.aborted) {
|
|
334
|
+
throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
335
|
+
}
|
|
336
|
+
const output = await handle.waitFor();
|
|
337
|
+
return output;
|
|
338
|
+
} finally {
|
|
339
|
+
cleanupProgress();
|
|
340
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
176
341
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
342
|
+
}
|
|
343
|
+
abort() {}
|
|
344
|
+
async* executeStream(jobInput, context, runnerId) {
|
|
345
|
+
const result = await this.execute(jobInput, context, runnerId);
|
|
346
|
+
yield { type: "finish", data: result };
|
|
347
|
+
}
|
|
348
|
+
ensureQueue() {
|
|
349
|
+
if (!this.initPromise) {
|
|
350
|
+
this.initPromise = this.createQueue().catch((err) => {
|
|
351
|
+
this.initPromise = null;
|
|
352
|
+
throw err;
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return this.initPromise;
|
|
356
|
+
}
|
|
357
|
+
async createQueue() {
|
|
358
|
+
const registry = getTaskQueueRegistry();
|
|
359
|
+
const existing = registry.getQueue(this.queueName);
|
|
360
|
+
if (existing) {
|
|
361
|
+
if (!existing.server.isRunning()) {
|
|
362
|
+
await existing.server.start();
|
|
363
|
+
}
|
|
364
|
+
return existing;
|
|
365
|
+
}
|
|
366
|
+
if (!this.autoCreate) {
|
|
367
|
+
throw new TaskConfigurationError(`Queue "${this.queueName}" is not registered and autoCreate is disabled. ` + `Register the queue before executing tasks with this provider.`);
|
|
368
|
+
}
|
|
369
|
+
const storage = new InMemoryQueueStorage(this.queueName);
|
|
370
|
+
await storage.setupDatabase();
|
|
371
|
+
const server = new JobQueueServer(AiJob, {
|
|
372
|
+
storage,
|
|
373
|
+
queueName: this.queueName,
|
|
374
|
+
limiter: new ConcurrencyLimiter(this.concurrency)
|
|
375
|
+
});
|
|
376
|
+
const client = new JobQueueClient({
|
|
377
|
+
storage,
|
|
378
|
+
queueName: this.queueName
|
|
180
379
|
});
|
|
181
|
-
|
|
182
|
-
|
|
380
|
+
client.attach(server);
|
|
381
|
+
const registeredQueue = {
|
|
382
|
+
server,
|
|
383
|
+
client,
|
|
384
|
+
storage
|
|
385
|
+
};
|
|
386
|
+
try {
|
|
387
|
+
registry.registerQueue(registeredQueue);
|
|
388
|
+
} catch (err) {
|
|
389
|
+
if (err instanceof Error && err.message.includes("already exists")) {
|
|
390
|
+
server.stop().catch((stopErr) => {
|
|
391
|
+
console.warn("QueuedExecutionStrategy: failed to stop raced-out queue server", stopErr);
|
|
392
|
+
});
|
|
393
|
+
const raced = registry.getQueue(this.queueName);
|
|
394
|
+
if (raced) {
|
|
395
|
+
if (!raced.server.isRunning()) {
|
|
396
|
+
await raced.server.start();
|
|
397
|
+
}
|
|
398
|
+
return raced;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
throw err;
|
|
402
|
+
}
|
|
403
|
+
await server.start();
|
|
404
|
+
return registeredQueue;
|
|
405
|
+
}
|
|
183
406
|
}
|
|
184
407
|
|
|
185
408
|
// src/model/InMemoryModelRepository.ts
|
|
@@ -352,6 +575,16 @@ import {
|
|
|
352
575
|
globalServiceRegistry as globalServiceRegistry3,
|
|
353
576
|
WORKER_MANAGER as WORKER_MANAGER2
|
|
354
577
|
} from "@workglow/util/worker";
|
|
578
|
+
function resolveAiProviderGpuQueueConcurrency(concurrency) {
|
|
579
|
+
if (concurrency === undefined) {
|
|
580
|
+
return 1;
|
|
581
|
+
}
|
|
582
|
+
if (typeof concurrency === "number") {
|
|
583
|
+
return concurrency;
|
|
584
|
+
}
|
|
585
|
+
return concurrency.gpu ?? 1;
|
|
586
|
+
}
|
|
587
|
+
|
|
355
588
|
class AiProvider {
|
|
356
589
|
tasks;
|
|
357
590
|
streamTasks;
|
|
@@ -411,7 +644,12 @@ class AiProvider {
|
|
|
411
644
|
}
|
|
412
645
|
}
|
|
413
646
|
registry.registerProvider(this);
|
|
414
|
-
|
|
647
|
+
try {
|
|
648
|
+
await this.afterRegister(options);
|
|
649
|
+
} catch (err) {
|
|
650
|
+
registry.unregisterProvider(this.name);
|
|
651
|
+
throw err;
|
|
652
|
+
}
|
|
415
653
|
}
|
|
416
654
|
registerOnWorkerServer(workerServer) {
|
|
417
655
|
if (!this.tasks) {
|
|
@@ -436,115 +674,28 @@ class AiProvider {
|
|
|
436
674
|
async afterRegister(_options) {}
|
|
437
675
|
}
|
|
438
676
|
|
|
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
677
|
// src/provider/QueuedAiProvider.ts
|
|
461
678
|
class QueuedAiProvider extends AiProvider {
|
|
679
|
+
queuedStrategy;
|
|
462
680
|
async afterRegister(options) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
681
|
+
const autoCreate = options.queue?.autoCreate !== false;
|
|
682
|
+
this.queuedStrategy = new QueuedExecutionStrategy(`${this.name}_gpu`, resolveAiProviderGpuQueueConcurrency(options.queue?.concurrency), autoCreate);
|
|
683
|
+
getAiProviderRegistry().registerStrategyResolver(this.name, (model) => this.getStrategyForModel(model));
|
|
684
|
+
}
|
|
685
|
+
createQueuedStrategy(queueName, concurrency, options) {
|
|
686
|
+
const autoCreate = options.queue?.autoCreate !== false;
|
|
687
|
+
return new QueuedExecutionStrategy(queueName, concurrency, autoCreate);
|
|
688
|
+
}
|
|
689
|
+
getStrategyForModel(_model) {
|
|
690
|
+
return this.queuedStrategy;
|
|
466
691
|
}
|
|
467
692
|
}
|
|
468
693
|
|
|
469
694
|
// src/task/index.ts
|
|
470
695
|
import { TaskRegistry } from "@workglow/task-graph";
|
|
471
696
|
|
|
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";
|
|
697
|
+
// src/task/BackgroundRemovalTask.ts
|
|
698
|
+
import { CreateWorkflow, Workflow } from "@workglow/task-graph";
|
|
548
699
|
|
|
549
700
|
// src/task/base/AiTaskSchemas.ts
|
|
550
701
|
var TypeLanguage = (annotations = {}) => ({
|
|
@@ -703,32 +854,44 @@ var TypeCategory = {
|
|
|
703
854
|
description: "Classification category with label and score"
|
|
704
855
|
};
|
|
705
856
|
|
|
706
|
-
// src/task/base/
|
|
707
|
-
import {
|
|
708
|
-
getStreamingPorts
|
|
709
|
-
} from "@workglow/task-graph";
|
|
857
|
+
// src/task/base/AiVisionTask.ts
|
|
858
|
+
import { convertImageDataToUseableForm } from "@workglow/util/media";
|
|
710
859
|
|
|
711
860
|
// src/task/base/AiTask.ts
|
|
712
861
|
import {
|
|
713
|
-
|
|
714
|
-
|
|
862
|
+
Task,
|
|
863
|
+
TaskConfigSchema,
|
|
864
|
+
TaskConfigurationError as TaskConfigurationError2,
|
|
715
865
|
hasStructuredOutput
|
|
716
866
|
} from "@workglow/task-graph";
|
|
717
867
|
function schemaFormat(schema) {
|
|
718
868
|
return typeof schema === "object" && schema !== null && "format" in schema ? schema.format : undefined;
|
|
719
869
|
}
|
|
870
|
+
var aiTaskConfigSchema = {
|
|
871
|
+
type: "object",
|
|
872
|
+
properties: {
|
|
873
|
+
...TaskConfigSchema["properties"]
|
|
874
|
+
},
|
|
875
|
+
additionalProperties: false
|
|
876
|
+
};
|
|
720
877
|
|
|
721
|
-
class AiTask extends
|
|
878
|
+
class AiTask extends Task {
|
|
722
879
|
static type = "AiTask";
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
this.jobClass = AiJob;
|
|
880
|
+
static configSchema() {
|
|
881
|
+
return aiTaskConfigSchema;
|
|
726
882
|
}
|
|
727
|
-
async
|
|
883
|
+
async execute(input, executeContext) {
|
|
728
884
|
const model = input.model;
|
|
729
885
|
if (!model || typeof model !== "object") {
|
|
730
|
-
throw new
|
|
886
|
+
throw new TaskConfigurationError2("AiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
|
|
731
887
|
}
|
|
888
|
+
const jobInput = await this.getJobInput(input);
|
|
889
|
+
const strategy = getAiProviderRegistry().getStrategy(model);
|
|
890
|
+
const output = await strategy.execute(jobInput, executeContext, this.runConfig.runnerId);
|
|
891
|
+
return output;
|
|
892
|
+
}
|
|
893
|
+
async getJobInput(input) {
|
|
894
|
+
const model = input.model;
|
|
732
895
|
const runtype = this.constructor.runtype ?? this.constructor.type;
|
|
733
896
|
const jobInput = {
|
|
734
897
|
taskType: runtype,
|
|
@@ -736,7 +899,7 @@ class AiTask extends JobQueueTask {
|
|
|
736
899
|
taskInput: input
|
|
737
900
|
};
|
|
738
901
|
const inputOutputSchema = input.outputSchema;
|
|
739
|
-
if (inputOutputSchema && typeof inputOutputSchema === "object") {
|
|
902
|
+
if (inputOutputSchema && typeof inputOutputSchema === "object" && !Array.isArray(inputOutputSchema) && typeof inputOutputSchema.type === "string") {
|
|
740
903
|
jobInput.outputSchema = inputOutputSchema;
|
|
741
904
|
} else {
|
|
742
905
|
const taskOutputSchema = this.outputSchema();
|
|
@@ -750,7 +913,7 @@ class AiTask extends JobQueueTask {
|
|
|
750
913
|
const jobInput = await this.getJobInput(input);
|
|
751
914
|
const resolvedQueueName = queueName ?? await this.getDefaultQueueName(input);
|
|
752
915
|
if (!resolvedQueueName) {
|
|
753
|
-
throw new
|
|
916
|
+
throw new TaskConfigurationError2("AiTask: Unable to determine queue for AI provider");
|
|
754
917
|
}
|
|
755
918
|
const job = new AiJob({
|
|
756
919
|
queueName: resolvedQueueName,
|
|
@@ -778,7 +941,7 @@ class AiTask extends JobQueueTask {
|
|
|
778
941
|
const inputSchema = this.inputSchema();
|
|
779
942
|
if (typeof inputSchema === "boolean") {
|
|
780
943
|
if (inputSchema === false) {
|
|
781
|
-
throw new
|
|
944
|
+
throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
|
|
782
945
|
}
|
|
783
946
|
return true;
|
|
784
947
|
}
|
|
@@ -788,17 +951,18 @@ class AiTask extends JobQueueTask {
|
|
|
788
951
|
if (typeof model === "object" && model !== null) {
|
|
789
952
|
const tasks = model.tasks;
|
|
790
953
|
if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
|
|
791
|
-
|
|
954
|
+
const modelId = model.model_id ?? "(inline config)";
|
|
955
|
+
throw new TaskConfigurationError2(`AiTask: Model "${modelId}" for '${key}' is not compatible with task '${this.type}'. ` + `Model supports: [${tasks.join(", ")}]`);
|
|
792
956
|
}
|
|
793
957
|
} else if (model !== undefined && model !== null) {
|
|
794
|
-
throw new
|
|
958
|
+
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
959
|
}
|
|
796
960
|
}
|
|
797
961
|
const modelPlainProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema) === "model");
|
|
798
962
|
for (const [key] of modelPlainProperties) {
|
|
799
963
|
const model = input[key];
|
|
800
964
|
if (model !== undefined && model !== null && typeof model !== "object") {
|
|
801
|
-
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.`);
|
|
802
966
|
}
|
|
803
967
|
}
|
|
804
968
|
return super.validateInput(input);
|
|
@@ -807,14 +971,14 @@ class AiTask extends JobQueueTask {
|
|
|
807
971
|
const inputSchema = this.inputSchema();
|
|
808
972
|
if (typeof inputSchema === "boolean") {
|
|
809
973
|
if (inputSchema === false) {
|
|
810
|
-
throw new
|
|
974
|
+
throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
|
|
811
975
|
}
|
|
812
976
|
return input;
|
|
813
977
|
}
|
|
814
978
|
const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
|
|
815
979
|
if (modelTaskProperties.length > 0) {
|
|
816
980
|
const modelRepo = registry.get(MODEL_REPOSITORY);
|
|
817
|
-
const taskModels = await modelRepo.findModelsByTask(this.type);
|
|
981
|
+
const taskModels = await modelRepo.findModelsByTask(this.type) ?? [];
|
|
818
982
|
for (const [key, propSchema] of modelTaskProperties) {
|
|
819
983
|
const requestedModel = input[key];
|
|
820
984
|
if (typeof requestedModel === "string") {
|
|
@@ -826,666 +990,29 @@ class AiTask extends JobQueueTask {
|
|
|
826
990
|
const model = requestedModel;
|
|
827
991
|
const tasks = model.tasks;
|
|
828
992
|
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;
|
|
993
|
+
input[key] = undefined;
|
|
994
|
+
}
|
|
1418
995
|
}
|
|
1419
996
|
}
|
|
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
997
|
}
|
|
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)];
|
|
998
|
+
return input;
|
|
1463
999
|
}
|
|
1464
1000
|
}
|
|
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
1001
|
|
|
1473
1002
|
// src/task/base/AiVisionTask.ts
|
|
1474
|
-
import { convertImageDataToUseableForm } from "@workglow/util/media";
|
|
1475
1003
|
class AiVisionTask extends AiTask {
|
|
1476
1004
|
static type = "AiVisionTask";
|
|
1477
1005
|
async getJobInput(input) {
|
|
1478
1006
|
const jobInput = await super.getJobInput(input);
|
|
1479
|
-
const
|
|
1480
|
-
const queueName = registeredQueue?.server.queueName;
|
|
1007
|
+
const providerName = input.model.provider;
|
|
1481
1008
|
const supports = ["Blob"];
|
|
1482
1009
|
if (input.image) {
|
|
1483
|
-
if (typeof
|
|
1010
|
+
if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "ImageBitmap" in globalThis) {
|
|
1484
1011
|
supports.push("ImageBitmap");
|
|
1485
|
-
} else if (typeof
|
|
1012
|
+
} else if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "VideoFrame" in globalThis) {
|
|
1486
1013
|
supports.push("VideoFrame");
|
|
1487
1014
|
}
|
|
1488
|
-
const image = await convertImageDataToUseableForm(input.image, supports);
|
|
1015
|
+
const image = Array.isArray(input.image) ? await Promise.all(input.image.map((img) => convertImageDataToUseableForm(img, supports))) : await convertImageDataToUseableForm(input.image, supports);
|
|
1489
1016
|
jobInput.taskInput.image = image;
|
|
1490
1017
|
}
|
|
1491
1018
|
return jobInput;
|
|
@@ -1493,7 +1020,7 @@ class AiVisionTask extends AiTask {
|
|
|
1493
1020
|
}
|
|
1494
1021
|
|
|
1495
1022
|
// src/task/BackgroundRemovalTask.ts
|
|
1496
|
-
var
|
|
1023
|
+
var modelSchema = TypeModel("model:BackgroundRemovalTask");
|
|
1497
1024
|
var processedImageSchema = {
|
|
1498
1025
|
type: "string",
|
|
1499
1026
|
contentEncoding: "base64",
|
|
@@ -1505,7 +1032,7 @@ var BackgroundRemovalInputSchema = {
|
|
|
1505
1032
|
type: "object",
|
|
1506
1033
|
properties: {
|
|
1507
1034
|
image: TypeImageInput,
|
|
1508
|
-
model:
|
|
1035
|
+
model: modelSchema
|
|
1509
1036
|
},
|
|
1510
1037
|
required: ["image", "model"],
|
|
1511
1038
|
additionalProperties: false
|
|
@@ -1534,26 +1061,22 @@ class BackgroundRemovalTask extends AiVisionTask {
|
|
|
1534
1061
|
var backgroundRemoval = (input, config) => {
|
|
1535
1062
|
return new BackgroundRemovalTask({}, config).run(input);
|
|
1536
1063
|
};
|
|
1537
|
-
|
|
1064
|
+
Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
|
|
1538
1065
|
|
|
1539
1066
|
// src/task/ChunkRetrievalTask.ts
|
|
1540
1067
|
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";
|
|
1068
|
+
import { CreateWorkflow as CreateWorkflow3, Task as Task2, Workflow as Workflow3 } from "@workglow/task-graph";
|
|
1546
1069
|
import {
|
|
1547
1070
|
isTypedArray,
|
|
1548
1071
|
TypedArraySchema as TypedArraySchema2
|
|
1549
1072
|
} from "@workglow/util/schema";
|
|
1550
1073
|
|
|
1551
1074
|
// src/task/TextEmbeddingTask.ts
|
|
1552
|
-
import { CreateWorkflow as
|
|
1075
|
+
import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
|
|
1553
1076
|
import {
|
|
1554
1077
|
TypedArraySchema
|
|
1555
1078
|
} from "@workglow/util/schema";
|
|
1556
|
-
var
|
|
1079
|
+
var modelSchema2 = TypeModel("model:TextEmbeddingTask");
|
|
1557
1080
|
var TextEmbeddingInputSchema = {
|
|
1558
1081
|
type: "object",
|
|
1559
1082
|
properties: {
|
|
@@ -1562,7 +1085,7 @@ var TextEmbeddingInputSchema = {
|
|
|
1562
1085
|
title: "Text",
|
|
1563
1086
|
description: "The text to embed"
|
|
1564
1087
|
}),
|
|
1565
|
-
model:
|
|
1088
|
+
model: modelSchema2
|
|
1566
1089
|
},
|
|
1567
1090
|
required: ["text", "model"],
|
|
1568
1091
|
additionalProperties: false
|
|
@@ -1594,7 +1117,7 @@ class TextEmbeddingTask extends AiTask {
|
|
|
1594
1117
|
var textEmbedding = async (input, config) => {
|
|
1595
1118
|
return new TextEmbeddingTask({}, config).run(input);
|
|
1596
1119
|
};
|
|
1597
|
-
|
|
1120
|
+
Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
|
|
1598
1121
|
|
|
1599
1122
|
// src/task/ChunkRetrievalTask.ts
|
|
1600
1123
|
var inputSchema = {
|
|
@@ -1786,15 +1309,11 @@ class ChunkRetrievalTask extends Task2 {
|
|
|
1786
1309
|
var chunkRetrieval = (input, config) => {
|
|
1787
1310
|
return new ChunkRetrievalTask({}, config).run(input);
|
|
1788
1311
|
};
|
|
1789
|
-
|
|
1312
|
+
Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
|
|
1790
1313
|
|
|
1791
1314
|
// src/task/ChunkToVectorTask.ts
|
|
1792
1315
|
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";
|
|
1316
|
+
import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
|
|
1798
1317
|
import {
|
|
1799
1318
|
TypedArraySchema as TypedArraySchema3
|
|
1800
1319
|
} from "@workglow/util/schema";
|
|
@@ -1920,15 +1439,11 @@ class ChunkToVectorTask extends Task3 {
|
|
|
1920
1439
|
var chunkToVector = (input, config) => {
|
|
1921
1440
|
return new ChunkToVectorTask({}, config).run(input);
|
|
1922
1441
|
};
|
|
1923
|
-
|
|
1442
|
+
Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
|
|
1924
1443
|
|
|
1925
1444
|
// src/task/ChunkVectorHybridSearchTask.ts
|
|
1926
1445
|
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";
|
|
1446
|
+
import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
1932
1447
|
import {
|
|
1933
1448
|
TypedArraySchema as TypedArraySchema4
|
|
1934
1449
|
} from "@workglow/util/schema";
|
|
@@ -2094,15 +1609,11 @@ class ChunkVectorHybridSearchTask extends Task4 {
|
|
|
2094
1609
|
var hybridSearch = async (input, config) => {
|
|
2095
1610
|
return new ChunkVectorHybridSearchTask({}, config).run(input);
|
|
2096
1611
|
};
|
|
2097
|
-
|
|
1612
|
+
Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
|
|
2098
1613
|
|
|
2099
1614
|
// src/task/ChunkVectorSearchTask.ts
|
|
2100
1615
|
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";
|
|
1616
|
+
import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
|
|
2106
1617
|
import {
|
|
2107
1618
|
TypedArraySchema as TypedArraySchema5
|
|
2108
1619
|
} from "@workglow/util/schema";
|
|
@@ -2217,15 +1728,11 @@ class ChunkVectorSearchTask extends Task5 {
|
|
|
2217
1728
|
var vectorStoreSearch = (input, config) => {
|
|
2218
1729
|
return new ChunkVectorSearchTask({}, config).run(input);
|
|
2219
1730
|
};
|
|
2220
|
-
|
|
1731
|
+
Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
|
|
2221
1732
|
|
|
2222
1733
|
// src/task/ChunkVectorUpsertTask.ts
|
|
2223
1734
|
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";
|
|
1735
|
+
import { CreateWorkflow as CreateWorkflow7, Task as Task6, Workflow as Workflow7 } from "@workglow/task-graph";
|
|
2229
1736
|
import {
|
|
2230
1737
|
TypedArraySchema as TypedArraySchema6
|
|
2231
1738
|
} from "@workglow/util/schema";
|
|
@@ -2339,28 +1846,28 @@ class ChunkVectorUpsertTask extends Task6 {
|
|
|
2339
1846
|
var chunkVectorUpsert = (input, config) => {
|
|
2340
1847
|
return new ChunkVectorUpsertTask({}, config).run(input);
|
|
2341
1848
|
};
|
|
2342
|
-
|
|
1849
|
+
Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
|
|
2343
1850
|
|
|
2344
1851
|
// src/task/ContextBuilderTask.ts
|
|
2345
1852
|
import { estimateTokens } from "@workglow/knowledge-base";
|
|
2346
1853
|
import {
|
|
2347
|
-
CreateWorkflow as
|
|
1854
|
+
CreateWorkflow as CreateWorkflow9,
|
|
2348
1855
|
Task as Task7,
|
|
2349
|
-
Workflow as
|
|
1856
|
+
Workflow as Workflow9
|
|
2350
1857
|
} from "@workglow/task-graph";
|
|
2351
1858
|
|
|
2352
1859
|
// src/task/CountTokensTask.ts
|
|
2353
|
-
import { CreateWorkflow as
|
|
2354
|
-
var
|
|
1860
|
+
import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
|
|
1861
|
+
var modelSchema3 = TypeModel("model");
|
|
2355
1862
|
var CountTokensInputSchema = {
|
|
2356
1863
|
type: "object",
|
|
2357
1864
|
properties: {
|
|
2358
|
-
text:
|
|
1865
|
+
text: {
|
|
2359
1866
|
type: "string",
|
|
2360
1867
|
title: "Text",
|
|
2361
1868
|
description: "The text to count tokens for"
|
|
2362
|
-
}
|
|
2363
|
-
model:
|
|
1869
|
+
},
|
|
1870
|
+
model: modelSchema3
|
|
2364
1871
|
},
|
|
2365
1872
|
required: ["text", "model"],
|
|
2366
1873
|
additionalProperties: false
|
|
@@ -2368,11 +1875,11 @@ var CountTokensInputSchema = {
|
|
|
2368
1875
|
var CountTokensOutputSchema = {
|
|
2369
1876
|
type: "object",
|
|
2370
1877
|
properties: {
|
|
2371
|
-
count:
|
|
1878
|
+
count: {
|
|
2372
1879
|
type: "number",
|
|
2373
1880
|
title: "Token Count",
|
|
2374
1881
|
description: "The number of tokens in the text"
|
|
2375
|
-
}
|
|
1882
|
+
}
|
|
2376
1883
|
},
|
|
2377
1884
|
required: ["count"],
|
|
2378
1885
|
additionalProperties: false
|
|
@@ -2394,7 +1901,7 @@ class CountTokensTask extends AiTask {
|
|
|
2394
1901
|
var countTokens = async (input, config) => {
|
|
2395
1902
|
return new CountTokensTask({}, config).run(input);
|
|
2396
1903
|
};
|
|
2397
|
-
|
|
1904
|
+
Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
|
|
2398
1905
|
|
|
2399
1906
|
// src/task/ContextBuilderTask.ts
|
|
2400
1907
|
var ContextFormat = {
|
|
@@ -2404,7 +1911,7 @@ var ContextFormat = {
|
|
|
2404
1911
|
MARKDOWN: "markdown",
|
|
2405
1912
|
JSON: "json"
|
|
2406
1913
|
};
|
|
2407
|
-
var
|
|
1914
|
+
var modelSchema4 = TypeModel("model", {
|
|
2408
1915
|
title: "Model",
|
|
2409
1916
|
description: "Model to use for token counting (optional, falls back to estimation)"
|
|
2410
1917
|
});
|
|
@@ -2468,7 +1975,7 @@ var inputSchema6 = {
|
|
|
2468
1975
|
|
|
2469
1976
|
`
|
|
2470
1977
|
},
|
|
2471
|
-
model:
|
|
1978
|
+
model: modelSchema4
|
|
2472
1979
|
},
|
|
2473
1980
|
required: ["chunks"],
|
|
2474
1981
|
additionalProperties: false
|
|
@@ -2694,30 +2201,26 @@ class ContextBuilderTask extends Task7 {
|
|
|
2694
2201
|
var contextBuilder = (input, config) => {
|
|
2695
2202
|
return new ContextBuilderTask({}, config).run(input);
|
|
2696
2203
|
};
|
|
2697
|
-
|
|
2204
|
+
Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
|
|
2698
2205
|
|
|
2699
2206
|
// src/task/DocumentEnricherTask.ts
|
|
2700
2207
|
import {
|
|
2701
2208
|
getChildren,
|
|
2702
2209
|
hasChildren
|
|
2703
2210
|
} from "@workglow/knowledge-base";
|
|
2704
|
-
import {
|
|
2705
|
-
CreateWorkflow as CreateWorkflow14,
|
|
2706
|
-
Task as Task8,
|
|
2707
|
-
Workflow as Workflow14
|
|
2708
|
-
} from "@workglow/task-graph";
|
|
2211
|
+
import { CreateWorkflow as CreateWorkflow12, Task as Task8, Workflow as Workflow12 } from "@workglow/task-graph";
|
|
2709
2212
|
|
|
2710
2213
|
// src/task/TextNamedEntityRecognitionTask.ts
|
|
2711
|
-
import { CreateWorkflow as
|
|
2712
|
-
var
|
|
2214
|
+
import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
|
|
2215
|
+
var modelSchema5 = TypeModel("model:TextNamedEntityRecognitionTask");
|
|
2713
2216
|
var TextNamedEntityRecognitionInputSchema = {
|
|
2714
2217
|
type: "object",
|
|
2715
2218
|
properties: {
|
|
2716
|
-
text:
|
|
2219
|
+
text: {
|
|
2717
2220
|
type: "string",
|
|
2718
2221
|
title: "Text",
|
|
2719
2222
|
description: "The text to extract named entities from"
|
|
2720
|
-
}
|
|
2223
|
+
},
|
|
2721
2224
|
blockList: {
|
|
2722
2225
|
type: "array",
|
|
2723
2226
|
items: {
|
|
@@ -2728,7 +2231,7 @@ var TextNamedEntityRecognitionInputSchema = {
|
|
|
2728
2231
|
"x-ui-group": "Configuration",
|
|
2729
2232
|
"x-ui-group-open": false
|
|
2730
2233
|
},
|
|
2731
|
-
model:
|
|
2234
|
+
model: modelSchema5
|
|
2732
2235
|
},
|
|
2733
2236
|
required: ["text", "model"],
|
|
2734
2237
|
additionalProperties: false
|
|
@@ -2736,7 +2239,7 @@ var TextNamedEntityRecognitionInputSchema = {
|
|
|
2736
2239
|
var TextNamedEntityRecognitionOutputSchema = {
|
|
2737
2240
|
type: "object",
|
|
2738
2241
|
properties: {
|
|
2739
|
-
entities:
|
|
2242
|
+
entities: {
|
|
2740
2243
|
type: "array",
|
|
2741
2244
|
items: {
|
|
2742
2245
|
type: "object",
|
|
@@ -2762,7 +2265,7 @@ var TextNamedEntityRecognitionOutputSchema = {
|
|
|
2762
2265
|
},
|
|
2763
2266
|
title: "Entities",
|
|
2764
2267
|
description: "The extracted named entities with their types, scores, and text"
|
|
2765
|
-
}
|
|
2268
|
+
}
|
|
2766
2269
|
},
|
|
2767
2270
|
required: ["entities"],
|
|
2768
2271
|
additionalProperties: false
|
|
@@ -2783,20 +2286,60 @@ class TextNamedEntityRecognitionTask extends AiTask {
|
|
|
2783
2286
|
var textNamedEntityRecognition = (input, config) => {
|
|
2784
2287
|
return new TextNamedEntityRecognitionTask({}, config).run(input);
|
|
2785
2288
|
};
|
|
2786
|
-
|
|
2289
|
+
Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
|
|
2787
2290
|
|
|
2788
2291
|
// src/task/TextSummaryTask.ts
|
|
2789
|
-
import { CreateWorkflow as
|
|
2790
|
-
|
|
2292
|
+
import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
|
|
2293
|
+
|
|
2294
|
+
// src/task/base/StreamingAiTask.ts
|
|
2295
|
+
import {
|
|
2296
|
+
getStreamingPorts,
|
|
2297
|
+
TaskConfigurationError as TaskConfigurationError3
|
|
2298
|
+
} from "@workglow/task-graph";
|
|
2299
|
+
class StreamingAiTask extends AiTask {
|
|
2300
|
+
static type = "StreamingAiTask";
|
|
2301
|
+
async* executeStream(input, context) {
|
|
2302
|
+
const model = input.model;
|
|
2303
|
+
if (!model || typeof model !== "object") {
|
|
2304
|
+
throw new TaskConfigurationError3("StreamingAiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
|
|
2305
|
+
}
|
|
2306
|
+
const jobInput = await this.getJobInput(input);
|
|
2307
|
+
const strategy = getAiProviderRegistry().getStrategy(model);
|
|
2308
|
+
const outSchema = this.outputSchema();
|
|
2309
|
+
const ports = getStreamingPorts(outSchema);
|
|
2310
|
+
let defaultPort = "text";
|
|
2311
|
+
if (ports.length > 0) {
|
|
2312
|
+
defaultPort = ports[0].port;
|
|
2313
|
+
} else {
|
|
2314
|
+
if (typeof outSchema === "object" && outSchema.properties) {
|
|
2315
|
+
const firstProp = Object.keys(outSchema.properties)[0];
|
|
2316
|
+
if (firstProp)
|
|
2317
|
+
defaultPort = firstProp;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
for await (const event of strategy.executeStream(jobInput, context, this.runConfig.runnerId)) {
|
|
2321
|
+
if (event.type === "text-delta") {
|
|
2322
|
+
yield { ...event, port: event.port ?? defaultPort };
|
|
2323
|
+
} else if (event.type === "object-delta") {
|
|
2324
|
+
yield { ...event, port: event.port ?? defaultPort };
|
|
2325
|
+
} else {
|
|
2326
|
+
yield event;
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
// src/task/TextSummaryTask.ts
|
|
2333
|
+
var modelSchema6 = TypeModel("model:TextSummaryTask");
|
|
2791
2334
|
var TextSummaryInputSchema = {
|
|
2792
2335
|
type: "object",
|
|
2793
2336
|
properties: {
|
|
2794
|
-
text:
|
|
2337
|
+
text: {
|
|
2795
2338
|
type: "string",
|
|
2796
2339
|
title: "Text",
|
|
2797
2340
|
description: "The text to summarize"
|
|
2798
|
-
}
|
|
2799
|
-
model:
|
|
2341
|
+
},
|
|
2342
|
+
model: modelSchema6
|
|
2800
2343
|
},
|
|
2801
2344
|
required: ["text", "model"],
|
|
2802
2345
|
additionalProperties: false
|
|
@@ -2804,12 +2347,12 @@ var TextSummaryInputSchema = {
|
|
|
2804
2347
|
var TextSummaryOutputSchema = {
|
|
2805
2348
|
type: "object",
|
|
2806
2349
|
properties: {
|
|
2807
|
-
text:
|
|
2350
|
+
text: {
|
|
2808
2351
|
type: "string",
|
|
2809
2352
|
title: "Text",
|
|
2810
2353
|
description: "The summarized text",
|
|
2811
2354
|
"x-stream": "append"
|
|
2812
|
-
}
|
|
2355
|
+
}
|
|
2813
2356
|
},
|
|
2814
2357
|
required: ["text"],
|
|
2815
2358
|
additionalProperties: false
|
|
@@ -2830,7 +2373,7 @@ class TextSummaryTask extends StreamingAiTask {
|
|
|
2830
2373
|
var textSummary = async (input, config) => {
|
|
2831
2374
|
return new TextSummaryTask({}, config).run(input);
|
|
2832
2375
|
};
|
|
2833
|
-
|
|
2376
|
+
Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
|
|
2834
2377
|
|
|
2835
2378
|
// src/task/DocumentEnricherTask.ts
|
|
2836
2379
|
var inputSchema7 = {
|
|
@@ -3061,15 +2604,15 @@ class DocumentEnricherTask extends Task8 {
|
|
|
3061
2604
|
var documentEnricher = (input, config) => {
|
|
3062
2605
|
return new DocumentEnricherTask({}, config).run(input);
|
|
3063
2606
|
};
|
|
3064
|
-
|
|
2607
|
+
Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
|
|
3065
2608
|
|
|
3066
2609
|
// src/task/DownloadModelTask.ts
|
|
3067
|
-
import { CreateWorkflow as
|
|
3068
|
-
var
|
|
2610
|
+
import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
|
|
2611
|
+
var modelSchema7 = TypeModel("model");
|
|
3069
2612
|
var DownloadModelInputSchema = {
|
|
3070
2613
|
type: "object",
|
|
3071
2614
|
properties: {
|
|
3072
|
-
model:
|
|
2615
|
+
model: modelSchema7
|
|
3073
2616
|
},
|
|
3074
2617
|
required: ["model"],
|
|
3075
2618
|
additionalProperties: false
|
|
@@ -3077,7 +2620,7 @@ var DownloadModelInputSchema = {
|
|
|
3077
2620
|
var DownloadModelOutputSchema = {
|
|
3078
2621
|
type: "object",
|
|
3079
2622
|
properties: {
|
|
3080
|
-
model:
|
|
2623
|
+
model: modelSchema7
|
|
3081
2624
|
},
|
|
3082
2625
|
required: ["model"],
|
|
3083
2626
|
additionalProperties: false
|
|
@@ -3131,11 +2674,11 @@ class DownloadModelTask extends AiTask {
|
|
|
3131
2674
|
var downloadModel = (input, config) => {
|
|
3132
2675
|
return new DownloadModelTask({}, config).run(input);
|
|
3133
2676
|
};
|
|
3134
|
-
|
|
2677
|
+
Workflow13.prototype.downloadModel = CreateWorkflow13(DownloadModelTask);
|
|
3135
2678
|
|
|
3136
2679
|
// src/task/FaceDetectorTask.ts
|
|
3137
|
-
import { CreateWorkflow as
|
|
3138
|
-
var
|
|
2680
|
+
import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
|
|
2681
|
+
var modelSchema8 = TypeModel("model:FaceDetectorTask");
|
|
3139
2682
|
var TypeBoundingBox2 = {
|
|
3140
2683
|
type: "object",
|
|
3141
2684
|
properties: {
|
|
@@ -3208,7 +2751,7 @@ var FaceDetectorInputSchema = {
|
|
|
3208
2751
|
type: "object",
|
|
3209
2752
|
properties: {
|
|
3210
2753
|
image: TypeImageInput,
|
|
3211
|
-
model:
|
|
2754
|
+
model: modelSchema8,
|
|
3212
2755
|
minDetectionConfidence: {
|
|
3213
2756
|
type: "number",
|
|
3214
2757
|
minimum: 0,
|
|
@@ -3262,11 +2805,11 @@ class FaceDetectorTask extends AiVisionTask {
|
|
|
3262
2805
|
var faceDetector = (input, config) => {
|
|
3263
2806
|
return new FaceDetectorTask({}, config).run(input);
|
|
3264
2807
|
};
|
|
3265
|
-
|
|
2808
|
+
Workflow14.prototype.faceDetector = CreateWorkflow14(FaceDetectorTask);
|
|
3266
2809
|
|
|
3267
2810
|
// src/task/FaceLandmarkerTask.ts
|
|
3268
|
-
import { CreateWorkflow as
|
|
3269
|
-
var
|
|
2811
|
+
import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
|
|
2812
|
+
var modelSchema9 = TypeModel("model:FaceLandmarkerTask");
|
|
3270
2813
|
var TypeLandmark = {
|
|
3271
2814
|
type: "object",
|
|
3272
2815
|
properties: {
|
|
@@ -3338,7 +2881,7 @@ var FaceLandmarkerInputSchema = {
|
|
|
3338
2881
|
type: "object",
|
|
3339
2882
|
properties: {
|
|
3340
2883
|
image: TypeImageInput,
|
|
3341
|
-
model:
|
|
2884
|
+
model: modelSchema9,
|
|
3342
2885
|
numFaces: {
|
|
3343
2886
|
type: "number",
|
|
3344
2887
|
minimum: 1,
|
|
@@ -3424,11 +2967,11 @@ class FaceLandmarkerTask extends AiVisionTask {
|
|
|
3424
2967
|
var faceLandmarker = (input, config) => {
|
|
3425
2968
|
return new FaceLandmarkerTask({}, config).run(input);
|
|
3426
2969
|
};
|
|
3427
|
-
|
|
2970
|
+
Workflow15.prototype.faceLandmarker = CreateWorkflow15(FaceLandmarkerTask);
|
|
3428
2971
|
|
|
3429
2972
|
// src/task/GestureRecognizerTask.ts
|
|
3430
|
-
import { CreateWorkflow as
|
|
3431
|
-
var
|
|
2973
|
+
import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
|
|
2974
|
+
var modelSchema10 = TypeModel("model:GestureRecognizerTask");
|
|
3432
2975
|
var TypeLandmark2 = {
|
|
3433
2976
|
type: "object",
|
|
3434
2977
|
properties: {
|
|
@@ -3520,7 +3063,7 @@ var GestureRecognizerInputSchema = {
|
|
|
3520
3063
|
type: "object",
|
|
3521
3064
|
properties: {
|
|
3522
3065
|
image: TypeImageInput,
|
|
3523
|
-
model:
|
|
3066
|
+
model: modelSchema10,
|
|
3524
3067
|
numHands: {
|
|
3525
3068
|
type: "number",
|
|
3526
3069
|
minimum: 1,
|
|
@@ -3592,11 +3135,11 @@ class GestureRecognizerTask extends AiVisionTask {
|
|
|
3592
3135
|
var gestureRecognizer = (input, config) => {
|
|
3593
3136
|
return new GestureRecognizerTask({}, config).run(input);
|
|
3594
3137
|
};
|
|
3595
|
-
|
|
3138
|
+
Workflow16.prototype.gestureRecognizer = CreateWorkflow16(GestureRecognizerTask);
|
|
3596
3139
|
|
|
3597
3140
|
// src/task/HandLandmarkerTask.ts
|
|
3598
|
-
import { CreateWorkflow as
|
|
3599
|
-
var
|
|
3141
|
+
import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
|
|
3142
|
+
var modelSchema11 = TypeModel("model:HandLandmarkerTask");
|
|
3600
3143
|
var TypeLandmark3 = {
|
|
3601
3144
|
type: "object",
|
|
3602
3145
|
properties: {
|
|
@@ -3665,7 +3208,7 @@ var HandLandmarkerInputSchema = {
|
|
|
3665
3208
|
type: "object",
|
|
3666
3209
|
properties: {
|
|
3667
3210
|
image: TypeImageInput,
|
|
3668
|
-
model:
|
|
3211
|
+
model: modelSchema11,
|
|
3669
3212
|
numHands: {
|
|
3670
3213
|
type: "number",
|
|
3671
3214
|
minimum: 1,
|
|
@@ -3737,7 +3280,7 @@ class HandLandmarkerTask extends AiVisionTask {
|
|
|
3737
3280
|
var handLandmarker = (input, config) => {
|
|
3738
3281
|
return new HandLandmarkerTask({}, config).run(input);
|
|
3739
3282
|
};
|
|
3740
|
-
|
|
3283
|
+
Workflow17.prototype.handLandmarker = CreateWorkflow17(HandLandmarkerTask);
|
|
3741
3284
|
|
|
3742
3285
|
// src/task/HierarchicalChunkerTask.ts
|
|
3743
3286
|
import {
|
|
@@ -3746,13 +3289,9 @@ import {
|
|
|
3746
3289
|
getChildren as getChildren2,
|
|
3747
3290
|
hasChildren as hasChildren2
|
|
3748
3291
|
} from "@workglow/knowledge-base";
|
|
3749
|
-
import {
|
|
3750
|
-
CreateWorkflow as CreateWorkflow20,
|
|
3751
|
-
Task as Task9,
|
|
3752
|
-
Workflow as Workflow20
|
|
3753
|
-
} from "@workglow/task-graph";
|
|
3292
|
+
import { CreateWorkflow as CreateWorkflow18, Task as Task9, Workflow as Workflow18 } from "@workglow/task-graph";
|
|
3754
3293
|
import { uuid4 } from "@workglow/util";
|
|
3755
|
-
var
|
|
3294
|
+
var modelSchema12 = TypeModel("model", {
|
|
3756
3295
|
title: "Model",
|
|
3757
3296
|
description: "Model to use for token counting"
|
|
3758
3297
|
});
|
|
@@ -3796,7 +3335,7 @@ var inputSchema8 = {
|
|
|
3796
3335
|
description: "Strategy for chunking",
|
|
3797
3336
|
default: "hierarchical"
|
|
3798
3337
|
},
|
|
3799
|
-
model:
|
|
3338
|
+
model: modelSchema12
|
|
3800
3339
|
},
|
|
3801
3340
|
required: ["doc_id", "documentTree"],
|
|
3802
3341
|
additionalProperties: false
|
|
@@ -3975,18 +3514,14 @@ class HierarchicalChunkerTask extends Task9 {
|
|
|
3975
3514
|
var hierarchicalChunker = (input, config) => {
|
|
3976
3515
|
return new HierarchicalChunkerTask({}, config).run(input);
|
|
3977
3516
|
};
|
|
3978
|
-
|
|
3517
|
+
Workflow18.prototype.hierarchicalChunker = CreateWorkflow18(HierarchicalChunkerTask);
|
|
3979
3518
|
|
|
3980
3519
|
// src/task/HierarchyJoinTask.ts
|
|
3981
3520
|
import {
|
|
3982
3521
|
ChunkRecordArraySchema,
|
|
3983
3522
|
TypeKnowledgeBase as TypeKnowledgeBase5
|
|
3984
3523
|
} from "@workglow/knowledge-base";
|
|
3985
|
-
import {
|
|
3986
|
-
CreateWorkflow as CreateWorkflow21,
|
|
3987
|
-
Task as Task10,
|
|
3988
|
-
Workflow as Workflow21
|
|
3989
|
-
} from "@workglow/task-graph";
|
|
3524
|
+
import { CreateWorkflow as CreateWorkflow19, Task as Task10, Workflow as Workflow19 } from "@workglow/task-graph";
|
|
3990
3525
|
var inputSchema9 = {
|
|
3991
3526
|
type: "object",
|
|
3992
3527
|
properties: {
|
|
@@ -4155,16 +3690,16 @@ class HierarchyJoinTask extends Task10 {
|
|
|
4155
3690
|
var hierarchyJoin = (input, config) => {
|
|
4156
3691
|
return new HierarchyJoinTask({}, config).run(input);
|
|
4157
3692
|
};
|
|
4158
|
-
|
|
3693
|
+
Workflow19.prototype.hierarchyJoin = CreateWorkflow19(HierarchyJoinTask);
|
|
4159
3694
|
|
|
4160
3695
|
// src/task/ImageClassificationTask.ts
|
|
4161
|
-
import { CreateWorkflow as
|
|
4162
|
-
var
|
|
3696
|
+
import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
|
|
3697
|
+
var modelSchema13 = TypeModel("model:ImageClassificationTask");
|
|
4163
3698
|
var ImageClassificationInputSchema = {
|
|
4164
3699
|
type: "object",
|
|
4165
3700
|
properties: {
|
|
4166
3701
|
image: TypeImageInput,
|
|
4167
|
-
model:
|
|
3702
|
+
model: modelSchema13,
|
|
4168
3703
|
categories: {
|
|
4169
3704
|
type: "array",
|
|
4170
3705
|
items: {
|
|
@@ -4218,23 +3753,19 @@ class ImageClassificationTask extends AiVisionTask {
|
|
|
4218
3753
|
var imageClassification = (input, config) => {
|
|
4219
3754
|
return new ImageClassificationTask({}, config).run(input);
|
|
4220
3755
|
};
|
|
4221
|
-
|
|
3756
|
+
Workflow20.prototype.imageClassification = CreateWorkflow20(ImageClassificationTask);
|
|
4222
3757
|
|
|
4223
3758
|
// src/task/ImageEmbeddingTask.ts
|
|
4224
|
-
import { CreateWorkflow as
|
|
3759
|
+
import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
|
|
4225
3760
|
import {
|
|
4226
3761
|
TypedArraySchema as TypedArraySchema7
|
|
4227
3762
|
} from "@workglow/util/schema";
|
|
4228
|
-
var
|
|
4229
|
-
var embeddingSchema = TypedArraySchema7({
|
|
4230
|
-
title: "Embedding",
|
|
4231
|
-
description: "The image embedding vector"
|
|
4232
|
-
});
|
|
3763
|
+
var modelSchema14 = TypeModel("model:ImageEmbeddingTask");
|
|
4233
3764
|
var ImageEmbeddingInputSchema = {
|
|
4234
3765
|
type: "object",
|
|
4235
3766
|
properties: {
|
|
4236
|
-
image: TypeImageInput,
|
|
4237
|
-
model:
|
|
3767
|
+
image: TypeSingleOrArray(TypeImageInput),
|
|
3768
|
+
model: modelSchema14
|
|
4238
3769
|
},
|
|
4239
3770
|
required: ["image", "model"],
|
|
4240
3771
|
additionalProperties: false
|
|
@@ -4242,7 +3773,10 @@ var ImageEmbeddingInputSchema = {
|
|
|
4242
3773
|
var ImageEmbeddingOutputSchema = {
|
|
4243
3774
|
type: "object",
|
|
4244
3775
|
properties: {
|
|
4245
|
-
vector:
|
|
3776
|
+
vector: TypeSingleOrArray(TypedArraySchema7({
|
|
3777
|
+
title: "Embedding",
|
|
3778
|
+
description: "The image embedding vector"
|
|
3779
|
+
}))
|
|
4246
3780
|
},
|
|
4247
3781
|
required: ["vector"],
|
|
4248
3782
|
additionalProperties: false
|
|
@@ -4263,16 +3797,16 @@ class ImageEmbeddingTask extends AiVisionTask {
|
|
|
4263
3797
|
var imageEmbedding = (input, config) => {
|
|
4264
3798
|
return new ImageEmbeddingTask({}, config).run(input);
|
|
4265
3799
|
};
|
|
4266
|
-
|
|
3800
|
+
Workflow21.prototype.imageEmbedding = CreateWorkflow21(ImageEmbeddingTask);
|
|
4267
3801
|
|
|
4268
3802
|
// src/task/ImageSegmentationTask.ts
|
|
4269
|
-
import { CreateWorkflow as
|
|
4270
|
-
var
|
|
3803
|
+
import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
|
|
3804
|
+
var modelSchema15 = TypeModel("model:ImageSegmentationTask");
|
|
4271
3805
|
var ImageSegmentationInputSchema = {
|
|
4272
3806
|
type: "object",
|
|
4273
3807
|
properties: {
|
|
4274
3808
|
image: TypeImageInput,
|
|
4275
|
-
model:
|
|
3809
|
+
model: modelSchema15,
|
|
4276
3810
|
threshold: {
|
|
4277
3811
|
type: "number",
|
|
4278
3812
|
title: "Threshold",
|
|
@@ -4351,11 +3885,11 @@ class ImageSegmentationTask extends AiVisionTask {
|
|
|
4351
3885
|
var imageSegmentation = (input, config) => {
|
|
4352
3886
|
return new ImageSegmentationTask({}, config).run(input);
|
|
4353
3887
|
};
|
|
4354
|
-
|
|
3888
|
+
Workflow22.prototype.imageSegmentation = CreateWorkflow22(ImageSegmentationTask);
|
|
4355
3889
|
|
|
4356
3890
|
// src/task/ImageToTextTask.ts
|
|
4357
|
-
import { CreateWorkflow as
|
|
4358
|
-
var
|
|
3891
|
+
import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
|
|
3892
|
+
var modelSchema16 = TypeModel("model:ImageToTextTask");
|
|
4359
3893
|
var generatedTextSchema = {
|
|
4360
3894
|
type: "string",
|
|
4361
3895
|
title: "Text",
|
|
@@ -4365,7 +3899,7 @@ var ImageToTextInputSchema = {
|
|
|
4365
3899
|
type: "object",
|
|
4366
3900
|
properties: {
|
|
4367
3901
|
image: TypeImageInput,
|
|
4368
|
-
model:
|
|
3902
|
+
model: modelSchema16,
|
|
4369
3903
|
maxTokens: {
|
|
4370
3904
|
type: "number",
|
|
4371
3905
|
title: "Max Tokens",
|
|
@@ -4406,18 +3940,15 @@ class ImageToTextTask extends AiVisionTask {
|
|
|
4406
3940
|
var imageToText = (input, config) => {
|
|
4407
3941
|
return new ImageToTextTask({}, config).run(input);
|
|
4408
3942
|
};
|
|
4409
|
-
|
|
3943
|
+
Workflow23.prototype.imageToText = CreateWorkflow23(ImageToTextTask);
|
|
4410
3944
|
|
|
4411
3945
|
// src/task/ModelInfoTask.ts
|
|
4412
|
-
import {
|
|
4413
|
-
|
|
4414
|
-
Workflow as Workflow26
|
|
4415
|
-
} from "@workglow/task-graph";
|
|
4416
|
-
var modelSchema19 = TypeModel("model");
|
|
3946
|
+
import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
|
|
3947
|
+
var modelSchema17 = TypeModel("model");
|
|
4417
3948
|
var ModelInfoInputSchema = {
|
|
4418
3949
|
type: "object",
|
|
4419
3950
|
properties: {
|
|
4420
|
-
model:
|
|
3951
|
+
model: modelSchema17,
|
|
4421
3952
|
detail: {
|
|
4422
3953
|
type: "string",
|
|
4423
3954
|
enum: ["cached_status", "files", "files_with_metadata"],
|
|
@@ -4430,7 +3961,7 @@ var ModelInfoInputSchema = {
|
|
|
4430
3961
|
var ModelInfoOutputSchema = {
|
|
4431
3962
|
type: "object",
|
|
4432
3963
|
properties: {
|
|
4433
|
-
model:
|
|
3964
|
+
model: modelSchema17,
|
|
4434
3965
|
is_local: { type: "boolean" },
|
|
4435
3966
|
is_remote: { type: "boolean" },
|
|
4436
3967
|
supports_browser: { type: "boolean" },
|
|
@@ -4480,10 +4011,10 @@ class ModelInfoTask extends AiTask {
|
|
|
4480
4011
|
var modelInfo = (input, config) => {
|
|
4481
4012
|
return new ModelInfoTask({}, config).run(input);
|
|
4482
4013
|
};
|
|
4483
|
-
|
|
4014
|
+
Workflow24.prototype.modelInfo = CreateWorkflow24(ModelInfoTask);
|
|
4484
4015
|
|
|
4485
4016
|
// src/task/ModelSearchTask.ts
|
|
4486
|
-
import { CreateWorkflow as
|
|
4017
|
+
import { CreateWorkflow as CreateWorkflow25, Task as Task11, Workflow as Workflow25 } from "@workglow/task-graph";
|
|
4487
4018
|
var ModelSearchInputSchema = {
|
|
4488
4019
|
type: "object",
|
|
4489
4020
|
properties: {
|
|
@@ -4495,10 +4026,10 @@ var ModelSearchInputSchema = {
|
|
|
4495
4026
|
query: {
|
|
4496
4027
|
type: "string",
|
|
4497
4028
|
title: "Query",
|
|
4498
|
-
description: "
|
|
4029
|
+
description: "Optional search string. When omitted or empty, returns all models (provider-specific listing)."
|
|
4499
4030
|
}
|
|
4500
4031
|
},
|
|
4501
|
-
required: ["provider"
|
|
4032
|
+
required: ["provider"],
|
|
4502
4033
|
additionalProperties: false
|
|
4503
4034
|
};
|
|
4504
4035
|
function buildModelSearchInputSchemaDynamic() {
|
|
@@ -4536,7 +4067,7 @@ var ModelSearchOutputSchema = {
|
|
|
4536
4067
|
id: { type: "string" },
|
|
4537
4068
|
label: { type: "string" },
|
|
4538
4069
|
description: { type: "string" },
|
|
4539
|
-
record:
|
|
4070
|
+
record: TypeModel("model"),
|
|
4540
4071
|
raw: {}
|
|
4541
4072
|
},
|
|
4542
4073
|
required: ["id", "label", "description", "record"],
|
|
@@ -4574,11 +4105,11 @@ class ModelSearchTask extends Task11 {
|
|
|
4574
4105
|
var modelSearch = (input, config) => {
|
|
4575
4106
|
return new ModelSearchTask({}, config).run(input);
|
|
4576
4107
|
};
|
|
4577
|
-
|
|
4108
|
+
Workflow25.prototype.modelSearch = CreateWorkflow25(ModelSearchTask);
|
|
4578
4109
|
|
|
4579
4110
|
// src/task/ObjectDetectionTask.ts
|
|
4580
|
-
import { CreateWorkflow as
|
|
4581
|
-
var
|
|
4111
|
+
import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
|
|
4112
|
+
var modelSchema18 = TypeModel("model:ObjectDetectionTask");
|
|
4582
4113
|
var detectionSchema = {
|
|
4583
4114
|
type: "object",
|
|
4584
4115
|
properties: {
|
|
@@ -4603,7 +4134,7 @@ var ObjectDetectionInputSchema = {
|
|
|
4603
4134
|
type: "object",
|
|
4604
4135
|
properties: {
|
|
4605
4136
|
image: TypeImageInput,
|
|
4606
|
-
model:
|
|
4137
|
+
model: modelSchema18,
|
|
4607
4138
|
labels: {
|
|
4608
4139
|
type: "array",
|
|
4609
4140
|
items: {
|
|
@@ -4657,11 +4188,11 @@ class ObjectDetectionTask extends AiVisionTask {
|
|
|
4657
4188
|
var objectDetection = (input, config) => {
|
|
4658
4189
|
return new ObjectDetectionTask({}, config).run(input);
|
|
4659
4190
|
};
|
|
4660
|
-
|
|
4191
|
+
Workflow26.prototype.objectDetection = CreateWorkflow26(ObjectDetectionTask);
|
|
4661
4192
|
|
|
4662
4193
|
// src/task/PoseLandmarkerTask.ts
|
|
4663
|
-
import { CreateWorkflow as
|
|
4664
|
-
var
|
|
4194
|
+
import { CreateWorkflow as CreateWorkflow27, Workflow as Workflow27 } from "@workglow/task-graph";
|
|
4195
|
+
var modelSchema19 = TypeModel("model:PoseLandmarkerTask");
|
|
4665
4196
|
var TypePoseLandmark = {
|
|
4666
4197
|
type: "object",
|
|
4667
4198
|
properties: {
|
|
@@ -4740,7 +4271,7 @@ var PoseLandmarkerInputSchema = {
|
|
|
4740
4271
|
type: "object",
|
|
4741
4272
|
properties: {
|
|
4742
4273
|
image: TypeImageInput,
|
|
4743
|
-
model:
|
|
4274
|
+
model: modelSchema19,
|
|
4744
4275
|
numPoses: {
|
|
4745
4276
|
type: "number",
|
|
4746
4277
|
minimum: 1,
|
|
@@ -4819,14 +4350,10 @@ class PoseLandmarkerTask extends AiVisionTask {
|
|
|
4819
4350
|
var poseLandmarker = (input, config) => {
|
|
4820
4351
|
return new PoseLandmarkerTask({}, config).run(input);
|
|
4821
4352
|
};
|
|
4822
|
-
|
|
4353
|
+
Workflow27.prototype.poseLandmarker = CreateWorkflow27(PoseLandmarkerTask);
|
|
4823
4354
|
|
|
4824
4355
|
// src/task/QueryExpanderTask.ts
|
|
4825
|
-
import {
|
|
4826
|
-
CreateWorkflow as CreateWorkflow30,
|
|
4827
|
-
Task as Task12,
|
|
4828
|
-
Workflow as Workflow30
|
|
4829
|
-
} from "@workglow/task-graph";
|
|
4356
|
+
import { CreateWorkflow as CreateWorkflow28, Task as Task12, Workflow as Workflow28 } from "@workglow/task-graph";
|
|
4830
4357
|
var QueryExpansionMethod = {
|
|
4831
4358
|
MULTI_QUERY: "multi-query",
|
|
4832
4359
|
HYDE: "hyde",
|
|
@@ -5036,26 +4563,22 @@ class QueryExpanderTask extends Task12 {
|
|
|
5036
4563
|
var queryExpander = (input, config) => {
|
|
5037
4564
|
return new QueryExpanderTask({}, config).run(input);
|
|
5038
4565
|
};
|
|
5039
|
-
|
|
4566
|
+
Workflow28.prototype.queryExpander = CreateWorkflow28(QueryExpanderTask);
|
|
5040
4567
|
|
|
5041
4568
|
// src/task/RerankerTask.ts
|
|
5042
|
-
import {
|
|
5043
|
-
CreateWorkflow as CreateWorkflow32,
|
|
5044
|
-
Task as Task13,
|
|
5045
|
-
Workflow as Workflow32
|
|
5046
|
-
} from "@workglow/task-graph";
|
|
4569
|
+
import { CreateWorkflow as CreateWorkflow30, Task as Task13, Workflow as Workflow30 } from "@workglow/task-graph";
|
|
5047
4570
|
|
|
5048
4571
|
// src/task/TextClassificationTask.ts
|
|
5049
|
-
import { CreateWorkflow as
|
|
5050
|
-
var
|
|
4572
|
+
import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
|
|
4573
|
+
var modelSchema20 = TypeModel("model:TextClassificationTask");
|
|
5051
4574
|
var TextClassificationInputSchema = {
|
|
5052
4575
|
type: "object",
|
|
5053
4576
|
properties: {
|
|
5054
|
-
text:
|
|
4577
|
+
text: {
|
|
5055
4578
|
type: "string",
|
|
5056
4579
|
title: "Text",
|
|
5057
4580
|
description: "The text to classify"
|
|
5058
|
-
}
|
|
4581
|
+
},
|
|
5059
4582
|
candidateLabels: {
|
|
5060
4583
|
type: "array",
|
|
5061
4584
|
items: {
|
|
@@ -5074,7 +4597,7 @@ var TextClassificationInputSchema = {
|
|
|
5074
4597
|
description: "The maximum number of categories to return",
|
|
5075
4598
|
"x-ui-group": "Configuration"
|
|
5076
4599
|
},
|
|
5077
|
-
model:
|
|
4600
|
+
model: modelSchema20
|
|
5078
4601
|
},
|
|
5079
4602
|
required: ["text", "model"],
|
|
5080
4603
|
additionalProperties: false
|
|
@@ -5082,7 +4605,7 @@ var TextClassificationInputSchema = {
|
|
|
5082
4605
|
var TextClassificationOutputSchema = {
|
|
5083
4606
|
type: "object",
|
|
5084
4607
|
properties: {
|
|
5085
|
-
categories:
|
|
4608
|
+
categories: {
|
|
5086
4609
|
type: "array",
|
|
5087
4610
|
items: {
|
|
5088
4611
|
type: "object",
|
|
@@ -5103,7 +4626,7 @@ var TextClassificationOutputSchema = {
|
|
|
5103
4626
|
},
|
|
5104
4627
|
title: "Categories",
|
|
5105
4628
|
description: "The classification categories with their scores"
|
|
5106
|
-
}
|
|
4629
|
+
}
|
|
5107
4630
|
},
|
|
5108
4631
|
required: ["categories"],
|
|
5109
4632
|
additionalProperties: false
|
|
@@ -5124,7 +4647,7 @@ class TextClassificationTask extends AiTask {
|
|
|
5124
4647
|
var textClassification = (input, config) => {
|
|
5125
4648
|
return new TextClassificationTask({}, config).run(input);
|
|
5126
4649
|
};
|
|
5127
|
-
|
|
4650
|
+
Workflow29.prototype.textClassification = CreateWorkflow29(TextClassificationTask);
|
|
5128
4651
|
|
|
5129
4652
|
// src/task/RerankerTask.ts
|
|
5130
4653
|
var inputSchema11 = {
|
|
@@ -5348,15 +4871,11 @@ class RerankerTask extends Task13 {
|
|
|
5348
4871
|
var reranker = (input, config) => {
|
|
5349
4872
|
return new RerankerTask({}, config).run(input);
|
|
5350
4873
|
};
|
|
5351
|
-
|
|
4874
|
+
Workflow30.prototype.reranker = CreateWorkflow30(RerankerTask);
|
|
5352
4875
|
|
|
5353
4876
|
// src/task/StructuralParserTask.ts
|
|
5354
4877
|
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";
|
|
4878
|
+
import { CreateWorkflow as CreateWorkflow31, Task as Task14, Workflow as Workflow31 } from "@workglow/task-graph";
|
|
5360
4879
|
import { uuid4 as uuid42 } from "@workglow/util";
|
|
5361
4880
|
var inputSchema12 = {
|
|
5362
4881
|
type: "object",
|
|
@@ -5457,15 +4976,15 @@ class StructuralParserTask extends Task14 {
|
|
|
5457
4976
|
var structuralParser = (input, config) => {
|
|
5458
4977
|
return new StructuralParserTask({}, config).run(input);
|
|
5459
4978
|
};
|
|
5460
|
-
|
|
4979
|
+
Workflow31.prototype.structuralParser = CreateWorkflow31(StructuralParserTask);
|
|
5461
4980
|
|
|
5462
4981
|
// src/task/StructuredGenerationTask.ts
|
|
5463
|
-
import { CreateWorkflow as
|
|
5464
|
-
var
|
|
4982
|
+
import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
|
|
4983
|
+
var modelSchema21 = TypeModel("model:StructuredGenerationTask");
|
|
5465
4984
|
var StructuredGenerationInputSchema = {
|
|
5466
4985
|
type: "object",
|
|
5467
4986
|
properties: {
|
|
5468
|
-
model:
|
|
4987
|
+
model: modelSchema21,
|
|
5469
4988
|
prompt: {
|
|
5470
4989
|
type: "string",
|
|
5471
4990
|
title: "Prompt",
|
|
@@ -5528,14 +5047,10 @@ class StructuredGenerationTask extends StreamingAiTask {
|
|
|
5528
5047
|
var structuredGeneration = (input, config) => {
|
|
5529
5048
|
return new StructuredGenerationTask({}, config).run(input);
|
|
5530
5049
|
};
|
|
5531
|
-
|
|
5050
|
+
Workflow32.prototype.structuredGeneration = CreateWorkflow32(StructuredGenerationTask);
|
|
5532
5051
|
|
|
5533
5052
|
// src/task/TextChunkerTask.ts
|
|
5534
|
-
import {
|
|
5535
|
-
CreateWorkflow as CreateWorkflow35,
|
|
5536
|
-
Task as Task15,
|
|
5537
|
-
Workflow as Workflow35
|
|
5538
|
-
} from "@workglow/task-graph";
|
|
5053
|
+
import { CreateWorkflow as CreateWorkflow33, Task as Task15, Workflow as Workflow33 } from "@workglow/task-graph";
|
|
5539
5054
|
var ChunkingStrategy = {
|
|
5540
5055
|
FIXED: "fixed",
|
|
5541
5056
|
SENTENCE: "sentence",
|
|
@@ -5784,20 +5299,20 @@ class TextChunkerTask extends Task15 {
|
|
|
5784
5299
|
var textChunker = (input, config) => {
|
|
5785
5300
|
return new TextChunkerTask({}, config).run(input);
|
|
5786
5301
|
};
|
|
5787
|
-
|
|
5302
|
+
Workflow33.prototype.textChunker = CreateWorkflow33(TextChunkerTask);
|
|
5788
5303
|
|
|
5789
5304
|
// src/task/TextFillMaskTask.ts
|
|
5790
|
-
import { CreateWorkflow as
|
|
5791
|
-
var
|
|
5305
|
+
import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
|
|
5306
|
+
var modelSchema22 = TypeModel("model:TextFillMaskTask");
|
|
5792
5307
|
var TextFillMaskInputSchema = {
|
|
5793
5308
|
type: "object",
|
|
5794
5309
|
properties: {
|
|
5795
|
-
text:
|
|
5310
|
+
text: {
|
|
5796
5311
|
type: "string",
|
|
5797
5312
|
title: "Text",
|
|
5798
5313
|
description: "The text with a mask token to fill"
|
|
5799
|
-
}
|
|
5800
|
-
model:
|
|
5314
|
+
},
|
|
5315
|
+
model: modelSchema22
|
|
5801
5316
|
},
|
|
5802
5317
|
required: ["text", "model"],
|
|
5803
5318
|
additionalProperties: false
|
|
@@ -5805,7 +5320,7 @@ var TextFillMaskInputSchema = {
|
|
|
5805
5320
|
var TextFillMaskOutputSchema = {
|
|
5806
5321
|
type: "object",
|
|
5807
5322
|
properties: {
|
|
5808
|
-
predictions:
|
|
5323
|
+
predictions: {
|
|
5809
5324
|
type: "array",
|
|
5810
5325
|
items: {
|
|
5811
5326
|
type: "object",
|
|
@@ -5831,7 +5346,7 @@ var TextFillMaskOutputSchema = {
|
|
|
5831
5346
|
},
|
|
5832
5347
|
title: "Predictions",
|
|
5833
5348
|
description: "The predicted tokens to fill the mask with their scores and complete sequences"
|
|
5834
|
-
}
|
|
5349
|
+
}
|
|
5835
5350
|
},
|
|
5836
5351
|
required: ["predictions"],
|
|
5837
5352
|
additionalProperties: false
|
|
@@ -5852,26 +5367,26 @@ class TextFillMaskTask extends AiTask {
|
|
|
5852
5367
|
var textFillMask = (input, config) => {
|
|
5853
5368
|
return new TextFillMaskTask({}, config).run(input);
|
|
5854
5369
|
};
|
|
5855
|
-
|
|
5370
|
+
Workflow34.prototype.textFillMask = CreateWorkflow34(TextFillMaskTask);
|
|
5856
5371
|
|
|
5857
5372
|
// src/task/TextGenerationTask.ts
|
|
5858
|
-
import { CreateWorkflow as
|
|
5859
|
-
var generatedTextSchema2 =
|
|
5373
|
+
import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
|
|
5374
|
+
var generatedTextSchema2 = {
|
|
5860
5375
|
type: "string",
|
|
5861
5376
|
title: "Text",
|
|
5862
5377
|
description: "The generated text",
|
|
5863
5378
|
"x-stream": "append"
|
|
5864
|
-
}
|
|
5865
|
-
var
|
|
5379
|
+
};
|
|
5380
|
+
var modelSchema23 = TypeModel("model:TextGenerationTask");
|
|
5866
5381
|
var TextGenerationInputSchema = {
|
|
5867
5382
|
type: "object",
|
|
5868
5383
|
properties: {
|
|
5869
|
-
model:
|
|
5870
|
-
prompt:
|
|
5384
|
+
model: modelSchema23,
|
|
5385
|
+
prompt: {
|
|
5871
5386
|
type: "string",
|
|
5872
5387
|
title: "Prompt",
|
|
5873
5388
|
description: "The prompt to generate text from"
|
|
5874
|
-
}
|
|
5389
|
+
},
|
|
5875
5390
|
maxTokens: {
|
|
5876
5391
|
type: "number",
|
|
5877
5392
|
title: "Max Tokens",
|
|
@@ -5940,19 +5455,19 @@ class TextGenerationTask extends StreamingAiTask {
|
|
|
5940
5455
|
var textGeneration = (input, config) => {
|
|
5941
5456
|
return new TextGenerationTask({}, config).run(input);
|
|
5942
5457
|
};
|
|
5943
|
-
|
|
5458
|
+
Workflow35.prototype.textGeneration = CreateWorkflow35(TextGenerationTask);
|
|
5944
5459
|
|
|
5945
5460
|
// src/task/TextLanguageDetectionTask.ts
|
|
5946
|
-
import { CreateWorkflow as
|
|
5947
|
-
var
|
|
5461
|
+
import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
|
|
5462
|
+
var modelSchema24 = TypeModel("model:TextLanguageDetectionTask");
|
|
5948
5463
|
var TextLanguageDetectionInputSchema = {
|
|
5949
5464
|
type: "object",
|
|
5950
5465
|
properties: {
|
|
5951
|
-
text:
|
|
5466
|
+
text: {
|
|
5952
5467
|
type: "string",
|
|
5953
5468
|
title: "Text",
|
|
5954
5469
|
description: "The text to detect the language of"
|
|
5955
|
-
}
|
|
5470
|
+
},
|
|
5956
5471
|
maxLanguages: {
|
|
5957
5472
|
type: "number",
|
|
5958
5473
|
minimum: 0,
|
|
@@ -5961,7 +5476,7 @@ var TextLanguageDetectionInputSchema = {
|
|
|
5961
5476
|
title: "Max Languages",
|
|
5962
5477
|
description: "The maximum number of languages to return"
|
|
5963
5478
|
},
|
|
5964
|
-
model:
|
|
5479
|
+
model: modelSchema24
|
|
5965
5480
|
},
|
|
5966
5481
|
required: ["text", "model"],
|
|
5967
5482
|
additionalProperties: false
|
|
@@ -5969,7 +5484,7 @@ var TextLanguageDetectionInputSchema = {
|
|
|
5969
5484
|
var TextLanguageDetectionOutputSchema = {
|
|
5970
5485
|
type: "object",
|
|
5971
5486
|
properties: {
|
|
5972
|
-
languages:
|
|
5487
|
+
languages: {
|
|
5973
5488
|
type: "array",
|
|
5974
5489
|
items: {
|
|
5975
5490
|
type: "object",
|
|
@@ -5990,7 +5505,7 @@ var TextLanguageDetectionOutputSchema = {
|
|
|
5990
5505
|
},
|
|
5991
5506
|
title: "Languages",
|
|
5992
5507
|
description: "The languages with their scores"
|
|
5993
|
-
}
|
|
5508
|
+
}
|
|
5994
5509
|
},
|
|
5995
5510
|
required: ["languages"],
|
|
5996
5511
|
additionalProperties: false
|
|
@@ -6011,33 +5526,33 @@ class TextLanguageDetectionTask extends AiTask {
|
|
|
6011
5526
|
var textLanguageDetection = (input, config) => {
|
|
6012
5527
|
return new TextLanguageDetectionTask({}, config).run(input);
|
|
6013
5528
|
};
|
|
6014
|
-
|
|
5529
|
+
Workflow36.prototype.textLanguageDetection = CreateWorkflow36(TextLanguageDetectionTask);
|
|
6015
5530
|
|
|
6016
5531
|
// src/task/TextQuestionAnswerTask.ts
|
|
6017
|
-
import { CreateWorkflow as
|
|
6018
|
-
var contextSchema =
|
|
5532
|
+
import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
|
|
5533
|
+
var contextSchema = {
|
|
6019
5534
|
type: "string",
|
|
6020
5535
|
title: "Context",
|
|
6021
5536
|
description: "The context of the question"
|
|
6022
|
-
}
|
|
6023
|
-
var questionSchema =
|
|
5537
|
+
};
|
|
5538
|
+
var questionSchema = {
|
|
6024
5539
|
type: "string",
|
|
6025
5540
|
title: "Question",
|
|
6026
5541
|
description: "The question to answer"
|
|
6027
|
-
}
|
|
6028
|
-
var textSchema =
|
|
5542
|
+
};
|
|
5543
|
+
var textSchema = {
|
|
6029
5544
|
type: "string",
|
|
6030
5545
|
title: "Text",
|
|
6031
5546
|
description: "The generated text",
|
|
6032
5547
|
"x-stream": "append"
|
|
6033
|
-
}
|
|
6034
|
-
var
|
|
5548
|
+
};
|
|
5549
|
+
var modelSchema25 = TypeModel("model:TextQuestionAnswerTask");
|
|
6035
5550
|
var TextQuestionAnswerInputSchema = {
|
|
6036
5551
|
type: "object",
|
|
6037
5552
|
properties: {
|
|
6038
5553
|
context: contextSchema,
|
|
6039
5554
|
question: questionSchema,
|
|
6040
|
-
model:
|
|
5555
|
+
model: modelSchema25
|
|
6041
5556
|
},
|
|
6042
5557
|
required: ["context", "question", "model"],
|
|
6043
5558
|
additionalProperties: false
|
|
@@ -6066,25 +5581,25 @@ class TextQuestionAnswerTask extends StreamingAiTask {
|
|
|
6066
5581
|
var textQuestionAnswer = (input, config) => {
|
|
6067
5582
|
return new TextQuestionAnswerTask({}, config).run(input);
|
|
6068
5583
|
};
|
|
6069
|
-
|
|
5584
|
+
Workflow37.prototype.textQuestionAnswer = CreateWorkflow37(TextQuestionAnswerTask);
|
|
6070
5585
|
|
|
6071
5586
|
// src/task/TextRewriterTask.ts
|
|
6072
|
-
import { CreateWorkflow as
|
|
6073
|
-
var
|
|
5587
|
+
import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
|
|
5588
|
+
var modelSchema26 = TypeModel("model:TextRewriterTask");
|
|
6074
5589
|
var TextRewriterInputSchema = {
|
|
6075
5590
|
type: "object",
|
|
6076
5591
|
properties: {
|
|
6077
|
-
text:
|
|
5592
|
+
text: {
|
|
6078
5593
|
type: "string",
|
|
6079
5594
|
title: "Text",
|
|
6080
5595
|
description: "The text to rewrite"
|
|
6081
|
-
}
|
|
5596
|
+
},
|
|
6082
5597
|
prompt: {
|
|
6083
5598
|
type: "string",
|
|
6084
5599
|
title: "Prompt",
|
|
6085
5600
|
description: "The prompt to direct the rewriting"
|
|
6086
5601
|
},
|
|
6087
|
-
model:
|
|
5602
|
+
model: modelSchema26
|
|
6088
5603
|
},
|
|
6089
5604
|
required: ["text", "prompt", "model"],
|
|
6090
5605
|
additionalProperties: false
|
|
@@ -6092,12 +5607,12 @@ var TextRewriterInputSchema = {
|
|
|
6092
5607
|
var TextRewriterOutputSchema = {
|
|
6093
5608
|
type: "object",
|
|
6094
5609
|
properties: {
|
|
6095
|
-
text:
|
|
5610
|
+
text: {
|
|
6096
5611
|
type: "string",
|
|
6097
5612
|
title: "Text",
|
|
6098
5613
|
description: "The rewritten text",
|
|
6099
5614
|
"x-stream": "append"
|
|
6100
|
-
}
|
|
5615
|
+
}
|
|
6101
5616
|
},
|
|
6102
5617
|
required: ["text"],
|
|
6103
5618
|
additionalProperties: false
|
|
@@ -6118,25 +5633,25 @@ class TextRewriterTask extends StreamingAiTask {
|
|
|
6118
5633
|
var textRewriter = (input, config) => {
|
|
6119
5634
|
return new TextRewriterTask({}, config).run(input);
|
|
6120
5635
|
};
|
|
6121
|
-
|
|
5636
|
+
Workflow38.prototype.textRewriter = CreateWorkflow38(TextRewriterTask);
|
|
6122
5637
|
|
|
6123
5638
|
// src/task/TextTranslationTask.ts
|
|
6124
|
-
import { CreateWorkflow as
|
|
6125
|
-
var
|
|
6126
|
-
var translationTextSchema =
|
|
5639
|
+
import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
|
|
5640
|
+
var modelSchema27 = TypeModel("model:TextTranslationTask");
|
|
5641
|
+
var translationTextSchema = {
|
|
6127
5642
|
type: "string",
|
|
6128
5643
|
title: "Text",
|
|
6129
5644
|
description: "The translated text",
|
|
6130
5645
|
"x-stream": "replace"
|
|
6131
|
-
}
|
|
5646
|
+
};
|
|
6132
5647
|
var TextTranslationInputSchema = {
|
|
6133
5648
|
type: "object",
|
|
6134
5649
|
properties: {
|
|
6135
|
-
text:
|
|
5650
|
+
text: {
|
|
6136
5651
|
type: "string",
|
|
6137
5652
|
title: "Text",
|
|
6138
5653
|
description: "The text to translate"
|
|
6139
|
-
}
|
|
5654
|
+
},
|
|
6140
5655
|
source_lang: TypeLanguage({
|
|
6141
5656
|
title: "Source Language",
|
|
6142
5657
|
description: "The source language",
|
|
@@ -6149,7 +5664,7 @@ var TextTranslationInputSchema = {
|
|
|
6149
5664
|
minLength: 2,
|
|
6150
5665
|
maxLength: 2
|
|
6151
5666
|
}),
|
|
6152
|
-
model:
|
|
5667
|
+
model: modelSchema27
|
|
6153
5668
|
},
|
|
6154
5669
|
required: ["text", "source_lang", "target_lang", "model"],
|
|
6155
5670
|
additionalProperties: false
|
|
@@ -6184,14 +5699,10 @@ class TextTranslationTask extends StreamingAiTask {
|
|
|
6184
5699
|
var textTranslation = (input, config) => {
|
|
6185
5700
|
return new TextTranslationTask({}, config).run(input);
|
|
6186
5701
|
};
|
|
6187
|
-
|
|
5702
|
+
Workflow39.prototype.textTranslation = CreateWorkflow39(TextTranslationTask);
|
|
6188
5703
|
|
|
6189
5704
|
// src/task/TopicSegmenterTask.ts
|
|
6190
|
-
import {
|
|
6191
|
-
CreateWorkflow as CreateWorkflow42,
|
|
6192
|
-
Task as Task16,
|
|
6193
|
-
Workflow as Workflow42
|
|
6194
|
-
} from "@workglow/task-graph";
|
|
5705
|
+
import { CreateWorkflow as CreateWorkflow40, Task as Task16, Workflow as Workflow40 } from "@workglow/task-graph";
|
|
6195
5706
|
var SegmentationMethod = {
|
|
6196
5707
|
HEURISTIC: "heuristic",
|
|
6197
5708
|
EMBEDDING_SIMILARITY: "embedding-similarity",
|
|
@@ -6471,15 +5982,15 @@ class TopicSegmenterTask extends Task16 {
|
|
|
6471
5982
|
var topicSegmenter = (input, config) => {
|
|
6472
5983
|
return new TopicSegmenterTask({}, config).run(input);
|
|
6473
5984
|
};
|
|
6474
|
-
|
|
5985
|
+
Workflow40.prototype.topicSegmenter = CreateWorkflow40(TopicSegmenterTask);
|
|
6475
5986
|
|
|
6476
5987
|
// src/task/UnloadModelTask.ts
|
|
6477
|
-
import { CreateWorkflow as
|
|
6478
|
-
var
|
|
5988
|
+
import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
|
|
5989
|
+
var modelSchema28 = TypeModel("model");
|
|
6479
5990
|
var UnloadModelInputSchema = {
|
|
6480
5991
|
type: "object",
|
|
6481
5992
|
properties: {
|
|
6482
|
-
model:
|
|
5993
|
+
model: modelSchema28
|
|
6483
5994
|
},
|
|
6484
5995
|
required: ["model"],
|
|
6485
5996
|
additionalProperties: false
|
|
@@ -6487,7 +5998,7 @@ var UnloadModelInputSchema = {
|
|
|
6487
5998
|
var UnloadModelOutputSchema = {
|
|
6488
5999
|
type: "object",
|
|
6489
6000
|
properties: {
|
|
6490
|
-
model:
|
|
6001
|
+
model: modelSchema28
|
|
6491
6002
|
},
|
|
6492
6003
|
required: ["model"],
|
|
6493
6004
|
additionalProperties: false
|
|
@@ -6509,10 +6020,10 @@ class UnloadModelTask extends AiTask {
|
|
|
6509
6020
|
var unloadModel = (input, config) => {
|
|
6510
6021
|
return new UnloadModelTask({}, config).run(input);
|
|
6511
6022
|
};
|
|
6512
|
-
|
|
6023
|
+
Workflow41.prototype.unloadModel = CreateWorkflow41(UnloadModelTask);
|
|
6513
6024
|
|
|
6514
6025
|
// src/task/VectorQuantizeTask.ts
|
|
6515
|
-
import { CreateWorkflow as
|
|
6026
|
+
import { CreateWorkflow as CreateWorkflow42, Task as Task17, Workflow as Workflow42 } from "@workglow/task-graph";
|
|
6516
6027
|
import {
|
|
6517
6028
|
normalizeNumberArray,
|
|
6518
6029
|
TensorType,
|
|
@@ -6692,10 +6203,10 @@ class VectorQuantizeTask extends Task17 {
|
|
|
6692
6203
|
var vectorQuantize = (input, config) => {
|
|
6693
6204
|
return new VectorQuantizeTask({}, config).run(input);
|
|
6694
6205
|
};
|
|
6695
|
-
|
|
6206
|
+
Workflow42.prototype.vectorQuantize = CreateWorkflow42(VectorQuantizeTask);
|
|
6696
6207
|
|
|
6697
6208
|
// src/task/VectorSimilarityTask.ts
|
|
6698
|
-
import { CreateWorkflow as
|
|
6209
|
+
import { CreateWorkflow as CreateWorkflow43, GraphAsTask, Workflow as Workflow43 } from "@workglow/task-graph";
|
|
6699
6210
|
import {
|
|
6700
6211
|
cosineSimilarity,
|
|
6701
6212
|
hammingSimilarity,
|
|
@@ -6801,208 +6312,11 @@ class VectorSimilarityTask extends GraphAsTask {
|
|
|
6801
6312
|
var similarity = (input, config) => {
|
|
6802
6313
|
return new VectorSimilarityTask({}, config).run(input);
|
|
6803
6314
|
};
|
|
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
|
-
}
|
|
6315
|
+
Workflow43.prototype.similarity = CreateWorkflow43(VectorSimilarityTask);
|
|
7001
6316
|
|
|
7002
6317
|
// src/task/index.ts
|
|
7003
6318
|
var registerAiTasks = () => {
|
|
7004
6319
|
const tasks = [
|
|
7005
|
-
AgentTask,
|
|
7006
6320
|
BackgroundRemovalTask,
|
|
7007
6321
|
ChunkToVectorTask,
|
|
7008
6322
|
CountTokensTask,
|
|
@@ -7042,7 +6356,6 @@ var registerAiTasks = () => {
|
|
|
7042
6356
|
TextRewriterTask,
|
|
7043
6357
|
TextSummaryTask,
|
|
7044
6358
|
TextTranslationTask,
|
|
7045
|
-
ToolCallingTask,
|
|
7046
6359
|
TopicSegmenterTask,
|
|
7047
6360
|
UnloadModelTask,
|
|
7048
6361
|
VectorQuantizeTask,
|
|
@@ -7054,14 +6367,8 @@ var registerAiTasks = () => {
|
|
|
7054
6367
|
export {
|
|
7055
6368
|
vectorStoreSearch,
|
|
7056
6369
|
vectorQuantize,
|
|
7057
|
-
userMessage,
|
|
7058
6370
|
unloadModel,
|
|
7059
6371
|
topicSegmenter,
|
|
7060
|
-
toolSourceDefinitions,
|
|
7061
|
-
toolMessage,
|
|
7062
|
-
toolCalling,
|
|
7063
|
-
toTextFlatMessages,
|
|
7064
|
-
toOpenAIMessages,
|
|
7065
6372
|
textTranslation,
|
|
7066
6373
|
textSummary,
|
|
7067
6374
|
textRewriter,
|
|
@@ -7073,12 +6380,12 @@ export {
|
|
|
7073
6380
|
textEmbedding,
|
|
7074
6381
|
textClassification,
|
|
7075
6382
|
textChunker,
|
|
7076
|
-
taskTypesToTools,
|
|
7077
6383
|
structuredGeneration,
|
|
7078
6384
|
structuralParser,
|
|
7079
6385
|
similarity,
|
|
7080
6386
|
setGlobalModelRepository,
|
|
7081
6387
|
setAiProviderRegistry,
|
|
6388
|
+
resolveAiProviderGpuQueueConcurrency,
|
|
7082
6389
|
reranker,
|
|
7083
6390
|
registerAiTasks,
|
|
7084
6391
|
queryExpander,
|
|
@@ -7086,27 +6393,19 @@ export {
|
|
|
7086
6393
|
objectDetection,
|
|
7087
6394
|
modelSearch,
|
|
7088
6395
|
modelInfo,
|
|
7089
|
-
isAllowedToolName,
|
|
7090
6396
|
imageToText,
|
|
7091
6397
|
imageSegmentation,
|
|
7092
6398
|
imageEmbedding,
|
|
7093
6399
|
imageClassification,
|
|
7094
|
-
imageBlockFromDataUri,
|
|
7095
|
-
imageBlock,
|
|
7096
6400
|
hybridSearch,
|
|
7097
6401
|
hierarchyJoin,
|
|
7098
6402
|
hierarchicalChunker,
|
|
7099
|
-
hasToolCalls,
|
|
7100
6403
|
handLandmarker,
|
|
7101
6404
|
getGlobalModelRepository,
|
|
7102
6405
|
getAiProviderRegistry,
|
|
7103
6406
|
gestureRecognizer,
|
|
7104
|
-
findToolSource,
|
|
7105
|
-
filterValidToolCalls,
|
|
7106
6407
|
faceLandmarker,
|
|
7107
6408
|
faceDetector,
|
|
7108
|
-
executeToolCalls,
|
|
7109
|
-
executeToolCall,
|
|
7110
6409
|
downloadModel,
|
|
7111
6410
|
documentEnricher,
|
|
7112
6411
|
countTokens,
|
|
@@ -7114,13 +6413,7 @@ export {
|
|
|
7114
6413
|
chunkVectorUpsert,
|
|
7115
6414
|
chunkToVector,
|
|
7116
6415
|
chunkRetrieval,
|
|
7117
|
-
buildToolSources,
|
|
7118
|
-
buildToolDescription,
|
|
7119
6416
|
backgroundRemoval,
|
|
7120
|
-
audioBlockFromDataUri,
|
|
7121
|
-
audioBlock,
|
|
7122
|
-
assistantMessage,
|
|
7123
|
-
agent,
|
|
7124
6417
|
VectorSimilarityTask,
|
|
7125
6418
|
VectorQuantizeTask,
|
|
7126
6419
|
UnloadModelTask,
|
|
@@ -7134,10 +6427,6 @@ export {
|
|
|
7134
6427
|
TypeBoundingBox,
|
|
7135
6428
|
TypeAudioInput,
|
|
7136
6429
|
TopicSegmenterTask,
|
|
7137
|
-
ToolDefinitionSchema,
|
|
7138
|
-
ToolCallingTask,
|
|
7139
|
-
ToolCallingOutputSchema,
|
|
7140
|
-
ToolCallingInputSchema,
|
|
7141
6430
|
TextTranslationTask,
|
|
7142
6431
|
TextTranslationOutputSchema,
|
|
7143
6432
|
TextTranslationInputSchema,
|
|
@@ -7177,6 +6466,7 @@ export {
|
|
|
7177
6466
|
SimilarityFn,
|
|
7178
6467
|
SegmentationMethod,
|
|
7179
6468
|
RerankerTask,
|
|
6469
|
+
QueuedExecutionStrategy,
|
|
7180
6470
|
QueuedAiProvider,
|
|
7181
6471
|
QueryExpansionMethod,
|
|
7182
6472
|
QueryExpanderTask,
|
|
@@ -7222,6 +6512,7 @@ export {
|
|
|
7222
6512
|
FaceDetectorInputSchema,
|
|
7223
6513
|
DownloadModelTask,
|
|
7224
6514
|
DocumentEnricherTask,
|
|
6515
|
+
DirectExecutionStrategy,
|
|
7225
6516
|
CountTokensTask,
|
|
7226
6517
|
CountTokensOutputSchema,
|
|
7227
6518
|
CountTokensInputSchema,
|
|
@@ -7239,10 +6530,7 @@ export {
|
|
|
7239
6530
|
AiTask,
|
|
7240
6531
|
AiProviderRegistry,
|
|
7241
6532
|
AiProvider,
|
|
7242
|
-
AiJob
|
|
7243
|
-
AgentTask,
|
|
7244
|
-
AgentOutputSchema,
|
|
7245
|
-
AgentInputSchema
|
|
6533
|
+
AiJob
|
|
7246
6534
|
};
|
|
7247
6535
|
|
|
7248
|
-
//# debugId=
|
|
6536
|
+
//# debugId=E524D982D216D11064756E2164756E21
|