@stigmer/react-core 0.1.3 → 0.3.0
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/internal/store/conversation-store.d.ts +9 -2
- package/internal/store/conversation-store.d.ts.map +1 -1
- package/internal/store/conversation-store.js +25 -11
- package/internal/store/conversation-store.js.map +1 -1
- package/internal.d.ts +1 -0
- package/internal.d.ts.map +1 -1
- package/internal.js +1 -0
- package/internal.js.map +1 -1
- package/models/registry.d.ts +1 -1
- package/package.json +4 -4
- package/run/FileReviewContext.d.ts +17 -2
- package/run/FileReviewContext.d.ts.map +1 -1
- package/run/FileReviewContext.js +25 -0
- package/run/FileReviewContext.js.map +1 -1
- package/run/tool-categories.d.ts +13 -16
- package/run/tool-categories.d.ts.map +1 -1
- package/run/tool-categories.js +17 -30
- package/run/tool-categories.js.map +1 -1
- package/run/useReviewFileChanges.d.ts +2 -1
- package/run/useReviewFileChanges.d.ts.map +1 -1
- package/run/useReviewFileChanges.js +2 -1
- package/run/useReviewFileChanges.js.map +1 -1
- package/run/useRunActions.d.ts +10 -2
- package/run/useRunActions.d.ts.map +1 -1
- package/run/useRunActions.js +6 -2
- package/run/useRunActions.js.map +1 -1
- package/session/useSessionConversation.d.ts +19 -9
- package/session/useSessionConversation.d.ts.map +1 -1
- package/session/useSessionConversation.js +110 -48
- package/session/useSessionConversation.js.map +1 -1
- package/session/useSessionEvents.d.ts +2 -1
- package/session/useSessionEvents.d.ts.map +1 -1
- package/session/useSessionEvents.js +28 -12
- package/session/useSessionEvents.js.map +1 -1
- package/src/internal/store/conversation-store.ts +25 -10
- package/src/internal.ts +1 -0
- package/src/models/registry.ts +1 -1
- package/src/run/FileReviewContext.ts +27 -2
- package/src/run/tool-categories.ts +30 -46
- package/src/run/useReviewFileChanges.ts +2 -1
- package/src/run/useRunActions.ts +24 -2
- package/src/session/useSessionConversation.ts +153 -62
- package/src/session/useSessionEvents.ts +29 -13
- package/src/test/samples.ts +85 -1
- package/test/samples.d.ts +50 -0
- package/test/samples.d.ts.map +1 -1
- package/test/samples.js +53 -1
- package/test/samples.js.map +1 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
// The conversation's live state for one session:
|
|
2
|
-
// folded (`SessionLog` from @stigmer/client), plus the
|
|
3
|
-
// and its two watchdog signals.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
1
|
+
// The conversation's live state for one session: which session it holds, the
|
|
2
|
+
// session's event log, folded (`SessionLog` from @stigmer/client), plus the
|
|
3
|
+
// follow's lifecycle stage and its two watchdog signals. The session id is
|
|
4
|
+
// read with the rest, so a reader can tell state that belongs to the session
|
|
5
|
+
// it renders from state still left over from another (stigmer/stigmer#2921).
|
|
6
|
+
// Frames go into the log as they arrive; the fold is published to React only
|
|
7
|
+
// when the stream controller flushes, so a burst of frames commits once. The
|
|
8
|
+
// fold itself keeps every turn, item and thread object no event touched, so a
|
|
9
|
+
// published snapshot shares unchanged objects by reference with the one before
|
|
10
|
+
// it and only the changed rows re-render. Implements the contract
|
|
11
|
+
// `useSyncExternalStore` reads.
|
|
9
12
|
|
|
10
13
|
import { useRef } from "react";
|
|
11
14
|
import { SessionLog, type SessionFold } from "@stigmer/client";
|
|
@@ -56,6 +59,7 @@ export type Listener = () => void;
|
|
|
56
59
|
* they can read changed; every getter returns a stable reference.
|
|
57
60
|
*/
|
|
58
61
|
export class ConversationStore {
|
|
62
|
+
private _sessionId: string | null = null;
|
|
59
63
|
private _log = new SessionLog();
|
|
60
64
|
private _fold: SessionFold | null = null;
|
|
61
65
|
private _streamState: StreamState = IDLE_STATE;
|
|
@@ -119,13 +123,19 @@ export class ConversationStore {
|
|
|
119
123
|
this._notify();
|
|
120
124
|
}
|
|
121
125
|
|
|
122
|
-
/**
|
|
123
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Start over with an empty log, holding `sessionId` (none when omitted).
|
|
128
|
+
* Listeners hear it when anything they can read changed, the held session
|
|
129
|
+
* included, even for a store that was already empty.
|
|
130
|
+
*/
|
|
131
|
+
reset(sessionId: string | null = null): void {
|
|
124
132
|
const wasClean =
|
|
133
|
+
this._sessionId === sessionId &&
|
|
125
134
|
this._fold === null &&
|
|
126
135
|
this._streamState.stage === "idle" &&
|
|
127
136
|
!this._connectTimedOut &&
|
|
128
137
|
!this._isSlow;
|
|
138
|
+
this._sessionId = sessionId;
|
|
129
139
|
this._log = new SessionLog();
|
|
130
140
|
this._fold = null;
|
|
131
141
|
this._streamState = IDLE_STATE;
|
|
@@ -144,6 +154,11 @@ export class ConversationStore {
|
|
|
144
154
|
};
|
|
145
155
|
};
|
|
146
156
|
|
|
157
|
+
/** The session the store holds, as the last {@link reset} named it. */
|
|
158
|
+
getSessionId = (): string | null => {
|
|
159
|
+
return this._sessionId;
|
|
160
|
+
};
|
|
161
|
+
|
|
147
162
|
/** The published fold, or `null` before the first publish. */
|
|
148
163
|
getFold = (): SessionFold | null => {
|
|
149
164
|
return this._fold;
|
package/src/internal.ts
CHANGED
|
@@ -58,6 +58,7 @@ export {
|
|
|
58
58
|
export type { ToolChrome } from "./run/tool-categories.js";
|
|
59
59
|
export { runIdFromStorageKey } from "./run/useFileChangeContent.js";
|
|
60
60
|
export { RunnerAdapterContext } from "./runner-adapter.js";
|
|
61
|
+
export { useFileReviewRowFile } from "./run/FileReviewContext.js";
|
|
61
62
|
export { useResourceCount, useResourceList, useResourceSearch } from "./search/index.js";
|
|
62
63
|
export { fromProtoExecutionTarget, toProtoExecutionTarget } from "./session/execution-target.js";
|
|
63
64
|
export { mapPatchHunks } from "./version-history/diff-hunks.js";
|
package/src/models/registry.ts
CHANGED
|
@@ -69,7 +69,7 @@ export const DISABLED_PROVIDERS: ReadonlySet<Provider> = new Set([
|
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
export interface ModelInfo {
|
|
72
|
-
/** Unique model identifier sent to the backend (e.g. `"claude-sonnet-4.
|
|
72
|
+
/** Unique model identifier sent to the backend (e.g. `"claude-sonnet-4.6"`). */
|
|
73
73
|
readonly modelId: string;
|
|
74
74
|
/** LLM provider that serves this model. */
|
|
75
75
|
readonly provider: Provider;
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
CapturedFileChange,
|
|
4
4
|
FileChangeSet,
|
|
5
5
|
} from "@stigmer/apis/ai/stigmer/agentic/run/v1/filereview_pb";
|
|
6
|
-
import type { FileReviewSet } from "@stigmer/client";
|
|
6
|
+
import type { FileReviewFile, FileReviewSet } from "@stigmer/client";
|
|
7
7
|
import {
|
|
8
8
|
fileForRowPath,
|
|
9
9
|
fileReviewRowChange,
|
|
@@ -28,7 +28,8 @@ import {
|
|
|
28
28
|
* without a provider render no badge.
|
|
29
29
|
*
|
|
30
30
|
* Read-only by design: the row badge is presentation, never a decision
|
|
31
|
-
* surface
|
|
31
|
+
* surface; a turn's files are undone from its Changed group (the React kit's
|
|
32
|
+
* `TurnOutcome`).
|
|
32
33
|
*/
|
|
33
34
|
export interface FileReviewContextValue {
|
|
34
35
|
/** Each turn's file reviews from the session's fold, keyed by the turn's run id. */
|
|
@@ -93,3 +94,27 @@ export function useFileReviewRowChange(
|
|
|
93
94
|
}
|
|
94
95
|
return null;
|
|
95
96
|
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The file of its turn's review a transcript row's path refers to, or `null`
|
|
100
|
+
* when the turn has no review (review off, an embed's end user) or the path
|
|
101
|
+
* is not among its files. Its `change` says what the turn did to the file
|
|
102
|
+
* (`added` for a file the turn made), which nothing in the call itself
|
|
103
|
+
* records, so a write row reads "Created" from it.
|
|
104
|
+
*
|
|
105
|
+
* The file sibling of {@link useFileReviewRowChange}: the same newest-first
|
|
106
|
+
* walk over the turn's reviews, through the same path match.
|
|
107
|
+
*
|
|
108
|
+
* @param runId The row's turn (`ToolUse.runId`).
|
|
109
|
+
* @param rowPath The row's file path; `null` for a row that names no file.
|
|
110
|
+
*/
|
|
111
|
+
export function useFileReviewRowFile(runId: string, rowPath: string | null): FileReviewFile | null {
|
|
112
|
+
const { fileReviewByRunId } = useContext(FileReviewContext);
|
|
113
|
+
if (!rowPath) return null;
|
|
114
|
+
const sets = fileReviewByRunId.get(runId) ?? NO_SETS;
|
|
115
|
+
for (let i = sets.length - 1; i >= 0; i--) {
|
|
116
|
+
const file = fileForRowPath(sets[i]!, rowPath);
|
|
117
|
+
if (file) return file;
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
@@ -43,22 +43,19 @@ export type ToolCategory =
|
|
|
43
43
|
/**
|
|
44
44
|
* How much of a settled tool call to reveal inline by default in the thread.
|
|
45
45
|
*
|
|
46
|
-
* - `"summary"` — a
|
|
47
|
-
*
|
|
48
|
-
* `
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* - `"tail"` —
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* output is content, not context. Shell is the canonical tail category — a
|
|
60
|
-
* working session's compile/validate loops would otherwise dominate the
|
|
61
|
-
* transcript at full contrast (Cursor's chat is the reference UX).
|
|
46
|
+
* - `"summary"` — a closed one-line step that opens to its body on a click.
|
|
47
|
+
* The line says what the step did (`Read foo.ts`, `Edited bar.ts +40 −0`,
|
|
48
|
+
* `Searched for … 2 matches`); the diff, the matches or the output are one
|
|
49
|
+
* click away. Every category but a memory proposal and shell.
|
|
50
|
+
* - `"preview"` — the row renders its result body **always** (no card
|
|
51
|
+
* chevron), because the body is a decision surface: a memory proposal's
|
|
52
|
+
* fact and its Confirm/Reject actions. A host may ask for it per kind
|
|
53
|
+
* ({@link registerToolPresenter}).
|
|
54
|
+
* - `"tail"` — a summary step that stays open while it shows a failure: the
|
|
55
|
+
* full body streams in view while the tool runs (or awaits approval), it
|
|
56
|
+
* closes once it settles successfully, and a settled failure (an error or
|
|
57
|
+
* a non-zero exit) stays open, because error output is the content the
|
|
58
|
+
* person needs next. Shell is the tail category.
|
|
62
59
|
*
|
|
63
60
|
* This is the *disclosure* axis (how much of a result to show); it is
|
|
64
61
|
* orthogonal to `isRunGroupableCategory` (whether consecutive same-kind
|
|
@@ -117,38 +114,24 @@ export function defaultChromeForCategory(category: ToolCategory): ToolChrome {
|
|
|
117
114
|
}
|
|
118
115
|
|
|
119
116
|
/**
|
|
120
|
-
* Categories whose result is foregrounded as a persistent
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
117
|
+
* Categories whose result is foregrounded as a persistent preview by default.
|
|
118
|
+
* Every other category is a closed one-line step that opens to its body on a
|
|
119
|
+
* click: the line already says what the step did ("Edited invoice.ts
|
|
120
|
+
* +2 −2"), and a turn of many steps reads as a list, not a wall of bodies.
|
|
124
121
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* under control even in turns with many edits.
|
|
122
|
+
* A memory proposal is the exception: it is a decision surface, and the
|
|
123
|
+
* verbatim fact and its Confirm/Reject actions ARE the content, so it never
|
|
124
|
+
* folds behind a chevron (a proposal the user scrolled past is caught by the
|
|
125
|
+
* memory page, but the chip must not hide itself while in view).
|
|
130
126
|
*/
|
|
131
|
-
const PREVIEW_CATEGORIES: ReadonlySet<ToolCategory> = new Set<ToolCategory>([
|
|
132
|
-
"edit",
|
|
133
|
-
"write",
|
|
134
|
-
"mcp",
|
|
135
|
-
"web-search",
|
|
136
|
-
"fetch",
|
|
137
|
-
// A memory proposal is a decision surface: the verbatim fact and the
|
|
138
|
-
// Confirm/Reject actions ARE the content — never fold it behind a chevron
|
|
139
|
-
// (a proposal the user scrolled past is caught by the memory
|
|
140
|
-
// page, but the chip must not hide itself while in view).
|
|
141
|
-
"memory",
|
|
142
|
-
"unknown",
|
|
143
|
-
]);
|
|
127
|
+
const PREVIEW_CATEGORIES: ReadonlySet<ToolCategory> = new Set<ToolCategory>(["memory"]);
|
|
144
128
|
|
|
145
129
|
/**
|
|
146
|
-
* Categories that stream in full while live
|
|
147
|
-
*
|
|
148
|
-
* Today that is shell alone
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* {@link registerToolPresenter} (`disclosure: () => "preview"`).
|
|
130
|
+
* Categories that stream in full while live, close once they settle
|
|
131
|
+
* successfully, and stay open on a failure (see the `"tail"` arm of
|
|
132
|
+
* {@link ToolDisclosure}). Today that is shell alone. Consumers can restore
|
|
133
|
+
* the always-expanded preview per kind via {@link registerToolPresenter}
|
|
134
|
+
* (`disclosure: () => "preview"`).
|
|
152
135
|
*/
|
|
153
136
|
const TAIL_CATEGORIES: ReadonlySet<ToolCategory> = new Set<ToolCategory>([
|
|
154
137
|
"shell",
|
|
@@ -159,12 +142,13 @@ const TAIL_CATEGORIES: ReadonlySet<ToolCategory> = new Set<ToolCategory>([
|
|
|
159
142
|
* "Read 5 files" chip in the thread. These are the read-only, repetitive
|
|
160
143
|
* operations whose individual rows are noise in bulk; everything else renders
|
|
161
144
|
* as a persistent row. This is the *run-grouping* axis, orthogonal to
|
|
162
|
-
* {@link ToolDisclosure} — see `isRunGroupableCategory`.
|
|
145
|
+
* {@link ToolDisclosure} — see `isRunGroupableCategory`. A search is not one
|
|
146
|
+
* of them: each names its own pattern and what it found, so two searches
|
|
147
|
+
* folded into "Searched 2 times" would hide both.
|
|
163
148
|
*/
|
|
164
149
|
const RUN_GROUPABLE_CATEGORIES: ReadonlySet<ToolCategory> = new Set<ToolCategory>([
|
|
165
150
|
"read",
|
|
166
151
|
"list",
|
|
167
|
-
"search",
|
|
168
152
|
]);
|
|
169
153
|
|
|
170
154
|
/**
|
|
@@ -84,7 +84,8 @@ const NO_DECISION_ERRORS: ReadonlyMap<string, Error> = new Map();
|
|
|
84
84
|
* session's events (`FileReviewSet`).
|
|
85
85
|
*
|
|
86
86
|
* Platform builders who render their own review UI use this hook directly;
|
|
87
|
-
*
|
|
87
|
+
* the React kit's session viewer sends its Undo through the same call
|
|
88
|
+
* (`useSessionConversation().reviewFileChanges`).
|
|
88
89
|
*
|
|
89
90
|
* @example
|
|
90
91
|
* ```tsx
|
package/src/run/useRunActions.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { create } from "@bufbuild/protobuf";
|
|
|
6
6
|
import {
|
|
7
7
|
TerminateRunInputSchema,
|
|
8
8
|
PauseRunInputSchema,
|
|
9
|
+
RecoverRunInputSchema,
|
|
9
10
|
ResumeRunInputSchema,
|
|
10
11
|
} from "@stigmer/apis/ai/stigmer/agentic/run/v1/io_pb";
|
|
11
12
|
import { useStigmer } from "../hooks.js";
|
|
@@ -14,7 +15,7 @@ import { toError } from "../internal/toError.js";
|
|
|
14
15
|
/** Options for {@link useRunActions}. */
|
|
15
16
|
export interface UseRunActionsOptions {
|
|
16
17
|
/**
|
|
17
|
-
* Called after any lifecycle action (terminate, pause, resume)
|
|
18
|
+
* Called after any lifecycle action (terminate, pause, resume, recover)
|
|
18
19
|
* succeeds. Receives the updated run returned by the server.
|
|
19
20
|
* Useful for triggering a refetch so the UI reflects the new phase.
|
|
20
21
|
*/
|
|
@@ -29,6 +30,14 @@ export interface UseRunActionsReturn {
|
|
|
29
30
|
readonly pause: (reason?: string) => Promise<Run | null>;
|
|
30
31
|
/** Resume a paused run. */
|
|
31
32
|
readonly resume: () => Promise<Run | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Pick a FAILED run up where it stopped: the same turn runs again, steps
|
|
35
|
+
* that worked are not run again, and its values (a key fixed meanwhile)
|
|
36
|
+
* are read again. Needs `can_edit` on the run; refused for a run that was
|
|
37
|
+
* stopped (TERMINATED or CANCELLED) or while another turn of its session
|
|
38
|
+
* is unfinished.
|
|
39
|
+
*/
|
|
40
|
+
readonly recover: () => Promise<Run | null>;
|
|
32
41
|
/** `true` while any action is in flight. */
|
|
33
42
|
readonly isSubmitting: boolean;
|
|
34
43
|
/** Error from the last failed action, or `null`. */
|
|
@@ -39,7 +48,7 @@ export interface UseRunActionsReturn {
|
|
|
39
48
|
|
|
40
49
|
/**
|
|
41
50
|
* Behavior hook that encapsulates one run's lifecycle actions: terminate,
|
|
42
|
-
* pause and
|
|
51
|
+
* pause, resume and recover.
|
|
43
52
|
*
|
|
44
53
|
* Each action calls the corresponding RPC and returns the updated run, or
|
|
45
54
|
* `null` on failure (with `error` populated).
|
|
@@ -139,10 +148,23 @@ export function useRunActions(
|
|
|
139
148
|
[wrap],
|
|
140
149
|
);
|
|
141
150
|
|
|
151
|
+
const recover = useCallback(
|
|
152
|
+
() =>
|
|
153
|
+
wrap(() =>
|
|
154
|
+
stigmerRef.current.run.recover(
|
|
155
|
+
create(RecoverRunInputSchema, {
|
|
156
|
+
id: executionIdRef.current!,
|
|
157
|
+
}),
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
[wrap],
|
|
161
|
+
);
|
|
162
|
+
|
|
142
163
|
return {
|
|
143
164
|
terminate,
|
|
144
165
|
pause,
|
|
145
166
|
resume,
|
|
167
|
+
recover,
|
|
146
168
|
isSubmitting,
|
|
147
169
|
error,
|
|
148
170
|
clearError,
|