@agentshouse/mdruntime 0.1.0-cc2e934017fb1 → 0.1.0-cc4575cb1254b
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 +21 -19
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +15 -24
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +139 -68
- package/dist/adapter.d.ts +114 -24
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +347 -0
- package/dist/binary.d.ts +6 -2
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +10 -3
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +20 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +32 -60
- package/dist/collection.d.ts +5 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +16 -8
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +2 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +21 -11
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +22 -16
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +23 -10
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +18 -8
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +26 -15
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +270 -206
- package/dist/declaration.js +1 -1
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +36 -9
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +5 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +14 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +45 -16
- package/dist/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- package/dist/failure.d.ts +2 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +4 -2
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +80 -34
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +67 -0
- package/dist/index.d.ts +18 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -6
- package/dist/install.d.ts +10 -4
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +45 -46
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +50 -32
- package/dist/listing.d.ts +24 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +50 -21
- package/dist/live.d.ts +5 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +71 -30
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +4 -3
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +2 -3
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +167 -33
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +77 -29
- package/dist/messages.d.ts +17 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +29 -10
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +5 -8
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +20 -10
- package/dist/outcome.d.ts +24 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +33 -3
- package/dist/overlay.d.ts +7 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -9
- package/dist/parts.d.ts +4 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -15
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +198 -87
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +81 -64
- package/dist/query.d.ts +2 -2
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +2 -2
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +73 -48
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +166 -41
- package/dist/react.d.ts +11 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/readiness.d.ts +20 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +17 -10
- package/dist/reads.d.ts +4 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +7 -3
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +1 -3
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +4 -4
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +30 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +258 -32
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +11 -6
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +10 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +23 -10
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +6 -4
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +105 -124
- package/dist/saves.d.ts +4 -2
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +66 -21
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/shown.d.ts +5 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +79 -43
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +4 -3
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +4 -9
- package/dist/source.d.ts +7 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +15 -2
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +21 -5
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +63 -22
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store.d.ts +17 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +18 -6
- package/dist/stored.d.ts +38 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +203 -55
- package/dist/surface.d.ts +14 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +59 -27
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +76 -40
- package/dist/tables.d.ts +22 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +90 -324
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +1 -2
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +47 -10
- package/dist/wire.d.ts +38 -15
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +20 -13
- package/package.json +3 -3
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
package/dist/actions.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { roomTarget, target } from '@agentshouse/mdmodel';
|
|
2
|
-
import { resendConversations } from './conversation.js';
|
|
2
|
+
import { CATCHING_UP, holdsSubmission, resendConversations } from './conversation.js';
|
|
3
3
|
import { listingNow } from './listing.js';
|
|
4
4
|
import { locked, lockedRooms } from './locks.js';
|
|
5
5
|
import { scoped } from './models.js';
|
|
6
|
-
import { ABSENT_TARGET,
|
|
6
|
+
import { ABSENT_TARGET, failure, historyAnswer, LOCKED_UNREADABLE, lockedRoom, handedOutcome, UNANSWERED, undeclared, UNCERTAIN, UNREADABLE, } from './outcome.js';
|
|
7
7
|
import { refuse } from './refusal.js';
|
|
8
8
|
function operationOf(input) {
|
|
9
9
|
const operation = input?.operation_id;
|
|
10
10
|
return typeof operation === 'string' ? operation : null;
|
|
11
11
|
}
|
|
12
12
|
export async function readHistory(runtime, locator, path, query = {}) {
|
|
13
|
-
const { store, socket, presence
|
|
13
|
+
const { store, socket, presence } = runtime;
|
|
14
14
|
const { session } = socket;
|
|
15
15
|
if (socket.closed() || session.now().refusal !== null)
|
|
16
16
|
return UNCERTAIN;
|
|
@@ -27,12 +27,6 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
27
27
|
if (closed || authorization === undefined || refusal !== null)
|
|
28
28
|
return UNCERTAIN;
|
|
29
29
|
const since = presence.losses();
|
|
30
|
-
const transfer = ['transfer', 'history', locator, path];
|
|
31
|
-
if (query.revision !== undefined)
|
|
32
|
-
transfer.push(query.revision);
|
|
33
|
-
if (query.pageToken !== undefined)
|
|
34
|
-
transfer.push(query.pageToken);
|
|
35
|
-
journal.record(transfer.join(' '));
|
|
36
30
|
try {
|
|
37
31
|
const result = await socket.history(authorization, {
|
|
38
32
|
locator,
|
|
@@ -40,7 +34,6 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
40
34
|
...(query.revision === undefined ? {} : { revision: query.revision }),
|
|
41
35
|
...(query.pageToken === undefined ? {} : { pageToken: query.pageToken }),
|
|
42
36
|
});
|
|
43
|
-
journal.record(`outcome history ${result.kind}`);
|
|
44
37
|
if (presence.lostSince(locator, since))
|
|
45
38
|
return failure({ kind: 'room-not-readable', locator });
|
|
46
39
|
if (result.kind === 'scoped-refusal') {
|
|
@@ -53,7 +46,6 @@ export async function readHistory(runtime, locator, path, query = {}) {
|
|
|
53
46
|
return historyAnswer(result);
|
|
54
47
|
}
|
|
55
48
|
catch {
|
|
56
|
-
journal.record('outcome history transport-uncertainty');
|
|
57
49
|
return UNCERTAIN;
|
|
58
50
|
}
|
|
59
51
|
}
|
|
@@ -94,8 +86,16 @@ export async function resolveReference(runtime, room, path, destination) {
|
|
|
94
86
|
? { kind: 'deleted', ...at, revision: last }
|
|
95
87
|
: { kind: 'document', ...at };
|
|
96
88
|
}
|
|
97
|
-
async function
|
|
98
|
-
|
|
89
|
+
async function declaredActions({ store, socket }) {
|
|
90
|
+
const { unstored } = socket.session.now();
|
|
91
|
+
if (unstored !== null)
|
|
92
|
+
return unstored.capabilities;
|
|
93
|
+
if (!store.needed())
|
|
94
|
+
return [];
|
|
95
|
+
return (await (await store.open()).facts()).capabilities;
|
|
96
|
+
}
|
|
97
|
+
async function declaredAction(runtime, name) {
|
|
98
|
+
for (const capability of await declaredActions(runtime)) {
|
|
99
99
|
for (const action of capability.actions ?? []) {
|
|
100
100
|
if (action.name === name)
|
|
101
101
|
return action;
|
|
@@ -103,32 +103,44 @@ async function declaredAction({ store }, name) {
|
|
|
103
103
|
}
|
|
104
104
|
return undefined;
|
|
105
105
|
}
|
|
106
|
+
async function declaration(runtime, name) {
|
|
107
|
+
const { socket } = runtime;
|
|
108
|
+
const declared = await declaredAction(runtime, name);
|
|
109
|
+
if (declared !== undefined || socket.streamed || socket.session.now().roomsNamed)
|
|
110
|
+
return declared;
|
|
111
|
+
await runtime.discover();
|
|
112
|
+
return declaredAction(runtime, name);
|
|
113
|
+
}
|
|
106
114
|
async function calledRooms(runtime, name, input) {
|
|
107
|
-
const member = (await
|
|
115
|
+
const member = (await declaration(runtime, name))?.room;
|
|
108
116
|
if (member === undefined || input === null || typeof input !== 'object')
|
|
109
117
|
return [];
|
|
110
118
|
const named = input[member];
|
|
111
119
|
return (Array.isArray(named) ? named : [named]).filter((room) => typeof room === 'string');
|
|
112
120
|
}
|
|
113
|
-
export async function invokeAction(runtime, name, input, dispatching) {
|
|
114
|
-
const { store, socket,
|
|
121
|
+
export async function invokeAction(runtime, name, input, { dispatching, attempt } = {}) {
|
|
122
|
+
const { store, socket, retries } = runtime;
|
|
115
123
|
const { session } = socket;
|
|
116
124
|
await socket.ready;
|
|
117
|
-
if (socket.closed() || session.now().refusal !== null)
|
|
118
|
-
return
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
if (socket.closed() || session.now().refusal !== null) {
|
|
126
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
127
|
+
}
|
|
128
|
+
if ((await declaredAction(runtime, name)) === undefined) {
|
|
129
|
+
return session.now().roomsNamed
|
|
130
|
+
? undeclared(name)
|
|
131
|
+
: handedOutcome(retries, attempt, UNANSWERED);
|
|
132
|
+
}
|
|
121
133
|
try {
|
|
122
134
|
await socket.authorize();
|
|
123
135
|
}
|
|
124
136
|
catch {
|
|
125
|
-
return
|
|
137
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
126
138
|
}
|
|
127
139
|
const { closed, authorization, refusal } = session.now();
|
|
128
|
-
if (closed || authorization === undefined || refusal !== null)
|
|
129
|
-
return
|
|
140
|
+
if (closed || authorization === undefined || refusal !== null) {
|
|
141
|
+
return handedOutcome(retries, attempt, UNANSWERED);
|
|
142
|
+
}
|
|
130
143
|
await dispatching?.();
|
|
131
|
-
journal.record(`transfer action ${name}`);
|
|
132
144
|
try {
|
|
133
145
|
const result = await socket.action(authorization, { name, input });
|
|
134
146
|
if (result.kind === 'scoped-refusal') {
|
|
@@ -138,34 +150,28 @@ export async function invokeAction(runtime, name, input, dispatching) {
|
|
|
138
150
|
}
|
|
139
151
|
if (result.kind === 'revoked-authorization')
|
|
140
152
|
await refuse(runtime, 'revoked-authorization');
|
|
141
|
-
|
|
142
|
-
if (result.kind === 'rejected')
|
|
143
|
-
journal.record(`refusal rejected ${result.code}`);
|
|
144
|
-
return calledResult(result);
|
|
153
|
+
return handedOutcome(retries, attempt, result);
|
|
145
154
|
}
|
|
146
|
-
catch {
|
|
147
|
-
|
|
148
|
-
return UNCERTAIN;
|
|
155
|
+
catch (error) {
|
|
156
|
+
return handedOutcome(retries, attempt, { kind: 'transport-uncertainty', failure: error });
|
|
149
157
|
}
|
|
150
158
|
}
|
|
151
159
|
export async function readConversationHistory(runtime, request) {
|
|
152
|
-
const { socket,
|
|
160
|
+
const { socket, retries } = runtime;
|
|
161
|
+
const caught = { step: 'conversations', instance: CATCHING_UP };
|
|
153
162
|
await socket.ready;
|
|
154
163
|
const stream = socket.conversations();
|
|
155
164
|
if (socket.closed() || socket.session.now().refusal !== null || stream?.history === undefined) {
|
|
156
|
-
return
|
|
165
|
+
return handedOutcome(retries, caught, UNANSWERED);
|
|
157
166
|
}
|
|
158
|
-
journal.record('transfer conversation history');
|
|
159
167
|
try {
|
|
160
168
|
const result = await stream.history(request);
|
|
161
169
|
if (result.kind === 'revoked-authorization')
|
|
162
170
|
await refuse(runtime, 'revoked-authorization');
|
|
163
|
-
|
|
164
|
-
return calledResult(result);
|
|
171
|
+
return handedOutcome(retries, caught, result);
|
|
165
172
|
}
|
|
166
|
-
catch {
|
|
167
|
-
|
|
168
|
-
return UNCERTAIN;
|
|
173
|
+
catch (error) {
|
|
174
|
+
return handedOutcome(retries, caught, { kind: 'transport-uncertainty', failure: error });
|
|
169
175
|
}
|
|
170
176
|
}
|
|
171
177
|
function unsettled(result) {
|
|
@@ -173,59 +179,124 @@ function unsettled(result) {
|
|
|
173
179
|
return false;
|
|
174
180
|
return result.retryable && (result.kind !== 'rejected' || result.reset === undefined);
|
|
175
181
|
}
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
function numberedCall(runtime, name, input, operation, dispatching) {
|
|
183
|
+
return invokeAction(runtime, name, input, {
|
|
184
|
+
dispatching,
|
|
185
|
+
attempt: { step: 'sending', instance: `action ${operation}` },
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function keptSender(runtime, name, input, operation, resent = false) {
|
|
189
|
+
const { store, socket } = runtime;
|
|
178
190
|
const { lanes } = socket;
|
|
191
|
+
const dispatching = async () => (await store.open()).keepCall({ operation, name, input });
|
|
192
|
+
let waiting = [];
|
|
193
|
+
let last = UNCERTAIN;
|
|
194
|
+
let lost = resent;
|
|
195
|
+
const tell = (result) => {
|
|
196
|
+
last = result;
|
|
197
|
+
const told = waiting;
|
|
198
|
+
waiting = [];
|
|
199
|
+
for (const answer of told)
|
|
200
|
+
answer(result);
|
|
201
|
+
};
|
|
202
|
+
const sender = {
|
|
203
|
+
next: () => new Promise((answer) => waiting.push(answer)),
|
|
204
|
+
async send() {
|
|
205
|
+
let result;
|
|
206
|
+
try {
|
|
207
|
+
result = await numberedCall(runtime, name, input, operation, dispatching);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
tell(last);
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
if (unsettled(result))
|
|
214
|
+
lost = true;
|
|
215
|
+
else {
|
|
216
|
+
await (await store.open()).dropCall(operation);
|
|
217
|
+
lanes.settle(operation, lost);
|
|
218
|
+
}
|
|
219
|
+
tell(result);
|
|
220
|
+
return result;
|
|
221
|
+
},
|
|
222
|
+
release() {
|
|
223
|
+
lanes.sent(operation, sender);
|
|
224
|
+
tell(last);
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
lanes.sending(operation, sender);
|
|
228
|
+
return sender;
|
|
229
|
+
}
|
|
230
|
+
async function recoveredAction(runtime, name, input, attempt) {
|
|
231
|
+
const { socket, recovery } = runtime;
|
|
179
232
|
const operation = operationOf(input);
|
|
180
233
|
if (operation === null)
|
|
181
|
-
return invokeAction(runtime, name, input);
|
|
182
|
-
const
|
|
183
|
-
|
|
234
|
+
return invokeAction(runtime, name, input, { attempt });
|
|
235
|
+
const held = socket.lanes.sender(operation);
|
|
236
|
+
if (held !== undefined)
|
|
237
|
+
return held.next();
|
|
238
|
+
const sender = keptSender(runtime, name, input, operation);
|
|
239
|
+
let first;
|
|
184
240
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (!socket.isOpen())
|
|
191
|
-
return 'again';
|
|
192
|
-
result = await invokeAction(runtime, name, input, kept);
|
|
193
|
-
return unsettled(result) ? 'again' : 'done';
|
|
194
|
-
}, { again: true });
|
|
195
|
-
}
|
|
196
|
-
if (!unsettled(result))
|
|
197
|
-
await (await store.open()).dropCall(operation);
|
|
198
|
-
return result;
|
|
241
|
+
first = await sender.send();
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
sender.release();
|
|
245
|
+
throw error;
|
|
199
246
|
}
|
|
200
|
-
|
|
201
|
-
|
|
247
|
+
if (!unsettled(first)) {
|
|
248
|
+
sender.release();
|
|
249
|
+
return first;
|
|
202
250
|
}
|
|
251
|
+
void recovery
|
|
252
|
+
.attempt(`action ${operation}`, async () => {
|
|
253
|
+
if (socket.closed() || socket.session.now().refusal !== null)
|
|
254
|
+
return 'done';
|
|
255
|
+
if (!socket.isOpen())
|
|
256
|
+
return 'again';
|
|
257
|
+
return unsettled(await sender.send()) ? 'again' : 'done';
|
|
258
|
+
}, { again: true })
|
|
259
|
+
.finally(() => sender.release());
|
|
260
|
+
return first;
|
|
203
261
|
}
|
|
204
|
-
export async function called(runtime, name, input) {
|
|
262
|
+
export async function called(runtime, name, input, attempt) {
|
|
205
263
|
await runtime.socket.ready;
|
|
206
264
|
const lockedNow = await lockedRooms(runtime);
|
|
207
265
|
const room = (await calledRooms(runtime, name, input)).find((one) => lockedNow.includes(one));
|
|
208
|
-
return room === undefined ? recoveredAction(runtime, name, input) : lockedRoom(room);
|
|
266
|
+
return room === undefined ? recoveredAction(runtime, name, input, attempt) : lockedRoom(room);
|
|
209
267
|
}
|
|
210
|
-
export async function
|
|
268
|
+
export async function answeredCall(runtime, operation) {
|
|
211
269
|
const { store, socket } = runtime;
|
|
212
270
|
const { lanes } = socket;
|
|
271
|
+
const held = () => lanes.sender(operation) !== undefined || lanes.unclaimed(operation);
|
|
272
|
+
if (!held()) {
|
|
273
|
+
const calls = await (await store.open()).calls();
|
|
274
|
+
const kept = calls.some((one) => one.operation === operation) ||
|
|
275
|
+
(await holdsSubmission(runtime.conversations, operation));
|
|
276
|
+
if (!held() && !kept)
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
await lanes.settled(operation);
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
export async function resendCalls(runtime, signal) {
|
|
283
|
+
const { store, socket } = runtime;
|
|
213
284
|
if (!socket.isOpen() || socket.closed() || socket.stopping())
|
|
214
285
|
return 'done';
|
|
215
286
|
const local = await store.open();
|
|
216
287
|
for (const held of await local.calls()) {
|
|
217
|
-
if (lanes.
|
|
288
|
+
if (socket.lanes.sender(held.operation) !== undefined)
|
|
218
289
|
continue;
|
|
219
290
|
if (socket.closed() || signal.aborted)
|
|
220
291
|
return 'done';
|
|
221
|
-
|
|
292
|
+
const name = runtime.renamedActions.get(held.name) ?? held.name;
|
|
293
|
+
const sender = keptSender(runtime, name, held.input, held.operation, true);
|
|
222
294
|
try {
|
|
223
|
-
if (unsettled(await
|
|
295
|
+
if (unsettled(await sender.send()))
|
|
224
296
|
return 'again';
|
|
225
|
-
await local.dropCall(held.operation);
|
|
226
297
|
}
|
|
227
298
|
finally {
|
|
228
|
-
|
|
299
|
+
sender.release();
|
|
229
300
|
}
|
|
230
301
|
}
|
|
231
302
|
return 'done';
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { SavedFacts, TypedPath } from '@agentshouse/mdmodel';
|
|
1
|
+
import type { SavedFacts, TypedPath, VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { Operation, SessionState } from '@agentshouse/session-content';
|
|
3
3
|
import type { ModelResult } from './model.js';
|
|
4
4
|
export type { SavedFacts, TypedPath };
|
|
5
5
|
import type { Open } from './open.js';
|
|
6
6
|
import type { ChangeBatch } from './change.js';
|
|
7
|
+
import type { QueryDocument, QueryGroup } from './query.js';
|
|
7
8
|
export type Authorization = object;
|
|
8
9
|
export type MdModelIdentity = {
|
|
9
10
|
identity: string;
|
|
@@ -42,15 +43,13 @@ export type Capability = {
|
|
|
42
43
|
export type ListedConversation = {
|
|
43
44
|
conversation: string;
|
|
44
45
|
agent: string;
|
|
45
|
-
agentName: string;
|
|
46
|
-
agentRetired: boolean;
|
|
47
46
|
name: string;
|
|
48
47
|
created: string;
|
|
49
|
-
finished: string | null;
|
|
50
48
|
outcome: string | null;
|
|
51
49
|
waiting: boolean;
|
|
52
50
|
newest: string | null;
|
|
53
51
|
processEnded: string | null;
|
|
52
|
+
subject: string | null;
|
|
54
53
|
};
|
|
55
54
|
export type ConversationAction = 'conversations/create' | 'conversations/send' | 'conversations/interaction/answer' | 'conversations/interrupt' | 'conversations/kill' | 'conversations/delete' | 'conversations/take-out' | 'conversations/rename' | 'conversations/option/set' | 'conversations/retry' | 'agent-functions/decide';
|
|
56
55
|
export type ConversationMessage = {
|
|
@@ -146,10 +145,6 @@ export type ConversationEvent = {
|
|
|
146
145
|
kind: 'state';
|
|
147
146
|
conversation: string;
|
|
148
147
|
state: SessionState | null;
|
|
149
|
-
} | {
|
|
150
|
-
kind: 'link';
|
|
151
|
-
conversation: string;
|
|
152
|
-
connected: boolean;
|
|
153
148
|
} | {
|
|
154
149
|
kind: 'deliveries';
|
|
155
150
|
conversation: string;
|
|
@@ -164,6 +159,7 @@ export type ConversationEvent = {
|
|
|
164
159
|
conversation: string;
|
|
165
160
|
} | {
|
|
166
161
|
kind: 'list';
|
|
162
|
+
agents: readonly ListedAgent[];
|
|
167
163
|
entries: readonly ListedConversation[];
|
|
168
164
|
whole: boolean;
|
|
169
165
|
more: boolean;
|
|
@@ -171,6 +167,9 @@ export type ConversationEvent = {
|
|
|
171
167
|
} | {
|
|
172
168
|
kind: 'listed';
|
|
173
169
|
entry: ListedConversation;
|
|
170
|
+
} | {
|
|
171
|
+
kind: 'agent';
|
|
172
|
+
agent: ListedAgent;
|
|
174
173
|
} | {
|
|
175
174
|
kind: 'unlisted';
|
|
176
175
|
conversation: string;
|
|
@@ -180,18 +179,56 @@ export type AgentEnvironment = {
|
|
|
180
179
|
name: string;
|
|
181
180
|
state: 'online' | 'offline';
|
|
182
181
|
};
|
|
182
|
+
export type ListedOwner = {
|
|
183
|
+
readonly user: string;
|
|
184
|
+
readonly name: string;
|
|
185
|
+
};
|
|
186
|
+
export type ListedSpaceRef = {
|
|
187
|
+
readonly space_ref: string;
|
|
188
|
+
readonly name: string;
|
|
189
|
+
};
|
|
190
|
+
export type RoomListEntry = {
|
|
191
|
+
readonly room_ref: string;
|
|
192
|
+
readonly room_handle: string;
|
|
193
|
+
readonly name: string;
|
|
194
|
+
readonly level: 'search' | 'open' | 'keep';
|
|
195
|
+
readonly access: 'owner' | 'manage' | 'write' | 'read' | 'public';
|
|
196
|
+
readonly owner: ListedOwner;
|
|
197
|
+
readonly created: string;
|
|
198
|
+
readonly archived?: string;
|
|
199
|
+
readonly exportable?: true;
|
|
200
|
+
readonly space?: ListedSpaceRef;
|
|
201
|
+
};
|
|
202
|
+
export type SpaceListEntry = ListedSpaceRef & {
|
|
203
|
+
readonly owner: ListedOwner;
|
|
204
|
+
readonly created: string;
|
|
205
|
+
readonly manages?: true;
|
|
206
|
+
};
|
|
207
|
+
export type RoomList = {
|
|
208
|
+
readonly rooms: readonly RoomListEntry[];
|
|
209
|
+
readonly spaces: readonly SpaceListEntry[];
|
|
210
|
+
};
|
|
183
211
|
export type ListedAgent = {
|
|
184
|
-
|
|
212
|
+
id: string;
|
|
185
213
|
name: string;
|
|
186
|
-
|
|
214
|
+
revision: number;
|
|
215
|
+
environment: string;
|
|
216
|
+
environment_name: string;
|
|
217
|
+
environment_connected: boolean;
|
|
218
|
+
launch_directory: string;
|
|
187
219
|
cli: string;
|
|
188
|
-
|
|
220
|
+
model: string | null;
|
|
221
|
+
effort: string | null;
|
|
222
|
+
mode: string | null;
|
|
223
|
+
base_instructions: string;
|
|
224
|
+
in_telegram: boolean;
|
|
225
|
+
created: string;
|
|
226
|
+
retired_at: string | null;
|
|
189
227
|
};
|
|
190
228
|
export type ConversationStream = {
|
|
191
229
|
replicate(conversations: readonly string[]): void;
|
|
192
230
|
hold(cursor: string | null): void;
|
|
193
231
|
observe(notify: (event: ConversationEvent) => void): () => void;
|
|
194
|
-
agents?(): Promise<readonly ListedAgent[] | null>;
|
|
195
232
|
history?(request: ConversationHistoryRequest): Promise<ActionResult>;
|
|
196
233
|
};
|
|
197
234
|
export type ActionDeclaration = {
|
|
@@ -214,6 +251,11 @@ export type Retention = {
|
|
|
214
251
|
history: HistoryRetention;
|
|
215
252
|
refreshHorizon: number;
|
|
216
253
|
};
|
|
254
|
+
export type QueriedRoom = {
|
|
255
|
+
readonly locator: string;
|
|
256
|
+
readonly handle: string;
|
|
257
|
+
readonly name: string;
|
|
258
|
+
};
|
|
217
259
|
export type Discovery = {
|
|
218
260
|
kind: 'discovery';
|
|
219
261
|
rooms: readonly DiscoveredRoom[];
|
|
@@ -221,9 +263,13 @@ export type Discovery = {
|
|
|
221
263
|
providerLimits: readonly ProviderLimit[];
|
|
222
264
|
retention: Retention;
|
|
223
265
|
member?: Member;
|
|
266
|
+
timeZone?: string | null;
|
|
267
|
+
roomList?: RoomList;
|
|
268
|
+
queriesOnly?: readonly QueriedRoom[];
|
|
224
269
|
};
|
|
225
270
|
export type TransportUncertainty = {
|
|
226
271
|
kind: 'transport-uncertainty';
|
|
272
|
+
failure?: unknown;
|
|
227
273
|
};
|
|
228
274
|
export type RoomNotReadable = {
|
|
229
275
|
kind: 'room-not-readable';
|
|
@@ -262,10 +308,12 @@ export type HeadChange = {
|
|
|
262
308
|
author: ChangeAuthor | null;
|
|
263
309
|
time: string;
|
|
264
310
|
};
|
|
265
|
-
export type
|
|
311
|
+
export type Attachment = {
|
|
266
312
|
byteLength: number;
|
|
267
313
|
mediaType: string;
|
|
268
314
|
sha256: string;
|
|
315
|
+
width?: number | null;
|
|
316
|
+
height?: number | null;
|
|
269
317
|
};
|
|
270
318
|
export type BootstrapRequest = {
|
|
271
319
|
locator: string;
|
|
@@ -294,7 +342,7 @@ export type BootstrapPage = {
|
|
|
294
342
|
fileIds?: Readonly<Record<string, string>>;
|
|
295
343
|
created?: Readonly<Record<string, string>>;
|
|
296
344
|
changes: Readonly<Record<string, HeadChange>>;
|
|
297
|
-
|
|
345
|
+
attachments: Readonly<Record<string, Attachment>>;
|
|
298
346
|
folders?: readonly string[];
|
|
299
347
|
pageToken?: PageToken;
|
|
300
348
|
parts?: readonly BootstrapPart[];
|
|
@@ -322,7 +370,7 @@ export type RefreshPage = {
|
|
|
322
370
|
fileIds?: Readonly<Record<string, string>>;
|
|
323
371
|
created?: Readonly<Record<string, string>>;
|
|
324
372
|
changes: Readonly<Record<string, HeadChange>>;
|
|
325
|
-
|
|
373
|
+
attachments: Readonly<Record<string, Attachment>>;
|
|
326
374
|
removals: readonly string[];
|
|
327
375
|
folders?: readonly string[];
|
|
328
376
|
folderRemovals?: readonly string[];
|
|
@@ -354,16 +402,13 @@ export type AcceptedRoom = {
|
|
|
354
402
|
fileIds?: Readonly<Record<string, string>>;
|
|
355
403
|
changes: Readonly<Record<string, HeadChange>>;
|
|
356
404
|
removals: readonly string[];
|
|
357
|
-
|
|
405
|
+
attachments?: Readonly<Record<string, Attachment>>;
|
|
358
406
|
};
|
|
359
407
|
export type MutationResult = (AcceptedRoom & {
|
|
360
408
|
kind: 'accepted';
|
|
361
|
-
author?: string;
|
|
362
|
-
time?: string;
|
|
363
409
|
destination?: AcceptedRoom;
|
|
364
410
|
}) | (ProviderRefusal & {
|
|
365
411
|
kind: 'conflicted';
|
|
366
|
-
roomVersion?: string;
|
|
367
412
|
affected: Readonly<Record<string, string>>;
|
|
368
413
|
}) | (ProviderRefusal & {
|
|
369
414
|
kind: 'rejected';
|
|
@@ -380,7 +425,7 @@ export type HistoryRevision = {
|
|
|
380
425
|
revision: string;
|
|
381
426
|
author: HistoryAuthor;
|
|
382
427
|
time: string;
|
|
383
|
-
|
|
428
|
+
attachment?: Attachment;
|
|
384
429
|
};
|
|
385
430
|
export type HistoryRequest = {
|
|
386
431
|
locator: string;
|
|
@@ -405,11 +450,21 @@ export type BinaryRequest = {
|
|
|
405
450
|
path: string;
|
|
406
451
|
revision: string;
|
|
407
452
|
};
|
|
453
|
+
export type KeyedRequest = {
|
|
454
|
+
kind: 'key';
|
|
455
|
+
link: string;
|
|
456
|
+
};
|
|
457
|
+
export type BinaryCopy = {
|
|
458
|
+
url: string;
|
|
459
|
+
width: number;
|
|
460
|
+
};
|
|
408
461
|
export type BinaryResult = {
|
|
409
462
|
kind: 'binary';
|
|
410
463
|
body: ReadableStream<Uint8Array>;
|
|
411
464
|
mediaType: string;
|
|
412
465
|
sha256?: string;
|
|
466
|
+
url?: string;
|
|
467
|
+
copies?: readonly BinaryCopy[];
|
|
413
468
|
} | (ProviderRefusal & {
|
|
414
469
|
kind: 'rejected';
|
|
415
470
|
}) | AdapterFailure;
|
|
@@ -422,7 +477,7 @@ export type BinaryLinkResult = {
|
|
|
422
477
|
kind: 'rejected';
|
|
423
478
|
}) | AdapterFailure;
|
|
424
479
|
export type AttachRequest = {
|
|
425
|
-
locator
|
|
480
|
+
locator?: string;
|
|
426
481
|
name: string;
|
|
427
482
|
mediaType: string;
|
|
428
483
|
byteLength: number;
|
|
@@ -433,6 +488,9 @@ export type AttachResult = {
|
|
|
433
488
|
kind: 'attached';
|
|
434
489
|
path: string;
|
|
435
490
|
revision: string;
|
|
491
|
+
} | {
|
|
492
|
+
kind: 'linked';
|
|
493
|
+
link: string;
|
|
436
494
|
} | (ProviderRefusal & {
|
|
437
495
|
kind: 'rejected';
|
|
438
496
|
}) | AdapterFailure;
|
|
@@ -468,6 +526,31 @@ export type SearchAnswer = {
|
|
|
468
526
|
} | (ProviderRefusal & {
|
|
469
527
|
kind: 'rejected';
|
|
470
528
|
}) | AdapterFailure;
|
|
529
|
+
export type HouseQueryAsk = {
|
|
530
|
+
room: string;
|
|
531
|
+
fresh: boolean;
|
|
532
|
+
} & ({
|
|
533
|
+
query: Readonly<Record<string, unknown>>;
|
|
534
|
+
} | {
|
|
535
|
+
path: string;
|
|
536
|
+
after?: string;
|
|
537
|
+
});
|
|
538
|
+
export type HouseQueryRows = {
|
|
539
|
+
kind: 'rows';
|
|
540
|
+
documents: readonly QueryDocument[];
|
|
541
|
+
next?: string;
|
|
542
|
+
total?: number;
|
|
543
|
+
totalCapped?: true;
|
|
544
|
+
};
|
|
545
|
+
export type HouseQueryGroups = {
|
|
546
|
+
kind: 'groups';
|
|
547
|
+
groups: readonly QueryGroup[];
|
|
548
|
+
next?: string;
|
|
549
|
+
capped?: true;
|
|
550
|
+
};
|
|
551
|
+
export type HouseQueryAnswer = HouseQueryRows | HouseQueryGroups | (ProviderRefusal & {
|
|
552
|
+
kind: 'rejected';
|
|
553
|
+
}) | AdapterFailure;
|
|
471
554
|
export type HeldRoom = {
|
|
472
555
|
locator: string;
|
|
473
556
|
roomVersion: string | null;
|
|
@@ -484,6 +567,10 @@ export type AuthorityChange = {
|
|
|
484
567
|
rooms: readonly DiscoveredRoom[];
|
|
485
568
|
left: readonly string[];
|
|
486
569
|
member?: Member;
|
|
570
|
+
timeZone?: string | null;
|
|
571
|
+
roomList?: RoomList & {
|
|
572
|
+
readonly left: readonly string[];
|
|
573
|
+
};
|
|
487
574
|
};
|
|
488
575
|
export type RoomStreamEvent = {
|
|
489
576
|
kind: 'opened';
|
|
@@ -498,6 +585,8 @@ export type RoomStreamEvent = {
|
|
|
498
585
|
} | {
|
|
499
586
|
kind: 'caught-up';
|
|
500
587
|
expired: readonly string[];
|
|
588
|
+
} | {
|
|
589
|
+
kind: 'reported';
|
|
501
590
|
} | AuthorityChange | RoomChange;
|
|
502
591
|
export type RoomStream = {
|
|
503
592
|
hold(rooms: readonly HeldRoom[]): void;
|
|
@@ -506,12 +595,12 @@ export type RoomStream = {
|
|
|
506
595
|
export type PathRule = (path: string) => boolean;
|
|
507
596
|
export type Adapter = {
|
|
508
597
|
readonly localSaves?: true;
|
|
509
|
-
readonly roomTypes?:
|
|
510
|
-
readonly nameableRoomTypes?: readonly string[];
|
|
598
|
+
readonly roomTypes?: VerifiedModel;
|
|
511
599
|
readonly typedPaths?: readonly TypedPath[];
|
|
512
600
|
readonly pathRule?: PathRule;
|
|
513
601
|
readonly unkeptReads?: readonly string[];
|
|
514
602
|
readonly leadingReads?: readonly string[];
|
|
603
|
+
readonly renamedActions?: ReadonlyMap<string, string>;
|
|
515
604
|
authorize(): Promise<Authorization>;
|
|
516
605
|
discover?(authorization: Authorization): Promise<DiscoverResult>;
|
|
517
606
|
bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;
|
|
@@ -519,10 +608,11 @@ export type Adapter = {
|
|
|
519
608
|
mutate(authorization: Authorization, request: MutationRequest, keep: (upload: unknown) => Promise<void>): Promise<MutationResult>;
|
|
520
609
|
history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;
|
|
521
610
|
binary(authorization: Authorization, request: BinaryRequest): Promise<BinaryResult>;
|
|
522
|
-
link(authorization: Authorization, request: BinaryRequest): Promise<BinaryLinkResult>;
|
|
611
|
+
link(authorization: Authorization, request: BinaryRequest | KeyedRequest): Promise<BinaryLinkResult>;
|
|
523
612
|
attach(authorization: Authorization, request: AttachRequest): Promise<AttachResult>;
|
|
524
613
|
action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;
|
|
525
614
|
search?(authorization: Authorization, request: SearchAsk): Promise<SearchAnswer>;
|
|
615
|
+
queryHouse?(authorization: Authorization, request: HouseQueryAsk): Promise<HouseQueryAnswer>;
|
|
526
616
|
reached(locator: string, roomVersion: string, target: string): boolean;
|
|
527
617
|
follows(locator: string, roomVersion: string, next: string): boolean;
|
|
528
618
|
roomStream?: RoomStream;
|