@workglow/ai 0.0.104 → 0.0.106
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 +185 -19
- package/dist/browser.js.map +5 -4
- package/dist/bun.js +185 -19
- package/dist/bun.js.map +5 -4
- package/dist/node.js +185 -19
- package/dist/node.js.map +5 -4
- package/dist/task/ToolCallingTask.d.ts +235 -0
- package/dist/task/ToolCallingTask.d.ts.map +1 -0
- package/dist/task/index.d.ts +3 -1
- package/dist/task/index.d.ts.map +1 -1
- package/package.json +11 -11
package/dist/node.js
CHANGED
|
@@ -419,7 +419,7 @@ class AiProvider {
|
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
// src/task/index.ts
|
|
422
|
-
import { TaskRegistry } from "@workglow/task-graph";
|
|
422
|
+
import { TaskRegistry as TaskRegistry2 } from "@workglow/task-graph";
|
|
423
423
|
|
|
424
424
|
// src/task/BackgroundRemovalTask.ts
|
|
425
425
|
import { CreateWorkflow, Workflow } from "@workglow/task-graph";
|
|
@@ -5200,9 +5200,166 @@ var textRewriter = (input, config) => {
|
|
|
5200
5200
|
};
|
|
5201
5201
|
Workflow36.prototype.textRewriter = CreateWorkflow36(TextRewriterTask);
|
|
5202
5202
|
|
|
5203
|
+
// src/task/ToolCallingTask.ts
|
|
5204
|
+
import { CreateWorkflow as CreateWorkflow37, TaskRegistry, Workflow as Workflow37 } from "@workglow/task-graph";
|
|
5205
|
+
import { getLogger } from "@workglow/util";
|
|
5206
|
+
function buildToolDescription(tool) {
|
|
5207
|
+
let desc = tool.description;
|
|
5208
|
+
if (tool.outputSchema && typeof tool.outputSchema === "object") {
|
|
5209
|
+
desc += `
|
|
5210
|
+
|
|
5211
|
+
Returns: ${JSON.stringify(tool.outputSchema)}`;
|
|
5212
|
+
}
|
|
5213
|
+
return desc;
|
|
5214
|
+
}
|
|
5215
|
+
function isAllowedToolName(name, allowedTools) {
|
|
5216
|
+
return allowedTools.some((t) => t.name === name);
|
|
5217
|
+
}
|
|
5218
|
+
function filterValidToolCalls(toolCalls, allowedTools) {
|
|
5219
|
+
const filtered = {};
|
|
5220
|
+
for (const [key, value] of Object.entries(toolCalls)) {
|
|
5221
|
+
const tc = value;
|
|
5222
|
+
if (tc.name && isAllowedToolName(tc.name, allowedTools)) {
|
|
5223
|
+
filtered[key] = value;
|
|
5224
|
+
} else {
|
|
5225
|
+
getLogger().warn(`Filtered out tool call with unknown name "${tc.name ?? "(missing)"}"`, {
|
|
5226
|
+
callId: key,
|
|
5227
|
+
toolName: tc.name
|
|
5228
|
+
});
|
|
5229
|
+
}
|
|
5230
|
+
}
|
|
5231
|
+
return filtered;
|
|
5232
|
+
}
|
|
5233
|
+
function taskTypesToTools(taskNames) {
|
|
5234
|
+
return taskNames.map((name) => {
|
|
5235
|
+
const ctor = TaskRegistry.all.get(name);
|
|
5236
|
+
if (!ctor) {
|
|
5237
|
+
throw new Error(`taskTypesToTools: Unknown task type "${name}" — not found in TaskRegistry`);
|
|
5238
|
+
}
|
|
5239
|
+
return {
|
|
5240
|
+
name: ctor.type,
|
|
5241
|
+
description: ctor.description ?? "",
|
|
5242
|
+
inputSchema: ctor.inputSchema(),
|
|
5243
|
+
outputSchema: ctor.outputSchema()
|
|
5244
|
+
};
|
|
5245
|
+
});
|
|
5246
|
+
}
|
|
5247
|
+
var ToolDefinitionSchema = {
|
|
5248
|
+
type: "object",
|
|
5249
|
+
properties: {
|
|
5250
|
+
name: {
|
|
5251
|
+
type: "string",
|
|
5252
|
+
title: "Name",
|
|
5253
|
+
description: "The tool name"
|
|
5254
|
+
},
|
|
5255
|
+
description: {
|
|
5256
|
+
type: "string",
|
|
5257
|
+
title: "Description",
|
|
5258
|
+
description: "A description of what the tool does"
|
|
5259
|
+
},
|
|
5260
|
+
inputSchema: {
|
|
5261
|
+
type: "object",
|
|
5262
|
+
title: "Input Schema",
|
|
5263
|
+
description: "JSON Schema describing the tool's input parameters",
|
|
5264
|
+
additionalProperties: true
|
|
5265
|
+
},
|
|
5266
|
+
outputSchema: {
|
|
5267
|
+
type: "object",
|
|
5268
|
+
title: "Output Schema",
|
|
5269
|
+
description: "JSON Schema describing what the tool returns",
|
|
5270
|
+
additionalProperties: true
|
|
5271
|
+
}
|
|
5272
|
+
},
|
|
5273
|
+
required: ["name", "description", "inputSchema"],
|
|
5274
|
+
additionalProperties: false
|
|
5275
|
+
};
|
|
5276
|
+
var modelSchema26 = TypeModel("model:ToolCallingTask");
|
|
5277
|
+
var ToolCallingInputSchema = {
|
|
5278
|
+
type: "object",
|
|
5279
|
+
properties: {
|
|
5280
|
+
model: modelSchema26,
|
|
5281
|
+
prompt: {
|
|
5282
|
+
type: "string",
|
|
5283
|
+
title: "Prompt",
|
|
5284
|
+
description: "The prompt to send to the model"
|
|
5285
|
+
},
|
|
5286
|
+
systemPrompt: {
|
|
5287
|
+
type: "string",
|
|
5288
|
+
title: "System Prompt",
|
|
5289
|
+
description: "Optional system instructions for the model"
|
|
5290
|
+
},
|
|
5291
|
+
tools: {
|
|
5292
|
+
type: "array",
|
|
5293
|
+
title: "Tools",
|
|
5294
|
+
description: "Tool definitions available for the model to call",
|
|
5295
|
+
items: ToolDefinitionSchema
|
|
5296
|
+
},
|
|
5297
|
+
toolChoice: {
|
|
5298
|
+
type: "string",
|
|
5299
|
+
title: "Tool Choice",
|
|
5300
|
+
description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
|
|
5301
|
+
"x-ui-group": "Configuration"
|
|
5302
|
+
},
|
|
5303
|
+
maxTokens: {
|
|
5304
|
+
type: "number",
|
|
5305
|
+
title: "Max Tokens",
|
|
5306
|
+
description: "The maximum number of tokens to generate",
|
|
5307
|
+
minimum: 1,
|
|
5308
|
+
"x-ui-group": "Configuration"
|
|
5309
|
+
},
|
|
5310
|
+
temperature: {
|
|
5311
|
+
type: "number",
|
|
5312
|
+
title: "Temperature",
|
|
5313
|
+
description: "The temperature to use for sampling",
|
|
5314
|
+
minimum: 0,
|
|
5315
|
+
maximum: 2,
|
|
5316
|
+
"x-ui-group": "Configuration"
|
|
5317
|
+
}
|
|
5318
|
+
},
|
|
5319
|
+
required: ["model", "prompt", "tools"],
|
|
5320
|
+
additionalProperties: false
|
|
5321
|
+
};
|
|
5322
|
+
var ToolCallingOutputSchema = {
|
|
5323
|
+
type: "object",
|
|
5324
|
+
properties: {
|
|
5325
|
+
text: {
|
|
5326
|
+
type: "string",
|
|
5327
|
+
title: "Text",
|
|
5328
|
+
description: "Any text content generated by the model",
|
|
5329
|
+
"x-stream": "append"
|
|
5330
|
+
},
|
|
5331
|
+
toolCalls: {
|
|
5332
|
+
type: "object",
|
|
5333
|
+
title: "Tool Calls",
|
|
5334
|
+
description: "Tool invocations requested by the model, keyed by call id",
|
|
5335
|
+
additionalProperties: true,
|
|
5336
|
+
"x-stream": "object"
|
|
5337
|
+
}
|
|
5338
|
+
},
|
|
5339
|
+
required: ["text", "toolCalls"],
|
|
5340
|
+
additionalProperties: false
|
|
5341
|
+
};
|
|
5342
|
+
|
|
5343
|
+
class ToolCallingTask extends StreamingAiTask {
|
|
5344
|
+
static type = "ToolCallingTask";
|
|
5345
|
+
static category = "AI Text Model";
|
|
5346
|
+
static title = "Tool Calling";
|
|
5347
|
+
static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
|
|
5348
|
+
static inputSchema() {
|
|
5349
|
+
return ToolCallingInputSchema;
|
|
5350
|
+
}
|
|
5351
|
+
static outputSchema() {
|
|
5352
|
+
return ToolCallingOutputSchema;
|
|
5353
|
+
}
|
|
5354
|
+
}
|
|
5355
|
+
var toolCalling = (input, config) => {
|
|
5356
|
+
return new ToolCallingTask({}, config).run(input);
|
|
5357
|
+
};
|
|
5358
|
+
Workflow37.prototype.toolCalling = CreateWorkflow37(ToolCallingTask);
|
|
5359
|
+
|
|
5203
5360
|
// src/task/TextTranslationTask.ts
|
|
5204
|
-
import { CreateWorkflow as
|
|
5205
|
-
var
|
|
5361
|
+
import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
|
|
5362
|
+
var modelSchema27 = TypeModel("model:TextTranslationTask");
|
|
5206
5363
|
var translationTextSchema = {
|
|
5207
5364
|
type: "string",
|
|
5208
5365
|
title: "Text",
|
|
@@ -5229,7 +5386,7 @@ var TextTranslationInputSchema = {
|
|
|
5229
5386
|
minLength: 2,
|
|
5230
5387
|
maxLength: 2
|
|
5231
5388
|
}),
|
|
5232
|
-
model:
|
|
5389
|
+
model: modelSchema27
|
|
5233
5390
|
},
|
|
5234
5391
|
required: ["text", "source_lang", "target_lang", "model"],
|
|
5235
5392
|
additionalProperties: false
|
|
@@ -5264,13 +5421,13 @@ class TextTranslationTask extends StreamingAiTask {
|
|
|
5264
5421
|
var textTranslation = (input, config) => {
|
|
5265
5422
|
return new TextTranslationTask({}, config).run(input);
|
|
5266
5423
|
};
|
|
5267
|
-
|
|
5424
|
+
Workflow38.prototype.textTranslation = CreateWorkflow38(TextTranslationTask);
|
|
5268
5425
|
|
|
5269
5426
|
// src/task/TopicSegmenterTask.ts
|
|
5270
5427
|
import {
|
|
5271
|
-
CreateWorkflow as
|
|
5428
|
+
CreateWorkflow as CreateWorkflow39,
|
|
5272
5429
|
Task as Task14,
|
|
5273
|
-
Workflow as
|
|
5430
|
+
Workflow as Workflow39
|
|
5274
5431
|
} from "@workglow/task-graph";
|
|
5275
5432
|
var SegmentationMethod = {
|
|
5276
5433
|
HEURISTIC: "heuristic",
|
|
@@ -5551,15 +5708,15 @@ class TopicSegmenterTask extends Task14 {
|
|
|
5551
5708
|
var topicSegmenter = (input, config) => {
|
|
5552
5709
|
return new TopicSegmenterTask({}, config).run(input);
|
|
5553
5710
|
};
|
|
5554
|
-
|
|
5711
|
+
Workflow39.prototype.topicSegmenter = CreateWorkflow39(TopicSegmenterTask);
|
|
5555
5712
|
|
|
5556
5713
|
// src/task/UnloadModelTask.ts
|
|
5557
|
-
import { CreateWorkflow as
|
|
5558
|
-
var
|
|
5714
|
+
import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
|
|
5715
|
+
var modelSchema28 = TypeModel("model");
|
|
5559
5716
|
var UnloadModelInputSchema = {
|
|
5560
5717
|
type: "object",
|
|
5561
5718
|
properties: {
|
|
5562
|
-
model:
|
|
5719
|
+
model: modelSchema28
|
|
5563
5720
|
},
|
|
5564
5721
|
required: ["model"],
|
|
5565
5722
|
additionalProperties: false
|
|
@@ -5567,7 +5724,7 @@ var UnloadModelInputSchema = {
|
|
|
5567
5724
|
var UnloadModelOutputSchema = {
|
|
5568
5725
|
type: "object",
|
|
5569
5726
|
properties: {
|
|
5570
|
-
model:
|
|
5727
|
+
model: modelSchema28
|
|
5571
5728
|
},
|
|
5572
5729
|
required: ["model"],
|
|
5573
5730
|
additionalProperties: false
|
|
@@ -5589,10 +5746,10 @@ class UnloadModelTask extends AiTask {
|
|
|
5589
5746
|
var unloadModel = (input, config) => {
|
|
5590
5747
|
return new UnloadModelTask({}, config).run(input);
|
|
5591
5748
|
};
|
|
5592
|
-
|
|
5749
|
+
Workflow40.prototype.unloadModel = CreateWorkflow40(UnloadModelTask);
|
|
5593
5750
|
|
|
5594
5751
|
// src/task/VectorQuantizeTask.ts
|
|
5595
|
-
import { CreateWorkflow as
|
|
5752
|
+
import { CreateWorkflow as CreateWorkflow41, Task as Task15, Workflow as Workflow41 } from "@workglow/task-graph";
|
|
5596
5753
|
import {
|
|
5597
5754
|
normalizeNumberArray,
|
|
5598
5755
|
TensorType,
|
|
@@ -5772,10 +5929,10 @@ class VectorQuantizeTask extends Task15 {
|
|
|
5772
5929
|
var vectorQuantize = (input, config) => {
|
|
5773
5930
|
return new VectorQuantizeTask({}, config).run(input);
|
|
5774
5931
|
};
|
|
5775
|
-
|
|
5932
|
+
Workflow41.prototype.vectorQuantize = CreateWorkflow41(VectorQuantizeTask);
|
|
5776
5933
|
|
|
5777
5934
|
// src/task/VectorSimilarityTask.ts
|
|
5778
|
-
import { CreateWorkflow as
|
|
5935
|
+
import { CreateWorkflow as CreateWorkflow42, GraphAsTask, Workflow as Workflow42 } from "@workglow/task-graph";
|
|
5779
5936
|
import {
|
|
5780
5937
|
cosineSimilarity,
|
|
5781
5938
|
hammingSimilarity,
|
|
@@ -5881,7 +6038,7 @@ class VectorSimilarityTask extends GraphAsTask {
|
|
|
5881
6038
|
var similarity = (input, config) => {
|
|
5882
6039
|
return new VectorSimilarityTask({}, config).run(input);
|
|
5883
6040
|
};
|
|
5884
|
-
|
|
6041
|
+
Workflow42.prototype.similarity = CreateWorkflow42(VectorSimilarityTask);
|
|
5885
6042
|
|
|
5886
6043
|
// src/task/index.ts
|
|
5887
6044
|
var registerAiTasks = () => {
|
|
@@ -5923,12 +6080,13 @@ var registerAiTasks = () => {
|
|
|
5923
6080
|
TextRewriterTask,
|
|
5924
6081
|
TextSummaryTask,
|
|
5925
6082
|
TextTranslationTask,
|
|
6083
|
+
ToolCallingTask,
|
|
5926
6084
|
TopicSegmenterTask,
|
|
5927
6085
|
UnloadModelTask,
|
|
5928
6086
|
VectorQuantizeTask,
|
|
5929
6087
|
VectorSimilarityTask
|
|
5930
6088
|
];
|
|
5931
|
-
tasks.map(
|
|
6089
|
+
tasks.map(TaskRegistry2.registerTask);
|
|
5932
6090
|
return tasks;
|
|
5933
6091
|
};
|
|
5934
6092
|
export {
|
|
@@ -5936,6 +6094,7 @@ export {
|
|
|
5936
6094
|
vectorQuantize,
|
|
5937
6095
|
unloadModel,
|
|
5938
6096
|
topicSegmenter,
|
|
6097
|
+
toolCalling,
|
|
5939
6098
|
textTranslation,
|
|
5940
6099
|
textSummary,
|
|
5941
6100
|
textRewriter,
|
|
@@ -5947,6 +6106,7 @@ export {
|
|
|
5947
6106
|
textEmbedding,
|
|
5948
6107
|
textClassification,
|
|
5949
6108
|
textChunker,
|
|
6109
|
+
taskTypesToTools,
|
|
5950
6110
|
structuredGeneration,
|
|
5951
6111
|
structuralParser,
|
|
5952
6112
|
similarity,
|
|
@@ -5957,6 +6117,7 @@ export {
|
|
|
5957
6117
|
queryExpander,
|
|
5958
6118
|
poseLandmarker,
|
|
5959
6119
|
objectDetection,
|
|
6120
|
+
isAllowedToolName,
|
|
5960
6121
|
imageToText,
|
|
5961
6122
|
imageSegmentation,
|
|
5962
6123
|
imageEmbedding,
|
|
@@ -5968,6 +6129,7 @@ export {
|
|
|
5968
6129
|
getGlobalModelRepository,
|
|
5969
6130
|
getAiProviderRegistry,
|
|
5970
6131
|
gestureRecognizer,
|
|
6132
|
+
filterValidToolCalls,
|
|
5971
6133
|
faceLandmarker,
|
|
5972
6134
|
faceDetector,
|
|
5973
6135
|
downloadModel,
|
|
@@ -5977,6 +6139,7 @@ export {
|
|
|
5977
6139
|
chunkVectorUpsert,
|
|
5978
6140
|
chunkToVector,
|
|
5979
6141
|
chunkRetrieval,
|
|
6142
|
+
buildToolDescription,
|
|
5980
6143
|
backgroundRemoval,
|
|
5981
6144
|
VectorSimilarityTask,
|
|
5982
6145
|
VectorQuantizeTask,
|
|
@@ -5991,6 +6154,9 @@ export {
|
|
|
5991
6154
|
TypeBoundingBox,
|
|
5992
6155
|
TypeAudioInput,
|
|
5993
6156
|
TopicSegmenterTask,
|
|
6157
|
+
ToolCallingTask,
|
|
6158
|
+
ToolCallingOutputSchema,
|
|
6159
|
+
ToolCallingInputSchema,
|
|
5994
6160
|
TextTranslationTask,
|
|
5995
6161
|
TextTranslationOutputSchema,
|
|
5996
6162
|
TextTranslationInputSchema,
|
|
@@ -6092,4 +6258,4 @@ export {
|
|
|
6092
6258
|
AiJob
|
|
6093
6259
|
};
|
|
6094
6260
|
|
|
6095
|
-
//# debugId=
|
|
6261
|
+
//# debugId=BBE56DE7C6A6386364756E2164756E21
|