@agentshouse/mdruntime-adapter 0.1.0-cf41d9210cb6b → 0.1.0-cf863e7a50d6e

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,57 +1,7 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents, 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
- export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
43
- export declare const SITE_SUBMIT = "submit";
44
- export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
45
- export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
46
- export declare function houseConversationAgents(locator: string): ConversationAgents;
47
4
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
48
5
  export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
49
6
  export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
50
- type HistoryCursor = {
51
- accepted_at: string;
52
- message_id: string;
53
- };
54
- export declare function cursorPosition(cursor: HistoryCursor): string;
55
- export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
56
- export {};
57
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,EACjB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAE1B,KAAK,0BAA0B,EAChC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAExD,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,KAAK,mBAAmB,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,GAAG;QACpD,QAAQ,CAAC,MAAM,EAAE;YAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;SAAE,CAAC;KAClF,CAAC;IACF,QAAQ,CAAC,qBAAqB,EAAE,QAAQ,GAAG;QACzC,QA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M,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAKvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AAkFD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAQjF;AA+BD,KAAK,aAAa,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AASjE,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAE5D;AAUD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE7F,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAExD,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAEvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAoBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAQjF"}
package/dist/actions.js CHANGED
@@ -1,74 +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
- 'triggerOccurrence.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
- export function houseConversationAgents(locator) {
58
- return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
59
- }
60
2
  export function declaredActions(routes) {
61
- return routes.map((route) => {
62
- const name = APP_NAMES.get(route) ?? route;
63
- return { name, inputShape: {}, resultKind: 'house', room: 'room_ref' };
64
- });
3
+ return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
65
4
  }
66
5
  export function houseAction(transport, request) {
67
- if (Object.hasOwn(APP_ACTS, request.name)) {
68
- return APP_ACTS[request.name].carry(transport, request.input, request.name);
69
- }
70
- if (APP_NAMES.has(request.name))
71
- return Promise.resolve(unimplemented(request.name));
72
6
  const route = routeOf(request.name);
73
7
  if (route === null)
74
8
  return Promise.resolve(malformed());
@@ -85,62 +19,12 @@ function routeOf(name) {
85
19
  return null;
86
20
  }
87
21
  }
88
- function record(value) {
89
- return typeof value === 'object' && value !== null ? value : {};
90
- }
91
- function text(value, name) {
92
- const held = record(value)[name];
93
- return typeof held === 'string' ? held : undefined;
94
- }
95
- function operationId(input) {
96
- return text(input, 'operation_id') ?? changeBatchIdentity();
97
- }
98
22
  function malformed() {
99
23
  return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
100
24
  }
101
25
  function unimplemented(name) {
102
26
  return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
103
27
  }
104
- function createBody(input) {
105
- const replaces = text(input, 'replaces');
106
- return {
107
- agent_id: text(input, 'agent_id'),
108
- operation_id: operationId(input),
109
- ...(replaces === undefined ? {} : { replaces }),
110
- };
111
- }
112
- function controlBody(input) {
113
- return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
114
- }
115
- function answerBody(input) {
116
- const nested = record(record(input).answer);
117
- return {
118
- conversation_id: text(input, 'conversation'),
119
- operation_id: operationId(input),
120
- interaction_id: text(nested, 'interaction_id'),
121
- response: nested.response,
122
- };
123
- }
124
- async function createAction(transport, route, input, name) {
125
- const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
126
- if (outcome.kind !== 'action')
127
- return outcome;
128
- const held = record(outcome.result);
129
- const conversation = text(held, 'conversation_id');
130
- return conversation === undefined
131
- ? outcome
132
- : {
133
- ...outcome,
134
- result: { ...held, conversation },
135
- };
136
- }
137
- function withTurn(body) {
138
- const held = record(body);
139
- const turn = text(held, 'message_id');
140
- return turn === undefined
141
- ? body
142
- : { ...held, turn };
143
- }
144
28
  export function actionOutcome(answer, name) {
145
29
  if (answer.status === 401)
146
30
  return { kind: 'revoked-authorization' };
@@ -158,109 +42,3 @@ export function actionOutcome(answer, name) {
158
42
  async function carry(transport, route, name, input) {
159
43
  return actionOutcome(await transport.door(route, input), name);
160
44
  }
161
- function sendBody(input) {
162
- const operation = text(input, 'operation_id');
163
- const said = text(input, 'text');
164
- if (operation === undefined || said === undefined)
165
- return null;
166
- return { conversation_id: text(input, 'conversation'), operation_id: operation, text: said };
167
- }
168
- async function sendAction(transport, route, input, name) {
169
- const body = sendBody(input);
170
- if (body === null)
171
- return malformed();
172
- const outcome = actionOutcome(await transport.door(route, body), name);
173
- if (outcome.kind !== 'action')
174
- return outcome;
175
- return { ...outcome, result: withTurn(outcome.result) };
176
- }
177
- function historyCursor(value) {
178
- const acceptedAt = text(value, 'accepted_at');
179
- const messageId = text(value, 'message_id');
180
- if (acceptedAt === undefined || messageId === undefined)
181
- return null;
182
- return { accepted_at: acceptedAt, message_id: messageId };
183
- }
184
- export function cursorPosition(cursor) {
185
- return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
186
- }
187
- function positionCursor(value) {
188
- try {
189
- return historyCursor(JSON.parse(value));
190
- }
191
- catch {
192
- return null;
193
- }
194
- }
195
- export function acceptedMessage(entry) {
196
- const cursor = historyCursor(entry);
197
- if (cursor === null)
198
- return null;
199
- return {
200
- identity: cursor.message_id,
201
- turn: text(entry, 'turn_id') ?? cursor.message_id,
202
- position: cursorPosition(cursor),
203
- text: text(entry, 'text') ?? '',
204
- message: structuredClone(record(entry)),
205
- };
206
- }
207
- function historyPage(entry) {
208
- const held = record(entry);
209
- const conversation = text(held, 'conversation_id');
210
- if (conversation === undefined || !Array.isArray(held.messages))
211
- return null;
212
- const messages = [];
213
- for (const one of held.messages) {
214
- const message = acceptedMessage(one);
215
- if (message === null)
216
- return null;
217
- messages.push(message);
218
- }
219
- const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
220
- if (next === null)
221
- return null;
222
- return { conversation, messages, ...(next === undefined ? {} : { next: cursorPosition(next) }) };
223
- }
224
- function historyAsks(input) {
225
- const asked = record(input).conversations;
226
- if (!Array.isArray(asked) || asked.length === 0)
227
- return null;
228
- const asks = [];
229
- for (const entry of asked) {
230
- const conversationId = text(entry, 'conversation');
231
- if (conversationId === undefined)
232
- return null;
233
- const afterValue = text(entry, 'after');
234
- const after = afterValue === undefined ? undefined : positionCursor(afterValue);
235
- if (after === null)
236
- return null;
237
- asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
238
- }
239
- return asks;
240
- }
241
- async function historyAction(transport, route, input, name) {
242
- const asks = historyAsks(input);
243
- if (asks === null)
244
- return malformed();
245
- const histories = [];
246
- for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
247
- const answer = await transport.door(route, {
248
- conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
249
- limit: HISTORY_PAGE,
250
- });
251
- const outcome = actionOutcome(answer, name);
252
- if (outcome.kind !== 'action')
253
- return outcome;
254
- const answered = record(outcome.result).histories;
255
- if (!Array.isArray(answered))
256
- return { kind: 'transport-uncertainty' };
257
- for (const entry of answered) {
258
- const page = historyPage(entry);
259
- if (page === null)
260
- return { kind: 'transport-uncertainty' };
261
- histories.push(page);
262
- }
263
- }
264
- const result = { histories };
265
- return { kind: 'action', result };
266
- }
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAGP,aAAa,EAkBd,MAAM,wBAAwB,CAAC;AAoChC,OAAO,EAUL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAqErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA+jBpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAcd,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAmBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AA6DrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA0ZpF"}