@hatchet-dev/typescript-sdk 1.22.2 → 1.23.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.
- package/clients/event/event-client.js +3 -3
- package/clients/hatchet-client/client-config.d.ts +5 -1
- package/clients/hatchet-client/client-config.js +12 -0
- package/package.json +15 -5
- package/step.js +2 -3
- package/util/config-loader/config-loader.d.ts +1 -0
- package/util/config-loader/config-loader.js +19 -4
- package/util/grpc-helpers.js +16 -11
- package/util/v0-deprecation-warning.d.ts +44 -0
- package/util/v0-deprecation-warning.js +80 -0
- package/v1/agent/openai.js +4 -3
- package/v1/client/admin.js +2 -2
- package/v1/examples/affinity/affinity-workers.js +2 -2
- package/v1/examples/agent/agent-claude.js +39 -9
- package/v1/examples/agent/agent-openai.js +1 -5
- package/v1/examples/agent/workflow.d.ts +10 -6
- package/v1/examples/agent/workflow.js +33 -11
- package/v1/examples/bulk_operations/workflow.js +3 -3
- package/v1/examples/cancellation/cancellation-workflow.js +3 -3
- package/v1/examples/cancellations/workflow.js +3 -3
- package/v1/examples/conditions/workflow.js +1 -1
- package/v1/examples/dag_match_condition/workflow.js +1 -1
- package/v1/examples/durable/workflow.js +6 -6
- package/v1/examples/durable-event/workflow.js +2 -2
- package/v1/examples/durable-sleep/workflow.js +2 -2
- package/v1/examples/durable_event/workflow.js +3 -3
- package/v1/examples/durable_sleep/workflow.js +2 -2
- package/v1/examples/events/workflow.js +1 -1
- package/v1/examples/middleware/client.js +3 -3
- package/v1/examples/middleware/workflow.js +5 -5
- package/v1/examples/on_event/workflow.js +1 -1
- package/v1/examples/on_failure/workflow.js +2 -2
- package/v1/examples/on_success/workflow.js +1 -1
- package/v1/examples/rate_limit/workflow.js +4 -4
- package/v1/examples/retries/workflow.js +1 -1
- package/v1/examples/webhooks/workflow.js +10 -10
- package/v1/examples/welcome_email/workflow.js +3 -3
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.js +2 -4
|
@@ -70,7 +70,7 @@ class EventClient {
|
|
|
70
70
|
bulkPush(type, inputs, options = {}) {
|
|
71
71
|
const namespacedType = (0, apply_namespace_1.applyNamespace)(type, this.config.namespace);
|
|
72
72
|
const events = inputs.map((input) => {
|
|
73
|
-
var _a, _b;
|
|
73
|
+
var _a, _b, _c, _d;
|
|
74
74
|
const baseMeta = (_b = (_a = input.additionalMetadata) !== null && _a !== void 0 ? _a : options.additionalMetadata) !== null && _b !== void 0 ? _b : {};
|
|
75
75
|
const enhanced = injectSourceInfo(baseMeta);
|
|
76
76
|
return {
|
|
@@ -78,8 +78,8 @@ class EventClient {
|
|
|
78
78
|
payload: JSON.stringify(input.payload),
|
|
79
79
|
eventTimestamp: new Date(),
|
|
80
80
|
additionalMetadata: Object.keys(enhanced).length > 0 ? JSON.stringify(enhanced) : undefined,
|
|
81
|
-
priority: input.priority,
|
|
82
|
-
scope: input.scope,
|
|
81
|
+
priority: (_c = input.priority) !== null && _c !== void 0 ? _c : options.priority,
|
|
82
|
+
scope: (_d = input.scope) !== null && _d !== void 0 ? _d : options.scope,
|
|
83
83
|
};
|
|
84
84
|
});
|
|
85
85
|
const req = {
|
|
@@ -56,6 +56,8 @@ export declare const ClientConfigSchema: z.ZodObject<{
|
|
|
56
56
|
}, z.core.$strip>>;
|
|
57
57
|
cancellation_grace_period: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
58
58
|
cancellation_warning_threshold: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
59
|
+
grpc_max_recv_message_length: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
60
|
+
grpc_max_send_message_length: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
59
61
|
}, z.core.$strip>;
|
|
60
62
|
export type LogConstructor = (context: string, logLevel?: LogLevel) => Logger;
|
|
61
63
|
/**
|
|
@@ -98,9 +100,11 @@ export type InferMiddlewareAfter<M> = M extends {
|
|
|
98
100
|
after: infer P;
|
|
99
101
|
} ? P extends (...args: any[]) => any ? NonVoidReturn<P> : P extends readonly any[] ? MergeReturns<P> : {} : {};
|
|
100
102
|
type ClientConfigInferred = z.infer<typeof ClientConfigSchema>;
|
|
101
|
-
export type ClientConfig = Omit<ClientConfigInferred, 'cancellation_grace_period' | 'cancellation_warning_threshold'> & {
|
|
103
|
+
export type ClientConfig = Omit<ClientConfigInferred, 'cancellation_grace_period' | 'cancellation_warning_threshold' | 'grpc_max_recv_message_length' | 'grpc_max_send_message_length'> & {
|
|
102
104
|
cancellation_grace_period?: number;
|
|
103
105
|
cancellation_warning_threshold?: number;
|
|
106
|
+
grpc_max_recv_message_length?: number;
|
|
107
|
+
grpc_max_send_message_length?: number;
|
|
104
108
|
} & {
|
|
105
109
|
credentials?: ChannelCredentials;
|
|
106
110
|
} & {
|
|
@@ -45,4 +45,16 @@ exports.ClientConfigSchema = v4_1.z.object({
|
|
|
45
45
|
middleware: TaskMiddlewareSchema,
|
|
46
46
|
cancellation_grace_period: DurationMsSchema.optional().default(1000),
|
|
47
47
|
cancellation_warning_threshold: DurationMsSchema.optional().default(300),
|
|
48
|
+
grpc_max_recv_message_length: v4_1.z
|
|
49
|
+
.number()
|
|
50
|
+
.int()
|
|
51
|
+
.positive()
|
|
52
|
+
.optional()
|
|
53
|
+
.default(4 * 1024 * 1024),
|
|
54
|
+
grpc_max_send_message_length: v4_1.z
|
|
55
|
+
.number()
|
|
56
|
+
.int()
|
|
57
|
+
.positive()
|
|
58
|
+
.optional()
|
|
59
|
+
.default(4 * 1024 * 1024),
|
|
48
60
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -40,6 +40,16 @@
|
|
|
40
40
|
"ts-proto": "^2.11.4",
|
|
41
41
|
"tsconfig-paths": "^4.2.0",
|
|
42
42
|
"tsx": "^4.21.0",
|
|
43
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.148",
|
|
44
|
+
"@grpc/grpc-js": "^1.14.3",
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
46
|
+
"@openai/agents": "0.11.4",
|
|
47
|
+
"@opentelemetry/api": "^1.9.0",
|
|
48
|
+
"@opentelemetry/core": "^2.0.0",
|
|
49
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.218.0",
|
|
50
|
+
"@opentelemetry/instrumentation": "^0.218.0",
|
|
51
|
+
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
52
|
+
"prom-client": "^15.1.3",
|
|
43
53
|
"typedoc": "^0.28.17",
|
|
44
54
|
"typedoc-plugin-markdown": "^4.10.0",
|
|
45
55
|
"typedoc-plugin-no-inherit": "^1.6.1",
|
|
@@ -62,14 +72,14 @@
|
|
|
62
72
|
},
|
|
63
73
|
"peerDependencies": {
|
|
64
74
|
"zod": "^3.25.0 || ^4.0.0",
|
|
65
|
-
"@anthropic-ai/claude-agent-sdk": "^0.
|
|
75
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.148",
|
|
66
76
|
"@grpc/grpc-js": "^1.14.3",
|
|
67
77
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
68
|
-
"@openai/agents": "0.
|
|
78
|
+
"@openai/agents": "0.11.4",
|
|
69
79
|
"@opentelemetry/api": "^1.9.0",
|
|
70
80
|
"@opentelemetry/core": "^2.0.0",
|
|
71
|
-
"@opentelemetry/exporter-trace-otlp-grpc": "^0.
|
|
72
|
-
"@opentelemetry/instrumentation": "^0.
|
|
81
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.218.0",
|
|
82
|
+
"@opentelemetry/instrumentation": "^0.218.0",
|
|
73
83
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
74
84
|
"prom-client": "^15.1.3"
|
|
75
85
|
},
|
package/step.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const v0_deprecation_warning_1 = require("./util/v0-deprecation-warning");
|
|
17
18
|
__exportStar(require("./legacy/step"), exports);
|
|
18
|
-
|
|
19
|
-
console.warn('\x1b[32mPlease migrate to v1 SDK instead: https://docs.hatchet.run/home/v1-sdk-improvements\x1b[0m');
|
|
20
|
-
console.warn('--------------------------------');
|
|
19
|
+
(0, v0_deprecation_warning_1.emitV0RemovedWarning)('step');
|
|
@@ -5,6 +5,7 @@ interface LoadClientConfigOptions {
|
|
|
5
5
|
}
|
|
6
6
|
export declare class ConfigLoader {
|
|
7
7
|
static loadClientConfig(override?: Partial<ClientConfig>, config?: LoadClientConfigOptions): Partial<ClientConfig>;
|
|
8
|
+
private static parseIntEnv;
|
|
8
9
|
private static parseJsonArray;
|
|
9
10
|
static get default_yaml_config_path(): string;
|
|
10
11
|
static createCredentials(config: ClientConfig['tls_config']): ChannelCredentials;
|
|
@@ -44,7 +44,7 @@ const token_1 = require("./token");
|
|
|
44
44
|
const DEFAULT_CONFIG_FILE = '.hatchet.yaml';
|
|
45
45
|
class ConfigLoader {
|
|
46
46
|
static loadClientConfig(override, config) {
|
|
47
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
|
|
47
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
|
|
48
48
|
const yaml = this.loadYamlConfig(config === null || config === void 0 ? void 0 : config.path);
|
|
49
49
|
const tlsConfig = (_a = override === null || override === void 0 ? void 0 : override.tls_config) !== null && _a !== void 0 ? _a : {
|
|
50
50
|
tls_strategy: (_d = (_c = (_b = yaml === null || yaml === void 0 ? void 0 : yaml.tls_config) === null || _b === void 0 ? void 0 : _b.tls_strategy) !== null && _c !== void 0 ? _c : this.env('HATCHET_CLIENT_TLS_STRATEGY')) !== null && _d !== void 0 ? _d : 'tls',
|
|
@@ -74,7 +74,7 @@ class ConfigLoader {
|
|
|
74
74
|
apiUrl =
|
|
75
75
|
(_x = (_w = (_v = override === null || override === void 0 ? void 0 : override.api_url) !== null && _v !== void 0 ? _v : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _w !== void 0 ? _w : this.env('HATCHET_CLIENT_API_URL')) !== null && _x !== void 0 ? _x : addresses.serverUrl;
|
|
76
76
|
}
|
|
77
|
-
catch (
|
|
77
|
+
catch (_19) {
|
|
78
78
|
grpcBroadcastAddress =
|
|
79
79
|
(_z = (_y = override === null || override === void 0 ? void 0 : override.host_port) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_HOST_PORT');
|
|
80
80
|
apiUrl = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.api_url) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_API_URL');
|
|
@@ -87,18 +87,33 @@ class ConfigLoader {
|
|
|
87
87
|
excludedAttributes: this.parseJsonArray(this.env('HATCHET_CLIENT_OPENTELEMETRY_EXCLUDED_ATTRIBUTES') || '[]'),
|
|
88
88
|
includeTaskNameInSpanName: this.env('HATCHET_CLIENT_OPENTELEMETRY_INCLUDE_TASK_NAME_IN_SPAN_NAME') === 'true',
|
|
89
89
|
};
|
|
90
|
+
const grpcMaxRecvMessageLength = (_8 = (_7 = (_6 = override === null || override === void 0 ? void 0 : override.grpc_max_recv_message_length) !== null && _6 !== void 0 ? _6 : yaml === null || yaml === void 0 ? void 0 : yaml.grpc_max_recv_message_length) !== null && _7 !== void 0 ? _7 : this.parseIntEnv('HATCHET_CLIENT_GRPC_MAX_RECV_MESSAGE_LENGTH')) !== null && _8 !== void 0 ? _8 : 4 * 1024 * 1024;
|
|
91
|
+
const grpcMaxSendMessageLength = (_11 = (_10 = (_9 = override === null || override === void 0 ? void 0 : override.grpc_max_send_message_length) !== null && _9 !== void 0 ? _9 : yaml === null || yaml === void 0 ? void 0 : yaml.grpc_max_send_message_length) !== null && _10 !== void 0 ? _10 : this.parseIntEnv('HATCHET_CLIENT_GRPC_MAX_SEND_MESSAGE_LENGTH')) !== null && _11 !== void 0 ? _11 : 4 * 1024 * 1024;
|
|
90
92
|
return {
|
|
91
|
-
token: (
|
|
93
|
+
token: (_13 = (_12 = override === null || override === void 0 ? void 0 : override.token) !== null && _12 !== void 0 ? _12 : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _13 !== void 0 ? _13 : this.env('HATCHET_CLIENT_TOKEN'),
|
|
92
94
|
host_port: grpcBroadcastAddress,
|
|
93
95
|
api_url: apiUrl,
|
|
94
96
|
tls_config: tlsConfig,
|
|
95
97
|
healthcheck: healthCheckConfig,
|
|
96
|
-
log_level: (
|
|
98
|
+
log_level: (_16 = (_15 = (_14 = override === null || override === void 0 ? void 0 : override.log_level) !== null && _14 !== void 0 ? _14 : yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _15 !== void 0 ? _15 : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _16 !== void 0 ? _16 : 'INFO',
|
|
97
99
|
tenant_id: tenantId,
|
|
98
100
|
namespace: namespace ? `${namespace}`.toLowerCase() : '',
|
|
99
101
|
otel: otelConfig,
|
|
102
|
+
grpc_max_recv_message_length: grpcMaxRecvMessageLength,
|
|
103
|
+
grpc_max_send_message_length: grpcMaxSendMessageLength,
|
|
104
|
+
cancellation_grace_period: (_17 = override === null || override === void 0 ? void 0 : override.cancellation_grace_period) !== null && _17 !== void 0 ? _17 : yaml === null || yaml === void 0 ? void 0 : yaml.cancellation_grace_period,
|
|
105
|
+
cancellation_warning_threshold: (_18 = override === null || override === void 0 ? void 0 : override.cancellation_warning_threshold) !== null && _18 !== void 0 ? _18 : yaml === null || yaml === void 0 ? void 0 : yaml.cancellation_warning_threshold,
|
|
100
106
|
};
|
|
101
107
|
}
|
|
108
|
+
static parseIntEnv(envName) {
|
|
109
|
+
const value = this.env(envName);
|
|
110
|
+
if (value === undefined || value === '')
|
|
111
|
+
return undefined;
|
|
112
|
+
if (!/^\d+$/.test(value.trim())) {
|
|
113
|
+
throw new Error(`Invalid value for ${envName}: "${value}". Expected a positive integer.`);
|
|
114
|
+
}
|
|
115
|
+
return parseInt(value, 10);
|
|
116
|
+
}
|
|
102
117
|
static parseJsonArray(value) {
|
|
103
118
|
try {
|
|
104
119
|
const parsed = JSON.parse(value);
|
package/util/grpc-helpers.js
CHANGED
|
@@ -29,17 +29,22 @@ exports.createGrpcClient = exports.addTokenMiddleware = exports.channelFactory =
|
|
|
29
29
|
const nice_grpc_1 = require("nice-grpc");
|
|
30
30
|
const nice_grpc_common_1 = require("nice-grpc-common");
|
|
31
31
|
const config_loader_1 = require("./config-loader");
|
|
32
|
-
const channelFactory = (config, credentials) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
const channelFactory = (config, credentials) => {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
return (0, nice_grpc_1.createChannel)(config.host_port, credentials, {
|
|
35
|
+
'grpc.ssl_target_name_override': config.tls_config.server_name,
|
|
36
|
+
'grpc.keepalive_timeout_ms': 60 * 1000,
|
|
37
|
+
'grpc.client_idle_timeout_ms': 60 * 1000,
|
|
38
|
+
// Send keepalive pings every 10 seconds, default is 2 hours.
|
|
39
|
+
'grpc.keepalive_time_ms': 10 * 1000,
|
|
40
|
+
// Allow keepalive pings when there are no gRPC calls.
|
|
41
|
+
'grpc.keepalive_permit_without_calls': 1,
|
|
42
|
+
// Enable gzip compression for all calls on this channel
|
|
43
|
+
'grpc.default_compression_algorithm': 2, // 2 = Gzip compression
|
|
44
|
+
'grpc.max_send_message_length': (_a = config.grpc_max_send_message_length) !== null && _a !== void 0 ? _a : 4 * 1024 * 1024,
|
|
45
|
+
'grpc.max_receive_message_length': (_b = config.grpc_max_recv_message_length) !== null && _b !== void 0 ? _b : 4 * 1024 * 1024,
|
|
46
|
+
});
|
|
47
|
+
};
|
|
43
48
|
exports.channelFactory = channelFactory;
|
|
44
49
|
const addTokenMiddleware = (token) => function _(call, options) {
|
|
45
50
|
return __asyncGenerator(this, arguments, function* _1() {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0 SDK root-import deprecation warnings.
|
|
3
|
+
*
|
|
4
|
+
* The legacy `workflow` and `step` re-exports under the root specifier need
|
|
5
|
+
* to keep nagging consumers to migrate to v1, but the original implementation
|
|
6
|
+
* used `console.warn` at module evaluation time, which:
|
|
7
|
+
* - cannot be silenced by Node's standard `--no-deprecation`,
|
|
8
|
+
* `--no-warnings`, or `--no-warnings=DeprecationWarning` flags;
|
|
9
|
+
* - has no stable `code` for `process.on('warning', ...)` handlers; and
|
|
10
|
+
* - is duplicated when both submodules are loaded (which happens for
|
|
11
|
+
* anyone importing from the root, since `index.ts` re-exports both).
|
|
12
|
+
*
|
|
13
|
+
* Switching to `process.emitWarning` with a fixed code makes the warnings
|
|
14
|
+
* filterable, dedupable, and consistent with the rest of Node's deprecation
|
|
15
|
+
* surface, while still being visible by default.
|
|
16
|
+
*/
|
|
17
|
+
export declare const V0_DEPRECATION_CODE = "HATCHET_V0_REMOVED";
|
|
18
|
+
/** Reset hook for tests. Not part of the public API. */
|
|
19
|
+
export declare function _resetEmittedV0Warnings(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Emit a deduplicated v0-removal deprecation warning for a given submodule.
|
|
22
|
+
*
|
|
23
|
+
* Each unique `submodule` is emitted at most once per process. Uses
|
|
24
|
+
* `process.emitWarning` when available so consumers can suppress or filter
|
|
25
|
+
* via standard Node mechanisms.
|
|
26
|
+
*
|
|
27
|
+
* Importing the SDK must never abort module evaluation, since the root
|
|
28
|
+
* specifier still re-exports v0 `workflow` and `step` for transitive
|
|
29
|
+
* consumers who only use v1 APIs. Two cases would otherwise crash them:
|
|
30
|
+
*
|
|
31
|
+
* 1. `process.throwDeprecation` (set by `--throw-deprecation` or directly).
|
|
32
|
+
* Node queues a `throw warning` on the next tick after `emitWarning`
|
|
33
|
+
* returns, so a `try`/`catch` around the call would not catch it. We
|
|
34
|
+
* check the flag up front and route to `console.warn` instead.
|
|
35
|
+
* 2. Runtimes that don't expose `process.emitWarning` at all (older
|
|
36
|
+
* browsers, certain bundler shims). Same fallback applies.
|
|
37
|
+
*
|
|
38
|
+
* The remaining `try`/`catch` is belt-and-suspenders for non-Node hosts
|
|
39
|
+
* where a polyfilled `emitWarning` could throw synchronously.
|
|
40
|
+
*
|
|
41
|
+
* @param submodule - The legacy v0 submodule being imported (e.g. "workflow", "step").
|
|
42
|
+
* @param detail - Optional follow-up sentence appended to the warning detail.
|
|
43
|
+
*/
|
|
44
|
+
export declare function emitV0RemovedWarning(submodule: string, detail?: string): void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* v0 SDK root-import deprecation warnings.
|
|
4
|
+
*
|
|
5
|
+
* The legacy `workflow` and `step` re-exports under the root specifier need
|
|
6
|
+
* to keep nagging consumers to migrate to v1, but the original implementation
|
|
7
|
+
* used `console.warn` at module evaluation time, which:
|
|
8
|
+
* - cannot be silenced by Node's standard `--no-deprecation`,
|
|
9
|
+
* `--no-warnings`, or `--no-warnings=DeprecationWarning` flags;
|
|
10
|
+
* - has no stable `code` for `process.on('warning', ...)` handlers; and
|
|
11
|
+
* - is duplicated when both submodules are loaded (which happens for
|
|
12
|
+
* anyone importing from the root, since `index.ts` re-exports both).
|
|
13
|
+
*
|
|
14
|
+
* Switching to `process.emitWarning` with a fixed code makes the warnings
|
|
15
|
+
* filterable, dedupable, and consistent with the rest of Node's deprecation
|
|
16
|
+
* surface, while still being visible by default.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.V0_DEPRECATION_CODE = void 0;
|
|
20
|
+
exports._resetEmittedV0Warnings = _resetEmittedV0Warnings;
|
|
21
|
+
exports.emitV0RemovedWarning = emitV0RemovedWarning;
|
|
22
|
+
exports.V0_DEPRECATION_CODE = 'HATCHET_V0_REMOVED';
|
|
23
|
+
const MIGRATION_URL = 'https://docs.hatchet.run/home/v1-sdk-improvements';
|
|
24
|
+
const emittedSubmodules = new Set();
|
|
25
|
+
/** Reset hook for tests. Not part of the public API. */
|
|
26
|
+
function _resetEmittedV0Warnings() {
|
|
27
|
+
emittedSubmodules.clear();
|
|
28
|
+
}
|
|
29
|
+
function fallbackConsoleWarn(message, detail) {
|
|
30
|
+
console.warn(`[${exports.V0_DEPRECATION_CODE}] ${message}${detail ? `\n${detail}` : ''}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Emit a deduplicated v0-removal deprecation warning for a given submodule.
|
|
34
|
+
*
|
|
35
|
+
* Each unique `submodule` is emitted at most once per process. Uses
|
|
36
|
+
* `process.emitWarning` when available so consumers can suppress or filter
|
|
37
|
+
* via standard Node mechanisms.
|
|
38
|
+
*
|
|
39
|
+
* Importing the SDK must never abort module evaluation, since the root
|
|
40
|
+
* specifier still re-exports v0 `workflow` and `step` for transitive
|
|
41
|
+
* consumers who only use v1 APIs. Two cases would otherwise crash them:
|
|
42
|
+
*
|
|
43
|
+
* 1. `process.throwDeprecation` (set by `--throw-deprecation` or directly).
|
|
44
|
+
* Node queues a `throw warning` on the next tick after `emitWarning`
|
|
45
|
+
* returns, so a `try`/`catch` around the call would not catch it. We
|
|
46
|
+
* check the flag up front and route to `console.warn` instead.
|
|
47
|
+
* 2. Runtimes that don't expose `process.emitWarning` at all (older
|
|
48
|
+
* browsers, certain bundler shims). Same fallback applies.
|
|
49
|
+
*
|
|
50
|
+
* The remaining `try`/`catch` is belt-and-suspenders for non-Node hosts
|
|
51
|
+
* where a polyfilled `emitWarning` could throw synchronously.
|
|
52
|
+
*
|
|
53
|
+
* @param submodule - The legacy v0 submodule being imported (e.g. "workflow", "step").
|
|
54
|
+
* @param detail - Optional follow-up sentence appended to the warning detail.
|
|
55
|
+
*/
|
|
56
|
+
function emitV0RemovedWarning(submodule, detail) {
|
|
57
|
+
if (emittedSubmodules.has(submodule)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
emittedSubmodules.add(submodule);
|
|
61
|
+
const message = `The v0 SDK, including the ${submodule} module, has been deprecated and was removed in v1.14.0. ` +
|
|
62
|
+
`Please migrate to the v1 SDK: ${MIGRATION_URL}`;
|
|
63
|
+
const hasProcess = typeof process !== 'undefined';
|
|
64
|
+
const hasEmitWarning = hasProcess && typeof process.emitWarning === 'function';
|
|
65
|
+
const willThrowAsync = hasProcess && process.throwDeprecation === true;
|
|
66
|
+
if (!hasEmitWarning || willThrowAsync) {
|
|
67
|
+
fallbackConsoleWarn(message, detail);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
process.emitWarning(message, {
|
|
72
|
+
type: 'DeprecationWarning',
|
|
73
|
+
code: exports.V0_DEPRECATION_CODE,
|
|
74
|
+
detail,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (_a) {
|
|
78
|
+
fallbackConsoleWarn(message, detail);
|
|
79
|
+
}
|
|
80
|
+
}
|
package/v1/agent/openai.js
CHANGED
|
@@ -49,8 +49,11 @@ const OpenAIToolFunc = (runnable) => {
|
|
|
49
49
|
// z is imported from 'zod', so '_zod' in z.string() reflects the user's actual installed version.
|
|
50
50
|
const hasZodV4 = '_zod' in z.string();
|
|
51
51
|
let hasOpenAIAgents = true;
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
let tool;
|
|
52
54
|
try {
|
|
53
|
-
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
56
|
+
({ tool } = require('@openai/agents'));
|
|
54
57
|
}
|
|
55
58
|
catch (_a) {
|
|
56
59
|
hasOpenAIAgents = false;
|
|
@@ -61,8 +64,6 @@ const OpenAIToolFunc = (runnable) => {
|
|
|
61
64
|
if (!runnable.definition.inputValidator) {
|
|
62
65
|
throw new Error('inputValidator must be defined');
|
|
63
66
|
}
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
65
|
-
const { tool } = require('@openai/agents');
|
|
66
67
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
68
|
const inputValidatorV4 = runnable.definition.inputValidator;
|
|
68
69
|
const { description } = runnable.definition;
|
package/v1/client/admin.js
CHANGED
|
@@ -114,6 +114,7 @@ class AdminClient {
|
|
|
114
114
|
*/
|
|
115
115
|
runWorkflows(workflowRuns_1) {
|
|
116
116
|
return __awaiter(this, arguments, void 0, function* (workflowRuns, batchSize = 500) {
|
|
117
|
+
var _a;
|
|
117
118
|
// Prepare workflows to be triggered in bulk
|
|
118
119
|
const workflowRequests = workflowRuns.map(({ workflowName, input, options }) => {
|
|
119
120
|
const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace).toLowerCase();
|
|
@@ -126,8 +127,7 @@ class AdminClient {
|
|
|
126
127
|
? convertDesiredWorkerLabels(desiredWorkerLabels)
|
|
127
128
|
: {} });
|
|
128
129
|
});
|
|
129
|
-
const
|
|
130
|
-
const batches = (0, batch_1.batch)(workflowRequests, batchSize, limit);
|
|
130
|
+
const batches = (0, batch_1.batch)(workflowRequests, batchSize, (_a = this.config.grpc_max_send_message_length) !== null && _a !== void 0 ? _a : 4 * 1024 * 1024);
|
|
131
131
|
this.logger.debug(`batching ${batches.length} batches`);
|
|
132
132
|
try {
|
|
133
133
|
const results = [];
|
|
@@ -24,8 +24,8 @@ workflow.task({
|
|
|
24
24
|
const result = yield childWorkflow.run({});
|
|
25
25
|
results.push(result);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
ctx.logger.info('Spawned 50 child workflows');
|
|
28
|
+
ctx.logger.info('Results', { results });
|
|
29
29
|
return { step1: 'step1 results!' };
|
|
30
30
|
}),
|
|
31
31
|
});
|
|
@@ -1,4 +1,37 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -16,25 +49,22 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
16
49
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
50
|
};
|
|
18
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
// eslint-disable-next-line
|
|
20
52
|
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
53
|
function main() {
|
|
24
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
// Generate a tool from a standalone task
|
|
26
|
-
// const temperatureTool = getTemperature.mcpTool('claude');
|
|
27
55
|
var _a, e_1, _b, _c;
|
|
28
|
-
|
|
29
|
-
|
|
56
|
+
const temperatureTool = (0, workflow_1.createTemperatureWorkflowToolClaude)();
|
|
57
|
+
// The Claude Agent SDK is ESM-only, so avoid loading it at module import time.
|
|
58
|
+
// Run this example with an ESM-compatible TypeScript runner.
|
|
59
|
+
const { query, createSdkMcpServer } = yield Promise.resolve().then(() => __importStar(require('@anthropic-ai/claude-agent-sdk')));
|
|
30
60
|
// Wrap the tool in an in-process MCP server
|
|
31
|
-
const weatherServer =
|
|
61
|
+
const weatherServer = createSdkMcpServer({
|
|
32
62
|
name: 'weather',
|
|
33
63
|
version: '1.0.0',
|
|
34
64
|
tools: [temperatureTool],
|
|
35
65
|
});
|
|
36
66
|
try {
|
|
37
|
-
for (var _d = true, _e = __asyncValues(
|
|
67
|
+
for (var _d = true, _e = __asyncValues(query({
|
|
38
68
|
prompt: "What's the temperature in San Francisco?",
|
|
39
69
|
options: {
|
|
40
70
|
mcpServers: { weather: weatherServer },
|
|
@@ -42,16 +42,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
// eslint-disable-next-line
|
|
46
45
|
const workflow_1 = require("./workflow");
|
|
47
46
|
function main() {
|
|
48
47
|
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
48
|
// mcpTool validates Zod v4 is installed before loading @openai/agents, so call it first
|
|
53
49
|
// to get a clear error message if the wrong Zod version is present.
|
|
54
|
-
const temperatureTool = workflow_1.
|
|
50
|
+
const temperatureTool = (0, workflow_1.createTemperatureWorkflowToolOpenai)();
|
|
55
51
|
// Dynamic import — @openai/agents crashes at load time with Zod v3, so we delay
|
|
56
52
|
// the import until after mcpTool has already verified Zod v4 is available.
|
|
57
53
|
const { Agent, run } = yield Promise.resolve().then(() => __importStar(require('@openai/agents')));
|
|
@@ -7,20 +7,24 @@ declare const TemperatureInput: z.ZodObject<{
|
|
|
7
7
|
}, z.core.$strip>;
|
|
8
8
|
}, z.core.$strip>;
|
|
9
9
|
export type TemperatureInputWithZod = z.infer<typeof TemperatureInput>;
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const getTemperatureWorkflow: import("../..").WorkflowDeclaration<{
|
|
11
11
|
locationName: string;
|
|
12
12
|
coords: {
|
|
13
13
|
latitude: number;
|
|
14
14
|
longitude: number;
|
|
15
15
|
};
|
|
16
|
-
}, {
|
|
17
|
-
|
|
18
|
-
}, {}, {}, {}, {}>;
|
|
19
|
-
export declare const getTemperatureWorkflow: import("../..").WorkflowDeclaration<{
|
|
16
|
+
}, {}, {}>;
|
|
17
|
+
export declare const getTemperature: import("../..").TaskWorkflowDeclaration<{
|
|
20
18
|
locationName: string;
|
|
21
19
|
coords: {
|
|
22
20
|
latitude: number;
|
|
23
21
|
longitude: number;
|
|
24
22
|
};
|
|
25
|
-
}, {
|
|
23
|
+
}, {
|
|
24
|
+
text: string;
|
|
25
|
+
}, {}, {}, {}, {}>;
|
|
26
|
+
export declare function createTemperatureWorkflowToolClaude(): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition;
|
|
27
|
+
export declare function createTemperatureWorkflowToolOpenai(): import("@openai/agents").FunctionTool;
|
|
28
|
+
export declare function createTemperatureTaskToolClaude(): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition;
|
|
29
|
+
export declare function createTemperatureTaskToolOpenai(): import("@openai/agents").FunctionTool;
|
|
26
30
|
export {};
|
|
@@ -9,11 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
|
|
12
|
+
exports.getTemperature = exports.getTemperatureWorkflow = void 0;
|
|
13
|
+
exports.createTemperatureWorkflowToolClaude = createTemperatureWorkflowToolClaude;
|
|
14
|
+
exports.createTemperatureWorkflowToolOpenai = createTemperatureWorkflowToolOpenai;
|
|
15
|
+
exports.createTemperatureTaskToolClaude = createTemperatureTaskToolClaude;
|
|
16
|
+
exports.createTemperatureTaskToolOpenai = createTemperatureTaskToolOpenai;
|
|
14
17
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
18
|
const v4_1 = require("zod/v4");
|
|
16
|
-
//
|
|
19
|
+
// > Models
|
|
20
|
+
// Agent tools require a Zod v4 inputValidator so the SDK can generate the tool input schema.
|
|
17
21
|
const TemperatureCoordinates = v4_1.z.object({
|
|
18
22
|
latitude: v4_1.z.number(),
|
|
19
23
|
longitude: v4_1.z.number(),
|
|
@@ -22,20 +26,15 @@ const TemperatureInput = v4_1.z.object({
|
|
|
22
26
|
locationName: v4_1.z.string(),
|
|
23
27
|
coords: TemperatureCoordinates,
|
|
24
28
|
});
|
|
29
|
+
// !!
|
|
25
30
|
const temperatureRequest = (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
31
|
const response = yield fetch(`https://api.open-meteo.com/v1/forecast?latitude=${input.coords.latitude}&longitude=${input.coords.longitude}¤t=temperature_2m&temperature_unit=fahrenheit`);
|
|
27
32
|
const data = yield response.json();
|
|
28
33
|
return {
|
|
29
|
-
text: `Temperature: ${data.current.temperature_2m}°F`,
|
|
34
|
+
text: `Temperature in ${input.locationName}: ${data.current.temperature_2m}°F`,
|
|
30
35
|
};
|
|
31
36
|
});
|
|
32
|
-
|
|
33
|
-
name: 'getTemperature',
|
|
34
|
-
retries: 3,
|
|
35
|
-
fn: temperatureRequest,
|
|
36
|
-
inputValidator: TemperatureInput,
|
|
37
|
-
description: 'Get the current temperature at a location',
|
|
38
|
-
});
|
|
37
|
+
// > Workflow definition
|
|
39
38
|
exports.getTemperatureWorkflow = hatchet_client_1.hatchet.workflow({
|
|
40
39
|
name: 'getTemperatureWorkflow',
|
|
41
40
|
inputValidator: TemperatureInput,
|
|
@@ -46,3 +45,26 @@ exports.getTemperatureWorkflow.task({
|
|
|
46
45
|
fn: temperatureRequest,
|
|
47
46
|
});
|
|
48
47
|
// !!
|
|
48
|
+
// > Standalone task
|
|
49
|
+
exports.getTemperature = hatchet_client_1.hatchet.task({
|
|
50
|
+
name: 'getTemperature',
|
|
51
|
+
retries: 3,
|
|
52
|
+
fn: temperatureRequest,
|
|
53
|
+
inputValidator: TemperatureInput,
|
|
54
|
+
description: 'Get the current temperature at a location',
|
|
55
|
+
});
|
|
56
|
+
// !!
|
|
57
|
+
// > Create MCP tools
|
|
58
|
+
function createTemperatureWorkflowToolClaude() {
|
|
59
|
+
return exports.getTemperatureWorkflow.mcpTool('claude');
|
|
60
|
+
}
|
|
61
|
+
function createTemperatureWorkflowToolOpenai() {
|
|
62
|
+
return exports.getTemperatureWorkflow.mcpTool('openai');
|
|
63
|
+
}
|
|
64
|
+
function createTemperatureTaskToolClaude() {
|
|
65
|
+
return exports.getTemperature.mcpTool('claude');
|
|
66
|
+
}
|
|
67
|
+
function createTemperatureTaskToolOpenai() {
|
|
68
|
+
return exports.getTemperature.mcpTool('openai');
|
|
69
|
+
}
|
|
70
|
+
// !!
|
|
@@ -15,7 +15,7 @@ exports.bulkReplayTest1 = hatchet_client_1.hatchet.task({
|
|
|
15
15
|
name: 'bulk-replay-test-1',
|
|
16
16
|
retries: 1,
|
|
17
17
|
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
|
|
18
|
+
ctx.logger.info('retrying bulk replay test task', { retryCount: ctx.retryCount() });
|
|
19
19
|
if (ctx.retryCount() === 0) {
|
|
20
20
|
throw new Error('This is a test error to trigger a retry.');
|
|
21
21
|
}
|
|
@@ -25,7 +25,7 @@ exports.bulkReplayTest2 = hatchet_client_1.hatchet.task({
|
|
|
25
25
|
name: 'bulk-replay-test-2',
|
|
26
26
|
retries: 1,
|
|
27
27
|
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
|
|
28
|
+
ctx.logger.info('retrying bulk replay test task', { retryCount: ctx.retryCount() });
|
|
29
29
|
if (ctx.retryCount() === 0) {
|
|
30
30
|
throw new Error('This is a test error to trigger a retry.');
|
|
31
31
|
}
|
|
@@ -35,7 +35,7 @@ exports.bulkReplayTest3 = hatchet_client_1.hatchet.task({
|
|
|
35
35
|
name: 'bulk-replay-test-3',
|
|
36
36
|
retries: 1,
|
|
37
37
|
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
-
|
|
38
|
+
ctx.logger.info('retrying bulk replay test task', { retryCount: ctx.retryCount() });
|
|
39
39
|
if (ctx.retryCount() === 0) {
|
|
40
40
|
throw new Error('This is a test error to trigger a retry.');
|
|
41
41
|
}
|
|
@@ -47,17 +47,17 @@ exports.cancellationWorkflow.task({
|
|
|
47
47
|
// > Abort Signal
|
|
48
48
|
exports.abortSignal = hatchet_client_1.hatchet.task({
|
|
49
49
|
name: 'abort-signal',
|
|
50
|
-
fn: (
|
|
50
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
51
|
try {
|
|
52
52
|
const response = yield axios_1.default.get('https://api.example.com/data', {
|
|
53
|
-
signal: abortController.signal,
|
|
53
|
+
signal: ctx.abortController.signal,
|
|
54
54
|
});
|
|
55
55
|
// Handle the response
|
|
56
56
|
}
|
|
57
57
|
catch (error) {
|
|
58
58
|
if (axios_1.default.isCancel(error)) {
|
|
59
59
|
// Request was canceled
|
|
60
|
-
|
|
60
|
+
ctx.logger.info('Request canceled');
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
// Handle other errors
|
|
@@ -33,17 +33,17 @@ exports.cancellation = hatchet_client_1.hatchet.task({
|
|
|
33
33
|
// > Abort Signal
|
|
34
34
|
exports.abortSignal = hatchet_client_1.hatchet.task({
|
|
35
35
|
name: 'abort-signal',
|
|
36
|
-
fn: (
|
|
36
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
37
|
try {
|
|
38
38
|
const response = yield axios_1.default.get('https://api.example.com/data', {
|
|
39
|
-
signal: abortController.signal,
|
|
39
|
+
signal: ctx.abortController.signal,
|
|
40
40
|
});
|
|
41
41
|
// Handle the response
|
|
42
42
|
}
|
|
43
43
|
catch (error) {
|
|
44
44
|
if (axios_1.default.isCancel(error)) {
|
|
45
45
|
// Request was canceled
|
|
46
|
-
|
|
46
|
+
ctx.logger.info('Request canceled');
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
49
|
// Handle other errors
|
|
@@ -33,7 +33,7 @@ exports.dagWithConditions.task({
|
|
|
33
33
|
parents: [firstTask],
|
|
34
34
|
waitFor: (0, conditions_1.Or)({ eventKey: 'user:event' }, { sleepFor: '10s' }),
|
|
35
35
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
|
|
36
|
+
ctx.logger.info('triggered by condition', { triggers: ctx.triggers() });
|
|
37
37
|
return {
|
|
38
38
|
Completed: true,
|
|
39
39
|
};
|
|
@@ -33,7 +33,7 @@ exports.dagWithConditions.task({
|
|
|
33
33
|
parents: [firstTask],
|
|
34
34
|
waitFor: (0, conditions_1.Or)({ eventKey: 'user:event' }, { sleepFor: '10s' }),
|
|
35
35
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
|
|
36
|
+
ctx.logger.info('triggered by condition', { triggers: ctx.triggers() });
|
|
37
37
|
return {
|
|
38
38
|
Completed: true,
|
|
39
39
|
};
|
|
@@ -29,20 +29,20 @@ exports.durableWorkflow = hatchet_client_1.hatchet.workflow({
|
|
|
29
29
|
// !!
|
|
30
30
|
exports.durableWorkflow.task({
|
|
31
31
|
name: 'ephemeral_task',
|
|
32
|
-
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
|
|
32
|
+
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
ctx.logger.info('Running non-durable task');
|
|
34
34
|
}),
|
|
35
35
|
});
|
|
36
36
|
exports.durableWorkflow.durableTask({
|
|
37
37
|
name: 'durable_task',
|
|
38
38
|
executionTimeout: '10m',
|
|
39
39
|
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
|
|
40
|
+
ctx.logger.info('Waiting for sleep');
|
|
41
41
|
const sleepResult = yield ctx.sleepFor(exports.SLEEP_TIME, { label: 'waiting for sleep' });
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
ctx.logger.info('Sleep finished');
|
|
43
|
+
ctx.logger.info('Waiting for event');
|
|
44
44
|
const event = yield ctx.waitForEvent(exports.EVENT_KEY, 'true');
|
|
45
|
-
|
|
45
|
+
ctx.logger.info('Event received');
|
|
46
46
|
return {
|
|
47
47
|
status: 'success',
|
|
48
48
|
event: event,
|
|
@@ -18,7 +18,7 @@ exports.durableEvent = hatchet_client_1.hatchet.durableTask({
|
|
|
18
18
|
executionTimeout: '10m',
|
|
19
19
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
20
|
const res = yield ctx.waitForEvent('user:update');
|
|
21
|
-
|
|
21
|
+
ctx.logger.info('res', { res });
|
|
22
22
|
return {
|
|
23
23
|
Value: 'done',
|
|
24
24
|
};
|
|
@@ -32,7 +32,7 @@ exports.durableEventWithFilter = hatchet_client_1.hatchet.durableTask({
|
|
|
32
32
|
// > Durable Event With Filter
|
|
33
33
|
const res = yield ctx.waitForEvent('user:update', "input.userId == '1234'");
|
|
34
34
|
// !!
|
|
35
|
-
|
|
35
|
+
ctx.logger.info('res', { res });
|
|
36
36
|
return {
|
|
37
37
|
Value: 'done',
|
|
38
38
|
};
|
|
@@ -20,9 +20,9 @@ exports.durableSleep.durableTask({
|
|
|
20
20
|
name: 'durable-sleep',
|
|
21
21
|
executionTimeout: '10m',
|
|
22
22
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
|
|
23
|
+
ctx.logger.info('sleeping for 5s');
|
|
24
24
|
const sleepRes = yield ctx.sleepFor('5s');
|
|
25
|
-
|
|
25
|
+
ctx.logger.info('done sleeping for 5s', { sleepRes });
|
|
26
26
|
return {
|
|
27
27
|
Value: 'done',
|
|
28
28
|
};
|
|
@@ -19,7 +19,7 @@ exports.durableEvent = hatchet_client_1.hatchet.durableTask({
|
|
|
19
19
|
executionTimeout: '10m',
|
|
20
20
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
const res = yield ctx.waitForEvent(exports.EVENT_KEY);
|
|
22
|
-
|
|
22
|
+
ctx.logger.info('res', { res });
|
|
23
23
|
return {
|
|
24
24
|
Value: 'done',
|
|
25
25
|
};
|
|
@@ -33,7 +33,7 @@ exports.durableEventWithFilter = hatchet_client_1.hatchet.durableTask({
|
|
|
33
33
|
// > Durable Event With Filter
|
|
34
34
|
const res = yield ctx.waitForEvent(exports.EVENT_KEY, "input.userId == '1234'");
|
|
35
35
|
// !!
|
|
36
|
-
|
|
36
|
+
ctx.logger.info('res', { res });
|
|
37
37
|
return {
|
|
38
38
|
Value: 'done',
|
|
39
39
|
};
|
|
@@ -46,7 +46,7 @@ exports.durableEventWithLookback = hatchet_client_1.hatchet.durableTask({
|
|
|
46
46
|
executionTimeout: '10m',
|
|
47
47
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
48
|
const res = yield ctx.waitForEvent(exports.EVENT_KEY, undefined, undefined, exports.SCOPE, '1m');
|
|
49
|
-
|
|
49
|
+
ctx.logger.info('res', { res });
|
|
50
50
|
return {
|
|
51
51
|
Value: 'done',
|
|
52
52
|
};
|
|
@@ -20,9 +20,9 @@ exports.durableSleep.durableTask({
|
|
|
20
20
|
name: 'durable-sleep',
|
|
21
21
|
executionTimeout: '10m',
|
|
22
22
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
|
|
23
|
+
ctx.logger.info('sleeping for 5s');
|
|
24
24
|
const sleepRes = yield ctx.sleepFor('5s');
|
|
25
|
-
|
|
25
|
+
ctx.logger.info('done sleeping for 5s', { sleepRes });
|
|
26
26
|
return {
|
|
27
27
|
Value: 'done',
|
|
28
28
|
};
|
|
@@ -5,7 +5,7 @@ exports.hatchetWithMiddlewareChaining = exports.hatchetWithMiddleware = void 0;
|
|
|
5
5
|
const v1_1 = require("../..");
|
|
6
6
|
const myMiddleware = {
|
|
7
7
|
before: (input, ctx) => {
|
|
8
|
-
|
|
8
|
+
ctx.logger.info('before', { first: input.first });
|
|
9
9
|
return Object.assign(Object.assign({}, input), { dependency: 'abc-123' });
|
|
10
10
|
},
|
|
11
11
|
after: (output, ctx, input) => {
|
|
@@ -17,7 +17,7 @@ exports.hatchetWithMiddleware = v1_1.HatchetClient.init().withMiddleware(myMiddl
|
|
|
17
17
|
// > Chaining middleware
|
|
18
18
|
const firstMiddleware = {
|
|
19
19
|
before: (input, ctx) => {
|
|
20
|
-
|
|
20
|
+
ctx.logger.info('before', { first: input.first });
|
|
21
21
|
return Object.assign(Object.assign({}, input), { dependency: 'abc-123' });
|
|
22
22
|
},
|
|
23
23
|
after: (output, ctx, input) => {
|
|
@@ -26,7 +26,7 @@ const firstMiddleware = {
|
|
|
26
26
|
};
|
|
27
27
|
const secondMiddleware = {
|
|
28
28
|
before: (input, ctx) => {
|
|
29
|
-
|
|
29
|
+
ctx.logger.info('before', { dependency: input.dependency }); // available from previous middleware
|
|
30
30
|
return Object.assign(Object.assign({}, input), { anotherDep: true });
|
|
31
31
|
},
|
|
32
32
|
after: (output, ctx, input) => {
|
|
@@ -4,11 +4,11 @@ exports.taskWithMiddleware = void 0;
|
|
|
4
4
|
const client_1 = require("./client");
|
|
5
5
|
exports.taskWithMiddleware = client_1.hatchetWithMiddleware.task({
|
|
6
6
|
name: 'task-with-middleware',
|
|
7
|
-
fn: (input,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
fn: (input, ctx) => {
|
|
8
|
+
ctx.logger.info('task', { message: input.message }); // string (from TaskInput)
|
|
9
|
+
ctx.logger.info('task', { first: input.first }); // number (from GlobalInputType)
|
|
10
|
+
ctx.logger.info('task', { second: input.second }); // number (from GlobalInputType)
|
|
11
|
+
ctx.logger.info('task', { dependency: input.dependency }); // string (from Pre Middleware)
|
|
12
12
|
return {
|
|
13
13
|
message: input.message,
|
|
14
14
|
extra: 1,
|
|
@@ -28,8 +28,8 @@ exports.failureWorkflow.task({
|
|
|
28
28
|
exports.failureWorkflow.onFailure({
|
|
29
29
|
name: 'on_failure',
|
|
30
30
|
fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
ctx.logger.info(`onFailure for run: ${ctx.workflowRunId()}`);
|
|
32
|
+
ctx.logger.info('upstream errors', { errors: ctx.errors() });
|
|
33
33
|
return {
|
|
34
34
|
status: 'success',
|
|
35
35
|
};
|
|
@@ -34,7 +34,7 @@ exports.onSuccessDag.task({
|
|
|
34
34
|
// 👀 onSuccess handler will run if all tasks in the workflow succeed
|
|
35
35
|
exports.onSuccessDag.onSuccess({
|
|
36
36
|
fn: (_, ctx) => {
|
|
37
|
-
|
|
37
|
+
ctx.logger.info(`onSuccess for run: ${ctx.workflowRunId()}`);
|
|
38
38
|
return {
|
|
39
39
|
'on-success': 'success',
|
|
40
40
|
};
|
|
@@ -19,16 +19,16 @@ const task1 = hatchet_client_1.hatchet.task({
|
|
|
19
19
|
units: 1,
|
|
20
20
|
},
|
|
21
21
|
],
|
|
22
|
-
fn: (
|
|
23
|
-
|
|
22
|
+
fn: (_input, ctx) => {
|
|
23
|
+
ctx.logger.info('executed task1');
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
// !!
|
|
27
27
|
// > Dynamic
|
|
28
28
|
const task2 = hatchet_client_1.hatchet.task({
|
|
29
29
|
name: 'task2',
|
|
30
|
-
fn: (input) => {
|
|
31
|
-
|
|
30
|
+
fn: (input, ctx) => {
|
|
31
|
+
ctx.logger.info(`executed task2 for user: ${input.userId}`);
|
|
32
32
|
},
|
|
33
33
|
rateLimits: [
|
|
34
34
|
{
|
|
@@ -27,7 +27,7 @@ exports.retriesWithCount = hatchet_client_1.hatchet.task({
|
|
|
27
27
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
28
|
// > Get the current retry count
|
|
29
29
|
const retryCount = ctx.retryCount();
|
|
30
|
-
|
|
30
|
+
ctx.logger.info(`Retry count: ${retryCount}`);
|
|
31
31
|
if (retryCount < 2) {
|
|
32
32
|
throw new Error('intentional failure');
|
|
33
33
|
}
|
|
@@ -26,9 +26,9 @@ exports.handleStripePayment = hatchet_client_1.hatchet.task({
|
|
|
26
26
|
on: {
|
|
27
27
|
event: 'stripe:payment_intent.succeeded',
|
|
28
28
|
},
|
|
29
|
-
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
30
|
const { customer, amount } = input.data.object;
|
|
31
|
-
|
|
31
|
+
ctx.logger.info(`Payment of ${amount} from ${customer}`);
|
|
32
32
|
return { customer, amount };
|
|
33
33
|
}),
|
|
34
34
|
});
|
|
@@ -37,11 +37,11 @@ exports.handleGitHubPR = hatchet_client_1.hatchet.task({
|
|
|
37
37
|
on: {
|
|
38
38
|
event: 'github:pull_request:opened',
|
|
39
39
|
},
|
|
40
|
-
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
41
|
const repo = input.repository.full_name;
|
|
42
42
|
const prNumber = input.pull_request.number;
|
|
43
43
|
const { title } = input.pull_request;
|
|
44
|
-
|
|
44
|
+
ctx.logger.info(`PR #${prNumber} opened on ${repo}: ${title}`);
|
|
45
45
|
return { repo, pr: prNumber };
|
|
46
46
|
}),
|
|
47
47
|
});
|
|
@@ -50,9 +50,9 @@ exports.handleSlackMention = hatchet_client_1.hatchet.task({
|
|
|
50
50
|
on: {
|
|
51
51
|
event: 'slack:event:app_mention',
|
|
52
52
|
},
|
|
53
|
-
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
54
|
const { user, text, channel } = input.event;
|
|
55
|
-
|
|
55
|
+
ctx.logger.info(`Mentioned by ${user} in ${channel}: ${text}`);
|
|
56
56
|
return { handled: true };
|
|
57
57
|
}),
|
|
58
58
|
});
|
|
@@ -61,8 +61,8 @@ exports.handleSlackCommand = hatchet_client_1.hatchet.task({
|
|
|
61
61
|
on: {
|
|
62
62
|
event: 'slack:command:/deploy',
|
|
63
63
|
},
|
|
64
|
-
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
|
|
64
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
ctx.logger.info(`${input.user_name} ran ${input.command} ${input.text}`);
|
|
66
66
|
return { command: input.command, args: input.text };
|
|
67
67
|
}),
|
|
68
68
|
});
|
|
@@ -71,9 +71,9 @@ exports.handleSlackInteraction = hatchet_client_1.hatchet.task({
|
|
|
71
71
|
on: {
|
|
72
72
|
event: 'slack:interaction:block_actions',
|
|
73
73
|
},
|
|
74
|
-
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
75
|
const [action] = input.actions;
|
|
76
|
-
|
|
76
|
+
ctx.logger.info(`${input.user.username} clicked button: ${action.action_id}`);
|
|
77
77
|
return { action: action.action_id };
|
|
78
78
|
}),
|
|
79
79
|
});
|
|
@@ -25,7 +25,7 @@ exports.welcomeEmail = hatchet_client_1.hatchet.durableTask({
|
|
|
25
25
|
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
26
|
var _a, _b;
|
|
27
27
|
// Step 1: Send the welcome email
|
|
28
|
-
|
|
28
|
+
ctx.logger.info(`Sending welcome email to ${input.email}: finish your first onboarding step`);
|
|
29
29
|
// Step 2: Wait for the user to complete onboarding, or time out
|
|
30
30
|
// (use a longer duration for a more realistic workflow)
|
|
31
31
|
const now = yield ctx.now();
|
|
@@ -41,11 +41,11 @@ exports.welcomeEmail = hatchet_client_1.hatchet.durableTask({
|
|
|
41
41
|
const onboardingCompleted = resolvedKey === exports.ONBOARDING_EVENT_KEY;
|
|
42
42
|
if (onboardingCompleted) {
|
|
43
43
|
// Step 3a: User completed onboarding -> skip follow-up
|
|
44
|
-
|
|
44
|
+
ctx.logger.info(`User ${input.user_id} completed onboarding, skipping follow-up`);
|
|
45
45
|
return { userId: input.user_id, welcomeSent: true, followUpSent: false };
|
|
46
46
|
}
|
|
47
47
|
// Step 3b: Timeout -> send follow-up email
|
|
48
|
-
|
|
48
|
+
ctx.logger.info(`Sending follow-up email to ${input.email}: need help finishing onboarding?`);
|
|
49
49
|
return { userId: input.user_id, welcomeSent: true, followUpSent: true };
|
|
50
50
|
}),
|
|
51
51
|
});
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.23.0";
|
package/version.js
CHANGED
package/workflow.js
CHANGED
|
@@ -18,8 +18,6 @@ exports.StickyStrategy = exports.ConcurrencyLimitStrategy = void 0;
|
|
|
18
18
|
const v1_1 = require("./v1");
|
|
19
19
|
Object.defineProperty(exports, "ConcurrencyLimitStrategy", { enumerable: true, get: function () { return v1_1.ConcurrencyLimitStrategy; } });
|
|
20
20
|
Object.defineProperty(exports, "StickyStrategy", { enumerable: true, get: function () { return v1_1.StickyStrategy; } });
|
|
21
|
+
const v0_deprecation_warning_1 = require("./util/v0-deprecation-warning");
|
|
21
22
|
__exportStar(require("./legacy/workflow"), exports);
|
|
22
|
-
|
|
23
|
-
console.warn('\x1b[31mPlease migrate to v1 SDK instead: https://docs.hatchet.run/home/v1-sdk-improvements\x1b[0m');
|
|
24
|
-
console.warn('ConcurrencyLimitStrategy, StickyStrategy have been moved to @hatchet-dev/typescript-sdk/v1');
|
|
25
|
-
console.warn('--------------------------------');
|
|
23
|
+
(0, v0_deprecation_warning_1.emitV0RemovedWarning)('workflow', 'ConcurrencyLimitStrategy and StickyStrategy have been moved to @hatchet-dev/typescript-sdk/v1.');
|