@agentshouse/mdruntime-adapter 0.1.0-cc9252710ca54 → 0.1.0-cca52f699c50b

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/dist/actions.d.ts CHANGED
@@ -1,168 +1,7 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationHistories, type ConversationHistoryRequest } from '@agentshouse/mdruntime';
1
+ import type { ActionDeclaration, ActionRequest, ActionResult } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
3
  export type HouseActDoor = Pick<HouseTransport, 'door'>;
4
- export declare const HISTORY_PAGE = 100;
5
- type Operated = {
6
- readonly operation_id?: string;
7
- };
8
- type ConversationControl = Operated & {
9
- readonly conversation: string;
10
- };
11
- export type AppInputs = {
12
- readonly 'conversation.answer': ConversationControl & {
13
- readonly answer: {
14
- readonly interaction_id: string;
15
- readonly response: unknown;
16
- };
17
- };
18
- readonly 'conversation.create': Operated & {
19
- readonly agent_id: string;
20
- readonly replaces?: string;
21
- };
22
- readonly 'conversation.delete': ConversationControl;
23
- readonly 'conversation.history': ConversationHistoryRequest;
24
- readonly 'conversation.interrupt': ConversationControl;
25
- readonly 'conversation.kill': ConversationControl;
26
- readonly 'conversation.send': ConversationControl & {
27
- readonly operation_id: string;
28
- readonly text: string;
29
- };
30
- };
31
- export type AppAnswers = {
32
- readonly 'conversation.history': ConversationHistories;
33
- };
34
- export type AppAnswerAdditions = {
35
- readonly 'conversation.create': {
36
- readonly conversation: string;
37
- };
38
- readonly 'conversation.send': {
39
- readonly turn: string;
40
- };
41
- };
42
- type AppAct<Input = unknown> = {
43
- readonly door: string;
44
- readonly batched?: readonly string[];
45
- carry(transport: HouseActDoor, input: Input, name: string): Promise<ActionResult>;
46
- };
47
- declare const APP_ACTS: {
48
- 'access.read': AppAct<unknown> & {
49
- readonly door: "rooms/access/read";
50
- };
51
- 'conversation.answer': AppAct<Operated & {
52
- readonly conversation: string;
53
- } & {
54
- readonly answer: {
55
- readonly interaction_id: string;
56
- readonly response: unknown;
57
- };
58
- }> & {
59
- readonly door: "conversations/interaction/answer";
60
- };
61
- 'conversation.create': AppAct<Operated & {
62
- readonly agent_id: string;
63
- readonly replaces?: string;
64
- }> & {
65
- readonly door: "conversations/create";
66
- };
67
- 'conversation.delete': AppAct<ConversationControl> & {
68
- readonly door: "conversations/delete";
69
- };
70
- 'conversation.history': AppAct<ConversationHistoryRequest> & {
71
- readonly door: "conversations/history";
72
- };
73
- 'conversation.interrupt': AppAct<ConversationControl> & {
74
- readonly door: "conversations/interrupt";
75
- };
76
- 'conversation.kill': AppAct<ConversationControl> & {
77
- readonly door: "conversations/kill";
78
- };
79
- 'conversation.markDone': AppAct<unknown> & {
80
- readonly door: "conversations/done";
81
- };
82
- 'conversation.rename': AppAct<unknown> & {
83
- readonly door: "conversations/rename";
84
- };
85
- 'conversation.retry': AppAct<unknown> & {
86
- readonly door: "conversations/retry";
87
- };
88
- 'conversation.send': AppAct<Operated & {
89
- readonly conversation: string;
90
- } & {
91
- readonly operation_id: string;
92
- readonly text: string;
93
- }> & {
94
- readonly door: "conversations/send";
95
- };
96
- 'conversation.setOption': AppAct<unknown> & {
97
- readonly door: "conversations/option";
98
- };
99
- 'feature.list': AppAct<unknown> & {
100
- readonly door: "apps/features/read";
101
- };
102
- 'holder.list': AppAct<unknown> & {
103
- readonly door: "apps/holders";
104
- };
105
- 'holder.ring': AppAct<unknown> & {
106
- readonly door: "apps/ring";
107
- };
108
- 'inboxChat.assign': AppAct<unknown> & {
109
- readonly door: "chats/assign";
110
- };
111
- 'inboxChat.return': AppAct<unknown> & {
112
- readonly door: "chats/return";
113
- };
114
- 'inboxChat.takeControl': AppAct<unknown> & {
115
- readonly door: "chats/take-control";
116
- };
117
- 'member.list': AppAct<unknown> & {
118
- readonly door: "rooms/members";
119
- };
120
- 'message.send': AppAct<unknown> & {
121
- readonly door: "apps/messages/send";
122
- };
123
- 'processing.read': AppAct<unknown> & {
124
- readonly door: "rooms/settings/processing/read";
125
- };
126
- 'record.list': AppAct<unknown> & {
127
- readonly door: "records/read";
128
- };
129
- 'relay.read': AppAct<unknown> & {
130
- readonly door: "apps/relay";
131
- };
132
- 'routine.list': AppAct<unknown> & {
133
- readonly door: "routines/access";
134
- };
135
- 'routineAccess.list': AppAct<unknown> & {
136
- readonly door: "routines/granted";
137
- };
138
- 'routineAllowance.list': AppAct<unknown> & {
139
- readonly door: "routines/allowance";
140
- };
141
- 'routineRequest.list': AppAct<unknown> & {
142
- readonly door: "routines/requests";
143
- };
144
- 'storage.read': AppAct<unknown> & {
145
- readonly door: "storage/inventory";
146
- };
147
- 'triggerEvent.list': AppAct<unknown> & {
148
- readonly door: "triggers/fired";
149
- };
150
- };
151
- export type HouseAppActs = {
152
- readonly [Name in keyof typeof APP_ACTS]: (typeof APP_ACTS)[Name]['door'];
153
- };
154
- export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
155
- export declare const SITE_SUBMIT = "submit";
156
- export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
157
- export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
158
4
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
159
5
  export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
160
6
  export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
161
- type HistoryCursor = {
162
- accepted_at: string;
163
- message_id: string;
164
- };
165
- export declare function cursorPosition(cursor: HistoryCursor): string;
166
- export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
167
- export {};
168
7
  //# sourceMappingURL=actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EAC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dist/actions.js CHANGED
@@ -1,71 +1,8 @@
1
- import { changeBatchIdentity, HISTORY_CONVERSATIONS, } from '@agentshouse/mdruntime';
2
1
  import { doorRefusal } from './refusal.js';
3
- export const HISTORY_PAGE = 100;
4
- function mapped(door, input = (given) => given) {
5
- return {
6
- door,
7
- async carry(transport, given, name) {
8
- return actionOutcome(await transport.door(`/door/${door}`, input(given)), name);
9
- },
10
- };
11
- }
12
- function carried(door, carry, batched) {
13
- return {
14
- door,
15
- ...(batched === undefined ? {} : { batched }),
16
- carry: (transport, input, name) => carry(transport, `/door/${door}`, input, name),
17
- };
18
- }
19
- const APP_ACTS = {
20
- 'access.read': mapped('rooms/access/read'),
21
- 'conversation.answer': mapped('conversations/interaction/answer', answerBody),
22
- 'conversation.create': carried('conversations/create', createAction),
23
- 'conversation.delete': mapped('conversations/delete', controlBody),
24
- 'conversation.history': carried('conversations/history', historyAction, ['conversations']),
25
- 'conversation.interrupt': mapped('conversations/interrupt', controlBody),
26
- 'conversation.kill': mapped('conversations/kill', controlBody),
27
- 'conversation.markDone': mapped('conversations/done'),
28
- 'conversation.rename': mapped('conversations/rename'),
29
- 'conversation.retry': mapped('conversations/retry'),
30
- 'conversation.send': carried('conversations/send', sendAction),
31
- 'conversation.setOption': mapped('conversations/option'),
32
- 'feature.list': mapped('apps/features/read'),
33
- 'holder.list': mapped('apps/holders'),
34
- 'holder.ring': mapped('apps/ring'),
35
- 'inboxChat.assign': mapped('chats/assign'),
36
- 'inboxChat.return': mapped('chats/return'),
37
- 'inboxChat.takeControl': mapped('chats/take-control'),
38
- 'member.list': mapped('rooms/members'),
39
- 'message.send': mapped('apps/messages/send'),
40
- 'processing.read': mapped('rooms/settings/processing/read'),
41
- 'record.list': mapped('records/read'),
42
- 'relay.read': mapped('apps/relay'),
43
- 'routine.list': mapped('routines/access'),
44
- 'routineAccess.list': mapped('routines/granted'),
45
- 'routineAllowance.list': mapped('routines/allowance'),
46
- 'routineRequest.list': mapped('routines/requests'),
47
- 'storage.read': mapped('storage/inventory'),
48
- 'triggerEvent.list': mapped('triggers/fired'),
49
- };
50
- export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
51
- export const SITE_SUBMIT = 'submit';
52
- export const HOUSE_SITE_ACTS = {
53
- [SITE_SUBMIT]: 'site/submission',
54
- };
55
- export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
56
- const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
57
2
  export function declaredActions(routes) {
58
- return routes.map((route) => {
59
- const name = APP_NAMES.get(route) ?? route;
60
- return { name, inputShape: {}, resultKind: 'house', room: 'room_ref' };
61
- });
3
+ return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
62
4
  }
63
5
  export function houseAction(transport, request) {
64
- if (Object.hasOwn(APP_ACTS, request.name)) {
65
- return APP_ACTS[request.name].carry(transport, request.input, request.name);
66
- }
67
- if (APP_NAMES.has(request.name))
68
- return Promise.resolve(unimplemented(request.name));
69
6
  const route = routeOf(request.name);
70
7
  if (route === null)
71
8
  return Promise.resolve(malformed());
@@ -82,62 +19,12 @@ function routeOf(name) {
82
19
  return null;
83
20
  }
84
21
  }
85
- function record(value) {
86
- return typeof value === 'object' && value !== null ? value : {};
87
- }
88
- function text(value, name) {
89
- const held = record(value)[name];
90
- return typeof held === 'string' ? held : undefined;
91
- }
92
- function operationId(input) {
93
- return text(input, 'operation_id') ?? changeBatchIdentity();
94
- }
95
22
  function malformed() {
96
23
  return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
97
24
  }
98
25
  function unimplemented(name) {
99
26
  return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
100
27
  }
101
- function createBody(input) {
102
- const replaces = text(input, 'replaces');
103
- return {
104
- agent_id: text(input, 'agent_id'),
105
- operation_id: operationId(input),
106
- ...(replaces === undefined ? {} : { replaces }),
107
- };
108
- }
109
- function controlBody(input) {
110
- return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
111
- }
112
- function answerBody(input) {
113
- const nested = record(record(input).answer);
114
- return {
115
- conversation_id: text(input, 'conversation'),
116
- operation_id: operationId(input),
117
- interaction_id: text(nested, 'interaction_id'),
118
- response: nested.response,
119
- };
120
- }
121
- async function createAction(transport, route, input, name) {
122
- const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
123
- if (outcome.kind !== 'action')
124
- return outcome;
125
- const held = record(outcome.result);
126
- const conversation = text(held, 'conversation_id');
127
- return conversation === undefined
128
- ? outcome
129
- : {
130
- ...outcome,
131
- result: { ...held, conversation },
132
- };
133
- }
134
- function withTurn(body) {
135
- const held = record(body);
136
- const turn = text(held, 'message_id');
137
- return turn === undefined
138
- ? body
139
- : { ...held, turn };
140
- }
141
28
  export function actionOutcome(answer, name) {
142
29
  if (answer.status === 401)
143
30
  return { kind: 'revoked-authorization' };
@@ -155,109 +42,3 @@ export function actionOutcome(answer, name) {
155
42
  async function carry(transport, route, name, input) {
156
43
  return actionOutcome(await transport.door(route, input), name);
157
44
  }
158
- function sendBody(input) {
159
- const operation = text(input, 'operation_id');
160
- const said = text(input, 'text');
161
- if (operation === undefined || said === undefined)
162
- return null;
163
- return { conversation_id: text(input, 'conversation'), operation_id: operation, text: said };
164
- }
165
- async function sendAction(transport, route, input, name) {
166
- const body = sendBody(input);
167
- if (body === null)
168
- return malformed();
169
- const outcome = actionOutcome(await transport.door(route, body), name);
170
- if (outcome.kind !== 'action')
171
- return outcome;
172
- return { ...outcome, result: withTurn(outcome.result) };
173
- }
174
- function historyCursor(value) {
175
- const acceptedAt = text(value, 'accepted_at');
176
- const messageId = text(value, 'message_id');
177
- if (acceptedAt === undefined || messageId === undefined)
178
- return null;
179
- return { accepted_at: acceptedAt, message_id: messageId };
180
- }
181
- export function cursorPosition(cursor) {
182
- return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
183
- }
184
- function positionCursor(value) {
185
- try {
186
- return historyCursor(JSON.parse(value));
187
- }
188
- catch {
189
- return null;
190
- }
191
- }
192
- export function acceptedMessage(entry) {
193
- const cursor = historyCursor(entry);
194
- if (cursor === null)
195
- return null;
196
- return {
197
- identity: cursor.message_id,
198
- turn: text(entry, 'turn_id') ?? cursor.message_id,
199
- position: cursorPosition(cursor),
200
- text: text(entry, 'text') ?? '',
201
- message: structuredClone(record(entry)),
202
- };
203
- }
204
- function historyPage(entry) {
205
- const held = record(entry);
206
- const conversation = text(held, 'conversation_id');
207
- if (conversation === undefined || !Array.isArray(held.messages))
208
- return null;
209
- const messages = [];
210
- for (const one of held.messages) {
211
- const message = acceptedMessage(one);
212
- if (message === null)
213
- return null;
214
- messages.push(message);
215
- }
216
- const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
217
- if (next === null)
218
- return null;
219
- return { conversation, messages, ...(next === undefined ? {} : { next: cursorPosition(next) }) };
220
- }
221
- function historyAsks(input) {
222
- const asked = record(input).conversations;
223
- if (!Array.isArray(asked) || asked.length === 0)
224
- return null;
225
- const asks = [];
226
- for (const entry of asked) {
227
- const conversationId = text(entry, 'conversation');
228
- if (conversationId === undefined)
229
- return null;
230
- const afterValue = text(entry, 'after');
231
- const after = afterValue === undefined ? undefined : positionCursor(afterValue);
232
- if (after === null)
233
- return null;
234
- asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
235
- }
236
- return asks;
237
- }
238
- async function historyAction(transport, route, input, name) {
239
- const asks = historyAsks(input);
240
- if (asks === null)
241
- return malformed();
242
- const histories = [];
243
- for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
244
- const answer = await transport.door(route, {
245
- conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
246
- limit: HISTORY_PAGE,
247
- });
248
- const outcome = actionOutcome(answer, name);
249
- if (outcome.kind !== 'action')
250
- return outcome;
251
- const answered = record(outcome.result).histories;
252
- if (!Array.isArray(answered))
253
- return { kind: 'transport-uncertainty' };
254
- for (const entry of answered) {
255
- const page = historyPage(entry);
256
- if (page === null)
257
- return { kind: 'transport-uncertainty' };
258
- histories.push(page);
259
- }
260
- }
261
- const result = { histories };
262
- return { kind: 'action', result };
263
- }
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,wBAAwB,EAAE,MAAM,CAAC;IACjC,2BAA2B,EAAE,MAAM,CAAC;IACpC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1D,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,UAA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U,EAAE,CAE9F;AAED,wBAAgB,gBAAgB,IAAI,SAAS,UAAU,EAAE,CAOxD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc,CAqBxE;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,EAChD,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,SAAS,CAQX"}
package/dist/discovery.js CHANGED
@@ -1,4 +1,5 @@
1
- import { declaredActions, SITE_SUBMIT } from './actions.js';
1
+ import { declaredActions } from './actions.js';
2
+ import { SITE_SUBMISSION } from './transport.js';
2
3
  import { readPosition, roomVersion } from './version.js';
3
4
  export const PROVIDER_ACTIONS = 'provider-actions';
4
5
  const BOUND_KEYS = [
@@ -240,7 +241,7 @@ export function siteCapabilities() {
240
241
  return [
241
242
  {
242
243
  name: PROVIDER_ACTIONS,
243
- actions: [{ name: SITE_SUBMIT, inputShape: {}, resultKind: 'house' }],
244
+ actions: [{ name: SITE_SUBMISSION, inputShape: {}, resultKind: 'house' }],
244
245
  },
245
246
  ];
246
247
  }
@@ -0,0 +1,12 @@
1
+ import type { AcceptedMessage, ActionResult, ConversationHistoryRequest } from '@agentshouse/mdruntime';
2
+ import { type HouseDoor } from './transport.js';
3
+ export declare const HISTORY_PAGE = 100;
4
+ type HistoryCursor = {
5
+ accepted_at: string;
6
+ message_id: string;
7
+ };
8
+ export declare function cursorPosition(cursor: HistoryCursor): string;
9
+ export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
10
+ export declare function houseHistory(transport: HouseDoor, request: ConversationHistoryRequest): Promise<ActionResult>;
11
+ export {};
12
+ //# sourceMappingURL=history.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAGZ,0BAA0B,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhE,eAAO,MAAM,YAAY,MAAM,CAAC;AAIhC,KAAK,aAAa,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAkBjE,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAE5D;AAUD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE;AA8BD,wBAAsB,YAAY,CAChC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,YAAY,CAAC,CAmBvB"}
@@ -0,0 +1,91 @@
1
+ import { actionOutcome } from './actions.js';
2
+ import { houseDoorRoute } from './transport.js';
3
+ export const HISTORY_PAGE = 100;
4
+ const HISTORY = 'conversations/history';
5
+ function record(value) {
6
+ return typeof value === 'object' && value !== null ? value : {};
7
+ }
8
+ function text(value, name) {
9
+ const held = record(value)[name];
10
+ return typeof held === 'string' ? held : undefined;
11
+ }
12
+ function historyCursor(value) {
13
+ const acceptedAt = text(value, 'accepted_at');
14
+ const messageId = text(value, 'message_id');
15
+ if (acceptedAt === undefined || messageId === undefined)
16
+ return null;
17
+ return { accepted_at: acceptedAt, message_id: messageId };
18
+ }
19
+ export function cursorPosition(cursor) {
20
+ return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
21
+ }
22
+ function positionCursor(value) {
23
+ try {
24
+ return historyCursor(JSON.parse(value));
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ export function acceptedMessage(entry) {
31
+ const cursor = historyCursor(entry);
32
+ if (cursor === null)
33
+ return null;
34
+ return {
35
+ identity: cursor.message_id,
36
+ turn: text(entry, 'turn_id') ?? cursor.message_id,
37
+ position: cursorPosition(cursor),
38
+ text: text(entry, 'text') ?? '',
39
+ message: structuredClone(record(entry)),
40
+ };
41
+ }
42
+ function historyPage(entry) {
43
+ const held = record(entry);
44
+ const conversation = text(held, 'conversation_id');
45
+ if (conversation === undefined || !Array.isArray(held.messages))
46
+ return null;
47
+ const messages = [];
48
+ for (const one of held.messages) {
49
+ const message = acceptedMessage(one);
50
+ if (message === null)
51
+ return null;
52
+ messages.push(message);
53
+ }
54
+ const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
55
+ if (next === null)
56
+ return null;
57
+ return { conversation, messages, ...(next === undefined ? {} : { next: cursorPosition(next) }) };
58
+ }
59
+ function historyAsks(request) {
60
+ const asks = [];
61
+ for (const { conversation, after } of request.conversations) {
62
+ const cursor = after === undefined ? undefined : positionCursor(after);
63
+ if (cursor === null)
64
+ return null;
65
+ asks.push({
66
+ conversation_id: conversation,
67
+ ...(cursor === undefined ? {} : { after: cursor }),
68
+ });
69
+ }
70
+ return asks;
71
+ }
72
+ export async function houseHistory(transport, request) {
73
+ const asks = historyAsks(request);
74
+ if (asks === null)
75
+ return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
76
+ const outcome = actionOutcome(await transport.door(houseDoorRoute(HISTORY), { conversations: asks, limit: HISTORY_PAGE }), HISTORY);
77
+ if (outcome.kind !== 'action')
78
+ return outcome;
79
+ const answered = record(outcome.result).histories;
80
+ if (!Array.isArray(answered))
81
+ return { kind: 'transport-uncertainty' };
82
+ const histories = [];
83
+ for (const entry of answered) {
84
+ const page = historyPage(entry);
85
+ if (page === null)
86
+ return { kind: 'transport-uncertainty' };
87
+ histories.push(page);
88
+ }
89
+ const result = { histories };
90
+ return { kind: 'action', result };
91
+ }