@byok-sdk/bot-collaboration 0.0.0-stage → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2075 -2
- package/dist/adapter-steps.d.ts +49 -0
- package/dist/channel.d.ts +111 -0
- package/dist/chunk-33YA66U7.js +7 -0
- package/dist/chunk-33YA66U7.js.map +1 -0
- package/dist/chunk-6Y2B2XCP.js +12 -0
- package/dist/chunk-6Y2B2XCP.js.map +1 -0
- package/dist/chunk-QZRWFFHM.js +12 -0
- package/dist/chunk-QZRWFFHM.js.map +1 -0
- package/dist/chunk-ZX6C5U2S.js +27 -0
- package/dist/chunk-ZX6C5U2S.js.map +1 -0
- package/dist/coalesce.d.ts +18 -0
- package/dist/commit-vectors.test-support.d.ts +173 -0
- package/dist/commit.d.ts +53 -0
- package/dist/compaction.d.ts +13 -0
- package/dist/delegation.d.ts +12 -0
- package/dist/delivery-routing.d.ts +63 -0
- package/dist/delivery-vectors.test-support.d.ts +78 -0
- package/dist/delivery.d.ts +20 -0
- package/dist/dream.d.ts +88 -0
- package/dist/home-projections.d.ts +5 -0
- package/dist/host-kit.d.ts +60 -0
- package/dist/host-kit.js +11 -0
- package/dist/host-kit.js.map +1 -0
- package/dist/host.d.ts +472 -0
- package/dist/inbound.d.ts +17 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/k4-fixtures.test-support.d.ts +10 -0
- package/dist/l-test-host.test-support.d.ts +72 -0
- package/dist/migration.d.ts +251 -0
- package/dist/model.d.ts +89 -0
- package/dist/persona.d.ts +2 -0
- package/dist/retention-vectors.test-support.d.ts +17 -0
- package/dist/retention.d.ts +61 -0
- package/dist/rooms.d.ts +22 -0
- package/dist/routine-vectors.test-support.d.ts +81 -0
- package/dist/routines.d.ts +110 -0
- package/dist/rules/autonomy.d.ts +67 -0
- package/dist/rules/cards.d.ts +31 -0
- package/dist/rules/coalesce.d.ts +111 -0
- package/dist/rules/commands.d.ts +306 -0
- package/dist/rules/commit.d.ts +82 -0
- package/dist/rules/compaction.d.ts +33 -0
- package/dist/rules/context.d.ts +484 -0
- package/dist/rules/delegation.d.ts +366 -0
- package/dist/rules/due.d.ts +15 -0
- package/dist/rules/frame.d.ts +4 -0
- package/dist/rules/history.d.ts +34 -0
- package/dist/rules/inbound.d.ts +53 -0
- package/dist/rules/index.d.ts +13 -0
- package/dist/rules/index.js +4 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/message.d.ts +31 -0
- package/dist/rules/outcome.d.ts +45 -0
- package/dist/rules/priority.d.ts +52 -0
- package/dist/rules/rooms.d.ts +187 -0
- package/dist/rules/schema.d.ts +110 -0
- package/dist/rules/sync.d.ts +157 -0
- package/dist/rules/team.d.ts +119 -0
- package/dist/rules/turn.d.ts +129 -0
- package/dist/schema.d.ts +154 -0
- package/dist/store-compatibility.d.ts +3 -0
- package/dist/switch.d.ts +53 -0
- package/dist/team-model.d.ts +54 -0
- package/dist/team.d.ts +56 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.js +20 -0
- package/dist/testing.js.map +1 -0
- package/dist/toolset-policy.d.ts +2 -0
- package/dist/topology.d.ts +49 -0
- package/package.json +80 -4
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { type Conclusion, type Intent, type Json, type Occurrence, type RetryPolicy, type Routine, type RoutineDefinition } from '@byok-sdk/server/execution-core';
|
|
2
|
+
import type { CollaborationState } from './model.js';
|
|
3
|
+
/**
|
|
4
|
+
* The state that an L/H owner switch moves (#975, design §8): one coordination domain, an L ledger tenant or an H scope,
|
|
5
|
+
* exported by the old owner after every device of the domain is frozen and drained, and imported by the new owner into an
|
|
6
|
+
* empty domain. Both Hosts read and write this one neutral form, so neither Host's storage is the format. The old owner
|
|
7
|
+
* seals it; the new owner verifies it, writes it, reads its own rows back into this form, and compares the digest.
|
|
8
|
+
*
|
|
9
|
+
* A record holds what a target needs to rebuild the row. Each value is one the source stores, never a default. H stores
|
|
10
|
+
* only part of it today: the K4-only fields (#975 D1 to D5) get H columns in the H slice that imports them, and until then
|
|
11
|
+
* H cannot import a record that has them. Every object has an exact set of keys, so nothing an importer would drop can
|
|
12
|
+
* ride along.
|
|
13
|
+
*
|
|
14
|
+
* A value that a Host derives from others is not in the record, and the target derives its own. The format never sees
|
|
15
|
+
* the source's stored copies, so each Host's export builder checks its copies against these rules and refuses to build an
|
|
16
|
+
* export where one differs:
|
|
17
|
+
* - an intent's `agent`, K4 `agentKey(domain, execution)` (`transitions.ts`, H `intents.ts` with its scope). It names the
|
|
18
|
+
* source's tenant or scope, and K4 `loadForSwitch` refuses another tenant's, so each target derives it with its domain;
|
|
19
|
+
* - the K4 execution input of an earlier generation, and K4 `intent.execution`: `input` with that generation's task id, and
|
|
20
|
+
* `input` without `taskId`. That holds while K4 runs without its memory option, which rewrites the frozen instruction
|
|
21
|
+
* (`core.ts` begin); K8 passes none;
|
|
22
|
+
* - K4 `applied`: the current task id exactly when `conclusion` is `succeeded`, which K4 sets only with that settle
|
|
23
|
+
* (`core.ts` terminal);
|
|
24
|
+
* - a K4 occurrence's wake key and slot, K4 `routineWakeKey(routineId, definitionVersion, trigger.plannedAt)` and its hash. K4 records
|
|
25
|
+
* and compacts one slot with each occurrence (`routines.ts` recordOccurrence, `ledger.ts` compact), and H's slot is the
|
|
26
|
+
* occurrence's unique `(routine_id, definition_version, planned_at)`, so the format has no slot section;
|
|
27
|
+
* - an occurrence's intent id, the hash of K4 `occurrenceIntentKey(key)`, and K4 `attempts` (`switchAttempts`).
|
|
28
|
+
* An occurrence key is checked here as well: K4 `hash([routineId, definitionVersion, trigger])`.
|
|
29
|
+
*
|
|
30
|
+
* The digest covers the header too: `domain` is the source's tenant or scope id, never the target's (a switch back to L
|
|
31
|
+
* opens a new tenant). So the target's read-back copies the document's header as it is and rebuilds only the sections
|
|
32
|
+
* from its own rows. Devices are in JS string order of `deviceId`, and each section in JS string order of
|
|
33
|
+
* `canonical(identity)`, so a read-back sorts that way in JS or reseals; a database `ORDER BY` may give `unsorted`.
|
|
34
|
+
*
|
|
35
|
+
* A channel delivery moves under its id, `hash([taskId, messageId, routeKey, nonce?])` (`delivery.ts` deliveryId), which
|
|
36
|
+
* names no domain, so the target's readback or resend of a `sending` or `unknown` delivery uses the source's idempotency
|
|
37
|
+
* key. Whether a platform honors that key is its adapter's concern (`docs/host-im-adapter.md`), and the switch does not
|
|
38
|
+
* change it. A projection does not move: H's receiver deduplicates by `(scope, id)` (H `sender.ts` ProjectionPort), and L
|
|
39
|
+
* does not record whether a pending projection was sent (H does: it raises `tries` before the send), so the source
|
|
40
|
+
* flushes its projections before the export.
|
|
41
|
+
*/
|
|
42
|
+
export declare const SWITCH_EXPORT_VERSION = 1;
|
|
43
|
+
export declare const SWITCH_SECTIONS: readonly ['collaboration', 'archived', 'intents', 'routines', 'occurrences', 'outbox', 'tombstones'];
|
|
44
|
+
export type SwitchSection = typeof SWITCH_SECTIONS[number];
|
|
45
|
+
/** A device of the domain and its revision on the source Host, frozen by the source's open switch. */
|
|
46
|
+
export interface SwitchDevice {
|
|
47
|
+
deviceId: string;
|
|
48
|
+
frozenRevision: number;
|
|
49
|
+
}
|
|
50
|
+
/** A K8 retention row (#798), `commands` included, with its absolute expiry. The importer keeps the expiry. */
|
|
51
|
+
export interface ArchivedRecord {
|
|
52
|
+
namespace: string;
|
|
53
|
+
id: string;
|
|
54
|
+
body: Json;
|
|
55
|
+
expiresAt?: number;
|
|
56
|
+
}
|
|
57
|
+
/** An accepted Agent message of one task: the K4 execution's `messageReceipt`. */
|
|
58
|
+
export interface MessageReceipt {
|
|
59
|
+
messageId: string;
|
|
60
|
+
contentHash: string;
|
|
61
|
+
}
|
|
62
|
+
/** The K4 execution facts of one earlier generation of an intent. K4 begins each generation before it opens the next. */
|
|
63
|
+
export interface ExecutionRecord {
|
|
64
|
+
submission: 'uncertain' | 'delivered';
|
|
65
|
+
started: boolean;
|
|
66
|
+
attempt: Json;
|
|
67
|
+
terminal: Json;
|
|
68
|
+
messageReceipt?: MessageReceipt;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A concluded intent, moved as a row: L K4 `intents` and `executions[taskId]` with K8 `hostIntents`, H `intent`. `input` is
|
|
72
|
+
* the frozen execution input that was submitted, a sealed one still sealed. A late terminal or message for it is refused
|
|
73
|
+
* by its conclusion; one for a compacted intent, by its `intent` tombstone.
|
|
74
|
+
*
|
|
75
|
+
* `earlierExecutions` holds generations 0 to `generation - 1`, in order, each with the execution facts K4 stores
|
|
76
|
+
* (#975 D1). Its task id is `hash([key, generation])` and its input is `input` with that task id, so neither is stored.
|
|
77
|
+
* K4 compacts an intent only with the execution of every generation (`ledger.ts` compact: `Missing execution evidence`).
|
|
78
|
+
* A message for an earlier task is answered from its execution, by its receipt or else `stale_generation`, never
|
|
79
|
+
* `unknown_task` (`core.ts` consumeMessage); H stores the same generations in its H slice. Nothing here relies on a
|
|
80
|
+
* replay after the switch getting `accepted`: the target's SDK passes an Agent message to the Host only when its own
|
|
81
|
+
* stores hold the device's task and offer binding (`packages/cloud` `inbound.ts`), which this export does not carry and
|
|
82
|
+
* no code moves.
|
|
83
|
+
*
|
|
84
|
+
* Each receipt, current or earlier, is the same fact as the K8 accepted reply of its task id, so the two must agree. A
|
|
85
|
+
* `reserved` intent is in generation 0 and was never submitted: K4 begins a new generation in the transaction that
|
|
86
|
+
* opens it. So K4 `attempts` is not carried: it is `generation + 1` once the intent began, and 0 while `reserved`.
|
|
87
|
+
*
|
|
88
|
+
* The scheduler cursors of a concluded row are not carried either (#975 D6, the one exception to "no defaults"): K4
|
|
89
|
+
* `phase` and `notBefore`, H `tries`, `next_at`, `reconcile_at` and `last_error`. Nothing reads them on a concluded row,
|
|
90
|
+
* so a target writes its own initial values of a new row.
|
|
91
|
+
*/
|
|
92
|
+
export interface IntentRecord {
|
|
93
|
+
key: string;
|
|
94
|
+
source: 'user' | 'bot' | 'routine';
|
|
95
|
+
handler?: string;
|
|
96
|
+
ordinal: number;
|
|
97
|
+
taskId: string;
|
|
98
|
+
generation: number;
|
|
99
|
+
input: Json;
|
|
100
|
+
waitUntil: number;
|
|
101
|
+
retry: RetryPolicy;
|
|
102
|
+
submission: 'reserved' | 'uncertain' | 'delivered';
|
|
103
|
+
started: boolean;
|
|
104
|
+
attempt?: Json;
|
|
105
|
+
terminal?: Json;
|
|
106
|
+
messageReceipt?: MessageReceipt;
|
|
107
|
+
earlierExecutions: ExecutionRecord[];
|
|
108
|
+
preparationError?: string;
|
|
109
|
+
memoryBlocked?: NonNullable<Intent['memoryBlocked']>;
|
|
110
|
+
cancelReason?: 'expired' | 'cancelled';
|
|
111
|
+
retryUntil?: number;
|
|
112
|
+
conclusion: Conclusion;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A routine: L K4 `routines`, H `routine`. `ordinal` is its position in the section, exactly 0 to n - 1: K4 stores only the
|
|
116
|
+
* insertion order. `nextAt` is the planned slot. The schedule retry fields and `lastError` are K4's pacing of a slot past
|
|
117
|
+
* the SDK's furthest wake, and `lastError` is never cleared.
|
|
118
|
+
*/
|
|
119
|
+
export interface RoutineRecord {
|
|
120
|
+
id: string;
|
|
121
|
+
ordinal: number;
|
|
122
|
+
definition: RoutineDefinition;
|
|
123
|
+
pending?: RoutineDefinition;
|
|
124
|
+
lifecycle: Routine['lifecycle'];
|
|
125
|
+
status: Routine['status'];
|
|
126
|
+
nextAt: number | null;
|
|
127
|
+
calendarErrors?: NonNullable<Routine['calendarErrors']>;
|
|
128
|
+
scheduleRetryAt?: number;
|
|
129
|
+
scheduleRetryCount?: number;
|
|
130
|
+
lastError?: NonNullable<Routine['lastError']>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* An occurrence: L K4 `occurrences`, H `occurrence`, with `ordinal` its position as a routine's. `job` is a Host job's tries and
|
|
134
|
+
* summary, `null` for an occurrence hook. `conclusion` is set only on one with no intent; a promoted one has its intent's.
|
|
135
|
+
* K4 `attempts` is not carried: it is its intent's, or 0. `slotReplayCount` counts redelivered wakes of its slot.
|
|
136
|
+
*/
|
|
137
|
+
export interface OccurrenceRecord {
|
|
138
|
+
key: string;
|
|
139
|
+
ordinal: number;
|
|
140
|
+
routineId: string;
|
|
141
|
+
definitionVersion: number;
|
|
142
|
+
trigger: Occurrence['trigger'];
|
|
143
|
+
recordedAt: number;
|
|
144
|
+
nextAt: number | null;
|
|
145
|
+
job: {
|
|
146
|
+
attempts: number;
|
|
147
|
+
summary?: Json;
|
|
148
|
+
} | null;
|
|
149
|
+
executionSuperseded: boolean;
|
|
150
|
+
conclusion?: Conclusion;
|
|
151
|
+
slotReplayCount?: number;
|
|
152
|
+
}
|
|
153
|
+
/** A pending Host job of an open occurrence. The target runs it again, as K4 does after a crash. */
|
|
154
|
+
export interface OutboxRecord {
|
|
155
|
+
kind: 'host-job';
|
|
156
|
+
occurrenceKey: string;
|
|
157
|
+
}
|
|
158
|
+
/** A permanent or expiring tombstone in the K4 scheme: the digest of the retired identity, by kind. */
|
|
159
|
+
export interface TombstoneRecord {
|
|
160
|
+
kind: 'intent' | 'row' | 'slot' | 'application';
|
|
161
|
+
digest: string;
|
|
162
|
+
expiresAt?: number;
|
|
163
|
+
}
|
|
164
|
+
export interface SwitchContent {
|
|
165
|
+
version: typeof SWITCH_EXPORT_VERSION;
|
|
166
|
+
source: 'L' | 'H';
|
|
167
|
+
domain: string;
|
|
168
|
+
devices: SwitchDevice[];
|
|
169
|
+
exportedAt: number;
|
|
170
|
+
/**
|
|
171
|
+
* The live state. The source Host's owner records (L `topology`, L `hostIntents`, now on each intent) and L's switch
|
|
172
|
+
* records (`switchExport`, `switchImport`) are not part of it.
|
|
173
|
+
*/
|
|
174
|
+
collaboration: CollaborationState;
|
|
175
|
+
archived: ArchivedRecord[];
|
|
176
|
+
intents: IntentRecord[];
|
|
177
|
+
routines: RoutineRecord[];
|
|
178
|
+
occurrences: OccurrenceRecord[];
|
|
179
|
+
outbox: OutboxRecord[];
|
|
180
|
+
tombstones: TombstoneRecord[];
|
|
181
|
+
}
|
|
182
|
+
/** The count and digest of each section, and `digest` over them and the header: the identity of one export. */
|
|
183
|
+
export interface SwitchManifest {
|
|
184
|
+
counts: Record<SwitchSection, number>;
|
|
185
|
+
digests: Record<SwitchSection, string>;
|
|
186
|
+
digest: string;
|
|
187
|
+
}
|
|
188
|
+
export interface SwitchExport extends SwitchContent {
|
|
189
|
+
manifest: SwitchManifest;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* K4 `attempts`, which the format does not carry (#975 D5): one per generation begun, so 0 while the intent is `reserved`
|
|
193
|
+
* and `generation + 1` once it began. An occurrence has its intent's, and 0 without one. Both builders and both importers
|
|
194
|
+
* use it.
|
|
195
|
+
*/
|
|
196
|
+
export declare function switchAttempts(intent: Pick<IntentRecord, 'submission' | 'generation'> | undefined): number;
|
|
197
|
+
export type SwitchExportRefusal = 'invalid' | 'unsorted' | 'duplicate' | 'reference' | 'receipt_mismatch' | 'owner_record' | 'device_missing' | 'open_work' | 'home_sent' | 'projection_pending' | 'card_call' | 'execution_routine' | 'manifest';
|
|
198
|
+
/** An export that the format refuses. Nothing may be imported or committed from it. */
|
|
199
|
+
export declare class SwitchExportError extends Error {
|
|
200
|
+
readonly reason: SwitchExportRefusal;
|
|
201
|
+
readonly code: 'switch_export_refused';
|
|
202
|
+
constructor(reason: SwitchExportRefusal, message: string);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Seals the old owner's content: checks it, orders each section by its identity and computes the manifest. Returns a new
|
|
206
|
+
* document; the content is not changed. Throws `SwitchExportError` for content that no target may import.
|
|
207
|
+
*/
|
|
208
|
+
export declare function sealSwitchExport(content: SwitchContent): SwitchExport;
|
|
209
|
+
/**
|
|
210
|
+
* Verifies a document before an import, and the new owner's read-back after it: the format checks, each section in its
|
|
211
|
+
* one order with unique identities, and the manifest recomputed from the content. Returns the manifest.
|
|
212
|
+
*/
|
|
213
|
+
export declare function verifySwitchExport(document: SwitchExport): SwitchManifest;
|
|
214
|
+
/** The header fields of a document: the source's, also on the target's read-back. */
|
|
215
|
+
export type SwitchHeader = Pick<SwitchContent, 'source' | 'domain' | 'devices' | 'exportedAt'>;
|
|
216
|
+
/** What a new owner returns after its read-back: the digest the old owner commits away on. */
|
|
217
|
+
export interface SwitchReceipt {
|
|
218
|
+
digest: string;
|
|
219
|
+
devices: string[];
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The export record of an old owner (an L ledger or `scope.switch_export` of H): from the export on, also after the
|
|
223
|
+
* commit, so the domain keeps the exported state. `devices` and `exportedAt` are the document's header.
|
|
224
|
+
*/
|
|
225
|
+
export interface SwitchExportMark {
|
|
226
|
+
digest: string;
|
|
227
|
+
exportedAt: number;
|
|
228
|
+
devices: SwitchDevice[];
|
|
229
|
+
}
|
|
230
|
+
/** The domain was exported for a switch, so its owner writes nothing to it. Abort the switch to resume it. Nothing was written. */
|
|
231
|
+
export declare class SwitchExportedError extends Error {
|
|
232
|
+
readonly digest: string;
|
|
233
|
+
readonly code: 'switch_exported';
|
|
234
|
+
constructor(digest: string);
|
|
235
|
+
}
|
|
236
|
+
/** The domain holds a switch import that is not committed yet, so no work runs on it. Nothing was written. */
|
|
237
|
+
export declare class SwitchImportedError extends Error {
|
|
238
|
+
readonly digest: string;
|
|
239
|
+
readonly code: 'switch_imported';
|
|
240
|
+
constructor(digest: string);
|
|
241
|
+
}
|
|
242
|
+
/** The device is frozen for an owner switch. A retry after the switch may succeed. */
|
|
243
|
+
export declare class DeviceSwitchingError extends Error {
|
|
244
|
+
readonly deviceId: string;
|
|
245
|
+
readonly target: 'L' | 'H';
|
|
246
|
+
readonly revision: number;
|
|
247
|
+
readonly code = "device_switching";
|
|
248
|
+
constructor(deviceId: string, target: 'L' | 'H', revision: number);
|
|
249
|
+
}
|
|
250
|
+
/** A stored export mark, checked field by field: a malformed one fails closed. */
|
|
251
|
+
export declare function exportMarkOf(value: unknown): SwitchExportMark;
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ResultSchema } from '@byok-sdk/protocol';
|
|
2
|
+
import { type TeamState } from './team-model.js';
|
|
3
|
+
import type { Json } from '@byok-sdk/server/execution-core';
|
|
4
|
+
import type { ChannelState } from './delivery-routing.js';
|
|
5
|
+
import type { InputBatch, UserInput } from './rules/coalesce.js';
|
|
6
|
+
import { type Budget, type Card, type Question, type Rejection, type Turn } from './rules/turn.js';
|
|
7
|
+
import type { AcceptedReply, Batch, Delegation, Unit } from './rules/delegation.js';
|
|
8
|
+
import type { CommandRecord } from './rules/commit.js';
|
|
9
|
+
import type { DeviceTopology } from './topology.js';
|
|
10
|
+
import type { SwitchExportMark } from './migration.js';
|
|
11
|
+
import type { SwitchImport } from './switch.js';
|
|
12
|
+
import type { AutonomyState, WouldDo } from './rules/autonomy.js';
|
|
13
|
+
import type { DreamState } from './dream.js';
|
|
14
|
+
export type { Authority, InputBatch, SealReason, UserInput } from './rules/coalesce.js';
|
|
15
|
+
export { addBatchTurns, addTurn, json } from './rules/turn.js';
|
|
16
|
+
export type { Budget, Card, Question, Rejection, ReplyEntry, Turn, TurnFields, Verdict } from './rules/turn.js';
|
|
17
|
+
export type { AcceptedReply, Batch, Delegation, DelegationCancel, Unit } from './rules/delegation.js';
|
|
18
|
+
/**
|
|
19
|
+
* Version 3 (#798): retention moves settled rows out of this state into K4 application rows, so a version 2 writer
|
|
20
|
+
* would read archived evidence as absent. Bot routines are K4 routines with the `bot-routine` occurrence hook.
|
|
21
|
+
*/
|
|
22
|
+
export interface CollaborationState extends AutonomyState {
|
|
23
|
+
version: 3;
|
|
24
|
+
team: TeamState;
|
|
25
|
+
turns: Record<string, Turn>;
|
|
26
|
+
budgets: Record<string, Budget>;
|
|
27
|
+
delegations: Record<string, Delegation>;
|
|
28
|
+
batches: Record<string, Batch>;
|
|
29
|
+
units: Record<string, Unit>;
|
|
30
|
+
replies: Record<string, AcceptedReply>;
|
|
31
|
+
schemas: Record<string, ResultSchema>;
|
|
32
|
+
questions: Record<string, Question>;
|
|
33
|
+
cards: Record<string, Card>;
|
|
34
|
+
rejected: Rejection[];
|
|
35
|
+
audit: string[];
|
|
36
|
+
sequence: number;
|
|
37
|
+
/** Input coalescing. Both appear at the first coalesced input. */
|
|
38
|
+
inputs?: Record<string, UserInput>;
|
|
39
|
+
inputBatches?: Record<string, InputBatch>;
|
|
40
|
+
/** Host-only routes and final-content outbox. Never included in ContextPack or projections. */
|
|
41
|
+
channel?: ChannelState;
|
|
42
|
+
/**
|
|
43
|
+
* Commit contract (#739 D1). Both appear at the first commit; a state without them is at revision 0.
|
|
44
|
+
* `commands` holds the dedup evidence of owner commands. K4 deduplicates terminals and messages itself.
|
|
45
|
+
*/
|
|
46
|
+
revision?: number;
|
|
47
|
+
commands?: Record<string, CommandRecord>;
|
|
48
|
+
/**
|
|
49
|
+
* Host intents (#882): the handler name of each Host-owned K4 intent, by intent key. A record lives as long as K4
|
|
50
|
+
* keeps its intent. It appears at the first Host intent, so an older ledger reads an empty table.
|
|
51
|
+
*/
|
|
52
|
+
hostIntents?: Record<string, {
|
|
53
|
+
handler: string;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* L card call claims (#958): a card id is here from the transaction before its connector call until the one that settles
|
|
57
|
+
* it. It appears at the first claim, so an older ledger reads an empty table. Never in ContextPack or projections.
|
|
58
|
+
*/
|
|
59
|
+
cardCalls?: Record<string, true>;
|
|
60
|
+
/**
|
|
61
|
+
* L owner records by device id (#957, §4.1), from `topology.ts`. A device appears at its first switch step, so an older
|
|
62
|
+
* ledger reads every device as L at revision 0. Never in ContextPack or projections.
|
|
63
|
+
*/
|
|
64
|
+
topology?: Record<string, DeviceTopology>;
|
|
65
|
+
/**
|
|
66
|
+
* L switch records (#975), from `switch.ts`. `switchExport` appears at the export of an old owner and stays; while it is
|
|
67
|
+
* here the Host writes nothing. `switchImport` is here from the load of a new owner until its commit toward L. Neither
|
|
68
|
+
* moves in an export, and neither is in ContextPack or projections.
|
|
69
|
+
*/
|
|
70
|
+
switchExport?: SwitchExportMark;
|
|
71
|
+
switchImport?: SwitchImport;
|
|
72
|
+
/**
|
|
73
|
+
* Would-do rows of observing Bots (#1229), keyed by `wouldDoId(taskId, action, index)`. They appear at the first
|
|
74
|
+
* observed action, so an older ledger reads none. They are Host UI history, never part of the Bot's ContextPack or wire.
|
|
75
|
+
*/
|
|
76
|
+
wouldDo?: Record<string, WouldDo>;
|
|
77
|
+
/**
|
|
78
|
+
* Dreaming (#1475), from `dream.ts`: the owner of each dream intent and the last result of each Bot. It appears at the first
|
|
79
|
+
* dream routine, so an older ledger reads none. Never in ContextPack or projections.
|
|
80
|
+
*/
|
|
81
|
+
dreams?: DreamState;
|
|
82
|
+
}
|
|
83
|
+
/** A state version this build cannot adopt without a new ledger. */
|
|
84
|
+
export declare class OldCollaborationStateError extends Error {
|
|
85
|
+
readonly foundVersion: 1 | 2;
|
|
86
|
+
readonly code: 'collaboration_state_unsupported_old';
|
|
87
|
+
constructor(foundVersion: 1 | 2, message: string);
|
|
88
|
+
}
|
|
89
|
+
export declare function stateOf(application: Record<string, Json>): CollaborationState;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Json } from '@byok-sdk/server/execution-core';
|
|
2
|
+
import type { CollaborationState } from './model.js';
|
|
3
|
+
import { type RetentionInput, type RetentionLimits, type RetentionResult } from './retention.js';
|
|
4
|
+
import type { CommitSubject } from './commit-vectors.test-support.js';
|
|
5
|
+
/**
|
|
6
|
+
* #798 retention vectors. Each store runs the same cases: the memory rules and the K8 L ledger now, the H adapter in D2.
|
|
7
|
+
* A subject starts from `seedCollaboration`. The cases see only `commit`, `retain`, `state` and `stored`, not the row layout.
|
|
8
|
+
*/
|
|
9
|
+
export interface RetentionSubject extends CommitSubject {
|
|
10
|
+
retain(input: RetentionInput, limits: RetentionLimits): RetentionResult | Promise<RetentionResult>;
|
|
11
|
+
/** Writes the stored collaboration state directly, as the Host's passes do. */
|
|
12
|
+
change(edit: (state: CollaborationState) => void): void | Promise<void>;
|
|
13
|
+
/** The archived row of `namespace` and `id`, as the store's application row port reads it. */
|
|
14
|
+
archived(namespace: string, id: string): Json | undefined | Promise<Json | undefined>;
|
|
15
|
+
}
|
|
16
|
+
export declare const RETENTION_NOW = 10000;
|
|
17
|
+
export declare function retentionVectors(name: string, open: () => RetentionSubject | Promise<RetentionSubject>): void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type HandoffPackBudgets } from '@byok-sdk/protocol';
|
|
2
|
+
import { type Json } from '@byok-sdk/server/execution-core';
|
|
3
|
+
import type { CollaborationState } from './model.js';
|
|
4
|
+
/**
|
|
5
|
+
* Explicit retention (#798). The Host acknowledges settled roots. One call moves every row of each root out of the
|
|
6
|
+
* state into per-id rows, and retires the root's Turn, input and round ids for good. It never runs on its own.
|
|
7
|
+
* Command records answer replays for `retentionMs` after they move; the other rows stay.
|
|
8
|
+
*/
|
|
9
|
+
export interface RetentionInput {
|
|
10
|
+
/**
|
|
11
|
+
* Root ids: the `root` field of a Turn projection, or the round root that `roomInput` and a room `receive` return.
|
|
12
|
+
* A room seat Turn shows its seat id as `root`; it is refused with `seat_root` and its `roundRoot`.
|
|
13
|
+
* A root that is already archived counts again harmlessly.
|
|
14
|
+
*/
|
|
15
|
+
acknowledgedRoots: readonly string[];
|
|
16
|
+
now: number;
|
|
17
|
+
/** At least seven days: the replay window of the moved command records. */
|
|
18
|
+
retentionMs: number;
|
|
19
|
+
}
|
|
20
|
+
/** The ContextPack limits of the Host. Rows in the window of a Bot stay in the state. */
|
|
21
|
+
export interface RetentionLimits {
|
|
22
|
+
contextTurnLimit: number;
|
|
23
|
+
/** The budgets of the Bot history: the ones the Host freezes with, so its Turns read only what stays. */
|
|
24
|
+
handoff: HandoffPackBudgets;
|
|
25
|
+
}
|
|
26
|
+
/** K4 facts by Turn id. */
|
|
27
|
+
export interface RetentionFacts {
|
|
28
|
+
/** The Turn still has its K4 intent. */
|
|
29
|
+
hasIntent(turnId: string): boolean;
|
|
30
|
+
/** The routine occurrence of a routine Turn is not concluded yet. */
|
|
31
|
+
occurrenceOpen(turnId: string): boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Where retention writes, in the same transaction as the state. L: the K4 application row port. */
|
|
34
|
+
export interface RetentionStore {
|
|
35
|
+
put(namespace: string, id: string, value: Json, expiresAt?: number): void;
|
|
36
|
+
expire(namespace: string, now: number): number;
|
|
37
|
+
retire(namespace: string, id: string): void;
|
|
38
|
+
isRetired(namespace: string, id: string): boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface RetentionResult {
|
|
41
|
+
archivedRoots: number;
|
|
42
|
+
alreadyArchivedRoots: number;
|
|
43
|
+
archivedRows: number;
|
|
44
|
+
archivedCommands: number;
|
|
45
|
+
expiredCommands: number;
|
|
46
|
+
beforeBytes: number;
|
|
47
|
+
afterBytes: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The whole call changes nothing. `protected_root`: the root is still in use; acknowledge it again after it settles.
|
|
51
|
+
* `seat_root`: the id is a room seat Turn, which belongs to its round's root. Acknowledge `roundRoot` instead; a retry of
|
|
52
|
+
* the seat id fails the same way each time.
|
|
53
|
+
*/
|
|
54
|
+
export type RetentionRefusedCode = 'protected_root' | 'seat_root';
|
|
55
|
+
export declare class RetentionRefused extends Error {
|
|
56
|
+
readonly code: RetentionRefusedCode;
|
|
57
|
+
readonly root: string;
|
|
58
|
+
readonly roundRoot?: string | undefined;
|
|
59
|
+
constructor(code: RetentionRefusedCode, root: string, reason: string, roundRoot?: string | undefined);
|
|
60
|
+
}
|
|
61
|
+
export declare function retainRoots(state: CollaborationState, input: RetentionInput, limits: RetentionLimits, facts: RetentionFacts, store: RetentionStore): RetentionResult;
|
package/dist/rooms.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BotTurnOutcome } from '@byok-sdk/protocol';
|
|
2
|
+
import { type LedgerState } from '@byok-sdk/server/execution-core';
|
|
3
|
+
import type { Publish } from './rules/delegation.js';
|
|
4
|
+
import { type CollaborationState, type Turn } from './model.js';
|
|
5
|
+
import * as rules from './rules/rooms.js';
|
|
6
|
+
import type { AutonomyGate } from './rules/autonomy.js';
|
|
7
|
+
export { DEFAULT_MEMBER_MENTIONS, ROOM_GRACE_MS, memberMentions, memberPresent, roomContext, roomMessageProjection, roomMessages, roomVisibility, type MemberMentions, type Mentions, type RoomMessage } from './rules/rooms.js';
|
|
8
|
+
export { ROOM_CONTEXT_BYTES, ROOM_CONTEXT_MESSAGES } from './rules/rooms.js';
|
|
9
|
+
export declare function roomInput(state: CollaborationState, key: string, roomId: string, text: string, mentions: rules.Mentions, publish: Publish, from?: string): string;
|
|
10
|
+
export declare function applySpeech(state: CollaborationState, turn: Turn, document: BotTurnOutcome, taskId: string, now: number, publish: Publish, accept: (action: string, work: () => void) => void, gate: AutonomyGate): void;
|
|
11
|
+
/**
|
|
12
|
+
* Seat facts come from the K4 intent and execution of each seat Turn. A cancel of admitted work sets
|
|
13
|
+
* the K4 `cancelReason`; a seat Turn without an intent fails at once. Then the new seat Turns are added.
|
|
14
|
+
*/
|
|
15
|
+
export declare function advanceRooms(s: LedgerState, state: CollaborationState, now: number, add: (id: string, botId: string, request: string) => void, publish: Publish): void;
|
|
16
|
+
/**
|
|
17
|
+
* The room step and the Turn steps of L's sync (K8 host.ts `sync`). A Turn step can release a seat (a blocked or retired seat
|
|
18
|
+
* Turn), so the room step then runs again and the next seat gets its Turn in this sync, as H's sync does (#876). Only
|
|
19
|
+
* `reserve` sets `released = false`, and a sync never reserves, so each seat adds at most one more round. Returns whether any
|
|
20
|
+
* Turn step returned true.
|
|
21
|
+
*/
|
|
22
|
+
export declare function advanceRoomsAndTurns(s: LedgerState, state: CollaborationState, now: number, step: (turn: Turn) => boolean, publish: Publish): boolean;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type RoutineScheduleFields, type UpdateRoutineAction } from '@byok-sdk/protocol';
|
|
2
|
+
import { type Conclusion, type Intent, type Json, type Occurrence, type Routine } from '@byok-sdk/server/execution-core';
|
|
3
|
+
import { type CollaborationState } from './model.js';
|
|
4
|
+
/**
|
|
5
|
+
* #793 D2f routine vectors. Each Host runs the same cases: the K8 L ledger now, and the H store in D2f-3.
|
|
6
|
+
* A subject sees only Host verbs and the row views below, not its row layout. The views are the H projection of the K4
|
|
7
|
+
* rows (scheduler note §2.0): K4 fields with no H reader are left out. A subject may be async.
|
|
8
|
+
* Each verb that writes (`input`, `finish`, `fire`, `cancelTurn`, `update`, `lifecycle`, `end`) ends by running the Host as `sync` does,
|
|
9
|
+
* so the cases read promotions, claims and switches right after it.
|
|
10
|
+
*/
|
|
11
|
+
export interface RoutineSubject {
|
|
12
|
+
/** The Host clock. The subject picks the start, because the L SDK keeps real time. */
|
|
13
|
+
now(): number;
|
|
14
|
+
at(now: number): void;
|
|
15
|
+
/** A test edit of the stored collaboration state, outside the contract. */
|
|
16
|
+
change(edit: (state: CollaborationState) => void): void | Promise<void>;
|
|
17
|
+
/** A test write of the tombstone that retention leaves for Turn id `turnId` (#798), outside the contract. */
|
|
18
|
+
retire(turnId: string): void | Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* A test write of one routine of Bot `owner`, outside the contract: the K4 create command with the K8 Bot definition, as an
|
|
21
|
+
* outcome of that Bot's Turn writes it. Returns the routine id. The other cases create routines through Bot `main`'s outcomes.
|
|
22
|
+
*/
|
|
23
|
+
addRoutine(owner: string, schedule: RoutineScheduleFields): Promise<string>;
|
|
24
|
+
/** An owner input to Bot `main`. Returns its Turn id once the Host has run it. */
|
|
25
|
+
input(key: string, request: string): Promise<string>;
|
|
26
|
+
/** Waits until the device has claimed the Turn's intent. Then the intent is tried (K4 `attempts > 0`, H `tries > 0`). */
|
|
27
|
+
start(turnId: string): Promise<void>;
|
|
28
|
+
/** Completes a started Turn with this outcome document, and runs the Host. */
|
|
29
|
+
finish(turnId: string, document: Json): Promise<void>;
|
|
30
|
+
/** Fires the due slot of routine `id` at the clock: L delivers its reserved wake, H runs a scheduler pass. */
|
|
31
|
+
fire(id: string): Promise<void>;
|
|
32
|
+
/** Runs the Host: sync, promotion, claims and expiries. */
|
|
33
|
+
sync(): Promise<void>;
|
|
34
|
+
cancelTurn(turnId: string): Promise<void>;
|
|
35
|
+
/** The owner routine API of the Main Bot. */
|
|
36
|
+
update(action: UpdateRoutineAction): Promise<void>;
|
|
37
|
+
lifecycle(id: string, value: Routine['lifecycle']): Promise<void>;
|
|
38
|
+
/** The keyless `end_routine` command of Bot `main` (§55c). */
|
|
39
|
+
end(id: string): Promise<void>;
|
|
40
|
+
routine(id: string): RoutineRow | undefined | Promise<RoutineRow | undefined>;
|
|
41
|
+
/** The slot times that the Host still holds to fire routine `id`: L's pending SDK wakes, H's `routine_due` scan rows. */
|
|
42
|
+
reserved(id: string): Promise<number[]>;
|
|
43
|
+
/** The occurrences of a routine, by planned time. */
|
|
44
|
+
occurrences(id: string): OccurrenceRow[] | Promise<OccurrenceRow[]>;
|
|
45
|
+
intent(key: string): RoutineIntentRow | undefined | Promise<RoutineIntentRow | undefined>;
|
|
46
|
+
state(): CollaborationState | Promise<CollaborationState>;
|
|
47
|
+
}
|
|
48
|
+
export interface RoutineRow {
|
|
49
|
+
id: string;
|
|
50
|
+
version: number;
|
|
51
|
+
pending: number | null;
|
|
52
|
+
lifecycle: Routine['lifecycle'];
|
|
53
|
+
status: Routine['status'];
|
|
54
|
+
nextAt: number | null;
|
|
55
|
+
calendarErrors: number;
|
|
56
|
+
}
|
|
57
|
+
export interface OccurrenceRow {
|
|
58
|
+
key: string;
|
|
59
|
+
routineId: string;
|
|
60
|
+
version: number;
|
|
61
|
+
trigger: Occurrence['trigger'];
|
|
62
|
+
recordedAt: number;
|
|
63
|
+
nextAt: number | null;
|
|
64
|
+
executionSuperseded: boolean;
|
|
65
|
+
promoted: boolean;
|
|
66
|
+
conclusion: Conclusion | null;
|
|
67
|
+
}
|
|
68
|
+
export interface RoutineIntentRow {
|
|
69
|
+
key: string;
|
|
70
|
+
source: Intent['source'];
|
|
71
|
+
waitUntil: number;
|
|
72
|
+
retryUntil: number | null;
|
|
73
|
+
conclusion: Conclusion | null;
|
|
74
|
+
tried: boolean;
|
|
75
|
+
instruction: string;
|
|
76
|
+
}
|
|
77
|
+
/** The H view of a K4 routine row. */
|
|
78
|
+
export declare function routineView(routine: Readonly<Routine>): RoutineRow;
|
|
79
|
+
/** The H view of a K4 occurrence. A promoted occurrence takes its conclusion from its intent (DDL D5). */
|
|
80
|
+
export declare function occurrenceView(occurrence: Readonly<Occurrence>, intent?: Readonly<Pick<Intent, 'conclusion'>>): OccurrenceRow;
|
|
81
|
+
export declare function routineVectors(name: string, open: () => RoutineSubject | Promise<RoutineSubject>): void;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type CreateRoutineAction, type RoutineScheduleFields, type UpdateRoutineAction } from '@byok-sdk/protocol';
|
|
2
|
+
import { type ExecutionTemplate, type HostOccurrenceRoutineDefinition, type HostOccurrenceRun, type LedgerState, type NextOccurrence, type Routine } from '@byok-sdk/server/execution-core';
|
|
3
|
+
import { type Authority, type CollaborationState, type Turn } from './model.js';
|
|
4
|
+
import type { SealedRoutineTemplate } from './rules/sync.js';
|
|
5
|
+
import type { SealedRoutineRef } from './rules/turn.js';
|
|
6
|
+
import type { DreamState } from './dream.js';
|
|
7
|
+
export type { SealedRoutineTemplate } from './rules/sync.js';
|
|
8
|
+
/** The K4 occurrence hook of Bot routines. Other K4 routines of the Host are not Bot routines. */
|
|
9
|
+
export declare const BOT_ROUTINE = "bot-routine";
|
|
10
|
+
/** The K4 occurrence hook of dream routines (`dream.ts`). Bot policy never reads these rows. */
|
|
11
|
+
export declare const BOT_DREAM = "bot-dream";
|
|
12
|
+
/** A routine Turn expires this long after K4 records its occurrence. */
|
|
13
|
+
export declare const ROUTINE_WAIT_MS = 300000;
|
|
14
|
+
/** A delivery later than this after its planned time is a catch-up. */
|
|
15
|
+
export declare const ROUTINE_LATE_AFTER_MS = 60000;
|
|
16
|
+
/** Fixed at creation. Owner and authority never change between versions, and a routine stays plain or sealed. */
|
|
17
|
+
export type BotRoutineInput = {
|
|
18
|
+
owner: string;
|
|
19
|
+
authority: Authority;
|
|
20
|
+
prompt: string;
|
|
21
|
+
} | {
|
|
22
|
+
owner: string;
|
|
23
|
+
authority: 'owner';
|
|
24
|
+
sealed: SealedRoutineTemplate;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* What the owner's member endpoint sends to create or reseal a routine: the schedule and one template, sealed for routine
|
|
28
|
+
* `routineId` version `definitionVersion`.
|
|
29
|
+
*/
|
|
30
|
+
export interface SealedRoutineAction {
|
|
31
|
+
routineId: string;
|
|
32
|
+
definitionVersion: number;
|
|
33
|
+
schedule: RoutineScheduleFields;
|
|
34
|
+
sealed: SealedRoutineTemplate;
|
|
35
|
+
}
|
|
36
|
+
/** The member sealed for another version than the one this command stages. Nothing is written; read the routine again. */
|
|
37
|
+
export declare class SealedRoutineVersionError extends Error {
|
|
38
|
+
readonly expected: number;
|
|
39
|
+
readonly code = "sealed_routine_version";
|
|
40
|
+
constructor(expected: number);
|
|
41
|
+
}
|
|
42
|
+
/** The ContextPack view of one Bot routine. */
|
|
43
|
+
export interface BotRoutine {
|
|
44
|
+
id: string;
|
|
45
|
+
owner: string;
|
|
46
|
+
current: number;
|
|
47
|
+
pending: number | null;
|
|
48
|
+
lifecycle: Routine['lifecycle'];
|
|
49
|
+
status: Routine['status'];
|
|
50
|
+
/** A sealed routine has no `prompt` and shows nothing else of its template: the view goes into each ContextPack. */
|
|
51
|
+
definition: {
|
|
52
|
+
version: number;
|
|
53
|
+
schedule: RoutineScheduleFields;
|
|
54
|
+
prompt?: string;
|
|
55
|
+
sealed?: true;
|
|
56
|
+
target: string;
|
|
57
|
+
};
|
|
58
|
+
lastError?: {
|
|
59
|
+
at: number;
|
|
60
|
+
message: string;
|
|
61
|
+
wakeKey?: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export declare const dreamTable: (state: CollaborationState) => DreamState;
|
|
65
|
+
/** The K4 calendar of the Bot Host core. A rule is a `RoutineSchedule` whose `tz` is the definition time zone. */
|
|
66
|
+
export declare const routineCalendar: NextOccurrence;
|
|
67
|
+
/** The owner `updateRoutine` API. An outcome's update_routine passed the contract, which refuses the same as this. */
|
|
68
|
+
export declare function ownerRoutineUpdate(action: UpdateRoutineAction): UpdateRoutineAction;
|
|
69
|
+
/** The Bot routines among the Host's K4 routine rows. */
|
|
70
|
+
export declare function botRoutines(routines: Iterable<Routine>): BotRoutine[];
|
|
71
|
+
/** The definition for `RoutineCommands.create`. Each owner has at most 8 routines that are not completed. */
|
|
72
|
+
export declare function createDefinition(routines: readonly Routine[], owner: string, taskId: string, index: number, action: CreateRoutineAction, authority: Authority): HostOccurrenceRoutineDefinition;
|
|
73
|
+
export declare function owned(routines: readonly Routine[], owner: string, id: string): Routine;
|
|
74
|
+
/**
|
|
75
|
+
* The routine that `end_routine` completes (§55c): any Bot routine that is open, whatever its owner, so the Main Bot can end
|
|
76
|
+
* the routine of an archived Bot. The command checks the Main Bot role.
|
|
77
|
+
*/
|
|
78
|
+
export declare function endable(routines: readonly Routine[], id: string): Routine;
|
|
79
|
+
/** The next version for `RoutineCommands.update`. It builds on `pending` when one is staged. */
|
|
80
|
+
export declare function updateDefinition(routines: readonly Routine[], owner: string, action: UpdateRoutineAction): HostOccurrenceRoutineDefinition;
|
|
81
|
+
/**
|
|
82
|
+
* The member side of a sealed Bot routine: the whole Turn instruction it seals. It is the K8 Bot Turn frame with every
|
|
83
|
+
* action and no ContextPack, because v1 has no plaintext field for Host content next to a sealed instruction. The Turn's
|
|
84
|
+
* frozen outcome schema stays the authority on which actions the Bot may take.
|
|
85
|
+
*/
|
|
86
|
+
export declare function sealedRoutineInstruction(prompt: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* The definition of a new sealed routine. The member picks `routineId` (a fresh UUID), because the template binds it, and
|
|
89
|
+
* seals version 1. An id that any routine row already has is refused, whatever its lifecycle, except an exact retry: the
|
|
90
|
+
* version 1 that the same command made, which K4 `create` takes as a no-op. It counts toward the limit of 8 open routines
|
|
91
|
+
* of the owner.
|
|
92
|
+
*/
|
|
93
|
+
export declare function sealedDefinition(routines: readonly Routine[], owner: string, action: SealedRoutineAction, execution: ExecutionTemplate): HostOccurrenceRoutineDefinition;
|
|
94
|
+
/**
|
|
95
|
+
* The next version of a sealed routine, with a new template. Only a routine that is already sealed takes one, and it keeps
|
|
96
|
+
* its owner and authority. The template must be sealed for `max(current, pending) + 1`, else `SealedRoutineVersionError`.
|
|
97
|
+
* A retry resends the same template bytes; K4 treats the same definition as a no-op.
|
|
98
|
+
*/
|
|
99
|
+
export declare function resealDefinition(routines: readonly Routine[], owner: string, action: SealedRoutineAction, execution: ExecutionTemplate): HostOccurrenceRoutineDefinition;
|
|
100
|
+
/** The sealed template of one routine version: the K8 `sealedTemplate` lookup of a Host sync. */
|
|
101
|
+
export declare function sealedTemplate(routines: Iterable<Routine>, ref: SealedRoutineRef): SealedRoutineTemplate | undefined;
|
|
102
|
+
/** The `bot-routine` occurrence hook. It writes the routine Turn in the occurrence commit. `sync` promotes it. */
|
|
103
|
+
export declare function routineTurn(state: CollaborationState, run: HostOccurrenceRun): void;
|
|
104
|
+
/** A routine Turn id is its K4 intent key, `occurrenceIntentKey(<occurrence key>)`. */
|
|
105
|
+
export declare function routineOccurrence(turn: Pick<Turn, 'id'>): string;
|
|
106
|
+
/**
|
|
107
|
+
* A routine Turn that ends without an intent concludes its open occurrence.
|
|
108
|
+
* Then a staged version can switch, and `compact` can remove the row.
|
|
109
|
+
*/
|
|
110
|
+
export declare function concludeRoutineTurn(s: LedgerState, turn: Turn): boolean;
|