@helmr/sdk 0.1.1-rc.3 → 0.1.1-rc.5
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/README.md +20 -12
- package/dist/compile.d.ts +1 -1
- package/dist/compile.js +35 -4
- package/dist/config.d.ts +1 -1
- package/dist/idempotency.d.ts +30 -0
- package/dist/index.d.ts +26 -8
- package/dist/index.js +764 -204
- package/dist/internal.d.ts +162 -33
- package/dist/internal.js +265 -26
- package/dist/runtime/client.d.ts +114 -56
- package/dist/runtime/run.d.ts +32 -48
- package/dist/schedules.d.ts +30 -0
- package/dist/schema/payload.d.ts +40 -0
- package/dist/schema/task.d.ts +15 -0
- package/dist/task.d.ts +6 -3
- package/dist/trigger.d.ts +10 -20
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Schemes such as `env:` and `file:` are local runner sources and are rejected for
|
|
|
19
19
|
|
|
20
20
|
## TypeScript Runtime Client
|
|
21
21
|
|
|
22
|
-
External TypeScript processes create runs with `tasks.trigger()`. Triggering returns a lightweight `RunHandle`; retrieve or wait on that handle to get a `RunSnapshot`.
|
|
22
|
+
External TypeScript processes create runs with `task.trigger()` or the id-based `client.tasks.trigger()`. Triggering returns a lightweight `RunHandle`; retrieve or wait on that handle to get a `RunSnapshot`.
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
25
|
import { HelmrClient, workspace } from "@helmr/sdk"
|
|
@@ -30,15 +30,20 @@ const client = new HelmrClient({
|
|
|
30
30
|
apiKey: process.env.HELMR_API_KEY,
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
const handle = await client.tasks.trigger(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const handle = await client.tasks.trigger<typeof impl>(
|
|
34
|
+
"impl",
|
|
35
|
+
{ issue: 123 },
|
|
36
|
+
{
|
|
37
|
+
workspace: workspace.github("OWNER/REPO", { ref: "main", subpath: "tasks" }),
|
|
38
|
+
},
|
|
39
|
+
)
|
|
37
40
|
|
|
38
41
|
const current = await client.runs.retrieve(handle)
|
|
39
42
|
const pendingWaitpoint = current.pendingWaitpoint
|
|
40
|
-
if (pendingWaitpoint !== null && pendingWaitpoint.kind === "
|
|
41
|
-
await client.waitpoints.
|
|
43
|
+
if (pendingWaitpoint !== null && pendingWaitpoint.kind === "manual") {
|
|
44
|
+
await client.waitpoints.respond(pendingWaitpoint, {
|
|
45
|
+
value: { approved: true },
|
|
46
|
+
})
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
const finished = await client.runs.wait(handle, { timeoutMs: 10 * 60_000, intervalMs: 1_000 })
|
|
@@ -52,19 +57,22 @@ for await (const event of await client.runs.events.subscribe(handle)) {
|
|
|
52
57
|
console.log(finished.status, logs.stdout, events.length)
|
|
53
58
|
```
|
|
54
59
|
|
|
55
|
-
Waitpoint
|
|
60
|
+
Waitpoint responses live on `client.waitpoints`. Pass either a pending waitpoint from a run snapshot or a waitpoint id:
|
|
56
61
|
|
|
57
62
|
```ts
|
|
58
|
-
await client.waitpoints.
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
await client.waitpoints.respond("waitpoint-456", {
|
|
64
|
+
value: { approved: true },
|
|
65
|
+
})
|
|
66
|
+
await client.waitpoints.respond("waitpoint-456", {
|
|
67
|
+
value: { text: "Use the smaller rollout." },
|
|
68
|
+
})
|
|
61
69
|
```
|
|
62
70
|
|
|
63
71
|
## API Reference
|
|
64
72
|
|
|
65
73
|
### `POST /api/runs`
|
|
66
74
|
|
|
67
|
-
`payload` is a
|
|
75
|
+
`payload` is a JSON field for tasks that accept payload. Payload is audit data: Helmr persists it in plaintext in the `run.created` event, DB, and events stream. Do not put secret values (tokens, API keys, credentials, or PII) in payload; use `secrets:` instead. Use payload for business context such as PR numbers, repo names, ticket ids, and other identifiers.
|
|
68
76
|
|
|
69
77
|
`secrets` maps declared task secret names to vault URIs:
|
|
70
78
|
|
package/dist/compile.d.ts
CHANGED
package/dist/compile.js
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
ImageStepSchema,
|
|
17
17
|
PlacementSchema as BundlePlacementSchema,
|
|
18
18
|
PlatformSchema,
|
|
19
|
+
QueueSpecSchema,
|
|
19
20
|
ResourcesSchema,
|
|
20
21
|
RunSchema,
|
|
21
22
|
SandboxSpecSchema,
|
|
@@ -25,11 +26,16 @@ import {
|
|
|
25
26
|
SourceDirRefSchema,
|
|
26
27
|
SourceFileRefSchema,
|
|
27
28
|
TaskSpecSchema,
|
|
29
|
+
TaskScheduleSpecSchema,
|
|
30
|
+
TaskScheduleWorkspaceSpecSchema,
|
|
28
31
|
UserSchema,
|
|
29
32
|
WorkdirSchema,
|
|
30
33
|
WorkspaceRuntimeBindingSchema
|
|
31
34
|
} from "@helmr/proto";
|
|
32
35
|
|
|
36
|
+
// sdk/typescript/src/schema/payload.ts
|
|
37
|
+
var payloadSchemaValidationErrorBrand = Symbol.for("helmr.sdk.PayloadSchemaValidationError");
|
|
38
|
+
|
|
33
39
|
// sdk/typescript/src/schema/task.ts
|
|
34
40
|
var DEFAULT_MAX_DURATION_SECONDS = 900;
|
|
35
41
|
var MIN_MAX_DURATION_SECONDS = 5;
|
|
@@ -55,8 +61,6 @@ function readOptionalMaxDurationSeconds(value, label = "task maxDuration") {
|
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
// sdk/typescript/src/internal.ts
|
|
58
|
-
var approvalTimeoutErrorBrand = Symbol.for("helmr.sdk.ApprovalTimeoutError");
|
|
59
|
-
var messageTimeoutErrorBrand = Symbol.for("helmr.sdk.MessageTimeoutError");
|
|
60
64
|
var concurrentWaitErrorBrand = Symbol.for("helmr.sdk.ConcurrentWaitError");
|
|
61
65
|
function validateSecretName(name, label = "secret name") {
|
|
62
66
|
if (name.length === 0) {
|
|
@@ -80,6 +84,9 @@ var imageBuilderBrand = Symbol.for("helmr.sdk.ImageBuilder");
|
|
|
80
84
|
var sandboxBuilderBrand = Symbol.for("helmr.sdk.SandboxBuilder");
|
|
81
85
|
var sourceFileRefBrand = Symbol.for("helmr.sdk.SourceFileRef");
|
|
82
86
|
var sourceDirRefBrand = Symbol.for("helmr.sdk.SourceDirRef");
|
|
87
|
+
function defaultTaskQueueName(taskId) {
|
|
88
|
+
return `task/${taskId}`;
|
|
89
|
+
}
|
|
83
90
|
function isImageBuilder(value) {
|
|
84
91
|
return hasBrand(value, imageBuilderBrand);
|
|
85
92
|
}
|
|
@@ -97,8 +104,8 @@ function hasBrand(value, brand) {
|
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
// sdk/typescript/src/compile.ts
|
|
100
|
-
var IMAGE_FORMAT_VERSION =
|
|
101
|
-
var IMAGE_KEY_DOMAIN = `helmr.image.
|
|
107
|
+
var IMAGE_FORMAT_VERSION = 0;
|
|
108
|
+
var IMAGE_KEY_DOMAIN = `helmr.image.v0
|
|
102
109
|
`;
|
|
103
110
|
function compile(opts) {
|
|
104
111
|
const task = opts.task;
|
|
@@ -131,6 +138,12 @@ function compile(opts) {
|
|
|
131
138
|
modulePath: opts.modulePath,
|
|
132
139
|
exportName: opts.exportName ?? "default",
|
|
133
140
|
maxDurationSeconds,
|
|
141
|
+
queue: create(QueueSpecSchema, {
|
|
142
|
+
name: task.queue?.name ?? defaultTaskQueueName(task.id),
|
|
143
|
+
...task.queue?.concurrencyLimit === undefined || task.queue.concurrencyLimit === null ? {} : { concurrencyLimit: task.queue.concurrencyLimit }
|
|
144
|
+
}),
|
|
145
|
+
...task.ttl === undefined ? {} : { ttl: task.ttl },
|
|
146
|
+
schedules: compileTaskSchedules(task.schedule),
|
|
134
147
|
secrets: Object.entries(readSecretDecls(task.secrets)).map(([name, placement]) => create(BundleSecretPlacementSchema, {
|
|
135
148
|
name,
|
|
136
149
|
placement: compilePlacement(placement)
|
|
@@ -138,6 +151,24 @@ function compile(opts) {
|
|
|
138
151
|
})
|
|
139
152
|
});
|
|
140
153
|
}
|
|
154
|
+
function compileTaskSchedules(schedule) {
|
|
155
|
+
if (schedule === undefined) {
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
return [
|
|
159
|
+
create(TaskScheduleSpecSchema, {
|
|
160
|
+
id: "",
|
|
161
|
+
cron: schedule.cron,
|
|
162
|
+
timezone: schedule.timezone ?? "UTC",
|
|
163
|
+
workspace: create(TaskScheduleWorkspaceSpecSchema, {
|
|
164
|
+
repository: schedule.workspace.repository,
|
|
165
|
+
ref: schedule.workspace.ref,
|
|
166
|
+
subpath: schedule.workspace.subpath ?? ""
|
|
167
|
+
}),
|
|
168
|
+
secretBindings: { ...schedule.secretBindings }
|
|
169
|
+
})
|
|
170
|
+
];
|
|
171
|
+
}
|
|
141
172
|
function compilePlacement(placement) {
|
|
142
173
|
if ("env" in placement) {
|
|
143
174
|
return create(BundlePlacementSchema, {
|
package/dist/config.d.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type IdempotencyKeyScope = "global" | "run" | "attempt";
|
|
2
|
+
export type IdempotencyKeyMaterial = string | readonly string[];
|
|
3
|
+
export type IdempotencyKeyCreateOptions = {
|
|
4
|
+
readonly scope?: "global";
|
|
5
|
+
} | {
|
|
6
|
+
readonly scope?: "run";
|
|
7
|
+
readonly runId?: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly scope: "attempt";
|
|
10
|
+
readonly runId: string;
|
|
11
|
+
readonly attemptNumber: number;
|
|
12
|
+
};
|
|
13
|
+
export interface IdempotencyKey {
|
|
14
|
+
readonly value: string;
|
|
15
|
+
readonly key: IdempotencyKeyMaterial;
|
|
16
|
+
readonly scope: IdempotencyKeyScope;
|
|
17
|
+
}
|
|
18
|
+
export type IdempotencyKeyInput = IdempotencyKeyMaterial | IdempotencyKey;
|
|
19
|
+
export interface RunIdempotencyRequestFields {
|
|
20
|
+
readonly idempotency_key?: string;
|
|
21
|
+
readonly idempotency_key_ttl?: string;
|
|
22
|
+
readonly idempotency_key_options?: {
|
|
23
|
+
readonly key: IdempotencyKeyMaterial;
|
|
24
|
+
readonly scope: IdempotencyKeyScope;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare const idempotencyKeys: {
|
|
28
|
+
create(key: IdempotencyKeyMaterial, options?: IdempotencyKeyCreateOptions): IdempotencyKey;
|
|
29
|
+
};
|
|
30
|
+
export declare function runIdempotencyRequestFields(input: IdempotencyKeyInput | undefined, ttl: string | undefined): RunIdempotencyRequestFields;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcurrentWaitError, validateSecretName, type CacheBuilder, type CacheMount, type CacheMountBinding, type EmitContent, type EmitEvent, type ImageBuilder, type ImageRunOptions, type NoPayload, type Placement, type SandboxBuilder, type SecretDecls, type SecretMountBinding, type SourceCapabilities, type SourceDirRef, type SourceDirectoryOptions, type SourceFileRef, type TaskContext, type TaskSource, type TaskWorkspace, type GitHubRefKind, type GitHubPullRequestMetadata, type GitHubTaskSource, type TaskOutput, type TaskPayload, type TaskTriggerPayload, type WaitCapabilities, type WaitForInput, type WaitJson, type WaitOptions, type WaitResolution, type WaitManualOptions, type WaitUntilInput, type WorkspaceCapabilities, type WorkspaceSpec } from "./internal.js";
|
|
2
|
+
import { PayloadSchemaValidationError } from "./schema/payload.js";
|
|
3
|
+
import { idempotencyKeys } from "./idempotency.js";
|
|
4
|
+
export type { IdempotencyKey, IdempotencyKeyCreateOptions, IdempotencyKeyInput, IdempotencyKeyScope } from "./idempotency.js";
|
|
5
|
+
import type { PayloadSchema, StandardSchemaV1 } from "./schema/payload.js";
|
|
2
6
|
import { HelmrClient } from "./runtime/client.js";
|
|
3
|
-
export type {
|
|
7
|
+
export type { ListSchedulesOptions, RetrieveScheduleOptions, Schedule, ScheduleCreateOptions, ScheduleUpdateOptions, SchedulesApi, WaitpointResponseToken, WaitpointTokenRespondOptions, WaitpointTokenCreateOptions, } from "./runtime/client.js";
|
|
4
8
|
import { sandbox } from "./sandbox.js";
|
|
5
9
|
import { defineConfig, type HelmrConfig, type HelmrConfigInput } from "./config.js";
|
|
6
|
-
import { task, type Task, type TaskConfig } from "./task.js";
|
|
10
|
+
import { queue, task, type Task, type TaskConfig, type TaskQueueConfig } from "./task.js";
|
|
11
|
+
import { task as scheduledTask, type ScheduleCron, type ScheduledTaskConfig, type ScheduledTaskPayload } from "./schedules.js";
|
|
7
12
|
import { tasks } from "./trigger.js";
|
|
8
13
|
export { AuthError, RunNotFoundError, TimeoutError, UnsupportedTransportError } from "./runtime/errors.js";
|
|
9
|
-
export {
|
|
10
|
-
export { type LogSnapshot, type ListRunEventsOptions, type ListRunsOptions, type
|
|
11
|
-
export { defineConfig, sandbox, task, tasks };
|
|
12
|
-
export type { HelmrConfig, HelmrConfigInput, Placement, SecretDecls, Task, TaskConfig, TaskOutput, TaskPayload, };
|
|
14
|
+
export { ConcurrentWaitError, PayloadSchemaValidationError };
|
|
15
|
+
export { type LogSnapshot, type ListRunEventsOptions, type ListRunsOptions, type PendingDelayWaitpoint, type PendingManualWaitpoint, type PendingWaitpoint, type RetrieveRunOptions, type RunEvent, type RunEventRecord, type RunEventRecordPage, type RunHandle, type RunSnapshot, type RunStatus, type RunSummary, type RunWaitOptions, type SubscribeRunEventsOptions, type WaitpointRespondOptions, type WaitpointRef, } from "./runtime/run.js";
|
|
16
|
+
export { defineConfig, idempotencyKeys, queue, sandbox, task, tasks };
|
|
17
|
+
export type { HelmrConfig, HelmrConfigInput, Placement, SecretDecls, Task, TaskConfig, TaskQueueConfig, TaskOutput, TaskPayload, TaskTriggerPayload, WaitCapabilities, WaitForInput, WaitJson, WaitOptions, WaitResolution, WaitManualOptions, WaitUntilInput, PayloadSchema, StandardSchemaV1, NoPayload, };
|
|
13
18
|
export declare const image: (id: string) => ImageBuilder;
|
|
14
19
|
export declare const cache: (id: string) => CacheBuilder;
|
|
15
20
|
export declare const source: SourceCapabilities;
|
|
@@ -31,4 +36,17 @@ export declare const runs: {
|
|
|
31
36
|
};
|
|
32
37
|
};
|
|
33
38
|
export declare const waitpoints: import("./runtime/client.js").WaitpointsApi;
|
|
34
|
-
export
|
|
39
|
+
export declare const schedules: Readonly<{
|
|
40
|
+
task: typeof scheduledTask;
|
|
41
|
+
create: (opts: import("./index.js").ScheduleCreateOptions) => Promise<import("./index.js").Schedule>;
|
|
42
|
+
update: (id: string, opts: Omit<import("./index.js").ScheduleCreateOptions, "deduplicationKey"> & {
|
|
43
|
+
readonly externalId?: string;
|
|
44
|
+
} & import("./index.js").RetrieveScheduleOptions) => Promise<import("./index.js").Schedule>;
|
|
45
|
+
list: (opts?: import("./index.js").ListSchedulesOptions | undefined) => Promise<import("./index.js").Schedule[]>;
|
|
46
|
+
retrieve: (id: string, opts?: import("./index.js").RetrieveScheduleOptions | undefined) => Promise<import("./index.js").Schedule>;
|
|
47
|
+
activate: (id: string, opts?: import("./index.js").RetrieveScheduleOptions | undefined) => Promise<import("./index.js").Schedule>;
|
|
48
|
+
deactivate: (id: string, opts?: import("./index.js").RetrieveScheduleOptions | undefined) => Promise<import("./index.js").Schedule>;
|
|
49
|
+
delete: (id: string, opts?: import("./index.js").RetrieveScheduleOptions | undefined) => Promise<void>;
|
|
50
|
+
}>;
|
|
51
|
+
export type { ScheduleCron, ScheduledTaskConfig, ScheduledTaskPayload, };
|
|
52
|
+
export type { CacheBuilder, CacheMount, CacheMountBinding, EmitContent, EmitEvent, ImageBuilder, ImageRunOptions, SandboxBuilder, SecretMountBinding, SourceCapabilities, SourceDirRef, SourceDirectoryOptions, SourceFileRef, WorkspaceCapabilities, WorkspaceSpec, TaskContext, TaskSource, TaskWorkspace, GitHubRefKind, GitHubPullRequestMetadata, GitHubTaskSource, };
|