@ancientpantheon/khronoton-core 0.6.1 → 0.7.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 +18 -0
- package/README.md +4 -0
- package/dist/blockchain/stoachain.d.ts +1 -1
- package/dist/{chunk-J7P2NCO4.js → chunk-OGKXCOCK.js} +37 -2
- package/dist/{chunk-5SUNXUSH.js → chunk-WLZXX2SQ.js} +149 -117
- package/dist/{context-D7LCfXdC.d.ts → context--Qofoc6Z.d.ts} +91 -1
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +2 -2
- package/dist/handlers/read.d.ts +6 -0
- package/dist/handlers/read.js +9 -1
- package/dist/hooks/index.d.ts +13 -3
- package/dist/hooks/index.js +2 -2
- package/dist/provider/index.d.ts +3 -3
- package/dist/provider/index.js +11 -2
- package/dist/{seams-BvPnTSmg.d.ts → seams-DapFZ4sM.d.ts} +11 -1
- package/dist/server/resolvers.d.ts +26 -0
- package/dist/server/resolvers.js +12 -0
- package/dist/server/store/cronoton.js +54 -15
- package/dist/ui/index.js +8 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,24 @@ All notable changes to `@ancientpantheon/khronoton-core`.
|
|
|
4
4
|
|
|
5
5
|
The engine's pre-extraction history lives in the AncientHoldings hub, whose inline scheduler ("Cronoton") this package extracts and generalises.
|
|
6
6
|
|
|
7
|
+
## 0.7.0 — 2026-08-03
|
|
8
|
+
|
|
9
|
+
**MINOR — server-authoritative evented resolvers: scheduleless + external-fireable enforced in the store, `GET /resolvers`, one-resolver-one-cronoton.**
|
|
10
|
+
|
|
11
|
+
0.6.0 shipped event-driven resolvers behind a **client-side** `eventDriven` flag — the guarantee lived in each consumer's proxy, not the package. 0.7.0 makes the **resolver registry** the source of truth and enforces the scheduleless contract in the **store**, so it holds for every consumer regardless of what the client sends.
|
|
12
|
+
|
|
13
|
+
- **`evented` on the resolver registry.** `SingleTxResolver` and `MultiTxResolver` gain an optional `evented?: boolean`. `createCodexCronoton`/`editCodexCronoton` derive it via `getServerResolver(name)?.evented` (a safe, acyclic store→resolvers import) and force the persisted row **scheduleless** (`next_fire_at = NULL`, excluded from `fetchDueCodexCronotons`) **and `external_fireable = 1`** — even when the caller sends a real schedule. An evented→non-evented edit correctly re-arms `next_fire_at` from the stored schedule and clears `external_fireable`; a genuine (non-evented) external-fireable row is never clobbered.
|
|
14
|
+
- **`GET /resolvers`.** New `listServerResolvers()` + `resolversHandler` return `{ ok: true, resolvers: [{ name, kind, evented }] }` listing every registered resolver with its flag. Exposed as a new **OPTIONAL** `resolvers()` method on the `KhronotonAdapter` read tier (implemented by both reference adapters) — deliberately **not** added to `REQUIRED_METHODS`, so pre-0.7.0 adapters still pass `assertAdapter` and the Builder degrades gracefully (falls back to the 0.6.0 `serverResolverOptions.eventDriven`) via the new `useServerResolvers` hook.
|
|
15
|
+
- **Builder is server-authoritative.** `eventDrivenResolver` is now `registry.evented(name) || serverResolverOptions.eventDriven` — a resolver the server marks evented hides the schedule editor, shows the event-driven notice, and commits `externalFireable: true` (derived at commit time, so switching to a non-evented resolver never leaves the flag stuck on).
|
|
16
|
+
- **List shows "Evented".** `CronotonList`'s next-fire cell reads **"Evented"** for a trigger-only row (`external_fireable === 1` or runtime-arg keys) instead of a blank/timestamp.
|
|
17
|
+
- **One resolver, one cronoton.** `createCodexCronoton` rejects a second commit reusing an already-bound `server_resolver` with `CodexCronotonValidationError` naming the existing cronoton id (→ HTTP 400).
|
|
18
|
+
|
|
19
|
+
**Note — deliberate HMAC-exposure reversal.** An evented resolver now forces `external_fireable = 1`, which makes the row HMAC-fireable. This reverses 0.6.0's "don't reuse `externalFireable`" stance and is a conscious choice: it **codifies Pythia's already-shipped production behavior** (v2.7.19/2.7.20 already force this) rather than introducing new exposure, and gives one persisted signal that the store, Builder, and list all read consistently. Manually HMAC-firing an evented resolver just re-runs its idempotent resolve, which no-ops when nothing is ready.
|
|
20
|
+
|
|
21
|
+
The published 0.6.0 `eventDriven` surface (`ServerResolverOption.eventDriven`, `CommitEnvelope.eventDriven`, the store input/patch fields, `builderToCommit` opts) is kept intact as an additive fallback; no breaking removals. Ordinary scheduled resolvers are unchanged.
|
|
22
|
+
|
|
23
|
+
**871 specs pass.**
|
|
24
|
+
|
|
7
25
|
## 0.6.1 — 2026-08-02
|
|
8
26
|
|
|
9
27
|
**PATCH — fix a CronotonList crash (white-screen) on any non-empty list.**
|
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ Khronoton is the "When do I act?" Constructor of the Pantheon architecture — t
|
|
|
6
6
|
|
|
7
7
|
## Status
|
|
8
8
|
|
|
9
|
+
**`0.7.0` on public npmjs** — **MINOR.** Released 2026-08-03. Makes event-driven resolvers **server-authoritative**: `SingleTxResolver`/`MultiTxResolver` gain an `evented?` flag, and the **store** forces an evented resolver's cronoton scheduleless (`next_fire_at = NULL`, excluded from the due-query) **and `external_fireable = 1`** even when a schedule is sent — the guarantee no longer depends on the consumer. Adds `GET /resolvers` (+ an OPTIONAL `resolvers()` adapter method and `useServerResolvers` hook) so the Builder learns which resolvers are evented; the list shows **"Evented"** as the next-fire for a trigger-only row; and the store enforces **one resolver ↔ one cronoton** (a second bind is rejected). Deliberately reverses 0.6.0's HMAC stance — an evented row is now HMAC-fireable — codifying Pythia's shipped behavior (see version history). **871 specs pass.**
|
|
10
|
+
|
|
9
11
|
**`0.6.1` on public npmjs** — **PATCH.** Released 2026-08-02. Fixes a crash that white-screened the Khronoton admin list whenever it held ≥1 cronoton: `listCodexCronotons` returned a camelCase 9-field projection while `CronotonList` renders full snake_case rows, so `pact_code` was `undefined` and crashed `pactPreview`. The list now returns full `CodexCronotonRow`s (`SELECT *`, like `getCodexCronoton`) and `pactPreview` guards a missing `pact_code`. **850 specs pass.**
|
|
10
12
|
|
|
11
13
|
**`0.6.0` on public npmjs** — **MINOR.** Released 2026-08-02. Server resolvers can now declare themselves **event-driven** (`ServerResolverOption.eventDriven`): selecting one in the Builder commits the cronoton scheduler-off (`next_fire_at = NULL`, never auto-fired) and swaps the schedule editor for an event-driven notice — the host fires it in-process via the existing `executeNow` (not the HMAC endpoint). Ordinary scheduled resolvers are unchanged. **848 specs pass.**
|
|
@@ -238,6 +240,8 @@ npm install @ancientpantheon/khronoton-core
|
|
|
238
240
|
|
|
239
241
|
## Version history
|
|
240
242
|
|
|
243
|
+
**v0.7.0** — Server-authoritative evented resolvers. `SingleTxResolver`/`MultiTxResolver` gain an optional `evented?` flag; the **store** (`createCodexCronoton`/`editCodexCronoton`, via an acyclic `getServerResolver` lookup) forces an evented resolver's cronoton `next_fire_at = NULL` **and `external_fireable = 1`** even when a real schedule is committed, so the scheduleless guarantee lives in the package rather than each consumer's proxy (`fetchDueCodexCronotons` skips it; an evented→non-evented edit re-arms `next_fire_at` and clears `external_fireable`; a genuine non-evented external-fireable row is never clobbered). A new `GET /resolvers` handler + `listServerResolvers()` expose `{ name, kind, evented }`; the `KhronotonAdapter` read tier gains an **OPTIONAL** `resolvers()` method (both reference adapters implement it, but it is **not** in `REQUIRED_METHODS`, so older adapters still pass `assertAdapter`), consumed by the new `useServerResolvers` hook. The Builder makes `eventDrivenResolver` server-authoritative (registry `evented` OR the 0.6.0 `serverResolverOptions.eventDriven` fallback), commits `externalFireable: true` for an evented resolver (derived at commit time — never stuck when switching away), and the `CronotonList` next-fire cell reads **"Evented"** for a trigger-only row (`external_fireable === 1` or runtime-arg keys). The store also enforces **one resolver ↔ one cronoton** — a second `createCodexCronoton` reusing a bound `server_resolver` throws `CodexCronotonValidationError` naming the existing id (→ 400). **Deliberate reversal of 0.6.0's HMAC stance:** an evented row is now `external_fireable = 1` and thus HMAC-fireable — a conscious choice codifying Pythia's already-shipped production behavior (v2.7.19/2.7.20), giving one persisted signal the store, Builder, and list all read; manually firing an evented resolver just re-runs its idempotent resolve (no-ops when nothing is ready). The published 0.6.0 `eventDriven` surface is kept intact as an additive fallback; ordinary scheduled resolvers are unchanged. Released 2026-08-03. **871 specs pass.**
|
|
244
|
+
|
|
241
245
|
**v0.6.1** — Fix a CronotonList white-screen crash on any non-empty list. `listCodexCronotons` returned a camelCase 9-field projection while the read handler declares `CodexCronotonRow[]` and `CronotonList` renders full snake_case fields — so `pact_code`/`schedule_mode`/`schedule_config_json`/`next_fire_at`/`last_fire_at`/`runtime_arg_keys`/`description`/`server_resolver` were all `undefined` and `pactPreview(row.pact_code).replace(...)` crashed. The list now returns full `CodexCronotonRow`s via `SELECT *` (matching the declared type and what the UI reads), and `pactPreview` guards a missing/non-string `pact_code` → `"(empty)"`. `CodexCronotonListItem` is now a deprecated alias of `CodexCronotonRow`. Released 2026-08-02. **850 specs pass.**
|
|
242
246
|
|
|
243
247
|
**v0.6.0** — Event-driven server resolvers. `ServerResolverOption` gains an optional `eventDriven` flag; a cronoton on an event-driven resolver commits scheduler-off (`next_fire_at = NULL`, excluded from the tick due-query) and the Builder shows an "Event-driven (host-fired)" notice instead of a schedule editor. The host fires it via the existing `executeNow` primitive, in-process — event-driven is a dedicated commit-envelope flag, deliberately NOT `externalFireable`, so it never exposes the public HMAC trigger endpoint. `server_resolver` + event-driven is allowed; `server_resolver` + `runtime_arg_keys` stays forbidden. No new DB column (the `next_fire_at = NULL` state carries it; edit and pause/resume keep it NULL). Ordinary scheduled resolvers unchanged; a non-event-driven commit body is byte-identical to 0.5.0. Released 2026-08-02. **848 specs pass.**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useKhronotonAdapter, useKhronotonConfig, runGated } from './chunk-
|
|
1
|
+
import { useKhronotonAdapter, useKhronotonConfig, runGated } from './chunk-WLZXX2SQ.js';
|
|
2
2
|
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
3
3
|
|
|
4
4
|
function useCronotons(query) {
|
|
@@ -203,6 +203,41 @@ function useManualBatch(id) {
|
|
|
203
203
|
}, [active, adapter, id, config.pollCadenceMs]);
|
|
204
204
|
return { batch, active, loading, error, refetch };
|
|
205
205
|
}
|
|
206
|
+
function useServerResolvers() {
|
|
207
|
+
const adapter = useKhronotonAdapter();
|
|
208
|
+
const [resolvers, setResolvers] = useState([]);
|
|
209
|
+
const [loading, setLoading] = useState(true);
|
|
210
|
+
const [error, setError] = useState(null);
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
const fetchResolvers = adapter.resolvers;
|
|
213
|
+
if (typeof fetchResolvers !== "function") {
|
|
214
|
+
setResolvers([]);
|
|
215
|
+
setError(null);
|
|
216
|
+
setLoading(false);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
let active = true;
|
|
220
|
+
setLoading(true);
|
|
221
|
+
setError(null);
|
|
222
|
+
void (async () => {
|
|
223
|
+
try {
|
|
224
|
+
const view = await fetchResolvers();
|
|
225
|
+
if (!active) return;
|
|
226
|
+
setResolvers(view.ok ? view.resolvers : []);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
if (!active) return;
|
|
229
|
+
setResolvers([]);
|
|
230
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
231
|
+
} finally {
|
|
232
|
+
if (active) setLoading(false);
|
|
233
|
+
}
|
|
234
|
+
})();
|
|
235
|
+
return () => {
|
|
236
|
+
active = false;
|
|
237
|
+
};
|
|
238
|
+
}, [adapter]);
|
|
239
|
+
return { resolvers, loading, error };
|
|
240
|
+
}
|
|
206
241
|
function useGatedAction(makeCall, onNeedConfirm, onSuccess) {
|
|
207
242
|
const [pending, setPending] = useState(false);
|
|
208
243
|
const [error, setError] = useState(null);
|
|
@@ -376,4 +411,4 @@ function useRecoverFire() {
|
|
|
376
411
|
);
|
|
377
412
|
}
|
|
378
413
|
|
|
379
|
-
export { useCancelBatch, useCronoton, useCronotonActions, useCronotonFires, useCronotons, useExecuteNow, useManualBatch, useRecoverFire, useSimulate, useStartBatch, useTrigger };
|
|
414
|
+
export { useCancelBatch, useCronoton, useCronotonActions, useCronotonFires, useCronotons, useExecuteNow, useManualBatch, useRecoverFire, useServerResolvers, useSimulate, useStartBatch, useTrigger };
|
|
@@ -1023,6 +1023,121 @@ function recoverFire(fireId, requestKey, dep) {
|
|
|
1023
1023
|
).run(requestKey, (/* @__PURE__ */ new Date()).toISOString(), fireId);
|
|
1024
1024
|
return res.changes > 0;
|
|
1025
1025
|
}
|
|
1026
|
+
|
|
1027
|
+
// src/server/resolvers.ts
|
|
1028
|
+
var SERVER_RESOLVERS = {};
|
|
1029
|
+
function getServerResolver(name) {
|
|
1030
|
+
return SERVER_RESOLVERS[name];
|
|
1031
|
+
}
|
|
1032
|
+
function listServerResolvers() {
|
|
1033
|
+
return Object.entries(SERVER_RESOLVERS).map(([name, r]) => ({ name, kind: r.kind, evented: r.evented === true })).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1034
|
+
}
|
|
1035
|
+
function resolveServerVars(name, dep) {
|
|
1036
|
+
const r = SERVER_RESOLVERS[name];
|
|
1037
|
+
return r && r.kind === "single-tx" ? r.resolve(dep) : null;
|
|
1038
|
+
}
|
|
1039
|
+
async function dispatchMultiTxResolver(name, opts) {
|
|
1040
|
+
const r = SERVER_RESOLVERS[name];
|
|
1041
|
+
if (!r) throw new Error(`unknown server resolver: ${name}`);
|
|
1042
|
+
if (r.kind !== "multi-tx") {
|
|
1043
|
+
throw new Error(`server resolver "${name}" is not a multi-tx resolver (kind=${r.kind})`);
|
|
1044
|
+
}
|
|
1045
|
+
return r.run(opts);
|
|
1046
|
+
}
|
|
1047
|
+
function postponed(error) {
|
|
1048
|
+
return { ok: false, mode: "fire", error, terminalIntent: null };
|
|
1049
|
+
}
|
|
1050
|
+
function adaptMultiTxSummary(summary) {
|
|
1051
|
+
const s = summary ?? {};
|
|
1052
|
+
const firstBatchKey = Array.isArray(s.batches) && s.batches.length > 0 ? s.batches[0]?.requestKey : void 0;
|
|
1053
|
+
return {
|
|
1054
|
+
ok: true,
|
|
1055
|
+
mode: "fire",
|
|
1056
|
+
requestKey: firstBatchKey,
|
|
1057
|
+
rawResult: summary,
|
|
1058
|
+
terminalIntent: null
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
function resolveExec(opts) {
|
|
1062
|
+
if (opts.exec) return opts.exec;
|
|
1063
|
+
const ctx = {
|
|
1064
|
+
runtime: opts.runtime,
|
|
1065
|
+
resolver: opts.resolver,
|
|
1066
|
+
config: opts.config
|
|
1067
|
+
};
|
|
1068
|
+
const bound = (definition, mode) => mode === "simulate" ? executeCodexTransaction(definition, "simulate", ctx) : executeCodexTransaction(definition, "fire", ctx);
|
|
1069
|
+
return bound;
|
|
1070
|
+
}
|
|
1071
|
+
async function fireByServerResolver(definition, row, opts = {}) {
|
|
1072
|
+
if (!definition.serverResolver) {
|
|
1073
|
+
const exec = resolveExec(opts);
|
|
1074
|
+
return exec(definition, "fire");
|
|
1075
|
+
}
|
|
1076
|
+
const registered = SERVER_RESOLVERS[definition.serverResolver];
|
|
1077
|
+
if (registered && registered.kind === "multi-tx") {
|
|
1078
|
+
try {
|
|
1079
|
+
const dispatchOpts = opts.deps ?? (opts.db ? { db: opts.db } : {});
|
|
1080
|
+
const summary = await dispatchMultiTxResolver(definition.serverResolver, dispatchOpts);
|
|
1081
|
+
return adaptMultiTxSummary(summary);
|
|
1082
|
+
} catch (err2) {
|
|
1083
|
+
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
1084
|
+
return postponed(`multi-tx dispatch error: ${message}`);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
return fireWithServerResolver(definition, row, opts);
|
|
1088
|
+
}
|
|
1089
|
+
async function fireWithServerResolver(definition, _row, opts = {}) {
|
|
1090
|
+
const exec = resolveExec(opts);
|
|
1091
|
+
if (!definition.serverResolver) {
|
|
1092
|
+
return exec(definition, "fire");
|
|
1093
|
+
}
|
|
1094
|
+
const registered = SERVER_RESOLVERS[definition.serverResolver];
|
|
1095
|
+
if (registered && registered.kind !== "single-tx") {
|
|
1096
|
+
return postponed(
|
|
1097
|
+
`server resolver "${definition.serverResolver}" is multi-tx \u2014 dispatch via the orchestrator, not the single-tx fire path`
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
const resolve = opts.resolve ?? registered?.resolve;
|
|
1101
|
+
const settle = opts.settle ?? registered?.settle;
|
|
1102
|
+
if (!resolve || !settle) {
|
|
1103
|
+
return postponed(`unknown server resolver: ${definition.serverResolver}`);
|
|
1104
|
+
}
|
|
1105
|
+
const { plan, payload } = resolve(opts.db ? { db: opts.db } : void 0);
|
|
1106
|
+
const fired = {
|
|
1107
|
+
...definition,
|
|
1108
|
+
payload: { ...definition.payload, ...payload }
|
|
1109
|
+
};
|
|
1110
|
+
const sim = await exec(fired, "simulate");
|
|
1111
|
+
if (!sim.ok) {
|
|
1112
|
+
opts.onEvent?.({ kind: "postponed", reason: "simulate failed", error: sim.error });
|
|
1113
|
+
return postponed(`postponed: simulate failed: ${sim.error ?? "unknown"}`);
|
|
1114
|
+
}
|
|
1115
|
+
const guard = opts.config?.singleTxGasGuard ?? SINGLE_TX_GAS_GUARD;
|
|
1116
|
+
const gasUsed = sim.gasUsed ?? 0;
|
|
1117
|
+
if (gasUsed > guard) {
|
|
1118
|
+
opts.onEvent?.({ kind: "postponed", reason: "gas over single-tx guard", gasUsed, guard });
|
|
1119
|
+
return postponed(
|
|
1120
|
+
`postponed: gas ${gasUsed} exceeds single-tx guard ${guard} (multi-tx split deferred)`
|
|
1121
|
+
);
|
|
1122
|
+
}
|
|
1123
|
+
const result = await exec(fired, "fire");
|
|
1124
|
+
if (result.ok) {
|
|
1125
|
+
try {
|
|
1126
|
+
settle(plan, { db: opts.db, requestKey: result.requestKey });
|
|
1127
|
+
opts.onEvent?.({ kind: "settled", count: plan.length, requestKey: result.requestKey });
|
|
1128
|
+
} catch (err2) {
|
|
1129
|
+
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
1130
|
+
opts.onEvent?.({
|
|
1131
|
+
kind: "settlement-needs-attention",
|
|
1132
|
+
error: message,
|
|
1133
|
+
requestKey: result.requestKey
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return result;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
// src/server/store/cronoton.ts
|
|
1026
1141
|
function computeNextOrReject(mode, config, now) {
|
|
1027
1142
|
let next;
|
|
1028
1143
|
try {
|
|
@@ -1066,8 +1181,20 @@ function commitCodexCronoton(input, opts) {
|
|
|
1066
1181
|
"server-resolver rows cannot declare runtime args"
|
|
1067
1182
|
);
|
|
1068
1183
|
}
|
|
1184
|
+
if (input.serverResolver) {
|
|
1185
|
+
const existing = findCodexCronotonIdByServerResolver(input.serverResolver, {
|
|
1186
|
+
db: opts.db
|
|
1187
|
+
});
|
|
1188
|
+
if (existing) {
|
|
1189
|
+
throw new CodexCronotonValidationError(
|
|
1190
|
+
`server resolver "${input.serverResolver}" is already bound to cronoton ${existing} \u2014 delete it first`
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1069
1194
|
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
1070
|
-
const
|
|
1195
|
+
const evented = getServerResolver(input.serverResolver ?? "")?.evented === true;
|
|
1196
|
+
const externalFireable = input.externalFireable === true || evented;
|
|
1197
|
+
const triggerOnly = externalFireable || runtimeArgKeys.length > 0 || input.eventDriven === true;
|
|
1071
1198
|
const nextFireAt = triggerOnly ? null : computeNextOrReject(input.scheduleMode, input.scheduleConfig, now).toISOString();
|
|
1072
1199
|
const id = crypto2.randomUUID();
|
|
1073
1200
|
const nowIso = now.toISOString();
|
|
@@ -1090,7 +1217,7 @@ function commitCodexCronoton(input, opts) {
|
|
|
1090
1217
|
input.scheduleMode,
|
|
1091
1218
|
JSON.stringify(input.scheduleConfig),
|
|
1092
1219
|
input.serverResolver ?? null,
|
|
1093
|
-
|
|
1220
|
+
externalFireable ? 1 : 0,
|
|
1094
1221
|
runtimeArgKeys.length > 0 ? JSON.stringify(runtimeArgKeys) : null,
|
|
1095
1222
|
nextFireAt,
|
|
1096
1223
|
nowIso,
|
|
@@ -1103,6 +1230,13 @@ function getCodexCronoton(id, dep) {
|
|
|
1103
1230
|
const row = dep.db.prepare("SELECT * FROM codex_cronotons WHERE id = ?").get(id);
|
|
1104
1231
|
return row ?? null;
|
|
1105
1232
|
}
|
|
1233
|
+
function findCodexCronotonIdByServerResolver(serverResolver, dep) {
|
|
1234
|
+
const row = dep.db.prepare(
|
|
1235
|
+
`SELECT id FROM codex_cronotons WHERE server_resolver = ?
|
|
1236
|
+
ORDER BY created_at DESC LIMIT 1`
|
|
1237
|
+
).get(serverResolver);
|
|
1238
|
+
return row?.id ?? null;
|
|
1239
|
+
}
|
|
1106
1240
|
function listCodexCronotons(params, dep) {
|
|
1107
1241
|
const limit = Math.min(Math.max(params.limit ?? 50, 1), 200);
|
|
1108
1242
|
const offset = Math.max(params.offset ?? 0, 0);
|
|
@@ -1176,29 +1310,36 @@ function editCodexCronoton(id, patch, opts) {
|
|
|
1176
1310
|
scheduleChanged = true;
|
|
1177
1311
|
changedFields.push("schedule");
|
|
1178
1312
|
}
|
|
1179
|
-
const
|
|
1180
|
-
|
|
1313
|
+
const resolverName = patch.serverResolver !== void 0 ? patch.serverResolver : row.server_resolver;
|
|
1314
|
+
const evented = getServerResolver(resolverName ?? "")?.evented === true;
|
|
1315
|
+
const prevEvented = getServerResolver(row.server_resolver ?? "")?.evented === true;
|
|
1316
|
+
const genuineExternalFireable = Boolean(rowExternalFireable(row)) && !prevEvented;
|
|
1317
|
+
const rowSchedulerOff = evented || rowRuntimeArgKeys(row).length > 0 || genuineExternalFireable;
|
|
1318
|
+
const eventedDeparted = prevEvented && !evented;
|
|
1319
|
+
if (patch.eventDriven === true || evented) {
|
|
1181
1320
|
if (nextFireAt !== null && !changedFields.includes("schedule")) {
|
|
1182
1321
|
changedFields.push("schedule");
|
|
1183
1322
|
}
|
|
1184
1323
|
nextFireAt = null;
|
|
1185
|
-
} else if (scheduleChanged && !
|
|
1324
|
+
} else if ((scheduleChanged || eventedDeparted) && !rowSchedulerOff) {
|
|
1186
1325
|
const next = computeNextOrReject(
|
|
1187
1326
|
nextScheduleMode,
|
|
1188
1327
|
JSON.parse(nextScheduleConfigJson),
|
|
1189
1328
|
opts.now ?? /* @__PURE__ */ new Date()
|
|
1190
1329
|
);
|
|
1191
1330
|
nextFireAt = next.toISOString();
|
|
1331
|
+
if (!changedFields.includes("schedule")) changedFields.push("schedule");
|
|
1192
1332
|
}
|
|
1193
1333
|
if (changedFields.length === 0) {
|
|
1194
1334
|
return { changedFields, nextFireAt };
|
|
1195
1335
|
}
|
|
1336
|
+
const nextExternalFireable = evented ? 1 : genuineExternalFireable ? 1 : 0;
|
|
1196
1337
|
db.prepare(
|
|
1197
1338
|
`UPDATE codex_cronotons
|
|
1198
1339
|
SET name = ?, description = ?, pact_code = ?, config_json = ?,
|
|
1199
1340
|
payload_json = ?, gas_payer_json = ?, signers_json = ?,
|
|
1200
1341
|
schedule_mode = ?, schedule_config_json = ?, server_resolver = ?,
|
|
1201
|
-
next_fire_at = ?, modified_at = ?
|
|
1342
|
+
external_fireable = ?, next_fire_at = ?, modified_at = ?
|
|
1202
1343
|
WHERE id = ?`
|
|
1203
1344
|
).run(
|
|
1204
1345
|
nextName,
|
|
@@ -1211,6 +1352,7 @@ function editCodexCronoton(id, patch, opts) {
|
|
|
1211
1352
|
nextScheduleMode,
|
|
1212
1353
|
nextScheduleConfigJson,
|
|
1213
1354
|
nextServerResolver,
|
|
1355
|
+
nextExternalFireable,
|
|
1214
1356
|
nextFireAt,
|
|
1215
1357
|
(opts.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
1216
1358
|
id
|
|
@@ -1355,116 +1497,6 @@ function computeDefinitionFingerprint(row) {
|
|
|
1355
1497
|
return crypto2.createHash("sha256").update(canonical).digest("hex");
|
|
1356
1498
|
}
|
|
1357
1499
|
|
|
1358
|
-
// src/server/resolvers.ts
|
|
1359
|
-
var SERVER_RESOLVERS = {};
|
|
1360
|
-
function getServerResolver(name) {
|
|
1361
|
-
return SERVER_RESOLVERS[name];
|
|
1362
|
-
}
|
|
1363
|
-
function resolveServerVars(name, dep) {
|
|
1364
|
-
const r = SERVER_RESOLVERS[name];
|
|
1365
|
-
return r && r.kind === "single-tx" ? r.resolve(dep) : null;
|
|
1366
|
-
}
|
|
1367
|
-
async function dispatchMultiTxResolver(name, opts) {
|
|
1368
|
-
const r = SERVER_RESOLVERS[name];
|
|
1369
|
-
if (!r) throw new Error(`unknown server resolver: ${name}`);
|
|
1370
|
-
if (r.kind !== "multi-tx") {
|
|
1371
|
-
throw new Error(`server resolver "${name}" is not a multi-tx resolver (kind=${r.kind})`);
|
|
1372
|
-
}
|
|
1373
|
-
return r.run(opts);
|
|
1374
|
-
}
|
|
1375
|
-
function postponed(error) {
|
|
1376
|
-
return { ok: false, mode: "fire", error, terminalIntent: null };
|
|
1377
|
-
}
|
|
1378
|
-
function adaptMultiTxSummary(summary) {
|
|
1379
|
-
const s = summary ?? {};
|
|
1380
|
-
const firstBatchKey = Array.isArray(s.batches) && s.batches.length > 0 ? s.batches[0]?.requestKey : void 0;
|
|
1381
|
-
return {
|
|
1382
|
-
ok: true,
|
|
1383
|
-
mode: "fire",
|
|
1384
|
-
requestKey: firstBatchKey,
|
|
1385
|
-
rawResult: summary,
|
|
1386
|
-
terminalIntent: null
|
|
1387
|
-
};
|
|
1388
|
-
}
|
|
1389
|
-
function resolveExec(opts) {
|
|
1390
|
-
if (opts.exec) return opts.exec;
|
|
1391
|
-
const ctx = {
|
|
1392
|
-
runtime: opts.runtime,
|
|
1393
|
-
resolver: opts.resolver,
|
|
1394
|
-
config: opts.config
|
|
1395
|
-
};
|
|
1396
|
-
const bound = (definition, mode) => mode === "simulate" ? executeCodexTransaction(definition, "simulate", ctx) : executeCodexTransaction(definition, "fire", ctx);
|
|
1397
|
-
return bound;
|
|
1398
|
-
}
|
|
1399
|
-
async function fireByServerResolver(definition, row, opts = {}) {
|
|
1400
|
-
if (!definition.serverResolver) {
|
|
1401
|
-
const exec = resolveExec(opts);
|
|
1402
|
-
return exec(definition, "fire");
|
|
1403
|
-
}
|
|
1404
|
-
const registered = SERVER_RESOLVERS[definition.serverResolver];
|
|
1405
|
-
if (registered && registered.kind === "multi-tx") {
|
|
1406
|
-
try {
|
|
1407
|
-
const dispatchOpts = opts.deps ?? (opts.db ? { db: opts.db } : {});
|
|
1408
|
-
const summary = await dispatchMultiTxResolver(definition.serverResolver, dispatchOpts);
|
|
1409
|
-
return adaptMultiTxSummary(summary);
|
|
1410
|
-
} catch (err2) {
|
|
1411
|
-
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
1412
|
-
return postponed(`multi-tx dispatch error: ${message}`);
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
return fireWithServerResolver(definition, row, opts);
|
|
1416
|
-
}
|
|
1417
|
-
async function fireWithServerResolver(definition, _row, opts = {}) {
|
|
1418
|
-
const exec = resolveExec(opts);
|
|
1419
|
-
if (!definition.serverResolver) {
|
|
1420
|
-
return exec(definition, "fire");
|
|
1421
|
-
}
|
|
1422
|
-
const registered = SERVER_RESOLVERS[definition.serverResolver];
|
|
1423
|
-
if (registered && registered.kind !== "single-tx") {
|
|
1424
|
-
return postponed(
|
|
1425
|
-
`server resolver "${definition.serverResolver}" is multi-tx \u2014 dispatch via the orchestrator, not the single-tx fire path`
|
|
1426
|
-
);
|
|
1427
|
-
}
|
|
1428
|
-
const resolve = opts.resolve ?? registered?.resolve;
|
|
1429
|
-
const settle = opts.settle ?? registered?.settle;
|
|
1430
|
-
if (!resolve || !settle) {
|
|
1431
|
-
return postponed(`unknown server resolver: ${definition.serverResolver}`);
|
|
1432
|
-
}
|
|
1433
|
-
const { plan, payload } = resolve(opts.db ? { db: opts.db } : void 0);
|
|
1434
|
-
const fired = {
|
|
1435
|
-
...definition,
|
|
1436
|
-
payload: { ...definition.payload, ...payload }
|
|
1437
|
-
};
|
|
1438
|
-
const sim = await exec(fired, "simulate");
|
|
1439
|
-
if (!sim.ok) {
|
|
1440
|
-
opts.onEvent?.({ kind: "postponed", reason: "simulate failed", error: sim.error });
|
|
1441
|
-
return postponed(`postponed: simulate failed: ${sim.error ?? "unknown"}`);
|
|
1442
|
-
}
|
|
1443
|
-
const guard = opts.config?.singleTxGasGuard ?? SINGLE_TX_GAS_GUARD;
|
|
1444
|
-
const gasUsed = sim.gasUsed ?? 0;
|
|
1445
|
-
if (gasUsed > guard) {
|
|
1446
|
-
opts.onEvent?.({ kind: "postponed", reason: "gas over single-tx guard", gasUsed, guard });
|
|
1447
|
-
return postponed(
|
|
1448
|
-
`postponed: gas ${gasUsed} exceeds single-tx guard ${guard} (multi-tx split deferred)`
|
|
1449
|
-
);
|
|
1450
|
-
}
|
|
1451
|
-
const result = await exec(fired, "fire");
|
|
1452
|
-
if (result.ok) {
|
|
1453
|
-
try {
|
|
1454
|
-
settle(plan, { db: opts.db, requestKey: result.requestKey });
|
|
1455
|
-
opts.onEvent?.({ kind: "settled", count: plan.length, requestKey: result.requestKey });
|
|
1456
|
-
} catch (err2) {
|
|
1457
|
-
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
1458
|
-
opts.onEvent?.({
|
|
1459
|
-
kind: "settlement-needs-attention",
|
|
1460
|
-
error: message,
|
|
1461
|
-
requestKey: result.requestKey
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
return result;
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
1500
|
// src/handlers/http.ts
|
|
1469
1501
|
function json(status, body) {
|
|
1470
1502
|
return { status, body };
|
|
@@ -1626,4 +1658,4 @@ async function runGated2(fn, options = {}) {
|
|
|
1626
1658
|
}
|
|
1627
1659
|
}
|
|
1628
1660
|
|
|
1629
|
-
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 };
|
|
1661
|
+
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, listServerResolvers, manualBatchView, parseRuntimeArgKeys, pauseCodexCronoton, recordFire, recoverFire, resolveConfig, resolveServerVars, resumeCodexCronoton, rowRuntimeArgKeys, rowToDefinition, runGated2 as runGated, summariseSchedule, useKhronoton, useKhronotonAdapter, useKhronotonConfig, validateRuntimeArgs, withConfirm, withRead };
|
|
@@ -1,9 +1,83 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { b as CodexTxConfig, c as CodexGasPayer, d as CodexSigner, S as ScheduleMode, e as ScheduleConfig, C as CodexCronotonRow, a as CodexCronotonFireRow, M as ManualBatchView } from './types-u_nUX1Bg.js';
|
|
3
|
+
import { b as DbDep, D as Database } from './seams-DapFZ4sM.js';
|
|
3
4
|
|
|
4
5
|
/** A validated bag of runtime args — every value is a string (Pact `read-string`). */
|
|
5
6
|
type RuntimeArgs = Record<string, string>;
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Generic server-resolver registry + the kind-routed fire dispatcher.
|
|
10
|
+
*
|
|
11
|
+
* A "server resolver" is a named hook consulted at fire time. Two kinds are
|
|
12
|
+
* distinguished by a `kind` discriminator so the tick can route each to the
|
|
13
|
+
* right execution path:
|
|
14
|
+
*
|
|
15
|
+
* - 'single-tx' — fills designated payload keys from live server data, merges
|
|
16
|
+
* them into ONE {@link CodexTxDefinition}, runs a safety-guard simulate,
|
|
17
|
+
* fires ONE transaction, then settles the server ledger. Dispatched through
|
|
18
|
+
* {@link fireWithServerResolver} (resolve → simulate-guard → fire → settle).
|
|
19
|
+
*
|
|
20
|
+
* - 'multi-tx' — an orchestrator that owns its own fire cardinality and guard
|
|
21
|
+
* (N independent fires). It does NOT ride the single-merge fire path; it is
|
|
22
|
+
* dispatched to its own `run` orchestrator via {@link dispatchMultiTxResolver}.
|
|
23
|
+
* The `run` implementation is supplied by the registering module.
|
|
24
|
+
*
|
|
25
|
+
* This module carries NO consumer-domain coupling: the concrete resolvers and
|
|
26
|
+
* their settlement-event sinks belong to the host, which registers them and may
|
|
27
|
+
* observe settlement outcomes through the optional `onEvent` hook on the fire
|
|
28
|
+
* opts. The only runtime dependency is the Phase-3 executor, bound at the
|
|
29
|
+
* dispatch boundary via an injectable `exec` seam (default: a ctx-bound closure).
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** The plan + payload a single-tx resolver produces for one fire. */
|
|
33
|
+
interface ServerResolverResolution {
|
|
34
|
+
/** Opaque per-entry settlement plan, forwarded verbatim to `settle`. */
|
|
35
|
+
plan: unknown[];
|
|
36
|
+
/** Payload keys merged into the fired definition before simulate/fire. */
|
|
37
|
+
payload: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/** Opts passed to a single-tx resolver's `settle` after a successful fire. */
|
|
40
|
+
interface SettleOpts {
|
|
41
|
+
db?: Database;
|
|
42
|
+
/** The landed on-chain request key, so the ledger write links to the tx. */
|
|
43
|
+
requestKey?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A single-tx server resolver: how to fill the payload + how to settle on
|
|
47
|
+
* success. The resolve/settle pair is consumed by {@link fireWithServerResolver}.
|
|
48
|
+
*/
|
|
49
|
+
interface SingleTxResolver {
|
|
50
|
+
kind: "single-tx";
|
|
51
|
+
/**
|
|
52
|
+
* When true, this resolver is fired by an in-process EVENT, never by a
|
|
53
|
+
* schedule — a cronoton bound to it is scheduleless (the store forces
|
|
54
|
+
* `external_fireable = 1` / `next_fire_at = NULL`) and the Builder hides its
|
|
55
|
+
* schedule controls.
|
|
56
|
+
*/
|
|
57
|
+
evented?: boolean;
|
|
58
|
+
resolve(dep?: DbDep): ServerResolverResolution;
|
|
59
|
+
settle(plan: unknown[], opts?: SettleOpts): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A multi-tx server resolver: a net-new orchestrator that owns its own fire
|
|
63
|
+
* cardinality and guard. `run` is the seam the tick dispatches to; its concrete
|
|
64
|
+
* signature/return is defined by the orchestrator that registers it. The
|
|
65
|
+
* registry only knows it is an async orchestrator taking an injected opts bag.
|
|
66
|
+
*/
|
|
67
|
+
interface MultiTxResolver {
|
|
68
|
+
kind: "multi-tx";
|
|
69
|
+
/**
|
|
70
|
+
* When true, this resolver is fired by an in-process EVENT, never by a
|
|
71
|
+
* schedule — a cronoton bound to it is scheduleless (the store forces
|
|
72
|
+
* `external_fireable = 1` / `next_fire_at = NULL`) and the Builder hides its
|
|
73
|
+
* schedule controls.
|
|
74
|
+
*/
|
|
75
|
+
evented?: boolean;
|
|
76
|
+
run(opts: unknown): Promise<unknown>;
|
|
77
|
+
}
|
|
78
|
+
/** Either resolver kind; the `kind` field discriminates the union. */
|
|
79
|
+
type ServerResolver = SingleTxResolver | MultiTxResolver;
|
|
80
|
+
|
|
7
81
|
/**
|
|
8
82
|
* The framework-agnostic HTTP contract for `@ancientpantheon/khronoton-core/handlers`.
|
|
9
83
|
*
|
|
@@ -191,6 +265,15 @@ interface SignersView {
|
|
|
191
265
|
ok: true;
|
|
192
266
|
signers: CodexSignerDescriptor[];
|
|
193
267
|
}
|
|
268
|
+
/** `GET /resolvers` body — the registered server resolvers + their `evented` flag. */
|
|
269
|
+
interface ResolversView {
|
|
270
|
+
ok: true;
|
|
271
|
+
resolvers: {
|
|
272
|
+
name: string;
|
|
273
|
+
kind: ServerResolver["kind"];
|
|
274
|
+
evented: boolean;
|
|
275
|
+
}[];
|
|
276
|
+
}
|
|
194
277
|
/** `POST /` body — the new id + its first scheduled fire. */
|
|
195
278
|
interface CommitView {
|
|
196
279
|
ok: true;
|
|
@@ -272,6 +355,13 @@ interface KhronotonAdapter {
|
|
|
272
355
|
get(id: string): Promise<GetCronotonView>;
|
|
273
356
|
fires(query: FiresQuery): Promise<FiresView>;
|
|
274
357
|
signers(): Promise<SignersView>;
|
|
358
|
+
/**
|
|
359
|
+
* `GET /resolvers` — OPTIONAL. Added in 0.7.0; an adapter predating it (or one
|
|
360
|
+
* whose backend can't serve it) simply omits it, and the provider degrades
|
|
361
|
+
* gracefully. Deliberately NOT in `REQUIRED_METHODS` — requiring it would be a
|
|
362
|
+
* breaking change for every existing consumer/fake adapter on upgrade.
|
|
363
|
+
*/
|
|
364
|
+
resolvers?(): Promise<ResolversView>;
|
|
275
365
|
commit(body: CommitBody, opts?: ConfirmOpts): Promise<CommitView>;
|
|
276
366
|
edit(id: string, patch: EditPatch, opts?: ConfirmOpts): Promise<EditView>;
|
|
277
367
|
pause(id: string, opts?: ConfirmOpts): Promise<ToggleView>;
|
|
@@ -368,4 +458,4 @@ interface UseKhronotonResult {
|
|
|
368
458
|
*/
|
|
369
459
|
declare function useKhronoton(): UseKhronotonResult;
|
|
370
460
|
|
|
371
|
-
export {
|
|
461
|
+
export { assertAdapter as A, emptySnapshot as B, type CommitBody as C, type DeleteView as D, type EditPatch as E, type FiresQuery as F, type GetBatchView as G, type HandlerRequest as H, type KhronotonProviderProps as K, type ListCronotonsQuery as L, type ResolversView as R, type SimulateEnvelope as S, type ToggleView as T, type UseKhronotonResult as U, type CommitView as a, type EditView as b, type CancelBatchView as c, type ExecuteView as d, type RecoverView as e, type SimulateView as f, type StartBatchView as g, type RuntimeArgs as h, type HandlerResponse as i, type KhronotonAdapter as j, type SignerSource as k, type CodexSignerDescriptor as l, type ConfirmGate as m, type ConfirmOpts as n, DEFAULT_EXPLORER_BASE as o, DEFAULT_PAGE_SIZE as p, DEFAULT_POLL_CADENCE_MS as q, type FiresView as r, type GetCronotonView as s, type KhronotonConfig as t, useKhronoton as u, type KhronotonSnapshot as v, type ListCronotonsView as w, type RenderMultiTx as x, type ServerResolverOption as y, type SignersView as z };
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* framework-agnostic route surface over the `/server` store + executor. A
|
|
4
4
|
* consumer adapts its framework's request/response into {@link HandlerRequest} /
|
|
5
5
|
* {@link HandlerResponse}, injects a {@link HandlerContext} (db + runtime +
|
|
6
|
-
* resolver + an {@link AuthSeam}), and calls the
|
|
6
|
+
* resolver + an {@link AuthSeam}), and calls the seventeen handlers below.
|
|
7
7
|
*
|
|
8
8
|
* The read handlers keep their contract names here (aliasing their module's
|
|
9
9
|
* `*Handler` implementations), so the barrel exposes the exact route contract
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* Every re-export is `export type` where the symbol is a type, so the emitted
|
|
14
14
|
* `.d.ts` stays fully erasable. Explicit `.js` extensions throughout.
|
|
15
15
|
*/
|
|
16
|
-
export { listHandler as listCodexCronotons, getHandler as getCodexCronoton, signersHandler as fetchSigners, firesHandler as fetchFires, } from "./read.js";
|
|
16
|
+
export { listHandler as listCodexCronotons, getHandler as getCodexCronoton, signersHandler as fetchSigners, firesHandler as fetchFires, resolversHandler as listResolvers, } from "./read.js";
|
|
17
17
|
export { commitCodexCronoton, editCodexCronoton, pauseCodexCronoton, resumeCodexCronoton, deleteCodexCronoton, } from "./cronoton.js";
|
|
18
18
|
export type { CommitBody, CommitEnvelope, CommitSchedule } from "./cronoton.js";
|
|
19
19
|
export { simulateCodexTx, executeNow, triggerCronoton, recoverFire } from "./execute.js";
|
package/dist/handlers/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* framework-agnostic route surface over the `/server` store + executor. A
|
|
4
4
|
* consumer adapts its framework's request/response into {@link HandlerRequest} /
|
|
5
5
|
* {@link HandlerResponse}, injects a {@link HandlerContext} (db + runtime +
|
|
6
|
-
* resolver + an {@link AuthSeam}), and calls the
|
|
6
|
+
* resolver + an {@link AuthSeam}), and calls the seventeen handlers below.
|
|
7
7
|
*
|
|
8
8
|
* The read handlers keep their contract names here (aliasing their module's
|
|
9
9
|
* `*Handler` implementations), so the barrel exposes the exact route contract
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* `.d.ts` stays fully erasable. Explicit `.js` extensions throughout.
|
|
15
15
|
*/
|
|
16
16
|
// ── Read handlers (TC.2) — aliased to their contract names ────────────────────
|
|
17
|
-
export { listHandler as listCodexCronotons, getHandler as getCodexCronoton, signersHandler as fetchSigners, firesHandler as fetchFires, } from "./read.js";
|
|
17
|
+
export { listHandler as listCodexCronotons, getHandler as getCodexCronoton, signersHandler as fetchSigners, firesHandler as fetchFires, resolversHandler as listResolvers, } from "./read.js";
|
|
18
18
|
// ── Cronoton-lifecycle handlers (TC.3) ────────────────────────────────────────
|
|
19
19
|
export { commitCodexCronoton, editCodexCronoton, pauseCodexCronoton, resumeCodexCronoton, deleteCodexCronoton, } from "./cronoton.js";
|
|
20
20
|
// ── Execution handlers (TC.4) ─────────────────────────────────────────────────
|
package/dist/handlers/read.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ export declare function listHandler(ctx: HandlerContext, request: HandlerRequest
|
|
|
21
21
|
export declare function getHandler(ctx: HandlerContext, request: HandlerRequest): Promise<HandlerResponse>;
|
|
22
22
|
/** `GET /signers` — the SECRET-FREE signer descriptors (never key material). */
|
|
23
23
|
export declare function signersHandler(ctx: HandlerContext, request: HandlerRequest): Promise<HandlerResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* `GET /resolvers` — the server-authoritative resolver registry: every registered
|
|
26
|
+
* server resolver with its `kind` and `evented` flag. Takes no params/query; the
|
|
27
|
+
* Builder consumes it to learn which resolver names are event-driven (scheduleless).
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolversHandler(ctx: HandlerContext, request: HandlerRequest): Promise<HandlerResponse>;
|
|
24
30
|
/**
|
|
25
31
|
* `GET /[id]/fires?limit&offset` — paginated fire history. The page size defaults
|
|
26
32
|
* to 50 (REQ-G08) — overriding the store's own default of 20 — and both echoed
|
package/dist/handlers/read.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { json, err, defaultSignerSource, } from "./http.js";
|
|
16
16
|
import { withRead } from "./context.js";
|
|
17
|
-
import { listCodexCronotons, getCodexCronoton, listFires, } from "../server/index.js";
|
|
17
|
+
import { listCodexCronotons, getCodexCronoton, listFires, listServerResolvers, } from "../server/index.js";
|
|
18
18
|
/** First scalar of a query value (a repeated key arrives as an array); `undefined` if empty. */
|
|
19
19
|
function firstScalar(raw) {
|
|
20
20
|
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
@@ -77,6 +77,14 @@ export async function signersHandler(ctx, request) {
|
|
|
77
77
|
return json(200, { ok: true, signers });
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* `GET /resolvers` — the server-authoritative resolver registry: every registered
|
|
82
|
+
* server resolver with its `kind` and `evented` flag. Takes no params/query; the
|
|
83
|
+
* Builder consumes it to learn which resolver names are event-driven (scheduleless).
|
|
84
|
+
*/
|
|
85
|
+
export async function resolversHandler(ctx, request) {
|
|
86
|
+
return withRead(ctx, request, async () => json(200, { ok: true, resolvers: listServerResolvers() }));
|
|
87
|
+
}
|
|
80
88
|
/**
|
|
81
89
|
* `GET /[id]/fires?limit&offset` — paginated fire history. The page size defaults
|
|
82
90
|
* to 50 (REQ-G08) — overriding the store's own default of 20 — and both echoed
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { L as ListCronotonsQuery, C as CommitBody, a as CommitView, E as EditPatch, b as EditView, T as ToggleView, D as DeleteView, c as CancelBatchView, d as ExecuteView,
|
|
2
|
-
export { U as UseKhronotonResult, u as useKhronoton } from '../context
|
|
1
|
+
import { L as ListCronotonsQuery, R as ResolversView, C as CommitBody, a as CommitView, E as EditPatch, b as EditView, T as ToggleView, D as DeleteView, c as CancelBatchView, d as ExecuteView, e as RecoverView, S as SimulateEnvelope, f as SimulateView, g as StartBatchView, h as RuntimeArgs } from '../context--Qofoc6Z.js';
|
|
2
|
+
export { U as UseKhronotonResult, u as useKhronoton } from '../context--Qofoc6Z.js';
|
|
3
3
|
import { C as CodexCronotonRow, a as CodexCronotonFireRow, M as ManualBatchView } from '../types-u_nUX1Bg.js';
|
|
4
4
|
import 'react';
|
|
5
|
+
import '../seams-DapFZ4sM.js';
|
|
5
6
|
|
|
6
7
|
/** The `useCronotons()` return shape — the list, its load state, and a refetch. */
|
|
7
8
|
interface UseCronotonsView {
|
|
@@ -54,6 +55,15 @@ interface UseManualBatchResult {
|
|
|
54
55
|
}
|
|
55
56
|
declare function useManualBatch(id: string): UseManualBatchResult;
|
|
56
57
|
|
|
58
|
+
/** The `useServerResolvers()` return shape — the registry, its load state. */
|
|
59
|
+
interface UseServerResolversView {
|
|
60
|
+
/** The registered resolvers + their `evented` flag; `[]` before load / on error / when unsupported. */
|
|
61
|
+
resolvers: ResolversView["resolvers"];
|
|
62
|
+
loading: boolean;
|
|
63
|
+
error: Error | null;
|
|
64
|
+
}
|
|
65
|
+
declare function useServerResolvers(): UseServerResolversView;
|
|
66
|
+
|
|
57
67
|
/** A successful action: the adapter body, untouched. */
|
|
58
68
|
interface ActionOk<T> {
|
|
59
69
|
ok: true;
|
|
@@ -140,4 +150,4 @@ declare function useRecoverFire(): UseExecuteActionResult<[
|
|
|
140
150
|
requestKey: string
|
|
141
151
|
], RecoverView>;
|
|
142
152
|
|
|
143
|
-
export { type ActionFail, type ActionOk, type ActionResult, type CreateAction, type CronotonActions, type DeleteAction, type EditAction, type GatedAction, type ToggleAction, type UseCronotonActionsOptions, type UseCronotonFiresOptions, type UseCronotonFiresResult, type UseCronotonView, type UseCronotonsView, type UseExecuteActionResult, type UseManualBatchResult, useCancelBatch, useCronoton, useCronotonActions, useCronotonFires, useCronotons, useExecuteNow, useManualBatch, useRecoverFire, useSimulate, useStartBatch, useTrigger };
|
|
153
|
+
export { type ActionFail, type ActionOk, type ActionResult, type CreateAction, type CronotonActions, type DeleteAction, type EditAction, type GatedAction, type ToggleAction, type UseCronotonActionsOptions, type UseCronotonFiresOptions, type UseCronotonFiresResult, type UseCronotonView, type UseCronotonsView, type UseExecuteActionResult, type UseManualBatchResult, type UseServerResolversView, useCancelBatch, useCronoton, useCronotonActions, useCronotonFires, useCronotons, useExecuteNow, useManualBatch, useRecoverFire, useServerResolvers, useSimulate, useStartBatch, useTrigger };
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { useCancelBatch, useCronoton, useCronotonActions, useCronotonFires, useCronotons, useExecuteNow, useManualBatch, useRecoverFire, useSimulate, useStartBatch, useTrigger } from '../chunk-
|
|
2
|
-
export { useKhronoton } from '../chunk-
|
|
1
|
+
export { useCancelBatch, useCronoton, useCronotonActions, useCronotonFires, useCronotons, useExecuteNow, useManualBatch, useRecoverFire, useServerResolvers, useSimulate, useStartBatch, useTrigger } from '../chunk-OGKXCOCK.js';
|
|
2
|
+
export { useKhronoton } from '../chunk-WLZXX2SQ.js';
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { H as HandlerRequest,
|
|
3
|
-
export { c as CancelBatchView,
|
|
4
|
-
import { D as Database, C as ChainRuntime, K as KeyResolver, R as ResolveFireMode, O as OnAudit, a as Config } from '../seams-
|
|
2
|
+
import { H as HandlerRequest, i as HandlerResponse, K as KhronotonProviderProps, j as KhronotonAdapter, k as SignerSource } from '../context--Qofoc6Z.js';
|
|
3
|
+
export { c as CancelBatchView, l as CodexSignerDescriptor, C as CommitBody, a as CommitView, m as ConfirmGate, n as ConfirmOpts, o as DEFAULT_EXPLORER_BASE, p as DEFAULT_PAGE_SIZE, q as DEFAULT_POLL_CADENCE_MS, D as DeleteView, E as EditPatch, b as EditView, d as ExecuteView, F as FiresQuery, r as FiresView, G as GetBatchView, s as GetCronotonView, t as KhronotonConfig, v as KhronotonSnapshot, L as ListCronotonsQuery, w as ListCronotonsView, e as RecoverView, x as RenderMultiTx, h as RuntimeArgs, y as ServerResolverOption, z as SignersView, S as SimulateEnvelope, f as SimulateView, g as StartBatchView, T as ToggleView, U as UseKhronotonResult, A as assertAdapter, B as emptySnapshot, u as useKhronoton } from '../context--Qofoc6Z.js';
|
|
4
|
+
import { D as Database, C as ChainRuntime, K as KeyResolver, R as ResolveFireMode, O as OnAudit, a as Config } from '../seams-DapFZ4sM.js';
|
|
5
5
|
export { a as CodexCronotonFireRow, C as CodexCronotonRow, M as ManualBatchView } from '../types-u_nUX1Bg.js';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/provider/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { assertAdapter, resolveConfig, KhronotonStaticContext, KhronotonStatusContext, NeedsConfirmError, installSchema, defaultOpenAuth, withConfirm, err, recoverFire, json, createManualBatch, manualBatchView, getCodexCronoton, validateRuntimeArgs, rowRuntimeArgKeys, applyRuntimeArgs, rowToDefinition, getServerResolver, resolveServerVars, executeCodexTransaction, CodexCronotonValidationError, deleteCodexCronoton, resumeCodexCronoton, pauseCodexCronoton, editCodexCronoton, commitCodexCronoton, withRead, listFires, listCodexCronotons, getActiveManualBatchForCronoton, cancelManualBatch, defaultSignerSource, fireByServerResolver, computeDefinitionFingerprint, recordFire, applyTerminalIntent } from '../chunk-
|
|
2
|
-
export { DEFAULT_EXPLORER_BASE, DEFAULT_PAGE_SIZE, DEFAULT_POLL_CADENCE_MS, NeedsConfirmError, assertAdapter, emptySnapshot, runGated, useKhronoton } from '../chunk-
|
|
1
|
+
import { assertAdapter, resolveConfig, KhronotonStaticContext, KhronotonStatusContext, NeedsConfirmError, installSchema, defaultOpenAuth, withConfirm, err, recoverFire, json, createManualBatch, manualBatchView, getCodexCronoton, validateRuntimeArgs, rowRuntimeArgKeys, applyRuntimeArgs, rowToDefinition, getServerResolver, resolveServerVars, executeCodexTransaction, CodexCronotonValidationError, deleteCodexCronoton, resumeCodexCronoton, pauseCodexCronoton, editCodexCronoton, commitCodexCronoton, withRead, listFires, listCodexCronotons, getActiveManualBatchForCronoton, cancelManualBatch, listServerResolvers, defaultSignerSource, fireByServerResolver, computeDefinitionFingerprint, recordFire, applyTerminalIntent } from '../chunk-WLZXX2SQ.js';
|
|
2
|
+
export { DEFAULT_EXPLORER_BASE, DEFAULT_PAGE_SIZE, DEFAULT_POLL_CADENCE_MS, NeedsConfirmError, assertAdapter, emptySnapshot, runGated, useKhronoton } from '../chunk-WLZXX2SQ.js';
|
|
3
3
|
import { useRef, useState, useEffect } from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
@@ -120,6 +120,9 @@ function createFetchAdapter(baseUrl, opts = {}) {
|
|
|
120
120
|
signers() {
|
|
121
121
|
return request("GET", "/signers");
|
|
122
122
|
},
|
|
123
|
+
resolvers() {
|
|
124
|
+
return request("GET", "/resolvers");
|
|
125
|
+
},
|
|
123
126
|
// Lifecycle tier (confirm-gated)
|
|
124
127
|
commit(body, confirm) {
|
|
125
128
|
return request("POST", "", { body, confirmed: confirm?.confirmed });
|
|
@@ -228,6 +231,9 @@ async function signersHandler(ctx, request) {
|
|
|
228
231
|
return json(200, { ok: true, signers });
|
|
229
232
|
});
|
|
230
233
|
}
|
|
234
|
+
async function resolversHandler(ctx, request) {
|
|
235
|
+
return withRead(ctx, request, async () => json(200, { ok: true, resolvers: listServerResolvers() }));
|
|
236
|
+
}
|
|
231
237
|
async function firesHandler(ctx, request) {
|
|
232
238
|
return withRead(ctx, request, async () => {
|
|
233
239
|
const id = request.params?.id ?? "";
|
|
@@ -612,6 +618,9 @@ function createMemoryAdapter(opts) {
|
|
|
612
618
|
signers() {
|
|
613
619
|
return call(signersHandler, {});
|
|
614
620
|
},
|
|
621
|
+
resolvers() {
|
|
622
|
+
return call(resolversHandler, {});
|
|
623
|
+
},
|
|
615
624
|
// Lifecycle tier (confirm-gated)
|
|
616
625
|
commit(body, confirm) {
|
|
617
626
|
return call(commitCodexCronoton2, { body, confirmed: confirm?.confirmed });
|
|
@@ -153,6 +153,16 @@ interface Database {
|
|
|
153
153
|
exec(sql: string): unknown;
|
|
154
154
|
prepare(sql: string): Statement;
|
|
155
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Carries the injected DB handle into store calls.
|
|
158
|
+
*
|
|
159
|
+
* Divergence from the Hub's `resolveDb(dep) = dep?.db ?? getDb()`: this package
|
|
160
|
+
* has no ambient `getDb()` fallback, so the handle is REQUIRED — the consumer
|
|
161
|
+
* always injects a handle at the call boundary.
|
|
162
|
+
*/
|
|
163
|
+
interface DbDep {
|
|
164
|
+
db: Database;
|
|
165
|
+
}
|
|
156
166
|
/** The structured event passed to an {@link OnAudit} sink. */
|
|
157
167
|
interface AuditEvent {
|
|
158
168
|
action: string;
|
|
@@ -200,4 +210,4 @@ interface Config {
|
|
|
200
210
|
};
|
|
201
211
|
}
|
|
202
212
|
|
|
203
|
-
export type { ChainRuntime as C, Database as D, KeyResolver as K, OnAudit as O, ResolveFireMode as R, Config as a };
|
|
213
|
+
export type { ChainRuntime as C, Database as D, KeyResolver as K, OnAudit as O, ResolveFireMode as R, Config as a, DbDep as b };
|
|
@@ -42,6 +42,13 @@ export interface SettleOpts {
|
|
|
42
42
|
*/
|
|
43
43
|
export interface SingleTxResolver {
|
|
44
44
|
kind: "single-tx";
|
|
45
|
+
/**
|
|
46
|
+
* When true, this resolver is fired by an in-process EVENT, never by a
|
|
47
|
+
* schedule — a cronoton bound to it is scheduleless (the store forces
|
|
48
|
+
* `external_fireable = 1` / `next_fire_at = NULL`) and the Builder hides its
|
|
49
|
+
* schedule controls.
|
|
50
|
+
*/
|
|
51
|
+
evented?: boolean;
|
|
45
52
|
resolve(dep?: DbDep): ServerResolverResolution;
|
|
46
53
|
settle(plan: unknown[], opts?: SettleOpts): void;
|
|
47
54
|
}
|
|
@@ -53,6 +60,13 @@ export interface SingleTxResolver {
|
|
|
53
60
|
*/
|
|
54
61
|
export interface MultiTxResolver {
|
|
55
62
|
kind: "multi-tx";
|
|
63
|
+
/**
|
|
64
|
+
* When true, this resolver is fired by an in-process EVENT, never by a
|
|
65
|
+
* schedule — a cronoton bound to it is scheduleless (the store forces
|
|
66
|
+
* `external_fireable = 1` / `next_fire_at = NULL`) and the Builder hides its
|
|
67
|
+
* schedule controls.
|
|
68
|
+
*/
|
|
69
|
+
evented?: boolean;
|
|
56
70
|
run(opts: unknown): Promise<unknown>;
|
|
57
71
|
}
|
|
58
72
|
/** Either resolver kind; the `kind` field discriminates the union. */
|
|
@@ -65,6 +79,18 @@ export type ServerResolver = SingleTxResolver | MultiTxResolver;
|
|
|
65
79
|
export declare function registerServerResolver(name: string, resolver: ServerResolver): void;
|
|
66
80
|
/** Read a registered resolver entry (with its `kind`) by name, or `undefined`. */
|
|
67
81
|
export declare function getServerResolver(name: string): ServerResolver | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Enumerate the registry as a flat, name-sorted list of `{ name, kind, evented }`
|
|
84
|
+
* — the server-authoritative source consumed by the `GET /resolvers` read handler
|
|
85
|
+
* and the Builder (to learn which resolver names are event-driven / scheduleless).
|
|
86
|
+
* `evented` is normalized to a boolean (`r.evented === true`) so consumers never
|
|
87
|
+
* see `undefined`. Sorted by `name` for deterministic responses.
|
|
88
|
+
*/
|
|
89
|
+
export declare function listServerResolvers(): {
|
|
90
|
+
name: string;
|
|
91
|
+
kind: ServerResolver["kind"];
|
|
92
|
+
evented: boolean;
|
|
93
|
+
}[];
|
|
68
94
|
/**
|
|
69
95
|
* Resolve a named SINGLE-TX resolver's plan + payload WITHOUT firing — used by a
|
|
70
96
|
* simulate/preview endpoint to show what a fire would produce. Returns `null`
|
package/dist/server/resolvers.js
CHANGED
|
@@ -37,6 +37,18 @@ export function registerServerResolver(name, resolver) {
|
|
|
37
37
|
export function getServerResolver(name) {
|
|
38
38
|
return SERVER_RESOLVERS[name];
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Enumerate the registry as a flat, name-sorted list of `{ name, kind, evented }`
|
|
42
|
+
* — the server-authoritative source consumed by the `GET /resolvers` read handler
|
|
43
|
+
* and the Builder (to learn which resolver names are event-driven / scheduleless).
|
|
44
|
+
* `evented` is normalized to a boolean (`r.evented === true`) so consumers never
|
|
45
|
+
* see `undefined`. Sorted by `name` for deterministic responses.
|
|
46
|
+
*/
|
|
47
|
+
export function listServerResolvers() {
|
|
48
|
+
return Object.entries(SERVER_RESOLVERS)
|
|
49
|
+
.map(([name, r]) => ({ name, kind: r.kind, evented: r.evented === true }))
|
|
50
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
51
|
+
}
|
|
40
52
|
/**
|
|
41
53
|
* Resolve a named SINGLE-TX resolver's plan + payload WITHOUT firing — used by a
|
|
42
54
|
* simulate/preview endpoint to show what a fire would produce. Returns `null`
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import crypto from "node:crypto";
|
|
19
19
|
import { computeNextFire, InvalidScheduleConfigError, } from "../../schedule.js";
|
|
20
20
|
import { runtimeArgKeysCollide } from "../pure/runtime-args.js";
|
|
21
|
+
import { getServerResolver } from "../resolvers.js";
|
|
21
22
|
import { CodexCronotonValidationError, TerminalCronotonError } from "./errors.js";
|
|
22
23
|
import { assertAutoGasGate, rowExternalFireable, rowRuntimeArgKeys, } from "./mappers.js";
|
|
23
24
|
/** Compute the first next-fire, mapping engine errors to a typed reject. */
|
|
@@ -65,13 +66,30 @@ export function commitCodexCronoton(input, opts) {
|
|
|
65
66
|
if (input.serverResolver && runtimeArgKeys.length > 0) {
|
|
66
67
|
throw new CodexCronotonValidationError("server-resolver rows cannot declare runtime args");
|
|
67
68
|
}
|
|
69
|
+
// One-resolver-one-cronoton: a server_resolver may bind AT MOST one cronoton.
|
|
70
|
+
// The finder returns the newest match, so a duplicate would silently shadow the
|
|
71
|
+
// first and fire the wrong template — reject it, naming the existing row.
|
|
72
|
+
if (input.serverResolver) {
|
|
73
|
+
const existing = findCodexCronotonIdByServerResolver(input.serverResolver, {
|
|
74
|
+
db: opts.db,
|
|
75
|
+
});
|
|
76
|
+
if (existing) {
|
|
77
|
+
throw new CodexCronotonValidationError(`server resolver "${input.serverResolver}" is already bound to cronoton ${existing} — delete it first`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
68
80
|
const now = opts.now ?? new Date();
|
|
69
81
|
// A SCHEDULER-OFF cronoton (externally fireable, OR declaring runtime args, OR
|
|
70
82
|
// event-driven — a server-resolver the host fires via `executeNow`) fires on
|
|
71
83
|
// demand, never on a timer — so it carries NO schedule: skip the next-fire
|
|
72
84
|
// computation and store next_fire_at = NULL. The scheduler's
|
|
73
85
|
// `next_fire_at IS NOT NULL` gate then skips it.
|
|
74
|
-
|
|
86
|
+
// An EVENTED server resolver (per the registry) is host-fired on an in-process
|
|
87
|
+
// event, never on a timer — the store is authoritative: it forces the row
|
|
88
|
+
// external-fireable (external_fireable = 1) and scheduler-off, regardless of what
|
|
89
|
+
// the client sent, so the guarantee holds for every consumer.
|
|
90
|
+
const evented = getServerResolver(input.serverResolver ?? "")?.evented === true;
|
|
91
|
+
const externalFireable = input.externalFireable === true || evented;
|
|
92
|
+
const triggerOnly = externalFireable ||
|
|
75
93
|
runtimeArgKeys.length > 0 ||
|
|
76
94
|
input.eventDriven === true;
|
|
77
95
|
const nextFireAt = triggerOnly
|
|
@@ -86,7 +104,7 @@ export function commitCodexCronoton(input, opts) {
|
|
|
86
104
|
server_resolver, external_fireable, runtime_arg_keys, status,
|
|
87
105
|
next_fire_at, last_fire_at, created_at, modified_at, created_by)
|
|
88
106
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, NULL, ?, ?, ?)`)
|
|
89
|
-
.run(id, input.name.trim(), input.description, input.pactCode, JSON.stringify(input.config), input.payload ? JSON.stringify(input.payload) : null, JSON.stringify(input.gasPayer), JSON.stringify(input.signers), input.scheduleMode, JSON.stringify(input.scheduleConfig), input.serverResolver ?? null,
|
|
107
|
+
.run(id, input.name.trim(), input.description, input.pactCode, JSON.stringify(input.config), input.payload ? JSON.stringify(input.payload) : null, JSON.stringify(input.gasPayer), JSON.stringify(input.signers), input.scheduleMode, JSON.stringify(input.scheduleConfig), input.serverResolver ?? null, externalFireable ? 1 : 0, runtimeArgKeys.length > 0 ? JSON.stringify(runtimeArgKeys) : null, nextFireAt, nowIso, nowIso, input.createdBy);
|
|
90
108
|
return { id, nextFireAt };
|
|
91
109
|
}
|
|
92
110
|
export function getCodexCronoton(id, dep) {
|
|
@@ -204,35 +222,56 @@ export function editCodexCronoton(id, patch, opts) {
|
|
|
204
222
|
scheduleChanged = true;
|
|
205
223
|
changedFields.push("schedule");
|
|
206
224
|
}
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
|
|
225
|
+
// Derive EVENTED-ness of both the PATCHED (post-edit) resolver and the row's
|
|
226
|
+
// CURRENT (pre-edit) resolver from the registry (authoritative). An edit that
|
|
227
|
+
// repoints onto an evented resolver — even WITHOUT the client eventDriven flag —
|
|
228
|
+
// must force scheduler-off + external-fireable, mirroring commit; an edit that
|
|
229
|
+
// repoints AWAY from an evented resolver must shed the evented-forced
|
|
230
|
+
// external_fireable and re-arm a real schedule.
|
|
231
|
+
const resolverName = patch.serverResolver !== undefined ? patch.serverResolver : row.server_resolver;
|
|
232
|
+
const evented = getServerResolver(resolverName ?? "")?.evented === true;
|
|
233
|
+
const prevEvented = getServerResolver(row.server_resolver ?? "")?.evented === true;
|
|
234
|
+
// The row's external_fireable is "genuine" (a user-set HMAC-fire flag to preserve)
|
|
235
|
+
// ONLY when it was NOT forced by a now-departed evented resolver. This lets a plain
|
|
236
|
+
// edit of a genuinely external-fireable row keep its flag, while an evented→
|
|
237
|
+
// non-evented repoint correctly drops the evented-forced flag.
|
|
238
|
+
const genuineExternalFireable = Boolean(rowExternalFireable(row)) && !prevEvented;
|
|
239
|
+
const rowSchedulerOff = evented || rowRuntimeArgKeys(row).length > 0 || genuineExternalFireable;
|
|
240
|
+
// A row that just LEFT an evented resolver must re-arm its schedule even if the
|
|
241
|
+
// edit carried no explicit schedule patch (else it would sit external_fireable=0 +
|
|
242
|
+
// next_fire_at=NULL — a dead row that never fires).
|
|
243
|
+
const eventedDeparted = prevEvented && !evented;
|
|
211
244
|
// An event-driven edit forces the row scheduler-off (next_fire_at NULL). There is
|
|
212
|
-
// no persisted event_driven column, so `
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
if (patch.eventDriven === true) {
|
|
245
|
+
// no persisted event_driven column, so `rowSchedulerOff` can't see the departed
|
|
246
|
+
// case via the row alone — the patch/registry signals above drive this. Marking
|
|
247
|
+
// "schedule" ensures the UPDATE runs even when the next_fire_at change is the only
|
|
248
|
+
// change, so the early-out below doesn't skip the write.
|
|
249
|
+
if (patch.eventDriven === true || evented) {
|
|
218
250
|
if (nextFireAt !== null && !changedFields.includes("schedule")) {
|
|
219
251
|
changedFields.push("schedule");
|
|
220
252
|
}
|
|
221
253
|
nextFireAt = null;
|
|
222
254
|
}
|
|
223
|
-
else if (scheduleChanged && !
|
|
255
|
+
else if ((scheduleChanged || eventedDeparted) && !rowSchedulerOff) {
|
|
224
256
|
const next = computeNextOrReject(nextScheduleMode, JSON.parse(nextScheduleConfigJson), opts.now ?? new Date());
|
|
225
257
|
nextFireAt = next.toISOString();
|
|
258
|
+
if (!changedFields.includes("schedule"))
|
|
259
|
+
changedFields.push("schedule");
|
|
226
260
|
}
|
|
227
261
|
if (changedFields.length === 0) {
|
|
228
262
|
return { changedFields, nextFireAt };
|
|
229
263
|
}
|
|
264
|
+
// An evented edit forces external_fireable = 1 (mirroring commit). Otherwise the
|
|
265
|
+
// edit PRESERVES a GENUINE (user-set) external-fireable flag, but DROPS one that
|
|
266
|
+
// was only forced by a now-departed evented resolver — so an evented→non-evented
|
|
267
|
+
// repoint doesn't leave the row permanently external-fireable/scheduler-off.
|
|
268
|
+
const nextExternalFireable = evented ? 1 : genuineExternalFireable ? 1 : 0;
|
|
230
269
|
db.prepare(`UPDATE codex_cronotons
|
|
231
270
|
SET name = ?, description = ?, pact_code = ?, config_json = ?,
|
|
232
271
|
payload_json = ?, gas_payer_json = ?, signers_json = ?,
|
|
233
272
|
schedule_mode = ?, schedule_config_json = ?, server_resolver = ?,
|
|
234
|
-
next_fire_at = ?, modified_at = ?
|
|
235
|
-
WHERE id = ?`).run(nextName, nextDescription, nextPactCode, nextConfigJson, nextPayloadJson, nextGasPayerJson, nextSignersJson, nextScheduleMode, nextScheduleConfigJson, nextServerResolver, nextFireAt, (opts.now ?? new Date()).toISOString(), id);
|
|
273
|
+
external_fireable = ?, next_fire_at = ?, modified_at = ?
|
|
274
|
+
WHERE id = ?`).run(nextName, nextDescription, nextPactCode, nextConfigJson, nextPayloadJson, nextGasPayerJson, nextSignersJson, nextScheduleMode, nextScheduleConfigJson, nextServerResolver, nextExternalFireable, nextFireAt, (opts.now ?? new Date()).toISOString(), id);
|
|
236
275
|
return { changedFields, nextFireAt };
|
|
237
276
|
}
|
|
238
277
|
// ── Pause / resume / delete ──────────────────────────────────────────────────
|
package/dist/ui/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useCronotons, useCronoton, useCronotonActions, useExecuteNow, useSimulate, useManualBatch, useStartBatch, useCancelBatch, useTrigger, useCronotonFires, useRecoverFire } from '../chunk-
|
|
2
|
-
import { useKhronotonAdapter, useKhronotonConfig, parseRuntimeArgKeys, summariseSchedule, KhronotonStaticContext, useKhronoton, computeNextFire, InvalidScheduleConfigError } from '../chunk-
|
|
1
|
+
import { useCronotons, useCronoton, useCronotonActions, useExecuteNow, useSimulate, useServerResolvers, useManualBatch, useStartBatch, useCancelBatch, useTrigger, useCronotonFires, useRecoverFire } from '../chunk-OGKXCOCK.js';
|
|
2
|
+
import { useKhronotonAdapter, useKhronotonConfig, parseRuntimeArgKeys, summariseSchedule, KhronotonStaticContext, useKhronoton, computeNextFire, InvalidScheduleConfigError } from '../chunk-WLZXX2SQ.js';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { lazy, forwardRef, createElement, useState, useEffect, useCallback, Suspense, useContext } from 'react';
|
|
5
5
|
|
|
@@ -474,6 +474,7 @@ function pactPreview(pactCode) {
|
|
|
474
474
|
return collapsed.length > PACT_PREVIEW_MAX ? `${collapsed.slice(0, PACT_PREVIEW_MAX)}\u2026` : collapsed;
|
|
475
475
|
}
|
|
476
476
|
function isTriggerOnly(row) {
|
|
477
|
+
if (row.external_fireable === 1) return true;
|
|
477
478
|
const raw = row.runtime_arg_keys;
|
|
478
479
|
if (!raw) return false;
|
|
479
480
|
try {
|
|
@@ -564,7 +565,7 @@ function CronotonListRowView({
|
|
|
564
565
|
/* @__PURE__ */ jsx("div", { style: MONO, children: pactPreview(row.pact_code) }),
|
|
565
566
|
/* @__PURE__ */ jsx("div", { style: { ...DIM, fontSize: "11px", marginTop: "3px" }, children: isTriggerOnly(row) ? "External trigger" : scheduleLine(row) })
|
|
566
567
|
] }),
|
|
567
|
-
/* @__PURE__ */ jsx(Cell, { children: row.next_fire_at ? /* @__PURE__ */ jsx(RelativeTime, { iso: row.next_fire_at }) : EM_DASH }),
|
|
568
|
+
/* @__PURE__ */ jsx(Cell, { children: isTriggerOnly(row) ? /* @__PURE__ */ jsx("span", { style: DIM, children: "Evented" }) : row.next_fire_at ? /* @__PURE__ */ jsx(RelativeTime, { iso: row.next_fire_at }) : EM_DASH }),
|
|
568
569
|
/* @__PURE__ */ jsx(Cell, { children: lastFireCell(row) }),
|
|
569
570
|
/* @__PURE__ */ jsx(Cell, { children: /* @__PURE__ */ jsx(CronotonStatusBadge, { status: row.status }) }),
|
|
570
571
|
/* @__PURE__ */ jsx(Cell, { children: access.tier === "logged-out" ? /* @__PURE__ */ jsx("span", { style: { ...DIM, fontSize: "11px" }, children: "view only" }) : /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" }, children: [
|
|
@@ -3648,6 +3649,7 @@ function Builder({
|
|
|
3648
3649
|
const config = useKhronotonConfig();
|
|
3649
3650
|
const actions = useCronotonActions(editId);
|
|
3650
3651
|
const sim = useSimulate();
|
|
3652
|
+
const { resolvers } = useServerResolvers();
|
|
3651
3653
|
const [state, setState] = useState(() => makeEmptyBuilderState());
|
|
3652
3654
|
const [signers, setSigners] = useState([]);
|
|
3653
3655
|
const [activeTab, setActiveTab] = useState("config");
|
|
@@ -3656,8 +3658,9 @@ function Builder({
|
|
|
3656
3658
|
const [loadedEditId, setLoadedEditId] = useState(void 0);
|
|
3657
3659
|
const isEdit = Boolean(editId);
|
|
3658
3660
|
const editReady = !editId || loadedEditId === editId;
|
|
3661
|
+
const eventedNames = new Set(resolvers.filter((r) => r.evented).map((r) => r.name));
|
|
3659
3662
|
const eventDrivenResolver = Boolean(
|
|
3660
|
-
state.serverResolver && config.serverResolverOptions.find((o) => o.value === state.serverResolver)?.eventDriven
|
|
3663
|
+
state.serverResolver && (eventedNames.has(state.serverResolver) || config.serverResolverOptions.find((o) => o.value === state.serverResolver)?.eventDriven)
|
|
3661
3664
|
);
|
|
3662
3665
|
useEffect(() => {
|
|
3663
3666
|
let active = true;
|
|
@@ -3693,6 +3696,7 @@ function Builder({
|
|
|
3693
3696
|
setCommitting(true);
|
|
3694
3697
|
try {
|
|
3695
3698
|
const body = builderToCommit(state, { eventDriven: eventDrivenResolver });
|
|
3699
|
+
if (eventDrivenResolver) body.envelope.externalFireable = true;
|
|
3696
3700
|
if (isEdit && editId) {
|
|
3697
3701
|
const res = await actions.edit.run(body);
|
|
3698
3702
|
if (res.ok) onDone?.(editId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancientpantheon/khronoton-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Headless framework-agnostic scheduler engine: pure schedule math plus an injectable tick engine. No database, no job queue, no framework — hosts inject storage and firing via hooks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|