@ancientpantheon/khronoton-core 0.1.1 → 0.3.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 +25 -0
- package/README.md +83 -3
- package/dist/PactCodeMirror-HQTGE2K3.js +64 -0
- package/dist/chunk-DK4CDPXH.js +379 -0
- package/dist/chunk-U3F5HEHO.js +1639 -0
- package/dist/context-BKtdrA2B.d.ts +363 -0
- package/dist/handlers/batch.d.ts +21 -0
- package/dist/handlers/batch.js +57 -0
- package/dist/handlers/context.d.ts +94 -0
- package/dist/handlers/context.js +75 -0
- package/dist/handlers/cronoton.d.ts +70 -0
- package/dist/handlers/cronoton.js +165 -0
- package/dist/handlers/execute.d.ts +30 -0
- package/dist/handlers/execute.js +227 -0
- package/dist/handlers/http.d.ts +85 -0
- package/dist/handlers/http.js +84 -0
- package/dist/handlers/index.d.ts +27 -0
- package/dist/handlers/index.js +34 -0
- package/dist/handlers/read.d.ts +29 -0
- package/dist/handlers/read.js +94 -0
- package/dist/hooks/index.d.ts +143 -0
- package/dist/hooks/index.js +2 -0
- package/dist/provider/index.d.ts +421 -0
- package/dist/provider/index.js +675 -0
- package/dist/server/executor-signers.d.ts +29 -0
- package/dist/server/executor-signers.js +60 -0
- package/dist/server/executor.d.ts +53 -0
- package/dist/server/executor.js +280 -0
- package/dist/server/index.d.ts +27 -0
- package/dist/server/index.js +51 -0
- package/dist/server/loop.d.ts +36 -0
- package/dist/server/loop.js +51 -0
- package/dist/server/pure/capability.d.ts +31 -0
- package/dist/server/pure/capability.js +63 -0
- package/dist/server/pure/fingerprint.d.ts +8 -0
- package/dist/server/pure/fingerprint.js +44 -0
- package/dist/server/pure/runtime-args.d.ts +34 -0
- package/dist/server/pure/runtime-args.js +99 -0
- package/dist/server/resolvers.d.ts +140 -0
- package/dist/server/resolvers.js +200 -0
- package/dist/server/schema.d.ts +31 -0
- package/dist/server/schema.js +93 -0
- package/dist/server/seams.d.ts +231 -0
- package/dist/server/seams.js +34 -0
- package/dist/server/store/claim.d.ts +59 -0
- package/dist/server/store/claim.js +97 -0
- package/dist/server/store/cronoton.d.ts +79 -0
- package/dist/server/store/cronoton.js +268 -0
- package/dist/server/store/errors.d.ts +26 -0
- package/dist/server/store/errors.js +40 -0
- package/dist/server/store/fires.d.ts +77 -0
- package/dist/server/store/fires.js +170 -0
- package/dist/server/store/index.d.ts +26 -0
- package/dist/server/store/index.js +33 -0
- package/dist/server/store/manual-batch.d.ts +38 -0
- package/dist/server/store/manual-batch.js +110 -0
- package/dist/server/store/mappers.d.ts +21 -0
- package/dist/server/store/mappers.js +62 -0
- package/dist/server/tick.d.ts +83 -0
- package/dist/server/tick.js +235 -0
- package/dist/server/types.d.ts +220 -0
- package/dist/server/types.js +14 -0
- package/dist/types-u_nUX1Bg.d.ts +222 -0
- package/dist/ui/index.d.ts +235 -0
- package/dist/ui/index.js +3646 -0
- package/dist/ui.css +35 -0
- package/package.json +64 -5
|
@@ -0,0 +1,1639 @@
|
|
|
1
|
+
import crypto2, { randomUUID } from 'crypto';
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
|
|
4
|
+
// src/server/seams.ts
|
|
5
|
+
var defaultResolveFireMode = () => "live";
|
|
6
|
+
var LISTEN_TIMEOUT_MS = 3e5;
|
|
7
|
+
var AUTO_GAS_CEILING = 2e6;
|
|
8
|
+
var SINGLE_TX_GAS_GUARD = 16e5;
|
|
9
|
+
|
|
10
|
+
// src/server/pure/capability.ts
|
|
11
|
+
function parseCapabilityLine(line) {
|
|
12
|
+
const trimmed = line.trim();
|
|
13
|
+
if (!trimmed) return null;
|
|
14
|
+
if (trimmed.startsWith("(") && trimmed.endsWith(")")) {
|
|
15
|
+
const inner = trimmed.slice(1, -1);
|
|
16
|
+
const spaceIndex = inner.indexOf(" ");
|
|
17
|
+
if (spaceIndex > -1) {
|
|
18
|
+
const capName = inner.substring(0, spaceIndex);
|
|
19
|
+
const argsString = inner.substring(spaceIndex + 1);
|
|
20
|
+
const args = [];
|
|
21
|
+
const argMatches = argsString.match(/("([^"\\]|\\.)*"|[^\s]+)/g) || [];
|
|
22
|
+
for (const arg of argMatches) {
|
|
23
|
+
if (arg.startsWith('"') && arg.endsWith('"')) {
|
|
24
|
+
args.push(arg.slice(1, -1));
|
|
25
|
+
} else if (/^\d+$/.test(arg)) {
|
|
26
|
+
args.push({ int: parseInt(arg, 10) });
|
|
27
|
+
} else if (/^\d*\.\d+$/.test(arg)) {
|
|
28
|
+
args.push({ decimal: arg });
|
|
29
|
+
} else {
|
|
30
|
+
args.push(arg);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { name: capName, args };
|
|
34
|
+
}
|
|
35
|
+
return { name: inner, args: [] };
|
|
36
|
+
}
|
|
37
|
+
if (trimmed.includes(".")) {
|
|
38
|
+
return { name: trimmed, args: [] };
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function computeTerminalIntent(scheduleKind, mode, ok) {
|
|
43
|
+
if (scheduleKind !== "one-time") return null;
|
|
44
|
+
return ok ? { status: "completed", clearNextFire: true } : { status: "error", clearNextFire: true };
|
|
45
|
+
}
|
|
46
|
+
function parseRuntimeArgKeys(raw) {
|
|
47
|
+
if (!raw) return [];
|
|
48
|
+
let parsed;
|
|
49
|
+
try {
|
|
50
|
+
parsed = JSON.parse(raw);
|
|
51
|
+
} catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
if (!Array.isArray(parsed)) return [];
|
|
55
|
+
return parsed.filter((k) => typeof k === "string" && k.length > 0);
|
|
56
|
+
}
|
|
57
|
+
function validateRuntimeArgs(declaredKeys, supplied) {
|
|
58
|
+
if (declaredKeys.length === 0) {
|
|
59
|
+
return { ok: false, error: "this cronoton declares no runtime args" };
|
|
60
|
+
}
|
|
61
|
+
if (supplied == null || typeof supplied !== "object" || Array.isArray(supplied)) {
|
|
62
|
+
return { ok: false, error: "args must be an object" };
|
|
63
|
+
}
|
|
64
|
+
const obj = supplied;
|
|
65
|
+
const declared = new Set(declaredKeys);
|
|
66
|
+
for (const k of Object.keys(obj)) {
|
|
67
|
+
if (!declared.has(k)) return { ok: false, error: `unexpected arg "${k}"` };
|
|
68
|
+
}
|
|
69
|
+
const args = /* @__PURE__ */ Object.create(null);
|
|
70
|
+
for (const k of declaredKeys) {
|
|
71
|
+
if (!Object.prototype.hasOwnProperty.call(obj, k)) return { ok: false, error: `missing arg "${k}"` };
|
|
72
|
+
const v = obj[k];
|
|
73
|
+
if (typeof v !== "string") return { ok: false, error: `arg "${k}" must be a string` };
|
|
74
|
+
args[k] = v;
|
|
75
|
+
}
|
|
76
|
+
return { ok: true, args };
|
|
77
|
+
}
|
|
78
|
+
function applyRuntimeArgs(definition, args) {
|
|
79
|
+
for (const k of Object.keys(args)) {
|
|
80
|
+
if (Object.prototype.hasOwnProperty.call(definition.payload, k)) {
|
|
81
|
+
throw new Error(`runtime arg "${k}" collides with a fixed payload key`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { ...definition, payload: { ...definition.payload, ...args } };
|
|
85
|
+
}
|
|
86
|
+
function runtimeArgKeysCollide(payload, declaredKeys) {
|
|
87
|
+
return declaredKeys.some((k) => Object.prototype.hasOwnProperty.call(payload, k));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/server/schema.ts
|
|
91
|
+
var SCHEMA_SQL = `
|
|
92
|
+
CREATE TABLE IF NOT EXISTS codex_cronotons (
|
|
93
|
+
id TEXT PRIMARY KEY,
|
|
94
|
+
name TEXT NOT NULL,
|
|
95
|
+
description TEXT,
|
|
96
|
+
pact_code TEXT NOT NULL,
|
|
97
|
+
config_json TEXT NOT NULL,
|
|
98
|
+
payload_json TEXT,
|
|
99
|
+
gas_payer_json TEXT NOT NULL,
|
|
100
|
+
signers_json TEXT NOT NULL,
|
|
101
|
+
schedule_mode TEXT NOT NULL CHECK (schedule_mode IN (
|
|
102
|
+
'daily-at-utc',
|
|
103
|
+
'every-n-minutes',
|
|
104
|
+
'weekly',
|
|
105
|
+
'monthly',
|
|
106
|
+
'cron-expression',
|
|
107
|
+
'one-time',
|
|
108
|
+
'several-times-per-day'
|
|
109
|
+
)),
|
|
110
|
+
schedule_config_json TEXT NOT NULL,
|
|
111
|
+
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN (
|
|
112
|
+
'active',
|
|
113
|
+
'paused',
|
|
114
|
+
'completed',
|
|
115
|
+
'error'
|
|
116
|
+
)),
|
|
117
|
+
next_fire_at TEXT,
|
|
118
|
+
last_fire_at TEXT,
|
|
119
|
+
created_at TEXT NOT NULL,
|
|
120
|
+
modified_at TEXT NOT NULL,
|
|
121
|
+
created_by TEXT NOT NULL,
|
|
122
|
+
server_resolver TEXT,
|
|
123
|
+
fire_mode_override TEXT,
|
|
124
|
+
external_fireable INTEGER NOT NULL DEFAULT 0,
|
|
125
|
+
runtime_arg_keys TEXT
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
CREATE INDEX IF NOT EXISTS idx_codex_cronotons_next_fire
|
|
129
|
+
ON codex_cronotons(status, next_fire_at);
|
|
130
|
+
|
|
131
|
+
CREATE TABLE IF NOT EXISTS codex_cronoton_fires (
|
|
132
|
+
id TEXT PRIMARY KEY,
|
|
133
|
+
codex_cronoton_id TEXT NOT NULL REFERENCES codex_cronotons(id) ON DELETE CASCADE,
|
|
134
|
+
job_id TEXT,
|
|
135
|
+
fired_at TEXT NOT NULL,
|
|
136
|
+
status TEXT NOT NULL,
|
|
137
|
+
request_key TEXT,
|
|
138
|
+
chain_id TEXT,
|
|
139
|
+
error_message TEXT,
|
|
140
|
+
chain_response_json TEXT,
|
|
141
|
+
definition_fingerprint TEXT,
|
|
142
|
+
mode TEXT NOT NULL DEFAULT 'test',
|
|
143
|
+
recovered_at TEXT,
|
|
144
|
+
tx_keys_json TEXT
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
CREATE INDEX IF NOT EXISTS idx_codex_fires_cronoton
|
|
148
|
+
ON codex_cronoton_fires(codex_cronoton_id, fired_at DESC);
|
|
149
|
+
|
|
150
|
+
CREATE TABLE IF NOT EXISTS codex_cronoton_manual_batches (
|
|
151
|
+
id TEXT PRIMARY KEY,
|
|
152
|
+
codex_cronoton_id TEXT NOT NULL REFERENCES codex_cronotons(id) ON DELETE CASCADE,
|
|
153
|
+
total INTEGER NOT NULL,
|
|
154
|
+
completed INTEGER NOT NULL DEFAULT 0,
|
|
155
|
+
interval_seconds INTEGER NOT NULL DEFAULT 60,
|
|
156
|
+
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN (
|
|
157
|
+
'active',
|
|
158
|
+
'completed',
|
|
159
|
+
'cancelled'
|
|
160
|
+
)),
|
|
161
|
+
next_at TEXT,
|
|
162
|
+
created_at TEXT NOT NULL,
|
|
163
|
+
modified_at TEXT NOT NULL,
|
|
164
|
+
created_by TEXT NOT NULL
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
CREATE INDEX IF NOT EXISTS idx_codex_manual_batches_due
|
|
168
|
+
ON codex_cronoton_manual_batches(status, next_at);
|
|
169
|
+
|
|
170
|
+
CREATE INDEX IF NOT EXISTS idx_codex_manual_batches_cronoton
|
|
171
|
+
ON codex_cronoton_manual_batches(codex_cronoton_id);
|
|
172
|
+
`;
|
|
173
|
+
function installSchema(db) {
|
|
174
|
+
db.exec(SCHEMA_SQL);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/server/executor-signers.ts
|
|
178
|
+
function stripPrefix(addr) {
|
|
179
|
+
return addr.startsWith("k:") ? addr.slice(2) : addr;
|
|
180
|
+
}
|
|
181
|
+
function deriveSenderAccount(gasPayer, gasStation) {
|
|
182
|
+
if (gasPayer.type === "gas-station") return gasStation;
|
|
183
|
+
return `k:${stripPrefix(gasPayer.address || "")}`;
|
|
184
|
+
}
|
|
185
|
+
function effectiveSigners(definition, kadenaNamespace) {
|
|
186
|
+
const signers = [...definition.signers];
|
|
187
|
+
if (definition.gasPayer.type === "codex" && definition.gasPayer.address) {
|
|
188
|
+
const gasPub = stripPrefix(definition.gasPayer.address);
|
|
189
|
+
if (!signers.some((s) => s.publicKey === gasPub)) {
|
|
190
|
+
signers.push({
|
|
191
|
+
publicKey: gasPub,
|
|
192
|
+
capabilityMode: "pure",
|
|
193
|
+
capabilities: ""
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (definition.gasPayer.type === "gas-station") {
|
|
198
|
+
const gasKey = definition.gasPayer.gasStationSignerKey;
|
|
199
|
+
if (!gasKey) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
"Gas-station gas payer requires a signing key for the DALOS.GAS_PAYER capability."
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if (!signers.some((s) => s.publicKey === gasKey)) {
|
|
205
|
+
signers.push({
|
|
206
|
+
publicKey: gasKey,
|
|
207
|
+
capabilityMode: "scoped",
|
|
208
|
+
capabilities: `(${kadenaNamespace}.DALOS.GAS_PAYER "" 0 0.0)`
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return signers;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/server/executor.ts
|
|
216
|
+
function buildTransaction(runtime, definition, signers, gasLimitOverride) {
|
|
217
|
+
if (signers.length === 0) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
"At least one signer is required to build a codex transaction."
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
const senderAccount = deriveSenderAccount(
|
|
223
|
+
definition.gasPayer,
|
|
224
|
+
runtime.gasStationAccount
|
|
225
|
+
);
|
|
226
|
+
const builder = runtime.Pact.builder.execution(
|
|
227
|
+
definition.pactCode
|
|
228
|
+
);
|
|
229
|
+
builder.setMeta({
|
|
230
|
+
senderAccount,
|
|
231
|
+
chainId: definition.config.chainId,
|
|
232
|
+
gasLimit: gasLimitOverride ?? definition.config.gasLimit,
|
|
233
|
+
gasPrice: runtime.anuToStoa(definition.config.gasPrice),
|
|
234
|
+
ttl: definition.config.ttl
|
|
235
|
+
}).setNetworkId(runtime.networkId);
|
|
236
|
+
for (const [key, value] of Object.entries(definition.payload)) {
|
|
237
|
+
builder.addData(key, value);
|
|
238
|
+
}
|
|
239
|
+
for (const signer of signers) {
|
|
240
|
+
if (signer.capabilityMode === "pure") {
|
|
241
|
+
builder.addSigner(signer.publicKey);
|
|
242
|
+
} else {
|
|
243
|
+
builder.addSigner(signer.publicKey, (withCapability) => {
|
|
244
|
+
const caps = [];
|
|
245
|
+
for (const line of (signer.capabilities || "").split("\n")) {
|
|
246
|
+
const parsed = parseCapabilityLine(line);
|
|
247
|
+
if (parsed) caps.push(withCapability(parsed.name, ...parsed.args));
|
|
248
|
+
}
|
|
249
|
+
return caps;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return builder.createTransaction();
|
|
254
|
+
}
|
|
255
|
+
async function signTransaction(runtime, resolver, signers, tx) {
|
|
256
|
+
const keypairs = [];
|
|
257
|
+
for (const signer of signers) {
|
|
258
|
+
const kp = await resolver.getKeyPairByPublicKey(signer.publicKey);
|
|
259
|
+
keypairs.push({
|
|
260
|
+
publicKey: kp.publicKey,
|
|
261
|
+
secretKey: kp.privateKey,
|
|
262
|
+
seedType: kp.seedType,
|
|
263
|
+
encryptedSecretKey: kp.encryptedSecretKey,
|
|
264
|
+
password: kp.password
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const signed = await runtime.universalSignTransaction(tx, keypairs);
|
|
268
|
+
if (!runtime.isSignedTransaction(signed)) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
"Signing incomplete: one or more signatures are missing after universalSignTransaction."
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
return signed;
|
|
274
|
+
}
|
|
275
|
+
function dirtyReadError(result) {
|
|
276
|
+
return result.error?.message || "Transaction simulation failed on-chain.";
|
|
277
|
+
}
|
|
278
|
+
async function listenWithTimeout(listen, descriptor, timeoutMs) {
|
|
279
|
+
let timeoutId = null;
|
|
280
|
+
try {
|
|
281
|
+
return await Promise.race([
|
|
282
|
+
listen(descriptor).finally(() => {
|
|
283
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
284
|
+
}),
|
|
285
|
+
new Promise((_, reject) => {
|
|
286
|
+
timeoutId = setTimeout(
|
|
287
|
+
() => reject(
|
|
288
|
+
new Error(
|
|
289
|
+
"Transaction confirmation timed out. Check explorer with the request key."
|
|
290
|
+
)
|
|
291
|
+
),
|
|
292
|
+
timeoutMs
|
|
293
|
+
);
|
|
294
|
+
})
|
|
295
|
+
]);
|
|
296
|
+
} finally {
|
|
297
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async function runSimulate(ctx, definition, signers) {
|
|
301
|
+
const { runtime, resolver } = ctx;
|
|
302
|
+
const ceiling = ctx.config?.autoGasCeiling ?? AUTO_GAS_CEILING;
|
|
303
|
+
const { autoGasLimit } = definition.config;
|
|
304
|
+
const tx = buildTransaction(
|
|
305
|
+
runtime,
|
|
306
|
+
definition,
|
|
307
|
+
signers,
|
|
308
|
+
autoGasLimit ? ceiling : void 0
|
|
309
|
+
);
|
|
310
|
+
const signed = await signTransaction(runtime, resolver, signers, tx);
|
|
311
|
+
const { dirtyRead } = runtime.createClient(
|
|
312
|
+
runtime.getPactUrl(definition.config.chainId)
|
|
313
|
+
);
|
|
314
|
+
const simulation = await dirtyRead(signed);
|
|
315
|
+
if (simulation.result.status === "failure") {
|
|
316
|
+
return {
|
|
317
|
+
ok: false,
|
|
318
|
+
mode: "simulate",
|
|
319
|
+
error: dirtyReadError(simulation.result),
|
|
320
|
+
rawResult: simulation.result,
|
|
321
|
+
terminalIntent: null
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const gasUsed = simulation.gas || 0;
|
|
325
|
+
const calibratedGasLimit = autoGasLimit && gasUsed > 0 ? runtime.calculateAutoGasLimit(gasUsed) : void 0;
|
|
326
|
+
return {
|
|
327
|
+
ok: true,
|
|
328
|
+
mode: "simulate",
|
|
329
|
+
gasUsed,
|
|
330
|
+
calibratedGasLimit,
|
|
331
|
+
rawResult: simulation.result,
|
|
332
|
+
terminalIntent: null
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
async function runFire(ctx, definition, signers) {
|
|
336
|
+
const { runtime, resolver } = ctx;
|
|
337
|
+
const ceiling = ctx.config?.autoGasCeiling ?? AUTO_GAS_CEILING;
|
|
338
|
+
const listenMs = ctx.config?.listenTimeoutMs ?? LISTEN_TIMEOUT_MS;
|
|
339
|
+
const { chainId, autoGasLimit } = definition.config;
|
|
340
|
+
const client = runtime.createClient(runtime.getPactUrl(chainId));
|
|
341
|
+
let tx = buildTransaction(
|
|
342
|
+
runtime,
|
|
343
|
+
definition,
|
|
344
|
+
signers,
|
|
345
|
+
autoGasLimit ? ceiling : void 0
|
|
346
|
+
);
|
|
347
|
+
let signed = await signTransaction(runtime, resolver, signers, tx);
|
|
348
|
+
const preflight = await client.dirtyRead(signed);
|
|
349
|
+
if (preflight.result.status === "failure") {
|
|
350
|
+
return {
|
|
351
|
+
ok: false,
|
|
352
|
+
mode: "fire",
|
|
353
|
+
chainId,
|
|
354
|
+
error: dirtyReadError(preflight.result),
|
|
355
|
+
rawResult: preflight.result,
|
|
356
|
+
terminalIntent: computeTerminalIntent(definition.scheduleKind, "fire", false)
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
if (autoGasLimit && (preflight.gas || 0) > 0) {
|
|
360
|
+
const calibrated = runtime.calculateAutoGasLimit(preflight.gas || 0);
|
|
361
|
+
tx = buildTransaction(runtime, definition, signers, calibrated);
|
|
362
|
+
signed = await signTransaction(runtime, resolver, signers, tx);
|
|
363
|
+
}
|
|
364
|
+
const signedAny = signed;
|
|
365
|
+
const derivedRequestKey = typeof signedAny.hash === "string" ? signedAny.hash : null;
|
|
366
|
+
let derivedNetworkId;
|
|
367
|
+
try {
|
|
368
|
+
const parsed = JSON.parse(
|
|
369
|
+
typeof signedAny.cmd === "string" ? signedAny.cmd : "{}"
|
|
370
|
+
);
|
|
371
|
+
if (typeof parsed.networkId === "string") derivedNetworkId = parsed.networkId;
|
|
372
|
+
} catch {
|
|
373
|
+
}
|
|
374
|
+
let submitResult;
|
|
375
|
+
try {
|
|
376
|
+
submitResult = await client.submit(signed);
|
|
377
|
+
} catch (submitErr) {
|
|
378
|
+
if (!derivedRequestKey) throw submitErr;
|
|
379
|
+
const descriptor = {
|
|
380
|
+
requestKey: derivedRequestKey,
|
|
381
|
+
chainId
|
|
382
|
+
};
|
|
383
|
+
if (derivedNetworkId) descriptor.networkId = derivedNetworkId;
|
|
384
|
+
submitResult = descriptor;
|
|
385
|
+
}
|
|
386
|
+
let result;
|
|
387
|
+
try {
|
|
388
|
+
result = await listenWithTimeout(client.listen, submitResult, listenMs);
|
|
389
|
+
} catch (listenErr) {
|
|
390
|
+
return {
|
|
391
|
+
ok: false,
|
|
392
|
+
mode: "fire",
|
|
393
|
+
chainId,
|
|
394
|
+
requestKey: submitResult.requestKey,
|
|
395
|
+
error: listenErr instanceof Error ? listenErr.message : "Transaction confirmation could not be observed.",
|
|
396
|
+
terminalIntent: computeTerminalIntent(definition.scheduleKind, "fire", false)
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
if (result.result.status === "failure") {
|
|
400
|
+
return {
|
|
401
|
+
ok: false,
|
|
402
|
+
mode: "fire",
|
|
403
|
+
chainId,
|
|
404
|
+
requestKey: result.reqKey || submitResult.requestKey,
|
|
405
|
+
error: result.result.error?.message || "Transaction failed on-chain.",
|
|
406
|
+
rawResult: result.result,
|
|
407
|
+
terminalIntent: computeTerminalIntent(definition.scheduleKind, "fire", false)
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
ok: true,
|
|
412
|
+
mode: "fire",
|
|
413
|
+
chainId,
|
|
414
|
+
requestKey: result.reqKey || submitResult.requestKey,
|
|
415
|
+
rawResult: result.result,
|
|
416
|
+
terminalIntent: computeTerminalIntent(definition.scheduleKind, "fire", true)
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
async function executeCodexTransaction(definition, mode, ctx) {
|
|
420
|
+
const { runtime } = ctx;
|
|
421
|
+
if (mode === "simulate") {
|
|
422
|
+
const signers = effectiveSigners(definition, runtime.namespace);
|
|
423
|
+
if (signers.length === 0) {
|
|
424
|
+
throw new Error(
|
|
425
|
+
"At least one signer is required to build a codex transaction."
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
return runSimulate(ctx, definition, signers);
|
|
429
|
+
}
|
|
430
|
+
try {
|
|
431
|
+
const signers = effectiveSigners(definition, runtime.namespace);
|
|
432
|
+
if (signers.length === 0) {
|
|
433
|
+
throw new Error(
|
|
434
|
+
"At least one signer is required to build a codex transaction."
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
return await runFire(ctx, definition, signers);
|
|
438
|
+
} catch (e) {
|
|
439
|
+
const error = (e instanceof Error ? e.message : String(e)) || (e instanceof Error ? `${e.name} (no message)` : "unknown fire error");
|
|
440
|
+
return {
|
|
441
|
+
ok: false,
|
|
442
|
+
mode: "fire",
|
|
443
|
+
chainId: definition.config.chainId,
|
|
444
|
+
error,
|
|
445
|
+
terminalIntent: computeTerminalIntent(definition.scheduleKind, "fire", false)
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/server/store/errors.ts
|
|
451
|
+
var CodexCronotonValidationError = class extends Error {
|
|
452
|
+
constructor(message) {
|
|
453
|
+
super(message);
|
|
454
|
+
this.name = "CodexCronotonValidationError";
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
var AutoGasGateError = class extends CodexCronotonValidationError {
|
|
458
|
+
constructor(message = "AUTO-gas row requires a concrete calibrated gasLimit > 0") {
|
|
459
|
+
super(message);
|
|
460
|
+
this.name = "AutoGasGateError";
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
var TerminalCronotonError = class extends Error {
|
|
464
|
+
constructor(status) {
|
|
465
|
+
super(
|
|
466
|
+
`codex cronoton is terminal (status='${status}'): a spent one-time entry cannot be reactivated or re-fired`
|
|
467
|
+
);
|
|
468
|
+
this.name = "TerminalCronotonError";
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
var ManualBatchActiveError = class extends Error {
|
|
472
|
+
constructor() {
|
|
473
|
+
super("a manual execution batch is already running for this codex cronoton");
|
|
474
|
+
this.name = "ManualBatchActiveError";
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
var MANUAL_BATCH_MIN = 2;
|
|
478
|
+
var MANUAL_BATCH_MAX = 60;
|
|
479
|
+
var MANUAL_BATCH_INTERVAL_SECONDS = 60;
|
|
480
|
+
|
|
481
|
+
// src/server/store/mappers.ts
|
|
482
|
+
function parseJson(json2, fallback) {
|
|
483
|
+
if (json2 == null) return fallback;
|
|
484
|
+
return JSON.parse(json2);
|
|
485
|
+
}
|
|
486
|
+
function rowToDefinition(row) {
|
|
487
|
+
return {
|
|
488
|
+
pactCode: row.pact_code,
|
|
489
|
+
config: parseJson(row.config_json, {}),
|
|
490
|
+
payload: parseJson(row.payload_json, {}),
|
|
491
|
+
gasPayer: parseJson(row.gas_payer_json, {
|
|
492
|
+
type: "gas-station"
|
|
493
|
+
}),
|
|
494
|
+
signers: parseJson(row.signers_json, []),
|
|
495
|
+
scheduleKind: row.schedule_mode === "one-time" ? "one-time" : "recurring",
|
|
496
|
+
serverResolver: row.server_resolver ?? void 0
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
function rowExternalFireable(row) {
|
|
500
|
+
return row.external_fireable === 1;
|
|
501
|
+
}
|
|
502
|
+
function rowRuntimeArgKeys(row) {
|
|
503
|
+
return parseRuntimeArgKeys(row.runtime_arg_keys);
|
|
504
|
+
}
|
|
505
|
+
function assertAutoGasGate(config) {
|
|
506
|
+
if (config.autoGasLimit !== true) return;
|
|
507
|
+
if (!Number.isFinite(config.gasLimit) || config.gasLimit <= 0) {
|
|
508
|
+
throw new AutoGasGateError();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function manualBatchView(row) {
|
|
512
|
+
return {
|
|
513
|
+
id: row.id,
|
|
514
|
+
codexCronotonId: row.codex_cronoton_id,
|
|
515
|
+
total: row.total,
|
|
516
|
+
completed: row.completed,
|
|
517
|
+
remaining: Math.max(0, row.total - row.completed),
|
|
518
|
+
intervalSeconds: row.interval_seconds,
|
|
519
|
+
status: row.status,
|
|
520
|
+
nextAt: row.next_at,
|
|
521
|
+
createdBy: row.created_by,
|
|
522
|
+
createdAt: row.created_at
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// src/schedule.ts
|
|
527
|
+
var InvalidScheduleConfigError = class extends Error {
|
|
528
|
+
constructor(message) {
|
|
529
|
+
super(message);
|
|
530
|
+
this.name = "InvalidScheduleConfigError";
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
function assertNever(x) {
|
|
534
|
+
throw new InvalidScheduleConfigError(`unknown schedule mode: ${String(x)}`);
|
|
535
|
+
}
|
|
536
|
+
function isValidHour(h) {
|
|
537
|
+
return Number.isInteger(h) && h >= 0 && h <= 23;
|
|
538
|
+
}
|
|
539
|
+
function isValidMinute(m) {
|
|
540
|
+
return Number.isInteger(m) && m >= 0 && m <= 59;
|
|
541
|
+
}
|
|
542
|
+
function isValidDayOfWeek(d) {
|
|
543
|
+
return Number.isInteger(d) && d >= 0 && d <= 6;
|
|
544
|
+
}
|
|
545
|
+
function isValidDayOfMonth(d) {
|
|
546
|
+
return Number.isInteger(d) && d >= 1 && d <= 31;
|
|
547
|
+
}
|
|
548
|
+
function computeNextFire(mode, config, now) {
|
|
549
|
+
if (config.mode !== mode) {
|
|
550
|
+
throw new InvalidScheduleConfigError(
|
|
551
|
+
`mode/config mismatch: mode=${mode} config.mode=${config.mode}`
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
switch (config.mode) {
|
|
555
|
+
case "daily-at-utc":
|
|
556
|
+
return nextDailyAtUtc(config, now);
|
|
557
|
+
case "every-n-minutes":
|
|
558
|
+
return nextEveryNMinutes(config, now);
|
|
559
|
+
case "weekly":
|
|
560
|
+
return nextWeekly(config, now);
|
|
561
|
+
case "monthly":
|
|
562
|
+
return nextMonthly(config, now);
|
|
563
|
+
case "cron-expression":
|
|
564
|
+
return nextCronExpression(config, now);
|
|
565
|
+
case "one-time":
|
|
566
|
+
return nextOneTime(config, now);
|
|
567
|
+
case "several-times-per-day":
|
|
568
|
+
return nextSeveralTimesPerDay(config, now);
|
|
569
|
+
default:
|
|
570
|
+
return assertNever(config);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
function nextOneTime(config, now) {
|
|
574
|
+
const fireMs = Date.parse(config.fireAt);
|
|
575
|
+
if (Number.isNaN(fireMs)) {
|
|
576
|
+
throw new InvalidScheduleConfigError(
|
|
577
|
+
`one-time: fireAt is not a valid ISO8601 string: ${config.fireAt}`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
if (fireMs <= now.getTime()) return null;
|
|
581
|
+
return new Date(fireMs);
|
|
582
|
+
}
|
|
583
|
+
function sortedTimesOfDay(times) {
|
|
584
|
+
const seen = /* @__PURE__ */ new Set();
|
|
585
|
+
const unique = [];
|
|
586
|
+
for (const t of times) {
|
|
587
|
+
const key = t.hour * 60 + t.minute;
|
|
588
|
+
if (seen.has(key)) continue;
|
|
589
|
+
seen.add(key);
|
|
590
|
+
unique.push(t);
|
|
591
|
+
}
|
|
592
|
+
return unique.sort(
|
|
593
|
+
(a, b) => a.hour * 60 + a.minute - (b.hour * 60 + b.minute)
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
function nextSeveralTimesPerDay(config, now) {
|
|
597
|
+
if (!Array.isArray(config.times) || config.times.length === 0) {
|
|
598
|
+
throw new InvalidScheduleConfigError(
|
|
599
|
+
"several-times-per-day requires a non-empty times array"
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
if (!config.times.every((t) => isValidHour(t.hour) && isValidMinute(t.minute))) {
|
|
603
|
+
throw new InvalidScheduleConfigError(
|
|
604
|
+
"several-times-per-day: each time must have hour in [0..23] and minute in [0..59] (integers)"
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
const times = sortedTimesOfDay(config.times);
|
|
608
|
+
for (let dayOffset = 0; dayOffset <= 1; dayOffset++) {
|
|
609
|
+
for (const t of times) {
|
|
610
|
+
const candidate = new Date(
|
|
611
|
+
Date.UTC(
|
|
612
|
+
now.getUTCFullYear(),
|
|
613
|
+
now.getUTCMonth(),
|
|
614
|
+
now.getUTCDate() + dayOffset,
|
|
615
|
+
t.hour,
|
|
616
|
+
t.minute,
|
|
617
|
+
0,
|
|
618
|
+
0
|
|
619
|
+
)
|
|
620
|
+
);
|
|
621
|
+
if (candidate.getTime() > now.getTime()) {
|
|
622
|
+
return candidate;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
throw new InvalidScheduleConfigError(
|
|
627
|
+
"several-times-per-day: failed to find next-fire within 48h sweep"
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
function nextDailyAtUtc(config, now) {
|
|
631
|
+
if (!Array.isArray(config.hours) || config.hours.length === 0) {
|
|
632
|
+
throw new InvalidScheduleConfigError(
|
|
633
|
+
"daily-at-utc requires a non-empty hours array"
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
if (!config.hours.every(isValidHour)) {
|
|
637
|
+
throw new InvalidScheduleConfigError(
|
|
638
|
+
"daily-at-utc hours must be integers in [0..23]"
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
if (!isValidMinute(config.minute)) {
|
|
642
|
+
throw new InvalidScheduleConfigError(
|
|
643
|
+
"daily-at-utc minute must be an integer in [0..59]"
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
const sortedHours = [...new Set(config.hours)].sort((a, b) => a - b);
|
|
647
|
+
for (let dayOffset = 0; dayOffset <= 1; dayOffset++) {
|
|
648
|
+
for (const h of sortedHours) {
|
|
649
|
+
const candidate = new Date(
|
|
650
|
+
Date.UTC(
|
|
651
|
+
now.getUTCFullYear(),
|
|
652
|
+
now.getUTCMonth(),
|
|
653
|
+
now.getUTCDate() + dayOffset,
|
|
654
|
+
h,
|
|
655
|
+
config.minute,
|
|
656
|
+
0,
|
|
657
|
+
0
|
|
658
|
+
)
|
|
659
|
+
);
|
|
660
|
+
if (candidate.getTime() > now.getTime()) {
|
|
661
|
+
return candidate;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
throw new InvalidScheduleConfigError(
|
|
666
|
+
"daily-at-utc: failed to find next-fire within 48h sweep"
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
function nextEveryNMinutes(config, now) {
|
|
670
|
+
if (!Number.isInteger(config.intervalMinutes) || config.intervalMinutes <= 0) {
|
|
671
|
+
throw new InvalidScheduleConfigError(
|
|
672
|
+
"every-n-minutes: intervalMinutes must be a positive integer"
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
const startMs = Date.parse(config.startDate);
|
|
676
|
+
if (Number.isNaN(startMs)) {
|
|
677
|
+
throw new InvalidScheduleConfigError(
|
|
678
|
+
`every-n-minutes: startDate is not a valid ISO8601 string: ${config.startDate}`
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
const intervalMs = config.intervalMinutes * 6e4;
|
|
682
|
+
const nowMs = now.getTime();
|
|
683
|
+
if (nowMs < startMs) return new Date(startMs);
|
|
684
|
+
const elapsed = nowMs - startMs;
|
|
685
|
+
const nextMs = startMs + (Math.floor(elapsed / intervalMs) + 1) * intervalMs;
|
|
686
|
+
return new Date(nextMs);
|
|
687
|
+
}
|
|
688
|
+
function nextWeekly(config, now) {
|
|
689
|
+
if (!Array.isArray(config.daysOfWeek) || config.daysOfWeek.length === 0) {
|
|
690
|
+
throw new InvalidScheduleConfigError(
|
|
691
|
+
"weekly: daysOfWeek must be a non-empty array"
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
if (!config.daysOfWeek.every(isValidDayOfWeek)) {
|
|
695
|
+
throw new InvalidScheduleConfigError(
|
|
696
|
+
"weekly: daysOfWeek values must be integers in [0..6]"
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
if (!isValidHour(config.hour)) {
|
|
700
|
+
throw new InvalidScheduleConfigError(
|
|
701
|
+
"weekly: hour must be an integer in [0..23]"
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
if (!isValidMinute(config.minute)) {
|
|
705
|
+
throw new InvalidScheduleConfigError(
|
|
706
|
+
"weekly: minute must be an integer in [0..59]"
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
const dows = new Set(config.daysOfWeek);
|
|
710
|
+
for (let i = 0; i < 8; i++) {
|
|
711
|
+
const probe = new Date(
|
|
712
|
+
Date.UTC(
|
|
713
|
+
now.getUTCFullYear(),
|
|
714
|
+
now.getUTCMonth(),
|
|
715
|
+
now.getUTCDate() + i,
|
|
716
|
+
config.hour,
|
|
717
|
+
config.minute,
|
|
718
|
+
0,
|
|
719
|
+
0
|
|
720
|
+
)
|
|
721
|
+
);
|
|
722
|
+
if (!dows.has(probe.getUTCDay())) continue;
|
|
723
|
+
if (probe.getTime() > now.getTime()) return probe;
|
|
724
|
+
}
|
|
725
|
+
throw new InvalidScheduleConfigError(
|
|
726
|
+
"weekly: failed to find next-fire within 8-day sweep"
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
function nextMonthly(config, now) {
|
|
730
|
+
if (!Array.isArray(config.daysOfMonth) || config.daysOfMonth.length === 0) {
|
|
731
|
+
throw new InvalidScheduleConfigError(
|
|
732
|
+
"monthly: daysOfMonth must be a non-empty array"
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
if (!config.daysOfMonth.every(isValidDayOfMonth)) {
|
|
736
|
+
throw new InvalidScheduleConfigError(
|
|
737
|
+
"monthly: daysOfMonth values must be integers in [1..31]"
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
if (!isValidHour(config.hour)) {
|
|
741
|
+
throw new InvalidScheduleConfigError(
|
|
742
|
+
"monthly: hour must be an integer in [0..23]"
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
if (!isValidMinute(config.minute)) {
|
|
746
|
+
throw new InvalidScheduleConfigError(
|
|
747
|
+
"monthly: minute must be an integer in [0..59]"
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
for (let i = 0; i < 33; i++) {
|
|
751
|
+
const probe = new Date(
|
|
752
|
+
Date.UTC(
|
|
753
|
+
now.getUTCFullYear(),
|
|
754
|
+
now.getUTCMonth(),
|
|
755
|
+
now.getUTCDate() + i,
|
|
756
|
+
config.hour,
|
|
757
|
+
config.minute,
|
|
758
|
+
0,
|
|
759
|
+
0
|
|
760
|
+
)
|
|
761
|
+
);
|
|
762
|
+
const probeDay = probe.getUTCDate();
|
|
763
|
+
if (!config.daysOfMonth.includes(probeDay)) continue;
|
|
764
|
+
if (probe.getTime() > now.getTime()) return probe;
|
|
765
|
+
}
|
|
766
|
+
throw new InvalidScheduleConfigError(
|
|
767
|
+
"monthly: failed to find next-fire within 33-day sweep"
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
function parseCronField(raw, min, max) {
|
|
771
|
+
const out = /* @__PURE__ */ new Set();
|
|
772
|
+
if (!raw || typeof raw !== "string") {
|
|
773
|
+
throw new InvalidScheduleConfigError(`cron-expression: empty field`);
|
|
774
|
+
}
|
|
775
|
+
for (const piece of raw.split(",")) {
|
|
776
|
+
const p = piece.trim();
|
|
777
|
+
if (!p) {
|
|
778
|
+
throw new InvalidScheduleConfigError(`cron-expression: empty list slot`);
|
|
779
|
+
}
|
|
780
|
+
if (p.includes("/")) {
|
|
781
|
+
const [basePart, stepPart] = p.split("/");
|
|
782
|
+
const step = Number(stepPart);
|
|
783
|
+
if (!Number.isInteger(step) || step <= 0) {
|
|
784
|
+
throw new InvalidScheduleConfigError(
|
|
785
|
+
`cron-expression: invalid step '${stepPart}'`
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
let rangeStart = min;
|
|
789
|
+
let rangeEnd = max;
|
|
790
|
+
if (basePart === "*") ; else if (basePart.includes("-")) {
|
|
791
|
+
const [s, e] = basePart.split("-").map(Number);
|
|
792
|
+
if (!Number.isInteger(s) || !Number.isInteger(e) || s < min || e > max || s > e) {
|
|
793
|
+
throw new InvalidScheduleConfigError(
|
|
794
|
+
`cron-expression: invalid range '${basePart}'`
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
rangeStart = s;
|
|
798
|
+
rangeEnd = e;
|
|
799
|
+
} else {
|
|
800
|
+
const n2 = Number(basePart);
|
|
801
|
+
if (!Number.isInteger(n2) || n2 < min || n2 > max) {
|
|
802
|
+
throw new InvalidScheduleConfigError(
|
|
803
|
+
`cron-expression: invalid base '${basePart}'`
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
rangeStart = n2;
|
|
807
|
+
rangeEnd = max;
|
|
808
|
+
}
|
|
809
|
+
for (let v = rangeStart; v <= rangeEnd; v += step) {
|
|
810
|
+
out.add(v);
|
|
811
|
+
}
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
if (p === "*") {
|
|
815
|
+
for (let v = min; v <= max; v++) out.add(v);
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
if (p.includes("-")) {
|
|
819
|
+
const [s, e] = p.split("-").map(Number);
|
|
820
|
+
if (!Number.isInteger(s) || !Number.isInteger(e) || s < min || e > max || s > e) {
|
|
821
|
+
throw new InvalidScheduleConfigError(
|
|
822
|
+
`cron-expression: invalid range '${p}'`
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
for (let v = s; v <= e; v++) out.add(v);
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
const n = Number(p);
|
|
829
|
+
if (!Number.isInteger(n) || n < min || n > max) {
|
|
830
|
+
throw new InvalidScheduleConfigError(
|
|
831
|
+
`cron-expression: invalid literal '${p}'`
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
out.add(n);
|
|
835
|
+
}
|
|
836
|
+
if (out.size === 0) {
|
|
837
|
+
throw new InvalidScheduleConfigError(
|
|
838
|
+
`cron-expression: parsed an empty value set from '${raw}'`
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
return out;
|
|
842
|
+
}
|
|
843
|
+
function parseCronExpression(expression) {
|
|
844
|
+
if (typeof expression !== "string") {
|
|
845
|
+
throw new InvalidScheduleConfigError(
|
|
846
|
+
"cron-expression: expression must be a string"
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
const fields = expression.trim().split(/\s+/);
|
|
850
|
+
if (fields.length !== 5) {
|
|
851
|
+
throw new InvalidScheduleConfigError(
|
|
852
|
+
`cron-expression: expected 5 fields, got ${fields.length} ('${expression}')`
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
return {
|
|
856
|
+
minutes: parseCronField(fields[0], 0, 59),
|
|
857
|
+
hours: parseCronField(fields[1], 0, 23),
|
|
858
|
+
daysOfMonth: parseCronField(fields[2], 1, 31),
|
|
859
|
+
months: parseCronField(fields[3], 1, 12),
|
|
860
|
+
daysOfWeek: parseCronField(fields[4], 0, 6)
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
function nextCronExpression(config, now) {
|
|
864
|
+
const parsed = parseCronExpression(config.expression);
|
|
865
|
+
const MAX_MINUTES = 366 * 24 * 60;
|
|
866
|
+
const start = new Date(now.getTime());
|
|
867
|
+
start.setUTCSeconds(0, 0);
|
|
868
|
+
start.setUTCMinutes(start.getUTCMinutes() + 1);
|
|
869
|
+
for (let i = 0; i < MAX_MINUTES; i++) {
|
|
870
|
+
const probe = new Date(start.getTime() + i * 6e4);
|
|
871
|
+
const minute = probe.getUTCMinutes();
|
|
872
|
+
const hour = probe.getUTCHours();
|
|
873
|
+
const dom = probe.getUTCDate();
|
|
874
|
+
const month = probe.getUTCMonth() + 1;
|
|
875
|
+
const dow = probe.getUTCDay();
|
|
876
|
+
if (!parsed.minutes.has(minute)) continue;
|
|
877
|
+
if (!parsed.hours.has(hour)) continue;
|
|
878
|
+
if (!parsed.months.has(month)) continue;
|
|
879
|
+
const domAny = parsed.daysOfMonth.size === 31;
|
|
880
|
+
const dowAny = parsed.daysOfWeek.size === 7;
|
|
881
|
+
if (domAny && dowAny) {
|
|
882
|
+
return probe;
|
|
883
|
+
}
|
|
884
|
+
if (domAny) {
|
|
885
|
+
if (parsed.daysOfWeek.has(dow)) return probe;
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
if (dowAny) {
|
|
889
|
+
if (parsed.daysOfMonth.has(dom)) return probe;
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
if (parsed.daysOfMonth.has(dom) || parsed.daysOfWeek.has(dow)) {
|
|
893
|
+
return probe;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
throw new InvalidScheduleConfigError(
|
|
897
|
+
`cron-expression: no future fire found within ${MAX_MINUTES} minutes`
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
function summariseSchedule(mode, config) {
|
|
901
|
+
if (config.mode !== mode) return `${mode} (config mismatch)`;
|
|
902
|
+
switch (config.mode) {
|
|
903
|
+
case "daily-at-utc": {
|
|
904
|
+
const hours = [...new Set(config.hours)].sort((a, b) => a - b);
|
|
905
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
906
|
+
const hourList = hours.map((h) => `${pad(h)}:${pad(config.minute)}`).join(", ");
|
|
907
|
+
return `Daily at ${hourList} UTC`;
|
|
908
|
+
}
|
|
909
|
+
case "every-n-minutes":
|
|
910
|
+
return `Every ${config.intervalMinutes} minute${config.intervalMinutes === 1 ? "" : "s"} from ${config.startDate}`;
|
|
911
|
+
case "weekly": {
|
|
912
|
+
const names = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
913
|
+
const days = [...new Set(config.daysOfWeek)].sort((a, b) => a - b).map((d) => names[d]).join("/");
|
|
914
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
915
|
+
return `Weekly ${days} at ${pad(config.hour)}:${pad(config.minute)} UTC`;
|
|
916
|
+
}
|
|
917
|
+
case "monthly": {
|
|
918
|
+
const days = [...new Set(config.daysOfMonth)].sort((a, b) => a - b).join(", ");
|
|
919
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
920
|
+
return `Monthly day(s) ${days} at ${pad(config.hour)}:${pad(config.minute)} UTC`;
|
|
921
|
+
}
|
|
922
|
+
case "cron-expression":
|
|
923
|
+
return `Cron '${config.expression}' (UTC)`;
|
|
924
|
+
case "one-time":
|
|
925
|
+
return `One-time at ${config.fireAt} UTC`;
|
|
926
|
+
case "several-times-per-day": {
|
|
927
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
928
|
+
const list = sortedTimesOfDay(config.times).map((t) => `${pad(t.hour)}:${pad(t.minute)}`).join(", ");
|
|
929
|
+
return `Several times daily at ${list} UTC`;
|
|
930
|
+
}
|
|
931
|
+
default:
|
|
932
|
+
return assertNever(config);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// src/server/store/claim.ts
|
|
937
|
+
function applyTerminalIntent(id, terminalIntent, dep) {
|
|
938
|
+
if (terminalIntent == null) return;
|
|
939
|
+
dep.db.prepare(
|
|
940
|
+
`UPDATE codex_cronotons SET status = ?, next_fire_at = NULL, modified_at = ? WHERE id = ?`
|
|
941
|
+
).run(terminalIntent.status, (/* @__PURE__ */ new Date()).toISOString(), id);
|
|
942
|
+
}
|
|
943
|
+
function readFireMode(db, codexCronotonId, resolveFireMode) {
|
|
944
|
+
const parent = db.prepare(`SELECT fire_mode_override FROM codex_cronotons WHERE id = ?`).get(codexCronotonId);
|
|
945
|
+
if (parent?.fire_mode_override === "live") return "live";
|
|
946
|
+
return resolveFireMode(codexCronotonId);
|
|
947
|
+
}
|
|
948
|
+
function recordFire(input, dep) {
|
|
949
|
+
const db = dep.db;
|
|
950
|
+
const fireId = randomUUID();
|
|
951
|
+
const mode = readFireMode(db, input.codexCronotonId, dep.resolveFireMode ?? defaultResolveFireMode);
|
|
952
|
+
db.prepare(
|
|
953
|
+
`INSERT INTO codex_cronoton_fires
|
|
954
|
+
(id, codex_cronoton_id, job_id, fired_at, status, request_key, chain_id,
|
|
955
|
+
error_message, chain_response_json, definition_fingerprint, mode, tx_keys_json)
|
|
956
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
957
|
+
).run(
|
|
958
|
+
fireId,
|
|
959
|
+
input.codexCronotonId,
|
|
960
|
+
input.jobId,
|
|
961
|
+
input.firedAt,
|
|
962
|
+
input.status,
|
|
963
|
+
input.requestKey ?? null,
|
|
964
|
+
input.chainId ?? null,
|
|
965
|
+
input.errorMessage ?? null,
|
|
966
|
+
input.chainResponse !== void 0 ? JSON.stringify(input.chainResponse) : null,
|
|
967
|
+
input.definitionFingerprint,
|
|
968
|
+
mode,
|
|
969
|
+
input.txKeys && input.txKeys.length ? JSON.stringify(input.txKeys) : null
|
|
970
|
+
);
|
|
971
|
+
db.prepare(`UPDATE codex_cronotons SET last_fire_at = ? WHERE id = ?`).run(
|
|
972
|
+
input.firedAt,
|
|
973
|
+
input.codexCronotonId
|
|
974
|
+
);
|
|
975
|
+
return fireId;
|
|
976
|
+
}
|
|
977
|
+
function parseTxKeys(json2) {
|
|
978
|
+
if (!json2) return [];
|
|
979
|
+
try {
|
|
980
|
+
const parsed = JSON.parse(json2);
|
|
981
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
982
|
+
} catch {
|
|
983
|
+
return [];
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
function listFires(id, params = {}, dep) {
|
|
987
|
+
const db = dep.db;
|
|
988
|
+
const limit = Math.min(Math.max(params.limit ?? 20, 1), 100);
|
|
989
|
+
const offset = Math.max(params.offset ?? 0, 0);
|
|
990
|
+
const rows = db.prepare(
|
|
991
|
+
`SELECT id, fired_at, status, request_key, chain_id, error_message,
|
|
992
|
+
chain_response_json, definition_fingerprint, mode, recovered_at, tx_keys_json
|
|
993
|
+
FROM codex_cronoton_fires
|
|
994
|
+
WHERE codex_cronoton_id = ?
|
|
995
|
+
ORDER BY fired_at DESC LIMIT ? OFFSET ?`
|
|
996
|
+
).all(id, limit, offset);
|
|
997
|
+
const totalRow = db.prepare("SELECT COUNT(*) AS c FROM codex_cronoton_fires WHERE codex_cronoton_id = ?").get(id);
|
|
998
|
+
return {
|
|
999
|
+
fires: rows.map((r) => ({
|
|
1000
|
+
id: r.id,
|
|
1001
|
+
firedAt: r.fired_at,
|
|
1002
|
+
status: r.status,
|
|
1003
|
+
requestKey: r.request_key,
|
|
1004
|
+
chainId: r.chain_id,
|
|
1005
|
+
errorMessage: r.error_message,
|
|
1006
|
+
chainResponse: r.chain_response_json ? JSON.parse(r.chain_response_json) : null,
|
|
1007
|
+
definitionFingerprint: r.definition_fingerprint,
|
|
1008
|
+
mode: r.mode === "live" ? "live" : "test",
|
|
1009
|
+
recoveredAt: r.recovered_at,
|
|
1010
|
+
txKeys: parseTxKeys(r.tx_keys_json)
|
|
1011
|
+
})),
|
|
1012
|
+
total: totalRow?.c ?? 0
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
function recoverFire(fireId, requestKey, dep) {
|
|
1016
|
+
const res = dep.db.prepare(
|
|
1017
|
+
`UPDATE codex_cronoton_fires
|
|
1018
|
+
SET status = 'success',
|
|
1019
|
+
request_key = ?,
|
|
1020
|
+
recovered_at = ?,
|
|
1021
|
+
error_message = NULL
|
|
1022
|
+
WHERE id = ? AND status = 'failure'`
|
|
1023
|
+
).run(requestKey, (/* @__PURE__ */ new Date()).toISOString(), fireId);
|
|
1024
|
+
return res.changes > 0;
|
|
1025
|
+
}
|
|
1026
|
+
function computeNextOrReject(mode, config, now) {
|
|
1027
|
+
let next;
|
|
1028
|
+
try {
|
|
1029
|
+
next = computeNextFire(mode, config, now);
|
|
1030
|
+
} catch (err2) {
|
|
1031
|
+
if (err2 instanceof InvalidScheduleConfigError) {
|
|
1032
|
+
throw new CodexCronotonValidationError(err2.message);
|
|
1033
|
+
}
|
|
1034
|
+
throw err2;
|
|
1035
|
+
}
|
|
1036
|
+
if (!next) {
|
|
1037
|
+
throw new CodexCronotonValidationError("schedule has no future fires");
|
|
1038
|
+
}
|
|
1039
|
+
return next;
|
|
1040
|
+
}
|
|
1041
|
+
function commitCodexCronoton(input, opts) {
|
|
1042
|
+
if (typeof input.name !== "string" || input.name.trim() === "") {
|
|
1043
|
+
throw new CodexCronotonValidationError("name must be a non-empty string");
|
|
1044
|
+
}
|
|
1045
|
+
if (typeof input.pactCode !== "string") {
|
|
1046
|
+
throw new CodexCronotonValidationError("pactCode must be a string");
|
|
1047
|
+
}
|
|
1048
|
+
if (!input.config || typeof input.config.chainId !== "string") {
|
|
1049
|
+
throw new CodexCronotonValidationError("config.chainId must be a string");
|
|
1050
|
+
}
|
|
1051
|
+
if (!Array.isArray(input.signers)) {
|
|
1052
|
+
throw new CodexCronotonValidationError("signers must be an array");
|
|
1053
|
+
}
|
|
1054
|
+
if (!input.gasPayer || typeof input.gasPayer.type !== "string") {
|
|
1055
|
+
throw new CodexCronotonValidationError("gasPayer.type must be a string");
|
|
1056
|
+
}
|
|
1057
|
+
assertAutoGasGate(input.config);
|
|
1058
|
+
const runtimeArgKeys = input.runtimeArgKeys ?? [];
|
|
1059
|
+
if (runtimeArgKeysCollide(input.payload ?? {}, runtimeArgKeys)) {
|
|
1060
|
+
throw new CodexCronotonValidationError(
|
|
1061
|
+
"runtimeArgKeys must be disjoint from payload keys"
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
if (input.serverResolver && runtimeArgKeys.length > 0) {
|
|
1065
|
+
throw new CodexCronotonValidationError(
|
|
1066
|
+
"server-resolver rows cannot declare runtime args"
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
1070
|
+
const triggerOnly = input.externalFireable === true || runtimeArgKeys.length > 0;
|
|
1071
|
+
const nextFireAt = triggerOnly ? null : computeNextOrReject(input.scheduleMode, input.scheduleConfig, now).toISOString();
|
|
1072
|
+
const id = crypto2.randomUUID();
|
|
1073
|
+
const nowIso = now.toISOString();
|
|
1074
|
+
opts.db.prepare(
|
|
1075
|
+
`INSERT INTO codex_cronotons
|
|
1076
|
+
(id, name, description, pact_code, config_json, payload_json,
|
|
1077
|
+
gas_payer_json, signers_json, schedule_mode, schedule_config_json,
|
|
1078
|
+
server_resolver, external_fireable, runtime_arg_keys, status,
|
|
1079
|
+
next_fire_at, last_fire_at, created_at, modified_at, created_by)
|
|
1080
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, NULL, ?, ?, ?)`
|
|
1081
|
+
).run(
|
|
1082
|
+
id,
|
|
1083
|
+
input.name.trim(),
|
|
1084
|
+
input.description,
|
|
1085
|
+
input.pactCode,
|
|
1086
|
+
JSON.stringify(input.config),
|
|
1087
|
+
input.payload ? JSON.stringify(input.payload) : null,
|
|
1088
|
+
JSON.stringify(input.gasPayer),
|
|
1089
|
+
JSON.stringify(input.signers),
|
|
1090
|
+
input.scheduleMode,
|
|
1091
|
+
JSON.stringify(input.scheduleConfig),
|
|
1092
|
+
input.serverResolver ?? null,
|
|
1093
|
+
input.externalFireable ? 1 : 0,
|
|
1094
|
+
runtimeArgKeys.length > 0 ? JSON.stringify(runtimeArgKeys) : null,
|
|
1095
|
+
nextFireAt,
|
|
1096
|
+
nowIso,
|
|
1097
|
+
nowIso,
|
|
1098
|
+
input.createdBy
|
|
1099
|
+
);
|
|
1100
|
+
return { id, nextFireAt };
|
|
1101
|
+
}
|
|
1102
|
+
function getCodexCronoton(id, dep) {
|
|
1103
|
+
const row = dep.db.prepare("SELECT * FROM codex_cronotons WHERE id = ?").get(id);
|
|
1104
|
+
return row ?? null;
|
|
1105
|
+
}
|
|
1106
|
+
function listCodexCronotons(params, dep) {
|
|
1107
|
+
const limit = Math.min(Math.max(params.limit ?? 50, 1), 200);
|
|
1108
|
+
const offset = Math.max(params.offset ?? 0, 0);
|
|
1109
|
+
const db = dep.db;
|
|
1110
|
+
const rows = params.status ? db.prepare(
|
|
1111
|
+
`SELECT id, name, schedule_mode, status, next_fire_at, last_fire_at,
|
|
1112
|
+
created_at, modified_at, created_by
|
|
1113
|
+
FROM codex_cronotons WHERE status = ?
|
|
1114
|
+
ORDER BY created_at DESC LIMIT ? OFFSET ?`
|
|
1115
|
+
).all(params.status, limit, offset) : db.prepare(
|
|
1116
|
+
`SELECT id, name, schedule_mode, status, next_fire_at, last_fire_at,
|
|
1117
|
+
created_at, modified_at, created_by
|
|
1118
|
+
FROM codex_cronotons
|
|
1119
|
+
ORDER BY created_at DESC LIMIT ? OFFSET ?`
|
|
1120
|
+
).all(limit, offset);
|
|
1121
|
+
return rows.map((r) => ({
|
|
1122
|
+
id: r.id,
|
|
1123
|
+
name: r.name,
|
|
1124
|
+
scheduleMode: r.schedule_mode,
|
|
1125
|
+
status: r.status,
|
|
1126
|
+
nextFireAt: r.next_fire_at,
|
|
1127
|
+
lastFireAt: r.last_fire_at,
|
|
1128
|
+
createdAt: r.created_at,
|
|
1129
|
+
modifiedAt: r.modified_at,
|
|
1130
|
+
createdBy: r.created_by
|
|
1131
|
+
}));
|
|
1132
|
+
}
|
|
1133
|
+
function editCodexCronoton(id, patch, opts) {
|
|
1134
|
+
const db = opts.db;
|
|
1135
|
+
const row = getCodexCronoton(id, { db });
|
|
1136
|
+
if (!row) throw new CodexCronotonValidationError("not found");
|
|
1137
|
+
const changedFields = [];
|
|
1138
|
+
let nextName = row.name;
|
|
1139
|
+
let nextDescription = row.description;
|
|
1140
|
+
let nextPactCode = row.pact_code;
|
|
1141
|
+
let nextConfigJson = row.config_json;
|
|
1142
|
+
let nextPayloadJson = row.payload_json;
|
|
1143
|
+
let nextGasPayerJson = row.gas_payer_json;
|
|
1144
|
+
let nextSignersJson = row.signers_json;
|
|
1145
|
+
let nextScheduleMode = row.schedule_mode;
|
|
1146
|
+
let nextScheduleConfigJson = row.schedule_config_json;
|
|
1147
|
+
let nextServerResolver = row.server_resolver;
|
|
1148
|
+
let nextFireAt = row.next_fire_at;
|
|
1149
|
+
if (typeof patch.name === "string" && patch.name.trim() !== "" && patch.name.trim() !== row.name) {
|
|
1150
|
+
nextName = patch.name.trim();
|
|
1151
|
+
changedFields.push("name");
|
|
1152
|
+
}
|
|
1153
|
+
if (patch.description !== void 0 && patch.description !== row.description) {
|
|
1154
|
+
nextDescription = patch.description;
|
|
1155
|
+
changedFields.push("description");
|
|
1156
|
+
}
|
|
1157
|
+
if (typeof patch.pactCode === "string" && patch.pactCode !== row.pact_code) {
|
|
1158
|
+
nextPactCode = patch.pactCode;
|
|
1159
|
+
changedFields.push("pactCode");
|
|
1160
|
+
}
|
|
1161
|
+
if (patch.config) {
|
|
1162
|
+
assertAutoGasGate(patch.config);
|
|
1163
|
+
nextConfigJson = JSON.stringify(patch.config);
|
|
1164
|
+
changedFields.push("config");
|
|
1165
|
+
}
|
|
1166
|
+
if (patch.payload !== void 0) {
|
|
1167
|
+
if (runtimeArgKeysCollide(patch.payload ?? {}, rowRuntimeArgKeys(row))) {
|
|
1168
|
+
throw new CodexCronotonValidationError(
|
|
1169
|
+
"payload keys must be disjoint from runtimeArgKeys"
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1172
|
+
nextPayloadJson = patch.payload ? JSON.stringify(patch.payload) : null;
|
|
1173
|
+
changedFields.push("payload");
|
|
1174
|
+
}
|
|
1175
|
+
if (patch.gasPayer) {
|
|
1176
|
+
nextGasPayerJson = JSON.stringify(patch.gasPayer);
|
|
1177
|
+
changedFields.push("gasPayer");
|
|
1178
|
+
}
|
|
1179
|
+
if (patch.signers) {
|
|
1180
|
+
nextSignersJson = JSON.stringify(patch.signers);
|
|
1181
|
+
changedFields.push("signers");
|
|
1182
|
+
}
|
|
1183
|
+
if (patch.serverResolver !== void 0) {
|
|
1184
|
+
nextServerResolver = patch.serverResolver;
|
|
1185
|
+
changedFields.push("serverResolver");
|
|
1186
|
+
}
|
|
1187
|
+
let scheduleChanged = false;
|
|
1188
|
+
if (patch.scheduleMode && patch.scheduleConfig) {
|
|
1189
|
+
nextScheduleMode = patch.scheduleMode;
|
|
1190
|
+
nextScheduleConfigJson = JSON.stringify(patch.scheduleConfig);
|
|
1191
|
+
scheduleChanged = true;
|
|
1192
|
+
changedFields.push("schedule");
|
|
1193
|
+
}
|
|
1194
|
+
const rowTriggerOnly = rowExternalFireable(row) || rowRuntimeArgKeys(row).length > 0;
|
|
1195
|
+
if (scheduleChanged && !rowTriggerOnly) {
|
|
1196
|
+
const next = computeNextOrReject(
|
|
1197
|
+
nextScheduleMode,
|
|
1198
|
+
JSON.parse(nextScheduleConfigJson),
|
|
1199
|
+
opts.now ?? /* @__PURE__ */ new Date()
|
|
1200
|
+
);
|
|
1201
|
+
nextFireAt = next.toISOString();
|
|
1202
|
+
}
|
|
1203
|
+
if (changedFields.length === 0) {
|
|
1204
|
+
return { changedFields, nextFireAt };
|
|
1205
|
+
}
|
|
1206
|
+
db.prepare(
|
|
1207
|
+
`UPDATE codex_cronotons
|
|
1208
|
+
SET name = ?, description = ?, pact_code = ?, config_json = ?,
|
|
1209
|
+
payload_json = ?, gas_payer_json = ?, signers_json = ?,
|
|
1210
|
+
schedule_mode = ?, schedule_config_json = ?, server_resolver = ?,
|
|
1211
|
+
next_fire_at = ?, modified_at = ?
|
|
1212
|
+
WHERE id = ?`
|
|
1213
|
+
).run(
|
|
1214
|
+
nextName,
|
|
1215
|
+
nextDescription,
|
|
1216
|
+
nextPactCode,
|
|
1217
|
+
nextConfigJson,
|
|
1218
|
+
nextPayloadJson,
|
|
1219
|
+
nextGasPayerJson,
|
|
1220
|
+
nextSignersJson,
|
|
1221
|
+
nextScheduleMode,
|
|
1222
|
+
nextScheduleConfigJson,
|
|
1223
|
+
nextServerResolver,
|
|
1224
|
+
nextFireAt,
|
|
1225
|
+
(opts.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
1226
|
+
id
|
|
1227
|
+
);
|
|
1228
|
+
return { changedFields, nextFireAt };
|
|
1229
|
+
}
|
|
1230
|
+
function assertNotTerminal(row) {
|
|
1231
|
+
if (row.status === "completed" || row.status === "error") {
|
|
1232
|
+
throw new TerminalCronotonError(row.status);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
function pauseCodexCronoton(id, dep) {
|
|
1236
|
+
const db = dep.db;
|
|
1237
|
+
const row = getCodexCronoton(id, { db });
|
|
1238
|
+
if (!row) throw new CodexCronotonValidationError("not found");
|
|
1239
|
+
assertNotTerminal(row);
|
|
1240
|
+
db.prepare(
|
|
1241
|
+
`UPDATE codex_cronotons SET status = 'paused', modified_at = ? WHERE id = ?`
|
|
1242
|
+
).run((/* @__PURE__ */ new Date()).toISOString(), id);
|
|
1243
|
+
return { status: "paused", nextFireAt: row.next_fire_at };
|
|
1244
|
+
}
|
|
1245
|
+
function resumeCodexCronoton(id, opts) {
|
|
1246
|
+
const db = opts.db;
|
|
1247
|
+
const row = getCodexCronoton(id, { db });
|
|
1248
|
+
if (!row) throw new CodexCronotonValidationError("not found");
|
|
1249
|
+
assertNotTerminal(row);
|
|
1250
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
1251
|
+
const rowTriggerOnly = rowExternalFireable(row) || rowRuntimeArgKeys(row).length > 0;
|
|
1252
|
+
const nextFireAt = rowTriggerOnly ? null : computeNextOrReject(
|
|
1253
|
+
row.schedule_mode,
|
|
1254
|
+
JSON.parse(row.schedule_config_json),
|
|
1255
|
+
now
|
|
1256
|
+
).toISOString();
|
|
1257
|
+
db.prepare(
|
|
1258
|
+
`UPDATE codex_cronotons SET status = 'active', next_fire_at = ?, modified_at = ? WHERE id = ?`
|
|
1259
|
+
).run(nextFireAt, now.toISOString(), id);
|
|
1260
|
+
return { status: "active", nextFireAt };
|
|
1261
|
+
}
|
|
1262
|
+
function deleteCodexCronoton(id, dep) {
|
|
1263
|
+
const db = dep.db;
|
|
1264
|
+
const countRow = db.prepare(
|
|
1265
|
+
"SELECT COUNT(*) AS c FROM codex_cronoton_fires WHERE codex_cronoton_id = ?"
|
|
1266
|
+
).get(id);
|
|
1267
|
+
const fireCountAtDelete = countRow?.c ?? 0;
|
|
1268
|
+
db.prepare("DELETE FROM codex_cronotons WHERE id = ?").run(id);
|
|
1269
|
+
return { fireCountAtDelete };
|
|
1270
|
+
}
|
|
1271
|
+
function getManualBatch(id, dep) {
|
|
1272
|
+
const row = dep.db.prepare("SELECT * FROM codex_cronoton_manual_batches WHERE id = ?").get(id);
|
|
1273
|
+
return row ?? null;
|
|
1274
|
+
}
|
|
1275
|
+
function getActiveManualBatchForCronoton(cronotonId, dep) {
|
|
1276
|
+
const row = dep.db.prepare(
|
|
1277
|
+
`SELECT * FROM codex_cronoton_manual_batches
|
|
1278
|
+
WHERE codex_cronoton_id = ? AND status = 'active'
|
|
1279
|
+
ORDER BY created_at DESC LIMIT 1`
|
|
1280
|
+
).get(cronotonId);
|
|
1281
|
+
return row ?? null;
|
|
1282
|
+
}
|
|
1283
|
+
function createManualBatch(input, opts) {
|
|
1284
|
+
const db = opts.db;
|
|
1285
|
+
const { min, max, intervalSeconds } = opts.config?.manualBatch ?? {
|
|
1286
|
+
min: MANUAL_BATCH_MIN,
|
|
1287
|
+
max: MANUAL_BATCH_MAX,
|
|
1288
|
+
intervalSeconds: MANUAL_BATCH_INTERVAL_SECONDS
|
|
1289
|
+
};
|
|
1290
|
+
const total = Math.trunc(input.total);
|
|
1291
|
+
if (!Number.isFinite(input.total) || total < min || total > max) {
|
|
1292
|
+
throw new CodexCronotonValidationError(
|
|
1293
|
+
`count must be an integer between ${min} and ${max}`
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
const cronoton = getCodexCronoton(input.cronotonId, { db });
|
|
1297
|
+
if (!cronoton) throw new CodexCronotonValidationError("not found");
|
|
1298
|
+
if (cronoton.status !== "active") {
|
|
1299
|
+
throw new CodexCronotonValidationError(
|
|
1300
|
+
`cannot batch-execute a codex cronoton with status '${cronoton.status}'`
|
|
1301
|
+
);
|
|
1302
|
+
}
|
|
1303
|
+
if (cronoton.schedule_mode === "one-time") {
|
|
1304
|
+
throw new CodexCronotonValidationError(
|
|
1305
|
+
"one-time codex cronotons cannot be batch-executed (a single fire spends them)"
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1308
|
+
if (getActiveManualBatchForCronoton(input.cronotonId, { db })) {
|
|
1309
|
+
throw new ManualBatchActiveError();
|
|
1310
|
+
}
|
|
1311
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
1312
|
+
const nowIso = now.toISOString();
|
|
1313
|
+
const id = crypto2.randomUUID();
|
|
1314
|
+
db.prepare(
|
|
1315
|
+
`INSERT INTO codex_cronoton_manual_batches
|
|
1316
|
+
(id, codex_cronoton_id, total, completed, interval_seconds, status,
|
|
1317
|
+
next_at, created_at, modified_at, created_by)
|
|
1318
|
+
VALUES (?, ?, ?, 0, ?, 'active', ?, ?, ?, ?)`
|
|
1319
|
+
).run(
|
|
1320
|
+
id,
|
|
1321
|
+
input.cronotonId,
|
|
1322
|
+
total,
|
|
1323
|
+
intervalSeconds,
|
|
1324
|
+
nowIso,
|
|
1325
|
+
nowIso,
|
|
1326
|
+
nowIso,
|
|
1327
|
+
input.createdBy
|
|
1328
|
+
);
|
|
1329
|
+
return getManualBatch(id, { db });
|
|
1330
|
+
}
|
|
1331
|
+
function cancelManualBatch(id, dep) {
|
|
1332
|
+
const result = dep.db.prepare(
|
|
1333
|
+
`UPDATE codex_cronoton_manual_batches
|
|
1334
|
+
SET status = 'cancelled', next_at = NULL, modified_at = ?
|
|
1335
|
+
WHERE id = ? AND status = 'active'`
|
|
1336
|
+
).run((/* @__PURE__ */ new Date()).toISOString(), id);
|
|
1337
|
+
return { ok: result.changes === 1 };
|
|
1338
|
+
}
|
|
1339
|
+
function canonicalize(value) {
|
|
1340
|
+
if (Array.isArray(value)) return value.map(canonicalize);
|
|
1341
|
+
if (value && typeof value === "object") {
|
|
1342
|
+
const sorted = {};
|
|
1343
|
+
for (const key of Object.keys(value).sort()) {
|
|
1344
|
+
sorted[key] = canonicalize(value[key]);
|
|
1345
|
+
}
|
|
1346
|
+
return sorted;
|
|
1347
|
+
}
|
|
1348
|
+
return value;
|
|
1349
|
+
}
|
|
1350
|
+
function parseJson2(json2, fallback) {
|
|
1351
|
+
if (json2 == null) return fallback;
|
|
1352
|
+
return JSON.parse(json2);
|
|
1353
|
+
}
|
|
1354
|
+
function computeDefinitionFingerprint(row) {
|
|
1355
|
+
const parts = {
|
|
1356
|
+
pactCode: row.pact_code,
|
|
1357
|
+
config: parseJson2(row.config_json, {}),
|
|
1358
|
+
payload: parseJson2(row.payload_json, {}),
|
|
1359
|
+
gasPayer: parseJson2(row.gas_payer_json, {}),
|
|
1360
|
+
signers: parseJson2(row.signers_json, []),
|
|
1361
|
+
scheduleMode: row.schedule_mode,
|
|
1362
|
+
scheduleConfig: parseJson2(row.schedule_config_json, {})
|
|
1363
|
+
};
|
|
1364
|
+
const canonical = JSON.stringify(canonicalize(parts));
|
|
1365
|
+
return crypto2.createHash("sha256").update(canonical).digest("hex");
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// src/server/resolvers.ts
|
|
1369
|
+
var SERVER_RESOLVERS = {};
|
|
1370
|
+
function getServerResolver(name) {
|
|
1371
|
+
return SERVER_RESOLVERS[name];
|
|
1372
|
+
}
|
|
1373
|
+
function resolveServerVars(name, dep) {
|
|
1374
|
+
const r = SERVER_RESOLVERS[name];
|
|
1375
|
+
return r && r.kind === "single-tx" ? r.resolve(dep) : null;
|
|
1376
|
+
}
|
|
1377
|
+
async function dispatchMultiTxResolver(name, opts) {
|
|
1378
|
+
const r = SERVER_RESOLVERS[name];
|
|
1379
|
+
if (!r) throw new Error(`unknown server resolver: ${name}`);
|
|
1380
|
+
if (r.kind !== "multi-tx") {
|
|
1381
|
+
throw new Error(`server resolver "${name}" is not a multi-tx resolver (kind=${r.kind})`);
|
|
1382
|
+
}
|
|
1383
|
+
return r.run(opts);
|
|
1384
|
+
}
|
|
1385
|
+
function postponed(error) {
|
|
1386
|
+
return { ok: false, mode: "fire", error, terminalIntent: null };
|
|
1387
|
+
}
|
|
1388
|
+
function adaptMultiTxSummary(summary) {
|
|
1389
|
+
const s = summary ?? {};
|
|
1390
|
+
const firstBatchKey = Array.isArray(s.batches) && s.batches.length > 0 ? s.batches[0]?.requestKey : void 0;
|
|
1391
|
+
return {
|
|
1392
|
+
ok: true,
|
|
1393
|
+
mode: "fire",
|
|
1394
|
+
requestKey: firstBatchKey,
|
|
1395
|
+
rawResult: summary,
|
|
1396
|
+
terminalIntent: null
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
function resolveExec(opts) {
|
|
1400
|
+
if (opts.exec) return opts.exec;
|
|
1401
|
+
const ctx = {
|
|
1402
|
+
runtime: opts.runtime,
|
|
1403
|
+
resolver: opts.resolver,
|
|
1404
|
+
config: opts.config
|
|
1405
|
+
};
|
|
1406
|
+
const bound = (definition, mode) => mode === "simulate" ? executeCodexTransaction(definition, "simulate", ctx) : executeCodexTransaction(definition, "fire", ctx);
|
|
1407
|
+
return bound;
|
|
1408
|
+
}
|
|
1409
|
+
async function fireByServerResolver(definition, row, opts = {}) {
|
|
1410
|
+
if (!definition.serverResolver) {
|
|
1411
|
+
const exec = resolveExec(opts);
|
|
1412
|
+
return exec(definition, "fire");
|
|
1413
|
+
}
|
|
1414
|
+
const registered = SERVER_RESOLVERS[definition.serverResolver];
|
|
1415
|
+
if (registered && registered.kind === "multi-tx") {
|
|
1416
|
+
try {
|
|
1417
|
+
const dispatchOpts = opts.deps ?? (opts.db ? { db: opts.db } : {});
|
|
1418
|
+
const summary = await dispatchMultiTxResolver(definition.serverResolver, dispatchOpts);
|
|
1419
|
+
return adaptMultiTxSummary(summary);
|
|
1420
|
+
} catch (err2) {
|
|
1421
|
+
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
1422
|
+
return postponed(`multi-tx dispatch error: ${message}`);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
return fireWithServerResolver(definition, row, opts);
|
|
1426
|
+
}
|
|
1427
|
+
async function fireWithServerResolver(definition, _row, opts = {}) {
|
|
1428
|
+
const exec = resolveExec(opts);
|
|
1429
|
+
if (!definition.serverResolver) {
|
|
1430
|
+
return exec(definition, "fire");
|
|
1431
|
+
}
|
|
1432
|
+
const registered = SERVER_RESOLVERS[definition.serverResolver];
|
|
1433
|
+
if (registered && registered.kind !== "single-tx") {
|
|
1434
|
+
return postponed(
|
|
1435
|
+
`server resolver "${definition.serverResolver}" is multi-tx \u2014 dispatch via the orchestrator, not the single-tx fire path`
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1438
|
+
const resolve = opts.resolve ?? registered?.resolve;
|
|
1439
|
+
const settle = opts.settle ?? registered?.settle;
|
|
1440
|
+
if (!resolve || !settle) {
|
|
1441
|
+
return postponed(`unknown server resolver: ${definition.serverResolver}`);
|
|
1442
|
+
}
|
|
1443
|
+
const { plan, payload } = resolve(opts.db ? { db: opts.db } : void 0);
|
|
1444
|
+
const fired = {
|
|
1445
|
+
...definition,
|
|
1446
|
+
payload: { ...definition.payload, ...payload }
|
|
1447
|
+
};
|
|
1448
|
+
const sim = await exec(fired, "simulate");
|
|
1449
|
+
if (!sim.ok) {
|
|
1450
|
+
opts.onEvent?.({ kind: "postponed", reason: "simulate failed", error: sim.error });
|
|
1451
|
+
return postponed(`postponed: simulate failed: ${sim.error ?? "unknown"}`);
|
|
1452
|
+
}
|
|
1453
|
+
const guard = opts.config?.singleTxGasGuard ?? SINGLE_TX_GAS_GUARD;
|
|
1454
|
+
const gasUsed = sim.gasUsed ?? 0;
|
|
1455
|
+
if (gasUsed > guard) {
|
|
1456
|
+
opts.onEvent?.({ kind: "postponed", reason: "gas over single-tx guard", gasUsed, guard });
|
|
1457
|
+
return postponed(
|
|
1458
|
+
`postponed: gas ${gasUsed} exceeds single-tx guard ${guard} (multi-tx split deferred)`
|
|
1459
|
+
);
|
|
1460
|
+
}
|
|
1461
|
+
const result = await exec(fired, "fire");
|
|
1462
|
+
if (result.ok) {
|
|
1463
|
+
try {
|
|
1464
|
+
settle(plan, { db: opts.db, requestKey: result.requestKey });
|
|
1465
|
+
opts.onEvent?.({ kind: "settled", count: plan.length, requestKey: result.requestKey });
|
|
1466
|
+
} catch (err2) {
|
|
1467
|
+
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
1468
|
+
opts.onEvent?.({
|
|
1469
|
+
kind: "settlement-needs-attention",
|
|
1470
|
+
error: message,
|
|
1471
|
+
requestKey: result.requestKey
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
return result;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
// src/handlers/http.ts
|
|
1479
|
+
function json(status, body) {
|
|
1480
|
+
return { status, body };
|
|
1481
|
+
}
|
|
1482
|
+
function errorBody(status, message) {
|
|
1483
|
+
return { error: message ?? `HTTP ${status}` };
|
|
1484
|
+
}
|
|
1485
|
+
function err(status, message) {
|
|
1486
|
+
return json(status, errorBody(status, message));
|
|
1487
|
+
}
|
|
1488
|
+
function mapStoreError(error) {
|
|
1489
|
+
if (error instanceof ManualBatchActiveError) {
|
|
1490
|
+
return json(409, errorBody(409, error.message));
|
|
1491
|
+
}
|
|
1492
|
+
if (error instanceof TerminalCronotonError) {
|
|
1493
|
+
return json(409, errorBody(409, error.message));
|
|
1494
|
+
}
|
|
1495
|
+
if (error instanceof CodexCronotonValidationError) {
|
|
1496
|
+
const status = /not found/i.test(error.message) ? 404 : 400;
|
|
1497
|
+
return json(status, errorBody(status, error.message));
|
|
1498
|
+
}
|
|
1499
|
+
const message = error instanceof Error ? error.message : void 0;
|
|
1500
|
+
return json(500, errorBody(500, message));
|
|
1501
|
+
}
|
|
1502
|
+
function defaultSignerSource(resolver) {
|
|
1503
|
+
return {
|
|
1504
|
+
async listSignerDescriptors() {
|
|
1505
|
+
const pubs = await resolver.listCodexPubs();
|
|
1506
|
+
return [...pubs].map((publicKey) => ({ publicKey, display: "foreign" }));
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// src/handlers/context.ts
|
|
1512
|
+
var NeedsConfirmError = class extends Error {
|
|
1513
|
+
constructor(message = "admin_confirm_required") {
|
|
1514
|
+
super(message);
|
|
1515
|
+
this.code = "admin_confirm_required";
|
|
1516
|
+
this.name = "NeedsConfirmError";
|
|
1517
|
+
}
|
|
1518
|
+
};
|
|
1519
|
+
var defaultOpenAuth = {
|
|
1520
|
+
requireRead() {
|
|
1521
|
+
return { ok: true, identity: {} };
|
|
1522
|
+
},
|
|
1523
|
+
requireConfirm(req) {
|
|
1524
|
+
if (req.confirmed === true) {
|
|
1525
|
+
return { ok: true, identity: {} };
|
|
1526
|
+
}
|
|
1527
|
+
return { ok: false, response: json(401, { error: "admin_confirm_required" }) };
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
async function runGated(gate, fn) {
|
|
1531
|
+
if (!gate.ok) {
|
|
1532
|
+
return gate.response;
|
|
1533
|
+
}
|
|
1534
|
+
try {
|
|
1535
|
+
return await fn(gate.identity);
|
|
1536
|
+
} catch (error) {
|
|
1537
|
+
if (error instanceof NeedsConfirmError) {
|
|
1538
|
+
return json(401, { error: error.code });
|
|
1539
|
+
}
|
|
1540
|
+
return mapStoreError(error);
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
async function withRead(ctx, req, fn) {
|
|
1544
|
+
return runGated(await ctx.auth.requireRead(req), fn);
|
|
1545
|
+
}
|
|
1546
|
+
async function withConfirm(ctx, req, fn) {
|
|
1547
|
+
return runGated(await ctx.auth.requireConfirm(req), fn);
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
// src/provider/adapter.ts
|
|
1551
|
+
var REQUIRED_METHODS = [
|
|
1552
|
+
"list",
|
|
1553
|
+
"get",
|
|
1554
|
+
"fires",
|
|
1555
|
+
"signers",
|
|
1556
|
+
"commit",
|
|
1557
|
+
"edit",
|
|
1558
|
+
"pause",
|
|
1559
|
+
"resume",
|
|
1560
|
+
"delete",
|
|
1561
|
+
"simulate",
|
|
1562
|
+
"executeNow",
|
|
1563
|
+
"trigger",
|
|
1564
|
+
"startBatch",
|
|
1565
|
+
"getBatch",
|
|
1566
|
+
"cancelBatch",
|
|
1567
|
+
"recover"
|
|
1568
|
+
];
|
|
1569
|
+
function assertAdapter(x) {
|
|
1570
|
+
if (!x || typeof x !== "object") {
|
|
1571
|
+
throw new TypeError(
|
|
1572
|
+
`KhronotonAdapter must be an object, received ${x === null ? "null" : typeof x}`
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
const candidate = x;
|
|
1576
|
+
for (const method of REQUIRED_METHODS) {
|
|
1577
|
+
if (typeof candidate[method] !== "function") {
|
|
1578
|
+
throw new TypeError(`KhronotonAdapter is missing method "${method}"`);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
function emptySnapshot() {
|
|
1583
|
+
return { cronotons: [] };
|
|
1584
|
+
}
|
|
1585
|
+
var DEFAULT_EXPLORER_BASE = "https://explorer.stoachain.com/transactions";
|
|
1586
|
+
var DEFAULT_PAGE_SIZE = 50;
|
|
1587
|
+
var DEFAULT_POLL_CADENCE_MS = 5e3;
|
|
1588
|
+
function resolveConfig(props) {
|
|
1589
|
+
return {
|
|
1590
|
+
explorerBase: props.explorerBase ?? DEFAULT_EXPLORER_BASE,
|
|
1591
|
+
showMode: props.showMode ?? true,
|
|
1592
|
+
renderMultiTx: props.renderMultiTx,
|
|
1593
|
+
serverResolverOptions: props.serverResolverOptions ?? [],
|
|
1594
|
+
pageSize: props.pageSize ?? DEFAULT_PAGE_SIZE,
|
|
1595
|
+
pollCadenceMs: props.pollCadenceMs ?? DEFAULT_POLL_CADENCE_MS,
|
|
1596
|
+
onNeedConfirm: props.onNeedConfirm
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
var KhronotonStaticContext = createContext(null);
|
|
1600
|
+
var KhronotonStatusContext = createContext(null);
|
|
1601
|
+
function useStatic(caller) {
|
|
1602
|
+
const value = useContext(KhronotonStaticContext);
|
|
1603
|
+
if (value === null) {
|
|
1604
|
+
throw new Error(`${caller} must be used within a <KhronotonProvider>`);
|
|
1605
|
+
}
|
|
1606
|
+
return value;
|
|
1607
|
+
}
|
|
1608
|
+
function useKhronotonAdapter() {
|
|
1609
|
+
return useStatic("useKhronotonAdapter").adapter;
|
|
1610
|
+
}
|
|
1611
|
+
function useKhronotonConfig() {
|
|
1612
|
+
return useStatic("useKhronotonConfig").config;
|
|
1613
|
+
}
|
|
1614
|
+
function useKhronoton() {
|
|
1615
|
+
const { adapter, config } = useStatic("useKhronoton");
|
|
1616
|
+
const status = useContext(KhronotonStatusContext);
|
|
1617
|
+
if (status === null) {
|
|
1618
|
+
throw new Error("useKhronoton must be used within a <KhronotonProvider>");
|
|
1619
|
+
}
|
|
1620
|
+
return { ready: status.ready, error: status.error, adapter, config };
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
// src/provider/runGated.ts
|
|
1624
|
+
async function runGated2(fn, options = {}) {
|
|
1625
|
+
const { onNeedConfirm } = options;
|
|
1626
|
+
try {
|
|
1627
|
+
return await fn({ confirmed: true });
|
|
1628
|
+
} catch (err2) {
|
|
1629
|
+
if (err2 instanceof NeedsConfirmError && onNeedConfirm) {
|
|
1630
|
+
const reconfirmed = await onNeedConfirm();
|
|
1631
|
+
if (reconfirmed) {
|
|
1632
|
+
return await fn({ confirmed: true });
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
throw err2;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
export { CodexCronotonValidationError, DEFAULT_EXPLORER_BASE, DEFAULT_PAGE_SIZE, DEFAULT_POLL_CADENCE_MS, InvalidScheduleConfigError, KhronotonStaticContext, KhronotonStatusContext, NeedsConfirmError, applyRuntimeArgs, applyTerminalIntent, assertAdapter, cancelManualBatch, commitCodexCronoton, computeDefinitionFingerprint, computeNextFire, createManualBatch, defaultOpenAuth, defaultSignerSource, deleteCodexCronoton, editCodexCronoton, emptySnapshot, err, executeCodexTransaction, fireByServerResolver, getActiveManualBatchForCronoton, getCodexCronoton, getServerResolver, installSchema, json, listCodexCronotons, listFires, manualBatchView, parseRuntimeArgKeys, pauseCodexCronoton, recordFire, recoverFire, resolveConfig, resolveServerVars, resumeCodexCronoton, rowRuntimeArgKeys, rowToDefinition, runGated2 as runGated, summariseSchedule, useKhronoton, useKhronotonAdapter, useKhronotonConfig, validateRuntimeArgs, withConfirm, withRead };
|