@usine/durable 0.0.0-stage → 0.2.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/LICENSE +661 -0
- package/README.md +83 -2
- package/dist/attempt/documents.d.ts +86 -0
- package/dist/attempt/documents.d.ts.map +1 -0
- package/dist/attempt/documents.js +30 -0
- package/dist/attempt/documents.js.map +1 -0
- package/dist/attempt/events.d.ts +22 -0
- package/dist/attempt/events.d.ts.map +1 -0
- package/dist/attempt/events.js +110 -0
- package/dist/attempt/events.js.map +1 -0
- package/dist/attempt/extension.d.ts +48 -0
- package/dist/attempt/extension.d.ts.map +1 -0
- package/dist/attempt/extension.js +34 -0
- package/dist/attempt/extension.js.map +1 -0
- package/dist/attempt/hubs.d.ts +133 -0
- package/dist/attempt/hubs.d.ts.map +1 -0
- package/dist/attempt/hubs.js +146 -0
- package/dist/attempt/hubs.js.map +1 -0
- package/dist/attempt/outcome.d.ts +22 -0
- package/dist/attempt/outcome.d.ts.map +1 -0
- package/dist/attempt/outcome.js +84 -0
- package/dist/attempt/outcome.js.map +1 -0
- package/dist/attempt/parent.d.ts +27 -0
- package/dist/attempt/parent.d.ts.map +1 -0
- package/dist/attempt/parent.js +109 -0
- package/dist/attempt/parent.js.map +1 -0
- package/dist/attempt/relay.d.ts +41 -0
- package/dist/attempt/relay.d.ts.map +1 -0
- package/dist/attempt/relay.js +457 -0
- package/dist/attempt/relay.js.map +1 -0
- package/dist/attempt/repair.d.ts +14 -0
- package/dist/attempt/repair.d.ts.map +1 -0
- package/dist/attempt/repair.js +150 -0
- package/dist/attempt/repair.js.map +1 -0
- package/dist/attempt/request.d.ts +18 -0
- package/dist/attempt/request.d.ts.map +1 -0
- package/dist/attempt/request.js +24 -0
- package/dist/attempt/request.js.map +1 -0
- package/dist/attempt/runtime.d.ts +10 -0
- package/dist/attempt/runtime.d.ts.map +1 -0
- package/dist/attempt/runtime.js +429 -0
- package/dist/attempt/runtime.js.map +1 -0
- package/dist/attempt/services.d.ts +15 -0
- package/dist/attempt/services.d.ts.map +1 -0
- package/dist/attempt/services.js +2 -0
- package/dist/attempt/services.js.map +1 -0
- package/dist/attempt/subagent.d.ts +17 -0
- package/dist/attempt/subagent.d.ts.map +1 -0
- package/dist/attempt/subagent.js +208 -0
- package/dist/attempt/subagent.js.map +1 -0
- package/dist/attempt/task.d.ts +61 -0
- package/dist/attempt/task.d.ts.map +1 -0
- package/dist/attempt/task.js +302 -0
- package/dist/attempt/task.js.map +1 -0
- package/dist/attempt/watch.d.ts +8 -0
- package/dist/attempt/watch.d.ts.map +1 -0
- package/dist/attempt/watch.js +25 -0
- package/dist/attempt/watch.js.map +1 -0
- package/dist/attempt-runtime.d.ts +128 -0
- package/dist/attempt-runtime.d.ts.map +1 -0
- package/dist/attempt-runtime.js +78 -0
- package/dist/attempt-runtime.js.map +1 -0
- package/dist/backup.d.ts +26 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +100 -0
- package/dist/backup.js.map +1 -0
- package/dist/harness.d.ts +101 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +298 -0
- package/dist/harness.js.map +1 -0
- package/dist/live.d.ts +15 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +51 -0
- package/dist/live.js.map +1 -0
- package/dist/storage-path.d.ts +4 -0
- package/dist/storage-path.d.ts.map +1 -0
- package/dist/storage-path.js +2 -0
- package/dist/storage-path.js.map +1 -0
- package/dist/testing.d.ts +116 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +314 -0
- package/dist/testing.js.map +1 -0
- package/package.json +72 -3
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
|
+
import { AgentDoc, InboxDoc, LiveDoc, ProviderDoc, UsageDoc, } from "@earendil-works/pi-durable";
|
|
3
|
+
import { Effect, Option, Result } from "effect";
|
|
4
|
+
import { durableError } from "../harness.js";
|
|
5
|
+
import { AttemptRecordDoc } from "./documents.js";
|
|
6
|
+
import { attemptIdOf } from "./request.js";
|
|
7
|
+
import { ATTEMPT_TASK } from "./task.js";
|
|
8
|
+
const call = (operation, run) => Effect.tryPromise({ try: run, catch: (cause) => durableError(operation, cause) });
|
|
9
|
+
const conversationDocument = (token) => ({
|
|
10
|
+
kind: token.definition.kind,
|
|
11
|
+
read: async (storage, conversationId) => {
|
|
12
|
+
const record = await storage.findDocument({ kind: token.definition.kind, scope: { kind: "conversation", conversationId } }, "current", BACKGROUND_CONTEXT);
|
|
13
|
+
if (record !== undefined)
|
|
14
|
+
await storage.document(record.id, "current", BACKGROUND_CONTEXT);
|
|
15
|
+
},
|
|
16
|
+
replace: async (tx, conversationId) => {
|
|
17
|
+
await tx.retireDoc(token, conversationId);
|
|
18
|
+
await tx.doc(token, conversationId);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const CONVERSATION_DOCUMENTS = [
|
|
22
|
+
conversationDocument(LiveDoc),
|
|
23
|
+
conversationDocument(InboxDoc),
|
|
24
|
+
conversationDocument(UsageDoc),
|
|
25
|
+
conversationDocument(AgentDoc),
|
|
26
|
+
conversationDocument(ProviderDoc),
|
|
27
|
+
];
|
|
28
|
+
const messageOf = (cause) => cause instanceof Error && cause.message.length > 0 ? cause.message : String(cause);
|
|
29
|
+
/** Returns the conversation's documents that cannot be read, with each failure reason. */
|
|
30
|
+
const unreadableDocuments = Effect.fn("AttemptRepair.unreadableDocuments")(function* (storage, conversationId) {
|
|
31
|
+
const unreadable = [];
|
|
32
|
+
for (const document of CONVERSATION_DOCUMENTS) {
|
|
33
|
+
const read = yield* Effect.tryPromise({
|
|
34
|
+
try: () => document.read(storage, conversationId),
|
|
35
|
+
catch: messageOf,
|
|
36
|
+
}).pipe(Effect.result);
|
|
37
|
+
if (Result.isFailure(read))
|
|
38
|
+
unreadable.push({ document, message: read.failure });
|
|
39
|
+
}
|
|
40
|
+
return unreadable;
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Returns the Attempt of the conversation's owner task, or `None` if that task isn't a
|
|
44
|
+
* `usine.attempt` task.
|
|
45
|
+
*/
|
|
46
|
+
const owningAttempt = Effect.fn("AttemptRepair.owningAttempt")(function* (harness, conversationId) {
|
|
47
|
+
const conversation = yield* call("read the conversation", () => harness.commit((tx) => tx.conversation(conversationId), BACKGROUND_CONTEXT));
|
|
48
|
+
const ownerTaskId = conversation?.owner?.taskId;
|
|
49
|
+
if (ownerTaskId === undefined)
|
|
50
|
+
return Option.none();
|
|
51
|
+
const owner = yield* call("read the conversation's owner task", () => harness.getTask(ownerTaskId, BACKGROUND_CONTEXT));
|
|
52
|
+
if (owner === undefined || owner.kind !== ATTEMPT_TASK)
|
|
53
|
+
return Option.none();
|
|
54
|
+
return attemptIdOf(owner.input);
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Replaces the unreadable documents of the live tasks' conversations in one commit and sets
|
|
58
|
+
* `storageFailure` on each affected Attempt record.
|
|
59
|
+
*/
|
|
60
|
+
const replaceUnreadable = Effect.fn("AttemptRepair.replaceUnreadable")(function* (harness, storage, tasks) {
|
|
61
|
+
const conversations = [...new Set(tasks.map(({ conversationId }) => conversationId))];
|
|
62
|
+
const repairs = [];
|
|
63
|
+
for (const conversationId of conversations) {
|
|
64
|
+
const unreadable = yield* unreadableDocuments(storage, conversationId);
|
|
65
|
+
if (unreadable.length === 0)
|
|
66
|
+
continue;
|
|
67
|
+
const reasons = unreadable.map(({ document, message }) => `${document.kind}: ${message}`);
|
|
68
|
+
repairs.push({
|
|
69
|
+
conversationId,
|
|
70
|
+
documents: unreadable.map(({ document }) => document),
|
|
71
|
+
attempt: yield* owningAttempt(harness, conversationId),
|
|
72
|
+
cause: `Can't read the parent conversation ${conversationId} from durable storage: ${reasons.join("; ")}`,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (repairs.length === 0) {
|
|
76
|
+
yield* Effect.logDebug("Every live task's conversation reads back", {
|
|
77
|
+
conversations: conversations.length,
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
yield* call("replace the unreadable documents", () => harness.commit(async (tx) => {
|
|
82
|
+
for (const repair of repairs) {
|
|
83
|
+
for (const document of repair.documents)
|
|
84
|
+
await document.replace(tx, repair.conversationId);
|
|
85
|
+
if (Option.isSome(repair.attempt)) {
|
|
86
|
+
const record = await tx.doc(AttemptRecordDoc, repair.attempt.value, null);
|
|
87
|
+
record.storageFailure = repair.cause;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, BACKGROUND_CONTEXT));
|
|
91
|
+
for (const repair of repairs) {
|
|
92
|
+
yield* Option.match(repair.attempt, {
|
|
93
|
+
onNone: () => Effect.logWarning("Replaced unreadable documents of a conversation no Attempt owns", {
|
|
94
|
+
conversationId: repair.conversationId,
|
|
95
|
+
cause: repair.cause,
|
|
96
|
+
}),
|
|
97
|
+
onSome: (attemptId) => Effect.logError("Replaced the unreadable documents of an Attempt's parent conversation; the Attempt fails", { attemptId, conversationId: repair.conversationId, cause: repair.cause }),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
/** Aborts each live `usine.attempt` task whose Attempt record has a `storageFailure`. */
|
|
102
|
+
const abortFailedAttempts = Effect.fn("AttemptRepair.abortFailedAttempts")(function* (harness, tasks) {
|
|
103
|
+
for (const task of tasks) {
|
|
104
|
+
if (task.kind !== ATTEMPT_TASK || task.abortRequested)
|
|
105
|
+
continue;
|
|
106
|
+
const attemptId = attemptIdOf(task.input);
|
|
107
|
+
if (Option.isNone(attemptId))
|
|
108
|
+
continue;
|
|
109
|
+
const record = yield* call("read the Attempt record", () => harness.snapshot(AttemptRecordDoc, attemptId.value, BACKGROUND_CONTEXT));
|
|
110
|
+
if (record?.storageFailure === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
yield* call("abort the Attempt task", () => harness.abortTask(task.id, BACKGROUND_CONTEXT));
|
|
113
|
+
yield* Effect.logInfo("Aborting the Attempt task whose conversation could not be read", {
|
|
114
|
+
attemptId: attemptId.value,
|
|
115
|
+
taskId: task.id,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* Replaces the unreadable documents of each live task's conversation and aborts the affected
|
|
121
|
+
* Attempt's task with the reason. Runs before the harness resumes its tasks.
|
|
122
|
+
*/
|
|
123
|
+
export const repairUnreadableConversations = (harness, storage) => Effect.gen(function* () {
|
|
124
|
+
const { tasks } = yield* call("inspect the live tasks", () => harness.inspect(BACKGROUND_CONTEXT));
|
|
125
|
+
const records = tasks.map(({ record }) => record);
|
|
126
|
+
yield* replaceUnreadable(harness, storage, records);
|
|
127
|
+
yield* abortFailedAttempts(harness, records);
|
|
128
|
+
}).pipe(Effect.tapError((error) => Effect.logError("Could not repair the durable storage before resuming its tasks", {
|
|
129
|
+
operation: error.operation,
|
|
130
|
+
message: error.message,
|
|
131
|
+
})), Effect.ignore, Effect.withSpan("AttemptRepair.repair"));
|
|
132
|
+
/**
|
|
133
|
+
* Aborts the tasks of the Attempts whose `execute` a storage failure ended, so the reopened harness
|
|
134
|
+
* doesn't run their parents again. Runs before the harness resumes its tasks. Failures are logged.
|
|
135
|
+
*/
|
|
136
|
+
export const abortEndedAttempts = Effect.fn("AttemptRepair.abortEndedAttempts")(function* (harness, attempts) {
|
|
137
|
+
yield* Effect.annotateCurrentSpan({ attempts: attempts.length });
|
|
138
|
+
for (const { attemptId, taskId } of attempts) {
|
|
139
|
+
yield* call("abort the Attempt task", () => harness.abortTask(taskId, BACKGROUND_CONTEXT)).pipe(Effect.tap((marked) => Effect.logInfo("Aborting the task of an Attempt that a storage failure ended", {
|
|
140
|
+
attemptId,
|
|
141
|
+
taskId,
|
|
142
|
+
marked,
|
|
143
|
+
})), Effect.tapError((error) => Effect.logWarning("Could not abort the task of an Attempt that a storage failure ended", {
|
|
144
|
+
attemptId,
|
|
145
|
+
taskId,
|
|
146
|
+
message: error.message,
|
|
147
|
+
})), Effect.ignore);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
//# sourceMappingURL=repair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repair.js","sourceRoot":"","sources":["../../src/attempt/repair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EACL,QAAQ,EAIR,QAAQ,EAER,OAAO,EACP,WAAW,EAIX,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,IAAI,GAAG,CAAI,SAAiB,EAAE,GAAqB,EAAE,EAAE,CAC3D,MAAM,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;AAcpF,MAAM,oBAAoB,GAAG,CAC3B,KAA8B,EACR,EAAE,CAAC,CAAC;IAC1B,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI;IAC3B,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;QACtC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,YAAY,CACvC,EAAE,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,EAAE,EAChF,SAAS,EACT,kBAAkB,CACnB,CAAC;QACF,IAAI,MAAM,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ChF,SAAS,EAAE,KAAK,CAAC,SAAS;IAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;CACvB,CAAC,CACH,EACD,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CACxC,CAAC;AAEJ;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAGJ,MAAM,CAAC,EAAE,CAAC,kCAAkC,CAAC,CAAC,QAAQ,CAAC,EAChF,OAAgB,EAChB,QAAqC;IAErC,KAAK,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACjE,KAAK,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;QAC7C,KAAK,CAAC,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAC7F,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACpB,MAAM,CAAC,OAAO,CAAC,8DAA8D,EAAE;YAC7E,SAAS;YACT,MAAM;YACN,MAAM;SACP,CAAC,CACH,EACD,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CACxB,MAAM,CAAC,UAAU,CAAC,qEAAqE,EAAE;YACvF,SAAS;YACT,MAAM;YACN,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,CACH,EACD,MAAM,CAAC,MAAM,CACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { AttemptId } from "@usine/core/attempt";
|
|
3
|
+
import { Effect, Option } from "effect";
|
|
4
|
+
import { type AttemptRequest, StoredRequest } from "../attempt-runtime.ts";
|
|
5
|
+
import type { DurableHarness } from "../harness.ts";
|
|
6
|
+
/**
|
|
7
|
+
* The input of the `usine.attempt` task: the encoded `StoredRequest`, which contains no
|
|
8
|
+
* credentials.
|
|
9
|
+
*/
|
|
10
|
+
export type AttemptTaskInput = typeof StoredRequest.Encoded;
|
|
11
|
+
/** Returns the Attempt ID of a task input, or `None` if the input isn't a stored request. */
|
|
12
|
+
export declare const attemptIdOf: (input: JsonValue) => Option.Option<AttemptId>;
|
|
13
|
+
export declare const taskInput: (request: AttemptRequest) => AttemptTaskInput;
|
|
14
|
+
/** Decodes a stored task input. Dies on a malformed input, since only this package writes it. */
|
|
15
|
+
export declare const storedRequestOf: (input: AttemptTaskInput | JsonValue) => Effect.Effect<StoredRequest, never, never>;
|
|
16
|
+
/** Reads the request the Attempt's task was created with, or `None` if the Attempt has no task. */
|
|
17
|
+
export declare const readStoredRequest: (durable: DurableHarness["Service"], attemptId: AttemptId) => Effect.Effect<Option.None<StoredRequest> | Option.Some<StoredRequest>, import("../harness.ts").DurableHarnessError, never>;
|
|
18
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/attempt/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,KAAK,cAAc,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,aAAa,CAAC,OAAO,CAAC;AAM5D,6FAA6F;AAC7F,eAAO,MAAM,WAAW,UAAW,SAAS,KAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CACD,CAAC;AAEtE,eAAO,MAAM,SAAS,YAAa,cAAc,KAAG,gBAC+C,CAAC;AAEpG,iGAAiG;AACjG,eAAO,MAAM,eAAe,UAAW,gBAAgB,GAAG,SAAS,+CAC3B,CAAC;AAEzC,mGAAmG;AACnG,eAAO,MAAM,iBAAiB,YAAa,cAAc,CAAC,SAAS,CAAC,aAAa,SAAS,+HActF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from "effect";
|
|
2
|
+
import { StoredRequest } from "../attempt-runtime.js";
|
|
3
|
+
import { readRecord } from "./relay.js";
|
|
4
|
+
const encodeStored = Schema.encodeSync(StoredRequest);
|
|
5
|
+
const decodeStored = Schema.decodeUnknownEffect(StoredRequest);
|
|
6
|
+
const decodeStoredOption = Schema.decodeUnknownOption(StoredRequest);
|
|
7
|
+
/** Returns the Attempt ID of a task input, or `None` if the input isn't a stored request. */
|
|
8
|
+
export const attemptIdOf = (input) => Option.map(decodeStoredOption(input), ({ spec }) => spec.attemptId);
|
|
9
|
+
export const taskInput = (request) => encodeStored(new StoredRequest({ spec: request.spec, worker: request.worker, cwd: request.cwd }));
|
|
10
|
+
/** Decodes a stored task input. Dies on a malformed input, since only this package writes it. */
|
|
11
|
+
export const storedRequestOf = (input) => decodeStored(input).pipe(Effect.orDie);
|
|
12
|
+
/** Reads the request the Attempt's task was created with, or `None` if the Attempt has no task. */
|
|
13
|
+
export const readStoredRequest = (durable, attemptId) => Effect.gen(function* () {
|
|
14
|
+
const taskId = (yield* readRecord(durable, attemptId))?.taskId ?? null;
|
|
15
|
+
const task = taskId === null
|
|
16
|
+
? undefined
|
|
17
|
+
: yield* durable.use("read the Attempt task", (harness, context) => harness.getTask(taskId, context));
|
|
18
|
+
yield* Effect.logDebug("Read the Attempt's stored request", {
|
|
19
|
+
attemptId,
|
|
20
|
+
found: task !== undefined,
|
|
21
|
+
});
|
|
22
|
+
return task === undefined ? Option.none() : Option.some(yield* storedRequestOf(task.input));
|
|
23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C,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,EAAE,MAAM,IAAI,IAAI,CAAC;IACvE,MAAM,IAAI,GACR,MAAM,KAAK,IAAI;QACb,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAC/D,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CACjC,CAAC;IACR,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,mCAAmC,EAAE;QAC1D,SAAS;QACT,KAAK,EAAE,IAAI,KAAK,SAAS;KAC1B,CAAC,CAAC;IACH,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9F,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChildBackend } from "@usine/agents/runtime";
|
|
2
|
+
import { Layer } from "effect";
|
|
3
|
+
import { AttemptRuntime } from "../attempt-runtime.ts";
|
|
4
|
+
import { DurableHarness, type DurableHarnessError } from "../harness.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Provides `AttemptRuntime` on the durable harness. Building it installs the usine extension and
|
|
7
|
+
* resumes unfinished Attempts.
|
|
8
|
+
*/
|
|
9
|
+
export declare const layer: Layer.Layer<AttemptRuntime, DurableHarnessError, ChildBackend | DurableHarness>;
|
|
10
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/attempt/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAKrD,OAAO,EAA8B,KAAK,EAA0B,MAAM,QAAQ,CAAC;AACnF,OAAO,EAAuB,cAAc,EAAwB,MAAM,uBAAuB,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAA6B,MAAM,eAAe,CAAC;AAglBpG;;;GAGG;AACH,eAAO,MAAM,KAAK,iFAAmD,CAAC"}
|