@hatchet-dev/typescript-sdk 0.6.1 → 0.7.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.
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.DispatcherDefinition = exports.HeartbeatResponse = exports.HeartbeatRequest = exports.OverridesDataResponse = exports.OverridesData = exports.StepRunResult = exports.WorkflowRunEvent = exports.WorkflowEvent = exports.SubscribeToWorkflowRunsRequest = exports.SubscribeToWorkflowEventsRequest = exports.ActionEventResponse = exports.StepActionEvent = exports.GroupKeyActionEvent = exports.WorkerUnsubscribeResponse = exports.WorkerUnsubscribeRequest = exports.WorkerListenRequest = exports.AssignedAction = exports.WorkerRegisterResponse = exports.WorkerRegisterRequest = exports.workflowRunEventTypeToJSON = exports.workflowRunEventTypeFromJSON = exports.WorkflowRunEventType = exports.resourceEventTypeToJSON = exports.resourceEventTypeFromJSON = exports.ResourceEventType = exports.resourceTypeToJSON = exports.resourceTypeFromJSON = exports.ResourceType = exports.stepActionEventTypeToJSON = exports.stepActionEventTypeFromJSON = exports.StepActionEventType = exports.groupKeyActionEventTypeToJSON = exports.groupKeyActionEventTypeFromJSON = exports.GroupKeyActionEventType = exports.actionTypeToJSON = exports.actionTypeFromJSON = exports.ActionType = exports.protobufPackage = void 0;
26
+ exports.DispatcherDefinition = exports.ReleaseSlotResponse = exports.ReleaseSlotRequest = exports.RefreshTimeoutResponse = exports.RefreshTimeoutRequest = exports.HeartbeatResponse = exports.HeartbeatRequest = exports.OverridesDataResponse = exports.OverridesData = exports.StepRunResult = exports.WorkflowRunEvent = exports.WorkflowEvent = exports.SubscribeToWorkflowRunsRequest = exports.SubscribeToWorkflowEventsRequest = exports.ActionEventResponse = exports.StepActionEvent = exports.GroupKeyActionEvent = exports.WorkerUnsubscribeResponse = exports.WorkerUnsubscribeRequest = exports.WorkerListenRequest = exports.AssignedAction = exports.WorkerRegisterResponse = exports.WorkerRegisterRequest = exports.workflowRunEventTypeToJSON = exports.workflowRunEventTypeFromJSON = exports.WorkflowRunEventType = exports.resourceEventTypeToJSON = exports.resourceEventTypeFromJSON = exports.ResourceEventType = exports.resourceTypeToJSON = exports.resourceTypeFromJSON = exports.ResourceType = exports.stepActionEventTypeToJSON = exports.stepActionEventTypeFromJSON = exports.StepActionEventType = exports.groupKeyActionEventTypeToJSON = exports.groupKeyActionEventTypeFromJSON = exports.GroupKeyActionEventType = exports.actionTypeToJSON = exports.actionTypeFromJSON = exports.ActionType = exports.protobufPackage = void 0;
27
27
  const _m0 = __importStar(require("protobufjs/minimal"));
28
28
  const timestamp_1 = require("../google/protobuf/timestamp");
29
29
  exports.protobufPackage = '';
@@ -1978,6 +1978,214 @@ exports.HeartbeatResponse = {
1978
1978
  return message;
1979
1979
  },
1980
1980
  };
1981
+ function createBaseRefreshTimeoutRequest() {
1982
+ return { stepRunId: '', incrementTimeoutBy: '' };
1983
+ }
1984
+ exports.RefreshTimeoutRequest = {
1985
+ encode(message, writer = _m0.Writer.create()) {
1986
+ if (message.stepRunId !== '') {
1987
+ writer.uint32(10).string(message.stepRunId);
1988
+ }
1989
+ if (message.incrementTimeoutBy !== '') {
1990
+ writer.uint32(18).string(message.incrementTimeoutBy);
1991
+ }
1992
+ return writer;
1993
+ },
1994
+ decode(input, length) {
1995
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
1996
+ let end = length === undefined ? reader.len : reader.pos + length;
1997
+ const message = createBaseRefreshTimeoutRequest();
1998
+ while (reader.pos < end) {
1999
+ const tag = reader.uint32();
2000
+ switch (tag >>> 3) {
2001
+ case 1:
2002
+ if (tag !== 10) {
2003
+ break;
2004
+ }
2005
+ message.stepRunId = reader.string();
2006
+ continue;
2007
+ case 2:
2008
+ if (tag !== 18) {
2009
+ break;
2010
+ }
2011
+ message.incrementTimeoutBy = reader.string();
2012
+ continue;
2013
+ }
2014
+ if ((tag & 7) === 4 || tag === 0) {
2015
+ break;
2016
+ }
2017
+ reader.skipType(tag & 7);
2018
+ }
2019
+ return message;
2020
+ },
2021
+ fromJSON(object) {
2022
+ return {
2023
+ stepRunId: isSet(object.stepRunId) ? globalThis.String(object.stepRunId) : '',
2024
+ incrementTimeoutBy: isSet(object.incrementTimeoutBy)
2025
+ ? globalThis.String(object.incrementTimeoutBy)
2026
+ : '',
2027
+ };
2028
+ },
2029
+ toJSON(message) {
2030
+ const obj = {};
2031
+ if (message.stepRunId !== '') {
2032
+ obj.stepRunId = message.stepRunId;
2033
+ }
2034
+ if (message.incrementTimeoutBy !== '') {
2035
+ obj.incrementTimeoutBy = message.incrementTimeoutBy;
2036
+ }
2037
+ return obj;
2038
+ },
2039
+ create(base) {
2040
+ return exports.RefreshTimeoutRequest.fromPartial(base !== null && base !== void 0 ? base : {});
2041
+ },
2042
+ fromPartial(object) {
2043
+ var _a, _b;
2044
+ const message = createBaseRefreshTimeoutRequest();
2045
+ message.stepRunId = (_a = object.stepRunId) !== null && _a !== void 0 ? _a : '';
2046
+ message.incrementTimeoutBy = (_b = object.incrementTimeoutBy) !== null && _b !== void 0 ? _b : '';
2047
+ return message;
2048
+ },
2049
+ };
2050
+ function createBaseRefreshTimeoutResponse() {
2051
+ return { timeoutAt: undefined };
2052
+ }
2053
+ exports.RefreshTimeoutResponse = {
2054
+ encode(message, writer = _m0.Writer.create()) {
2055
+ if (message.timeoutAt !== undefined) {
2056
+ timestamp_1.Timestamp.encode(toTimestamp(message.timeoutAt), writer.uint32(10).fork()).ldelim();
2057
+ }
2058
+ return writer;
2059
+ },
2060
+ decode(input, length) {
2061
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
2062
+ let end = length === undefined ? reader.len : reader.pos + length;
2063
+ const message = createBaseRefreshTimeoutResponse();
2064
+ while (reader.pos < end) {
2065
+ const tag = reader.uint32();
2066
+ switch (tag >>> 3) {
2067
+ case 1:
2068
+ if (tag !== 10) {
2069
+ break;
2070
+ }
2071
+ message.timeoutAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
2072
+ continue;
2073
+ }
2074
+ if ((tag & 7) === 4 || tag === 0) {
2075
+ break;
2076
+ }
2077
+ reader.skipType(tag & 7);
2078
+ }
2079
+ return message;
2080
+ },
2081
+ fromJSON(object) {
2082
+ return { timeoutAt: isSet(object.timeoutAt) ? fromJsonTimestamp(object.timeoutAt) : undefined };
2083
+ },
2084
+ toJSON(message) {
2085
+ const obj = {};
2086
+ if (message.timeoutAt !== undefined) {
2087
+ obj.timeoutAt = message.timeoutAt.toISOString();
2088
+ }
2089
+ return obj;
2090
+ },
2091
+ create(base) {
2092
+ return exports.RefreshTimeoutResponse.fromPartial(base !== null && base !== void 0 ? base : {});
2093
+ },
2094
+ fromPartial(object) {
2095
+ var _a;
2096
+ const message = createBaseRefreshTimeoutResponse();
2097
+ message.timeoutAt = (_a = object.timeoutAt) !== null && _a !== void 0 ? _a : undefined;
2098
+ return message;
2099
+ },
2100
+ };
2101
+ function createBaseReleaseSlotRequest() {
2102
+ return { stepRunId: '' };
2103
+ }
2104
+ exports.ReleaseSlotRequest = {
2105
+ encode(message, writer = _m0.Writer.create()) {
2106
+ if (message.stepRunId !== '') {
2107
+ writer.uint32(10).string(message.stepRunId);
2108
+ }
2109
+ return writer;
2110
+ },
2111
+ decode(input, length) {
2112
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
2113
+ let end = length === undefined ? reader.len : reader.pos + length;
2114
+ const message = createBaseReleaseSlotRequest();
2115
+ while (reader.pos < end) {
2116
+ const tag = reader.uint32();
2117
+ switch (tag >>> 3) {
2118
+ case 1:
2119
+ if (tag !== 10) {
2120
+ break;
2121
+ }
2122
+ message.stepRunId = reader.string();
2123
+ continue;
2124
+ }
2125
+ if ((tag & 7) === 4 || tag === 0) {
2126
+ break;
2127
+ }
2128
+ reader.skipType(tag & 7);
2129
+ }
2130
+ return message;
2131
+ },
2132
+ fromJSON(object) {
2133
+ return { stepRunId: isSet(object.stepRunId) ? globalThis.String(object.stepRunId) : '' };
2134
+ },
2135
+ toJSON(message) {
2136
+ const obj = {};
2137
+ if (message.stepRunId !== '') {
2138
+ obj.stepRunId = message.stepRunId;
2139
+ }
2140
+ return obj;
2141
+ },
2142
+ create(base) {
2143
+ return exports.ReleaseSlotRequest.fromPartial(base !== null && base !== void 0 ? base : {});
2144
+ },
2145
+ fromPartial(object) {
2146
+ var _a;
2147
+ const message = createBaseReleaseSlotRequest();
2148
+ message.stepRunId = (_a = object.stepRunId) !== null && _a !== void 0 ? _a : '';
2149
+ return message;
2150
+ },
2151
+ };
2152
+ function createBaseReleaseSlotResponse() {
2153
+ return {};
2154
+ }
2155
+ exports.ReleaseSlotResponse = {
2156
+ encode(_, writer = _m0.Writer.create()) {
2157
+ return writer;
2158
+ },
2159
+ decode(input, length) {
2160
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
2161
+ let end = length === undefined ? reader.len : reader.pos + length;
2162
+ const message = createBaseReleaseSlotResponse();
2163
+ while (reader.pos < end) {
2164
+ const tag = reader.uint32();
2165
+ switch (tag >>> 3) {
2166
+ }
2167
+ if ((tag & 7) === 4 || tag === 0) {
2168
+ break;
2169
+ }
2170
+ reader.skipType(tag & 7);
2171
+ }
2172
+ return message;
2173
+ },
2174
+ fromJSON(_) {
2175
+ return {};
2176
+ },
2177
+ toJSON(_) {
2178
+ const obj = {};
2179
+ return obj;
2180
+ },
2181
+ create(base) {
2182
+ return exports.ReleaseSlotResponse.fromPartial(base !== null && base !== void 0 ? base : {});
2183
+ },
2184
+ fromPartial(_) {
2185
+ const message = createBaseReleaseSlotResponse();
2186
+ return message;
2187
+ },
2188
+ };
1981
2189
  exports.DispatcherDefinition = {
1982
2190
  name: 'Dispatcher',
1983
2191
  fullName: 'Dispatcher',
@@ -2067,6 +2275,22 @@ exports.DispatcherDefinition = {
2067
2275
  responseStream: false,
2068
2276
  options: {},
2069
2277
  },
2278
+ refreshTimeout: {
2279
+ name: 'RefreshTimeout',
2280
+ requestType: exports.RefreshTimeoutRequest,
2281
+ requestStream: false,
2282
+ responseType: exports.RefreshTimeoutResponse,
2283
+ responseStream: false,
2284
+ options: {},
2285
+ },
2286
+ releaseSlot: {
2287
+ name: 'ReleaseSlot',
2288
+ requestType: exports.ReleaseSlotRequest,
2289
+ requestStream: false,
2290
+ responseType: exports.ReleaseSlotResponse,
2291
+ responseStream: false,
2292
+ options: {},
2293
+ },
2070
2294
  },
2071
2295
  };
2072
2296
  function toTimestamp(date) {
package/step.d.ts CHANGED
@@ -31,8 +31,8 @@ export declare const CreateStepSchema: z.ZodObject<{
31
31
  }>, "many">>;
32
32
  }, "strip", z.ZodTypeAny, {
33
33
  name: string;
34
- parents?: string[] | undefined;
35
34
  timeout?: string | undefined;
35
+ parents?: string[] | undefined;
36
36
  retries?: number | undefined;
37
37
  rate_limits?: {
38
38
  key: string;
@@ -40,8 +40,8 @@ export declare const CreateStepSchema: z.ZodObject<{
40
40
  }[] | undefined;
41
41
  }, {
42
42
  name: string;
43
- parents?: string[] | undefined;
44
43
  timeout?: string | undefined;
44
+ parents?: string[] | undefined;
45
45
  retries?: number | undefined;
46
46
  rate_limits?: {
47
47
  key: string;
@@ -86,6 +86,14 @@ export declare class Context<T, K> {
86
86
  workflowRunId(): string;
87
87
  playground(name: string, defaultValue?: string): string;
88
88
  log(message: string, level?: LogLevel): void;
89
+ /**
90
+ * Refreshes the timeout for the current step.
91
+ * @param incrementBy - The interval by which to increment the timeout.
92
+ * The interval should be specified in the format of '10s' for 10 seconds,
93
+ * '1m' for 1 minute, or '1d' for 1 day.
94
+ */
95
+ refreshTimeout(incrementBy: string): Promise<void>;
96
+ releaseSlot(): Promise<void>;
89
97
  putStream(data: string | Uint8Array): Promise<void>;
90
98
  spawnWorkflow<P = unknown, Q = unknown>(workflowName: string, input: Q, key?: string): ChildWorkflowRef<P>;
91
99
  }
package/step.js CHANGED
@@ -188,6 +188,30 @@ class Context {
188
188
  }
189
189
  this.client.event.putLog(stepRunId, message, level);
190
190
  }
191
+ /**
192
+ * Refreshes the timeout for the current step.
193
+ * @param incrementBy - The interval by which to increment the timeout.
194
+ * The interval should be specified in the format of '10s' for 10 seconds,
195
+ * '1m' for 1 minute, or '1d' for 1 day.
196
+ */
197
+ refreshTimeout(incrementBy) {
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ const { stepRunId } = this.action;
200
+ if (!stepRunId) {
201
+ // log a warning
202
+ this.logger.warn('cannot refresh timeout from context without stepRunId');
203
+ return;
204
+ }
205
+ yield this.client.dispatcher.refreshTimeout(incrementBy, stepRunId);
206
+ });
207
+ }
208
+ releaseSlot() {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ yield this.client.dispatcher.client.releaseSlot({
211
+ stepRunId: this.action.stepRunId,
212
+ });
213
+ });
214
+ }
191
215
  putStream(data) {
192
216
  return __awaiter(this, void 0, void 0, function* () {
193
217
  const { stepRunId } = this.action;
package/util/retrier.js CHANGED
@@ -16,8 +16,8 @@ exports.retrier = void 0;
16
16
  const sleep_1 = __importDefault(require("./sleep"));
17
17
  const DEFAULT_RETRY_INTERVAL = 5; // seconds
18
18
  const DEFAULT_RETRY_COUNT = 5;
19
- function retrier(fn, logger, retries = DEFAULT_RETRY_COUNT, interval = DEFAULT_RETRY_INTERVAL) {
20
- return __awaiter(this, void 0, void 0, function* () {
19
+ function retrier(fn_1, logger_1) {
20
+ return __awaiter(this, arguments, void 0, function* (fn, logger, retries = DEFAULT_RETRY_COUNT, interval = DEFAULT_RETRY_INTERVAL) {
21
21
  let lastError;
22
22
  // eslint-disable-next-line no-plusplus
23
23
  for (let i = 0; i < retries; i++) {
package/workflow.d.ts CHANGED
@@ -18,8 +18,8 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
18
18
  }>, "many">>;
19
19
  }, "strip", z.ZodTypeAny, {
20
20
  name: string;
21
- parents?: string[] | undefined;
22
21
  timeout?: string | undefined;
22
+ parents?: string[] | undefined;
23
23
  retries?: number | undefined;
24
24
  rate_limits?: {
25
25
  key: string;
@@ -27,8 +27,8 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
27
27
  }[] | undefined;
28
28
  }, {
29
29
  name: string;
30
- parents?: string[] | undefined;
31
30
  timeout?: string | undefined;
31
+ parents?: string[] | undefined;
32
32
  retries?: number | undefined;
33
33
  rate_limits?: {
34
34
  key: string;
@@ -96,8 +96,8 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
96
96
  }>, "many">>;
97
97
  }, "strip", z.ZodTypeAny, {
98
98
  name: string;
99
- parents?: string[] | undefined;
100
99
  timeout?: string | undefined;
100
+ parents?: string[] | undefined;
101
101
  retries?: number | undefined;
102
102
  rate_limits?: {
103
103
  key: string;
@@ -105,8 +105,8 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
105
105
  }[] | undefined;
106
106
  }, {
107
107
  name: string;
108
- parents?: string[] | undefined;
109
108
  timeout?: string | undefined;
109
+ parents?: string[] | undefined;
110
110
  retries?: number | undefined;
111
111
  rate_limits?: {
112
112
  key: string;
@@ -130,8 +130,8 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
130
130
  }>, "many">>;
131
131
  }, "strip", z.ZodTypeAny, {
132
132
  name: string;
133
- parents?: string[] | undefined;
134
133
  timeout?: string | undefined;
134
+ parents?: string[] | undefined;
135
135
  retries?: number | undefined;
136
136
  rate_limits?: {
137
137
  key: string;
@@ -139,8 +139,8 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
139
139
  }[] | undefined;
140
140
  }, {
141
141
  name: string;
142
- parents?: string[] | undefined;
143
142
  timeout?: string | undefined;
143
+ parents?: string[] | undefined;
144
144
  retries?: number | undefined;
145
145
  rate_limits?: {
146
146
  key: string;
@@ -151,8 +151,8 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
151
151
  description: string;
152
152
  steps: {
153
153
  name: string;
154
- parents?: string[] | undefined;
155
154
  timeout?: string | undefined;
155
+ parents?: string[] | undefined;
156
156
  retries?: number | undefined;
157
157
  rate_limits?: {
158
158
  key: string;
@@ -172,8 +172,8 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
172
172
  timeout?: string | undefined;
173
173
  onFailure?: {
174
174
  name: string;
175
- parents?: string[] | undefined;
176
175
  timeout?: string | undefined;
176
+ parents?: string[] | undefined;
177
177
  retries?: number | undefined;
178
178
  rate_limits?: {
179
179
  key: string;
@@ -184,8 +184,8 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
184
184
  description: string;
185
185
  steps: {
186
186
  name: string;
187
- parents?: string[] | undefined;
188
187
  timeout?: string | undefined;
188
+ parents?: string[] | undefined;
189
189
  retries?: number | undefined;
190
190
  rate_limits?: {
191
191
  key: string;
@@ -205,8 +205,8 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
205
205
  timeout?: string | undefined;
206
206
  onFailure?: {
207
207
  name: string;
208
- parents?: string[] | undefined;
209
208
  timeout?: string | undefined;
209
+ parents?: string[] | undefined;
210
210
  retries?: number | undefined;
211
211
  rate_limits?: {
212
212
  key: string;