@salesforce/agentic-common 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -309,6 +309,24 @@ type FrontmatterSplit = {
309
309
  };
310
310
  ```
311
311
 
312
+ ### `backfillCreatedAt<T extends { createdAt?: Date }>(messages: T[], clock: Clock): T[]`
313
+
314
+ Backfills missing `createdAt` timestamps on a batch of message-shaped records, stepping per-position via
315
+ `clock.nextAfter` so a bulk insert produces strictly-ascending timestamps rather than ms-precision ties tie-broken by
316
+ stable sort. Records that already carry a `createdAt` pass through unchanged (same reference, no clone). Records missing
317
+ one are cloned with a freshly-stepped value: the first missing position seeds from `clock.now()`, each subsequent
318
+ missing position uses `clock.nextAfter(<prior>)`.
319
+
320
+ Used by `sfdx-agent-sdk`'s `ChatSession.addContext()` and both harnesses' `addContext` boundaries so the read-side
321
+ "every Message has populated `createdAt`; sort ascending" contract is upheld regardless of consumer-construction style.
322
+ Generic over the record shape, so any consumer with a `createdAt?: Date` field can reuse the same policy.
323
+
324
+ ```typescript
325
+ import { backfillCreatedAt, RealClock } from '@salesforce/agentic-common';
326
+
327
+ const filled = backfillCreatedAt(messages, new RealClock());
328
+ ```
329
+
312
330
  ## Development
313
331
 
314
332
  See [DEVELOPING.md](../../DEVELOPING.md) for build-from-source setup, scripts, and monorepo commands.
@@ -0,0 +1,24 @@
1
+ import type { Clock } from './clock.js';
2
+ /**
3
+ * Backfills missing `createdAt` timestamps on a batch of message-shaped
4
+ * records, stepping per-position via `clock.nextAfter` so a bulk insert
5
+ * produces strictly-ascending timestamps rather than ms-precision ties
6
+ * tie-broken by stable sort.
7
+ *
8
+ * Records that already carry a `createdAt` are returned unchanged (same
9
+ * reference, no clone). Records missing one are cloned with a freshly-
10
+ * stepped `createdAt`. The first missing position seeds from `clock.now()`;
11
+ * each subsequent missing position uses `clock.nextAfter(<prior>)`.
12
+ *
13
+ * Generic over the record shape so this can be reused by:
14
+ * - The SDK's `DefaultChatSession.addContext` (over `Message`)
15
+ * - Both production harnesses' `addContext` boundaries
16
+ *
17
+ * Anywhere the message-shape contract requires an ascending sortable
18
+ * timestamp, this is the single backfill site so the three implementations
19
+ * can't drift on subtle policy questions (clamp-to-lastExplicit, behavior
20
+ * at the boundary between explicit and implicit positions, etc.).
21
+ */
22
+ export declare function backfillCreatedAt<T extends {
23
+ createdAt?: Date;
24
+ }>(messages: T[], clock: Clock): T[];
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc. All rights reserved.
3
+ * See LICENSE.txt for license terms.
4
+ */
5
+ /**
6
+ * Backfills missing `createdAt` timestamps on a batch of message-shaped
7
+ * records, stepping per-position via `clock.nextAfter` so a bulk insert
8
+ * produces strictly-ascending timestamps rather than ms-precision ties
9
+ * tie-broken by stable sort.
10
+ *
11
+ * Records that already carry a `createdAt` are returned unchanged (same
12
+ * reference, no clone). Records missing one are cloned with a freshly-
13
+ * stepped `createdAt`. The first missing position seeds from `clock.now()`;
14
+ * each subsequent missing position uses `clock.nextAfter(<prior>)`.
15
+ *
16
+ * Generic over the record shape so this can be reused by:
17
+ * - The SDK's `DefaultChatSession.addContext` (over `Message`)
18
+ * - Both production harnesses' `addContext` boundaries
19
+ *
20
+ * Anywhere the message-shape contract requires an ascending sortable
21
+ * timestamp, this is the single backfill site so the three implementations
22
+ * can't drift on subtle policy questions (clamp-to-lastExplicit, behavior
23
+ * at the boundary between explicit and implicit positions, etc.).
24
+ */
25
+ export function backfillCreatedAt(messages, clock) {
26
+ let last;
27
+ return messages.map((m) => {
28
+ if (m.createdAt)
29
+ return m;
30
+ last = last ? clock.nextAfter(last) : clock.now();
31
+ return { ...m, createdAt: last };
32
+ });
33
+ }
34
+ //# sourceMappingURL=backfill-created-at.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { backfillCreatedAt } from './backfill-created-at.js';
1
2
  export { Clock, RealClock } from './clock.js';
2
3
  export { type OrgConnection, RealOrgConnection } from './connection.js';
3
4
  export { type OrgConnectionFactory, RealOrgConnectionFactory } from './connection-factory.js';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * Copyright 2026, Salesforce, Inc. All rights reserved.
3
3
  * See LICENSE.txt for license terms.
4
4
  */
5
+ export { backfillCreatedAt } from './backfill-created-at.js';
5
6
  export { Clock, RealClock } from './clock.js';
6
7
  export { RealOrgConnection } from './connection.js';
7
8
  export { RealOrgConnectionFactory } from './connection-factory.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/agentic-common",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Shared primitives and common utilities for the Salesforce agentic DX packages",
5
5
  "type": "module",
6
6
  "exports": {