@helmr/sdk 0.1.1-rc.1 → 0.1.1-rc.2
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/dist/index.d.ts +1 -0
- package/dist/index.js +56 -5
- package/dist/internal.d.ts +2 -0
- package/dist/runtime/client.d.ts +48 -1
- package/dist/runtime/run.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApprovalTimeoutError, ConcurrentWaitError, MessageTimeoutError, validateSecretName, type CacheBuilder, type CacheMount, type CacheMountBinding, type EmitContent, type EmitEvent, type ImageBuilder, type ImageRunOptions, type Placement, type SandboxBuilder, type SecretDecls, type SecretMountBinding, type SourceCapabilities, type SourceDirRef, type SourceDirectoryOptions, type SourceFileRef, type TaskContext, type TaskOutput, type TaskPayload, type WorkspaceCapabilities, type WorkspaceSpec } from "./internal.js";
|
|
2
2
|
import { HelmrClient } from "./runtime/client.js";
|
|
3
|
+
export type { WaitpointResponseToken, WaitpointTokenAction, WaitpointTokenCompleteOptions, WaitpointTokenCreateOptions, } from "./runtime/client.js";
|
|
3
4
|
import { sandbox } from "./sandbox.js";
|
|
4
5
|
import { defineConfig, type HelmrConfig, type HelmrConfigInput } from "./config.js";
|
|
5
6
|
import { task, type Task, type TaskConfig } from "./task.js";
|
package/dist/index.js
CHANGED
|
@@ -380,7 +380,7 @@ function runId(value) {
|
|
|
380
380
|
function runStateBooleans(status) {
|
|
381
381
|
return {
|
|
382
382
|
isQueued: status === "queued",
|
|
383
|
-
isRunning: status === "
|
|
383
|
+
isRunning: status === "running",
|
|
384
384
|
isWaiting: status === "waiting",
|
|
385
385
|
isTerminal: isTerminalRunStatus(status),
|
|
386
386
|
isSuccess: status === "succeeded",
|
|
@@ -391,7 +391,6 @@ function runStateBooleans(status) {
|
|
|
391
391
|
function runStatus(status) {
|
|
392
392
|
switch (status) {
|
|
393
393
|
case "queued":
|
|
394
|
-
case "claimed":
|
|
395
394
|
case "running":
|
|
396
395
|
case "waiting":
|
|
397
396
|
case "succeeded":
|
|
@@ -430,9 +429,6 @@ class HelmrClient {
|
|
|
430
429
|
throw new UnsupportedTransportError("HelmrClient requires an http(s) URL");
|
|
431
430
|
}
|
|
432
431
|
if (parsedUrl.protocol === "https:") {
|
|
433
|
-
if (apiKey === undefined || apiKey === "") {
|
|
434
|
-
throw new AuthError("HelmrClient https:// transport requires apiKey or HELMR_API_KEY");
|
|
435
|
-
}
|
|
436
432
|
this.#baseUrl = normalizedBaseUrl(parsedUrl);
|
|
437
433
|
this.#apiKey = apiKey;
|
|
438
434
|
} else if (parsedUrl.protocol === "http:") {
|
|
@@ -539,6 +535,25 @@ class HelmrClient {
|
|
|
539
535
|
body: JSON.stringify({ text: resolved.opts.text, attachments: [] }),
|
|
540
536
|
headers: { "content-type": "application/json" }
|
|
541
537
|
});
|
|
538
|
+
},
|
|
539
|
+
tokens: {
|
|
540
|
+
create: async (target, waitpointIdOrOpts, opts = {}) => {
|
|
541
|
+
const resolved = resolveWaitpointArgs(target, waitpointIdOrOpts, opts);
|
|
542
|
+
const response = await this.#json("/api/waitpoints/tokens", {
|
|
543
|
+
method: "POST",
|
|
544
|
+
body: JSON.stringify(waitpointTokenCreateBody(resolved.runId, resolved.waitpointId, resolved.opts)),
|
|
545
|
+
headers: { "content-type": "application/json" }
|
|
546
|
+
});
|
|
547
|
+
return waitpointResponseTokenFromResponse(response);
|
|
548
|
+
},
|
|
549
|
+
complete: async (target, tokenOrOpts, maybeOpts) => {
|
|
550
|
+
const resolved = typeof target === "string" ? resolveWaitpointTokenCompleteArgs(target, tokenOrOpts, maybeOpts) : { id: target.id, token: target.token, opts: tokenOrOpts };
|
|
551
|
+
await this.#fetch(`/api/waitpoints/tokens/${encodeURIComponent(resolved.id)}/complete`, {
|
|
552
|
+
method: "POST",
|
|
553
|
+
body: JSON.stringify(waitpointTokenCompleteBody(resolved.token, resolved.opts)),
|
|
554
|
+
headers: { "content-type": "application/json" }
|
|
555
|
+
});
|
|
556
|
+
}
|
|
542
557
|
}
|
|
543
558
|
};
|
|
544
559
|
async#retrieveLogs(id, signal) {
|
|
@@ -649,6 +664,42 @@ function runResponseToSnapshot(response) {
|
|
|
649
664
|
function approvalBody(opts) {
|
|
650
665
|
return opts.reason === undefined ? {} : { reason: opts.reason };
|
|
651
666
|
}
|
|
667
|
+
function waitpointTokenCreateBody(runId2, waitpointId, opts) {
|
|
668
|
+
return {
|
|
669
|
+
run_id: runId2,
|
|
670
|
+
waitpoint_id: waitpointId,
|
|
671
|
+
...opts.actions === undefined ? {} : { actions: opts.actions },
|
|
672
|
+
...opts.expiresInSeconds === undefined ? {} : { expires_in_seconds: opts.expiresInSeconds },
|
|
673
|
+
...opts.expiresAt === undefined ? {} : { expires_at: opts.expiresAt },
|
|
674
|
+
...opts.metadata === undefined ? {} : { metadata: opts.metadata }
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function waitpointTokenCompleteBody(token, opts) {
|
|
678
|
+
return {
|
|
679
|
+
token,
|
|
680
|
+
action: opts.action,
|
|
681
|
+
..."reason" in opts && opts.reason === undefined ? {} : ("reason" in opts) ? { reason: opts.reason } : {},
|
|
682
|
+
..."text" in opts ? { text: opts.text } : {},
|
|
683
|
+
...opts.externalSubject === undefined ? {} : { external_subject: opts.externalSubject },
|
|
684
|
+
...opts.metadata === undefined ? {} : { metadata: opts.metadata }
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
function resolveWaitpointTokenCompleteArgs(id, token, opts) {
|
|
688
|
+
if (typeof token !== "string" || opts === undefined) {
|
|
689
|
+
throw new Error("waitpoint token secret is required when completing by token id");
|
|
690
|
+
}
|
|
691
|
+
return { id, token, opts };
|
|
692
|
+
}
|
|
693
|
+
function waitpointResponseTokenFromResponse(response) {
|
|
694
|
+
return {
|
|
695
|
+
id: response.id,
|
|
696
|
+
runId: response.run_id,
|
|
697
|
+
waitpointId: response.waitpoint_id,
|
|
698
|
+
url: response.url,
|
|
699
|
+
token: response.token,
|
|
700
|
+
expiresAt: response.expires_at ?? null
|
|
701
|
+
};
|
|
702
|
+
}
|
|
652
703
|
function resolveWaitpointArgs(target, waitpointIdOrOpts, opts) {
|
|
653
704
|
if (isWaitpointRef(target)) {
|
|
654
705
|
const resolvedOpts = waitpointIdOrOpts !== undefined && typeof waitpointIdOrOpts !== "string" ? waitpointIdOrOpts : opts;
|
package/dist/internal.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ export interface TaskContext {
|
|
|
65
65
|
readonly wait: {
|
|
66
66
|
approval(message: string, opts?: {
|
|
67
67
|
readonly timeout?: number;
|
|
68
|
+
readonly policy?: string;
|
|
68
69
|
}): Promise<{
|
|
69
70
|
readonly approved: boolean;
|
|
70
71
|
readonly approvedBy: string;
|
|
@@ -72,6 +73,7 @@ export interface TaskContext {
|
|
|
72
73
|
}>;
|
|
73
74
|
message(prompt?: string, opts?: {
|
|
74
75
|
readonly timeout?: number;
|
|
76
|
+
readonly policy?: string;
|
|
75
77
|
}): Promise<{
|
|
76
78
|
readonly text: string;
|
|
77
79
|
readonly sentBy: string;
|
package/dist/runtime/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SecretDecls, type Task, type WorkspaceSpec } from "../internal.js";
|
|
2
|
-
import { type LogSnapshot, type ListRunEventsOptions, type ListRunsOptions, type PendingApprovalWaitpoint, type PendingMessageWaitpoint, type PendingWaitpointResponse, type RetrieveRunOptions, type RunHandle, type RunEvent, type RunSnapshot, type RunSummary, type RunWaitOptions, type SubscribeRunEventsOptions, type WaitpointApprovalOptions, type WaitpointReplyOptions } from "./run.js";
|
|
2
|
+
import { type LogSnapshot, type ListRunEventsOptions, type ListRunsOptions, type PendingApprovalWaitpoint, type PendingMessageWaitpoint, type PendingWaitpoint, type PendingWaitpointResponse, type RetrieveRunOptions, type RunHandle, type RunEvent, type RunSnapshot, type RunSummary, type RunWaitOptions, type SubscribeRunEventsOptions, type WaitpointApprovalOptions, type WaitpointRef, type WaitpointReplyOptions } from "./run.js";
|
|
3
3
|
export interface HelmrClientOptions {
|
|
4
4
|
readonly url?: string;
|
|
5
5
|
readonly apiKey?: string;
|
|
@@ -34,7 +34,53 @@ export interface WaitpointsApi {
|
|
|
34
34
|
(target: PendingMessageWaitpoint, opts: WaitpointReplyOptions): Promise<void>;
|
|
35
35
|
(runId: string, waitpointId: string, opts: WaitpointReplyOptions): Promise<void>;
|
|
36
36
|
};
|
|
37
|
+
readonly tokens: {
|
|
38
|
+
readonly create: {
|
|
39
|
+
(target: PendingWaitpoint | WaitpointRef, opts?: WaitpointTokenCreateOptions): Promise<WaitpointResponseToken>;
|
|
40
|
+
(runId: string, waitpointId: string, opts?: WaitpointTokenCreateOptions): Promise<WaitpointResponseToken>;
|
|
41
|
+
};
|
|
42
|
+
readonly complete: {
|
|
43
|
+
(token: WaitpointResponseToken, opts: WaitpointTokenCompleteOptions): Promise<void>;
|
|
44
|
+
(id: string, token: string, opts: WaitpointTokenCompleteOptions): Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export type WaitpointTokenAction = "approve" | "deny" | "message" | "reply";
|
|
49
|
+
type WaitpointTokenExpirationOptions = {
|
|
50
|
+
readonly expiresInSeconds?: number;
|
|
51
|
+
readonly expiresAt?: never;
|
|
52
|
+
} | {
|
|
53
|
+
readonly expiresInSeconds?: never;
|
|
54
|
+
readonly expiresAt?: string;
|
|
55
|
+
};
|
|
56
|
+
export type WaitpointTokenCreateOptions = WaitpointTokenExpirationOptions & {
|
|
57
|
+
readonly actions?: readonly WaitpointTokenAction[];
|
|
58
|
+
readonly metadata?: Record<string, unknown>;
|
|
59
|
+
};
|
|
60
|
+
export interface WaitpointResponseToken {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
readonly runId: string;
|
|
63
|
+
readonly waitpointId: string;
|
|
64
|
+
readonly url: string;
|
|
65
|
+
readonly token: string;
|
|
66
|
+
readonly expiresAt: string | null;
|
|
37
67
|
}
|
|
68
|
+
export type WaitpointTokenCompleteOptions = {
|
|
69
|
+
readonly action: "approve";
|
|
70
|
+
readonly reason?: string;
|
|
71
|
+
readonly externalSubject?: string;
|
|
72
|
+
readonly metadata?: Record<string, unknown>;
|
|
73
|
+
} | {
|
|
74
|
+
readonly action: "deny";
|
|
75
|
+
readonly reason?: string;
|
|
76
|
+
readonly externalSubject?: string;
|
|
77
|
+
readonly metadata?: Record<string, unknown>;
|
|
78
|
+
} | {
|
|
79
|
+
readonly action: "message" | "reply";
|
|
80
|
+
readonly text: string;
|
|
81
|
+
readonly externalSubject?: string;
|
|
82
|
+
readonly metadata?: Record<string, unknown>;
|
|
83
|
+
};
|
|
38
84
|
export declare class HelmrClient {
|
|
39
85
|
#private;
|
|
40
86
|
constructor(options?: HelmrClientOptions);
|
|
@@ -72,3 +118,4 @@ export interface RunResponse {
|
|
|
72
118
|
export interface ListRunsResponse {
|
|
73
119
|
readonly runs: readonly RunResponse[];
|
|
74
120
|
}
|
|
121
|
+
export {};
|
package/dist/runtime/run.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type RunStatus = "queued" | "
|
|
1
|
+
export type RunStatus = "queued" | "running" | "waiting" | "succeeded" | "failed" | "cancelled";
|
|
2
2
|
declare const runOutputBrand: unique symbol;
|
|
3
3
|
export interface RunHandle<TOutput = unknown> {
|
|
4
4
|
readonly id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helmr/sdk",
|
|
3
|
-
"version": "0.1.1-rc.
|
|
3
|
+
"version": "0.1.1-rc.2",
|
|
4
4
|
"description": "TypeScript SDK for authoring and triggering Helmr tasks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@bufbuild/protobuf": "^2.11.0",
|
|
46
|
-
"@helmr/proto": "0.1.1-rc.
|
|
46
|
+
"@helmr/proto": "0.1.1-rc.2"
|
|
47
47
|
}
|
|
48
48
|
}
|