@maiaos/client-core 0.1.0-canary.7 → 0.1.0-canary.71
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/LICENSE +21 -0
- package/README.md +26 -23
- package/dist/cockpit/creation.d.ts +6 -2
- package/dist/cockpit/creation.js +11 -3
- package/dist/cockpit/index.d.ts +1 -1
- package/dist/cockpit/index.js +1 -1
- package/dist/cockpit/launcher.js +2 -8
- package/dist/cockpit/onboarding.js +10 -8
- package/dist/cockpit/routing.d.ts +1 -1
- package/dist/cockpit/routing.js +1 -0
- package/dist/interaction/recovery.d.ts +2 -0
- package/dist/portfolio/portfolio.d.ts +76 -2
- package/dist/presentation/collection-view.d.ts +14 -1
- package/dist/presentation/collection-view.js +67 -22
- package/dist/presentation/index.d.ts +1 -0
- package/dist/presentation/index.js +1 -0
- package/dist/presentation/live.d.ts +35 -2
- package/dist/presentation/session-view.d.ts +35 -2
- package/dist/records/agents.d.ts +36 -0
- package/dist/records/agents.js +20 -0
- package/dist/records/held.d.ts +82 -0
- package/dist/records/held.js +95 -0
- package/dist/records/index.d.ts +15 -0
- package/dist/records/index.js +7 -0
- package/dist/records/interactions.d.ts +62 -0
- package/dist/records/interactions.js +33 -0
- package/dist/records/kind.d.ts +44 -0
- package/dist/records/kind.js +36 -0
- package/dist/records/records.d.ts +41 -0
- package/dist/records/records.js +103 -0
- package/dist/records/routines.d.ts +28 -0
- package/dist/records/routines.js +35 -0
- package/dist/records/service.d.ts +42 -0
- package/dist/records/service.js +46 -0
- package/dist/records/state.d.ts +34 -0
- package/dist/records/state.js +26 -0
- package/dist/records/surface.d.ts +19 -0
- package/dist/records/surface.js +23 -0
- package/dist/records/watch.d.ts +24 -0
- package/dist/records/watch.js +68 -0
- package/dist/session-view/conversation.js +2 -5
- package/dist/session-view/session-view.d.ts +2 -0
- package/dist/session-view/session-view.js +9 -6
- package/dist/session-view/timeline.d.ts +10 -1
- package/dist/session-view/timeline.js +12 -4
- package/package.json +23 -3
|
@@ -61,7 +61,7 @@ export declare const watchSessionList: (view: import("./collection-view.js").Col
|
|
|
61
61
|
readonly rssBytes?: number | undefined;
|
|
62
62
|
readonly wallTimeMilliseconds?: number | undefined;
|
|
63
63
|
} | undefined;
|
|
64
|
-
readonly runtime:
|
|
64
|
+
readonly runtime: string;
|
|
65
65
|
readonly runtimeThreadId: string;
|
|
66
66
|
readonly startedAt: string;
|
|
67
67
|
readonly turn?: {
|
|
@@ -91,22 +91,55 @@ export declare const watchSessionList: (view: import("./collection-view.js").Col
|
|
|
91
91
|
readonly updatedAt: string;
|
|
92
92
|
readonly workspaceId: string;
|
|
93
93
|
readonly workspaceRevision: string;
|
|
94
|
+
readonly activity?: "idle" | "stopped" | "waiting_approval" | "working" | undefined;
|
|
94
95
|
readonly agentDefinitionRef?: {
|
|
95
96
|
readonly contentDigest: string;
|
|
96
97
|
readonly key: string;
|
|
97
98
|
readonly version: string;
|
|
98
99
|
} | undefined;
|
|
100
|
+
readonly containment?: "none" | undefined;
|
|
99
101
|
readonly executor?: {
|
|
100
102
|
readonly connectionId: string;
|
|
101
103
|
readonly effort?: "high" | "low" | "max" | "medium" | "ultra" | "xhigh" | undefined;
|
|
102
|
-
readonly kind:
|
|
104
|
+
readonly kind: string;
|
|
103
105
|
readonly model?: string | undefined;
|
|
104
106
|
} | undefined;
|
|
105
107
|
readonly failure?: {
|
|
106
108
|
readonly code: string;
|
|
107
109
|
readonly message: string;
|
|
108
110
|
} | undefined;
|
|
111
|
+
readonly heldTaskCount?: number | undefined;
|
|
112
|
+
readonly heldTasks?: readonly {
|
|
113
|
+
readonly claimedAt: string;
|
|
114
|
+
readonly id: string;
|
|
115
|
+
readonly leaseExpiresAt: string;
|
|
116
|
+
readonly state: "claimed";
|
|
117
|
+
readonly title: string;
|
|
118
|
+
}[] | undefined;
|
|
119
|
+
readonly labels?: {
|
|
120
|
+
readonly [x: string]: string;
|
|
121
|
+
} | undefined;
|
|
122
|
+
readonly latestTurnId?: string | undefined;
|
|
123
|
+
readonly latestTurnState?: "completed" | "dispatching" | "failed" | "interrupted" | "outcome-unknown" | "queued" | "running" | undefined;
|
|
124
|
+
readonly parentSessionId?: string | undefined;
|
|
125
|
+
readonly permission?: "acceptEdits" | "bypassPermissions" | "default" | "dontAsk" | "never" | "on-request" | "plan" | "untrusted" | undefined;
|
|
126
|
+
readonly prompt?: {
|
|
127
|
+
readonly approvalId: string;
|
|
128
|
+
readonly expiresAt: string;
|
|
129
|
+
readonly kind: "command" | "file_change" | "question" | "tool";
|
|
130
|
+
readonly options?: readonly {
|
|
131
|
+
readonly label: string;
|
|
132
|
+
readonly optionId: string;
|
|
133
|
+
}[] | undefined;
|
|
134
|
+
readonly summary?: string | undefined;
|
|
135
|
+
} | undefined;
|
|
136
|
+
readonly recovery?: {
|
|
137
|
+
readonly code: string;
|
|
138
|
+
readonly message: string;
|
|
139
|
+
} | undefined;
|
|
109
140
|
readonly schemaVersion: 4;
|
|
141
|
+
readonly settledReason?: "failed" | "idle" | "stopped" | undefined;
|
|
142
|
+
readonly status?: "approval" | "compacting" | "done" | "ended" | "error" | "idle" | "question" | "rate_limited" | "starting" | "unknown" | "working" | undefined;
|
|
110
143
|
readonly title?: string | undefined;
|
|
111
144
|
readonly worktree?: {
|
|
112
145
|
readonly baseRef: string;
|
|
@@ -45,7 +45,7 @@ export declare const makeSessionListView: (target: PortfolioProject, emit: (stat
|
|
|
45
45
|
readonly rssBytes?: number | undefined;
|
|
46
46
|
readonly wallTimeMilliseconds?: number | undefined;
|
|
47
47
|
} | undefined;
|
|
48
|
-
readonly runtime:
|
|
48
|
+
readonly runtime: string;
|
|
49
49
|
readonly runtimeThreadId: string;
|
|
50
50
|
readonly startedAt: string;
|
|
51
51
|
readonly turn?: {
|
|
@@ -75,22 +75,55 @@ export declare const makeSessionListView: (target: PortfolioProject, emit: (stat
|
|
|
75
75
|
readonly updatedAt: string;
|
|
76
76
|
readonly workspaceId: string;
|
|
77
77
|
readonly workspaceRevision: string;
|
|
78
|
+
readonly activity?: "idle" | "stopped" | "waiting_approval" | "working" | undefined;
|
|
78
79
|
readonly agentDefinitionRef?: {
|
|
79
80
|
readonly contentDigest: string;
|
|
80
81
|
readonly key: string;
|
|
81
82
|
readonly version: string;
|
|
82
83
|
} | undefined;
|
|
84
|
+
readonly containment?: "none" | undefined;
|
|
83
85
|
readonly executor?: {
|
|
84
86
|
readonly connectionId: string;
|
|
85
87
|
readonly effort?: "high" | "low" | "max" | "medium" | "ultra" | "xhigh" | undefined;
|
|
86
|
-
readonly kind:
|
|
88
|
+
readonly kind: string;
|
|
87
89
|
readonly model?: string | undefined;
|
|
88
90
|
} | undefined;
|
|
89
91
|
readonly failure?: {
|
|
90
92
|
readonly code: string;
|
|
91
93
|
readonly message: string;
|
|
92
94
|
} | undefined;
|
|
95
|
+
readonly heldTaskCount?: number | undefined;
|
|
96
|
+
readonly heldTasks?: readonly {
|
|
97
|
+
readonly claimedAt: string;
|
|
98
|
+
readonly id: string;
|
|
99
|
+
readonly leaseExpiresAt: string;
|
|
100
|
+
readonly state: "claimed";
|
|
101
|
+
readonly title: string;
|
|
102
|
+
}[] | undefined;
|
|
103
|
+
readonly labels?: {
|
|
104
|
+
readonly [x: string]: string;
|
|
105
|
+
} | undefined;
|
|
106
|
+
readonly latestTurnId?: string | undefined;
|
|
107
|
+
readonly latestTurnState?: "completed" | "dispatching" | "failed" | "interrupted" | "outcome-unknown" | "queued" | "running" | undefined;
|
|
108
|
+
readonly parentSessionId?: string | undefined;
|
|
109
|
+
readonly permission?: "acceptEdits" | "bypassPermissions" | "default" | "dontAsk" | "never" | "on-request" | "plan" | "untrusted" | undefined;
|
|
110
|
+
readonly prompt?: {
|
|
111
|
+
readonly approvalId: string;
|
|
112
|
+
readonly expiresAt: string;
|
|
113
|
+
readonly kind: "command" | "file_change" | "question" | "tool";
|
|
114
|
+
readonly options?: readonly {
|
|
115
|
+
readonly label: string;
|
|
116
|
+
readonly optionId: string;
|
|
117
|
+
}[] | undefined;
|
|
118
|
+
readonly summary?: string | undefined;
|
|
119
|
+
} | undefined;
|
|
120
|
+
readonly recovery?: {
|
|
121
|
+
readonly code: string;
|
|
122
|
+
readonly message: string;
|
|
123
|
+
} | undefined;
|
|
93
124
|
readonly schemaVersion: 4;
|
|
125
|
+
readonly settledReason?: "failed" | "idle" | "stopped" | undefined;
|
|
126
|
+
readonly status?: "approval" | "compacting" | "done" | "ended" | "error" | "idle" | "question" | "rate_limited" | "starting" | "unknown" | "working" | undefined;
|
|
94
127
|
readonly title?: string | undefined;
|
|
95
128
|
readonly worktree?: {
|
|
96
129
|
readonly baseRef: string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type AgentRecord } from "@maiaos/sdk";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import type { RecordsState } from "./state.js";
|
|
4
|
+
/** The Project whose Agents a view holds. */
|
|
5
|
+
export type AgentsScope = {
|
|
6
|
+
readonly projectId: string;
|
|
7
|
+
};
|
|
8
|
+
/** The state of an Agents view. */
|
|
9
|
+
export type AgentsState = RecordsState<AgentRecord>;
|
|
10
|
+
/**
|
|
11
|
+
* The Agents of one Project, live: `agents.list` fills the snapshot and
|
|
12
|
+
* `agents.show` reads each Agent a committed change names.
|
|
13
|
+
*/
|
|
14
|
+
export declare const makeAgentsView: (scope: AgentsScope, emit: (state: AgentsState) => void) => Effect.Effect<import("./records.js").RecordsView<{
|
|
15
|
+
readonly contentDigest: string;
|
|
16
|
+
readonly createdAt: string;
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly projectId: string;
|
|
19
|
+
readonly revision: string;
|
|
20
|
+
readonly schemaVersion: "maia.agent/v1";
|
|
21
|
+
readonly spec: {
|
|
22
|
+
readonly accountableActorId: string;
|
|
23
|
+
readonly connectionId?: string | undefined;
|
|
24
|
+
readonly effort?: "high" | "low" | "max" | "medium" | "ultra" | "xhigh" | undefined;
|
|
25
|
+
readonly harness: "claude-code" | "codex-cli" | "maia-agent" | "pi";
|
|
26
|
+
readonly homeSessionId?: string | undefined;
|
|
27
|
+
readonly instruction: string;
|
|
28
|
+
readonly managerAgentId?: string | undefined;
|
|
29
|
+
readonly model?: string | undefined;
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly placement: "local";
|
|
32
|
+
};
|
|
33
|
+
readonly state: "active" | "disabled";
|
|
34
|
+
readonly updatedAt: string;
|
|
35
|
+
}>, never, import("./service.js").RecordsApi | import("effect/Scope").Scope>;
|
|
36
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AGENT_AGGREGATE_TYPE } from "@maiaos/sdk";
|
|
2
|
+
import { Effect, Option } from "effect";
|
|
3
|
+
import { pageOf } from "./kind.js";
|
|
4
|
+
import { makeRecordsView } from "./records.js";
|
|
5
|
+
const agentsKind = ({ projectId }) => ({
|
|
6
|
+
aggregateType: AGENT_AGGREGATE_TYPE,
|
|
7
|
+
id: (agent) => agent.id,
|
|
8
|
+
inScope: (agent) => agent.projectId === projectId,
|
|
9
|
+
list: (api, page) => api
|
|
10
|
+
.listAgents({ ...page, projectId })
|
|
11
|
+
.pipe(Effect.map((result) => pageOf(result.items, result.nextCursor))),
|
|
12
|
+
revision: (agent) => agent.revision,
|
|
13
|
+
show: (api, id) => api.showAgent(id).pipe(Effect.map(Option.map((result) => result.agent))),
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* The Agents of one Project, live: `agents.list` fills the snapshot and
|
|
17
|
+
* `agents.show` reads each Agent a committed change names.
|
|
18
|
+
*/
|
|
19
|
+
export const makeAgentsView = (scope, emit) => makeRecordsView(agentsKind(scope), emit);
|
|
20
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Most records one view holds. A longer list loses its tail and sets `truncated`. */
|
|
2
|
+
export declare const MAX_HELD_RECORDS = 500;
|
|
3
|
+
/** Why a view read its whole list again instead of applying one change. */
|
|
4
|
+
export type ReloadReason = "instance-changed" | "resync" | "subscription-lost";
|
|
5
|
+
/**
|
|
6
|
+
* One record as a read of the Node returned it. `seq` counts the reads in the
|
|
7
|
+
* order the view issued them, so a late answer differs from a newer one even
|
|
8
|
+
* when both name the same revision.
|
|
9
|
+
*/
|
|
10
|
+
export type Held<TRecord> = {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly record: TRecord;
|
|
13
|
+
/** The Node's revision, a decimal string. */
|
|
14
|
+
readonly revision: string;
|
|
15
|
+
readonly seq: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The records one load of the list produced, and what the later changes did
|
|
19
|
+
* to them. A view's collection holds it as its page.
|
|
20
|
+
*/
|
|
21
|
+
export type Snapshot<TRecord> = {
|
|
22
|
+
/** The Node process instance that answered the list read. */
|
|
23
|
+
readonly instanceId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Set on the snapshot a reload produced. A read of one record keeps it; the
|
|
26
|
+
* next read of the whole list replaces it.
|
|
27
|
+
*/
|
|
28
|
+
readonly reload?: ReloadReason;
|
|
29
|
+
readonly rows: ReadonlyMap<string, Held<TRecord>>;
|
|
30
|
+
/** The sequence number of the list read. */
|
|
31
|
+
readonly seq: number;
|
|
32
|
+
/** A limit cut the list, so the rows omit some records the Node holds. */
|
|
33
|
+
readonly truncated: boolean;
|
|
34
|
+
};
|
|
35
|
+
/** Keeps the fire history or other detail a newer list row lacks. */
|
|
36
|
+
export type Carry<TRecord> = (held: TRecord, read: TRecord) => TRecord;
|
|
37
|
+
type Options<TRecord> = {
|
|
38
|
+
readonly cap?: number;
|
|
39
|
+
readonly carry?: Carry<TRecord>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Whether a read may replace the copy the view holds: it names a newer
|
|
43
|
+
* revision, or the same revision and the view issued it later. An older
|
|
44
|
+
* revision never replaces a newer one, whatever order the answers arrive in.
|
|
45
|
+
*/
|
|
46
|
+
export declare const admits: <TRecord>(held: Held<TRecord> | undefined, read: Held<TRecord>) => boolean;
|
|
47
|
+
/** Whether the snapshot already holds `revision`, or a newer one, of a record. */
|
|
48
|
+
export declare const holdsRevision: <TRecord>(snapshot: Snapshot<TRecord>, id: string, revision: string) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The snapshot of one list read, from the records its pages returned in the
|
|
51
|
+
* order the Node listed them. It holds at most `cap` records and sets
|
|
52
|
+
* `truncated` when the Node had more, whether the cap or the page limit
|
|
53
|
+
* stopped the read.
|
|
54
|
+
*/
|
|
55
|
+
export declare const listed: <TRecord>(input: {
|
|
56
|
+
readonly held: readonly Held<TRecord>[];
|
|
57
|
+
readonly instanceId: string;
|
|
58
|
+
readonly more: boolean;
|
|
59
|
+
readonly seq: number;
|
|
60
|
+
}, cap?: number) => Snapshot<TRecord>;
|
|
61
|
+
/**
|
|
62
|
+
* Applies one read the Node answered. A record the snapshot does not hold
|
|
63
|
+
* joins it unless the cap stops it, which sets `truncated`. It returns the
|
|
64
|
+
* same snapshot when the read changes nothing. A read of one record is not a
|
|
65
|
+
* new snapshot, so the reload marker stays.
|
|
66
|
+
*/
|
|
67
|
+
export declare const applyRead: <TRecord>(snapshot: Snapshot<TRecord>, read: Held<TRecord>, options?: Options<TRecord>) => Snapshot<TRecord>;
|
|
68
|
+
/**
|
|
69
|
+
* Removes a record the Node reports it no longer holds, unless a later read
|
|
70
|
+
* saw the record since. The reload marker stays, as it does for `applyRead`.
|
|
71
|
+
*/
|
|
72
|
+
export declare const removeRead: <TRecord>(snapshot: Snapshot<TRecord>, id: string, seq: number) => Snapshot<TRecord>;
|
|
73
|
+
/**
|
|
74
|
+
* Settles a fresh list against the snapshot on screen. Another Node instance
|
|
75
|
+
* answers for itself, and the snapshot names the change of instance. On the
|
|
76
|
+
* same instance no row rolls back: each id keeps the copy `admits` prefers,
|
|
77
|
+
* and a record that the older snapshot alone holds stays when a read issued
|
|
78
|
+
* after the fresh list saw it, since that list cannot have seen the record.
|
|
79
|
+
*/
|
|
80
|
+
export declare const settle: <TRecord>(current: Snapshot<TRecord> | undefined, fresh: Snapshot<TRecord>, options?: Options<TRecord>) => Snapshot<TRecord>;
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=held.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** Most records one view holds. A longer list loses its tail and sets `truncated`. */
|
|
2
|
+
export const MAX_HELD_RECORDS = 500;
|
|
3
|
+
/**
|
|
4
|
+
* Whether a read may replace the copy the view holds: it names a newer
|
|
5
|
+
* revision, or the same revision and the view issued it later. An older
|
|
6
|
+
* revision never replaces a newer one, whatever order the answers arrive in.
|
|
7
|
+
*/
|
|
8
|
+
export const admits = (held, read) => {
|
|
9
|
+
if (held === undefined)
|
|
10
|
+
return true;
|
|
11
|
+
const revision = BigInt(read.revision);
|
|
12
|
+
const known = BigInt(held.revision);
|
|
13
|
+
return revision > known || (revision === known && read.seq > held.seq);
|
|
14
|
+
};
|
|
15
|
+
/** Whether the snapshot already holds `revision`, or a newer one, of a record. */
|
|
16
|
+
export const holdsRevision = (snapshot, id, revision) => {
|
|
17
|
+
const held = snapshot.rows.get(id);
|
|
18
|
+
return held !== undefined && BigInt(held.revision) >= BigInt(revision);
|
|
19
|
+
};
|
|
20
|
+
const replaced = (held, read, carry) => held === undefined || carry === undefined
|
|
21
|
+
? read
|
|
22
|
+
: { ...read, record: carry(held.record, read.record) };
|
|
23
|
+
/**
|
|
24
|
+
* The snapshot of one list read, from the records its pages returned in the
|
|
25
|
+
* order the Node listed them. It holds at most `cap` records and sets
|
|
26
|
+
* `truncated` when the Node had more, whether the cap or the page limit
|
|
27
|
+
* stopped the read.
|
|
28
|
+
*/
|
|
29
|
+
export const listed = (input, cap = MAX_HELD_RECORDS) => {
|
|
30
|
+
const unique = input.held.reduce((rows, read) => admits(rows.get(read.id), read) ? rows.set(read.id, read) : rows, new Map());
|
|
31
|
+
return {
|
|
32
|
+
instanceId: input.instanceId,
|
|
33
|
+
rows: new Map([...unique].slice(0, cap)),
|
|
34
|
+
seq: input.seq,
|
|
35
|
+
truncated: input.more || unique.size > cap,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Applies one read the Node answered. A record the snapshot does not hold
|
|
40
|
+
* joins it unless the cap stops it, which sets `truncated`. It returns the
|
|
41
|
+
* same snapshot when the read changes nothing. A read of one record is not a
|
|
42
|
+
* new snapshot, so the reload marker stays.
|
|
43
|
+
*/
|
|
44
|
+
export const applyRead = (snapshot, read, options = {}) => {
|
|
45
|
+
const held = snapshot.rows.get(read.id);
|
|
46
|
+
if (!admits(held, read))
|
|
47
|
+
return snapshot;
|
|
48
|
+
if (held === undefined &&
|
|
49
|
+
snapshot.rows.size >= (options.cap ?? MAX_HELD_RECORDS))
|
|
50
|
+
return snapshot.truncated ? snapshot : { ...snapshot, truncated: true };
|
|
51
|
+
return {
|
|
52
|
+
...snapshot,
|
|
53
|
+
rows: new Map(snapshot.rows).set(read.id, replaced(held, read, options.carry)),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Removes a record the Node reports it no longer holds, unless a later read
|
|
58
|
+
* saw the record since. The reload marker stays, as it does for `applyRead`.
|
|
59
|
+
*/
|
|
60
|
+
export const removeRead = (snapshot, id, seq) => {
|
|
61
|
+
const held = snapshot.rows.get(id);
|
|
62
|
+
if (held === undefined || held.seq >= seq)
|
|
63
|
+
return snapshot;
|
|
64
|
+
const rows = new Map(snapshot.rows);
|
|
65
|
+
rows.delete(id);
|
|
66
|
+
return { ...snapshot, rows };
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Settles a fresh list against the snapshot on screen. Another Node instance
|
|
70
|
+
* answers for itself, and the snapshot names the change of instance. On the
|
|
71
|
+
* same instance no row rolls back: each id keeps the copy `admits` prefers,
|
|
72
|
+
* and a record that the older snapshot alone holds stays when a read issued
|
|
73
|
+
* after the fresh list saw it, since that list cannot have seen the record.
|
|
74
|
+
*/
|
|
75
|
+
export const settle = (current, fresh, options = {}) => {
|
|
76
|
+
if (current === undefined)
|
|
77
|
+
return fresh;
|
|
78
|
+
if (current.instanceId !== fresh.instanceId)
|
|
79
|
+
return { ...fresh, reload: "instance-changed" };
|
|
80
|
+
const merged = new Map([...fresh.rows].map(([id, read]) => {
|
|
81
|
+
const held = current.rows.get(id);
|
|
82
|
+
return [
|
|
83
|
+
id,
|
|
84
|
+
held !== undefined && !admits(held, read)
|
|
85
|
+
? held
|
|
86
|
+
: replaced(held, read, options.carry),
|
|
87
|
+
];
|
|
88
|
+
}));
|
|
89
|
+
const newer = [...current.rows.values()].filter((held) => !merged.has(held.id) && held.seq > fresh.seq);
|
|
90
|
+
const settled = newer.reduce((snapshot, held) => applyRead(snapshot, held, options), { ...fresh, rows: merged });
|
|
91
|
+
return fresh.reload === undefined
|
|
92
|
+
? settled
|
|
93
|
+
: { ...settled, reload: fresh.reload };
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=held.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type { AgentsScope, AgentsState } from "./agents.js";
|
|
2
|
+
export { makeAgentsView } from "./agents.js";
|
|
3
|
+
export type { ReloadReason } from "./held.js";
|
|
4
|
+
export { MAX_HELD_RECORDS } from "./held.js";
|
|
5
|
+
export type { InteractionsScope, InteractionsState } from "./interactions.js";
|
|
6
|
+
export { makeInteractionsView } from "./interactions.js";
|
|
7
|
+
export type { RecordsView } from "./records.js";
|
|
8
|
+
export type { RoutineRecord, RoutinesScope, RoutinesState, } from "./routines.js";
|
|
9
|
+
export { makeRoutinesView } from "./routines.js";
|
|
10
|
+
export type { ReadOptions, RecordsClient, RecordsService } from "./service.js";
|
|
11
|
+
export { attemptRead, makeRecordsLayer, RecordsApi } from "./service.js";
|
|
12
|
+
export type { RecordsCapability, RecordsState } from "./state.js";
|
|
13
|
+
export type { RecordsSurface, RuntimeRequest } from "./surface.js";
|
|
14
|
+
export { runtimeRequest } from "./surface.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { makeAgentsView } from "./agents.js";
|
|
2
|
+
export { MAX_HELD_RECORDS } from "./held.js";
|
|
3
|
+
export { makeInteractionsView } from "./interactions.js";
|
|
4
|
+
export { makeRoutinesView } from "./routines.js";
|
|
5
|
+
export { attemptRead, makeRecordsLayer, RecordsApi } from "./service.js";
|
|
6
|
+
export { runtimeRequest } from "./surface.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Interaction } from "@maiaos/sdk";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import type { RecordsState } from "./state.js";
|
|
4
|
+
/** The Session whose Interactions a view holds. */
|
|
5
|
+
export type InteractionsScope = {
|
|
6
|
+
readonly projectId: string;
|
|
7
|
+
readonly sessionId: string;
|
|
8
|
+
};
|
|
9
|
+
/** The state of an Interactions view. */
|
|
10
|
+
export type InteractionsState = RecordsState<Interaction>;
|
|
11
|
+
/**
|
|
12
|
+
* The Interactions of one Session, live: `interaction.list` fills the
|
|
13
|
+
* snapshot and `interaction.show` reads each Interaction a committed change
|
|
14
|
+
* names. An Interaction expires by the clock with no change, so one that reads
|
|
15
|
+
* `pending` here may read `expired` at the next `reread`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const makeInteractionsView: (scope: InteractionsScope, emit: (state: InteractionsState) => void) => Effect.Effect<import("./records.js").RecordsView<{
|
|
18
|
+
readonly activationId: null;
|
|
19
|
+
readonly answeredAt: string | null;
|
|
20
|
+
readonly answerSchemaDigest: string;
|
|
21
|
+
readonly body: string;
|
|
22
|
+
readonly createdAt: string;
|
|
23
|
+
readonly expiresAt: string | null;
|
|
24
|
+
readonly interactionId: string;
|
|
25
|
+
readonly lifecycleStatus: "answered" | "cancelled" | "expired" | "pending";
|
|
26
|
+
readonly origin: {
|
|
27
|
+
readonly kind: "external-cli";
|
|
28
|
+
};
|
|
29
|
+
readonly projectId: string;
|
|
30
|
+
readonly requestingActorId: string;
|
|
31
|
+
readonly revision: string;
|
|
32
|
+
readonly schemaVersion: "maia.interaction/v1";
|
|
33
|
+
readonly sessionId: string;
|
|
34
|
+
readonly subject: string;
|
|
35
|
+
readonly wakeDisposition: "record-only";
|
|
36
|
+
readonly kind: "question";
|
|
37
|
+
} | {
|
|
38
|
+
readonly activationId: null;
|
|
39
|
+
readonly answeredAt: string | null;
|
|
40
|
+
readonly answerSchemaDigest: string;
|
|
41
|
+
readonly body: string;
|
|
42
|
+
readonly createdAt: string;
|
|
43
|
+
readonly expiresAt: string | null;
|
|
44
|
+
readonly interactionId: string;
|
|
45
|
+
readonly lifecycleStatus: "answered" | "cancelled" | "expired" | "pending";
|
|
46
|
+
readonly origin: {
|
|
47
|
+
readonly kind: "external-cli";
|
|
48
|
+
};
|
|
49
|
+
readonly projectId: string;
|
|
50
|
+
readonly requestingActorId: string;
|
|
51
|
+
readonly revision: string;
|
|
52
|
+
readonly schemaVersion: "maia.interaction/v1";
|
|
53
|
+
readonly sessionId: string;
|
|
54
|
+
readonly subject: string;
|
|
55
|
+
readonly wakeDisposition: "record-only";
|
|
56
|
+
readonly kind: "selection";
|
|
57
|
+
readonly options: readonly {
|
|
58
|
+
readonly label: string;
|
|
59
|
+
readonly optionId: string;
|
|
60
|
+
}[];
|
|
61
|
+
}>, never, import("./service.js").RecordsApi | import("effect/Scope").Scope>;
|
|
62
|
+
//# sourceMappingURL=interactions.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
2
|
+
import { pageOf } from "./kind.js";
|
|
3
|
+
import { makeRecordsView } from "./records.js";
|
|
4
|
+
const INTERACTION_AGGREGATE_TYPE = "interaction";
|
|
5
|
+
/**
|
|
6
|
+
* A list row never carries the answer, but `interaction.show` does for the
|
|
7
|
+
* asking principal. A held record drops it: a renderer reads an answer when a
|
|
8
|
+
* person opens it and never keeps it in the collection.
|
|
9
|
+
*/
|
|
10
|
+
const withoutAnswer = (detail) => {
|
|
11
|
+
const { answer, respondingActorId, responseDigest, ...projection } = detail;
|
|
12
|
+
return projection;
|
|
13
|
+
};
|
|
14
|
+
const interactionsKind = ({ projectId, sessionId, }) => ({
|
|
15
|
+
aggregateType: INTERACTION_AGGREGATE_TYPE,
|
|
16
|
+
id: (interaction) => interaction.interactionId,
|
|
17
|
+
inScope: (interaction) => interaction.projectId === projectId && interaction.sessionId === sessionId,
|
|
18
|
+
list: (api, page) => api
|
|
19
|
+
.listInteractions({ ...page, projectId, sessionId })
|
|
20
|
+
.pipe(Effect.map((result) => pageOf(result.items, result.nextCursor))),
|
|
21
|
+
revision: (interaction) => interaction.revision,
|
|
22
|
+
show: (api, id) => api
|
|
23
|
+
.showInteraction(id)
|
|
24
|
+
.pipe(Effect.map(Option.map((result) => withoutAnswer(result.interaction)))),
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* The Interactions of one Session, live: `interaction.list` fills the
|
|
28
|
+
* snapshot and `interaction.show` reads each Interaction a committed change
|
|
29
|
+
* names. An Interaction expires by the clock with no change, so one that reads
|
|
30
|
+
* `pending` here may read `expired` at the next `reread`.
|
|
31
|
+
*/
|
|
32
|
+
export const makeInteractionsView = (scope, emit) => makeRecordsView(interactionsKind(scope), emit);
|
|
33
|
+
//# sourceMappingURL=interactions.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Effect, type Option } from "effect";
|
|
2
|
+
import type { PresentationError } from "../presentation/index.js";
|
|
3
|
+
import { type Carry, type Snapshot } from "./held.js";
|
|
4
|
+
import type { RecordsService } from "./service.js";
|
|
5
|
+
/** One page of a records list, in the order the Node listed it. */
|
|
6
|
+
export type RecordsPage<TRecord> = {
|
|
7
|
+
readonly nextCursor?: string;
|
|
8
|
+
readonly records: readonly TRecord[];
|
|
9
|
+
};
|
|
10
|
+
/** The page of a list result, with no `nextCursor` key on the last page. */
|
|
11
|
+
export declare const pageOf: <TRecord>(records: readonly TRecord[], nextCursor: string | undefined) => RecordsPage<TRecord>;
|
|
12
|
+
/** What one record type adds to the generic view: how to list, show and identify it. */
|
|
13
|
+
export type RecordsKind<TRecord> = {
|
|
14
|
+
/** The name the Node's change feed gives records of this type. */
|
|
15
|
+
readonly aggregateType: string;
|
|
16
|
+
/** Keeps detail a newer list row lacks, such as a routine's fire history. */
|
|
17
|
+
readonly carry?: Carry<TRecord>;
|
|
18
|
+
readonly id: (record: TRecord) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the view's scope holds the record. The change feed names every
|
|
21
|
+
* record of the type, so the view ignores a read of one outside the scope.
|
|
22
|
+
*/
|
|
23
|
+
readonly inScope: (record: TRecord) => boolean;
|
|
24
|
+
readonly list: (api: RecordsService, page: {
|
|
25
|
+
readonly afterCursor?: string;
|
|
26
|
+
readonly limit: number;
|
|
27
|
+
}) => Effect.Effect<RecordsPage<TRecord>, PresentationError>;
|
|
28
|
+
/** The Node's revision of the record, a decimal string. */
|
|
29
|
+
readonly revision: (record: TRecord) => string;
|
|
30
|
+
/** `None` when the Node holds no such record. */
|
|
31
|
+
readonly show: (api: RecordsService, id: string) => Effect.Effect<Option.Option<TRecord>, PresentationError>;
|
|
32
|
+
};
|
|
33
|
+
/** The list read number `seq` of one view. */
|
|
34
|
+
export type ListRead<TRecord> = {
|
|
35
|
+
readonly api: RecordsService;
|
|
36
|
+
readonly kind: RecordsKind<TRecord>;
|
|
37
|
+
readonly seq: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Reads the list page by page, up to the cap, as the snapshot of the Node
|
|
41
|
+
* instance that answers.
|
|
42
|
+
*/
|
|
43
|
+
export declare const readSnapshot: <TRecord>(read: ListRead<TRecord>) => Effect.Effect<Snapshot<TRecord>, PresentationError>;
|
|
44
|
+
//# sourceMappingURL=kind.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { listed, MAX_HELD_RECORDS, } from "./held.js";
|
|
3
|
+
/** Most records the Node returns in one page of any records list. */
|
|
4
|
+
const PAGE_SIZE = 100;
|
|
5
|
+
/** The page of a list result, with no `nextCursor` key on the last page. */
|
|
6
|
+
export const pageOf = (records, nextCursor) => nextCursor === undefined ? { records } : { nextCursor, records };
|
|
7
|
+
const readPages = (read, held, cursor) => {
|
|
8
|
+
const { api, kind, seq } = read;
|
|
9
|
+
const request = cursor === undefined
|
|
10
|
+
? { limit: PAGE_SIZE }
|
|
11
|
+
: { afterCursor: cursor, limit: PAGE_SIZE };
|
|
12
|
+
return kind.list(api, request).pipe(Effect.flatMap((page) => {
|
|
13
|
+
const all = [
|
|
14
|
+
...held,
|
|
15
|
+
...page.records.map((record) => ({
|
|
16
|
+
id: kind.id(record),
|
|
17
|
+
record,
|
|
18
|
+
revision: kind.revision(record),
|
|
19
|
+
seq,
|
|
20
|
+
})),
|
|
21
|
+
];
|
|
22
|
+
return page.nextCursor === undefined || all.length >= MAX_HELD_RECORDS
|
|
23
|
+
? Effect.succeed({ held: all, more: page.nextCursor !== undefined })
|
|
24
|
+
: readPages(read, all, page.nextCursor);
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Reads the list page by page, up to the cap, as the snapshot of the Node
|
|
29
|
+
* instance that answers.
|
|
30
|
+
*/
|
|
31
|
+
export const readSnapshot = (read) => Effect.gen(function* () {
|
|
32
|
+
const instanceId = yield* read.api.instance;
|
|
33
|
+
const { held, more } = yield* readPages(read, []);
|
|
34
|
+
return listed({ held, instanceId, more, seq: read.seq });
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=kind.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type NodeChanges } from "../presentation/index.js";
|
|
3
|
+
import { type ReloadReason } from "./held.js";
|
|
4
|
+
import { type RecordsKind } from "./kind.js";
|
|
5
|
+
import { RecordsApi } from "./service.js";
|
|
6
|
+
import { type RecordsState } from "./state.js";
|
|
7
|
+
/** One records view: its state, explicit reads and the live follow of the Node. */
|
|
8
|
+
export type RecordsView<TRecord> = {
|
|
9
|
+
/** Reads the list once, for the first state. */
|
|
10
|
+
readonly load: Effect.Effect<void>;
|
|
11
|
+
readonly read: Effect.Effect<RecordsState<TRecord>>;
|
|
12
|
+
/** Reads the whole list again under a new generation. */
|
|
13
|
+
readonly refresh: Effect.Effect<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Reads the whole list again once any read in flight settles, and recovers
|
|
16
|
+
* from a failed read. A `reason` marks the new snapshot `reloaded` with it;
|
|
17
|
+
* a reload with no reason is a quiet reread and sets no notice.
|
|
18
|
+
*/
|
|
19
|
+
readonly reload: (reason?: ReloadReason) => Effect.Effect<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Reads these records by id with `show` and applies each read when its
|
|
22
|
+
* revision exceeds the held one; a record the Node no longer holds leaves
|
|
23
|
+
* the view. Yields `false` when a read failed.
|
|
24
|
+
*/
|
|
25
|
+
readonly reread: (ids: readonly string[]) => Effect.Effect<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Keeps the view current from the Node's committed changes until
|
|
28
|
+
* interruption: it rereads the records a change names and reloads the list
|
|
29
|
+
* on a resync, a change that names no record, a lost subscription or a new
|
|
30
|
+
* Node instance.
|
|
31
|
+
*/
|
|
32
|
+
readonly watch: Effect.Effect<void, never, NodeChanges>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* One view of a record type, held as a bounded snapshot that follows the
|
|
36
|
+
* Node's committed changes. It reuses the collection view's generation, so the
|
|
37
|
+
* view drops a list read that a newer read replaced, and it never lets an
|
|
38
|
+
* older revision of a record replace a newer one.
|
|
39
|
+
*/
|
|
40
|
+
export declare const makeRecordsView: <TRecord>(kind: RecordsKind<TRecord>, emit: (state: RecordsState<TRecord>) => void) => Effect.Effect<RecordsView<TRecord>, never, RecordsApi | import("effect/Scope").Scope>;
|
|
41
|
+
//# sourceMappingURL=records.d.ts.map
|