@workglow/ai 0.0.102 → 0.0.104

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.
Files changed (84) hide show
  1. package/dist/browser.js +152 -50
  2. package/dist/browser.js.map +11 -10
  3. package/dist/bun.js +152 -50
  4. package/dist/bun.js.map +11 -10
  5. package/dist/job/AiJob.d.ts +3 -0
  6. package/dist/job/AiJob.d.ts.map +1 -1
  7. package/dist/model/ModelRepository.d.ts +2 -0
  8. package/dist/model/ModelRepository.d.ts.map +1 -1
  9. package/dist/model/ModelSchema.d.ts +16 -0
  10. package/dist/model/ModelSchema.d.ts.map +1 -1
  11. package/dist/node.js +152 -50
  12. package/dist/node.js.map +11 -10
  13. package/dist/provider/AiProviderRegistry.d.ts +9 -3
  14. package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
  15. package/dist/task/BackgroundRemovalTask.d.ts +8 -0
  16. package/dist/task/BackgroundRemovalTask.d.ts.map +1 -1
  17. package/dist/task/ChunkRetrievalTask.d.ts +8 -0
  18. package/dist/task/ChunkRetrievalTask.d.ts.map +1 -1
  19. package/dist/task/ChunkToVectorTask.d.ts +5 -0
  20. package/dist/task/ChunkToVectorTask.d.ts.map +1 -1
  21. package/dist/task/ContextBuilderTask.d.ts +8 -0
  22. package/dist/task/ContextBuilderTask.d.ts.map +1 -1
  23. package/dist/task/CountTokensTask.d.ts +8 -0
  24. package/dist/task/CountTokensTask.d.ts.map +1 -1
  25. package/dist/task/DocumentEnricherTask.d.ts +16 -0
  26. package/dist/task/DocumentEnricherTask.d.ts.map +1 -1
  27. package/dist/task/DownloadModelTask.d.ts +17 -0
  28. package/dist/task/DownloadModelTask.d.ts.map +1 -1
  29. package/dist/task/FaceDetectorTask.d.ts +8 -0
  30. package/dist/task/FaceDetectorTask.d.ts.map +1 -1
  31. package/dist/task/FaceLandmarkerTask.d.ts +8 -0
  32. package/dist/task/FaceLandmarkerTask.d.ts.map +1 -1
  33. package/dist/task/GestureRecognizerTask.d.ts +8 -0
  34. package/dist/task/GestureRecognizerTask.d.ts.map +1 -1
  35. package/dist/task/HandLandmarkerTask.d.ts +8 -0
  36. package/dist/task/HandLandmarkerTask.d.ts.map +1 -1
  37. package/dist/task/HierarchicalChunkerTask.d.ts +8 -0
  38. package/dist/task/HierarchicalChunkerTask.d.ts.map +1 -1
  39. package/dist/task/ImageClassificationTask.d.ts +8 -0
  40. package/dist/task/ImageClassificationTask.d.ts.map +1 -1
  41. package/dist/task/ImageEmbeddingTask.d.ts +8 -0
  42. package/dist/task/ImageEmbeddingTask.d.ts.map +1 -1
  43. package/dist/task/ImageSegmentationTask.d.ts +8 -0
  44. package/dist/task/ImageSegmentationTask.d.ts.map +1 -1
  45. package/dist/task/ImageToTextTask.d.ts +8 -0
  46. package/dist/task/ImageToTextTask.d.ts.map +1 -1
  47. package/dist/task/ObjectDetectionTask.d.ts +8 -0
  48. package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
  49. package/dist/task/PoseLandmarkerTask.d.ts +8 -0
  50. package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
  51. package/dist/task/RerankerTask.d.ts +8 -0
  52. package/dist/task/RerankerTask.d.ts.map +1 -1
  53. package/dist/task/StructuredGenerationTask.d.ts +138 -0
  54. package/dist/task/StructuredGenerationTask.d.ts.map +1 -0
  55. package/dist/task/TextClassificationTask.d.ts +8 -0
  56. package/dist/task/TextClassificationTask.d.ts.map +1 -1
  57. package/dist/task/TextEmbeddingTask.d.ts +8 -0
  58. package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
  59. package/dist/task/TextFillMaskTask.d.ts +8 -0
  60. package/dist/task/TextFillMaskTask.d.ts.map +1 -1
  61. package/dist/task/TextGenerationTask.d.ts +8 -0
  62. package/dist/task/TextGenerationTask.d.ts.map +1 -1
  63. package/dist/task/TextLanguageDetectionTask.d.ts +8 -0
  64. package/dist/task/TextLanguageDetectionTask.d.ts.map +1 -1
  65. package/dist/task/TextNamedEntityRecognitionTask.d.ts +8 -0
  66. package/dist/task/TextNamedEntityRecognitionTask.d.ts.map +1 -1
  67. package/dist/task/TextQuestionAnswerTask.d.ts +8 -0
  68. package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
  69. package/dist/task/TextRewriterTask.d.ts +8 -0
  70. package/dist/task/TextRewriterTask.d.ts.map +1 -1
  71. package/dist/task/TextSummaryTask.d.ts +8 -0
  72. package/dist/task/TextSummaryTask.d.ts.map +1 -1
  73. package/dist/task/TextTranslationTask.d.ts +8 -0
  74. package/dist/task/TextTranslationTask.d.ts.map +1 -1
  75. package/dist/task/UnloadModelTask.d.ts +17 -0
  76. package/dist/task/UnloadModelTask.d.ts.map +1 -1
  77. package/dist/task/base/AiTask.d.ts.map +1 -1
  78. package/dist/task/base/AiTaskSchemas.d.ts +16 -0
  79. package/dist/task/base/AiTaskSchemas.d.ts.map +1 -1
  80. package/dist/task/base/StreamingAiTask.d.ts +4 -3
  81. package/dist/task/base/StreamingAiTask.d.ts.map +1 -1
  82. package/dist/task/index.d.ts +3 -1
  83. package/dist/task/index.d.ts.map +1 -1
  84. package/package.json +11 -11
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { IJobExecuteContext, Job } from "@workglow/job-queue";
7
7
  import { TaskInput, TaskOutput, type StreamEvent } from "@workglow/task-graph";
8
+ import type { JsonSchema } from "@workglow/util";
8
9
  import type { ModelConfig } from "../model/ModelSchema";
9
10
  /**
10
11
  * Input data for the AiJob
@@ -15,6 +16,8 @@ export interface AiJobInput<Input extends TaskInput = TaskInput> {
15
16
  taskInput: Input & {
16
17
  model: ModelConfig;
17
18
  };
19
+ /** JSON Schema for structured output, when the task declares x-structured-output. */
20
+ outputSchema?: JsonSchema;
18
21
  }
19
22
  /**
20
23
  * Extends the base Job class to provide custom execution functionality
@@ -1 +1 @@
1
- {"version":3,"file":"AiJob.d.ts","sourceRoot":"","sources":["../../src/job/AiJob.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,kBA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AAK,SAAS,SAAS,GAAG,SAAS;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,KAAK,GAAG;QAAE,KAAK,EAAE,WAAW,CAAA;KAAE,CAAC;IAC1C,qFAAqF;IACrF,YAAY,CAAC,EAAE,UAAU,CAAC;CAC3B;AAED;;;GAGG;AACH,qBAAa,KAAK,CAChB,KAAK,SAAS,UAAU,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,EAC3D,MAAM,SAAS,UAAU,GAAG,UAAU,CACtC,SAAQ,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACG,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAkDzE;;;OAGG;IACI,aAAa,CAClB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,kBAAkB,GAC1B,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;CAmBtC"}
@@ -71,6 +71,7 @@ export declare class ModelRepository {
71
71
  provider: string;
72
72
  provider_config: {
73
73
  [x: string]: unknown;
74
+ credential_key?: string | undefined;
74
75
  };
75
76
  metadata: {
76
77
  [x: string]: unknown;
@@ -94,6 +95,7 @@ export declare class ModelRepository {
94
95
  provider: string;
95
96
  provider_config: {
96
97
  [x: string]: unknown;
98
+ credential_key?: string | undefined;
97
99
  };
98
100
  metadata: {
99
101
  [x: string]: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"ModelRepository.d.ts","sourceRoot":"","sources":["../../src/model/ModelRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,iBAAiB,EAAE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kBAAkB,IAAI,OAAO,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC;IAM9D;;;;OAIG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAMpE;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;CAG9B"}
@@ -36,6 +36,14 @@ export declare const ModelConfigSchema: {
36
36
  };
37
37
  readonly provider_config: {
38
38
  readonly type: "object";
39
+ readonly properties: {
40
+ readonly credential_key: {
41
+ readonly type: "string";
42
+ readonly format: "credential";
43
+ readonly "x-ui-hidden": true;
44
+ };
45
+ };
46
+ readonly additionalProperties: true;
39
47
  readonly default: {};
40
48
  };
41
49
  readonly metadata: {
@@ -76,6 +84,14 @@ export declare const ModelRecordSchema: {
76
84
  };
77
85
  readonly provider_config: {
78
86
  readonly type: "object";
87
+ readonly properties: {
88
+ readonly credential_key: {
89
+ readonly type: "string";
90
+ readonly format: "credential";
91
+ readonly "x-ui-hidden": true;
92
+ };
93
+ };
94
+ readonly additionalProperties: true;
79
95
  readonly default: {};
80
96
  };
81
97
  readonly metadata: {
@@ -1 +1 @@
1
- {"version":3,"file":"ModelSchema.d.ts","sourceRoot":"","sources":["../../src/model/ModelSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAwB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAElE;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAcW,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBW,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC/D,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC/D,eAAO,MAAM,oBAAoB,uBAAwB,CAAC"}
1
+ {"version":3,"file":"ModelSchema.d.ts","sourceRoot":"","sources":["../../src/model/ModelSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAwB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAElE;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqBW,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBW,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC/D,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC/D,eAAO,MAAM,oBAAoB,uBAAwB,CAAC"}
package/dist/node.js CHANGED
@@ -30,9 +30,9 @@ class AiProviderRegistry {
30
30
  this.runFnRegistry.get(taskType).set(modelProvider, runFn);
31
31
  }
32
32
  registerAsWorkerRunFn(modelProvider, taskType) {
33
- const workerFn = async (input, model, update_progress, signal) => {
33
+ const workerFn = async (input, model, update_progress, signal, outputSchema) => {
34
34
  const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
35
- const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model], {
35
+ const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema], {
36
36
  signal,
37
37
  onProgress: update_progress
38
38
  });
@@ -47,9 +47,9 @@ class AiProviderRegistry {
47
47
  this.streamFnRegistry.get(taskType).set(modelProvider, streamFn);
48
48
  }
49
49
  registerAsWorkerStreamFn(modelProvider, taskType) {
50
- const streamFn = async function* (input, model, signal) {
50
+ const streamFn = async function* (input, model, signal, outputSchema) {
51
51
  const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
52
- yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model], { signal });
52
+ yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema], { signal });
53
53
  };
54
54
  this.registerStreamFn(modelProvider, taskType, streamFn);
55
55
  }
@@ -121,7 +121,7 @@ class AiJob extends Job {
121
121
  if (context.signal?.aborted) {
122
122
  throw new AbortSignalJobError("Job aborted");
123
123
  }
124
- return await fn(input.taskInput, model, context.updateProgress, context.signal);
124
+ return await fn(input.taskInput, model, context.updateProgress, context.signal, input.outputSchema);
125
125
  };
126
126
  const runFnPromise = runFn();
127
127
  return await Promise.race([runFnPromise, abortPromise]);
@@ -142,7 +142,7 @@ class AiJob extends Job {
142
142
  return;
143
143
  }
144
144
  const model = input.taskInput.model;
145
- yield* streamFn(input.taskInput, model, context.signal);
145
+ yield* streamFn(input.taskInput, model, context.signal, input.outputSchema);
146
146
  }
147
147
  }
148
148
  // src/model/InMemoryModelRepository.ts
@@ -244,7 +244,14 @@ var ModelConfigSchema = {
244
244
  title: { type: "string" },
245
245
  description: { type: "string", "x-ui-editor": "textarea" },
246
246
  provider: { type: "string" },
247
- provider_config: { type: "object", default: {} },
247
+ provider_config: {
248
+ type: "object",
249
+ properties: {
250
+ credential_key: { type: "string", format: "credential", "x-ui-hidden": true }
251
+ },
252
+ additionalProperties: true,
253
+ default: {}
254
+ },
248
255
  metadata: { type: "object", default: {}, "x-ui-hidden": true }
249
256
  },
250
257
  required: ["provider", "provider_config"],
@@ -580,7 +587,8 @@ import { convertImageDataToUseableForm } from "@workglow/util";
580
587
  // src/task/base/AiTask.ts
581
588
  import {
582
589
  JobQueueTask,
583
- TaskConfigurationError
590
+ TaskConfigurationError,
591
+ hasStructuredOutput
584
592
  } from "@workglow/task-graph";
585
593
  function schemaFormat(schema) {
586
594
  return typeof schema === "object" && schema !== null && "format" in schema ? schema.format : undefined;
@@ -599,11 +607,21 @@ class AiTask extends JobQueueTask {
599
607
  throw new TaskConfigurationError("AiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
600
608
  }
601
609
  const runtype = this.constructor.runtype ?? this.constructor.type;
602
- return {
610
+ const jobInput = {
603
611
  taskType: runtype,
604
612
  aiProvider: model.provider,
605
613
  taskInput: input
606
614
  };
615
+ const inputOutputSchema = input.outputSchema;
616
+ if (inputOutputSchema && typeof inputOutputSchema === "object") {
617
+ jobInput.outputSchema = inputOutputSchema;
618
+ } else {
619
+ const taskOutputSchema = this.outputSchema();
620
+ if (hasStructuredOutput(taskOutputSchema)) {
621
+ jobInput.outputSchema = taskOutputSchema;
622
+ }
623
+ }
624
+ return jobInput;
607
625
  }
608
626
  async createJob(input, queueName) {
609
627
  const jobInput = await this.getJobInput(input);
@@ -1017,6 +1035,11 @@ var inputSchema2 = {
1017
1035
  title: "Document ID",
1018
1036
  description: "The document ID"
1019
1037
  },
1038
+ doc_title: {
1039
+ type: "string",
1040
+ title: "Document Title",
1041
+ description: "Human-readable title for the source document"
1042
+ },
1020
1043
  chunks: {
1021
1044
  type: "array",
1022
1045
  items: ChunkNodeSchema(),
@@ -1088,7 +1111,7 @@ class ChunkToVectorTask extends Task2 {
1088
1111
  return outputSchema2;
1089
1112
  }
1090
1113
  async execute(input, context) {
1091
- const { chunks, vectors } = input;
1114
+ const { chunks, vectors, doc_title } = input;
1092
1115
  const chunkArray = chunks;
1093
1116
  if (!chunkArray || !vectors) {
1094
1117
  throw new Error("Both chunks and vector are required");
@@ -1110,6 +1133,7 @@ class ChunkToVectorTask extends Task2 {
1110
1133
  depth: chunk.depth,
1111
1134
  text: chunk.text,
1112
1135
  nodePath: chunk.nodePath,
1136
+ ...doc_title ? { doc_title } : {},
1113
1137
  ...chunk.enrichment || {}
1114
1138
  });
1115
1139
  }
@@ -2011,6 +2035,8 @@ class StreamingAiTask extends AiTask {
2011
2035
  })) {
2012
2036
  if (event.type === "text-delta") {
2013
2037
  yield { ...event, port: event.port ?? defaultPort };
2038
+ } else if (event.type === "object-delta") {
2039
+ yield { ...event, port: event.port ?? defaultPort };
2014
2040
  } else {
2015
2041
  yield event;
2016
2042
  }
@@ -4513,11 +4539,82 @@ var structuralParser = (input, config) => {
4513
4539
  };
4514
4540
  Workflow29.prototype.structuralParser = CreateWorkflow29(StructuralParserTask);
4515
4541
 
4542
+ // src/task/StructuredGenerationTask.ts
4543
+ import { CreateWorkflow as CreateWorkflow30, Workflow as Workflow30 } from "@workglow/task-graph";
4544
+ var modelSchema20 = TypeModel("model:StructuredGenerationTask");
4545
+ var StructuredGenerationInputSchema = {
4546
+ type: "object",
4547
+ properties: {
4548
+ model: modelSchema20,
4549
+ prompt: {
4550
+ type: "string",
4551
+ title: "Prompt",
4552
+ description: "The prompt to generate structured output from"
4553
+ },
4554
+ outputSchema: {
4555
+ type: "object",
4556
+ title: "Output Schema",
4557
+ description: "JSON Schema describing the desired output structure",
4558
+ additionalProperties: true
4559
+ },
4560
+ maxTokens: {
4561
+ type: "number",
4562
+ title: "Max Tokens",
4563
+ description: "The maximum number of tokens to generate",
4564
+ minimum: 1,
4565
+ maximum: 4096,
4566
+ "x-ui-group": "Configuration"
4567
+ },
4568
+ temperature: {
4569
+ type: "number",
4570
+ title: "Temperature",
4571
+ description: "The temperature to use for sampling",
4572
+ minimum: 0,
4573
+ maximum: 2,
4574
+ "x-ui-group": "Configuration"
4575
+ }
4576
+ },
4577
+ required: ["model", "prompt", "outputSchema"],
4578
+ additionalProperties: false
4579
+ };
4580
+ var StructuredGenerationOutputSchema = {
4581
+ type: "object",
4582
+ properties: {
4583
+ object: {
4584
+ type: "object",
4585
+ title: "Structured Output",
4586
+ description: "The generated structured object conforming to the provided schema",
4587
+ "x-stream": "object",
4588
+ "x-structured-output": true,
4589
+ additionalProperties: true
4590
+ }
4591
+ },
4592
+ required: ["object"],
4593
+ additionalProperties: false
4594
+ };
4595
+
4596
+ class StructuredGenerationTask extends StreamingAiTask {
4597
+ static type = "StructuredGenerationTask";
4598
+ static category = "AI Text Model";
4599
+ static title = "Structured Generation";
4600
+ static description = "Generates structured JSON output conforming to a provided schema using language models";
4601
+ static inputSchema() {
4602
+ return StructuredGenerationInputSchema;
4603
+ }
4604
+ static outputSchema() {
4605
+ return StructuredGenerationOutputSchema;
4606
+ }
4607
+ }
4608
+ var structuredGeneration = (input, config) => {
4609
+ return new StructuredGenerationTask({}, config).run(input);
4610
+ };
4611
+ Workflow30.prototype.structuredGeneration = CreateWorkflow30(StructuredGenerationTask);
4612
+
4516
4613
  // src/task/TextChunkerTask.ts
4517
4614
  import {
4518
- CreateWorkflow as CreateWorkflow30,
4615
+ CreateWorkflow as CreateWorkflow31,
4519
4616
  Task as Task13,
4520
- Workflow as Workflow30
4617
+ Workflow as Workflow31
4521
4618
  } from "@workglow/task-graph";
4522
4619
  var ChunkingStrategy = {
4523
4620
  FIXED: "fixed",
@@ -4767,11 +4864,11 @@ class TextChunkerTask extends Task13 {
4767
4864
  var textChunker = (input, config) => {
4768
4865
  return new TextChunkerTask({}, config).run(input);
4769
4866
  };
4770
- Workflow30.prototype.textChunker = CreateWorkflow30(TextChunkerTask);
4867
+ Workflow31.prototype.textChunker = CreateWorkflow31(TextChunkerTask);
4771
4868
 
4772
4869
  // src/task/TextFillMaskTask.ts
4773
- import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
4774
- var modelSchema20 = TypeModel("model:TextFillMaskTask");
4870
+ import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
4871
+ var modelSchema21 = TypeModel("model:TextFillMaskTask");
4775
4872
  var TextFillMaskInputSchema = {
4776
4873
  type: "object",
4777
4874
  properties: {
@@ -4780,7 +4877,7 @@ var TextFillMaskInputSchema = {
4780
4877
  title: "Text",
4781
4878
  description: "The text with a mask token to fill"
4782
4879
  },
4783
- model: modelSchema20
4880
+ model: modelSchema21
4784
4881
  },
4785
4882
  required: ["text", "model"],
4786
4883
  additionalProperties: false
@@ -4835,21 +4932,21 @@ class TextFillMaskTask extends AiTask {
4835
4932
  var textFillMask = (input, config) => {
4836
4933
  return new TextFillMaskTask({}, config).run(input);
4837
4934
  };
4838
- Workflow31.prototype.textFillMask = CreateWorkflow31(TextFillMaskTask);
4935
+ Workflow32.prototype.textFillMask = CreateWorkflow32(TextFillMaskTask);
4839
4936
 
4840
4937
  // src/task/TextGenerationTask.ts
4841
- import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
4938
+ import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
4842
4939
  var generatedTextSchema2 = {
4843
4940
  type: "string",
4844
4941
  title: "Text",
4845
4942
  description: "The generated text",
4846
4943
  "x-stream": "append"
4847
4944
  };
4848
- var modelSchema21 = TypeModel("model:TextGenerationTask");
4945
+ var modelSchema22 = TypeModel("model:TextGenerationTask");
4849
4946
  var TextGenerationInputSchema = {
4850
4947
  type: "object",
4851
4948
  properties: {
4852
- model: modelSchema21,
4949
+ model: modelSchema22,
4853
4950
  prompt: {
4854
4951
  type: "string",
4855
4952
  title: "Prompt",
@@ -4923,11 +5020,11 @@ class TextGenerationTask extends StreamingAiTask {
4923
5020
  var textGeneration = (input, config) => {
4924
5021
  return new TextGenerationTask({}, config).run(input);
4925
5022
  };
4926
- Workflow32.prototype.textGeneration = CreateWorkflow32(TextGenerationTask);
5023
+ Workflow33.prototype.textGeneration = CreateWorkflow33(TextGenerationTask);
4927
5024
 
4928
5025
  // src/task/TextLanguageDetectionTask.ts
4929
- import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
4930
- var modelSchema22 = TypeModel("model:TextLanguageDetectionTask");
5026
+ import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
5027
+ var modelSchema23 = TypeModel("model:TextLanguageDetectionTask");
4931
5028
  var TextLanguageDetectionInputSchema = {
4932
5029
  type: "object",
4933
5030
  properties: {
@@ -4944,7 +5041,7 @@ var TextLanguageDetectionInputSchema = {
4944
5041
  title: "Max Languages",
4945
5042
  description: "The maximum number of languages to return"
4946
5043
  },
4947
- model: modelSchema22
5044
+ model: modelSchema23
4948
5045
  },
4949
5046
  required: ["text", "model"],
4950
5047
  additionalProperties: false
@@ -4994,10 +5091,10 @@ class TextLanguageDetectionTask extends AiTask {
4994
5091
  var textLanguageDetection = (input, config) => {
4995
5092
  return new TextLanguageDetectionTask({}, config).run(input);
4996
5093
  };
4997
- Workflow33.prototype.textLanguageDetection = CreateWorkflow33(TextLanguageDetectionTask);
5094
+ Workflow34.prototype.textLanguageDetection = CreateWorkflow34(TextLanguageDetectionTask);
4998
5095
 
4999
5096
  // src/task/TextQuestionAnswerTask.ts
5000
- import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
5097
+ import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
5001
5098
  var contextSchema = {
5002
5099
  type: "string",
5003
5100
  title: "Context",
@@ -5014,13 +5111,13 @@ var textSchema = {
5014
5111
  description: "The generated text",
5015
5112
  "x-stream": "append"
5016
5113
  };
5017
- var modelSchema23 = TypeModel("model:TextQuestionAnswerTask");
5114
+ var modelSchema24 = TypeModel("model:TextQuestionAnswerTask");
5018
5115
  var TextQuestionAnswerInputSchema = {
5019
5116
  type: "object",
5020
5117
  properties: {
5021
5118
  context: contextSchema,
5022
5119
  question: questionSchema,
5023
- model: modelSchema23
5120
+ model: modelSchema24
5024
5121
  },
5025
5122
  required: ["context", "question", "model"],
5026
5123
  additionalProperties: false
@@ -5049,11 +5146,11 @@ class TextQuestionAnswerTask extends StreamingAiTask {
5049
5146
  var textQuestionAnswer = (input, config) => {
5050
5147
  return new TextQuestionAnswerTask({}, config).run(input);
5051
5148
  };
5052
- Workflow34.prototype.textQuestionAnswer = CreateWorkflow34(TextQuestionAnswerTask);
5149
+ Workflow35.prototype.textQuestionAnswer = CreateWorkflow35(TextQuestionAnswerTask);
5053
5150
 
5054
5151
  // src/task/TextRewriterTask.ts
5055
- import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
5056
- var modelSchema24 = TypeModel("model:TextRewriterTask");
5152
+ import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5153
+ var modelSchema25 = TypeModel("model:TextRewriterTask");
5057
5154
  var TextRewriterInputSchema = {
5058
5155
  type: "object",
5059
5156
  properties: {
@@ -5067,7 +5164,7 @@ var TextRewriterInputSchema = {
5067
5164
  title: "Prompt",
5068
5165
  description: "The prompt to direct the rewriting"
5069
5166
  },
5070
- model: modelSchema24
5167
+ model: modelSchema25
5071
5168
  },
5072
5169
  required: ["text", "prompt", "model"],
5073
5170
  additionalProperties: false
@@ -5101,11 +5198,11 @@ class TextRewriterTask extends StreamingAiTask {
5101
5198
  var textRewriter = (input, config) => {
5102
5199
  return new TextRewriterTask({}, config).run(input);
5103
5200
  };
5104
- Workflow35.prototype.textRewriter = CreateWorkflow35(TextRewriterTask);
5201
+ Workflow36.prototype.textRewriter = CreateWorkflow36(TextRewriterTask);
5105
5202
 
5106
5203
  // src/task/TextTranslationTask.ts
5107
- import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5108
- var modelSchema25 = TypeModel("model:TextTranslationTask");
5204
+ import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
5205
+ var modelSchema26 = TypeModel("model:TextTranslationTask");
5109
5206
  var translationTextSchema = {
5110
5207
  type: "string",
5111
5208
  title: "Text",
@@ -5132,7 +5229,7 @@ var TextTranslationInputSchema = {
5132
5229
  minLength: 2,
5133
5230
  maxLength: 2
5134
5231
  }),
5135
- model: modelSchema25
5232
+ model: modelSchema26
5136
5233
  },
5137
5234
  required: ["text", "source_lang", "target_lang", "model"],
5138
5235
  additionalProperties: false
@@ -5167,13 +5264,13 @@ class TextTranslationTask extends StreamingAiTask {
5167
5264
  var textTranslation = (input, config) => {
5168
5265
  return new TextTranslationTask({}, config).run(input);
5169
5266
  };
5170
- Workflow36.prototype.textTranslation = CreateWorkflow36(TextTranslationTask);
5267
+ Workflow37.prototype.textTranslation = CreateWorkflow37(TextTranslationTask);
5171
5268
 
5172
5269
  // src/task/TopicSegmenterTask.ts
5173
5270
  import {
5174
- CreateWorkflow as CreateWorkflow37,
5271
+ CreateWorkflow as CreateWorkflow38,
5175
5272
  Task as Task14,
5176
- Workflow as Workflow37
5273
+ Workflow as Workflow38
5177
5274
  } from "@workglow/task-graph";
5178
5275
  var SegmentationMethod = {
5179
5276
  HEURISTIC: "heuristic",
@@ -5454,15 +5551,15 @@ class TopicSegmenterTask extends Task14 {
5454
5551
  var topicSegmenter = (input, config) => {
5455
5552
  return new TopicSegmenterTask({}, config).run(input);
5456
5553
  };
5457
- Workflow37.prototype.topicSegmenter = CreateWorkflow37(TopicSegmenterTask);
5554
+ Workflow38.prototype.topicSegmenter = CreateWorkflow38(TopicSegmenterTask);
5458
5555
 
5459
5556
  // src/task/UnloadModelTask.ts
5460
- import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5461
- var modelSchema26 = TypeModel("model");
5557
+ import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
5558
+ var modelSchema27 = TypeModel("model");
5462
5559
  var UnloadModelInputSchema = {
5463
5560
  type: "object",
5464
5561
  properties: {
5465
- model: modelSchema26
5562
+ model: modelSchema27
5466
5563
  },
5467
5564
  required: ["model"],
5468
5565
  additionalProperties: false
@@ -5470,7 +5567,7 @@ var UnloadModelInputSchema = {
5470
5567
  var UnloadModelOutputSchema = {
5471
5568
  type: "object",
5472
5569
  properties: {
5473
- model: modelSchema26
5570
+ model: modelSchema27
5474
5571
  },
5475
5572
  required: ["model"],
5476
5573
  additionalProperties: false
@@ -5492,10 +5589,10 @@ class UnloadModelTask extends AiTask {
5492
5589
  var unloadModel = (input, config) => {
5493
5590
  return new UnloadModelTask({}, config).run(input);
5494
5591
  };
5495
- Workflow38.prototype.unloadModel = CreateWorkflow38(UnloadModelTask);
5592
+ Workflow39.prototype.unloadModel = CreateWorkflow39(UnloadModelTask);
5496
5593
 
5497
5594
  // src/task/VectorQuantizeTask.ts
5498
- import { CreateWorkflow as CreateWorkflow39, Task as Task15, Workflow as Workflow39 } from "@workglow/task-graph";
5595
+ import { CreateWorkflow as CreateWorkflow40, Task as Task15, Workflow as Workflow40 } from "@workglow/task-graph";
5499
5596
  import {
5500
5597
  normalizeNumberArray,
5501
5598
  TensorType,
@@ -5675,10 +5772,10 @@ class VectorQuantizeTask extends Task15 {
5675
5772
  var vectorQuantize = (input, config) => {
5676
5773
  return new VectorQuantizeTask({}, config).run(input);
5677
5774
  };
5678
- Workflow39.prototype.vectorQuantize = CreateWorkflow39(VectorQuantizeTask);
5775
+ Workflow40.prototype.vectorQuantize = CreateWorkflow40(VectorQuantizeTask);
5679
5776
 
5680
5777
  // src/task/VectorSimilarityTask.ts
5681
- import { CreateWorkflow as CreateWorkflow40, GraphAsTask, Workflow as Workflow40 } from "@workglow/task-graph";
5778
+ import { CreateWorkflow as CreateWorkflow41, GraphAsTask, Workflow as Workflow41 } from "@workglow/task-graph";
5682
5779
  import {
5683
5780
  cosineSimilarity,
5684
5781
  hammingSimilarity,
@@ -5784,7 +5881,7 @@ class VectorSimilarityTask extends GraphAsTask {
5784
5881
  var similarity = (input, config) => {
5785
5882
  return new VectorSimilarityTask({}, config).run(input);
5786
5883
  };
5787
- Workflow40.prototype.similarity = CreateWorkflow40(VectorSimilarityTask);
5884
+ Workflow41.prototype.similarity = CreateWorkflow41(VectorSimilarityTask);
5788
5885
 
5789
5886
  // src/task/index.ts
5790
5887
  var registerAiTasks = () => {
@@ -5814,6 +5911,7 @@ var registerAiTasks = () => {
5814
5911
  QueryExpanderTask,
5815
5912
  RerankerTask,
5816
5913
  StructuralParserTask,
5914
+ StructuredGenerationTask,
5817
5915
  TextChunkerTask,
5818
5916
  TextClassificationTask,
5819
5917
  TextEmbeddingTask,
@@ -5849,6 +5947,7 @@ export {
5849
5947
  textEmbedding,
5850
5948
  textClassification,
5851
5949
  textChunker,
5950
+ structuredGeneration,
5852
5951
  structuralParser,
5853
5952
  similarity,
5854
5953
  setGlobalModelRepository,
@@ -5923,6 +6022,9 @@ export {
5923
6022
  TextClassificationOutputSchema,
5924
6023
  TextClassificationInputSchema,
5925
6024
  TextChunkerTask,
6025
+ StructuredGenerationTask,
6026
+ StructuredGenerationOutputSchema,
6027
+ StructuredGenerationInputSchema,
5926
6028
  StructuralParserTask,
5927
6029
  StreamingAiTask,
5928
6030
  SimilarityFn,
@@ -5990,4 +6092,4 @@ export {
5990
6092
  AiJob
5991
6093
  };
5992
6094
 
5993
- //# debugId=ABDF225708417FBC64756E2164756E21
6095
+ //# debugId=5AD14CDB7344CB9464756E2164756E21