@helmr/sdk 0.1.0-preview.g008b1d21.b36234405630

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.
Files changed (48) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +65 -0
  3. package/dist/actor.d.ts +3 -0
  4. package/dist/builder.d.ts +18 -0
  5. package/dist/client-actor.d.ts +32 -0
  6. package/dist/client-deployment.d.ts +30 -0
  7. package/dist/client-sandbox.d.ts +26 -0
  8. package/dist/client-schedule.d.ts +44 -0
  9. package/dist/client-secret.d.ts +51 -0
  10. package/dist/client-session.d.ts +29 -0
  11. package/dist/client-workspace.d.ts +36 -0
  12. package/dist/client.d.ts +164 -0
  13. package/dist/config.d.ts +24 -0
  14. package/dist/contract.d.ts +408 -0
  15. package/dist/definitions.d.ts +42 -0
  16. package/dist/fuzzy.d.ts +1 -0
  17. package/dist/fuzzy.js +29 -0
  18. package/dist/image.d.ts +63 -0
  19. package/dist/index.d.ts +31 -0
  20. package/dist/index.js +3326 -0
  21. package/dist/internal/abort.d.ts +1 -0
  22. package/dist/internal/definition-query.d.ts +10 -0
  23. package/dist/internal/id.d.ts +1 -0
  24. package/dist/internal/jsoncanon.d.ts +5 -0
  25. package/dist/internal/origin.d.ts +1 -0
  26. package/dist/internal/program.d.ts +10 -0
  27. package/dist/internal/run-failure.d.ts +2 -0
  28. package/dist/internal/run-handle.d.ts +3 -0
  29. package/dist/internal/runtime.d.ts +47 -0
  30. package/dist/internal/session.d.ts +14 -0
  31. package/dist/internal/strings.d.ts +1 -0
  32. package/dist/internal/timestamp.d.ts +1 -0
  33. package/dist/internal/utf8.d.ts +3 -0
  34. package/dist/internal.d.ts +15 -0
  35. package/dist/internal.js +1292 -0
  36. package/dist/logger.d.ts +9 -0
  37. package/dist/metadata.d.ts +6 -0
  38. package/dist/request.d.ts +3 -0
  39. package/dist/schedules.d.ts +33 -0
  40. package/dist/schema/payload.d.ts +39 -0
  41. package/dist/schema/task.d.ts +3 -0
  42. package/dist/secret.d.ts +1 -0
  43. package/dist/session.d.ts +14 -0
  44. package/dist/task.d.ts +2 -0
  45. package/dist/timers.d.ts +6 -0
  46. package/dist/tokens.d.ts +78 -0
  47. package/dist/workspace.d.ts +142 -0
  48. package/package.json +49 -0
@@ -0,0 +1,164 @@
1
+ import type { CursorPage, JsonValue, RunHandle, Run, RunStatus, Task, TaskInput, TaskOutput, RunOptions, TaskWait } from "./contract.js";
2
+ import type { TokenCreateRequest, TokenCreateResult, TokenListItem, TokenListQuery, Token } from "./tokens.js";
3
+ import type { WorkspaceRef } from "./workspace.js";
4
+ import { type ClientWorkspacesApi } from "./client-workspace.js";
5
+ import { type ClientSandboxesApi } from "./client-sandbox.js";
6
+ import { type ClientActorsApi } from "./client-actor.js";
7
+ import { type ClientSessionsApi } from "./client-session.js";
8
+ import { type ClientDeploymentsApi } from "./client-deployment.js";
9
+ import { type ClientSchedulesApi } from "./client-schedule.js";
10
+ import { type ClientSecretsApi } from "./client-secret.js";
11
+ import type { RequestOptions } from "./request.js";
12
+ import type { LogAttributes, RunLogLevel } from "./logger.js";
13
+ export interface HelmrClientOptions {
14
+ readonly url?: string;
15
+ readonly apiKey: string;
16
+ readonly fetch?: typeof fetch;
17
+ }
18
+ export interface TokenCompleteRequest {
19
+ readonly result: JsonValue;
20
+ readonly idempotencyKey?: string;
21
+ }
22
+ export interface TokenCancelRequest {
23
+ readonly idempotencyKey?: string;
24
+ }
25
+ export interface ClientTokensApi {
26
+ create(request?: TokenCreateRequest, options?: RequestOptions): Promise<TokenCreateResult>;
27
+ retrieve(id: string, options?: RequestOptions): Promise<Token>;
28
+ list(query?: TokenListQuery, options?: RequestOptions): Promise<CursorPage<TokenListItem>>;
29
+ complete(id: string, request: TokenCompleteRequest, options?: RequestOptions): Promise<Token>;
30
+ cancel(id: string, request?: TokenCancelRequest, options?: RequestOptions): Promise<Token>;
31
+ }
32
+ type ClientTaskRunRequest = RunOptions & Readonly<{
33
+ idempotencyKey?: string;
34
+ workspace: WorkspaceRef;
35
+ }>;
36
+ export type TaskStartRequest<TTask extends Task> = [
37
+ TaskInput<TTask>
38
+ ] extends [never] ? ClientTaskRunRequest & Readonly<{
39
+ payload?: never;
40
+ }> : ClientTaskRunRequest & Readonly<{
41
+ payload: TaskInput<TTask>;
42
+ }>;
43
+ export interface ClientTasksApi {
44
+ retrieve(id: string, query?: TaskRetrieveQuery, options?: RequestOptions): Promise<TaskInfo>;
45
+ list(query?: TaskListQuery, options?: RequestOptions): Promise<TaskPage>;
46
+ start<TTask extends Task>(taskId: TTask["id"], request: TaskStartRequest<TTask>, options?: RequestOptions): Promise<RunHandle<TaskOutput<TTask>>>;
47
+ }
48
+ export interface TaskRetrieveQuery {
49
+ readonly deploymentId?: string;
50
+ }
51
+ export interface TaskListQuery extends TaskRetrieveQuery {
52
+ readonly cursor?: string;
53
+ readonly limit?: number;
54
+ }
55
+ export interface TaskListItem {
56
+ readonly id: string;
57
+ }
58
+ export interface TaskInfo extends TaskListItem {
59
+ readonly deploymentId: string;
60
+ }
61
+ export interface TaskPage extends CursorPage<TaskListItem> {
62
+ readonly deploymentId: string;
63
+ }
64
+ export interface RunListQuery {
65
+ readonly status?: RunStatus | readonly RunStatus[];
66
+ readonly kind?: RunEntrypointKind | readonly RunEntrypointKind[];
67
+ readonly sessionId?: string;
68
+ readonly cursor?: string;
69
+ readonly limit?: number;
70
+ }
71
+ export type RunEntrypointKind = "task" | "actor";
72
+ export interface RunListItem {
73
+ readonly id: string;
74
+ readonly status: RunStatus;
75
+ readonly entrypoint: Readonly<{
76
+ kind: RunEntrypointKind;
77
+ id: string;
78
+ }>;
79
+ readonly workspaceId: string;
80
+ readonly sessionId?: string;
81
+ readonly currentAttemptNumber: number;
82
+ readonly createdAt: string;
83
+ readonly startedAt?: string;
84
+ readonly terminalAt?: string;
85
+ }
86
+ export interface RunLogQuery {
87
+ readonly cursor?: string;
88
+ readonly limit?: number;
89
+ readonly level?: RunLogLevel | readonly RunLogLevel[];
90
+ }
91
+ export interface RunEventQuery {
92
+ readonly cursor?: string;
93
+ readonly limit?: number;
94
+ readonly severity?: RunLogLevel | readonly RunLogLevel[];
95
+ }
96
+ export interface StructuredRunLogRecord {
97
+ readonly id: string;
98
+ readonly kind: "structured";
99
+ readonly runId: string;
100
+ readonly attemptNumber: number;
101
+ readonly level: RunLogLevel;
102
+ readonly message: string;
103
+ readonly attributes: LogAttributes;
104
+ readonly at: string;
105
+ }
106
+ export interface StreamRunLogRecord {
107
+ readonly id: string;
108
+ readonly kind: "stdout" | "stderr";
109
+ readonly runId: string;
110
+ readonly attemptNumber: number;
111
+ readonly observedSequence: number;
112
+ readonly contentBase64: string;
113
+ readonly bytes: number;
114
+ readonly at: string;
115
+ }
116
+ export type RunLogRecord = StructuredRunLogRecord | StreamRunLogRecord;
117
+ export interface RunEventRecord {
118
+ readonly id: string;
119
+ readonly runId: string;
120
+ readonly attemptNumber?: number;
121
+ readonly category: string;
122
+ readonly severity: RunLogLevel;
123
+ readonly source: string;
124
+ readonly kind: string;
125
+ readonly message: string;
126
+ readonly attributes: JsonValue;
127
+ readonly occurredAt: string;
128
+ readonly at: string;
129
+ }
130
+ export interface ActorRunCancellationReceipt {
131
+ readonly id: string;
132
+ readonly runId: string;
133
+ readonly sessionId: string;
134
+ readonly holdId: string;
135
+ readonly status: "accepted";
136
+ }
137
+ export interface RunCancelRequest {
138
+ readonly idempotencyKey?: string;
139
+ }
140
+ export type RunCancellation = Run<JsonValue> | ActorRunCancellationReceipt;
141
+ export interface ClientRunsApi {
142
+ retrieve<TOutput extends JsonValue>(run: RunHandle<TOutput>, options?: RequestOptions): Promise<Run<TOutput>>;
143
+ retrieve(runId: string, options?: RequestOptions): Promise<Run<JsonValue>>;
144
+ list(query?: RunListQuery, options?: RequestOptions): Promise<CursorPage<RunListItem>>;
145
+ cancel(runId: string, request?: RunCancelRequest, options?: RequestOptions): Promise<RunCancellation>;
146
+ wait<TOutput extends JsonValue>(run: RunHandle<TOutput>, options?: RequestOptions): TaskWait<TOutput>;
147
+ wait(runId: string, options?: RequestOptions): TaskWait<JsonValue>;
148
+ logs(runId: string, query?: RunLogQuery, options?: RequestOptions): Promise<CursorPage<RunLogRecord>>;
149
+ events(runId: string, query?: RunEventQuery, options?: RequestOptions): Promise<CursorPage<RunEventRecord>>;
150
+ }
151
+ export declare class HelmrClient {
152
+ readonly tasks: ClientTasksApi;
153
+ readonly actors: ClientActorsApi;
154
+ readonly sessions: ClientSessionsApi;
155
+ readonly sandboxes: ClientSandboxesApi;
156
+ readonly deployments: ClientDeploymentsApi;
157
+ readonly schedules: ClientSchedulesApi;
158
+ readonly secrets: ClientSecretsApi;
159
+ readonly runs: ClientRunsApi;
160
+ readonly tokens: ClientTokensApi;
161
+ readonly workspaces: ClientWorkspacesApi;
162
+ constructor(options: HelmrClientOptions);
163
+ }
164
+ export {};
@@ -0,0 +1,24 @@
1
+ import { type Builder } from "./builder.js";
2
+ export interface HelmrBuildInput {
3
+ readonly builder?: Builder;
4
+ readonly installCommand?: string;
5
+ readonly secrets?: readonly string[];
6
+ }
7
+ export interface HelmrConfigInput {
8
+ readonly dirs?: readonly string[];
9
+ readonly ignorePatterns?: readonly string[];
10
+ readonly build?: HelmrBuildInput;
11
+ }
12
+ export interface HelmrBuildConfig {
13
+ readonly builder: Builder;
14
+ readonly installCommand: string | undefined;
15
+ readonly secrets: readonly string[];
16
+ }
17
+ export interface HelmrConfig {
18
+ readonly dirs: readonly string[];
19
+ readonly ignorePatterns: readonly string[];
20
+ readonly build: HelmrBuildConfig;
21
+ }
22
+ export declare function defineConfig(input: HelmrConfigInput): HelmrConfig;
23
+ export declare function inspectConfig(value: unknown): HelmrConfig;
24
+ export declare function matchesIgnorePattern(pattern: string, path: string): boolean;
@@ -0,0 +1,408 @@
1
+ import type { PayloadSchema } from "./schema/payload.js";
2
+ import type { RequestOptions } from "./request.js";
3
+ import type { WorkspaceRef } from "./workspace.js";
4
+ export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
5
+ readonly [key: string]: JsonValue;
6
+ };
7
+ export type Serializable = JsonValue;
8
+ export type Metadata = Readonly<Record<string, JsonValue>>;
9
+ export type MaybePromise<T> = T | Promise<T>;
10
+ export type { PayloadSchema };
11
+ export interface CursorPage<T> {
12
+ readonly items: readonly T[];
13
+ readonly nextCursor?: string;
14
+ }
15
+ export type Duration = string;
16
+ export type RetryPolicy = Readonly<{
17
+ enabled?: true;
18
+ maxAttempts: number;
19
+ backoff?: Readonly<{
20
+ minDelay?: Duration;
21
+ maxDelay?: Duration;
22
+ factor?: number;
23
+ jitter?: "none" | "full";
24
+ }>;
25
+ }> | Readonly<{
26
+ enabled: false;
27
+ }>;
28
+ declare const queueTypeBrand: unique symbol;
29
+ export interface QueueConfig {
30
+ readonly name: string;
31
+ readonly concurrencyLimit?: number | null;
32
+ }
33
+ export interface Queue extends QueueConfig {
34
+ readonly [queueTypeBrand]: true;
35
+ }
36
+ export interface RunOptions {
37
+ readonly queue?: string;
38
+ readonly concurrencyKey?: string;
39
+ readonly priority?: number;
40
+ readonly ttl?: Duration;
41
+ readonly retry?: RetryPolicy;
42
+ readonly metadata?: Metadata;
43
+ readonly tags?: readonly string[];
44
+ }
45
+ export interface RunDefaults {
46
+ readonly queue?: Queue | string;
47
+ readonly maxDuration?: Duration;
48
+ readonly ttl?: Duration;
49
+ readonly retry?: RetryPolicy;
50
+ }
51
+ declare const workspaceAddressTypeBrand: unique symbol;
52
+ export interface WorkspaceAddress {
53
+ readonly [workspaceAddressTypeBrand]: true;
54
+ readonly id: string;
55
+ }
56
+ export type RunCause = Readonly<{
57
+ type: "api" | "manual";
58
+ }> | Readonly<{
59
+ type: "child";
60
+ parentRunId: string;
61
+ }> | Readonly<{
62
+ type: "schedule";
63
+ scheduleId: string;
64
+ scheduledAt: string;
65
+ lastScheduledAt?: string;
66
+ timezone: string;
67
+ }> | Readonly<{
68
+ type: "actor_start" | "continuation";
69
+ }>;
70
+ interface RunContext {
71
+ readonly signal: AbortSignal;
72
+ readonly run: Readonly<{
73
+ id: string;
74
+ attemptNumber: number;
75
+ cause: RunCause;
76
+ }>;
77
+ readonly deployment: Readonly<{
78
+ id: string;
79
+ version: string;
80
+ }>;
81
+ readonly workspace: WorkspaceRef;
82
+ }
83
+ export interface TaskContext extends RunContext {
84
+ readonly task: Readonly<{
85
+ id: string;
86
+ }>;
87
+ readonly actor?: never;
88
+ }
89
+ export interface ActorContext extends RunContext {
90
+ readonly task?: never;
91
+ readonly actor: Readonly<{
92
+ id: string;
93
+ }>;
94
+ }
95
+ export interface HelmrError extends Error {
96
+ readonly code: string;
97
+ readonly requestId?: string;
98
+ }
99
+ export interface APIError extends HelmrError {
100
+ readonly details?: Readonly<Record<string, JsonValue>>;
101
+ }
102
+ export type RunStatus = "queued" | "running" | "waiting" | "retry_delayed" | "cancel_requested" | "succeeded" | "failed" | "cancelled" | "expired" | "system_failed";
103
+ declare const runHandleOutputBrand: unique symbol;
104
+ export interface RunHandle<TOutput extends JsonValue = JsonValue> {
105
+ readonly id: string;
106
+ readonly [runHandleOutputBrand]: TOutput;
107
+ }
108
+ export interface RunFailure {
109
+ readonly code: string;
110
+ readonly message: string;
111
+ readonly details: Readonly<Record<string, JsonValue>>;
112
+ }
113
+ export interface Run<TOutput extends JsonValue = JsonValue> extends RunHandle<TOutput> {
114
+ readonly status: RunStatus;
115
+ readonly entrypoint: Readonly<{
116
+ kind: "task" | "actor";
117
+ id: string;
118
+ }>;
119
+ readonly deployment: Readonly<{
120
+ id: string;
121
+ version: string;
122
+ }>;
123
+ readonly workspaceId: string;
124
+ readonly sessionId?: string;
125
+ readonly parentRunId?: string;
126
+ readonly currentAttemptNumber: number;
127
+ readonly cause: RunCause;
128
+ readonly metadata: Metadata;
129
+ readonly tags: readonly string[];
130
+ readonly output?: TOutput;
131
+ readonly failure?: RunFailure;
132
+ readonly createdAt: string;
133
+ readonly startedAt?: string;
134
+ readonly terminalAt?: string;
135
+ }
136
+ export type TaskResult<T extends JsonValue> = Readonly<{
137
+ ok: true;
138
+ output: T;
139
+ run: RunHandle<T>;
140
+ }> | Readonly<{
141
+ ok: false;
142
+ failure: RunFailure;
143
+ run: RunHandle<T>;
144
+ }>;
145
+ export interface TaskWait<T extends JsonValue> extends PromiseLike<TaskResult<T>> {
146
+ unwrap(): Promise<T>;
147
+ }
148
+ export interface TaskStartOptions extends RunOptions {
149
+ readonly idempotencyKey?: string;
150
+ readonly workspace: WorkspaceRef;
151
+ readonly signal?: AbortSignal;
152
+ }
153
+ export interface TaskCallOptions extends RunOptions {
154
+ readonly idempotencyKey: string;
155
+ readonly workspace: WorkspaceRef;
156
+ readonly signal?: AbortSignal;
157
+ }
158
+ declare const taskBrand: unique symbol;
159
+ interface TaskTypeInfo<TIdentifier extends string, TInput extends JsonValue, TOutput extends JsonValue> {
160
+ readonly identifier: TIdentifier;
161
+ readonly input: TInput;
162
+ readonly output: TOutput;
163
+ }
164
+ export interface Task<TIdentifier extends string = string, TInput extends JsonValue = JsonValue, TOutput extends JsonValue = JsonValue> {
165
+ readonly [taskBrand]: TaskTypeInfo<TIdentifier, TInput, TOutput>;
166
+ readonly id: TIdentifier;
167
+ readonly hasPayload: boolean;
168
+ start(...args: [TInput] extends [never] ? [options: TaskStartOptions] : [payload: TInput, options: TaskStartOptions]): Promise<RunHandle<TOutput>>;
169
+ call(...args: [TInput] extends [never] ? [options: TaskCallOptions] : [payload: TInput, options: TaskCallOptions]): TaskWait<TOutput>;
170
+ }
171
+ export type TaskInput<TTask extends Task> = TTask[typeof taskBrand]["input"];
172
+ export type TaskOutput<TTask extends Task> = TTask[typeof taskBrand]["output"];
173
+ export type TaskConfigWithPayload<TIdentifier extends string, TInput extends JsonValue, TPayload, TOutput extends JsonValue> = RunDefaults & Readonly<{
174
+ id: TIdentifier;
175
+ payload: PayloadSchema<TInput, TPayload>;
176
+ run(payload: TPayload, ctx: TaskContext): MaybePromise<TOutput>;
177
+ }>;
178
+ export type TaskConfigWithoutPayload<TIdentifier extends string, TOutput extends JsonValue> = RunDefaults & Readonly<{
179
+ id: TIdentifier;
180
+ payload?: never;
181
+ run(ctx: TaskContext): MaybePromise<TOutput>;
182
+ }>;
183
+ export type TaskConfig<TIdentifier extends string = string, TInput extends JsonValue = never, TPayload = never, TOutput extends JsonValue = JsonValue> = TaskConfigWithPayload<TIdentifier, TInput, TPayload, TOutput> | TaskConfigWithoutPayload<TIdentifier, TOutput>;
184
+ export type TurnSource = Readonly<{
185
+ type: "external";
186
+ }> | Readonly<{
187
+ type: "run";
188
+ runId: string;
189
+ }>;
190
+ export interface WaitTimeoutError extends HelmrError {
191
+ readonly code: "wait_timeout";
192
+ }
193
+ export interface ActorSessionReceiveOptions {
194
+ readonly timeout?: Duration;
195
+ /** Hot managed-wait duration before suspension is eligible; not a response deadline or billing cap. */
196
+ readonly idleTimeout?: Duration;
197
+ readonly metadata?: Metadata;
198
+ readonly tags?: readonly string[];
199
+ }
200
+ export interface SessionOperationOptions {
201
+ readonly idempotencyKey?: string;
202
+ }
203
+ export interface OutputReceipt {
204
+ readonly id: string;
205
+ readonly sequence: number;
206
+ readonly sessionId: string;
207
+ readonly turnId: string | null;
208
+ readonly runId: string;
209
+ readonly attemptNumber: number;
210
+ readonly runGeneration: number;
211
+ }
212
+ export interface RecordWriter<TValue = JsonValue> {
213
+ write(value: TValue, options?: SessionOperationOptions): Promise<OutputReceipt>;
214
+ pipe(source: AsyncIterable<TValue> | Iterable<TValue>): Promise<void>;
215
+ }
216
+ export interface Message<TData = JsonValue> {
217
+ readonly id: string;
218
+ readonly data: TData;
219
+ }
220
+ export interface Turn {
221
+ readonly id: string;
222
+ readonly sequence: number;
223
+ readonly input: JsonValue;
224
+ readonly source: TurnSource;
225
+ readonly createdAt: string;
226
+ readonly signal: AbortSignal;
227
+ readonly output: RecordWriter;
228
+ onMessage(handler: (message: Message) => MaybePromise<void>): Promise<void>;
229
+ /** Commit the Turn result without checkpointing the Computer. */
230
+ complete(result?: JsonValue): Promise<void>;
231
+ fail(error: unknown): Promise<void>;
232
+ }
233
+ export interface ActorSession {
234
+ readonly id: string;
235
+ readonly key?: string;
236
+ readonly output: RecordWriter;
237
+ receive(options?: ActorSessionReceiveOptions): Promise<Turn | null>;
238
+ }
239
+ export interface ActorConfig extends RunDefaults {
240
+ readonly id: string;
241
+ /** Hot managed-wait duration before suspension is eligible; not a response deadline or billing cap. */
242
+ readonly idleTimeout?: Duration;
243
+ readonly run: (session: ActorSession, ctx: ActorContext) => MaybePromise<void>;
244
+ }
245
+ export interface ActorStartOptions {
246
+ readonly key?: string;
247
+ readonly idempotencyKey?: string;
248
+ readonly workspace: WorkspaceRef;
249
+ readonly run?: RunOptions;
250
+ readonly signal?: AbortSignal;
251
+ }
252
+ export type SessionStatus = "open" | "closing" | "closed" | "failed";
253
+ export type SessionFailureCode = string;
254
+ export interface SessionFailure {
255
+ readonly code: SessionFailureCode;
256
+ readonly message: string;
257
+ readonly details: Readonly<{
258
+ runId?: string;
259
+ }>;
260
+ }
261
+ export type SessionDispatch = Readonly<{
262
+ state: "ready";
263
+ }> | Readonly<{
264
+ state: "held";
265
+ holdId: string;
266
+ reason: "interrupt_requested" | "interrupted" | "recovery_required";
267
+ }>;
268
+ export interface Session {
269
+ readonly cancelRequestedAt?: string;
270
+ readonly id: string;
271
+ readonly actorId: string;
272
+ readonly deploymentId: string;
273
+ readonly workspaceId: string;
274
+ readonly key?: string;
275
+ readonly status: SessionStatus;
276
+ readonly createdAt: string;
277
+ readonly updatedAt: string;
278
+ readonly currentRunId: string | null;
279
+ readonly activeTurnId: string | null;
280
+ readonly dispatch: SessionDispatch;
281
+ readonly failure?: SessionFailure;
282
+ }
283
+ export type TurnStatus = "queued" | "running" | "completed" | "failed" | "interrupted" | "cancelled";
284
+ export interface TurnState {
285
+ readonly id: string;
286
+ readonly sessionId: string;
287
+ readonly sequence: number;
288
+ readonly input: JsonValue;
289
+ readonly source: TurnSource;
290
+ readonly status: TurnStatus;
291
+ readonly createdAt: string;
292
+ readonly interruptRequested: boolean;
293
+ readonly acceptsMessages: boolean;
294
+ readonly terminalEventId?: string;
295
+ readonly workspaceVersionId?: string;
296
+ readonly result?: JsonValue;
297
+ readonly error?: JsonValue;
298
+ }
299
+ export interface SessionCloseReceipt {
300
+ readonly id: string;
301
+ readonly sessionId: string;
302
+ readonly status: "accepted";
303
+ }
304
+ export interface SessionCancelReceipt {
305
+ readonly id: string;
306
+ readonly sessionId: string;
307
+ readonly status: "accepted";
308
+ }
309
+ export interface TurnInterruptReceipt {
310
+ readonly id: string;
311
+ readonly sessionId: string;
312
+ readonly turnId: string;
313
+ readonly holdId: string;
314
+ readonly status: "accepted";
315
+ }
316
+ export interface SessionResumeReceipt {
317
+ readonly id: string;
318
+ readonly sessionId: string;
319
+ readonly holdId: string;
320
+ readonly status: "accepted";
321
+ }
322
+ export interface SessionResumeRequest extends SessionOperationOptions {
323
+ readonly holdId: string;
324
+ }
325
+ export type SessionAdmissionReceipt = Readonly<{
326
+ id: string;
327
+ kind: "enqueued";
328
+ turnId: string;
329
+ }> | Readonly<{
330
+ id: string;
331
+ kind: "messaged";
332
+ turnId: string;
333
+ messageId: string;
334
+ }>;
335
+ export interface SessionMessageReceipt {
336
+ readonly id: string;
337
+ readonly turnId: string;
338
+ readonly messageId: string;
339
+ readonly status: "accepted";
340
+ }
341
+ export interface MessageReceipt {
342
+ readonly id: string;
343
+ readonly status: "accepted";
344
+ }
345
+ export type SessionEventKind = "output" | "turn.enqueued" | "turn.started" | "turn.interrupt_requested" | "turn.completed" | "turn.failed" | "turn.interrupted" | "message.accepted" | "message.handled" | "message.rejected" | "message.unknown" | "session.closing" | "session.closed" | "session.cancel_requested" | "turn.cancelled" | "session.failed" | "session.held" | "session.resumed" | "session.execution_lost";
346
+ export interface SessionEvent {
347
+ readonly id: string;
348
+ readonly sessionId: string;
349
+ readonly turnId: string | null;
350
+ readonly sequence: number;
351
+ readonly createdAt: string;
352
+ readonly kind: SessionEventKind;
353
+ readonly data: JsonValue;
354
+ readonly provenance: Readonly<{
355
+ runId: string;
356
+ attemptNumber: number;
357
+ runGeneration: number;
358
+ deploymentId: string;
359
+ }> | null;
360
+ }
361
+ export interface SessionEventQuery {
362
+ readonly after?: number;
363
+ readonly limit?: number;
364
+ }
365
+ export interface SessionEventPage {
366
+ readonly records: readonly SessionEvent[];
367
+ readonly nextAfter: number;
368
+ readonly hasMore: boolean;
369
+ readonly retainedAfter: number;
370
+ }
371
+ export interface TurnRef {
372
+ readonly id: string;
373
+ readonly sessionId: string;
374
+ send(data: JsonValue, request?: SessionOperationOptions, options?: RequestOptions): Promise<MessageReceipt>;
375
+ retrieve(options?: RequestOptions): Promise<TurnState>;
376
+ interrupt(request?: SessionOperationOptions, options?: RequestOptions): Promise<TurnInterruptReceipt>;
377
+ }
378
+ export type SessionSendResult = Readonly<{
379
+ kind: "enqueued";
380
+ turn: TurnRef;
381
+ }> | Readonly<{
382
+ kind: "messaged";
383
+ turn: TurnRef;
384
+ message: MessageReceipt;
385
+ }>;
386
+ export interface SessionRef {
387
+ readonly id: string;
388
+ send(data: JsonValue, request?: SessionOperationOptions, options?: RequestOptions): Promise<SessionSendResult>;
389
+ enqueue(input: JsonValue, request?: SessionOperationOptions, options?: RequestOptions): Promise<TurnRef>;
390
+ turn(id: string): TurnRef;
391
+ readonly events: Readonly<{
392
+ list(query?: SessionEventQuery, options?: RequestOptions): Promise<SessionEventPage>;
393
+ }>;
394
+ retrieve(options?: RequestOptions): Promise<Session>;
395
+ close(request?: SessionOperationOptions, options?: RequestOptions): Promise<SessionCloseReceipt>;
396
+ cancel(request?: SessionOperationOptions, options?: RequestOptions): Promise<SessionCancelReceipt>;
397
+ resume(request: SessionResumeRequest, options?: RequestOptions): Promise<SessionResumeReceipt>;
398
+ }
399
+ declare const actorTypeBrand: unique symbol;
400
+ export interface ActorStartResult {
401
+ readonly session: SessionRef;
402
+ readonly run: RunHandle<null>;
403
+ }
404
+ export interface Actor {
405
+ readonly [actorTypeBrand]: true;
406
+ readonly id: string;
407
+ start(options: ActorStartOptions): Promise<ActorStartResult>;
408
+ }
@@ -0,0 +1,42 @@
1
+ import { type ActorConfig, type Actor, type JsonValue, type Queue, type QueueConfig, type Task, type TaskConfigWithPayload, type TaskConfigWithoutPayload } from "./contract.js";
2
+ import { type PayloadSchema } from "./schema/payload.js";
3
+ export type InternalTaskDefinition = Readonly<{
4
+ kind: "task";
5
+ id: string;
6
+ hasPayload: boolean;
7
+ handler: (...args: readonly unknown[]) => unknown;
8
+ payloadSchema?: PayloadSchema;
9
+ queue?: Queue | string;
10
+ maxDuration?: import("./contract.js").Duration;
11
+ ttl?: import("./contract.js").Duration;
12
+ retry?: ActorConfig["retry"];
13
+ schedule?: Readonly<{
14
+ cron: string;
15
+ timezone: string;
16
+ workspace: Readonly<{
17
+ sandbox: import("./workspace.js").Sandbox;
18
+ secrets: readonly import("./workspace.js").EncodedWorkspaceSecret[];
19
+ }>;
20
+ }>;
21
+ }>;
22
+ export type InternalActorDefinition = Readonly<{
23
+ kind: "actor";
24
+ id: string;
25
+ handler: (...args: readonly unknown[]) => unknown;
26
+ queue?: Queue | string;
27
+ maxDuration?: import("./contract.js").Duration;
28
+ ttl?: import("./contract.js").Duration;
29
+ retry?: ActorConfig["retry"];
30
+ idleTimeout?: ActorConfig["idleTimeout"];
31
+ }>;
32
+ export type InternalDefinition = InternalTaskDefinition | InternalActorDefinition;
33
+ export declare function inspectDefinition(value: unknown): InternalDefinition | undefined;
34
+ export declare function isQueue(value: unknown): value is Queue;
35
+ export declare function queue(config: QueueConfig): Queue;
36
+ export declare function task<TIdentifier extends string, TInput extends JsonValue, TPayload, TOutput extends JsonValue>(config: TaskConfigWithPayload<TIdentifier, TInput, TPayload, TOutput>): Task<TIdentifier, TInput, TOutput>;
37
+ export declare function task<TIdentifier extends string, TOutput extends JsonValue>(config: TaskConfigWithoutPayload<TIdentifier, TOutput>): Task<TIdentifier, never, TOutput>;
38
+ export declare function actor(config: ActorConfig): Actor;
39
+ export declare function createScheduledTask<TIdentifier extends string, TInput extends JsonValue, TPayload, TOutput extends JsonValue>(config: Omit<TaskConfigWithPayload<TIdentifier, TInput, TPayload, TOutput>, "payload"> & {
40
+ readonly payload: PayloadSchema<TInput, TPayload>;
41
+ readonly schedule: NonNullable<InternalTaskDefinition["schedule"]>;
42
+ }): Task<TIdentifier, TInput, TOutput>;
@@ -0,0 +1 @@
1
+ export declare function levenshteinDistance(left: string, right: string): number;
package/dist/fuzzy.js ADDED
@@ -0,0 +1,29 @@
1
+ // sdk/typescript/src/fuzzy.ts
2
+ function levenshteinDistance(left, right) {
3
+ if (left === right) {
4
+ return 0;
5
+ }
6
+ if (left.length === 0) {
7
+ return right.length;
8
+ }
9
+ if (right.length === 0) {
10
+ return left.length;
11
+ }
12
+ const previous = new Array(right.length + 1);
13
+ const current = new Array(right.length + 1);
14
+ for (let column = 0;column <= right.length; column += 1) {
15
+ previous[column] = column;
16
+ }
17
+ for (let row = 1;row <= left.length; row += 1) {
18
+ current[0] = row;
19
+ for (let column = 1;column <= right.length; column += 1) {
20
+ const cost = left[row - 1] === right[column - 1] ? 0 : 1;
21
+ current[column] = Math.min(current[column - 1] + 1, previous[column] + 1, previous[column - 1] + cost);
22
+ }
23
+ previous.splice(0, previous.length, ...current);
24
+ }
25
+ return previous[right.length] ?? right.length;
26
+ }
27
+ export {
28
+ levenshteinDistance
29
+ };