@agentshouse/mdruntime-adapter 0.1.0-c8bd3a750f35b → 0.1.0-c8bfc1969f4fe
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 +1 -162
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -220
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +37 -42
- package/dist/discovery.d.ts +7 -2
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +27 -12
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +91 -0
- package/dist/house-model.d.ts +359 -2367
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +35 -1147
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +27 -22
- package/dist/stream.d.ts +13 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +66 -15
- package/dist/transport.d.ts +20 -4
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -0
- package/package.json +2 -2
package/dist/actions.d.ts
CHANGED
|
@@ -1,168 +1,7 @@
|
|
|
1
|
-
import
|
|
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
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,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((
|
|
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
|
-
}
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,
|
|
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,CAyZpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
|
-
import {
|
|
2
|
+
import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
3
3
|
import { createSiteAdapter } from './site.js';
|
|
4
4
|
import { authorityRoot, bootstrapping, parseFileAddress, parseGrant, } from './read.js';
|
|
5
5
|
import { roomStreams } from './room-stream.js';
|
|
6
6
|
import { sha256Hex } from './digest.js';
|
|
7
7
|
import { finishedUpload, houseUpload } from './upload.js';
|
|
8
8
|
import { houseAction } from './actions.js';
|
|
9
|
-
import { classifyDoor,
|
|
10
|
-
import { houseNotifications } from './stream.js';
|
|
9
|
+
import { classifyDoor, doorRefusal } from './refusal.js';
|
|
10
|
+
import { houseNotifications, } from './stream.js';
|
|
11
11
|
import { houseDoorRoute, } from './transport.js';
|
|
12
12
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
13
13
|
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
@@ -49,7 +49,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
49
49
|
if ('site' in options)
|
|
50
50
|
return createSiteAdapter(options.site, options.snapshot === true);
|
|
51
51
|
const transport = options.transport;
|
|
52
|
-
const notifications = houseNotifications(transport, 'credential'
|
|
52
|
+
const notifications = houseNotifications(transport, 'credential', {
|
|
53
|
+
opened: async (frame) => (frame === null ? null : opened(frame)),
|
|
54
|
+
changed,
|
|
55
|
+
});
|
|
53
56
|
const tracked = new Map();
|
|
54
57
|
const rooms = roomStreams('credential');
|
|
55
58
|
const unreused = new Set();
|
|
@@ -59,6 +62,36 @@ export function createAgentsHouseAdapter(options) {
|
|
|
59
62
|
throw new Error('no Discovery declared the bounds');
|
|
60
63
|
return bounds;
|
|
61
64
|
}
|
|
65
|
+
function opened(frame) {
|
|
66
|
+
const document = parseDiscovery(frame);
|
|
67
|
+
if (document === null)
|
|
68
|
+
return null;
|
|
69
|
+
bounds = document.bounds;
|
|
70
|
+
tracked.clear();
|
|
71
|
+
for (const entry of trackedFrom(document))
|
|
72
|
+
tracked.set(entry.locator, entry);
|
|
73
|
+
notifications.track([...tracked.values()]);
|
|
74
|
+
return {
|
|
75
|
+
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
76
|
+
member: document.member,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function changed(frame) {
|
|
80
|
+
const change = parseAuthorityChange(frame);
|
|
81
|
+
if (change === null)
|
|
82
|
+
return null;
|
|
83
|
+
for (const locator of change.left)
|
|
84
|
+
tracked.delete(locator);
|
|
85
|
+
for (const entry of trackedFrom(change))
|
|
86
|
+
tracked.set(entry.locator, entry);
|
|
87
|
+
notifications.track([...tracked.values()]);
|
|
88
|
+
return {
|
|
89
|
+
kind: 'authority-changed',
|
|
90
|
+
rooms: change.authorities.map((authority) => discoveredRoom(authority)),
|
|
91
|
+
left: change.left,
|
|
92
|
+
member: change.member,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
62
95
|
async function streamedPage(entry, token, held) {
|
|
63
96
|
const part = await rooms.part(entry, token);
|
|
64
97
|
if ('kind' in part)
|
|
@@ -255,43 +288,6 @@ export function createAgentsHouseAdapter(options) {
|
|
|
255
288
|
async authorize() {
|
|
256
289
|
return options.authorize();
|
|
257
290
|
},
|
|
258
|
-
async discover(_authorization, scope) {
|
|
259
|
-
const answer = await transport.door(houseDoorRoute('discover'), {
|
|
260
|
-
prefixes: [...DISCOVER_PREFIXES],
|
|
261
|
-
...(scope === undefined ? {} : { rooms: scope.authorities }),
|
|
262
|
-
});
|
|
263
|
-
const failed = discoveryFailure(answer.status, answer.body);
|
|
264
|
-
if (failed !== null)
|
|
265
|
-
return failed;
|
|
266
|
-
const document = parseDiscovery(answer.body);
|
|
267
|
-
if (document === null)
|
|
268
|
-
return { kind: 'transport-uncertainty' };
|
|
269
|
-
bounds = document.bounds;
|
|
270
|
-
const entries = trackedFrom(document);
|
|
271
|
-
const covered = scope === undefined
|
|
272
|
-
? null
|
|
273
|
-
: [
|
|
274
|
-
...new Set([
|
|
275
|
-
...[...tracked.values()]
|
|
276
|
-
.filter((entry) => scope.authorities.includes(entry.authority))
|
|
277
|
-
.map((entry) => entry.locator),
|
|
278
|
-
...entries.map((entry) => entry.locator),
|
|
279
|
-
]),
|
|
280
|
-
];
|
|
281
|
-
if (covered === null)
|
|
282
|
-
tracked.clear();
|
|
283
|
-
else
|
|
284
|
-
for (const locator of covered)
|
|
285
|
-
tracked.delete(locator);
|
|
286
|
-
for (const entry of entries)
|
|
287
|
-
tracked.set(entry.locator, entry);
|
|
288
|
-
notifications.track([...tracked.values()]);
|
|
289
|
-
return {
|
|
290
|
-
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
291
|
-
member: document.member,
|
|
292
|
-
...(covered === null ? {} : { covered }),
|
|
293
|
-
};
|
|
294
|
-
},
|
|
295
291
|
async bootstrap(_authorization, request) {
|
|
296
292
|
const entry = authorityFor(request.locator);
|
|
297
293
|
if (entry === undefined)
|
|
@@ -392,7 +388,6 @@ export function createAgentsHouseAdapter(options) {
|
|
|
392
388
|
},
|
|
393
389
|
roomStream: {
|
|
394
390
|
hold: held,
|
|
395
|
-
reopen: notifications.reopen,
|
|
396
391
|
observe: notifications.observe,
|
|
397
392
|
},
|
|
398
393
|
conversations: notifications.conversations,
|
package/dist/discovery.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Capability, DiscoveredRoom, Discovery, Member, ProviderLimit, Retention } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type LogPosition } from './version.js';
|
|
3
3
|
export declare const PROVIDER_ACTIONS = "provider-actions";
|
|
4
|
-
export declare const DISCOVER_PREFIXES: readonly string[];
|
|
5
4
|
export type HouseBounds = {
|
|
6
5
|
max_authored_file_bytes: number;
|
|
7
6
|
max_batch_operations: number;
|
|
@@ -40,6 +39,11 @@ export type HouseDiscoveryDocument = {
|
|
|
40
39
|
authorities: readonly HouseAuthority[];
|
|
41
40
|
actions: readonly string[];
|
|
42
41
|
};
|
|
42
|
+
export type HouseAuthorityChange = {
|
|
43
|
+
member: Member;
|
|
44
|
+
authorities: readonly HouseAuthority[];
|
|
45
|
+
left: readonly string[];
|
|
46
|
+
};
|
|
43
47
|
export type TrackedAuthority = LogPosition & {
|
|
44
48
|
locator: string;
|
|
45
49
|
authority: string;
|
|
@@ -57,9 +61,10 @@ export type HouseSiteDiscovery = {
|
|
|
57
61
|
authorities: readonly HouseSiteAuthority[];
|
|
58
62
|
};
|
|
59
63
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
64
|
+
export declare function parseAuthorityChange(body: unknown): HouseAuthorityChange | null;
|
|
60
65
|
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
61
66
|
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
62
|
-
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
67
|
+
export declare function trackedFrom(document: Pick<HouseDiscoveryDocument, 'authorities'>): TrackedAuthority[];
|
|
63
68
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
64
69
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
65
70
|
export declare function capabilities(actions: HouseDiscoveryDocument['actions']): readonly Capability[];
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"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"}
|
package/dist/discovery.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { declaredActions
|
|
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
|
-
export const DISCOVER_PREFIXES = ['/'];
|
|
5
5
|
const BOUND_KEYS = [
|
|
6
6
|
'max_authored_file_bytes',
|
|
7
7
|
'max_batch_operations',
|
|
@@ -110,6 +110,18 @@ function parseAuthority(value) {
|
|
|
110
110
|
...at,
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
+
function parseAuthorities(value) {
|
|
114
|
+
if (!Array.isArray(value))
|
|
115
|
+
return null;
|
|
116
|
+
const authorities = [];
|
|
117
|
+
for (const entry of value) {
|
|
118
|
+
const authority = parseAuthority(entry);
|
|
119
|
+
if (authority === null)
|
|
120
|
+
return null;
|
|
121
|
+
authorities.push(authority);
|
|
122
|
+
}
|
|
123
|
+
return authorities;
|
|
124
|
+
}
|
|
113
125
|
export function parseDiscovery(body) {
|
|
114
126
|
if (typeof body !== 'object' || body === null)
|
|
115
127
|
return null;
|
|
@@ -125,16 +137,19 @@ export function parseDiscovery(body) {
|
|
|
125
137
|
new Set(actions).size !== actions.length ||
|
|
126
138
|
actions.some((name) => name.length === 0))
|
|
127
139
|
return null;
|
|
128
|
-
|
|
140
|
+
const authorities = parseAuthorities(held.authorities);
|
|
141
|
+
return authorities === null ? null : { member, bounds, authorities, actions };
|
|
142
|
+
}
|
|
143
|
+
export function parseAuthorityChange(body) {
|
|
144
|
+
if (typeof body !== 'object' || body === null)
|
|
129
145
|
return null;
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
return { member, bounds, authorities, actions };
|
|
146
|
+
const held = body;
|
|
147
|
+
const member = parseMember(held.member);
|
|
148
|
+
const authorities = parseAuthorities(held.authorities);
|
|
149
|
+
const left = stringList(held.left);
|
|
150
|
+
if (member === null || authorities === null || left === null)
|
|
151
|
+
return null;
|
|
152
|
+
return { member, authorities, left };
|
|
138
153
|
}
|
|
139
154
|
function parseSiteAuthority(value) {
|
|
140
155
|
if (typeof value !== 'object' || value === null)
|
|
@@ -226,7 +241,7 @@ export function siteCapabilities() {
|
|
|
226
241
|
return [
|
|
227
242
|
{
|
|
228
243
|
name: PROVIDER_ACTIONS,
|
|
229
|
-
actions: [{ name:
|
|
244
|
+
actions: [{ name: SITE_SUBMISSION, inputShape: {}, resultKind: 'house' }],
|
|
230
245
|
},
|
|
231
246
|
];
|
|
232
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
|