@maiaos/client-core 0.1.0-canary.63 → 0.1.0-canary.65

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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -16
  3. package/dist/cockpit/creation.d.ts +6 -2
  4. package/dist/cockpit/creation.js +11 -3
  5. package/dist/cockpit/index.d.ts +1 -1
  6. package/dist/cockpit/index.js +1 -1
  7. package/dist/cockpit/launcher.js +2 -8
  8. package/dist/cockpit/onboarding.js +7 -7
  9. package/dist/cockpit/routing.d.ts +1 -1
  10. package/dist/cockpit/routing.js +1 -0
  11. package/dist/interaction/recovery.d.ts +2 -0
  12. package/dist/portfolio/portfolio.d.ts +28 -2
  13. package/dist/presentation/collection-view.d.ts +14 -1
  14. package/dist/presentation/collection-view.js +67 -22
  15. package/dist/presentation/index.d.ts +1 -0
  16. package/dist/presentation/index.js +1 -0
  17. package/dist/presentation/live.d.ts +11 -2
  18. package/dist/presentation/session-view.d.ts +11 -2
  19. package/dist/records/agents.d.ts +36 -0
  20. package/dist/records/agents.js +20 -0
  21. package/dist/records/held.d.ts +82 -0
  22. package/dist/records/held.js +95 -0
  23. package/dist/records/index.d.ts +15 -0
  24. package/dist/records/index.js +7 -0
  25. package/dist/records/interactions.d.ts +62 -0
  26. package/dist/records/interactions.js +33 -0
  27. package/dist/records/kind.d.ts +44 -0
  28. package/dist/records/kind.js +36 -0
  29. package/dist/records/records.d.ts +41 -0
  30. package/dist/records/records.js +103 -0
  31. package/dist/records/routines.d.ts +28 -0
  32. package/dist/records/routines.js +35 -0
  33. package/dist/records/service.d.ts +42 -0
  34. package/dist/records/service.js +46 -0
  35. package/dist/records/state.d.ts +34 -0
  36. package/dist/records/state.js +26 -0
  37. package/dist/records/surface.d.ts +19 -0
  38. package/dist/records/surface.js +23 -0
  39. package/dist/records/watch.d.ts +24 -0
  40. package/dist/records/watch.js +68 -0
  41. package/dist/session-view/conversation.js +2 -5
  42. package/package.json +23 -3
@@ -0,0 +1,46 @@
1
+ import { classifyClientError, } from "@maiaos/sdk";
2
+ import { Context, Effect, Layer, Option } from "effect";
3
+ import { nextCompactId } from "../id-generator/index.js";
4
+ import { PresentationError } from "../presentation/index.js";
5
+ /** The service the records views read through. */
6
+ export class RecordsApi extends Context.Service()("@maiaos/client-core/RecordsApi") {
7
+ }
8
+ /**
9
+ * The SDK's classification in the views' words: a Node without the operation
10
+ * is `unavailable`, a refusal by the credential, role or platform bridge is
11
+ * `denied`, and a record the Node does not hold is `scope_mismatch`.
12
+ */
13
+ const reasonOf = (error) => {
14
+ if (error instanceof PresentationError)
15
+ return error;
16
+ const { kind } = classifyClientError(error, { mutation: false });
17
+ if (kind === "unavailable" || kind === "denied" || kind === "invalid")
18
+ return new PresentationError(kind);
19
+ return new PresentationError(kind === "conflict" || kind === "not_found" ? "scope_mismatch" : "offline");
20
+ };
21
+ const isAbsent = (error) => classifyClientError(error, { mutation: false }).kind === "not_found";
22
+ /**
23
+ * One SDK read as an Effect: a fresh request identifier, a 5.5 s deadline
24
+ * that fails as `offline`, and the failure the request raised. Interrupting
25
+ * the Effect aborts the request's signal.
26
+ */
27
+ export const attemptRead = (request) => Effect.flatMap(nextCompactId("records"), (messageId) => Effect.tryPromise({
28
+ catch: (error) => error,
29
+ try: (signal) => request({ messageId, signal }),
30
+ })).pipe(Effect.timeoutOrElse({
31
+ duration: "5500 millis",
32
+ orElse: () => Effect.fail(new PresentationError("offline")),
33
+ }));
34
+ const read = (request) => attemptRead(request).pipe(Effect.mapError(reasonOf));
35
+ const readOrAbsent = (request) => attemptRead(request).pipe(Effect.map(Option.some), Effect.catchIf(isAbsent, () => Effect.succeed(Option.none())), Effect.mapError(reasonOf));
36
+ /** The records reads over an SDK client; the platform supplies the Node instance. */
37
+ export const makeRecordsLayer = ({ client, instance }) => Layer.succeed(RecordsApi, {
38
+ instance,
39
+ listAgents: (input) => read((options) => client.listAgents({ ...input }, options)),
40
+ listInteractions: (input) => read((options) => client.listInteractions({ ...input }, options)),
41
+ listRoutines: (input) => read((options) => client.listRoutines({ ...input }, options)),
42
+ showAgent: (agentId) => readOrAbsent((options) => client.showAgent({ agentId }, options)),
43
+ showInteraction: (interactionId) => readOrAbsent((options) => client.showInteraction({ interactionId }, options)),
44
+ showRoutine: (routineId) => readOrAbsent((options) => client.showRoutine({ routineId }, options)),
45
+ });
46
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1,34 @@
1
+ import type { CollectionState, PresentationErrorReason } from "../presentation/index.js";
2
+ import type { ReloadReason, Snapshot } from "./held.js";
3
+ /** What a view can do for its renderer; `available` carries the records. */
4
+ export type RecordsCapability = "available" | "denied" | "offline" | "unavailable";
5
+ /**
6
+ * What a renderer shows. Until the first answer the capability is `loading`.
7
+ * A Node that lacks the list (`unavailable`), a transport that refuses it
8
+ * (`denied`) and a Node that does not answer (`offline`) carry no records, so
9
+ * a renderer cannot show stale or sample data in them.
10
+ */
11
+ export type RecordsState<TRecord> = {
12
+ readonly capability: "available";
13
+ readonly generation: number;
14
+ /** In the order the Node listed them; a record that a change added comes last. */
15
+ readonly records: readonly TRecord[];
16
+ /** A read of the whole list runs, and `records` stay as held. */
17
+ readonly refreshing: boolean;
18
+ /** Set on the state a reload produced; a read of one record keeps it, the next read of the list replaces it. */
19
+ readonly reloaded?: true;
20
+ readonly reloadReason?: ReloadReason;
21
+ /** The Node holds more records than the cap, so `records` omits some. */
22
+ readonly truncated: boolean;
23
+ } | {
24
+ readonly capability: "loading";
25
+ readonly generation: number;
26
+ } | {
27
+ readonly capability: Exclude<RecordsCapability, "available">;
28
+ readonly generation: number;
29
+ /** Why the read failed, finer than the capability. */
30
+ readonly reason: PresentationErrorReason;
31
+ };
32
+ /** The renderer's state for one state of the view's collection. */
33
+ export declare const toState: <TRecord>({ generation, page, reason, status, }: CollectionState<Snapshot<TRecord>>) => RecordsState<TRecord>;
34
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1,26 @@
1
+ /** A refused, unsupported or unanswered read names the matching capability. */
2
+ const capabilityOf = (reason) => reason === "denied" || reason === "unavailable" ? reason : "offline";
3
+ /** The renderer's state for one state of the view's collection. */
4
+ export const toState = ({ generation, page, reason, status, }) => {
5
+ if (status === "error") {
6
+ const failure = reason ?? "offline";
7
+ return {
8
+ capability: capabilityOf(failure),
9
+ generation,
10
+ reason: failure,
11
+ };
12
+ }
13
+ if (page === undefined)
14
+ return { capability: "loading", generation };
15
+ return {
16
+ capability: "available",
17
+ generation,
18
+ records: [...page.rows.values()].map((held) => held.record),
19
+ refreshing: status === "loading",
20
+ ...(page.reload === undefined
21
+ ? {}
22
+ : { reloaded: true, reloadReason: page.reload }),
23
+ truncated: page.truncated,
24
+ };
25
+ };
26
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1,19 @@
1
+ /** The record surfaces the records views serve. */
2
+ export type RecordsSurface = "agents" | "interactions" | "routines";
3
+ /** What a surface needs from the Node, to show where its data is unavailable. */
4
+ export type RuntimeRequest = {
5
+ /** The Node operations that serve the surface: its list, then its show. */
6
+ readonly operations: readonly [string, string];
7
+ /** The issue references the caller tracks the request under. */
8
+ readonly references: readonly string[];
9
+ readonly surface: RecordsSurface;
10
+ /** One sentence naming the operations and the references. */
11
+ readonly text: string;
12
+ };
13
+ /**
14
+ * Names the runtime request behind a surface whose view is `unavailable`. The
15
+ * caller passes the issue references it tracks the request under, so the core
16
+ * holds no issue numbers.
17
+ */
18
+ export declare const runtimeRequest: (surface: RecordsSurface, references?: readonly string[]) => RuntimeRequest;
19
+ //# sourceMappingURL=surface.d.ts.map
@@ -0,0 +1,23 @@
1
+ const OPERATIONS = {
2
+ agents: ["agents.list", "agents.show"],
3
+ interactions: ["interaction.list", "interaction.show"],
4
+ routines: ["routine.list", "routine.show"],
5
+ };
6
+ /**
7
+ * Names the runtime request behind a surface whose view is `unavailable`. The
8
+ * caller passes the issue references it tracks the request under, so the core
9
+ * holds no issue numbers.
10
+ */
11
+ export const runtimeRequest = (surface, references = []) => {
12
+ const operations = OPERATIONS[surface];
13
+ const needs = `The Node must serve ${operations[0]} and ${operations[1]}.`;
14
+ return {
15
+ operations,
16
+ references,
17
+ surface,
18
+ text: references.length === 0
19
+ ? needs
20
+ : `${needs} Tracked in ${references.join(", ")}.`,
21
+ };
22
+ };
23
+ //# sourceMappingURL=surface.js.map
@@ -0,0 +1,24 @@
1
+ import { Effect, Option } from "effect";
2
+ import { NodeChanges, type PresentationError } from "../presentation/index.js";
3
+ import { type ReloadReason, type Snapshot } from "./held.js";
4
+ /** What the change feed needs of one records view. */
5
+ export type Follow<TRecord> = {
6
+ /** The name the change feed gives records of the view's type. */
7
+ readonly aggregateType: string;
8
+ readonly instance: Effect.Effect<string, PresentationError>;
9
+ /** The snapshot the view holds, once a list read in flight settles. */
10
+ readonly known: Effect.Effect<Option.Option<Snapshot<TRecord>>>;
11
+ /** Reads the whole list again and waits for the answer; `reason` names why. */
12
+ readonly reload: (reason?: ReloadReason) => Effect.Effect<void>;
13
+ /** Reads these records by id; yields `false` when any read failed. */
14
+ readonly reread: (ids: readonly string[]) => Effect.Effect<boolean>;
15
+ };
16
+ /**
17
+ * Keeps a records view current from the Node's committed changes until
18
+ * interruption. Bursts coalesce into one batch. The follow retries a lost
19
+ * subscription with backoff and resubscribes after two seconds when the stream
20
+ * ends; each subscription reads the Node instance again, so the follow tracks
21
+ * a restarted Node.
22
+ */
23
+ export declare const followChanges: <TRecord>(follow: Follow<TRecord>) => Effect.Effect<void, never, NodeChanges>;
24
+ //# sourceMappingURL=watch.d.ts.map
@@ -0,0 +1,68 @@
1
+ import { Duration, Effect, Option, Schedule, Stream } from "effect";
2
+ import { NodeChanges } from "../presentation/index.js";
3
+ import { holdsRevision } from "./held.js";
4
+ const COALESCE_WITHIN = Duration.millis(150);
5
+ const MAX_TARGETED_READS = 64;
6
+ const RESUBSCRIBE_AFTER = Duration.seconds(2);
7
+ /** A failed subscription retries after 2 s, doubling to 30 s, as the cockpit's feed does. */
8
+ const RECONNECT_BACKOFF = Schedule.min([
9
+ Schedule.exponential(Duration.seconds(2)),
10
+ Schedule.spaced(Duration.seconds(30)),
11
+ ]);
12
+ const touches = (type, batch) => batch.some((change) => change.kind === "records" && change.aggregateTypes.includes(type));
13
+ /** A resync, or a change of this type that names no record, says to read the list again. */
14
+ const needsReload = (type, batch) => batch.some((change) => change.kind === "resync" ||
15
+ (change.changed === undefined && change.aggregateTypes.includes(type)));
16
+ /** The records of this type that a batch changed past the revisions the snapshot holds. */
17
+ const changedIds = (type, snapshot, batch) => [
18
+ ...new Set(batch.flatMap((change) => change.kind === "records"
19
+ ? (change.changed ?? [])
20
+ .filter((aggregate) => aggregate.type === type &&
21
+ !holdsRevision(snapshot, aggregate.id, aggregate.revision))
22
+ .map((aggregate) => aggregate.id)
23
+ : [])),
24
+ ];
25
+ /**
26
+ * One coalesced batch. A resync, or a change that names no record, reloads the
27
+ * list. Otherwise the view reads each changed record by id. A batch that names
28
+ * more records than worth reading one by one, or a read that failed, reloads
29
+ * the list, which either converges or says the Node cannot serve it. A view
30
+ * that holds nothing reloads on the first change of its type.
31
+ */
32
+ const applyBatch = (follow, batch) => Effect.gen(function* () {
33
+ const { aggregateType } = follow;
34
+ if (needsReload(aggregateType, batch))
35
+ return yield* follow.reload("resync");
36
+ const known = yield* follow.known;
37
+ if (Option.isNone(known))
38
+ return yield* touches(aggregateType, batch)
39
+ ? follow.reload("resync")
40
+ : Effect.void;
41
+ const ids = changedIds(aggregateType, known.value, batch);
42
+ if (ids.length > MAX_TARGETED_READS)
43
+ return yield* follow.reload("resync");
44
+ if (ids.length > 0 && !(yield* follow.reread(ids)))
45
+ yield* follow.reload("resync");
46
+ });
47
+ /**
48
+ * One subscription to the Node instance now answering. A view that holds
49
+ * nothing, or holds another instance's snapshot, reads its list first. A
50
+ * subscription that fails reads the list again before the next attempt.
51
+ */
52
+ const subscription = (follow) => Effect.gen(function* () {
53
+ const changes = yield* NodeChanges;
54
+ const instanceId = yield* follow.instance;
55
+ const known = yield* follow.known;
56
+ if (Option.isNone(known) || known.value.instanceId !== instanceId)
57
+ yield* follow.reload();
58
+ yield* changes.watch(instanceId).pipe(Stream.groupedWithin(512, COALESCE_WITHIN), Stream.runForEach((batch) => applyBatch(follow, batch)));
59
+ }).pipe(Effect.tapError(() => follow.reload("subscription-lost")));
60
+ /**
61
+ * Keeps a records view current from the Node's committed changes until
62
+ * interruption. Bursts coalesce into one batch. The follow retries a lost
63
+ * subscription with backoff and resubscribes after two seconds when the stream
64
+ * ends; each subscription reads the Node instance again, so the follow tracks
65
+ * a restarted Node.
66
+ */
67
+ export const followChanges = (follow) => subscription(follow).pipe(Effect.retry(RECONNECT_BACKOFF), Effect.repeat(Schedule.spaced(RESUBSCRIBE_AFTER)), Effect.ignore);
68
+ //# sourceMappingURL=watch.js.map
@@ -1,3 +1,4 @@
1
+ import { executorLabel } from "../cockpit/index.js";
1
2
  const PENDING = new Set(["dispatching", "queued"]);
2
3
  const fromTimeline = (turn) => ({
3
4
  ...(turn.failureReason === undefined
@@ -67,10 +68,6 @@ export const durationLabel = (milliseconds) => {
67
68
  };
68
69
  /** A token count as `950` or `4.2k`. */
69
70
  export const tokenLabel = (tokens) => tokens < 1000 ? String(tokens) : `${(tokens / 1000).toFixed(1)}k`;
70
- const EXECUTOR_LABELS = new Map([
71
- ["claude-code", "Claude Code"],
72
- ["codex-cli", "Codex"],
73
- ]);
74
71
  /** The first line of the first prompt, as a title; at most 80 characters. */
75
72
  const titleOf = (conversation) => {
76
73
  const first = conversation
@@ -107,7 +104,7 @@ export const projectSessionSummary = (input) => {
107
104
  ? {}
108
105
  : {
109
106
  connection: connectionName ?? executor.connectionId,
110
- executor: EXECUTOR_LABELS.get(executor.kind) ?? executor.kind,
107
+ executor: executorLabel(executor.kind),
111
108
  }),
112
109
  ...(elapsed === undefined ? {} : { elapsed }),
113
110
  ...(executor?.model === undefined ? {} : { model: executor.model }),
package/package.json CHANGED
@@ -1,7 +1,18 @@
1
1
  {
2
2
  "name": "@maiaos/client-core",
3
- "version": "0.1.0-canary.63",
3
+ "version": "0.1.0-canary.65",
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
+ "keywords": [
6
+ "maia",
7
+ "maiaos",
8
+ "ai-agents",
9
+ "coding-agents",
10
+ "multi-agent",
11
+ "agent-orchestration",
12
+ "client",
13
+ "effect",
14
+ "typescript"
15
+ ],
5
16
  "homepage": "https://github.com/vllnt/maia/tree/main/packages/client-core#readme",
6
17
  "bugs": "https://github.com/vllnt/maia/issues",
7
18
  "repository": {
@@ -9,6 +20,7 @@
9
20
  "url": "git+https://github.com/vllnt/maia.git",
10
21
  "directory": "packages/client-core"
11
22
  },
23
+ "license": "MIT",
12
24
  "type": "module",
13
25
  "sideEffects": false,
14
26
  "exports": {
@@ -32,6 +44,10 @@
32
44
  "types": "./dist/dictation/index.d.ts",
33
45
  "import": "./dist/dictation/index.js"
34
46
  },
47
+ "./id-generator": {
48
+ "types": "./dist/id-generator/index.d.ts",
49
+ "import": "./dist/id-generator/index.js"
50
+ },
35
51
  "./interaction-view": {
36
52
  "types": "./dist/interaction/view.d.ts",
37
53
  "import": "./dist/interaction/view.js"
@@ -52,6 +68,10 @@
52
68
  "types": "./dist/presentation/index.d.ts",
53
69
  "import": "./dist/presentation/index.js"
54
70
  },
71
+ "./records": {
72
+ "types": "./dist/records/index.d.ts",
73
+ "import": "./dist/records/index.js"
74
+ },
55
75
  "./node-status": {
56
76
  "types": "./dist/node-status/index.d.ts",
57
77
  "import": "./dist/node-status/index.js"
@@ -94,13 +114,13 @@
94
114
  "node": "24.22.1"
95
115
  },
96
116
  "dependencies": {
97
- "@maiaos/sdk": "0.1.0-canary.63",
117
+ "@maiaos/sdk": "0.1.0-canary.65",
98
118
  "effect": "4.0.0"
99
119
  },
100
120
  "devDependencies": {
101
121
  "@types/node": "24.13.3",
102
122
  "@typescript/native": "npm:typescript@7.0.2",
103
- "@vllnt/typescript": "2.0.0-canary.a1749e0",
123
+ "@vllnt/typescript": "3.0.1",
104
124
  "eslint": "9.39.5",
105
125
  "typescript": "npm:@typescript/typescript6@6.0.2"
106
126
  },