gz-research-assistant 0.1.3 → 1.0.4

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/README.md CHANGED
@@ -1,16 +1,41 @@
1
1
  # gz-research-assistant
2
2
 
3
- Installable research assistant with gz-ui components, diagnostics, recording, assertions and local replay integration. Requires React 19 and gz-ui's peer dependencies.
3
+ Installable research assistant with gz-ui-web components, diagnostics, recording, assertions and local replay integration. Requires React 19 and gz-ui-web's peer dependencies.
4
4
 
5
5
  ```sh
6
- npm install gz-research-assistant @chenhui996/gg-ui @ant-design/icons antd react react-dom
6
+ npm install gz-research-assistant gz-ui-web @ant-design/icons antd react react-dom
7
7
  ```
8
8
 
9
- ## React component
9
+ ## Application entry point
10
+
11
+ ```ts
12
+ import { researchAssistant } from 'gz-research-assistant';
13
+ import 'gz-ui-web/gz-ui-web.css'; // Omit if the host already imports it.
14
+ import 'gz-research-assistant/style.css';
15
+
16
+ researchAssistant.inject({
17
+ enabled: () => Boolean(authStore.getState().token),
18
+ sessionKey: () => authStore.getState().userId,
19
+ themeMode: () => authStore.getState().theme,
20
+ subscribe: authStore.subscribe,
21
+ diagnosticsOnly: true,
22
+ });
23
+ ```
24
+
25
+ `inject(options)` configures and starts a single assistant instance. `enabled`, `sessionKey` and `themeMode` accept either values or getter functions. When supplied, `subscribe(refresh)` connects application state updates and must return an unsubscribe function; without it, getters are read on startup only. The host owns activation conditions. The package owns the React root, popup container, collection, error boundary and cleanup.
26
+
27
+ - `researchAssistant.stop()` removes the UI, stops collection and releases the host subscription.
28
+ - `researchAssistant.start()` resumes the last configuration; repeated starts do not create duplicates.
29
+ - `researchAssistant.destroy()` also forgets the configuration.
30
+ - Calling `inject` again replaces the previous configuration and session.
31
+
32
+ No application wrapper component, Vite plugin or assistant-specific environment variable is required. For Vite HMR, dispose with `import.meta.hot?.dispose(() => researchAssistant.destroy())`.
33
+
34
+ ## React component (optional)
10
35
 
11
36
  ```tsx
12
37
  import { ResearchAssistant, type ResearchAssistantProps } from 'gz-research-assistant';
13
- import '@chenhui996/gg-ui/gg-ui.css';
38
+ import 'gz-ui-web/gz-ui-web.css';
14
39
  import 'gz-research-assistant/style.css';
15
40
 
16
41
  // Keep callback references stable (module scope or useCallback).
@@ -26,37 +51,24 @@ const options: ResearchAssistantProps = {
26
51
  };
27
52
 
28
53
  // Render only after login; unmount on logout.
29
- <ResearchAssistant {...options} sessionKey={userId} />;
54
+ <ResearchAssistant {...options} enabled={Boolean(token)} sessionKey={userId} />;
30
55
  ```
31
56
 
32
- ## Imperative SDK
57
+ Version 1.0.4 replaces the retired `@chenhui996/gg-ui` dependency with `gz-ui-web@^1.0.4` without changing the assistant layout or icons. Theme isolation and Ant Design style hashing are handled inside the package, including hosts configured with `hashed: false`.
33
58
 
34
- ```tsx
35
- import { mountAssistant } from 'gz-research-assistant/sdk';
36
- import '@chenhui996/gg-ui/gg-ui.css';
37
- import 'gz-research-assistant/style.css';
38
-
39
- // Same options as the React example; no separate SDK business implementation.
40
- const assistant = mountAssistant(document.getElementById('assistant-root')!, {
41
- ...options,
42
- sessionKey: userId,
43
- });
44
- assistant.update({ themeMode: 'blue-light' }); // Retains recording and evidence.
45
- assistant.update({ sessionKey: nextUserId }); // Clears the previous session and resets the UI.
46
- assistant(); // Logout/unmount: restores hooks, stops timers and recording, clears data.
47
- ```
59
+ Import the component and its stylesheet directly in the application's entry point. `enabled` defaults to `true`; set it from application state to start or stop the assistant. Disabling it unmounts its UI, restores collection hooks and clears the session. No integration adapter, Vite plugin or assistant-specific environment variable is required. Use `diagnosticsOnly` to show only phase-one diagnostics.
48
60
 
49
- The SDK mounts the exact public React component in its own React root. Both entrypoints use the same lifecycle, gz-ui provider, UI, collection, diagnostics, recording, assertion editor and bridge. Given the same options and browser environment, their behavior is the same. Mount only **one** assistant per page; do not combine React, SDK and manual `startAssistant()` ownership. The SDK retains the legacy third `runtimeOptions` argument, but passing all settings in the second argument is recommended. Calling its disposer more than once is safe.
61
+ The package includes its own React error boundary. Assistant rendering failures hide its UI and tear down collection without propagating to the host React tree. Changing `sessionKey` or toggling `enabled` off and on starts a fresh attempt; the host does not need an assistant-specific error boundary.
50
62
 
51
- `sessionKey` changes reset the entire assistant, including open tabs, drafts, imported/frozen snapshots and paused collection. Changing `themeMode` or `developer` retains data. Changing the bridge URL or runtime callbacks restarts collection and discards diagnostics and recorded cases. The host controls authentication and business response semantics; the package does not import a host store or read auth tokens. Bridge polling is excluded from Fetch and XHR collection automatically, including custom bridge URLs. Additional `ignoreRequest` filters apply to both APIs.
63
+ `gz-laya-pilot@0.1.2` is installed automatically as a declared npm dependency. A browser application does not need a separate direct dependency or local tarball for it.
52
64
 
53
- Theme defaults to `gold-dark`; pass the same `themeMode` to both integration styles to follow your application. The assistant uses gg-ui's `getDesignTokenCssVariables({ themeMode, includeCustom: false })` on its own container. CSS Modules consume the library's `--gz-*` tokens directly, independent of host `--app-*` variables; there is no private color-token mapping. Both require the CSS imports and the same React/gz-ui peer dependencies. This SDK is an ESM npm entrypoint, not a dependency-free CDN script.
65
+ ## Chrome browser extension
54
66
 
55
- UI controls come from `@chenhui996/gg-ui`, including file selection (`Upload`, local parsing only), `Select`, `InputNumber`, `Checkbox`, `Collapse` and automation cards. Component configuration is isolated from the host provider. Preserve the existing flex layout, spacing, typography, timeline/JSON presentation and memory chart when adopting library components; replacing a control must not redesign the panel. The robot SVG and launcher appearance are intentionally unchanged.
67
+ The second supported integration is a Chrome Manifest V3 extension. Build it with `npm run assistant:extension:build`, then load `extensions/research-assistant/dist` in Chrome developer mode. Click the toolbar action to enable or disable the assistant on the current HTTP/HTTPS page. It bundles its dependencies and reuses the same React UI and collector. The first extension release exposes diagnostics only (timeline, requests, performance, environment and snapshots); feedback, automation, knowledge and bridge configuration are hidden. The npm component retains its complete feature set. See [installation, permissions and limitations](../../extensions/research-assistant/README.md).
56
68
 
57
- ### Migrating from 0.1.0
69
+ The previous `gz-research-assistant/sdk` export and `mountAssistant` API have been removed. Use `researchAssistant.inject()` from the main npm export, the React component, or the browser extension. Both npm entry styles own collection automatically; remove manual `startAssistant()` calls. The `core` export remains a low-level npm API, not an additional supported UI integration. Enable only one entry style per page.
58
70
 
59
- React now starts/stops the collector automatically. **Remove the old `startAssistant()` effect or bootstrap** when rendering `<ResearchAssistant>`. Pass business filters via `runtimeOptions`, and provide `sessionKey` for account switching. Existing SDK `mountAssistant(container, props, options)` calls remain supported. For diagnostics without React UI, `gz-research-assistant/core` still exposes manual `startAssistant`, `assistantRuntime` and `recorder`; the caller owns cleanup in that mode.
71
+ `sessionKey` changes reset the entire npm assistant session. Unmount on logout. Presentation-only changes retain recording and evidence. The extension requires manual disable/re-enable on account changes and starts fresh after navigation. Only enable one integration per page.
60
72
 
61
73
  ## Shared automation dependency
62
74
 
@@ -65,12 +77,12 @@ Version 0.1.3 keeps the existing **自主探索** interface and upgrades its sha
65
77
  ```text
66
78
  React <ResearchAssistant> ─┐
67
79
  ├→ shared Assistant → recorder / assertion UI
68
- SDK mountAssistant ───────┘ ├→ gz-laya-pilot/browser (semantic targets)
80
+ Chrome extension (diagnostics only) ─┘ ├→ gz-laya-pilot/browser (semantic targets)
69
81
  ├→ gz-laya-pilot/schema (case validation)
70
82
  └→ HTTP bridge → Node gz-laya-pilot.runCase
71
83
  ```
72
84
 
73
- `gz-laya-pilot@0.1.2` is a declared runtime dependency for **both** entrypoints. The browser imports only its schema and semantic targets. To execute, the host provides the same-origin bridge to a Node process importing `runCase` or `createAgentBridge` from `gz-laya-pilot`; no copied runner or SDK-specific replay path exists. Never bundle Node execution or model keys into the browser. This repository's `vite/laya-pilot.plugin.ts` and `tools/laya-pilot-recorded-runner.mjs` provide localhost integration, not a production test service.
85
+ `gz-laya-pilot@0.1.2` is a declared runtime dependency of the shared package. The phase-one extension does not expose automation or call its bridge. The browser imports only its schema and semantic targets. To execute, the host provides the same-origin bridge to a Node process importing `runCase` or `createAgentBridge` from `gz-laya-pilot`; no copied runner or extension-specific replay path exists. Never bundle Node execution or model keys into the browser. This repository's `vite/laya-pilot.plugin.ts` and `tools/laya-pilot-recorded-runner.mjs` provide localhost integration, not a production test service.
74
86
 
75
87
  Bridge: `GET /status` returns RunStatus + available; `POST /run` accepts `{testCase, delay, headed}` and returns 202 + status; `POST /stop` stops the run. POST uses JSON and `X-Laya-Pilot: recorded-case-v1`. The host must authenticate, validate input, restrict test targets and serialize runs. Server results use idle/running/passed/completed/failed/stopped and assertion evidence.
76
88
 
@@ -80,7 +92,7 @@ OverlayScrollbars handles scroll visibility/dragging. Performance warnings are b
80
92
 
81
93
  ## Verifying parity in this repository
82
94
 
83
- Run `npm run assistant:build`, `npm run assistant:test` and `npm run assistant:parity` (system Chrome required). The browser suite mounts each public entrypoint on the same fixture, records trusted form actions, adds an assertion through the editor, exports/imports JSON, and executes passing and failing cases through the real `gz-laya-pilot` Node package. It compares case JSON, replay results and theme styles, and checks window controls, narrow layouts, diagnostics, session reset and cleanup. It starts and closes its own local server; results are saved under `test-results/entry-parity/`.
95
+ Run `npm run assistant:build`, `npm run assistant:test` and `npm run assistant:parity` (system Chrome required). The npm browser suite mounts the public React component on a fixture, records trusted form actions, adds an assertion through the editor, exports/imports JSON, and executes passing and failing cases through the real `gz-laya-pilot` Node package. It checks case JSON, replay results, theme styles, and window controls, narrow layouts, diagnostics, session reset and cleanup. It starts and closes its own local server; results are saved under `test-results/entry-parity/`.
84
96
 
85
97
  ## 源码组织约定
86
98
 
@@ -88,9 +100,9 @@ Run `npm run assistant:build`, `npm run assistant:test` and `npm run assistant:p
88
100
 
89
101
  ```text
90
102
  src/
91
- ├─ index.ts / sdk.tsx / core.ts # npm、SDK、无 UI 能力的稳定公开入口
103
+ ├─ index.ts / core.ts # npm 组件、无 UI 能力的稳定公开入口
92
104
  ├─ App.tsx / App.module.less # 会话与 gg-ui 主题 token,样式就近存放
93
- ├─ App.test.tsx # 入口一致性测试
105
+ ├─ App.test.tsx # npm 会话与生命周期测试
94
106
  ├─ api/ # 回放服务通信、知识问答适配协议
95
107
  ├─ components/
96
108
  │ └─ AssistantAvatar/ # 复用的小机器人组件
@@ -124,6 +136,6 @@ src/
124
136
  - 目录或样式迁移不得改变小机器人 SVG、界面布局、行为及公开 API。新增功能沿用所属模块,不再堆回源码根目录。
125
137
  - 当前 UI 已冻结:未经用户明确授权,不修改任何样式、布局、图标或其他视觉表现相关代码;功能优化沿用现有界面。
126
138
 
127
- 自主探索的操作类型、断言与证据保存在 Excel 中,尚未验证的入口记录在工作簿“探索范围”及运行结果元数据中;“用例通过”不表示页面功能全覆盖。0.1.3 保留原有结果区 UI,React 与 SDK 仍使用同一 AgentPanel 和同一 `gz-laya-pilot` 工作流。
139
+ 自主探索的操作类型、断言与证据保存在 Excel 中,尚未验证的入口记录在工作簿“探索范围”及运行结果元数据中;“用例通过”不表示页面功能全覆盖。0.1.3 保留原有结果区 UI,npm 与 Chrome 扩展 仍使用同一 AgentPanel 和同一 `gz-laya-pilot` 工作流。
128
140
 
129
141
  关联列表测试在本轮新建父记录中选择现有数据、确认添加、独立会话核对,再移除关联并独立确认恢复。该事务与断言保存进 Excel,由相同引擎回放;不能将只打开详情页签计为关联业务测试通过。
package/dist/App.d.ts CHANGED
@@ -1,12 +1,16 @@
1
1
  import { type ComponentProps } from 'react';
2
- import { ConfigProvider } from '@chenhui996/gg-ui';
2
+ import { ConfigProvider } from 'gz-ui-web';
3
3
  import { type ResearchAssistantProps as ViewProps } from './pages/assistant/index';
4
4
  import { type AssistantOptions } from './utils/diagnostics/runtime';
5
5
  export interface ResearchAssistantProps extends ViewProps {
6
+ /** The host owns the activation condition. Disabling tears down collection and UI. */
7
+ enabled?: boolean;
6
8
  runtimeOptions?: AssistantOptions;
7
9
  themeMode?: ComponentProps<typeof ConfigProvider>['themeMode'];
8
10
  /** Change when the authenticated user/session changes to discard the previous session. */
9
11
  sessionKey?: string | number;
12
+ /** Container for overlays when embedded by the browser extension. */
13
+ popupContainer?: HTMLElement;
10
14
  }
11
- /** React and imperative SDK mounts enter the same session, theme and UI here. */
12
- export default function ResearchAssistant(props?: ResearchAssistantProps): import("react/jsx-runtime").JSX.Element;
15
+ /** npm and the browser extension share the same session, theme and UI. */
16
+ export default function ResearchAssistant(props?: ResearchAssistantProps): import("react/jsx-runtime").JSX.Element | null;
@@ -8,5 +8,5 @@ export declare const agentArtifactUrl: (base: string, id: string, file: string)
8
8
  export type AutomationStatus = RunStatus & {
9
9
  available?: boolean;
10
10
  };
11
- /** Same-origin replay bridge; shared by the React and SDK panels. */
11
+ /** Same-origin replay bridge; shared by the npm and browser extension panels. */
12
12
  export declare function bridge(base: string, action: 'status' | 'run' | 'stop', body?: unknown): Promise<AutomationStatus>;
@@ -0,0 +1,16 @@
1
+ import { Component, type ReactNode } from 'react';
2
+ /** An embedded assistant must not take down the host application's React tree. */
3
+ export default class AssistantErrorBoundary extends Component<{
4
+ children: ReactNode;
5
+ }, {
6
+ failed: boolean;
7
+ }> {
8
+ state: {
9
+ failed: boolean;
10
+ };
11
+ static getDerivedStateFromError(): {
12
+ failed: boolean;
13
+ };
14
+ componentDidCatch(error: Error): void;
15
+ render(): ReactNode;
16
+ }