@eigenpal/sdk 0.7.2 → 0.8.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.
@@ -1,221 +0,0 @@
1
- import type { OperationResult } from '../client';
2
- import type { Client } from '../generated/client';
3
- import {
4
- agentsCreate,
5
- agentsFilesListOrGet,
6
- agentsFilesPut,
7
- agentsFilesUploadBatch,
8
- agentsGet,
9
- agentsList,
10
- agentsTriggersEmailCreateAlias,
11
- agentsTriggersEmailDeleteAlias,
12
- agentsTriggersEmailGet,
13
- agentsTriggersEmailList,
14
- agentsTriggersEmailUpdate,
15
- agentsTriggersEmailUpdateAlias,
16
- agentsUpdate,
17
- agentsVersionsList,
18
- } from '../generated/sdk.gen';
19
- import type {
20
- AgentsTriggersEmailCreateAliasData,
21
- AgentsTriggersEmailCreateAliasResponse,
22
- AgentsTriggersEmailDeleteAliasResponse,
23
- AgentsTriggersEmailGetResponse,
24
- AgentsTriggersEmailListResponse,
25
- AgentsTriggersEmailUpdateAliasData,
26
- AgentsTriggersEmailUpdateAliasResponse,
27
- AgentsTriggersEmailUpdateData,
28
- AgentsTriggersEmailUpdateResponse,
29
- CreateAgentBody,
30
- CreateAgentResponse,
31
- GetAgentResponse,
32
- ListAgentVersionsResponse,
33
- ListAgentsResponse,
34
- PatchAgentBody,
35
- PatchAgentResponse,
36
- } from '../generated/types.gen';
37
-
38
- type Dispatch = <T>(call: () => Promise<OperationResult<T>>) => Promise<T>;
39
-
40
- export interface ListAgentsOptions {
41
- search?: string;
42
- limit?: number;
43
- offset?: number;
44
- signal?: AbortSignal;
45
- }
46
-
47
- export class AgentEmailTriggersResource {
48
- constructor(
49
- private readonly client: Client,
50
- private readonly dispatch: Dispatch
51
- ) {}
52
-
53
- async list(options: { signal?: AbortSignal } = {}): Promise<AgentsTriggersEmailListResponse> {
54
- return this.dispatch(() =>
55
- agentsTriggersEmailList({ client: this.client, signal: options.signal })
56
- );
57
- }
58
-
59
- async get(
60
- agentId: string,
61
- options: { signal?: AbortSignal } = {}
62
- ): Promise<AgentsTriggersEmailGetResponse> {
63
- return this.dispatch(() =>
64
- agentsTriggersEmailGet({
65
- client: this.client,
66
- path: { agentId },
67
- signal: options.signal,
68
- })
69
- );
70
- }
71
-
72
- async update(
73
- agentId: string,
74
- body: AgentsTriggersEmailUpdateData['body'],
75
- options: { signal?: AbortSignal } = {}
76
- ): Promise<AgentsTriggersEmailUpdateResponse> {
77
- return this.dispatch(() =>
78
- agentsTriggersEmailUpdate({
79
- client: this.client,
80
- path: { agentId },
81
- body,
82
- signal: options.signal,
83
- })
84
- );
85
- }
86
-
87
- async createAlias(
88
- agentId: string,
89
- body: AgentsTriggersEmailCreateAliasData['body'],
90
- options: { signal?: AbortSignal } = {}
91
- ): Promise<AgentsTriggersEmailCreateAliasResponse> {
92
- return this.dispatch(() =>
93
- agentsTriggersEmailCreateAlias({
94
- client: this.client,
95
- path: { agentId },
96
- body,
97
- signal: options.signal,
98
- })
99
- );
100
- }
101
-
102
- async updateAlias(
103
- agentId: string,
104
- emailId: string,
105
- body: AgentsTriggersEmailUpdateAliasData['body'],
106
- options: { signal?: AbortSignal } = {}
107
- ): Promise<AgentsTriggersEmailUpdateAliasResponse> {
108
- return this.dispatch(() =>
109
- agentsTriggersEmailUpdateAlias({
110
- client: this.client,
111
- path: { agentId, emailId },
112
- body,
113
- signal: options.signal,
114
- })
115
- );
116
- }
117
-
118
- async deleteAlias(
119
- agentId: string,
120
- emailId: string,
121
- options: { signal?: AbortSignal } = {}
122
- ): Promise<AgentsTriggersEmailDeleteAliasResponse> {
123
- return this.dispatch(() =>
124
- agentsTriggersEmailDeleteAlias({
125
- client: this.client,
126
- path: { agentId, emailId },
127
- signal: options.signal,
128
- })
129
- );
130
- }
131
- }
132
-
133
- export class AgentsResource {
134
- public readonly emailTriggers: AgentEmailTriggersResource;
135
-
136
- constructor(
137
- private readonly client: Client,
138
- private readonly dispatch: Dispatch
139
- ) {
140
- this.emailTriggers = new AgentEmailTriggersResource(client, dispatch);
141
- }
142
-
143
- async list(options: ListAgentsOptions = {}): Promise<ListAgentsResponse> {
144
- const { signal, ...query } = options;
145
- return this.dispatch(() => agentsList({ client: this.client, query, signal }));
146
- }
147
-
148
- async get(agentId: string, options: { signal?: AbortSignal } = {}): Promise<GetAgentResponse> {
149
- return this.dispatch(() =>
150
- agentsGet({ client: this.client, path: { agentId }, signal: options.signal })
151
- );
152
- }
153
-
154
- async listFiles(
155
- agentId: string,
156
- options: { path?: string; prefix?: string; signal?: AbortSignal } = {}
157
- ): Promise<unknown> {
158
- const { signal, ...query } = options;
159
- return this.dispatch(() =>
160
- agentsFilesListOrGet({ client: this.client, path: { agentId }, query, signal })
161
- );
162
- }
163
-
164
- async putFile(
165
- agentId: string,
166
- path: string,
167
- body: Record<string, unknown>,
168
- options: { signal?: AbortSignal } = {}
169
- ): Promise<unknown> {
170
- return this.dispatch(() =>
171
- agentsFilesPut({
172
- client: this.client,
173
- path: { agentId },
174
- query: { path },
175
- body,
176
- signal: options.signal,
177
- })
178
- );
179
- }
180
-
181
- async uploadFiles(
182
- agentId: string,
183
- body: Record<string, unknown>,
184
- options: { signal?: AbortSignal } = {}
185
- ): Promise<unknown> {
186
- return this.dispatch(() =>
187
- agentsFilesUploadBatch({
188
- client: this.client,
189
- path: { agentId },
190
- body,
191
- signal: options.signal,
192
- })
193
- );
194
- }
195
-
196
- async versions(
197
- agentId: string,
198
- options: { signal?: AbortSignal } = {}
199
- ): Promise<ListAgentVersionsResponse> {
200
- return this.dispatch(() =>
201
- agentsVersionsList({ client: this.client, path: { agentId }, signal: options.signal })
202
- );
203
- }
204
-
205
- async create(
206
- body: CreateAgentBody,
207
- options: { signal?: AbortSignal } = {}
208
- ): Promise<CreateAgentResponse> {
209
- return this.dispatch(() => agentsCreate({ client: this.client, body, signal: options.signal }));
210
- }
211
-
212
- async update(
213
- agentId: string,
214
- body: PatchAgentBody,
215
- options: { signal?: AbortSignal } = {}
216
- ): Promise<PatchAgentResponse> {
217
- return this.dispatch(() =>
218
- agentsUpdate({ client: this.client, path: { agentId }, body, signal: options.signal })
219
- );
220
- }
221
- }
@@ -1,142 +0,0 @@
1
- import type { OperationResult } from '../client';
2
- import { EigenpalTimeoutError } from '../errors';
3
- import type { Client } from '../generated/client';
4
- import { runsGet } from '../generated/sdk.gen';
5
- import type { ExecutionStatus, RunsGetResponse } from '../generated/types.gen';
6
- import { buildRunJsonBody, buildRunMultipart, hasFileInput } from '../lib/files';
7
- import type { WorkflowInput } from './workflows';
8
-
9
- export interface RunAndWaitOptions {
10
- /** Workflow version. Default: `"latest"`. */
11
- version?: string;
12
- /** Per-step output overrides for replay. */
13
- overrides?: { steps?: Record<string, Record<string, unknown>> };
14
- /** Polling interval in milliseconds. Default: 2_000. */
15
- pollIntervalMs?: number;
16
- /**
17
- * Total client-side timeout in milliseconds. Default: 5 minutes. Throws
18
- * `EigenpalTimeoutError` if the run hasn't reached a terminal state by then.
19
- */
20
- timeoutMs?: number;
21
- /** AbortSignal to cancel the entire poll loop. */
22
- signal?: AbortSignal;
23
- }
24
-
25
- export type WorkflowRunAndWaitResponse = {
26
- id: string;
27
- status?: ExecutionStatus;
28
- output?: unknown;
29
- error?: string;
30
- };
31
-
32
- const DEFAULT_POLL_INTERVAL_MS = 2_000;
33
- const DEFAULT_RUN_AND_WAIT_TIMEOUT_MS = 5 * 60 * 1000;
34
-
35
- type Dispatch = <T>(call: () => Promise<OperationResult<T>>) => Promise<T>;
36
-
37
- /**
38
- * Workflow execution helper namespace. Retrieval and mutation of existing runs
39
- * lives on `client.runs`; this namespace only keeps `runAndWait` because it
40
- * triggers a workflow before polling.
41
- */
42
- export class WorkflowExecutionsResource {
43
- constructor(
44
- private readonly client: Client,
45
- private readonly dispatch: Dispatch
46
- ) {}
47
-
48
- /**
49
- * Trigger a workflow and poll for completion client-side.
50
- *
51
- * Unlike `client.run(target, input, { waitForCompletion: 60 })`, this helper polls
52
- * indefinitely (up to `timeoutMs`, default 5 min) so it works for runs
53
- * that exceed the server-side 60s sync window. Returns the final
54
- * response with `status`/`output`/`error` populated.
55
- */
56
- async runAndWait(
57
- workflowId: string,
58
- input?: WorkflowInput,
59
- options: RunAndWaitOptions = {}
60
- ): Promise<WorkflowRunAndWaitResponse> {
61
- const pollInterval = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
62
- const timeoutMs = options.timeoutMs ?? DEFAULT_RUN_AND_WAIT_TIMEOUT_MS;
63
- const deadline = Date.now() + timeoutMs;
64
-
65
- const target = `workflows.${workflowId}`;
66
- const runUrl = '/api/v1/runs';
67
- const runQuery =
68
- options.version && options.version !== 'latest' ? { version: options.version } : undefined;
69
- let runResult: { id: string };
70
- if (hasFileInput(input)) {
71
- // Build the multipart body once, up front — `dispatch` may retry the
72
- // POST, and a drained stream cannot be replayed.
73
- const { formData } = await buildRunMultipart({
74
- target,
75
- input,
76
- overrides: options.overrides,
77
- });
78
- runResult = await this.dispatch<{ id: string }>(
79
- () =>
80
- this.client.post({
81
- url: runUrl,
82
- query: runQuery,
83
- body: formData,
84
- bodySerializer: null,
85
- headers: { 'Content-Type': null },
86
- signal: options.signal,
87
- }) as Promise<OperationResult<{ id: string }>>
88
- );
89
- } else {
90
- const body = buildRunJsonBody(target, input, options.overrides);
91
- runResult = await this.dispatch<{ id: string }>(
92
- () =>
93
- this.client.post({
94
- url: runUrl,
95
- query: runQuery,
96
- body,
97
- signal: options.signal,
98
- }) as Promise<OperationResult<{ id: string }>>
99
- );
100
- }
101
-
102
- const runId = runResult.id;
103
-
104
- while (true) {
105
- if (options.signal?.aborted) {
106
- throw new EigenpalTimeoutError('runAndWait aborted');
107
- }
108
- if (Date.now() >= deadline) {
109
- throw new EigenpalTimeoutError(
110
- `runAndWait timed out after ${timeoutMs}ms (runId=${runId})`
111
- );
112
- }
113
-
114
- const run = (await this.dispatch<RunsGetResponse>(
115
- () =>
116
- runsGet({
117
- client: this.client,
118
- path: { id: runId },
119
- query: { expand: 'execution' },
120
- signal: options.signal,
121
- }) as Promise<OperationResult<RunsGetResponse>>
122
- )) as {
123
- finished?: boolean;
124
- output?: unknown;
125
- error?: string | null;
126
- execution?: { status?: ExecutionStatus | null } | null;
127
- };
128
-
129
- const status = run.execution?.status;
130
- if (run.finished) {
131
- return {
132
- id: runId,
133
- status: status ?? 'completed',
134
- ...(run.output != null ? { output: run.output } : {}),
135
- ...(run.error != null ? { error: run.error } : {}),
136
- };
137
- }
138
-
139
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
140
- }
141
- }
142
- }
@@ -1,101 +0,0 @@
1
- import type { OperationResult } from '../client';
2
- import type { Client } from '../generated/client';
3
- import {
4
- sourceLockfilePreview,
5
- sourceRaw,
6
- sourceReleases,
7
- sourceRepository,
8
- sourceSecretsDecrypt,
9
- sourceSecretsEncrypt,
10
- } from '../generated/sdk.gen';
11
- import type {
12
- RawSourceResponse,
13
- SourceLockfileResponse,
14
- SourceReleasesResponse,
15
- SourceRepositoryResponse,
16
- SourceSecretsDecryptBody,
17
- SourceSecretsDecryptResponse,
18
- SourceSecretsEncryptBody,
19
- SourceSecretsEncryptResponse,
20
- } from '../generated/types.gen';
21
-
22
- type Dispatch = <T>(call: () => Promise<OperationResult<T>>) => Promise<T>;
23
-
24
- export interface SourceRawOptions {
25
- ref?: string;
26
- signal?: AbortSignal;
27
- }
28
-
29
- export interface SourceReleasesOptions {
30
- version?: string;
31
- signal?: AbortSignal;
32
- }
33
-
34
- export class SourceResource {
35
- constructor(
36
- private readonly client: Client,
37
- private readonly dispatch: Dispatch
38
- ) {}
39
-
40
- async repository(options: { signal?: AbortSignal } = {}): Promise<SourceRepositoryResponse> {
41
- return this.dispatch(() => sourceRepository({ client: this.client, signal: options.signal }));
42
- }
43
-
44
- async raw(path: string, options: SourceRawOptions = {}): Promise<RawSourceResponse> {
45
- const { signal, ref = 'main' } = options;
46
- return this.dispatch(() => sourceRaw({ client: this.client, query: { path, ref }, signal }));
47
- }
48
-
49
- async releases(
50
- packagePath: string,
51
- options: SourceReleasesOptions = {}
52
- ): Promise<SourceReleasesResponse> {
53
- const { signal, version } = options;
54
- return this.dispatch(() =>
55
- sourceReleases({
56
- client: this.client,
57
- query: { packagePath, ...(version !== undefined ? { version } : {}) },
58
- signal,
59
- })
60
- );
61
- }
62
-
63
- async lockfile(
64
- packageRef: string,
65
- options: { signal?: AbortSignal } = {}
66
- ): Promise<SourceLockfileResponse> {
67
- return this.dispatch(() =>
68
- sourceLockfilePreview({
69
- client: this.client,
70
- query: { packageRef },
71
- signal: options.signal,
72
- })
73
- );
74
- }
75
-
76
- async decryptSecrets(
77
- body: SourceSecretsDecryptBody,
78
- options: { signal?: AbortSignal } = {}
79
- ): Promise<SourceSecretsDecryptResponse> {
80
- return this.dispatch(() =>
81
- sourceSecretsDecrypt({
82
- client: this.client,
83
- body,
84
- signal: options.signal,
85
- })
86
- );
87
- }
88
-
89
- async encryptSecrets(
90
- body: SourceSecretsEncryptBody,
91
- options: { signal?: AbortSignal } = {}
92
- ): Promise<SourceSecretsEncryptResponse> {
93
- return this.dispatch(() =>
94
- sourceSecretsEncrypt({
95
- client: this.client,
96
- body,
97
- signal: options.signal,
98
- })
99
- );
100
- }
101
- }
@@ -1,82 +0,0 @@
1
- import type { OperationResult } from '../client';
2
- import type { Client } from '../generated/client';
3
- import { workflowsGet, workflowsList, workflowsVersionsList } from '../generated/sdk.gen';
4
- import type {
5
- ListVersionsResponse,
6
- ListWorkflowsResponse,
7
- WorkflowDetail,
8
- } from '../generated/types.gen';
9
- import { WorkflowExecutionsResource } from './executions';
10
-
11
- /**
12
- * Workflow inputs keyed by name as declared in the workflow YAML.
13
- *
14
- * File values (`File`, `Blob`, or `{ content, filename, mimeType }`) are
15
- * detected automatically and uploaded as `multipart/form-data` — same as
16
- * `curl -F`. No base64 round-trip required.
17
- */
18
- export type WorkflowInput = Record<string, unknown>;
19
-
20
- export interface ListWorkflowsOptions {
21
- /** Substring match against workflow name. */
22
- search?: string;
23
- /** Exact-match by workflow name (slug). */
24
- name?: string;
25
- kind?: 'workflow' | 'block';
26
- limit?: number;
27
- offset?: number;
28
- signal?: AbortSignal;
29
- }
30
-
31
- export interface ListVersionsOptions {
32
- limit?: number;
33
- offset?: number;
34
- signal?: AbortSignal;
35
- }
36
-
37
- type Dispatch = <T>(call: () => Promise<OperationResult<T>>) => Promise<T>;
38
-
39
- /**
40
- * Workflow resource — list, get, and inspect versions of saved workflows.
41
- * Existing run retrieval and mutation lives on `client.runs`.
42
- * Starting runs lives on root `client.run(...)`.
43
- */
44
- export class WorkflowsResource {
45
- public readonly executions: WorkflowExecutionsResource;
46
-
47
- constructor(
48
- private readonly client: Client,
49
- private readonly dispatch: Dispatch
50
- ) {
51
- this.executions = new WorkflowExecutionsResource(client, dispatch);
52
- }
53
-
54
- /** List workflows, paginated. */
55
- async list(options: ListWorkflowsOptions = {}): Promise<ListWorkflowsResponse> {
56
- const { signal, ...query } = options;
57
- return this.dispatch(() => workflowsList({ client: this.client, query, signal }));
58
- }
59
-
60
- /** Get a single workflow by id. Includes the current version's YAML. */
61
- async get(workflowId: string, options: { signal?: AbortSignal } = {}): Promise<WorkflowDetail> {
62
- return this.dispatch(() =>
63
- workflowsGet({ client: this.client, path: { id: workflowId }, signal: options.signal })
64
- );
65
- }
66
-
67
- /** List tagged versions for a workflow, paginated. */
68
- async versions(
69
- workflowId: string,
70
- options: ListVersionsOptions = {}
71
- ): Promise<ListVersionsResponse> {
72
- const { signal, ...query } = options;
73
- return this.dispatch(() =>
74
- workflowsVersionsList({
75
- client: this.client,
76
- path: { id: workflowId },
77
- query,
78
- signal,
79
- })
80
- );
81
- }
82
- }