@maiaos/client-core 0.1.0-canary.31 → 0.1.0-canary.33
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.
|
@@ -43,6 +43,8 @@ export type SessionViewState = {
|
|
|
43
43
|
readonly observedAt?: number;
|
|
44
44
|
/** An interrupt prepared for confirmation, bound to one turn revision. */
|
|
45
45
|
readonly pendingInterrupt?: TurnInterruptParameters;
|
|
46
|
+
/** The oldest cursor the Node still holds, when it pruned earlier history. */
|
|
47
|
+
readonly prunedBefore?: string;
|
|
46
48
|
readonly session?: Session;
|
|
47
49
|
readonly source: TimelineSource["kind"];
|
|
48
50
|
readonly turns: readonly TimelineTurn[];
|
|
@@ -38,14 +38,17 @@ const readDiff = (context, session) => session.worktree === undefined
|
|
|
38
38
|
}),
|
|
39
39
|
onSuccess: (diff) => ({ diffError: _error, ...state }) => ({ ...state, diff }),
|
|
40
40
|
}), Effect.flatMap((change) => SubscriptionRef.update(context.ref, change)));
|
|
41
|
+
/** A fresh read replaces the turns and the pruned marker, and clears an error. */
|
|
42
|
+
const withTimeline = (session, { prunedBefore, turns }) => ({ error: _error, prunedBefore: _pruned, ...state }) => ({
|
|
43
|
+
...state,
|
|
44
|
+
...(prunedBefore === undefined ? {} : { prunedBefore }),
|
|
45
|
+
session,
|
|
46
|
+
turns,
|
|
47
|
+
});
|
|
41
48
|
const refresh = (context) => Effect.gen(function* () {
|
|
42
49
|
const shown = yield* read("session.show", (options) => context.client.showSession({ sessionId: context.sessionId }, options));
|
|
43
|
-
const
|
|
44
|
-
yield* SubscriptionRef.update(context.ref, (
|
|
45
|
-
...state,
|
|
46
|
-
session: shown.session,
|
|
47
|
-
turns,
|
|
48
|
-
}));
|
|
50
|
+
const loaded = yield* context.timeline.load(context.sessionId);
|
|
51
|
+
yield* SubscriptionRef.update(context.ref, withTimeline(shown.session, loaded));
|
|
49
52
|
yield* observed(context);
|
|
50
53
|
yield* Effect.all([
|
|
51
54
|
readDiff(context, shown.session),
|
|
@@ -20,7 +20,16 @@ export type TimelineTurn = {
|
|
|
20
20
|
*/
|
|
21
21
|
export type TimelineSource = {
|
|
22
22
|
readonly kind: "final-text";
|
|
23
|
-
readonly load: (sessionId: string) => Effect.Effect<
|
|
23
|
+
readonly load: (sessionId: string) => Effect.Effect<TimelineLoad, CockpitError>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The recent turns and, when the Node pruned older events, the oldest cursor
|
|
27
|
+
* it still holds. The detail has no older-page load, so the read from cursor 0
|
|
28
|
+
* is the one place a hole can show.
|
|
29
|
+
*/
|
|
30
|
+
export type TimelineLoad = {
|
|
31
|
+
readonly prunedBefore?: string;
|
|
32
|
+
readonly turns: readonly TimelineTurn[];
|
|
24
33
|
};
|
|
25
34
|
/** The most recent turns a detail shows; older ones stay on the Node. */
|
|
26
35
|
export declare const MAX_TIMELINE_TURNS = 20;
|
|
@@ -25,9 +25,11 @@ const recentEvents = (client, sessionId) => Effect.gen(function* () {
|
|
|
25
25
|
const collect = (after, seen) => Effect.flatMap(eventPage(client, sessionId, after), (page) => page.next === undefined || page.items.length === 0
|
|
26
26
|
? Effect.succeed([...seen, ...page.items])
|
|
27
27
|
: collect(page.next, [...seen, ...page.items]));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const events = from <= 0n ? yield* collect("0", []) : yield* collect(String(from), []);
|
|
29
|
+
return {
|
|
30
|
+
events,
|
|
31
|
+
...(probe.oldest === undefined ? {} : { oldest: probe.oldest }),
|
|
32
|
+
};
|
|
31
33
|
});
|
|
32
34
|
const toTimeline = (turn) => ({
|
|
33
35
|
...("failureReason" in turn ? { failureReason: turn.failureReason } : {}),
|
|
@@ -41,6 +43,9 @@ const toTimeline = (turn) => ({
|
|
|
41
43
|
/** The final-text source over `session.events.list` and `turn.show`. */
|
|
42
44
|
export const finalTextTimeline = (client) => ({
|
|
43
45
|
kind: "final-text",
|
|
44
|
-
load: (sessionId) => recentEvents(client, sessionId).pipe(Effect.
|
|
46
|
+
load: (sessionId) => recentEvents(client, sessionId).pipe(Effect.flatMap(({ events, oldest }) => Effect.forEach([...new Set(events.flatMap((event) => turnIdOf(event) ?? []))].slice(-MAX_TIMELINE_TURNS), (turnId) => read("turn.show", (options) => client.showTurn({ turnId }, options)).pipe(Effect.map((result) => toTimeline(result.turn))), { concurrency: 4 }).pipe(Effect.map((turns) => ({
|
|
47
|
+
...(oldest === undefined ? {} : { prunedBefore: oldest }),
|
|
48
|
+
turns,
|
|
49
|
+
}))))),
|
|
45
50
|
});
|
|
46
51
|
//# sourceMappingURL=timeline.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiaos/client-core",
|
|
3
|
-
"version": "0.1.0-canary.
|
|
3
|
+
"version": "0.1.0-canary.33",
|
|
4
4
|
"description": "Platform-neutral client use cases for Maia OS: Effect services between a client's renderer and the SDK, so every client reads Maia Node state and sends requests the same way.",
|
|
5
5
|
"homepage": "https://github.com/vllnt/maia/tree/main/packages/client-core#readme",
|
|
6
6
|
"bugs": "https://github.com/vllnt/maia/issues",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"node": "24.22.1"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@maiaos/sdk": "0.1.0-canary.
|
|
97
|
+
"@maiaos/sdk": "0.1.0-canary.33",
|
|
98
98
|
"effect": "4.0.0"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|