@agentshouse/mdruntime-adapter 0.1.0-c2bcef775f3b3 → 0.1.0-c2c0ec6c1f436

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 (91) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +4 -53
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +48 -231
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +217 -366
  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 +40 -10
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +226 -45
  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 +10 -9
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +9 -7
  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 +20 -67
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +106 -347
  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/renamed.d.ts +10 -0
  35. package/dist/renamed.d.ts.map +1 -0
  36. package/dist/renamed.js +20 -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 +20 -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 +54 -0
  47. package/dist/session-content/turn.d.ts +147 -0
  48. package/dist/site.d.ts +0 -1
  49. package/dist/site.d.ts.map +1 -1
  50. package/dist/site.js +114 -130
  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 +16 -16
  55. package/dist/stream.d.ts.map +1 -1
  56. package/dist/stream.js +308 -434
  57. package/dist/transport.d.ts +111 -54
  58. package/dist/transport.d.ts.map +1 -1
  59. package/dist/transport.js +92 -12
  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 +51 -8
  66. package/dist/version.d.ts +0 -1
  67. package/dist/write.d.ts +2 -8
  68. package/dist/write.d.ts.map +1 -1
  69. package/dist/write.js +94 -129
  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/gather.d.ts +0 -3
  78. package/dist/gather.d.ts.map +0 -1
  79. package/dist/gather.js +0 -35
  80. package/dist/house-model.d.ts +0 -2
  81. package/dist/house-model.d.ts.map +0 -1
  82. package/dist/house-model.js +0 -490
  83. package/dist/part.d.ts +0 -14
  84. package/dist/part.d.ts.map +0 -1
  85. package/dist/part.js +0 -90
  86. package/dist/room-stream.d.ts +0 -19
  87. package/dist/room-stream.d.ts.map +0 -1
  88. package/dist/room-stream.js +0 -57
  89. package/dist/room-types.d.ts +0 -7
  90. package/dist/room-types.d.ts.map +0 -1
  91. package/dist/room-types.js +0 -126
package/dist/part.js DELETED
@@ -1,90 +0,0 @@
1
- const PART_MAGIC = 0x48505431;
2
- const PART_HEAD_BYTES = 8;
3
- const PART_DIGEST_BYTES = 32;
4
- function hex(bytes) {
5
- let text = '';
6
- for (const byte of bytes)
7
- text += byte.toString(16).padStart(2, '0');
8
- return text;
9
- }
10
- export async function checkedPayload(frame) {
11
- if (frame.length < PART_HEAD_BYTES + PART_DIGEST_BYTES)
12
- return null;
13
- const view = new DataView(frame.buffer, frame.byteOffset, frame.byteLength);
14
- if (view.getUint32(0) !== PART_MAGIC)
15
- return null;
16
- const length = view.getUint32(4);
17
- if (PART_HEAD_BYTES + length + PART_DIGEST_BYTES !== frame.length)
18
- return null;
19
- const payload = frame.subarray(PART_HEAD_BYTES, PART_HEAD_BYTES + length);
20
- const digest = hex(new Uint8Array(await crypto.subtle.digest('SHA-256', payload)));
21
- return hex(frame.subarray(PART_HEAD_BYTES + length)) === digest ? payload : null;
22
- }
23
- export function roomFrames(room, arrived, signal) {
24
- const reader = room.getReader();
25
- signal?.addEventListener('abort', () => void reader.cancel().catch(() => { }), { once: true });
26
- const chunks = [];
27
- let held = 0;
28
- let received = 0;
29
- let ended = false;
30
- async function filled(bytes) {
31
- while (held < bytes && !ended) {
32
- const read = await reader.read();
33
- if (read.done) {
34
- ended = true;
35
- break;
36
- }
37
- chunks.push(read.value);
38
- held += read.value.byteLength;
39
- received += read.value.byteLength;
40
- arrived?.(received);
41
- }
42
- return held >= bytes;
43
- }
44
- function taken(bytes) {
45
- const out = new Uint8Array(bytes);
46
- let at = 0;
47
- while (at < bytes) {
48
- const chunk = chunks[0];
49
- const used = Math.min(chunk.byteLength, bytes - at);
50
- out.set(chunk.subarray(0, used), at);
51
- at += used;
52
- if (used === chunk.byteLength)
53
- chunks.shift();
54
- else
55
- chunks[0] = chunk.subarray(used);
56
- }
57
- held -= bytes;
58
- return out;
59
- }
60
- return async () => {
61
- try {
62
- if (!(await filled(PART_HEAD_BYTES)))
63
- return held === 0 ? { kind: 'ended' } : { kind: 'broken' };
64
- const head = taken(PART_HEAD_BYTES);
65
- const view = new DataView(head.buffer);
66
- if (view.getUint32(0) !== PART_MAGIC)
67
- return { kind: 'broken' };
68
- const length = view.getUint32(4);
69
- const rest = length + PART_DIGEST_BYTES;
70
- if (!(await filled(rest)))
71
- return { kind: 'broken' };
72
- const frame = new Uint8Array(PART_HEAD_BYTES + rest);
73
- frame.set(head, 0);
74
- frame.set(taken(rest), PART_HEAD_BYTES);
75
- const payload = await checkedPayload(frame);
76
- return payload === null
77
- ? { kind: 'broken' }
78
- : { kind: 'frame', payload, bytes: frame.byteLength };
79
- }
80
- catch {
81
- return { kind: 'broken' };
82
- }
83
- };
84
- }
85
- export function gunzipped(payload) {
86
- return new Blob([payload])
87
- .stream()
88
- .pipeThrough(new DecompressionStream('gzip'))
89
- .pipeThrough(new TextDecoderStream());
90
- }
@@ -1,19 +0,0 @@
1
- import type { BootstrapResult, RoomModels } from '@agentshouse/mdruntime';
2
- import type { TrackedAuthority } from './discovery.js';
3
- import { type HouseScope } from './read.js';
4
- import type { HouseMode } from './transport.js';
5
- export type StreamedPart = {
6
- readonly scope: HouseScope;
7
- readonly first: boolean;
8
- readonly ended: boolean;
9
- readonly models: RoomModels | undefined;
10
- readonly pageToken: string | undefined;
11
- readonly bytes: number;
12
- };
13
- export declare function roomStreams(mode: HouseMode): {
14
- head: (entry: TrackedAuthority, room: ReadableStream<Uint8Array>, arriving: ((bytes: number) => void) | undefined, signal: AbortSignal | undefined) => Promise<BootstrapResult>;
15
- part: (entry: TrackedAuthority, token: string) => Promise<StreamedPart | Exclude<BootstrapResult, {
16
- kind: 'bootstrap';
17
- }>>;
18
- };
19
- //# sourceMappingURL=room-stream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"room-stream.d.ts","sourceRoot":"","sources":["../src/room-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAuD,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAYhD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS;kBAKhC,gBAAgB,QACjB,cAAc,CAAC,UAAU,CAAC,YACtB,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,UACvC,WAAW,GAAG,SAAS,KAC9B,OAAO,CAAC,eAAe,CAAC;kBAelB,gBAAgB,SAChB,MAAM,KACZ,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,eAAe,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;EAkC3E"}
@@ -1,57 +0,0 @@
1
- import { manifestedModels, partModels } from './model.js';
2
- import { roomFrames } from './part.js';
3
- import { housePart, manifested, roomHead } from './read.js';
4
- const UNCERTAIN = { kind: 'transport-uncertainty' };
5
- export function roomStreams(mode) {
6
- const open = new Map();
7
- let opened = 0;
8
- async function head(entry, room, arriving, signal) {
9
- const frames = roomFrames(room, arriving, signal);
10
- const first = await frames();
11
- if (first.kind !== 'frame')
12
- return UNCERTAIN;
13
- const held = await roomHead(first.payload, mode);
14
- if (held === null || held.anchor !== entry.authority)
15
- return UNCERTAIN;
16
- const { models, seen } = await manifestedModels(held, entry);
17
- opened += 1;
18
- const id = String(opened);
19
- open.set(id, { entry, head: held, frames, next: 1, seen });
20
- signal?.addEventListener('abort', () => open.delete(id), { once: true });
21
- return { ...manifested(held, `${id}:1`, models), bytes: first.bytes };
22
- }
23
- async function part(entry, token) {
24
- const [id = '', at = ''] = token.split(':');
25
- const room = open.get(id);
26
- if (room === undefined || room.entry.locator !== entry.locator || String(room.next) !== at)
27
- return UNCERTAIN;
28
- const frame = await room.frames();
29
- if (frame.kind !== 'frame') {
30
- open.delete(id);
31
- return UNCERTAIN;
32
- }
33
- const read = await housePart(room.head, frame.payload, mode);
34
- if ('kind' in read) {
35
- open.delete(id);
36
- return read;
37
- }
38
- const { scope, ended } = read;
39
- const first = room.next === 1;
40
- room.next += 1;
41
- room.seen = [
42
- ...room.seen,
43
- ...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
44
- ];
45
- if (ended)
46
- open.delete(id);
47
- return {
48
- scope,
49
- first,
50
- ended,
51
- models: await partModels(scope, entry, new Set(room.seen), ended),
52
- pageToken: ended ? undefined : `${id}:${room.next}`,
53
- bytes: frame.bytes,
54
- };
55
- }
56
- return { head, part };
57
- }
@@ -1,7 +0,0 @@
1
- export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot', 'telegram-business', 'whatsapp', 'messenger', 'instagram', 'viber', 'tiktok'];
2
- export type InboxChannelKind = (typeof INBOX_CHANNEL_KINDS)[number];
3
- export declare const INBOX_CHAT_TYPE = "inbox-chat";
4
- export declare const INBOX_MESSAGE_TYPE = "inbox-message";
5
- export declare const HOUSE_NAMEABLE_ROOM_TYPES: string[];
6
- export declare const HOUSE_ROOM_TYPES: string;
7
- //# sourceMappingURL=room-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,YAC9B,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD,eAAO,MAAM,yBAAyB,UAAwC,CAAC;AAyB/E,eAAO,MAAM,gBAAgB,QA8FjB,CAAC"}
@@ -1,126 +0,0 @@
1
- import { APP_REFERENCE_PATTERN } from './app-reference.js';
2
- import { HOUSE_MODEL_TYPES } from './house-model.js';
3
- export const INBOX_CHANNEL_KINDS = [
4
- 'telegram-bot',
5
- 'telegram-business',
6
- 'whatsapp',
7
- 'messenger',
8
- 'instagram',
9
- 'viber',
10
- 'tiktok',
11
- ];
12
- export const INBOX_CHAT_TYPE = 'inbox-chat';
13
- export const INBOX_MESSAGE_TYPE = 'inbox-message';
14
- export const HOUSE_NAMEABLE_ROOM_TYPES = [INBOX_CHAT_TYPE, INBOX_MESSAGE_TYPE];
15
- const WAYFINDING_MAP_TYPE = 'wayfinding-map';
16
- const WAYFINDING_TICKET_TYPE = 'wayfinding-ticket';
17
- const WAYFINDING_MAP_SECTIONS = [
18
- 'Destination',
19
- 'Notes',
20
- 'Decisions so far',
21
- 'Not yet specified',
22
- 'Out of scope',
23
- ];
24
- const IDENTITY = "{ type: string, pattern: '^\\S+$' }";
25
- const AGENT = [' agent: { type: string, format: uuid }', ' name: { type: string }'];
26
- const ASSIGNEE = [
27
- ' type: object',
28
- ' properties:',
29
- ' user: { type: string, format: uuid }',
30
- ...AGENT,
31
- ];
32
- export const HOUSE_ROOM_TYPES = [
33
- `${INBOX_CHAT_TYPE}:`,
34
- ' properties:',
35
- ' inbox: { type: string, format: uuid }',
36
- ` channel: { enum: [${INBOX_CHANNEL_KINDS.join(', ')}] }`,
37
- ` chat: ${IDENTITY}`,
38
- ' customer:',
39
- ' type: object',
40
- ' properties:',
41
- ' name: { type: string }',
42
- ` username: ${IDENTITY}`,
43
- ` phone: ${IDENTITY}`,
44
- ' assignee:',
45
- ...ASSIGNEE,
46
- ' return_to:',
47
- ' type: object',
48
- ' properties:',
49
- ...AGENT,
50
- ' conversation: { type: string, format: uuid }',
51
- ' required: [inbox, channel, chat, customer]',
52
- `${INBOX_MESSAGE_TYPE}:`,
53
- ' properties:',
54
- ' direction: { enum: [in, out] }',
55
- ' sender:',
56
- ' type: object',
57
- ' properties:',
58
- ' name: { type: string }',
59
- ` username: ${IDENTITY}`,
60
- ' sent_at: { type: string, format: date-time }',
61
- ` channel_message: ${IDENTITY}`,
62
- ' state: { enum: [sending, sent, failed] }',
63
- ' reason: { type: string }',
64
- ' labelled: { const: true }',
65
- ' reactions:',
66
- ' type: array',
67
- ' items:',
68
- ' type: object',
69
- ' properties:',
70
- ' reaction: { type: string, minLength: 1 }',
71
- ' sender:',
72
- ' type: object',
73
- ' properties:',
74
- ` id: ${IDENTITY}`,
75
- ' name: { type: string }',
76
- ` username: ${IDENTITY}`,
77
- ' count: { type: integer, minimum: 1 }',
78
- ' required: [reaction]',
79
- ` post: ${IDENTITY}`,
80
- ' assignee:',
81
- ...ASSIGNEE,
82
- ' sent_outside: { const: true }',
83
- ' template:',
84
- ' type: object',
85
- ' properties:',
86
- ' name: { type: string, minLength: 1 }',
87
- ' language: { type: string, minLength: 1 }',
88
- ' required: [name, language]',
89
- ' values:',
90
- ' type: object',
91
- ' additionalProperties: { type: string }',
92
- ' withheld: { const: true }',
93
- ' required: [direction]',
94
- ' if: { properties: { direction: { const: in } } }',
95
- ' then: { required: [sent_at] }',
96
- `${WAYFINDING_MAP_TYPE}:`,
97
- ' properties:',
98
- ' title: { type: string }',
99
- ' required: [title]',
100
- ' sections:',
101
- ...WAYFINDING_MAP_SECTIONS.map((name) => ` ${name}: { kind: text, required: true }`),
102
- `${WAYFINDING_TICKET_TYPE}:`,
103
- ' properties:',
104
- ' title: { type: string }',
105
- ' kind: { enum: [research, prototype, grilling, task] }',
106
- ' status: { enum: [open, in-progress, done, out-of-scope] }',
107
- ` map: { type: string, reference: ${WAYFINDING_MAP_TYPE} }`,
108
- ` blocked_by: { type: array, items: { type: string, reference: ${WAYFINDING_TICKET_TYPE} } }`,
109
- ' assignee:',
110
- ...ASSIGNEE,
111
- ' conversation: { type: string, format: uuid }',
112
- ` app: { type: string, pattern: '${APP_REFERENCE_PATTERN.source}' }`,
113
- ' required: [title, kind, status, map, blocked_by]',
114
- ' sections:',
115
- ' Question: { kind: text }',
116
- ' Answer: { kind: text }',
117
- ' allOf:',
118
- ' - if: { properties: { status: { enum: [in-progress, done, out-of-scope] } }, required: [status] }',
119
- ' then: { required: [assignee] }',
120
- ' else: { properties: { assignee: false } }',
121
- ' - if: { properties: { assignee: { required: [agent] } }, required: [assignee] }',
122
- ' else: { properties: { conversation: false } }',
123
- ' - if: { properties: { status: { enum: [done, out-of-scope] } }, required: [status] }',
124
- ' then: { sections: { Answer: { kind: text, required: true } } }',
125
- HOUSE_MODEL_TYPES,
126
- ].join('\n');