@hatchet-dev/typescript-sdk 1.21.1 → 1.22.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 (51) hide show
  1. package/clients/hatchet-client/client-config.d.ts +27 -133
  2. package/clients/hatchet-client/client-config.js +24 -24
  3. package/legacy/legacy-client.js +2 -2
  4. package/legacy/step.d.ts +22 -121
  5. package/legacy/step.js +7 -4
  6. package/legacy/workflow.d.ts +46 -420
  7. package/legacy/workflow.js +5 -5
  8. package/package.json +12 -6
  9. package/protoc/dispatcher/dispatcher.d.ts +4 -0
  10. package/protoc/dispatcher/dispatcher.js +41 -1
  11. package/util/config-loader/config-loader.js +2 -2
  12. package/util/uuid.js +2 -2
  13. package/v1/agent/claude.d.ts +17 -0
  14. package/v1/agent/claude.js +83 -0
  15. package/v1/agent/openai.d.ts +4 -0
  16. package/v1/agent/openai.js +83 -0
  17. package/v1/client/client.js +2 -2
  18. package/v1/client/features/crons.d.ts +3 -15
  19. package/v1/client/features/crons.js +8 -8
  20. package/v1/client/features/schedules.d.ts +6 -20
  21. package/v1/client/features/schedules.js +10 -10
  22. package/v1/client/worker/context.d.ts +11 -1
  23. package/v1/client/worker/context.js +14 -0
  24. package/v1/client/worker/worker-internal.js +2 -2
  25. package/v1/declaration.d.ts +18 -1
  26. package/v1/declaration.js +10 -0
  27. package/v1/examples/agent/agent-claude.d.ts +1 -0
  28. package/v1/examples/agent/agent-claude.js +68 -0
  29. package/v1/examples/agent/agent-openai.d.ts +1 -0
  30. package/v1/examples/agent/agent-openai.js +72 -0
  31. package/v1/examples/agent/worker.d.ts +1 -0
  32. package/v1/examples/agent/worker.js +24 -0
  33. package/v1/examples/agent/workflow.d.ts +26 -0
  34. package/v1/examples/agent/workflow.js +48 -0
  35. package/v1/examples/durable/workflow.d.ts +6 -2
  36. package/v1/examples/durable/workflow.js +9 -6
  37. package/v1/examples/durable_eviction/workflow.js +6 -0
  38. package/v1/examples/e2e-worker.js +7 -0
  39. package/v1/examples/simple/run.js +5 -0
  40. package/v1/examples/simple/zod.d.ts +2 -6
  41. package/v1/examples/simple/zod.js +1 -1
  42. package/v1/examples/support_agent/run.d.ts +1 -0
  43. package/v1/examples/support_agent/run.js +42 -0
  44. package/v1/examples/support_agent/workflow.d.ts +43 -0
  45. package/v1/examples/support_agent/workflow.js +140 -0
  46. package/v1/examples/welcome_email/run.d.ts +1 -0
  47. package/v1/examples/welcome_email/run.js +40 -0
  48. package/v1/examples/welcome_email/workflow.d.ts +11 -0
  49. package/v1/examples/welcome_email/workflow.js +52 -0
  50. package/version.d.ts +1 -1
  51. package/version.js +1 -1
@@ -1262,6 +1262,8 @@ function createBaseAssignedAction() {
1262
1262
  workflowId: undefined,
1263
1263
  workflowVersionId: undefined,
1264
1264
  durableTaskInvocationCount: undefined,
1265
+ triggeringEventExternalId: undefined,
1266
+ triggeringEventKey: undefined,
1265
1267
  };
1266
1268
  }
1267
1269
  exports.AssignedAction = {
@@ -1329,6 +1331,12 @@ exports.AssignedAction = {
1329
1331
  if (message.durableTaskInvocationCount !== undefined) {
1330
1332
  writer.uint32(168).int32(message.durableTaskInvocationCount);
1331
1333
  }
1334
+ if (message.triggeringEventExternalId !== undefined) {
1335
+ writer.uint32(178).string(message.triggeringEventExternalId);
1336
+ }
1337
+ if (message.triggeringEventKey !== undefined) {
1338
+ writer.uint32(186).string(message.triggeringEventKey);
1339
+ }
1332
1340
  return writer;
1333
1341
  },
1334
1342
  decode(input, length) {
@@ -1485,6 +1493,20 @@ exports.AssignedAction = {
1485
1493
  message.durableTaskInvocationCount = reader.int32();
1486
1494
  continue;
1487
1495
  }
1496
+ case 22: {
1497
+ if (tag !== 178) {
1498
+ break;
1499
+ }
1500
+ message.triggeringEventExternalId = reader.string();
1501
+ continue;
1502
+ }
1503
+ case 23: {
1504
+ if (tag !== 186) {
1505
+ break;
1506
+ }
1507
+ message.triggeringEventKey = reader.string();
1508
+ continue;
1509
+ }
1488
1510
  }
1489
1511
  if ((tag & 7) === 4 || tag === 0) {
1490
1512
  break;
@@ -1596,6 +1618,16 @@ exports.AssignedAction = {
1596
1618
  : isSet(object.durable_task_invocation_count)
1597
1619
  ? globalThis.Number(object.durable_task_invocation_count)
1598
1620
  : undefined,
1621
+ triggeringEventExternalId: isSet(object.triggeringEventExternalId)
1622
+ ? globalThis.String(object.triggeringEventExternalId)
1623
+ : isSet(object.triggering_event_external_id)
1624
+ ? globalThis.String(object.triggering_event_external_id)
1625
+ : undefined,
1626
+ triggeringEventKey: isSet(object.triggeringEventKey)
1627
+ ? globalThis.String(object.triggeringEventKey)
1628
+ : isSet(object.triggering_event_key)
1629
+ ? globalThis.String(object.triggering_event_key)
1630
+ : undefined,
1599
1631
  };
1600
1632
  },
1601
1633
  toJSON(message) {
@@ -1663,13 +1695,19 @@ exports.AssignedAction = {
1663
1695
  if (message.durableTaskInvocationCount !== undefined) {
1664
1696
  obj.durableTaskInvocationCount = Math.round(message.durableTaskInvocationCount);
1665
1697
  }
1698
+ if (message.triggeringEventExternalId !== undefined) {
1699
+ obj.triggeringEventExternalId = message.triggeringEventExternalId;
1700
+ }
1701
+ if (message.triggeringEventKey !== undefined) {
1702
+ obj.triggeringEventKey = message.triggeringEventKey;
1703
+ }
1666
1704
  return obj;
1667
1705
  },
1668
1706
  create(base) {
1669
1707
  return exports.AssignedAction.fromPartial(base !== null && base !== void 0 ? base : {});
1670
1708
  },
1671
1709
  fromPartial(object) {
1672
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1710
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
1673
1711
  const message = createBaseAssignedAction();
1674
1712
  message.tenantId = (_a = object.tenantId) !== null && _a !== void 0 ? _a : '';
1675
1713
  message.workflowRunId = (_b = object.workflowRunId) !== null && _b !== void 0 ? _b : '';
@@ -1692,6 +1730,8 @@ exports.AssignedAction = {
1692
1730
  message.workflowId = (_u = object.workflowId) !== null && _u !== void 0 ? _u : undefined;
1693
1731
  message.workflowVersionId = (_v = object.workflowVersionId) !== null && _v !== void 0 ? _v : undefined;
1694
1732
  message.durableTaskInvocationCount = (_w = object.durableTaskInvocationCount) !== null && _w !== void 0 ? _w : undefined;
1733
+ message.triggeringEventExternalId = (_x = object.triggeringEventExternalId) !== null && _x !== void 0 ? _x : undefined;
1734
+ message.triggeringEventKey = (_y = object.triggeringEventKey) !== null && _y !== void 0 ? _y : undefined;
1695
1735
  return message;
1696
1736
  },
1697
1737
  };
@@ -37,7 +37,7 @@ exports.ConfigLoader = void 0;
37
37
  const yaml_1 = require("yaml");
38
38
  const fs_1 = require("fs");
39
39
  const p = __importStar(require("path"));
40
- const zod_1 = require("zod");
40
+ const v4_1 = require("zod/v4");
41
41
  const hatchet_client_1 = require("../../clients/hatchet-client");
42
42
  const nice_grpc_1 = require("nice-grpc");
43
43
  const token_1 = require("./token");
@@ -136,7 +136,7 @@ class ConfigLoader {
136
136
  if (!path) {
137
137
  return undefined;
138
138
  }
139
- if (e instanceof zod_1.z.ZodError) {
139
+ if (e instanceof v4_1.z.ZodError) {
140
140
  throw new Error(`Invalid yaml config: ${e.message}`, { cause: e });
141
141
  }
142
142
  throw e;
package/util/uuid.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isValidUUID = isValidUUID;
4
- const zod_1 = require("zod");
4
+ const v4_1 = require("zod/v4");
5
5
  function isValidUUID(uuid) {
6
- return zod_1.z.string().uuid().safeParse(uuid).success;
6
+ return v4_1.z.uuid().safeParse(uuid).success;
7
7
  }
@@ -0,0 +1,17 @@
1
+ import { BaseWorkflowDeclaration, InputType, OutputType } from './..';
2
+ import type { SdkMcpToolDefinition } from '@anthropic-ai/claude-agent-sdk';
3
+ import type { CallToolResult, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
4
+ export type ClaudeToolFuncT = <I extends InputType, O extends OutputType>(runnable: BaseWorkflowDeclaration<I, O>, annotations?: ToolAnnotations) => SdkMcpToolDefinition;
5
+ export declare const ClaudeToolFunc: <I extends InputType, O extends OutputType>(runnable: BaseWorkflowDeclaration<I, O>, annotations?: ToolAnnotations) => {
6
+ annotations: {
7
+ title?: string | undefined;
8
+ readOnlyHint?: boolean | undefined;
9
+ destructiveHint?: boolean | undefined;
10
+ idempotentHint?: boolean | undefined;
11
+ openWorldHint?: boolean | undefined;
12
+ } | undefined;
13
+ description: string;
14
+ handler: (args: any, _: unknown) => Promise<CallToolResult>;
15
+ name: string;
16
+ inputSchema: any;
17
+ };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.ClaudeToolFunc = void 0;
46
+ const z = __importStar(require("zod/v4"));
47
+ const ClaudeToolFunc = (runnable, annotations) => {
48
+ const hasZodV4 = '_zod' in z.string();
49
+ let hasClaudeAgentSdk = true;
50
+ try {
51
+ require.resolve('@anthropic-ai/claude-agent-sdk');
52
+ }
53
+ catch (_a) {
54
+ hasClaudeAgentSdk = false;
55
+ }
56
+ if (!hasZodV4 || !hasClaudeAgentSdk) {
57
+ throw new Error("To use Hatchet's Claude agent SDK integration, you must install Zod v4 and @anthropic-ai/claude-agent-sdk: npm install zod@^4.0.0 @anthropic-ai/claude-agent-sdk @modelcontextprotocol/sdk");
58
+ }
59
+ if (!runnable.definition.inputValidator) {
60
+ throw new Error('inputValidator must be defined');
61
+ }
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ const inputValidatorV4 = runnable.definition.inputValidator;
64
+ const { description } = runnable.definition;
65
+ if (description === undefined) {
66
+ throw new Error('Runnable description must be defined');
67
+ }
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ const handler = (args, _) => __awaiter(void 0, void 0, void 0, function* () {
70
+ const result = yield runnable.run(args);
71
+ return {
72
+ content: [{ type: 'text', text: JSON.stringify(result) }],
73
+ };
74
+ });
75
+ return {
76
+ annotations: annotations,
77
+ description: description,
78
+ handler: handler,
79
+ name: runnable.name,
80
+ inputSchema: inputValidatorV4.shape,
81
+ };
82
+ };
83
+ exports.ClaudeToolFunc = ClaudeToolFunc;
@@ -0,0 +1,4 @@
1
+ import { BaseWorkflowDeclaration, InputType, OutputType } from './..';
2
+ import type { FunctionTool } from '@openai/agents';
3
+ export type OpenAIToolFuncT = <I extends InputType, O extends OutputType>(runnable: BaseWorkflowDeclaration<I, O>) => FunctionTool;
4
+ export declare const OpenAIToolFunc: <I extends InputType, O extends OutputType>(runnable: BaseWorkflowDeclaration<I, O>) => any;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.OpenAIToolFunc = void 0;
46
+ const z = __importStar(require("zod/v4"));
47
+ const OpenAIToolFunc = (runnable) => {
48
+ // Check both requirements before loading @openai/agents — it crashes at load time with Zod v3.
49
+ // z is imported from 'zod', so '_zod' in z.string() reflects the user's actual installed version.
50
+ const hasZodV4 = '_zod' in z.string();
51
+ let hasOpenAIAgents = true;
52
+ try {
53
+ require.resolve('@openai/agents');
54
+ }
55
+ catch (_a) {
56
+ hasOpenAIAgents = false;
57
+ }
58
+ if (!hasZodV4 || !hasOpenAIAgents) {
59
+ throw new Error("To use Hatchet's OpenAI agent SDK integration, you must install Zod v4 and @openai/agents: npm install zod@^4.0.0 @openai/agents");
60
+ }
61
+ if (!runnable.definition.inputValidator) {
62
+ throw new Error('inputValidator must be defined');
63
+ }
64
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
65
+ const { tool } = require('@openai/agents');
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ const inputValidatorV4 = runnable.definition.inputValidator;
68
+ const { description } = runnable.definition;
69
+ if (description === undefined) {
70
+ throw new Error('Runnable description must be defined');
71
+ }
72
+ return tool({
73
+ name: runnable.name,
74
+ description: description,
75
+ parameters: z.toJSONSchema(inputValidatorV4),
76
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
+ execute: (input) => __awaiter(void 0, void 0, void 0, function* () {
78
+ const result = yield runnable.run(input);
79
+ return JSON.stringify(result);
80
+ }),
81
+ });
82
+ };
83
+ exports.OpenAIToolFunc = OpenAIToolFunc;
@@ -23,7 +23,7 @@ const hatchet_client_1 = require("../../clients/hatchet-client");
23
23
  const rest_1 = __importDefault(require("../../clients/rest"));
24
24
  const config_loader_1 = require("../../util/config-loader");
25
25
  const hatchet_logger_1 = require("../../clients/hatchet-client/hatchet-logger");
26
- const zod_1 = require("zod");
26
+ const v4_1 = require("zod/v4");
27
27
  const event_client_1 = require("../../clients/event/event-client");
28
28
  const dispatcher_client_1 = require("../../clients/dispatcher/dispatcher-client");
29
29
  const child_listener_client_1 = require("../../clients/listeners/run-listener/child-listener-client");
@@ -89,7 +89,7 @@ class HatchetClient {
89
89
  this._axiosConfig = axiosConfig;
90
90
  }
91
91
  catch (e) {
92
- if (e instanceof zod_1.z.ZodError) {
92
+ if (e instanceof v4_1.z.ZodError) {
93
93
  throw new Error(`Invalid client config: ${e.message}`, { cause: e });
94
94
  }
95
95
  throw e;
@@ -1,5 +1,5 @@
1
1
  import { CronWorkflows, CronWorkflowsList } from '../../../clients/rest/generated/data-contracts';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v4';
3
3
  import { BaseWorkflowDeclaration } from '../..';
4
4
  import type { LegacyWorkflow } from '../../../legacy/legacy-transformer';
5
5
  import { HatchetClient } from '../client';
@@ -11,22 +11,10 @@ import { WorkflowsClient } from './workflows';
11
11
  export declare const CreateCronTriggerSchema: z.ZodObject<{
12
12
  name: z.ZodString;
13
13
  expression: z.ZodString;
14
- input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
14
+ input: z.ZodOptional<z.ZodRecord<z.ZodAny, z.ZodAny>>;
15
15
  additionalMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
16
16
  priority: z.ZodOptional<z.ZodNumber>;
17
- }, "strip", z.ZodTypeAny, {
18
- name: string;
19
- expression: string;
20
- additionalMetadata?: Record<string, string> | undefined;
21
- priority?: number | undefined;
22
- input?: Record<string, any> | undefined;
23
- }, {
24
- name: string;
25
- expression: string;
26
- additionalMetadata?: Record<string, string> | undefined;
27
- priority?: number | undefined;
28
- input?: Record<string, any> | undefined;
29
- }>;
17
+ }, z.core.$strip>;
30
18
  /**
31
19
  * Type representing the input for creating a Cron.
32
20
  * @internal
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.CronClient = exports.CreateCronTriggerSchema = void 0;
24
- const zod_1 = require("zod");
24
+ const v4_1 = require("zod/v4");
25
25
  const axios_1 = require("axios");
26
26
  const uuid_1 = require("../../../util/uuid");
27
27
  const apply_namespace_1 = require("../../../util/apply-namespace");
@@ -30,12 +30,12 @@ const workflows_1 = require("./workflows");
30
30
  * Schema for creating a Cron Trigger.
31
31
  * @internal
32
32
  */
33
- exports.CreateCronTriggerSchema = zod_1.z.object({
34
- name: zod_1.z.string(),
35
- expression: zod_1.z.string(),
36
- input: zod_1.z.record(zod_1.z.any()).optional(),
37
- additionalMetadata: zod_1.z.record(zod_1.z.string()).optional(),
38
- priority: zod_1.z.number().optional(),
33
+ exports.CreateCronTriggerSchema = v4_1.z.object({
34
+ name: v4_1.z.string(),
35
+ expression: v4_1.z.string(),
36
+ input: v4_1.z.record(v4_1.z.any(), v4_1.z.any()).optional(),
37
+ additionalMetadata: v4_1.z.record(v4_1.z.string(), v4_1.z.string()).optional(),
38
+ priority: v4_1.z.number().optional(),
39
39
  });
40
40
  /**
41
41
  * The cron client is a client for managing cron workflows within Hatchet.
@@ -83,7 +83,7 @@ class CronClient {
83
83
  return response.data;
84
84
  }
85
85
  catch (err) {
86
- if (err instanceof zod_1.z.ZodError) {
86
+ if (err instanceof v4_1.z.ZodError) {
87
87
  throw new Error(`Invalid cron input: ${err.message}`, { cause: err });
88
88
  }
89
89
  if (err instanceof axios_1.AxiosError) {
@@ -1,5 +1,5 @@
1
1
  import { ScheduledWorkflows, ScheduledWorkflowsBulkDeleteFilter, ScheduledWorkflowsBulkDeleteResponse, ScheduledWorkflowsBulkUpdateResponse, ScheduledWorkflowsList } from '../../../clients/rest/generated/data-contracts';
2
- import { z } from 'zod';
2
+ import { z } from 'zod/v4';
3
3
  import { Workflow } from '../../../workflow';
4
4
  import { BaseWorkflowDeclaration, WorkflowDefinition } from '../..';
5
5
  import { HatchetClient } from '../client';
@@ -9,21 +9,11 @@ import { WorkflowsClient } from './workflows';
9
9
  * @internal
10
10
  */
11
11
  export declare const CreateScheduledRunTriggerSchema: z.ZodObject<{
12
- triggerAt: z.ZodDate;
13
- input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
12
+ triggerAt: z.ZodCoercedDate<unknown>;
13
+ input: z.ZodOptional<z.ZodRecord<z.ZodAny, z.ZodAny>>;
14
14
  additionalMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
15
15
  priority: z.ZodOptional<z.ZodNumber>;
16
- }, "strip", z.ZodTypeAny, {
17
- triggerAt: Date;
18
- additionalMetadata?: Record<string, string> | undefined;
19
- priority?: number | undefined;
20
- input?: Record<string, any> | undefined;
21
- }, {
22
- triggerAt: Date;
23
- additionalMetadata?: Record<string, string> | undefined;
24
- priority?: number | undefined;
25
- input?: Record<string, any> | undefined;
26
- }>;
16
+ }, z.core.$strip>;
27
17
  /**
28
18
  * Type representing the input for creating a Cron.
29
19
  * @internal
@@ -34,12 +24,8 @@ export type CreateScheduledRunInput = z.infer<typeof CreateScheduledRunTriggerSc
34
24
  * @internal
35
25
  */
36
26
  export declare const UpdateScheduledRunTriggerSchema: z.ZodObject<{
37
- triggerAt: z.ZodDate;
38
- }, "strip", z.ZodTypeAny, {
39
- triggerAt: Date;
40
- }, {
41
- triggerAt: Date;
42
- }>;
27
+ triggerAt: z.ZodCoercedDate<unknown>;
28
+ }, z.core.$strip>;
43
29
  export type UpdateScheduledRunInput = z.infer<typeof UpdateScheduledRunTriggerSchema>;
44
30
  /**
45
31
  * The scheduled client is a client for managing scheduled workflows within Hatchet
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.ScheduleClient = exports.UpdateScheduledRunTriggerSchema = exports.CreateScheduledRunTriggerSchema = void 0;
24
- const zod_1 = require("zod");
24
+ const v4_1 = require("zod/v4");
25
25
  const axios_1 = require("axios");
26
26
  const uuid_1 = require("../../../util/uuid");
27
27
  const apply_namespace_1 = require("../../../util/apply-namespace");
@@ -30,18 +30,18 @@ const workflows_1 = require("./workflows");
30
30
  * Schema for creating a Scheduled Run Trigger.
31
31
  * @internal
32
32
  */
33
- exports.CreateScheduledRunTriggerSchema = zod_1.z.object({
34
- triggerAt: zod_1.z.coerce.date(),
35
- input: zod_1.z.record(zod_1.z.any()).optional(),
36
- additionalMetadata: zod_1.z.record(zod_1.z.string()).optional(),
37
- priority: zod_1.z.number().optional(),
33
+ exports.CreateScheduledRunTriggerSchema = v4_1.z.object({
34
+ triggerAt: v4_1.z.coerce.date(),
35
+ input: v4_1.z.record(v4_1.z.any(), v4_1.z.any()).optional(),
36
+ additionalMetadata: v4_1.z.record(v4_1.z.string(), v4_1.z.string()).optional(),
37
+ priority: v4_1.z.number().optional(),
38
38
  });
39
39
  /**
40
40
  * Schema for updating (rescheduling) a Scheduled Run Trigger.
41
41
  * @internal
42
42
  */
43
- exports.UpdateScheduledRunTriggerSchema = zod_1.z.object({
44
- triggerAt: zod_1.z.coerce.date(),
43
+ exports.UpdateScheduledRunTriggerSchema = v4_1.z.object({
44
+ triggerAt: v4_1.z.coerce.date(),
45
45
  });
46
46
  /**
47
47
  * The scheduled client is a client for managing scheduled workflows within Hatchet
@@ -91,7 +91,7 @@ class ScheduleClient {
91
91
  return response.data;
92
92
  }
93
93
  catch (err) {
94
- if (err instanceof zod_1.z.ZodError) {
94
+ if (err instanceof v4_1.z.ZodError) {
95
95
  throw new Error(`Invalid cron input: ${err.message}`, { cause: err });
96
96
  }
97
97
  if (err instanceof axios_1.AxiosError) {
@@ -119,7 +119,7 @@ class ScheduleClient {
119
119
  return response.data;
120
120
  }
121
121
  catch (err) {
122
- if (err instanceof zod_1.z.ZodError) {
122
+ if (err instanceof v4_1.z.ZodError) {
123
123
  throw new Error(`Invalid update input: ${err.message}`, { cause: err });
124
124
  }
125
125
  if (err instanceof axios_1.AxiosError) {
@@ -18,7 +18,7 @@ import { HatchetClient } from '../..';
18
18
  import { WorkerLabels } from '../../../clients/dispatcher/dispatcher-client';
19
19
  import { NextStep } from '../../../legacy/step';
20
20
  import { DurableListenerClient } from '../../../clients/listeners/durable-listener/durable-listener-client';
21
- import { z } from 'zod';
21
+ import { z } from 'zod/v4';
22
22
  import { InternalWorker } from './worker-internal';
23
23
  import { Duration } from '../duration';
24
24
  import { DurableEvictionManager } from './eviction/eviction-manager';
@@ -306,6 +306,16 @@ export declare class Context<T, K = {}> {
306
306
  */
307
307
  parentWorkflowRunId(): string | undefined;
308
308
  priority(): Priority | undefined;
309
+ /**
310
+ * Gets the external ID of the event that triggered this workflow run, if any.
311
+ * @returns The triggering event external ID, or undefined if the workflow was not triggered by an event.
312
+ */
313
+ triggeringEventId(): string | undefined;
314
+ /**
315
+ * Gets the key of the event that triggered this workflow run, if any.
316
+ * @returns The triggering event key, or undefined if the workflow was not triggered by an event.
317
+ */
318
+ triggeringEventKey(): string | undefined;
309
319
  /**
310
320
  * Get the output of a task.
311
321
  * @param task - The name of the task to get the output for.
@@ -506,6 +506,20 @@ class Context {
506
506
  return undefined;
507
507
  }
508
508
  }
509
+ /**
510
+ * Gets the external ID of the event that triggered this workflow run, if any.
511
+ * @returns The triggering event external ID, or undefined if the workflow was not triggered by an event.
512
+ */
513
+ triggeringEventId() {
514
+ return this.action.triggeringEventExternalId;
515
+ }
516
+ /**
517
+ * Gets the key of the event that triggered this workflow run, if any.
518
+ * @returns The triggering event key, or undefined if the workflow was not triggered by an event.
519
+ */
520
+ triggeringEventKey() {
521
+ return this.action.triggeringEventKey;
522
+ }
509
523
  // FIXME: drop these at some point soon
510
524
  /**
511
525
  * Get the output of a task.
@@ -64,7 +64,7 @@ const workflows_1 = require("../../../protoc/workflows");
64
64
  const logger_1 = require("../../../util/logger");
65
65
  const task_1 = require("../../task");
66
66
  const transformer_1 = require("../../conditions/transformer");
67
- const zod_to_json_schema_1 = require("zod-to-json-schema");
67
+ const z = __importStar(require("zod/v4"));
68
68
  const apply_namespace_1 = require("../../../util/apply-namespace");
69
69
  const sleep_1 = __importDefault(require("../../../util/sleep"));
70
70
  const abort_error_1 = require("../../../util/abort-error");
@@ -263,7 +263,7 @@ class InternalWorker {
263
263
  // Convert Zod schema to JSON Schema if provided
264
264
  let inputJsonSchema;
265
265
  if (workflow.inputValidator) {
266
- const jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(workflow.inputValidator);
266
+ const jsonSchema = z.toJSONSchema(workflow.inputValidator);
267
267
  inputJsonSchema = new TextEncoder().encode(JSON.stringify(jsonSchema));
268
268
  }
269
269
  const durableTaskSet = new Set(workflow._durableTasks);
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import WorkflowRunRef from '../util/workflow-run-ref';
9
9
  import { CronWorkflows, ScheduledWorkflows, V1CreateFilterRequest } from '../clients/rest/generated/data-contracts';
10
- import { z } from 'zod';
10
+ import * as z from 'zod/v4';
11
11
  import { IHatchetClient } from './client/client.interface';
12
12
  import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn, WorkerLabelComparator } from './task';
13
13
  import { Duration } from './client/duration';
@@ -15,11 +15,20 @@ import { MetricsClient } from './client/features/metrics';
15
15
  import { InputType, OutputType, UnknownInputType, JsonObject, Resolved } from './types';
16
16
  import { Context, DurableContext } from './client/worker/context';
17
17
  import { EvictionPolicy } from './client/worker/eviction/eviction-policy';
18
+ import type { FunctionTool } from '@openai/agents';
19
+ import type { SdkMcpToolDefinition } from '@anthropic-ai/claude-agent-sdk';
20
+ import type { OpenAIToolFuncT } from './agent/openai';
21
+ import type { ClaudeToolFuncT } from './agent/claude';
18
22
  export declare enum Priority {
19
23
  LOW = 1,
20
24
  MEDIUM = 2,
21
25
  HIGH = 3
22
26
  }
27
+ type AgentSdkFuncMap = {
28
+ claude: ClaudeToolFuncT;
29
+ openai: OpenAIToolFuncT;
30
+ };
31
+ type Tail<T extends any[]> = T extends [any, ...infer R] ? R : never;
23
32
  /**
24
33
  * Additional metadata that can be attached to a workflow run.
25
34
  */
@@ -358,6 +367,14 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
358
367
  * @returns The name of the workflow.
359
368
  */
360
369
  get name(): string;
370
+ /**
371
+ * Create an MCP tool from a workflow. Supports both Claude and OpenAI agent sdks.
372
+ * @param sdk The agent SDK the tool will be used with.
373
+ * @param args Optional arguments passed to create the MCP tool object.
374
+ * @returns The MCP tool object.
375
+ **/
376
+ mcpTool(sdk: 'claude', ...args: Tail<Parameters<AgentSdkFuncMap['claude']>>): SdkMcpToolDefinition;
377
+ mcpTool(sdk: 'openai', ...args: Tail<Parameters<AgentSdkFuncMap['openai']>>): FunctionTool;
361
378
  }
362
379
  /**
363
380
  * A Hatchet workflow, which lets you define tasks and perform actions on the workflow.
package/v1/declaration.js CHANGED
@@ -409,6 +409,16 @@ class BaseWorkflowDeclaration {
409
409
  get name() {
410
410
  return this.definition.name;
411
411
  }
412
+ mcpTool(sdk, ...args) {
413
+ if (sdk === 'openai') {
414
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
415
+ const { OpenAIToolFunc } = require('./agent/openai');
416
+ return OpenAIToolFunc(this, ...args);
417
+ }
418
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
419
+ const { ClaudeToolFunc } = require('./agent/claude');
420
+ return ClaudeToolFunc(this, ...args);
421
+ }
412
422
  }
413
423
  exports.BaseWorkflowDeclaration = BaseWorkflowDeclaration;
414
424
  /**
@@ -0,0 +1 @@
1
+ export {};