@byok-sdk/bot-collaboration 0.42.0 → 0.44.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.
Files changed (42) hide show
  1. package/README.md +105 -77
  2. package/dist/chunk-6X7ARUDF.js +9 -0
  3. package/dist/chunk-6X7ARUDF.js.map +1 -0
  4. package/dist/chunk-BGGEZHPC.js +27 -0
  5. package/dist/chunk-BGGEZHPC.js.map +1 -0
  6. package/dist/chunk-UXEHG75I.js +11 -0
  7. package/dist/chunk-UXEHG75I.js.map +1 -0
  8. package/dist/commit.d.ts +0 -12
  9. package/dist/compaction.d.ts +9 -2
  10. package/dist/delivery-routing.d.ts +1 -1
  11. package/dist/delivery-superseded.d.ts +3 -0
  12. package/dist/delivery.d.ts +1 -1
  13. package/dist/dream.d.ts +18 -4
  14. package/dist/host-kit.d.ts +25 -6
  15. package/dist/host-kit.js +8 -4
  16. package/dist/host-kit.js.map +1 -1
  17. package/dist/host.d.ts +58 -9
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.js +11 -9
  20. package/dist/index.js.map +1 -1
  21. package/dist/ledger-compatibility.d.ts +4 -0
  22. package/dist/migration.d.ts +1 -1
  23. package/dist/model.d.ts +5 -3
  24. package/dist/routines.d.ts +0 -6
  25. package/dist/rules/autonomy.d.ts +1 -4
  26. package/dist/rules/delegation.d.ts +19 -6
  27. package/dist/rules/index.js +1 -2
  28. package/dist/rules/priority.d.ts +2 -0
  29. package/dist/rules/sync.d.ts +6 -0
  30. package/dist/store-compatibility.d.ts +3 -0
  31. package/dist/switch.d.ts +2 -30
  32. package/dist/testing.js +3 -3
  33. package/dist/testing.js.map +1 -1
  34. package/package.json +8 -8
  35. package/dist/chunk-33YA66U7.js +0 -7
  36. package/dist/chunk-33YA66U7.js.map +0 -1
  37. package/dist/chunk-5J5SOWWI.js +0 -12
  38. package/dist/chunk-5J5SOWWI.js.map +0 -1
  39. package/dist/chunk-XTZUCECQ.js +0 -12
  40. package/dist/chunk-XTZUCECQ.js.map +0 -1
  41. package/dist/chunk-ZUFZCROA.js +0 -27
  42. package/dist/chunk-ZUFZCROA.js.map +0 -1
@@ -0,0 +1,4 @@
1
+ import type { HostLedger } from '@byok-sdk/server/execution-core';
2
+ import { type AutonomyState } from './rules/autonomy.js';
3
+ export declare function checkLedgerWouldDo(ledger: Pick<HostLedger, 'transaction'>, state: AutonomyState): void;
4
+ export declare function admitLedgerWouldDo(ledger: Pick<HostLedger, 'transaction'>, state: AutonomyState): void;
@@ -39,7 +39,7 @@ import type { CollaborationState } from './model.js';
39
39
  * does not record whether a pending projection was sent (H does: it raises `tries` before the send), so the source
40
40
  * flushes its projections before the export.
41
41
  */
42
- export declare const SWITCH_EXPORT_VERSION = 1;
42
+ export declare const SWITCH_EXPORT_VERSION = 2;
43
43
  export declare const SWITCH_SECTIONS: readonly ['collaboration', 'archived', 'intents', 'routines', 'occurrences', 'outbox', 'tombstones'];
44
44
  export type SwitchSection = typeof SWITCH_SECTIONS[number];
45
45
  /** A device of the domain and its revision on the source Host, frozen by the source's open switch. */
package/dist/model.d.ts CHANGED
@@ -16,11 +16,12 @@ export { addBatchTurns, addTurn, json } from './rules/turn.js';
16
16
  export type { Budget, Card, Question, Rejection, ReplyEntry, Turn, TurnFields, Verdict } from './rules/turn.js';
17
17
  export type { AcceptedReply, Batch, Delegation, DelegationCancel, Unit } from './rules/delegation.js';
18
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.
19
+ * The K8 state. A Host ledger keeps it in its application body, and the ledger's `k8` format row (`botLedgerOptions`) is
20
+ * its format.
21
+ * Retention keeps settled rows in K4 application rows (#798). Bot routines are K4 routines with the `bot-routine`
22
+ * occurrence hook.
21
23
  */
22
24
  export interface CollaborationState extends AutonomyState {
23
- version: 3;
24
25
  team: TeamState;
25
26
  turns: Record<string, Turn>;
26
27
  budgets: Record<string, Budget>;
@@ -80,4 +81,5 @@ export interface CollaborationState extends AutonomyState {
80
81
  */
81
82
  dreams?: DreamState;
82
83
  }
84
+ /** The K8 state of an application body, created empty at its first use. */
83
85
  export declare function stateOf(application: Record<string, Json>): CollaborationState;
@@ -78,12 +78,6 @@ export declare function owned(routines: readonly Routine[], owner: string, id: s
78
78
  export declare function endable(routines: readonly Routine[], id: string): Routine;
79
79
  /** The next version for `RoutineCommands.update`. It builds on `pending` when one is staged. */
80
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
81
  /**
88
82
  * The definition of a new sealed routine. The member picks `routineId` (a fresh UUID), because the template binds it, and
89
83
  * seals version 1. An id that any routine row already has is refused, whatever its lifecycle, except an exact retry: the
@@ -37,10 +37,7 @@ export declare function autonomyOf(bot: {
37
37
  export declare function wouldDoId(taskId: string, action: WouldDoAction, index: number): string;
38
38
  /** Records one would-do row. Returns the new row, or `undefined` when the same outcome already recorded it. */
39
39
  export declare function recordWouldDo(state: AutonomyState, row: Omit<WouldDo, 'id'>): WouldDo | undefined;
40
- /**
41
- * Refuses a state that still holds a would-do row from before #1756, which has no `turnId`. Only the one-shot migration
42
- * links such a row to its Turn, so a store that skipped it fails here instead of keeping the row forever.
43
- */
40
+ /** Refuse would-do rows written before turn identities were required. */
44
41
  export declare function refuseUnmigratedWouldDo(state: AutonomyState): void;
45
42
  /** The would-do rows of one Bot, or of every Bot, oldest first. A row of the same instant keeps a stable id order. */
46
43
  export declare function wouldDoRows(state: AutonomyState, botId?: string): WouldDo[];
@@ -197,7 +197,10 @@ export declare function applyDelegate(state: DelegationState, turn: Turn, taskId
197
197
  export declare function observeStart(state: DelegationState, turn: Turn, now: number, emit: Publish): void;
198
198
  /** Presence is display evidence only. It never controls submit, expiry, or a verdict. */
199
199
  export declare function observeDevices(state: DelegationState, facts: IntentFacts, devices: ReadonlyMap<string, boolean>, emit: Publish): void;
200
- /** The result of an owner cancel (#1405). `cancel_pending` and `already_settled` write nothing and send no cancel. */
200
+ /**
201
+ * The result of an owner cancel (#1405). `cancelled` confirms the cancel committed, not necessarily its settlement.
202
+ * Turn/delegation replays that return `cancel_pending` or `already_settled` write nothing and send no cancel.
203
+ */
201
204
  export type CancelOutcome = 'cancelled' | 'cancel_pending' | 'already_settled';
202
205
  export interface TurnCancelResult {
203
206
  turnId: string;
@@ -222,16 +225,26 @@ export declare class DelegationError extends Error {
222
225
  /**
223
226
  * A refused intent key. `cancelHostIntent` (#1320): `unknown_intent` for a key with no Host intent, or `not_host_intent` for a
224
227
  * Bot Turn. `failStuckIntent` (#1405): `unknown_intent` for a key with no K4 intent, `already_settled`, or `not_stuck` for an
225
- * intent whose terminal K8 did not refuse.
228
+ * intent whose terminal K8 did not refuse. `cancelHostIntents` (#2003) also refuses `inflight`, and `rejected` lists every
229
+ * refused key in input order. `key` and `code` name the first refusal.
226
230
  */
227
231
  export declare class HostIntentError extends Error {
228
232
  readonly key: string;
229
- readonly code: 'unknown_intent' | 'not_host_intent' | 'already_settled' | 'not_stuck';
230
- constructor(key: string, code: 'unknown_intent' | 'not_host_intent' | 'already_settled' | 'not_stuck', message: string);
233
+ readonly code: 'unknown_intent' | 'not_host_intent' | 'already_settled' | 'not_stuck' | 'inflight';
234
+ readonly rejected: readonly {
235
+ key: string;
236
+ code: HostIntentError['code'];
237
+ }[];
238
+ constructor(key: string, code: 'unknown_intent' | 'not_host_intent' | 'already_settled' | 'not_stuck' | 'inflight', message: string, rejected?: readonly {
239
+ key: string;
240
+ code: HostIntentError['code'];
241
+ }[]);
231
242
  }
232
243
  /**
233
- * `cancelled`: the intent was not submitted and settled as `cancelled`. `cancel_pending`: the SDK cancel went out, and K4
234
- * settles the intent at its terminal. `already_settled`: no cancel was sent; `conclusion` is the earlier one.
244
+ * `cancelled`: the intent was not submitted and its cancel committed. `conclusion` is optional: a `drainError` or
245
+ * `wakePending` result can precede settlement, which waits for a later successful drain. Replay then returns
246
+ * `already_settled` with the conclusion. `cancel_pending`: the SDK cancel was requested and K4 awaits its terminal;
247
+ * `conclusion` is absent until settlement. `already_settled`: no cancel was sent; `conclusion` is the earlier one.
235
248
  */
236
249
  export interface IntentCancelResult<C extends string> {
237
250
  key: string;
@@ -1,4 +1,3 @@
1
- export { admitDeviceSlot, autonomousIntentIds, userFirst } from '../chunk-33YA66U7.js';
2
- export { COALESCE_DEFAULTS, CONNECTOR_OUTCOME_UNKNOWN, DEVICE_NOT_BOUND, DEVICE_SWITCHING, OFFER_WAIT_MS, addTurn, admitBotToolsets, advanceRoomSeats, cardCallDue, checkReply, coalescePolicy, collaborationDue, commandBots, commitCommand, compactVeto, delegationCancelAnswer, hostIntentCancelAnswer, hostMessageDisposition, inactive, observeDevices, replyCheckDue, reportCardDecisions, requireMain, seatTurn, settleCardCall, settleDelegations, syncTurn, turnCancelAnswer } from '../chunk-ZUFZCROA.js';
1
+ export { COALESCE_DEFAULTS, CONNECTOR_OUTCOME_UNKNOWN, DEVICE_NOT_BOUND, DEVICE_SWITCHING, OFFER_WAIT_MS, addTurn, admitBotToolsets, admitDeviceSlot, advanceRoomSeats, autonomousIntentIds, cardCallDue, checkReply, coalescePolicy, collaborationDue, commandBots, commitCommand, compactVeto, delegationCancelAnswer, hostIntentCancelAnswer, hostMessageDisposition, inactive, observeDevices, replyCheckDue, reportCardDecisions, requireMain, seatTurn, settleCardCall, settleDelegations, syncTurn, turnCancelAnswer, userFirst } from '../chunk-BGGEZHPC.js';
3
2
  //# sourceMappingURL=index.js.map
4
3
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,6 @@
1
1
  import type { Turn } from './turn.js';
2
+ /** Background work that user input goes ahead of: a routine Turn, or another Bot's request. */
3
+ export declare function isAutonomous(turn: Pick<Turn, 'source'>): boolean;
2
4
  /** The background intents that user input overtakes; dream ids already use the ledger's hashed identity. */
3
5
  export declare function autonomousIntentIds(turns: readonly Pick<Turn, 'id' | 'source'>[], dreams: readonly string[]): Set<string>;
4
6
  /**
@@ -100,6 +100,12 @@ export interface SyncFacts extends Pick<IntentFacts, 'intent'> {
100
100
  * A refusal holds that Bot's Turns that have no intent, and the rest of the scope syncs. Absent: no check.
101
101
  */
102
102
  deviceRefusal?(botId: string): SyncRefusal | undefined;
103
+ /**
104
+ * The `limits.maxDurationMs` of the offer of the Bot's submitted dream (#2334), or `undefined` when the Bot has none. A
105
+ * claimed dream is not interrupted, so a Turn that is not autonomous and freezes behind it waits that much longer.
106
+ * Absent: no Bot has a submitted dream.
107
+ */
108
+ dreamHold?(botId: string): number | undefined;
103
109
  }
104
110
  export interface SyncOptions<R extends ContextRoutine> {
105
111
  now: number;
@@ -0,0 +1,3 @@
1
+ import type { StoreCompatibility } from '@byok-sdk/client';
2
+ /** Inspect a stopped L ledger on a private copy, including its WAL or rollback journal. */
3
+ export declare function inspectLedger(path: string, tenant: string): StoreCompatibility;
package/dist/switch.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type HostLedger, type LedgerDump } from '@byok-sdk/server/execution-core';
2
2
  import { type CollaborationState } from './model.js';
3
- import { type SwitchContent, type SwitchExport, type SwitchHeader, type SwitchReceipt } from './migration.js';
3
+ import { type SwitchContent, type SwitchExport, type SwitchHeader } from './migration.js';
4
4
  /** The import record of a new L owner: from the load until the commit toward L. */
5
5
  export interface SwitchImport {
6
6
  digest: string;
@@ -9,10 +9,7 @@ export interface SwitchImport {
9
9
  }
10
10
  /** Throws while the domain has an export mark. Each L write calls it after its own refusals, so those come first. */
11
11
  export declare function refuseExported(state: CollaborationState): void;
12
- /**
13
- * Throws while the ledger holds a switch import, which is not committed toward L yet: no K8 work runs on it. The switch
14
- * steps `commitImport` and `discardImport` write it themselves.
15
- */
12
+ /** Refuse work on a ledger that still holds an uncommitted switch import. */
16
13
  export declare function refuseImported(state: CollaborationState): void;
17
14
  /**
18
15
  * A restart reads the switch records before any write. A ledger with an import is not committed toward L yet, so no
@@ -24,30 +21,5 @@ export declare function checkSwitchRecords(state: CollaborationState): void;
24
21
  * (#975 "Export builder must check"). `tenant` names the ledger (its `agent` keys); `header` is the document's.
25
22
  */
26
23
  export declare function switchContent(dump: LedgerDump, tenant: string, header: SwitchHeader): SwitchContent;
27
- /**
28
- * Writes the neutral form into a K4 dump bound to `tenant`. The K8 owner records the target needs are passed in `owner`.
29
- * A concluded row gets K4's values of a new row for its scheduler cursors (#975 D6): `phase: 'settled'`, `notBefore: 0`.
30
- */
31
- export declare function switchDump(content: SwitchContent, tenant: string, owner: Pick<CollaborationState, 'topology' | 'switchImport'>): LedgerDump;
32
24
  /** Seals the content that a ledger holds now, under a given header. */
33
25
  export declare function sealLedger(ledger: HostLedger, header: SwitchHeader): SwitchExport;
34
- /**
35
- * Step 2 of a switch to L (#975): writes an H export into an empty L ledger tenant and verifies it in the same transaction.
36
- * The document must verify. Each of its devices is recorded as owned by H, with the import record, until `commitImport`.
37
- * Before the load commits, K4 reads the tenant's rows back, and they must give the document's digest under its header;
38
- * otherwise nothing is written. Returns the receipt the old owner commits away on. A `BotCollaboration` refuses a ledger
39
- * with an import, so no work runs on it before the commit.
40
- */
41
- export declare function importForSwitch(ledger: HostLedger, document: SwitchExport): SwitchReceipt;
42
- /**
43
- * Step 4 of a switch to L, after the old owner committed away on the receipt: L owns each device of the import. Only the
44
- * import of this digest that is not being discarded commits. Then a `BotCollaboration` can open the ledger.
45
- */
46
- export declare function commitImport(ledger: HostLedger, digest: string): void;
47
- /**
48
- * Deletes an import that was not committed, when the switch does not go ahead: the old owner aborts, or the product
49
- * decides against it. It first records
50
- * that the import is being discarded, so `commitImport` refuses it from then on, then deletes the tenant (K4 `discard`).
51
- * A committed tenant has no import record, so it is refused; no `BotCollaboration` ran work on an uncommitted one.
52
- */
53
- export declare function discardImport(ledger: HostLedger): void;