@outputai/core 0.15.1-dev.46e7530.0 → 0.15.1-dev.de5fa8c.0

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 (101) hide show
  1. package/dist/credentials/index.d.ts +1 -1
  2. package/dist/credentials/types.d.ts +4 -4
  3. package/dist/evals/aggregate.d.ts +2 -0
  4. package/dist/evals/aggregate.js +11 -0
  5. package/dist/evals/eval_workflow.d.ts +20 -0
  6. package/dist/evals/eval_workflow.js +98 -0
  7. package/dist/evals/index.d.ts +7 -0
  8. package/dist/evals/index.js +4 -0
  9. package/dist/evals/interpret.d.ts +3 -0
  10. package/dist/evals/interpret.js +40 -0
  11. package/dist/evals/schemas.d.ts +96 -0
  12. package/dist/evals/schemas.js +60 -0
  13. package/dist/evals/verdict.d.ts +27 -0
  14. package/dist/evals/verdict.js +109 -0
  15. package/dist/evals/verify.d.ts +42 -0
  16. package/dist/evals/verify.js +19 -0
  17. package/package.json +64 -14
  18. package/src/consts.d.ts +2 -0
  19. package/src/helpers/fetch.js +21 -9
  20. package/src/helpers/path.js +34 -0
  21. package/src/helpers/redact.js +2 -1
  22. package/src/http/config.js +10 -0
  23. package/src/http/cost.d.ts +20 -0
  24. package/src/http/cost.js +41 -0
  25. package/src/http/fetch/events.js +10 -0
  26. package/src/http/fetch/index.d.ts +24 -0
  27. package/src/http/fetch/index.js +78 -0
  28. package/src/http/fetch/logger.d.ts +10 -0
  29. package/src/http/fetch/logger.js +56 -0
  30. package/src/http/index.d.ts +28 -0
  31. package/src/http/index.js +9 -0
  32. package/src/http/ky/index.d.ts +25 -0
  33. package/src/http/ky/index.js +10 -0
  34. package/src/http/request_tag.js +30 -0
  35. package/src/interface/index.d.ts +1 -0
  36. package/src/llm/agent.js +147 -0
  37. package/src/llm/ai_provider.js +131 -0
  38. package/src/llm/ai_sdk_options.js +126 -0
  39. package/src/llm/consts.js +6 -0
  40. package/src/llm/deprecated_provider_aliases.js +8 -0
  41. package/src/llm/generate.js +98 -0
  42. package/src/llm/index.d.ts +697 -0
  43. package/src/llm/index.js +6 -0
  44. package/src/llm/judge.js +48 -0
  45. package/src/llm/prompt/content.js +70 -0
  46. package/src/llm/prompt/interpolations.js +58 -0
  47. package/src/llm/prompt/loader.js +67 -0
  48. package/src/llm/prompt/markup/attributes.js +52 -0
  49. package/src/llm/prompt/markup/nodes.js +71 -0
  50. package/src/llm/prompt/markup/tokenizer.js +3 -0
  51. package/src/llm/prompt/markup/tokens.js +26 -0
  52. package/src/llm/prompt/validations.js +129 -0
  53. package/src/llm/utils/cost.js +267 -0
  54. package/src/llm/utils/error_handler.js +53 -0
  55. package/src/llm/utils/file.js +42 -0
  56. package/src/llm/utils/google_vertex_auth.js +31 -0
  57. package/src/llm/utils/image.js +37 -0
  58. package/src/llm/utils/legacy_cost_attribute.js +75 -0
  59. package/src/llm/utils/metering.js +139 -0
  60. package/src/llm/utils/models.js +15 -0
  61. package/src/llm/utils/models_pricing.js +96 -0
  62. package/src/llm/utils/models_pricing_snapshot.json +4711 -0
  63. package/src/llm/utils/skills.js +74 -0
  64. package/src/llm/utils/sources.js +73 -0
  65. package/src/llm/utils/stream.js +75 -0
  66. package/src/llm/utils/tools.js +62 -0
  67. package/src/llm/utils/usage.js +155 -0
  68. package/src/llm/utils/usage_tools.js +23 -0
  69. package/src/llm/utils/web_search.js +155 -0
  70. package/src/llm/utils/wrap.js +279 -0
  71. package/src/llm/validations.js +234 -0
  72. package/src/tracing/trace_attribute.d.ts +0 -17
  73. package/src/tracing/trace_attribute.js +1 -29
  74. package/src/worker/bundler_options.js +1 -9
  75. package/src/worker/configs.js +23 -4
  76. package/src/worker/index.js +16 -47
  77. package/src/worker/interceptors/activity.js +0 -1
  78. package/src/worker/interceptors/workflow.js +0 -1
  79. package/src/worker/loader/workflows.js +16 -2
  80. package/src/worker/telemetry.js +122 -2
  81. package/src/worker/webpack_loaders/workflow_rewriter/index.mjs +3 -7
  82. package/src/worker/webpack_loaders/workflow_rewriter/rewrite_activity_calls.js +27 -7
  83. package/src/worker/webpack_loaders/workflow_validator/npm_workflow_export_resolve.js +5 -6
  84. package/src/worker/worker_options.js +43 -0
  85. package/src/sdk/README.md +0 -47
  86. package/src/sdk/helpers/component_metadata.d.ts +0 -17
  87. package/src/sdk/helpers/component_metadata.js +0 -6
  88. package/src/sdk/helpers/index.d.ts +0 -12
  89. package/src/sdk/helpers/index.js +0 -3
  90. package/src/sdk/helpers/objects.d.ts +0 -56
  91. package/src/sdk/helpers/objects.js +0 -8
  92. package/src/sdk/helpers/path.d.ts +0 -11
  93. package/src/sdk/helpers/path.js +0 -32
  94. package/src/sdk/runtime/context.d.ts +0 -30
  95. package/src/sdk/runtime/context.js +0 -15
  96. package/src/sdk/runtime/events.d.ts +0 -13
  97. package/src/sdk/runtime/events.js +0 -5
  98. package/src/sdk/runtime/index.d.ts +0 -12
  99. package/src/sdk/runtime/index.js +0 -3
  100. package/src/sdk/runtime/tracing.d.ts +0 -48
  101. package/src/sdk/runtime/tracing.js +0 -11
@@ -1,5 +1,5 @@
1
1
  import { Worker, NativeConnection } from '@temporalio/worker';
2
- import * as configs from './configs.js';
2
+ import { address, apiKey, namespace, taskQueue, grpcProxy, hookFlushTimeoutMs } from './configs.js';
3
3
  import { loadActivities } from './loader/activities.js';
4
4
  import { loadWorkflows } from './loader/workflows.js';
5
5
  import { loadHooks } from './loader/hooks.js';
@@ -15,7 +15,7 @@ import { CatalogPublisher } from './catalog_workflow/catalog_publisher.js';
15
15
  import { mainEventBus } from '#bus';
16
16
  import { flushPendingHooks } from '#hooks/pending_hooks';
17
17
  import { BusEventType } from '#consts';
18
- import { setupTelemetry } from './telemetry.js';
18
+ import { setupTelemetry, logIsolateSizing } from './telemetry.js';
19
19
  import { TemporalConnectionMonitor } from './connection_monitor.js';
20
20
  import { bindGlobalFunctions } from './global_functions.js';
21
21
  import { setupClientConfig } from '#temporal/client';
@@ -24,28 +24,12 @@ import { setupTemporalLogger } from './temporal_logger.js';
24
24
  import { WorkerRunner } from './worker_runner.js';
25
25
  import { shutdownServices } from './shutdown.js';
26
26
  import { init as initCredentials } from '#credentials/init';
27
+ import { buildWorkerOptions } from './worker_options.js';
27
28
 
28
29
  import './log_hooks.js';
29
30
 
30
31
  const log = createChildLogger( 'Worker' );
31
32
 
32
- const {
33
- address,
34
- apiKey,
35
- namespace,
36
- taskQueue,
37
- grpcProxy,
38
- maxConcurrentWorkflowTaskExecutions,
39
- maxConcurrentActivityTaskExecutions,
40
- maxCachedWorkflows,
41
- maxConcurrentActivityTaskPolls,
42
- maxConcurrentWorkflowTaskPolls,
43
- shutdownForceTime,
44
- shutdownGraceTime,
45
- hookFlushTimeoutMs,
46
- workerTuner
47
- } = configs;
48
-
49
33
  const services = {
50
34
  connection: null,
51
35
  connectionMonitor: null,
@@ -113,34 +97,19 @@ const execute = async () => {
113
97
  await run( () => services.catalogPublisher.run() );
114
98
 
115
99
  log.info( 'Creating Temporal worker...' );
116
- const worker = await run( () => {
117
- if ( workerTuner ) {
118
- log.info( 'Using worker tuner options', { ...workerTuner } );
119
- }
120
-
121
- return Worker.create( {
122
- connection,
123
- namespace,
124
- taskQueue,
125
- workflowsPath,
126
- activities,
127
- sinks,
128
- interceptors: initInterceptors( { activities, workflows } ),
129
- // tuner isn't compatible with concurrent task executions configs
130
- ...( workerTuner ? {
131
- tuner: workerTuner
132
- } : {
133
- maxConcurrentWorkflowTaskExecutions,
134
- maxConcurrentActivityTaskExecutions
135
- } ),
136
- maxCachedWorkflows,
137
- maxConcurrentActivityTaskPolls,
138
- maxConcurrentWorkflowTaskPolls,
139
- bundlerOptions: { webpackConfigHook },
140
- ...( shutdownForceTime !== undefined && { shutdownForceTime } ),
141
- ...( shutdownGraceTime !== undefined && { shutdownGraceTime } )
142
- } );
143
- } );
100
+ const worker = await run( () => Worker.create( {
101
+ connection,
102
+ namespace,
103
+ taskQueue,
104
+ workflowsPath,
105
+ activities,
106
+ sinks,
107
+ interceptors: initInterceptors( { activities, workflows } ),
108
+ bundlerOptions: { webpackConfigHook },
109
+ ...buildWorkerOptions()
110
+ } ) );
111
+
112
+ run( () => logIsolateSizing( { worker } ) );
144
113
 
145
114
  log.info( 'Setting up telemetry...' );
146
115
  run( () => setupTelemetry( { worker } ) );
@@ -103,7 +103,6 @@ export class ActivityExecutionInterceptor {
103
103
  const nonRetryable = error instanceof FatalError || inheritsFromAnyNamedType( error, activityInfo.retryPolicy?.nonRetryableErrorTypes ?? [] );
104
104
  throw ApplicationFailure.fromError( unwrappedError, {
105
105
  nonRetryable,
106
- cause: unwrappedError,
107
106
  details: [ { error: serializeError( unwrappedError, { dropKeys: [ 'stack' ] } ) } ]
108
107
  } );
109
108
  } finally {
@@ -89,7 +89,6 @@ class WorkflowExecutionInterceptor {
89
89
  const unwrappedError = error instanceof TransparentFatalError ? error.cause : error;
90
90
  sinks.workflow.error( serializeError( unwrappedError ) );
91
91
  throw ApplicationFailure.fromError( unwrappedError, {
92
- cause: unwrappedError,
93
92
  nonRetryable: true,
94
93
  details: [ { error: serializeError( unwrappedError, { dropKeys: [ 'stack' ] } ) } ]
95
94
  } );
@@ -19,8 +19,22 @@ const createWorkflowsEntrypoint = workflows => {
19
19
  aliases.map( alias => ( { name: alias, path } ) )
20
20
  );
21
21
 
22
- const content = [ ...workflows, ...aliasExports, catalog ]
23
- .map( ( { name, path } ) => `export { default as ${name} } from '${path}';` ).join( EOL );
22
+ // A static re-export makes every cached workflow evaluate the whole catalog: Temporal's reusable VM
23
+ // keeps each module loaded during an activation in that workflow's own cache. A lazy export loads
24
+ // only the invoked workflow; eager mode keeps it in the same bundle. Workflow type resolution is by
25
+ // export name, and the metadata the framework reads is read in Node, never from the bundle.
26
+ const lazyExports = [ ...workflows, ...aliasExports ].map( ( { name, path } ) => `\
27
+ async function _${name}( ...args ) {
28
+ const { default: workflow } = await import( /* webpackMode: "eager" */ '${path}' );
29
+ if ( typeof workflow !== 'function' ) {
30
+ throw new TypeError( 'Workflow "${name}" must be exported as default.' );
31
+ }
32
+ return workflow( ...args );
33
+ }
34
+ export { _${name} as ${name} };` );
35
+
36
+ // The catalog stays static: it is the framework's own workflow, small, and always loaded.
37
+ const content = [ ...lazyExports, `export { default as ${catalog.name} } from '${catalog.path}';` ].join( EOL );
24
38
 
25
39
  return writeFileInTempDir( content, WORKFLOWS_INDEX_FILENAME );
26
40
  };
@@ -1,21 +1,141 @@
1
+ import { totalmem } from 'node:os';
2
+ import { getHeapStatistics } from 'node:v8';
1
3
  import { serializeError } from '#helpers/error_serializer';
2
4
  import { createChildLogger } from '#logger';
3
5
  import { workerTelemetryIntervalMs } from './configs.js';
4
6
 
5
7
  const log = createChildLogger( 'Telemetry' );
6
8
 
9
+ /**
10
+ * Resolve the memory limit to compare the worker against: the container's limit, or the
11
+ * machine's total memory when there is none.
12
+ *
13
+ * `process.constrainedMemory()` returns a sentinel near 2^64 rather than 0 when the process is
14
+ * unconstrained, so values at or above the machine's memory are treated as no limit.
15
+ *
16
+ * @returns {number} Bytes.
17
+ */
18
+ const resolveMemoryLimit = () => {
19
+ const constrainedMemory = process.constrainedMemory();
20
+ const machineMemory = totalmem();
21
+ return constrainedMemory > 0 && constrainedMemory < machineMemory ? constrainedMemory : machineMemory;
22
+ };
23
+
24
+ /**
25
+ * Log the worker's isolate and cache sizing. Warn when the projected
26
+ * heap exceeds the memory limit, or when workflow task slots exceed
27
+ * the cache.
28
+ *
29
+ * The worker runs one isolate on the main thread and one per workflow
30
+ * thread. A NODE_OPTIONS heap cap applies to each isolate, not to the
31
+ * process, so on a 4 GB container `--max-old-space-size-percentage=85`
32
+ * allows each isolate ~3.4 GB and two isolates can commit well over
33
+ * the container's memory.
34
+ *
35
+ * The cache and the task slots are sized independently:
36
+ * `@temporalio/worker` derives `maxCachedWorkflows` from the heap limit
37
+ * but fixes `workflowTaskSlots` at 40. On a small container the slots
38
+ * can exceed the cache, which causes tasks to evict each other's
39
+ * workflows and forces history replays.
40
+ *
41
+ * Logged fields are read from `worker.options`, so each is the resolved
42
+ * value rather than the requested one:
43
+ *
44
+ * - `workflowThreadPoolSize`: threads running workflow sandboxes.
45
+ * Defaults to 1 with `reuseV8Context`, 2 without. Ignored under
46
+ * `debugMode`.
47
+ * - `reuseV8Context`: whether workflows share one VM context per thread
48
+ * or each get a new one. Enabled by default. Upstream estimates
49
+ * roughly 600 cached workflows per GB with it and 250 without.
50
+ * - `isolateCount`: `1 + workflowThreadPoolSize`, the multiplier on the
51
+ * per-isolate heap cap. 1 under `debugMode`, which runs workflows in
52
+ * the main isolate and spawns no workflow threads.
53
+ * - `heapSizeLimit`: the main isolate's V8 heap ceiling, as resolved
54
+ * from NODE_OPTIONS.
55
+ * - `projectedCommittedHeap`: `isolateCount * heapSizeLimit`, the heap
56
+ * the process can commit if every isolate fills. Only the main
57
+ * thread's limit is readable, so this assumes the workflow threads
58
+ * have the same one.
59
+ * - `memoryLimit`: the limit the projection is compared against. The
60
+ * container's limit, or the machine's total memory when unconstrained.
61
+ * - `maxCachedWorkflows`: sticky cache size. Derived from
62
+ * `heapSizeLimit` when TEMPORAL_MAX_CACHED_WORKFLOWS is unset.
63
+ * - `workflowTaskSlots`: workflow tasks that may run at once, from the
64
+ * tuner. Undefined with a resource-based tuner, which sizes slots at
65
+ * runtime.
66
+ *
67
+ * @param {object} params Parameters.
68
+ * @param {import('@temporalio/worker').Worker} params.worker The created Temporal worker.
69
+ */
70
+ export const logIsolateSizing = ( { worker } ) => {
71
+ const { workflowThreadPoolSize, reuseV8Context, maxCachedWorkflows, tuner, debugMode } = worker.options;
72
+ // debugMode runs workflows in the main isolate and spawns no workflow threads.
73
+ const isolateCount = debugMode ? 1 : 1 + workflowThreadPoolSize;
74
+ const heapSizeLimit = getHeapStatistics().heap_size_limit;
75
+ const memoryLimit = resolveMemoryLimit();
76
+ const workflowTaskSlots = tuner?.workflowTaskSlotSupplier?.numSlots;
77
+ const projectedCommittedHeap = isolateCount * heapSizeLimit;
78
+
79
+ log.info( 'Worker sizing', {
80
+ workflowThreadPoolSize,
81
+ reuseV8Context,
82
+ isolateCount,
83
+ heapSizeLimit,
84
+ projectedCommittedHeap,
85
+ memoryLimit,
86
+ maxCachedWorkflows,
87
+ workflowTaskSlots
88
+ } );
89
+
90
+ if ( projectedCommittedHeap > memoryLimit ) {
91
+ log.warn( 'Worker isolates may commit more heap than the host allows', { isolateCount, heapSizeLimit, projectedCommittedHeap, memoryLimit } );
92
+ }
93
+
94
+ if ( workflowTaskSlots > maxCachedWorkflows ) {
95
+ log.warn( 'Worker runs more workflow tasks than it can cache, forcing replays', { workflowTaskSlots, maxCachedWorkflows } );
96
+ }
97
+ };
98
+
99
+ /**
100
+ * Start an interval that logs worker status and memory every
101
+ * OUTPUT_WORKER_TELEMETRY_INTERVAL_MS. Disabled when it is 0.
102
+ *
103
+ * Each record holds the Temporal worker's `status` and a `memory`
104
+ * block. The memory fields mix process-wide and main-isolate scopes:
105
+ *
106
+ * - `availableMemory`: memory the process can still allocate, within
107
+ * the container limit.
108
+ * - `memoryLimit`: the container's limit, or the machine's total memory
109
+ * when unconstrained.
110
+ * - `memoryUsage`: raw `process.memoryUsage()`. `rss` is process-wide;
111
+ * `heapTotal` and `heapUsed` cover only the main isolate.
112
+ * - `nonMainHeap`: `memoryUsage.rss - memoryUsage.heapUsed`, the
113
+ * resident memory outside the main isolate's live objects: workflow
114
+ * thread heaps, Rust core allocations, buffers, and heap pages V8 has
115
+ * committed but not filled. An upper bound on the workflow thread
116
+ * heap, not a measurement of it. Cached workflow memory is counted
117
+ * here, so it grows with the cache while `heapUsed` stays flat.
118
+ * - `heapSizeLimit`: the main isolate's V8 heap ceiling. Constant, but
119
+ * included in each sample so records are self-contained.
120
+ *
121
+ * @param {object} params Parameters.
122
+ * @param {import('@temporalio/worker').Worker} params.worker The created Temporal worker.
123
+ */
7
124
  export const setupTelemetry = ( { worker } ) => {
8
125
  if ( workerTelemetryIntervalMs <= 0 ) {
9
126
  return;
10
127
  }
11
128
  setInterval( () => {
12
129
  try {
130
+ const memoryUsage = process.memoryUsage();
13
131
  log.info( 'Worker', {
14
132
  status: worker.getStatus(),
15
133
  memory: {
16
134
  availableMemory: process.availableMemory(),
17
- constrainedMemory: process.constrainedMemory(),
18
- memoryUsage: process.memoryUsage()
135
+ memoryLimit: resolveMemoryLimit(),
136
+ memoryUsage,
137
+ nonMainHeap: memoryUsage.rss - memoryUsage.heapUsed,
138
+ heapSizeLimit: getHeapStatistics().heap_size_limit
19
139
  }
20
140
  } );
21
141
  } catch ( error ) {
@@ -15,8 +15,8 @@ const evaluatorsNameCache = new Map(); // path -> Map<exported, evaluatorName>
15
15
  const sharedEvaluatorsNameCache = new Map(); // path -> Map<exported, evaluatorName> (shared)
16
16
 
17
17
  /**
18
- * Webpack loader that rewrites imported step/evaluator calls by reading
19
- * declared activity names and transforming function-body activity calls accordingly.
18
+ * Webpack loader that strips imported steps/evaluators by reading declared activity names,
19
+ * transforming function-body activity calls and replacing other references with the activity name.
20
20
  * Preserves sourcemaps.
21
21
  *
22
22
  * @param {string|Buffer} source - Module source code.
@@ -40,11 +40,7 @@ export default function stepImportRewriterAstLoader( source, inputMap ) {
40
40
  return callback( null, source, inputMap );
41
41
  }
42
42
 
43
- const rewrote = rewriteActivityCalls( { ast, activityImports } );
44
- // No edits performed
45
- if ( !rewrote ) {
46
- return callback( null, source, inputMap );
47
- }
43
+ rewriteActivityCalls( { ast, activityImports } );
48
44
 
49
45
  const { code, map } = generate( ast, {
50
46
  sourceMaps: true,
@@ -54,8 +54,6 @@ const createInvokeActivityCall = ( activityName, args ) =>
54
54
 
55
55
  // Rewrite valid function-body activity calls; top-level call validation belongs to the validator loader.
56
56
  const rewriteActivityCallsInFunctions = ( { ast, activityNames } ) => {
57
- const state = { rewrote: false };
58
-
59
57
  traverse( ast, {
60
58
  CallExpression: path => {
61
59
  if ( !path.getFunctionParent() || !isIdentifierCallee( path ) ) {
@@ -70,19 +68,41 @@ const rewriteActivityCallsInFunctions = ( { ast, activityNames } ) => {
70
68
 
71
69
  assertGlobalThisIsSafe( path );
72
70
  path.replaceWith( createInvokeActivityCall( activityName, path.node.arguments ) );
73
- state.rewrote = true;
74
71
  }
75
72
  } );
73
+ };
74
+
75
+ // Calls belong to the call rewrite (function bodies) or the validator loader (top level).
76
+ const isCallee = path => path.parentPath.isCallExpression( { callee: path.node } );
77
+
78
+ // The activity import is stripped from the bundle, so non-call references become the activity name.
79
+ const rewriteActivityReferences = ( { ast, activityNames } ) => {
80
+ traverse( ast, {
81
+ Identifier: path => {
82
+ const { name } = path.node;
83
+ const activityName = activityNames.get( name );
84
+ if ( !activityName || !path.isReferencedIdentifier() || isCallee( path ) || path.parentPath.isExportSpecifier() ) {
85
+ return;
86
+ }
87
+ if ( hasLiveLocalBinding( path, name ) ) {
88
+ return;
89
+ }
76
90
 
77
- return state.rewrote;
91
+ if ( path.parentPath.isObjectProperty( { shorthand: true } ) ) {
92
+ path.parent.shorthand = false;
93
+ }
94
+ path.replaceWith( stringLiteral( activityName ) );
95
+ }
96
+ } );
78
97
  };
79
98
 
80
- // Entry point: resolve collected component imports into plain dispatcher calls.
99
+ // Entry point: resolve collected component imports into dispatcher calls and activity names.
81
100
  export default function rewriteActivityCalls( { ast, activityImports } ) {
82
101
  const activityNames = buildActivityNameMap( activityImports );
83
102
  if ( activityNames.size === 0 ) {
84
- return false;
103
+ return;
85
104
  }
86
105
 
87
- return rewriteActivityCallsInFunctions( { ast, activityNames } );
106
+ rewriteActivityCallsInFunctions( { ast, activityNames } );
107
+ rewriteActivityReferences( { ast, activityNames } );
88
108
  };
@@ -103,8 +103,7 @@ const findPackageJson = ( fromDir, packageName ) => {
103
103
  /**
104
104
  * Choose the best concrete file target from a package exports target.
105
105
  *
106
- * Prefers the workflow-specific webpack condition, then the same fallback conditions used by
107
- * `webpackConfigHook`.
106
+ * Uses the same conditions as `webpackConfigHook`.
108
107
  *
109
108
  * @param {string|Array|object|null|undefined} target - Value from package.json `exports`.
110
109
  * @returns {string|null} Relative file target, or null when no supported condition resolves.
@@ -126,7 +125,7 @@ const resolveConditionalExportTarget = target => {
126
125
  return null;
127
126
  }
128
127
 
129
- for ( const condition of [ 'output-workflow-bundle', 'import', 'module', 'webpack', 'default' ] ) {
128
+ for ( const condition of [ 'import', 'module', 'webpack', 'default' ] ) {
130
129
  if ( condition in target ) {
131
130
  const resolved = resolveConditionalExportTarget( target[condition] );
132
131
  if ( resolved ) {
@@ -138,7 +137,7 @@ const resolveConditionalExportTarget = target => {
138
137
  };
139
138
 
140
139
  /**
141
- * Resolve a bare package specifier using the `output-workflow-bundle` export condition when present.
140
+ * Resolve a bare package specifier from its package.json `exports`.
142
141
  *
143
142
  * This keeps AST workflow import resolution aligned with webpack's configured condition order before
144
143
  * falling back to Node's `require.resolve`.
@@ -147,7 +146,7 @@ const resolveConditionalExportTarget = target => {
147
146
  * @param {string} specifier - Bare npm package specifier.
148
147
  * @returns {string|null} Absolute module path selected from package exports, or null when unsupported.
149
148
  */
150
- const resolveBareSpecifierWithOutputCondition = ( fromAbsoluteFile, specifier ) => {
149
+ const resolveBareSpecifierWithExportConditions = ( fromAbsoluteFile, specifier ) => {
151
150
  const { packageName, subpath } = packagePartsFromSpecifier( specifier );
152
151
  const pkgJsonPath = findPackageJson( dirname( fromAbsoluteFile ), packageName );
153
152
  if ( !pkgJsonPath ) {
@@ -315,7 +314,7 @@ const moduleMayExportWorkflows = ( moduleAbsPath, visited = new Set() ) => {
315
314
  * @returns {string|null} Absolute path to the resolved entry file, or null on failure.
316
315
  */
317
316
  const resolveBareSpecifierToFirstModule = ( fromAbsoluteFile, specifier ) => {
318
- const conditionalEntry = resolveBareSpecifierWithOutputCondition( fromAbsoluteFile, specifier );
317
+ const conditionalEntry = resolveBareSpecifierWithExportConditions( fromAbsoluteFile, specifier );
319
318
  if ( conditionalEntry ) {
320
319
  return conditionalEntry;
321
320
  }
@@ -0,0 +1,43 @@
1
+ import * as configs from './configs.js';
2
+ import { createChildLogger } from '#logger';
3
+
4
+ const log = createChildLogger( 'Worker' );
5
+
6
+ const {
7
+ maxConcurrentWorkflowTaskExecutions,
8
+ maxConcurrentActivityTaskExecutions,
9
+ maxCachedWorkflows,
10
+ maxConcurrentActivityTaskPolls,
11
+ maxConcurrentWorkflowTaskPolls,
12
+ workflowThreadPoolSize,
13
+ shutdownForceTime,
14
+ shutdownGraceTime,
15
+ workerTuner
16
+ } = configs;
17
+
18
+ /**
19
+ * Builds the concurrency, cache and shutdown options passed to `Worker.create`.
20
+ * Unset values are omitted so @temporalio/worker applies its own defaults.
21
+ * @returns {object} partial Temporal worker options
22
+ */
23
+ export const buildWorkerOptions = () => {
24
+ if ( workerTuner ) {
25
+ log.info( 'Using worker tuner options', { ...workerTuner } );
26
+ }
27
+ return {
28
+ // tuner isn't compatible with concurrent task executions configs
29
+ ...( workerTuner ? {
30
+ tuner: workerTuner
31
+ } : {
32
+ ...( maxConcurrentWorkflowTaskExecutions !== undefined && { maxConcurrentWorkflowTaskExecutions } ),
33
+ maxConcurrentActivityTaskExecutions
34
+ } ),
35
+ ...( maxCachedWorkflows !== undefined && { maxCachedWorkflows } ),
36
+ maxConcurrentActivityTaskPolls,
37
+ maxConcurrentWorkflowTaskPolls,
38
+ // Omitted when unset so @temporalio/worker applies its own default, which depends on reuseV8Context.
39
+ ...( workflowThreadPoolSize !== undefined && { workflowThreadPoolSize } ),
40
+ ...( shutdownForceTime !== undefined && { shutdownForceTime } ),
41
+ ...( shutdownGraceTime !== undefined && { shutdownGraceTime } )
42
+ };
43
+ };
package/src/sdk/README.md DELETED
@@ -1,47 +0,0 @@
1
- ## SDK integration API for Output packages
2
-
3
- **THESE MODULES ARE NOT PUBLIC. DO NOT IMPORT THEM ON YOUR PROJECT.**
4
-
5
- This folder contains integration helpers used by other Output SDK packages.
6
-
7
- The two subfolders represent a hard Temporal boundary. Code imported by
8
- workflow-bundled modules must only depend on `helpers`. Code that needs worker
9
- or activity runtime state belongs in `runtime`.
10
-
11
- Do not change these without reviewing call-sites.
12
-
13
- ### `helpers`
14
-
15
- Helpers must be safe to import while Temporal workflows are bundled and executed
16
- in the workflow sandbox.
17
-
18
- Allowed:
19
-
20
- - Stateless functions and namespace objects.
21
- - Deterministic code with no runtime side effects at import time.
22
- - Imports from other sandbox-safe helper modules.
23
- - Small, dependency-free helpers for any deterministic computation that can run
24
- without worker or activity state.
25
-
26
- Not allowed:
27
-
28
- - Access to activity context, async storage, sinks, tracing state, workers, or
29
- clients.
30
- - Imports from `@temporalio/activity`, `@temporalio/worker`, or Node-only APIs
31
- that cannot be bundled into workflow code.
32
- - Process, filesystem, network, clock, randomness, or environment access unless
33
- the behavior is known to be safe and deterministic in the workflow sandbox.
34
- - Any import chain that reaches `runtime`.
35
-
36
- If a helper cannot satisfy these rules, put it in `runtime` instead.
37
-
38
- ### `runtime`
39
-
40
- Runtime modules are for helpers that need Output or Temporal runtime state.
41
-
42
- Use `runtime` for activity-only integrations such as context lookup, event
43
- emission, tracing, async storage, worker state, sinks, and other behavior that is
44
- not safe inside workflow-bundled code.
45
-
46
- Runtime modules may depend on activity runtime APIs and internal state, but they
47
- must not be imported by workflow-safe code.
@@ -1,17 +0,0 @@
1
- /**
2
- * Tools to extract data from Outputai Core Components metadata storage
3
- */
4
- export declare const ComponentMetadata: {
5
- /**
6
- * Extract the name from a workflow(), step() or evaluator() return
7
- * @param fn
8
- * @returns
9
- */
10
- getName( fn: Function ): string | undefined;
11
-
12
- /**
13
- * Check if a function has metadata from workflow(), step() or evaluator()
14
- * @param fn
15
- */
16
- has( fn: Function ): boolean;
17
- };
@@ -1,6 +0,0 @@
1
- import { METADATA_ACCESS_SYMBOL } from '#consts';
2
-
3
- export const ComponentMetadata = {
4
- getName: fn => fn[METADATA_ACCESS_SYMBOL]?.name,
5
- has: fn => !!fn[METADATA_ACCESS_SYMBOL]
6
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * > [!WARNING]
3
- * > **Internal use only.** Not part of the public API; may change without notice.
4
- *
5
- * These are stateless helpers for other SDK modules integration.
6
- * They can be used while Temporal workflows are bundled.
7
- *
8
- * @packageDocumentation
9
- */
10
- export * from './component_metadata.js';
11
- export * from './path.js';
12
- export * from './objects.js';
@@ -1,3 +0,0 @@
1
- export * from './component_metadata.js';
2
- export * from './path.js';
3
- export * from './objects.js';
@@ -1,56 +0,0 @@
1
- /** Tools to manipulate JS Objects */
2
- export declare const Objects: {
3
- /**
4
- * Node safe clone implementation that doesn't use global structuredClone().
5
- *
6
- * Returns a cloned version of the object.
7
- *
8
- * Only clones static properties. Getters become static properties.
9
- *
10
- * @param object
11
- */
12
- clone( object: object ): object,
13
-
14
- /**
15
- * Returns true if the value is a plain object:
16
- * - `{}`
17
- * - `new Object()`
18
- * - `Object.create(null)`
19
- *
20
- * @param object - The value to check.
21
- * @returns Whether the value is a plain object.
22
- */
23
- isPlainObject( object: unknown ): boolean,
24
-
25
- /**
26
- * Creates a new object by recursively merging overlays onto a base object.
27
- * Later objects overwrite fields from earlier objects.
28
- *
29
- * Non-object overlays are ignored.
30
- *
31
- * @param base - The base object.
32
- * @param overlays - The overriding objects, applied from left to right.
33
- * @throws {Error} If `base` is not a plain object.
34
- * @returns A new merged object.
35
- */
36
- deepMerge( base: object, ...overlays: Array<object | null | undefined> ): object,
37
-
38
- /**
39
- * Creates a new object by recursively merging overlays onto a base object.
40
- * Existing leaf values are resolved by the resolver function.
41
- *
42
- * Non-object overlays are ignored.
43
- *
44
- * @param base - The base object.
45
- * @param args - The overriding objects, applied from left to right, followed by the resolver function.
46
- * @throws {Error} If `base` is not a plain object.
47
- * @returns A new merged object.
48
- */
49
- deepMergeWithResolver(
50
- base: object,
51
- ...args: [
52
- ...overlays: Array<object | null | undefined>,
53
- resolver: ( a: unknown, b: unknown ) => unknown
54
- ]
55
- ): object
56
- };
@@ -1,8 +0,0 @@
1
- import { clone, deepMerge, deepMergeWithResolver, isPlainObject } from '#helpers/object';
2
-
3
- export const Objects = {
4
- clone,
5
- deepMerge,
6
- deepMergeWithResolver,
7
- isPlainObject
8
- };
@@ -1,11 +0,0 @@
1
- /**
2
- * Tools to interact with filesystem paths
3
- */
4
- export declare const Path: {
5
- /**
6
- * Return the first immediate directory of the file invoking the code that called this function.
7
- *
8
- * Excludes `@outputai/core`, node, other internal paths, and any additional ignore paths.
9
- */
10
- resolveInvocationDir( additionalIgnorePaths?: string[] ): string
11
- };
@@ -1,32 +0,0 @@
1
- import * as stackTraceParser from 'stacktrace-parser';
2
-
3
- // OS separator, but in a deterministic way, allowing this to work in Temporal's sandbox
4
- // This avoids importing from node:path
5
- const SEP = new Error().stack.includes( '/' ) ? '/' : '\\';
6
- const transformSeparators = path => path.replaceAll( '/', SEP );
7
-
8
- const defaultIgnorePaths = [
9
- '/@outputai/core/',
10
- '/@outputai/llm/',
11
- '/@outputai/evals/',
12
- '/sdk/core/',
13
- '/sdk/llm/',
14
- '/sdk/evals/',
15
- 'node:internal/',
16
- 'evalmachine.',
17
- 'webpack/bootstrap'
18
- ];
19
-
20
- export const Path = {
21
- resolveInvocationDir: ( additionalIgnorePaths = [] ) => {
22
- const stack = new Error().stack;
23
- const lines = stackTraceParser.parse( stack );
24
- const ignorePaths = [ ...additionalIgnorePaths, ...defaultIgnorePaths ].map( transformSeparators );
25
-
26
- const frame = lines.find( l => !ignorePaths.some( p => l.file.includes( p ) ) );
27
- if ( !frame ) {
28
- throw new Error( `Invocation dir resolution via stack trace failed. Stack: ${stack}` );
29
- }
30
- return frame.file.replace( 'file://', '' ).split( SEP ).slice( 0, -1 ).join( SEP );
31
- }
32
- };