@output.ai/core 0.0.14 → 0.0.16

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 (32) hide show
  1. package/bin/worker.sh +1 -1
  2. package/package.json +5 -8
  3. package/src/consts.js +8 -1
  4. package/src/index.d.ts +169 -7
  5. package/src/index.js +18 -1
  6. package/src/interface/evaluator.js +146 -0
  7. package/src/interface/step.js +4 -9
  8. package/src/interface/{schema_utils.js → validations/runtime.js} +0 -14
  9. package/src/interface/validations/runtime.spec.js +29 -0
  10. package/src/interface/validations/schema_utils.js +8 -0
  11. package/src/interface/validations/static.js +13 -1
  12. package/src/interface/validations/static.spec.js +29 -1
  13. package/src/interface/workflow.js +3 -8
  14. package/src/internal_activities/index.js +6 -0
  15. package/src/worker/catalog_workflow/catalog.js +19 -10
  16. package/src/worker/catalog_workflow/index.js +30 -1
  17. package/src/worker/catalog_workflow/index.spec.js +83 -22
  18. package/src/worker/index.js +1 -1
  19. package/src/worker/interceptors/activity.js +16 -3
  20. package/src/worker/loader.js +2 -2
  21. package/src/worker/tracer/index.js +1 -1
  22. package/src/worker/tracer/index.test.js +1 -2
  23. package/src/worker/tracer/tracer_tree.js +4 -3
  24. package/src/worker/tracer/tracer_tree.test.js +1 -1
  25. package/src/worker/webpack_loaders/workflow_rewriter/collect_target_imports.js +35 -4
  26. package/src/worker/webpack_loaders/workflow_rewriter/collect_target_imports.spec.js +12 -4
  27. package/src/worker/webpack_loaders/workflow_rewriter/index.mjs +5 -4
  28. package/src/worker/webpack_loaders/workflow_rewriter/rewrite_fn_bodies.js +13 -4
  29. package/src/worker/webpack_loaders/workflow_rewriter/rewrite_fn_bodies.spec.js +16 -2
  30. package/src/worker/webpack_loaders/workflow_rewriter/tools.js +46 -13
  31. package/src/worker/webpack_loaders/workflow_rewriter/tools.spec.js +20 -2
  32. /package/src/interface/{schema_utils.spec.js → validations/schema_utils.spec.js} +0 -0
@@ -106,6 +106,13 @@ export const toFunctionExpression = arrow => {
106
106
  */
107
107
  export const isStepsPath = value => /(^|\/)steps\.js$/.test( value );
108
108
 
109
+ /**
110
+ * Check if a module specifier or request string points to evaluators.js.
111
+ * @param {string} value - Module path or request string.
112
+ * @returns {boolean} True if it matches evaluators.js.
113
+ */
114
+ export const isEvaluatorsPath = value => /(^|\/)evaluators\.js$/.test( value );
115
+
109
116
  /**
110
117
  * Check if a module specifier or request string points to workflow.js.
111
118
  * @param {string} value - Module path or request string.
@@ -165,14 +172,18 @@ export const resolveNameFromOptions = ( optionsNode, consts, errorMessagePrefix
165
172
  };
166
173
 
167
174
  /**
168
- * Build a map from exported step variable name to declared step name.
169
- * Parses the steps module and extracts `step({ name: '...' })` names.
170
- * @param {string} path - Absolute path to the steps module file.
171
- * @param {Map<string, Map<string,string>>} cache - Cache of computed step name maps.
172
- * @returns {Map<string,string>} Exported identifier -> step name.
173
- * @throws {Error} When a step name is invalid (non-static or missing).
175
+ * Build a map of exported component identifiers to declared names by scanning a module.
176
+ * Coerces only static, analyzable forms: `export const X = callee({ name: '...' })`.
177
+ *
178
+ * @param {object} params
179
+ * @param {string} params.path - Absolute path to the module file.
180
+ * @param {Map<string, Map<string,string>>} params.cache - Cache for memoizing results by file path.
181
+ * @param {('step'|'evaluator')} params.calleeName - Factory function identifier to match.
182
+ * @param {string} params.invalidMessagePrefix - Prefix used in thrown errors when name is invalid.
183
+ * @returns {Map<string,string>} Map of `exportedIdentifier` -> `declaredName`.
184
+ * @throws {Error} When names are missing, dynamic, or otherwise non-static.
174
185
  */
175
- export const buildStepsNameMap = ( path, cache ) => {
186
+ const buildComponentNameMap = ( { path, cache, calleeName, invalidMessagePrefix } ) => {
176
187
  if ( cache.has( path ) ) {
177
188
  return cache.get( path );
178
189
  }
@@ -180,24 +191,46 @@ export const buildStepsNameMap = ( path, cache ) => {
180
191
  const ast = parse( text, path );
181
192
  const consts = extractTopLevelStringConsts( ast );
182
193
 
183
- const stepMap = ast.program.body
194
+ const result = ast.program.body
184
195
  .filter( node => isExportNamedDeclaration( node ) && isVariableDeclaration( node.declaration ) )
185
196
  .reduce( ( map, node ) => {
186
-
187
197
  node.declaration.declarations
188
- .filter( dec => isIdentifier( dec.id ) && isCallExpression( dec.init ) && isIdentifier( dec.init.callee, { name: 'step' } ) )
198
+ .filter( dec => isIdentifier( dec.id ) && isCallExpression( dec.init ) && isIdentifier( dec.init.callee, { name: calleeName } ) )
189
199
  .map( dec => [
190
200
  dec,
191
- resolveNameFromOptions( dec.init.arguments[0], consts, `Invalid step name in ${path} for "${dec.id.name}"` )
201
+ resolveNameFromOptions( dec.init.arguments[0], consts, `${invalidMessagePrefix} ${path} for "${dec.id.name}"` )
192
202
  ] )
193
203
  .forEach( ( [ dec, name ] ) => map.set( dec.id.name, name ) );
194
204
  return map;
195
205
  }, new Map() );
196
206
 
197
- cache.set( path, stepMap );
198
- return stepMap;
207
+ cache.set( path, result );
208
+ return result;
199
209
  };
200
210
 
211
+ export const buildStepsNameMap = ( path, cache ) => buildComponentNameMap( {
212
+ path,
213
+ cache,
214
+ calleeName: 'step',
215
+ invalidMessagePrefix: 'Invalid step name in'
216
+ } );
217
+
218
+ /**
219
+ * Build a map from exported evaluator identifier to declared evaluator name.
220
+ * Parses `evaluators.js` for `export const X = evaluator({ name: '...' })`.
221
+ *
222
+ * @param {string} path - Absolute path to the evaluators module file.
223
+ * @param {Map<string, Map<string,string>>} cache - Cache of computed evaluator name maps.
224
+ * @returns {Map<string,string>} Exported identifier -> evaluator name.
225
+ * @throws {Error} When a evaluator name is invalid (non-static or missing).
226
+ */
227
+ export const buildEvaluatorsNameMap = ( path, cache ) => buildComponentNameMap( {
228
+ path,
229
+ cache,
230
+ calleeName: 'evaluator',
231
+ invalidMessagePrefix: 'Invalid evaluator name in'
232
+ } );
233
+
201
234
  /**
202
235
  * Build a structure with default and named workflow names from a workflow module.
203
236
  * Extracts names from `workflow({ name: '...' })` calls.
@@ -15,7 +15,8 @@ import {
15
15
  createThisMethodCall,
16
16
  resolveNameFromOptions,
17
17
  buildStepsNameMap,
18
- buildWorkflowNameMap
18
+ buildWorkflowNameMap,
19
+ buildEvaluatorsNameMap
19
20
  } from './tools.js';
20
21
 
21
22
  describe( 'workflow_rewriter tools', () => {
@@ -72,6 +73,23 @@ describe( 'workflow_rewriter tools', () => {
72
73
  rmSync( dir, { recursive: true, force: true } );
73
74
  } );
74
75
 
76
+ it( 'buildEvaluatorsNameMap: reads names from evaluators module and caches result', () => {
77
+ const dir = mkdtempSync( join( tmpdir(), 'tools-evals-' ) );
78
+ const evalsPath = join( dir, 'evaluators.js' );
79
+ writeFileSync( evalsPath, [
80
+ 'export const EvalA = evaluator({ name: "eval.a" })',
81
+ 'export const EvalB = evaluator({ name: "eval.b" })'
82
+ ].join( '\n' ) );
83
+ const cache = new Map();
84
+ const map1 = buildEvaluatorsNameMap( evalsPath, cache );
85
+ expect( map1.get( 'EvalA' ) ).toBe( 'eval.a' );
86
+ expect( map1.get( 'EvalB' ) ).toBe( 'eval.b' );
87
+ expect( cache.get( evalsPath ) ).toBe( map1 );
88
+ const map2 = buildEvaluatorsNameMap( evalsPath, cache );
89
+ expect( map2 ).toBe( map1 );
90
+ rmSync( dir, { recursive: true, force: true } );
91
+ } );
92
+
75
93
  it( 'getLocalNameFromDestructuredProperty: handles { a }, { a: b }, { a: b = 1 }', () => {
76
94
  // { a }
77
95
  const p1 = t.objectProperty( t.identifier( 'a' ), t.identifier( 'a' ), false, true );
@@ -88,7 +106,7 @@ describe( 'workflow_rewriter tools', () => {
88
106
  } );
89
107
 
90
108
  it( 'buildWorkflowNameMap: reads named and default workflow names and caches', () => {
91
- const dir = mkdtempSync( join( tmpdir(), 'tools-flow-' ) );
109
+ const dir = mkdtempSync( join( tmpdir(), 'tools-output-' ) );
92
110
  const wfPath = join( dir, 'workflow.js' );
93
111
  writeFileSync( wfPath, [
94
112
  'export const FlowA = workflow({ name: "flow.a" })',