@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
|
+
import { GatewayClient } from './client.js';
|
|
2
|
+
export type ScheduleKind = 'schedule_cron' | 'schedule_once';
|
|
3
|
+
export type ScheduleStatus = 'active' | 'paused' | 'completed' | 'disabled';
|
|
4
|
+
export interface SchedulePolicy {
|
|
5
|
+
catchupPolicy?: 'skip' | 'all';
|
|
6
|
+
overlapPolicy?: 'allow' | 'skip';
|
|
7
|
+
jitterMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateScheduleOptions {
|
|
10
|
+
definition: string;
|
|
11
|
+
kind: ScheduleKind;
|
|
12
|
+
input?: unknown;
|
|
13
|
+
cron?: string;
|
|
14
|
+
timezone?: string;
|
|
15
|
+
startAt?: string;
|
|
16
|
+
endAt?: string;
|
|
17
|
+
policy?: SchedulePolicy;
|
|
18
|
+
at?: string | Date;
|
|
19
|
+
}
|
|
20
|
+
export interface ScheduleFireRecord {
|
|
21
|
+
scheduledFor: string;
|
|
22
|
+
state: string;
|
|
23
|
+
firedAt: string | null;
|
|
24
|
+
executionId: string | null;
|
|
25
|
+
error?: unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface ScheduleSummary {
|
|
28
|
+
id: string;
|
|
29
|
+
kind: ScheduleKind;
|
|
30
|
+
status: ScheduleStatus;
|
|
31
|
+
definitionSlug: string;
|
|
32
|
+
cron: string | null;
|
|
33
|
+
timezone: string | null;
|
|
34
|
+
nextFireAt: string | null;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ScheduleDetail extends ScheduleSummary {
|
|
38
|
+
input: unknown;
|
|
39
|
+
startAt: string | null;
|
|
40
|
+
endAt: string | null;
|
|
41
|
+
policy: unknown;
|
|
42
|
+
recentFires: ScheduleFireRecord[];
|
|
43
|
+
}
|
|
44
|
+
export interface ListSchedulesOptions {
|
|
45
|
+
definition: string;
|
|
46
|
+
status?: ScheduleStatus;
|
|
47
|
+
limit?: number;
|
|
48
|
+
offset?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface CronPreviewOptions {
|
|
51
|
+
cron: string;
|
|
52
|
+
timezone?: string;
|
|
53
|
+
count?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface CronPreview {
|
|
56
|
+
cron: string;
|
|
57
|
+
timezone: string;
|
|
58
|
+
occurrences: string[];
|
|
59
|
+
}
|
|
60
|
+
export declare function createSchedule(opts: CreateScheduleOptions, client: GatewayClient): Promise<ScheduleDetail>;
|
|
61
|
+
export declare function listSchedules(opts: ListSchedulesOptions, client: GatewayClient): Promise<ScheduleSummary[]>;
|
|
62
|
+
export declare function getSchedule(id: string, client: GatewayClient): Promise<ScheduleDetail>;
|
|
63
|
+
export declare function cancelSchedule(id: string, client: GatewayClient): Promise<{
|
|
64
|
+
id: string;
|
|
65
|
+
status: ScheduleStatus;
|
|
66
|
+
}>;
|
|
67
|
+
export declare function previewCron(opts: CronPreviewOptions, client: GatewayClient): Promise<CronPreview>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSchedule = createSchedule;
|
|
4
|
+
exports.listSchedules = listSchedules;
|
|
5
|
+
exports.getSchedule = getSchedule;
|
|
6
|
+
exports.cancelSchedule = cancelSchedule;
|
|
7
|
+
exports.previewCron = previewCron;
|
|
8
|
+
async function createSchedule(opts, client) {
|
|
9
|
+
const { definition, ...body } = opts;
|
|
10
|
+
return client.post(`/${encodeURIComponent(definition)}/triggers`, body);
|
|
11
|
+
}
|
|
12
|
+
async function listSchedules(opts, client) {
|
|
13
|
+
const { definition, ...filters } = opts;
|
|
14
|
+
return client.get(`/${encodeURIComponent(definition)}/triggers${toQuery(filters)}`);
|
|
15
|
+
}
|
|
16
|
+
async function getSchedule(id, client) {
|
|
17
|
+
return client.get(`/triggers/${encodeURIComponent(id)}`);
|
|
18
|
+
}
|
|
19
|
+
async function cancelSchedule(id, client) {
|
|
20
|
+
return client.request('DELETE', `/triggers/${encodeURIComponent(id)}`);
|
|
21
|
+
}
|
|
22
|
+
async function previewCron(opts, client) {
|
|
23
|
+
return client.post('/triggers/preview-cron', opts);
|
|
24
|
+
}
|
|
25
|
+
function toQuery(filters) {
|
|
26
|
+
const params = new URLSearchParams();
|
|
27
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
28
|
+
if (value !== undefined && value !== null)
|
|
29
|
+
params.set(key, String(value));
|
|
30
|
+
}
|
|
31
|
+
const qs = params.toString();
|
|
32
|
+
return qs ? `?${qs}` : '';
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GatewayClient } from './client.js';
|
|
2
|
+
export interface SignalOptions {
|
|
3
|
+
executionId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
correlationId: string;
|
|
6
|
+
payload?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface SignalResult {
|
|
9
|
+
matched: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function signal(opts: SignalOptions, client: GatewayClient): Promise<SignalResult>;
|
|
12
|
+
export declare function parseSignalPayload(raw: string): unknown;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signal = signal;
|
|
4
|
+
exports.parseSignalPayload = parseSignalPayload;
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
async function signal(opts, client) {
|
|
7
|
+
const res = await client.post(`/executions/${opts.executionId}/signals`, {
|
|
8
|
+
name: opts.name,
|
|
9
|
+
correlationId: opts.correlationId,
|
|
10
|
+
payload: opts.payload,
|
|
11
|
+
});
|
|
12
|
+
return { matched: res.matched ?? 0 };
|
|
13
|
+
}
|
|
14
|
+
function parseSignalPayload(raw) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new errors_js_1.AgentOperationError({
|
|
20
|
+
code: 'BAD_PAYLOAD',
|
|
21
|
+
message: 'Signal payload is not valid JSON.',
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type SettleState = "pending" | "settling" | "final";
|
|
2
|
+
export interface CostNode {
|
|
3
|
+
authorizedUsd: string;
|
|
4
|
+
capturedUsd: string;
|
|
5
|
+
settleState: SettleState;
|
|
6
|
+
}
|
|
7
|
+
export interface StepEvent {
|
|
8
|
+
sourceId: string;
|
|
9
|
+
sequence: number;
|
|
10
|
+
kind: string;
|
|
11
|
+
payload: Record<string, unknown>;
|
|
12
|
+
eventTs: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface StepErrorFrame {
|
|
15
|
+
function?: string;
|
|
16
|
+
file?: string;
|
|
17
|
+
line?: number;
|
|
18
|
+
column?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface StepErrorTrace {
|
|
21
|
+
frames: StepErrorFrame[];
|
|
22
|
+
sourceMapped: boolean;
|
|
23
|
+
raw?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface StepError {
|
|
26
|
+
message: string;
|
|
27
|
+
trace: StepErrorTrace | null;
|
|
28
|
+
traceUnavailableReason: string | null;
|
|
29
|
+
}
|
|
30
|
+
export declare const SSE_EVENT_TYPES: readonly ["step.started", "step.captured", "cost.updated", "run.paused", "run.resumed", "run.terminal"];
|
|
31
|
+
export type SseEventType = (typeof SSE_EVENT_TYPES)[number];
|
|
32
|
+
export interface SseEvent {
|
|
33
|
+
type: SseEventType;
|
|
34
|
+
executionId: string;
|
|
35
|
+
traceRoot: string | null;
|
|
36
|
+
nodeId: string | null;
|
|
37
|
+
}
|
|
38
|
+
export interface ExecutionRef {
|
|
39
|
+
executionId: string;
|
|
40
|
+
traceRoot: string;
|
|
41
|
+
name: string;
|
|
42
|
+
status: string;
|
|
43
|
+
}
|
|
44
|
+
export interface DispatchRef {
|
|
45
|
+
childExecutionId: string;
|
|
46
|
+
targetType: string;
|
|
47
|
+
correlationId: string;
|
|
48
|
+
status: string;
|
|
49
|
+
}
|
|
50
|
+
export interface StepProjection {
|
|
51
|
+
stepName: string;
|
|
52
|
+
stepOrder: number;
|
|
53
|
+
attempt: number;
|
|
54
|
+
status: string;
|
|
55
|
+
spanId: string | null;
|
|
56
|
+
startedAt: string | null;
|
|
57
|
+
finishedAt: string | null;
|
|
58
|
+
input: unknown;
|
|
59
|
+
output: unknown;
|
|
60
|
+
sharedStateAfter: Record<string, unknown> | null;
|
|
61
|
+
nextDirective: unknown;
|
|
62
|
+
cost: CostNode | null;
|
|
63
|
+
logs: unknown;
|
|
64
|
+
events: StepEvent[];
|
|
65
|
+
error: StepError | null;
|
|
66
|
+
dispatch: DispatchRef | null;
|
|
67
|
+
}
|
|
68
|
+
export interface ExecutionProjection {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
organizationId: string | null;
|
|
72
|
+
tenantId: string | null;
|
|
73
|
+
status: string;
|
|
74
|
+
currentStep: string | null;
|
|
75
|
+
currentStepAttempt: number;
|
|
76
|
+
version: number;
|
|
77
|
+
definitionId: string | null;
|
|
78
|
+
buildRunId: string | null;
|
|
79
|
+
idempotencyKey: string | null;
|
|
80
|
+
pausedSignalName: string | null;
|
|
81
|
+
pausedSignalCorrelationId: string | null;
|
|
82
|
+
pausedUntil: string | null;
|
|
83
|
+
startedAt: string;
|
|
84
|
+
finishedAt: string | null;
|
|
85
|
+
input: unknown;
|
|
86
|
+
sharedState: Record<string, unknown>;
|
|
87
|
+
output: unknown;
|
|
88
|
+
error: unknown;
|
|
89
|
+
pausedStepInputSchema: Record<string, unknown> | null;
|
|
90
|
+
pausedStepInputExample: unknown;
|
|
91
|
+
traceRoot: string;
|
|
92
|
+
rootExecutionId: string;
|
|
93
|
+
traceParent: string | null;
|
|
94
|
+
parentExecutionId: string | null;
|
|
95
|
+
traceId: string | null;
|
|
96
|
+
children: ExecutionRef[];
|
|
97
|
+
cost: CostNode | null;
|
|
98
|
+
steps: StepProjection[];
|
|
99
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GatewayClient } from "./client.js";
|
|
2
|
+
import { type SseEvent } from "./types.js";
|
|
3
|
+
export interface WatchExecutionOptions {
|
|
4
|
+
executionId: string;
|
|
5
|
+
lastEventId?: string;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export declare function watchExecution(opts: WatchExecutionOptions, client: GatewayClient): AsyncGenerator<SseEvent>;
|
|
9
|
+
export declare function parseSseFrame(raw: string): SseEvent | null;
|
|
10
|
+
export declare function parseSseEvent(raw: string): SseEvent | null;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.watchExecution = watchExecution;
|
|
4
|
+
exports.parseSseFrame = parseSseFrame;
|
|
5
|
+
exports.parseSseEvent = parseSseEvent;
|
|
6
|
+
const types_js_1 = require("./types.js");
|
|
7
|
+
async function* watchExecution(opts, client) {
|
|
8
|
+
const controller = new AbortController();
|
|
9
|
+
const onExternalAbort = () => controller.abort();
|
|
10
|
+
if (opts.signal) {
|
|
11
|
+
if (opts.signal.aborted)
|
|
12
|
+
controller.abort();
|
|
13
|
+
else
|
|
14
|
+
opts.signal.addEventListener("abort", onExternalAbort, { once: true });
|
|
15
|
+
}
|
|
16
|
+
const path = `/executions/${encodeURIComponent(opts.executionId)}/stream`;
|
|
17
|
+
try {
|
|
18
|
+
const res = await client.openStream(path, {
|
|
19
|
+
signal: controller.signal,
|
|
20
|
+
lastEventId: opts.lastEventId,
|
|
21
|
+
});
|
|
22
|
+
const reader = res.body.getReader();
|
|
23
|
+
const decoder = new TextDecoder();
|
|
24
|
+
let buffer = "";
|
|
25
|
+
try {
|
|
26
|
+
for (;;) {
|
|
27
|
+
const { done, value } = await reader.read();
|
|
28
|
+
if (done)
|
|
29
|
+
break;
|
|
30
|
+
buffer += decoder.decode(value, { stream: true });
|
|
31
|
+
for (;;) {
|
|
32
|
+
const boundary = indexOfFrameBoundary(buffer);
|
|
33
|
+
if (boundary === -1)
|
|
34
|
+
break;
|
|
35
|
+
const raw = buffer.slice(0, boundary.at);
|
|
36
|
+
buffer = buffer.slice(boundary.after);
|
|
37
|
+
const event = parseSseFrame(raw);
|
|
38
|
+
if (event)
|
|
39
|
+
yield event;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
reader.releaseLock();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
controller.abort();
|
|
49
|
+
if (opts.signal)
|
|
50
|
+
opts.signal.removeEventListener("abort", onExternalAbort);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function indexOfFrameBoundary(buffer) {
|
|
54
|
+
const lf = buffer.indexOf("\n\n");
|
|
55
|
+
const crlf = buffer.indexOf("\r\n\r\n");
|
|
56
|
+
if (lf === -1 && crlf === -1)
|
|
57
|
+
return -1;
|
|
58
|
+
if (crlf !== -1 && (lf === -1 || crlf < lf))
|
|
59
|
+
return { at: crlf, after: crlf + 4 };
|
|
60
|
+
return { at: lf, after: lf + 2 };
|
|
61
|
+
}
|
|
62
|
+
function parseSseFrame(raw) {
|
|
63
|
+
const dataLines = [];
|
|
64
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
65
|
+
if (!line || line.startsWith(":"))
|
|
66
|
+
continue;
|
|
67
|
+
const colon = line.indexOf(":");
|
|
68
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
69
|
+
let value = colon === -1 ? "" : line.slice(colon + 1);
|
|
70
|
+
if (value.startsWith(" "))
|
|
71
|
+
value = value.slice(1);
|
|
72
|
+
if (field === "data")
|
|
73
|
+
dataLines.push(value);
|
|
74
|
+
}
|
|
75
|
+
if (dataLines.length === 0)
|
|
76
|
+
return null;
|
|
77
|
+
return parseSseEvent(dataLines.join("\n"));
|
|
78
|
+
}
|
|
79
|
+
function parseSseEvent(raw) {
|
|
80
|
+
let parsed;
|
|
81
|
+
try {
|
|
82
|
+
parsed = JSON.parse(raw);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (!parsed || typeof parsed !== "object")
|
|
88
|
+
return null;
|
|
89
|
+
const m = parsed;
|
|
90
|
+
if (typeof m.type !== "string" || !types_js_1.SSE_EVENT_TYPES.includes(m.type)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (typeof m.executionId !== "string" || m.executionId.length === 0)
|
|
94
|
+
return null;
|
|
95
|
+
return {
|
|
96
|
+
type: m.type,
|
|
97
|
+
executionId: m.executionId,
|
|
98
|
+
traceRoot: typeof m.traceRoot === "string" ? m.traceRoot : null,
|
|
99
|
+
nodeId: typeof m.nodeId === "string" ? m.nodeId : null,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "exec_0001",
|
|
3
|
+
"name": "daily-digest",
|
|
4
|
+
"organizationId": "org_0001",
|
|
5
|
+
"tenantId": "tenant_0001",
|
|
6
|
+
"status": "failed",
|
|
7
|
+
"currentStep": "render",
|
|
8
|
+
"currentStepAttempt": 2,
|
|
9
|
+
"version": 3,
|
|
10
|
+
"definitionId": "def_0001",
|
|
11
|
+
"buildRunId": "build_0001",
|
|
12
|
+
"idempotencyKey": null,
|
|
13
|
+
"pausedSignalName": null,
|
|
14
|
+
"pausedSignalCorrelationId": null,
|
|
15
|
+
"pausedUntil": null,
|
|
16
|
+
"startedAt": "2026-01-01T00:00:00.000Z",
|
|
17
|
+
"finishedAt": "2026-01-01T00:02:30.000Z",
|
|
18
|
+
"input": { "topic": "weekly-summary" },
|
|
19
|
+
"sharedState": { "count": 2 },
|
|
20
|
+
"output": null,
|
|
21
|
+
"error": null,
|
|
22
|
+
"pausedStepInputSchema": null,
|
|
23
|
+
"pausedStepInputExample": null,
|
|
24
|
+
"repoFullName": "example-org/example-workflows",
|
|
25
|
+
"pinnedCommitSha": "0000000000000000000000000000000000000000",
|
|
26
|
+
"traceId": "trace_0001",
|
|
27
|
+
"traceRoot": "exec_0001",
|
|
28
|
+
"rootExecutionId": "exec_0001",
|
|
29
|
+
"traceParent": null,
|
|
30
|
+
"parentExecutionId": null,
|
|
31
|
+
"children": [
|
|
32
|
+
{
|
|
33
|
+
"executionId": "exec_0002",
|
|
34
|
+
"targetType": "agent",
|
|
35
|
+
"correlationId": "exec_0002",
|
|
36
|
+
"status": "resolved"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"steps": [
|
|
40
|
+
{
|
|
41
|
+
"id": "step_0001",
|
|
42
|
+
"stepName": "gather",
|
|
43
|
+
"stepOrder": 0,
|
|
44
|
+
"attempt": 1,
|
|
45
|
+
"status": "completed",
|
|
46
|
+
"input": { "topic": "weekly-summary" },
|
|
47
|
+
"output": { "items": 12 },
|
|
48
|
+
"error": null,
|
|
49
|
+
"nextDirective": { "kind": "continue" },
|
|
50
|
+
"sharedStateAfter": { "count": 1 },
|
|
51
|
+
"logs": [{ "ts": "2026-01-01T00:00:05.000Z", "level": "info", "msg": "fetched 12 items" }],
|
|
52
|
+
"events": [
|
|
53
|
+
{
|
|
54
|
+
"sourceId": "run_0001",
|
|
55
|
+
"sequence": 1,
|
|
56
|
+
"kind": "tool_use",
|
|
57
|
+
"payload": { "tool": "web.search" },
|
|
58
|
+
"eventTs": "2026-01-01T00:00:10.000Z"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"spanId": "span_0001",
|
|
62
|
+
"dispatch": null,
|
|
63
|
+
"startedAt": "2026-01-01T00:00:00.000Z",
|
|
64
|
+
"finishedAt": "2026-01-01T00:00:45.000Z"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "step_0002",
|
|
68
|
+
"stepName": "render",
|
|
69
|
+
"stepOrder": 1,
|
|
70
|
+
"attempt": 2,
|
|
71
|
+
"status": "failed",
|
|
72
|
+
"input": { "items": 12 },
|
|
73
|
+
"output": null,
|
|
74
|
+
"error": {
|
|
75
|
+
"message": "template not found",
|
|
76
|
+
"trace": {
|
|
77
|
+
"frames": [
|
|
78
|
+
{ "function": "render", "file": "src/steps/render.ts", "line": 12, "column": 11 },
|
|
79
|
+
{ "function": "run", "file": "src/engine/runner.ts", "line": 88, "column": 5 }
|
|
80
|
+
],
|
|
81
|
+
"sourceMapped": true,
|
|
82
|
+
"raw": "Error: template not found\n at render (dist/steps/render.mjs:8:9)"
|
|
83
|
+
},
|
|
84
|
+
"traceUnavailableReason": null
|
|
85
|
+
},
|
|
86
|
+
"nextDirective": null,
|
|
87
|
+
"sharedStateAfter": { "count": 2 },
|
|
88
|
+
"logs": null,
|
|
89
|
+
"events": [],
|
|
90
|
+
"spanId": "span_0002",
|
|
91
|
+
"dispatch": {
|
|
92
|
+
"targetId": "exec_0002",
|
|
93
|
+
"targetType": "agent",
|
|
94
|
+
"correlationId": "exec_0002",
|
|
95
|
+
"status": "resolved"
|
|
96
|
+
},
|
|
97
|
+
"startedAt": "2026-01-01T00:00:45.000Z",
|
|
98
|
+
"finishedAt": "2026-01-01T00:02:30.000Z"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "exec_legacy_0001",
|
|
3
|
+
"name": "old-run",
|
|
4
|
+
"organizationId": "org_0001",
|
|
5
|
+
"tenantId": "tenant_0001",
|
|
6
|
+
"status": "completed",
|
|
7
|
+
"currentStep": null,
|
|
8
|
+
"currentStepAttempt": 1,
|
|
9
|
+
"version": 1,
|
|
10
|
+
"definitionId": null,
|
|
11
|
+
"buildRunId": null,
|
|
12
|
+
"idempotencyKey": null,
|
|
13
|
+
"pausedSignalName": null,
|
|
14
|
+
"pausedSignalCorrelationId": null,
|
|
15
|
+
"pausedUntil": null,
|
|
16
|
+
"startedAt": "2025-06-01T00:00:00.000Z",
|
|
17
|
+
"finishedAt": "2025-06-01T00:00:20.000Z",
|
|
18
|
+
"input": {},
|
|
19
|
+
"sharedState": {},
|
|
20
|
+
"output": { "ok": true },
|
|
21
|
+
"error": null,
|
|
22
|
+
"steps": [
|
|
23
|
+
{
|
|
24
|
+
"stepName": "run",
|
|
25
|
+
"stepOrder": 0,
|
|
26
|
+
"attempt": 1,
|
|
27
|
+
"status": "completed",
|
|
28
|
+
"input": {},
|
|
29
|
+
"output": { "ok": true },
|
|
30
|
+
"error": null,
|
|
31
|
+
"nextDirective": { "kind": "complete" },
|
|
32
|
+
"sharedStateAfter": {},
|
|
33
|
+
"startedAt": "2025-06-01T00:00:00.000Z",
|
|
34
|
+
"finishedAt": "2025-06-01T00:00:20.000Z"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "exec_0001",
|
|
3
|
+
"name": "daily-digest",
|
|
4
|
+
"organizationId": "org_0001",
|
|
5
|
+
"tenantId": "tenant_0001",
|
|
6
|
+
"status": "completed",
|
|
7
|
+
"currentStep": null,
|
|
8
|
+
"currentStepAttempt": 1,
|
|
9
|
+
"version": 3,
|
|
10
|
+
"definitionId": "def_0001",
|
|
11
|
+
"buildRunId": "build_0001",
|
|
12
|
+
"idempotencyKey": null,
|
|
13
|
+
"pausedSignalName": null,
|
|
14
|
+
"pausedSignalCorrelationId": null,
|
|
15
|
+
"pausedUntil": null,
|
|
16
|
+
"startedAt": "2026-01-01T00:00:00.000Z",
|
|
17
|
+
"finishedAt": "2026-01-01T00:02:30.000Z",
|
|
18
|
+
"input": { "topic": "weekly-summary" },
|
|
19
|
+
"sharedState": { "count": 2 },
|
|
20
|
+
"output": { "url": "https://example.com/report/exec_0001" },
|
|
21
|
+
"error": null,
|
|
22
|
+
"pausedStepInputSchema": null,
|
|
23
|
+
"pausedStepInputExample": null,
|
|
24
|
+
"traceId": "trace_0001",
|
|
25
|
+
"traceRoot": "exec_0001",
|
|
26
|
+
"rootExecutionId": "exec_0001",
|
|
27
|
+
"traceParent": null,
|
|
28
|
+
"parentExecutionId": null,
|
|
29
|
+
"children": [],
|
|
30
|
+
"cost": {
|
|
31
|
+
"authorizedUsd": "1.50",
|
|
32
|
+
"capturedUsd": "1.20",
|
|
33
|
+
"settleState": "settling"
|
|
34
|
+
},
|
|
35
|
+
"steps": [
|
|
36
|
+
{
|
|
37
|
+
"id": "step_0001",
|
|
38
|
+
"stepName": "gather",
|
|
39
|
+
"stepOrder": 0,
|
|
40
|
+
"attempt": 1,
|
|
41
|
+
"status": "completed",
|
|
42
|
+
"input": { "topic": "weekly-summary" },
|
|
43
|
+
"output": { "items": 12 },
|
|
44
|
+
"error": null,
|
|
45
|
+
"nextDirective": { "kind": "continue" },
|
|
46
|
+
"sharedStateAfter": { "count": 1 },
|
|
47
|
+
"logs": null,
|
|
48
|
+
"events": [],
|
|
49
|
+
"spanId": "span_0001",
|
|
50
|
+
"dispatch": null,
|
|
51
|
+
"cost": {
|
|
52
|
+
"authorizedUsd": "0.50",
|
|
53
|
+
"capturedUsd": "0.50",
|
|
54
|
+
"settleState": "final"
|
|
55
|
+
},
|
|
56
|
+
"startedAt": "2026-01-01T00:00:00.000Z",
|
|
57
|
+
"finishedAt": "2026-01-01T00:00:45.000Z"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { isBuiltin } from 'node:module';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import * as esbuild from 'esbuild';
|
|
6
|
+
import { AgentOperationError } from './errors.js';
|
|
7
|
+
export async function bundleForDeploy(sourceDir) {
|
|
8
|
+
const entryFile = path.join(sourceDir, 'index.ts');
|
|
9
|
+
if (!existsSync(entryFile)) {
|
|
10
|
+
throw new AgentOperationError({
|
|
11
|
+
code: 'NO_ENTRY',
|
|
12
|
+
message: `No index.ts found in ${sourceDir}.`,
|
|
13
|
+
hint: 'Run this from an agent project, or pass its directory.',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const tmp = mkdtempSync(path.join(tmpdir(), 'sapiom-deploy-bundle-'));
|
|
17
|
+
const outfile = path.join(tmp, 'index.js');
|
|
18
|
+
try {
|
|
19
|
+
let result;
|
|
20
|
+
try {
|
|
21
|
+
result = await esbuild.build({
|
|
22
|
+
entryPoints: [entryFile],
|
|
23
|
+
outfile,
|
|
24
|
+
bundle: true,
|
|
25
|
+
platform: 'node',
|
|
26
|
+
target: 'node20',
|
|
27
|
+
format: 'esm',
|
|
28
|
+
packages: 'external',
|
|
29
|
+
metafile: true,
|
|
30
|
+
logLevel: 'silent',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
throw new AgentOperationError({
|
|
35
|
+
code: 'BUNDLE_FAILED',
|
|
36
|
+
message: 'Failed to bundle the agent for deploy.',
|
|
37
|
+
hint: err instanceof Error ? err.message : String(err),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const code = readFileSync(outfile, 'utf8');
|
|
41
|
+
const externals = collectExternalPackages(result.metafile, outfile);
|
|
42
|
+
const dependencies = resolveInstalledVersions(sourceDir, externals);
|
|
43
|
+
return { code, dependencies };
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function collectExternalPackages(metafile, outfile) {
|
|
50
|
+
const key = Object.keys(metafile.outputs).find((k) => path.resolve(k) === path.resolve(outfile));
|
|
51
|
+
const imports = key ? metafile.outputs[key].imports : [];
|
|
52
|
+
const names = new Set();
|
|
53
|
+
for (const imp of imports) {
|
|
54
|
+
if (!imp.external)
|
|
55
|
+
continue;
|
|
56
|
+
const name = packageNameOf(imp.path);
|
|
57
|
+
if (name && !isBuiltin(name))
|
|
58
|
+
names.add(name);
|
|
59
|
+
}
|
|
60
|
+
return [...names].sort();
|
|
61
|
+
}
|
|
62
|
+
function packageNameOf(importPath) {
|
|
63
|
+
if (importPath.startsWith('node:'))
|
|
64
|
+
return null;
|
|
65
|
+
const parts = importPath.split('/');
|
|
66
|
+
if (importPath.startsWith('@'))
|
|
67
|
+
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : null;
|
|
68
|
+
return parts[0] || null;
|
|
69
|
+
}
|
|
70
|
+
function resolveInstalledVersions(sourceDir, packages) {
|
|
71
|
+
const deps = {};
|
|
72
|
+
for (const pkg of packages) {
|
|
73
|
+
deps[pkg] = readInstalledVersion(sourceDir, pkg) ?? 'latest';
|
|
74
|
+
}
|
|
75
|
+
return deps;
|
|
76
|
+
}
|
|
77
|
+
function readInstalledVersion(fromDir, pkg) {
|
|
78
|
+
let dir = path.resolve(fromDir);
|
|
79
|
+
while (true) {
|
|
80
|
+
const pkgJson = path.join(dir, 'node_modules', ...pkg.split('/'), 'package.json');
|
|
81
|
+
if (existsSync(pkgJson)) {
|
|
82
|
+
try {
|
|
83
|
+
const version = JSON.parse(readFileSync(pkgJson, 'utf8')).version;
|
|
84
|
+
if (version)
|
|
85
|
+
return version;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const parent = path.dirname(dir);
|
|
91
|
+
if (parent === dir)
|
|
92
|
+
return null;
|
|
93
|
+
dir = parent;
|
|
94
|
+
}
|
|
95
|
+
}
|