@agentshouse/mdruntime-adapter 0.1.0-c86c633e372c4 → 0.1.0-c87013e8a4dd8
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/README.md +3 -3
- package/dist/actions.d.ts +12 -66
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +124 -334
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +290 -406
- package/dist/authored-path.d.ts +61 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +166 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +45 -19
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +252 -67
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -6
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +31 -48
- package/dist/read.d.ts +54 -72
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +198 -325
- package/dist/refusal.d.ts +6 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -11
- package/dist/renamed.d.ts +10 -0
- package/dist/renamed.d.ts.map +1 -0
- package/dist/renamed.js +20 -0
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +63 -0
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/check.d.ts +17 -0
- package/dist/session-content/index.d.ts +6 -0
- package/dist/session-content/parts.d.ts +30 -0
- package/dist/session-content/state.d.ts +59 -0
- package/dist/session-content/turn.d.ts +137 -0
- package/dist/site.d.ts +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +144 -208
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +15 -16
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +263 -423
- package/dist/transport.d.ts +114 -51
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +90 -11
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +17 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +106 -0
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +14 -5
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +177 -166
- package/package.json +10 -5
- package/AGENTS.md +0 -300
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -45
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -38
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -35
package/README.md
CHANGED
|
@@ -20,12 +20,12 @@ import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
|
|
|
20
20
|
|
|
21
21
|
const adapter = createAgentsHouseAdapter({ transport, authorize });
|
|
22
22
|
const host = serveMdRuntime({ adapter, shell });
|
|
23
|
-
host.attach(port, 'my-app');
|
|
23
|
+
host.attach(port, { app: 'my-app' });
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
App code never imports this package; it reaches the Runtime only through the
|
|
27
|
-
client its host hands it. The rules an App's agent follows are
|
|
28
|
-
|
|
27
|
+
client its host hands it. The rules an App's agent follows are the `apps/` pages
|
|
28
|
+
of House's Guide, which House's `guide` tool opens.
|
|
29
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,69 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ActionDeclaration, ActionRequest, ActionResult } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { HouseDoorAnswer, HouseTransport } from './transport.js';
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export type AppInputs = {
|
|
13
|
-
readonly 'conversation.answer': ConversationControl & {
|
|
14
|
-
readonly answer: {
|
|
15
|
-
readonly interaction_id: string;
|
|
16
|
-
readonly response: unknown;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
readonly 'conversation.create': Operated & {
|
|
20
|
-
readonly agent_id: 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
|
-
readonly files?: readonly SentFile[];
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export type AppAnswers = {
|
|
33
|
-
readonly 'conversation.history': ConversationHistories;
|
|
34
|
-
};
|
|
35
|
-
export type AppAnswerAdditions = {
|
|
36
|
-
readonly 'conversation.create': {
|
|
37
|
-
readonly conversation: string;
|
|
38
|
-
};
|
|
39
|
-
readonly 'conversation.send': {
|
|
40
|
-
readonly turn: string;
|
|
41
|
-
};
|
|
42
|
-
readonly 'record.list': {
|
|
43
|
-
readonly attachments: readonly {
|
|
44
|
-
readonly referrer: {
|
|
45
|
-
readonly room_ref: string;
|
|
46
|
-
readonly record: string;
|
|
47
|
-
};
|
|
48
|
-
}[];
|
|
49
|
-
readonly records: readonly {
|
|
50
|
-
readonly attachments: readonly {
|
|
51
|
-
readonly referrer: {
|
|
52
|
-
readonly room_ref: string;
|
|
53
|
-
readonly record: string;
|
|
54
|
-
};
|
|
55
|
-
}[];
|
|
56
|
-
}[];
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
|
|
60
|
-
export declare const SITE_SUBMIT = "submit";
|
|
61
|
-
export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
|
|
62
|
-
export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
|
|
63
|
-
export declare function houseConversationAgents(locator: string): ConversationAgents;
|
|
3
|
+
export type HouseActDoor = Pick<HouseTransport, 'door'>;
|
|
4
|
+
export declare const HOUSE_UNKEPT_READS: readonly string[];
|
|
5
|
+
export declare const HOUSE_LEADING_READS: readonly string[];
|
|
6
|
+
export declare const HOUSE_RENAMED_UNTIL_2026_12_18: ReadonlyMap<string, string>;
|
|
7
|
+
type Rewrites = ReadonlyMap<string, (input: unknown) => unknown>;
|
|
8
|
+
export declare const HOUSE_REWRITTEN_UNTIL_2026_12_19: Rewrites;
|
|
9
|
+
export declare const HOUSE_RENAMED_UNTIL_2026_12_21: ReadonlyMap<string, string>;
|
|
10
|
+
export declare const HOUSE_REWRITTEN_UNTIL_2026_12_21: Rewrites;
|
|
11
|
+
export declare function rewrittenInTurn(...rewrites: readonly Rewrites[]): Rewrites;
|
|
64
12
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
65
|
-
export declare function houseAction(transport:
|
|
66
|
-
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
67
|
-
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
13
|
+
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
14
|
+
export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
|
|
68
15
|
export {};
|
|
69
|
-
//# 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;AAI7F,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,kBAAkB,EAAE,SAAS,MAAM,EAI/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAMhD,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAErE,CAAC;AAgCH,KAAK,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;AAEjE,eAAO,MAAM,gCAAgC,EAAE,QAAgD,CAAC;AAEhG,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAWrE,CAAC;AA4BH,eAAO,MAAM,gCAAgC,EAAE,QAY7C,CAAC;AAEH,wBAAgB,eAAe,CAAC,GAAG,QAAQ,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,CAQ1E;AAUD,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAOvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAwBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,YAAY,CAajG"}
|
package/dist/actions.js
CHANGED
|
@@ -1,74 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { answeredFailure, doorRefusal, resetOf } from './refusal.js';
|
|
2
|
+
import { movedPaths, renamedHandle } from './renamed.js';
|
|
3
|
+
import { refusedFor } from './uncertain.js';
|
|
4
|
+
export const HOUSE_UNKEPT_READS = [
|
|
5
|
+
'account/security/read',
|
|
6
|
+
'billing/read',
|
|
7
|
+
'clients/last-use/list',
|
|
8
|
+
];
|
|
9
|
+
export const HOUSE_LEADING_READS = [
|
|
10
|
+
'app.list',
|
|
11
|
+
'apps/list',
|
|
12
|
+
'sites/list',
|
|
13
|
+
'rooms/members/list',
|
|
14
|
+
'sharing.members',
|
|
15
|
+
];
|
|
16
|
+
export const HOUSE_RENAMED_UNTIL_2026_12_18 = new Map([
|
|
17
|
+
['files/batch', 'update'],
|
|
18
|
+
]);
|
|
19
|
+
function withoutRoomRef(input) {
|
|
20
|
+
if (typeof input !== 'object' || input === null || !('room_ref' in input))
|
|
21
|
+
return input;
|
|
22
|
+
const { room_ref: _room, ...paths } = input;
|
|
23
|
+
return paths;
|
|
24
|
+
}
|
|
25
|
+
const CURRENT_OPS = new Map([
|
|
26
|
+
['create', 'write'],
|
|
27
|
+
['replace', 'write'],
|
|
28
|
+
['patch', 'edit'],
|
|
29
|
+
['rename', 'move'],
|
|
30
|
+
['remove', 'delete'],
|
|
31
|
+
['create_folder', 'mkdir'],
|
|
32
|
+
['remove_folder', 'delete'],
|
|
33
|
+
]);
|
|
34
|
+
function withCurrentOps(input) {
|
|
35
|
+
if (typeof input !== 'object' || input === null || !('changes' in input))
|
|
36
|
+
return input;
|
|
37
|
+
const { changes } = input;
|
|
38
|
+
if (!Array.isArray(changes))
|
|
39
|
+
return input;
|
|
7
40
|
return {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
41
|
+
...input,
|
|
42
|
+
changes: changes.map((change) => {
|
|
43
|
+
if (typeof change !== 'object' || change === null || !('op' in change))
|
|
44
|
+
return change;
|
|
45
|
+
const op = CURRENT_OPS.get(change.op);
|
|
46
|
+
return op === undefined ? change : { ...change, op };
|
|
47
|
+
}),
|
|
12
48
|
};
|
|
13
49
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
50
|
+
export const HOUSE_REWRITTEN_UNTIL_2026_12_19 = new Map([['update', withoutRoomRef]]);
|
|
51
|
+
export const HOUSE_RENAMED_UNTIL_2026_12_21 = new Map([
|
|
52
|
+
['apps/create', 'app_update'],
|
|
53
|
+
['apps/upload', 'app_update'],
|
|
54
|
+
['shares/accept', 'sharing_update'],
|
|
55
|
+
['shares/decline', 'sharing_update'],
|
|
56
|
+
['shares/join-requests/approve', 'sharing_update'],
|
|
57
|
+
['shares/join-requests/decline', 'sharing_update'],
|
|
58
|
+
['rooms/ownership/offer', 'sharing_update'],
|
|
59
|
+
['rooms/ownership/accept', 'sharing_update'],
|
|
60
|
+
['rooms/ownership/decline', 'sharing_update'],
|
|
61
|
+
['rooms/instructions/follow', 'sharing_update'],
|
|
62
|
+
]);
|
|
63
|
+
function held(input) {
|
|
64
|
+
return typeof input === 'object' && input !== null
|
|
65
|
+
? { ...input }
|
|
66
|
+
: {};
|
|
67
|
+
}
|
|
68
|
+
function created(input) {
|
|
69
|
+
return { op: 'create', ...held(input) };
|
|
70
|
+
}
|
|
71
|
+
function uploaded(input) {
|
|
72
|
+
const { app_ref: app, ...files } = held(input);
|
|
73
|
+
return { op: 'publish', app, ...files };
|
|
74
|
+
}
|
|
75
|
+
function decided(op) {
|
|
76
|
+
return (input) => ({ op, ...held(input) });
|
|
77
|
+
}
|
|
78
|
+
function roomNamed(op) {
|
|
79
|
+
return (input) => {
|
|
80
|
+
const { room_ref: room, ...named } = held(input);
|
|
81
|
+
return { op, room, ...named };
|
|
19
82
|
};
|
|
20
83
|
}
|
|
21
|
-
const
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
'
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
|
|
46
|
-
'trigger.list': mapped('triggers/read'),
|
|
47
|
-
'triggerOccurrence.list': mapped('triggers/fired'),
|
|
48
|
-
};
|
|
49
|
-
export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
|
|
50
|
-
export const SITE_SUBMIT = 'submit';
|
|
51
|
-
export const HOUSE_SITE_ACTS = {
|
|
52
|
-
[SITE_SUBMIT]: 'site/submission',
|
|
53
|
-
};
|
|
54
|
-
export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
|
|
55
|
-
const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
|
|
56
|
-
export function houseConversationAgents(locator) {
|
|
57
|
-
return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
|
|
58
|
-
}
|
|
84
|
+
export const HOUSE_REWRITTEN_UNTIL_2026_12_21 = new Map([
|
|
85
|
+
['apps/create', created],
|
|
86
|
+
['apps/upload', uploaded],
|
|
87
|
+
['shares/accept', decided('share_accept')],
|
|
88
|
+
['shares/decline', decided('share_decline')],
|
|
89
|
+
['shares/join-requests/approve', decided('join_request_approve')],
|
|
90
|
+
['shares/join-requests/decline', decided('join_request_decline')],
|
|
91
|
+
['rooms/ownership/offer', roomNamed('ownership_offer')],
|
|
92
|
+
['rooms/ownership/accept', decided('ownership_accept')],
|
|
93
|
+
['rooms/ownership/decline', decided('ownership_decline')],
|
|
94
|
+
['rooms/instructions/follow', roomNamed('instructions_follow')],
|
|
95
|
+
['update', withCurrentOps],
|
|
96
|
+
]);
|
|
97
|
+
export function rewrittenInTurn(...rewrites) {
|
|
98
|
+
const names = new Set(rewrites.flatMap((each) => [...each.keys()]));
|
|
99
|
+
return new Map([...names].map((name) => [
|
|
100
|
+
name,
|
|
101
|
+
(input) => rewrites.reduce((held, each) => each.get(name)?.(held) ?? held, input),
|
|
102
|
+
]));
|
|
103
|
+
}
|
|
104
|
+
const ROOM_SELECTORS = new Map([
|
|
105
|
+
['update', { room: 'changes.room', roomPaths: ['changes.path', 'changes.to', 'paths', 'mount'] }],
|
|
106
|
+
['sharing', { room: 'room' }],
|
|
107
|
+
['sharing_update', { room: 'room' }],
|
|
108
|
+
]);
|
|
59
109
|
export function declaredActions(routes) {
|
|
60
|
-
return routes.map((
|
|
61
|
-
name
|
|
110
|
+
return routes.map((name) => ({
|
|
111
|
+
name,
|
|
62
112
|
inputShape: {},
|
|
63
113
|
resultKind: 'house',
|
|
114
|
+
...(ROOM_SELECTORS.get(name) ?? { room: 'room_ref' }),
|
|
64
115
|
}));
|
|
65
116
|
}
|
|
66
117
|
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
118
|
const route = routeOf(request.name);
|
|
73
119
|
if (route === null)
|
|
74
120
|
return Promise.resolve(malformed());
|
|
@@ -85,293 +131,37 @@ function routeOf(name) {
|
|
|
85
131
|
return null;
|
|
86
132
|
}
|
|
87
133
|
}
|
|
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
134
|
function malformed() {
|
|
99
135
|
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
100
136
|
}
|
|
101
137
|
function unimplemented(name) {
|
|
102
138
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
103
139
|
}
|
|
104
|
-
function
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
function controlBody(input) {
|
|
108
|
-
return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
|
|
140
|
+
function numbered(input) {
|
|
141
|
+
return typeof input?.operation_id === 'string';
|
|
109
142
|
}
|
|
110
|
-
function
|
|
111
|
-
const nested = record(record(input).answer);
|
|
112
|
-
return {
|
|
113
|
-
conversation_id: text(input, 'conversation'),
|
|
114
|
-
operation_id: operationId(input),
|
|
115
|
-
interaction_id: text(nested, 'interaction_id'),
|
|
116
|
-
response: nested.response,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async function createAction(transport, route, input, name) {
|
|
120
|
-
const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
|
|
121
|
-
if (outcome.kind !== 'action')
|
|
122
|
-
return outcome;
|
|
123
|
-
const held = record(outcome.result);
|
|
124
|
-
const conversation = text(held, 'conversation_id');
|
|
125
|
-
return conversation === undefined
|
|
126
|
-
? outcome
|
|
127
|
-
: {
|
|
128
|
-
...outcome,
|
|
129
|
-
result: { ...held, conversation },
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
function withTurn(body) {
|
|
133
|
-
const held = record(body);
|
|
134
|
-
const turn = text(held, 'message_id');
|
|
135
|
-
return turn === undefined
|
|
136
|
-
? body
|
|
137
|
-
: { ...held, turn };
|
|
138
|
-
}
|
|
139
|
-
export function actionOutcome(answer, name) {
|
|
143
|
+
export function actionOutcome(answer, name, input) {
|
|
140
144
|
if (answer.status === 401)
|
|
141
145
|
return { kind: 'revoked-authorization' };
|
|
142
146
|
const refusal = doorRefusal(answer.body);
|
|
143
|
-
if (refusal
|
|
144
|
-
return
|
|
147
|
+
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
148
|
+
return refusedFor(refusal);
|
|
149
|
+
if (refusal !== null) {
|
|
150
|
+
const reset = resetOf(refusal);
|
|
151
|
+
return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
|
|
152
|
+
}
|
|
145
153
|
if (answer.status === 404)
|
|
146
154
|
return unimplemented(name);
|
|
147
|
-
if (answer.status === 0 || answer.status >= 400)
|
|
148
|
-
return
|
|
155
|
+
if (answer.status === 0 || answer.status >= 400) {
|
|
156
|
+
return answeredFailure(answer.status, answer.body);
|
|
157
|
+
}
|
|
149
158
|
return { kind: 'action', result: answer.body };
|
|
150
159
|
}
|
|
151
|
-
function referredRecord(view, roomRef) {
|
|
152
|
-
const held = record(view);
|
|
153
|
-
if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
|
|
154
|
-
return view;
|
|
155
|
-
const referrer = {
|
|
156
|
-
room_ref: roomRef,
|
|
157
|
-
record: held.record,
|
|
158
|
-
};
|
|
159
|
-
return {
|
|
160
|
-
...held,
|
|
161
|
-
attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
async function recordsAction(transport, route, input, name) {
|
|
165
|
-
const outcome = actionOutcome(await transport.door(route, input), name);
|
|
166
|
-
if (outcome.kind !== 'action')
|
|
167
|
-
return outcome;
|
|
168
|
-
const roomRef = text(input, 'room_ref');
|
|
169
|
-
const read = record(outcome.result);
|
|
170
|
-
return {
|
|
171
|
-
...outcome,
|
|
172
|
-
result: Array.isArray(read.records)
|
|
173
|
-
? { ...read, records: read.records.map((view) => referredRecord(view, roomRef)) }
|
|
174
|
-
: referredRecord(outcome.result, roomRef),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
160
|
async function carry(transport, route, name, input) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
const sha256 = text(file, 'contentHash');
|
|
185
|
-
if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
|
|
186
|
-
return null;
|
|
187
|
-
const mediaType = text(file, 'mediaType');
|
|
188
|
-
const width = file.width;
|
|
189
|
-
const height = file.height;
|
|
190
|
-
return {
|
|
191
|
-
name,
|
|
192
|
-
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
193
|
-
bytes,
|
|
194
|
-
sha256,
|
|
195
|
-
...(typeof width === 'number' && typeof height === 'number'
|
|
196
|
-
? { dimensions: { width, height } }
|
|
197
|
-
: {}),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
function sendFiles(input) {
|
|
201
|
-
const files = record(input).files;
|
|
202
|
-
if (files === undefined)
|
|
203
|
-
return [];
|
|
204
|
-
if (!Array.isArray(files))
|
|
205
|
-
return null;
|
|
206
|
-
const declared = [];
|
|
207
|
-
for (const entry of files) {
|
|
208
|
-
const file = sendFile(entry);
|
|
209
|
-
if (file === null)
|
|
210
|
-
return null;
|
|
211
|
-
declared.push(file);
|
|
212
|
-
}
|
|
213
|
-
return declared;
|
|
214
|
-
}
|
|
215
|
-
function sendBody(input) {
|
|
216
|
-
const files = sendFiles(input);
|
|
217
|
-
const operation = text(input, 'operation_id');
|
|
218
|
-
if (files === null || operation === undefined)
|
|
219
|
-
return null;
|
|
220
|
-
const textValue = text(input, 'text');
|
|
221
|
-
return {
|
|
222
|
-
conversation_id: text(input, 'conversation'),
|
|
223
|
-
operation_id: operation,
|
|
224
|
-
...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
|
|
225
|
-
...(files.length === 0 ? {} : { files }),
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
async function fileBytes(file) {
|
|
229
|
-
const blob = record(file).blob;
|
|
230
|
-
if (blob === undefined || typeof blob !== 'object' || blob === null)
|
|
231
|
-
return null;
|
|
232
|
-
if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
|
|
233
|
-
return null;
|
|
234
|
-
return new Uint8Array(await blob.arrayBuffer());
|
|
235
|
-
}
|
|
236
|
-
function uploadGrant(entry) {
|
|
237
|
-
if (!('upload' in record(entry)))
|
|
238
|
-
return 'absent';
|
|
239
|
-
const upload = record(record(entry).upload);
|
|
240
|
-
if (upload.method !== 'POST')
|
|
241
|
-
return null;
|
|
242
|
-
if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
|
|
243
|
-
return null;
|
|
244
|
-
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
245
|
-
}
|
|
246
|
-
async function uploadFiles(transport, input, result) {
|
|
247
|
-
const sent = record(result).files;
|
|
248
|
-
if (!Array.isArray(sent))
|
|
249
|
-
return true;
|
|
250
|
-
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
251
|
-
for (const [index, entry] of sent.entries()) {
|
|
252
|
-
const grant = uploadGrant(entry);
|
|
253
|
-
if (grant === 'absent')
|
|
254
|
-
continue;
|
|
255
|
-
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
256
|
-
if (grant === null || bytes === null)
|
|
257
|
-
return false;
|
|
258
|
-
const answer = await transport.transfer({
|
|
259
|
-
act: 'conversation_file_upload',
|
|
260
|
-
url: grant.url,
|
|
261
|
-
body: bytes,
|
|
262
|
-
operation: grant.operation,
|
|
263
|
-
});
|
|
264
|
-
if (answer.status !== 200)
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
269
|
-
async function sendAction(transport, route, input, name) {
|
|
270
|
-
const body = sendBody(input);
|
|
271
|
-
if (body === null)
|
|
272
|
-
return malformed();
|
|
273
|
-
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
274
|
-
if (outcome.kind !== 'action')
|
|
275
|
-
return outcome;
|
|
276
|
-
if (!(await uploadFiles(transport, input, outcome.result))) {
|
|
277
|
-
return { kind: 'transport-uncertainty' };
|
|
278
|
-
}
|
|
279
|
-
return { ...outcome, result: withTurn(outcome.result) };
|
|
280
|
-
}
|
|
281
|
-
function historyCursor(value) {
|
|
282
|
-
const acceptedAt = text(value, 'accepted_at');
|
|
283
|
-
const messageId = text(value, 'message_id');
|
|
284
|
-
if (acceptedAt === undefined || messageId === undefined)
|
|
285
|
-
return null;
|
|
286
|
-
return { accepted_at: acceptedAt, message_id: messageId };
|
|
287
|
-
}
|
|
288
|
-
function position(cursor) {
|
|
289
|
-
return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
|
|
290
|
-
}
|
|
291
|
-
function positionCursor(value) {
|
|
292
|
-
try {
|
|
293
|
-
return historyCursor(JSON.parse(value));
|
|
294
|
-
}
|
|
295
|
-
catch {
|
|
296
|
-
return null;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
export function acceptedMessage(entry) {
|
|
300
|
-
const cursor = historyCursor(entry);
|
|
301
|
-
if (cursor === null)
|
|
302
|
-
return null;
|
|
303
|
-
const message = structuredClone(record(entry));
|
|
304
|
-
const referrer = { message: cursor.message_id };
|
|
305
|
-
return {
|
|
306
|
-
identity: cursor.message_id,
|
|
307
|
-
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
308
|
-
position: position(cursor),
|
|
309
|
-
text: text(entry, 'text') ?? '',
|
|
310
|
-
message: Array.isArray(message.files)
|
|
311
|
-
? {
|
|
312
|
-
...message,
|
|
313
|
-
files: message.files.map((file) => ({ ...record(file), referrer })),
|
|
314
|
-
}
|
|
315
|
-
: message,
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
function historyPage(entry) {
|
|
319
|
-
const held = record(entry);
|
|
320
|
-
const conversation = text(held, 'conversation_id');
|
|
321
|
-
if (conversation === undefined || !Array.isArray(held.messages))
|
|
322
|
-
return null;
|
|
323
|
-
const messages = [];
|
|
324
|
-
for (const one of held.messages) {
|
|
325
|
-
const message = acceptedMessage(one);
|
|
326
|
-
if (message === null)
|
|
327
|
-
return null;
|
|
328
|
-
messages.push(message);
|
|
329
|
-
}
|
|
330
|
-
const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
|
|
331
|
-
if (next === null)
|
|
332
|
-
return null;
|
|
333
|
-
return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
|
|
334
|
-
}
|
|
335
|
-
function historyAsks(input) {
|
|
336
|
-
const asked = record(input).conversations;
|
|
337
|
-
if (!Array.isArray(asked) || asked.length === 0)
|
|
338
|
-
return null;
|
|
339
|
-
const asks = [];
|
|
340
|
-
for (const entry of asked) {
|
|
341
|
-
const conversationId = text(entry, 'conversation');
|
|
342
|
-
if (conversationId === undefined)
|
|
343
|
-
return null;
|
|
344
|
-
const afterValue = text(entry, 'after');
|
|
345
|
-
const after = afterValue === undefined ? undefined : positionCursor(afterValue);
|
|
346
|
-
if (after === null)
|
|
347
|
-
return null;
|
|
348
|
-
asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
|
|
349
|
-
}
|
|
350
|
-
return asks;
|
|
351
|
-
}
|
|
352
|
-
async function historyAction(transport, route, input, name) {
|
|
353
|
-
const asks = historyAsks(input);
|
|
354
|
-
if (asks === null)
|
|
355
|
-
return malformed();
|
|
356
|
-
const histories = [];
|
|
357
|
-
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
358
|
-
const answer = await transport.door(route, {
|
|
359
|
-
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
360
|
-
limit: HISTORY_PAGE,
|
|
361
|
-
});
|
|
362
|
-
const outcome = actionOutcome(answer, name);
|
|
363
|
-
if (outcome.kind !== 'action')
|
|
364
|
-
return outcome;
|
|
365
|
-
const answered = record(outcome.result).histories;
|
|
366
|
-
if (!Array.isArray(answered))
|
|
367
|
-
return { kind: 'transport-uncertainty' };
|
|
368
|
-
for (const entry of answered) {
|
|
369
|
-
const page = historyPage(entry);
|
|
370
|
-
if (page === null)
|
|
371
|
-
return { kind: 'transport-uncertainty' };
|
|
372
|
-
histories.push(page);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
const result = { histories };
|
|
376
|
-
return { kind: 'action', result };
|
|
161
|
+
const answered = actionOutcome(await transport.door(route, input), name, input);
|
|
162
|
+
const renamed = renamedHandle(answered);
|
|
163
|
+
if (renamed === null)
|
|
164
|
+
return answered;
|
|
165
|
+
const moved = movedPaths(input, ROOM_SELECTORS.get(name)?.roomPaths ?? [], renamed);
|
|
166
|
+
return actionOutcome(await transport.door(route, moved), name, moved);
|
|
377
167
|
}
|
package/dist/adapter.d.ts
CHANGED
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAkBd,MAAM,wBAAwB,CAAC;AAmChC,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAoBxB,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;AAcrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA8cpF"}
|