@agentshouse/mdruntime-adapter 0.1.0-c2c54ea2d0d14 → 0.1.0-c2e62cffcd088

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 (85) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +6 -49
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +26 -231
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +212 -434
  8. package/dist/authored-path.d.ts +9 -0
  9. package/dist/authored-path.d.ts.map +1 -0
  10. package/dist/authored-path.js +34 -0
  11. package/dist/chunks.d.ts +36 -0
  12. package/dist/chunks.d.ts.map +1 -0
  13. package/dist/chunks.js +281 -0
  14. package/dist/digest.d.ts +0 -1
  15. package/dist/discovery.d.ts +40 -12
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +214 -47
  18. package/dist/history.d.ts +6 -0
  19. package/dist/history.d.ts.map +1 -0
  20. package/dist/history.js +85 -0
  21. package/dist/index.d.ts +9 -7
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +8 -5
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +6 -10
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +27 -42
  28. package/dist/read.d.ts +17 -70
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +70 -351
  31. package/dist/refusal.d.ts +6 -5
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +27 -11
  34. package/dist/room-query.d.ts +4 -0
  35. package/dist/room-query.d.ts.map +1 -0
  36. package/dist/room-query.js +36 -0
  37. package/dist/search.d.ts +4 -0
  38. package/dist/search.d.ts.map +1 -0
  39. package/dist/search.js +47 -0
  40. package/dist/session-content/check.d.ts +17 -0
  41. package/dist/session-content/index.d.ts +6 -0
  42. package/dist/session-content/parts.d.ts +30 -0
  43. package/dist/session-content/state.d.ts +59 -0
  44. package/dist/session-content/turn.d.ts +137 -0
  45. package/dist/site.d.ts +0 -1
  46. package/dist/site.d.ts.map +1 -1
  47. package/dist/site.js +94 -174
  48. package/dist/space-schema.d.ts +6 -0
  49. package/dist/space-schema.d.ts.map +1 -0
  50. package/dist/space-schema.js +11 -0
  51. package/dist/stream.d.ts +15 -16
  52. package/dist/stream.d.ts.map +1 -1
  53. package/dist/stream.js +242 -426
  54. package/dist/transport.d.ts +84 -44
  55. package/dist/transport.d.ts.map +1 -1
  56. package/dist/transport.js +89 -12
  57. package/dist/uncertain.d.ts +5 -0
  58. package/dist/uncertain.d.ts.map +1 -0
  59. package/dist/uncertain.js +11 -0
  60. package/dist/upload.d.ts +3 -2
  61. package/dist/upload.d.ts.map +1 -1
  62. package/dist/upload.js +10 -8
  63. package/dist/version.d.ts +0 -1
  64. package/dist/write.d.ts +6 -3
  65. package/dist/write.d.ts.map +1 -1
  66. package/dist/write.js +39 -48
  67. package/package.json +3 -2
  68. package/dist/app-reference.d.ts +0 -2
  69. package/dist/app-reference.d.ts.map +0 -1
  70. package/dist/app-reference.js +0 -2
  71. package/dist/crockford.d.ts +0 -4
  72. package/dist/crockford.d.ts.map +0 -1
  73. package/dist/crockford.js +0 -3
  74. package/dist/gather.d.ts +0 -4
  75. package/dist/gather.d.ts.map +0 -1
  76. package/dist/gather.js +0 -35
  77. package/dist/house-model.d.ts +0 -2
  78. package/dist/house-model.d.ts.map +0 -1
  79. package/dist/house-model.js +0 -484
  80. package/dist/part.d.ts +0 -15
  81. package/dist/part.d.ts.map +0 -1
  82. package/dist/part.js +0 -82
  83. package/dist/room-types.d.ts +0 -7
  84. package/dist/room-types.d.ts.map +0 -1
  85. package/dist/room-types.js +0 -124
package/dist/search.js ADDED
@@ -0,0 +1,47 @@
1
+ import { answeredFailure, doorRefusal } from './refusal.js';
2
+ import { houseDoorRoute } from './transport.js';
3
+ const ROOMS = '/rooms/';
4
+ function hitOf(file, locators) {
5
+ if (typeof file !== 'object' || file === null)
6
+ return null;
7
+ const { path, line, snippet } = file;
8
+ if (typeof path !== 'string' || !path.startsWith(ROOMS))
9
+ return null;
10
+ const slash = path.indexOf('/', ROOMS.length);
11
+ if (slash < 0)
12
+ return null;
13
+ const room = locators.get(path.slice(ROOMS.length, slash));
14
+ if (room === undefined)
15
+ return null;
16
+ return {
17
+ room,
18
+ path: path.slice(slash + 1),
19
+ ...(typeof line === 'number' ? { line } : {}),
20
+ ...(typeof snippet === 'string' ? { snippet } : {}),
21
+ };
22
+ }
23
+ export async function houseSearch(transport, tracked, request) {
24
+ const named = request.rooms === null
25
+ ? null
26
+ : tracked.filter((entry) => request.rooms.includes(entry.locator));
27
+ if (named !== null && named.length === 0)
28
+ return { kind: 'found', documents: [] };
29
+ const answer = await transport.door(houseDoorRoute('rooms/search'), {
30
+ query: request.text,
31
+ ...(named === null ? {} : { paths: named.map((entry) => `${ROOMS}${entry.handle}`) }),
32
+ });
33
+ if (answer.status === 401)
34
+ return { kind: 'revoked-authorization' };
35
+ const refusal = doorRefusal(answer.body);
36
+ if (refusal !== null)
37
+ return { kind: 'rejected', ...refusal };
38
+ const files = answer.body?.files;
39
+ if (answer.status !== 200 || !Array.isArray(files)) {
40
+ return answeredFailure(answer.status, answer.body);
41
+ }
42
+ const locators = new Map(tracked.map((entry) => [entry.handle, entry.locator]));
43
+ return {
44
+ kind: 'found',
45
+ documents: files.flatMap((file) => hitOf(file, locators) ?? []),
46
+ };
47
+ }
@@ -0,0 +1,17 @@
1
+ export type Check<T> = (value: unknown) => value is T;
2
+ export type Checked<C> = C extends Check<infer T> ? T : never;
3
+ type Shape = Readonly<Record<string, Check<unknown>>>;
4
+ export type Shaped<S extends Shape> = {
5
+ readonly [K in keyof S]: Checked<S[K]>;
6
+ };
7
+ export declare const text: Check<string>;
8
+ export declare const count: Check<number>;
9
+ export declare const figure: Check<number>;
10
+ export declare const instant: Check<string>;
11
+ export declare function oneOf<const V extends readonly string[]>(...values: V): Check<V[number]>;
12
+ export declare function where<T>(check: Check<T>, holds: (value: T) => boolean): Check<T>;
13
+ export declare function nullable<T>(check: Check<T>): Check<T | null>;
14
+ export declare function list<T>(check: Check<T>): Check<readonly T[]>;
15
+ export declare function exact<const S extends Shape>(shape: S): Check<Shaped<S>>;
16
+ export declare function anyOf<const C extends readonly Check<unknown>[]>(...checks: C): Check<Checked<C[number]>>;
17
+ export {};
@@ -0,0 +1,6 @@
1
+ export { isPart, turnCounts } from './parts.js';
2
+ export type { Counts, Part, PartOf } from './parts.js';
3
+ export { isState, standingState } from './state.js';
4
+ export type { SessionState, Tokens } from './state.js';
5
+ export { applied, isOperation, isTurn } from './turn.js';
6
+ export type { Operation, Turn } from './turn.js';
@@ -0,0 +1,30 @@
1
+ import { type Check, type Checked } from './check.js';
2
+ declare const PART: Check<import("./check.js").Shaped<{
3
+ readonly type: Check<"text">;
4
+ readonly text: Check<string>;
5
+ }> | import("./check.js").Shaped<{
6
+ readonly commands: Check<number>;
7
+ readonly edited: Check<number>;
8
+ readonly other: Check<number>;
9
+ readonly added: Check<number>;
10
+ readonly removed: Check<number>;
11
+ readonly failed: Check<number>;
12
+ readonly type: Check<"counts">;
13
+ }> | import("./check.js").Shaped<{
14
+ readonly type: Check<"image">;
15
+ readonly file: Check<string>;
16
+ readonly name: Check<string>;
17
+ readonly media_type: Check<string>;
18
+ }> | import("./check.js").Shaped<{
19
+ readonly type: Check<"notice">;
20
+ readonly kind: Check<"compaction" | "error" | "info" | "mode" | "model" | "retry" | "warning">;
21
+ readonly text: Check<string>;
22
+ }>>;
23
+ export type Part = Checked<typeof PART>;
24
+ export type PartOf<T extends Part['type']> = Extract<Part, {
25
+ readonly type: T;
26
+ }>;
27
+ export type Counts = Omit<PartOf<'counts'>, 'type'>;
28
+ export declare const isPart: Check<Part>;
29
+ export declare function turnCounts(parts: readonly Part[]): Counts;
30
+ export {};
@@ -0,0 +1,59 @@
1
+ import { type Check, type Checked } from './check.js';
2
+ export declare const TOKENS: Check<import("./check.js").Shaped<{
3
+ readonly input: Check<number>;
4
+ readonly output: Check<number>;
5
+ readonly cache_read: Check<number>;
6
+ readonly cache_write: Check<number>;
7
+ }>>;
8
+ export type Tokens = Checked<typeof TOKENS>;
9
+ declare const STATE: Check<import("./check.js").Shaped<{
10
+ readonly title: Check<string | null>;
11
+ readonly context: Check<import("./check.js").Shaped<{
12
+ readonly used: Check<number>;
13
+ readonly window: Check<number>;
14
+ readonly breakdown: Check<readonly import("./check.js").Shaped<{
15
+ readonly name: Check<string>;
16
+ readonly tokens: Check<number>;
17
+ }>[]>;
18
+ }> | null>;
19
+ readonly limits: Check<readonly import("./check.js").Shaped<{
20
+ readonly name: Check<string | null>;
21
+ readonly minutes: Check<number>;
22
+ readonly percent: Check<number>;
23
+ readonly resets: Check<string | null>;
24
+ }>[]>;
25
+ readonly cost: Check<import("./check.js").Shaped<{
26
+ readonly amount: Check<number>;
27
+ readonly currency: Check<string>;
28
+ }> | null>;
29
+ readonly tokens: Check<import("./check.js").Shaped<{
30
+ readonly input: Check<number>;
31
+ readonly output: Check<number>;
32
+ readonly cache_read: Check<number>;
33
+ readonly cache_write: Check<number>;
34
+ }> | null>;
35
+ readonly duration: Check<number | null>;
36
+ readonly files: Check<import("./check.js").Shaped<{
37
+ readonly count: Check<number>;
38
+ readonly added: Check<number>;
39
+ readonly removed: Check<number>;
40
+ }>>;
41
+ readonly branch: Check<string | null>;
42
+ readonly worktree: Check<string | null>;
43
+ readonly pull: Check<import("./check.js").Shaped<{
44
+ readonly number: Check<number>;
45
+ readonly url: Check<string>;
46
+ }> | null>;
47
+ readonly model: Check<string | null>;
48
+ readonly effort: Check<string | null>;
49
+ readonly mode: Check<string | null>;
50
+ readonly suggestion: Check<string | null>;
51
+ readonly running: Check<readonly import("./check.js").Shaped<{
52
+ readonly kind: Check<"monitor" | "schedule" | "shell" | "subagent" | "task">;
53
+ readonly count: Check<number>;
54
+ }>[]>;
55
+ }>>;
56
+ export type SessionState = Checked<typeof STATE>;
57
+ export declare const isState: Check<SessionState>;
58
+ export declare function standingState(state: SessionState, saved: string, ended: string | null): SessionState;
59
+ export {};
@@ -0,0 +1,137 @@
1
+ import { type Check, type Checked } from './check.js';
2
+ import { type Part } from './parts.js';
3
+ declare const OPERATION: Check<import("./check.js").Shaped<{
4
+ readonly op: Check<"start">;
5
+ readonly index: Check<number>;
6
+ readonly part: Check<import("./check.js").Shaped<{
7
+ readonly type: Check<"text">;
8
+ readonly text: Check<string>;
9
+ }> | import("./check.js").Shaped<{
10
+ readonly commands: Check<number>;
11
+ readonly edited: Check<number>;
12
+ readonly other: Check<number>;
13
+ readonly added: Check<number>;
14
+ readonly removed: Check<number>;
15
+ readonly failed: Check<number>;
16
+ readonly type: Check<"counts">;
17
+ }> | import("./check.js").Shaped<{
18
+ readonly type: Check<"image">;
19
+ readonly file: Check<string>;
20
+ readonly name: Check<string>;
21
+ readonly media_type: Check<string>;
22
+ }> | import("./check.js").Shaped<{
23
+ readonly type: Check<"notice">;
24
+ readonly kind: Check<"compaction" | "error" | "info" | "mode" | "model" | "retry" | "warning">;
25
+ readonly text: Check<string>;
26
+ }>>;
27
+ }> | import("./check.js").Shaped<{
28
+ readonly op: Check<"append">;
29
+ readonly index: Check<number>;
30
+ readonly text: Check<string>;
31
+ }> | import("./check.js").Shaped<{
32
+ readonly op: Check<"set">;
33
+ readonly index: Check<number>;
34
+ readonly part: Check<import("./check.js").Shaped<{
35
+ readonly type: Check<"text">;
36
+ readonly text: Check<string>;
37
+ }> | import("./check.js").Shaped<{
38
+ readonly commands: Check<number>;
39
+ readonly edited: Check<number>;
40
+ readonly other: Check<number>;
41
+ readonly added: Check<number>;
42
+ readonly removed: Check<number>;
43
+ readonly failed: Check<number>;
44
+ readonly type: Check<"counts">;
45
+ }> | import("./check.js").Shaped<{
46
+ readonly type: Check<"image">;
47
+ readonly file: Check<string>;
48
+ readonly name: Check<string>;
49
+ readonly media_type: Check<string>;
50
+ }> | import("./check.js").Shaped<{
51
+ readonly type: Check<"notice">;
52
+ readonly kind: Check<"compaction" | "error" | "info" | "mode" | "model" | "retry" | "warning">;
53
+ readonly text: Check<string>;
54
+ }>>;
55
+ }>>;
56
+ export type Operation = Checked<typeof OPERATION>;
57
+ export declare const isOperation: Check<Operation>;
58
+ declare const TURN: Check<import("./check.js").Shaped<{
59
+ readonly parts: Check<readonly (import("./check.js").Shaped<{
60
+ readonly type: Check<"text">;
61
+ readonly text: Check<string>;
62
+ }> | import("./check.js").Shaped<{
63
+ readonly commands: Check<number>;
64
+ readonly edited: Check<number>;
65
+ readonly other: Check<number>;
66
+ readonly added: Check<number>;
67
+ readonly removed: Check<number>;
68
+ readonly failed: Check<number>;
69
+ readonly type: Check<"counts">;
70
+ }> | import("./check.js").Shaped<{
71
+ readonly type: Check<"image">;
72
+ readonly file: Check<string>;
73
+ readonly name: Check<string>;
74
+ readonly media_type: Check<string>;
75
+ }> | import("./check.js").Shaped<{
76
+ readonly type: Check<"notice">;
77
+ readonly kind: Check<"compaction" | "error" | "info" | "mode" | "model" | "retry" | "warning">;
78
+ readonly text: Check<string>;
79
+ }>)[]>;
80
+ readonly tokens: Check<import("./check.js").Shaped<{
81
+ readonly input: Check<number>;
82
+ readonly output: Check<number>;
83
+ readonly cache_read: Check<number>;
84
+ readonly cache_write: Check<number>;
85
+ }> | null>;
86
+ readonly state: Check<import("./check.js").Shaped<{
87
+ readonly title: Check<string | null>;
88
+ readonly context: Check<import("./check.js").Shaped<{
89
+ readonly used: Check<number>;
90
+ readonly window: Check<number>;
91
+ readonly breakdown: Check<readonly import("./check.js").Shaped<{
92
+ readonly name: Check<string>;
93
+ readonly tokens: Check<number>;
94
+ }>[]>;
95
+ }> | null>;
96
+ readonly limits: Check<readonly import("./check.js").Shaped<{
97
+ readonly name: Check<string | null>;
98
+ readonly minutes: Check<number>;
99
+ readonly percent: Check<number>;
100
+ readonly resets: Check<string | null>;
101
+ }>[]>;
102
+ readonly cost: Check<import("./check.js").Shaped<{
103
+ readonly amount: Check<number>;
104
+ readonly currency: Check<string>;
105
+ }> | null>;
106
+ readonly tokens: Check<import("./check.js").Shaped<{
107
+ readonly input: Check<number>;
108
+ readonly output: Check<number>;
109
+ readonly cache_read: Check<number>;
110
+ readonly cache_write: Check<number>;
111
+ }> | null>;
112
+ readonly duration: Check<number | null>;
113
+ readonly files: Check<import("./check.js").Shaped<{
114
+ readonly count: Check<number>;
115
+ readonly added: Check<number>;
116
+ readonly removed: Check<number>;
117
+ }>>;
118
+ readonly branch: Check<string | null>;
119
+ readonly worktree: Check<string | null>;
120
+ readonly pull: Check<import("./check.js").Shaped<{
121
+ readonly number: Check<number>;
122
+ readonly url: Check<string>;
123
+ }> | null>;
124
+ readonly model: Check<string | null>;
125
+ readonly effort: Check<string | null>;
126
+ readonly mode: Check<string | null>;
127
+ readonly suggestion: Check<string | null>;
128
+ readonly running: Check<readonly import("./check.js").Shaped<{
129
+ readonly kind: Check<"monitor" | "schedule" | "shell" | "subagent" | "task">;
130
+ readonly count: Check<number>;
131
+ }>[]>;
132
+ }>>;
133
+ }>>;
134
+ export type Turn = Checked<typeof TURN>;
135
+ export declare const isTurn: Check<Turn>;
136
+ export declare function applied(parts: readonly Part[], operation: Operation): readonly Part[] | null;
137
+ export {};
package/dist/site.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import type { Adapter } from '@agentshouse/mdruntime';
2
2
  import { type HouseSiteTransport } from './transport.js';
3
3
  export declare function createSiteAdapter(transport: HouseSiteTransport, snapshot?: boolean): Adapter;
4
- //# sourceMappingURL=site.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAWR,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAoCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CA4P1F"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;AAchC,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAwBxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAoK1F"}
package/dist/site.js CHANGED
@@ -1,17 +1,16 @@
1
- import { stepped } from '@agentshouse/mdruntime';
2
- import { actionOutcome, SITE_SUBMIT } from './actions.js';
1
+ import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
2
+ import { actionOutcome } from './actions.js';
3
+ import { chunkedHead, chunkPart, siteChunkList } from './chunks.js';
3
4
  import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
4
- import { manifestedModels, partModels, streamedModels, viewModels } from './model.js';
5
- import { bootstrapping, emptyScope, housePart, manifested, parseEnumeration, parseSiteParted, partInventory, refreshFrom, viewOf, wholeView, } from './read.js';
6
- import { PART_ATTEMPTS, partArrival, partFrame, unverifiedPart } from './part.js';
7
- import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
8
- import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
5
+ import { answeredFailure, discoveryFailure } from './refusal.js';
6
+ import { admittedPath } from './authored-path.js';
7
+ import { siteQuery } from './room-query.js';
9
8
  import { houseNotifications } from './stream.js';
10
- import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILES, } from './transport.js';
11
- import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
12
- const UNCERTAIN = { kind: 'transport-uncertainty' };
9
+ import { houseSiteRoute, SITE_DOOR_ACTS, SITE_FILES, } from './transport.js';
10
+ import { UNANSWERED, unusable } from './uncertain.js';
11
+ import { followsVersion, reachedVersion, roomVersion } from './version.js';
13
12
  function unfound() {
14
- return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
13
+ return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
15
14
  }
16
15
  function siteRoom(tracked) {
17
16
  return {
@@ -19,174 +18,102 @@ function siteRoom(tracked) {
19
18
  locator: tracked.locator,
20
19
  handle: tracked.handle,
21
20
  roomVersion: roomVersion(tracked),
22
- operations: { write: [], delete: [] },
21
+ operations: { write: [], erase: [] },
23
22
  replica: { selection: tracked.locator, admission: 'admitted', offline: 'open' },
23
+ typedSelection: null,
24
24
  providerOwnedPaths: [],
25
+ authoredPaths: ['**'],
25
26
  };
26
27
  }
27
28
  export function createSiteAdapter(transport, snapshot = false) {
28
- const notifications = houseNotifications(transport, 'site');
29
+ const notifications = houseNotifications(transport, 'site', {
30
+ opened: async () => {
31
+ const found = await discovered();
32
+ return found.kind === 'discovery' ? found : null;
33
+ },
34
+ changed: () => null,
35
+ });
29
36
  const tracked = new Map();
30
- const expired = new Map();
37
+ const chunked = new Map();
31
38
  function fileRoute(request) {
32
39
  const entry = tracked.get(request.locator);
33
40
  if (entry === undefined)
34
41
  return { kind: 'room-not-readable', locator: request.locator };
35
42
  return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
36
43
  }
37
- async function enumerated(entry, from, page) {
38
- const answer = await transport.door(SITE_DOOR_ENUMERATE, {
39
- positions: [
40
- page === undefined
41
- ? presented(entry.authority, from)
42
- : {
43
- ...presented(entry.authority, { position: page.after, logEpoch: from.logEpoch }),
44
- page: { through: page.through, read: page.read },
45
- },
46
- ],
47
- });
48
- const classified = classifyRead(answer.status, answer.body, entry.locator);
49
- if (classified !== null)
50
- return classified;
51
- const found = parseEnumeration(answer.body, 'site');
52
- if (found === null)
53
- return UNCERTAIN;
54
- return viewOf(found, entry) ?? { kind: 'room-not-readable', locator: entry.locator };
55
- }
56
- async function enumeration(entry, from) {
57
- const first = await enumerated(entry, from);
58
- return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
44
+ async function listedRoom(entry) {
45
+ const past = chunked.get(entry.locator)?.position;
46
+ const listed = siteChunkList(await transport.read(`${houseSiteRoute('chunks')}/${entry.authority}${past === undefined ? '' : `?expired=${past}`}`), entry.locator);
47
+ if ('kind' in listed)
48
+ return listed;
49
+ const head = await chunkedHead(listed, entry);
50
+ if (head.kind === 'bootstrap')
51
+ chunked.set(entry.locator, listed);
52
+ return head;
59
53
  }
60
- async function partedRoom(entry) {
61
- const cut = expired.get(entry.locator);
62
- const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`);
63
- const classified = classifyDoor(answer.status, answer.body, entry.locator);
64
- if (classified !== null)
65
- return classified;
66
- const room = parseSiteParted(answer.body);
67
- return room === null || room.anchor !== entry.authority ? UNCERTAIN : room;
54
+ async function chunkPage(entry, id, arriving) {
55
+ const room = chunked.get(entry.locator);
56
+ const address = room?.chunks.get(id);
57
+ if (room === undefined || address === undefined)
58
+ return UNANSWERED;
59
+ const read = await transport.download(address.url);
60
+ if (read.status !== 200)
61
+ return answeredFailure(read.status, null);
62
+ return chunkPart(read.body, room, id, arriving);
68
63
  }
69
- async function fetchedPart(entry, room, listed, received, arriving) {
70
- if (received !== undefined) {
71
- const kept = new Uint8Array(received);
72
- const held = await housePart(room, kept, listed, 'site');
73
- if (held !== null)
74
- return 'kind' in held ? held : { scope: held, frame: kept };
75
- }
76
- for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
77
- const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}?part=${encodeURIComponent(listed.part)}`, partArrival(listed, arriving));
78
- const failure = classifyRead(answer.status, answer.body, entry.locator);
79
- if (failure?.kind === 'beyond-horizon')
80
- expired.set(entry.locator, room.position);
81
- if (failure !== null)
82
- return failure;
83
- const frame = partFrame(answer.body);
84
- if (frame === null)
85
- continue;
86
- const scope = await housePart(room, frame, listed, 'site');
87
- if (scope !== null)
88
- return 'kind' in scope ? scope : { scope, frame };
89
- }
90
- return unverifiedPart(entry.locator);
91
- }
92
- async function refreshed(entry, fromRoomVersion) {
93
- const from = logPosition(fromRoomVersion);
94
- if (from === null)
95
- return { kind: 'beyond-horizon' };
96
- const streamed = await stepped(notifications.advance(entry, from));
97
- if (streamed !== null) {
98
- const models = await streamedModels(streamed.schemas, entry, 'site');
99
- return models === undefined ? streamed.page : { ...streamed.page, models };
100
- }
101
- const view = await enumeration(entry, from);
102
- if ('kind' in view)
103
- return view;
104
- notifications.reach(entry.authority, view);
105
- const answer = await refreshFrom(view, fromRoomVersion);
106
- if (answer.kind !== 'net-advancement')
107
- return answer;
108
- const models = await viewModels(view, entry);
109
- return models === undefined ? answer : { ...answer, models };
64
+ async function discovered() {
65
+ const answer = await transport.read(houseSiteRoute('discover'));
66
+ const failed = discoveryFailure(answer.status, answer.body);
67
+ if (failed !== null)
68
+ return failed;
69
+ const document = parseSiteDiscovery(answer.body);
70
+ if (document === null)
71
+ return unusable();
72
+ const entries = siteTracked(document);
73
+ tracked.clear();
74
+ for (const entry of entries)
75
+ tracked.set(entry.locator, entry);
76
+ notifications.track(entries);
77
+ return {
78
+ ...mapDiscovery(document, entries.map(siteRoom), siteCapabilities()),
79
+ queriesOnly: document.queriesOnly.map(({ roomRef, roomHandle }) => ({
80
+ locator: roomRef,
81
+ handle: roomHandle,
82
+ name: roomHandle,
83
+ })),
84
+ };
110
85
  }
111
86
  return {
112
87
  localSaves: true,
113
- exhaustiveDiscovery: true,
114
88
  roomTypes: HOUSE_ROOM_TYPES,
115
- nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
89
+ typedPaths: HOUSE_TYPED_PATHS,
90
+ pathRule: admittedPath,
116
91
  async authorize() {
117
92
  return {};
118
93
  },
119
- async discover() {
120
- const answer = await transport.read(SITE_DOOR_DISCOVER);
121
- const failed = discoveryFailure(answer.status, answer.body);
122
- if (failed !== null)
123
- return failed;
124
- const document = parseSiteDiscovery(answer.body);
125
- if (document === null)
126
- return UNCERTAIN;
127
- const entries = siteTracked(document);
128
- tracked.clear();
129
- for (const entry of entries)
130
- tracked.set(entry.locator, entry);
131
- notifications.track(entries);
132
- return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
133
- },
134
94
  async bootstrap(_authorization, request) {
135
95
  const entry = tracked.get(request.locator);
136
96
  if (entry === undefined)
137
97
  return { kind: 'room-not-readable', locator: request.locator };
138
- let continued;
139
- let inventory;
140
- if (request.pageToken === undefined) {
141
- const room = await partedRoom(entry);
142
- if ('kind' in room)
143
- return room;
144
- const { models, seen } = await manifestedModels(room, entry);
145
- continued = { room, next: 0, seen };
146
- inventory = partInventory(room);
147
- if (inventory.parts > 0) {
148
- return manifested(room, inventory, JSON.stringify(continued), models);
149
- }
150
- }
151
- else
152
- continued = JSON.parse(request.pageToken);
153
- const listed = continued.room.parts[continued.next];
154
- const sent = listed === undefined
155
- ? { scope: emptyScope(continued.room), frame: null }
156
- : await fetchedPart(entry, continued.room, listed, request.received, request.arriving);
157
- if ('kind' in sent)
158
- return sent;
159
- const { scope } = sent;
160
- notifications.reach(entry.authority, scope);
161
- const next = continued.next + 1;
162
- const more = next < continued.room.parts.length;
163
- const seen = [
164
- ...continued.seen,
165
- ...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
166
- ];
167
- const models = await partModels(scope, entry, new Set(seen), !more);
168
- const { folders: _folders, ...page } = await stepped(bootstrapping(scope));
169
- return {
170
- ...page,
171
- ...(models === undefined ? {} : { models }),
172
- ...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
173
- ...(inventory === undefined ? {} : { inventory }),
174
- ...(sent.frame === null ? {} : { received: sent.frame }),
175
- };
98
+ return request.pageToken === undefined
99
+ ? listedRoom(entry)
100
+ : chunkPage(entry, request.pageToken, request.arriving);
176
101
  },
177
- async refresh(_authorization, request) {
178
- const entry = tracked.get(request.locator);
179
- if (entry === undefined)
180
- return { kind: 'room-not-readable', locator: request.locator };
181
- if (request.pageToken !== undefined)
182
- return UNCERTAIN;
183
- if (snapshot) {
184
- return request.fromRoomVersion === roomVersion(entry)
185
- ? { kind: 'still-current' }
186
- : { kind: 'beyond-horizon' };
102
+ ...(snapshot
103
+ ? {
104
+ discover: discovered,
105
+ async refresh(_authorization, request) {
106
+ const entry = tracked.get(request.locator);
107
+ if (entry === undefined)
108
+ return { kind: 'room-not-readable', locator: request.locator };
109
+ if (request.pageToken !== undefined)
110
+ return UNANSWERED;
111
+ return request.fromRoomVersion === roomVersion(entry)
112
+ ? { kind: 'still-current' }
113
+ : { kind: 'beyond-horizon' };
114
+ },
187
115
  }
188
- return refreshed(entry, request.fromRoomVersion);
189
- },
116
+ : {}),
190
117
  async mutate() {
191
118
  return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {}, retryable: false };
192
119
  },
@@ -196,6 +123,7 @@ export function createSiteAdapter(transport, snapshot = false) {
196
123
  async history() {
197
124
  return { kind: 'no-history' };
198
125
  },
126
+ queryHouse: snapshot ? undefined : (_authorization, request) => siteQuery(transport, request),
199
127
  async binary(_authorization, request) {
200
128
  const route = fileRoute(request);
201
129
  if (typeof route !== 'string')
@@ -203,11 +131,15 @@ export function createSiteAdapter(transport, snapshot = false) {
203
131
  const read = await transport.download(route);
204
132
  if (read.status === 404)
205
133
  return unfound();
206
- return read.status === 200 && read.body !== null
207
- ? { kind: 'binary', body: read.body, mediaType: read.mediaType }
208
- : UNCERTAIN;
134
+ if (read.status !== 200)
135
+ return answeredFailure(read.status, null);
136
+ if (read.body === null)
137
+ return unusable();
138
+ return { kind: 'binary', body: read.body, mediaType: read.mediaType };
209
139
  },
210
140
  async link(_authorization, request) {
141
+ if (request.kind === 'key')
142
+ return unfound();
211
143
  const route = fileRoute(request);
212
144
  if (typeof route !== 'string')
213
145
  return route;
@@ -224,7 +156,10 @@ export function createSiteAdapter(transport, snapshot = false) {
224
156
  return followsVersion(version, next);
225
157
  },
226
158
  async action(_authorization, request) {
227
- if (request.name !== SITE_SUBMIT) {
159
+ const route = Object.hasOwn(SITE_DOOR_ACTS, request.name)
160
+ ? SITE_DOOR_ACTS[request.name]
161
+ : null;
162
+ if (route === null) {
228
163
  return {
229
164
  kind: 'rejected',
230
165
  code: 'action-unimplemented',
@@ -233,29 +168,14 @@ export function createSiteAdapter(transport, snapshot = false) {
233
168
  };
234
169
  }
235
170
  if (!transport.online())
236
- return UNCERTAIN;
237
- return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITE_SUBMIT);
171
+ return UNANSWERED;
172
+ return actionOutcome(await transport.door(route, request.input), request.name, request.input);
238
173
  },
239
174
  roomStream: snapshot
240
175
  ? undefined
241
176
  : {
242
- hold(rooms) {
243
- notifications.send(rooms.flatMap((room) => {
244
- const entry = tracked.get(room.locator);
245
- const at = logPosition(room.roomVersion);
246
- if (entry === undefined || at === null)
247
- return [];
248
- notifications.reach(entry.authority, at);
249
- return [presented(entry.authority, at)];
250
- }));
251
- },
252
- reopen: notifications.reopen,
177
+ hold: notifications.send,
253
178
  observe: notifications.observe,
254
- published(locator, roomVersion) {
255
- const at = logPosition(roomVersion);
256
- if (at !== null)
257
- notifications.published(locator, at);
258
- },
259
179
  },
260
180
  serviceMode: notifications.serviceMode,
261
181
  };