@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.
- 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 +12 -6
- package/protoc/dispatcher/dispatcher.d.ts +4 -0
- package/protoc/dispatcher/dispatcher.js +41 -1
- 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 +11 -1
- package/v1/client/worker/context.js +14 -0
- 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,40 @@
|
|
|
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
|
+
// > Trigger the workflow
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
const workflow_1 = require("./workflow");
|
|
15
|
+
function main() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const input = {
|
|
18
|
+
email: 'alice@example.com',
|
|
19
|
+
user_id: 'user-123',
|
|
20
|
+
};
|
|
21
|
+
// Start the welcome-email workflow
|
|
22
|
+
const ref = yield workflow_1.welcomeEmail.runNoWait(input);
|
|
23
|
+
const runId = yield ref.getWorkflowRunId();
|
|
24
|
+
console.log(`Started workflow run: ${runId}`);
|
|
25
|
+
// Push onboarding-completed event (scoped to this user)
|
|
26
|
+
console.log('Pushing onboarding-completed event...');
|
|
27
|
+
yield hatchet_client_1.hatchet.events.push(workflow_1.ONBOARDING_EVENT_KEY, { status: 'done' }, { scope: input.user_id });
|
|
28
|
+
// Wait for the workflow to complete
|
|
29
|
+
const result = yield ref.output;
|
|
30
|
+
console.log('Workflow completed:', result);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// !!
|
|
34
|
+
if (require.main === module) {
|
|
35
|
+
main()
|
|
36
|
+
.catch(console.error)
|
|
37
|
+
.finally(() => {
|
|
38
|
+
process.exit(0);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const ONBOARDING_EVENT_KEY = "user:onboarding-completed";
|
|
2
|
+
export type SignupInput = {
|
|
3
|
+
email: string;
|
|
4
|
+
user_id: string;
|
|
5
|
+
};
|
|
6
|
+
export type WelcomeEmailResult = {
|
|
7
|
+
userId: string;
|
|
8
|
+
welcomeSent: boolean;
|
|
9
|
+
followUpSent: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const welcomeEmail: import("../..").TaskWorkflowDeclaration<SignupInput, WelcomeEmailResult, {}, {}, {}, {}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
exports.welcomeEmail = exports.ONBOARDING_EVENT_KEY = void 0;
|
|
13
|
+
const conditions_1 = require("../../conditions");
|
|
14
|
+
const duration_1 = require("../../client/duration");
|
|
15
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
16
|
+
exports.ONBOARDING_EVENT_KEY = 'user:onboarding-completed';
|
|
17
|
+
const TIMEOUT_SECONDS = 5;
|
|
18
|
+
const LOOKBACK_WINDOW = '5m';
|
|
19
|
+
// !!
|
|
20
|
+
// > Welcome email task
|
|
21
|
+
exports.welcomeEmail = hatchet_client_1.hatchet.durableTask({
|
|
22
|
+
name: 'welcome-email',
|
|
23
|
+
onEvents: ['user:signup'],
|
|
24
|
+
executionTimeout: '5m',
|
|
25
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
// Step 1: Send the welcome email
|
|
28
|
+
console.log(`Sending welcome email to ${input.email}: finish your first onboarding step`);
|
|
29
|
+
// Step 2: Wait for the user to complete onboarding, or time out
|
|
30
|
+
// (use a longer duration for a more realistic workflow)
|
|
31
|
+
const now = yield ctx.now();
|
|
32
|
+
const considerEventsSince = new Date(now.getTime() - (0, duration_1.durationToMs)(LOOKBACK_WINDOW)).toISOString();
|
|
33
|
+
const waitResult = yield ctx.waitFor((0, conditions_1.Or)({ sleepFor: `${TIMEOUT_SECONDS}s` },
|
|
34
|
+
// Scope the event condition to this user so that another user's
|
|
35
|
+
// onboarding-completed event does not resolve this wait.
|
|
36
|
+
{ eventKey: exports.ONBOARDING_EVENT_KEY, scope: input.user_id, considerEventsSince }));
|
|
37
|
+
// The or-group result is { CREATE: { <condition_key>: ... } }.
|
|
38
|
+
// Check whether the onboarding event was the one that resolved.
|
|
39
|
+
const create = (_a = waitResult['CREATE']) !== null && _a !== void 0 ? _a : waitResult;
|
|
40
|
+
const resolvedKey = (_b = Object.keys(create)[0]) !== null && _b !== void 0 ? _b : '';
|
|
41
|
+
const onboardingCompleted = resolvedKey === exports.ONBOARDING_EVENT_KEY;
|
|
42
|
+
if (onboardingCompleted) {
|
|
43
|
+
// Step 3a: User completed onboarding -> skip follow-up
|
|
44
|
+
console.log(`User ${input.user_id} completed onboarding, skipping follow-up`);
|
|
45
|
+
return { userId: input.user_id, welcomeSent: true, followUpSent: false };
|
|
46
|
+
}
|
|
47
|
+
// Step 3b: Timeout -> send follow-up email
|
|
48
|
+
console.log(`Sending follow-up email to ${input.email}: need help finishing onboarding?`);
|
|
49
|
+
return { userId: input.user_id, welcomeSent: true, followUpSent: true };
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
// !!
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.22.0";
|
package/version.js
CHANGED