@agentshouse/mdruntime 0.1.0-cff1b70c6ad46 → 0.1.0-cffcba9cd9c2f
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/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +48 -124
- package/dist/actions.js +2 -2
- package/dist/adapter.d.ts +16 -44
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -19
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/client.d.ts +3 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -3
- package/dist/collection.d.ts +22 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +12 -2
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +13 -13
- package/dist/conversation-live.d.ts +3 -4
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +2 -3
- package/dist/conversation.d.ts +4 -6
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +43 -71
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +5 -3
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/host.d.ts +17 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +16 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/install.d.ts +0 -1
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +46 -57
- package/dist/job.d.ts +1 -29
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +2 -49
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +9 -6
- package/dist/listing.d.ts +3 -4
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +14 -22
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +3 -1
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +2 -1
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +3 -3
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +8 -6
- package/dist/messages.d.ts +0 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +0 -14
- package/dist/model.d.ts +0 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +101 -126
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +6 -4
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +32 -21
- package/dist/parts.d.ts +3 -52
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +15 -120
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +10 -3
- package/dist/queue.d.ts +32 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +402 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +5 -4
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +4 -1
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +3 -1
- package/dist/replica.d.ts +5 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +12 -14
- package/dist/room-draft.d.ts +3 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +33 -20
- package/dist/room-drafts.js +3 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +3 -4
- package/dist/runtime.d.ts +5 -16
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +5 -10
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +59 -56
- package/dist/saves.d.ts +2 -40
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +23 -349
- package/dist/shown.d.ts +2 -1
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +13 -6
- package/dist/socket/rooms.d.ts +1 -4
- package/dist/socket/rooms.d.ts.map +1 -1
- package/dist/socket.d.ts +0 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/store/records.d.ts +0 -2
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +0 -3
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +1 -1
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +3 -3
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +2 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +18 -20
- package/dist/tables.d.ts +0 -4
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +1 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +2 -2
- package/dist/wire.d.ts +4 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -3
- package/package.json +3 -2
package/dist/messages.js
CHANGED
|
@@ -2,7 +2,6 @@ import { sql } from '@agentshouse/mdmodel';
|
|
|
2
2
|
import { EXCERPT } from './read.js';
|
|
3
3
|
const SAID_BY_HOUSE = `json_extract(message, '$.role') = 'house'`;
|
|
4
4
|
const ANSWERS_THE_TURN = `json_extract(message, '$.role') = 'assistant'`;
|
|
5
|
-
const MARKS_A_JOB = `instr(message, '"marker":"job"') > 0`;
|
|
6
5
|
export const MESSAGE_TABLES = [
|
|
7
6
|
'CREATE TABLE conversation_reads (conversation TEXT PRIMARY KEY, read TEXT, partial INTEGER NOT NULL) WITHOUT ROWID',
|
|
8
7
|
'CREATE TABLE conversation_messages (id INTEGER PRIMARY KEY, conversation TEXT NOT NULL, identity TEXT NOT NULL, turn TEXT NOT NULL, position TEXT NOT NULL, message TEXT NOT NULL, text TEXT NOT NULL)',
|
|
@@ -10,7 +9,6 @@ export const MESSAGE_TABLES = [
|
|
|
10
9
|
'CREATE INDEX conversation_messages_position ON conversation_messages (conversation, position, identity)',
|
|
11
10
|
'CREATE INDEX conversation_messages_turn ON conversation_messages (conversation, turn)',
|
|
12
11
|
`CREATE INDEX conversation_messages_house ON conversation_messages (conversation, position, identity) WHERE ${SAID_BY_HOUSE}`,
|
|
13
|
-
`CREATE INDEX conversation_messages_jobs ON conversation_messages (conversation, position, identity) WHERE ${MARKS_A_JOB}`,
|
|
14
12
|
];
|
|
15
13
|
const NEWEST_FIRST = 'ORDER BY position DESC, identity DESC LIMIT 1';
|
|
16
14
|
const OLDEST_FIRST = 'ORDER BY position, identity LIMIT 1';
|
|
@@ -40,13 +38,6 @@ export const ROWS = `WITH chosen AS (
|
|
|
40
38
|
LEFT JOIN conversation_messages answer ON answer.id = chosen.answer
|
|
41
39
|
LEFT JOIN conversation_messages opened ON opened.id = chosen.opened
|
|
42
40
|
LEFT JOIN conversation_messages asking ON asking.id = chosen.asking`;
|
|
43
|
-
export const JOB_MARKERS = `SELECT json_extract(part.value, '$.text') AS said,
|
|
44
|
-
json_extract(message, '$.accepted_at') AS at
|
|
45
|
-
FROM conversation_messages, json_each(message, '$.parts') AS part
|
|
46
|
-
WHERE conversation = ? AND ${MARKS_A_JOB}
|
|
47
|
-
AND json_extract(part.value, '$.type') = 'marker'
|
|
48
|
-
AND json_extract(part.value, '$.marker') = 'job'
|
|
49
|
-
ORDER BY position, identity, part.key`;
|
|
50
41
|
function text(value) {
|
|
51
42
|
return typeof value === 'string' ? value : String(value);
|
|
52
43
|
}
|
|
@@ -143,11 +134,6 @@ export function conversationRows(connection, conversations) {
|
|
|
143
134
|
},
|
|
144
135
|
}));
|
|
145
136
|
}
|
|
146
|
-
export function jobMarkers(connection, conversation) {
|
|
147
|
-
return connection
|
|
148
|
-
.rows(JOB_MARKERS, [conversation])
|
|
149
|
-
.map((row) => ({ said: text(row.said), at: text(row.at) }));
|
|
150
|
-
}
|
|
151
137
|
export function turnArrived(connection, conversation, turn) {
|
|
152
138
|
return (connection.rows('SELECT 1 FROM conversation_messages WHERE conversation = ? AND turn = ? LIMIT 1', [conversation, turn]).length > 0);
|
|
153
139
|
}
|
package/dist/model.d.ts
CHANGED
|
@@ -50,7 +50,6 @@ export type ValidationReceipt = {
|
|
|
50
50
|
source: Open<'current' | 'cached'>;
|
|
51
51
|
};
|
|
52
52
|
export declare const NO_MODEL: ModelState;
|
|
53
|
-
export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
|
|
54
53
|
export declare function modelTypes(state: ModelState): TypesResult;
|
|
55
54
|
export declare function storedModel(state: ModelState): StoredModel;
|
|
56
55
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAC/F,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,cAAc,GAAG,SAAS,GAAG,cAAc,CAAC,CAAC;AACvF,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAA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,MAAM,WAAW,GACnB;IAAE,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAC5E;IACE,MAAM,EAAE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AACN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC;CACpC,CAAC;AACF,eAAO,MAAM,QAAQ,EAAE,UAA8D,CAAC;AACtF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAczD;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAI1D"}
|
package/dist/model.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
export const NO_MODEL = { status: 'unavailable', reason: 'not-acquired' };
|
|
2
|
-
export function definitionOf(state, type) {
|
|
3
|
-
if (state.status === 'unavailable' || type === undefined)
|
|
4
|
-
return undefined;
|
|
5
|
-
return Object.hasOwn(state.types, type) ? state.types[type] : undefined;
|
|
6
|
-
}
|
|
7
2
|
export function modelTypes(state) {
|
|
8
3
|
return state.status === 'unavailable'
|
|
9
4
|
? { ...state, types: null }
|
package/dist/models.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import type { ScopedRefusal } from './adapter.js';
|
|
1
|
+
import type { RoomDeclaration, ScopedRefusal } from './adapter.js';
|
|
2
2
|
import { type ModelState } from './model.js';
|
|
3
|
-
import { type ReplicaRecord } from './replica.js';
|
|
4
3
|
import type { Runtime } from './runtime.js';
|
|
5
|
-
import type { RoomDeclaration } from './socket.js';
|
|
6
4
|
import type { RuntimeStore } from './store.js';
|
|
7
|
-
export declare function declaredAsHeld(held: ReplicaRecord | undefined, room: RoomDeclaration): boolean;
|
|
8
5
|
export declare function revoked(model: ModelState | undefined): boolean;
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function settleModels(runtime: Runtime, held: readonly RoomDeclaration[], status: 'current' | 'cached', local: RuntimeStore): Promise<void>;
|
|
6
|
+
export declare function retainModel(runtime: Runtime, locator: string, declaration: RoomDeclaration, given: ModelState | null, refused?: true): Promise<void>;
|
|
7
|
+
export declare function scoped(runtime: Runtime, result: ScopedRefusal, locator: string, declaration: RoomDeclaration): Promise<void>;
|
|
8
|
+
export declare function settleModels(runtime: Runtime, held: ReadonlyMap<string, RoomDeclaration>, status: 'current' | 'cached', local: RuntimeStore): Promise<void>;
|
|
13
9
|
export declare function cachedModels(runtime: Runtime, local: RuntimeStore): Promise<void>;
|
|
14
10
|
//# sourceMappingURL=models.d.ts.map
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAOnE,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAGvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAc,YAAY,EAAS,MAAM,YAAY,CAAC;AAMlE,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAE9D;AAqED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,eAAe,EAC5B,KAAK,EAAE,UAAU,GAAG,IAAI,EACxB,OAAO,CAAC,EAAE,IAAI,iBA4Bf;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,eAAe,iBAwB7B;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,EAC1C,MAAM,EAAE,SAAS,GAAG,QAAQ,EAC5B,KAAK,EAAE,YAAY,iBAkDpB;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBvF"}
|
package/dist/models.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
+
import { equalValue } from '@agentshouse/mdmodel';
|
|
1
2
|
import { changeSet } from './change-set.js';
|
|
2
3
|
import { composedOf } from './collection.js';
|
|
4
|
+
import { declared, sameDeclaration } from './declaration.js';
|
|
5
|
+
import { uncaught } from './failure.js';
|
|
3
6
|
import { admitted, declarationOf, list, listedLocators } from './listing.js';
|
|
4
7
|
import { loseRooms } from './lost.js';
|
|
5
8
|
import { NO_MODEL } from './model.js';
|
|
9
|
+
import { settle } from './queue.js';
|
|
6
10
|
import { storedRecord } from './replica.js';
|
|
7
|
-
import { overlayDiff, preparedAfter, replayed, sliceAt } from './saves.js';
|
|
8
11
|
import { emitRooms } from './shown.js';
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
(JSON.stringify(held.operations) === JSON.stringify(room.operations) &&
|
|
12
|
-
JSON.stringify(held.replica) === JSON.stringify(room.replica) &&
|
|
13
|
-
JSON.stringify(held.providerOwnedPaths) === JSON.stringify(room.providerOwnedPaths) &&
|
|
14
|
-
JSON.stringify(held.authoredPaths) === JSON.stringify(room.authoredPaths) &&
|
|
15
|
-
JSON.stringify(held.typedSelection) === JSON.stringify(room.typedSelection ?? null)));
|
|
12
|
+
function declaredAsHeld(held, declaration) {
|
|
13
|
+
return held === undefined || sameDeclaration(held.declaration, declaration);
|
|
16
14
|
}
|
|
17
15
|
export function revoked(model) {
|
|
18
16
|
return model?.status === 'unavailable' && model.reason === 'revoked';
|
|
@@ -20,115 +18,96 @@ export function revoked(model) {
|
|
|
20
18
|
function unheldModelOf({ socket }, locator) {
|
|
21
19
|
return socket.rooms.standing(locator).unheldModel ?? NO_MODEL;
|
|
22
20
|
}
|
|
23
|
-
|
|
21
|
+
async function modelNow(runtime, locator) {
|
|
22
|
+
return (await runtime.store.record(locator))?.model ?? unheldModelOf(runtime, locator);
|
|
23
|
+
}
|
|
24
|
+
function restands(held, model, declaration) {
|
|
25
|
+
return (JSON.stringify(held.model) !== JSON.stringify(model) ||
|
|
26
|
+
!equalValue(held.declaration.typedSelection, declaration.typedSelection));
|
|
27
|
+
}
|
|
28
|
+
function recordAlone(store, record) {
|
|
29
|
+
return {
|
|
30
|
+
locator: record.locator,
|
|
31
|
+
key: record.key,
|
|
32
|
+
record: storedRecord(record),
|
|
33
|
+
composed: composedOf(store.composed(record)),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function listed(runtime, locator, declaration) {
|
|
37
|
+
list(runtime, locator, declaration, admitted(runtime, locator, declaration));
|
|
38
|
+
}
|
|
39
|
+
function unheld(runtime, locator, declaration, model) {
|
|
40
|
+
runtime.socket.rooms.stand(locator, { unheldModel: model });
|
|
41
|
+
listed(runtime, locator, declaration);
|
|
42
|
+
emitRooms(runtime);
|
|
43
|
+
}
|
|
44
|
+
function recorded(runtime, locator, declaration, model) {
|
|
24
45
|
const { store, socket } = runtime;
|
|
25
|
-
|
|
26
|
-
if (held === undefined || (held.name === room.name && held.handle === room.handle))
|
|
27
|
-
return;
|
|
28
|
-
await store.exclusive(async () => {
|
|
46
|
+
return store.exclusive(async () => {
|
|
29
47
|
if (!socket.continuing())
|
|
30
48
|
return;
|
|
31
|
-
const current = await store.record(
|
|
32
|
-
if (current === undefined)
|
|
49
|
+
const current = await store.record(locator);
|
|
50
|
+
if (current === undefined) {
|
|
51
|
+
unheld(runtime, locator, declaration, model);
|
|
33
52
|
return;
|
|
34
|
-
|
|
35
|
-
await
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
});
|
|
45
|
-
emitRooms(runtime);
|
|
53
|
+
}
|
|
54
|
+
const answer = await (await store.open()).commit({ rooms: [recordAlone(store, { ...current, declaration, model })] });
|
|
55
|
+
listed(runtime, locator, declaration);
|
|
56
|
+
void store.changed(changeSet(locator, {
|
|
57
|
+
documents: answer.changed[locator] ?? [],
|
|
58
|
+
room: true,
|
|
59
|
+
unindexed: answer.indexed[locator] === false,
|
|
60
|
+
}));
|
|
46
61
|
});
|
|
47
62
|
}
|
|
48
|
-
async function
|
|
49
|
-
return (await runtime.store.record(locator))?.model ?? unheldModelOf(runtime, locator);
|
|
50
|
-
}
|
|
51
|
-
export async function retainModel(runtime, local, room, given) {
|
|
63
|
+
export async function retainModel(runtime, locator, declaration, given, refused) {
|
|
52
64
|
const { store, socket } = runtime;
|
|
53
|
-
const held = await store.record(
|
|
54
|
-
const previous = held?.model ?? unheldModelOf(runtime,
|
|
65
|
+
const held = await store.record(locator);
|
|
66
|
+
const previous = held?.model ?? unheldModelOf(runtime, locator);
|
|
55
67
|
const next = given ?? previous;
|
|
56
|
-
if (JSON.stringify(previous) === JSON.stringify(next) && declaredAsHeld(held,
|
|
68
|
+
if (JSON.stringify(previous) === JSON.stringify(next) && declaredAsHeld(held, declaration))
|
|
69
|
+
return;
|
|
70
|
+
if (held !== undefined && !restands(held, next, declaration)) {
|
|
71
|
+
await recorded(runtime, locator, declaration, next);
|
|
57
72
|
return;
|
|
58
|
-
|
|
73
|
+
}
|
|
74
|
+
await settle(runtime, [locator], async (works) => {
|
|
59
75
|
if (!socket.continuing())
|
|
60
|
-
return;
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const record = {
|
|
66
|
-
...current.record,
|
|
67
|
-
name: room.name,
|
|
68
|
-
handle: room.handle,
|
|
69
|
-
operations: room.operations,
|
|
70
|
-
replica: room.replica,
|
|
71
|
-
providerOwnedPaths: room.providerOwnedPaths,
|
|
72
|
-
authoredPaths: room.authoredPaths,
|
|
73
|
-
typedSelection: room.typedSelection ?? null,
|
|
74
|
-
model: next,
|
|
75
|
-
};
|
|
76
|
-
const confirmedLayer = await sliceAt(store, record, 'confirmed', current.queue, current.overlaid);
|
|
77
|
-
const replayedLayer = await replayed(store, record, confirmedLayer, current.queue);
|
|
78
|
-
const diff = await overlayDiff(record, current, replayedLayer.visible, replayedLayer.touched);
|
|
79
|
-
const answer = await local.commit({
|
|
80
|
-
rooms: [
|
|
81
|
-
{
|
|
82
|
-
locator: room.locator,
|
|
83
|
-
key: record.key,
|
|
84
|
-
record: storedRecord(record),
|
|
85
|
-
roots: record.typedSelection?.roots ?? [],
|
|
86
|
-
composed: composedOf(store.composed(record)),
|
|
87
|
-
overlay: diff.overlay,
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
});
|
|
91
|
-
preparedAfter(runtime, room.locator, answer);
|
|
92
|
-
changed = changeSet(room.locator, {
|
|
93
|
-
documents: answer.changed[room.locator] ?? [],
|
|
94
|
-
room: true,
|
|
95
|
-
});
|
|
76
|
+
return [];
|
|
77
|
+
const current = works.get(locator)?.replica;
|
|
78
|
+
if (current === undefined) {
|
|
79
|
+
unheld(runtime, locator, declaration, next);
|
|
80
|
+
return [];
|
|
96
81
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
82
|
+
return [
|
|
83
|
+
{
|
|
84
|
+
locator,
|
|
85
|
+
record: { ...current.record, declaration, model: next },
|
|
86
|
+
...(refused === undefined ? {} : { refused }),
|
|
87
|
+
after: () => listed(runtime, locator, declaration),
|
|
88
|
+
},
|
|
89
|
+
];
|
|
104
90
|
});
|
|
105
91
|
}
|
|
106
|
-
export async function scoped(runtime, result,
|
|
92
|
+
export async function scoped(runtime, result, locator, declaration) {
|
|
107
93
|
const { socket, journal } = runtime;
|
|
108
94
|
if (result.scope === 'content' && !result.retryable) {
|
|
109
|
-
journal.record(`scoped refusal ${
|
|
110
|
-
await loseRooms(runtime, [
|
|
95
|
+
journal.record(`scoped refusal ${locator} ${result.scope} ${result.code}`);
|
|
96
|
+
await loseRooms(runtime, [locator]);
|
|
111
97
|
return;
|
|
112
98
|
}
|
|
113
|
-
socket.rooms.stand(
|
|
99
|
+
socket.rooms.stand(locator, {
|
|
114
100
|
refusal: { code: result.code, fields: result.fields, retryable: result.retryable },
|
|
115
101
|
});
|
|
116
|
-
let scopedAway = room;
|
|
117
102
|
if (result.scope === 'model')
|
|
118
|
-
await retainModel(runtime,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
else if (result.scope !== 'operation') {
|
|
123
|
-
socket.rooms.stand(room.locator, { unreadable: true });
|
|
124
|
-
scopedAway = { ...room, replica: { ...room.replica, admission: 'unavailable' } };
|
|
125
|
-
await retainModel(runtime, local, scopedAway, null);
|
|
126
|
-
}
|
|
103
|
+
await retainModel(runtime, locator, declaration, { status: 'unavailable', reason: 'not-readable' }, true);
|
|
104
|
+
else if (result.scope !== 'operation')
|
|
105
|
+
socket.rooms.stand(locator, { unreadable: true });
|
|
127
106
|
if (!socket.continuing())
|
|
128
107
|
return;
|
|
129
|
-
|
|
108
|
+
listed(runtime, locator, declaration);
|
|
130
109
|
emitRooms(runtime);
|
|
131
|
-
journal.record(`scoped refusal ${
|
|
110
|
+
journal.record(`scoped refusal ${locator} ${result.scope} ${result.code}`);
|
|
132
111
|
}
|
|
133
112
|
export async function settleModels(runtime, held, status, local) {
|
|
134
113
|
const { store, socket, journal } = runtime;
|
|
@@ -136,60 +115,56 @@ export async function settleModels(runtime, held, status, local) {
|
|
|
136
115
|
const declaredAnew = await store.exclusive(async () => {
|
|
137
116
|
if (!socket.continuing())
|
|
138
117
|
return [];
|
|
139
|
-
const stored = await store.rooms(held.
|
|
140
|
-
const unchanged = held.filter((
|
|
141
|
-
const record = stored.get(
|
|
142
|
-
return (owed(record?.model ?? unheldModelOf(runtime,
|
|
118
|
+
const stored = await store.rooms([...held.keys()]);
|
|
119
|
+
const unchanged = [...held].filter(([locator, declaration]) => {
|
|
120
|
+
const record = stored.get(locator)?.record;
|
|
121
|
+
return (owed(record?.model ?? unheldModelOf(runtime, locator)) &&
|
|
122
|
+
declaredAsHeld(record, declaration));
|
|
143
123
|
});
|
|
144
|
-
const records = unchanged.flatMap((
|
|
145
|
-
const record = stored.get(
|
|
124
|
+
const records = unchanged.flatMap(([locator]) => {
|
|
125
|
+
const record = stored.get(locator)?.record;
|
|
146
126
|
return record === undefined
|
|
147
127
|
? []
|
|
148
128
|
: [{ ...record, model: { ...record.model, status } }];
|
|
149
129
|
});
|
|
150
130
|
if (records.length > 0) {
|
|
151
131
|
try {
|
|
152
|
-
await local.commit({
|
|
153
|
-
rooms: records.map((record) => ({
|
|
154
|
-
locator: record.locator,
|
|
155
|
-
key: record.key,
|
|
156
|
-
record: storedRecord(record),
|
|
157
|
-
composed: composedOf(store.composed(record)),
|
|
158
|
-
})),
|
|
159
|
-
});
|
|
132
|
+
await local.commit({ rooms: records.map((record) => recordAlone(store, record)) });
|
|
160
133
|
}
|
|
161
|
-
catch {
|
|
134
|
+
catch (error) {
|
|
162
135
|
journal.record(`model ${status} persistence failed`);
|
|
136
|
+
uncaught(error);
|
|
163
137
|
}
|
|
164
138
|
}
|
|
165
|
-
for (const
|
|
166
|
-
const { unheldModel } = socket.rooms.standing(
|
|
167
|
-
if (!stored.has(
|
|
168
|
-
socket.rooms.stand(
|
|
139
|
+
for (const [locator, declaration] of unchanged) {
|
|
140
|
+
const { unheldModel } = socket.rooms.standing(locator);
|
|
141
|
+
if (!stored.has(locator) && unheldModel !== null) {
|
|
142
|
+
socket.rooms.stand(locator, {
|
|
169
143
|
unheldModel: { ...unheldModel, status },
|
|
170
144
|
});
|
|
171
145
|
}
|
|
172
|
-
|
|
146
|
+
listed(runtime, locator, declaration);
|
|
173
147
|
}
|
|
174
148
|
if (unchanged.length > 0)
|
|
175
149
|
emitRooms(runtime);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
150
|
+
const kept = new Set(unchanged.map(([locator]) => locator));
|
|
151
|
+
return [...held].filter(([locator]) => !kept.has(locator) &&
|
|
152
|
+
owed(stored.get(locator)?.record.model ?? unheldModelOf(runtime, locator)));
|
|
180
153
|
});
|
|
181
|
-
for (const
|
|
182
|
-
const model = await modelNow(runtime,
|
|
154
|
+
for (const [locator, declaration] of declaredAnew) {
|
|
155
|
+
const model = await modelNow(runtime, locator);
|
|
183
156
|
if (owed(model))
|
|
184
|
-
await retainModel(runtime,
|
|
157
|
+
await retainModel(runtime, locator, declaration, { ...model, status });
|
|
185
158
|
}
|
|
186
159
|
}
|
|
187
160
|
export async function cachedModels(runtime, local) {
|
|
188
161
|
const { store, socket } = runtime;
|
|
189
162
|
const held = await store.rooms();
|
|
190
|
-
await settleModels(runtime, listedLocators(runtime, held).flatMap((locator) => {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
163
|
+
await settleModels(runtime, new Map(listedLocators(runtime, held).flatMap((locator) => {
|
|
164
|
+
const discovered = socket.rooms.discovered(locator);
|
|
165
|
+
const declaration = discovered === undefined
|
|
166
|
+
? declarationOf(runtime, locator, held.get(locator))?.room
|
|
167
|
+
: declared(discovered);
|
|
168
|
+
return declaration === undefined ? [] : [[locator, declaration]];
|
|
169
|
+
})), 'cached', local);
|
|
195
170
|
}
|
package/dist/opening.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["../src/opening.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["../src/opening.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAsB,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CA2CxF"}
|
package/dist/opening.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { conversationsOpened } from './conversation.js';
|
|
2
2
|
import { detectStorageLoss, nextGeneration, refusedForSpace } from './durability.js';
|
|
3
|
+
import { uncaught } from './failure.js';
|
|
3
4
|
import { sweep } from './install.js';
|
|
4
5
|
import { eraseFenced } from './lost.js';
|
|
5
6
|
import { prepare } from './preparation.js';
|
|
7
|
+
import { unpair } from './queue.js';
|
|
6
8
|
import { emitRooms, emitStorageLoss, statusShown } from './shown.js';
|
|
7
9
|
export async function open(runtime, opened) {
|
|
8
10
|
const { store, socket, journal, shell, conversations, build, usableWhenHeld } = runtime;
|
|
@@ -40,18 +42,18 @@ export async function open(runtime, opened) {
|
|
|
40
42
|
await conversationsOpened(conversations, opened);
|
|
41
43
|
if (interrupted.length > 0) {
|
|
42
44
|
queueMicrotask(() => {
|
|
43
|
-
void eraseFenced(runtime, interrupted).catch(() => {
|
|
45
|
+
void eraseFenced(runtime, interrupted).catch((error) => {
|
|
44
46
|
journal.record('erasure failed');
|
|
47
|
+
uncaught(error);
|
|
45
48
|
});
|
|
46
49
|
});
|
|
47
50
|
}
|
|
48
51
|
statusShown(runtime);
|
|
49
52
|
prepare(runtime);
|
|
50
53
|
emitRooms(runtime);
|
|
51
|
-
void
|
|
52
|
-
.exclusive(() => runtime.unpair(opened))
|
|
53
|
-
.catch(() => {
|
|
54
|
+
void unpair(runtime).catch((error) => {
|
|
54
55
|
journal.record('unpair failed');
|
|
56
|
+
uncaught(error);
|
|
55
57
|
});
|
|
56
58
|
return opened;
|
|
57
59
|
}
|
package/dist/overlay.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BinaryFile, HeadChange } from './adapter.js';
|
|
2
|
+
import { type Composition } from './collection.js';
|
|
2
3
|
import type { ChangeBatch } from './change.js';
|
|
3
4
|
export type Heads = {
|
|
4
5
|
revisions: Readonly<Record<string, string>>;
|
|
@@ -22,5 +23,5 @@ export type Layer = Heads & {
|
|
|
22
23
|
export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Generator<readonly [string, HeldBinary]>;
|
|
23
24
|
export declare function sameBinary(left: HeldBinary | undefined, right: HeldBinary | undefined): boolean;
|
|
24
25
|
export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
|
|
25
|
-
export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], unapplied?: () => void): Generator<number, Layer, void>;
|
|
26
|
+
export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], composition: Composition, unapplied?: () => void): Generator<number, Layer, void>;
|
|
26
27
|
//# sourceMappingURL=overlay.d.ts.map
|
package/dist/overlay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../src/overlay.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAU,WAAW,EAAgB,MAAM,aAAa,C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AAI,EAAE,UAAU,GAAG,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAQ/F;AA+ND,wBAAiB,UAAU,CACzB,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,WAAW,EAAE,WAAW,EACxB,SAAS,CAAC,EAAE,MAAM,IAAI,GACrB,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAsChC"}
|
package/dist/overlay.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { apply, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, create, frontmatterValue, parse, serialize, TYPE_FIELD, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { definitionsAt } from './collection.js';
|
|
2
3
|
import { drafted, entriesIn, settling } from './shared.js';
|
|
3
4
|
import { ROW_WEIGHT } from './turn.js';
|
|
4
5
|
export function* acceptedBinaries(files) {
|
|
@@ -24,7 +25,6 @@ export function sameChange(left, right) {
|
|
|
24
25
|
left.author?.id === right.author?.id &&
|
|
25
26
|
left.author?.name === right.author?.name);
|
|
26
27
|
}
|
|
27
|
-
const EMPTY_FRONTMATTER = '---\n---\n';
|
|
28
28
|
function isPart(change) {
|
|
29
29
|
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
30
30
|
}
|
|
@@ -53,16 +53,23 @@ function* priorsOf(preconditions) {
|
|
|
53
53
|
preamble: (path) => preambles.get(path) ?? '',
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
function compose(fields, sections) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
function compose(path, fields, sections, composition) {
|
|
57
|
+
const declared = fields[TYPE_FIELD];
|
|
58
|
+
const type = typeof declared === 'string' && declared !== '' ? declared : undefined;
|
|
59
|
+
const definition = definitionsAt(composition, path)(type);
|
|
60
|
+
const created = create(type, definition);
|
|
61
|
+
const next = apply(created, [
|
|
62
|
+
...Object.entries(fields).flatMap(([name, value]) => (name !== TYPE_FIELD || type === undefined) && frontmatterValue(value)
|
|
63
|
+
? [{ kind: 'field', name, value, prior: undefined }]
|
|
64
|
+
: []),
|
|
65
|
+
...Object.entries(sections).map(([name, value]) => ({
|
|
66
|
+
kind: 'section',
|
|
67
|
+
name,
|
|
68
|
+
value,
|
|
69
|
+
prior: undefined,
|
|
70
|
+
})),
|
|
71
|
+
], definition);
|
|
72
|
+
return serialize(next.outcome === 'applied' ? next.document : created);
|
|
66
73
|
}
|
|
67
74
|
function edited(change, priors) {
|
|
68
75
|
if (change.kind === 'field')
|
|
@@ -81,17 +88,19 @@ function edited(change, priors) {
|
|
|
81
88
|
prior: priors.section(change.path, change.name),
|
|
82
89
|
};
|
|
83
90
|
}
|
|
84
|
-
function edit(staged, changes, priors) {
|
|
91
|
+
function edit(staged, changes, priors, composition) {
|
|
85
92
|
const path = changes[0].path;
|
|
86
93
|
delete staged.revisions[path];
|
|
87
94
|
const text = staged.documents[path];
|
|
88
95
|
if (text === undefined)
|
|
89
96
|
return changes.length;
|
|
90
|
-
const
|
|
97
|
+
const definitions = definitionsAt(composition, path);
|
|
98
|
+
const parsed = parse(text, path, definitions);
|
|
91
99
|
if (!parsed.ok)
|
|
92
100
|
return changes.length;
|
|
101
|
+
const definition = definitions(parsed.document.type);
|
|
93
102
|
const wanted = changes.map((change) => edited(change, priors));
|
|
94
|
-
const first = apply(parsed.document, wanted);
|
|
103
|
+
const first = apply(parsed.document, wanted, definition);
|
|
95
104
|
if (first.outcome === 'refuse')
|
|
96
105
|
return changes.length;
|
|
97
106
|
if (first.outcome === 'applied') {
|
|
@@ -100,7 +109,7 @@ function edit(staged, changes, priors) {
|
|
|
100
109
|
}
|
|
101
110
|
const stale = new Set(first.stale);
|
|
102
111
|
const kept = wanted.filter((_, at) => !stale.has(at));
|
|
103
|
-
const rest = apply(parsed.document, kept);
|
|
112
|
+
const rest = apply(parsed.document, kept, definition);
|
|
104
113
|
if (rest.outcome !== 'applied')
|
|
105
114
|
return changes.length;
|
|
106
115
|
staged.documents[path] = serialize(rest.document);
|
|
@@ -151,10 +160,12 @@ function erase(staged, path) {
|
|
|
151
160
|
delete staged.changes[path];
|
|
152
161
|
delete staged.binaries[path];
|
|
153
162
|
}
|
|
154
|
-
function stage(staged, change) {
|
|
163
|
+
function stage(staged, change, composition) {
|
|
155
164
|
if (change.kind === 'create') {
|
|
156
165
|
staged.documents[change.path] =
|
|
157
|
-
'content' in change
|
|
166
|
+
'content' in change
|
|
167
|
+
? change.content
|
|
168
|
+
: compose(change.path, change.fields, change.sections, composition);
|
|
158
169
|
delete staged.fileIds[change.path];
|
|
159
170
|
delete staged.created[change.path];
|
|
160
171
|
delete staged.changes[change.path];
|
|
@@ -206,7 +217,7 @@ function arrive(heads, change) {
|
|
|
206
217
|
if (change.change !== undefined)
|
|
207
218
|
heads.changes[change.path] = change.change;
|
|
208
219
|
}
|
|
209
|
-
export function* overlaying(base, queue, unapplied) {
|
|
220
|
+
export function* overlaying(base, queue, composition, unapplied) {
|
|
210
221
|
const staged = {
|
|
211
222
|
documents: drafted(base.documents),
|
|
212
223
|
binaries: drafted(base.binaries),
|
|
@@ -220,7 +231,7 @@ export function* overlaying(base, queue, unapplied) {
|
|
|
220
231
|
for (let index = 0; index < batch.changes.length; index += 1) {
|
|
221
232
|
const change = batch.changes[index];
|
|
222
233
|
if (!isPart(change)) {
|
|
223
|
-
if (!stage(staged, change))
|
|
234
|
+
if (!stage(staged, change, composition))
|
|
224
235
|
unapplied?.();
|
|
225
236
|
yield ROW_WEIGHT;
|
|
226
237
|
continue;
|
|
@@ -234,7 +245,7 @@ export function* overlaying(base, queue, unapplied) {
|
|
|
234
245
|
index += 1;
|
|
235
246
|
}
|
|
236
247
|
const text = staged.documents[change.path] ?? '';
|
|
237
|
-
for (let left = edit(staged, run, priors); left > 0; left -= 1)
|
|
248
|
+
for (let left = edit(staged, run, priors, composition); left > 0; left -= 1)
|
|
238
249
|
unapplied?.();
|
|
239
250
|
yield ROW_WEIGHT + text.length;
|
|
240
251
|
}
|
package/dist/parts.d.ts
CHANGED
|
@@ -1,49 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type JobMarker, type OpenJob } from './job.js';
|
|
3
|
-
export type PlanStep = {
|
|
4
|
-
readonly content: string;
|
|
5
|
-
readonly status: string;
|
|
6
|
-
};
|
|
7
|
-
export type Marker = 'mode' | 'compaction' | 'retry' | 'model' | 'job';
|
|
8
|
-
export type Part = {
|
|
9
|
-
readonly type: 'text';
|
|
10
|
-
readonly text: string;
|
|
11
|
-
} | {
|
|
12
|
-
readonly type: 'reasoning';
|
|
13
|
-
readonly text: string;
|
|
14
|
-
} | {
|
|
15
|
-
readonly type: 'commands';
|
|
16
|
-
readonly count: number;
|
|
17
|
-
} | {
|
|
18
|
-
readonly type: 'subagent';
|
|
19
|
-
readonly description: string;
|
|
20
|
-
readonly done: boolean;
|
|
21
|
-
readonly result: string | null;
|
|
22
|
-
} | {
|
|
23
|
-
readonly type: 'message';
|
|
24
|
-
readonly command: string;
|
|
25
|
-
readonly target: string | null;
|
|
26
|
-
} | {
|
|
27
|
-
readonly type: 'image';
|
|
28
|
-
readonly path: string;
|
|
29
|
-
readonly name: string;
|
|
30
|
-
readonly mediaType: string;
|
|
31
|
-
} | {
|
|
32
|
-
readonly type: 'marker';
|
|
33
|
-
readonly marker: Marker;
|
|
34
|
-
readonly text: string;
|
|
35
|
-
} | {
|
|
36
|
-
readonly type: 'plan';
|
|
37
|
-
readonly steps: readonly PlanStep[];
|
|
38
|
-
};
|
|
39
|
-
export declare function partsOf(raw: readonly unknown[]): readonly Part[];
|
|
40
|
-
export declare function contextIn(raw: unknown): TurnContext | null;
|
|
41
|
-
export declare function tokensIn(raw: unknown): number | null;
|
|
42
|
-
export type Turn = {
|
|
43
|
-
readonly turn: string;
|
|
44
|
-
readonly parts: readonly Part[];
|
|
45
|
-
readonly ended: boolean;
|
|
46
|
-
};
|
|
1
|
+
import { type Part, type SessionState } from '@agentshouse/session-content';
|
|
47
2
|
export type ChatWork = {
|
|
48
3
|
readonly kind: 'job' | 'schedule' | 'subagent';
|
|
49
4
|
readonly title: string;
|
|
@@ -51,10 +6,6 @@ export type ChatWork = {
|
|
|
51
6
|
readonly activity: string | null;
|
|
52
7
|
};
|
|
53
8
|
export declare function counted(count: number): string;
|
|
54
|
-
export declare function runningLine(
|
|
55
|
-
export declare function
|
|
56
|
-
readonly started: string | null;
|
|
57
|
-
readonly parts: readonly unknown[];
|
|
58
|
-
} | null): readonly OpenJob[];
|
|
59
|
-
export declare function stillRunning(turns: readonly Turn[], subagents: readonly RunningSubagent[]): ReadonlyMap<string, readonly ChatWork[]>;
|
|
9
|
+
export declare function runningLine(parts: readonly Part[]): string | null;
|
|
10
|
+
export declare function workOf(state: SessionState | null): readonly ChatWork[];
|
|
60
11
|
//# sourceMappingURL=parts.d.ts.map
|