@robosystems/core 0.16.0 → 0.17.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/components/console/ConsoleContent.js +134 -20
- package/package.json +2 -2
|
@@ -9,6 +9,15 @@ import { useStreamingQuery } from '../../hooks';
|
|
|
9
9
|
import { emitGraphWrites, readGraphWrites, } from '../../lib/graph-writes';
|
|
10
10
|
import { ConsoleMarkdown } from './ConsoleMarkdown';
|
|
11
11
|
import { ProgressiveText } from './ProgressiveText';
|
|
12
|
+
// A conversation's id, minted here and sent with every question in it; the
|
|
13
|
+
// server records each run under it. Any URL-safe token under 64 characters.
|
|
14
|
+
function mintThreadId() {
|
|
15
|
+
if (typeof crypto !== 'undefined' &&
|
|
16
|
+
typeof crypto.randomUUID === 'function') {
|
|
17
|
+
return crypto.randomUUID();
|
|
18
|
+
}
|
|
19
|
+
return `thr_${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}`;
|
|
20
|
+
}
|
|
12
21
|
function generateMessageId() {
|
|
13
22
|
return `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
14
23
|
}
|
|
@@ -108,10 +117,14 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
108
117
|
const [historyIndex, setHistoryIndex] = useState(-1);
|
|
109
118
|
const terminalEndRef = useRef(null);
|
|
110
119
|
const terminalScrollRef = useRef(null);
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
|
|
120
|
+
// The conversation the operator questions belong to. Minted on the first
|
|
121
|
+
// question, sent with every one after it, so a follow-up like "and for
|
|
122
|
+
// June?" resolves against the previous answers: the server seeds the run
|
|
123
|
+
// from the thread's own record. Null until a question is asked, and reset
|
|
124
|
+
// by /clear and by a graph switch.
|
|
125
|
+
const threadRef = useRef(null);
|
|
126
|
+
// The threads /history last listed, so /resume <n> can name one.
|
|
127
|
+
const listedThreadsRef = useRef([]);
|
|
115
128
|
const [currentQueryStartTime, setCurrentQueryStartTime] = useState(null);
|
|
116
129
|
const [apiVersion, setApiVersion] = useState(null);
|
|
117
130
|
const [operatorProgress, setOperatorProgress] = useState({ isRunning: false, message: '' });
|
|
@@ -144,7 +157,9 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
144
157
|
` /mcp - Connect an MCP client (sign in — no key)\n` +
|
|
145
158
|
` /mcp key - Mint a graph-scoped API key for header-only clients\n` +
|
|
146
159
|
` /help - Show this help message\n` +
|
|
147
|
-
` /
|
|
160
|
+
` /history - List your recent conversations on this graph\n` +
|
|
161
|
+
` /resume <n> - Continue a listed conversation\n` +
|
|
162
|
+
` /clear - Clear the console and start a new conversation\n` +
|
|
148
163
|
` /examples - Show example queries`;
|
|
149
164
|
const extraLines = ((_a = config.extraCommands) !== null && _a !== void 0 ? _a : [])
|
|
150
165
|
.map((ec) => ` ${ec.command.padEnd(12)}- Custom command`)
|
|
@@ -250,7 +265,7 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
250
265
|
setTerminalMessages([]);
|
|
251
266
|
// A follow-up on the new graph must not resolve against the previous
|
|
252
267
|
// graph's answers.
|
|
253
|
-
|
|
268
|
+
threadRef.current = null;
|
|
254
269
|
setCurrentQueryStartTime(null);
|
|
255
270
|
addSystemMessage(`═══════════════════════════════════════════════════════════════\n` +
|
|
256
271
|
`${config.welcome.contextLabel} context changed: ${fromGraphId} → ${graphId}\n` +
|
|
@@ -372,7 +387,7 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
372
387
|
// `operatorType` names an operator (`author` for /do); unset, the API
|
|
373
388
|
// chooses one for a question.
|
|
374
389
|
const executeOperatorQuery = async (userQuery, operatorType) => {
|
|
375
|
-
var _a;
|
|
390
|
+
var _a, _b;
|
|
376
391
|
if (!graphId) {
|
|
377
392
|
addErrorMessage(config.noSelectionError);
|
|
378
393
|
return;
|
|
@@ -390,11 +405,15 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
390
405
|
graphEpochRef.current !== requestEpoch;
|
|
391
406
|
try {
|
|
392
407
|
const { clients } = await import('@robosystems/client/clients');
|
|
393
|
-
const
|
|
394
|
-
|
|
408
|
+
const threadId = (_a = threadRef.current) !== null && _a !== void 0 ? _a : mintThreadId();
|
|
409
|
+
threadRef.current = threadId;
|
|
410
|
+
const request = {
|
|
411
|
+
message: userQuery,
|
|
395
412
|
// `standard` gives the operator loop six tool turns; `quick` (three)
|
|
396
413
|
// was exhausted by schema + examples before the first query ran.
|
|
397
|
-
mode: 'standard'
|
|
414
|
+
mode: 'standard',
|
|
415
|
+
threadId,
|
|
416
|
+
};
|
|
398
417
|
const options = {
|
|
399
418
|
mode: 'auto',
|
|
400
419
|
onProgress: (message, percentage) => {
|
|
@@ -463,7 +482,7 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
463
482
|
narrative = narrative.replace(jsonBlockMatch[0], '').trim();
|
|
464
483
|
}
|
|
465
484
|
}
|
|
466
|
-
catch (
|
|
485
|
+
catch (_c) {
|
|
467
486
|
// Not valid JSON, keep as text
|
|
468
487
|
}
|
|
469
488
|
}
|
|
@@ -502,13 +521,6 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
502
521
|
footer,
|
|
503
522
|
writes,
|
|
504
523
|
});
|
|
505
|
-
// Record the exchange for follow-ups. Only a narrative answer is
|
|
506
|
-
// worth carrying; the answer is clipped so history stays cheap.
|
|
507
|
-
conversationRef.current = [
|
|
508
|
-
...conversationRef.current,
|
|
509
|
-
{ role: 'user', content: userQuery },
|
|
510
|
-
{ role: 'assistant', content: narrative.slice(0, 2000) },
|
|
511
|
-
].slice(-6);
|
|
512
524
|
}
|
|
513
525
|
else {
|
|
514
526
|
addResultMessage(footer, rows, cypher, { writes });
|
|
@@ -524,7 +536,7 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
524
536
|
}
|
|
525
537
|
setOperatorProgress({ isRunning: false, message: '' });
|
|
526
538
|
const errorMessage = error.message ||
|
|
527
|
-
((
|
|
539
|
+
((_b = error.data) === null || _b === void 0 ? void 0 : _b.detail) ||
|
|
528
540
|
'Failed to process natural language query';
|
|
529
541
|
if (error.status === 402) {
|
|
530
542
|
addErrorMessage(`Insufficient credits to process query.\n\nPlease upgrade your subscription or wait for credits to reset.`);
|
|
@@ -622,6 +634,102 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
622
634
|
` Header: X-API-Key: <your key>`);
|
|
623
635
|
}
|
|
624
636
|
};
|
|
637
|
+
// `/history`: the user's own conversations on this graph, newest first.
|
|
638
|
+
const showThreads = async () => {
|
|
639
|
+
var _a, _b;
|
|
640
|
+
if (!graphId) {
|
|
641
|
+
addErrorMessage(config.noSelectionError);
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const stale = leftScope();
|
|
645
|
+
try {
|
|
646
|
+
const res = await SDK.listOperatorThreads({
|
|
647
|
+
path: { graph_id: graphId },
|
|
648
|
+
query: { limit: 10 },
|
|
649
|
+
});
|
|
650
|
+
if (stale())
|
|
651
|
+
return;
|
|
652
|
+
const threads = (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.threads) !== null && _b !== void 0 ? _b : [];
|
|
653
|
+
listedThreadsRef.current = threads;
|
|
654
|
+
if (threads.length === 0) {
|
|
655
|
+
addSystemMessage('No conversations recorded on this graph yet. Ask a question to start one.', true);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const lines = threads.map((t, idx) => {
|
|
659
|
+
const when = new Date(t.last_run_at).toLocaleString();
|
|
660
|
+
const runs = `${t.run_count} ${t.run_count === 1 ? 'question' : 'questions'}`;
|
|
661
|
+
const current = t.thread_id === threadRef.current ? ' (current)' : '';
|
|
662
|
+
return `${idx + 1}. ${t.title}\n ${runs} · last ${when}${current}`;
|
|
663
|
+
});
|
|
664
|
+
addSystemMessage(`Recent conversations:\n\n${lines.join('\n\n')}\n\nUse: /resume <n> to continue one`, true);
|
|
665
|
+
}
|
|
666
|
+
catch (err) {
|
|
667
|
+
if (stale())
|
|
668
|
+
return;
|
|
669
|
+
addErrorMessage((err === null || err === void 0 ? void 0 : err.message) || 'Could not load conversations.');
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
// `/resume <n>`: replay a listed conversation and continue it — the next
|
|
673
|
+
// question carries its thread id.
|
|
674
|
+
const resumeThread = async (arg) => {
|
|
675
|
+
var _a, _b;
|
|
676
|
+
if (!graphId) {
|
|
677
|
+
addErrorMessage(config.noSelectionError);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
const index = Number.parseInt(arg, 10);
|
|
681
|
+
const thread = listedThreadsRef.current[index - 1];
|
|
682
|
+
if (!arg || Number.isNaN(index) || !thread) {
|
|
683
|
+
addErrorMessage(listedThreadsRef.current.length === 0
|
|
684
|
+
? 'Run /history first, then /resume <n> with a number from the list.'
|
|
685
|
+
: `Pick a number from 1 to ${listedThreadsRef.current.length}.`);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
const stale = leftScope();
|
|
689
|
+
try {
|
|
690
|
+
const res = await SDK.listOperatorRuns({
|
|
691
|
+
path: { graph_id: graphId },
|
|
692
|
+
query: { thread_id: thread.thread_id, limit: 50 },
|
|
693
|
+
});
|
|
694
|
+
if (stale())
|
|
695
|
+
return;
|
|
696
|
+
// Newest first on the wire; the console reads top to bottom.
|
|
697
|
+
const runs = [...((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.runs) !== null && _b !== void 0 ? _b : [])].reverse();
|
|
698
|
+
setTerminalMessages([]);
|
|
699
|
+
threadRef.current = thread.thread_id;
|
|
700
|
+
addSystemMessage(`Resumed conversation from ${new Date(thread.first_run_at).toLocaleString()}. Follow-up questions continue it.`, true);
|
|
701
|
+
for (const run of runs) {
|
|
702
|
+
addUserMessage(run.question);
|
|
703
|
+
replayRun(run);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
catch (err) {
|
|
707
|
+
if (stale())
|
|
708
|
+
return;
|
|
709
|
+
addErrorMessage((err === null || err === void 0 ? void 0 : err.message) || 'Could not load the conversation.');
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
// A recorded run, rendered the way its answer was first printed: the
|
|
713
|
+
// Cypher keeps its Run button, the receipt its writes. Rows are not kept.
|
|
714
|
+
const replayRun = (run) => {
|
|
715
|
+
if (run.status === 'failed') {
|
|
716
|
+
addErrorMessage(`Operator error: ${run.error || 'The run failed.'}`);
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (run.status === 'cancelled' || !run.answer) {
|
|
720
|
+
addSystemMessage('Cancelled before an answer was reached.');
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
const seconds = (run.duration_ms / 1000).toFixed(1);
|
|
724
|
+
let footer = `Answered by ${run.operator_type} in ${seconds}s · ${new Date(run.finished_at).toLocaleString()}`;
|
|
725
|
+
if (run.credits_consumed > 0) {
|
|
726
|
+
footer += `\nCredits used: ${run.credits_consumed.toFixed(1)}`;
|
|
727
|
+
}
|
|
728
|
+
addResultMessage(run.answer, undefined, undefined, {
|
|
729
|
+
markdown: true,
|
|
730
|
+
footer,
|
|
731
|
+
});
|
|
732
|
+
};
|
|
625
733
|
const handleCommand = async (command) => {
|
|
626
734
|
var _a, _b;
|
|
627
735
|
if (!command.trim())
|
|
@@ -782,9 +890,15 @@ export function ConsoleContent({ config, variant = 'page', }) {
|
|
|
782
890
|
return;
|
|
783
891
|
case '/clear':
|
|
784
892
|
setTerminalMessages([]);
|
|
785
|
-
|
|
893
|
+
threadRef.current = null;
|
|
786
894
|
addSystemMessage('Console cleared.', true);
|
|
787
895
|
return;
|
|
896
|
+
case '/history':
|
|
897
|
+
await showThreads();
|
|
898
|
+
return;
|
|
899
|
+
case '/resume':
|
|
900
|
+
await resumeThread(command.slice(cmd.length).trim());
|
|
901
|
+
return;
|
|
788
902
|
case '/examples': {
|
|
789
903
|
const examples = config.sampleQueries
|
|
790
904
|
.map((q, idx) => `${idx + 1}. ${q.name}\n/query ${q.query}`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robosystems/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Shared RoboSystems frontend core library (auth, contexts, task monitoring, UI components) for the RoboSystems Next.js apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"tailwind-merge": "^3"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@robosystems/client": ">=2.
|
|
30
|
+
"@robosystems/client": ">=2.34 <3",
|
|
31
31
|
"flowbite-react": "^0.12.5",
|
|
32
32
|
"next": ">=15 <17",
|
|
33
33
|
"react": ">=18 <20",
|