@sapiom/agent-core 0.6.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/CHANGELOG.md +246 -0
- package/LICENSE +21 -0
- package/dist/cjs/__tests__/execution-detail.wire.fixture.json +101 -0
- package/dist/cjs/__tests__/execution-projection.preseam.fixture.json +37 -0
- package/dist/cjs/__tests__/execution-projection.with-cost.fixture.json +60 -0
- package/dist/cjs/bundle.d.ts +5 -0
- package/dist/cjs/bundle.js +134 -0
- package/dist/cjs/check.d.ts +10 -0
- package/dist/cjs/check.js +154 -0
- package/dist/cjs/client.d.ts +21 -0
- package/dist/cjs/client.js +108 -0
- package/dist/cjs/clone.d.ts +17 -0
- package/dist/cjs/clone.js +71 -0
- package/dist/cjs/config.d.ts +16 -0
- package/dist/cjs/config.js +40 -0
- package/dist/cjs/decode.d.ts +4 -0
- package/dist/cjs/decode.js +172 -0
- package/dist/cjs/deploy.d.ts +12 -0
- package/dist/cjs/deploy.js +67 -0
- package/dist/cjs/errors.d.ts +15 -0
- package/dist/cjs/errors.js +23 -0
- package/dist/cjs/git.d.ts +12 -0
- package/dist/cjs/git.js +76 -0
- package/dist/cjs/index.d.ts +41 -0
- package/dist/cjs/index.js +72 -0
- package/dist/cjs/inspect.d.ts +40 -0
- package/dist/cjs/inspect.js +99 -0
- package/dist/cjs/link.d.ts +15 -0
- package/dist/cjs/link.js +19 -0
- package/dist/cjs/local/dispatcher.d.ts +37 -0
- package/dist/cjs/local/dispatcher.js +149 -0
- package/dist/cjs/local/load.d.ts +6 -0
- package/dist/cjs/local/load.js +102 -0
- package/dist/cjs/local/run-local.d.ts +32 -0
- package/dist/cjs/local/run-local.js +95 -0
- package/dist/cjs/local/stubs.d.ts +8 -0
- package/dist/cjs/local/stubs.js +35 -0
- package/dist/cjs/run.d.ts +11 -0
- package/dist/cjs/run.js +29 -0
- package/dist/cjs/scaffold.d.ts +24 -0
- package/dist/cjs/scaffold.js +190 -0
- package/dist/cjs/schedule.d.ts +67 -0
- package/dist/cjs/schedule.js +33 -0
- package/dist/cjs/signal.d.ts +12 -0
- package/dist/cjs/signal.js +24 -0
- package/dist/cjs/types.d.ts +99 -0
- package/dist/cjs/types.js +11 -0
- package/dist/cjs/watch.d.ts +10 -0
- package/dist/cjs/watch.js +101 -0
- package/dist/esm/__tests__/execution-detail.wire.fixture.json +101 -0
- package/dist/esm/__tests__/execution-projection.preseam.fixture.json +37 -0
- package/dist/esm/__tests__/execution-projection.with-cost.fixture.json +60 -0
- package/dist/esm/bundle.d.ts +5 -0
- package/dist/esm/bundle.js +95 -0
- package/dist/esm/check.d.ts +10 -0
- package/dist/esm/check.js +115 -0
- package/dist/esm/client.d.ts +21 -0
- package/dist/esm/client.js +103 -0
- package/dist/esm/clone.d.ts +17 -0
- package/dist/esm/clone.js +65 -0
- package/dist/esm/config.d.ts +16 -0
- package/dist/esm/config.js +31 -0
- package/dist/esm/decode.d.ts +4 -0
- package/dist/esm/decode.js +167 -0
- package/dist/esm/deploy.d.ts +12 -0
- package/dist/esm/deploy.js +61 -0
- package/dist/esm/errors.d.ts +15 -0
- package/dist/esm/errors.js +19 -0
- package/dist/esm/git.d.ts +12 -0
- package/dist/esm/git.js +69 -0
- package/dist/esm/index.d.ts +41 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/inspect.d.ts +40 -0
- package/dist/esm/inspect.js +92 -0
- package/dist/esm/link.d.ts +15 -0
- package/dist/esm/link.js +16 -0
- package/dist/esm/local/dispatcher.d.ts +37 -0
- package/dist/esm/local/dispatcher.js +145 -0
- package/dist/esm/local/load.d.ts +6 -0
- package/dist/esm/local/load.js +63 -0
- package/dist/esm/local/run-local.d.ts +32 -0
- package/dist/esm/local/run-local.js +87 -0
- package/dist/esm/local/stubs.d.ts +8 -0
- package/dist/esm/local/stubs.js +31 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/run.d.ts +11 -0
- package/dist/esm/run.js +25 -0
- package/dist/esm/scaffold.d.ts +24 -0
- package/dist/esm/scaffold.js +179 -0
- package/dist/esm/schedule.d.ts +67 -0
- package/dist/esm/schedule.js +26 -0
- package/dist/esm/signal.d.ts +12 -0
- package/dist/esm/signal.js +20 -0
- package/dist/esm/types.d.ts +99 -0
- package/dist/esm/types.js +8 -0
- package/dist/esm/watch.d.ts +10 -0
- package/dist/esm/watch.js +96 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +73 -0
- package/templates/coding-pause/AGENTS.md +48 -0
- package/templates/coding-pause/CLAUDE.md +7 -0
- package/templates/coding-pause/README.md +53 -0
- package/templates/coding-pause/_gitignore +3 -0
- package/templates/coding-pause/index.ts +109 -0
- package/templates/coding-pause/package.json +21 -0
- package/templates/coding-pause/tsconfig.json +12 -0
- package/templates/default/AGENTS.md +48 -0
- package/templates/default/CLAUDE.md +7 -0
- package/templates/default/README.md +30 -0
- package/templates/default/_gitignore +3 -0
- package/templates/default/index.ts +26 -0
- package/templates/default/package.json +21 -0
- package/templates/default/tsconfig.json +12 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deploy = deploy;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_os_1 = require("node:os");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const bundle_js_1 = require("./bundle.js");
|
|
11
|
+
const errors_js_1 = require("./errors.js");
|
|
12
|
+
const git_js_1 = require("./git.js");
|
|
13
|
+
const TERMINAL = new Set(['ready', 'failed', 'cancelled', 'superseded']);
|
|
14
|
+
const POLL_DELAYS_MS = [1000, 2000, 3000, 5000, 5000, 8000, 10000];
|
|
15
|
+
const POLL_BUDGET_MS = 300000;
|
|
16
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
17
|
+
async function deploy(opts, client) {
|
|
18
|
+
const { projectDir, definitionId, branch = 'main' } = opts;
|
|
19
|
+
(0, git_js_1.assertDeployable)(projectDir);
|
|
20
|
+
const { code, dependencies } = await (0, bundle_js_1.bundleForDeploy)(projectDir);
|
|
21
|
+
const { pushUrl } = await client.post(`/definitions/${definitionId}/push-credentials`, {});
|
|
22
|
+
const treeDir = (0, node_fs_1.mkdtempSync)(node_path_1.default.join((0, node_os_1.tmpdir)(), 'sapiom-deploy-'));
|
|
23
|
+
try {
|
|
24
|
+
(0, node_fs_1.writeFileSync)(node_path_1.default.join(treeDir, 'index.ts'), code);
|
|
25
|
+
(0, node_fs_1.writeFileSync)(node_path_1.default.join(treeDir, 'package.json'), JSON.stringify({ name: 'agent-definition', private: true, type: 'module', dependencies }, null, 2) + '\n');
|
|
26
|
+
(0, git_js_1.pushSynthesizedTree)(treeDir, pushUrl, branch);
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
(0, node_fs_1.rmSync)(treeDir, { recursive: true, force: true });
|
|
30
|
+
}
|
|
31
|
+
const triggered = await client.post(`/definitions/${definitionId}/builds`, {});
|
|
32
|
+
const buildRunId = triggered.buildRunId ?? triggered.id;
|
|
33
|
+
if (!buildRunId) {
|
|
34
|
+
throw new errors_js_1.AgentOperationError({
|
|
35
|
+
code: 'BUILD_NO_ID',
|
|
36
|
+
message: 'The build was triggered but no build id was returned.',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const final = await pollBuild(client, definitionId, buildRunId);
|
|
40
|
+
if (final.status !== 'ready') {
|
|
41
|
+
throw new errors_js_1.AgentOperationError({
|
|
42
|
+
code: 'BUILD_FAILED',
|
|
43
|
+
message: `Build ${final.status}.`,
|
|
44
|
+
step: 'build',
|
|
45
|
+
hint: final.error?.stack || final.error?.message,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return { definitionId, buildRunId, status: final.status };
|
|
49
|
+
}
|
|
50
|
+
async function pollBuild(client, definitionId, buildRunId) {
|
|
51
|
+
let elapsed = 0;
|
|
52
|
+
let i = 0;
|
|
53
|
+
while (elapsed < POLL_BUDGET_MS) {
|
|
54
|
+
const build = await client.get(`/definitions/${definitionId}/builds/${buildRunId}`);
|
|
55
|
+
if (TERMINAL.has(build.status))
|
|
56
|
+
return build;
|
|
57
|
+
const delay = POLL_DELAYS_MS[Math.min(i++, POLL_DELAYS_MS.length - 1)];
|
|
58
|
+
await sleep(delay);
|
|
59
|
+
elapsed += delay;
|
|
60
|
+
}
|
|
61
|
+
throw new errors_js_1.AgentOperationError({
|
|
62
|
+
code: 'BUILD_TIMEOUT',
|
|
63
|
+
message: 'Build did not finish in time.',
|
|
64
|
+
step: 'build',
|
|
65
|
+
hint: `Check it later via the logs API for build ${buildRunId}`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface StructuredError {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
step?: string;
|
|
5
|
+
hint?: string;
|
|
6
|
+
docsUrl?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class AgentOperationError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly step?: string;
|
|
11
|
+
readonly hint?: string;
|
|
12
|
+
readonly docsUrl?: string;
|
|
13
|
+
constructor(err: StructuredError);
|
|
14
|
+
toStructured(): StructuredError;
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentOperationError = void 0;
|
|
4
|
+
class AgentOperationError extends Error {
|
|
5
|
+
constructor(err) {
|
|
6
|
+
super(err.message);
|
|
7
|
+
this.name = 'AgentOperationError';
|
|
8
|
+
this.code = err.code;
|
|
9
|
+
this.step = err.step;
|
|
10
|
+
this.hint = err.hint;
|
|
11
|
+
this.docsUrl = err.docsUrl;
|
|
12
|
+
}
|
|
13
|
+
toStructured() {
|
|
14
|
+
return {
|
|
15
|
+
code: this.code,
|
|
16
|
+
message: this.message,
|
|
17
|
+
...(this.step ? { step: this.step } : {}),
|
|
18
|
+
...(this.hint ? { hint: this.hint } : {}),
|
|
19
|
+
...(this.docsUrl ? { docsUrl: this.docsUrl } : {}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AgentOperationError = AgentOperationError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function assertDeployable(dir: string): void;
|
|
2
|
+
export declare function redactCredentials(text: string): string;
|
|
3
|
+
export interface CloneRepoOptions {
|
|
4
|
+
cloneUrl: string;
|
|
5
|
+
targetDir: string;
|
|
6
|
+
branch: string;
|
|
7
|
+
repoFullName: string;
|
|
8
|
+
cwd: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function cloneRepo(opts: CloneRepoOptions): void;
|
|
11
|
+
export declare function pushHead(dir: string, pushUrl: string, branch: string): void;
|
|
12
|
+
export declare function pushSynthesizedTree(treeDir: string, pushUrl: string, branch: string): void;
|
package/dist/cjs/git.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertDeployable = assertDeployable;
|
|
4
|
+
exports.redactCredentials = redactCredentials;
|
|
5
|
+
exports.cloneRepo = cloneRepo;
|
|
6
|
+
exports.pushHead = pushHead;
|
|
7
|
+
exports.pushSynthesizedTree = pushSynthesizedTree;
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
const errors_js_1 = require("./errors.js");
|
|
10
|
+
function git(args, cwd) {
|
|
11
|
+
try {
|
|
12
|
+
return (0, node_child_process_1.execFileSync)('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
const stderr = err.stderr?.toString().trim();
|
|
16
|
+
throw new errors_js_1.AgentOperationError({
|
|
17
|
+
code: 'GIT',
|
|
18
|
+
message: `git ${args[0]} failed.`,
|
|
19
|
+
hint: stderr || (err instanceof Error ? err.message : String(err)),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function assertDeployable(dir) {
|
|
24
|
+
try {
|
|
25
|
+
(0, node_child_process_1.execFileSync)('git', ['rev-parse', '--is-inside-work-tree'], { cwd: dir, stdio: 'ignore' });
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new errors_js_1.AgentOperationError({
|
|
29
|
+
code: 'NOT_GIT',
|
|
30
|
+
message: 'Not a git repository.',
|
|
31
|
+
hint: 'Initialize one: git init && git add -A && git commit -m "init"',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
(0, node_child_process_1.execFileSync)('git', ['rev-parse', 'HEAD'], { cwd: dir, stdio: 'ignore' });
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new errors_js_1.AgentOperationError({
|
|
39
|
+
code: 'NO_COMMITS',
|
|
40
|
+
message: 'This repository has no commits yet.',
|
|
41
|
+
hint: 'Commit your work: git add -A && git commit -m "…"',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function redactCredentials(text) {
|
|
46
|
+
return text.replace(/(https?:\/\/)[^@\s/]+@/gi, '$1***@');
|
|
47
|
+
}
|
|
48
|
+
function cloneRepo(opts) {
|
|
49
|
+
const { cloneUrl, targetDir, branch, repoFullName, cwd } = opts;
|
|
50
|
+
try {
|
|
51
|
+
(0, node_child_process_1.execFileSync)('git', ['clone', '--depth', '1', '--single-branch', '--branch', branch, '--', cloneUrl, targetDir], { cwd, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8' });
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
const stderr = err.stderr?.toString();
|
|
55
|
+
const raw = stderr?.trim() || (err instanceof Error ? err.message : String(err));
|
|
56
|
+
throw new errors_js_1.AgentOperationError({
|
|
57
|
+
code: 'GIT_CLONE',
|
|
58
|
+
message: 'git clone failed.',
|
|
59
|
+
hint: redactCredentials(raw),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
git(['remote', 'set-url', 'origin', `https://github.com/${repoFullName}.git`], targetDir);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function pushHead(dir, pushUrl, branch) {
|
|
69
|
+
git(['push', '--force', pushUrl, `HEAD:${branch}`], dir);
|
|
70
|
+
}
|
|
71
|
+
function pushSynthesizedTree(treeDir, pushUrl, branch) {
|
|
72
|
+
git(['init', '-q', '-b', branch], treeDir);
|
|
73
|
+
git(['add', '-A'], treeDir);
|
|
74
|
+
git(['-c', 'user.email=deploy@sapiom.ai', '-c', 'user.name=Sapiom Deploy', 'commit', '-q', '-m', 'deploy'], treeDir);
|
|
75
|
+
git(['push', '--force', pushUrl, `HEAD:${branch}`], treeDir);
|
|
76
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export { AgentOperationError } from "./errors.js";
|
|
2
|
+
export type { StructuredError } from "./errors.js";
|
|
3
|
+
export { GatewayClient, createClient, DEFAULT_WORKFLOWS_HOST, } from "./client.js";
|
|
4
|
+
export type { ClientOptions, GatewayErrorBody } from "./client.js";
|
|
5
|
+
export { readConfig, requireConfig, writeConfig, CONFIG_FILE, } from "./config.js";
|
|
6
|
+
export type { SapiomConfig, LinkedSapiomConfig } from "./config.js";
|
|
7
|
+
export { scaffold, resolveVersions, resolveTemplate, listTemplates, DEFAULT_TEMPLATE, } from "./scaffold.js";
|
|
8
|
+
export type { ScaffoldOptions, ScaffoldResult, ResolvedVersions, } from "./scaffold.js";
|
|
9
|
+
export { check } from "./check.js";
|
|
10
|
+
export type { CheckOptions, CheckResult } from "./check.js";
|
|
11
|
+
export { bundleForDeploy } from "./bundle.js";
|
|
12
|
+
export type { DeployBundle } from "./bundle.js";
|
|
13
|
+
export { link } from "./link.js";
|
|
14
|
+
export type { LinkOptions, LinkResult, DefinitionSummary } from "./link.js";
|
|
15
|
+
export { clone } from "./clone.js";
|
|
16
|
+
export type { CloneOptions, CloneResult } from "./clone.js";
|
|
17
|
+
export { deploy } from "./deploy.js";
|
|
18
|
+
export type { DeployOptions, DeployResult } from "./deploy.js";
|
|
19
|
+
export { run, parseJsonInput } from "./run.js";
|
|
20
|
+
export type { RunOptions, RunResult } from "./run.js";
|
|
21
|
+
export type { ExecutionProjection, StepProjection, CostNode, SettleState, ExecutionRef, DispatchRef, StepError, StepErrorTrace, StepErrorFrame, StepEvent, SseEvent, SseEventType, } from "./types.js";
|
|
22
|
+
export { SSE_EVENT_TYPES } from "./types.js";
|
|
23
|
+
export { decodeExecutionProjection } from "./decode.js";
|
|
24
|
+
export { inspect, listExecutions, inspectBuild, waitForExecution, isExecutionTerminal, } from "./inspect.js";
|
|
25
|
+
export type { InspectOptions, InspectBuildOptions, InspectBuildResult, BuildDetail, WaitForExecutionOptions, WaitForExecutionResult, WaitStopReason, } from "./inspect.js";
|
|
26
|
+
export { watchExecution, parseSseFrame, parseSseEvent } from "./watch.js";
|
|
27
|
+
export type { WatchExecutionOptions } from "./watch.js";
|
|
28
|
+
export { signal, parseSignalPayload } from "./signal.js";
|
|
29
|
+
export type { SignalOptions, SignalResult } from "./signal.js";
|
|
30
|
+
export { createSchedule, listSchedules, getSchedule, cancelSchedule, previewCron } from "./schedule.js";
|
|
31
|
+
export type { ScheduleKind, ScheduleStatus, SchedulePolicy, CreateScheduleOptions, ListSchedulesOptions, CronPreviewOptions, CronPreview, ScheduleSummary, ScheduleDetail, ScheduleFireRecord, } from "./schedule.js";
|
|
32
|
+
export { assertDeployable, pushHead, cloneRepo, redactCredentials } from "./git.js";
|
|
33
|
+
export type { CloneRepoOptions } from "./git.js";
|
|
34
|
+
export { parseStubFile, STUB_FILE_VERSION } from "./local/stubs.js";
|
|
35
|
+
export type { StubFile, StepStubs, StubResponse } from "./local/stubs.js";
|
|
36
|
+
export { runLocal, runLocalFromDir, STUBS_FILE } from "./local/run-local.js";
|
|
37
|
+
export type { RunLocalOptions, LocalRunResult, LocalRunOutcome, } from "./local/run-local.js";
|
|
38
|
+
export { loadDefinition } from "./local/load.js";
|
|
39
|
+
export type { LoadedDefinition } from "./local/load.js";
|
|
40
|
+
export { LocalStubDispatcher } from "./local/dispatcher.js";
|
|
41
|
+
export type { LocalStepTrace, LogEntry } from "./local/dispatcher.js";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalStubDispatcher = exports.loadDefinition = exports.STUBS_FILE = exports.runLocalFromDir = exports.runLocal = exports.STUB_FILE_VERSION = exports.parseStubFile = exports.redactCredentials = exports.cloneRepo = exports.pushHead = exports.assertDeployable = exports.previewCron = exports.cancelSchedule = exports.getSchedule = exports.listSchedules = exports.createSchedule = exports.parseSignalPayload = exports.signal = exports.parseSseEvent = exports.parseSseFrame = exports.watchExecution = exports.isExecutionTerminal = exports.waitForExecution = exports.inspectBuild = exports.listExecutions = exports.inspect = exports.decodeExecutionProjection = exports.SSE_EVENT_TYPES = exports.parseJsonInput = exports.run = exports.deploy = exports.clone = exports.link = exports.bundleForDeploy = exports.check = exports.DEFAULT_TEMPLATE = exports.listTemplates = exports.resolveTemplate = exports.resolveVersions = exports.scaffold = exports.CONFIG_FILE = exports.writeConfig = exports.requireConfig = exports.readConfig = exports.DEFAULT_WORKFLOWS_HOST = exports.createClient = exports.GatewayClient = exports.AgentOperationError = void 0;
|
|
4
|
+
var errors_js_1 = require("./errors.js");
|
|
5
|
+
Object.defineProperty(exports, "AgentOperationError", { enumerable: true, get: function () { return errors_js_1.AgentOperationError; } });
|
|
6
|
+
var client_js_1 = require("./client.js");
|
|
7
|
+
Object.defineProperty(exports, "GatewayClient", { enumerable: true, get: function () { return client_js_1.GatewayClient; } });
|
|
8
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_js_1.createClient; } });
|
|
9
|
+
Object.defineProperty(exports, "DEFAULT_WORKFLOWS_HOST", { enumerable: true, get: function () { return client_js_1.DEFAULT_WORKFLOWS_HOST; } });
|
|
10
|
+
var config_js_1 = require("./config.js");
|
|
11
|
+
Object.defineProperty(exports, "readConfig", { enumerable: true, get: function () { return config_js_1.readConfig; } });
|
|
12
|
+
Object.defineProperty(exports, "requireConfig", { enumerable: true, get: function () { return config_js_1.requireConfig; } });
|
|
13
|
+
Object.defineProperty(exports, "writeConfig", { enumerable: true, get: function () { return config_js_1.writeConfig; } });
|
|
14
|
+
Object.defineProperty(exports, "CONFIG_FILE", { enumerable: true, get: function () { return config_js_1.CONFIG_FILE; } });
|
|
15
|
+
var scaffold_js_1 = require("./scaffold.js");
|
|
16
|
+
Object.defineProperty(exports, "scaffold", { enumerable: true, get: function () { return scaffold_js_1.scaffold; } });
|
|
17
|
+
Object.defineProperty(exports, "resolveVersions", { enumerable: true, get: function () { return scaffold_js_1.resolveVersions; } });
|
|
18
|
+
Object.defineProperty(exports, "resolveTemplate", { enumerable: true, get: function () { return scaffold_js_1.resolveTemplate; } });
|
|
19
|
+
Object.defineProperty(exports, "listTemplates", { enumerable: true, get: function () { return scaffold_js_1.listTemplates; } });
|
|
20
|
+
Object.defineProperty(exports, "DEFAULT_TEMPLATE", { enumerable: true, get: function () { return scaffold_js_1.DEFAULT_TEMPLATE; } });
|
|
21
|
+
var check_js_1 = require("./check.js");
|
|
22
|
+
Object.defineProperty(exports, "check", { enumerable: true, get: function () { return check_js_1.check; } });
|
|
23
|
+
var bundle_js_1 = require("./bundle.js");
|
|
24
|
+
Object.defineProperty(exports, "bundleForDeploy", { enumerable: true, get: function () { return bundle_js_1.bundleForDeploy; } });
|
|
25
|
+
var link_js_1 = require("./link.js");
|
|
26
|
+
Object.defineProperty(exports, "link", { enumerable: true, get: function () { return link_js_1.link; } });
|
|
27
|
+
var clone_js_1 = require("./clone.js");
|
|
28
|
+
Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return clone_js_1.clone; } });
|
|
29
|
+
var deploy_js_1 = require("./deploy.js");
|
|
30
|
+
Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return deploy_js_1.deploy; } });
|
|
31
|
+
var run_js_1 = require("./run.js");
|
|
32
|
+
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_js_1.run; } });
|
|
33
|
+
Object.defineProperty(exports, "parseJsonInput", { enumerable: true, get: function () { return run_js_1.parseJsonInput; } });
|
|
34
|
+
var types_js_1 = require("./types.js");
|
|
35
|
+
Object.defineProperty(exports, "SSE_EVENT_TYPES", { enumerable: true, get: function () { return types_js_1.SSE_EVENT_TYPES; } });
|
|
36
|
+
var decode_js_1 = require("./decode.js");
|
|
37
|
+
Object.defineProperty(exports, "decodeExecutionProjection", { enumerable: true, get: function () { return decode_js_1.decodeExecutionProjection; } });
|
|
38
|
+
var inspect_js_1 = require("./inspect.js");
|
|
39
|
+
Object.defineProperty(exports, "inspect", { enumerable: true, get: function () { return inspect_js_1.inspect; } });
|
|
40
|
+
Object.defineProperty(exports, "listExecutions", { enumerable: true, get: function () { return inspect_js_1.listExecutions; } });
|
|
41
|
+
Object.defineProperty(exports, "inspectBuild", { enumerable: true, get: function () { return inspect_js_1.inspectBuild; } });
|
|
42
|
+
Object.defineProperty(exports, "waitForExecution", { enumerable: true, get: function () { return inspect_js_1.waitForExecution; } });
|
|
43
|
+
Object.defineProperty(exports, "isExecutionTerminal", { enumerable: true, get: function () { return inspect_js_1.isExecutionTerminal; } });
|
|
44
|
+
var watch_js_1 = require("./watch.js");
|
|
45
|
+
Object.defineProperty(exports, "watchExecution", { enumerable: true, get: function () { return watch_js_1.watchExecution; } });
|
|
46
|
+
Object.defineProperty(exports, "parseSseFrame", { enumerable: true, get: function () { return watch_js_1.parseSseFrame; } });
|
|
47
|
+
Object.defineProperty(exports, "parseSseEvent", { enumerable: true, get: function () { return watch_js_1.parseSseEvent; } });
|
|
48
|
+
var signal_js_1 = require("./signal.js");
|
|
49
|
+
Object.defineProperty(exports, "signal", { enumerable: true, get: function () { return signal_js_1.signal; } });
|
|
50
|
+
Object.defineProperty(exports, "parseSignalPayload", { enumerable: true, get: function () { return signal_js_1.parseSignalPayload; } });
|
|
51
|
+
var schedule_js_1 = require("./schedule.js");
|
|
52
|
+
Object.defineProperty(exports, "createSchedule", { enumerable: true, get: function () { return schedule_js_1.createSchedule; } });
|
|
53
|
+
Object.defineProperty(exports, "listSchedules", { enumerable: true, get: function () { return schedule_js_1.listSchedules; } });
|
|
54
|
+
Object.defineProperty(exports, "getSchedule", { enumerable: true, get: function () { return schedule_js_1.getSchedule; } });
|
|
55
|
+
Object.defineProperty(exports, "cancelSchedule", { enumerable: true, get: function () { return schedule_js_1.cancelSchedule; } });
|
|
56
|
+
Object.defineProperty(exports, "previewCron", { enumerable: true, get: function () { return schedule_js_1.previewCron; } });
|
|
57
|
+
var git_js_1 = require("./git.js");
|
|
58
|
+
Object.defineProperty(exports, "assertDeployable", { enumerable: true, get: function () { return git_js_1.assertDeployable; } });
|
|
59
|
+
Object.defineProperty(exports, "pushHead", { enumerable: true, get: function () { return git_js_1.pushHead; } });
|
|
60
|
+
Object.defineProperty(exports, "cloneRepo", { enumerable: true, get: function () { return git_js_1.cloneRepo; } });
|
|
61
|
+
Object.defineProperty(exports, "redactCredentials", { enumerable: true, get: function () { return git_js_1.redactCredentials; } });
|
|
62
|
+
var stubs_js_1 = require("./local/stubs.js");
|
|
63
|
+
Object.defineProperty(exports, "parseStubFile", { enumerable: true, get: function () { return stubs_js_1.parseStubFile; } });
|
|
64
|
+
Object.defineProperty(exports, "STUB_FILE_VERSION", { enumerable: true, get: function () { return stubs_js_1.STUB_FILE_VERSION; } });
|
|
65
|
+
var run_local_js_1 = require("./local/run-local.js");
|
|
66
|
+
Object.defineProperty(exports, "runLocal", { enumerable: true, get: function () { return run_local_js_1.runLocal; } });
|
|
67
|
+
Object.defineProperty(exports, "runLocalFromDir", { enumerable: true, get: function () { return run_local_js_1.runLocalFromDir; } });
|
|
68
|
+
Object.defineProperty(exports, "STUBS_FILE", { enumerable: true, get: function () { return run_local_js_1.STUBS_FILE; } });
|
|
69
|
+
var load_js_1 = require("./local/load.js");
|
|
70
|
+
Object.defineProperty(exports, "loadDefinition", { enumerable: true, get: function () { return load_js_1.loadDefinition; } });
|
|
71
|
+
var dispatcher_js_1 = require("./local/dispatcher.js");
|
|
72
|
+
Object.defineProperty(exports, "LocalStubDispatcher", { enumerable: true, get: function () { return dispatcher_js_1.LocalStubDispatcher; } });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { GatewayClient } from "./client.js";
|
|
2
|
+
import type { ExecutionProjection, ExecutionRef, SseEvent } from "./types.js";
|
|
3
|
+
export interface BuildDetail {
|
|
4
|
+
id?: string;
|
|
5
|
+
status: string;
|
|
6
|
+
error?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface InspectOptions {
|
|
9
|
+
executionId: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function inspect(opts: InspectOptions, client: GatewayClient): Promise<ExecutionProjection>;
|
|
12
|
+
export declare function isExecutionTerminal(status: string): boolean;
|
|
13
|
+
export type WaitStopReason = "terminal" | "needs-signal" | "timeout";
|
|
14
|
+
export interface WaitForExecutionOptions {
|
|
15
|
+
executionId: string;
|
|
16
|
+
maxWaitMs?: number;
|
|
17
|
+
pollMs?: number;
|
|
18
|
+
autoResumeSignals?: string[];
|
|
19
|
+
sleep?: (ms: number) => Promise<void>;
|
|
20
|
+
now?: () => number;
|
|
21
|
+
watch?: (opts: {
|
|
22
|
+
executionId: string;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}, client: GatewayClient) => AsyncIterable<SseEvent>;
|
|
25
|
+
}
|
|
26
|
+
export interface WaitForExecutionResult {
|
|
27
|
+
execution: ExecutionProjection;
|
|
28
|
+
reason: WaitStopReason;
|
|
29
|
+
done: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function waitForExecution(opts: WaitForExecutionOptions, client: GatewayClient): Promise<WaitForExecutionResult>;
|
|
32
|
+
export declare function listExecutions(client: GatewayClient): Promise<ExecutionRef[]>;
|
|
33
|
+
export interface InspectBuildOptions {
|
|
34
|
+
definitionId: string;
|
|
35
|
+
buildRunId: string;
|
|
36
|
+
}
|
|
37
|
+
export interface InspectBuildResult {
|
|
38
|
+
build: BuildDetail;
|
|
39
|
+
}
|
|
40
|
+
export declare function inspectBuild(opts: InspectBuildOptions, client: GatewayClient): Promise<InspectBuildResult>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inspect = inspect;
|
|
4
|
+
exports.isExecutionTerminal = isExecutionTerminal;
|
|
5
|
+
exports.waitForExecution = waitForExecution;
|
|
6
|
+
exports.listExecutions = listExecutions;
|
|
7
|
+
exports.inspectBuild = inspectBuild;
|
|
8
|
+
const decode_js_1 = require("./decode.js");
|
|
9
|
+
const watch_js_1 = require("./watch.js");
|
|
10
|
+
async function inspect(opts, client) {
|
|
11
|
+
const raw = await client.get(`/executions/${opts.executionId}`);
|
|
12
|
+
return (0, decode_js_1.decodeExecutionProjection)(raw);
|
|
13
|
+
}
|
|
14
|
+
const TERMINAL_STATUSES = new Set([
|
|
15
|
+
"completed",
|
|
16
|
+
"failed",
|
|
17
|
+
"cancelled",
|
|
18
|
+
"canceled",
|
|
19
|
+
]);
|
|
20
|
+
function isExecutionTerminal(status) {
|
|
21
|
+
return TERMINAL_STATUSES.has(status);
|
|
22
|
+
}
|
|
23
|
+
const AUTO_RESUME_PAUSE_SIGNALS = [
|
|
24
|
+
"models.coding.result",
|
|
25
|
+
"contentGeneration.video.result",
|
|
26
|
+
];
|
|
27
|
+
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
28
|
+
function settledResult(execution, autoResume) {
|
|
29
|
+
if (isExecutionTerminal(execution.status)) {
|
|
30
|
+
return { reason: "terminal", done: true };
|
|
31
|
+
}
|
|
32
|
+
if (execution.status === "paused") {
|
|
33
|
+
const signal = execution.pausedSignalName ?? null;
|
|
34
|
+
if (!signal || !autoResume.includes(signal)) {
|
|
35
|
+
return { reason: "needs-signal", done: false };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
async function waitForExecution(opts, client) {
|
|
41
|
+
const maxWaitMs = opts.maxWaitMs ?? 45000;
|
|
42
|
+
const autoResume = opts.autoResumeSignals ?? AUTO_RESUME_PAUSE_SIGNALS;
|
|
43
|
+
const sleep = opts.sleep ?? defaultSleep;
|
|
44
|
+
const now = opts.now ?? Date.now;
|
|
45
|
+
const watch = opts.watch ?? watch_js_1.watchExecution;
|
|
46
|
+
const deadline = now() + maxWaitMs;
|
|
47
|
+
const read = () => inspect({ executionId: opts.executionId }, client);
|
|
48
|
+
let execution = await read();
|
|
49
|
+
let settled = settledResult(execution, autoResume);
|
|
50
|
+
if (settled)
|
|
51
|
+
return { execution, ...settled };
|
|
52
|
+
if (now() >= deadline)
|
|
53
|
+
return { execution, reason: "timeout", done: false };
|
|
54
|
+
const abort = new AbortController();
|
|
55
|
+
const timer = setTimeout(() => abort.abort(), Math.max(0, deadline - now()));
|
|
56
|
+
timer.unref?.();
|
|
57
|
+
const events = watch({ executionId: opts.executionId, signal: abort.signal }, client)[Symbol.asyncIterator]();
|
|
58
|
+
try {
|
|
59
|
+
for (;;) {
|
|
60
|
+
const next = await events.next();
|
|
61
|
+
if (next.done)
|
|
62
|
+
break;
|
|
63
|
+
execution = await read();
|
|
64
|
+
settled = settledResult(execution, autoResume);
|
|
65
|
+
if (settled)
|
|
66
|
+
return { execution, ...settled };
|
|
67
|
+
if (now() >= deadline)
|
|
68
|
+
return { execution, reason: "timeout", done: false };
|
|
69
|
+
}
|
|
70
|
+
if (now() >= deadline)
|
|
71
|
+
return { execution, reason: "timeout", done: false };
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
await events.return?.(undefined);
|
|
78
|
+
}
|
|
79
|
+
let interval = opts.pollMs ?? 1000;
|
|
80
|
+
for (;;) {
|
|
81
|
+
const remaining = deadline - now();
|
|
82
|
+
if (remaining <= 0)
|
|
83
|
+
return { execution, reason: "timeout", done: false };
|
|
84
|
+
await sleep(Math.min(interval, remaining));
|
|
85
|
+
interval = Math.min(interval * 1.5, 5000);
|
|
86
|
+
execution = await read();
|
|
87
|
+
settled = settledResult(execution, autoResume);
|
|
88
|
+
if (settled)
|
|
89
|
+
return { execution, ...settled };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function listExecutions(client) {
|
|
93
|
+
const raw = await client.get("/executions");
|
|
94
|
+
return Array.isArray(raw) ? raw.map(decode_js_1.decodeExecutionRef) : [];
|
|
95
|
+
}
|
|
96
|
+
async function inspectBuild(opts, client) {
|
|
97
|
+
const build = await client.get(`/definitions/${opts.definitionId}/builds/${opts.buildRunId}`);
|
|
98
|
+
return { build };
|
|
99
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GatewayClient } from './client.js';
|
|
2
|
+
export interface DefinitionSummary {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
slug?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface LinkOptions {
|
|
8
|
+
name: string;
|
|
9
|
+
create?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface LinkResult {
|
|
12
|
+
definitionId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function link(opts: LinkOptions, client: GatewayClient): Promise<LinkResult>;
|
package/dist/cjs/link.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.link = link;
|
|
4
|
+
const errors_js_1 = require("./errors.js");
|
|
5
|
+
async function link(opts, client) {
|
|
6
|
+
const list = await client.get('/definitions');
|
|
7
|
+
let def = list.find((d) => d.name === opts.name || d.slug === opts.name);
|
|
8
|
+
if (!def) {
|
|
9
|
+
if (!opts.create) {
|
|
10
|
+
throw new errors_js_1.AgentOperationError({
|
|
11
|
+
code: 'NOT_FOUND',
|
|
12
|
+
message: `No agent named '${opts.name}'.`,
|
|
13
|
+
hint: 'Create it with { create: true }, or pass the name of an existing one.',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
def = await client.post('/definitions', { name: opts.name });
|
|
17
|
+
}
|
|
18
|
+
return { definitionId: def.id, name: def.name };
|
|
19
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type NextStepDirective, type AgentDefinition } from "@sapiom/agent";
|
|
2
|
+
import { type StepDispatcher, type StepDispatchRequest, type AgentRunnerCore } from "@sapiom/agent-runtime";
|
|
3
|
+
import type { StubFile } from "./stubs.js";
|
|
4
|
+
export interface LogEntry {
|
|
5
|
+
level: "info" | "warn" | "error" | "debug";
|
|
6
|
+
msg: string;
|
|
7
|
+
meta?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface LocalStepTrace {
|
|
10
|
+
step: string;
|
|
11
|
+
attempt: number;
|
|
12
|
+
input: unknown;
|
|
13
|
+
status: "succeeded" | "threw";
|
|
14
|
+
output?: unknown;
|
|
15
|
+
directive?: NextStepDirective;
|
|
16
|
+
error?: {
|
|
17
|
+
name: string;
|
|
18
|
+
message: string;
|
|
19
|
+
stack?: string;
|
|
20
|
+
};
|
|
21
|
+
logs: LogEntry[];
|
|
22
|
+
}
|
|
23
|
+
export declare class LocalStubDispatcher implements StepDispatcher {
|
|
24
|
+
private readonly definition;
|
|
25
|
+
private readonly stubs;
|
|
26
|
+
private core;
|
|
27
|
+
private maxAttemptsPerStep;
|
|
28
|
+
private signals;
|
|
29
|
+
readonly trace: LocalStepTrace[];
|
|
30
|
+
readonly usedKeysByStep: Map<string, Set<string>>;
|
|
31
|
+
readonly stubWarnings: Set<string>;
|
|
32
|
+
constructor(definition: AgentDefinition, stubs: StubFile);
|
|
33
|
+
setCore(core: AgentRunnerCore): void;
|
|
34
|
+
setMaxAttempts(max: number): void;
|
|
35
|
+
setSignals(signals: Map<string, unknown>): void;
|
|
36
|
+
dispatch(request: StepDispatchRequest): Promise<void>;
|
|
37
|
+
}
|