@hatchet-dev/typescript-sdk 1.22.3 → 1.23.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/event/event-client.js +3 -3
- package/clients/hatchet-client/client-config.d.ts +7 -1
- package/clients/hatchet-client/client-config.js +20 -0
- package/opentelemetry/instrumentor.js +78 -17
- package/opentelemetry/types.d.ts +1 -0
- package/opentelemetry/types.js +1 -0
- package/package.json +16 -5
- package/step.js +2 -3
- package/util/config-loader/config-loader.d.ts +1 -0
- package/util/config-loader/config-loader.js +20 -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/client/admin.js +2 -2
- package/v1/client/features/workflows.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/aws/s3/worker.d.ts +1 -0
- package/v1/examples/aws/s3/worker.js +177 -0
- 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/support_agent_tools/agent-claude.d.ts +1 -0
- package/v1/examples/support_agent_tools/agent-claude.js +109 -0
- package/v1/examples/support_agent_tools/agent-openai.d.ts +1 -0
- package/v1/examples/support_agent_tools/agent-openai.js +73 -0
- package/v1/examples/support_agent_tools/tools.d.ts +45 -0
- package/v1/examples/support_agent_tools/tools.js +144 -0
- package/v1/examples/support_agent_tools/worker.d.ts +1 -0
- package/v1/examples/support_agent_tools/worker.js +24 -0
- 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
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
45
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
46
|
+
var m = o[Symbol.asyncIterator], i;
|
|
47
|
+
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);
|
|
48
|
+
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); }); }; }
|
|
49
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
50
|
+
};
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
const tools_1 = require("./tools");
|
|
53
|
+
function main() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _a, e_1, _b, _c;
|
|
56
|
+
const lookupCustomerTool = (0, tools_1.createLookupCustomerToolClaude)();
|
|
57
|
+
const checkOrderStatusTool = (0, tools_1.createCheckOrderStatusToolClaude)();
|
|
58
|
+
const ticketTool = (0, tools_1.createTicketToolClaude)();
|
|
59
|
+
// The Claude Agent SDK is ESM-only, so avoid loading it at module import time.
|
|
60
|
+
// Run this example with an ESM-compatible TypeScript runner.
|
|
61
|
+
const { query, createSdkMcpServer } = yield Promise.resolve().then(() => __importStar(require('@anthropic-ai/claude-agent-sdk')));
|
|
62
|
+
// Wrap the tools in an in-process MCP server
|
|
63
|
+
const supportServer = createSdkMcpServer({
|
|
64
|
+
name: 'support',
|
|
65
|
+
version: '1.0.0',
|
|
66
|
+
tools: [lookupCustomerTool, checkOrderStatusTool, ticketTool],
|
|
67
|
+
});
|
|
68
|
+
try {
|
|
69
|
+
for (var _d = true, _e = __asyncValues(query({
|
|
70
|
+
prompt: 'Customer C-100 says order ORD-9987 has not arrived. ' +
|
|
71
|
+
'Look up the customer, check the order status, and create a ' +
|
|
72
|
+
'support ticket if the order has a known issue or delayed delivery. ' +
|
|
73
|
+
'If you create a ticket, use priority "high", subject ' +
|
|
74
|
+
'"Delayed order ORD-9987", and a body that summarizes the known ' +
|
|
75
|
+
'carrier delay. Then summarize what happened.',
|
|
76
|
+
options: {
|
|
77
|
+
mcpServers: { support: supportServer },
|
|
78
|
+
allowedTools: [
|
|
79
|
+
`mcp__${supportServer.name}__${lookupCustomerTool.name}`,
|
|
80
|
+
`mcp__${supportServer.name}__${checkOrderStatusTool.name}`,
|
|
81
|
+
`mcp__${supportServer.name}__${ticketTool.name}`,
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
})), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
85
|
+
_c = _f.value;
|
|
86
|
+
_d = false;
|
|
87
|
+
const message = _c;
|
|
88
|
+
// "result" is the final message after all tool calls complete
|
|
89
|
+
if (message.type === 'result' && message.subtype === 'success') {
|
|
90
|
+
console.log(message.result);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
95
|
+
finally {
|
|
96
|
+
try {
|
|
97
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
98
|
+
}
|
|
99
|
+
finally { if (e_1) throw e_1.error; }
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (require.main === module) {
|
|
104
|
+
main()
|
|
105
|
+
.catch(console.error)
|
|
106
|
+
.finally(() => {
|
|
107
|
+
process.exit(0);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
const tools_1 = require("./tools");
|
|
46
|
+
function main() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const lookupCustomerTool = (0, tools_1.createLookupCustomerToolOpenai)();
|
|
49
|
+
const checkOrderStatusTool = (0, tools_1.createCheckOrderStatusToolOpenai)();
|
|
50
|
+
const ticketTool = (0, tools_1.createTicketToolOpenai)();
|
|
51
|
+
// Dynamic import — @openai/agents crashes at load time with Zod v3, so we delay
|
|
52
|
+
// the import until after mcpTool has already verified Zod v4 is available.
|
|
53
|
+
const { Agent, run } = yield Promise.resolve().then(() => __importStar(require('@openai/agents')));
|
|
54
|
+
const agent = new Agent({
|
|
55
|
+
name: 'support-agent',
|
|
56
|
+
tools: [lookupCustomerTool, checkOrderStatusTool, ticketTool],
|
|
57
|
+
});
|
|
58
|
+
const result = yield run(agent, 'Customer C-100 says order ORD-9987 has not arrived. ' +
|
|
59
|
+
'Look up the customer, check the order status, and create a ' +
|
|
60
|
+
'support ticket if the order has a known issue or delayed delivery. ' +
|
|
61
|
+
'If you create a ticket, use priority "high", subject ' +
|
|
62
|
+
'"Delayed order ORD-9987", and a body that summarizes the known ' +
|
|
63
|
+
'carrier delay. Then summarize what happened.');
|
|
64
|
+
console.log(result.finalOutput);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (require.main === module) {
|
|
68
|
+
main()
|
|
69
|
+
.catch(console.error)
|
|
70
|
+
.finally(() => {
|
|
71
|
+
process.exit(0);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
type CustomerInfo = {
|
|
2
|
+
customerId: string;
|
|
3
|
+
name: string;
|
|
4
|
+
email: string;
|
|
5
|
+
plan: string;
|
|
6
|
+
accountStatus: string;
|
|
7
|
+
defaultOrderId: string;
|
|
8
|
+
supportTier: string;
|
|
9
|
+
};
|
|
10
|
+
type OrderStatus = {
|
|
11
|
+
orderId: string;
|
|
12
|
+
status: string;
|
|
13
|
+
lastUpdated: string;
|
|
14
|
+
estimatedDelivery: string;
|
|
15
|
+
knownIssue: string | null;
|
|
16
|
+
carrier: string;
|
|
17
|
+
trackingNumber: string;
|
|
18
|
+
};
|
|
19
|
+
type TicketResult = {
|
|
20
|
+
ticketId: string;
|
|
21
|
+
status: string;
|
|
22
|
+
priority: string;
|
|
23
|
+
routingTeam: string;
|
|
24
|
+
summary: string;
|
|
25
|
+
};
|
|
26
|
+
export declare const lookupCustomer: import("../..").TaskWorkflowDeclaration<{
|
|
27
|
+
customerId: string;
|
|
28
|
+
}, CustomerInfo, {}, {}, {}, {}>;
|
|
29
|
+
export declare const checkOrderStatus: import("../..").TaskWorkflowDeclaration<{
|
|
30
|
+
orderId: string;
|
|
31
|
+
}, OrderStatus, {}, {}, {}, {}>;
|
|
32
|
+
export declare const createTicket: import("../..").TaskWorkflowDeclaration<{
|
|
33
|
+
customerId: string;
|
|
34
|
+
orderId: string;
|
|
35
|
+
subject: string;
|
|
36
|
+
body: string;
|
|
37
|
+
priority: string;
|
|
38
|
+
}, TicketResult, {}, {}, {}, {}>;
|
|
39
|
+
export declare function createLookupCustomerToolClaude(): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition;
|
|
40
|
+
export declare function createCheckOrderStatusToolClaude(): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition;
|
|
41
|
+
export declare function createTicketToolClaude(): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition;
|
|
42
|
+
export declare function createLookupCustomerToolOpenai(): import("@openai/agents").FunctionTool;
|
|
43
|
+
export declare function createCheckOrderStatusToolOpenai(): import("@openai/agents").FunctionTool;
|
|
44
|
+
export declare function createTicketToolOpenai(): import("@openai/agents").FunctionTool;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
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.createTicket = exports.checkOrderStatus = exports.lookupCustomer = void 0;
|
|
13
|
+
exports.createLookupCustomerToolClaude = createLookupCustomerToolClaude;
|
|
14
|
+
exports.createCheckOrderStatusToolClaude = createCheckOrderStatusToolClaude;
|
|
15
|
+
exports.createTicketToolClaude = createTicketToolClaude;
|
|
16
|
+
exports.createLookupCustomerToolOpenai = createLookupCustomerToolOpenai;
|
|
17
|
+
exports.createCheckOrderStatusToolOpenai = createCheckOrderStatusToolOpenai;
|
|
18
|
+
exports.createTicketToolOpenai = createTicketToolOpenai;
|
|
19
|
+
// > Setup
|
|
20
|
+
const v4_1 = require("zod/v4");
|
|
21
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
22
|
+
// !!
|
|
23
|
+
// > Models
|
|
24
|
+
const CustomerLookupInput = v4_1.z.object({
|
|
25
|
+
customerId: v4_1.z.string(),
|
|
26
|
+
});
|
|
27
|
+
const OrderStatusInput = v4_1.z.object({
|
|
28
|
+
orderId: v4_1.z.string(),
|
|
29
|
+
});
|
|
30
|
+
const CreateTicketInput = v4_1.z.object({
|
|
31
|
+
customerId: v4_1.z.string(),
|
|
32
|
+
orderId: v4_1.z.string(),
|
|
33
|
+
subject: v4_1.z.string(),
|
|
34
|
+
body: v4_1.z.string(),
|
|
35
|
+
priority: v4_1.z.string(),
|
|
36
|
+
});
|
|
37
|
+
// !!
|
|
38
|
+
// > Fixture data
|
|
39
|
+
const CUSTOMERS = {
|
|
40
|
+
'C-100': {
|
|
41
|
+
customerId: 'C-100',
|
|
42
|
+
name: 'Alice Martin',
|
|
43
|
+
email: 'alice@example.com',
|
|
44
|
+
plan: 'business',
|
|
45
|
+
accountStatus: 'active',
|
|
46
|
+
defaultOrderId: 'ORD-9987',
|
|
47
|
+
supportTier: 'priority',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const ORDERS = {
|
|
51
|
+
'ORD-9987': {
|
|
52
|
+
orderId: 'ORD-9987',
|
|
53
|
+
status: 'delayed',
|
|
54
|
+
lastUpdated: '2026-05-20T14:30:00Z',
|
|
55
|
+
estimatedDelivery: '2026-05-28',
|
|
56
|
+
knownIssue: 'Carrier reported weather delay at regional hub',
|
|
57
|
+
carrier: 'FastShip',
|
|
58
|
+
trackingNumber: 'FS-482910',
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
// !!
|
|
62
|
+
// > Lookup customer
|
|
63
|
+
exports.lookupCustomer = hatchet_client_1.hatchet.task({
|
|
64
|
+
name: 'lookup-customer',
|
|
65
|
+
inputValidator: CustomerLookupInput,
|
|
66
|
+
description: 'Look up a customer by ID and return their profile, plan, and support tier.',
|
|
67
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const customer = CUSTOMERS[input.customerId];
|
|
69
|
+
if (!customer) {
|
|
70
|
+
return {
|
|
71
|
+
customerId: input.customerId,
|
|
72
|
+
name: 'Unknown',
|
|
73
|
+
email: 'unknown@example.com',
|
|
74
|
+
plan: 'none',
|
|
75
|
+
accountStatus: 'not_found',
|
|
76
|
+
defaultOrderId: '',
|
|
77
|
+
supportTier: 'standard',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return customer;
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
// !!
|
|
84
|
+
// > Check order status
|
|
85
|
+
exports.checkOrderStatus = hatchet_client_1.hatchet.task({
|
|
86
|
+
name: 'check-order-status',
|
|
87
|
+
inputValidator: OrderStatusInput,
|
|
88
|
+
description: 'Check the current status, carrier, and any known issues for an order.',
|
|
89
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const order = ORDERS[input.orderId];
|
|
91
|
+
if (!order) {
|
|
92
|
+
return {
|
|
93
|
+
orderId: input.orderId,
|
|
94
|
+
status: 'not_found',
|
|
95
|
+
lastUpdated: '',
|
|
96
|
+
estimatedDelivery: '',
|
|
97
|
+
knownIssue: null,
|
|
98
|
+
carrier: 'unknown',
|
|
99
|
+
trackingNumber: '',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return order;
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
// !!
|
|
106
|
+
// > Create ticket
|
|
107
|
+
exports.createTicket = hatchet_client_1.hatchet.task({
|
|
108
|
+
name: 'create-ticket',
|
|
109
|
+
inputValidator: CreateTicketInput,
|
|
110
|
+
description: 'Create a support ticket for a customer issue and return the ticket ID and routing.',
|
|
111
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
|
+
const ticketId = `TICKET-${input.customerId}-001`;
|
|
113
|
+
return {
|
|
114
|
+
ticketId,
|
|
115
|
+
status: 'open',
|
|
116
|
+
priority: input.priority,
|
|
117
|
+
routingTeam: 'shipping-support',
|
|
118
|
+
summary: `Ticket ${ticketId} created for ${input.customerId} regarding order ${input.orderId}: ${input.subject}`,
|
|
119
|
+
};
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
// !!
|
|
123
|
+
// > Create Claude tools
|
|
124
|
+
function createLookupCustomerToolClaude() {
|
|
125
|
+
return exports.lookupCustomer.mcpTool('claude');
|
|
126
|
+
}
|
|
127
|
+
function createCheckOrderStatusToolClaude() {
|
|
128
|
+
return exports.checkOrderStatus.mcpTool('claude');
|
|
129
|
+
}
|
|
130
|
+
function createTicketToolClaude() {
|
|
131
|
+
return exports.createTicket.mcpTool('claude');
|
|
132
|
+
}
|
|
133
|
+
// !!
|
|
134
|
+
// > Create openai tools
|
|
135
|
+
function createLookupCustomerToolOpenai() {
|
|
136
|
+
return exports.lookupCustomer.mcpTool('openai');
|
|
137
|
+
}
|
|
138
|
+
function createCheckOrderStatusToolOpenai() {
|
|
139
|
+
return exports.checkOrderStatus.mcpTool('openai');
|
|
140
|
+
}
|
|
141
|
+
function createTicketToolOpenai() {
|
|
142
|
+
return exports.createTicket.mcpTool('openai');
|
|
143
|
+
}
|
|
144
|
+
// !!
|
|
@@ -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 tools_1 = require("./tools");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const worker = yield hatchet_client_1.hatchet.worker('support-tools-worker', {
|
|
17
|
+
workflows: [tools_1.lookupCustomer, tools_1.checkOrderStatus, tools_1.createTicket],
|
|
18
|
+
});
|
|
19
|
+
yield worker.start();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (require.main === module) {
|
|
23
|
+
main();
|
|
24
|
+
}
|
|
@@ -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.1";
|
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.');
|