@helmr/sdk 0.1.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 +190 -0
- package/README.md +73 -0
- package/dist/compile.d.ts +9 -0
- package/dist/compile.js +503 -0
- package/dist/config.d.ts +8 -0
- package/dist/fuzzy.d.ts +1 -0
- package/dist/fuzzy.js +29 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +1023 -0
- package/dist/internal.d.ts +239 -0
- package/dist/internal.js +345 -0
- package/dist/runtime/client.d.ts +74 -0
- package/dist/runtime/errors.d.ts +13 -0
- package/dist/runtime/run.d.ts +195 -0
- package/dist/runtime/source.d.ts +7 -0
- package/dist/sandbox.d.ts +3 -0
- package/dist/schema/task.d.ts +20 -0
- package/dist/task.d.ts +3 -0
- package/dist/trigger.d.ts +25 -0
- package/package.json +48 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
export type RunStatus = "queued" | "claimed" | "running" | "waiting" | "succeeded" | "failed" | "cancelled";
|
|
2
|
+
declare const runOutputBrand: unique symbol;
|
|
3
|
+
export interface RunHandle<TOutput = unknown> {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly taskId: string;
|
|
6
|
+
readonly [runOutputBrand]?: TOutput;
|
|
7
|
+
}
|
|
8
|
+
export type RunOutput<T> = T extends {
|
|
9
|
+
readonly [runOutputBrand]?: infer TOutput;
|
|
10
|
+
} ? TOutput : unknown;
|
|
11
|
+
export interface RunStateBooleans {
|
|
12
|
+
readonly isQueued: boolean;
|
|
13
|
+
readonly isRunning: boolean;
|
|
14
|
+
readonly isWaiting: boolean;
|
|
15
|
+
readonly isTerminal: boolean;
|
|
16
|
+
readonly isSuccess: boolean;
|
|
17
|
+
readonly isFailed: boolean;
|
|
18
|
+
readonly isCancelled: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface RunSnapshot<TOutput = unknown> extends RunStateBooleans {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly taskId: string;
|
|
23
|
+
readonly status: RunStatus;
|
|
24
|
+
readonly exitCode: number | null;
|
|
25
|
+
readonly createdAt: string | null;
|
|
26
|
+
readonly updatedAt: string | null;
|
|
27
|
+
readonly pendingWaitpoint: PendingWaitpoint | null;
|
|
28
|
+
readonly output?: TOutput;
|
|
29
|
+
}
|
|
30
|
+
export type RunSummary<TOutput = unknown> = RunSnapshot<TOutput>;
|
|
31
|
+
export type PendingWaitpoint = PendingApprovalWaitpoint | PendingMessageWaitpoint;
|
|
32
|
+
interface PendingWaitpointBase {
|
|
33
|
+
readonly runId: string;
|
|
34
|
+
readonly waitpointId: string;
|
|
35
|
+
readonly timeout: number | null;
|
|
36
|
+
readonly requestedAt: string;
|
|
37
|
+
}
|
|
38
|
+
export interface PendingApprovalWaitpoint extends PendingWaitpointBase {
|
|
39
|
+
readonly kind: "approval";
|
|
40
|
+
readonly message: string;
|
|
41
|
+
}
|
|
42
|
+
export interface PendingMessageWaitpoint extends PendingWaitpointBase {
|
|
43
|
+
readonly kind: "message";
|
|
44
|
+
readonly prompt: string | null;
|
|
45
|
+
}
|
|
46
|
+
export interface WaitpointRef {
|
|
47
|
+
readonly runId: string;
|
|
48
|
+
readonly waitpointId: string;
|
|
49
|
+
}
|
|
50
|
+
export interface WaitpointApprovalOptions {
|
|
51
|
+
readonly reason?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface WaitpointReplyOptions {
|
|
54
|
+
readonly text: string;
|
|
55
|
+
}
|
|
56
|
+
export interface RunWaitOptions {
|
|
57
|
+
readonly timeoutMs?: number;
|
|
58
|
+
readonly intervalMs?: number;
|
|
59
|
+
readonly signal?: AbortSignal;
|
|
60
|
+
}
|
|
61
|
+
export interface RetrieveRunOptions {
|
|
62
|
+
readonly signal?: AbortSignal;
|
|
63
|
+
}
|
|
64
|
+
export interface ListRunsOptions {
|
|
65
|
+
readonly status?: RunStatus | "live" | "all";
|
|
66
|
+
readonly limit?: number;
|
|
67
|
+
readonly projectId?: string;
|
|
68
|
+
readonly environmentId?: string;
|
|
69
|
+
readonly signal?: AbortSignal;
|
|
70
|
+
}
|
|
71
|
+
export interface ListRunEventsOptions {
|
|
72
|
+
readonly cursor?: number;
|
|
73
|
+
readonly pageSize?: number;
|
|
74
|
+
readonly signal?: AbortSignal;
|
|
75
|
+
}
|
|
76
|
+
export interface SubscribeRunEventsOptions {
|
|
77
|
+
readonly cursor?: number;
|
|
78
|
+
readonly signal?: AbortSignal;
|
|
79
|
+
}
|
|
80
|
+
export type RunEvent = {
|
|
81
|
+
readonly type: "log";
|
|
82
|
+
readonly run_id: string;
|
|
83
|
+
readonly stream: "stdout" | "stderr";
|
|
84
|
+
readonly bytes: number;
|
|
85
|
+
readonly observed_seq: number;
|
|
86
|
+
readonly at: string;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "approval_request";
|
|
89
|
+
readonly run_id: string;
|
|
90
|
+
readonly waitpoint_id: string;
|
|
91
|
+
readonly message: string;
|
|
92
|
+
readonly timeout?: number;
|
|
93
|
+
readonly at: string;
|
|
94
|
+
} | {
|
|
95
|
+
readonly type: "approval_decided";
|
|
96
|
+
readonly run_id: string;
|
|
97
|
+
readonly waitpoint_id: string;
|
|
98
|
+
readonly decision: "approved" | "denied";
|
|
99
|
+
readonly reason?: string;
|
|
100
|
+
readonly at: string;
|
|
101
|
+
} | {
|
|
102
|
+
readonly type: "message_request";
|
|
103
|
+
readonly run_id: string;
|
|
104
|
+
readonly waitpoint_id: string;
|
|
105
|
+
readonly prompt?: string;
|
|
106
|
+
readonly timeout?: number;
|
|
107
|
+
readonly at: string;
|
|
108
|
+
} | {
|
|
109
|
+
readonly type: "message_received";
|
|
110
|
+
readonly run_id: string;
|
|
111
|
+
readonly waitpoint_id: string;
|
|
112
|
+
readonly text: string;
|
|
113
|
+
readonly at: string;
|
|
114
|
+
} | {
|
|
115
|
+
readonly type: "emit";
|
|
116
|
+
readonly run_id: string;
|
|
117
|
+
readonly event_type: string;
|
|
118
|
+
readonly content: unknown;
|
|
119
|
+
readonly at: string;
|
|
120
|
+
} | {
|
|
121
|
+
readonly type: "task_complete";
|
|
122
|
+
readonly run_id: string;
|
|
123
|
+
readonly exit_code: number;
|
|
124
|
+
readonly at: string;
|
|
125
|
+
} | {
|
|
126
|
+
readonly type: "run_failed";
|
|
127
|
+
readonly run_id: string;
|
|
128
|
+
readonly failure_kind: string;
|
|
129
|
+
readonly detail?: unknown;
|
|
130
|
+
readonly at: string;
|
|
131
|
+
} | {
|
|
132
|
+
readonly type: "run_timeout";
|
|
133
|
+
readonly run_id: string;
|
|
134
|
+
readonly elapsed_secs: number;
|
|
135
|
+
readonly limit_secs: number;
|
|
136
|
+
readonly at: string;
|
|
137
|
+
} | {
|
|
138
|
+
readonly type: "run_cancelled";
|
|
139
|
+
readonly run_id: string;
|
|
140
|
+
readonly reason?: string;
|
|
141
|
+
readonly at: string;
|
|
142
|
+
};
|
|
143
|
+
export interface RunEventRecord {
|
|
144
|
+
readonly id: string;
|
|
145
|
+
readonly run_id?: string | null;
|
|
146
|
+
readonly kind: string;
|
|
147
|
+
readonly message: string;
|
|
148
|
+
readonly at: string;
|
|
149
|
+
readonly attributes: unknown;
|
|
150
|
+
}
|
|
151
|
+
export interface RunEventRecordPage {
|
|
152
|
+
readonly events: readonly RunEventRecord[];
|
|
153
|
+
readonly cursor: number;
|
|
154
|
+
readonly next_cursor?: number | null;
|
|
155
|
+
}
|
|
156
|
+
export interface RunEventPage {
|
|
157
|
+
readonly events: readonly RunEvent[];
|
|
158
|
+
readonly cursor: number;
|
|
159
|
+
readonly nextCursor: number | null;
|
|
160
|
+
}
|
|
161
|
+
export interface LogSnapshot {
|
|
162
|
+
readonly stdout: string;
|
|
163
|
+
readonly stderr: string;
|
|
164
|
+
readonly cursor: string;
|
|
165
|
+
readonly truncated: boolean;
|
|
166
|
+
}
|
|
167
|
+
export type PendingWaitpointResponse = {
|
|
168
|
+
readonly kind: "approval";
|
|
169
|
+
readonly waitpoint_id: string;
|
|
170
|
+
readonly message?: string | null;
|
|
171
|
+
readonly timeout?: number | null;
|
|
172
|
+
readonly requested_at: string;
|
|
173
|
+
} | {
|
|
174
|
+
readonly kind: "message";
|
|
175
|
+
readonly waitpoint_id: string;
|
|
176
|
+
readonly prompt?: string | null;
|
|
177
|
+
readonly timeout?: number | null;
|
|
178
|
+
readonly requested_at: string;
|
|
179
|
+
};
|
|
180
|
+
export declare function runHandle<TOutput = unknown>(id: string, taskId: string): RunHandle<TOutput>;
|
|
181
|
+
export declare function runSnapshot<TOutput = unknown>(snapshot: {
|
|
182
|
+
readonly id: string;
|
|
183
|
+
readonly taskId: string;
|
|
184
|
+
readonly status: string;
|
|
185
|
+
readonly exitCode?: number | null;
|
|
186
|
+
readonly createdAt?: string | null;
|
|
187
|
+
readonly updatedAt?: string | null;
|
|
188
|
+
readonly pendingWaitpoint?: PendingWaitpoint | null;
|
|
189
|
+
readonly output?: TOutput;
|
|
190
|
+
}): RunSnapshot<TOutput>;
|
|
191
|
+
export declare function pendingWaitpointFromResponse(runId: string, wait: PendingWaitpointResponse | null | undefined): PendingWaitpoint | null;
|
|
192
|
+
export declare function isTerminalRunStatus(status: RunStatus): boolean;
|
|
193
|
+
export declare function runId(value: string | RunHandle<unknown>): string;
|
|
194
|
+
export declare function runStateBooleans(status: RunStatus): RunStateBooleans;
|
|
195
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const TASK_ID_PATTERN: "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$";
|
|
2
|
+
export declare const TASK_ID_MAX_LENGTH = 128;
|
|
3
|
+
export declare const DEFAULT_MAX_DURATION_SECONDS = 900;
|
|
4
|
+
export declare const MIN_MAX_DURATION_SECONDS = 5;
|
|
5
|
+
export declare const MAX_DURATION_SECONDS = 86400;
|
|
6
|
+
export declare class TaskIdError extends Error {
|
|
7
|
+
readonly name = "TaskIdError";
|
|
8
|
+
readonly value: string;
|
|
9
|
+
constructor(value: string);
|
|
10
|
+
}
|
|
11
|
+
export declare function validateTaskId(value: string): void;
|
|
12
|
+
export declare function isValidTaskId(value: string): boolean;
|
|
13
|
+
export declare class TaskMaxDurationError extends Error {
|
|
14
|
+
readonly name = "TaskMaxDurationError";
|
|
15
|
+
readonly value: unknown;
|
|
16
|
+
readonly label: string;
|
|
17
|
+
constructor(value: unknown, label?: string);
|
|
18
|
+
}
|
|
19
|
+
export declare function readOptionalMaxDurationSeconds(value: unknown, label?: string): number;
|
|
20
|
+
export declare function validateOptionalMaxDurationSeconds(value: unknown, label?: string): void;
|
package/dist/task.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type SecretDecls, type Task, type TaskConfig, type TaskOutput, type TaskPayload } from "./internal.js";
|
|
2
|
+
export declare function task<TPayload, TOutput, TSecrets extends SecretDecls = Record<never, never>>(config: TaskConfig<TPayload, TOutput, TSecrets>): Task<TPayload, Awaited<TOutput>, TSecrets>;
|
|
3
|
+
export type { Task, TaskConfig, TaskOutput, TaskPayload };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SecretDecls, Task, WorkspaceSpec } from "./internal.js";
|
|
2
|
+
import { HelmrClient } from "./runtime/client.js";
|
|
3
|
+
import type { RunHandle } from "./runtime/run.js";
|
|
4
|
+
export declare function getDefaultClient(): HelmrClient;
|
|
5
|
+
export type TriggerSecrets<TSecrets extends SecretDecls> = {
|
|
6
|
+
readonly [K in keyof TSecrets]: string;
|
|
7
|
+
};
|
|
8
|
+
export type TriggerOptions<TPayload, TSecrets extends SecretDecls> = {
|
|
9
|
+
/**
|
|
10
|
+
* Payload is audit data: Helmr persists it in plaintext in the `run.created`
|
|
11
|
+
* event, DB, and events stream. Do not put secret values (tokens, API keys,
|
|
12
|
+
* credentials, or PII) in payload; use `secrets:` instead. Use payload for
|
|
13
|
+
* business context such as PR numbers, repo names, ticket ids, and other
|
|
14
|
+
* identifiers.
|
|
15
|
+
*/
|
|
16
|
+
readonly payload: TPayload;
|
|
17
|
+
readonly workspace: WorkspaceSpec;
|
|
18
|
+
} & ([keyof TSecrets] extends [never] ? {
|
|
19
|
+
readonly secrets?: Record<never, never>;
|
|
20
|
+
} : {
|
|
21
|
+
readonly secrets: TriggerSecrets<TSecrets>;
|
|
22
|
+
});
|
|
23
|
+
export declare const tasks: {
|
|
24
|
+
trigger<TPayload, TOutput, TSecrets extends SecretDecls>(task: Task<TPayload, TOutput, TSecrets>, opts: TriggerOptions<TPayload, TSecrets>): Promise<RunHandle<TOutput>>;
|
|
25
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@helmr/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for authoring and triggering Helmr tasks.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/helmrdotdev/helmr.git",
|
|
12
|
+
"directory": "sdk/typescript"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/helmrdotdev/helmr/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://helmr.dev",
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./internal": {
|
|
27
|
+
"types": "./dist/internal.d.ts",
|
|
28
|
+
"import": "./dist/internal.js"
|
|
29
|
+
},
|
|
30
|
+
"./internal/compile": {
|
|
31
|
+
"types": "./dist/compile.d.ts",
|
|
32
|
+
"import": "./dist/compile.js"
|
|
33
|
+
},
|
|
34
|
+
"./internal/fuzzy": {
|
|
35
|
+
"types": "./dist/fuzzy.d.ts",
|
|
36
|
+
"import": "./dist/fuzzy.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"LICENSE",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@bufbuild/protobuf": "^2.11.0",
|
|
46
|
+
"@helmr/proto": "0.1.0"
|
|
47
|
+
}
|
|
48
|
+
}
|