@astrosheep/square 0.3.31 → 0.3.33

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.
@@ -39,6 +39,7 @@ export async function openSquare(squarePath, options = {}) {
39
39
  userPath: env.SQUARE_HOST_LEDGER_USER ?? ledgerRoot,
40
40
  localPath: env.SQUARE_HOST_LEDGER_LOCAL ?? ledgerRoot,
41
41
  }),
42
+ wakeTransport: options.wakeTransport,
42
43
  };
43
44
  }
44
45
  catch (error) {
@@ -77,7 +78,7 @@ export function buildMemorySquare(options) {
77
78
  hardCap: options.hardCap ?? null,
78
79
  ...(options.throttlePerMinute === undefined ? {} : { throttlePerMinute: options.throttlePerMinute }),
79
80
  }, options.markdown);
80
- return { artifact: memoryArtifact(createMemoryCell(squareState)), clock: options.clock ?? Date.now, location: 'memory', hostLedger: options.hostLedger };
81
+ return { artifact: memoryArtifact(createMemoryCell(squareState)), clock: options.clock ?? Date.now, location: 'memory', hostLedger: options.hostLedger, wakeTransport: options.wakeTransport };
81
82
  }
82
83
  function memoryArtifact(cell) {
83
84
  return { read: () => cell.read(), transact: (fn) => cell.transact(fn), changed: (since, timeout) => cell.changed(since, timeout), close: () => cell.close() };
@@ -2,6 +2,7 @@ import { formatActivityId, parseActivityId } from './square-core.js';
2
2
  import { nameKey } from './model.js';
3
3
  import { deriveDeliveryModel } from './delivery.js';
4
4
  import { freshWatchLease } from './runtime.js';
5
+ import { canonicalRouteLocation } from './routes.js';
5
6
  function bindingProjection(record) {
6
7
  return {
7
8
  location: record.location,
@@ -53,14 +54,18 @@ export function terminalWakeEvidence(attempts) { return attempts.findLast((attem
53
54
  export function isWakeRouteAttemptable(route, attempts) {
54
55
  if (terminalWakeEvidence(attempts) !== undefined)
55
56
  return false;
56
- const failed = attempts.findLast((attempt) => attempt.routeKind === route.kind && attempt.outcome === 'failed');
57
- return failed === undefined || route.updatedAt > failed.at;
57
+ if (attempts.some((attempt) => attempt.routeKind === route.kind && attempt.outcome === 'unknown'))
58
+ return false;
59
+ return true;
58
60
  }
59
61
  export function hasAttemptableWakeRoute(routes, attempts) { return routes.some((route) => isWakeRouteAttemptable(route, attempts)); }
60
62
  export async function projectWakeEvidenceFromState(input) {
63
+ const canonicalLocation = await canonicalRouteLocation(input.location);
61
64
  const delivery = input.delivery ?? deriveDeliveryModel(input.state);
62
- const bindings = (await input.hostLedger.listPresence({ location: input.location, scopes: ['user'], now: input.now })).map(bindingProjection);
63
- const wakeRecords = await input.hostLedger.listEvidence({ location: input.location, kind: 'wake', now: input.now });
65
+ const bindings = (input.state.routes ?? [])
66
+ .filter((route) => route.location === canonicalLocation || route.location === input.location)
67
+ .map((route) => ({ location: route.location, participant: route.participant, sessionId: route.sessionId, channel: route.channel, route: { ...route, address: { ...route.address } }, updatedAt: route.updatedAt }));
68
+ const wakeRecords = await input.hostLedger.listEvidence({ location: canonicalLocation, kind: 'wake', now: input.now });
64
69
  const attemptsByBinding = new Map();
65
70
  for (const record of wakeRecords) {
66
71
  const actIndex = parseActivityId(record.activity);
@@ -72,7 +77,7 @@ export async function projectWakeEvidenceFromState(input) {
72
77
  existing.push(attempt);
73
78
  attemptsByBinding.set(key, existing);
74
79
  }
75
- const presentedRows = await projectPresentationEvidence({ hostLedger: input.hostLedger, location: input.location, now: input.now });
80
+ const presentedRows = await projectPresentationEvidence({ hostLedger: input.hostLedger, location: canonicalLocation, now: input.now });
76
81
  return {
77
82
  evidence(recipient, actIndex) {
78
83
  const recipientBindings = bindings.filter((binding) => nameKey(binding.participant) === nameKey(recipient));
package/dist/wake-port.js CHANGED
@@ -14,7 +14,7 @@ export class WakePort {
14
14
  if (result.outcome === 'cancelled')
15
15
  return result;
16
16
  if (result.outcome === 'unavailable') {
17
- if (result.retainRoute !== true)
17
+ if (result.routeStale === true)
18
18
  await hooks.invalidate?.(route, result);
19
19
  continue;
20
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrosheep/square",
3
- "version": "0.3.31",
3
+ "version": "0.3.33",
4
4
  "description": "A shared public square where agents join, catch activity, express, and step out when done.",
5
5
  "type": "module",
6
6
  "bin": {