@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,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeUnknownError = serializeUnknownError;
|
|
4
|
+
exports.toSerializedEffectError = toSerializedEffectError;
|
|
5
|
+
function serializeUnknownError(error) {
|
|
6
|
+
if (error instanceof Error) {
|
|
7
|
+
return {
|
|
8
|
+
name: error.name ?? "Error",
|
|
9
|
+
message: error.message ?? "Unknown error",
|
|
10
|
+
stack: error.stack,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
if (typeof error === "object" && error) {
|
|
14
|
+
return {
|
|
15
|
+
name: error.constructor?.name ?? "Error",
|
|
16
|
+
message: JSON.stringify(error),
|
|
17
|
+
data: error,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
name: "Error",
|
|
22
|
+
message: String(error),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function toSerializedEffectError(error) {
|
|
26
|
+
if (error && typeof error === "object" && "name" in error) {
|
|
27
|
+
const err = error;
|
|
28
|
+
return {
|
|
29
|
+
name: err.name ?? "Error",
|
|
30
|
+
message: err.message ?? "Task failed",
|
|
31
|
+
stack: typeof err.stack === "string" ? err.stack : undefined,
|
|
32
|
+
data: err.data,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const serialized = serializeUnknownError(error);
|
|
36
|
+
return {
|
|
37
|
+
name: serialized.name,
|
|
38
|
+
message: serialized.message,
|
|
39
|
+
stack: serialized.stack,
|
|
40
|
+
data: serialized.data,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EffectAction, SerializedEffectError } from "./types";
|
|
2
|
+
import { type ParallelBatch } from "../tasks/batching";
|
|
3
|
+
export interface BabysitterErrorDetails {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare class BabysitterRuntimeError extends Error {
|
|
7
|
+
readonly details?: BabysitterErrorDetails;
|
|
8
|
+
constructor(name: string, message: string, details?: BabysitterErrorDetails);
|
|
9
|
+
}
|
|
10
|
+
export declare class BabysitterIntrinsicError extends BabysitterRuntimeError {
|
|
11
|
+
readonly isIntrinsic = true;
|
|
12
|
+
constructor(name: string, message: string, details?: BabysitterErrorDetails);
|
|
13
|
+
}
|
|
14
|
+
export declare class EffectRequestedError extends BabysitterIntrinsicError {
|
|
15
|
+
readonly action: EffectAction;
|
|
16
|
+
constructor(action: EffectAction);
|
|
17
|
+
}
|
|
18
|
+
export declare class EffectPendingError extends BabysitterIntrinsicError {
|
|
19
|
+
readonly action: EffectAction;
|
|
20
|
+
constructor(action: EffectAction);
|
|
21
|
+
}
|
|
22
|
+
export declare class ParallelPendingError extends BabysitterIntrinsicError {
|
|
23
|
+
readonly batch: ParallelBatch;
|
|
24
|
+
readonly effects: EffectAction[];
|
|
25
|
+
constructor(batch: ParallelBatch);
|
|
26
|
+
}
|
|
27
|
+
export declare class InvocationCollisionError extends BabysitterRuntimeError {
|
|
28
|
+
readonly invocationKey: string;
|
|
29
|
+
constructor(invocationKey: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class RunFailedError extends BabysitterRuntimeError {
|
|
32
|
+
constructor(message: string, details?: BabysitterErrorDetails);
|
|
33
|
+
}
|
|
34
|
+
export declare class MissingProcessContextError extends BabysitterRuntimeError {
|
|
35
|
+
constructor();
|
|
36
|
+
}
|
|
37
|
+
export declare class InvalidTaskDefinitionError extends BabysitterRuntimeError {
|
|
38
|
+
constructor(reason: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class InvalidSleepTargetError extends BabysitterRuntimeError {
|
|
41
|
+
constructor(value: string | number);
|
|
42
|
+
}
|
|
43
|
+
export declare function isIntrinsicError(error: unknown): error is BabysitterIntrinsicError;
|
|
44
|
+
export declare function rehydrateSerializedError(data?: SerializedEffectError): Error;
|
|
45
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/runtime/exceptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEjF,MAAM,WAAW,sBAAsB;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,OAAO,CAAC,EAAE,sBAAsB,CAAC;gBAE9B,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;CAK5E;AAED,qBAAa,wBAAyB,SAAQ,sBAAsB;IAClE,QAAQ,CAAC,WAAW,QAAQ;gBAEhB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;CAG5E;AAED,qBAAa,oBAAqB,SAAQ,wBAAwB;aACpC,MAAM,EAAE,YAAY;gBAApB,MAAM,EAAE,YAAY;CAGjD;AAED,qBAAa,kBAAmB,SAAQ,wBAAwB;aAClC,MAAM,EAAE,YAAY;gBAApB,MAAM,EAAE,YAAY;CAGjD;AAED,qBAAa,oBAAqB,SAAQ,wBAAwB;aAEpC,KAAK,EAAE,aAAa;IADhD,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;gBACL,KAAK,EAAE,aAAa;CAOjD;AAED,qBAAa,wBAAyB,SAAQ,sBAAsB;aACtC,aAAa,EAAE,MAAM;gBAArB,aAAa,EAAE,MAAM;CAOlD;AAED,qBAAa,cAAe,SAAQ,sBAAsB;gBAC5C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;CAG9D;AAED,qBAAa,0BAA2B,SAAQ,sBAAsB;;CAIrE;AAED,qBAAa,0BAA2B,SAAQ,sBAAsB;gBACxD,MAAM,EAAE,MAAM;CAG3B;AAED,qBAAa,uBAAwB,SAAQ,sBAAsB;gBACrD,KAAK,EAAE,MAAM,GAAG,MAAM;CAGnC;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,wBAAwB,CAElF;AAID,wBAAgB,wBAAwB,CAAC,IAAI,CAAC,EAAE,qBAAqB,GAAG,KAAK,CAY5E"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidSleepTargetError = exports.InvalidTaskDefinitionError = exports.MissingProcessContextError = exports.RunFailedError = exports.InvocationCollisionError = exports.ParallelPendingError = exports.EffectPendingError = exports.EffectRequestedError = exports.BabysitterIntrinsicError = exports.BabysitterRuntimeError = void 0;
|
|
4
|
+
exports.isIntrinsicError = isIntrinsicError;
|
|
5
|
+
exports.rehydrateSerializedError = rehydrateSerializedError;
|
|
6
|
+
const batching_1 = require("../tasks/batching");
|
|
7
|
+
class BabysitterRuntimeError extends Error {
|
|
8
|
+
details;
|
|
9
|
+
constructor(name, message, details) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = name;
|
|
12
|
+
this.details = details;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.BabysitterRuntimeError = BabysitterRuntimeError;
|
|
16
|
+
class BabysitterIntrinsicError extends BabysitterRuntimeError {
|
|
17
|
+
isIntrinsic = true;
|
|
18
|
+
constructor(name, message, details) {
|
|
19
|
+
super(name, message, details);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.BabysitterIntrinsicError = BabysitterIntrinsicError;
|
|
23
|
+
class EffectRequestedError extends BabysitterIntrinsicError {
|
|
24
|
+
action;
|
|
25
|
+
constructor(action) {
|
|
26
|
+
super("EffectRequestedError", `Effect ${action.effectId} requested`, { action });
|
|
27
|
+
this.action = action;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.EffectRequestedError = EffectRequestedError;
|
|
31
|
+
class EffectPendingError extends BabysitterIntrinsicError {
|
|
32
|
+
action;
|
|
33
|
+
constructor(action) {
|
|
34
|
+
super("EffectPendingError", `Effect ${action.effectId} pending`, { action });
|
|
35
|
+
this.action = action;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.EffectPendingError = EffectPendingError;
|
|
39
|
+
class ParallelPendingError extends BabysitterIntrinsicError {
|
|
40
|
+
batch;
|
|
41
|
+
effects;
|
|
42
|
+
constructor(batch) {
|
|
43
|
+
super("ParallelPendingError", "One or more parallel invocations are pending", {
|
|
44
|
+
payload: (0, batching_1.toParallelPendingPayload)(batch),
|
|
45
|
+
effects: batch.actions,
|
|
46
|
+
});
|
|
47
|
+
this.batch = batch;
|
|
48
|
+
this.effects = batch.actions;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ParallelPendingError = ParallelPendingError;
|
|
52
|
+
class InvocationCollisionError extends BabysitterRuntimeError {
|
|
53
|
+
invocationKey;
|
|
54
|
+
constructor(invocationKey) {
|
|
55
|
+
super("InvocationCollisionError", `Invocation key ${invocationKey} is already in use within this run`, { invocationKey });
|
|
56
|
+
this.invocationKey = invocationKey;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.InvocationCollisionError = InvocationCollisionError;
|
|
60
|
+
class RunFailedError extends BabysitterRuntimeError {
|
|
61
|
+
constructor(message, details) {
|
|
62
|
+
super("RunFailedError", message, details);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.RunFailedError = RunFailedError;
|
|
66
|
+
class MissingProcessContextError extends BabysitterRuntimeError {
|
|
67
|
+
constructor() {
|
|
68
|
+
super("MissingProcessContextError", "No active process context found on the current async call stack");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.MissingProcessContextError = MissingProcessContextError;
|
|
72
|
+
class InvalidTaskDefinitionError extends BabysitterRuntimeError {
|
|
73
|
+
constructor(reason) {
|
|
74
|
+
super("InvalidTaskDefinitionError", reason);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.InvalidTaskDefinitionError = InvalidTaskDefinitionError;
|
|
78
|
+
class InvalidSleepTargetError extends BabysitterRuntimeError {
|
|
79
|
+
constructor(value) {
|
|
80
|
+
super("InvalidSleepTargetError", `Invalid sleep target: ${value}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.InvalidSleepTargetError = InvalidSleepTargetError;
|
|
84
|
+
function isIntrinsicError(error) {
|
|
85
|
+
return Boolean(error && typeof error === "object" && error.isIntrinsic);
|
|
86
|
+
}
|
|
87
|
+
function rehydrateSerializedError(data) {
|
|
88
|
+
const name = data?.name ?? "TaskError";
|
|
89
|
+
const message = data?.message ?? "Task failed";
|
|
90
|
+
const err = new Error(message);
|
|
91
|
+
err.name = name;
|
|
92
|
+
if (data?.stack) {
|
|
93
|
+
err.stack = data.stack;
|
|
94
|
+
}
|
|
95
|
+
if (data?.data !== undefined) {
|
|
96
|
+
err.data = data.data;
|
|
97
|
+
}
|
|
98
|
+
return err;
|
|
99
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { createRun } from "./createRun";
|
|
2
|
+
export { orchestrateIteration } from "./orchestrateIteration";
|
|
3
|
+
export { commitEffectResult } from "./commitEffectResult";
|
|
4
|
+
export { createReplayEngine } from "./replay";
|
|
5
|
+
export { createProcessContext, withProcessContext, getActiveProcessContext, requireProcessContext, } from "./processContext";
|
|
6
|
+
export type { OrchestrateOptions, IterationResult, EffectAction, CommitEffectResultOptions, CommitEffectResultArtifacts, ProcessContext, DefinedTask, CreateRunOptions, CreateRunResult, } from "./types";
|
|
7
|
+
export { STATE_CACHE_SCHEMA_VERSION, createStateCacheSnapshot, journalHeadsEqual, normalizeJournalHead, normalizeSnapshot, readStateCache, rebuildStateCache, writeStateCache, } from "./replay";
|
|
8
|
+
export type { ReplayEngine, CreateReplayEngineOptions, StateCacheSnapshot, StateCacheJournalHead, DerivedEffectSummary, } from "./replay";
|
|
9
|
+
export { hashInvocationKey } from "./invocation";
|
|
10
|
+
export { EffectRequestedError, EffectPendingError, ParallelPendingError, RunFailedError } from "./exceptions";
|
|
11
|
+
export { replaySchemaVersion } from "./constants";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,yBAAyB,EACzB,2BAA2B,EAC3B,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaySchemaVersion = exports.RunFailedError = exports.ParallelPendingError = exports.EffectPendingError = exports.EffectRequestedError = exports.hashInvocationKey = exports.writeStateCache = exports.rebuildStateCache = exports.readStateCache = exports.normalizeSnapshot = exports.normalizeJournalHead = exports.journalHeadsEqual = exports.createStateCacheSnapshot = exports.STATE_CACHE_SCHEMA_VERSION = exports.requireProcessContext = exports.getActiveProcessContext = exports.withProcessContext = exports.createProcessContext = exports.createReplayEngine = exports.commitEffectResult = exports.orchestrateIteration = exports.createRun = void 0;
|
|
4
|
+
var createRun_1 = require("./createRun");
|
|
5
|
+
Object.defineProperty(exports, "createRun", { enumerable: true, get: function () { return createRun_1.createRun; } });
|
|
6
|
+
var orchestrateIteration_1 = require("./orchestrateIteration");
|
|
7
|
+
Object.defineProperty(exports, "orchestrateIteration", { enumerable: true, get: function () { return orchestrateIteration_1.orchestrateIteration; } });
|
|
8
|
+
var commitEffectResult_1 = require("./commitEffectResult");
|
|
9
|
+
Object.defineProperty(exports, "commitEffectResult", { enumerable: true, get: function () { return commitEffectResult_1.commitEffectResult; } });
|
|
10
|
+
var replay_1 = require("./replay");
|
|
11
|
+
Object.defineProperty(exports, "createReplayEngine", { enumerable: true, get: function () { return replay_1.createReplayEngine; } });
|
|
12
|
+
var processContext_1 = require("./processContext");
|
|
13
|
+
Object.defineProperty(exports, "createProcessContext", { enumerable: true, get: function () { return processContext_1.createProcessContext; } });
|
|
14
|
+
Object.defineProperty(exports, "withProcessContext", { enumerable: true, get: function () { return processContext_1.withProcessContext; } });
|
|
15
|
+
Object.defineProperty(exports, "getActiveProcessContext", { enumerable: true, get: function () { return processContext_1.getActiveProcessContext; } });
|
|
16
|
+
Object.defineProperty(exports, "requireProcessContext", { enumerable: true, get: function () { return processContext_1.requireProcessContext; } });
|
|
17
|
+
var replay_2 = require("./replay");
|
|
18
|
+
Object.defineProperty(exports, "STATE_CACHE_SCHEMA_VERSION", { enumerable: true, get: function () { return replay_2.STATE_CACHE_SCHEMA_VERSION; } });
|
|
19
|
+
Object.defineProperty(exports, "createStateCacheSnapshot", { enumerable: true, get: function () { return replay_2.createStateCacheSnapshot; } });
|
|
20
|
+
Object.defineProperty(exports, "journalHeadsEqual", { enumerable: true, get: function () { return replay_2.journalHeadsEqual; } });
|
|
21
|
+
Object.defineProperty(exports, "normalizeJournalHead", { enumerable: true, get: function () { return replay_2.normalizeJournalHead; } });
|
|
22
|
+
Object.defineProperty(exports, "normalizeSnapshot", { enumerable: true, get: function () { return replay_2.normalizeSnapshot; } });
|
|
23
|
+
Object.defineProperty(exports, "readStateCache", { enumerable: true, get: function () { return replay_2.readStateCache; } });
|
|
24
|
+
Object.defineProperty(exports, "rebuildStateCache", { enumerable: true, get: function () { return replay_2.rebuildStateCache; } });
|
|
25
|
+
Object.defineProperty(exports, "writeStateCache", { enumerable: true, get: function () { return replay_2.writeStateCache; } });
|
|
26
|
+
var invocation_1 = require("./invocation");
|
|
27
|
+
Object.defineProperty(exports, "hashInvocationKey", { enumerable: true, get: function () { return invocation_1.hashInvocationKey; } });
|
|
28
|
+
var exceptions_1 = require("./exceptions");
|
|
29
|
+
Object.defineProperty(exports, "EffectRequestedError", { enumerable: true, get: function () { return exceptions_1.EffectRequestedError; } });
|
|
30
|
+
Object.defineProperty(exports, "EffectPendingError", { enumerable: true, get: function () { return exceptions_1.EffectPendingError; } });
|
|
31
|
+
Object.defineProperty(exports, "ParallelPendingError", { enumerable: true, get: function () { return exceptions_1.ParallelPendingError; } });
|
|
32
|
+
Object.defineProperty(exports, "RunFailedError", { enumerable: true, get: function () { return exceptions_1.RunFailedError; } });
|
|
33
|
+
var constants_1 = require("./constants");
|
|
34
|
+
Object.defineProperty(exports, "replaySchemaVersion", { enumerable: true, get: function () { return constants_1.replaySchemaVersion; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type RuntimeLogger = (...args: any[]) => void;
|
|
2
|
+
export interface MetricPayload extends Record<string, unknown> {
|
|
3
|
+
metric: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function emitRuntimeMetric(logger: RuntimeLogger | undefined, metric: string, payload?: Record<string, unknown>): void;
|
|
6
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/runtime/instrumentation.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAErD,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACpC,IAAI,CAQN"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitRuntimeMetric = emitRuntimeMetric;
|
|
4
|
+
function emitRuntimeMetric(logger, metric, payload = {}) {
|
|
5
|
+
if (!logger)
|
|
6
|
+
return;
|
|
7
|
+
const entry = { metric, ...payload };
|
|
8
|
+
try {
|
|
9
|
+
logger(entry);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// Swallow logger failures to avoid breaking orchestrations.
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TaskInvokeOptions } from "../types";
|
|
2
|
+
import { TaskIntrinsicContext } from "./task";
|
|
3
|
+
export declare function runBreakpointIntrinsic<T = unknown>(payload: T, context: TaskIntrinsicContext, options?: TaskInvokeOptions): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=breakpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breakpoint.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/breakpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAoB,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AA0BhE,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,OAAO,EAChD,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,oBAAoB,EAC7B,OAAO,CAAC,EAAE,iBAAiB,iBAU5B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runBreakpointIntrinsic = runBreakpointIntrinsic;
|
|
4
|
+
const task_1 = require("./task");
|
|
5
|
+
const BREAKPOINT_TASK_ID = "__sdk.breakpoint";
|
|
6
|
+
const DEFAULT_BREAKPOINT_LABEL = "breakpoint";
|
|
7
|
+
const breakpointTask = {
|
|
8
|
+
id: BREAKPOINT_TASK_ID,
|
|
9
|
+
async build(args) {
|
|
10
|
+
return {
|
|
11
|
+
kind: "breakpoint",
|
|
12
|
+
title: args.label,
|
|
13
|
+
metadata: {
|
|
14
|
+
payload: args?.payload,
|
|
15
|
+
requestedAt: args.requestedAt,
|
|
16
|
+
label: args.label,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
function runBreakpointIntrinsic(payload, context, options) {
|
|
22
|
+
const label = deriveBreakpointLabel(payload, options?.label);
|
|
23
|
+
const invokeOptions = { ...options, label };
|
|
24
|
+
return (0, task_1.runTaskIntrinsic)({
|
|
25
|
+
task: breakpointTask,
|
|
26
|
+
args: { payload, label, requestedAt: context.now().toISOString() },
|
|
27
|
+
invokeOptions,
|
|
28
|
+
context,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function deriveBreakpointLabel(payload, provided) {
|
|
32
|
+
if (typeof provided === "string" && provided.length) {
|
|
33
|
+
return provided;
|
|
34
|
+
}
|
|
35
|
+
if (payload && typeof payload === "object" && "label" in payload) {
|
|
36
|
+
const inferred = payload.label;
|
|
37
|
+
if (typeof inferred === "string" && inferred.length) {
|
|
38
|
+
return inferred;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return DEFAULT_BREAKPOINT_LABEL;
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { runTaskIntrinsic } from "./task";
|
|
2
|
+
export type { TaskIntrinsicContext } from "./task";
|
|
3
|
+
export { runBreakpointIntrinsic } from "./breakpoint";
|
|
4
|
+
export { runSleepIntrinsic } from "./sleep";
|
|
5
|
+
export { runOrchestratorTaskIntrinsic } from "./orchestratorTask";
|
|
6
|
+
export { runParallelAll, runParallelMap, dedupeEffectActions } from "./parallel";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC1C,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dedupeEffectActions = exports.runParallelMap = exports.runParallelAll = exports.runOrchestratorTaskIntrinsic = exports.runSleepIntrinsic = exports.runBreakpointIntrinsic = exports.runTaskIntrinsic = void 0;
|
|
4
|
+
var task_1 = require("./task");
|
|
5
|
+
Object.defineProperty(exports, "runTaskIntrinsic", { enumerable: true, get: function () { return task_1.runTaskIntrinsic; } });
|
|
6
|
+
var breakpoint_1 = require("./breakpoint");
|
|
7
|
+
Object.defineProperty(exports, "runBreakpointIntrinsic", { enumerable: true, get: function () { return breakpoint_1.runBreakpointIntrinsic; } });
|
|
8
|
+
var sleep_1 = require("./sleep");
|
|
9
|
+
Object.defineProperty(exports, "runSleepIntrinsic", { enumerable: true, get: function () { return sleep_1.runSleepIntrinsic; } });
|
|
10
|
+
var orchestratorTask_1 = require("./orchestratorTask");
|
|
11
|
+
Object.defineProperty(exports, "runOrchestratorTaskIntrinsic", { enumerable: true, get: function () { return orchestratorTask_1.runOrchestratorTaskIntrinsic; } });
|
|
12
|
+
var parallel_1 = require("./parallel");
|
|
13
|
+
Object.defineProperty(exports, "runParallelAll", { enumerable: true, get: function () { return parallel_1.runParallelAll; } });
|
|
14
|
+
Object.defineProperty(exports, "runParallelMap", { enumerable: true, get: function () { return parallel_1.runParallelMap; } });
|
|
15
|
+
Object.defineProperty(exports, "dedupeEffectActions", { enumerable: true, get: function () { return parallel_1.dedupeEffectActions; } });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TaskInvokeOptions } from "../types";
|
|
2
|
+
import { TaskIntrinsicContext } from "./task";
|
|
3
|
+
export declare function runOrchestratorTaskIntrinsic<TPayload, TResult>(payload: TPayload, context: TaskIntrinsicContext, options?: TaskInvokeOptions): Promise<TResult>;
|
|
4
|
+
//# sourceMappingURL=orchestratorTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestratorTask.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/orchestratorTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAoB,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAuBhE,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,OAAO,EAC5D,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,oBAAoB,EAC7B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,OAAO,CAAC,CASlB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runOrchestratorTaskIntrinsic = runOrchestratorTaskIntrinsic;
|
|
4
|
+
const task_1 = require("./task");
|
|
5
|
+
const ORCHESTRATOR_TASK_ID = "__sdk.orchestratorTask";
|
|
6
|
+
const orchestratorTask = {
|
|
7
|
+
id: ORCHESTRATOR_TASK_ID,
|
|
8
|
+
async build(args) {
|
|
9
|
+
return {
|
|
10
|
+
kind: "orchestrator_task",
|
|
11
|
+
title: args.label,
|
|
12
|
+
metadata: {
|
|
13
|
+
payload: args?.payload,
|
|
14
|
+
orchestratorTask: true,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
function runOrchestratorTaskIntrinsic(payload, context, options) {
|
|
20
|
+
const label = options?.label ?? "orchestrator-task";
|
|
21
|
+
const invokeOptions = { ...options, label };
|
|
22
|
+
return (0, task_1.runTaskIntrinsic)({
|
|
23
|
+
task: orchestratorTask,
|
|
24
|
+
args: { payload, label },
|
|
25
|
+
invokeOptions,
|
|
26
|
+
context,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { EffectAction } from "../types";
|
|
2
|
+
export declare function runParallelAll<T>(thunks: Array<() => T | Promise<T>>): Promise<T[]>;
|
|
3
|
+
export declare function runParallelMap<TItem, TOut>(items: TItem[], fn: (item: TItem) => TOut | Promise<TOut>): Promise<TOut[]>;
|
|
4
|
+
export declare function dedupeEffectActions(actions: EffectAction[]): EffectAction[];
|
|
5
|
+
//# sourceMappingURL=parallel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/parallel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,wBAAsB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAuBzF;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,IAAI,EAC9C,KAAK,EAAE,KAAK,EAAE,EACd,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACxC,OAAO,CAAC,IAAI,EAAE,CAAC,CAGjB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,CAE3E"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runParallelAll = runParallelAll;
|
|
4
|
+
exports.runParallelMap = runParallelMap;
|
|
5
|
+
exports.dedupeEffectActions = dedupeEffectActions;
|
|
6
|
+
const exceptions_1 = require("../exceptions");
|
|
7
|
+
const batching_1 = require("../../tasks/batching");
|
|
8
|
+
async function runParallelAll(thunks) {
|
|
9
|
+
const results = [];
|
|
10
|
+
const pending = [];
|
|
11
|
+
for (const thunk of thunks) {
|
|
12
|
+
try {
|
|
13
|
+
const value = await thunk();
|
|
14
|
+
results.push(value);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
const actions = collectPendingActions(error);
|
|
18
|
+
if (actions.length) {
|
|
19
|
+
pending.push(...actions);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (pending.length) {
|
|
26
|
+
throw new exceptions_1.ParallelPendingError((0, batching_1.buildParallelBatch)(pending));
|
|
27
|
+
}
|
|
28
|
+
return results;
|
|
29
|
+
}
|
|
30
|
+
async function runParallelMap(items, fn) {
|
|
31
|
+
const thunks = items.map((item) => () => fn(item));
|
|
32
|
+
return runParallelAll(thunks);
|
|
33
|
+
}
|
|
34
|
+
function dedupeEffectActions(actions) {
|
|
35
|
+
return (0, batching_1.buildParallelBatch)(actions).actions;
|
|
36
|
+
}
|
|
37
|
+
function collectPendingActions(error) {
|
|
38
|
+
if (error instanceof exceptions_1.ParallelPendingError) {
|
|
39
|
+
return error.batch.actions;
|
|
40
|
+
}
|
|
41
|
+
if (error instanceof exceptions_1.EffectPendingError || error instanceof exceptions_1.EffectRequestedError) {
|
|
42
|
+
return [error.action];
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TaskInvokeOptions } from "../types";
|
|
2
|
+
import { TaskIntrinsicContext } from "./task";
|
|
3
|
+
export declare function runSleepIntrinsic(target: string | number, context: TaskIntrinsicContext, options?: TaskInvokeOptions): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=sleep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE1D,OAAO,EAAoB,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AA2BhE,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,OAAO,EAAE,oBAAoB,EAC7B,OAAO,CAAC,EAAE,iBAAiB,iBA2B5B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runSleepIntrinsic = runSleepIntrinsic;
|
|
4
|
+
const exceptions_1 = require("../exceptions");
|
|
5
|
+
const task_1 = require("./task");
|
|
6
|
+
const SLEEP_TASK_ID = "__sdk.sleep";
|
|
7
|
+
const sleepTask = {
|
|
8
|
+
id: SLEEP_TASK_ID,
|
|
9
|
+
async build(args) {
|
|
10
|
+
return {
|
|
11
|
+
kind: "sleep",
|
|
12
|
+
title: `sleep:${args.iso}`,
|
|
13
|
+
sleep: {
|
|
14
|
+
iso: args.iso,
|
|
15
|
+
targetEpochMs: args.targetEpochMs,
|
|
16
|
+
},
|
|
17
|
+
metadata: {
|
|
18
|
+
targetEpochMs: args.targetEpochMs,
|
|
19
|
+
iso: args.iso,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
async function runSleepIntrinsic(target, context, options) {
|
|
25
|
+
const epoch = normalizeSleepTarget(target);
|
|
26
|
+
if (!Number.isFinite(epoch) || epoch < 0) {
|
|
27
|
+
throw new exceptions_1.InvalidSleepTargetError(target);
|
|
28
|
+
}
|
|
29
|
+
const nowMs = context.now().getTime();
|
|
30
|
+
if (epoch <= nowMs) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const iso = new Date(epoch).toISOString();
|
|
34
|
+
const label = options?.label ?? `sleep:${iso}`;
|
|
35
|
+
const invokeOptions = { ...options, label };
|
|
36
|
+
try {
|
|
37
|
+
await (0, task_1.runTaskIntrinsic)({
|
|
38
|
+
task: sleepTask,
|
|
39
|
+
args: { targetEpochMs: epoch, iso },
|
|
40
|
+
invokeOptions,
|
|
41
|
+
context,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (shouldShortCircuitPending(error, nowMs)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function normalizeSleepTarget(target) {
|
|
52
|
+
if (typeof target === "number") {
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
if (typeof target === "string") {
|
|
56
|
+
const parsed = Date.parse(target);
|
|
57
|
+
return Number.isNaN(parsed) ? NaN : parsed;
|
|
58
|
+
}
|
|
59
|
+
return NaN;
|
|
60
|
+
}
|
|
61
|
+
function shouldShortCircuitPending(error, nowMs) {
|
|
62
|
+
if (!(error instanceof exceptions_1.EffectPendingError)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const metadata = error.action.taskDef?.metadata;
|
|
66
|
+
if (typeof metadata?.targetEpochMs !== "number") {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return metadata.targetEpochMs <= nowMs;
|
|
70
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EffectIndex } from "../replay/effectIndex";
|
|
2
|
+
import { ReplayCursor } from "../replay/replayCursor";
|
|
3
|
+
import { DefinedTask, ProcessLogger, TaskInvokeOptions } from "../types";
|
|
4
|
+
export interface TaskIntrinsicContext {
|
|
5
|
+
runId: string;
|
|
6
|
+
runDir: string;
|
|
7
|
+
processId: string;
|
|
8
|
+
effectIndex: EffectIndex;
|
|
9
|
+
replayCursor: ReplayCursor;
|
|
10
|
+
now: () => Date;
|
|
11
|
+
logger?: ProcessLogger;
|
|
12
|
+
}
|
|
13
|
+
export interface TaskIntrinsicInvokeOptions<TArgs, TResult> {
|
|
14
|
+
task: DefinedTask<TArgs, TResult>;
|
|
15
|
+
args: TArgs;
|
|
16
|
+
invokeOptions?: TaskInvokeOptions;
|
|
17
|
+
context: TaskIntrinsicContext;
|
|
18
|
+
}
|
|
19
|
+
export declare function runTaskIntrinsic<TArgs, TResult>(options: TaskIntrinsicInvokeOptions<TArgs, TResult>): Promise<TResult>;
|
|
20
|
+
//# sourceMappingURL=task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/task.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACL,WAAW,EAIX,aAAa,EAGb,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAMlB,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B,CAAC,KAAK,EAAE,OAAO;IACxD,IAAI,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,EAAE,KAAK,CAAC;IACZ,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EACnD,OAAO,EAAE,0BAA0B,CAAC,KAAK,EAAE,OAAO,CAAC,GAClD,OAAO,CAAC,OAAO,CAAC,CAmBlB"}
|