@agentshouse/mdruntime-adapter 0.1.0-cf059d0c8e9c0 → 0.1.0-cf151c882c69c

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 (88) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +7 -2
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +72 -10
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +186 -177
  8. package/dist/authored-path.d.ts +61 -0
  9. package/dist/authored-path.d.ts.map +1 -0
  10. package/dist/authored-path.js +166 -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 +32 -7
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +203 -29
  18. package/dist/history.d.ts +1 -7
  19. package/dist/history.d.ts.map +1 -1
  20. package/dist/history.js +24 -30
  21. package/dist/index.d.ts +7 -8
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +6 -6
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +6 -9
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +28 -26
  28. package/dist/read.d.ts +20 -24
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +103 -173
  31. package/dist/refusal.d.ts +6 -2
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +28 -7
  34. package/dist/renamed.d.ts +10 -0
  35. package/dist/renamed.d.ts.map +1 -0
  36. package/dist/renamed.js +29 -0
  37. package/dist/room-query.d.ts +4 -0
  38. package/dist/room-query.d.ts.map +1 -0
  39. package/dist/room-query.js +63 -0
  40. package/dist/search.d.ts +4 -0
  41. package/dist/search.d.ts.map +1 -0
  42. package/dist/search.js +47 -0
  43. package/dist/session-content/check.d.ts +17 -0
  44. package/dist/session-content/index.d.ts +6 -0
  45. package/dist/session-content/parts.d.ts +30 -0
  46. package/dist/session-content/state.d.ts +59 -0
  47. package/dist/session-content/turn.d.ts +137 -0
  48. package/dist/site.d.ts +0 -1
  49. package/dist/site.d.ts.map +1 -1
  50. package/dist/site.js +82 -52
  51. package/dist/space-schema.d.ts +6 -0
  52. package/dist/space-schema.d.ts.map +1 -0
  53. package/dist/space-schema.js +11 -0
  54. package/dist/stream.d.ts +4 -4
  55. package/dist/stream.d.ts.map +1 -1
  56. package/dist/stream.js +152 -77
  57. package/dist/transport.d.ts +65 -31
  58. package/dist/transport.d.ts.map +1 -1
  59. package/dist/transport.js +56 -15
  60. package/dist/uncertain.d.ts +5 -0
  61. package/dist/uncertain.d.ts.map +1 -0
  62. package/dist/uncertain.js +11 -0
  63. package/dist/upload.d.ts +7 -2
  64. package/dist/upload.d.ts.map +1 -1
  65. package/dist/upload.js +49 -6
  66. package/dist/version.d.ts +0 -1
  67. package/dist/write.d.ts +0 -2
  68. package/dist/write.d.ts.map +1 -1
  69. package/dist/write.js +36 -53
  70. package/package.json +4 -3
  71. package/dist/app-reference.d.ts +0 -2
  72. package/dist/app-reference.d.ts.map +0 -1
  73. package/dist/app-reference.js +0 -2
  74. package/dist/crockford.d.ts +0 -4
  75. package/dist/crockford.d.ts.map +0 -1
  76. package/dist/crockford.js +0 -3
  77. package/dist/house-model.d.ts +0 -2249
  78. package/dist/house-model.d.ts.map +0 -1
  79. package/dist/house-model.js +0 -1237
  80. package/dist/part.d.ts +0 -14
  81. package/dist/part.d.ts.map +0 -1
  82. package/dist/part.js +0 -90
  83. package/dist/room-stream.d.ts +0 -19
  84. package/dist/room-stream.d.ts.map +0 -1
  85. package/dist/room-stream.js +0 -57
  86. package/dist/room-types.d.ts +0 -7
  87. package/dist/room-types.d.ts.map +0 -1
  88. package/dist/room-types.js +0 -126
@@ -0,0 +1,63 @@
1
+ import { answeredFailure, doorRefusal } from './refusal.js';
2
+ import { houseDoorRoute, SITE_QUERY_ROUTE_CHARACTERS, siteQueryRoute, } from './transport.js';
3
+ const TOO_LONG_FOR_AN_ADDRESS = {
4
+ kind: 'rejected',
5
+ code: 'query_too_large',
6
+ fields: {},
7
+ retryable: false,
8
+ };
9
+ function infoAsked(request) {
10
+ const root = `/rooms/${request.room}`;
11
+ const follows = request.follows === undefined ? {} : { follows: request.follows };
12
+ if (!('query' in request)) {
13
+ const { path, after } = request;
14
+ return {
15
+ path: `${root}/${path}`,
16
+ ...(after === undefined ? {} : { cursor: after }),
17
+ ...follows,
18
+ };
19
+ }
20
+ const { after, ...query } = request.query;
21
+ return { path: root, query, ...(after === undefined ? {} : { cursor: after }), ...follows };
22
+ }
23
+ export async function houseQuery(transport, request) {
24
+ return queriedPage(await transport.door(houseDoorRoute('info'), infoAsked(request)), 'next_cursor');
25
+ }
26
+ export async function siteQuery(transport, request) {
27
+ const asked = 'query' in request
28
+ ? request.query
29
+ : { path: request.path, ...(request.after === undefined ? {} : { after: request.after }) };
30
+ const route = siteQueryRoute(request.room, asked, request.fresh);
31
+ if (route.length > SITE_QUERY_ROUTE_CHARACTERS)
32
+ return TOO_LONG_FOR_AN_ADDRESS;
33
+ return queriedPage(await transport.read(route), 'next');
34
+ }
35
+ function queriedPage(answer, named) {
36
+ if (answer.status === 401)
37
+ return { kind: 'revoked-authorization' };
38
+ const refusal = doorRefusal(answer.body);
39
+ if (refusal !== null)
40
+ return { kind: 'rejected', ...refusal };
41
+ const body = (answer.body ?? {});
42
+ const { documents, groups, total, totalCapped, capped } = body;
43
+ const next = body[named];
44
+ if (answer.status !== 200 || !(Array.isArray(documents) || Array.isArray(groups))) {
45
+ return answeredFailure(answer.status, answer.body);
46
+ }
47
+ const continued = typeof next === 'string' ? { next } : {};
48
+ if (Array.isArray(groups)) {
49
+ return {
50
+ kind: 'groups',
51
+ groups: groups,
52
+ ...continued,
53
+ ...(capped === true ? { capped } : {}),
54
+ };
55
+ }
56
+ return {
57
+ kind: 'rows',
58
+ documents: documents,
59
+ ...continued,
60
+ ...(typeof total === 'number' ? { total } : {}),
61
+ ...(totalCapped === true ? { totalCapped } : {}),
62
+ };
63
+ }
@@ -0,0 +1,4 @@
1
+ import type { SearchAnswer, SearchAsk } from '@agentshouse/mdruntime';
2
+ import type { TrackedAuthority } from './discovery.js';
3
+ import { type HouseTransport } from './transport.js';
4
+ export declare function houseSearch(transport: Pick<HouseTransport, 'door'>, tracked: readonly TrackedAuthority[], request: SearchAsk): Promise<SearchAnswer>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,wBAAwB,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAoBrE,wBAAsB,WAAW,CAC/B,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,YAAY,CAAC,CAsBvB"}
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,EAQR,MAAM,wBAAwB,CAAC;AAehC,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuBxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAkK1F"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,OAAO,EASR,MAAM,wBAAwB,CAAC;AAchC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CA2K1F"}
package/dist/site.js CHANGED
@@ -1,16 +1,31 @@
1
- import { stepped } from '@agentshouse/mdruntime';
1
+ import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
2
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 { bootstrapping } from './read.js';
5
- import { roomStreams } from './room-stream.js';
6
- import { classifyDoor, discoveryFailure } from './refusal.js';
7
- 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';
8
8
  import { houseNotifications } from './stream.js';
9
- import { houseSiteRoute, SITE_DOOR_SUBMIT, SITE_FILES, SITE_SUBMISSION, } from './transport.js';
10
- import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
11
- const UNCERTAIN = { kind: 'transport-uncertainty' };
9
+ import { houseSiteRoute, SITE_DOOR_ACTS, SITE_DOOR_OPS, SITE_DOOR_TOOL, SITE_FILES, } from './transport.js';
10
+ import { UNANSWERED, unusable } from './uncertain.js';
11
+ import { followsVersion, reachedVersion, roomVersion } from './version.js';
12
+ function siteDoorRequest(request) {
13
+ const { op, ...input } = (request.input ?? {});
14
+ if (request.name !== SITE_DOOR_TOOL || typeof op !== 'string')
15
+ return request;
16
+ const named = Object.entries(SITE_DOOR_ACTS).find(([, route]) => route === SITE_DOOR_OPS[op]);
17
+ return named === undefined ? request : { ...request, name: named[0], input };
18
+ }
12
19
  function unfound() {
13
- return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
20
+ return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
21
+ }
22
+ function siteCopies(copies) {
23
+ if (copies === null || copies === undefined)
24
+ return [];
25
+ return copies.split(', ').map((offered) => {
26
+ const [url = '', width = ''] = offered.split(' ');
27
+ return { url, width: Number.parseInt(width, 10) };
28
+ });
14
29
  }
15
30
  function siteRoom(tracked) {
16
31
  return {
@@ -18,9 +33,11 @@ function siteRoom(tracked) {
18
33
  locator: tracked.locator,
19
34
  handle: tracked.handle,
20
35
  roomVersion: roomVersion(tracked),
21
- operations: { write: [], delete: [] },
36
+ operations: { write: [], erase: [] },
22
37
  replica: { selection: tracked.locator, admission: 'admitted', offline: 'open' },
38
+ typedSelection: null,
23
39
  providerOwnedPaths: [],
40
+ authoredPaths: ['**'],
24
41
  };
25
42
  }
26
43
  export function createSiteAdapter(transport, snapshot = false) {
@@ -32,36 +49,32 @@ export function createSiteAdapter(transport, snapshot = false) {
32
49
  changed: () => null,
33
50
  });
34
51
  const tracked = new Map();
35
- const read = new Map();
36
- const rooms = roomStreams('site');
52
+ const chunked = new Map();
37
53
  function fileRoute(request) {
38
54
  const entry = tracked.get(request.locator);
39
55
  if (entry === undefined)
40
56
  return { kind: 'room-not-readable', locator: request.locator };
41
57
  return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
42
58
  }
43
- async function openedRoom(entry, arriving, signal) {
44
- const cut = read.get(entry.locator);
45
- const answered = await transport.streamed(`${houseSiteRoute('bootstrap')}/${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`, signal ?? new AbortController().signal);
46
- if (answered.room === null)
47
- return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN;
48
- const head = await rooms.head(entry, answered.room, arriving, signal);
49
- const at = head.kind === 'bootstrap' ? logPosition(head.roomVersion) : null;
50
- if (at !== null)
51
- read.set(entry.locator, at.position);
59
+ async function listedRoom(entry) {
60
+ const past = chunked.get(entry.locator)?.position;
61
+ const listed = siteChunkList(await transport.read(`${houseSiteRoute('chunks')}/${entry.authority}${past === undefined ? '' : `?expired=${past}`}`), entry.locator);
62
+ if ('kind' in listed)
63
+ return listed;
64
+ const head = await chunkedHead(listed, entry);
65
+ if (head.kind === 'bootstrap')
66
+ chunked.set(entry.locator, listed);
52
67
  return head;
53
68
  }
54
- async function streamedPage(entry, token) {
55
- const part = await rooms.part(entry, token);
56
- if ('kind' in part)
57
- return part;
58
- const { folders: _folders, ...page } = await stepped(bootstrapping(part.scope));
59
- return {
60
- ...page,
61
- ...(part.models === undefined ? {} : { models: part.models }),
62
- ...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
63
- bytes: part.bytes,
64
- };
69
+ async function chunkPage(entry, id, arriving) {
70
+ const room = chunked.get(entry.locator);
71
+ const address = room?.chunks.get(id);
72
+ if (room === undefined || address === undefined)
73
+ return UNANSWERED;
74
+ const read = await transport.download(address.url);
75
+ if (read.status !== 200)
76
+ return answeredFailure(read.status, null);
77
+ return chunkPart(read.body, room, id, arriving);
65
78
  }
66
79
  async function discovered() {
67
80
  const answer = await transport.read(houseSiteRoute('discover'));
@@ -70,18 +83,26 @@ export function createSiteAdapter(transport, snapshot = false) {
70
83
  return failed;
71
84
  const document = parseSiteDiscovery(answer.body);
72
85
  if (document === null)
73
- return UNCERTAIN;
86
+ return unusable();
74
87
  const entries = siteTracked(document);
75
88
  tracked.clear();
76
89
  for (const entry of entries)
77
90
  tracked.set(entry.locator, entry);
78
91
  notifications.track(entries);
79
- return mapDiscovery(document, entries.map(siteRoom), siteCapabilities());
92
+ return {
93
+ ...mapDiscovery(document, entries.map(siteRoom), siteCapabilities()),
94
+ queriesOnly: document.queriesOnly.map(({ roomRef, roomHandle }) => ({
95
+ locator: roomRef,
96
+ handle: roomHandle,
97
+ name: roomHandle,
98
+ })),
99
+ };
80
100
  }
81
101
  return {
82
102
  localSaves: true,
83
103
  roomTypes: HOUSE_ROOM_TYPES,
84
- nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
104
+ typedPaths: HOUSE_TYPED_PATHS,
105
+ pathRule: admittedPath,
85
106
  async authorize() {
86
107
  return {};
87
108
  },
@@ -90,8 +111,8 @@ export function createSiteAdapter(transport, snapshot = false) {
90
111
  if (entry === undefined)
91
112
  return { kind: 'room-not-readable', locator: request.locator };
92
113
  return request.pageToken === undefined
93
- ? openedRoom(entry, request.arriving, request.signal)
94
- : streamedPage(entry, request.pageToken);
114
+ ? listedRoom(entry)
115
+ : chunkPage(entry, request.pageToken, request.arriving);
95
116
  },
96
117
  ...(snapshot
97
118
  ? {
@@ -101,7 +122,7 @@ export function createSiteAdapter(transport, snapshot = false) {
101
122
  if (entry === undefined)
102
123
  return { kind: 'room-not-readable', locator: request.locator };
103
124
  if (request.pageToken !== undefined)
104
- return UNCERTAIN;
125
+ return UNANSWERED;
105
126
  return request.fromRoomVersion === roomVersion(entry)
106
127
  ? { kind: 'still-current' }
107
128
  : { kind: 'beyond-horizon' };
@@ -117,6 +138,7 @@ export function createSiteAdapter(transport, snapshot = false) {
117
138
  async history() {
118
139
  return { kind: 'no-history' };
119
140
  },
141
+ queryHouse: (_authorization, request) => siteQuery(transport, request),
120
142
  async binary(_authorization, request) {
121
143
  const route = fileRoute(request);
122
144
  if (typeof route !== 'string')
@@ -124,11 +146,21 @@ export function createSiteAdapter(transport, snapshot = false) {
124
146
  const read = await transport.download(route);
125
147
  if (read.status === 404)
126
148
  return unfound();
127
- return read.status === 200 && read.body !== null
128
- ? { kind: 'binary', body: read.body, mediaType: read.mediaType }
129
- : UNCERTAIN;
149
+ if (read.status !== 200)
150
+ return answeredFailure(read.status, null);
151
+ if (read.body === null)
152
+ return unusable();
153
+ return {
154
+ kind: 'binary',
155
+ body: read.body,
156
+ mediaType: read.mediaType,
157
+ url: route,
158
+ copies: siteCopies(read.copies),
159
+ };
130
160
  },
131
161
  async link(_authorization, request) {
162
+ if (request.kind === 'key')
163
+ return unfound();
132
164
  const route = fileRoute(request);
133
165
  if (typeof route !== 'string')
134
166
  return route;
@@ -144,8 +176,12 @@ export function createSiteAdapter(transport, snapshot = false) {
144
176
  follows(_locator, version, next) {
145
177
  return followsVersion(version, next);
146
178
  },
147
- async action(_authorization, request) {
148
- if (request.name !== SITE_SUBMISSION) {
179
+ async action(_authorization, asked) {
180
+ const request = siteDoorRequest(asked);
181
+ const route = Object.hasOwn(SITE_DOOR_ACTS, request.name)
182
+ ? SITE_DOOR_ACTS[request.name]
183
+ : null;
184
+ if (route === null) {
149
185
  return {
150
186
  kind: 'rejected',
151
187
  code: 'action-unimplemented',
@@ -154,19 +190,13 @@ export function createSiteAdapter(transport, snapshot = false) {
154
190
  };
155
191
  }
156
192
  if (!transport.online())
157
- return UNCERTAIN;
158
- return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITE_SUBMISSION);
193
+ return UNANSWERED;
194
+ return actionOutcome(await transport.door(route, request.input), request.name, request.input);
159
195
  },
160
196
  roomStream: snapshot
161
197
  ? undefined
162
198
  : {
163
- hold(rooms) {
164
- notifications.send(rooms.flatMap((room) => {
165
- const entry = tracked.get(room.locator);
166
- const at = logPosition(room.roomVersion);
167
- return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
168
- }));
169
- },
199
+ hold: notifications.send,
170
200
  observe: notifications.observe,
171
201
  },
172
202
  serviceMode: notifications.serviceMode,
@@ -0,0 +1,6 @@
1
+ export type SpaceSchemas = {
2
+ held(space: string, revision: string): string | undefined;
3
+ keep(space: string, revision: string, text: string): void;
4
+ };
5
+ export declare function spaceSchemas(): SpaceSchemas;
6
+ export declare function spaceIdentity(space: string): string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space-schema.d.ts","sourceRoot":"","sources":["../src/space-schema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3D,CAAC;AAEF,wBAAgB,YAAY,IAAI,YAAY,CAO3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,11 @@
1
+ export function spaceSchemas() {
2
+ const texts = new Map();
3
+ const key = (space, revision) => `${space} ${revision}`;
4
+ return {
5
+ held: (space, revision) => texts.get(key(space, revision)),
6
+ keep: (space, revision, text) => void texts.set(key(space, revision), text),
7
+ };
8
+ }
9
+ export function spaceIdentity(space) {
10
+ return `space:${space}`;
11
+ }