spool-sdk 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/README.md +149 -2
- package/dist/backoff.d.ts +15 -0
- package/dist/backoff.js +51 -0
- package/dist/backoff.js.map +1 -0
- package/dist/channel.d.ts +13 -0
- package/dist/channel.js +46 -0
- package/dist/channel.js.map +1 -0
- package/dist/context.d.ts +221 -0
- package/dist/context.js +331 -0
- package/dist/context.js.map +1 -0
- package/dist/duration.d.ts +22 -0
- package/dist/duration.js +39 -0
- package/dist/duration.js.map +1 -0
- package/dist/errors.d.ts +115 -0
- package/dist/errors.js +143 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +8 -0
- package/dist/json.js +24 -0
- package/dist/json.js.map +1 -0
- package/dist/logger.d.ts +9 -0
- package/dist/logger.js +12 -0
- package/dist/logger.js.map +1 -0
- package/dist/proto/workers_pb.d.ts +900 -0
- package/dist/proto/workers_pb.js +168 -0
- package/dist/worker.d.ts +51 -0
- package/dist/worker.js +543 -0
- package/dist/worker.js.map +1 -0
- package/dist/workflow.d.ts +13 -0
- package/dist/workflow.js +10 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +49 -3
- package/src/backoff.ts +66 -0
- package/src/channel.ts +45 -0
- package/src/context.ts +604 -0
- package/src/duration.ts +50 -0
- package/src/errors.ts +164 -0
- package/src/index.ts +26 -0
- package/src/json.ts +23 -0
- package/src/logger.ts +19 -0
- package/src/worker.ts +658 -0
- package/src/workflow.ts +20 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// @generated by protoc-gen-es v2.17.0 with parameter "target=js+dts,import_extension=js"
|
|
2
|
+
// @generated from file spool/v1/workers.proto (package spool.v1, syntax proto3)
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
|
|
5
|
+
import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2";
|
|
6
|
+
import { file_google_protobuf_struct } from "@bufbuild/protobuf/wkt";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Describes the file spool/v1/workers.proto.
|
|
10
|
+
*/
|
|
11
|
+
export const file_spool_v1_workers = /*@__PURE__*/
|
|
12
|
+
fileDesc("ChZzcG9vbC92MS93b3JrZXJzLnByb3RvEghzcG9vbC52MSKsAwoOQ29ubmVjdFJlcXVlc3QSIAoFaGVsbG8YASABKAsyDy5zcG9vbC52MS5IZWxsb0gAEh4KBHB1bGwYAiABKAsyDi5zcG9vbC52MS5QdWxsSAASJAoEc3RlcBgDIAEoCzIULnNwb29sLnYxLlN0ZXBSZXBvcnRIABIqCgpjb21wbGV0aW9uGAQgASgLMhQuc3Bvb2wudjEuQ29tcGxldGlvbkgAEigKCWhlYXJ0YmVhdBgFIAEoCzITLnNwb29sLnYxLkhlYXJ0YmVhdEgAEi0KDHN0ZXBfZmFpbHVyZRgGIAEoCzIVLnNwb29sLnYxLlN0ZXBGYWlsdXJlSAASIAoFc2xlZXAYByABKAsyDy5zcG9vbC52MS5TbGVlcEgAEjAKDndhaXRfZm9yX2V2ZW50GAggASgLMhYuc3Bvb2wudjEuV2FpdEZvckV2ZW50SAASJgoIdGhyb3R0bGUYCSABKAsyEi5zcG9vbC52MS5UaHJvdHRsZUgAEikKCmxsbV90b2tlbnMYCiABKAsyEy5zcG9vbC52MS5MbG1Ub2tlbnNIAEIGCgRraW5kIkgKCUxsbVRva2VucxIPCgd0YXNrX2lkGAEgASgDEg8KB2F0dGVtcHQYAiABKAUSCwoDc2VxGAMgASgFEgwKBHRleHQYBCABKAkiWQoFSGVsbG8SEQoJd29ya2VyX2lkGAEgASgJEhEKCXdvcmtmbG93cxgCIAMoCRISCgVxdWV1ZRgDIAEoCUgAiAEBEgwKBHB1bGwYBCABKAVCCAoGX3F1ZXVlIhUKBFB1bGwSDQoFY291bnQYASABKAUiyAEKCl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cm5hbEVudHJ5EgsKA3NlcRgBIAEoBRIMCgRuYW1lGAIgASgJEiYKBm91dHB1dBgDIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZSI8CgNBY2sSEgoKcmVxdWVzdF9pZBgBIAEoBBIQCghyZWNvcmRlZBgCIAEoCBIPCgd3YWl0X21zGAMgASgDIk8KB0ZhaWx1cmUSEgoKcmVxdWVzdF9pZBgBIAEoBBIMCgRjb2RlGAIgASgJEg8KB21lc3NhZ2UYAyABKAkSEQoJcmV0cnlhYmxlGAQgASgIIkQKDEhlYXJ0YmVhdEFjaxISCgpyZXF1ZXN0X2lkGAEgASgEEiAKBGxvc3QYAiADKAsyEi5zcG9vbC52MS5MZWFzZVJlZjJVCg1Xb3JrZXJTZXJ2aWNlEkQKB0Nvbm5lY3QSGC5zcG9vbC52MS5Db25uZWN0UmVxdWVzdBoZLnNwb29sLnYxLkNvbm5lY3RSZXNwb25zZSIAKAEwAWIGcHJvdG8z", [file_google_protobuf_struct]);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Describes the message spool.v1.ConnectRequest.
|
|
16
|
+
* Use `create(ConnectRequestSchema)` to create a new message.
|
|
17
|
+
*/
|
|
18
|
+
export const ConnectRequestSchema = /*@__PURE__*/
|
|
19
|
+
messageDesc(file_spool_v1_workers, 0);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Describes the message spool.v1.LlmTokens.
|
|
23
|
+
* Use `create(LlmTokensSchema)` to create a new message.
|
|
24
|
+
*/
|
|
25
|
+
export const LlmTokensSchema = /*@__PURE__*/
|
|
26
|
+
messageDesc(file_spool_v1_workers, 1);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Describes the message spool.v1.Hello.
|
|
30
|
+
* Use `create(HelloSchema)` to create a new message.
|
|
31
|
+
*/
|
|
32
|
+
export const HelloSchema = /*@__PURE__*/
|
|
33
|
+
messageDesc(file_spool_v1_workers, 2);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Describes the message spool.v1.Pull.
|
|
37
|
+
* Use `create(PullSchema)` to create a new message.
|
|
38
|
+
*/
|
|
39
|
+
export const PullSchema = /*@__PURE__*/
|
|
40
|
+
messageDesc(file_spool_v1_workers, 3);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Describes the message spool.v1.StepReport.
|
|
44
|
+
* Use `create(StepReportSchema)` to create a new message.
|
|
45
|
+
*/
|
|
46
|
+
export const StepReportSchema = /*@__PURE__*/
|
|
47
|
+
messageDesc(file_spool_v1_workers, 4);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Describes the message spool.v1.LlmUsage.
|
|
51
|
+
* Use `create(LlmUsageSchema)` to create a new message.
|
|
52
|
+
*/
|
|
53
|
+
export const LlmUsageSchema = /*@__PURE__*/
|
|
54
|
+
messageDesc(file_spool_v1_workers, 5);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Describes the message spool.v1.StepFailure.
|
|
58
|
+
* Use `create(StepFailureSchema)` to create a new message.
|
|
59
|
+
*/
|
|
60
|
+
export const StepFailureSchema = /*@__PURE__*/
|
|
61
|
+
messageDesc(file_spool_v1_workers, 6);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Describes the message spool.v1.Sleep.
|
|
65
|
+
* Use `create(SleepSchema)` to create a new message.
|
|
66
|
+
*/
|
|
67
|
+
export const SleepSchema = /*@__PURE__*/
|
|
68
|
+
messageDesc(file_spool_v1_workers, 7);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Describes the message spool.v1.WaitForEvent.
|
|
72
|
+
* Use `create(WaitForEventSchema)` to create a new message.
|
|
73
|
+
*/
|
|
74
|
+
export const WaitForEventSchema = /*@__PURE__*/
|
|
75
|
+
messageDesc(file_spool_v1_workers, 8);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Describes the message spool.v1.Throttle.
|
|
79
|
+
* Use `create(ThrottleSchema)` to create a new message.
|
|
80
|
+
*/
|
|
81
|
+
export const ThrottleSchema = /*@__PURE__*/
|
|
82
|
+
messageDesc(file_spool_v1_workers, 9);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Describes the message spool.v1.StepError.
|
|
86
|
+
* Use `create(StepErrorSchema)` to create a new message.
|
|
87
|
+
*/
|
|
88
|
+
export const StepErrorSchema = /*@__PURE__*/
|
|
89
|
+
messageDesc(file_spool_v1_workers, 10);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Describes the message spool.v1.Completion.
|
|
93
|
+
* Use `create(CompletionSchema)` to create a new message.
|
|
94
|
+
*/
|
|
95
|
+
export const CompletionSchema = /*@__PURE__*/
|
|
96
|
+
messageDesc(file_spool_v1_workers, 11);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Describes the message spool.v1.Heartbeat.
|
|
100
|
+
* Use `create(HeartbeatSchema)` to create a new message.
|
|
101
|
+
*/
|
|
102
|
+
export const HeartbeatSchema = /*@__PURE__*/
|
|
103
|
+
messageDesc(file_spool_v1_workers, 12);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Describes the message spool.v1.LeaseRef.
|
|
107
|
+
* Use `create(LeaseRefSchema)` to create a new message.
|
|
108
|
+
*/
|
|
109
|
+
export const LeaseRefSchema = /*@__PURE__*/
|
|
110
|
+
messageDesc(file_spool_v1_workers, 13);
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Describes the message spool.v1.ConnectResponse.
|
|
114
|
+
* Use `create(ConnectResponseSchema)` to create a new message.
|
|
115
|
+
*/
|
|
116
|
+
export const ConnectResponseSchema = /*@__PURE__*/
|
|
117
|
+
messageDesc(file_spool_v1_workers, 14);
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Describes the message spool.v1.Ready.
|
|
121
|
+
* Use `create(ReadySchema)` to create a new message.
|
|
122
|
+
*/
|
|
123
|
+
export const ReadySchema = /*@__PURE__*/
|
|
124
|
+
messageDesc(file_spool_v1_workers, 15);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Describes the message spool.v1.ClaimedTask.
|
|
128
|
+
* Use `create(ClaimedTaskSchema)` to create a new message.
|
|
129
|
+
*/
|
|
130
|
+
export const ClaimedTaskSchema = /*@__PURE__*/
|
|
131
|
+
messageDesc(file_spool_v1_workers, 16);
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Describes the message spool.v1.JournalEntry.
|
|
135
|
+
* Use `create(JournalEntrySchema)` to create a new message.
|
|
136
|
+
*/
|
|
137
|
+
export const JournalEntrySchema = /*@__PURE__*/
|
|
138
|
+
messageDesc(file_spool_v1_workers, 17);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Describes the message spool.v1.Ack.
|
|
142
|
+
* Use `create(AckSchema)` to create a new message.
|
|
143
|
+
*/
|
|
144
|
+
export const AckSchema = /*@__PURE__*/
|
|
145
|
+
messageDesc(file_spool_v1_workers, 18);
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Describes the message spool.v1.Failure.
|
|
149
|
+
* Use `create(FailureSchema)` to create a new message.
|
|
150
|
+
*/
|
|
151
|
+
export const FailureSchema = /*@__PURE__*/
|
|
152
|
+
messageDesc(file_spool_v1_workers, 19);
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Describes the message spool.v1.HeartbeatAck.
|
|
156
|
+
* Use `create(HeartbeatAckSchema)` to create a new message.
|
|
157
|
+
*/
|
|
158
|
+
export const HeartbeatAckSchema = /*@__PURE__*/
|
|
159
|
+
messageDesc(file_spool_v1_workers, 20);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The worker protocol: one long-lived bidirectional stream per worker process.
|
|
163
|
+
*
|
|
164
|
+
* @generated from service spool.v1.WorkerService
|
|
165
|
+
*/
|
|
166
|
+
export const WorkerService = /*@__PURE__*/
|
|
167
|
+
serviceDesc(file_spool_v1_workers, 0);
|
|
168
|
+
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type Transport } from "@connectrpc/connect";
|
|
2
|
+
import { type BackoffPolicy } from "./backoff.js";
|
|
3
|
+
import { type Logger } from "./logger.js";
|
|
4
|
+
import type { Workflow } from "./workflow.js";
|
|
5
|
+
interface WorkerSettings {
|
|
6
|
+
/** The workflows this worker runs. Names must be unique. */
|
|
7
|
+
readonly workflows: readonly Workflow<never>[];
|
|
8
|
+
/** Runs at once; the engine never sends more. Default 10. */
|
|
9
|
+
readonly concurrency?: number;
|
|
10
|
+
/** Default "default". */
|
|
11
|
+
readonly queue?: string;
|
|
12
|
+
/** Who holds the leases; stable across reconnects. Default: host, pid and a random suffix. */
|
|
13
|
+
readonly workerId?: string;
|
|
14
|
+
readonly logger?: Logger;
|
|
15
|
+
/** Delays between reconnects and between resends of a request. */
|
|
16
|
+
readonly backoff?: Partial<BackoffPolicy>;
|
|
17
|
+
/** How long stop() lets running runs finish before abandoning them. Default 30 s. */
|
|
18
|
+
readonly drainTimeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
export type WorkerOptions = WorkerSettings & ({
|
|
21
|
+
readonly url: string;
|
|
22
|
+
readonly apiKey: string;
|
|
23
|
+
}
|
|
24
|
+
/** A ready-made transport, for custom TLS, interceptors or tests. Needs HTTP/2. */
|
|
25
|
+
| {
|
|
26
|
+
readonly transport: Transport;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Runs workflows for the engine. It keeps one stream open, reconnecting with backoff when
|
|
30
|
+
* it drops, and pulls as many tasks as it has free slots. Each task runs its workflow
|
|
31
|
+
* from the top, with recorded steps answered from the journal. Heartbeats renew the leases
|
|
32
|
+
* of running runs; a run whose lease is lost is stopped before its next step.
|
|
33
|
+
*
|
|
34
|
+
* Execution is at least once: a step whose report never reached the engine runs again on
|
|
35
|
+
* the next attempt. Give side effects an idempotency key.
|
|
36
|
+
*/
|
|
37
|
+
export declare class Worker {
|
|
38
|
+
#private;
|
|
39
|
+
readonly workerId: string;
|
|
40
|
+
constructor(options: WorkerOptions);
|
|
41
|
+
/** Connects and starts taking work. Returns at once; the worker runs until stop(). */
|
|
42
|
+
start(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Stops taking work, lets running runs finish (up to drainTimeoutMs, after which they are
|
|
45
|
+
* abandoned and their leases expire), then closes the stream.
|
|
46
|
+
*/
|
|
47
|
+
stop(): Promise<void>;
|
|
48
|
+
/** Runs currently in progress, for monitoring. */
|
|
49
|
+
get activeRuns(): number;
|
|
50
|
+
}
|
|
51
|
+
export {};
|