@workglow/ai 0.2.16 → 0.2.17

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
@@ -15,7 +15,7 @@ import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util/worker";
15
15
  class AiProviderRegistry {
16
16
  runFnRegistry = new Map;
17
17
  streamFnRegistry = new Map;
18
- reactiveRunFnRegistry = new Map;
18
+ previewRunFnRegistry = new Map;
19
19
  providers = new Map;
20
20
  strategyResolvers = new Map;
21
21
  defaultStrategy;
@@ -31,7 +31,7 @@ class AiProviderRegistry {
31
31
  for (const [, providerMap] of this.streamFnRegistry) {
32
32
  providerMap.delete(name);
33
33
  }
34
- for (const [, providerMap] of this.reactiveRunFnRegistry) {
34
+ for (const [, providerMap] of this.previewRunFnRegistry) {
35
35
  providerMap.delete(name);
36
36
  }
37
37
  }
@@ -109,25 +109,24 @@ class AiProviderRegistry {
109
109
  const taskTypeMap = this.streamFnRegistry.get(taskType);
110
110
  return taskTypeMap?.get(modelProvider);
111
111
  }
112
- registerAsWorkerReactiveRunFn(modelProvider, taskType) {
113
- const reactiveFn = async (input, output, model) => {
112
+ registerAsWorkerPreviewRunFn(modelProvider, taskType) {
113
+ const previewFn = async (input, model) => {
114
114
  const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
115
- return workerManager.callWorkerReactiveFunction(modelProvider, taskType, [
115
+ return workerManager.callWorkerPreviewFunction(modelProvider, taskType, [
116
116
  input,
117
- output,
118
117
  model
119
118
  ]);
120
119
  };
121
- this.registerReactiveRunFn(modelProvider, taskType, reactiveFn);
120
+ this.registerPreviewRunFn(modelProvider, taskType, previewFn);
122
121
  }
123
- registerReactiveRunFn(modelProvider, taskType, reactiveRunFn) {
124
- if (!this.reactiveRunFnRegistry.has(taskType)) {
125
- this.reactiveRunFnRegistry.set(taskType, new Map);
122
+ registerPreviewRunFn(modelProvider, taskType, previewRunFn) {
123
+ if (!this.previewRunFnRegistry.has(taskType)) {
124
+ this.previewRunFnRegistry.set(taskType, new Map);
126
125
  }
127
- this.reactiveRunFnRegistry.get(taskType).set(modelProvider, reactiveRunFn);
126
+ this.previewRunFnRegistry.get(taskType).set(modelProvider, previewRunFn);
128
127
  }
129
- getReactiveRunFn(modelProvider, taskType) {
130
- const taskTypeMap = this.reactiveRunFnRegistry.get(taskType);
128
+ getPreviewRunFn(modelProvider, taskType) {
129
+ const taskTypeMap = this.previewRunFnRegistry.get(taskType);
131
130
  return taskTypeMap?.get(modelProvider);
132
131
  }
133
132
  getDirectRunFn(modelProvider, taskType) {
@@ -722,11 +721,11 @@ function resolveAiProviderGpuQueueConcurrency(concurrency) {
722
721
  class AiProvider {
723
722
  tasks;
724
723
  streamTasks;
725
- reactiveTasks;
726
- constructor(tasks, streamTasks, reactiveTasks) {
724
+ previewTasks;
725
+ constructor(tasks, streamTasks, previewTasks) {
727
726
  this.tasks = tasks;
728
727
  this.streamTasks = streamTasks;
729
- this.reactiveTasks = reactiveTasks;
728
+ this.previewTasks = previewTasks;
730
729
  }
731
730
  get supportedTaskTypes() {
732
731
  return this.taskTypes;
@@ -737,8 +736,8 @@ class AiProvider {
737
736
  getStreamFn(taskType) {
738
737
  return this.streamTasks?.[taskType];
739
738
  }
740
- getReactiveRunFn(taskType) {
741
- return this.reactiveTasks?.[taskType];
739
+ getPreviewRunFn(taskType) {
740
+ return this.previewTasks?.[taskType];
742
741
  }
743
742
  async register(options = {}) {
744
743
  const isInline = !!this.tasks;
@@ -766,7 +765,7 @@ class AiProvider {
766
765
  for (const taskType of this.taskTypes) {
767
766
  registry.registerAsWorkerRunFn(this.name, taskType);
768
767
  registry.registerAsWorkerStreamFn(this.name, taskType);
769
- registry.registerAsWorkerReactiveRunFn(this.name, taskType);
768
+ registry.registerAsWorkerPreviewRunFn(this.name, taskType);
770
769
  }
771
770
  } else {
772
771
  for (const [taskType, fn] of Object.entries(this.tasks)) {
@@ -778,9 +777,9 @@ class AiProvider {
778
777
  }
779
778
  }
780
779
  }
781
- if (this.reactiveTasks) {
782
- for (const [taskType, fn] of Object.entries(this.reactiveTasks)) {
783
- registry.registerReactiveRunFn(this.name, taskType, fn);
780
+ if (this.previewTasks) {
781
+ for (const [taskType, fn] of Object.entries(this.previewTasks)) {
782
+ registry.registerPreviewRunFn(this.name, taskType, fn);
784
783
  }
785
784
  }
786
785
  registry.registerProvider(this);
@@ -803,9 +802,9 @@ class AiProvider {
803
802
  workerServer.registerStreamFunction(taskType, fn);
804
803
  }
805
804
  }
806
- if (this.reactiveTasks) {
807
- for (const [taskType, fn] of Object.entries(this.reactiveTasks)) {
808
- workerServer.registerReactiveFunction(taskType, fn);
805
+ if (this.previewTasks) {
806
+ for (const [taskType, fn] of Object.entries(this.previewTasks)) {
807
+ workerServer.registerPreviewFunction(taskType, fn);
809
808
  }
810
809
  }
811
810
  }
@@ -1112,16 +1111,16 @@ class AiTask extends Task {
1112
1111
  const model = input.model;
1113
1112
  return model?.provider;
1114
1113
  }
1115
- async executeReactive(input, output, context) {
1114
+ async executePreview(input, context) {
1116
1115
  const model = input.model;
1117
1116
  if (model && typeof model === "object" && model.provider) {
1118
1117
  const taskType = this.constructor.runtype ?? this.constructor.type;
1119
- const reactiveFn = getAiProviderRegistry().getReactiveRunFn(model.provider, taskType);
1120
- if (reactiveFn) {
1121
- return reactiveFn(input, output, model);
1118
+ const previewFn = getAiProviderRegistry().getPreviewRunFn(model.provider, taskType);
1119
+ if (previewFn) {
1120
+ return previewFn(input, model);
1122
1121
  }
1123
1122
  }
1124
- return super.executeReactive(input, output, context);
1123
+ return super.executePreview(input, context);
1125
1124
  }
1126
1125
  async validateInput(input) {
1127
1126
  const inputSchema = this.inputSchema();
@@ -2031,7 +2030,11 @@ Workflow4.prototype.chunkVectorUpsert = CreateWorkflow4(ChunkVectorUpsertTask);
2031
2030
 
2032
2031
  // src/task/ContextBuilderTask.ts
2033
2032
  import { estimateTokens } from "@workglow/knowledge-base";
2034
- import { CreateWorkflow as CreateWorkflow6, Task as Task4, Workflow as Workflow6 } from "@workglow/task-graph";
2033
+ import {
2034
+ CreateWorkflow as CreateWorkflow6,
2035
+ Task as Task4,
2036
+ Workflow as Workflow6
2037
+ } from "@workglow/task-graph";
2035
2038
 
2036
2039
  // src/task/CountTokensTask.ts
2037
2040
  import { CreateWorkflow as CreateWorkflow5, Workflow as Workflow5 } from "@workglow/task-graph";
@@ -2197,7 +2200,10 @@ class ContextBuilderTask extends Task4 {
2197
2200
  static outputSchema() {
2198
2201
  return outputSchema3;
2199
2202
  }
2200
- async executeReactive(input, _output, context) {
2203
+ async execute(input, context) {
2204
+ return this.executePreview(input, context);
2205
+ }
2206
+ async executePreview(input, context) {
2201
2207
  const {
2202
2208
  chunks,
2203
2209
  metadata = [],
@@ -6675,7 +6681,10 @@ class VectorQuantizeTask extends Task16 {
6675
6681
  static outputSchema() {
6676
6682
  return outputSchema14;
6677
6683
  }
6678
- async executeReactive(input) {
6684
+ async execute(input) {
6685
+ return this.executePreview(input);
6686
+ }
6687
+ async executePreview(input) {
6679
6688
  const { vector, targetType, normalize = true } = input;
6680
6689
  const isArray = Array.isArray(vector);
6681
6690
  const vectors = isArray ? vector : [vector];
@@ -6850,7 +6859,15 @@ class VectorSimilarityTask extends GraphAsTask {
6850
6859
  static outputSchema() {
6851
6860
  return SimilarityOutputSchema;
6852
6861
  }
6853
- async executeReactive({ query, vectors, method, topK }) {
6862
+ async execute(input) {
6863
+ return this.executePreview(input);
6864
+ }
6865
+ async executePreview({
6866
+ query,
6867
+ vectors,
6868
+ method,
6869
+ topK
6870
+ }) {
6854
6871
  let similarities = [];
6855
6872
  const fnName = method;
6856
6873
  const fn = similarityFunctions[fnName];
@@ -7261,4 +7278,4 @@ export {
7261
7278
  AiChatInputSchema
7262
7279
  };
7263
7280
 
7264
- //# debugId=D0BE66A575D71CC764756E2164756E21
7281
+ //# debugId=4A65F3B2D404BCCD64756E2164756E21