@workglow/ai 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +887 -929
- package/dist/browser.js.map +15 -16
- package/dist/bun.js +887 -929
- package/dist/bun.js.map +15 -16
- package/dist/execution/QueuedExecutionStrategy.d.ts +14 -5
- package/dist/execution/QueuedExecutionStrategy.d.ts.map +1 -1
- package/dist/job/AiJob.d.ts +2 -0
- package/dist/job/AiJob.d.ts.map +1 -1
- package/dist/node.js +887 -929
- package/dist/node.js.map +15 -16
- package/dist/provider/AiProvider.d.ts +15 -0
- package/dist/provider/AiProvider.d.ts.map +1 -1
- package/dist/provider/AiProviderRegistry.d.ts +16 -2
- package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
- package/dist/task/AiChatTask.d.ts +666 -0
- package/dist/task/AiChatTask.d.ts.map +1 -0
- package/dist/task/ChatMessage.d.ts +356 -0
- package/dist/task/ChatMessage.d.ts.map +1 -0
- package/dist/task/MessageConversion.d.ts +1 -9
- package/dist/task/MessageConversion.d.ts.map +1 -1
- package/dist/task/StructuredGenerationTask.d.ts +50 -3
- package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
- package/dist/task/ToolCallingTask.d.ts +177 -10
- package/dist/task/ToolCallingTask.d.ts.map +1 -1
- package/dist/task/base/AiTask.d.ts.map +1 -1
- package/dist/task/index.d.ts +6 -7
- package/dist/task/index.d.ts.map +1 -1
- package/dist/worker.js +65 -97
- package/dist/worker.js.map +6 -6
- package/package.json +11 -11
- package/dist/task/AgentTask.d.ts +0 -541
- package/dist/task/AgentTask.d.ts.map +0 -1
- package/dist/task/AgentTypes.d.ts +0 -183
- package/dist/task/AgentTypes.d.ts.map +0 -1
- package/dist/task/AgentUtils.d.ts +0 -55
- package/dist/task/AgentUtils.d.ts.map +0 -1
package/dist/browser.js
CHANGED
|
@@ -55,6 +55,19 @@ class AiProviderRegistry {
|
|
|
55
55
|
}
|
|
56
56
|
return this.defaultStrategy;
|
|
57
57
|
}
|
|
58
|
+
createSession(providerName, model) {
|
|
59
|
+
const provider = this.providers.get(providerName);
|
|
60
|
+
if (!provider) {
|
|
61
|
+
throw new Error(`No provider found for "${providerName}". Register the provider before creating sessions.`);
|
|
62
|
+
}
|
|
63
|
+
return provider.createSession(model);
|
|
64
|
+
}
|
|
65
|
+
async disposeSession(providerName, sessionId) {
|
|
66
|
+
const provider = this.providers.get(providerName);
|
|
67
|
+
if (provider) {
|
|
68
|
+
await provider.disposeSession(sessionId);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
getProviderIdsForTask(taskType) {
|
|
59
72
|
const taskMap = this.runFnRegistry.get(taskType);
|
|
60
73
|
if (!taskMap)
|
|
@@ -68,9 +81,9 @@ class AiProviderRegistry {
|
|
|
68
81
|
this.runFnRegistry.get(taskType).set(modelProvider, runFn);
|
|
69
82
|
}
|
|
70
83
|
registerAsWorkerRunFn(modelProvider, taskType) {
|
|
71
|
-
const workerFn = async (input, model, update_progress, signal, outputSchema) => {
|
|
84
|
+
const workerFn = async (input, model, update_progress, signal, outputSchema, sessionId) => {
|
|
72
85
|
const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
|
|
73
|
-
const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema], {
|
|
86
|
+
const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema, sessionId], {
|
|
74
87
|
signal,
|
|
75
88
|
onProgress: update_progress
|
|
76
89
|
});
|
|
@@ -85,9 +98,9 @@ class AiProviderRegistry {
|
|
|
85
98
|
this.streamFnRegistry.get(taskType).set(modelProvider, streamFn);
|
|
86
99
|
}
|
|
87
100
|
registerAsWorkerStreamFn(modelProvider, taskType) {
|
|
88
|
-
const streamFn = async function* (input, model, signal, outputSchema) {
|
|
101
|
+
const streamFn = async function* (input, model, signal, outputSchema, sessionId) {
|
|
89
102
|
const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
|
|
90
|
-
yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema], { signal });
|
|
103
|
+
yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema, sessionId], { signal });
|
|
91
104
|
};
|
|
92
105
|
this.registerStreamFn(modelProvider, taskType, streamFn);
|
|
93
106
|
}
|
|
@@ -215,7 +228,7 @@ class AiJob extends Job {
|
|
|
215
228
|
const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
|
|
216
229
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
217
230
|
const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
|
|
218
|
-
return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema);
|
|
231
|
+
return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema, input.sessionId);
|
|
219
232
|
};
|
|
220
233
|
const runFnPromise = runFn();
|
|
221
234
|
return await Promise.race([runFnPromise, abortPromise]);
|
|
@@ -243,7 +256,7 @@ class AiJob extends Job {
|
|
|
243
256
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
244
257
|
const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
|
|
245
258
|
try {
|
|
246
|
-
for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema)) {
|
|
259
|
+
for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema, input.sessionId)) {
|
|
247
260
|
if (event.type === "finish") {
|
|
248
261
|
lastFinishData = event.data;
|
|
249
262
|
}
|
|
@@ -308,6 +321,7 @@ class QueuedExecutionStrategy {
|
|
|
308
321
|
concurrency;
|
|
309
322
|
autoCreate;
|
|
310
323
|
initPromise = null;
|
|
324
|
+
limiter;
|
|
311
325
|
constructor(queueName, concurrency = 1, autoCreate = true) {
|
|
312
326
|
this.queueName = queueName;
|
|
313
327
|
this.concurrency = concurrency;
|
|
@@ -345,8 +359,42 @@ class QueuedExecutionStrategy {
|
|
|
345
359
|
}
|
|
346
360
|
abort() {}
|
|
347
361
|
async* executeStream(jobInput, context, runnerId) {
|
|
348
|
-
|
|
349
|
-
|
|
362
|
+
if (context.signal.aborted) {
|
|
363
|
+
throw context.signal.reason ?? new AbortSignalJobError2("The operation was aborted");
|
|
364
|
+
}
|
|
365
|
+
await this.ensureQueue();
|
|
366
|
+
const limiter = this.limiter;
|
|
367
|
+
if (!limiter) {
|
|
368
|
+
throw new TaskConfigurationError(`QueuedExecutionStrategy: limiter was not initialized for queue "${this.queueName}"`);
|
|
369
|
+
}
|
|
370
|
+
await this.acquireLimiterSlot(limiter, context.signal);
|
|
371
|
+
try {
|
|
372
|
+
const job = new AiJob({
|
|
373
|
+
queueName: jobInput.aiProvider,
|
|
374
|
+
jobRunId: runnerId,
|
|
375
|
+
input: jobInput
|
|
376
|
+
});
|
|
377
|
+
yield* job.executeStream(jobInput, {
|
|
378
|
+
signal: context.signal,
|
|
379
|
+
updateProgress: context.updateProgress
|
|
380
|
+
});
|
|
381
|
+
} finally {
|
|
382
|
+
await limiter.recordJobCompletion();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
async acquireLimiterSlot(limiter, signal) {
|
|
386
|
+
const poll = async () => {
|
|
387
|
+
while (!await limiter.canProceed()) {
|
|
388
|
+
if (signal.aborted) {
|
|
389
|
+
throw signal.reason ?? new AbortSignalJobError2("The operation was aborted");
|
|
390
|
+
}
|
|
391
|
+
const next = await limiter.getNextAvailableTime();
|
|
392
|
+
const delay = Math.max(0, next.getTime() - Date.now());
|
|
393
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(delay, 50)));
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
await poll();
|
|
397
|
+
await limiter.recordJobStart();
|
|
350
398
|
}
|
|
351
399
|
ensureQueue() {
|
|
352
400
|
if (!this.initPromise) {
|
|
@@ -364,6 +412,7 @@ class QueuedExecutionStrategy {
|
|
|
364
412
|
if (!existing.server.isRunning()) {
|
|
365
413
|
await existing.server.start();
|
|
366
414
|
}
|
|
415
|
+
this.limiter = existing.server.limiter;
|
|
367
416
|
return existing;
|
|
368
417
|
}
|
|
369
418
|
if (!this.autoCreate) {
|
|
@@ -371,10 +420,11 @@ class QueuedExecutionStrategy {
|
|
|
371
420
|
}
|
|
372
421
|
const storage = new InMemoryQueueStorage(this.queueName);
|
|
373
422
|
await storage.setupDatabase();
|
|
423
|
+
this.limiter = new ConcurrencyLimiter(this.concurrency);
|
|
374
424
|
const server = new JobQueueServer(AiJob, {
|
|
375
425
|
storage,
|
|
376
426
|
queueName: this.queueName,
|
|
377
|
-
limiter:
|
|
427
|
+
limiter: this.limiter
|
|
378
428
|
});
|
|
379
429
|
const client = new JobQueueClient({
|
|
380
430
|
storage,
|
|
@@ -398,6 +448,7 @@ class QueuedExecutionStrategy {
|
|
|
398
448
|
if (!raced.server.isRunning()) {
|
|
399
449
|
await raced.server.start();
|
|
400
450
|
}
|
|
451
|
+
this.limiter = raced.server.limiter;
|
|
401
452
|
return raced;
|
|
402
453
|
}
|
|
403
454
|
}
|
|
@@ -759,6 +810,10 @@ class AiProvider {
|
|
|
759
810
|
}
|
|
760
811
|
async onInitialize(_options) {}
|
|
761
812
|
async dispose() {}
|
|
813
|
+
createSession(_model) {
|
|
814
|
+
return crypto.randomUUID();
|
|
815
|
+
}
|
|
816
|
+
async disposeSession(_sessionId) {}
|
|
762
817
|
async afterRegister(_options) {}
|
|
763
818
|
}
|
|
764
819
|
|
|
@@ -782,74 +837,8 @@ class QueuedAiProvider extends AiProvider {
|
|
|
782
837
|
// src/task/index.ts
|
|
783
838
|
import { TaskRegistry } from "@workglow/task-graph";
|
|
784
839
|
|
|
785
|
-
// src/task/
|
|
786
|
-
import {
|
|
787
|
-
import { getLogger as getLogger4 } from "@workglow/util";
|
|
788
|
-
|
|
789
|
-
// src/task/AgentTypes.ts
|
|
790
|
-
import { parseDataUri } from "@workglow/util/media";
|
|
791
|
-
function imageBlock(mimeType, data) {
|
|
792
|
-
return { type: "image", mimeType, data };
|
|
793
|
-
}
|
|
794
|
-
function audioBlock(mimeType, data) {
|
|
795
|
-
return { type: "audio", mimeType, data };
|
|
796
|
-
}
|
|
797
|
-
function imageBlockFromDataUri(dataUri) {
|
|
798
|
-
const { mimeType, base64 } = parseDataUri(dataUri);
|
|
799
|
-
return { type: "image", mimeType, data: base64 };
|
|
800
|
-
}
|
|
801
|
-
function audioBlockFromDataUri(dataUri) {
|
|
802
|
-
const { mimeType, base64 } = parseDataUri(dataUri);
|
|
803
|
-
return { type: "audio", mimeType, data: base64 };
|
|
804
|
-
}
|
|
805
|
-
function userMessage(prompt) {
|
|
806
|
-
return { role: "user", content: prompt };
|
|
807
|
-
}
|
|
808
|
-
function assistantMessage(text, toolCalls) {
|
|
809
|
-
const content = [];
|
|
810
|
-
if (text) {
|
|
811
|
-
content.push({ type: "text", text });
|
|
812
|
-
}
|
|
813
|
-
if (toolCalls) {
|
|
814
|
-
for (const tc of toolCalls) {
|
|
815
|
-
content.push({
|
|
816
|
-
type: "tool_use",
|
|
817
|
-
id: tc.id,
|
|
818
|
-
name: tc.name,
|
|
819
|
-
input: tc.input
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
return { role: "assistant", content };
|
|
824
|
-
}
|
|
825
|
-
function toolMessage(results) {
|
|
826
|
-
return {
|
|
827
|
-
role: "tool",
|
|
828
|
-
content: results.map((r) => {
|
|
829
|
-
const jsonText = JSON.stringify(r.output);
|
|
830
|
-
const content = r.mediaContent && r.mediaContent.length > 0 ? [{ type: "text", text: jsonText }, ...r.mediaContent] : jsonText;
|
|
831
|
-
return {
|
|
832
|
-
type: "tool_result",
|
|
833
|
-
tool_use_id: r.toolCallId,
|
|
834
|
-
content,
|
|
835
|
-
is_error: r.isError || undefined
|
|
836
|
-
};
|
|
837
|
-
})
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
function toolSourceDefinitions(sources) {
|
|
841
|
-
return sources.map((s) => s.definition);
|
|
842
|
-
}
|
|
843
|
-
function findToolSource(sources, name) {
|
|
844
|
-
return sources.find((s) => s.definition.name === name);
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
// src/task/AgentUtils.ts
|
|
848
|
-
import { getTaskConstructors as getTaskConstructors2, TaskAbortedError } from "@workglow/task-graph";
|
|
849
|
-
import { getLogger as getLogger3 } from "@workglow/util";
|
|
850
|
-
|
|
851
|
-
// src/task/ToolCallingTask.ts
|
|
852
|
-
import { CreateWorkflow, getTaskConstructors, Workflow } from "@workglow/task-graph";
|
|
840
|
+
// src/task/AiChatTask.ts
|
|
841
|
+
import { TaskConfigSchema as TaskConfigSchema2 } from "@workglow/task-graph";
|
|
853
842
|
|
|
854
843
|
// src/task/base/AiTaskSchemas.ts
|
|
855
844
|
var TypeLanguage = (annotations = {}) => ({
|
|
@@ -1099,6 +1088,10 @@ class AiTask extends Task {
|
|
|
1099
1088
|
jobInput.outputSchema = taskOutputSchema;
|
|
1100
1089
|
}
|
|
1101
1090
|
}
|
|
1091
|
+
const sessionId = input.sessionId;
|
|
1092
|
+
if (sessionId) {
|
|
1093
|
+
jobInput.sessionId = sessionId;
|
|
1094
|
+
}
|
|
1102
1095
|
return jobInput;
|
|
1103
1096
|
}
|
|
1104
1097
|
async createJob(input, queueName) {
|
|
@@ -1225,672 +1218,356 @@ class StreamingAiTask extends AiTask {
|
|
|
1225
1218
|
}
|
|
1226
1219
|
}
|
|
1227
1220
|
|
|
1228
|
-
// src/task/
|
|
1229
|
-
|
|
1230
|
-
const constructors = getTaskConstructors(registry);
|
|
1231
|
-
return taskNames.map((name) => {
|
|
1232
|
-
const ctor = constructors.get(name);
|
|
1233
|
-
if (!ctor) {
|
|
1234
|
-
throw new Error(`taskTypesToTools: Unknown task type "${name}" — not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
|
|
1235
|
-
}
|
|
1236
|
-
const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
|
|
1237
|
-
return {
|
|
1238
|
-
name: ctor.type,
|
|
1239
|
-
description: ctor.description ?? "",
|
|
1240
|
-
inputSchema: ctor.inputSchema(),
|
|
1241
|
-
outputSchema: ctor.outputSchema(),
|
|
1242
|
-
...configSchema ? { configSchema } : {},
|
|
1243
|
-
taskType: name
|
|
1244
|
-
};
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
var ToolDefinitionSchema = {
|
|
1221
|
+
// src/task/ChatMessage.ts
|
|
1222
|
+
var ContentBlockTextSchema = {
|
|
1248
1223
|
type: "object",
|
|
1249
1224
|
properties: {
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
},
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
},
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1225
|
+
type: { type: "string", enum: ["text"] },
|
|
1226
|
+
text: { type: "string" }
|
|
1227
|
+
},
|
|
1228
|
+
required: ["type", "text"],
|
|
1229
|
+
additionalProperties: false
|
|
1230
|
+
};
|
|
1231
|
+
var ContentBlockImageSchema = {
|
|
1232
|
+
type: "object",
|
|
1233
|
+
properties: {
|
|
1234
|
+
type: { type: "string", enum: ["image"] },
|
|
1235
|
+
mimeType: { type: "string" },
|
|
1236
|
+
data: { type: "string" }
|
|
1237
|
+
},
|
|
1238
|
+
required: ["type", "mimeType", "data"],
|
|
1239
|
+
additionalProperties: false
|
|
1240
|
+
};
|
|
1241
|
+
var ContentBlockToolUseSchema = {
|
|
1242
|
+
type: "object",
|
|
1243
|
+
properties: {
|
|
1244
|
+
type: { type: "string", enum: ["tool_use"] },
|
|
1245
|
+
id: { type: "string" },
|
|
1246
|
+
name: { type: "string" },
|
|
1247
|
+
input: { type: "object", additionalProperties: true }
|
|
1248
|
+
},
|
|
1249
|
+
required: ["type", "id", "name", "input"],
|
|
1250
|
+
additionalProperties: false
|
|
1251
|
+
};
|
|
1252
|
+
var ContentBlockToolResultSchema = {
|
|
1253
|
+
type: "object",
|
|
1254
|
+
properties: {
|
|
1255
|
+
type: { type: "string", enum: ["tool_result"] },
|
|
1256
|
+
tool_use_id: { type: "string" },
|
|
1257
|
+
content: {
|
|
1258
|
+
type: "array",
|
|
1259
|
+
items: { $ref: "#/definitions/ContentBlock" }
|
|
1277
1260
|
},
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1261
|
+
is_error: { type: "boolean" }
|
|
1262
|
+
},
|
|
1263
|
+
required: ["type", "tool_use_id", "content"],
|
|
1264
|
+
additionalProperties: false
|
|
1265
|
+
};
|
|
1266
|
+
var ContentBlockSchema = {
|
|
1267
|
+
oneOf: [
|
|
1268
|
+
ContentBlockTextSchema,
|
|
1269
|
+
ContentBlockImageSchema,
|
|
1270
|
+
ContentBlockToolUseSchema,
|
|
1271
|
+
ContentBlockToolResultSchema
|
|
1272
|
+
],
|
|
1273
|
+
definitions: {
|
|
1274
|
+
ContentBlock: {
|
|
1275
|
+
oneOf: [
|
|
1276
|
+
ContentBlockTextSchema,
|
|
1277
|
+
ContentBlockImageSchema,
|
|
1278
|
+
ContentBlockToolUseSchema,
|
|
1279
|
+
ContentBlockToolResultSchema
|
|
1280
|
+
]
|
|
1283
1281
|
}
|
|
1284
1282
|
},
|
|
1285
|
-
|
|
1286
|
-
|
|
1283
|
+
title: "ContentBlock",
|
|
1284
|
+
description: "A single content block within a chat message"
|
|
1287
1285
|
};
|
|
1288
|
-
var
|
|
1286
|
+
var ChatMessageSchema = {
|
|
1289
1287
|
type: "object",
|
|
1290
1288
|
properties: {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1289
|
+
role: { type: "string", enum: ["user", "assistant", "tool", "system"] },
|
|
1290
|
+
content: {
|
|
1291
|
+
type: "array",
|
|
1292
|
+
items: ContentBlockSchema
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
required: ["role", "content"],
|
|
1296
|
+
additionalProperties: false,
|
|
1297
|
+
title: "ChatMessage",
|
|
1298
|
+
description: "A single chat message with role and structured content blocks"
|
|
1299
|
+
};
|
|
1300
|
+
function isContentBlock(value) {
|
|
1301
|
+
if (!value || typeof value !== "object")
|
|
1302
|
+
return false;
|
|
1303
|
+
const v = value;
|
|
1304
|
+
switch (v.type) {
|
|
1305
|
+
case "text":
|
|
1306
|
+
return typeof v.text === "string";
|
|
1307
|
+
case "image":
|
|
1308
|
+
return typeof v.mimeType === "string" && typeof v.data === "string";
|
|
1309
|
+
case "tool_use":
|
|
1310
|
+
return typeof v.id === "string" && typeof v.name === "string" && v.input !== null && typeof v.input === "object";
|
|
1311
|
+
case "tool_result":
|
|
1312
|
+
return typeof v.tool_use_id === "string" && Array.isArray(v.content) && v.content.every(isContentBlock);
|
|
1313
|
+
default:
|
|
1314
|
+
return false;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
function isChatMessage(value) {
|
|
1318
|
+
if (!value || typeof value !== "object")
|
|
1319
|
+
return false;
|
|
1320
|
+
const v = value;
|
|
1321
|
+
const validRole = v.role === "user" || v.role === "assistant" || v.role === "tool" || v.role === "system";
|
|
1322
|
+
return validRole && Array.isArray(v.content) && v.content.every(isContentBlock);
|
|
1323
|
+
}
|
|
1324
|
+
function textMessage(role, text) {
|
|
1325
|
+
return { role, content: [{ type: "text", text }] };
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
// src/task/AiChatTask.ts
|
|
1329
|
+
import { resolveHumanConnector } from "@workglow/util";
|
|
1330
|
+
var modelSchema = TypeModel("model:AiChatTask");
|
|
1331
|
+
var chatConnectorContentSchema = {
|
|
1332
|
+
type: "object",
|
|
1333
|
+
properties: {
|
|
1334
|
+
content: {
|
|
1297
1335
|
type: "string",
|
|
1298
|
-
title: "
|
|
1299
|
-
description: "
|
|
1300
|
-
},
|
|
1301
|
-
input: {
|
|
1302
|
-
type: "object",
|
|
1303
|
-
title: "Input",
|
|
1304
|
-
description: "The input arguments for the tool call",
|
|
1305
|
-
additionalProperties: true
|
|
1336
|
+
title: "Message",
|
|
1337
|
+
description: "Your reply (leave blank to end the conversation)"
|
|
1306
1338
|
}
|
|
1307
1339
|
},
|
|
1308
|
-
required: ["id", "name", "input"],
|
|
1309
1340
|
additionalProperties: false
|
|
1310
1341
|
};
|
|
1311
|
-
var
|
|
1312
|
-
var ToolCallingInputSchema = {
|
|
1342
|
+
var AiChatInputSchema = {
|
|
1313
1343
|
type: "object",
|
|
1314
1344
|
properties: {
|
|
1315
1345
|
model: modelSchema,
|
|
1316
1346
|
prompt: {
|
|
1317
1347
|
oneOf: [
|
|
1318
|
-
{ type: "string", title: "Prompt", description: "The
|
|
1348
|
+
{ type: "string", title: "Prompt", description: "The initial user message" },
|
|
1319
1349
|
{
|
|
1320
1350
|
type: "array",
|
|
1321
1351
|
title: "Prompt",
|
|
1322
|
-
description: "The
|
|
1323
|
-
items:
|
|
1324
|
-
oneOf: [
|
|
1325
|
-
{ type: "string" },
|
|
1326
|
-
{
|
|
1327
|
-
type: "object",
|
|
1328
|
-
properties: {
|
|
1329
|
-
type: { type: "string", enum: ["text", "image", "audio"] }
|
|
1330
|
-
},
|
|
1331
|
-
required: ["type"],
|
|
1332
|
-
additionalProperties: true
|
|
1333
|
-
}
|
|
1334
|
-
]
|
|
1335
|
-
}
|
|
1352
|
+
description: "The initial user message as structured content blocks",
|
|
1353
|
+
items: ContentBlockSchema
|
|
1336
1354
|
}
|
|
1337
1355
|
],
|
|
1338
1356
|
title: "Prompt",
|
|
1339
|
-
description: "The
|
|
1340
|
-
},
|
|
1341
|
-
systemPrompt: {
|
|
1342
|
-
type: "string",
|
|
1343
|
-
title: "System Prompt",
|
|
1344
|
-
description: "Optional system instructions for the model"
|
|
1357
|
+
description: "The first user message to start the conversation"
|
|
1345
1358
|
},
|
|
1346
1359
|
messages: {
|
|
1347
1360
|
type: "array",
|
|
1348
1361
|
title: "Messages",
|
|
1349
|
-
description: "
|
|
1350
|
-
items:
|
|
1351
|
-
|
|
1352
|
-
properties: {
|
|
1353
|
-
role: { type: "string", enum: ["user", "assistant", "tool"] },
|
|
1354
|
-
content: {}
|
|
1355
|
-
},
|
|
1356
|
-
required: ["role", "content"],
|
|
1357
|
-
additionalProperties: true
|
|
1358
|
-
}
|
|
1362
|
+
description: "Conversation history (managed internally by the chat loop; not a user-facing input)",
|
|
1363
|
+
items: ChatMessageSchema,
|
|
1364
|
+
"x-ui-hidden": true
|
|
1359
1365
|
},
|
|
1360
|
-
|
|
1361
|
-
type: "array",
|
|
1362
|
-
format: "tasks",
|
|
1363
|
-
title: "Tools",
|
|
1364
|
-
description: "Tool definitions available for the model to call",
|
|
1365
|
-
items: {
|
|
1366
|
-
oneOf: [
|
|
1367
|
-
{ type: "string", format: "tasks", description: "Task type name" },
|
|
1368
|
-
ToolDefinitionSchema
|
|
1369
|
-
]
|
|
1370
|
-
}
|
|
1371
|
-
},
|
|
1372
|
-
toolChoice: {
|
|
1366
|
+
systemPrompt: {
|
|
1373
1367
|
type: "string",
|
|
1374
|
-
title: "
|
|
1375
|
-
description:
|
|
1376
|
-
"x-ui-group": "Configuration"
|
|
1368
|
+
title: "System Prompt",
|
|
1369
|
+
description: "Optional system instructions for the model"
|
|
1377
1370
|
},
|
|
1378
1371
|
maxTokens: {
|
|
1379
1372
|
type: "number",
|
|
1380
1373
|
title: "Max Tokens",
|
|
1381
|
-
description: "
|
|
1374
|
+
description: "Per-turn token limit",
|
|
1382
1375
|
minimum: 1,
|
|
1383
1376
|
"x-ui-group": "Configuration"
|
|
1384
1377
|
},
|
|
1385
1378
|
temperature: {
|
|
1386
1379
|
type: "number",
|
|
1387
1380
|
title: "Temperature",
|
|
1388
|
-
description: "
|
|
1381
|
+
description: "Sampling temperature",
|
|
1389
1382
|
minimum: 0,
|
|
1390
1383
|
maximum: 2,
|
|
1391
1384
|
"x-ui-group": "Configuration"
|
|
1385
|
+
},
|
|
1386
|
+
maxIterations: {
|
|
1387
|
+
type: "number",
|
|
1388
|
+
title: "Max Iterations",
|
|
1389
|
+
description: "Safety cap on conversation turns",
|
|
1390
|
+
minimum: 1,
|
|
1391
|
+
default: 100,
|
|
1392
|
+
"x-ui-group": "Configuration"
|
|
1392
1393
|
}
|
|
1393
1394
|
},
|
|
1394
|
-
required: ["model", "prompt"
|
|
1395
|
+
required: ["model", "prompt"],
|
|
1395
1396
|
additionalProperties: false
|
|
1396
1397
|
};
|
|
1397
|
-
var
|
|
1398
|
+
var AiChatOutputSchema = {
|
|
1398
1399
|
type: "object",
|
|
1399
1400
|
properties: {
|
|
1400
1401
|
text: {
|
|
1401
1402
|
type: "string",
|
|
1402
1403
|
title: "Text",
|
|
1403
|
-
description: "
|
|
1404
|
+
description: "Last assistant response",
|
|
1404
1405
|
"x-stream": "append"
|
|
1405
1406
|
},
|
|
1406
|
-
|
|
1407
|
+
messages: {
|
|
1407
1408
|
type: "array",
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1409
|
+
title: "Messages",
|
|
1410
|
+
description: "Full conversation history",
|
|
1411
|
+
items: ChatMessageSchema,
|
|
1411
1412
|
"x-stream": "object"
|
|
1413
|
+
},
|
|
1414
|
+
iterations: {
|
|
1415
|
+
type: "number",
|
|
1416
|
+
title: "Iterations",
|
|
1417
|
+
description: "Number of completed turns"
|
|
1412
1418
|
}
|
|
1413
1419
|
},
|
|
1414
|
-
required: ["text", "
|
|
1420
|
+
required: ["text", "messages", "iterations"],
|
|
1415
1421
|
additionalProperties: false
|
|
1416
1422
|
};
|
|
1417
1423
|
|
|
1418
|
-
class
|
|
1419
|
-
static type = "
|
|
1420
|
-
static category = "AI
|
|
1421
|
-
static title = "
|
|
1422
|
-
static description = "
|
|
1424
|
+
class AiChatTask extends StreamingAiTask {
|
|
1425
|
+
static type = "AiChatTask";
|
|
1426
|
+
static category = "AI Chat";
|
|
1427
|
+
static title = "AI Chat";
|
|
1428
|
+
static description = "Multi-turn chat with a language model, using a human connector to collect user input between turns.";
|
|
1429
|
+
static cacheable = false;
|
|
1430
|
+
static configSchema() {
|
|
1431
|
+
return {
|
|
1432
|
+
type: "object",
|
|
1433
|
+
properties: {
|
|
1434
|
+
...TaskConfigSchema2["properties"]
|
|
1435
|
+
},
|
|
1436
|
+
additionalProperties: false
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1423
1439
|
static inputSchema() {
|
|
1424
|
-
return
|
|
1440
|
+
return AiChatInputSchema;
|
|
1425
1441
|
}
|
|
1426
1442
|
static outputSchema() {
|
|
1427
|
-
return
|
|
1443
|
+
return AiChatOutputSchema;
|
|
1428
1444
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1445
|
+
_sessionId;
|
|
1446
|
+
async getJobInput(input) {
|
|
1447
|
+
const model = input.model;
|
|
1448
|
+
if (!this._sessionId) {
|
|
1449
|
+
this._sessionId = getAiProviderRegistry().createSession(model.provider, model);
|
|
1450
|
+
}
|
|
1451
|
+
return {
|
|
1452
|
+
taskType: "AiChatTask",
|
|
1453
|
+
aiProvider: model.provider,
|
|
1454
|
+
taskInput: input,
|
|
1455
|
+
sessionId: this._sessionId
|
|
1456
|
+
};
|
|
1440
1457
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
|
-
if (!tool.execute) {
|
|
1463
|
-
getLogger3().warn(`AgentTask: Tool "${tool.name}" has type "function" but no execute function — will throw on invocation`);
|
|
1464
|
-
}
|
|
1465
|
-
const { execute, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1466
|
-
sources.push({
|
|
1467
|
-
type: "function",
|
|
1468
|
-
definition,
|
|
1469
|
-
run: execute ?? (async () => {
|
|
1470
|
-
throw new Error(`No execute function for tool "${tool.name}"`);
|
|
1471
|
-
})
|
|
1458
|
+
async* executeStream(input, context) {
|
|
1459
|
+
this._sessionId = undefined;
|
|
1460
|
+
const model = input.model;
|
|
1461
|
+
if (!model || typeof model !== "object") {
|
|
1462
|
+
throw new Error("AiChatTask: model was not resolved to ModelConfig");
|
|
1463
|
+
}
|
|
1464
|
+
const connector = resolveHumanConnector(context);
|
|
1465
|
+
const history = [];
|
|
1466
|
+
if (input.systemPrompt) {
|
|
1467
|
+
history.push({ role: "system", content: [{ type: "text", text: input.systemPrompt }] });
|
|
1468
|
+
}
|
|
1469
|
+
const firstUserBlocks = typeof input.prompt === "string" ? [{ type: "text", text: input.prompt }] : input.prompt;
|
|
1470
|
+
history.push({ role: "user", content: firstUserBlocks });
|
|
1471
|
+
const workingInput = { ...input, messages: history };
|
|
1472
|
+
await this.getJobInput(workingInput);
|
|
1473
|
+
const strategy = getAiProviderRegistry().getStrategy(model);
|
|
1474
|
+
const maxIterations = input.maxIterations ?? 100;
|
|
1475
|
+
if (context.resourceScope && this._sessionId) {
|
|
1476
|
+
const sessionId = this._sessionId;
|
|
1477
|
+
context.resourceScope.register(`ai:session:${sessionId}`, async () => {
|
|
1478
|
+
await getAiProviderRegistry().disposeSession(model.provider, sessionId);
|
|
1472
1479
|
});
|
|
1473
|
-
} else if (tool.type === "task") {
|
|
1474
|
-
const ctor = constructors.get(tool.name);
|
|
1475
|
-
if (!ctor) {
|
|
1476
|
-
getLogger3().warn(`AgentTask: Tool "${tool.name}" has type "task" but is not in TaskRegistry — will throw on invocation`);
|
|
1477
|
-
const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1478
|
-
sources.push({
|
|
1479
|
-
type: "function",
|
|
1480
|
-
definition,
|
|
1481
|
-
run: async () => {
|
|
1482
|
-
throw new Error(`Task "${tool.name}" not found in TaskRegistry`);
|
|
1483
|
-
}
|
|
1484
|
-
});
|
|
1485
|
-
} else {
|
|
1486
|
-
const safeConfig = resolveToolConfig(tool.name, tool.config, ctor.configSchema?.());
|
|
1487
|
-
const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1488
|
-
sources.push({
|
|
1489
|
-
type: "registry",
|
|
1490
|
-
definition,
|
|
1491
|
-
taskType: tool.name,
|
|
1492
|
-
config: safeConfig
|
|
1493
|
-
});
|
|
1494
|
-
}
|
|
1495
|
-
} else {
|
|
1496
|
-
const ctor = constructors.get(tool.name);
|
|
1497
|
-
if (ctor) {
|
|
1498
|
-
const safeConfig = resolveToolConfig(tool.name, tool.config, ctor.configSchema?.());
|
|
1499
|
-
const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1500
|
-
sources.push({
|
|
1501
|
-
type: "registry",
|
|
1502
|
-
definition,
|
|
1503
|
-
taskType: tool.name,
|
|
1504
|
-
config: safeConfig
|
|
1505
|
-
});
|
|
1506
|
-
} else {
|
|
1507
|
-
const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
|
|
1508
|
-
sources.push({
|
|
1509
|
-
type: "function",
|
|
1510
|
-
definition,
|
|
1511
|
-
run: async () => {
|
|
1512
|
-
throw new Error(`No executor registered for tool "${tool.name}"`);
|
|
1513
|
-
}
|
|
1514
|
-
});
|
|
1515
|
-
}
|
|
1516
1480
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
const source = findToolSource(sources, toolCall.name);
|
|
1522
|
-
if (!source) {
|
|
1523
|
-
getLogger3().warn(`AgentTask: Unknown tool "${toolCall.name}" — not found in tool sources`);
|
|
1524
|
-
return {
|
|
1525
|
-
toolCallId: toolCall.id,
|
|
1526
|
-
toolName: toolCall.name,
|
|
1527
|
-
output: { error: `Unknown tool: ${toolCall.name}` },
|
|
1528
|
-
isError: true
|
|
1481
|
+
yield {
|
|
1482
|
+
type: "object-delta",
|
|
1483
|
+
port: "messages",
|
|
1484
|
+
objectDelta: [...history]
|
|
1529
1485
|
};
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
}
|
|
1546
|
-
try {
|
|
1547
|
-
let output;
|
|
1548
|
-
switch (source.type) {
|
|
1549
|
-
case "registry": {
|
|
1550
|
-
const ctor = getTaskConstructors2(context.registry).get(source.taskType);
|
|
1551
|
-
if (!ctor) {
|
|
1552
|
-
throw new Error(`Task type "${source.taskType}" not found in TaskRegistry`);
|
|
1486
|
+
let iterations = 0;
|
|
1487
|
+
let lastAssistantText = "";
|
|
1488
|
+
for (let turn = 0;turn < maxIterations; turn++) {
|
|
1489
|
+
const perTurnInput = { ...input, messages: [...history] };
|
|
1490
|
+
const turnJobInput = await this.getJobInput(perTurnInput);
|
|
1491
|
+
let assistantText = "";
|
|
1492
|
+
for await (const event of strategy.executeStream(turnJobInput, context, this.runConfig.runnerId)) {
|
|
1493
|
+
if (event.type === "text-delta") {
|
|
1494
|
+
assistantText += event.textDelta;
|
|
1495
|
+
yield {
|
|
1496
|
+
...event,
|
|
1497
|
+
port: event.port ?? "text"
|
|
1498
|
+
};
|
|
1499
|
+
} else if (event.type === "finish") {} else {
|
|
1500
|
+
yield event;
|
|
1553
1501
|
}
|
|
1554
|
-
const taskConfig = source.config ?? {};
|
|
1555
|
-
const task = context.own(new ctor({}, taskConfig));
|
|
1556
|
-
output = await task.run(effectiveCall.input) ?? {};
|
|
1557
|
-
break;
|
|
1558
1502
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1503
|
+
iterations++;
|
|
1504
|
+
lastAssistantText = assistantText;
|
|
1505
|
+
const assistantMsg = {
|
|
1506
|
+
role: "assistant",
|
|
1507
|
+
content: [{ type: "text", text: assistantText }]
|
|
1508
|
+
};
|
|
1509
|
+
history.push(assistantMsg);
|
|
1510
|
+
yield {
|
|
1511
|
+
type: "object-delta",
|
|
1512
|
+
port: "messages",
|
|
1513
|
+
objectDelta: [assistantMsg]
|
|
1514
|
+
};
|
|
1515
|
+
const request = {
|
|
1516
|
+
requestId: crypto.randomUUID(),
|
|
1517
|
+
targetHumanId: "default",
|
|
1518
|
+
kind: "elicit",
|
|
1519
|
+
message: "",
|
|
1520
|
+
contentSchema: chatConnectorContentSchema,
|
|
1521
|
+
contentData: undefined,
|
|
1522
|
+
expectsResponse: true,
|
|
1523
|
+
mode: "multi-turn",
|
|
1524
|
+
metadata: { iteration: turn, taskId: this.id }
|
|
1525
|
+
};
|
|
1526
|
+
const response = await connector.send(request, context.signal);
|
|
1527
|
+
if (response.action === "cancel" || response.action === "decline")
|
|
1561
1528
|
break;
|
|
1529
|
+
const raw = response.content?.content;
|
|
1530
|
+
let userContent;
|
|
1531
|
+
if (typeof raw === "string") {
|
|
1532
|
+
const text = raw.trim();
|
|
1533
|
+
userContent = text.length > 0 ? [{ type: "text", text: raw }] : [];
|
|
1534
|
+
} else if (Array.isArray(raw)) {
|
|
1535
|
+
userContent = raw;
|
|
1536
|
+
} else {
|
|
1537
|
+
userContent = [];
|
|
1562
1538
|
}
|
|
1539
|
+
if (userContent.length === 0)
|
|
1540
|
+
break;
|
|
1541
|
+
const userMsg = { role: "user", content: userContent };
|
|
1542
|
+
history.push(userMsg);
|
|
1543
|
+
yield {
|
|
1544
|
+
type: "object-delta",
|
|
1545
|
+
port: "messages",
|
|
1546
|
+
objectDelta: [userMsg]
|
|
1547
|
+
};
|
|
1563
1548
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
if (hooks?.afterToolCall) {
|
|
1571
|
-
result = await hooks.afterToolCall(toolCall, result);
|
|
1572
|
-
}
|
|
1573
|
-
return result;
|
|
1574
|
-
} catch (err) {
|
|
1575
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
1576
|
-
if (hooks?.onToolError) {
|
|
1577
|
-
const action = await hooks.onToolError(toolCall, error);
|
|
1578
|
-
if (action.action === "result") {
|
|
1579
|
-
return {
|
|
1580
|
-
toolCallId: toolCall.id,
|
|
1581
|
-
toolName: toolCall.name,
|
|
1582
|
-
output: action.output,
|
|
1583
|
-
isError: false
|
|
1584
|
-
};
|
|
1549
|
+
yield {
|
|
1550
|
+
type: "finish",
|
|
1551
|
+
data: {
|
|
1552
|
+
text: lastAssistantText,
|
|
1553
|
+
messages: [...history],
|
|
1554
|
+
iterations
|
|
1585
1555
|
}
|
|
1586
|
-
}
|
|
1587
|
-
getLogger3().warn(`AgentTask: Tool "${toolCall.name}" failed: ${error.message}`);
|
|
1588
|
-
return {
|
|
1589
|
-
toolCallId: toolCall.id,
|
|
1590
|
-
toolName: toolCall.name,
|
|
1591
|
-
output: { error: error.message },
|
|
1592
|
-
isError: true
|
|
1593
1556
|
};
|
|
1594
1557
|
}
|
|
1595
|
-
}
|
|
1596
|
-
async function executeToolCalls(toolCalls, sources, context, hooks, maxConcurrency = 5) {
|
|
1597
|
-
const calls = toolCalls;
|
|
1598
|
-
if (calls.length === 0)
|
|
1599
|
-
return [];
|
|
1600
|
-
const concurrency = Math.max(1, Math.min(maxConcurrency, calls.length));
|
|
1601
|
-
const results = new Array(calls.length);
|
|
1602
|
-
let cursor = 0;
|
|
1603
|
-
const workers = Array.from({ length: concurrency }, async () => {
|
|
1604
|
-
while (true) {
|
|
1605
|
-
if (context.signal.aborted) {
|
|
1606
|
-
throw context.signal.reason ?? new TaskAbortedError("The operation was aborted");
|
|
1607
|
-
}
|
|
1608
|
-
const position = cursor;
|
|
1609
|
-
cursor += 1;
|
|
1610
|
-
if (position >= calls.length)
|
|
1611
|
-
return;
|
|
1612
|
-
results[position] = await executeToolCall(calls[position], sources, context, hooks);
|
|
1613
|
-
}
|
|
1614
|
-
});
|
|
1615
|
-
await Promise.all(workers);
|
|
1616
|
-
return results;
|
|
1617
|
-
}
|
|
1618
|
-
function hasToolCalls(toolCalls) {
|
|
1619
|
-
return toolCalls !== undefined && toolCalls.length > 0;
|
|
1620
|
-
}
|
|
1621
|
-
function countAssistantToolUses(messages) {
|
|
1622
|
-
let n = 0;
|
|
1623
|
-
for (const m of messages) {
|
|
1624
|
-
if (m.role !== "assistant")
|
|
1625
|
-
continue;
|
|
1626
|
-
for (const block of m.content) {
|
|
1627
|
-
if (block.type === "tool_use")
|
|
1628
|
-
n += 1;
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
return n;
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
// src/task/AgentTask.ts
|
|
1635
|
-
var MAX_CONTEXT_MESSAGES = 1000;
|
|
1636
|
-
var modelSchema2 = TypeModel("model:ToolCallingTask");
|
|
1637
|
-
var AgentInputSchema = {
|
|
1638
|
-
type: "object",
|
|
1639
|
-
properties: {
|
|
1640
|
-
model: modelSchema2,
|
|
1641
|
-
prompt: {
|
|
1642
|
-
oneOf: [
|
|
1643
|
-
{ type: "string" },
|
|
1644
|
-
{
|
|
1645
|
-
type: "array",
|
|
1646
|
-
items: {
|
|
1647
|
-
type: "object",
|
|
1648
|
-
properties: {
|
|
1649
|
-
type: { type: "string", enum: ["text", "image", "audio"] }
|
|
1650
|
-
},
|
|
1651
|
-
required: ["type"],
|
|
1652
|
-
additionalProperties: true
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
],
|
|
1656
|
-
title: "Prompt",
|
|
1657
|
-
description: "The user prompt to start the agent loop. Can be a string or an array of content blocks (text, image, audio)."
|
|
1658
|
-
},
|
|
1659
|
-
systemPrompt: {
|
|
1660
|
-
type: "string",
|
|
1661
|
-
title: "System Prompt",
|
|
1662
|
-
description: "Optional system instructions for the agent"
|
|
1663
|
-
},
|
|
1664
|
-
tools: {
|
|
1665
|
-
type: "array",
|
|
1666
|
-
format: "tasks",
|
|
1667
|
-
title: "Tools",
|
|
1668
|
-
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.",
|
|
1669
|
-
items: {
|
|
1670
|
-
oneOf: [
|
|
1671
|
-
{ type: "string", format: "tasks", description: "Task type name" },
|
|
1672
|
-
ToolDefinitionSchema
|
|
1673
|
-
]
|
|
1674
|
-
}
|
|
1675
|
-
},
|
|
1676
|
-
stopTool: {
|
|
1677
|
-
type: "string",
|
|
1678
|
-
title: "Stop Tool",
|
|
1679
|
-
description: "Name of a tool that signals agent completion. When called, the loop ends and the tool input becomes structuredOutput.",
|
|
1680
|
-
"x-ui-group": "Configuration"
|
|
1681
|
-
},
|
|
1682
|
-
maxIterations: {
|
|
1683
|
-
type: "number",
|
|
1684
|
-
title: "Max Iterations",
|
|
1685
|
-
description: "Maximum number of agent loop iterations (default: 10)",
|
|
1686
|
-
minimum: 1,
|
|
1687
|
-
"x-ui-group": "Configuration"
|
|
1688
|
-
},
|
|
1689
|
-
maxContextMessages: {
|
|
1690
|
-
type: "number",
|
|
1691
|
-
title: "Max Context Messages",
|
|
1692
|
-
description: "Maximum messages in conversation history. Older messages are trimmed to prevent context overflow.",
|
|
1693
|
-
minimum: 3,
|
|
1694
|
-
"x-ui-group": "Configuration"
|
|
1695
|
-
},
|
|
1696
|
-
maxTokens: {
|
|
1697
|
-
type: "number",
|
|
1698
|
-
title: "Max Tokens",
|
|
1699
|
-
description: "Maximum tokens per LLM call",
|
|
1700
|
-
minimum: 1,
|
|
1701
|
-
"x-ui-group": "Configuration"
|
|
1702
|
-
},
|
|
1703
|
-
temperature: {
|
|
1704
|
-
type: "number",
|
|
1705
|
-
title: "Temperature",
|
|
1706
|
-
description: "Sampling temperature for LLM calls",
|
|
1707
|
-
minimum: 0,
|
|
1708
|
-
maximum: 2,
|
|
1709
|
-
"x-ui-group": "Configuration"
|
|
1710
|
-
}
|
|
1711
|
-
},
|
|
1712
|
-
required: ["model", "prompt"],
|
|
1713
|
-
additionalProperties: false
|
|
1714
|
-
};
|
|
1715
|
-
var AgentOutputSchema = {
|
|
1716
|
-
type: "object",
|
|
1717
|
-
properties: {
|
|
1718
|
-
text: {
|
|
1719
|
-
type: "string",
|
|
1720
|
-
title: "Text",
|
|
1721
|
-
description: "The final text response from the agent",
|
|
1722
|
-
"x-stream": "append"
|
|
1723
|
-
},
|
|
1724
|
-
messages: {
|
|
1725
|
-
type: "array",
|
|
1726
|
-
title: "Messages",
|
|
1727
|
-
description: "Full conversation history including all tool calls and results",
|
|
1728
|
-
items: {
|
|
1729
|
-
type: "object",
|
|
1730
|
-
additionalProperties: true
|
|
1731
|
-
}
|
|
1732
|
-
},
|
|
1733
|
-
iterations: {
|
|
1734
|
-
type: "number",
|
|
1735
|
-
title: "Iterations",
|
|
1736
|
-
description: "Number of LLM calls made during the agent loop"
|
|
1737
|
-
},
|
|
1738
|
-
toolCallCount: {
|
|
1739
|
-
type: "number",
|
|
1740
|
-
title: "Tool Call Count",
|
|
1741
|
-
description: "Total number of tool calls the assistant requested (tool_use blocks in assistant messages)"
|
|
1742
|
-
},
|
|
1743
|
-
structuredOutput: {
|
|
1744
|
-
type: "object",
|
|
1745
|
-
title: "Structured Output",
|
|
1746
|
-
description: "Present when the agent terminated via a stop tool",
|
|
1747
|
-
additionalProperties: true
|
|
1748
|
-
}
|
|
1749
|
-
},
|
|
1750
|
-
required: ["text", "messages", "iterations", "toolCallCount"],
|
|
1751
|
-
additionalProperties: false
|
|
1752
|
-
};
|
|
1753
|
-
|
|
1754
|
-
class AgentTask extends Task2 {
|
|
1755
|
-
static type = "AgentTask";
|
|
1756
|
-
static category = "AI Agent";
|
|
1757
|
-
static title = "Agent";
|
|
1758
|
-
static description = "Multi-turn agentic loop that calls an LLM with tools, executes tool calls, and iterates until done";
|
|
1759
|
-
static cacheable = false;
|
|
1760
|
-
static inputSchema() {
|
|
1761
|
-
return AgentInputSchema;
|
|
1762
|
-
}
|
|
1763
|
-
static outputSchema() {
|
|
1764
|
-
return AgentOutputSchema;
|
|
1765
|
-
}
|
|
1766
1558
|
async execute(input, context) {
|
|
1767
1559
|
let result;
|
|
1768
|
-
for await (const event of this.
|
|
1560
|
+
for await (const event of this.executeStream(input, context)) {
|
|
1769
1561
|
if (event.type === "finish") {
|
|
1770
1562
|
result = event.data;
|
|
1771
1563
|
}
|
|
1772
1564
|
}
|
|
1773
|
-
if (!result) {
|
|
1774
|
-
throw new Error("AgentTask: loop ended without producing output");
|
|
1775
|
-
}
|
|
1776
1565
|
return result;
|
|
1777
1566
|
}
|
|
1778
|
-
async* executeStream(input, context) {
|
|
1779
|
-
yield* this.agentLoop(input, context);
|
|
1780
|
-
}
|
|
1781
|
-
async* agentLoop(input, context) {
|
|
1782
|
-
const maxIterations = input.maxIterations ?? 10;
|
|
1783
|
-
const hooks = this.config.hooks;
|
|
1784
|
-
const maxConcurrency = this.config.maxConcurrency ?? 5;
|
|
1785
|
-
const toolSources = this.resolveToolSources(input, context);
|
|
1786
|
-
const toolDefs = this.resolveToolDefs(toolSources, input.stopTool);
|
|
1787
|
-
const messages = [userMessage(input.prompt)];
|
|
1788
|
-
let finalText = "";
|
|
1789
|
-
let structuredOutput;
|
|
1790
|
-
for (let iteration = 0;iteration < maxIterations; iteration++) {
|
|
1791
|
-
if (context.signal.aborted)
|
|
1792
|
-
break;
|
|
1793
|
-
if (hooks?.onIteration) {
|
|
1794
|
-
const action = await hooks.onIteration(iteration, messages, {
|
|
1795
|
-
totalToolCalls: countAssistantToolUses(messages)
|
|
1796
|
-
});
|
|
1797
|
-
if (action.action === "stop")
|
|
1798
|
-
break;
|
|
1799
|
-
}
|
|
1800
|
-
await context.updateProgress(Math.round(iteration / maxIterations * 100), `Agent iteration ${iteration + 1}`);
|
|
1801
|
-
const contextMessages = this.trimMessages(messages, input.maxContextMessages ?? MAX_CONTEXT_MESSAGES);
|
|
1802
|
-
const llmTask = context.own(new ToolCallingTask);
|
|
1803
|
-
let iterationText = "";
|
|
1804
|
-
let toolCalls = [];
|
|
1805
|
-
for await (const event of llmTask.executeStream({
|
|
1806
|
-
model: input.model,
|
|
1807
|
-
prompt: input.prompt,
|
|
1808
|
-
systemPrompt: input.systemPrompt,
|
|
1809
|
-
tools: toolDefs,
|
|
1810
|
-
messages: contextMessages,
|
|
1811
|
-
maxTokens: input.maxTokens,
|
|
1812
|
-
temperature: input.temperature
|
|
1813
|
-
}, context)) {
|
|
1814
|
-
if (event.type === "text-delta") {
|
|
1815
|
-
yield { type: "text-delta", port: "text", textDelta: event.textDelta };
|
|
1816
|
-
iterationText += event.textDelta;
|
|
1817
|
-
} else if (event.type === "object-delta" && event.port === "toolCalls") {
|
|
1818
|
-
const items = event.objectDelta;
|
|
1819
|
-
for (const item of items) {
|
|
1820
|
-
const idx = toolCalls.findIndex((tc) => tc.id === item.id);
|
|
1821
|
-
if (idx >= 0)
|
|
1822
|
-
toolCalls[idx] = item;
|
|
1823
|
-
else
|
|
1824
|
-
toolCalls.push(item);
|
|
1825
|
-
}
|
|
1826
|
-
} else if (event.type === "finish") {
|
|
1827
|
-
const data = event.data;
|
|
1828
|
-
iterationText = data?.text ?? iterationText;
|
|
1829
|
-
if (data?.toolCalls && data.toolCalls.length > 0) {
|
|
1830
|
-
toolCalls = data.toolCalls;
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
finalText = iterationText;
|
|
1835
|
-
messages.push(assistantMessage(iterationText, toolCalls));
|
|
1836
|
-
if (input.stopTool) {
|
|
1837
|
-
const stopCall = toolCalls.find((tc) => tc.name === input.stopTool);
|
|
1838
|
-
if (stopCall) {
|
|
1839
|
-
structuredOutput = stopCall.input;
|
|
1840
|
-
break;
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
if (!hasToolCalls(toolCalls)) {
|
|
1844
|
-
break;
|
|
1845
|
-
}
|
|
1846
|
-
const results = await executeToolCalls(toolCalls, toolSources, context, hooks, maxConcurrency);
|
|
1847
|
-
messages.push(toolMessage(results));
|
|
1848
|
-
}
|
|
1849
|
-
const output = {
|
|
1850
|
-
text: finalText,
|
|
1851
|
-
messages,
|
|
1852
|
-
iterations: messages.filter((m) => m.role === "assistant").length,
|
|
1853
|
-
toolCallCount: countAssistantToolUses(messages),
|
|
1854
|
-
...structuredOutput !== undefined ? { structuredOutput } : {}
|
|
1855
|
-
};
|
|
1856
|
-
yield { type: "finish", data: output };
|
|
1857
|
-
}
|
|
1858
|
-
resolveToolSources(input, context) {
|
|
1859
|
-
return buildToolSources(input.tools, context.registry);
|
|
1860
|
-
}
|
|
1861
|
-
resolveToolDefs(toolSources, stopTool) {
|
|
1862
|
-
const defs = toolSourceDefinitions(toolSources);
|
|
1863
|
-
if (stopTool && !defs.some((d) => d.name === stopTool)) {
|
|
1864
|
-
defs.push({
|
|
1865
|
-
name: stopTool,
|
|
1866
|
-
description: "Call this tool when you have completed the task. Pass your final structured result as the input.",
|
|
1867
|
-
inputSchema: { type: "object", additionalProperties: true }
|
|
1868
|
-
});
|
|
1869
|
-
}
|
|
1870
|
-
return defs;
|
|
1871
|
-
}
|
|
1872
|
-
trimMessages(messages, maxContextMessages) {
|
|
1873
|
-
if (!maxContextMessages || messages.length <= maxContextMessages) {
|
|
1874
|
-
return messages;
|
|
1875
|
-
}
|
|
1876
|
-
getLogger4().debug(`AgentTask: Trimming context from ${messages.length} to ${maxContextMessages} messages`);
|
|
1877
|
-
const tail = messages.slice(1);
|
|
1878
|
-
let startIdx = tail.length - (maxContextMessages - 1);
|
|
1879
|
-
if (startIdx < 0)
|
|
1880
|
-
startIdx = 0;
|
|
1881
|
-
while (startIdx > 0 && startIdx < tail.length && tail[startIdx].role === "tool") {
|
|
1882
|
-
startIdx -= 1;
|
|
1883
|
-
}
|
|
1884
|
-
return [messages[0], ...tail.slice(startIdx)];
|
|
1885
|
-
}
|
|
1886
1567
|
}
|
|
1887
|
-
var agent = (input, config) => {
|
|
1888
|
-
return new AgentTask(config).run(input);
|
|
1889
|
-
};
|
|
1890
|
-
Workflow2.prototype.agent = CreateWorkflow2(AgentTask);
|
|
1891
1568
|
|
|
1892
1569
|
// src/task/BackgroundRemovalTask.ts
|
|
1893
|
-
import { CreateWorkflow
|
|
1570
|
+
import { CreateWorkflow, Workflow } from "@workglow/task-graph";
|
|
1894
1571
|
|
|
1895
1572
|
// src/task/base/AiVisionTask.ts
|
|
1896
1573
|
import { convertImageDataToUseableForm } from "@workglow/util/media";
|
|
@@ -1914,7 +1591,7 @@ class AiVisionTask extends AiTask {
|
|
|
1914
1591
|
}
|
|
1915
1592
|
|
|
1916
1593
|
// src/task/BackgroundRemovalTask.ts
|
|
1917
|
-
var
|
|
1594
|
+
var modelSchema2 = TypeModel("model:BackgroundRemovalTask");
|
|
1918
1595
|
var processedImageSchema = {
|
|
1919
1596
|
type: "string",
|
|
1920
1597
|
contentEncoding: "base64",
|
|
@@ -1926,7 +1603,7 @@ var BackgroundRemovalInputSchema = {
|
|
|
1926
1603
|
type: "object",
|
|
1927
1604
|
properties: {
|
|
1928
1605
|
image: TypeImageInput,
|
|
1929
|
-
model:
|
|
1606
|
+
model: modelSchema2
|
|
1930
1607
|
},
|
|
1931
1608
|
required: ["image", "model"],
|
|
1932
1609
|
additionalProperties: false
|
|
@@ -1955,22 +1632,22 @@ class BackgroundRemovalTask extends AiVisionTask {
|
|
|
1955
1632
|
var backgroundRemoval = (input, config) => {
|
|
1956
1633
|
return new BackgroundRemovalTask(config).run(input);
|
|
1957
1634
|
};
|
|
1958
|
-
|
|
1635
|
+
Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
|
|
1959
1636
|
|
|
1960
1637
|
// src/task/ChunkRetrievalTask.ts
|
|
1961
1638
|
import { TypeKnowledgeBase } from "@workglow/knowledge-base";
|
|
1962
|
-
import { CreateWorkflow as
|
|
1639
|
+
import { CreateWorkflow as CreateWorkflow3, Task as Task2, Workflow as Workflow3 } from "@workglow/task-graph";
|
|
1963
1640
|
import {
|
|
1964
1641
|
isTypedArray,
|
|
1965
1642
|
TypedArraySchema as TypedArraySchema2
|
|
1966
1643
|
} from "@workglow/util/schema";
|
|
1967
1644
|
|
|
1968
1645
|
// src/task/TextEmbeddingTask.ts
|
|
1969
|
-
import { CreateWorkflow as
|
|
1646
|
+
import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
|
|
1970
1647
|
import {
|
|
1971
1648
|
TypedArraySchema
|
|
1972
1649
|
} from "@workglow/util/schema";
|
|
1973
|
-
var
|
|
1650
|
+
var modelSchema3 = TypeModel("model:TextEmbeddingTask");
|
|
1974
1651
|
var TextEmbeddingInputSchema = {
|
|
1975
1652
|
type: "object",
|
|
1976
1653
|
properties: {
|
|
@@ -1979,7 +1656,7 @@ var TextEmbeddingInputSchema = {
|
|
|
1979
1656
|
title: "Text",
|
|
1980
1657
|
description: "The text to embed"
|
|
1981
1658
|
}),
|
|
1982
|
-
model:
|
|
1659
|
+
model: modelSchema3
|
|
1983
1660
|
},
|
|
1984
1661
|
required: ["text", "model"],
|
|
1985
1662
|
additionalProperties: false
|
|
@@ -2011,7 +1688,7 @@ class TextEmbeddingTask extends AiTask {
|
|
|
2011
1688
|
var textEmbedding = async (input, config) => {
|
|
2012
1689
|
return new TextEmbeddingTask(config).run(input);
|
|
2013
1690
|
};
|
|
2014
|
-
|
|
1691
|
+
Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
|
|
2015
1692
|
|
|
2016
1693
|
// src/task/ChunkRetrievalTask.ts
|
|
2017
1694
|
var inputSchema = {
|
|
@@ -2136,7 +1813,7 @@ var outputSchema = {
|
|
|
2136
1813
|
additionalProperties: false
|
|
2137
1814
|
};
|
|
2138
1815
|
|
|
2139
|
-
class ChunkRetrievalTask extends
|
|
1816
|
+
class ChunkRetrievalTask extends Task2 {
|
|
2140
1817
|
static type = "ChunkRetrievalTask";
|
|
2141
1818
|
static category = "RAG";
|
|
2142
1819
|
static title = "Chunk Retrieval";
|
|
@@ -2203,11 +1880,11 @@ class ChunkRetrievalTask extends Task3 {
|
|
|
2203
1880
|
var chunkRetrieval = (input, config) => {
|
|
2204
1881
|
return new ChunkRetrievalTask(config).run(input);
|
|
2205
1882
|
};
|
|
2206
|
-
|
|
1883
|
+
Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
|
|
2207
1884
|
|
|
2208
1885
|
// src/task/ChunkToVectorTask.ts
|
|
2209
1886
|
import { ChunkRecordSchema } from "@workglow/knowledge-base";
|
|
2210
|
-
import { CreateWorkflow as
|
|
1887
|
+
import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
|
|
2211
1888
|
import {
|
|
2212
1889
|
TypedArraySchema as TypedArraySchema3
|
|
2213
1890
|
} from "@workglow/util/schema";
|
|
@@ -2282,7 +1959,7 @@ var outputSchema2 = {
|
|
|
2282
1959
|
additionalProperties: false
|
|
2283
1960
|
};
|
|
2284
1961
|
|
|
2285
|
-
class ChunkToVectorTask extends
|
|
1962
|
+
class ChunkToVectorTask extends Task3 {
|
|
2286
1963
|
static type = "ChunkToVectorTask";
|
|
2287
1964
|
static category = "Document";
|
|
2288
1965
|
static title = "Chunk to Vector";
|
|
@@ -2333,11 +2010,11 @@ class ChunkToVectorTask extends Task4 {
|
|
|
2333
2010
|
var chunkToVector = (input, config) => {
|
|
2334
2011
|
return new ChunkToVectorTask(config).run(input);
|
|
2335
2012
|
};
|
|
2336
|
-
|
|
2013
|
+
Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
|
|
2337
2014
|
|
|
2338
2015
|
// src/task/ChunkVectorHybridSearchTask.ts
|
|
2339
2016
|
import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
|
|
2340
|
-
import { CreateWorkflow as
|
|
2017
|
+
import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
|
|
2341
2018
|
import {
|
|
2342
2019
|
TypedArraySchema as TypedArraySchema4
|
|
2343
2020
|
} from "@workglow/util/schema";
|
|
@@ -2450,7 +2127,7 @@ var outputSchema3 = {
|
|
|
2450
2127
|
additionalProperties: false
|
|
2451
2128
|
};
|
|
2452
2129
|
|
|
2453
|
-
class ChunkVectorHybridSearchTask extends
|
|
2130
|
+
class ChunkVectorHybridSearchTask extends Task4 {
|
|
2454
2131
|
static type = "ChunkVectorHybridSearchTask";
|
|
2455
2132
|
static category = "RAG";
|
|
2456
2133
|
static title = "Hybrid Search";
|
|
@@ -2503,11 +2180,11 @@ class ChunkVectorHybridSearchTask extends Task5 {
|
|
|
2503
2180
|
var hybridSearch = async (input, config) => {
|
|
2504
2181
|
return new ChunkVectorHybridSearchTask(config).run(input);
|
|
2505
2182
|
};
|
|
2506
|
-
|
|
2183
|
+
Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
|
|
2507
2184
|
|
|
2508
2185
|
// src/task/ChunkVectorSearchTask.ts
|
|
2509
2186
|
import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
|
|
2510
|
-
import { CreateWorkflow as
|
|
2187
|
+
import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
|
|
2511
2188
|
import {
|
|
2512
2189
|
TypedArraySchema as TypedArraySchema5
|
|
2513
2190
|
} from "@workglow/util/schema";
|
|
@@ -2590,7 +2267,7 @@ var outputSchema4 = {
|
|
|
2590
2267
|
additionalProperties: false
|
|
2591
2268
|
};
|
|
2592
2269
|
|
|
2593
|
-
class ChunkVectorSearchTask extends
|
|
2270
|
+
class ChunkVectorSearchTask extends Task5 {
|
|
2594
2271
|
static type = "ChunkVectorSearchTask";
|
|
2595
2272
|
static category = "Vector Store";
|
|
2596
2273
|
static title = "Vector Store Search";
|
|
@@ -2622,11 +2299,11 @@ class ChunkVectorSearchTask extends Task6 {
|
|
|
2622
2299
|
var vectorStoreSearch = (input, config) => {
|
|
2623
2300
|
return new ChunkVectorSearchTask(config).run(input);
|
|
2624
2301
|
};
|
|
2625
|
-
|
|
2302
|
+
Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
|
|
2626
2303
|
|
|
2627
2304
|
// src/task/ChunkVectorUpsertTask.ts
|
|
2628
2305
|
import { TypeKnowledgeBase as TypeKnowledgeBase4 } from "@workglow/knowledge-base";
|
|
2629
|
-
import { CreateWorkflow as
|
|
2306
|
+
import { CreateWorkflow as CreateWorkflow7, Task as Task6, Workflow as Workflow7 } from "@workglow/task-graph";
|
|
2630
2307
|
import {
|
|
2631
2308
|
TypedArraySchema as TypedArraySchema6
|
|
2632
2309
|
} from "@workglow/util/schema";
|
|
@@ -2680,7 +2357,7 @@ var outputSchema5 = {
|
|
|
2680
2357
|
additionalProperties: false
|
|
2681
2358
|
};
|
|
2682
2359
|
|
|
2683
|
-
class ChunkVectorUpsertTask extends
|
|
2360
|
+
class ChunkVectorUpsertTask extends Task6 {
|
|
2684
2361
|
static type = "ChunkVectorUpsertTask";
|
|
2685
2362
|
static category = "Vector Store";
|
|
2686
2363
|
static title = "Add to Vector Store";
|
|
@@ -2740,15 +2417,15 @@ class ChunkVectorUpsertTask extends Task7 {
|
|
|
2740
2417
|
var chunkVectorUpsert = (input, config) => {
|
|
2741
2418
|
return new ChunkVectorUpsertTask(config).run(input);
|
|
2742
2419
|
};
|
|
2743
|
-
|
|
2420
|
+
Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
|
|
2744
2421
|
|
|
2745
2422
|
// src/task/ContextBuilderTask.ts
|
|
2746
2423
|
import { estimateTokens } from "@workglow/knowledge-base";
|
|
2747
|
-
import { CreateWorkflow as
|
|
2424
|
+
import { CreateWorkflow as CreateWorkflow9, Task as Task7, Workflow as Workflow9 } from "@workglow/task-graph";
|
|
2748
2425
|
|
|
2749
2426
|
// src/task/CountTokensTask.ts
|
|
2750
|
-
import { CreateWorkflow as
|
|
2751
|
-
var
|
|
2427
|
+
import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
|
|
2428
|
+
var modelSchema4 = TypeModel("model");
|
|
2752
2429
|
var CountTokensInputSchema = {
|
|
2753
2430
|
type: "object",
|
|
2754
2431
|
properties: {
|
|
@@ -2757,7 +2434,7 @@ var CountTokensInputSchema = {
|
|
|
2757
2434
|
title: "Text",
|
|
2758
2435
|
description: "The text to count tokens for"
|
|
2759
2436
|
},
|
|
2760
|
-
model:
|
|
2437
|
+
model: modelSchema4
|
|
2761
2438
|
},
|
|
2762
2439
|
required: ["text", "model"],
|
|
2763
2440
|
additionalProperties: false
|
|
@@ -2791,7 +2468,7 @@ class CountTokensTask extends AiTask {
|
|
|
2791
2468
|
var countTokens = async (input, config) => {
|
|
2792
2469
|
return new CountTokensTask(config).run(input);
|
|
2793
2470
|
};
|
|
2794
|
-
|
|
2471
|
+
Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
|
|
2795
2472
|
|
|
2796
2473
|
// src/task/ContextBuilderTask.ts
|
|
2797
2474
|
var ContextFormat = {
|
|
@@ -2801,7 +2478,7 @@ var ContextFormat = {
|
|
|
2801
2478
|
MARKDOWN: "markdown",
|
|
2802
2479
|
JSON: "json"
|
|
2803
2480
|
};
|
|
2804
|
-
var
|
|
2481
|
+
var modelSchema5 = TypeModel("model", {
|
|
2805
2482
|
title: "Model",
|
|
2806
2483
|
description: "Model to use for token counting (optional, falls back to estimation)"
|
|
2807
2484
|
});
|
|
@@ -2865,7 +2542,7 @@ var inputSchema6 = {
|
|
|
2865
2542
|
|
|
2866
2543
|
`
|
|
2867
2544
|
},
|
|
2868
|
-
model:
|
|
2545
|
+
model: modelSchema5
|
|
2869
2546
|
},
|
|
2870
2547
|
required: ["chunks"],
|
|
2871
2548
|
additionalProperties: false
|
|
@@ -2898,7 +2575,7 @@ var outputSchema6 = {
|
|
|
2898
2575
|
additionalProperties: false
|
|
2899
2576
|
};
|
|
2900
2577
|
|
|
2901
|
-
class ContextBuilderTask extends
|
|
2578
|
+
class ContextBuilderTask extends Task7 {
|
|
2902
2579
|
static type = "ContextBuilderTask";
|
|
2903
2580
|
static category = "RAG";
|
|
2904
2581
|
static title = "Context Builder";
|
|
@@ -3091,15 +2768,15 @@ class ContextBuilderTask extends Task8 {
|
|
|
3091
2768
|
var contextBuilder = (input, config) => {
|
|
3092
2769
|
return new ContextBuilderTask(config).run(input);
|
|
3093
2770
|
};
|
|
3094
|
-
|
|
2771
|
+
Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
|
|
3095
2772
|
|
|
3096
2773
|
// src/task/DocumentEnricherTask.ts
|
|
3097
2774
|
import { getChildren, hasChildren } from "@workglow/knowledge-base";
|
|
3098
|
-
import { CreateWorkflow as
|
|
2775
|
+
import { CreateWorkflow as CreateWorkflow12, Task as Task8, Workflow as Workflow12 } from "@workglow/task-graph";
|
|
3099
2776
|
|
|
3100
2777
|
// src/task/TextNamedEntityRecognitionTask.ts
|
|
3101
|
-
import { CreateWorkflow as
|
|
3102
|
-
var
|
|
2778
|
+
import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
|
|
2779
|
+
var modelSchema6 = TypeModel("model:TextNamedEntityRecognitionTask");
|
|
3103
2780
|
var TextNamedEntityRecognitionInputSchema = {
|
|
3104
2781
|
type: "object",
|
|
3105
2782
|
properties: {
|
|
@@ -3118,7 +2795,7 @@ var TextNamedEntityRecognitionInputSchema = {
|
|
|
3118
2795
|
"x-ui-group": "Configuration",
|
|
3119
2796
|
"x-ui-group-open": false
|
|
3120
2797
|
},
|
|
3121
|
-
model:
|
|
2798
|
+
model: modelSchema6
|
|
3122
2799
|
},
|
|
3123
2800
|
required: ["text", "model"],
|
|
3124
2801
|
additionalProperties: false
|
|
@@ -3173,11 +2850,11 @@ class TextNamedEntityRecognitionTask extends AiTask {
|
|
|
3173
2850
|
var textNamedEntityRecognition = (input, config) => {
|
|
3174
2851
|
return new TextNamedEntityRecognitionTask(config).run(input);
|
|
3175
2852
|
};
|
|
3176
|
-
|
|
2853
|
+
Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
|
|
3177
2854
|
|
|
3178
2855
|
// src/task/TextSummaryTask.ts
|
|
3179
|
-
import { CreateWorkflow as
|
|
3180
|
-
var
|
|
2856
|
+
import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
|
|
2857
|
+
var modelSchema7 = TypeModel("model:TextSummaryTask");
|
|
3181
2858
|
var TextSummaryInputSchema = {
|
|
3182
2859
|
type: "object",
|
|
3183
2860
|
properties: {
|
|
@@ -3186,7 +2863,7 @@ var TextSummaryInputSchema = {
|
|
|
3186
2863
|
title: "Text",
|
|
3187
2864
|
description: "The text to summarize"
|
|
3188
2865
|
},
|
|
3189
|
-
model:
|
|
2866
|
+
model: modelSchema7
|
|
3190
2867
|
},
|
|
3191
2868
|
required: ["text", "model"],
|
|
3192
2869
|
additionalProperties: false
|
|
@@ -3220,7 +2897,7 @@ class TextSummaryTask extends StreamingAiTask {
|
|
|
3220
2897
|
var textSummary = async (input, config) => {
|
|
3221
2898
|
return new TextSummaryTask(config).run(input);
|
|
3222
2899
|
};
|
|
3223
|
-
|
|
2900
|
+
Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
|
|
3224
2901
|
|
|
3225
2902
|
// src/task/DocumentEnricherTask.ts
|
|
3226
2903
|
var inputSchema7 = {
|
|
@@ -3294,7 +2971,7 @@ var outputSchema7 = {
|
|
|
3294
2971
|
additionalProperties: false
|
|
3295
2972
|
};
|
|
3296
2973
|
|
|
3297
|
-
class DocumentEnricherTask extends
|
|
2974
|
+
class DocumentEnricherTask extends Task8 {
|
|
3298
2975
|
static type = "DocumentEnricherTask";
|
|
3299
2976
|
static category = "Document";
|
|
3300
2977
|
static title = "Document Enricher";
|
|
@@ -3453,12 +3130,12 @@ class DocumentEnricherTask extends Task9 {
|
|
|
3453
3130
|
var documentEnricher = (input, config) => {
|
|
3454
3131
|
return new DocumentEnricherTask(config).run(input);
|
|
3455
3132
|
};
|
|
3456
|
-
|
|
3133
|
+
Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
|
|
3457
3134
|
|
|
3458
3135
|
// src/task/DocumentUpsertTask.ts
|
|
3459
3136
|
import { Document, TypeKnowledgeBase as TypeKnowledgeBase5 } from "@workglow/knowledge-base";
|
|
3460
3137
|
import { DocumentMetadataSchema } from "@workglow/knowledge-base";
|
|
3461
|
-
import { CreateWorkflow as
|
|
3138
|
+
import { CreateWorkflow as CreateWorkflow13, Task as Task9, Workflow as Workflow13 } from "@workglow/task-graph";
|
|
3462
3139
|
var inputSchema8 = {
|
|
3463
3140
|
type: "object",
|
|
3464
3141
|
properties: {
|
|
@@ -3503,7 +3180,7 @@ var outputSchema8 = {
|
|
|
3503
3180
|
additionalProperties: false
|
|
3504
3181
|
};
|
|
3505
3182
|
|
|
3506
|
-
class DocumentUpsertTask extends
|
|
3183
|
+
class DocumentUpsertTask extends Task9 {
|
|
3507
3184
|
static type = "DocumentUpsertTask";
|
|
3508
3185
|
static category = "Vector Store";
|
|
3509
3186
|
static title = "Add Document";
|
|
@@ -3536,15 +3213,15 @@ class DocumentUpsertTask extends Task10 {
|
|
|
3536
3213
|
var documentUpsert = (input, config) => {
|
|
3537
3214
|
return new DocumentUpsertTask(config).run(input);
|
|
3538
3215
|
};
|
|
3539
|
-
|
|
3216
|
+
Workflow13.prototype.documentUpsert = CreateWorkflow13(DocumentUpsertTask);
|
|
3540
3217
|
|
|
3541
3218
|
// src/task/DownloadModelTask.ts
|
|
3542
|
-
import { CreateWorkflow as
|
|
3543
|
-
var
|
|
3219
|
+
import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
|
|
3220
|
+
var modelSchema8 = TypeModel("model");
|
|
3544
3221
|
var DownloadModelInputSchema = {
|
|
3545
3222
|
type: "object",
|
|
3546
3223
|
properties: {
|
|
3547
|
-
model:
|
|
3224
|
+
model: modelSchema8
|
|
3548
3225
|
},
|
|
3549
3226
|
required: ["model"],
|
|
3550
3227
|
additionalProperties: false
|
|
@@ -3552,7 +3229,7 @@ var DownloadModelInputSchema = {
|
|
|
3552
3229
|
var DownloadModelOutputSchema = {
|
|
3553
3230
|
type: "object",
|
|
3554
3231
|
properties: {
|
|
3555
|
-
model:
|
|
3232
|
+
model: modelSchema8
|
|
3556
3233
|
},
|
|
3557
3234
|
required: ["model"],
|
|
3558
3235
|
additionalProperties: false
|
|
@@ -3606,11 +3283,11 @@ class DownloadModelTask extends AiTask {
|
|
|
3606
3283
|
var downloadModel = (input, config) => {
|
|
3607
3284
|
return new DownloadModelTask(config).run(input);
|
|
3608
3285
|
};
|
|
3609
|
-
|
|
3286
|
+
Workflow14.prototype.downloadModel = CreateWorkflow14(DownloadModelTask);
|
|
3610
3287
|
|
|
3611
3288
|
// src/task/FaceDetectorTask.ts
|
|
3612
|
-
import { CreateWorkflow as
|
|
3613
|
-
var
|
|
3289
|
+
import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
|
|
3290
|
+
var modelSchema9 = TypeModel("model:FaceDetectorTask");
|
|
3614
3291
|
var TypeBoundingBox2 = {
|
|
3615
3292
|
type: "object",
|
|
3616
3293
|
properties: {
|
|
@@ -3683,7 +3360,7 @@ var FaceDetectorInputSchema = {
|
|
|
3683
3360
|
type: "object",
|
|
3684
3361
|
properties: {
|
|
3685
3362
|
image: TypeImageInput,
|
|
3686
|
-
model:
|
|
3363
|
+
model: modelSchema9,
|
|
3687
3364
|
minDetectionConfidence: {
|
|
3688
3365
|
type: "number",
|
|
3689
3366
|
minimum: 0,
|
|
@@ -3737,11 +3414,11 @@ class FaceDetectorTask extends AiVisionTask {
|
|
|
3737
3414
|
var faceDetector = (input, config) => {
|
|
3738
3415
|
return new FaceDetectorTask(config).run(input);
|
|
3739
3416
|
};
|
|
3740
|
-
|
|
3417
|
+
Workflow15.prototype.faceDetector = CreateWorkflow15(FaceDetectorTask);
|
|
3741
3418
|
|
|
3742
3419
|
// src/task/FaceLandmarkerTask.ts
|
|
3743
|
-
import { CreateWorkflow as
|
|
3744
|
-
var
|
|
3420
|
+
import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
|
|
3421
|
+
var modelSchema10 = TypeModel("model:FaceLandmarkerTask");
|
|
3745
3422
|
var TypeLandmark = {
|
|
3746
3423
|
type: "object",
|
|
3747
3424
|
properties: {
|
|
@@ -3813,7 +3490,7 @@ var FaceLandmarkerInputSchema = {
|
|
|
3813
3490
|
type: "object",
|
|
3814
3491
|
properties: {
|
|
3815
3492
|
image: TypeImageInput,
|
|
3816
|
-
model:
|
|
3493
|
+
model: modelSchema10,
|
|
3817
3494
|
numFaces: {
|
|
3818
3495
|
type: "number",
|
|
3819
3496
|
minimum: 1,
|
|
@@ -3899,11 +3576,11 @@ class FaceLandmarkerTask extends AiVisionTask {
|
|
|
3899
3576
|
var faceLandmarker = (input, config) => {
|
|
3900
3577
|
return new FaceLandmarkerTask(config).run(input);
|
|
3901
3578
|
};
|
|
3902
|
-
|
|
3579
|
+
Workflow16.prototype.faceLandmarker = CreateWorkflow16(FaceLandmarkerTask);
|
|
3903
3580
|
|
|
3904
3581
|
// src/task/GestureRecognizerTask.ts
|
|
3905
|
-
import { CreateWorkflow as
|
|
3906
|
-
var
|
|
3582
|
+
import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
|
|
3583
|
+
var modelSchema11 = TypeModel("model:GestureRecognizerTask");
|
|
3907
3584
|
var TypeLandmark2 = {
|
|
3908
3585
|
type: "object",
|
|
3909
3586
|
properties: {
|
|
@@ -3995,7 +3672,7 @@ var GestureRecognizerInputSchema = {
|
|
|
3995
3672
|
type: "object",
|
|
3996
3673
|
properties: {
|
|
3997
3674
|
image: TypeImageInput,
|
|
3998
|
-
model:
|
|
3675
|
+
model: modelSchema11,
|
|
3999
3676
|
numHands: {
|
|
4000
3677
|
type: "number",
|
|
4001
3678
|
minimum: 1,
|
|
@@ -4067,11 +3744,11 @@ class GestureRecognizerTask extends AiVisionTask {
|
|
|
4067
3744
|
var gestureRecognizer = (input, config) => {
|
|
4068
3745
|
return new GestureRecognizerTask(config).run(input);
|
|
4069
3746
|
};
|
|
4070
|
-
|
|
3747
|
+
Workflow17.prototype.gestureRecognizer = CreateWorkflow17(GestureRecognizerTask);
|
|
4071
3748
|
|
|
4072
3749
|
// src/task/HandLandmarkerTask.ts
|
|
4073
|
-
import { CreateWorkflow as
|
|
4074
|
-
var
|
|
3750
|
+
import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
|
|
3751
|
+
var modelSchema12 = TypeModel("model:HandLandmarkerTask");
|
|
4075
3752
|
var TypeLandmark3 = {
|
|
4076
3753
|
type: "object",
|
|
4077
3754
|
properties: {
|
|
@@ -4140,7 +3817,7 @@ var HandLandmarkerInputSchema = {
|
|
|
4140
3817
|
type: "object",
|
|
4141
3818
|
properties: {
|
|
4142
3819
|
image: TypeImageInput,
|
|
4143
|
-
model:
|
|
3820
|
+
model: modelSchema12,
|
|
4144
3821
|
numHands: {
|
|
4145
3822
|
type: "number",
|
|
4146
3823
|
minimum: 1,
|
|
@@ -4212,7 +3889,7 @@ class HandLandmarkerTask extends AiVisionTask {
|
|
|
4212
3889
|
var handLandmarker = (input, config) => {
|
|
4213
3890
|
return new HandLandmarkerTask(config).run(input);
|
|
4214
3891
|
};
|
|
4215
|
-
|
|
3892
|
+
Workflow18.prototype.handLandmarker = CreateWorkflow18(HandLandmarkerTask);
|
|
4216
3893
|
|
|
4217
3894
|
// src/task/HierarchicalChunkerTask.ts
|
|
4218
3895
|
import {
|
|
@@ -4221,9 +3898,9 @@ import {
|
|
|
4221
3898
|
getChildren as getChildren2,
|
|
4222
3899
|
hasChildren as hasChildren2
|
|
4223
3900
|
} from "@workglow/knowledge-base";
|
|
4224
|
-
import { CreateWorkflow as
|
|
3901
|
+
import { CreateWorkflow as CreateWorkflow19, Task as Task10, Workflow as Workflow19 } from "@workglow/task-graph";
|
|
4225
3902
|
import { uuid4 } from "@workglow/util";
|
|
4226
|
-
var
|
|
3903
|
+
var modelSchema13 = TypeModel("model", {
|
|
4227
3904
|
title: "Model",
|
|
4228
3905
|
description: "Model to use for token counting"
|
|
4229
3906
|
});
|
|
@@ -4269,7 +3946,7 @@ var inputSchema9 = {
|
|
|
4269
3946
|
description: "Strategy for chunking",
|
|
4270
3947
|
default: "hierarchical"
|
|
4271
3948
|
},
|
|
4272
|
-
model:
|
|
3949
|
+
model: modelSchema13
|
|
4273
3950
|
},
|
|
4274
3951
|
required: ["doc_id", "documentTree"],
|
|
4275
3952
|
additionalProperties: false
|
|
@@ -4304,7 +3981,7 @@ var outputSchema9 = {
|
|
|
4304
3981
|
additionalProperties: false
|
|
4305
3982
|
};
|
|
4306
3983
|
|
|
4307
|
-
class HierarchicalChunkerTask extends
|
|
3984
|
+
class HierarchicalChunkerTask extends Task10 {
|
|
4308
3985
|
static type = "HierarchicalChunkerTask";
|
|
4309
3986
|
static category = "Document";
|
|
4310
3987
|
static title = "Hierarchical Chunker";
|
|
@@ -4448,11 +4125,11 @@ class HierarchicalChunkerTask extends Task11 {
|
|
|
4448
4125
|
var hierarchicalChunker = (input, config) => {
|
|
4449
4126
|
return new HierarchicalChunkerTask(config).run(input);
|
|
4450
4127
|
};
|
|
4451
|
-
|
|
4128
|
+
Workflow19.prototype.hierarchicalChunker = CreateWorkflow19(HierarchicalChunkerTask);
|
|
4452
4129
|
|
|
4453
4130
|
// src/task/HierarchyJoinTask.ts
|
|
4454
4131
|
import { ChunkRecordArraySchema, TypeKnowledgeBase as TypeKnowledgeBase6 } from "@workglow/knowledge-base";
|
|
4455
|
-
import { CreateWorkflow as
|
|
4132
|
+
import { CreateWorkflow as CreateWorkflow20, Task as Task11, Workflow as Workflow20 } from "@workglow/task-graph";
|
|
4456
4133
|
var inputSchema10 = {
|
|
4457
4134
|
type: "object",
|
|
4458
4135
|
properties: {
|
|
@@ -4527,7 +4204,7 @@ var outputSchema10 = {
|
|
|
4527
4204
|
additionalProperties: false
|
|
4528
4205
|
};
|
|
4529
4206
|
|
|
4530
|
-
class HierarchyJoinTask extends
|
|
4207
|
+
class HierarchyJoinTask extends Task11 {
|
|
4531
4208
|
static type = "HierarchyJoinTask";
|
|
4532
4209
|
static category = "RAG";
|
|
4533
4210
|
static title = "Hierarchy Join";
|
|
@@ -4621,11 +4298,11 @@ class HierarchyJoinTask extends Task12 {
|
|
|
4621
4298
|
var hierarchyJoin = (input, config) => {
|
|
4622
4299
|
return new HierarchyJoinTask(config).run(input);
|
|
4623
4300
|
};
|
|
4624
|
-
|
|
4301
|
+
Workflow20.prototype.hierarchyJoin = CreateWorkflow20(HierarchyJoinTask);
|
|
4625
4302
|
|
|
4626
4303
|
// src/task/KbToDocumentsTask.ts
|
|
4627
4304
|
import { TypeKnowledgeBase as TypeKnowledgeBase7 } from "@workglow/knowledge-base";
|
|
4628
|
-
import { CreateWorkflow as
|
|
4305
|
+
import { CreateWorkflow as CreateWorkflow21, Task as Task12, Workflow as Workflow21 } from "@workglow/task-graph";
|
|
4629
4306
|
var inputSchema11 = {
|
|
4630
4307
|
type: "object",
|
|
4631
4308
|
properties: {
|
|
@@ -4669,7 +4346,7 @@ var outputSchema11 = {
|
|
|
4669
4346
|
additionalProperties: false
|
|
4670
4347
|
};
|
|
4671
4348
|
|
|
4672
|
-
class KbToDocumentsTask extends
|
|
4349
|
+
class KbToDocumentsTask extends Task12 {
|
|
4673
4350
|
static type = "KbToDocumentsTask";
|
|
4674
4351
|
static category = "Vector Store";
|
|
4675
4352
|
static title = "Knowledge Base to Documents";
|
|
@@ -4710,16 +4387,16 @@ class KbToDocumentsTask extends Task13 {
|
|
|
4710
4387
|
var kbToDocuments = (input, config) => {
|
|
4711
4388
|
return new KbToDocumentsTask(config).run(input);
|
|
4712
4389
|
};
|
|
4713
|
-
|
|
4390
|
+
Workflow21.prototype.kbToDocuments = CreateWorkflow21(KbToDocumentsTask);
|
|
4714
4391
|
|
|
4715
4392
|
// src/task/ImageClassificationTask.ts
|
|
4716
|
-
import { CreateWorkflow as
|
|
4717
|
-
var
|
|
4393
|
+
import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
|
|
4394
|
+
var modelSchema14 = TypeModel("model:ImageClassificationTask");
|
|
4718
4395
|
var ImageClassificationInputSchema = {
|
|
4719
4396
|
type: "object",
|
|
4720
4397
|
properties: {
|
|
4721
4398
|
image: TypeImageInput,
|
|
4722
|
-
model:
|
|
4399
|
+
model: modelSchema14,
|
|
4723
4400
|
categories: {
|
|
4724
4401
|
type: "array",
|
|
4725
4402
|
items: {
|
|
@@ -4773,19 +4450,19 @@ class ImageClassificationTask extends AiVisionTask {
|
|
|
4773
4450
|
var imageClassification = (input, config) => {
|
|
4774
4451
|
return new ImageClassificationTask(config).run(input);
|
|
4775
4452
|
};
|
|
4776
|
-
|
|
4453
|
+
Workflow22.prototype.imageClassification = CreateWorkflow22(ImageClassificationTask);
|
|
4777
4454
|
|
|
4778
4455
|
// src/task/ImageEmbeddingTask.ts
|
|
4779
|
-
import { CreateWorkflow as
|
|
4456
|
+
import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
|
|
4780
4457
|
import {
|
|
4781
4458
|
TypedArraySchema as TypedArraySchema7
|
|
4782
4459
|
} from "@workglow/util/schema";
|
|
4783
|
-
var
|
|
4460
|
+
var modelSchema15 = TypeModel("model:ImageEmbeddingTask");
|
|
4784
4461
|
var ImageEmbeddingInputSchema = {
|
|
4785
4462
|
type: "object",
|
|
4786
4463
|
properties: {
|
|
4787
4464
|
image: TypeSingleOrArray(TypeImageInput),
|
|
4788
|
-
model:
|
|
4465
|
+
model: modelSchema15
|
|
4789
4466
|
},
|
|
4790
4467
|
required: ["image", "model"],
|
|
4791
4468
|
additionalProperties: false
|
|
@@ -4817,16 +4494,16 @@ class ImageEmbeddingTask extends AiVisionTask {
|
|
|
4817
4494
|
var imageEmbedding = (input, config) => {
|
|
4818
4495
|
return new ImageEmbeddingTask(config).run(input);
|
|
4819
4496
|
};
|
|
4820
|
-
|
|
4497
|
+
Workflow23.prototype.imageEmbedding = CreateWorkflow23(ImageEmbeddingTask);
|
|
4821
4498
|
|
|
4822
4499
|
// src/task/ImageSegmentationTask.ts
|
|
4823
|
-
import { CreateWorkflow as
|
|
4824
|
-
var
|
|
4500
|
+
import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
|
|
4501
|
+
var modelSchema16 = TypeModel("model:ImageSegmentationTask");
|
|
4825
4502
|
var ImageSegmentationInputSchema = {
|
|
4826
4503
|
type: "object",
|
|
4827
4504
|
properties: {
|
|
4828
4505
|
image: TypeImageInput,
|
|
4829
|
-
model:
|
|
4506
|
+
model: modelSchema16,
|
|
4830
4507
|
threshold: {
|
|
4831
4508
|
type: "number",
|
|
4832
4509
|
title: "Threshold",
|
|
@@ -4905,11 +4582,11 @@ class ImageSegmentationTask extends AiVisionTask {
|
|
|
4905
4582
|
var imageSegmentation = (input, config) => {
|
|
4906
4583
|
return new ImageSegmentationTask(config).run(input);
|
|
4907
4584
|
};
|
|
4908
|
-
|
|
4585
|
+
Workflow24.prototype.imageSegmentation = CreateWorkflow24(ImageSegmentationTask);
|
|
4909
4586
|
|
|
4910
4587
|
// src/task/ImageToTextTask.ts
|
|
4911
|
-
import { CreateWorkflow as
|
|
4912
|
-
var
|
|
4588
|
+
import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
|
|
4589
|
+
var modelSchema17 = TypeModel("model:ImageToTextTask");
|
|
4913
4590
|
var generatedTextSchema = {
|
|
4914
4591
|
type: "string",
|
|
4915
4592
|
title: "Text",
|
|
@@ -4919,7 +4596,7 @@ var ImageToTextInputSchema = {
|
|
|
4919
4596
|
type: "object",
|
|
4920
4597
|
properties: {
|
|
4921
4598
|
image: TypeImageInput,
|
|
4922
|
-
model:
|
|
4599
|
+
model: modelSchema17,
|
|
4923
4600
|
maxTokens: {
|
|
4924
4601
|
type: "number",
|
|
4925
4602
|
title: "Max Tokens",
|
|
@@ -4960,15 +4637,15 @@ class ImageToTextTask extends AiVisionTask {
|
|
|
4960
4637
|
var imageToText = (input, config) => {
|
|
4961
4638
|
return new ImageToTextTask(config).run(input);
|
|
4962
4639
|
};
|
|
4963
|
-
|
|
4640
|
+
Workflow25.prototype.imageToText = CreateWorkflow25(ImageToTextTask);
|
|
4964
4641
|
|
|
4965
4642
|
// src/task/ModelInfoTask.ts
|
|
4966
|
-
import { CreateWorkflow as
|
|
4967
|
-
var
|
|
4643
|
+
import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
|
|
4644
|
+
var modelSchema18 = TypeModel("model");
|
|
4968
4645
|
var ModelInfoInputSchema = {
|
|
4969
4646
|
type: "object",
|
|
4970
4647
|
properties: {
|
|
4971
|
-
model:
|
|
4648
|
+
model: modelSchema18,
|
|
4972
4649
|
detail: {
|
|
4973
4650
|
type: "string",
|
|
4974
4651
|
enum: ["cached_status", "files", "files_with_metadata", "dimensions"],
|
|
@@ -4981,7 +4658,7 @@ var ModelInfoInputSchema = {
|
|
|
4981
4658
|
var ModelInfoOutputSchema = {
|
|
4982
4659
|
type: "object",
|
|
4983
4660
|
properties: {
|
|
4984
|
-
model:
|
|
4661
|
+
model: modelSchema18,
|
|
4985
4662
|
is_local: { type: "boolean" },
|
|
4986
4663
|
is_remote: { type: "boolean" },
|
|
4987
4664
|
supports_browser: { type: "boolean" },
|
|
@@ -5039,10 +4716,10 @@ class ModelInfoTask extends AiTask {
|
|
|
5039
4716
|
var modelInfo = (input, config) => {
|
|
5040
4717
|
return new ModelInfoTask(config).run(input);
|
|
5041
4718
|
};
|
|
5042
|
-
|
|
4719
|
+
Workflow26.prototype.modelInfo = CreateWorkflow26(ModelInfoTask);
|
|
5043
4720
|
|
|
5044
4721
|
// src/task/ModelSearchTask.ts
|
|
5045
|
-
import { CreateWorkflow as
|
|
4722
|
+
import { CreateWorkflow as CreateWorkflow27, Task as Task13, Workflow as Workflow27 } from "@workglow/task-graph";
|
|
5046
4723
|
var ModelSearchInputSchema = {
|
|
5047
4724
|
type: "object",
|
|
5048
4725
|
properties: {
|
|
@@ -5107,7 +4784,7 @@ var ModelSearchOutputSchema = {
|
|
|
5107
4784
|
additionalProperties: false
|
|
5108
4785
|
};
|
|
5109
4786
|
|
|
5110
|
-
class ModelSearchTask extends
|
|
4787
|
+
class ModelSearchTask extends Task13 {
|
|
5111
4788
|
static type = "ModelSearchTask";
|
|
5112
4789
|
static category = "AI Model";
|
|
5113
4790
|
static title = "Model Search";
|
|
@@ -5133,11 +4810,11 @@ class ModelSearchTask extends Task14 {
|
|
|
5133
4810
|
var modelSearch = (input, config) => {
|
|
5134
4811
|
return new ModelSearchTask(config).run(input);
|
|
5135
4812
|
};
|
|
5136
|
-
|
|
4813
|
+
Workflow27.prototype.modelSearch = CreateWorkflow27(ModelSearchTask);
|
|
5137
4814
|
|
|
5138
4815
|
// src/task/ObjectDetectionTask.ts
|
|
5139
|
-
import { CreateWorkflow as
|
|
5140
|
-
var
|
|
4816
|
+
import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
|
|
4817
|
+
var modelSchema19 = TypeModel("model:ObjectDetectionTask");
|
|
5141
4818
|
var detectionSchema = {
|
|
5142
4819
|
type: "object",
|
|
5143
4820
|
properties: {
|
|
@@ -5162,7 +4839,7 @@ var ObjectDetectionInputSchema = {
|
|
|
5162
4839
|
type: "object",
|
|
5163
4840
|
properties: {
|
|
5164
4841
|
image: TypeImageInput,
|
|
5165
|
-
model:
|
|
4842
|
+
model: modelSchema19,
|
|
5166
4843
|
labels: {
|
|
5167
4844
|
type: "array",
|
|
5168
4845
|
items: {
|
|
@@ -5216,11 +4893,11 @@ class ObjectDetectionTask extends AiVisionTask {
|
|
|
5216
4893
|
var objectDetection = (input, config) => {
|
|
5217
4894
|
return new ObjectDetectionTask(config).run(input);
|
|
5218
4895
|
};
|
|
5219
|
-
|
|
4896
|
+
Workflow28.prototype.objectDetection = CreateWorkflow28(ObjectDetectionTask);
|
|
5220
4897
|
|
|
5221
4898
|
// src/task/PoseLandmarkerTask.ts
|
|
5222
|
-
import { CreateWorkflow as
|
|
5223
|
-
var
|
|
4899
|
+
import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
|
|
4900
|
+
var modelSchema20 = TypeModel("model:PoseLandmarkerTask");
|
|
5224
4901
|
var TypePoseLandmark = {
|
|
5225
4902
|
type: "object",
|
|
5226
4903
|
properties: {
|
|
@@ -5299,7 +4976,7 @@ var PoseLandmarkerInputSchema = {
|
|
|
5299
4976
|
type: "object",
|
|
5300
4977
|
properties: {
|
|
5301
4978
|
image: TypeImageInput,
|
|
5302
|
-
model:
|
|
4979
|
+
model: modelSchema20,
|
|
5303
4980
|
numPoses: {
|
|
5304
4981
|
type: "number",
|
|
5305
4982
|
minimum: 1,
|
|
@@ -5378,10 +5055,10 @@ class PoseLandmarkerTask extends AiVisionTask {
|
|
|
5378
5055
|
var poseLandmarker = (input, config) => {
|
|
5379
5056
|
return new PoseLandmarkerTask(config).run(input);
|
|
5380
5057
|
};
|
|
5381
|
-
|
|
5058
|
+
Workflow29.prototype.poseLandmarker = CreateWorkflow29(PoseLandmarkerTask);
|
|
5382
5059
|
|
|
5383
5060
|
// src/task/QueryExpanderTask.ts
|
|
5384
|
-
import { CreateWorkflow as
|
|
5061
|
+
import { CreateWorkflow as CreateWorkflow30, Task as Task14, Workflow as Workflow30 } from "@workglow/task-graph";
|
|
5385
5062
|
var QueryExpansionMethod = {
|
|
5386
5063
|
MULTI_QUERY: "multi-query",
|
|
5387
5064
|
HYDE: "hyde",
|
|
@@ -5449,7 +5126,7 @@ var outputSchema12 = {
|
|
|
5449
5126
|
additionalProperties: false
|
|
5450
5127
|
};
|
|
5451
5128
|
|
|
5452
|
-
class QueryExpanderTask extends
|
|
5129
|
+
class QueryExpanderTask extends Task14 {
|
|
5453
5130
|
static type = "QueryExpanderTask";
|
|
5454
5131
|
static category = "RAG";
|
|
5455
5132
|
static title = "Query Expander";
|
|
@@ -5591,14 +5268,14 @@ class QueryExpanderTask extends Task15 {
|
|
|
5591
5268
|
var queryExpander = (input, config) => {
|
|
5592
5269
|
return new QueryExpanderTask(config).run(input);
|
|
5593
5270
|
};
|
|
5594
|
-
|
|
5271
|
+
Workflow30.prototype.queryExpander = CreateWorkflow30(QueryExpanderTask);
|
|
5595
5272
|
|
|
5596
5273
|
// src/task/RerankerTask.ts
|
|
5597
|
-
import { CreateWorkflow as
|
|
5274
|
+
import { CreateWorkflow as CreateWorkflow32, Task as Task15, Workflow as Workflow32 } from "@workglow/task-graph";
|
|
5598
5275
|
|
|
5599
5276
|
// src/task/TextClassificationTask.ts
|
|
5600
|
-
import { CreateWorkflow as
|
|
5601
|
-
var
|
|
5277
|
+
import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
|
|
5278
|
+
var modelSchema21 = TypeModel("model:TextClassificationTask");
|
|
5602
5279
|
var TextClassificationInputSchema = {
|
|
5603
5280
|
type: "object",
|
|
5604
5281
|
properties: {
|
|
@@ -5625,7 +5302,7 @@ var TextClassificationInputSchema = {
|
|
|
5625
5302
|
description: "The maximum number of categories to return",
|
|
5626
5303
|
"x-ui-group": "Configuration"
|
|
5627
5304
|
},
|
|
5628
|
-
model:
|
|
5305
|
+
model: modelSchema21
|
|
5629
5306
|
},
|
|
5630
5307
|
required: ["text", "model"],
|
|
5631
5308
|
additionalProperties: false
|
|
@@ -5675,7 +5352,7 @@ class TextClassificationTask extends AiTask {
|
|
|
5675
5352
|
var textClassification = (input, config) => {
|
|
5676
5353
|
return new TextClassificationTask(config).run(input);
|
|
5677
5354
|
};
|
|
5678
|
-
|
|
5355
|
+
Workflow31.prototype.textClassification = CreateWorkflow31(TextClassificationTask);
|
|
5679
5356
|
|
|
5680
5357
|
// src/task/RerankerTask.ts
|
|
5681
5358
|
var inputSchema13 = {
|
|
@@ -5770,7 +5447,7 @@ var outputSchema13 = {
|
|
|
5770
5447
|
additionalProperties: false
|
|
5771
5448
|
};
|
|
5772
5449
|
|
|
5773
|
-
class RerankerTask extends
|
|
5450
|
+
class RerankerTask extends Task15 {
|
|
5774
5451
|
static type = "RerankerTask";
|
|
5775
5452
|
static category = "RAG";
|
|
5776
5453
|
static title = "Reranker";
|
|
@@ -5898,11 +5575,11 @@ class RerankerTask extends Task16 {
|
|
|
5898
5575
|
var reranker = (input, config) => {
|
|
5899
5576
|
return new RerankerTask(config).run(input);
|
|
5900
5577
|
};
|
|
5901
|
-
|
|
5578
|
+
Workflow32.prototype.reranker = CreateWorkflow32(RerankerTask);
|
|
5902
5579
|
|
|
5903
5580
|
// src/task/StructuralParserTask.ts
|
|
5904
5581
|
import { StructuralParser } from "@workglow/knowledge-base";
|
|
5905
|
-
import { CreateWorkflow as
|
|
5582
|
+
import { CreateWorkflow as CreateWorkflow33, Task as Task16, Workflow as Workflow33 } from "@workglow/task-graph";
|
|
5906
5583
|
import { uuid4 as uuid42 } from "@workglow/util";
|
|
5907
5584
|
var inputSchema14 = {
|
|
5908
5585
|
type: "object",
|
|
@@ -5962,7 +5639,7 @@ var outputSchema14 = {
|
|
|
5962
5639
|
additionalProperties: false
|
|
5963
5640
|
};
|
|
5964
5641
|
|
|
5965
|
-
class StructuralParserTask extends
|
|
5642
|
+
class StructuralParserTask extends Task16 {
|
|
5966
5643
|
static type = "StructuralParserTask";
|
|
5967
5644
|
static category = "Document";
|
|
5968
5645
|
static title = "Structural Parser";
|
|
@@ -6005,15 +5682,16 @@ class StructuralParserTask extends Task17 {
|
|
|
6005
5682
|
var structuralParser = (input, config) => {
|
|
6006
5683
|
return new StructuralParserTask(config).run(input);
|
|
6007
5684
|
};
|
|
6008
|
-
|
|
5685
|
+
Workflow33.prototype.structuralParser = CreateWorkflow33(StructuralParserTask);
|
|
6009
5686
|
|
|
6010
5687
|
// src/task/StructuredGenerationTask.ts
|
|
6011
|
-
import { CreateWorkflow as
|
|
6012
|
-
|
|
5688
|
+
import { CreateWorkflow as CreateWorkflow34, TaskConfigurationError as TaskConfigurationError4, TaskError, Workflow as Workflow34 } from "@workglow/task-graph";
|
|
5689
|
+
import { compileSchema as compileSchema2 } from "@workglow/util/schema";
|
|
5690
|
+
var modelSchema22 = TypeModel("model:StructuredGenerationTask");
|
|
6013
5691
|
var StructuredGenerationInputSchema = {
|
|
6014
5692
|
type: "object",
|
|
6015
5693
|
properties: {
|
|
6016
|
-
model:
|
|
5694
|
+
model: modelSchema22,
|
|
6017
5695
|
prompt: {
|
|
6018
5696
|
type: "string",
|
|
6019
5697
|
title: "Prompt",
|
|
@@ -6040,6 +5718,15 @@ var StructuredGenerationInputSchema = {
|
|
|
6040
5718
|
minimum: 0,
|
|
6041
5719
|
maximum: 2,
|
|
6042
5720
|
"x-ui-group": "Configuration"
|
|
5721
|
+
},
|
|
5722
|
+
maxRetries: {
|
|
5723
|
+
type: "integer",
|
|
5724
|
+
title: "Max Retries",
|
|
5725
|
+
description: "Number of times to re-prompt the model with validation errors when its output doesn't match the schema. 0 disables retries (fail on first mismatch).",
|
|
5726
|
+
minimum: 0,
|
|
5727
|
+
maximum: 10,
|
|
5728
|
+
default: 2,
|
|
5729
|
+
"x-ui-group": "Configuration"
|
|
6043
5730
|
}
|
|
6044
5731
|
},
|
|
6045
5732
|
required: ["model", "prompt", "outputSchema"],
|
|
@@ -6061,25 +5748,119 @@ var StructuredGenerationOutputSchema = {
|
|
|
6061
5748
|
additionalProperties: false
|
|
6062
5749
|
};
|
|
6063
5750
|
|
|
5751
|
+
class StructuredOutputValidationError extends TaskError {
|
|
5752
|
+
static type = "StructuredOutputValidationError";
|
|
5753
|
+
attempts;
|
|
5754
|
+
constructor(attempts) {
|
|
5755
|
+
const last = attempts[attempts.length - 1];
|
|
5756
|
+
const summary = last?.errors.map((e) => `${e.path || "/"}: ${e.message}`).join("; ") ?? "";
|
|
5757
|
+
super(`StructuredGenerationTask: model output failed validation after ${attempts.length} attempt(s). ` + `Last errors: ${summary}`);
|
|
5758
|
+
this.attempts = attempts;
|
|
5759
|
+
}
|
|
5760
|
+
}
|
|
5761
|
+
function validationErrorsFromSchemaNode(result) {
|
|
5762
|
+
return result.errors.map((e) => ({ path: e.data.pointer || "", message: e.message }));
|
|
5763
|
+
}
|
|
5764
|
+
function buildRetryPrompt(originalPrompt, errors) {
|
|
5765
|
+
const errorList = errors.map((e) => ` - ${e.path || "/"}: ${e.message}`).join(`
|
|
5766
|
+
`);
|
|
5767
|
+
return `${originalPrompt}
|
|
5768
|
+
|
|
5769
|
+
` + `Your previous response did not conform to the required JSON schema. ` + `Validation errors:
|
|
5770
|
+
${errorList}
|
|
5771
|
+
|
|
5772
|
+
` + `Please respond again with a JSON object that satisfies the schema. ` + `Output ONLY the JSON object, no other text.`;
|
|
5773
|
+
}
|
|
5774
|
+
|
|
6064
5775
|
class StructuredGenerationTask extends StreamingAiTask {
|
|
6065
5776
|
static type = "StructuredGenerationTask";
|
|
6066
5777
|
static category = "AI Text Model";
|
|
6067
5778
|
static title = "Structured Generation";
|
|
6068
|
-
static description = "Generates structured JSON output conforming to a provided schema using language models";
|
|
5779
|
+
static description = "Generates structured JSON output conforming to a provided schema using language models, with automatic validation and retry on mismatch";
|
|
6069
5780
|
static inputSchema() {
|
|
6070
5781
|
return StructuredGenerationInputSchema;
|
|
6071
5782
|
}
|
|
6072
5783
|
static outputSchema() {
|
|
6073
5784
|
return StructuredGenerationOutputSchema;
|
|
6074
5785
|
}
|
|
5786
|
+
async* executeStream(input, context) {
|
|
5787
|
+
let validator;
|
|
5788
|
+
try {
|
|
5789
|
+
validator = compileSchema2(input.outputSchema);
|
|
5790
|
+
} catch (err2) {
|
|
5791
|
+
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
5792
|
+
const configErr = new TaskConfigurationError4(`StructuredGenerationTask: invalid outputSchema — ${msg}`);
|
|
5793
|
+
configErr.taskType = this.type;
|
|
5794
|
+
configErr.taskId = this.id;
|
|
5795
|
+
throw configErr;
|
|
5796
|
+
}
|
|
5797
|
+
const maxRetries = Math.max(0, input.maxRetries ?? 2);
|
|
5798
|
+
const maxAttempts = maxRetries + 1;
|
|
5799
|
+
const attempts = [];
|
|
5800
|
+
let currentInput = input;
|
|
5801
|
+
for (let attempt = 1;attempt <= maxAttempts; attempt++) {
|
|
5802
|
+
let lastObject;
|
|
5803
|
+
for await (const event of super.executeStream(currentInput, context)) {
|
|
5804
|
+
if (event.type === "object-delta" && event.port === "object") {
|
|
5805
|
+
const delta = event.objectDelta;
|
|
5806
|
+
if (delta && !Array.isArray(delta)) {
|
|
5807
|
+
lastObject = delta;
|
|
5808
|
+
}
|
|
5809
|
+
yield event;
|
|
5810
|
+
} else if (event.type === "finish") {
|
|
5811
|
+
const data = event.data;
|
|
5812
|
+
const finalObject = data?.object ?? lastObject ?? {};
|
|
5813
|
+
const result = validator.validate(finalObject);
|
|
5814
|
+
if (result.valid) {
|
|
5815
|
+
yield {
|
|
5816
|
+
type: "finish",
|
|
5817
|
+
data: { object: finalObject }
|
|
5818
|
+
};
|
|
5819
|
+
return;
|
|
5820
|
+
}
|
|
5821
|
+
const errors = validationErrorsFromSchemaNode(result);
|
|
5822
|
+
attempts.push({ attempt, errors, object: finalObject });
|
|
5823
|
+
lastObject = finalObject;
|
|
5824
|
+
break;
|
|
5825
|
+
} else {
|
|
5826
|
+
yield event;
|
|
5827
|
+
}
|
|
5828
|
+
}
|
|
5829
|
+
if (attempt < maxAttempts) {
|
|
5830
|
+
yield {
|
|
5831
|
+
type: "object-delta",
|
|
5832
|
+
port: "object",
|
|
5833
|
+
objectDelta: {}
|
|
5834
|
+
};
|
|
5835
|
+
const lastErrors = attempts[attempts.length - 1].errors;
|
|
5836
|
+
currentInput = {
|
|
5837
|
+
...input,
|
|
5838
|
+
prompt: buildRetryPrompt(input.prompt, lastErrors)
|
|
5839
|
+
};
|
|
5840
|
+
}
|
|
5841
|
+
}
|
|
5842
|
+
const err = new StructuredOutputValidationError(attempts);
|
|
5843
|
+
err.taskType = this.type;
|
|
5844
|
+
err.taskId = this.id;
|
|
5845
|
+
throw err;
|
|
5846
|
+
}
|
|
5847
|
+
async execute(input, context) {
|
|
5848
|
+
let result;
|
|
5849
|
+
for await (const event of this.executeStream(input, context)) {
|
|
5850
|
+
if (event.type === "finish") {
|
|
5851
|
+
result = event.data;
|
|
5852
|
+
}
|
|
5853
|
+
}
|
|
5854
|
+
return result;
|
|
5855
|
+
}
|
|
6075
5856
|
}
|
|
6076
5857
|
var structuredGeneration = (input, config) => {
|
|
6077
5858
|
return new StructuredGenerationTask(config).run(input);
|
|
6078
5859
|
};
|
|
6079
|
-
|
|
5860
|
+
Workflow34.prototype.structuredGeneration = CreateWorkflow34(StructuredGenerationTask);
|
|
6080
5861
|
|
|
6081
5862
|
// src/task/TextChunkerTask.ts
|
|
6082
|
-
import { CreateWorkflow as
|
|
5863
|
+
import { CreateWorkflow as CreateWorkflow35, Task as Task17, Workflow as Workflow35 } from "@workglow/task-graph";
|
|
6083
5864
|
var ChunkingStrategy = {
|
|
6084
5865
|
FIXED: "fixed",
|
|
6085
5866
|
SENTENCE: "sentence",
|
|
@@ -6148,7 +5929,7 @@ var outputSchema15 = {
|
|
|
6148
5929
|
additionalProperties: false
|
|
6149
5930
|
};
|
|
6150
5931
|
|
|
6151
|
-
class TextChunkerTask extends
|
|
5932
|
+
class TextChunkerTask extends Task17 {
|
|
6152
5933
|
static type = "TextChunkerTask";
|
|
6153
5934
|
static category = "Document";
|
|
6154
5935
|
static title = "Text Chunker";
|
|
@@ -6328,11 +6109,11 @@ class TextChunkerTask extends Task18 {
|
|
|
6328
6109
|
var textChunker = (input, config) => {
|
|
6329
6110
|
return new TextChunkerTask(config).run(input);
|
|
6330
6111
|
};
|
|
6331
|
-
|
|
6112
|
+
Workflow35.prototype.textChunker = CreateWorkflow35(TextChunkerTask);
|
|
6332
6113
|
|
|
6333
6114
|
// src/task/TextFillMaskTask.ts
|
|
6334
|
-
import { CreateWorkflow as
|
|
6335
|
-
var
|
|
6115
|
+
import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
|
|
6116
|
+
var modelSchema23 = TypeModel("model:TextFillMaskTask");
|
|
6336
6117
|
var TextFillMaskInputSchema = {
|
|
6337
6118
|
type: "object",
|
|
6338
6119
|
properties: {
|
|
@@ -6341,7 +6122,7 @@ var TextFillMaskInputSchema = {
|
|
|
6341
6122
|
title: "Text",
|
|
6342
6123
|
description: "The text with a mask token to fill"
|
|
6343
6124
|
},
|
|
6344
|
-
model:
|
|
6125
|
+
model: modelSchema23
|
|
6345
6126
|
},
|
|
6346
6127
|
required: ["text", "model"],
|
|
6347
6128
|
additionalProperties: false
|
|
@@ -6396,21 +6177,21 @@ class TextFillMaskTask extends AiTask {
|
|
|
6396
6177
|
var textFillMask = (input, config) => {
|
|
6397
6178
|
return new TextFillMaskTask(config).run(input);
|
|
6398
6179
|
};
|
|
6399
|
-
|
|
6180
|
+
Workflow36.prototype.textFillMask = CreateWorkflow36(TextFillMaskTask);
|
|
6400
6181
|
|
|
6401
6182
|
// src/task/TextGenerationTask.ts
|
|
6402
|
-
import { CreateWorkflow as
|
|
6183
|
+
import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
|
|
6403
6184
|
var generatedTextSchema2 = {
|
|
6404
6185
|
type: "string",
|
|
6405
6186
|
title: "Text",
|
|
6406
6187
|
description: "The generated text",
|
|
6407
6188
|
"x-stream": "append"
|
|
6408
6189
|
};
|
|
6409
|
-
var
|
|
6190
|
+
var modelSchema24 = TypeModel("model:TextGenerationTask");
|
|
6410
6191
|
var TextGenerationInputSchema = {
|
|
6411
6192
|
type: "object",
|
|
6412
6193
|
properties: {
|
|
6413
|
-
model:
|
|
6194
|
+
model: modelSchema24,
|
|
6414
6195
|
prompt: {
|
|
6415
6196
|
type: "string",
|
|
6416
6197
|
title: "Prompt",
|
|
@@ -6484,11 +6265,11 @@ class TextGenerationTask extends StreamingAiTask {
|
|
|
6484
6265
|
var textGeneration = (input, config) => {
|
|
6485
6266
|
return new TextGenerationTask(config).run(input);
|
|
6486
6267
|
};
|
|
6487
|
-
|
|
6268
|
+
Workflow37.prototype.textGeneration = CreateWorkflow37(TextGenerationTask);
|
|
6488
6269
|
|
|
6489
6270
|
// src/task/TextLanguageDetectionTask.ts
|
|
6490
|
-
import { CreateWorkflow as
|
|
6491
|
-
var
|
|
6271
|
+
import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
|
|
6272
|
+
var modelSchema25 = TypeModel("model:TextLanguageDetectionTask");
|
|
6492
6273
|
var TextLanguageDetectionInputSchema = {
|
|
6493
6274
|
type: "object",
|
|
6494
6275
|
properties: {
|
|
@@ -6505,7 +6286,7 @@ var TextLanguageDetectionInputSchema = {
|
|
|
6505
6286
|
title: "Max Languages",
|
|
6506
6287
|
description: "The maximum number of languages to return"
|
|
6507
6288
|
},
|
|
6508
|
-
model:
|
|
6289
|
+
model: modelSchema25
|
|
6509
6290
|
},
|
|
6510
6291
|
required: ["text", "model"],
|
|
6511
6292
|
additionalProperties: false
|
|
@@ -6555,10 +6336,10 @@ class TextLanguageDetectionTask extends AiTask {
|
|
|
6555
6336
|
var textLanguageDetection = (input, config) => {
|
|
6556
6337
|
return new TextLanguageDetectionTask(config).run(input);
|
|
6557
6338
|
};
|
|
6558
|
-
|
|
6339
|
+
Workflow38.prototype.textLanguageDetection = CreateWorkflow38(TextLanguageDetectionTask);
|
|
6559
6340
|
|
|
6560
6341
|
// src/task/TextQuestionAnswerTask.ts
|
|
6561
|
-
import { CreateWorkflow as
|
|
6342
|
+
import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
|
|
6562
6343
|
var contextSchema = {
|
|
6563
6344
|
type: "string",
|
|
6564
6345
|
title: "Context",
|
|
@@ -6575,13 +6356,13 @@ var textSchema = {
|
|
|
6575
6356
|
description: "The generated text",
|
|
6576
6357
|
"x-stream": "append"
|
|
6577
6358
|
};
|
|
6578
|
-
var
|
|
6359
|
+
var modelSchema26 = TypeModel("model:TextQuestionAnswerTask");
|
|
6579
6360
|
var TextQuestionAnswerInputSchema = {
|
|
6580
6361
|
type: "object",
|
|
6581
6362
|
properties: {
|
|
6582
6363
|
context: contextSchema,
|
|
6583
6364
|
question: questionSchema,
|
|
6584
|
-
model:
|
|
6365
|
+
model: modelSchema26
|
|
6585
6366
|
},
|
|
6586
6367
|
required: ["context", "question", "model"],
|
|
6587
6368
|
additionalProperties: false
|
|
@@ -6610,11 +6391,11 @@ class TextQuestionAnswerTask extends StreamingAiTask {
|
|
|
6610
6391
|
var textQuestionAnswer = (input, config) => {
|
|
6611
6392
|
return new TextQuestionAnswerTask(config).run(input);
|
|
6612
6393
|
};
|
|
6613
|
-
|
|
6394
|
+
Workflow39.prototype.textQuestionAnswer = CreateWorkflow39(TextQuestionAnswerTask);
|
|
6614
6395
|
|
|
6615
6396
|
// src/task/TextRewriterTask.ts
|
|
6616
|
-
import { CreateWorkflow as
|
|
6617
|
-
var
|
|
6397
|
+
import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
|
|
6398
|
+
var modelSchema27 = TypeModel("model:TextRewriterTask");
|
|
6618
6399
|
var TextRewriterInputSchema = {
|
|
6619
6400
|
type: "object",
|
|
6620
6401
|
properties: {
|
|
@@ -6628,7 +6409,7 @@ var TextRewriterInputSchema = {
|
|
|
6628
6409
|
title: "Prompt",
|
|
6629
6410
|
description: "The prompt to direct the rewriting"
|
|
6630
6411
|
},
|
|
6631
|
-
model:
|
|
6412
|
+
model: modelSchema27
|
|
6632
6413
|
},
|
|
6633
6414
|
required: ["text", "prompt", "model"],
|
|
6634
6415
|
additionalProperties: false
|
|
@@ -6662,11 +6443,11 @@ class TextRewriterTask extends StreamingAiTask {
|
|
|
6662
6443
|
var textRewriter = (input, config) => {
|
|
6663
6444
|
return new TextRewriterTask(config).run(input);
|
|
6664
6445
|
};
|
|
6665
|
-
|
|
6446
|
+
Workflow40.prototype.textRewriter = CreateWorkflow40(TextRewriterTask);
|
|
6666
6447
|
|
|
6667
6448
|
// src/task/TextTranslationTask.ts
|
|
6668
|
-
import { CreateWorkflow as
|
|
6669
|
-
var
|
|
6449
|
+
import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
|
|
6450
|
+
var modelSchema28 = TypeModel("model:TextTranslationTask");
|
|
6670
6451
|
var translationTextSchema = {
|
|
6671
6452
|
type: "string",
|
|
6672
6453
|
title: "Text",
|
|
@@ -6693,7 +6474,7 @@ var TextTranslationInputSchema = {
|
|
|
6693
6474
|
minLength: 2,
|
|
6694
6475
|
maxLength: 2
|
|
6695
6476
|
}),
|
|
6696
|
-
model:
|
|
6477
|
+
model: modelSchema28
|
|
6697
6478
|
},
|
|
6698
6479
|
required: ["text", "source_lang", "target_lang", "model"],
|
|
6699
6480
|
additionalProperties: false
|
|
@@ -6728,10 +6509,245 @@ class TextTranslationTask extends StreamingAiTask {
|
|
|
6728
6509
|
var textTranslation = (input, config) => {
|
|
6729
6510
|
return new TextTranslationTask(config).run(input);
|
|
6730
6511
|
};
|
|
6731
|
-
|
|
6512
|
+
Workflow41.prototype.textTranslation = CreateWorkflow41(TextTranslationTask);
|
|
6513
|
+
|
|
6514
|
+
// src/task/ToolCallingTask.ts
|
|
6515
|
+
import { CreateWorkflow as CreateWorkflow42, getTaskConstructors, Workflow as Workflow42 } from "@workglow/task-graph";
|
|
6516
|
+
import { makeFingerprint } from "@workglow/util";
|
|
6517
|
+
function taskTypesToTools(taskNames, registry) {
|
|
6518
|
+
const constructors = getTaskConstructors(registry);
|
|
6519
|
+
return taskNames.map((name) => {
|
|
6520
|
+
const ctor = constructors.get(name);
|
|
6521
|
+
if (!ctor) {
|
|
6522
|
+
throw new Error(`taskTypesToTools: Unknown task type "${name}" — not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
|
|
6523
|
+
}
|
|
6524
|
+
const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
|
|
6525
|
+
return {
|
|
6526
|
+
name: ctor.type,
|
|
6527
|
+
description: ctor.description ?? "",
|
|
6528
|
+
inputSchema: ctor.inputSchema(),
|
|
6529
|
+
outputSchema: ctor.outputSchema(),
|
|
6530
|
+
...configSchema ? { configSchema } : {},
|
|
6531
|
+
taskType: name
|
|
6532
|
+
};
|
|
6533
|
+
});
|
|
6534
|
+
}
|
|
6535
|
+
var ToolDefinitionSchema = {
|
|
6536
|
+
type: "object",
|
|
6537
|
+
properties: {
|
|
6538
|
+
name: {
|
|
6539
|
+
type: "string",
|
|
6540
|
+
title: "Name",
|
|
6541
|
+
description: "The tool name"
|
|
6542
|
+
},
|
|
6543
|
+
description: {
|
|
6544
|
+
type: "string",
|
|
6545
|
+
title: "Description",
|
|
6546
|
+
description: "A description of what the tool does"
|
|
6547
|
+
},
|
|
6548
|
+
inputSchema: {
|
|
6549
|
+
type: "object",
|
|
6550
|
+
title: "Input Schema",
|
|
6551
|
+
description: "JSON Schema describing the tool's input parameters",
|
|
6552
|
+
additionalProperties: true
|
|
6553
|
+
},
|
|
6554
|
+
outputSchema: {
|
|
6555
|
+
type: "object",
|
|
6556
|
+
title: "Output Schema",
|
|
6557
|
+
description: "JSON Schema describing what the tool returns",
|
|
6558
|
+
additionalProperties: true
|
|
6559
|
+
},
|
|
6560
|
+
configSchema: {
|
|
6561
|
+
type: "object",
|
|
6562
|
+
title: "Config Schema",
|
|
6563
|
+
description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
|
|
6564
|
+
additionalProperties: true
|
|
6565
|
+
},
|
|
6566
|
+
config: {
|
|
6567
|
+
type: "object",
|
|
6568
|
+
title: "Config",
|
|
6569
|
+
description: "Concrete configuration values for the backing task (not sent to the LLM)",
|
|
6570
|
+
additionalProperties: true
|
|
6571
|
+
}
|
|
6572
|
+
},
|
|
6573
|
+
required: ["name", "description", "inputSchema"],
|
|
6574
|
+
additionalProperties: true
|
|
6575
|
+
};
|
|
6576
|
+
var ToolCallSchema = {
|
|
6577
|
+
type: "object",
|
|
6578
|
+
properties: {
|
|
6579
|
+
id: {
|
|
6580
|
+
type: "string",
|
|
6581
|
+
title: "ID",
|
|
6582
|
+
description: "Unique identifier for this tool call"
|
|
6583
|
+
},
|
|
6584
|
+
name: {
|
|
6585
|
+
type: "string",
|
|
6586
|
+
title: "Name",
|
|
6587
|
+
description: "The name of the tool to invoke"
|
|
6588
|
+
},
|
|
6589
|
+
input: {
|
|
6590
|
+
type: "object",
|
|
6591
|
+
title: "Input",
|
|
6592
|
+
description: "The input arguments for the tool call",
|
|
6593
|
+
additionalProperties: true
|
|
6594
|
+
}
|
|
6595
|
+
},
|
|
6596
|
+
required: ["id", "name", "input"],
|
|
6597
|
+
additionalProperties: false
|
|
6598
|
+
};
|
|
6599
|
+
var modelSchema29 = TypeModel("model:ToolCallingTask");
|
|
6600
|
+
var ToolCallingInputSchema = {
|
|
6601
|
+
type: "object",
|
|
6602
|
+
properties: {
|
|
6603
|
+
model: modelSchema29,
|
|
6604
|
+
prompt: {
|
|
6605
|
+
oneOf: [
|
|
6606
|
+
{ type: "string", title: "Prompt", description: "The prompt to send to the model" },
|
|
6607
|
+
{
|
|
6608
|
+
type: "array",
|
|
6609
|
+
title: "Prompt",
|
|
6610
|
+
description: "The prompt as an array of strings or content blocks",
|
|
6611
|
+
items: {
|
|
6612
|
+
oneOf: [
|
|
6613
|
+
{ type: "string" },
|
|
6614
|
+
{
|
|
6615
|
+
type: "object",
|
|
6616
|
+
properties: {
|
|
6617
|
+
type: { type: "string", enum: ["text", "image", "audio"] }
|
|
6618
|
+
},
|
|
6619
|
+
required: ["type"],
|
|
6620
|
+
additionalProperties: true
|
|
6621
|
+
}
|
|
6622
|
+
]
|
|
6623
|
+
}
|
|
6624
|
+
}
|
|
6625
|
+
],
|
|
6626
|
+
title: "Prompt",
|
|
6627
|
+
description: "The prompt to send to the model"
|
|
6628
|
+
},
|
|
6629
|
+
systemPrompt: {
|
|
6630
|
+
type: "string",
|
|
6631
|
+
title: "System Prompt",
|
|
6632
|
+
description: "Optional system instructions for the model"
|
|
6633
|
+
},
|
|
6634
|
+
messages: {
|
|
6635
|
+
type: "array",
|
|
6636
|
+
title: "Messages",
|
|
6637
|
+
description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
|
|
6638
|
+
items: ChatMessageSchema
|
|
6639
|
+
},
|
|
6640
|
+
tools: {
|
|
6641
|
+
type: "array",
|
|
6642
|
+
format: "tasks",
|
|
6643
|
+
title: "Tools",
|
|
6644
|
+
description: "Tool definitions available for the model to call",
|
|
6645
|
+
items: {
|
|
6646
|
+
oneOf: [
|
|
6647
|
+
{ type: "string", format: "tasks", description: "Task type name" },
|
|
6648
|
+
ToolDefinitionSchema
|
|
6649
|
+
]
|
|
6650
|
+
}
|
|
6651
|
+
},
|
|
6652
|
+
toolChoice: {
|
|
6653
|
+
type: "string",
|
|
6654
|
+
title: "Tool Choice",
|
|
6655
|
+
description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
|
|
6656
|
+
"x-ui-group": "Configuration"
|
|
6657
|
+
},
|
|
6658
|
+
maxTokens: {
|
|
6659
|
+
type: "number",
|
|
6660
|
+
title: "Max Tokens",
|
|
6661
|
+
description: "The maximum number of tokens to generate",
|
|
6662
|
+
minimum: 1,
|
|
6663
|
+
"x-ui-group": "Configuration"
|
|
6664
|
+
},
|
|
6665
|
+
temperature: {
|
|
6666
|
+
type: "number",
|
|
6667
|
+
title: "Temperature",
|
|
6668
|
+
description: "The temperature to use for sampling",
|
|
6669
|
+
minimum: 0,
|
|
6670
|
+
maximum: 2,
|
|
6671
|
+
"x-ui-group": "Configuration"
|
|
6672
|
+
}
|
|
6673
|
+
},
|
|
6674
|
+
required: ["model", "prompt", "tools"],
|
|
6675
|
+
additionalProperties: false
|
|
6676
|
+
};
|
|
6677
|
+
var ToolCallingOutputSchema = {
|
|
6678
|
+
type: "object",
|
|
6679
|
+
properties: {
|
|
6680
|
+
text: {
|
|
6681
|
+
type: "string",
|
|
6682
|
+
title: "Text",
|
|
6683
|
+
description: "Any text content generated by the model",
|
|
6684
|
+
"x-stream": "append"
|
|
6685
|
+
},
|
|
6686
|
+
toolCalls: {
|
|
6687
|
+
type: "array",
|
|
6688
|
+
items: ToolCallSchema,
|
|
6689
|
+
title: "Tool Calls",
|
|
6690
|
+
description: "Tool calls requested by the model",
|
|
6691
|
+
"x-stream": "object"
|
|
6692
|
+
}
|
|
6693
|
+
},
|
|
6694
|
+
required: ["text", "toolCalls"],
|
|
6695
|
+
additionalProperties: false
|
|
6696
|
+
};
|
|
6697
|
+
|
|
6698
|
+
class ToolCallingTask extends StreamingAiTask {
|
|
6699
|
+
static type = "ToolCallingTask";
|
|
6700
|
+
static category = "AI Text Model";
|
|
6701
|
+
static title = "Tool Calling";
|
|
6702
|
+
static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
|
|
6703
|
+
static inputSchema() {
|
|
6704
|
+
return ToolCallingInputSchema;
|
|
6705
|
+
}
|
|
6706
|
+
static outputSchema() {
|
|
6707
|
+
return ToolCallingOutputSchema;
|
|
6708
|
+
}
|
|
6709
|
+
_computedSessionId;
|
|
6710
|
+
async getJobInput(input) {
|
|
6711
|
+
const jobInput = await super.getJobInput(input);
|
|
6712
|
+
if (!jobInput.sessionId && input.tools && input.tools.length > 0) {
|
|
6713
|
+
jobInput.sessionId = await makeFingerprint({
|
|
6714
|
+
tools: input.tools,
|
|
6715
|
+
systemPrompt: input.systemPrompt,
|
|
6716
|
+
runnerId: this.runConfig.runnerId
|
|
6717
|
+
});
|
|
6718
|
+
this._computedSessionId = jobInput.sessionId;
|
|
6719
|
+
}
|
|
6720
|
+
return jobInput;
|
|
6721
|
+
}
|
|
6722
|
+
registerSessionDispose(input, context) {
|
|
6723
|
+
const sessionId = this._computedSessionId;
|
|
6724
|
+
if (!sessionId || !context.resourceScope)
|
|
6725
|
+
return;
|
|
6726
|
+
const model = input.model;
|
|
6727
|
+
if (!model || typeof model !== "object")
|
|
6728
|
+
return;
|
|
6729
|
+
const providerName = model.provider;
|
|
6730
|
+
context.resourceScope.register(`ai:session:${sessionId}`, async () => {
|
|
6731
|
+
await getAiProviderRegistry().disposeSession(providerName, sessionId);
|
|
6732
|
+
});
|
|
6733
|
+
}
|
|
6734
|
+
async execute(input, executeContext) {
|
|
6735
|
+
const result = await super.execute(input, executeContext);
|
|
6736
|
+
this.registerSessionDispose(input, executeContext);
|
|
6737
|
+
return result;
|
|
6738
|
+
}
|
|
6739
|
+
async* executeStream(input, context) {
|
|
6740
|
+
yield* super.executeStream(input, context);
|
|
6741
|
+
this.registerSessionDispose(input, context);
|
|
6742
|
+
}
|
|
6743
|
+
}
|
|
6744
|
+
var toolCalling = (input, config) => {
|
|
6745
|
+
return new ToolCallingTask(config).run(input);
|
|
6746
|
+
};
|
|
6747
|
+
Workflow42.prototype.toolCalling = CreateWorkflow42(ToolCallingTask);
|
|
6732
6748
|
|
|
6733
6749
|
// src/task/TopicSegmenterTask.ts
|
|
6734
|
-
import { CreateWorkflow as
|
|
6750
|
+
import { CreateWorkflow as CreateWorkflow43, Task as Task18, Workflow as Workflow43 } from "@workglow/task-graph";
|
|
6735
6751
|
var SegmentationMethod = {
|
|
6736
6752
|
HEURISTIC: "heuristic",
|
|
6737
6753
|
EMBEDDING_SIMILARITY: "embedding-similarity",
|
|
@@ -6806,7 +6822,7 @@ var outputSchema16 = {
|
|
|
6806
6822
|
additionalProperties: false
|
|
6807
6823
|
};
|
|
6808
6824
|
|
|
6809
|
-
class TopicSegmenterTask extends
|
|
6825
|
+
class TopicSegmenterTask extends Task18 {
|
|
6810
6826
|
static type = "TopicSegmenterTask";
|
|
6811
6827
|
static category = "Document";
|
|
6812
6828
|
static title = "Topic Segmenter";
|
|
@@ -7011,10 +7027,10 @@ class TopicSegmenterTask extends Task19 {
|
|
|
7011
7027
|
var topicSegmenter = (input, config) => {
|
|
7012
7028
|
return new TopicSegmenterTask(config).run(input);
|
|
7013
7029
|
};
|
|
7014
|
-
|
|
7030
|
+
Workflow43.prototype.topicSegmenter = CreateWorkflow43(TopicSegmenterTask);
|
|
7015
7031
|
|
|
7016
7032
|
// src/task/UnloadModelTask.ts
|
|
7017
|
-
import { CreateWorkflow as
|
|
7033
|
+
import { CreateWorkflow as CreateWorkflow44, Workflow as Workflow44 } from "@workglow/task-graph";
|
|
7018
7034
|
var modelSchema30 = TypeModel("model");
|
|
7019
7035
|
var UnloadModelInputSchema = {
|
|
7020
7036
|
type: "object",
|
|
@@ -7049,10 +7065,10 @@ class UnloadModelTask extends AiTask {
|
|
|
7049
7065
|
var unloadModel = (input, config) => {
|
|
7050
7066
|
return new UnloadModelTask(config).run(input);
|
|
7051
7067
|
};
|
|
7052
|
-
|
|
7068
|
+
Workflow44.prototype.unloadModel = CreateWorkflow44(UnloadModelTask);
|
|
7053
7069
|
|
|
7054
7070
|
// src/task/VectorQuantizeTask.ts
|
|
7055
|
-
import { CreateWorkflow as
|
|
7071
|
+
import { CreateWorkflow as CreateWorkflow45, Task as Task19, Workflow as Workflow45 } from "@workglow/task-graph";
|
|
7056
7072
|
import {
|
|
7057
7073
|
normalizeNumberArray,
|
|
7058
7074
|
TensorType,
|
|
@@ -7132,7 +7148,7 @@ var outputSchema17 = {
|
|
|
7132
7148
|
additionalProperties: false
|
|
7133
7149
|
};
|
|
7134
7150
|
|
|
7135
|
-
class VectorQuantizeTask extends
|
|
7151
|
+
class VectorQuantizeTask extends Task19 {
|
|
7136
7152
|
static type = "VectorQuantizeTask";
|
|
7137
7153
|
static category = "Vector";
|
|
7138
7154
|
static title = "Quantize";
|
|
@@ -7232,10 +7248,10 @@ class VectorQuantizeTask extends Task20 {
|
|
|
7232
7248
|
var vectorQuantize = (input, config) => {
|
|
7233
7249
|
return new VectorQuantizeTask(config).run(input);
|
|
7234
7250
|
};
|
|
7235
|
-
|
|
7251
|
+
Workflow45.prototype.vectorQuantize = CreateWorkflow45(VectorQuantizeTask);
|
|
7236
7252
|
|
|
7237
7253
|
// src/task/VectorSimilarityTask.ts
|
|
7238
|
-
import { CreateWorkflow as
|
|
7254
|
+
import { CreateWorkflow as CreateWorkflow46, GraphAsTask, Workflow as Workflow46 } from "@workglow/task-graph";
|
|
7239
7255
|
import {
|
|
7240
7256
|
cosineSimilarity,
|
|
7241
7257
|
hammingSimilarity,
|
|
@@ -7341,7 +7357,7 @@ class VectorSimilarityTask extends GraphAsTask {
|
|
|
7341
7357
|
var similarity = (input, config) => {
|
|
7342
7358
|
return new VectorSimilarityTask(config).run(input);
|
|
7343
7359
|
};
|
|
7344
|
-
|
|
7360
|
+
Workflow46.prototype.similarity = CreateWorkflow46(VectorSimilarityTask);
|
|
7345
7361
|
// src/task/MessageConversion.ts
|
|
7346
7362
|
function getInputMessages(input) {
|
|
7347
7363
|
const messages = input.messages;
|
|
@@ -7390,66 +7406,46 @@ function toOpenAIMessages(input) {
|
|
|
7390
7406
|
}
|
|
7391
7407
|
for (const msg of inputMessages) {
|
|
7392
7408
|
if (msg.role === "user") {
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
}
|
|
7402
|
-
parts.push({
|
|
7403
|
-
type: "image_url",
|
|
7404
|
-
image_url: { url: `data:${b.mimeType};base64,${b.data}` }
|
|
7405
|
-
});
|
|
7406
|
-
} else if (b.type === "audio") {
|
|
7407
|
-
const format = b.mimeType.replace(/^audio\//, "");
|
|
7408
|
-
parts.push({
|
|
7409
|
-
type: "input_audio",
|
|
7410
|
-
input_audio: { data: b.data, format }
|
|
7411
|
-
});
|
|
7412
|
-
}
|
|
7413
|
-
}
|
|
7414
|
-
messages.push({ role: "user", content: parts });
|
|
7415
|
-
} else {
|
|
7416
|
-
try {
|
|
7417
|
-
messages.push({ role: "user", content: JSON.stringify(msg.content) });
|
|
7418
|
-
} catch {
|
|
7419
|
-
messages.push({ role: "user", content: String(msg.content) });
|
|
7409
|
+
const parts = [];
|
|
7410
|
+
for (const block of msg.content) {
|
|
7411
|
+
if (block.type === "text") {
|
|
7412
|
+
parts.push({ type: "text", text: block.text });
|
|
7413
|
+
} else if (block.type === "image") {
|
|
7414
|
+
parts.push({
|
|
7415
|
+
type: "image_url",
|
|
7416
|
+
image_url: { url: `data:${block.mimeType};base64,${block.data}` }
|
|
7417
|
+
});
|
|
7420
7418
|
}
|
|
7421
7419
|
}
|
|
7420
|
+
messages.push({ role: "user", content: parts });
|
|
7422
7421
|
} else if (msg.role === "assistant") {
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
function: {
|
|
7431
|
-
name: b.name,
|
|
7432
|
-
arguments: JSON.stringify(b.input)
|
|
7433
|
-
}
|
|
7434
|
-
}));
|
|
7435
|
-
const entry = {
|
|
7436
|
-
role: "assistant",
|
|
7437
|
-
content: textParts.length > 0 ? textParts : null
|
|
7438
|
-
};
|
|
7439
|
-
if (toolCalls.length > 0) {
|
|
7440
|
-
entry.tool_calls = toolCalls;
|
|
7422
|
+
const textParts = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
7423
|
+
const toolCalls = msg.content.filter((b) => b.type === "tool_use").map((b) => ({
|
|
7424
|
+
id: b.id,
|
|
7425
|
+
type: "function",
|
|
7426
|
+
function: {
|
|
7427
|
+
name: b.name,
|
|
7428
|
+
arguments: JSON.stringify(b.input)
|
|
7441
7429
|
}
|
|
7442
|
-
|
|
7430
|
+
}));
|
|
7431
|
+
const entry = {
|
|
7432
|
+
role: "assistant",
|
|
7433
|
+
content: textParts.length > 0 ? textParts : null
|
|
7434
|
+
};
|
|
7435
|
+
if (toolCalls.length > 0) {
|
|
7436
|
+
entry.tool_calls = toolCalls;
|
|
7443
7437
|
}
|
|
7444
|
-
|
|
7438
|
+
messages.push(entry);
|
|
7439
|
+
} else if (msg.role === "tool") {
|
|
7445
7440
|
for (const block of msg.content) {
|
|
7446
|
-
|
|
7441
|
+
if (block.type !== "tool_result")
|
|
7442
|
+
continue;
|
|
7447
7443
|
let content;
|
|
7448
|
-
if (
|
|
7449
|
-
content =
|
|
7450
|
-
} else
|
|
7444
|
+
if (block.content.length === 1 && block.content[0].type === "text") {
|
|
7445
|
+
content = block.content[0].text;
|
|
7446
|
+
} else {
|
|
7451
7447
|
const parts = [];
|
|
7452
|
-
for (const inner of
|
|
7448
|
+
for (const inner of block.content) {
|
|
7453
7449
|
if (inner.type === "text") {
|
|
7454
7450
|
parts.push({ type: "text", text: inner.text });
|
|
7455
7451
|
} else if (inner.type === "image") {
|
|
@@ -7460,14 +7456,8 @@ function toOpenAIMessages(input) {
|
|
|
7460
7456
|
}
|
|
7461
7457
|
}
|
|
7462
7458
|
content = parts;
|
|
7463
|
-
} else {
|
|
7464
|
-
content = "";
|
|
7465
7459
|
}
|
|
7466
|
-
messages.push({
|
|
7467
|
-
role: "tool",
|
|
7468
|
-
content,
|
|
7469
|
-
tool_call_id: b.tool_use_id
|
|
7470
|
-
});
|
|
7460
|
+
messages.push({ role: "tool", content, tool_call_id: block.tool_use_id });
|
|
7471
7461
|
}
|
|
7472
7462
|
}
|
|
7473
7463
|
}
|
|
@@ -7497,41 +7487,18 @@ function toTextFlatMessages(input) {
|
|
|
7497
7487
|
}
|
|
7498
7488
|
for (const msg of inputMessages) {
|
|
7499
7489
|
if (msg.role === "user") {
|
|
7500
|
-
|
|
7501
|
-
if (typeof msg.content === "string") {
|
|
7502
|
-
content = msg.content;
|
|
7503
|
-
} else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
|
|
7504
|
-
content = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
7505
|
-
} else if (msg.content != null) {
|
|
7506
|
-
try {
|
|
7507
|
-
content = JSON.stringify(msg.content);
|
|
7508
|
-
} catch {
|
|
7509
|
-
content = String(msg.content);
|
|
7510
|
-
}
|
|
7511
|
-
}
|
|
7490
|
+
const content = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
7512
7491
|
messages.push({ role: "user", content });
|
|
7513
7492
|
} else if (msg.role === "assistant") {
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
}
|
|
7518
|
-
} else if (Array.isArray(msg.content)) {
|
|
7519
|
-
const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
7520
|
-
if (text) {
|
|
7521
|
-
messages.push({ role: "assistant", content: text });
|
|
7522
|
-
}
|
|
7493
|
+
const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
7494
|
+
if (text) {
|
|
7495
|
+
messages.push({ role: "assistant", content: text });
|
|
7523
7496
|
}
|
|
7524
|
-
} else if (msg.role === "tool"
|
|
7497
|
+
} else if (msg.role === "tool") {
|
|
7525
7498
|
for (const block of msg.content) {
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
content = b.content;
|
|
7530
|
-
} else if (Array.isArray(b.content)) {
|
|
7531
|
-
content = b.content.filter((inner) => inner.type === "text").map((inner) => inner.text).join("");
|
|
7532
|
-
} else {
|
|
7533
|
-
content = "";
|
|
7534
|
-
}
|
|
7499
|
+
if (block.type !== "tool_result")
|
|
7500
|
+
continue;
|
|
7501
|
+
const content = block.content.filter((inner) => inner.type === "text").map((inner) => inner.text).join("");
|
|
7535
7502
|
messages.push({ role: "tool", content });
|
|
7536
7503
|
}
|
|
7537
7504
|
}
|
|
@@ -7542,7 +7509,7 @@ function toTextFlatMessages(input) {
|
|
|
7542
7509
|
// src/task/index.ts
|
|
7543
7510
|
var registerAiTasks = () => {
|
|
7544
7511
|
const tasks = [
|
|
7545
|
-
|
|
7512
|
+
AiChatTask,
|
|
7546
7513
|
BackgroundRemovalTask,
|
|
7547
7514
|
ChunkToVectorTask,
|
|
7548
7515
|
CountTokensTask,
|
|
@@ -7596,11 +7563,8 @@ var registerAiTasks = () => {
|
|
|
7596
7563
|
export {
|
|
7597
7564
|
vectorStoreSearch,
|
|
7598
7565
|
vectorQuantize,
|
|
7599
|
-
userMessage,
|
|
7600
7566
|
unloadModel,
|
|
7601
7567
|
topicSegmenter,
|
|
7602
|
-
toolSourceDefinitions,
|
|
7603
|
-
toolMessage,
|
|
7604
7568
|
toolCalling,
|
|
7605
7569
|
toTextFlatMessages,
|
|
7606
7570
|
toOpenAIMessages,
|
|
@@ -7609,6 +7573,7 @@ export {
|
|
|
7609
7573
|
textRewriter,
|
|
7610
7574
|
textQuestionAnswer,
|
|
7611
7575
|
textNamedEntityRecognition,
|
|
7576
|
+
textMessage,
|
|
7612
7577
|
textLanguageDetection,
|
|
7613
7578
|
textGeneration,
|
|
7614
7579
|
textFillMask,
|
|
@@ -7630,43 +7595,33 @@ export {
|
|
|
7630
7595
|
modelSearch,
|
|
7631
7596
|
modelInfo,
|
|
7632
7597
|
kbToDocuments,
|
|
7598
|
+
isContentBlock,
|
|
7599
|
+
isChatMessage,
|
|
7633
7600
|
isAllowedToolName,
|
|
7634
7601
|
imageToText,
|
|
7635
7602
|
imageSegmentation,
|
|
7636
7603
|
imageEmbedding,
|
|
7637
7604
|
imageClassification,
|
|
7638
|
-
imageBlockFromDataUri,
|
|
7639
|
-
imageBlock,
|
|
7640
7605
|
hybridSearch,
|
|
7641
7606
|
hierarchyJoin,
|
|
7642
7607
|
hierarchicalChunker,
|
|
7643
|
-
hasToolCalls,
|
|
7644
7608
|
handLandmarker,
|
|
7645
7609
|
getGlobalModelRepository,
|
|
7646
7610
|
getAiProviderRegistry,
|
|
7647
7611
|
gestureRecognizer,
|
|
7648
|
-
findToolSource,
|
|
7649
7612
|
filterValidToolCalls,
|
|
7650
7613
|
faceLandmarker,
|
|
7651
7614
|
faceDetector,
|
|
7652
|
-
executeToolCalls,
|
|
7653
|
-
executeToolCall,
|
|
7654
7615
|
downloadModel,
|
|
7655
7616
|
documentUpsert,
|
|
7656
7617
|
documentEnricher,
|
|
7657
7618
|
countTokens,
|
|
7658
|
-
countAssistantToolUses,
|
|
7659
7619
|
contextBuilder,
|
|
7660
7620
|
chunkVectorUpsert,
|
|
7661
7621
|
chunkToVector,
|
|
7662
7622
|
chunkRetrieval,
|
|
7663
|
-
buildToolSources,
|
|
7664
7623
|
buildToolDescription,
|
|
7665
7624
|
backgroundRemoval,
|
|
7666
|
-
audioBlockFromDataUri,
|
|
7667
|
-
audioBlock,
|
|
7668
|
-
assistantMessage,
|
|
7669
|
-
agent,
|
|
7670
7625
|
VectorSimilarityTask,
|
|
7671
7626
|
VectorQuantizeTask,
|
|
7672
7627
|
UnloadModelTask,
|
|
@@ -7715,6 +7670,7 @@ export {
|
|
|
7715
7670
|
TextClassificationOutputSchema,
|
|
7716
7671
|
TextClassificationInputSchema,
|
|
7717
7672
|
TextChunkerTask,
|
|
7673
|
+
StructuredOutputValidationError,
|
|
7718
7674
|
StructuredGenerationTask,
|
|
7719
7675
|
StructuredGenerationOutputSchema,
|
|
7720
7676
|
StructuredGenerationInputSchema,
|
|
@@ -7778,12 +7734,14 @@ export {
|
|
|
7778
7734
|
CountTokensInputSchema,
|
|
7779
7735
|
ContextFormat,
|
|
7780
7736
|
ContextBuilderTask,
|
|
7737
|
+
ContentBlockSchema,
|
|
7781
7738
|
ChunkingStrategy,
|
|
7782
7739
|
ChunkVectorUpsertTask,
|
|
7783
7740
|
ChunkVectorSearchTask,
|
|
7784
7741
|
ChunkVectorHybridSearchTask,
|
|
7785
7742
|
ChunkToVectorTask,
|
|
7786
7743
|
ChunkRetrievalTask,
|
|
7744
|
+
ChatMessageSchema,
|
|
7787
7745
|
BackgroundRemovalTask,
|
|
7788
7746
|
BackgroundRemovalOutputSchema,
|
|
7789
7747
|
BackgroundRemovalInputSchema,
|
|
@@ -7791,9 +7749,9 @@ export {
|
|
|
7791
7749
|
AiProviderRegistry,
|
|
7792
7750
|
AiProvider,
|
|
7793
7751
|
AiJob,
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7752
|
+
AiChatTask,
|
|
7753
|
+
AiChatOutputSchema,
|
|
7754
|
+
AiChatInputSchema
|
|
7797
7755
|
};
|
|
7798
7756
|
|
|
7799
|
-
//# debugId=
|
|
7757
|
+
//# debugId=CA8AB8D417D38A5264756E2164756E21
|