@workglow/ai 0.0.99 → 0.0.100

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
@@ -13,6 +13,7 @@ import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util";
13
13
  class AiProviderRegistry {
14
14
  runFnRegistry = new Map;
15
15
  streamFnRegistry = new Map;
16
+ reactiveRunFnRegistry = new Map;
16
17
  providers = new Map;
17
18
  registerProvider(provider) {
18
19
  this.providers.set(provider.name, provider);
@@ -57,6 +58,27 @@ class AiProviderRegistry {
57
58
  const taskTypeMap = this.streamFnRegistry.get(taskType);
58
59
  return taskTypeMap?.get(modelProvider);
59
60
  }
61
+ registerAsWorkerReactiveRunFn(modelProvider, taskType) {
62
+ const reactiveFn = async (input, output, model) => {
63
+ const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
64
+ return workerManager.callWorkerReactiveFunction(modelProvider, taskType, [
65
+ input,
66
+ output,
67
+ model
68
+ ]);
69
+ };
70
+ this.registerReactiveRunFn(modelProvider, taskType, reactiveFn);
71
+ }
72
+ registerReactiveRunFn(modelProvider, taskType, reactiveRunFn) {
73
+ if (!this.reactiveRunFnRegistry.has(taskType)) {
74
+ this.reactiveRunFnRegistry.set(taskType, new Map);
75
+ }
76
+ this.reactiveRunFnRegistry.get(taskType).set(modelProvider, reactiveRunFn);
77
+ }
78
+ getReactiveRunFn(modelProvider, taskType) {
79
+ const taskTypeMap = this.reactiveRunFnRegistry.get(taskType);
80
+ return taskTypeMap?.get(modelProvider);
81
+ }
60
82
  getDirectRunFn(modelProvider, taskType) {
61
83
  const taskTypeMap = this.runFnRegistry.get(taskType);
62
84
  const runFn = taskTypeMap?.get(modelProvider);
@@ -308,9 +330,11 @@ async function createDefaultQueue(providerName, concurrency) {
308
330
  class AiProvider {
309
331
  tasks;
310
332
  streamTasks;
311
- constructor(tasks, streamTasks) {
333
+ reactiveTasks;
334
+ constructor(tasks, streamTasks, reactiveTasks) {
312
335
  this.tasks = tasks;
313
336
  this.streamTasks = streamTasks;
337
+ this.reactiveTasks = reactiveTasks;
314
338
  }
315
339
  get supportedTaskTypes() {
316
340
  return this.taskTypes;
@@ -321,6 +345,9 @@ class AiProvider {
321
345
  getStreamFn(taskType) {
322
346
  return this.streamTasks?.[taskType];
323
347
  }
348
+ getReactiveRunFn(taskType) {
349
+ return this.reactiveTasks?.[taskType];
350
+ }
324
351
  async register(options = { mode: "inline" }) {
325
352
  await this.onInitialize(options);
326
353
  if (options.mode === "worker") {
@@ -339,6 +366,7 @@ class AiProvider {
339
366
  for (const taskType of this.taskTypes) {
340
367
  registry.registerAsWorkerRunFn(this.name, taskType);
341
368
  registry.registerAsWorkerStreamFn(this.name, taskType);
369
+ registry.registerAsWorkerReactiveRunFn(this.name, taskType);
342
370
  }
343
371
  } else {
344
372
  for (const [taskType, fn] of Object.entries(this.tasks)) {
@@ -350,6 +378,11 @@ class AiProvider {
350
378
  }
351
379
  }
352
380
  }
381
+ if (this.reactiveTasks) {
382
+ for (const [taskType, fn] of Object.entries(this.reactiveTasks)) {
383
+ registry.registerReactiveRunFn(this.name, taskType, fn);
384
+ }
385
+ }
353
386
  registry.registerProvider(this);
354
387
  if (options.queue?.autoCreate !== false) {
355
388
  await this.createQueue(options.queue?.concurrency ?? 1);
@@ -367,6 +400,11 @@ class AiProvider {
367
400
  workerServer.registerStreamFunction(taskType, fn);
368
401
  }
369
402
  }
403
+ if (this.reactiveTasks) {
404
+ for (const [taskType, fn] of Object.entries(this.reactiveTasks)) {
405
+ workerServer.registerReactiveFunction(taskType, fn);
406
+ }
407
+ }
370
408
  }
371
409
  async onInitialize(_options) {}
372
410
  async dispose() {}
@@ -585,6 +623,17 @@ class AiTask extends JobQueueTask {
585
623
  const model = input.model;
586
624
  return model?.provider;
587
625
  }
626
+ async executeReactive(input, output, context) {
627
+ const model = input.model;
628
+ if (model && typeof model === "object" && model.provider) {
629
+ const taskType = this.constructor.runtype ?? this.constructor.type;
630
+ const reactiveFn = getAiProviderRegistry().getReactiveRunFn(model.provider, taskType);
631
+ if (reactiveFn) {
632
+ return reactiveFn(input, output, model);
633
+ }
634
+ }
635
+ return super.executeReactive(input, output, context);
636
+ }
588
637
  async validateInput(input) {
589
638
  const inputSchema = this.inputSchema();
590
639
  if (typeof inputSchema === "boolean") {
@@ -1495,7 +1544,61 @@ var chunkVectorUpsert = (input, config) => {
1495
1544
  Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
1496
1545
 
1497
1546
  // src/task/ContextBuilderTask.ts
1498
- import { CreateWorkflow as CreateWorkflow8, Task as Task6, Workflow as Workflow8 } from "@workglow/task-graph";
1547
+ import { estimateTokens } from "@workglow/dataset";
1548
+ import {
1549
+ CreateWorkflow as CreateWorkflow9,
1550
+ Task as Task6,
1551
+ Workflow as Workflow9
1552
+ } from "@workglow/task-graph";
1553
+
1554
+ // src/task/CountTokensTask.ts
1555
+ import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
1556
+ var modelSchema3 = TypeModel("model");
1557
+ var CountTokensInputSchema = {
1558
+ type: "object",
1559
+ properties: {
1560
+ text: {
1561
+ type: "string",
1562
+ title: "Text",
1563
+ description: "The text to count tokens for"
1564
+ },
1565
+ model: modelSchema3
1566
+ },
1567
+ required: ["text", "model"],
1568
+ additionalProperties: false
1569
+ };
1570
+ var CountTokensOutputSchema = {
1571
+ type: "object",
1572
+ properties: {
1573
+ count: {
1574
+ type: "number",
1575
+ title: "Token Count",
1576
+ description: "The number of tokens in the text"
1577
+ }
1578
+ },
1579
+ required: ["count"],
1580
+ additionalProperties: false
1581
+ };
1582
+
1583
+ class CountTokensTask extends AiTask {
1584
+ static type = "CountTokensTask";
1585
+ static category = "AI Text Model";
1586
+ static title = "Count Tokens";
1587
+ static description = "Counts the number of tokens in a text string using the model's tokenizer";
1588
+ static cacheable = true;
1589
+ static inputSchema() {
1590
+ return CountTokensInputSchema;
1591
+ }
1592
+ static outputSchema() {
1593
+ return CountTokensOutputSchema;
1594
+ }
1595
+ }
1596
+ var countTokens = async (input, config) => {
1597
+ return new CountTokensTask({}, config).run(input);
1598
+ };
1599
+ Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
1600
+
1601
+ // src/task/ContextBuilderTask.ts
1499
1602
  var ContextFormat = {
1500
1603
  SIMPLE: "simple",
1501
1604
  NUMBERED: "numbered",
@@ -1503,6 +1606,10 @@ var ContextFormat = {
1503
1606
  MARKDOWN: "markdown",
1504
1607
  JSON: "json"
1505
1608
  };
1609
+ var modelSchema4 = TypeModel("model", {
1610
+ title: "Model",
1611
+ description: "Model to use for token counting (optional, falls back to estimation)"
1612
+ });
1506
1613
  var inputSchema6 = {
1507
1614
  type: "object",
1508
1615
  properties: {
@@ -1542,6 +1649,13 @@ var inputSchema6 = {
1542
1649
  minimum: 0,
1543
1650
  default: 0
1544
1651
  },
1652
+ maxTokens: {
1653
+ type: "number",
1654
+ title: "Max Tokens",
1655
+ description: "Maximum number of tokens in context (0 = unlimited). Takes precedence over maxLength when set.",
1656
+ minimum: 0,
1657
+ default: 0
1658
+ },
1545
1659
  includeMetadata: {
1546
1660
  type: "boolean",
1547
1661
  title: "Include Metadata",
@@ -1555,7 +1669,8 @@ var inputSchema6 = {
1555
1669
  default: `
1556
1670
 
1557
1671
  `
1558
- }
1672
+ },
1673
+ model: modelSchema4
1559
1674
  },
1560
1675
  required: ["chunks"],
1561
1676
  additionalProperties: false
@@ -1577,9 +1692,14 @@ var outputSchema6 = {
1577
1692
  type: "number",
1578
1693
  title: "Total Length",
1579
1694
  description: "Total length of context in characters"
1695
+ },
1696
+ totalTokens: {
1697
+ type: "number",
1698
+ title: "Total Tokens",
1699
+ description: "Estimated token count of the context"
1580
1700
  }
1581
1701
  },
1582
- required: ["context", "chunksUsed", "totalLength"],
1702
+ required: ["context", "chunksUsed", "totalLength", "totalTokens"],
1583
1703
  additionalProperties: false
1584
1704
  };
1585
1705
 
@@ -1595,49 +1715,77 @@ class ContextBuilderTask extends Task6 {
1595
1715
  static outputSchema() {
1596
1716
  return outputSchema6;
1597
1717
  }
1598
- async executeReactive(input, output) {
1718
+ async executeReactive(input, _output, context) {
1599
1719
  const {
1600
1720
  chunks,
1601
1721
  metadata = [],
1602
1722
  scores = [],
1603
1723
  format = ContextFormat.SIMPLE,
1604
1724
  maxLength = 0,
1725
+ maxTokens = 0,
1605
1726
  includeMetadata = false,
1606
1727
  separator = `
1607
1728
 
1608
1729
  `
1609
1730
  } = input;
1610
- let context = "";
1731
+ let countFn = async (text) => estimateTokens(text);
1732
+ if (input.model) {
1733
+ const countTask = context.own(new CountTokensTask({ model: input.model }));
1734
+ countFn = async (text) => {
1735
+ try {
1736
+ const result = await countTask.run({ text });
1737
+ return result.count;
1738
+ } catch (_err) {
1739
+ return estimateTokens(text);
1740
+ }
1741
+ };
1742
+ }
1743
+ const useTokenBudget = maxTokens > 0;
1744
+ let ctx = "";
1611
1745
  let chunksUsed = 0;
1612
1746
  for (let i = 0;i < chunks.length; i++) {
1613
1747
  const chunk = chunks[i];
1614
1748
  const meta = metadata[i];
1615
1749
  const score = scores[i];
1616
1750
  let formattedChunk = this.formatChunk(chunk, meta, score, i, format, includeMetadata);
1617
- if (maxLength > 0) {
1618
- const potentialLength = context.length + formattedChunk.length + separator.length;
1619
- if (potentialLength > maxLength) {
1751
+ const prefix = chunksUsed > 0 ? separator : "";
1752
+ const candidate = ctx + prefix + formattedChunk;
1753
+ if (useTokenBudget) {
1754
+ if (await countFn(candidate) > maxTokens) {
1620
1755
  if (chunksUsed === 0) {
1621
- const available = maxLength - context.length;
1622
- if (available > 100) {
1756
+ let truncated = formattedChunk;
1757
+ while (truncated.length > 10 && await countFn(truncated) > maxTokens) {
1758
+ truncated = truncated.substring(0, Math.floor(truncated.length * 0.9));
1759
+ }
1760
+ if (truncated.length > 10) {
1761
+ ctx = truncated.substring(0, truncated.length - 3) + "...";
1762
+ chunksUsed++;
1763
+ }
1764
+ }
1765
+ break;
1766
+ }
1767
+ } else if (maxLength > 0) {
1768
+ if (candidate.length > maxLength) {
1769
+ if (chunksUsed === 0) {
1770
+ const available = maxLength - ctx.length;
1771
+ if (available > 10) {
1623
1772
  formattedChunk = formattedChunk.substring(0, available - 3) + "...";
1624
- context += formattedChunk;
1773
+ ctx += formattedChunk;
1625
1774
  chunksUsed++;
1626
1775
  }
1627
1776
  }
1628
1777
  break;
1629
1778
  }
1630
1779
  }
1631
- if (chunksUsed > 0) {
1632
- context += separator;
1633
- }
1634
- context += formattedChunk;
1780
+ ctx = candidate;
1635
1781
  chunksUsed++;
1636
1782
  }
1783
+ const totalTokens = await countFn(ctx);
1637
1784
  return {
1638
- context,
1785
+ context: ctx,
1639
1786
  chunksUsed,
1640
- totalLength: context.length
1787
+ totalLength: ctx.length,
1788
+ totalTokens
1641
1789
  };
1642
1790
  }
1643
1791
  formatChunk(chunk, metadata, score, index, format, includeMetadata) {
@@ -1748,7 +1896,7 @@ class ContextBuilderTask extends Task6 {
1748
1896
  var contextBuilder = (input, config) => {
1749
1897
  return new ContextBuilderTask({}, config).run(input);
1750
1898
  };
1751
- Workflow8.prototype.contextBuilder = CreateWorkflow8(ContextBuilderTask);
1899
+ Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
1752
1900
 
1753
1901
  // src/task/DocumentEnricherTask.ts
1754
1902
  import {
@@ -1756,14 +1904,14 @@ import {
1756
1904
  hasChildren
1757
1905
  } from "@workglow/dataset";
1758
1906
  import {
1759
- CreateWorkflow as CreateWorkflow11,
1907
+ CreateWorkflow as CreateWorkflow12,
1760
1908
  Task as Task7,
1761
- Workflow as Workflow11
1909
+ Workflow as Workflow12
1762
1910
  } from "@workglow/task-graph";
1763
1911
 
1764
1912
  // src/task/TextNamedEntityRecognitionTask.ts
1765
- import { CreateWorkflow as CreateWorkflow9, Workflow as Workflow9 } from "@workglow/task-graph";
1766
- var modelSchema3 = TypeModel("model:TextNamedEntityRecognitionTask");
1913
+ import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
1914
+ var modelSchema5 = TypeModel("model:TextNamedEntityRecognitionTask");
1767
1915
  var TextNamedEntityRecognitionInputSchema = {
1768
1916
  type: "object",
1769
1917
  properties: {
@@ -1782,7 +1930,7 @@ var TextNamedEntityRecognitionInputSchema = {
1782
1930
  "x-ui-group": "Configuration",
1783
1931
  "x-ui-group-open": false
1784
1932
  },
1785
- model: modelSchema3
1933
+ model: modelSchema5
1786
1934
  },
1787
1935
  required: ["text", "model"],
1788
1936
  additionalProperties: false
@@ -1837,10 +1985,10 @@ class TextNamedEntityRecognitionTask extends AiTask {
1837
1985
  var textNamedEntityRecognition = (input, config) => {
1838
1986
  return new TextNamedEntityRecognitionTask({}, config).run(input);
1839
1987
  };
1840
- Workflow9.prototype.textNamedEntityRecognition = CreateWorkflow9(TextNamedEntityRecognitionTask);
1988
+ Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
1841
1989
 
1842
1990
  // src/task/TextSummaryTask.ts
1843
- import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
1991
+ import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
1844
1992
 
1845
1993
  // src/task/base/StreamingAiTask.ts
1846
1994
  import {
@@ -1872,7 +2020,7 @@ class StreamingAiTask extends AiTask {
1872
2020
  }
1873
2021
 
1874
2022
  // src/task/TextSummaryTask.ts
1875
- var modelSchema4 = TypeModel("model:TextSummaryTask");
2023
+ var modelSchema6 = TypeModel("model:TextSummaryTask");
1876
2024
  var TextSummaryInputSchema = {
1877
2025
  type: "object",
1878
2026
  properties: {
@@ -1881,7 +2029,7 @@ var TextSummaryInputSchema = {
1881
2029
  title: "Text",
1882
2030
  description: "The text to summarize"
1883
2031
  },
1884
- model: modelSchema4
2032
+ model: modelSchema6
1885
2033
  },
1886
2034
  required: ["text", "model"],
1887
2035
  additionalProperties: false
@@ -1915,7 +2063,7 @@ class TextSummaryTask extends StreamingAiTask {
1915
2063
  var textSummary = async (input, config) => {
1916
2064
  return new TextSummaryTask({}, config).run(input);
1917
2065
  };
1918
- Workflow10.prototype.textSummary = CreateWorkflow10(TextSummaryTask);
2066
+ Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
1919
2067
 
1920
2068
  // src/task/DocumentEnricherTask.ts
1921
2069
  var inputSchema7 = {
@@ -2146,15 +2294,15 @@ class DocumentEnricherTask extends Task7 {
2146
2294
  var documentEnricher = (input, config) => {
2147
2295
  return new DocumentEnricherTask({}, config).run(input);
2148
2296
  };
2149
- Workflow11.prototype.documentEnricher = CreateWorkflow11(DocumentEnricherTask);
2297
+ Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
2150
2298
 
2151
2299
  // src/task/DownloadModelTask.ts
2152
- import { CreateWorkflow as CreateWorkflow12, Workflow as Workflow12 } from "@workglow/task-graph";
2153
- var modelSchema5 = TypeModel("model");
2300
+ import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
2301
+ var modelSchema7 = TypeModel("model");
2154
2302
  var DownloadModelInputSchema = {
2155
2303
  type: "object",
2156
2304
  properties: {
2157
- model: modelSchema5
2305
+ model: modelSchema7
2158
2306
  },
2159
2307
  required: ["model"],
2160
2308
  additionalProperties: false
@@ -2162,7 +2310,7 @@ var DownloadModelInputSchema = {
2162
2310
  var DownloadModelOutputSchema = {
2163
2311
  type: "object",
2164
2312
  properties: {
2165
- model: modelSchema5
2313
+ model: modelSchema7
2166
2314
  },
2167
2315
  required: ["model"],
2168
2316
  additionalProperties: false
@@ -2205,11 +2353,11 @@ class DownloadModelTask extends AiTask {
2205
2353
  var downloadModel = (input, config) => {
2206
2354
  return new DownloadModelTask({}, config).run(input);
2207
2355
  };
2208
- Workflow12.prototype.downloadModel = CreateWorkflow12(DownloadModelTask);
2356
+ Workflow13.prototype.downloadModel = CreateWorkflow13(DownloadModelTask);
2209
2357
 
2210
2358
  // src/task/FaceDetectorTask.ts
2211
- import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
2212
- var modelSchema6 = TypeModel("model:FaceDetectorTask");
2359
+ import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
2360
+ var modelSchema8 = TypeModel("model:FaceDetectorTask");
2213
2361
  var TypeBoundingBox2 = {
2214
2362
  type: "object",
2215
2363
  properties: {
@@ -2282,7 +2430,7 @@ var FaceDetectorInputSchema = {
2282
2430
  type: "object",
2283
2431
  properties: {
2284
2432
  image: TypeImageInput,
2285
- model: modelSchema6,
2433
+ model: modelSchema8,
2286
2434
  minDetectionConfidence: {
2287
2435
  type: "number",
2288
2436
  minimum: 0,
@@ -2336,11 +2484,11 @@ class FaceDetectorTask extends AiVisionTask {
2336
2484
  var faceDetector = (input, config) => {
2337
2485
  return new FaceDetectorTask({}, config).run(input);
2338
2486
  };
2339
- Workflow13.prototype.faceDetector = CreateWorkflow13(FaceDetectorTask);
2487
+ Workflow14.prototype.faceDetector = CreateWorkflow14(FaceDetectorTask);
2340
2488
 
2341
2489
  // src/task/FaceLandmarkerTask.ts
2342
- import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
2343
- var modelSchema7 = TypeModel("model:FaceLandmarkerTask");
2490
+ import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
2491
+ var modelSchema9 = TypeModel("model:FaceLandmarkerTask");
2344
2492
  var TypeLandmark = {
2345
2493
  type: "object",
2346
2494
  properties: {
@@ -2412,7 +2560,7 @@ var FaceLandmarkerInputSchema = {
2412
2560
  type: "object",
2413
2561
  properties: {
2414
2562
  image: TypeImageInput,
2415
- model: modelSchema7,
2563
+ model: modelSchema9,
2416
2564
  numFaces: {
2417
2565
  type: "number",
2418
2566
  minimum: 1,
@@ -2498,11 +2646,11 @@ class FaceLandmarkerTask extends AiVisionTask {
2498
2646
  var faceLandmarker = (input, config) => {
2499
2647
  return new FaceLandmarkerTask({}, config).run(input);
2500
2648
  };
2501
- Workflow14.prototype.faceLandmarker = CreateWorkflow14(FaceLandmarkerTask);
2649
+ Workflow15.prototype.faceLandmarker = CreateWorkflow15(FaceLandmarkerTask);
2502
2650
 
2503
2651
  // src/task/GestureRecognizerTask.ts
2504
- import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
2505
- var modelSchema8 = TypeModel("model:GestureRecognizerTask");
2652
+ import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
2653
+ var modelSchema10 = TypeModel("model:GestureRecognizerTask");
2506
2654
  var TypeLandmark2 = {
2507
2655
  type: "object",
2508
2656
  properties: {
@@ -2594,7 +2742,7 @@ var GestureRecognizerInputSchema = {
2594
2742
  type: "object",
2595
2743
  properties: {
2596
2744
  image: TypeImageInput,
2597
- model: modelSchema8,
2745
+ model: modelSchema10,
2598
2746
  numHands: {
2599
2747
  type: "number",
2600
2748
  minimum: 1,
@@ -2666,11 +2814,11 @@ class GestureRecognizerTask extends AiVisionTask {
2666
2814
  var gestureRecognizer = (input, config) => {
2667
2815
  return new GestureRecognizerTask({}, config).run(input);
2668
2816
  };
2669
- Workflow15.prototype.gestureRecognizer = CreateWorkflow15(GestureRecognizerTask);
2817
+ Workflow16.prototype.gestureRecognizer = CreateWorkflow16(GestureRecognizerTask);
2670
2818
 
2671
2819
  // src/task/HandLandmarkerTask.ts
2672
- import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
2673
- var modelSchema9 = TypeModel("model:HandLandmarkerTask");
2820
+ import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
2821
+ var modelSchema11 = TypeModel("model:HandLandmarkerTask");
2674
2822
  var TypeLandmark3 = {
2675
2823
  type: "object",
2676
2824
  properties: {
@@ -2739,7 +2887,7 @@ var HandLandmarkerInputSchema = {
2739
2887
  type: "object",
2740
2888
  properties: {
2741
2889
  image: TypeImageInput,
2742
- model: modelSchema9,
2890
+ model: modelSchema11,
2743
2891
  numHands: {
2744
2892
  type: "number",
2745
2893
  minimum: 1,
@@ -2811,21 +2959,25 @@ class HandLandmarkerTask extends AiVisionTask {
2811
2959
  var handLandmarker = (input, config) => {
2812
2960
  return new HandLandmarkerTask({}, config).run(input);
2813
2961
  };
2814
- Workflow16.prototype.handLandmarker = CreateWorkflow16(HandLandmarkerTask);
2962
+ Workflow17.prototype.handLandmarker = CreateWorkflow17(HandLandmarkerTask);
2815
2963
 
2816
2964
  // src/task/HierarchicalChunkerTask.ts
2817
2965
  import {
2818
2966
  ChunkNodeSchema as ChunkNodeSchema2,
2819
- estimateTokens,
2967
+ estimateTokens as estimateTokens2,
2820
2968
  getChildren as getChildren2,
2821
2969
  hasChildren as hasChildren2
2822
2970
  } from "@workglow/dataset";
2823
2971
  import {
2824
- CreateWorkflow as CreateWorkflow17,
2972
+ CreateWorkflow as CreateWorkflow18,
2825
2973
  Task as Task8,
2826
- Workflow as Workflow17
2974
+ Workflow as Workflow18
2827
2975
  } from "@workglow/task-graph";
2828
2976
  import { uuid4 } from "@workglow/util";
2977
+ var modelSchema12 = TypeModel("model", {
2978
+ title: "Model",
2979
+ description: "Model to use for token counting"
2980
+ });
2829
2981
  var inputSchema8 = {
2830
2982
  type: "object",
2831
2983
  properties: {
@@ -2865,9 +3017,10 @@ var inputSchema8 = {
2865
3017
  title: "Chunking Strategy",
2866
3018
  description: "Strategy for chunking",
2867
3019
  default: "hierarchical"
2868
- }
3020
+ },
3021
+ model: modelSchema12
2869
3022
  },
2870
- required: [],
3023
+ required: ["doc_id", "documentTree"],
2871
3024
  additionalProperties: false
2872
3025
  };
2873
3026
  var outputSchema8 = {
@@ -2933,11 +3086,23 @@ class HierarchicalChunkerTask extends Task8 {
2933
3086
  overlapTokens: overlap,
2934
3087
  reservedTokens
2935
3088
  };
3089
+ let countFn = async (text) => estimateTokens2(text);
3090
+ if (input.model) {
3091
+ const countTask = context.own(new CountTokensTask({ model: input.model }));
3092
+ countFn = async (text) => {
3093
+ try {
3094
+ const result = await countTask.run({ text });
3095
+ return result.count;
3096
+ } catch (_err) {
3097
+ return estimateTokens2(text);
3098
+ }
3099
+ };
3100
+ }
2936
3101
  const chunks = [];
2937
3102
  if (strategy === "hierarchical") {
2938
- await this.chunkHierarchically(root, [], doc_id, tokenBudget, chunks);
3103
+ await this.chunkHierarchically(root, [], doc_id, tokenBudget, chunks, countFn);
2939
3104
  } else {
2940
- await this.chunkFlat(root, doc_id, tokenBudget, chunks);
3105
+ await this.chunkFlat(root, doc_id, tokenBudget, chunks, countFn);
2941
3106
  }
2942
3107
  return {
2943
3108
  doc_id,
@@ -2946,24 +3111,30 @@ class HierarchicalChunkerTask extends Task8 {
2946
3111
  count: chunks.length
2947
3112
  };
2948
3113
  }
2949
- async chunkHierarchically(node, nodePath, doc_id, tokenBudget, chunks) {
3114
+ async chunkHierarchically(node, nodePath, doc_id, tokenBudget, chunks, countFn) {
2950
3115
  const currentPath = [...nodePath, node.nodeId];
2951
3116
  if (!hasChildren2(node)) {
2952
- await this.chunkText(node.text, currentPath, doc_id, tokenBudget, chunks, node.nodeId);
3117
+ await this.chunkText(node.text, currentPath, doc_id, tokenBudget, chunks, node.nodeId, countFn);
2953
3118
  return;
2954
3119
  }
2955
3120
  const children = getChildren2(node);
2956
3121
  for (const child of children) {
2957
- await this.chunkHierarchically(child, currentPath, doc_id, tokenBudget, chunks);
3122
+ await this.chunkHierarchically(child, currentPath, doc_id, tokenBudget, chunks, countFn);
2958
3123
  }
2959
3124
  }
2960
- async chunkText(text, nodePath, doc_id, tokenBudget, chunks, leafNodeId) {
2961
- const maxChars = (tokenBudget.maxTokensPerChunk - tokenBudget.reservedTokens) * 4;
2962
- const overlapChars = tokenBudget.overlapTokens * 4;
2963
- if (estimateTokens(text) <= tokenBudget.maxTokensPerChunk - tokenBudget.reservedTokens) {
2964
- const chunkId = uuid4();
3125
+ async chunkText(text, nodePath, doc_id, tokenBudget, chunks, leafNodeId, countFn) {
3126
+ const maxTokens = tokenBudget.maxTokensPerChunk - tokenBudget.reservedTokens;
3127
+ const overlapTokens = tokenBudget.overlapTokens;
3128
+ if (maxTokens <= 0) {
3129
+ throw new Error(`Invalid token budget: reservedTokens (${tokenBudget.reservedTokens}) must be less than maxTokensPerChunk (${tokenBudget.maxTokensPerChunk})`);
3130
+ }
3131
+ if (overlapTokens >= maxTokens) {
3132
+ throw new Error(`Invalid token budget: overlapTokens (${overlapTokens}) must be less than effective maxTokens (${maxTokens})`);
3133
+ }
3134
+ const count = await countFn(text);
3135
+ if (count <= maxTokens) {
2965
3136
  chunks.push({
2966
- chunkId,
3137
+ chunkId: uuid4(),
2967
3138
  doc_id,
2968
3139
  text,
2969
3140
  nodePath,
@@ -2971,29 +3142,40 @@ class HierarchicalChunkerTask extends Task8 {
2971
3142
  });
2972
3143
  return;
2973
3144
  }
2974
- let chunkOrdinal = 0;
3145
+ const findCharBoundary = async (startChar, targetTokens) => {
3146
+ let lo = startChar;
3147
+ let hi = Math.min(startChar + targetTokens * 6, text.length);
3148
+ while (lo < hi) {
3149
+ const mid = Math.ceil((lo + hi) / 2);
3150
+ const count2 = await countFn(text.substring(startChar, mid));
3151
+ if (count2 <= targetTokens) {
3152
+ lo = mid;
3153
+ } else {
3154
+ hi = mid - 1;
3155
+ }
3156
+ }
3157
+ return lo;
3158
+ };
2975
3159
  let startOffset = 0;
2976
3160
  while (startOffset < text.length) {
2977
- const endOffset = Math.min(startOffset + maxChars, text.length);
2978
- const chunkText = text.substring(startOffset, endOffset);
2979
- const chunkId = uuid4();
3161
+ const boundary = await findCharBoundary(startOffset, maxTokens);
3162
+ const endOffset = Math.max(Math.min(boundary, text.length), startOffset + 1);
2980
3163
  chunks.push({
2981
- chunkId,
3164
+ chunkId: uuid4(),
2982
3165
  doc_id,
2983
- text: chunkText,
3166
+ text: text.substring(startOffset, endOffset),
2984
3167
  nodePath,
2985
3168
  depth: nodePath.length
2986
3169
  });
2987
- chunkOrdinal++;
2988
- startOffset += maxChars - overlapChars;
2989
- if (overlapChars >= maxChars) {
2990
- startOffset = endOffset;
2991
- }
3170
+ if (endOffset >= text.length)
3171
+ break;
3172
+ const nextStart = await findCharBoundary(startOffset, maxTokens - overlapTokens);
3173
+ startOffset = nextStart > startOffset ? nextStart : endOffset;
2992
3174
  }
2993
3175
  }
2994
- async chunkFlat(root, doc_id, tokenBudget, chunks) {
3176
+ async chunkFlat(root, doc_id, tokenBudget, chunks, countFn) {
2995
3177
  const allText = this.collectAllText(root);
2996
- await this.chunkText(allText, [root.nodeId], doc_id, tokenBudget, chunks, root.nodeId);
3178
+ await this.chunkText(allText, [root.nodeId], doc_id, tokenBudget, chunks, root.nodeId, countFn);
2997
3179
  }
2998
3180
  collectAllText(node) {
2999
3181
  const texts = [];
@@ -3015,7 +3197,7 @@ class HierarchicalChunkerTask extends Task8 {
3015
3197
  var hierarchicalChunker = (input, config) => {
3016
3198
  return new HierarchicalChunkerTask({}, config).run(input);
3017
3199
  };
3018
- Workflow17.prototype.hierarchicalChunker = CreateWorkflow17(HierarchicalChunkerTask);
3200
+ Workflow18.prototype.hierarchicalChunker = CreateWorkflow18(HierarchicalChunkerTask);
3019
3201
 
3020
3202
  // src/task/HierarchyJoinTask.ts
3021
3203
  import {
@@ -3024,9 +3206,9 @@ import {
3024
3206
  TypeDocumentDataset
3025
3207
  } from "@workglow/dataset";
3026
3208
  import {
3027
- CreateWorkflow as CreateWorkflow18,
3209
+ CreateWorkflow as CreateWorkflow19,
3028
3210
  Task as Task9,
3029
- Workflow as Workflow18
3211
+ Workflow as Workflow19
3030
3212
  } from "@workglow/task-graph";
3031
3213
  var inputSchema9 = {
3032
3214
  type: "object",
@@ -3196,16 +3378,16 @@ class HierarchyJoinTask extends Task9 {
3196
3378
  var hierarchyJoin = (input, config) => {
3197
3379
  return new HierarchyJoinTask({}, config).run(input);
3198
3380
  };
3199
- Workflow18.prototype.hierarchyJoin = CreateWorkflow18(HierarchyJoinTask);
3381
+ Workflow19.prototype.hierarchyJoin = CreateWorkflow19(HierarchyJoinTask);
3200
3382
 
3201
3383
  // src/task/ImageClassificationTask.ts
3202
- import { CreateWorkflow as CreateWorkflow19, Workflow as Workflow19 } from "@workglow/task-graph";
3203
- var modelSchema10 = TypeModel("model:ImageClassificationTask");
3384
+ import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
3385
+ var modelSchema13 = TypeModel("model:ImageClassificationTask");
3204
3386
  var ImageClassificationInputSchema = {
3205
3387
  type: "object",
3206
3388
  properties: {
3207
3389
  image: TypeImageInput,
3208
- model: modelSchema10,
3390
+ model: modelSchema13,
3209
3391
  categories: {
3210
3392
  type: "array",
3211
3393
  items: {
@@ -3259,14 +3441,14 @@ class ImageClassificationTask extends AiVisionTask {
3259
3441
  var imageClassification = (input, config) => {
3260
3442
  return new ImageClassificationTask({}, config).run(input);
3261
3443
  };
3262
- Workflow19.prototype.imageClassification = CreateWorkflow19(ImageClassificationTask);
3444
+ Workflow20.prototype.imageClassification = CreateWorkflow20(ImageClassificationTask);
3263
3445
 
3264
3446
  // src/task/ImageEmbeddingTask.ts
3265
- import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
3447
+ import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
3266
3448
  import {
3267
3449
  TypedArraySchema as TypedArraySchema7
3268
3450
  } from "@workglow/util";
3269
- var modelSchema11 = TypeModel("model:ImageEmbeddingTask");
3451
+ var modelSchema14 = TypeModel("model:ImageEmbeddingTask");
3270
3452
  var embeddingSchema = TypedArraySchema7({
3271
3453
  title: "Embedding",
3272
3454
  description: "The image embedding vector"
@@ -3275,7 +3457,7 @@ var ImageEmbeddingInputSchema = {
3275
3457
  type: "object",
3276
3458
  properties: {
3277
3459
  image: TypeImageInput,
3278
- model: modelSchema11
3460
+ model: modelSchema14
3279
3461
  },
3280
3462
  required: ["image", "model"],
3281
3463
  additionalProperties: false
@@ -3304,16 +3486,16 @@ class ImageEmbeddingTask extends AiVisionTask {
3304
3486
  var imageEmbedding = (input, config) => {
3305
3487
  return new ImageEmbeddingTask({}, config).run(input);
3306
3488
  };
3307
- Workflow20.prototype.imageEmbedding = CreateWorkflow20(ImageEmbeddingTask);
3489
+ Workflow21.prototype.imageEmbedding = CreateWorkflow21(ImageEmbeddingTask);
3308
3490
 
3309
3491
  // src/task/ImageSegmentationTask.ts
3310
- import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
3311
- var modelSchema12 = TypeModel("model:ImageSegmentationTask");
3492
+ import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
3493
+ var modelSchema15 = TypeModel("model:ImageSegmentationTask");
3312
3494
  var ImageSegmentationInputSchema = {
3313
3495
  type: "object",
3314
3496
  properties: {
3315
3497
  image: TypeImageInput,
3316
- model: modelSchema12,
3498
+ model: modelSchema15,
3317
3499
  threshold: {
3318
3500
  type: "number",
3319
3501
  title: "Threshold",
@@ -3392,11 +3574,11 @@ class ImageSegmentationTask extends AiVisionTask {
3392
3574
  var imageSegmentation = (input, config) => {
3393
3575
  return new ImageSegmentationTask({}, config).run(input);
3394
3576
  };
3395
- Workflow21.prototype.imageSegmentation = CreateWorkflow21(ImageSegmentationTask);
3577
+ Workflow22.prototype.imageSegmentation = CreateWorkflow22(ImageSegmentationTask);
3396
3578
 
3397
3579
  // src/task/ImageToTextTask.ts
3398
- import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
3399
- var modelSchema13 = TypeModel("model:ImageToTextTask");
3580
+ import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
3581
+ var modelSchema16 = TypeModel("model:ImageToTextTask");
3400
3582
  var generatedTextSchema = {
3401
3583
  type: "string",
3402
3584
  title: "Text",
@@ -3406,7 +3588,7 @@ var ImageToTextInputSchema = {
3406
3588
  type: "object",
3407
3589
  properties: {
3408
3590
  image: TypeImageInput,
3409
- model: modelSchema13,
3591
+ model: modelSchema16,
3410
3592
  maxTokens: {
3411
3593
  type: "number",
3412
3594
  title: "Max Tokens",
@@ -3447,11 +3629,11 @@ class ImageToTextTask extends AiVisionTask {
3447
3629
  var imageToText = (input, config) => {
3448
3630
  return new ImageToTextTask({}, config).run(input);
3449
3631
  };
3450
- Workflow22.prototype.imageToText = CreateWorkflow22(ImageToTextTask);
3632
+ Workflow23.prototype.imageToText = CreateWorkflow23(ImageToTextTask);
3451
3633
 
3452
3634
  // src/task/ObjectDetectionTask.ts
3453
- import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
3454
- var modelSchema14 = TypeModel("model:ObjectDetectionTask");
3635
+ import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
3636
+ var modelSchema17 = TypeModel("model:ObjectDetectionTask");
3455
3637
  var detectionSchema = {
3456
3638
  type: "object",
3457
3639
  properties: {
@@ -3476,7 +3658,7 @@ var ObjectDetectionInputSchema = {
3476
3658
  type: "object",
3477
3659
  properties: {
3478
3660
  image: TypeImageInput,
3479
- model: modelSchema14,
3661
+ model: modelSchema17,
3480
3662
  labels: {
3481
3663
  type: "array",
3482
3664
  items: {
@@ -3530,11 +3712,11 @@ class ObjectDetectionTask extends AiVisionTask {
3530
3712
  var objectDetection = (input, config) => {
3531
3713
  return new ObjectDetectionTask({}, config).run(input);
3532
3714
  };
3533
- Workflow23.prototype.objectDetection = CreateWorkflow23(ObjectDetectionTask);
3715
+ Workflow24.prototype.objectDetection = CreateWorkflow24(ObjectDetectionTask);
3534
3716
 
3535
3717
  // src/task/PoseLandmarkerTask.ts
3536
- import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
3537
- var modelSchema15 = TypeModel("model:PoseLandmarkerTask");
3718
+ import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
3719
+ var modelSchema18 = TypeModel("model:PoseLandmarkerTask");
3538
3720
  var TypePoseLandmark = {
3539
3721
  type: "object",
3540
3722
  properties: {
@@ -3613,7 +3795,7 @@ var PoseLandmarkerInputSchema = {
3613
3795
  type: "object",
3614
3796
  properties: {
3615
3797
  image: TypeImageInput,
3616
- model: modelSchema15,
3798
+ model: modelSchema18,
3617
3799
  numPoses: {
3618
3800
  type: "number",
3619
3801
  minimum: 1,
@@ -3692,13 +3874,13 @@ class PoseLandmarkerTask extends AiVisionTask {
3692
3874
  var poseLandmarker = (input, config) => {
3693
3875
  return new PoseLandmarkerTask({}, config).run(input);
3694
3876
  };
3695
- Workflow24.prototype.poseLandmarker = CreateWorkflow24(PoseLandmarkerTask);
3877
+ Workflow25.prototype.poseLandmarker = CreateWorkflow25(PoseLandmarkerTask);
3696
3878
 
3697
3879
  // src/task/QueryExpanderTask.ts
3698
3880
  import {
3699
- CreateWorkflow as CreateWorkflow25,
3881
+ CreateWorkflow as CreateWorkflow26,
3700
3882
  Task as Task10,
3701
- Workflow as Workflow25
3883
+ Workflow as Workflow26
3702
3884
  } from "@workglow/task-graph";
3703
3885
  var QueryExpansionMethod = {
3704
3886
  MULTI_QUERY: "multi-query",
@@ -3909,18 +4091,18 @@ class QueryExpanderTask extends Task10 {
3909
4091
  var queryExpander = (input, config) => {
3910
4092
  return new QueryExpanderTask({}, config).run(input);
3911
4093
  };
3912
- Workflow25.prototype.queryExpander = CreateWorkflow25(QueryExpanderTask);
4094
+ Workflow26.prototype.queryExpander = CreateWorkflow26(QueryExpanderTask);
3913
4095
 
3914
4096
  // src/task/RerankerTask.ts
3915
4097
  import {
3916
- CreateWorkflow as CreateWorkflow27,
4098
+ CreateWorkflow as CreateWorkflow28,
3917
4099
  Task as Task11,
3918
- Workflow as Workflow27
4100
+ Workflow as Workflow28
3919
4101
  } from "@workglow/task-graph";
3920
4102
 
3921
4103
  // src/task/TextClassificationTask.ts
3922
- import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
3923
- var modelSchema16 = TypeModel("model:TextClassificationTask");
4104
+ import { CreateWorkflow as CreateWorkflow27, Workflow as Workflow27 } from "@workglow/task-graph";
4105
+ var modelSchema19 = TypeModel("model:TextClassificationTask");
3924
4106
  var TextClassificationInputSchema = {
3925
4107
  type: "object",
3926
4108
  properties: {
@@ -3947,7 +4129,7 @@ var TextClassificationInputSchema = {
3947
4129
  description: "The maximum number of categories to return",
3948
4130
  "x-ui-group": "Configuration"
3949
4131
  },
3950
- model: modelSchema16
4132
+ model: modelSchema19
3951
4133
  },
3952
4134
  required: ["text", "model"],
3953
4135
  additionalProperties: false
@@ -3997,7 +4179,7 @@ class TextClassificationTask extends AiTask {
3997
4179
  var textClassification = (input, config) => {
3998
4180
  return new TextClassificationTask({}, config).run(input);
3999
4181
  };
4000
- Workflow26.prototype.textClassification = CreateWorkflow26(TextClassificationTask);
4182
+ Workflow27.prototype.textClassification = CreateWorkflow27(TextClassificationTask);
4001
4183
 
4002
4184
  // src/task/RerankerTask.ts
4003
4185
  var inputSchema11 = {
@@ -4221,14 +4403,14 @@ class RerankerTask extends Task11 {
4221
4403
  var reranker = (input, config) => {
4222
4404
  return new RerankerTask({}, config).run(input);
4223
4405
  };
4224
- Workflow27.prototype.reranker = CreateWorkflow27(RerankerTask);
4406
+ Workflow28.prototype.reranker = CreateWorkflow28(RerankerTask);
4225
4407
 
4226
4408
  // src/task/StructuralParserTask.ts
4227
4409
  import { StructuralParser } from "@workglow/dataset";
4228
4410
  import {
4229
- CreateWorkflow as CreateWorkflow28,
4411
+ CreateWorkflow as CreateWorkflow29,
4230
4412
  Task as Task12,
4231
- Workflow as Workflow28
4413
+ Workflow as Workflow29
4232
4414
  } from "@workglow/task-graph";
4233
4415
  import { uuid4 as uuid42 } from "@workglow/util";
4234
4416
  var inputSchema12 = {
@@ -4330,13 +4512,13 @@ class StructuralParserTask extends Task12 {
4330
4512
  var structuralParser = (input, config) => {
4331
4513
  return new StructuralParserTask({}, config).run(input);
4332
4514
  };
4333
- Workflow28.prototype.structuralParser = CreateWorkflow28(StructuralParserTask);
4515
+ Workflow29.prototype.structuralParser = CreateWorkflow29(StructuralParserTask);
4334
4516
 
4335
4517
  // src/task/TextChunkerTask.ts
4336
4518
  import {
4337
- CreateWorkflow as CreateWorkflow29,
4519
+ CreateWorkflow as CreateWorkflow30,
4338
4520
  Task as Task13,
4339
- Workflow as Workflow29
4521
+ Workflow as Workflow30
4340
4522
  } from "@workglow/task-graph";
4341
4523
  var ChunkingStrategy = {
4342
4524
  FIXED: "fixed",
@@ -4586,11 +4768,11 @@ class TextChunkerTask extends Task13 {
4586
4768
  var textChunker = (input, config) => {
4587
4769
  return new TextChunkerTask({}, config).run(input);
4588
4770
  };
4589
- Workflow29.prototype.textChunker = CreateWorkflow29(TextChunkerTask);
4771
+ Workflow30.prototype.textChunker = CreateWorkflow30(TextChunkerTask);
4590
4772
 
4591
4773
  // src/task/TextFillMaskTask.ts
4592
- import { CreateWorkflow as CreateWorkflow30, Workflow as Workflow30 } from "@workglow/task-graph";
4593
- var modelSchema17 = TypeModel("model:TextFillMaskTask");
4774
+ import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
4775
+ var modelSchema20 = TypeModel("model:TextFillMaskTask");
4594
4776
  var TextFillMaskInputSchema = {
4595
4777
  type: "object",
4596
4778
  properties: {
@@ -4599,7 +4781,7 @@ var TextFillMaskInputSchema = {
4599
4781
  title: "Text",
4600
4782
  description: "The text with a mask token to fill"
4601
4783
  },
4602
- model: modelSchema17
4784
+ model: modelSchema20
4603
4785
  },
4604
4786
  required: ["text", "model"],
4605
4787
  additionalProperties: false
@@ -4654,21 +4836,21 @@ class TextFillMaskTask extends AiTask {
4654
4836
  var textFillMask = (input, config) => {
4655
4837
  return new TextFillMaskTask({}, config).run(input);
4656
4838
  };
4657
- Workflow30.prototype.textFillMask = CreateWorkflow30(TextFillMaskTask);
4839
+ Workflow31.prototype.textFillMask = CreateWorkflow31(TextFillMaskTask);
4658
4840
 
4659
4841
  // src/task/TextGenerationTask.ts
4660
- import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
4842
+ import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
4661
4843
  var generatedTextSchema2 = {
4662
4844
  type: "string",
4663
4845
  title: "Text",
4664
4846
  description: "The generated text",
4665
4847
  "x-stream": "append"
4666
4848
  };
4667
- var modelSchema18 = TypeModel("model:TextGenerationTask");
4849
+ var modelSchema21 = TypeModel("model:TextGenerationTask");
4668
4850
  var TextGenerationInputSchema = {
4669
4851
  type: "object",
4670
4852
  properties: {
4671
- model: modelSchema18,
4853
+ model: modelSchema21,
4672
4854
  prompt: {
4673
4855
  type: "string",
4674
4856
  title: "Prompt",
@@ -4742,11 +4924,11 @@ class TextGenerationTask extends StreamingAiTask {
4742
4924
  var textGeneration = (input, config) => {
4743
4925
  return new TextGenerationTask({}, config).run(input);
4744
4926
  };
4745
- Workflow31.prototype.textGeneration = CreateWorkflow31(TextGenerationTask);
4927
+ Workflow32.prototype.textGeneration = CreateWorkflow32(TextGenerationTask);
4746
4928
 
4747
4929
  // src/task/TextLanguageDetectionTask.ts
4748
- import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
4749
- var modelSchema19 = TypeModel("model:TextLanguageDetectionTask");
4930
+ import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
4931
+ var modelSchema22 = TypeModel("model:TextLanguageDetectionTask");
4750
4932
  var TextLanguageDetectionInputSchema = {
4751
4933
  type: "object",
4752
4934
  properties: {
@@ -4763,7 +4945,7 @@ var TextLanguageDetectionInputSchema = {
4763
4945
  title: "Max Languages",
4764
4946
  description: "The maximum number of languages to return"
4765
4947
  },
4766
- model: modelSchema19
4948
+ model: modelSchema22
4767
4949
  },
4768
4950
  required: ["text", "model"],
4769
4951
  additionalProperties: false
@@ -4813,10 +4995,10 @@ class TextLanguageDetectionTask extends AiTask {
4813
4995
  var textLanguageDetection = (input, config) => {
4814
4996
  return new TextLanguageDetectionTask({}, config).run(input);
4815
4997
  };
4816
- Workflow32.prototype.textLanguageDetection = CreateWorkflow32(TextLanguageDetectionTask);
4998
+ Workflow33.prototype.textLanguageDetection = CreateWorkflow33(TextLanguageDetectionTask);
4817
4999
 
4818
5000
  // src/task/TextQuestionAnswerTask.ts
4819
- import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
5001
+ import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
4820
5002
  var contextSchema = {
4821
5003
  type: "string",
4822
5004
  title: "Context",
@@ -4833,13 +5015,13 @@ var textSchema = {
4833
5015
  description: "The generated text",
4834
5016
  "x-stream": "append"
4835
5017
  };
4836
- var modelSchema20 = TypeModel("model:TextQuestionAnswerTask");
5018
+ var modelSchema23 = TypeModel("model:TextQuestionAnswerTask");
4837
5019
  var TextQuestionAnswerInputSchema = {
4838
5020
  type: "object",
4839
5021
  properties: {
4840
5022
  context: contextSchema,
4841
5023
  question: questionSchema,
4842
- model: modelSchema20
5024
+ model: modelSchema23
4843
5025
  },
4844
5026
  required: ["context", "question", "model"],
4845
5027
  additionalProperties: false
@@ -4868,11 +5050,11 @@ class TextQuestionAnswerTask extends StreamingAiTask {
4868
5050
  var textQuestionAnswer = (input, config) => {
4869
5051
  return new TextQuestionAnswerTask({}, config).run(input);
4870
5052
  };
4871
- Workflow33.prototype.textQuestionAnswer = CreateWorkflow33(TextQuestionAnswerTask);
5053
+ Workflow34.prototype.textQuestionAnswer = CreateWorkflow34(TextQuestionAnswerTask);
4872
5054
 
4873
5055
  // src/task/TextRewriterTask.ts
4874
- import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
4875
- var modelSchema21 = TypeModel("model:TextRewriterTask");
5056
+ import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
5057
+ var modelSchema24 = TypeModel("model:TextRewriterTask");
4876
5058
  var TextRewriterInputSchema = {
4877
5059
  type: "object",
4878
5060
  properties: {
@@ -4886,7 +5068,7 @@ var TextRewriterInputSchema = {
4886
5068
  title: "Prompt",
4887
5069
  description: "The prompt to direct the rewriting"
4888
5070
  },
4889
- model: modelSchema21
5071
+ model: modelSchema24
4890
5072
  },
4891
5073
  required: ["text", "prompt", "model"],
4892
5074
  additionalProperties: false
@@ -4920,11 +5102,11 @@ class TextRewriterTask extends StreamingAiTask {
4920
5102
  var textRewriter = (input, config) => {
4921
5103
  return new TextRewriterTask({}, config).run(input);
4922
5104
  };
4923
- Workflow34.prototype.textRewriter = CreateWorkflow34(TextRewriterTask);
5105
+ Workflow35.prototype.textRewriter = CreateWorkflow35(TextRewriterTask);
4924
5106
 
4925
5107
  // src/task/TextTranslationTask.ts
4926
- import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
4927
- var modelSchema22 = TypeModel("model:TextTranslationTask");
5108
+ import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5109
+ var modelSchema25 = TypeModel("model:TextTranslationTask");
4928
5110
  var translationTextSchema = {
4929
5111
  type: "string",
4930
5112
  title: "Text",
@@ -4951,7 +5133,7 @@ var TextTranslationInputSchema = {
4951
5133
  minLength: 2,
4952
5134
  maxLength: 2
4953
5135
  }),
4954
- model: modelSchema22
5136
+ model: modelSchema25
4955
5137
  },
4956
5138
  required: ["text", "source_lang", "target_lang", "model"],
4957
5139
  additionalProperties: false
@@ -4986,13 +5168,13 @@ class TextTranslationTask extends StreamingAiTask {
4986
5168
  var textTranslation = (input, config) => {
4987
5169
  return new TextTranslationTask({}, config).run(input);
4988
5170
  };
4989
- Workflow35.prototype.textTranslation = CreateWorkflow35(TextTranslationTask);
5171
+ Workflow36.prototype.textTranslation = CreateWorkflow36(TextTranslationTask);
4990
5172
 
4991
5173
  // src/task/TopicSegmenterTask.ts
4992
5174
  import {
4993
- CreateWorkflow as CreateWorkflow36,
5175
+ CreateWorkflow as CreateWorkflow37,
4994
5176
  Task as Task14,
4995
- Workflow as Workflow36
5177
+ Workflow as Workflow37
4996
5178
  } from "@workglow/task-graph";
4997
5179
  var SegmentationMethod = {
4998
5180
  HEURISTIC: "heuristic",
@@ -5273,15 +5455,15 @@ class TopicSegmenterTask extends Task14 {
5273
5455
  var topicSegmenter = (input, config) => {
5274
5456
  return new TopicSegmenterTask({}, config).run(input);
5275
5457
  };
5276
- Workflow36.prototype.topicSegmenter = CreateWorkflow36(TopicSegmenterTask);
5458
+ Workflow37.prototype.topicSegmenter = CreateWorkflow37(TopicSegmenterTask);
5277
5459
 
5278
5460
  // src/task/UnloadModelTask.ts
5279
- import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
5280
- var modelSchema23 = TypeModel("model");
5461
+ import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5462
+ var modelSchema26 = TypeModel("model");
5281
5463
  var UnloadModelInputSchema = {
5282
5464
  type: "object",
5283
5465
  properties: {
5284
- model: modelSchema23
5466
+ model: modelSchema26
5285
5467
  },
5286
5468
  required: ["model"],
5287
5469
  additionalProperties: false
@@ -5289,7 +5471,7 @@ var UnloadModelInputSchema = {
5289
5471
  var UnloadModelOutputSchema = {
5290
5472
  type: "object",
5291
5473
  properties: {
5292
- model: modelSchema23
5474
+ model: modelSchema26
5293
5475
  },
5294
5476
  required: ["model"],
5295
5477
  additionalProperties: false
@@ -5311,10 +5493,10 @@ class UnloadModelTask extends AiTask {
5311
5493
  var unloadModel = (input, config) => {
5312
5494
  return new UnloadModelTask({}, config).run(input);
5313
5495
  };
5314
- Workflow37.prototype.unloadModel = CreateWorkflow37(UnloadModelTask);
5496
+ Workflow38.prototype.unloadModel = CreateWorkflow38(UnloadModelTask);
5315
5497
 
5316
5498
  // src/task/VectorQuantizeTask.ts
5317
- import { CreateWorkflow as CreateWorkflow38, Task as Task15, Workflow as Workflow38 } from "@workglow/task-graph";
5499
+ import { CreateWorkflow as CreateWorkflow39, Task as Task15, Workflow as Workflow39 } from "@workglow/task-graph";
5318
5500
  import {
5319
5501
  normalizeNumberArray,
5320
5502
  TensorType,
@@ -5494,10 +5676,10 @@ class VectorQuantizeTask extends Task15 {
5494
5676
  var vectorQuantize = (input, config) => {
5495
5677
  return new VectorQuantizeTask({}, config).run(input);
5496
5678
  };
5497
- Workflow38.prototype.vectorQuantize = CreateWorkflow38(VectorQuantizeTask);
5679
+ Workflow39.prototype.vectorQuantize = CreateWorkflow39(VectorQuantizeTask);
5498
5680
 
5499
5681
  // src/task/VectorSimilarityTask.ts
5500
- import { CreateWorkflow as CreateWorkflow39, GraphAsTask, Workflow as Workflow39 } from "@workglow/task-graph";
5682
+ import { CreateWorkflow as CreateWorkflow40, GraphAsTask, Workflow as Workflow40 } from "@workglow/task-graph";
5501
5683
  import {
5502
5684
  cosineSimilarity,
5503
5685
  hammingSimilarity,
@@ -5603,13 +5785,14 @@ class VectorSimilarityTask extends GraphAsTask {
5603
5785
  var similarity = (input, config) => {
5604
5786
  return new VectorSimilarityTask({}, config).run(input);
5605
5787
  };
5606
- Workflow39.prototype.similarity = CreateWorkflow39(VectorSimilarityTask);
5788
+ Workflow40.prototype.similarity = CreateWorkflow40(VectorSimilarityTask);
5607
5789
 
5608
5790
  // src/task/index.ts
5609
5791
  var registerAiTasks = () => {
5610
5792
  const tasks = [
5611
5793
  BackgroundRemovalTask,
5612
5794
  ChunkToVectorTask,
5795
+ CountTokensTask,
5613
5796
  ContextBuilderTask,
5614
5797
  DocumentEnricherTask,
5615
5798
  ChunkRetrievalTask,
@@ -5691,6 +5874,7 @@ export {
5691
5874
  faceDetector,
5692
5875
  downloadModel,
5693
5876
  documentEnricher,
5877
+ countTokens,
5694
5878
  contextBuilder,
5695
5879
  chunkVectorUpsert,
5696
5880
  chunkToVector,
@@ -5787,6 +5971,9 @@ export {
5787
5971
  FaceDetectorInputSchema,
5788
5972
  DownloadModelTask,
5789
5973
  DocumentEnricherTask,
5974
+ CountTokensTask,
5975
+ CountTokensOutputSchema,
5976
+ CountTokensInputSchema,
5790
5977
  ContextFormat,
5791
5978
  ContextBuilderTask,
5792
5979
  ChunkingStrategy,
@@ -5804,4 +5991,4 @@ export {
5804
5991
  AiJob
5805
5992
  };
5806
5993
 
5807
- //# debugId=E3FAD6BE2442A4DE64756E2164756E21
5994
+ //# debugId=C1244851274A09B764756E2164756E21