@hatchet-dev/typescript-sdk 1.21.2 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clients/hatchet-client/client-config.d.ts +27 -133
- package/clients/hatchet-client/client-config.js +24 -24
- package/legacy/legacy-client.js +2 -2
- package/legacy/step.d.ts +22 -121
- package/legacy/step.js +7 -4
- package/legacy/workflow.d.ts +46 -420
- package/legacy/workflow.js +5 -5
- package/package.json +46 -7
- package/util/config-loader/config-loader.js +2 -2
- package/util/uuid.js +2 -2
- package/v1/agent/claude.d.ts +17 -0
- package/v1/agent/claude.js +83 -0
- package/v1/agent/openai.d.ts +4 -0
- package/v1/agent/openai.js +83 -0
- package/v1/client/client.js +2 -2
- package/v1/client/features/crons.d.ts +3 -15
- package/v1/client/features/crons.js +8 -8
- package/v1/client/features/schedules.d.ts +6 -20
- package/v1/client/features/schedules.js +10 -10
- package/v1/client/worker/context.d.ts +1 -1
- package/v1/client/worker/worker-internal.js +2 -2
- package/v1/declaration.d.ts +18 -1
- package/v1/declaration.js +10 -0
- package/v1/examples/agent/agent-claude.d.ts +1 -0
- package/v1/examples/agent/agent-claude.js +68 -0
- package/v1/examples/agent/agent-openai.d.ts +1 -0
- package/v1/examples/agent/agent-openai.js +72 -0
- package/v1/examples/agent/worker.d.ts +1 -0
- package/v1/examples/agent/worker.js +24 -0
- package/v1/examples/agent/workflow.d.ts +26 -0
- package/v1/examples/agent/workflow.js +48 -0
- package/v1/examples/durable/workflow.d.ts +6 -2
- package/v1/examples/durable/workflow.js +9 -6
- package/v1/examples/durable_eviction/workflow.js +6 -0
- package/v1/examples/e2e-worker.js +7 -0
- package/v1/examples/simple/run.js +5 -0
- package/v1/examples/simple/zod.d.ts +2 -6
- package/v1/examples/simple/zod.js +1 -1
- package/v1/examples/support_agent/run.d.ts +1 -0
- package/v1/examples/support_agent/run.js +42 -0
- package/v1/examples/support_agent/workflow.d.ts +43 -0
- package/v1/examples/support_agent/workflow.js +140 -0
- package/v1/examples/welcome_email/run.d.ts +1 -0
- package/v1/examples/welcome_email/run.js +40 -0
- package/v1/examples/welcome_email/workflow.d.ts +11 -0
- package/v1/examples/welcome_email/workflow.js +52 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -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;
|
package/v1/client/client.js
CHANGED
|
@@ -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
|
|
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
|
|
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.
|
|
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
|
-
},
|
|
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
|
|
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 =
|
|
34
|
-
name:
|
|
35
|
-
expression:
|
|
36
|
-
input:
|
|
37
|
-
additionalMetadata:
|
|
38
|
-
priority:
|
|
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
|
|
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.
|
|
13
|
-
input: z.ZodOptional<z.ZodRecord<z.
|
|
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
|
-
},
|
|
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.
|
|
38
|
-
},
|
|
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
|
|
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 =
|
|
34
|
-
triggerAt:
|
|
35
|
-
input:
|
|
36
|
-
additionalMetadata:
|
|
37
|
-
priority:
|
|
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 =
|
|
44
|
-
triggerAt:
|
|
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
|
|
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
|
|
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';
|
|
@@ -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
|
|
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 =
|
|
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);
|
package/v1/declaration.d.ts
CHANGED
|
@@ -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
|
|
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 {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
// eslint-disable-next-line
|
|
20
|
+
const workflow_1 = require("./workflow");
|
|
21
|
+
const claude_agent_sdk_1 = require("@anthropic-ai/claude-agent-sdk");
|
|
22
|
+
const claude_agent_sdk_2 = require("@anthropic-ai/claude-agent-sdk");
|
|
23
|
+
function main() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
// Generate a tool from a standalone task
|
|
26
|
+
// const temperatureTool = getTemperature.mcpTool('claude');
|
|
27
|
+
var _a, e_1, _b, _c;
|
|
28
|
+
// Or from a workflow
|
|
29
|
+
const temperatureTool = workflow_1.getTemperatureWorkflow.mcpTool('claude');
|
|
30
|
+
// Wrap the tool in an in-process MCP server
|
|
31
|
+
const weatherServer = (0, claude_agent_sdk_2.createSdkMcpServer)({
|
|
32
|
+
name: 'weather',
|
|
33
|
+
version: '1.0.0',
|
|
34
|
+
tools: [temperatureTool],
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
for (var _d = true, _e = __asyncValues((0, claude_agent_sdk_1.query)({
|
|
38
|
+
prompt: "What's the temperature in San Francisco?",
|
|
39
|
+
options: {
|
|
40
|
+
mcpServers: { weather: weatherServer },
|
|
41
|
+
allowedTools: [`mcp__${weatherServer.name}__${temperatureTool.name}`],
|
|
42
|
+
},
|
|
43
|
+
})), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
44
|
+
_c = _f.value;
|
|
45
|
+
_d = false;
|
|
46
|
+
const message = _c;
|
|
47
|
+
// "result" is the final message after all tool calls complete
|
|
48
|
+
if (message.type === 'result' && message.subtype === 'success') {
|
|
49
|
+
console.log(message.result);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
54
|
+
finally {
|
|
55
|
+
try {
|
|
56
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
57
|
+
}
|
|
58
|
+
finally { if (e_1) throw e_1.error; }
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (require.main === module) {
|
|
63
|
+
main()
|
|
64
|
+
.catch(console.error)
|
|
65
|
+
.finally(() => {
|
|
66
|
+
process.exit(0);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
// eslint-disable-next-line
|
|
46
|
+
const workflow_1 = require("./workflow");
|
|
47
|
+
function main() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
// Generate a tool from a standalone task
|
|
50
|
+
// const temperatureTool = getTemperature.mcpTool('openai');
|
|
51
|
+
// Or from a workflow.
|
|
52
|
+
// mcpTool validates Zod v4 is installed before loading @openai/agents, so call it first
|
|
53
|
+
// to get a clear error message if the wrong Zod version is present.
|
|
54
|
+
const temperatureTool = workflow_1.getTemperatureWorkflow.mcpTool('openai');
|
|
55
|
+
// Dynamic import — @openai/agents crashes at load time with Zod v3, so we delay
|
|
56
|
+
// the import until after mcpTool has already verified Zod v4 is available.
|
|
57
|
+
const { Agent, run } = yield Promise.resolve().then(() => __importStar(require('@openai/agents')));
|
|
58
|
+
const agent = new Agent({
|
|
59
|
+
name: 'Agent',
|
|
60
|
+
tools: [temperatureTool],
|
|
61
|
+
});
|
|
62
|
+
const result = yield run(agent, 'What is the weather in San Francisco?');
|
|
63
|
+
console.log(result.finalOutput);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (require.main === module) {
|
|
67
|
+
main()
|
|
68
|
+
.catch(console.error)
|
|
69
|
+
.finally(() => {
|
|
70
|
+
process.exit(0);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
|
+
const workflow_1 = require("./workflow");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('temperature-worker', {
|
|
17
|
+
workflows: [workflow_1.getTemperature, workflow_1.getTemperatureWorkflow],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|