@colin_kerr/query-agent-react 0.0.0-stage → 0.1.1
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 +17 -2
- package/dist/AgentChat.d.ts +64 -0
- package/dist/AgentChat.js +119 -0
- package/dist/AgentChat.js.map +1 -0
- package/dist/AgentWorkbench.d.ts +32 -0
- package/dist/AgentWorkbench.js +47 -0
- package/dist/AgentWorkbench.js.map +1 -0
- package/dist/Dots.d.ts +2 -0
- package/dist/Dots.js +12 -0
- package/dist/Dots.js.map +1 -0
- package/dist/Feedback.d.ts +28 -0
- package/dist/Feedback.js +48 -0
- package/dist/Feedback.js.map +1 -0
- package/dist/ResultsTable.d.ts +22 -0
- package/dist/ResultsTable.js +106 -0
- package/dist/ResultsTable.js.map +1 -0
- package/dist/SelectElements.d.ts +26 -0
- package/dist/SelectElements.js +33 -0
- package/dist/SelectElements.js.map +1 -0
- package/dist/chat.d.ts +30 -0
- package/dist/chat.js +15 -0
- package/dist/chat.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/selection.d.ts +88 -0
- package/dist/selection.js +121 -0
- package/dist/selection.js.map +1 -0
- package/dist/styles.css +49 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Colin Kerr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @colin_kerr/query-agent-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React controls for the query agent: `AgentChat` (the chat and the ask box), `AgentWorkbench` (the
|
|
4
|
+
chat with the answer's results and earlier chats beside it), the feedback form, and selecting an
|
|
5
|
+
answer's elements.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { AgentWorkbench } from "@colin_kerr/query-agent-react";
|
|
9
|
+
import "@colin_kerr/query-agent-react/styles.css";
|
|
10
|
+
|
|
11
|
+
<AgentWorkbench client={client} editorText={() => editor.value} onUseQuery={(ecsql) => editor.setValue(ecsql)} />
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`client` is a started `AgentClient` from `@colin_kerr/query-agent-client`. The controls upload
|
|
15
|
+
nothing: feedback goes to your `onFeedback` handler. The full guide and the design are in the
|
|
16
|
+
[repository](https://github.com/ColinKerr/query_agent_ui).
|
|
17
|
+
|
|
18
|
+
Needs React 18.3.1 or later 18.x. MIT licence.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The core control: the chat window and the ask box. A host starts an `AgentClient` for its open
|
|
3
|
+
* iModel and passes it in; the control does the rest.
|
|
4
|
+
*/
|
|
5
|
+
import { type ReactNode } from "react";
|
|
6
|
+
import { TurnRefused, type AgentClient, type AgentRun, type AgentStatus } from "@colin_kerr/query-agent-client";
|
|
7
|
+
import { type Chat, type ChatTurn } from "./chat.js";
|
|
8
|
+
import { type Feedback } from "./Feedback.js";
|
|
9
|
+
import { type AnswerSelection } from "./SelectElements.js";
|
|
10
|
+
export interface AgentChatProps {
|
|
11
|
+
/** The started client, or undefined when the agent is not set up. */
|
|
12
|
+
client?: AgentClient;
|
|
13
|
+
/** The text in the host's query editor, read when a question is asked. */
|
|
14
|
+
editorText?: () => string | undefined;
|
|
15
|
+
/** A chat to start from, such as one the host kept. */
|
|
16
|
+
initialChat?: Chat;
|
|
17
|
+
/** Called whenever the chat changes, so a host can keep it. */
|
|
18
|
+
onChange?: (chat: Chat) => void;
|
|
19
|
+
/** Called with each finished answer. */
|
|
20
|
+
onAnswer?: (answer: {
|
|
21
|
+
question: string;
|
|
22
|
+
answer: string;
|
|
23
|
+
query?: string;
|
|
24
|
+
outcome?: string;
|
|
25
|
+
}) => void;
|
|
26
|
+
/** Called with each finished run, whole. */
|
|
27
|
+
onRunFinished?: (run: AgentRun, question: string) => void;
|
|
28
|
+
/**
|
|
29
|
+
* The function refused a question for a reason the user can act on (`TurnRefused`): 401 or 403
|
|
30
|
+
* ask for an access key, 429 means the key is used up, 413 that the request is too long. The control shows the function's sentence;
|
|
31
|
+
* a host can ask for a key here.
|
|
32
|
+
*/
|
|
33
|
+
onRefused?: (refusal: TurnRefused) => void;
|
|
34
|
+
/** Offered beside an answer's query: put it in the host's editor. */
|
|
35
|
+
onUseQuery?: (ecsql: string) => void;
|
|
36
|
+
/** When set, each answer has the feedback form, and what the user chooses to send goes here. */
|
|
37
|
+
onFeedback?: (feedback: Feedback) => void | Promise<void>;
|
|
38
|
+
/** Drawn under each finished answer, in place of the feedback form. */
|
|
39
|
+
renderAfterAnswer?: (turn: ChatTurn, index: number) => ReactNode;
|
|
40
|
+
/** Drawn after the questions. */
|
|
41
|
+
renderAfterChat?: (chat: Chat, status: AgentStatus | undefined) => ReactNode;
|
|
42
|
+
/** Called with each status and step while a run is in progress. */
|
|
43
|
+
onStatus?: (status: AgentStatus | undefined) => void;
|
|
44
|
+
placeholder?: string;
|
|
45
|
+
/** Why there is no client, in place of saying the agent is not set up. */
|
|
46
|
+
unavailable?: string;
|
|
47
|
+
/** A question for the control to ask, as if typed: asked when `key` changes (a host's own "Ask" button). */
|
|
48
|
+
question?: {
|
|
49
|
+
text: string;
|
|
50
|
+
key: string | number;
|
|
51
|
+
};
|
|
52
|
+
/** The host's own buttons under each finished answer. */
|
|
53
|
+
answerActions?: (turn: ChatTurn, index: number) => ReactNode;
|
|
54
|
+
/**
|
|
55
|
+
* The host's unified selection. Each answer that names elements offers "Select N elements",
|
|
56
|
+
* before the host's own buttons; with `autoSelect`, every element of an answer that names
|
|
57
|
+
* elements (rows with `ECInstanceId` and `ClassName`) replaces the selection
|
|
58
|
+
* once the answer is shown.
|
|
59
|
+
*/
|
|
60
|
+
selection?: AnswerSelection;
|
|
61
|
+
}
|
|
62
|
+
/** What the user sees while the agent works. */
|
|
63
|
+
export declare function statusLabel(status: AgentStatus | undefined): string;
|
|
64
|
+
export declare function AgentChat(props: AgentChatProps): JSX.Element;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The core control: the chat window and the ask box. A host starts an `AgentClient` for its open
|
|
4
|
+
* iModel and passes it in; the control does the rest.
|
|
5
|
+
*/
|
|
6
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
7
|
+
import { TurnRefused } from "@colin_kerr/query-agent-client";
|
|
8
|
+
import { contextOf, FAILED } from "./chat.js";
|
|
9
|
+
import { Dots } from "./Dots.js";
|
|
10
|
+
import { FeedbackForm } from "./Feedback.js";
|
|
11
|
+
import { SelectElements } from "./SelectElements.js";
|
|
12
|
+
import { selectableOf, selectAnswerElements, selectsNothing } from "./selection.js";
|
|
13
|
+
/** Select an answer's elements as it arrives. A failure here must not lose the answer. */
|
|
14
|
+
async function autoSelect(run, client, selection) {
|
|
15
|
+
try {
|
|
16
|
+
const result = await selectAnswerElements(run, client, selection.storage, selection.imodelKey);
|
|
17
|
+
if (result)
|
|
18
|
+
selection.onSelected?.(result, run);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// The button under the answer still offers the selection, and says what went wrong.
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** What the user sees while the agent works. */
|
|
25
|
+
export function statusLabel(status) {
|
|
26
|
+
switch (status?.phase) {
|
|
27
|
+
case "exploring": return "Exploring";
|
|
28
|
+
case "querying": return "Running a query";
|
|
29
|
+
default: return "Thinking";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function AgentChat(props) {
|
|
33
|
+
const { client, editorText, onChange, onAnswer, onRunFinished, onRefused, onUseQuery, onFeedback, renderAfterChat, onStatus } = props;
|
|
34
|
+
const renderAfterAnswer = props.renderAfterAnswer
|
|
35
|
+
?? (onFeedback ? (turn) => (turn.run ? _jsx(FeedbackForm, { turn: turn, onFeedback: onFeedback }) : null) : undefined);
|
|
36
|
+
const [chat, setChat] = useState(props.initialChat ?? { turns: [] });
|
|
37
|
+
const [question, setQuestion] = useState("");
|
|
38
|
+
const [status, setStatus] = useState();
|
|
39
|
+
const [busy, setBusy] = useState(false);
|
|
40
|
+
const stop = useRef(undefined);
|
|
41
|
+
const end = useRef(null);
|
|
42
|
+
const update = useCallback((next) => {
|
|
43
|
+
setChat(next);
|
|
44
|
+
onChange?.(next);
|
|
45
|
+
}, [onChange]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
end.current?.scrollIntoView?.({ block: "end" });
|
|
48
|
+
}, [chat, status]);
|
|
49
|
+
const report = (next) => {
|
|
50
|
+
setStatus(next);
|
|
51
|
+
onStatus?.(next);
|
|
52
|
+
};
|
|
53
|
+
const ask = async (asked) => {
|
|
54
|
+
const text = (asked ?? question).trim();
|
|
55
|
+
if (!client || busy || text.length === 0)
|
|
56
|
+
return;
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
stop.current = controller;
|
|
59
|
+
setBusy(true);
|
|
60
|
+
setQuestion("");
|
|
61
|
+
const before = chat;
|
|
62
|
+
const asking = { turns: [...before.turns, { question: text, answer: "" }] };
|
|
63
|
+
update(asking);
|
|
64
|
+
let turn;
|
|
65
|
+
try {
|
|
66
|
+
const run = await client.ask(text, {
|
|
67
|
+
...(await contextOf(before)),
|
|
68
|
+
editorText: editorText?.(),
|
|
69
|
+
signal: controller.signal,
|
|
70
|
+
onStatus: report,
|
|
71
|
+
});
|
|
72
|
+
const outcome = run.structured?.outcome ?? run.stoppedBecause;
|
|
73
|
+
turn = { question: text, answer: run.structured?.explanation ?? run.answer, query: run.structured?.query ?? run.query, outcome, run };
|
|
74
|
+
onRunFinished?.(run, text);
|
|
75
|
+
onAnswer?.({ question: text, answer: turn.answer, query: turn.query, outcome });
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
// A refusal the user can act on is shown as the function said it; anything else is a failure.
|
|
79
|
+
if (err instanceof TurnRefused) {
|
|
80
|
+
turn = { question: text, answer: "", error: err.message };
|
|
81
|
+
onRefused?.(err);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
turn = { question: text, answer: "", error: FAILED };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
update({ turns: [...before.turns, turn] });
|
|
88
|
+
report(undefined);
|
|
89
|
+
// After the answer is shown: selecting a million elements must not hold the answer back.
|
|
90
|
+
if (turn.run && props.selection?.autoSelect && (selectableOf(turn.run) || selectsNothing(turn.run)))
|
|
91
|
+
void autoSelect(turn.run, client, props.selection);
|
|
92
|
+
setBusy(false);
|
|
93
|
+
stop.current = undefined;
|
|
94
|
+
};
|
|
95
|
+
// A question the host asks: once for each key, when the control is free.
|
|
96
|
+
const hostQuestion = props.question;
|
|
97
|
+
const askedKey = useRef(undefined);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (!hostQuestion || hostQuestion.key === askedKey.current || !client || busy)
|
|
100
|
+
return;
|
|
101
|
+
askedKey.current = hostQuestion.key;
|
|
102
|
+
void ask(hostQuestion.text);
|
|
103
|
+
});
|
|
104
|
+
const onKeyDown = (event) => {
|
|
105
|
+
// Enter asks; Shift+Enter is a new line. A question is usually one line.
|
|
106
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
void ask();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return (_jsxs("div", { className: "qa-chat", children: [_jsxs("div", { className: "qa-messages", "aria-live": "polite", children: [!client && _jsx("div", { className: "qa-notice", children: props.unavailable ?? "The agent is not set up." }), chat.turns.map((turn, index) => (_jsxs("div", { className: "qa-turn", children: [_jsx("div", { className: "qa-question", children: turn.question }), turn.error
|
|
112
|
+
? _jsx("div", { className: "qa-error", children: turn.error })
|
|
113
|
+
: turn.run || turn.answer
|
|
114
|
+
? (_jsxs("div", { className: "qa-answer", children: [_jsx("div", { className: "qa-answer-text", children: turn.answer }), turn.query && (_jsxs("div", { className: "qa-query", children: [_jsx("pre", { children: _jsx("code", { children: turn.query }) }), onUseQuery && _jsx("button", { type: "button", onClick: () => onUseQuery(turn.query), children: "Use this query" })] })), (props.answerActions || (props.selection && client)) && (_jsxs("div", { className: "qa-answer-actions", children: [props.selection && client && _jsx(SelectElements, { run: turn.run, client: client, selection: props.selection }), props.answerActions?.(turn, index)] })), renderAfterAnswer?.(turn, index)] }))
|
|
115
|
+
: (_jsxs("div", { className: "qa-progress", role: "status", children: [statusLabel(status), _jsx(Dots, {})] }))] }, index))), renderAfterChat?.(chat, status), _jsx("div", { ref: end })] }), _jsxs("div", { className: "qa-compose", children: [_jsx("textarea", { className: "qa-input", rows: 3, value: question, disabled: !client || busy, placeholder: props.placeholder ?? "Ask for a query. Enter to send, Shift+Enter for a new line.", onChange: (event) => setQuestion(event.target.value), onKeyDown: onKeyDown }), _jsxs("div", { className: "qa-controls", children: [_jsx("button", { type: "button", onClick: () => update({ turns: [] }), disabled: busy, children: "New chat" }), busy
|
|
116
|
+
? _jsx("button", { type: "button", onClick: () => stop.current?.abort(), children: "Stop" })
|
|
117
|
+
: _jsx("button", { type: "button", onClick: () => void ask(), disabled: !client || question.trim().length === 0, children: "Ask" })] })] })] }));
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=AgentChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChat.js","sourceRoot":"","sources":["../src/AgentChat.tsx"],"names":[],"mappings":";AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAsC,MAAM,OAAO,CAAC;AACrG,OAAO,EAAE,WAAW,EAAqD,MAAM,gCAAgC,CAAC;AAChH,OAAO,EAAE,SAAS,EAAE,MAAM,EAA4B,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAiB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA+CpF,0FAA0F;AAC1F,KAAK,UAAU,UAAU,CAAC,GAAa,EAAE,MAAmB,EAAE,SAA0B;IACtF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QAC/F,IAAI,MAAM;YACR,SAAS,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,GAAG,C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AC,EAAC,KAAC,IAAI,KAAG,IACzB,CACP,KA3BuB,KAAK,CA4B7B,CACP,CAAC,EACD,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAChC,cAAK,GAAG,EAAE,GAAG,GAAI,IACb,EACN,eAAK,SAAS,EAAC,YAAY,aACzB,mBACE,SAAS,EAAC,UAAU,EACpB,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,CAAC,MAAM,IAAI,IAAI,EACzB,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,6DAA6D,EAC/F,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EACpD,SAAS,EAAE,SAAS,GACpB,EACF,eAAK,SAAS,EAAC,aAAa,aAC1B,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,yBAAmB,EAC5F,IAAI;gCACH,CAAC,CAAC,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,qBAAe;gCAC3E,CAAC,CAAC,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,MAAM,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,oBAAc,IAChH,IACF,IACF,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The larger control: the chat, with the answer's results and the earlier chats of this page
|
|
3
|
+
* beside it. It has no query editor of its own: a query goes to the host's editor (`onUseQuery`).
|
|
4
|
+
*
|
|
5
|
+
* It shows nothing of how the agent worked: no steps, no notes. Those are the agent's private
|
|
6
|
+
* data, which the client keeps for the next question and never shows.
|
|
7
|
+
*/
|
|
8
|
+
import type { AnswerRows, ResultPages } from "@colin_kerr/query-agent-client";
|
|
9
|
+
import { type AgentChatProps } from "./AgentChat.js";
|
|
10
|
+
import type { Chat } from "./chat.js";
|
|
11
|
+
export type AgentWorkbenchProps = Omit<AgentChatProps, "renderAfterAnswer" | "renderAfterChat" | "initialChat"> & {
|
|
12
|
+
/**
|
|
13
|
+
* Show the last answer's results in a Results tab beside the chat. True by default. A host that
|
|
14
|
+
* shows them elsewhere (with `AnswerResults`, from `onChange`) sets it to false.
|
|
15
|
+
*/
|
|
16
|
+
showResults?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** The last answer's results in a chat, or undefined when no answer has finished. */
|
|
19
|
+
export declare function lastAnswer(chat: Chat): {
|
|
20
|
+
question: string;
|
|
21
|
+
rows?: AnswerRows;
|
|
22
|
+
results?: ResultPages;
|
|
23
|
+
} | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* An answer's results, with no row limit: a virtualized table (`ResultsTable`) that reads its rows
|
|
26
|
+
* a page at a time from `results` as it scrolls, starting from the rows the client first read.
|
|
27
|
+
*/
|
|
28
|
+
export declare function AnswerResults(props: {
|
|
29
|
+
rows?: AnswerRows;
|
|
30
|
+
results?: ResultPages;
|
|
31
|
+
}): JSX.Element;
|
|
32
|
+
export declare function AgentWorkbench(props: AgentWorkbenchProps): JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The larger control: the chat, with the answer's results and the earlier chats of this page
|
|
4
|
+
* beside it. It has no query editor of its own: a query goes to the host's editor (`onUseQuery`).
|
|
5
|
+
*
|
|
6
|
+
* It shows nothing of how the agent worked: no steps, no notes. Those are the agent's private
|
|
7
|
+
* data, which the client keeps for the next question and never shows.
|
|
8
|
+
*/
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import { ResultsTable } from "./ResultsTable.js";
|
|
11
|
+
import { AgentChat } from "./AgentChat.js";
|
|
12
|
+
/** The last answer's results in a chat, or undefined when no answer has finished. */
|
|
13
|
+
export function lastAnswer(chat) {
|
|
14
|
+
const last = [...chat.turns].reverse().find((turn) => turn.run);
|
|
15
|
+
return last && { question: last.question, rows: last.run?.answerRows, results: last.run?.results };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* An answer's results, with no row limit: a virtualized table (`ResultsTable`) that reads its rows
|
|
19
|
+
* a page at a time from `results` as it scrolls, starting from the rows the client first read.
|
|
20
|
+
*/
|
|
21
|
+
export function AnswerResults(props) {
|
|
22
|
+
return _jsx(ResultsTable, { rows: props.rows, results: props.results });
|
|
23
|
+
}
|
|
24
|
+
export function AgentWorkbench(props) {
|
|
25
|
+
const { client, onChange, showResults = true, ...chatProps } = props;
|
|
26
|
+
const [chat, setChat] = useState({ turns: [] });
|
|
27
|
+
const [history, setHistory] = useState([]);
|
|
28
|
+
const [opened, setOpened] = useState({ chat: { turns: [] }, key: 0 });
|
|
29
|
+
const tabs = showResults ? ["results", "history"] : ["history"];
|
|
30
|
+
const [chosen, setTab] = useState("results");
|
|
31
|
+
const tab = tabs.includes(chosen) ? chosen : tabs[0];
|
|
32
|
+
const changed = (next) => {
|
|
33
|
+
// "New chat" empties the chat: the one before goes into the history.
|
|
34
|
+
if (next.turns.length === 0 && chat.turns.length > 0)
|
|
35
|
+
setHistory((earlier) => [chat, ...earlier]);
|
|
36
|
+
setChat(next);
|
|
37
|
+
onChange?.(next);
|
|
38
|
+
};
|
|
39
|
+
const reopen = (earlier) => {
|
|
40
|
+
setHistory((list) => [...(chat.turns.length > 0 ? [chat] : []), ...list.filter((item) => item !== earlier)]);
|
|
41
|
+
setChat(earlier);
|
|
42
|
+
onChange?.(earlier);
|
|
43
|
+
setOpened({ chat: earlier, key: opened.key + 1 });
|
|
44
|
+
};
|
|
45
|
+
return (_jsx("div", { className: "qa-workbench-frame", children: _jsxs("div", { className: "qa-workbench", children: [_jsx("div", { className: "qa-workbench-chat", children: _jsx(AgentChat, { ...chatProps, client: client, initialChat: opened.chat, onChange: changed }, opened.key) }), _jsxs("div", { className: "qa-workbench-side", children: [_jsx("div", { className: "qa-tabs", role: "tablist", children: tabs.map((name) => (_jsx("button", { type: "button", role: "tab", "aria-selected": tab === name, onClick: () => setTab(name), children: { results: "Results", history: "History" }[name] }, name))) }), tab === "results" && _jsx(AnswerResults, { rows: lastAnswer(chat)?.rows, results: lastAnswer(chat)?.results }), tab === "history" && (_jsxs("ul", { className: "qa-history", children: [history.map((earlier, i) => (_jsx("li", { children: _jsx("button", { type: "button", onClick: () => reopen(earlier), children: earlier.turns[0]?.question ?? "(empty)" }) }, i))), history.length === 0 && _jsx("li", { className: "qa-muted", children: "No earlier chats." })] }))] })] }) }));
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=AgentWorkbench.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentWorkbench.js","sourceRoot":"","sources":["../src/AgentWorkbench.tsx"],"names":[],"mappings":";AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAuB,MAAM,gBAAgB,CAAC;AAahE,qFAAqF;AACrF,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChE,OAAO,IAAI,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,GAA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YACjG,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,IADgB,IAAI,CAE9D,CACV,CAAC,GACE,EACL,GAAG,KAAK,SAAS,IAAI,KAAC,aAAa,IAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,GAAI,EACxG,GAAG,KAAK,SAAS,IAAI,CACpB,cAAI,SAAS,EAAC,YAAY,aACvB,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAC3B,uBAAY,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,YAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,IAAI,SAAS,GAAU,IAA3G,CAAC,CAA+G,CAC1H,CAAC,EACD,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,aAAI,SAAS,EAAC,UAAU,kCAAuB,IACrE,CACN,IACG,IACF,GACA,CACP,CAAC;AACJ,CAAC"}
|
package/dist/Dots.d.ts
ADDED
package/dist/Dots.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
/** ".", "..", "...", and round again: a wait that is moving, so it is not mistaken for a hang. */
|
|
4
|
+
export function Dots() {
|
|
5
|
+
const [count, setCount] = useState(1);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const timer = setInterval(() => setCount((n) => (n % 3) + 1), 400);
|
|
8
|
+
return () => clearInterval(timer);
|
|
9
|
+
}, []);
|
|
10
|
+
return _jsx("span", { className: "qa-dots", "aria-hidden": "true", children: ".".repeat(count) });
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Dots.js.map
|
package/dist/Dots.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dots.js","sourceRoot":"","sources":["../src/Dots.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,kGAAkG;AAClG,MAAM,UAAU,IAAI;IAClB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACnE,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,eAAM,SAAS,EAAC,SAAS,iBAAa,MAAM,YAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAQ,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The feedback form under an answer. The user rates the answer, may correct its text or its query,
|
|
3
|
+
* may add a comment, then sees exactly what would be sent and chooses to send it. It holds only
|
|
4
|
+
* what the user saw and wrote: the question, the answer, the query, and the user's own text.
|
|
5
|
+
* Nothing is uploaded by the control: the host gets the feedback (`onFeedback`) and decides.
|
|
6
|
+
*/
|
|
7
|
+
import type { ChatTurn } from "./chat.js";
|
|
8
|
+
export type Rating = "right" | "partly" | "wrong";
|
|
9
|
+
/** What is sent: everything here was shown to, or written by, the user. */
|
|
10
|
+
export interface Feedback {
|
|
11
|
+
question: string;
|
|
12
|
+
answer: string;
|
|
13
|
+
query?: string;
|
|
14
|
+
rating: Rating;
|
|
15
|
+
correctedAnswer?: string;
|
|
16
|
+
correctedQuery?: string;
|
|
17
|
+
comment?: string;
|
|
18
|
+
}
|
|
19
|
+
/** The feedback for a turn, with empty text left out. */
|
|
20
|
+
export declare function feedbackOf(turn: ChatTurn, rating: Rating, edits: {
|
|
21
|
+
correctedAnswer?: string;
|
|
22
|
+
correctedQuery?: string;
|
|
23
|
+
comment?: string;
|
|
24
|
+
}): Feedback;
|
|
25
|
+
export declare function FeedbackForm(props: {
|
|
26
|
+
turn: ChatTurn;
|
|
27
|
+
onFeedback: (feedback: Feedback) => void | Promise<void>;
|
|
28
|
+
}): JSX.Element;
|
package/dist/Feedback.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The feedback form under an answer. The user rates the answer, may correct its text or its query,
|
|
4
|
+
* may add a comment, then sees exactly what would be sent and chooses to send it. It holds only
|
|
5
|
+
* what the user saw and wrote: the question, the answer, the query, and the user's own text.
|
|
6
|
+
* Nothing is uploaded by the control: the host gets the feedback (`onFeedback`) and decides.
|
|
7
|
+
*/
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
/** The feedback for a turn, with empty text left out. */
|
|
10
|
+
export function feedbackOf(turn, rating, edits) {
|
|
11
|
+
const text = (value) => (value && value.trim().length > 0 ? value.trim() : undefined);
|
|
12
|
+
const correctedAnswer = text(edits.correctedAnswer);
|
|
13
|
+
const correctedQuery = text(edits.correctedQuery);
|
|
14
|
+
const comment = text(edits.comment);
|
|
15
|
+
return {
|
|
16
|
+
question: turn.question,
|
|
17
|
+
answer: turn.answer,
|
|
18
|
+
...(turn.query ? { query: turn.query } : {}),
|
|
19
|
+
rating,
|
|
20
|
+
...(correctedAnswer && correctedAnswer !== turn.answer.trim() ? { correctedAnswer } : {}),
|
|
21
|
+
...(correctedQuery && correctedQuery !== turn.query?.trim() ? { correctedQuery } : {}),
|
|
22
|
+
...(comment ? { comment } : {}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const RATINGS = [
|
|
26
|
+
{ value: "right", label: "Right" },
|
|
27
|
+
{ value: "partly", label: "Partly right" },
|
|
28
|
+
{ value: "wrong", label: "Wrong" },
|
|
29
|
+
];
|
|
30
|
+
export function FeedbackForm(props) {
|
|
31
|
+
const { turn } = props;
|
|
32
|
+
const [rating, setRating] = useState();
|
|
33
|
+
const [correctedAnswer, setCorrectedAnswer] = useState(turn.answer);
|
|
34
|
+
const [correctedQuery, setCorrectedQuery] = useState(turn.query ?? "");
|
|
35
|
+
const [comment, setComment] = useState("");
|
|
36
|
+
const [stage, setStage] = useState("rate");
|
|
37
|
+
if (stage === "sent")
|
|
38
|
+
return _jsx("div", { className: "qa-feedback qa-feedback-sent", children: "Thank you. Your feedback was sent." });
|
|
39
|
+
if (!rating) {
|
|
40
|
+
return (_jsxs("div", { className: "qa-feedback", role: "group", "aria-label": "Rate this answer", children: [_jsx("span", { children: "Was this answer right?" }), RATINGS.map((option) => (_jsx("button", { type: "button", onClick: () => setRating(option.value), children: option.label }, option.value)))] }));
|
|
41
|
+
}
|
|
42
|
+
const feedback = feedbackOf(turn, rating, { correctedAnswer, correctedQuery, comment });
|
|
43
|
+
if (stage === "review") {
|
|
44
|
+
return (_jsxs("div", { className: "qa-feedback", children: [_jsx("div", { children: "This is exactly what will be sent:" }), _jsx("pre", { className: "qa-feedback-preview", children: JSON.stringify(feedback, null, 2) }), _jsx("button", { type: "button", onClick: () => setStage("rate"), children: "Edit" }), _jsx("button", { type: "button", onClick: () => void Promise.resolve(props.onFeedback(feedback)).then(() => setStage("sent")), children: "Send" }), _jsx("button", { type: "button", onClick: () => setRating(undefined), children: "Cancel" })] }));
|
|
45
|
+
}
|
|
46
|
+
return (_jsxs("div", { className: "qa-feedback", children: [_jsxs("div", { children: ["Rated: ", RATINGS.find((option) => option.value === rating)?.label, ". You can correct the answer or the query, and add a comment."] }), _jsxs("label", { children: ["The right answer", _jsx("textarea", { value: correctedAnswer, onChange: (event) => setCorrectedAnswer(event.target.value), rows: 3 })] }), turn.query !== undefined && (_jsxs("label", { children: ["The right query", _jsx("textarea", { value: correctedQuery, onChange: (event) => setCorrectedQuery(event.target.value), rows: 4 })] })), _jsxs("label", { children: ["Comment", _jsx("textarea", { value: comment, onChange: (event) => setComment(event.target.value), rows: 2 })] }), _jsx("button", { type: "button", onClick: () => setStage("review"), children: "Review what will be sent" }), _jsx("button", { type: "button", onClick: () => setRating(undefined), children: "Cancel" })] }));
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=Feedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Feedback.js","sourceRoot":"","sources":["../src/Feedback.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAgBjC,yDAAyD;AACzD,MAAM,UAAU,UAAU,CAAC,IAAc,EAAE,MAAc,EAAE,KAA8E;IACvI,MAAM,IAAI,GAAG,CAAC,KAAyB,EAAsB,EAAE,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC9H,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACpD,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,MAAM;QACN,GAAG,CAAC,eAAe,IAAI,eAAe,KAAK,IA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CAAC,KAAK,KAAK,MAAM,CAAC,EAAE,KAAK,qEAAoE,EACzI,gDAAuB,mBAAU,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,GAAI,IAAQ,EACxI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,CAC3B,+CAAsB,mBAAU,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,GAAI,IAAQ,CACvI,EACD,uCAAc,mBAAU,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,GAAI,IAAQ,EAChH,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,yCAAmC,EAC1F,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,uBAAiB,IACtE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An answer's results as a virtualized table, with no row limit.
|
|
3
|
+
*
|
|
4
|
+
* Only the rows in view (and a few either side) are drawn: the rows above and below are two spacer
|
|
5
|
+
* rows of the right height, so the scroll bar is the whole result's. A result taller than
|
|
6
|
+
* `MAX_SCROLL_HEIGHT` gets a scaled scroll bar. The rows come from the run's
|
|
7
|
+
* `ResultPages`, which reads them a page at a time through the query reader as the table scrolls.
|
|
8
|
+
* Without one (a host that gives rows only), the rows given are shown.
|
|
9
|
+
*/
|
|
10
|
+
import type { AnswerRows, ResultPages } from "@colin_kerr/query-agent-client";
|
|
11
|
+
/** The height of one row, in pixels: `.qa-results td` in `styles.css` keeps rows to one line of it. */
|
|
12
|
+
export declare const ROW_HEIGHT = 22;
|
|
13
|
+
/**
|
|
14
|
+
* The tallest the scrolled content is made, in pixels. Browsers stop drawing taller elements
|
|
15
|
+
* (Chrome near 33.5 million pixels, Firefox near 17.9 million), which at 22px a row is about 1.5
|
|
16
|
+
* million rows in Chrome. Past this the scroll bar is scaled, so every row can still be reached.
|
|
17
|
+
*/
|
|
18
|
+
export declare const MAX_SCROLL_HEIGHT = 15000000;
|
|
19
|
+
export declare function ResultsTable(props: {
|
|
20
|
+
rows?: AnswerRows;
|
|
21
|
+
results?: ResultPages;
|
|
22
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* An answer's results as a virtualized table, with no row limit.
|
|
4
|
+
*
|
|
5
|
+
* Only the rows in view (and a few either side) are drawn: the rows above and below are two spacer
|
|
6
|
+
* rows of the right height, so the scroll bar is the whole result's. A result taller than
|
|
7
|
+
* `MAX_SCROLL_HEIGHT` gets a scaled scroll bar. The rows come from the run's
|
|
8
|
+
* `ResultPages`, which reads them a page at a time through the query reader as the table scrolls.
|
|
9
|
+
* Without one (a host that gives rows only), the rows given are shown.
|
|
10
|
+
*/
|
|
11
|
+
import { useEffect, useReducer, useRef, useState } from "react";
|
|
12
|
+
/** The height of one row, in pixels: `.qa-results td` in `styles.css` keeps rows to one line of it. */
|
|
13
|
+
export const ROW_HEIGHT = 22;
|
|
14
|
+
/** Rows drawn beyond the view on each side, so a short scroll shows rows already drawn. */
|
|
15
|
+
const OVERSCAN = 20;
|
|
16
|
+
/**
|
|
17
|
+
* The tallest the scrolled content is made, in pixels. Browsers stop drawing taller elements
|
|
18
|
+
* (Chrome near 33.5 million pixels, Firefox near 17.9 million), which at 22px a row is about 1.5
|
|
19
|
+
* million rows in Chrome. Past this the scroll bar is scaled, so every row can still be reached.
|
|
20
|
+
*/
|
|
21
|
+
export const MAX_SCROLL_HEIGHT = 15_000_000;
|
|
22
|
+
/** The rows assumed visible before the table has been measured (and under jsdom, which has no layout). */
|
|
23
|
+
const DEFAULT_VISIBLE = 40;
|
|
24
|
+
function cellText(value) {
|
|
25
|
+
return value === null || value === undefined ? "null" : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
26
|
+
}
|
|
27
|
+
function sourceOf(rows, results) {
|
|
28
|
+
if (results) {
|
|
29
|
+
// Until the pages arrive, the rows the client first read stand in for them.
|
|
30
|
+
const firstRows = rows?.error === undefined ? rows?.rows ?? [] : [];
|
|
31
|
+
return {
|
|
32
|
+
columns: results.columns ?? rows?.columns ?? [],
|
|
33
|
+
count: results.count ?? Math.max(results.atLeast, firstRows.length),
|
|
34
|
+
more: results.count === undefined,
|
|
35
|
+
row: (index) => results.row(index) ?? firstRows[index],
|
|
36
|
+
error: results.error,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (!rows || rows.error !== undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
const list = rows.rows ?? [];
|
|
42
|
+
return { columns: rows.columns ?? [], count: list.length, more: rows.truncatedBy !== undefined, row: (index) => list[index] };
|
|
43
|
+
}
|
|
44
|
+
export function ResultsTable(props) {
|
|
45
|
+
const { rows, results } = props;
|
|
46
|
+
const [, changed] = useReducer((n) => n + 1, 0);
|
|
47
|
+
const scroller = useRef(null);
|
|
48
|
+
const [top, setTop] = useState(0);
|
|
49
|
+
const header = useRef(null);
|
|
50
|
+
// The height the rows can use: the scroller's, less the header that stays at its top.
|
|
51
|
+
const [viewPx, setViewPx] = useState(DEFAULT_VISIBLE * ROW_HEIGHT);
|
|
52
|
+
useEffect(() => results?.subscribe(changed), [results]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
setTop(0);
|
|
55
|
+
if (scroller.current)
|
|
56
|
+
scroller.current.scrollTop = 0;
|
|
57
|
+
}, [results, rows]);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const element = scroller.current;
|
|
60
|
+
if (!element || typeof ResizeObserver === "undefined")
|
|
61
|
+
return;
|
|
62
|
+
const measure = () => setViewPx(element.clientHeight > 0
|
|
63
|
+
? Math.max(ROW_HEIGHT, element.clientHeight - (header.current?.offsetHeight ?? 0))
|
|
64
|
+
: DEFAULT_VISIBLE * ROW_HEIGHT);
|
|
65
|
+
measure();
|
|
66
|
+
const observer = new ResizeObserver(measure);
|
|
67
|
+
observer.observe(element);
|
|
68
|
+
return () => observer.disconnect();
|
|
69
|
+
}, []);
|
|
70
|
+
const source = sourceOf(rows, results);
|
|
71
|
+
// With pages and no rows read yet, the count is 0: ask for the first rows to learn more.
|
|
72
|
+
const knownCount = source?.count ?? 0;
|
|
73
|
+
// Past MAX_SCROLL_HEIGHT the scroll bar is scaled: a scroll position stands for a row further on.
|
|
74
|
+
// The scroll position runs from 0 to height - viewPx; it stands for 0 to full - viewPx in rows.
|
|
75
|
+
const full = knownCount * ROW_HEIGHT;
|
|
76
|
+
const height = Math.min(full, MAX_SCROLL_HEIGHT);
|
|
77
|
+
const visible = Math.ceil(viewPx / ROW_HEIGHT) + 1;
|
|
78
|
+
const ratio = full > height && height > viewPx ? (full - viewPx) / (height - viewPx) : 1;
|
|
79
|
+
const virtualTop = Math.min(top * ratio, Math.max(0, full - viewPx));
|
|
80
|
+
const firstInView = Math.floor(virtualTop / ROW_HEIGHT);
|
|
81
|
+
const first = Math.max(0, firstInView - OVERSCAN);
|
|
82
|
+
const last = Math.min(source?.more ? Math.max(knownCount, first + visible + 2 * OVERSCAN) : knownCount, firstInView + visible + OVERSCAN);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
results?.want(first, last);
|
|
85
|
+
}, [results, first, last]);
|
|
86
|
+
if (rows?.error !== undefined)
|
|
87
|
+
return _jsx("div", { className: "qa-error", children: rows.error });
|
|
88
|
+
if (!source)
|
|
89
|
+
return _jsx("div", { className: "qa-muted", children: "No results yet." });
|
|
90
|
+
const drawn = [];
|
|
91
|
+
for (let index = first; index < Math.min(last, knownCount); index++) {
|
|
92
|
+
const row = source.row(index);
|
|
93
|
+
drawn.push(_jsx("tr", { style: { height: ROW_HEIGHT }, children: source.columns.map((_, c) => _jsx("td", { children: row ? cellText(row[c]) : "" }, c)) }, index));
|
|
94
|
+
}
|
|
95
|
+
// The drawn rows sit where the view is: their first visible row at the top of the view.
|
|
96
|
+
// In both cases the spacers and the drawn rows add up to `height` exactly, so the content never
|
|
97
|
+
// changes height as the rows are redrawn (which made the browser move the scroll position).
|
|
98
|
+
const drawnPx = drawn.length * ROW_HEIGHT;
|
|
99
|
+
const above = ratio === 1
|
|
100
|
+
? first * ROW_HEIGHT
|
|
101
|
+
: Math.round(Math.min(Math.max(0, top - (virtualTop - first * ROW_HEIGHT)), Math.max(0, height - drawnPx)));
|
|
102
|
+
const below = Math.max(0, height - above - drawnPx);
|
|
103
|
+
const counted = source.more ? `${knownCount.toLocaleString()}+ rows` : `${knownCount.toLocaleString()} ${knownCount === 1 ? "row" : "rows"}`;
|
|
104
|
+
return (_jsxs("div", { className: "qa-results", children: [_jsx("div", { className: "qa-results-count qa-muted", children: source.error ? `Could not read more rows: ${source.error}` : counted }), _jsx("div", { className: "qa-results-scroll", ref: scroller, onScroll: (event) => setTop(event.currentTarget.scrollTop), children: _jsxs("table", { children: [_jsx("thead", { ref: header, children: _jsx("tr", { children: source.columns.map((column, i) => _jsx("th", { children: column }, i)) }) }), _jsxs("tbody", { children: [above > 0 && _jsx("tr", { className: "qa-spacer", style: { height: above } }), drawn, below > 0 && _jsx("tr", { className: "qa-spacer", style: { height: below } })] })] }) })] }));
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=ResultsTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResultsTable.js","sourceRoot":"","sources":["../src/ResultsTable.tsx"],"names":[],"mappings":";AA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AAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,YAC1G,4BACE,gBAAO,GAAG,EAAE,MAAM,YAAE,uBAAK,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,uBAAa,MAAM,IAAV,CAAC,CAAe,CAAC,GAAM,GAAQ,EACnG,4BACG,KAAK,GAAG,CAAC,IAAI,aAAI,SAAS,EAAC,WAAW,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAI,EACnE,KAAK,EACL,KAAK,GAAG,CAAC,IAAI,aAAI,SAAS,EAAC,WAAW,EAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAI,IAC9D,IACF,GACJ,IACF,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Select N elements" under an answer: replaces the host's selection with the elements the answer
|
|
3
|
+
* is about (`selection.ts`).
|
|
4
|
+
*/
|
|
5
|
+
import type { AgentClient, AgentRun } from "@colin_kerr/query-agent-client";
|
|
6
|
+
import { type SelectedElements, type SelectionTarget } from "./selection.js";
|
|
7
|
+
/** The host's unified selection, as the controls are given it (`AgentChatProps.selection`). */
|
|
8
|
+
export interface AnswerSelection {
|
|
9
|
+
/** The store: a `SelectionStorage` from `@itwin/unified-selection` fits. */
|
|
10
|
+
storage: SelectionTarget;
|
|
11
|
+
/** The open iModel's key (`IModelConnection.key`). */
|
|
12
|
+
imodelKey: string;
|
|
13
|
+
/**
|
|
14
|
+
* Replace the selection when an answer arrives, without a click: with every element the answer
|
|
15
|
+
* names (its rows, when they carry `ECInstanceId` and `ClassName`). A selection request that found
|
|
16
|
+
* nothing clears the selection.
|
|
17
|
+
*/
|
|
18
|
+
autoSelect?: boolean;
|
|
19
|
+
/** Called each time the agent replaced the selection: a host zooms to the elements here. */
|
|
20
|
+
onSelected?: (result: SelectedElements, run: AgentRun) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare function SelectElements(props: {
|
|
23
|
+
run?: AgentRun;
|
|
24
|
+
client: AgentClient;
|
|
25
|
+
selection: AnswerSelection;
|
|
26
|
+
}): JSX.Element | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* "Select N elements" under an answer: replaces the host's selection with the elements the answer
|
|
4
|
+
* is about (`selection.ts`).
|
|
5
|
+
*/
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { plural, selectableOf, selectAnswerElements, selectedMessage } from "./selection.js";
|
|
8
|
+
export function SelectElements(props) {
|
|
9
|
+
const { run, client, selection } = props;
|
|
10
|
+
const [message, setMessage] = useState();
|
|
11
|
+
const [busy, setBusy] = useState(false);
|
|
12
|
+
const offered = selectableOf(run);
|
|
13
|
+
if (!run || !offered)
|
|
14
|
+
return null;
|
|
15
|
+
const select = async () => {
|
|
16
|
+
setBusy(true);
|
|
17
|
+
try {
|
|
18
|
+
const result = await selectAnswerElements(run, client, selection.storage, selection.imodelKey);
|
|
19
|
+
if (!result)
|
|
20
|
+
return;
|
|
21
|
+
setMessage(selectedMessage(result));
|
|
22
|
+
selection.onSelected?.(result, run);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
setMessage(`Could not select them: ${err instanceof Error ? err.message : String(err)}`);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
setBusy(false);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: () => void select(), disabled: busy, children: offered.count === undefined ? "Select all the elements" : `Select ${plural(offered.count, "element")}` }), message && _jsx("span", { className: "qa-muted", children: message })] }));
|
|
32
|
+
}
|
|
33
|
+
//# s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AS,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,CACL,8BACE,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,YAC/D,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,UAAU,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,GAChG,EACR,OAAO,IAAI,eAAM,SAAS,EAAC,UAAU,YAAE,OAAO,GAAQ,IACtD,CACJ,CAAC;AACJ,CAAC"}
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type AgentRun, type EarlierQuestion } from "@colin_kerr/query-agent-client";
|
|
2
|
+
/** One question and what came of it. */
|
|
3
|
+
export interface ChatTurn {
|
|
4
|
+
question: string;
|
|
5
|
+
/** The answer's text. Empty while the run is in progress. */
|
|
6
|
+
answer: string;
|
|
7
|
+
/** The answer's query, when it has one. */
|
|
8
|
+
query?: string;
|
|
9
|
+
/** How the run ended: "answered", "partial", "not_found", or why it stopped. */
|
|
10
|
+
outcome?: string;
|
|
11
|
+
/** Set when the run failed: what to tell the user. */
|
|
12
|
+
error?: string;
|
|
13
|
+
/** The whole run, for a host that keeps or shows more of it. Absent on a failed run. */
|
|
14
|
+
run?: AgentRun;
|
|
15
|
+
}
|
|
16
|
+
/** A chat: its questions in order. The earlier questions and the last run's token give a follow-up its context. */
|
|
17
|
+
export interface Chat {
|
|
18
|
+
turns: ChatTurn[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What a follow-up is sent of the chat so far: each earlier question as the user saw it, and the
|
|
22
|
+
* token of the last finished run, which carries what the agent keeps from the chat (sealed; the
|
|
23
|
+
* client never reads it). A question that failed is left out.
|
|
24
|
+
*/
|
|
25
|
+
export declare function contextOf(chat: Chat): Promise<{
|
|
26
|
+
earlier: EarlierQuestion[];
|
|
27
|
+
token?: string;
|
|
28
|
+
}>;
|
|
29
|
+
/** The failure a user is shown. The reason is in the function's log, never in its reply. */
|
|
30
|
+
export declare const FAILED = "The agent could not finish. The function's log has the reason.";
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { earlierQuestion } from "@colin_kerr/query-agent-client";
|
|
2
|
+
/**
|
|
3
|
+
* What a follow-up is sent of the chat so far: each earlier question as the user saw it, and the
|
|
4
|
+
* token of the last finished run, which carries what the agent keeps from the chat (sealed; the
|
|
5
|
+
* client never reads it). A question that failed is left out.
|
|
6
|
+
*/
|
|
7
|
+
export async function contextOf(chat) {
|
|
8
|
+
const answered = chat.turns.filter((turn) => turn.run !== undefined);
|
|
9
|
+
const earlier = await Promise.all(answered.map((turn) => earlierQuestion(turn.question, turn.run)));
|
|
10
|
+
const token = answered.at(-1)?.run.token;
|
|
11
|
+
return { earlier, ...(token ? { token } : {}) };
|
|
12
|
+
}
|
|
13
|
+
/** The failure a user is shown. The reason is in the function's log, never in its reply. */
|
|
14
|
+
export const FAILED = "The agent could not finish. The function's log has the reason.";
|
|
15
|
+
//# sourceMappingURL=chat.js.map
|
package/dist/chat.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAuC,MAAM,gCAAgC,CAAC;AAsBtG;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAU;IACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAwC,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC;IAC3G,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpG,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC;IACzC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAClD,CAAC;AAED,4FAA4F;AAC5F,MAAM,CAAC,MAAM,MAAM,GAAG,gEAAgE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The query agent's React controls. `AgentChat` is the chat window and the ask box;
|
|
3
|
+
* `AgentWorkbench` embeds it and shows what the agent did beside it. Import `styles.css` once.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./AgentChat.js";
|
|
6
|
+
export * from "./AgentWorkbench.js";
|
|
7
|
+
export * from "./Feedback.js";
|
|
8
|
+
export * from "./chat.js";
|
|
9
|
+
export * from "./Dots.js";
|
|
10
|
+
export * from "./selection.js";
|
|
11
|
+
export * from "./SelectElements.js";
|
|
12
|
+
export * from "./ResultsTable.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The query agent's React controls. `AgentChat` is the chat window and the ask box;
|
|
3
|
+
* `AgentWorkbench` embeds it and shows what the agent did beside it. Import `styles.css` once.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./AgentChat.js";
|
|
6
|
+
export * from "./AgentWorkbench.js";
|
|
7
|
+
export * from "./Feedback.js";
|
|
8
|
+
export * from "./chat.js";
|
|
9
|
+
export * from "./Dots.js";
|
|
10
|
+
export * from "./selection.js";
|
|
11
|
+
export * from "./SelectElements.js";
|
|
12
|
+
export * from "./ResultsTable.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Selecting the elements an answer is about, in the host's unified selection store.
|
|
3
|
+
*
|
|
4
|
+
* - **An answer whose rows carry `ECInstanceId` and `ClassName` is about those elements:** its
|
|
5
|
+
* query is read again in full to select them, so the number selected is never limited (the
|
|
6
|
+
* owner's decisions D1 and D2).
|
|
7
|
+
* - **An answer whose `resultType` is `selection`** (the user asked to select) that found nothing
|
|
8
|
+
* clears the selection.
|
|
9
|
+
* - **Large selections go to the store in chunks** (`SELECTION_CHUNK`): the first replaces the
|
|
10
|
+
* selection and the rest are added, as the keys are read.
|
|
11
|
+
*
|
|
12
|
+
* The store is typed by the methods used, so this package does not depend on
|
|
13
|
+
* `@itwin/unified-selection`. A `SelectionStorage` from that package fits.
|
|
14
|
+
*/
|
|
15
|
+
import { type AgentClient, type AgentRun, type AnswerRows, type InstanceKey } from "@colin_kerr/query-agent-client";
|
|
16
|
+
/** The part of `SelectionStorage` (`@itwin/unified-selection`) that is used. */
|
|
17
|
+
export interface SelectionTarget {
|
|
18
|
+
replaceSelection(props: {
|
|
19
|
+
imodelKey: string;
|
|
20
|
+
source: string;
|
|
21
|
+
selectables: InstanceKey[];
|
|
22
|
+
level?: number;
|
|
23
|
+
}): void;
|
|
24
|
+
addToSelection(props: {
|
|
25
|
+
imodelKey: string;
|
|
26
|
+
source: string;
|
|
27
|
+
selectables: InstanceKey[];
|
|
28
|
+
level?: number;
|
|
29
|
+
}): void;
|
|
30
|
+
}
|
|
31
|
+
/** The name the agent's changes to the selection carry. */
|
|
32
|
+
export declare const SELECTION_SOURCE = "QueryAgent";
|
|
33
|
+
/** The selection level the agent replaces: the top one, as a click in the viewport does. */
|
|
34
|
+
export declare const SELECTION_LEVEL = 0;
|
|
35
|
+
/**
|
|
36
|
+
* Whether an answer's rows can be selected (the owner's decision D1): they have both the
|
|
37
|
+
* `ECInstanceId` and the `ClassName` columns. An id alone is not enough, since ids are not unique
|
|
38
|
+
* across tables.
|
|
39
|
+
*/
|
|
40
|
+
export declare function rowsSelectable(rows: AnswerRows | undefined): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* What an answer offers to select. Undefined when it offers nothing: rows without both key
|
|
43
|
+
* columns, or no rows.
|
|
44
|
+
*
|
|
45
|
+
* - `count` is the number of elements when the rows were read in full. Otherwise it is undefined,
|
|
46
|
+
* and selecting reads them all.
|
|
47
|
+
*/
|
|
48
|
+
export declare function selectableOf(run: AgentRun | undefined): {
|
|
49
|
+
count?: number;
|
|
50
|
+
} | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* A selection request that found nothing: an answer whose `resultType` is `selection` and whose
|
|
53
|
+
* query returned no rows (with both key columns), or that ended `not_found`. Selecting it clears
|
|
54
|
+
* the selection, so an earlier answer's elements do not stay selected as if they were the answer.
|
|
55
|
+
*/
|
|
56
|
+
export declare function selectsNothing(run: AgentRun | undefined): boolean;
|
|
57
|
+
export interface SelectedElements {
|
|
58
|
+
/**
|
|
59
|
+
* The first `SELECTION_SAMPLE` (1,000) elements selected, with their classes. The keys went to
|
|
60
|
+
* the store in chunks and are not held again here.
|
|
61
|
+
*/
|
|
62
|
+
selected: InstanceKey[];
|
|
63
|
+
/** How many elements were selected. */
|
|
64
|
+
count: number;
|
|
65
|
+
/** How many of the rows did not name an element (aspects, models and the like). */
|
|
66
|
+
notElements: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Replace the selection with these elements, as the agent: the first chunk replaces it, and the
|
|
70
|
+
* rest are added in chunks of `SELECTION_CHUNK`, so the hilite and the property grid start on the
|
|
71
|
+
* first chunk rather than waiting for every key.
|
|
72
|
+
*/
|
|
73
|
+
export declare function replaceWith(storage: SelectionTarget, imodelKey: string, selectables: InstanceKey[]): void;
|
|
74
|
+
/**
|
|
75
|
+
* Select every element an answer is about, with no limit (the owner's decision D2): all the rows
|
|
76
|
+
* of its query, when they carry `ECInstanceId` and `ClassName`. The query is read again, in full, and the keys go to the store in chunks as they are
|
|
77
|
+
* read. Keys whose class is not an element class are left out. Undefined when the answer offers
|
|
78
|
+
* nothing to select. A selection request that found nothing (`selectsNothing`) clears the
|
|
79
|
+
* selection. Throws the selection's error.
|
|
80
|
+
*
|
|
81
|
+
* A newer call for the same store and iModel supersedes this one: it stops reading, changes the
|
|
82
|
+
* selection no more, and returns undefined. An earlier answer's long read cannot overwrite a later
|
|
83
|
+
* answer's selection.
|
|
84
|
+
*/
|
|
85
|
+
export declare function selectAnswerElements(run: AgentRun | undefined, client: AgentClient, storage: SelectionTarget, imodelKey: string): Promise<SelectedElements | undefined>;
|
|
86
|
+
/** The sentence said after a selection. */
|
|
87
|
+
export declare function selectedMessage(result: SelectedElements): string;
|
|
88
|
+
export declare function plural(count: number, noun: string): string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Selecting the elements an answer is about, in the host's unified selection store.
|
|
3
|
+
*
|
|
4
|
+
* - **An answer whose rows carry `ECInstanceId` and `ClassName` is about those elements:** its
|
|
5
|
+
* query is read again in full to select them, so the number selected is never limited (the
|
|
6
|
+
* owner's decisions D1 and D2).
|
|
7
|
+
* - **An answer whose `resultType` is `selection`** (the user asked to select) that found nothing
|
|
8
|
+
* clears the selection.
|
|
9
|
+
* - **Large selections go to the store in chunks** (`SELECTION_CHUNK`): the first replaces the
|
|
10
|
+
* selection and the rest are added, as the keys are read.
|
|
11
|
+
*
|
|
12
|
+
* The store is typed by the methods used, so this package does not depend on
|
|
13
|
+
* `@itwin/unified-selection`. A `SelectionStorage` from that package fits.
|
|
14
|
+
*/
|
|
15
|
+
import { hasKeyColumns, SELECTION_CHUNK } from "@colin_kerr/query-agent-client";
|
|
16
|
+
/** The name the agent's changes to the selection carry. */
|
|
17
|
+
export const SELECTION_SOURCE = "QueryAgent";
|
|
18
|
+
/** The selection level the agent replaces: the top one, as a click in the viewport does. */
|
|
19
|
+
export const SELECTION_LEVEL = 0;
|
|
20
|
+
/**
|
|
21
|
+
* Whether an answer's rows can be selected (the owner's decision D1): they have both the
|
|
22
|
+
* `ECInstanceId` and the `ClassName` columns. An id alone is not enough, since ids are not unique
|
|
23
|
+
* across tables.
|
|
24
|
+
*/
|
|
25
|
+
export function rowsSelectable(rows) {
|
|
26
|
+
return rows !== undefined && rows.error === undefined && hasKeyColumns(rows.columns);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What an answer offers to select. Undefined when it offers nothing: rows without both key
|
|
30
|
+
* columns, or no rows.
|
|
31
|
+
*
|
|
32
|
+
* - `count` is the number of elements when the rows were read in full. Otherwise it is undefined,
|
|
33
|
+
* and selecting reads them all.
|
|
34
|
+
*/
|
|
35
|
+
export function selectableOf(run) {
|
|
36
|
+
const rows = run?.answerRows;
|
|
37
|
+
if (!rowsSelectable(rows) || (rows.rows ?? []).length === 0)
|
|
38
|
+
return undefined;
|
|
39
|
+
return { count: rows.truncatedBy === undefined ? rows.rows.length : undefined };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A selection request that found nothing: an answer whose `resultType` is `selection` and whose
|
|
43
|
+
* query returned no rows (with both key columns), or that ended `not_found`. Selecting it clears
|
|
44
|
+
* the selection, so an earlier answer's elements do not stay selected as if they were the answer.
|
|
45
|
+
*/
|
|
46
|
+
export function selectsNothing(run) {
|
|
47
|
+
if (run?.resultType !== "selection" || run.stoppedBecause !== "answered")
|
|
48
|
+
return false;
|
|
49
|
+
const rows = run.answerRows;
|
|
50
|
+
if (run.structured?.outcome === "not_found" && (rows?.rows ?? []).length === 0)
|
|
51
|
+
return true;
|
|
52
|
+
return rowsSelectable(rows) && (rows.rows ?? []).length === 0 && rows.truncatedBy === undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Replace the selection with these elements, as the agent: the first chunk replaces it, and the
|
|
56
|
+
* rest are added in chunks of `SELECTION_CHUNK`, so the hilite and the property grid start on the
|
|
57
|
+
* first chunk rather than waiting for every key.
|
|
58
|
+
*/
|
|
59
|
+
export function replaceWith(storage, imodelKey, selectables) {
|
|
60
|
+
storage.replaceSelection({ imodelKey, source: SELECTION_SOURCE, selectables: selectables.slice(0, SELECTION_CHUNK), level: SELECTION_LEVEL });
|
|
61
|
+
for (let start = SELECTION_CHUNK; start < selectables.length; start += SELECTION_CHUNK)
|
|
62
|
+
storage.addToSelection({ imodelKey, source: SELECTION_SOURCE, selectables: selectables.slice(start, start + SELECTION_CHUNK), level: SELECTION_LEVEL });
|
|
63
|
+
}
|
|
64
|
+
/** The selection being read in each store, by iModel: a newer one aborts any still being read. */
|
|
65
|
+
const reading = new WeakMap();
|
|
66
|
+
/**
|
|
67
|
+
* Select every element an answer is about, with no limit (the owner's decision D2): all the rows
|
|
68
|
+
* of its query, when they carry `ECInstanceId` and `ClassName`. The query is read again, in full, and the keys go to the store in chunks as they are
|
|
69
|
+
* read. Keys whose class is not an element class are left out. Undefined when the answer offers
|
|
70
|
+
* nothing to select. A selection request that found nothing (`selectsNothing`) clears the
|
|
71
|
+
* selection. Throws the selection's error.
|
|
72
|
+
*
|
|
73
|
+
* A newer call for the same store and iModel supersedes this one: it stops reading, changes the
|
|
74
|
+
* selection no more, and returns undefined. An earlier answer's long read cannot overwrite a later
|
|
75
|
+
* answer's selection.
|
|
76
|
+
*/
|
|
77
|
+
export async function selectAnswerElements(run, client, storage, imodelKey) {
|
|
78
|
+
const byIModel = reading.get(storage) ?? new Map();
|
|
79
|
+
reading.set(storage, byIModel);
|
|
80
|
+
byIModel.get(imodelKey)?.abort();
|
|
81
|
+
const mine = new AbortController();
|
|
82
|
+
byIModel.set(imodelKey, mine);
|
|
83
|
+
const current = () => !mine.signal.aborted;
|
|
84
|
+
if (selectsNothing(run)) {
|
|
85
|
+
storage.replaceSelection({ imodelKey, source: SELECTION_SOURCE, selectables: [], level: SELECTION_LEVEL });
|
|
86
|
+
return { selected: [], count: 0, notElements: 0 };
|
|
87
|
+
}
|
|
88
|
+
const query = run?.structured?.query || run?.query;
|
|
89
|
+
if (!query || !selectableOf(run))
|
|
90
|
+
return undefined;
|
|
91
|
+
let first = true;
|
|
92
|
+
const all = await client.readSelection(query, (keys) => {
|
|
93
|
+
// A newer selection has started: change nothing more (the reader stops on the signal).
|
|
94
|
+
if (!current())
|
|
95
|
+
return;
|
|
96
|
+
if (first)
|
|
97
|
+
storage.replaceSelection({ imodelKey, source: SELECTION_SOURCE, selectables: keys, level: SELECTION_LEVEL });
|
|
98
|
+
else
|
|
99
|
+
storage.addToSelection({ imodelKey, source: SELECTION_SOURCE, selectables: keys, level: SELECTION_LEVEL });
|
|
100
|
+
first = false;
|
|
101
|
+
}, mine.signal);
|
|
102
|
+
if (!current())
|
|
103
|
+
return undefined;
|
|
104
|
+
if ("error" in all)
|
|
105
|
+
throw new Error(all.error);
|
|
106
|
+
// No element at all: the selection is still replaced, so it does not show an earlier answer's.
|
|
107
|
+
if (first)
|
|
108
|
+
storage.replaceSelection({ imodelKey, source: SELECTION_SOURCE, selectables: [], level: SELECTION_LEVEL });
|
|
109
|
+
return { selected: all.keys, count: all.count, notElements: all.notElements };
|
|
110
|
+
}
|
|
111
|
+
/** The sentence said after a selection. */
|
|
112
|
+
export function selectedMessage(result) {
|
|
113
|
+
return [
|
|
114
|
+
`Selected ${plural(result.count, "element")}.`,
|
|
115
|
+
result.notElements > 0 ? `${plural(result.notElements, "row")} did not name an element.` : "",
|
|
116
|
+
].filter(Boolean).join(" ");
|
|
117
|
+
}
|
|
118
|
+
export function plural(count, noun) {
|
|
119
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../src/selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAsE,MAAM,gCAAgC,CAAC;AAQpJ,2DAA2D;AAC3D,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAE7C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAEjC;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAA4B;IACzD,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACvF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAyB;IACpD,MAAM,IAAI,GAAG,GAAG,EAAE,UAAU,CAAC;IAC7B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC;QAC1D,OAAO,SAAS,CAAC;IACnB,OAAO,EAAE,KAAK,EAAE,IAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,IAAK,CAAC,IAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACrF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAyB;IACtD,IAAI,GAAG,EAAE,UAAU,KAAK,WAAW,IAAI,GAAG,CAAC,cAAc,KAAK,UAAU;QACtE,OAAO,KAAK,CAAC;IACf,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC;IAC5B,IAAI,GAAG,CAAC,UAAU,EAA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AAC,OAAO,EAAE;QACZ,OAAO,SAAS,CAAC;IACnB,IAAI,OAAO,IAAI,GAAG;QAChB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7B,+FAA+F;IAC/F,IAAI,KAAK;QACP,OAAO,CAAC,gBAAgB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC;IAC7G,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC;AAChF,CAAC;AAED,2CAA2C;AAC3C,MAAM,UAAU,eAAe,CAAC,MAAwB;IACtD,OAAO;QACL,YAAY,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG;QAC9C,MAAM,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC,EAAE;KAC9F,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAa,EAAE,IAAY;IAChD,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACrD,CAAC"}
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The controls' styles. Colours come from variables a host can set on any ancestor; each has a
|
|
3
|
+
* plain fallback, so the controls look right with none set.
|
|
4
|
+
*/
|
|
5
|
+
.qa-chat { display: flex; flex-direction: column; height: 100%; min-height: 0; font: inherit; color: var(--qa-text, inherit); }
|
|
6
|
+
.qa-messages { flex: 1 1 auto; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 10px; }
|
|
7
|
+
.qa-question { align-self: flex-end; max-width: 85%; padding: 6px 10px; border-radius: 8px; background: var(--qa-question-bg, #e8eef8); white-space: pre-wrap; margin-left: auto; width: fit-content; }
|
|
8
|
+
.qa-answer, .qa-progress, .qa-error, .qa-notice { max-width: 95%; padding: 6px 10px; border-radius: 8px; background: var(--qa-answer-bg, #f4f4f4); white-space: pre-wrap; margin-top: 6px; }
|
|
9
|
+
.qa-progress, .qa-muted, .qa-notice { color: var(--qa-muted, #666); }
|
|
10
|
+
.qa-error { color: var(--qa-error, #a40000); }
|
|
11
|
+
.qa-dots { display: inline-block; width: 1.5em; }
|
|
12
|
+
/* Each turn keeps its full height: the messages scroll, and a query's box must not be squeezed over its button. */
|
|
13
|
+
.qa-turn { flex-shrink: 0; min-width: 0; }
|
|
14
|
+
/* The answer, its query and the button stack in one column, each keeping its full height. */
|
|
15
|
+
.qa-answer { display: flex; flex-direction: column; gap: 6px; }
|
|
16
|
+
.qa-answer > *, .qa-query > * { flex: none; min-width: 0; }
|
|
17
|
+
.qa-query { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
|
|
18
|
+
/* Long lines wrap rather than scroll: Safari leaves no room for a horizontal scroll bar here. */
|
|
19
|
+
.qa-query pre { align-self: stretch; margin: 0; padding: 6px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--qa-code-bg, #fff); border: 1px solid var(--qa-border, #ddd); border-radius: 4px; }
|
|
20
|
+
.qa-compose { border-top: 1px solid var(--qa-border, #ddd); padding: 8px; display: flex; flex-direction: column; gap: 6px; }
|
|
21
|
+
.qa-input { width: 100%; box-sizing: border-box; font: inherit; resize: vertical; }
|
|
22
|
+
.qa-controls { display: flex; gap: 6px; justify-content: flex-end; }
|
|
23
|
+
.qa-feedback { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
|
|
24
|
+
.qa-feedback label { display: flex; flex-direction: column; width: 100%; gap: 2px; }
|
|
25
|
+
.qa-feedback textarea { font: inherit; }
|
|
26
|
+
.qa-feedback-preview { width: 100%; margin: 0; overflow-x: auto; }
|
|
27
|
+
.qa-workbench-frame { container-type: inline-size; height: 100%; min-height: 0; }
|
|
28
|
+
.qa-workbench { display: flex; height: 100%; min-height: 0; gap: 8px; }
|
|
29
|
+
.qa-workbench-chat { flex: 3 1 0; min-width: 0; display: flex; flex-direction: column; }
|
|
30
|
+
.qa-workbench-side { flex: 2 1 0; min-width: 0; overflow-y: auto; border-left: 1px solid var(--qa-border, #ddd); padding: 0 8px; }
|
|
31
|
+
.qa-tabs { display: flex; gap: 4px; position: sticky; top: 0; background: var(--qa-bg, #fff); padding: 6px 0; }
|
|
32
|
+
.qa-tabs [aria-selected="true"] { font-weight: 600; }
|
|
33
|
+
.qa-results table { border-collapse: collapse; font-size: 0.9em; }
|
|
34
|
+
.qa-results th, .qa-results td { border: 1px solid var(--qa-border, #ddd); padding: 2px 6px; text-align: left; vertical-align: top; }
|
|
35
|
+
/* The results table is virtualized: one line per row at ROW_HEIGHT (22px), a header that stays, and its own scroll. */
|
|
36
|
+
.qa-results { display: flex; flex-direction: column; min-height: 0; height: 100%; }
|
|
37
|
+
.qa-results-scroll { flex: 1 1 auto; min-height: 120px; overflow: auto; }
|
|
38
|
+
.qa-results-scroll thead th { position: sticky; top: 0; background: var(--qa-background, #fff); }
|
|
39
|
+
.qa-results-scroll td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32em; height: 22px; box-sizing: border-box; }
|
|
40
|
+
.qa-results-scroll tr.qa-spacer { border: none; }
|
|
41
|
+
.qa-results-count { padding: 2px 0; }
|
|
42
|
+
/* By the control's own width, not the window's: it often sits in a side pane. */
|
|
43
|
+
@container (max-width: 700px) {
|
|
44
|
+
.qa-workbench { flex-direction: column; }
|
|
45
|
+
.qa-workbench-chat { flex: 1 1 auto; min-height: 60%; }
|
|
46
|
+
.qa-workbench-side { flex: 0 0 auto; max-height: 40%; border-left: none; border-top: 1px solid var(--qa-border, #ddd); }
|
|
47
|
+
}
|
|
48
|
+
/* The host's buttons under an answer wrap. */
|
|
49
|
+
.qa-answer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colin_kerr/query-agent-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "The query agent's React controls: the chat (AgentChat), the larger control (AgentWorkbench), and the feedback form.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"itwin",
|
|
7
|
+
"itwinjs",
|
|
8
|
+
"imodel",
|
|
9
|
+
"react",
|
|
10
|
+
"ecsql",
|
|
11
|
+
"ai",
|
|
12
|
+
"agent",
|
|
13
|
+
"chat"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./styles.css": "./dist/styles.css"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc -p tsconfig.json && cp src/styles.css dist/styles.css"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@colin_kerr/query-agent-client": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": "^18.3.1",
|
|
37
|
+
"react-dom": "^18.3.1"
|
|
38
|
+
},
|
|
39
|
+
"author": "Colin Kerr",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/ColinKerr/query_agent_ui.git",
|
|
43
|
+
"directory": "packages/react"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/ColinKerr/query_agent_ui#readme",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/ColinKerr/query_agent_ui/issues"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|