@robosystems/core 0.13.1 → 0.13.3

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.
@@ -388,9 +388,12 @@ export function ConsoleContent({ config, variant = 'page', }) {
388
388
  : await clients.operator.executeQuery(graphId, request, options);
389
389
  // The user switched graphs while the operator ran: the reset already
390
390
  // cleared the console, so drop the answer rather than print it (and
391
- // record it as history) under the new graph.
392
- if (isStale())
391
+ // record it as history) under the new graph. Its writes still landed
392
+ // on the first graph, so say so.
393
+ if (isStale()) {
394
+ reportStaleWrites(requestGraphId, readGraphWrites((result.metadata || {})));
393
395
  return;
396
+ }
394
397
  setOperatorProgress({ isRunning: false, message: '' });
395
398
  // The API reports operator failures (credit pre-flight, timeouts,
396
399
  // unbilled calls) as HTTP 200 with `error_details` set and an
@@ -403,6 +406,7 @@ export function ConsoleContent({ config, variant = 'page', }) {
403
406
  errorDetails.detail,
404
407
  ].find((v) => typeof v === 'string' && v.length > 0);
405
408
  addErrorMessage(`Operator error: ${detail || result.content || 'The operator could not complete this request.'}`);
409
+ reportStoppedWrites(requestGraphId, readGraphWrites((result.metadata || {})));
406
410
  return;
407
411
  }
408
412
  const duration = Date.now() - startTime;
@@ -479,8 +483,13 @@ export function ConsoleContent({ config, variant = 'page', }) {
479
483
  }
480
484
  }
481
485
  catch (error) {
482
- if (isStale())
486
+ // A run that stopped after writing reports what it changed, so a
487
+ // retry doesn't repeat it.
488
+ const landed = readGraphWrites(error);
489
+ if (isStale()) {
490
+ reportStaleWrites(requestGraphId, landed);
483
491
  return;
492
+ }
484
493
  setOperatorProgress({ isRunning: false, message: '' });
485
494
  const errorMessage = error.message ||
486
495
  ((_a = error.data) === null || _a === void 0 ? void 0 : _a.detail) ||
@@ -494,8 +503,21 @@ export function ConsoleContent({ config, variant = 'page', }) {
494
503
  else {
495
504
  addErrorMessage(`Operator error: ${errorMessage}`);
496
505
  }
506
+ reportStoppedWrites(requestGraphId, landed);
497
507
  }
498
508
  };
509
+ const reportStoppedWrites = (writtenGraphId, writes) => {
510
+ if (writes.length === 0)
511
+ return;
512
+ emitGraphWrites(writtenGraphId, writes);
513
+ addResultMessage('The run stopped after making these changes. Check them before asking again.', undefined, undefined, { writes });
514
+ };
515
+ const reportStaleWrites = (writtenGraphId, writes) => {
516
+ if (writes.length === 0)
517
+ return;
518
+ emitGraphWrites(writtenGraphId, writes);
519
+ addResultMessage(`A request you started on ${writtenGraphId} finished after you switched graphs, and changed that graph:`, undefined, undefined, { writes });
520
+ };
499
521
  const showMcpSetup = async (mode) => {
500
522
  const apiUrl = process.env.NEXT_PUBLIC_ROBOSYSTEMS_API_URL ||
501
523
  'https://api.robosystems.ai';
@@ -2,8 +2,9 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useCallback, useEffect, useRef, useState } from 'react';
4
4
  import { HiChevronDown, HiChevronUp, HiOutlineArrowsExpand, HiOutlineMinus, HiTerminal, } from 'react-icons/hi';
5
+ import { CONSOLE_DRAWER_STORAGE_KEY, CONSOLE_OPEN_EVENT, } from '../../lib/console-drawer';
5
6
  import { ConsoleContent } from './ConsoleContent';
6
- const STORAGE_KEY = 'robosystems:console-drawer';
7
+ const STORAGE_KEY = CONSOLE_DRAWER_STORAGE_KEY;
7
8
  /** Height of the closed drawer's bar. */
8
9
  export const CONSOLE_DRAWER_BAR_HEIGHT = 32;
9
10
  /** Set on <html> to the space the drawer covers; pad page content by it. */
@@ -77,6 +78,21 @@ export function ConsoleDrawer({ config, className = 'left-0 right-0', }) {
77
78
  useEffect(() => () => {
78
79
  document.documentElement.style.removeProperty(CONSOLE_DRAWER_HEIGHT_VAR);
79
80
  }, []);
81
+ // openConsoleDrawer() from any button or page.
82
+ useEffect(() => {
83
+ const onOpen = () => {
84
+ setState((prev) => {
85
+ if (prev.open)
86
+ return prev;
87
+ const merged = Object.assign(Object.assign({}, prev), { open: true });
88
+ writeState(merged);
89
+ return merged;
90
+ });
91
+ setHasOpened(true);
92
+ };
93
+ window.addEventListener(CONSOLE_OPEN_EVENT, onOpen);
94
+ return () => window.removeEventListener(CONSOLE_OPEN_EVENT, onOpen);
95
+ }, []);
80
96
  useEffect(() => {
81
97
  const onKey = (event) => {
82
98
  if (event.ctrlKey && event.key === '`') {
package/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { clearUserCookies, clearUserLocalStorage, clearUserSessionStorage, listU
4
4
  export { AppSwitcher, AuthGuard, AuthProvider, LoginRedirector, SignInForm, SignUpForm, useAuth, } from './auth-components';
5
5
  export { useApiError, useGraphWrites, useMediaQuery, useToast, useUser, useUserLimits, type ToastMessage, } from './hooks';
6
6
  export { createGraphContext, createGraphProvider, createUseGraphContext, EntityProvider, GraphContext, GraphProvider, OrgProvider, ServiceOfferingsProvider, SidebarProvider, useEntity, useGraphContext, useOrg, useServiceOfferings, useSidebarContext, type EntityContextValue, type EntityProviderProps, type GraphContextValue, type GraphProviderProps, type GraphState, type OrgContextState, type OrgContextValue, type OrgProviderProps, type ServiceOfferings, } from './contexts';
7
- export { clientGraphCookie, clientSidebarCookie, createMcpConnectorUrl, emitGraphWrites, entityCookie, GRAPH_WRITES_EVENT, graphCookie, readGraphWrites, sidebarCookie, type EntityCookie, type GraphCookie, type GraphWrite, type GraphWritesDetail, type McpConnectorUrl, type SidebarCookie, } from './lib';
7
+ export { clientGraphCookie, clientSidebarCookie, CONSOLE_OPEN_EVENT, createMcpConnectorUrl, emitGraphWrites, entityCookie, GRAPH_WRITES_EVENT, graphCookie, openConsoleDrawer, readGraphWrites, sidebarCookie, type EntityCookie, type GraphCookie, type GraphWrite, type GraphWritesDetail, type McpConnectorUrl, type SidebarCookie, } from './lib';
8
8
  export { ApiError, errorStatus, extractErrorDetail, isApiError, isSessionRejection, isTransientError, toApiError, unwrapSdk, type SdkResult, } from './lib/sdk-errors';
9
9
  export { generateEntityUri, isUUID, UUID_REGEX } from './utils';
10
10
  export { clearGraphSelection, getGraphSelection, persistGraphSelection, } from './actions/graph-actions';
package/index.js CHANGED
@@ -20,7 +20,7 @@ OrgProvider,
20
20
  // Service offerings context
21
21
  ServiceOfferingsProvider, SidebarProvider, useEntity, useGraphContext, useOrg, useServiceOfferings, useSidebarContext, } from './contexts';
22
22
  // Export lib utilities
23
- export { clientGraphCookie, clientSidebarCookie, createMcpConnectorUrl, emitGraphWrites, entityCookie, GRAPH_WRITES_EVENT, graphCookie, readGraphWrites, sidebarCookie, } from './lib';
23
+ export { clientGraphCookie, clientSidebarCookie, CONSOLE_OPEN_EVENT, createMcpConnectorUrl, emitGraphWrites, entityCookie, GRAPH_WRITES_EVENT, graphCookie, openConsoleDrawer, readGraphWrites, sidebarCookie, } from './lib';
24
24
  // Export the SDK error seam (unwrap an SDK result or throw ApiError)
25
25
  export { ApiError, errorStatus, extractErrorDetail, isApiError, isSessionRejection, isTransientError, toApiError, unwrapSdk, } from './lib/sdk-errors';
26
26
  // Export utils
@@ -0,0 +1,12 @@
1
+ /** Window event that opens the console drawer from anywhere in an app. */
2
+ export declare const CONSOLE_OPEN_EVENT = "robosystems:console-open";
3
+ /** Where the drawer keeps whether it is open and its height. */
4
+ export declare const CONSOLE_DRAWER_STORAGE_KEY = "robosystems:console-drawer";
5
+ /**
6
+ * Open the console drawer: the one way into the console, from any page.
7
+ *
8
+ * Records the open state as well as signalling it, so a call made before
9
+ * the drawer has mounted (a page's effect runs before its layout's) is
10
+ * still honoured when the drawer reads its state.
11
+ */
12
+ export declare function openConsoleDrawer(): void;
@@ -0,0 +1,24 @@
1
+ /** Window event that opens the console drawer from anywhere in an app. */
2
+ export const CONSOLE_OPEN_EVENT = 'robosystems:console-open';
3
+ /** Where the drawer keeps whether it is open and its height. */
4
+ export const CONSOLE_DRAWER_STORAGE_KEY = 'robosystems:console-drawer';
5
+ /**
6
+ * Open the console drawer: the one way into the console, from any page.
7
+ *
8
+ * Records the open state as well as signalling it, so a call made before
9
+ * the drawer has mounted (a page's effect runs before its layout's) is
10
+ * still honoured when the drawer reads its state.
11
+ */
12
+ export function openConsoleDrawer() {
13
+ if (typeof window === 'undefined')
14
+ return;
15
+ try {
16
+ const raw = window.localStorage.getItem(CONSOLE_DRAWER_STORAGE_KEY);
17
+ const state = raw ? JSON.parse(raw) : {};
18
+ window.localStorage.setItem(CONSOLE_DRAWER_STORAGE_KEY, JSON.stringify(Object.assign(Object.assign({}, state), { open: true })));
19
+ }
20
+ catch (_a) {
21
+ // Storage unavailable: the event alone opens a mounted drawer.
22
+ }
23
+ window.dispatchEvent(new Event(CONSOLE_OPEN_EVENT));
24
+ }
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { clientSidebarCookie, sidebarCookie, type SidebarCookie, } from './sidebar-cookie';
2
2
  export { clientGraphCookie, graphCookie, type GraphCookie, } from './graph-cookie';
3
+ export { CONSOLE_OPEN_EVENT, openConsoleDrawer } from './console-drawer';
3
4
  export { entityCookie, type EntityCookie } from './entity-cookie';
4
5
  export { GRAPH_WRITES_EVENT, emitGraphWrites, readGraphWrites, type GraphWrite, type GraphWritesDetail, } from './graph-writes';
5
6
  export { createMcpConnectorUrl, type McpConnectorUrl } from './mcp-connector';
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { clientSidebarCookie, sidebarCookie, } from './sidebar-cookie';
2
2
  export { clientGraphCookie, graphCookie, } from './graph-cookie';
3
+ export { CONSOLE_OPEN_EVENT, openConsoleDrawer } from './console-drawer';
3
4
  export { entityCookie } from './entity-cookie';
4
5
  export { GRAPH_WRITES_EVENT, emitGraphWrites, readGraphWrites, } from './graph-writes';
5
6
  export { createMcpConnectorUrl } from './mcp-connector';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robosystems/core",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
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,