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