@a5c-ai/babysitter-sdk 0.0.16
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/cli/main.d.ts +5 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +1343 -0
- package/dist/cli/nodeTaskRunner.d.ts +16 -0
- package/dist/cli/nodeTaskRunner.d.ts.map +1 -0
- package/dist/cli/nodeTaskRunner.js +46 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/runner/env.d.ts +58 -0
- package/dist/runner/env.d.ts.map +1 -0
- package/dist/runner/env.js +113 -0
- package/dist/runner/index.d.ts +3 -0
- package/dist/runner/index.d.ts.map +1 -0
- package/dist/runner/index.js +18 -0
- package/dist/runner/nodeRunner.d.ts +60 -0
- package/dist/runner/nodeRunner.d.ts.map +1 -0
- package/dist/runner/nodeRunner.js +354 -0
- package/dist/runtime/commitEffectResult.d.ts +3 -0
- package/dist/runtime/commitEffectResult.d.ts.map +1 -0
- package/dist/runtime/commitEffectResult.js +172 -0
- package/dist/runtime/constants.d.ts +2 -0
- package/dist/runtime/constants.d.ts.map +1 -0
- package/dist/runtime/constants.js +5 -0
- package/dist/runtime/createRun.d.ts +3 -0
- package/dist/runtime/createRun.d.ts.map +1 -0
- package/dist/runtime/createRun.js +81 -0
- package/dist/runtime/errorUtils.d.ts +10 -0
- package/dist/runtime/errorUtils.d.ts.map +1 -0
- package/dist/runtime/errorUtils.js +42 -0
- package/dist/runtime/exceptions.d.ts +45 -0
- package/dist/runtime/exceptions.d.ts.map +1 -0
- package/dist/runtime/exceptions.js +99 -0
- package/dist/runtime/index.d.ts +12 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +34 -0
- package/dist/runtime/instrumentation.d.ts +6 -0
- package/dist/runtime/instrumentation.d.ts.map +1 -0
- package/dist/runtime/instrumentation.js +14 -0
- package/dist/runtime/intrinsics/breakpoint.d.ts +4 -0
- package/dist/runtime/intrinsics/breakpoint.d.ts.map +1 -0
- package/dist/runtime/intrinsics/breakpoint.js +42 -0
- package/dist/runtime/intrinsics/index.d.ts +7 -0
- package/dist/runtime/intrinsics/index.d.ts.map +1 -0
- package/dist/runtime/intrinsics/index.js +15 -0
- package/dist/runtime/intrinsics/orchestratorTask.d.ts +4 -0
- package/dist/runtime/intrinsics/orchestratorTask.d.ts.map +1 -0
- package/dist/runtime/intrinsics/orchestratorTask.js +28 -0
- package/dist/runtime/intrinsics/parallel.d.ts +5 -0
- package/dist/runtime/intrinsics/parallel.d.ts.map +1 -0
- package/dist/runtime/intrinsics/parallel.js +45 -0
- package/dist/runtime/intrinsics/sleep.d.ts +4 -0
- package/dist/runtime/intrinsics/sleep.d.ts.map +1 -0
- package/dist/runtime/intrinsics/sleep.js +70 -0
- package/dist/runtime/intrinsics/task.d.ts +20 -0
- package/dist/runtime/intrinsics/task.d.ts.map +1 -0
- package/dist/runtime/intrinsics/task.js +237 -0
- package/dist/runtime/invocation/hashInvocationKey.d.ts +12 -0
- package/dist/runtime/invocation/hashInvocationKey.d.ts.map +1 -0
- package/dist/runtime/invocation/hashInvocationKey.js +12 -0
- package/dist/runtime/invocation/index.d.ts +3 -0
- package/dist/runtime/invocation/index.d.ts.map +1 -0
- package/dist/runtime/invocation/index.js +5 -0
- package/dist/runtime/orchestrateIteration.d.ts +3 -0
- package/dist/runtime/orchestrateIteration.d.ts.map +1 -0
- package/dist/runtime/orchestrateIteration.js +195 -0
- package/dist/runtime/processContext.d.ts +19 -0
- package/dist/runtime/processContext.d.ts.map +1 -0
- package/dist/runtime/processContext.js +55 -0
- package/dist/runtime/replay/createReplayEngine.d.ts +31 -0
- package/dist/runtime/replay/createReplayEngine.d.ts.map +1 -0
- package/dist/runtime/replay/createReplayEngine.js +82 -0
- package/dist/runtime/replay/effectIndex.d.ts +34 -0
- package/dist/runtime/replay/effectIndex.d.ts.map +1 -0
- package/dist/runtime/replay/effectIndex.js +241 -0
- package/dist/runtime/replay/index.d.ts +7 -0
- package/dist/runtime/replay/index.d.ts.map +1 -0
- package/dist/runtime/replay/index.js +19 -0
- package/dist/runtime/replay/replayCursor.d.ts +7 -0
- package/dist/runtime/replay/replayCursor.d.ts.map +1 -0
- package/dist/runtime/replay/replayCursor.js +22 -0
- package/dist/runtime/replay/stateCache.d.ts +48 -0
- package/dist/runtime/replay/stateCache.d.ts.map +1 -0
- package/dist/runtime/replay/stateCache.js +211 -0
- package/dist/runtime/types.d.ts +147 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/storage/atomic.d.ts +2 -0
- package/dist/storage/atomic.d.ts.map +1 -0
- package/dist/storage/atomic.js +54 -0
- package/dist/storage/cleanup.d.ts +4 -0
- package/dist/storage/cleanup.d.ts.map +1 -0
- package/dist/storage/cleanup.js +96 -0
- package/dist/storage/clock.d.ts +6 -0
- package/dist/storage/clock.d.ts.map +1 -0
- package/dist/storage/clock.js +29 -0
- package/dist/storage/createRunDir.d.ts +6 -0
- package/dist/storage/createRunDir.d.ts.map +1 -0
- package/dist/storage/createRunDir.js +59 -0
- package/dist/storage/index.d.ts +9 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +28 -0
- package/dist/storage/journal.d.ts +4 -0
- package/dist/storage/journal.d.ts.map +1 -0
- package/dist/storage/journal.js +103 -0
- package/dist/storage/lock.d.ts +5 -0
- package/dist/storage/lock.d.ts.map +1 -0
- package/dist/storage/lock.js +41 -0
- package/dist/storage/paths.d.ts +19 -0
- package/dist/storage/paths.d.ts.map +1 -0
- package/dist/storage/paths.js +46 -0
- package/dist/storage/runFiles.d.ts +5 -0
- package/dist/storage/runFiles.d.ts.map +1 -0
- package/dist/storage/runFiles.js +39 -0
- package/dist/storage/snapshotState.d.ts +10 -0
- package/dist/storage/snapshotState.d.ts.map +1 -0
- package/dist/storage/snapshotState.js +15 -0
- package/dist/storage/storeTaskArtifacts.d.ts +6 -0
- package/dist/storage/storeTaskArtifacts.d.ts.map +1 -0
- package/dist/storage/storeTaskArtifacts.js +58 -0
- package/dist/storage/tasks.d.ts +17 -0
- package/dist/storage/tasks.d.ts.map +1 -0
- package/dist/storage/tasks.js +82 -0
- package/dist/storage/types.d.ts +112 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +2 -0
- package/dist/storage/ulids.d.ts +11 -0
- package/dist/storage/ulids.d.ts.map +1 -0
- package/dist/storage/ulids.js +25 -0
- package/dist/tasks/batching.d.ts +29 -0
- package/dist/tasks/batching.d.ts.map +1 -0
- package/dist/tasks/batching.js +66 -0
- package/dist/tasks/context.d.ts +11 -0
- package/dist/tasks/context.d.ts.map +1 -0
- package/dist/tasks/context.js +181 -0
- package/dist/tasks/defineTask.d.ts +9 -0
- package/dist/tasks/defineTask.d.ts.map +1 -0
- package/dist/tasks/defineTask.js +58 -0
- package/dist/tasks/index.d.ts +8 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +23 -0
- package/dist/tasks/kinds/index.d.ts +7 -0
- package/dist/tasks/kinds/index.d.ts.map +1 -0
- package/dist/tasks/kinds/index.js +333 -0
- package/dist/tasks/registry.d.ts +53 -0
- package/dist/tasks/registry.d.ts.map +1 -0
- package/dist/tasks/registry.js +145 -0
- package/dist/tasks/serializer.d.ts +60 -0
- package/dist/tasks/serializer.d.ts.map +1 -0
- package/dist/tasks/serializer.js +193 -0
- package/dist/tasks/types.d.ts +148 -0
- package/dist/tasks/types.d.ts.map +1 -0
- package/dist/tasks/types.js +2 -0
- package/dist/test-fixtures/kinds/index.d.ts +56 -0
- package/dist/test-fixtures/kinds/index.d.ts.map +1 -0
- package/dist/test-fixtures/kinds/index.js +44 -0
- package/dist/testing/deterministic.d.ts +90 -0
- package/dist/testing/deterministic.d.ts.map +1 -0
- package/dist/testing/deterministic.js +449 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +23 -0
- package/dist/testing/runHarness.d.ts +64 -0
- package/dist/testing/runHarness.d.ts.map +1 -0
- package/dist/testing/runHarness.js +161 -0
- package/dist/testing/snapshots.d.ts +17 -0
- package/dist/testing/snapshots.d.ts.map +1 -0
- package/dist/testing/snapshots.js +24 -0
- package/package.json +35 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type UlidFactory = () => string;
|
|
2
|
+
export declare function nextUlid(): string;
|
|
3
|
+
/**
|
|
4
|
+
* Overrides the ULID factory so tests can run with deterministic identifiers.
|
|
5
|
+
*/
|
|
6
|
+
export declare function setUlidFactoryForTests(factory: UlidFactory): void;
|
|
7
|
+
/**
|
|
8
|
+
* Restores the default monotonic ULID factory.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resetUlidFactory(): void;
|
|
11
|
+
//# sourceMappingURL=ulids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ulids.d.ts","sourceRoot":"","sources":["../../src/storage/ulids.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC;AAIvC,wBAAgB,QAAQ,WAEvB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,WAAW,QAK1D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,SAE/B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nextUlid = nextUlid;
|
|
4
|
+
exports.setUlidFactoryForTests = setUlidFactoryForTests;
|
|
5
|
+
exports.resetUlidFactory = resetUlidFactory;
|
|
6
|
+
const ulid_1 = require("ulid");
|
|
7
|
+
let activeFactory = (0, ulid_1.monotonicFactory)();
|
|
8
|
+
function nextUlid() {
|
|
9
|
+
return activeFactory();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Overrides the ULID factory so tests can run with deterministic identifiers.
|
|
13
|
+
*/
|
|
14
|
+
function setUlidFactoryForTests(factory) {
|
|
15
|
+
if (typeof factory !== "function") {
|
|
16
|
+
throw new Error("setUlidFactoryForTests requires a function");
|
|
17
|
+
}
|
|
18
|
+
activeFactory = factory;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Restores the default monotonic ULID factory.
|
|
22
|
+
*/
|
|
23
|
+
function resetUlidFactory() {
|
|
24
|
+
activeFactory = (0, ulid_1.monotonicFactory)();
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { EffectAction } from "../runtime/types";
|
|
2
|
+
import type { JsonRecord } from "../storage/types";
|
|
3
|
+
export interface BatchedEffectSummary {
|
|
4
|
+
effectId: string;
|
|
5
|
+
invocationKey: string;
|
|
6
|
+
taskId?: string;
|
|
7
|
+
stepId?: string;
|
|
8
|
+
kind: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
labels?: string[];
|
|
11
|
+
taskDefRef?: string;
|
|
12
|
+
inputsRef?: string;
|
|
13
|
+
requestedAt?: string;
|
|
14
|
+
metadata?: JsonRecord;
|
|
15
|
+
}
|
|
16
|
+
export interface ParallelBatch {
|
|
17
|
+
actions: EffectAction[];
|
|
18
|
+
summaries: BatchedEffectSummary[];
|
|
19
|
+
}
|
|
20
|
+
export interface ParallelPendingPayload {
|
|
21
|
+
effects: BatchedEffectSummary[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Deduplicates EffectAction entries by effectId while preserving order and builds summaries.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildParallelBatch(actions: EffectAction[]): ParallelBatch;
|
|
27
|
+
export declare function summarizeEffectAction(action: EffectAction): BatchedEffectSummary;
|
|
28
|
+
export declare function toParallelPendingPayload(batch: ParallelBatch): ParallelPendingPayload;
|
|
29
|
+
//# sourceMappingURL=batching.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batching.d.ts","sourceRoot":"","sources":["../../src/tasks/batching.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAwB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,UAAU,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,SAAS,EAAE,oBAAoB,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,oBAAoB,EAAE,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,aAAa,CAiBzE;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,oBAAoB,CAchF;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,aAAa,GAAG,sBAAsB,CAIrF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildParallelBatch = buildParallelBatch;
|
|
4
|
+
exports.summarizeEffectAction = summarizeEffectAction;
|
|
5
|
+
exports.toParallelPendingPayload = toParallelPendingPayload;
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
/**
|
|
8
|
+
* Deduplicates EffectAction entries by effectId while preserving order and builds summaries.
|
|
9
|
+
*/
|
|
10
|
+
function buildParallelBatch(actions) {
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
const deduped = [];
|
|
13
|
+
for (const action of actions) {
|
|
14
|
+
if (seen.has(action.effectId))
|
|
15
|
+
continue;
|
|
16
|
+
seen.add(action.effectId);
|
|
17
|
+
deduped.push(action);
|
|
18
|
+
}
|
|
19
|
+
const annotated = assignParallelGroupHints(deduped);
|
|
20
|
+
const summaries = annotated.map(summarizeEffectAction);
|
|
21
|
+
return {
|
|
22
|
+
actions: annotated,
|
|
23
|
+
summaries,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function summarizeEffectAction(action) {
|
|
27
|
+
return {
|
|
28
|
+
effectId: action.effectId,
|
|
29
|
+
invocationKey: action.invocationKey,
|
|
30
|
+
taskId: action.taskId,
|
|
31
|
+
stepId: action.stepId,
|
|
32
|
+
kind: action.kind,
|
|
33
|
+
label: action.label,
|
|
34
|
+
labels: action.labels ? [...action.labels] : undefined,
|
|
35
|
+
taskDefRef: action.taskDefRef,
|
|
36
|
+
inputsRef: action.inputsRef,
|
|
37
|
+
requestedAt: action.requestedAt,
|
|
38
|
+
metadata: action.taskDef?.metadata,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function toParallelPendingPayload(batch) {
|
|
42
|
+
return {
|
|
43
|
+
effects: batch.summaries,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function assignParallelGroupHints(actions) {
|
|
47
|
+
if (actions.length <= 1) {
|
|
48
|
+
return actions;
|
|
49
|
+
}
|
|
50
|
+
const hash = (0, crypto_1.createHash)("sha1");
|
|
51
|
+
actions.forEach((action) => {
|
|
52
|
+
hash.update(action.invocationKey ?? action.effectId);
|
|
53
|
+
hash.update("|");
|
|
54
|
+
});
|
|
55
|
+
const parallelGroupId = hash.digest("hex").slice(0, 16);
|
|
56
|
+
return actions.map((action) => ({
|
|
57
|
+
...action,
|
|
58
|
+
schedulerHints: mergeSchedulerHints(action.schedulerHints, { parallelGroupId }),
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
function mergeSchedulerHints(base, extra) {
|
|
62
|
+
return {
|
|
63
|
+
...(base ?? {}),
|
|
64
|
+
...extra,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TaskBuildContext } from "./types";
|
|
2
|
+
export interface CreateTaskBuildContextOptions {
|
|
3
|
+
runId: string;
|
|
4
|
+
runDir: string;
|
|
5
|
+
effectId: string;
|
|
6
|
+
invocationKey: string;
|
|
7
|
+
taskId: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createTaskBuildContext(options: CreateTaskBuildContextOptions): TaskBuildContext;
|
|
11
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/tasks/context.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAO7D,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,6BAA6B,GAAG,gBAAgB,CAoC/F"}
|
|
@@ -0,0 +1,181 @@
|
|
|
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.createTaskBuildContext = createTaskBuildContext;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const atomic_1 = require("../storage/atomic");
|
|
11
|
+
const paths_1 = require("../storage/paths");
|
|
12
|
+
const DEFAULT_TEXT_ENCODING = "utf8";
|
|
13
|
+
const DEFAULT_JSON_EXTENSION = ".json";
|
|
14
|
+
const MAX_BLOB_BASENAME_LENGTH = 128;
|
|
15
|
+
const HASH_SUFFIX_LENGTH = 10;
|
|
16
|
+
function createTaskBuildContext(options) {
|
|
17
|
+
const runId = mustBeNonEmpty(options.runId, "runId");
|
|
18
|
+
const runDir = path_1.default.resolve(mustBeNonEmpty(options.runDir, "runDir"));
|
|
19
|
+
const effectId = mustBeNonEmpty(options.effectId, "effectId");
|
|
20
|
+
const invocationKey = mustBeNonEmpty(options.invocationKey, "invocationKey");
|
|
21
|
+
const taskId = mustBeNonEmpty(options.taskId, "taskId");
|
|
22
|
+
const tasksRoot = (0, paths_1.getTasksDir)(runDir);
|
|
23
|
+
const taskDir = path_1.default.join(tasksRoot, effectId);
|
|
24
|
+
const normalizedLabel = normalizeLabel(options.label);
|
|
25
|
+
const labels = normalizedLabel ? [normalizedLabel] : [];
|
|
26
|
+
const ctx = {
|
|
27
|
+
effectId,
|
|
28
|
+
invocationKey,
|
|
29
|
+
taskId,
|
|
30
|
+
runId,
|
|
31
|
+
runDir,
|
|
32
|
+
taskDir,
|
|
33
|
+
tasksDir: tasksRoot,
|
|
34
|
+
label: normalizedLabel,
|
|
35
|
+
labels,
|
|
36
|
+
async createBlobRef(name, value, blobOptions) {
|
|
37
|
+
const prepared = prepareBlobContents(value, blobOptions);
|
|
38
|
+
const blobName = buildBlobFileName(name, prepared.defaultExtension, prepared.contents);
|
|
39
|
+
const blobDir = path_1.default.join(taskDir, "blobs");
|
|
40
|
+
await fs_1.promises.mkdir(blobDir, { recursive: true });
|
|
41
|
+
const blobPath = path_1.default.join(blobDir, blobName);
|
|
42
|
+
await (0, atomic_1.writeFileAtomic)(blobPath, prepared.contents);
|
|
43
|
+
return toRunRelative(runDir, blobPath);
|
|
44
|
+
},
|
|
45
|
+
toTaskRelativePath(relativePath) {
|
|
46
|
+
const normalized = normalizeTaskRelativePath(relativePath);
|
|
47
|
+
const absolute = path_1.default.join(taskDir, normalized);
|
|
48
|
+
return toRunRelative(runDir, absolute);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
return Object.freeze(ctx);
|
|
52
|
+
}
|
|
53
|
+
function mustBeNonEmpty(value, field) {
|
|
54
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
55
|
+
throw new Error(`TaskBuildContext requires a non-empty ${field}`);
|
|
56
|
+
}
|
|
57
|
+
return value.trim();
|
|
58
|
+
}
|
|
59
|
+
function normalizeLabel(label) {
|
|
60
|
+
if (!label)
|
|
61
|
+
return undefined;
|
|
62
|
+
const trimmed = label.trim();
|
|
63
|
+
return trimmed.length ? trimmed : undefined;
|
|
64
|
+
}
|
|
65
|
+
function buildBlobFileName(rawName, defaultExtension, contents) {
|
|
66
|
+
const safeName = sanitizeBlobName(rawName, defaultExtension);
|
|
67
|
+
const digest = hashBuffer(contents);
|
|
68
|
+
return appendDigestSuffix(safeName, digest);
|
|
69
|
+
}
|
|
70
|
+
function sanitizeBlobName(rawName, defaultExtension) {
|
|
71
|
+
if (typeof rawName !== "string") {
|
|
72
|
+
throw new Error("Blob name must be a non-empty string");
|
|
73
|
+
}
|
|
74
|
+
const trimmed = rawName.trim();
|
|
75
|
+
if (!trimmed.length) {
|
|
76
|
+
throw new Error("Blob name must be a non-empty string");
|
|
77
|
+
}
|
|
78
|
+
const normalized = trimmed.replace(/[\\/]+/g, "/");
|
|
79
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
80
|
+
let safe = segments.join("-").replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
81
|
+
safe = safe.replace(/-+/g, "-");
|
|
82
|
+
safe = safe.replace(/^[-.]+/, "").replace(/[-.]+$/, "");
|
|
83
|
+
if (!safe.length) {
|
|
84
|
+
throw new Error("Blob name must include alphanumeric characters");
|
|
85
|
+
}
|
|
86
|
+
if (defaultExtension && !safe.includes(".")) {
|
|
87
|
+
const ext = defaultExtension.startsWith(".") ? defaultExtension : `.${defaultExtension}`;
|
|
88
|
+
safe = `${safe}${ext}`;
|
|
89
|
+
}
|
|
90
|
+
return clampBlobName(safe);
|
|
91
|
+
}
|
|
92
|
+
function clampBlobName(name) {
|
|
93
|
+
if (name.length <= MAX_BLOB_BASENAME_LENGTH) {
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
const ext = path_1.default.posix.extname(name);
|
|
97
|
+
const base = ext ? name.slice(0, -ext.length) : name;
|
|
98
|
+
const available = Math.max(8, MAX_BLOB_BASENAME_LENGTH - ext.length - HASH_SUFFIX_LENGTH - 1);
|
|
99
|
+
const truncated = base.slice(0, available);
|
|
100
|
+
const suffix = hashString(name);
|
|
101
|
+
return ext ? `${truncated}-${suffix}${ext}` : `${truncated}-${suffix}`;
|
|
102
|
+
}
|
|
103
|
+
function appendDigestSuffix(name, digest) {
|
|
104
|
+
if (!digest)
|
|
105
|
+
return name;
|
|
106
|
+
const ext = path_1.default.posix.extname(name);
|
|
107
|
+
if (!ext) {
|
|
108
|
+
return `${name}-${digest}`;
|
|
109
|
+
}
|
|
110
|
+
return `${name.slice(0, -ext.length)}-${digest}${ext}`;
|
|
111
|
+
}
|
|
112
|
+
function normalizeTaskRelativePath(value) {
|
|
113
|
+
if (typeof value !== "string") {
|
|
114
|
+
throw new Error("Relative path must be a string");
|
|
115
|
+
}
|
|
116
|
+
const trimmed = value.trim();
|
|
117
|
+
if (!trimmed.length) {
|
|
118
|
+
throw new Error("Relative path must be non-empty");
|
|
119
|
+
}
|
|
120
|
+
if (path_1.default.isAbsolute(trimmed)) {
|
|
121
|
+
throw new Error("Task-relative paths must not be absolute");
|
|
122
|
+
}
|
|
123
|
+
const replaced = trimmed.replace(/\\/g, "/");
|
|
124
|
+
const segments = replaced.split("/").filter(Boolean);
|
|
125
|
+
if (!segments.length) {
|
|
126
|
+
throw new Error("Relative path must include a filename");
|
|
127
|
+
}
|
|
128
|
+
const normalized = [];
|
|
129
|
+
for (const segment of segments) {
|
|
130
|
+
if (segment === ".")
|
|
131
|
+
continue;
|
|
132
|
+
if (segment === "..") {
|
|
133
|
+
throw new Error("Task-relative paths cannot traverse above the task directory");
|
|
134
|
+
}
|
|
135
|
+
normalized.push(segment);
|
|
136
|
+
}
|
|
137
|
+
if (!normalized.length) {
|
|
138
|
+
throw new Error("Relative path must include a filename");
|
|
139
|
+
}
|
|
140
|
+
return normalized.join("/");
|
|
141
|
+
}
|
|
142
|
+
function toRunRelative(runDir, absolutePath) {
|
|
143
|
+
const relative = path_1.default.relative(runDir, absolutePath);
|
|
144
|
+
if (!relative || relative.startsWith("..") || path_1.default.isAbsolute(relative)) {
|
|
145
|
+
throw new Error(`Path ${absolutePath} is not inside run directory ${runDir}`);
|
|
146
|
+
}
|
|
147
|
+
return relative.split(path_1.default.sep).join("/");
|
|
148
|
+
}
|
|
149
|
+
function hashString(value) {
|
|
150
|
+
return crypto_1.default.createHash("sha1").update(value).digest("hex").slice(0, HASH_SUFFIX_LENGTH);
|
|
151
|
+
}
|
|
152
|
+
function hashBuffer(contents) {
|
|
153
|
+
return crypto_1.default.createHash("sha256").update(contents).digest("hex");
|
|
154
|
+
}
|
|
155
|
+
function prepareBlobContents(value, options) {
|
|
156
|
+
const treatAsJson = shouldSerializeAsJson(value, options);
|
|
157
|
+
if (typeof value === "string" && !treatAsJson) {
|
|
158
|
+
const encoding = options?.encoding ?? DEFAULT_TEXT_ENCODING;
|
|
159
|
+
return {
|
|
160
|
+
contents: Buffer.from(value, encoding),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (Buffer.isBuffer(value) && !treatAsJson) {
|
|
164
|
+
return {
|
|
165
|
+
contents: value,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const normalizedValue = value === undefined ? null : value;
|
|
169
|
+
const serialized = JSON.stringify(normalizedValue, null, 2) ?? "null";
|
|
170
|
+
const withNewline = serialized.endsWith("\n") ? serialized : `${serialized}\n`;
|
|
171
|
+
return {
|
|
172
|
+
contents: Buffer.from(withNewline, DEFAULT_TEXT_ENCODING),
|
|
173
|
+
defaultExtension: DEFAULT_JSON_EXTENSION,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function shouldSerializeAsJson(value, options) {
|
|
177
|
+
if (options?.asJson !== undefined) {
|
|
178
|
+
return options.asJson;
|
|
179
|
+
}
|
|
180
|
+
return !(typeof value === "string" || Buffer.isBuffer(value));
|
|
181
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DefinedTask, TaskImpl } from "./types";
|
|
2
|
+
export interface DefineTaskOptions {
|
|
3
|
+
description?: string;
|
|
4
|
+
labels?: string[];
|
|
5
|
+
kind?: string;
|
|
6
|
+
source?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function defineTask<TArgs = unknown, TResult = unknown>(id: string, impl: TaskImpl<TArgs, TResult>, options?: DefineTaskOptions): DefinedTask<TArgs, TResult>;
|
|
9
|
+
//# sourceMappingURL=defineTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineTask.d.ts","sourceRoot":"","sources":["../../src/tasks/defineTask.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAA6B,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE3E,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,UAAU,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC3D,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,EAC9B,OAAO,GAAE,iBAAsB,GAC9B,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAoB7B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineTask = defineTask;
|
|
4
|
+
const registry_1 = require("./registry");
|
|
5
|
+
function defineTask(id, impl, options = {}) {
|
|
6
|
+
const taskId = normalizeTaskId(id);
|
|
7
|
+
registerTaskId(taskId, options);
|
|
8
|
+
const defined = {
|
|
9
|
+
id: taskId,
|
|
10
|
+
async build(args, ctx) {
|
|
11
|
+
const taskDef = await Promise.resolve(impl(args, ctx));
|
|
12
|
+
const normalized = normalizeTaskDef(taskDef);
|
|
13
|
+
const mergedLabels = [...(options.labels ?? []), ...(normalized.labels ?? [])];
|
|
14
|
+
registry_1.globalTaskRegistry.recordDefinitionMetadata(taskId, {
|
|
15
|
+
kind: normalized.kind,
|
|
16
|
+
description: normalized.description ?? options.description,
|
|
17
|
+
labels: mergedLabels,
|
|
18
|
+
});
|
|
19
|
+
return normalized;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
return Object.freeze(defined);
|
|
23
|
+
}
|
|
24
|
+
function registerTaskId(taskId, options) {
|
|
25
|
+
try {
|
|
26
|
+
registry_1.globalTaskRegistry.registerDefinition({
|
|
27
|
+
id: taskId,
|
|
28
|
+
kind: options.kind,
|
|
29
|
+
description: options.description,
|
|
30
|
+
labels: options.labels ?? [],
|
|
31
|
+
source: options.source,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error instanceof registry_1.DuplicateTaskIdError) {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
throw new registry_1.DuplicateTaskIdError(taskId);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function normalizeTaskId(id) {
|
|
42
|
+
if (typeof id !== "string" || !id.trim()) {
|
|
43
|
+
throw new Error("defineTask requires a non-empty string id");
|
|
44
|
+
}
|
|
45
|
+
return id.trim();
|
|
46
|
+
}
|
|
47
|
+
function normalizeTaskDef(taskDef) {
|
|
48
|
+
if (!taskDef || typeof taskDef !== "object") {
|
|
49
|
+
throw new Error("Task implementations must return a TaskDef object");
|
|
50
|
+
}
|
|
51
|
+
const labels = Array.isArray(taskDef.labels)
|
|
52
|
+
? taskDef.labels.filter((label) => typeof label === "string" && Boolean(label.trim()))
|
|
53
|
+
: undefined;
|
|
54
|
+
if (labels) {
|
|
55
|
+
taskDef.labels = Array.from(new Set(labels.map((label) => label.trim())));
|
|
56
|
+
}
|
|
57
|
+
return taskDef;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tasks/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./defineTask"), exports);
|
|
18
|
+
__exportStar(require("./context"), exports);
|
|
19
|
+
__exportStar(require("./serializer"), exports);
|
|
20
|
+
__exportStar(require("./registry"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
__exportStar(require("./kinds"), exports);
|
|
23
|
+
__exportStar(require("./batching"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JsonRecord } from "../../storage/types";
|
|
2
|
+
import { BreakpointTaskDefinitionOptions, DefinedTask, NodeTaskDefinitionOptions, OrchestratorTaskDefinitionOptions, SleepTaskBuilderArgs, SleepTaskDefinitionOptions } from "../types";
|
|
3
|
+
export declare function nodeTask<TArgs = unknown, TResult = unknown>(id: string, options: NodeTaskDefinitionOptions<TArgs>): DefinedTask<TArgs, TResult>;
|
|
4
|
+
export declare function breakpointTask<TArgs = unknown, TResult = void>(id: string, options?: BreakpointTaskDefinitionOptions<TArgs>): DefinedTask<TArgs, TResult>;
|
|
5
|
+
export declare function orchestratorTask<TArgs = JsonRecord, TResult = unknown>(id: string, options?: OrchestratorTaskDefinitionOptions<TArgs>): DefinedTask<TArgs, TResult>;
|
|
6
|
+
export declare function sleepTask<TArgs extends SleepTaskBuilderArgs = SleepTaskBuilderArgs>(id?: string, options?: SleepTaskDefinitionOptions<TArgs>): DefinedTask<TArgs, void>;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tasks/kinds/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EACL,+BAA+B,EAE/B,WAAW,EACX,yBAAyB,EAEzB,iCAAiC,EAEjC,oBAAoB,EACpB,0BAA0B,EAK3B,MAAM,UAAU,CAAC;AAUlB,wBAAgB,QAAQ,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EACzD,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,yBAAyB,CAAC,KAAK,CAAC,GACxC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAiD7B;AAED,wBAAgB,cAAc,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAG,IAAI,EAC5D,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,+BAA+B,CAAC,KAAK,CAAM,GACnD,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CA4B7B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,GAAG,UAAU,EAAE,OAAO,GAAG,OAAO,EACpE,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,iCAAiC,CAAC,KAAK,CAAM,GACrD,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CA8B7B;AAED,wBAAgB,SAAS,CAAC,KAAK,SAAS,oBAAoB,GAAG,oBAAoB,EACjF,EAAE,SAAwB,EAC1B,OAAO,GAAE,0BAA0B,CAAC,KAAK,CAAM,GAC9C,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAoC1B"}
|