@spine-event-engine/storage 2.0.0-snapshot.22 → 2.0.0-snapshot.24

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 (127) hide show
  1. package/README.md +7 -0
  2. package/REFERENCE.md +131 -7
  3. package/dist/entity/agent-execution-record-spec.d.ts +87 -0
  4. package/dist/entity/agent-execution-record-spec.d.ts.map +1 -0
  5. package/dist/entity/agent-execution-record-spec.js +230 -0
  6. package/dist/entity/agent-execution-record-spec.js.map +1 -0
  7. package/dist/entity/agent-execution-sizes.d.ts +30 -0
  8. package/dist/entity/agent-execution-sizes.d.ts.map +1 -0
  9. package/dist/entity/agent-execution-sizes.js +51 -0
  10. package/dist/entity/agent-execution-sizes.js.map +1 -0
  11. package/dist/entity/agent-execution-transitions.d.ts +72 -0
  12. package/dist/entity/agent-execution-transitions.d.ts.map +1 -0
  13. package/dist/entity/agent-execution-transitions.js +165 -0
  14. package/dist/entity/agent-execution-transitions.js.map +1 -0
  15. package/dist/entity/agent-execution-values.d.ts +143 -0
  16. package/dist/entity/agent-execution-values.d.ts.map +1 -0
  17. package/dist/entity/agent-execution-values.js +251 -0
  18. package/dist/entity/agent-execution-values.js.map +1 -0
  19. package/dist/entity/agent-execution.d.ts +235 -0
  20. package/dist/entity/agent-execution.d.ts.map +1 -0
  21. package/dist/entity/agent-execution.js +15 -0
  22. package/dist/entity/agent-execution.js.map +1 -0
  23. package/dist/entity/agent-history-conformance.d.ts +78 -0
  24. package/dist/entity/agent-history-conformance.d.ts.map +1 -0
  25. package/dist/entity/agent-history-conformance.js +493 -0
  26. package/dist/entity/agent-history-conformance.js.map +1 -0
  27. package/dist/entity/agent-history-provider-page.d.ts +39 -0
  28. package/dist/entity/agent-history-provider-page.d.ts.map +1 -0
  29. package/dist/entity/agent-history-provider-page.js +82 -0
  30. package/dist/entity/agent-history-provider-page.js.map +1 -0
  31. package/dist/entity/agent-history-record-spec.d.ts +79 -0
  32. package/dist/entity/agent-history-record-spec.d.ts.map +1 -0
  33. package/dist/entity/agent-history-record-spec.js +147 -0
  34. package/dist/entity/agent-history-record-spec.js.map +1 -0
  35. package/dist/entity/agent-history.d.ts +196 -0
  36. package/dist/entity/agent-history.d.ts.map +1 -0
  37. package/dist/entity/agent-history.js +136 -0
  38. package/dist/entity/agent-history.js.map +1 -0
  39. package/dist/event/event-store.d.ts +41 -35
  40. package/dist/event/event-store.d.ts.map +1 -1
  41. package/dist/event/event-store.js +149 -144
  42. package/dist/event/event-store.js.map +1 -1
  43. package/dist/index.d.ts +1 -1
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1 -1
  46. package/dist/index.js.map +1 -1
  47. package/dist/internal/agent-execution.d.ts +51 -0
  48. package/dist/internal/agent-execution.d.ts.map +1 -0
  49. package/dist/internal/agent-execution.js +53 -0
  50. package/dist/internal/agent-execution.js.map +1 -0
  51. package/dist/internal/agent-history.d.ts +48 -0
  52. package/dist/internal/agent-history.d.ts.map +1 -0
  53. package/dist/internal/agent-history.js +52 -0
  54. package/dist/internal/agent-history.js.map +1 -0
  55. package/dist/internal/entity-commit.d.ts +30 -11
  56. package/dist/internal/entity-commit.d.ts.map +1 -1
  57. package/dist/internal/entity-commit.js +45 -2
  58. package/dist/internal/entity-commit.js.map +1 -1
  59. package/dist/internal/entity-history.d.ts +11 -0
  60. package/dist/internal/entity-history.d.ts.map +1 -1
  61. package/dist/internal/entity-history.js +10 -0
  62. package/dist/internal/entity-history.js.map +1 -1
  63. package/dist/internal/event-store.d.ts +1 -1
  64. package/dist/internal/event-store.d.ts.map +1 -1
  65. package/dist/internal/event-store.js +1 -1
  66. package/dist/internal/event-store.js.map +1 -1
  67. package/dist/internal/tenancy.d.ts +87 -1
  68. package/dist/internal/tenancy.d.ts.map +1 -1
  69. package/dist/internal/tenancy.js +39 -0
  70. package/dist/internal/tenancy.js.map +1 -1
  71. package/dist/memory/agent-execution-head-index.d.ts +52 -0
  72. package/dist/memory/agent-execution-head-index.d.ts.map +1 -0
  73. package/dist/memory/agent-execution-head-index.js +91 -0
  74. package/dist/memory/agent-execution-head-index.js.map +1 -0
  75. package/dist/memory/agent-history-index.d.ts +49 -0
  76. package/dist/memory/agent-history-index.d.ts.map +1 -0
  77. package/dist/memory/agent-history-index.js +239 -0
  78. package/dist/memory/agent-history-index.js.map +1 -0
  79. package/dist/memory/agent-history-mutation-queue.d.ts +17 -0
  80. package/dist/memory/agent-history-mutation-queue.d.ts.map +1 -0
  81. package/dist/memory/agent-history-mutation-queue.js +31 -0
  82. package/dist/memory/agent-history-mutation-queue.js.map +1 -0
  83. package/dist/memory/in-memory-agent-execution.d.ts +21 -0
  84. package/dist/memory/in-memory-agent-execution.d.ts.map +1 -0
  85. package/dist/memory/in-memory-agent-execution.js +587 -0
  86. package/dist/memory/in-memory-agent-execution.js.map +1 -0
  87. package/dist/memory/in-memory-agent-history.d.ts +21 -0
  88. package/dist/memory/in-memory-agent-history.d.ts.map +1 -0
  89. package/dist/memory/in-memory-agent-history.js +133 -0
  90. package/dist/memory/in-memory-agent-history.js.map +1 -0
  91. package/dist/memory/in-memory-entity-commit.d.ts +107 -28
  92. package/dist/memory/in-memory-entity-commit.d.ts.map +1 -1
  93. package/dist/memory/in-memory-entity-commit.js +198 -286
  94. package/dist/memory/in-memory-entity-commit.js.map +1 -1
  95. package/dist/memory/in-memory-entity-history.d.ts +1 -1
  96. package/dist/memory/in-memory-entity-history.d.ts.map +1 -1
  97. package/dist/memory/in-memory-entity-history.js.map +1 -1
  98. package/dist/memory/in-memory-storage-backend.d.ts +18 -0
  99. package/dist/memory/in-memory-storage-backend.d.ts.map +1 -1
  100. package/dist/memory/in-memory-storage-backend.js +71 -0
  101. package/dist/memory/in-memory-storage-backend.js.map +1 -1
  102. package/dist/memory/in-memory-storage-factory.d.ts +38 -3
  103. package/dist/memory/in-memory-storage-factory.d.ts.map +1 -1
  104. package/dist/memory/in-memory-storage-factory.js +146 -10
  105. package/dist/memory/in-memory-storage-factory.js.map +1 -1
  106. package/dist/memory/tenant-records.d.ts +1 -1
  107. package/dist/memory/tenant-records.d.ts.map +1 -1
  108. package/dist/memory/tenant-records.js +3 -2
  109. package/dist/memory/tenant-records.js.map +1 -1
  110. package/dist/provider.d.ts +0 -1
  111. package/dist/provider.d.ts.map +1 -1
  112. package/dist/provider.js +0 -1
  113. package/dist/provider.js.map +1 -1
  114. package/dist/record/record-query.d.ts +10 -2
  115. package/dist/record/record-query.d.ts.map +1 -1
  116. package/dist/record/record-query.js +9 -0
  117. package/dist/record/record-query.js.map +1 -1
  118. package/dist/tsconfig.tsbuildinfo +1 -1
  119. package/package.json +3 -2
  120. package/dist/internal/delivery-cleanup.d.ts +0 -99
  121. package/dist/internal/delivery-cleanup.d.ts.map +0 -1
  122. package/dist/internal/delivery-cleanup.js +0 -38
  123. package/dist/internal/delivery-cleanup.js.map +0 -1
  124. package/dist/memory/memory-delivery-cleanup.d.ts +0 -32
  125. package/dist/memory/memory-delivery-cleanup.d.ts.map +0 -1
  126. package/dist/memory/memory-delivery-cleanup.js +0 -61
  127. package/dist/memory/memory-delivery-cleanup.js.map +0 -1
package/README.md CHANGED
@@ -5,6 +5,13 @@ includes an in-memory implementation for local development and tests. Use it
5
5
  when an application needs a small record store, or when an adapter needs to
6
6
  implement the same storage contract for a durable provider.
7
7
 
8
+ Agents use the configured storage provider to retain accepted work and the
9
+ recorded model interaction. The in-memory factory keeps these records only while
10
+ the process runs; choose a database provider when they must survive a restart.
11
+ Applications read an Agent's history through its repository, as shown in the
12
+ [support example](https://github.com/SpineEventEngine/spine-ts/blob/master/examples/support/README.md). Adapter implementation
13
+ details are in the [coding-agent reference](REFERENCE.md#provider-spi).
14
+
8
15
  This is an experimental snapshot package. Use Node 24 or newer and generated
9
16
  Protobuf record schemas before configuring storage.
10
17
 
package/REFERENCE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @spine-event-engine/storage reference
2
2
 
3
- This reference is for agents working with the Spine TS storage contract.
3
+ This reference is for coding agents working with the Spine TS storage contract.
4
4
 
5
5
  ## Public entry point
6
6
 
@@ -16,9 +16,118 @@ types, and entity history interfaces.
16
16
  Storage-adapter implementers import the complete provider-only contract set from
17
17
  `@spine-event-engine/storage/provider`: Event Store record access, Entity
18
18
  history and Entity commit contracts, query values, tenant boundaries/catalogs,
19
- and delivery-cleanup handles. The storage root intentionally does not export
19
+ and record access. The storage root intentionally does not export
20
20
  these provider seams; application code uses its root storage contracts instead.
21
21
 
22
+ The provider entry point also exports `AgentHistoryStorage`,
23
+ `AgentHistoryStorageFactories`, `AgentHistoryKeys`, and
24
+ `AgentHistoryConformance`. Calling `AgentHistoryStorageFactories.create()` to
25
+ open a handle fails if the supplied factory has not registered the capability.
26
+ Agent repository registration requires this capability. Opening the actual
27
+ tenant handle also checks the selected provider before accepting Agent work.
28
+ Agent history's append-only entries
29
+ retain the original conversation record or Event envelope,
30
+ ID, and occurrence time. The full, conversation, System, and domain views use
31
+ separate indexes. Conversation reads require a `ConversationId`. The complete
32
+ order is occurrence seconds and nanoseconds descending, then conversation,
33
+ System, domain, then unsigned UTF-8 record ID ascending. `AgentHistoryKeys`
34
+ derives a sortable index value from that order; it is not a record identity.
35
+
36
+ Provider reads require a positive count and accept an optional complete
37
+ ordering-key boundary and positive byte limit. Omitting the byte limit adds no
38
+ provider-contract default. A configured byte limit counts the sum of serialized
39
+ `AgentHistoryEntry` wrapper lengths, excluding provider framing. A page reports
40
+ whether older entries remain; if the first entry exceeds a configured byte
41
+ limit, the read rejects. Limits never remove stored entries. Identical repeated appends
42
+ are accepted, while different content with the same category and record ID
43
+ is rejected. `AgentHistoryConformance` runs reusable view, order, paging,
44
+ scope, and retention checks for adapter implementations. The memory provider
45
+ retains entries across handles sharing a backend during the process lifetime;
46
+ it does not provide restart durability.
47
+ The PostgreSQL, MySQL, and Datastore providers store complete entries in one
48
+ tenant-scoped `agent_history` record family with native full, category, and
49
+ conversation ordering indexes. Each derives a bounded physical record ID from
50
+ the full state type, Agent key, category, and original record ID, then checks
51
+ immutable payload equality on repeated appends. Their provider references
52
+ specify physical index and payload constraints.
53
+
54
+ ## Tenant catalog paging
55
+
56
+ Storage adapters implement `TenantCatalog.page({ count, signal, after? })` from
57
+ the provider entry point. `count` is a positive safe integer and bounds
58
+ native candidates examined, including candidates filtered out as unrelated
59
+ namespaces. `signal` accepts a native `AbortSignal`; `TenantCatalogSignal`
60
+ describes the required members without requiring DOM declarations in storage
61
+ consumers. `TenantCatalogReads.require()` performs common request validation.
62
+
63
+ A `TenantCatalogPage` returns complete `boundaries`, `hasMore`, and an opaque
64
+ `after` continuation when more candidates remain. Pass that continuation to the
65
+ same catalog instance. Forged or cross-catalog continuations are rejected; the
66
+ cursor is an in-process value, not a durable domain record. An empty page can
67
+ still have more candidates. Continue until `hasMore` is false, rather than
68
+ stopping at the first empty page. Repeating a valid continuation may repeat the
69
+ page. A fresh sweep starts without a continuation.
70
+
71
+ Memory pages use an admission-time index and capture its length for that sweep;
72
+ PostgreSQL and MySQL page their configured tenant collections. Datastore pages
73
+ its bounded early-admission cache and then native namespace metadata using a
74
+ query limit and native cursor. A tenant can appear in both phases. Existing
75
+ Agent claims prevent that duplicate discovery from running the same accepted
76
+ invocation concurrently. An empty native `MORE_RESULTS_AFTER_LIMIT` tail that repeats its cursor ends
77
+ that sweep; other continuing pages must advance. Datastore destroys its query
78
+ stream when the caller cancels the read.
79
+
80
+ Catalogs check cancellation before starting work and before returning a result.
81
+ Paging is a finite traversal, not an atomic catalog snapshot: a concurrent
82
+ admission can appear in the current or next sweep. Agent recovery uses this
83
+ paged contract; the separate `all()` operation remains available for existing
84
+ callers that require the complete catalog.
85
+
86
+ ## Agent execution storage
87
+
88
+ `AgentExecutionStorageFactories` opens the provider-only execution handle for an
89
+ Agent repository and tenant. `supports()` checks factory registration without
90
+ opening a tenant. It does not replace the provider checks made when admitting
91
+ work. Application code configures a storage factory; it does not claim or poll
92
+ these records directly.
93
+
94
+ The handle's `capacity` reports encoded execution, per-instance and history-record
95
+ limits plus a transaction payload limit where the provider enforces one.
96
+ `AgentExecutionSizes` measures the full internal Protobuf wrappers, including
97
+ scope and metadata. The runtime must allow for the bounded response and complete
98
+ record overhead before dispatch; a payload limit is not a history retention rule.
99
+
100
+ `admit()` stores the original signal, typed recipient and selected handlers once.
101
+ `claim()` permits one execution at a time for an Agent instance. `renew()`,
102
+ `update()`, `complete()` and `markDelivered()` check the current claim token.
103
+ Updates also compare the exact previously read record. Completion compares the
104
+ initial Entity Version and stores the Entity changes, mandatory histories, model
105
+ preferences and original outgoing Command obligations in one provider operation. Emitted
106
+ domain Events are retained in immutable Agent history and handed to the normal
107
+ EventBus after completion; they are not saved delivery obligations. This includes
108
+ handlers that change no state or produce only a Command.
109
+
110
+ Pending queries read one pending invocation per Agent instance from an index. A page
111
+ carries its original time cutoff and the provider-observed continuation, so the
112
+ caller can continue even when another execution claims a returned invocation.
113
+ These internal pages are separate from application history pages. Eligibility
114
+ and claim expiry use Spine `Time`; original Inbox order determines which signal
115
+ runs next within an instance.
116
+
117
+ Each saved outgoing Command can receive one dispatch plan before transport
118
+ begins. The plan and original Command envelope cannot be replaced.
119
+ `markDelivered()` requires that plan and a current claim. Command retries must
120
+ still visit every saved recipient; these records do not make downstream
121
+ application callbacks execute exactly once. Independently, the framework's
122
+ internal EventStore retry operation accepts an identical existing envelope;
123
+ ordinary public EventStore append still rejects duplicate IDs. EventStore
124
+ history is not an Agent Event delivery queue.
125
+
126
+ The memory implementation coordinates changes only within a shared in-process
127
+ backend. PostgreSQL, transactional MySQL and Datastore use native transactions.
128
+ Database query, index and payload requirements are documented in each provider's
129
+ reference. No execution-storage operation trims the Agent's history.
130
+
22
131
  ## Record storage
23
132
 
24
133
  `StorageFactory.createRecordStorage(context, spec, group?)` returns an
@@ -109,6 +218,17 @@ history stores generated `EventId`/`Event` rows in that same state-type-named
109
218
  group. The framework Event Store is a separate, ungrouped `EventId`/`Event`
110
219
  record family.
111
220
 
221
+ `EventStore.append()` and `appendAll()` store immutable complete Events. An
222
+ identical Event ID and envelope is a successful retry without rewriting; a
223
+ conflicting envelope is rejected. Batch append validates the supplied IDs and
224
+ tenant before writing, then leaves any completed prefix when a later write
225
+ fails. Retrying the same input continues with those IDs. `accept()` and
226
+ `acceptThenAppend()` are strict new-admission operations: an existing ID is
227
+ rejected even when its Event is identical. `acceptThenAppend()` checks absence,
228
+ runs its callback, then inserts with an atomic absent-slot condition. Competing
229
+ callbacks may both run and may each have effects, but at most one Event is stored.
230
+ The framework EventBus dispatches only after strict insertion succeeds.
231
+
112
232
  History ports are lazy. When a history is disabled, the in-memory provider does
113
233
  not open or allocate its grouped records. Current Entity loading always uses
114
234
  the current record, never retained history. Event history is diagnostic data,
@@ -121,8 +241,12 @@ errors reject. There is no Entity conflict result. This changes the published
121
241
  `storage/provider` types for custom adapters; application APIs and persisted
122
242
  record layouts are unchanged.
123
243
 
124
- The in-memory provider prepares only the affected records before applying them
125
- together. Saving one Entity does not copy other Entities or whole history/Event
126
- Store collections. Automatic Entity versions, immutable-record checks and
127
- unrelated Inbox conditional updates remain. Other providers document their
128
- transaction and partial-write guarantees separately.
244
+ The built-in providers capture prepared input before I/O and write state history,
245
+ diagnostic Events, delivery Events, then current state as independent records.
246
+ SQL and Datastore providers automatically retry one classified transient Entity
247
+ persistence failure using that captured input. In memory, a caller retry must
248
+ reuse the same versions and Event IDs without rerunning the handler. A later
249
+ failure leaves completed writes in place. The presence of a delivery Event
250
+ alone does not prove the entire Entity save completed. Concurrent saves may
251
+ interleave, including current-state writes. Automatic Entity versions,
252
+ single-record atomic compare-and-set, and immutable-record checks remain.
@@ -0,0 +1,87 @@
1
+ import type { Timestamp } from "@bufbuild/protobuf/wkt";
2
+ import { type AgentExecutionHead, type AgentExecutionRecord, type AgentExecutionScope, type AgentInboxOrder, type AgentInvocationKey, type AgentSignalKey } from "@spine-event-engine/proto/generated/spine/server/agent/execution_record_pb.js";
3
+ import { RecordSpec } from "../record/record-spec.js";
4
+ import { StorageGroup } from "../record/storage-group.js";
5
+ /**
6
+ * Describes physical execution record families and their indexed keys.
7
+ */
8
+ interface AgentExecutionRecordLayout {
9
+ /**
10
+ * Shared invocation record family.
11
+ */
12
+ readonly invocationGroup: StorageGroup;
13
+ /**
14
+ * Shared per-instance claim and preference family.
15
+ */
16
+ readonly headGroup: StorageGroup;
17
+ /**
18
+ * Encodes the complete Agent instance scope.
19
+ *
20
+ * @param scope Generated state type and Agent key.
21
+ * @returns Complete encoded Agent instance scope.
22
+ */
23
+ scope(scope: AgentExecutionScope): string;
24
+ /**
25
+ * Encodes full Agent scope for binary-collated continuations.
26
+ *
27
+ * @param scope Generated state type and Agent key.
28
+ * @returns Binary-collated Agent instance scope key.
29
+ */
30
+ scopeOrder(scope: AgentExecutionScope): string;
31
+ /**
32
+ * Encodes the original source and Agent scope.
33
+ *
34
+ * @param key Original Agent invocation identity.
35
+ * @returns Complete immutable invocation key.
36
+ */
37
+ invocation(key: AgentInvocationKey): string;
38
+ /**
39
+ * Encodes the typed original Command or Event ID.
40
+ *
41
+ * @param signal Original signal identity.
42
+ * @returns Complete typed source signal key.
43
+ */
44
+ signal(signal: AgentSignalKey): string;
45
+ /**
46
+ * Encodes full Inbox time, version and source ID for binary order.
47
+ *
48
+ * @param order Original Inbox order.
49
+ * @returns Complete binary-collated Inbox order key.
50
+ */
51
+ order(order: AgentInboxOrder): string;
52
+ /**
53
+ * Encodes provider eligibility time and complete Agent scope.
54
+ *
55
+ * @param eligibleAt Time when this head becomes eligible.
56
+ * @param scope Generated state type and Agent key.
57
+ * @returns Complete binary-collated eligibility and scope key.
58
+ */
59
+ pendingKey(eligibleAt: Timestamp, scope: AgentExecutionScope): string;
60
+ /**
61
+ * Encodes the strict upper bound before all scopes at this time.
62
+ *
63
+ * @param asOf Fixed eligibility cutoff for the page.
64
+ * @returns Strict eligibility upper-bound key.
65
+ */
66
+ pendingLower(asOf: Timestamp): string;
67
+ /**
68
+ * Creates the indexed invocation record specification.
69
+ *
70
+ * @param digest Fixed-width digest of the complete indexed value.
71
+ * @returns Invocation record layout and complete native index columns.
72
+ */
73
+ invocationSpec(digest: (value: string) => string): RecordSpec<string, AgentExecutionRecord>;
74
+ /**
75
+ * Creates the indexed per-instance head specification.
76
+ *
77
+ * @param digest Fixed-width digest of the complete indexed value.
78
+ * @returns Per-instance head layout and complete native index columns.
79
+ */
80
+ headSpec(digest: (value: string) => string): RecordSpec<string, AgentExecutionHead>;
81
+ }
82
+ /**
83
+ * Materializes complete Agent execution records and full indexed identities.
84
+ */
85
+ export declare const AgentExecutionRecords: AgentExecutionRecordLayout;
86
+ export {};
87
+ //# sourceMappingURL=agent-execution-record-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-execution-record-spec.d.ts","sourceRoot":"","sources":["../../src/entity/agent-execution-record-spec.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,+EAA+E,CAAC;AAIvF,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAM1D;;GAEG;AACH,UAAU,0BAA0B;IAClC;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAC;IAEvC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IAEjC;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAE1C;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAE/C;;;;;OAKG;IACH,UAAU,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAAC;IAE5C;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC;IAEvC;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAAC;IAEtC;;;;;;OAMG;IACH,UAAU,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAEtE;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;IAEtC;;;;;OAKG;IACH,cAAc,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAE5F;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CACrF;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,0BA8KnC,CAAC"}
@@ -0,0 +1,230 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { ScalarType } from "@bufbuild/protobuf";
15
+ import { AgentExecutionHeadSchema, AgentExecutionRecordSchema, } from "@spine-event-engine/proto/generated/spine/server/agent/execution_record_pb.js";
16
+ import { RecordColumn } from "../record/record-column.js";
17
+ import { ColumnTypes } from "../record/column-type.js";
18
+ import { RecordSpec } from "../record/record-spec.js";
19
+ import { StorageGroup } from "../record/storage-group.js";
20
+ const string = ColumnTypes.scalar(ScalarType.STRING);
21
+ const invocationGroup = new StorageGroup("agent_execution");
22
+ const headGroup = new StorageGroup("agent_execution_head");
23
+ /**
24
+ * Materializes complete Agent execution records and full indexed identities.
25
+ */
26
+ export const AgentExecutionRecords = {
27
+ /**
28
+ * Shared physical invocation family inside one provider tenant.
29
+ */
30
+ invocationGroup: invocationGroup,
31
+ /**
32
+ * Shared physical per-instance head family inside one provider tenant.
33
+ */
34
+ headGroup: headGroup,
35
+ /**
36
+ * Encodes complete Agent scope without truncation.
37
+ *
38
+ * @param scope Generated state type and canonical typed Agent key.
39
+ * @returns Unambiguous complete scope text.
40
+ */
41
+ scope(scope) {
42
+ if (!scope.stateType || !scope.agentKey)
43
+ throw new TypeError("Agent execution requires complete state type and Agent key.");
44
+ return JSON.stringify([scope.stateType, scope.agentKey]);
45
+ },
46
+ /**
47
+ * Encodes every scope byte for unambiguous binary continuation order.
48
+ *
49
+ * @param scope Generated state type and canonical typed Agent key.
50
+ * @returns Prefix-safe full ordering text.
51
+ */
52
+ scopeOrder(scope) {
53
+ this.scope(scope);
54
+ return `${utf8Hex(scope.stateType)}!${utf8Hex(scope.agentKey)}`;
55
+ },
56
+ /**
57
+ * Encodes one original source identity within its Agent scope.
58
+ *
59
+ * @param key Agent instance and original Command or Event ID.
60
+ * @returns Complete immutable invocation identity.
61
+ */
62
+ invocation(key) {
63
+ if (key.scope === undefined || key.sourceSignal === undefined)
64
+ throw new TypeError("Agent execution requires scope and original source ID.");
65
+ return JSON.stringify([this.scope(key.scope), this.signal(key.sourceSignal)]);
66
+ },
67
+ /**
68
+ * Encodes a typed source ID without optional MessageId Version metadata.
69
+ *
70
+ * @param signal Original Command or Event identity.
71
+ * @returns Complete typed source identity.
72
+ */
73
+ signal(signal) {
74
+ const id = signal.id;
75
+ if (id.case === "command" && id.value.uuid)
76
+ return JSON.stringify(["command", id.value.uuid]);
77
+ if (id.case === "event" && id.value.value)
78
+ return JSON.stringify(["event", id.value.value]);
79
+ throw new TypeError("Agent execution requires an original Command or Event ID.");
80
+ },
81
+ /**
82
+ * Encodes full Timestamp, Inbox version and source ID for native binary order.
83
+ *
84
+ * @param order Existing Inbox acceptance order.
85
+ * @returns Prefix-safe order text.
86
+ */
87
+ order(order) {
88
+ const at = order.receivedAt;
89
+ if (at === undefined ||
90
+ order.sourceSignal === undefined ||
91
+ order.inboxVersion < 0n ||
92
+ order.inboxVersion > 18446744073709551615n)
93
+ throw new TypeError("Agent execution requires complete Inbox order.");
94
+ if (at.seconds < -62135596800n ||
95
+ at.seconds > 253402300799n ||
96
+ at.nanos < 0 ||
97
+ at.nanos > 999_999_999)
98
+ throw new RangeError("Agent Inbox Timestamp is out of range.");
99
+ const seconds = (at.seconds + 62135596800n).toString().padStart(12, "0");
100
+ const nanos = at.nanos.toString().padStart(9, "0");
101
+ const version = order.inboxVersion.toString().padStart(20, "0");
102
+ const signal = order.sourceSignal.id;
103
+ const id = signal.case === "command"
104
+ ? signal.value.uuid
105
+ : signal.case === "event"
106
+ ? signal.value.value
107
+ : undefined;
108
+ if (!id)
109
+ throw new TypeError("Agent Inbox order requires an original source ID.");
110
+ const rank = signal.case === "command" ? "0" : "1";
111
+ return `${seconds}:${nanos}:${version}:${rank}${utf8Hex(id)}`;
112
+ },
113
+ /**
114
+ * Encodes full provider eligibility time and complete instance scope.
115
+ *
116
+ * @param eligibleAt Time when this head becomes eligible.
117
+ * @param scope Generated state type and Agent key.
118
+ * @returns Complete binary-collated eligibility and scope key.
119
+ */
120
+ pendingKey(eligibleAt, scope) {
121
+ return `${timestampKey(eligibleAt)}!${this.scopeOrder(scope)}`;
122
+ },
123
+ /**
124
+ * Returns an exclusive upper bound before all scopes at the sampled time.
125
+ *
126
+ * @param asOf Fixed eligibility cutoff for the page.
127
+ * @returns Strict eligibility upper-bound key.
128
+ */
129
+ pendingLower(asOf) {
130
+ return `${timestampKey(asOf)}!`;
131
+ },
132
+ /**
133
+ * Builds materialized invocation columns under one fixed-width provider digest.
134
+ *
135
+ * @param digest Physical identity digest of the full logical key.
136
+ * @returns Shared native record specification.
137
+ */
138
+ invocationSpec(digest) {
139
+ return new RecordSpec({
140
+ sourceType: AgentExecutionRecordSchema,
141
+ recordType: AgentExecutionRecordSchema,
142
+ idKind: "string",
143
+ extractId: (record) => digest(this.invocation(requiredInvocation(record))),
144
+ columns: [
145
+ new RecordColumn("state_type", string, (record) => requiredInvocation(record).scope.stateType),
146
+ new RecordColumn("agent_key", string, (record) => requiredInvocation(record).scope.agentKey),
147
+ new RecordColumn("scope_digest", string, (record) => digest(this.scope(requiredInvocation(record).scope))),
148
+ new RecordColumn("status", string, (record) => String(record.status)),
149
+ new RecordColumn("order_key", string, (record) => this.order(requiredOrder(record))),
150
+ ],
151
+ });
152
+ },
153
+ /**
154
+ * Builds materialized current-head columns under one provider digest.
155
+ *
156
+ * @param digest Physical identity digest of the full Agent scope.
157
+ * @returns Shared native head specification.
158
+ */
159
+ headSpec(digest) {
160
+ return new RecordSpec({
161
+ sourceType: AgentExecutionHeadSchema,
162
+ recordType: AgentExecutionHeadSchema,
163
+ idKind: "string",
164
+ extractId: (record) => digest(this.scope(requiredScope(record))),
165
+ columns: [
166
+ new RecordColumn("state_type", string, (record) => requiredScope(record).stateType),
167
+ new RecordColumn("agent_key", string, (record) => requiredScope(record).agentKey),
168
+ new RecordColumn("scope_digest", string, (record) => digest(this.scope(requiredScope(record)))),
169
+ new RecordColumn("state_digest", string, (record) => digest(requiredScope(record).stateType)),
170
+ new RecordColumn("pending_key", string, (record) => headPendingKey(record, this)),
171
+ ],
172
+ });
173
+ },
174
+ };
175
+ /**
176
+ * Reads the immutable accepted invocation identity from a record.
177
+ */
178
+ function requiredInvocation(record) {
179
+ const key = record.accepted?.key;
180
+ if (key?.scope === undefined || key.sourceSignal === undefined)
181
+ throw new TypeError("Agent execution record requires its original invocation key.");
182
+ return key;
183
+ }
184
+ /**
185
+ * Reads the original Inbox order from a record.
186
+ */
187
+ function requiredOrder(record) {
188
+ const order = record.accepted?.order;
189
+ if (order === undefined)
190
+ throw new TypeError("Agent execution record requires Inbox order.");
191
+ return order;
192
+ }
193
+ /**
194
+ * Reads the complete Agent instance scope from a head.
195
+ */
196
+ function requiredScope(head) {
197
+ if (head.scope === undefined)
198
+ throw new TypeError("Agent execution head requires its scope.");
199
+ return head.scope;
200
+ }
201
+ /**
202
+ * Encodes an optional lease expiry for native index eligibility.
203
+ */
204
+ function timestampKey(value) {
205
+ if (value.seconds < -62135596800n ||
206
+ value.seconds > 253402300799n ||
207
+ value.nanos < 0 ||
208
+ value.nanos > 999_999_999)
209
+ throw new RangeError("Agent execution Timestamp is out of range.");
210
+ return `${(value.seconds + 62135596800n).toString().padStart(12, "0")}:${value.nanos.toString().padStart(9, "0")}`;
211
+ }
212
+ /**
213
+ * Materializes the head candidate or a value beyond every valid Timestamp.
214
+ */
215
+ function headPendingKey(head, layout) {
216
+ const present = [head.pending, head.pendingOrder, head.eligibleAt].filter((value) => value !== undefined).length;
217
+ if (present === 0)
218
+ return "~";
219
+ if (present !== 3 || head.eligibleAt === undefined)
220
+ throw new TypeError("Agent execution head has incomplete discovery metadata.");
221
+ return layout.pendingKey(head.eligibleAt, requiredScope(head));
222
+ }
223
+ /**
224
+ * Encodes every UTF-8 byte without locale-dependent collation.
225
+ */
226
+ function utf8Hex(value) {
227
+ const encoder = new globalThis.TextEncoder();
228
+ return [...encoder.encode(value)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
229
+ }
230
+ //# sourceMappingURL=agent-execution-record-spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-execution-record-spec.js","sourceRoot":"","sources":["../../src/entity/agent-execution-record-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EACL,wBAAwB,EACxB,0BAA0B,GAO3B,MAAM,+EAA+E,CAAC;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE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G,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/F,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { AgentHistoryEntry } from "@spine-event-engine/proto/agent";
2
+ import { type AgentExecutionHead, type AgentExecutionRecord, type AgentExecutionScope } from "@spine-event-engine/proto/generated/spine/server/agent/execution_record_pb.js";
3
+ /**
4
+ * Calculates complete internal Protobuf row sizes before an external Agent call.
5
+ */
6
+ export declare const AgentExecutionSizes: {
7
+ /**
8
+ * Calculates the retained execution journal and accepted source facts.
9
+ *
10
+ * @param record Complete execution record proposed for persistence.
11
+ * @returns Exact serialized execution-record bytes.
12
+ */
13
+ record(record: AgentExecutionRecord): number;
14
+ /**
15
+ * Calculates per-instance claim, eligibility and preferences.
16
+ *
17
+ * @param head Complete head proposed for persistence.
18
+ * @returns Exact serialized head bytes.
19
+ */
20
+ head(head: AgentExecutionHead): number;
21
+ /**
22
+ * Calculates a history entry inside its persisted scope envelope.
23
+ *
24
+ * @param scope Generated state type and canonical Agent key.
25
+ * @param entry Original conversation, System or domain entry.
26
+ * @returns Exact serialized internal history-record bytes.
27
+ */
28
+ history(scope: AgentExecutionScope, entry: AgentHistoryEntry): number;
29
+ };
30
+ //# sourceMappingURL=agent-execution-sizes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-execution-sizes.d.ts","sourceRoot":"","sources":["../../src/entity/agent-execution-sizes.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,+EAA+E,CAAC;AAKvF;;GAEG;AACH,eAAO,MAAM,mBAAmB;IAC9B;;;;;OAKG;mBACY,oBAAoB,GAAG,MAAM;IAI5C;;;;;OAKG;eACQ,kBAAkB,GAAG,MAAM;IAItC;;;;;;OAMG;mBACY,mBAAmB,SAAS,iBAAiB,GAAG,MAAM;CAMtE,CAAC"}
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { toBinary } from "@bufbuild/protobuf";
15
+ import { AgentExecutionHeadSchema, AgentExecutionRecordSchema, } from "@spine-event-engine/proto/generated/spine/server/agent/execution_record_pb.js";
16
+ import { AgentHistoryRecordSchema } from "@spine-event-engine/proto/generated/spine/server/agent/history_record_pb.js";
17
+ import { AgentHistoryRecords } from "./agent-history-record-spec.js";
18
+ /**
19
+ * Calculates complete internal Protobuf row sizes before an external Agent call.
20
+ */
21
+ export const AgentExecutionSizes = {
22
+ /**
23
+ * Calculates the retained execution journal and accepted source facts.
24
+ *
25
+ * @param record Complete execution record proposed for persistence.
26
+ * @returns Exact serialized execution-record bytes.
27
+ */
28
+ record(record) {
29
+ return toBinary(AgentExecutionRecordSchema, record).length;
30
+ },
31
+ /**
32
+ * Calculates per-instance claim, eligibility and preferences.
33
+ *
34
+ * @param head Complete head proposed for persistence.
35
+ * @returns Exact serialized head bytes.
36
+ */
37
+ head(head) {
38
+ return toBinary(AgentExecutionHeadSchema, head).length;
39
+ },
40
+ /**
41
+ * Calculates a history entry inside its persisted scope envelope.
42
+ *
43
+ * @param scope Generated state type and canonical Agent key.
44
+ * @param entry Original conversation, System or domain entry.
45
+ * @returns Exact serialized internal history-record bytes.
46
+ */
47
+ history(scope, entry) {
48
+ return toBinary(AgentHistoryRecordSchema, AgentHistoryRecords.record(scope.stateType, scope.agentKey, entry)).length;
49
+ },
50
+ };
51
+ //# sourceMappingURL=agent-execution-sizes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-execution-sizes.js","sourceRoot":"","sources":["../../src/entity/agent-execution-sizes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EACL,wBAAwB,EACxB,0BAA0B,GAI3B,MAAM,+EAA+E,CAAC;AACvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,6EAA6E,CAAC;AAEvH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC;;;;;OAKG;IACH,MAAM,CAAC,MAA4B;QACjC,OAAO,QAAQ,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,IAAwB;QAC3B,OAAO,QAAQ,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC;IACzD,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,KAA0B,EAAE,KAAwB;QAC1D,OAAO,QAAQ,CACb,wBAAwB,EACxB,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CACnE,CAAC,MAAM,CAAC;IACX,CAAC;CACF,CAAC"}