@hatchet-dev/typescript-sdk 1.31.1 → 1.32.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 (46) hide show
  1. package/README.md +46 -0
  2. package/clients/dispatcher/action-listener.d.ts +3 -8
  3. package/clients/dispatcher/action-listener.js +7 -25
  4. package/clients/dispatcher/action.d.ts +19 -0
  5. package/clients/dispatcher/action.js +35 -0
  6. package/clients/dispatcher/dispatcher-client.d.ts +2 -2
  7. package/clients/dispatcher/heartbeat/heartbeat-controller.d.ts +1 -1
  8. package/clients/listeners/durable-listener/durable-events.d.ts +56 -0
  9. package/clients/listeners/durable-listener/durable-events.js +2 -0
  10. package/clients/listeners/durable-listener/durable-listener-client.d.ts +3 -52
  11. package/clients/listeners/durable-listener/durable-listener-client.js +3 -2
  12. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +2 -1
  13. package/clients/listeners/run-listener/pooled-child-listener-client.js +2 -1
  14. package/clients/rest/generated/Api.d.ts +1 -62
  15. package/clients/rest/generated/Api.js +0 -50
  16. package/clients/rest/generated/data-contracts.d.ts +0 -52
  17. package/dist/check-edge-entry.mjs +84 -0
  18. package/edge/declarations.d.ts +49 -0
  19. package/edge/declarations.js +21 -0
  20. package/edge/index.d.ts +49 -0
  21. package/edge/index.js +115 -0
  22. package/package.json +7 -2
  23. package/scripts/check-edge-entry.mjs +84 -0
  24. package/util/abort-error.d.ts +0 -10
  25. package/util/abort-error.js +0 -15
  26. package/util/abort-signal.d.ts +12 -0
  27. package/util/abort-signal.js +19 -0
  28. package/util/logger/logger.d.ts +1 -1
  29. package/v1/client/worker/context.d.ts +58 -12
  30. package/v1/client/worker/context.js +79 -51
  31. package/v1/client/worker/deprecated/pre-eviction.d.ts +5 -2
  32. package/v1/client/worker/deprecated/pre-eviction.js +5 -0
  33. package/v1/client/worker/runtime.d.ts +118 -0
  34. package/v1/client/worker/runtime.js +9 -0
  35. package/v1/client/worker/worker-internal.d.ts +3 -39
  36. package/v1/client/worker/worker-internal.js +22 -393
  37. package/v1/client/worker/worker-runtime.d.ts +8 -0
  38. package/v1/client/worker/worker-runtime.js +67 -0
  39. package/v1/client/worker/workflow-proto.d.ts +76 -0
  40. package/v1/client/worker/workflow-proto.js +482 -0
  41. package/v1/parent-run-context-storage.d.ts +11 -0
  42. package/v1/parent-run-context-storage.js +28 -0
  43. package/v1/parent-run-context-vars.d.ts +15 -1
  44. package/v1/parent-run-context-vars.js +13 -4
  45. package/version.d.ts +1 -1
  46. package/version.js +1 -1
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+ // Verifies the edge entry point (`@hatchet-dev/typescript-sdk/edge`) imports nothing
4
+ // from Node. Bundles dist/edge/index.js for a workerd-like browser target and fails on
5
+ // any `node:` specifier or Node builtin reached from it, transitively.
6
+ //
7
+ // Run after `pnpm run tsc:build` (the `check:edge` script does both). An alternative
8
+ // entry can be given as the first argument to inspect another module, for example
9
+ // `node scripts/check-edge-entry.mjs dist/index.js` to see what the root reaches.
10
+ import { builtinModules } from 'node:module';
11
+ import { existsSync } from 'node:fs';
12
+ import { resolve, dirname } from 'node:path';
13
+ import { fileURLToPath } from 'node:url';
14
+ import { build } from 'esbuild';
15
+
16
+ const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
17
+ const entry = resolve(root, process.argv[2] ?? 'dist/edge/index.js');
18
+
19
+ if (!existsSync(entry)) {
20
+ console.error(`entry not built: ${entry} is missing. Run \`pnpm run tsc:build\` first.`);
21
+ process.exit(1);
22
+ }
23
+
24
+ // Optional peers the declaration classes load lazily (`mcpTool()`); never reached on a
25
+ // serverless code path and not part of the edge contract.
26
+ const lazyOptionalPeers = ['@openai/agents', '@anthropic-ai/claude-agent-sdk', '@modelcontextprotocol/sdk'];
27
+
28
+ const builtins = new Set(builtinModules.flatMap((m) => [m, `node:${m}`]));
29
+ const violations = new Map();
30
+
31
+ const nodeBuiltinDetector = {
32
+ name: 'node-builtin-detector',
33
+ setup(pluginBuild) {
34
+ pluginBuild.onResolve({ filter: /.*/ }, (args) => {
35
+ const isBuiltin = args.path.startsWith('node:') || builtins.has(args.path);
36
+ if (!isBuiltin) return undefined;
37
+ const importer = args.importer ? args.importer.replace(`${root}/`, '') : '<entry>';
38
+ if (!violations.has(args.path)) violations.set(args.path, new Set());
39
+ violations.get(args.path).add(importer);
40
+ // Resolve to an empty stub so the bundle continues and every violation is collected.
41
+ return { path: args.path, namespace: 'node-builtin-stub' };
42
+ });
43
+ pluginBuild.onLoad({ filter: /.*/, namespace: 'node-builtin-stub' }, () => ({
44
+ contents: 'export default {};',
45
+ loader: 'js',
46
+ }));
47
+ },
48
+ };
49
+
50
+ const result = await build({
51
+ entryPoints: [entry],
52
+ bundle: true,
53
+ write: false,
54
+ platform: 'browser',
55
+ conditions: ['workerd', 'worker', 'browser'],
56
+ mainFields: ['browser', 'module', 'main'],
57
+ format: 'esm',
58
+ target: 'es2022',
59
+ logLevel: 'silent',
60
+ metafile: true,
61
+ external: lazyOptionalPeers,
62
+ plugins: [nodeBuiltinDetector],
63
+ });
64
+
65
+ const bundled = Object.keys(result.metafile.inputs);
66
+ const sdkInputs = bundled.filter((f) => f.startsWith('dist/'));
67
+ const packageInputs = [...new Set(bundled.filter((f) => f.includes('node_modules/')).map((f) => {
68
+ const m = f.match(/node_modules\/(?:\.pnpm\/[^/]+\/node_modules\/)?((?:@[^/]+\/)?[^/]+)/);
69
+ return m ? m[1] : f;
70
+ }))].sort();
71
+
72
+ console.log(`edge entry: bundled ${sdkInputs.length} SDK module(s) and ${packageInputs.length} package(s)`);
73
+ if (packageInputs.length) console.log(`packages: ${packageInputs.join(', ')}`);
74
+
75
+ if (violations.size > 0) {
76
+ console.error('\nedge entry reaches Node builtins:');
77
+ for (const [specifier, importers] of [...violations.entries()].sort()) {
78
+ console.error(` ${specifier}`);
79
+ for (const importer of [...importers].sort()) console.error(` from ${importer}`);
80
+ }
81
+ process.exit(1);
82
+ }
83
+
84
+ console.log('edge entry is free of Node builtins');
@@ -0,0 +1,49 @@
1
+ import { CreateBatchTaskWorkflowOpts, CreateDurableTaskWorkflowOpts, CreateTaskWorkflowOpts, CreateWorkflowOpts, TaskWorkflowDeclaration, WorkflowDeclaration } from '../v1/declaration';
2
+ import type { InputType, JsonObject, OutputType, StrictWorkflowOutputType, UnknownInputType } from '../v1/types';
3
+ import type { BatchTaskConfig, BatchTaskFn } from '../v1/task';
4
+ import type { DurableContext } from '../v1/client/worker/context';
5
+ /**
6
+ * The declaration factories of `HatchetClient` (`task`, `durableTask`, `workflow`,
7
+ * `batchTask`) bound to no client. The declarations they return can be registered and
8
+ * served but cannot be run, scheduled or triggered from the process that declared them.
9
+ */
10
+ export interface Declarations {
11
+ /**
12
+ * Declares a task. Types come from generics or are inferred from `fn`.
13
+ */
14
+ task<I extends InputType = UnknownInputType, O extends OutputType = void>(options: CreateTaskWorkflowOpts<I, O>): TaskWorkflowDeclaration<I, O>;
15
+ task<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends InputType = Parameters<Fn>[0], O extends OutputType = ReturnType<Fn> extends Promise<infer P> ? P extends OutputType ? P : void : ReturnType<Fn> extends OutputType ? ReturnType<Fn> : void>(options: {
16
+ fn: Fn;
17
+ } & Omit<CreateTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
18
+ /**
19
+ * Declares a durable task. Types come from generics or are inferred from `fn`.
20
+ */
21
+ durableTask<I extends InputType, O extends OutputType>(options: CreateDurableTaskWorkflowOpts<I, O>): TaskWorkflowDeclaration<I, O>;
22
+ durableTask<Fn extends (input: I, ctx: DurableContext<I>) => O | Promise<O>, I extends JsonObject = Parameters<Fn>[0], O extends JsonObject = ReturnType<Fn> extends Promise<infer P> ? P extends JsonObject ? P : never : ReturnType<Fn> extends JsonObject ? ReturnType<Fn> : never>(options: {
23
+ fn: Fn;
24
+ } & Omit<CreateDurableTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
25
+ /**
26
+ * Declares a workflow: a DAG of tasks added with `workflow.task(...)`.
27
+ */
28
+ workflow<I extends InputType = UnknownInputType, O extends StrictWorkflowOutputType = {}>(options: CreateWorkflowOpts): WorkflowDeclaration<I, O>;
29
+ /**
30
+ * Declares a batch task. Types come from generics or are inferred from `fn`.
31
+ *
32
+ * Preview: batch tasks are in beta and may change in future releases.
33
+ */
34
+ batchTask<I extends InputType = UnknownInputType, O extends OutputType = void>(options: CreateBatchTaskWorkflowOpts<I, O>): TaskWorkflowDeclaration<I, O>;
35
+ batchTask<Fn extends BatchTaskFn<I, O>, I extends InputType = Parameters<Fn>[0] extends Record<string, infer II> ? II extends InputType ? II : UnknownInputType : UnknownInputType, O extends OutputType = ReturnType<Fn> extends Promise<infer P> ? P extends OutputType ? P : void : ReturnType<Fn> extends OutputType ? ReturnType<Fn> : void>(options: {
36
+ fn: Fn;
37
+ batch: BatchTaskConfig;
38
+ } & Omit<CreateBatchTaskWorkflowOpts<I, O>, 'fn' | 'batch'>): TaskWorkflowDeclaration<I, O>;
39
+ }
40
+ /**
41
+ * Returns the declaration factories bound to no client, so tasks can be declared where
42
+ * a `HatchetClient` cannot exist (edge runtimes, or code that must not read
43
+ * `HATCHET_CLIENT_TOKEN`).
44
+ *
45
+ * ```typescript
46
+ * const { task, durableTask, workflow, batchTask } = declarations();
47
+ * ```
48
+ */
49
+ export declare function declarations(): Declarations;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.declarations = declarations;
4
+ const declaration_1 = require("../v1/declaration");
5
+ /**
6
+ * Returns the declaration factories bound to no client, so tasks can be declared where
7
+ * a `HatchetClient` cannot exist (edge runtimes, or code that must not read
8
+ * `HATCHET_CLIENT_TOKEN`).
9
+ *
10
+ * ```typescript
11
+ * const { task, durableTask, workflow, batchTask } = declarations();
12
+ * ```
13
+ */
14
+ function declarations() {
15
+ return {
16
+ task: (options) => (0, declaration_1.CreateTaskWorkflow)(options),
17
+ durableTask: (options) => (0, declaration_1.CreateDurableTaskWorkflow)(options),
18
+ workflow: (options) => (0, declaration_1.CreateWorkflow)(options),
19
+ batchTask: (options) => (0, declaration_1.CreateBatchTaskWorkflow)(options),
20
+ };
21
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The edge entry point: everything needed to declare Hatchet tasks and run them from a
3
+ * runtime that has no Hatchet client, such as a Cloudflare Worker or a Vercel Function.
4
+ *
5
+ * Nothing exported here imports from Node. `scripts/check-edge-entry.mjs` bundles this
6
+ * module for a browser-like target and fails the build if a Node builtin sneaks in.
7
+ *
8
+ * ```typescript
9
+ * import { declarations, workflowToProto } from './';
10
+ *
11
+ * const { task } = declarations();
12
+ * const greet = task({ name: 'greet', fn: (input: { name: string }) => ({ hi: input.name }) });
13
+ * const request = workflowToProto(greet, { namespace: 'prod_' });
14
+ * ```
15
+ * @module Edge
16
+ */
17
+ export { BaseWorkflowDeclaration, CreateBatchTaskWorkflow, CreateDurableTaskWorkflow, CreateTaskWorkflow, CreateWorkflow, Priority, StickyStrategy, TaskWorkflowDeclaration, WorkflowDeclaration, } from '../v1/declaration';
18
+ export type { CreateBaseWorkflowOpts, CreateBatchTaskWorkflowOpts, CreateDurableTaskWorkflowOpts, CreateTaskWorkflowOpts, CreateWorkflowOpts, RunManyOpt, RunOpts, StickyStrategyInput, TaskDefaults, TaskOutput, TaskOutputType, WorkflowDefinition, } from '../v1/declaration';
19
+ export * from '../v1/task';
20
+ export * from '../v1/types';
21
+ export * from '../v1/client/duration';
22
+ export * from '../v1/conditions';
23
+ export { conditionsToPb, taskConditionsToPb } from '../v1/conditions/transformer';
24
+ export { applyNamespace } from '../util/apply-namespace';
25
+ export { createAction, createActionId, workflowNameFromAction, } from '../clients/dispatcher/action';
26
+ export type { Action, ActionKey } from '../clients/dispatcher/action';
27
+ export { Context, ContextWorker, DurableContext, computeMemoKey, } from '../v1/client/worker/context';
28
+ export type { SleepForOptions, SleepResult } from '../v1/client/worker/context';
29
+ export type { CancelBatchRequest, ContextRuntime, DesiredWorkerLabel, DurableContextOptions, DurableTransport, SpawnRunOptions, SpawnRunRequest, WorkerLabels, } from '../v1/client/worker/runtime';
30
+ export { isContextRuntime } from '../v1/client/worker/runtime';
31
+ export type { DurableTaskEventAck, DurableTaskEventLogEntryResult, DurableTaskEventMemoAck, DurableTaskEventRunAck, DurableTaskEventWaitForAck, DurableTaskRunAckEntryResult, DurableTaskSendEvent, MemoEvent, RunChildrenEvent, WaitForEvent, } from '../clients/listeners/durable-listener/durable-events';
32
+ export { Logger, LogLevelEnum } from '../util/logger/logger';
33
+ export type { LogExtra, LogLevel } from '../util/logger/logger';
34
+ export { ParentRunContextManager, parentRunContextManager, } from '../v1/parent-run-context-vars';
35
+ export type { ParentRunContext, ParentRunContextStorage, } from '../v1/parent-run-context-vars';
36
+ export { default as HatchetError, getErrorMessage, toHatchetError, } from '../util/errors/hatchet-error';
37
+ export { NonDeterminismError } from '../util/errors/non-determinism-error';
38
+ export { TaskRunTerminatedError, isTaskRunTerminatedError, } from '../util/errors/task-run-terminated-error';
39
+ export type { TaskRunTerminationReason } from '../util/errors/task-run-terminated-error';
40
+ export { AbortError, createAbortError, isAbortError, rethrowIfAborted, throwIfAborted, } from '../util/abort-error';
41
+ export { DEFAULT_DURABLE_TASK_EVICTION_POLICY, EvictionPolicy, } from '../v1/client/worker/eviction/eviction-policy';
42
+ export { MinEngineVersion, supportsEviction } from '../v1/client/worker/engine-version';
43
+ export { ON_FAILURE_TASK_NAME, ON_SUCCESS_TASK_NAME, normalizeWorkflowDefinition, onFailureTaskName, workflowToProto, } from '../v1/client/worker/workflow-proto';
44
+ export type { WorkflowProtoOptions } from '../v1/client/worker/workflow-proto';
45
+ export { CreateWorkflowVersionRequest } from '../protoc/v1/workflows';
46
+ export { AssignedAction } from '../protoc/dispatcher';
47
+ export { DurableTaskRequest, DurableTaskResponse } from '../protoc/v1/dispatcher';
48
+ export { declarations } from './declarations';
49
+ export type { Declarations } from './declarations';
package/edge/index.js ADDED
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ /**
3
+ * The edge entry point: everything needed to declare Hatchet tasks and run them from a
4
+ * runtime that has no Hatchet client, such as a Cloudflare Worker or a Vercel Function.
5
+ *
6
+ * Nothing exported here imports from Node. `scripts/check-edge-entry.mjs` bundles this
7
+ * module for a browser-like target and fails the build if a Node builtin sneaks in.
8
+ *
9
+ * ```typescript
10
+ * import { declarations, workflowToProto } from './index.js';
11
+ *
12
+ * const { task } = declarations();
13
+ * const greet = task({ name: 'greet', fn: (input: { name: string }) => ({ hi: input.name }) });
14
+ * const request = workflowToProto(greet, { namespace: 'prod_' });
15
+ * ```
16
+ * @module Edge
17
+ */
18
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ var desc = Object.getOwnPropertyDescriptor(m, k);
21
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
22
+ desc = { enumerable: true, get: function() { return m[k]; } };
23
+ }
24
+ Object.defineProperty(o, k2, desc);
25
+ }) : (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ o[k2] = m[k];
28
+ }));
29
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
30
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
31
+ };
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.declarations = exports.DurableTaskResponse = exports.DurableTaskRequest = exports.AssignedAction = exports.CreateWorkflowVersionRequest = exports.workflowToProto = exports.onFailureTaskName = exports.normalizeWorkflowDefinition = exports.ON_SUCCESS_TASK_NAME = exports.ON_FAILURE_TASK_NAME = exports.supportsEviction = exports.MinEngineVersion = exports.DEFAULT_DURABLE_TASK_EVICTION_POLICY = exports.throwIfAborted = exports.rethrowIfAborted = exports.isAbortError = exports.createAbortError = exports.AbortError = exports.isTaskRunTerminatedError = exports.TaskRunTerminatedError = exports.NonDeterminismError = exports.toHatchetError = exports.getErrorMessage = exports.HatchetError = exports.parentRunContextManager = exports.ParentRunContextManager = exports.LogLevelEnum = exports.Logger = exports.isContextRuntime = exports.computeMemoKey = exports.DurableContext = exports.ContextWorker = exports.Context = exports.workflowNameFromAction = exports.createActionId = exports.createAction = exports.applyNamespace = exports.taskConditionsToPb = exports.conditionsToPb = exports.WorkflowDeclaration = exports.TaskWorkflowDeclaration = exports.StickyStrategy = exports.Priority = exports.CreateWorkflow = exports.CreateTaskWorkflow = exports.CreateDurableTaskWorkflow = exports.CreateBatchTaskWorkflow = exports.BaseWorkflowDeclaration = void 0;
37
+ // Declarations
38
+ var declaration_1 = require("../v1/declaration");
39
+ Object.defineProperty(exports, "BaseWorkflowDeclaration", { enumerable: true, get: function () { return declaration_1.BaseWorkflowDeclaration; } });
40
+ Object.defineProperty(exports, "CreateBatchTaskWorkflow", { enumerable: true, get: function () { return declaration_1.CreateBatchTaskWorkflow; } });
41
+ Object.defineProperty(exports, "CreateDurableTaskWorkflow", { enumerable: true, get: function () { return declaration_1.CreateDurableTaskWorkflow; } });
42
+ Object.defineProperty(exports, "CreateTaskWorkflow", { enumerable: true, get: function () { return declaration_1.CreateTaskWorkflow; } });
43
+ Object.defineProperty(exports, "CreateWorkflow", { enumerable: true, get: function () { return declaration_1.CreateWorkflow; } });
44
+ Object.defineProperty(exports, "Priority", { enumerable: true, get: function () { return declaration_1.Priority; } });
45
+ Object.defineProperty(exports, "StickyStrategy", { enumerable: true, get: function () { return declaration_1.StickyStrategy; } });
46
+ Object.defineProperty(exports, "TaskWorkflowDeclaration", { enumerable: true, get: function () { return declaration_1.TaskWorkflowDeclaration; } });
47
+ Object.defineProperty(exports, "WorkflowDeclaration", { enumerable: true, get: function () { return declaration_1.WorkflowDeclaration; } });
48
+ // Tasks, types, durations and conditions
49
+ __exportStar(require("../v1/task"), exports);
50
+ __exportStar(require("../v1/types"), exports);
51
+ __exportStar(require("../v1/client/duration"), exports);
52
+ __exportStar(require("../v1/conditions"), exports);
53
+ var transformer_1 = require("../v1/conditions/transformer");
54
+ Object.defineProperty(exports, "conditionsToPb", { enumerable: true, get: function () { return transformer_1.conditionsToPb; } });
55
+ Object.defineProperty(exports, "taskConditionsToPb", { enumerable: true, get: function () { return transformer_1.taskConditionsToPb; } });
56
+ // Naming
57
+ var apply_namespace_1 = require("../util/apply-namespace");
58
+ Object.defineProperty(exports, "applyNamespace", { enumerable: true, get: function () { return apply_namespace_1.applyNamespace; } });
59
+ var action_1 = require("../clients/dispatcher/action");
60
+ Object.defineProperty(exports, "createAction", { enumerable: true, get: function () { return action_1.createAction; } });
61
+ Object.defineProperty(exports, "createActionId", { enumerable: true, get: function () { return action_1.createActionId; } });
62
+ Object.defineProperty(exports, "workflowNameFromAction", { enumerable: true, get: function () { return action_1.workflowNameFromAction; } });
63
+ // Contexts and the runtime seams they depend on
64
+ var context_1 = require("../v1/client/worker/context");
65
+ Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
66
+ Object.defineProperty(exports, "ContextWorker", { enumerable: true, get: function () { return context_1.ContextWorker; } });
67
+ Object.defineProperty(exports, "DurableContext", { enumerable: true, get: function () { return context_1.DurableContext; } });
68
+ Object.defineProperty(exports, "computeMemoKey", { enumerable: true, get: function () { return context_1.computeMemoKey; } });
69
+ var runtime_1 = require("../v1/client/worker/runtime");
70
+ Object.defineProperty(exports, "isContextRuntime", { enumerable: true, get: function () { return runtime_1.isContextRuntime; } });
71
+ var logger_1 = require("../util/logger/logger");
72
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
73
+ Object.defineProperty(exports, "LogLevelEnum", { enumerable: true, get: function () { return logger_1.LogLevelEnum; } });
74
+ var parent_run_context_vars_1 = require("../v1/parent-run-context-vars");
75
+ Object.defineProperty(exports, "ParentRunContextManager", { enumerable: true, get: function () { return parent_run_context_vars_1.ParentRunContextManager; } });
76
+ Object.defineProperty(exports, "parentRunContextManager", { enumerable: true, get: function () { return parent_run_context_vars_1.parentRunContextManager; } });
77
+ // Errors
78
+ var hatchet_error_1 = require("../util/errors/hatchet-error");
79
+ Object.defineProperty(exports, "HatchetError", { enumerable: true, get: function () { return __importDefault(hatchet_error_1).default; } });
80
+ Object.defineProperty(exports, "getErrorMessage", { enumerable: true, get: function () { return hatchet_error_1.getErrorMessage; } });
81
+ Object.defineProperty(exports, "toHatchetError", { enumerable: true, get: function () { return hatchet_error_1.toHatchetError; } });
82
+ var non_determinism_error_1 = require("../util/errors/non-determinism-error");
83
+ Object.defineProperty(exports, "NonDeterminismError", { enumerable: true, get: function () { return non_determinism_error_1.NonDeterminismError; } });
84
+ var task_run_terminated_error_1 = require("../util/errors/task-run-terminated-error");
85
+ Object.defineProperty(exports, "TaskRunTerminatedError", { enumerable: true, get: function () { return task_run_terminated_error_1.TaskRunTerminatedError; } });
86
+ Object.defineProperty(exports, "isTaskRunTerminatedError", { enumerable: true, get: function () { return task_run_terminated_error_1.isTaskRunTerminatedError; } });
87
+ var abort_error_1 = require("../util/abort-error");
88
+ Object.defineProperty(exports, "AbortError", { enumerable: true, get: function () { return abort_error_1.AbortError; } });
89
+ Object.defineProperty(exports, "createAbortError", { enumerable: true, get: function () { return abort_error_1.createAbortError; } });
90
+ Object.defineProperty(exports, "isAbortError", { enumerable: true, get: function () { return abort_error_1.isAbortError; } });
91
+ Object.defineProperty(exports, "rethrowIfAborted", { enumerable: true, get: function () { return abort_error_1.rethrowIfAborted; } });
92
+ Object.defineProperty(exports, "throwIfAborted", { enumerable: true, get: function () { return abort_error_1.throwIfAborted; } });
93
+ // Eviction policy
94
+ var eviction_policy_1 = require("../v1/client/worker/eviction/eviction-policy");
95
+ Object.defineProperty(exports, "DEFAULT_DURABLE_TASK_EVICTION_POLICY", { enumerable: true, get: function () { return eviction_policy_1.DEFAULT_DURABLE_TASK_EVICTION_POLICY; } });
96
+ var engine_version_1 = require("../v1/client/worker/engine-version");
97
+ Object.defineProperty(exports, "MinEngineVersion", { enumerable: true, get: function () { return engine_version_1.MinEngineVersion; } });
98
+ Object.defineProperty(exports, "supportsEviction", { enumerable: true, get: function () { return engine_version_1.supportsEviction; } });
99
+ // Registration
100
+ var workflow_proto_1 = require("../v1/client/worker/workflow-proto");
101
+ Object.defineProperty(exports, "ON_FAILURE_TASK_NAME", { enumerable: true, get: function () { return workflow_proto_1.ON_FAILURE_TASK_NAME; } });
102
+ Object.defineProperty(exports, "ON_SUCCESS_TASK_NAME", { enumerable: true, get: function () { return workflow_proto_1.ON_SUCCESS_TASK_NAME; } });
103
+ Object.defineProperty(exports, "normalizeWorkflowDefinition", { enumerable: true, get: function () { return workflow_proto_1.normalizeWorkflowDefinition; } });
104
+ Object.defineProperty(exports, "onFailureTaskName", { enumerable: true, get: function () { return workflow_proto_1.onFailureTaskName; } });
105
+ Object.defineProperty(exports, "workflowToProto", { enumerable: true, get: function () { return workflow_proto_1.workflowToProto; } });
106
+ // Wire types
107
+ var workflows_1 = require("../protoc/v1/workflows");
108
+ Object.defineProperty(exports, "CreateWorkflowVersionRequest", { enumerable: true, get: function () { return workflows_1.CreateWorkflowVersionRequest; } });
109
+ var dispatcher_1 = require("../protoc/dispatcher");
110
+ Object.defineProperty(exports, "AssignedAction", { enumerable: true, get: function () { return dispatcher_1.AssignedAction; } });
111
+ var dispatcher_2 = require("../protoc/v1/dispatcher");
112
+ Object.defineProperty(exports, "DurableTaskRequest", { enumerable: true, get: function () { return dispatcher_2.DurableTaskRequest; } });
113
+ Object.defineProperty(exports, "DurableTaskResponse", { enumerable: true, get: function () { return dispatcher_2.DurableTaskResponse; } });
114
+ var declarations_1 = require("./declarations");
115
+ Object.defineProperty(exports, "declarations", { enumerable: true, get: function () { return declarations_1.declarations; } });
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.31.1",
3
+ "version": "1.32.0",
4
+ "engines": {
5
+ "node": ">=20"
6
+ },
4
7
  "description": "Background task orchestration & visibility for developers",
5
- "types": "dist/index.d.ts",
8
+ "types": "index.d.ts",
6
9
  "files": [
7
10
  "*",
8
11
  "!**/*.test.js",
@@ -48,6 +51,7 @@
48
51
  "@types/node": "^22.13.14",
49
52
  "autoprefixer": "^10.4.27",
50
53
  "dotenv-cli": "^7.4.4",
54
+ "esbuild": "0.28.2",
51
55
  "eslint": "^10.0.3",
52
56
  "eslint-config-prettier": "^10.1.8",
53
57
  "eslint-import-resolver-typescript": "^3.10.0",
@@ -140,6 +144,7 @@
140
144
  "dump-version": "node -e \"console.log('export const HATCHET_VERSION = \\'' + require('./package.json').version + '\\';');\" > src/version.ts",
141
145
  "tsc:build": "pnpm run dump-version && tsc && resolve-tspaths",
142
146
  "test:unit": "jest --testMatch='**/*.test.ts'",
147
+ "check:edge": "pnpm run tsc:build && node scripts/check-edge-entry.mjs",
143
148
  "test:e2e": "jest --config jest.e2e.config.ts --silent --forceExit --runInBand",
144
149
  "test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
145
150
  "generate": "pnpm run '/generate-.*/'",
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+ // Verifies the edge entry point (`@hatchet-dev/typescript-sdk/edge`) imports nothing
4
+ // from Node. Bundles dist/edge/index.js for a workerd-like browser target and fails on
5
+ // any `node:` specifier or Node builtin reached from it, transitively.
6
+ //
7
+ // Run after `pnpm run tsc:build` (the `check:edge` script does both). An alternative
8
+ // entry can be given as the first argument to inspect another module, for example
9
+ // `node scripts/check-edge-entry.mjs dist/index.js` to see what the root reaches.
10
+ import { builtinModules } from 'node:module';
11
+ import { existsSync } from 'node:fs';
12
+ import { resolve, dirname } from 'node:path';
13
+ import { fileURLToPath } from 'node:url';
14
+ import { build } from 'esbuild';
15
+
16
+ const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
17
+ const entry = resolve(root, process.argv[2] ?? 'dist/edge/index.js');
18
+
19
+ if (!existsSync(entry)) {
20
+ console.error(`entry not built: ${entry} is missing. Run \`pnpm run tsc:build\` first.`);
21
+ process.exit(1);
22
+ }
23
+
24
+ // Optional peers the declaration classes load lazily (`mcpTool()`); never reached on a
25
+ // serverless code path and not part of the edge contract.
26
+ const lazyOptionalPeers = ['@openai/agents', '@anthropic-ai/claude-agent-sdk', '@modelcontextprotocol/sdk'];
27
+
28
+ const builtins = new Set(builtinModules.flatMap((m) => [m, `node:${m}`]));
29
+ const violations = new Map();
30
+
31
+ const nodeBuiltinDetector = {
32
+ name: 'node-builtin-detector',
33
+ setup(pluginBuild) {
34
+ pluginBuild.onResolve({ filter: /.*/ }, (args) => {
35
+ const isBuiltin = args.path.startsWith('node:') || builtins.has(args.path);
36
+ if (!isBuiltin) return undefined;
37
+ const importer = args.importer ? args.importer.replace(`${root}/`, '') : '<entry>';
38
+ if (!violations.has(args.path)) violations.set(args.path, new Set());
39
+ violations.get(args.path).add(importer);
40
+ // Resolve to an empty stub so the bundle continues and every violation is collected.
41
+ return { path: args.path, namespace: 'node-builtin-stub' };
42
+ });
43
+ pluginBuild.onLoad({ filter: /.*/, namespace: 'node-builtin-stub' }, () => ({
44
+ contents: 'export default {};',
45
+ loader: 'js',
46
+ }));
47
+ },
48
+ };
49
+
50
+ const result = await build({
51
+ entryPoints: [entry],
52
+ bundle: true,
53
+ write: false,
54
+ platform: 'browser',
55
+ conditions: ['workerd', 'worker', 'browser'],
56
+ mainFields: ['browser', 'module', 'main'],
57
+ format: 'esm',
58
+ target: 'es2022',
59
+ logLevel: 'silent',
60
+ metafile: true,
61
+ external: lazyOptionalPeers,
62
+ plugins: [nodeBuiltinDetector],
63
+ });
64
+
65
+ const bundled = Object.keys(result.metafile.inputs);
66
+ const sdkInputs = bundled.filter((f) => f.startsWith('dist/'));
67
+ const packageInputs = [...new Set(bundled.filter((f) => f.includes('node_modules/')).map((f) => {
68
+ const m = f.match(/node_modules\/(?:\.pnpm\/[^/]+\/node_modules\/)?((?:@[^/]+\/)?[^/]+)/);
69
+ return m ? m[1] : f;
70
+ }))].sort();
71
+
72
+ console.log(`edge entry: bundled ${sdkInputs.length} SDK module(s) and ${packageInputs.length} package(s)`);
73
+ if (packageInputs.length) console.log(`packages: ${packageInputs.join(', ')}`);
74
+
75
+ if (violations.size > 0) {
76
+ console.error('\nedge entry reaches Node builtins:');
77
+ for (const [specifier, importers] of [...violations.entries()].sort()) {
78
+ console.error(` ${specifier}`);
79
+ for (const importer of [...importers].sort()) console.error(` from ${importer}`);
80
+ }
81
+ process.exit(1);
82
+ }
83
+
84
+ console.log('edge entry is free of Node builtins');
@@ -13,16 +13,6 @@ export declare function isAbortError(err: unknown): err is Error;
13
13
  * ```
14
14
  */
15
15
  export declare function rethrowIfAborted(err: unknown): void;
16
- /**
17
- * Attach an `abort` listener to a signal, disabling the Node.js
18
- * `MaxListenersExceededWarning` first.
19
- *
20
- * A single durable task can attach many concurrent listeners to the same signal
21
- * (fan-out children, parallel waitFor calls, etc.), easily exceeding the default
22
- * cap of 10. Setting max to 0 (unlimited) is safe here because every listener is
23
- * removed on settlement.
24
- */
25
- export declare function bindAbortSignalHandler(signal: AbortSignal, handler: () => void): void;
26
16
  export type ThrowIfAbortedOpts = {
27
17
  /**
28
18
  * Optional: called before throwing when the signal is aborted.
@@ -4,9 +4,7 @@ exports.AbortError = void 0;
4
4
  exports.createAbortError = createAbortError;
5
5
  exports.isAbortError = isAbortError;
6
6
  exports.rethrowIfAborted = rethrowIfAborted;
7
- exports.bindAbortSignalHandler = bindAbortSignalHandler;
8
7
  exports.throwIfAborted = throwIfAborted;
9
- const events_1 = require("events");
10
8
  class AbortError extends Error {
11
9
  constructor(message = 'Operation aborted') {
12
10
  super(message);
@@ -38,19 +36,6 @@ function rethrowIfAborted(err) {
38
36
  throw err;
39
37
  }
40
38
  }
41
- /**
42
- * Attach an `abort` listener to a signal, disabling the Node.js
43
- * `MaxListenersExceededWarning` first.
44
- *
45
- * A single durable task can attach many concurrent listeners to the same signal
46
- * (fan-out children, parallel waitFor calls, etc.), easily exceeding the default
47
- * cap of 10. Setting max to 0 (unlimited) is safe here because every listener is
48
- * removed on settlement.
49
- */
50
- function bindAbortSignalHandler(signal, handler) {
51
- (0, events_1.setMaxListeners)(0, signal);
52
- signal.addEventListener('abort', handler, { once: true });
53
- }
54
39
  /**
55
40
  * Throws an AbortError if the provided signal is aborted.
56
41
  *
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Attach an `abort` listener to a signal, disabling the Node.js
3
+ * `MaxListenersExceededWarning` first.
4
+ *
5
+ * A single durable task can attach many concurrent listeners to the same signal
6
+ * (fan-out children, parallel waitFor calls, etc.), easily exceeding the default
7
+ * cap of 10. Setting max to 0 (unlimited) is safe here because every listener is
8
+ * removed on settlement.
9
+ *
10
+ * Lives apart from `abort-error.ts` so the abort helpers stay free of Node imports.
11
+ */
12
+ export declare function bindAbortSignalHandler(signal: AbortSignal, handler: () => void): void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindAbortSignalHandler = bindAbortSignalHandler;
4
+ const events_1 = require("events");
5
+ /**
6
+ * Attach an `abort` listener to a signal, disabling the Node.js
7
+ * `MaxListenersExceededWarning` first.
8
+ *
9
+ * A single durable task can attach many concurrent listeners to the same signal
10
+ * (fan-out children, parallel waitFor calls, etc.), easily exceeding the default
11
+ * cap of 10. Setting max to 0 (unlimited) is safe here because every listener is
12
+ * removed on settlement.
13
+ *
14
+ * Lives apart from `abort-error.ts` so the abort helpers stay free of Node imports.
15
+ */
16
+ function bindAbortSignalHandler(signal, handler) {
17
+ (0, events_1.setMaxListeners)(0, signal);
18
+ signal.addEventListener('abort', handler, { once: true });
19
+ }
@@ -1,4 +1,4 @@
1
- import { JsonObject } from '../../v1';
1
+ import { JsonObject } from '../../v1/types';
2
2
  export type LogExtra = JsonObject;
3
3
  export declare abstract class Logger {
4
4
  abstract debug(message: string, extra?: LogExtra): void | Promise<void>;