gz-research-assistant 0.1.0 → 0.1.2
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 +102 -21
- package/dist/App-B12hd4tM.js +2524 -0
- package/dist/App-B12hd4tM.js.map +1 -0
- package/dist/App.d.ts +12 -0
- package/dist/api/automation.d.ts +12 -0
- package/dist/{knowledge.d.ts → api/knowledge.d.ts} +1 -1
- package/dist/components/AssistantAvatar/index.d.ts +3 -0
- package/dist/core.d.ts +4 -4
- package/dist/core.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/pages/assistant/components/AgentPanel/index.d.ts +5 -0
- package/dist/{automation/AssertionEditor.d.ts → pages/assistant/components/AssertionEditor/index.d.ts} +1 -1
- package/dist/{PerformancePanel.d.ts → pages/assistant/components/PerformancePanel/index.d.ts} +1 -1
- package/dist/{automation/StepSupplement.d.ts → pages/assistant/components/StepSupplement/index.d.ts} +1 -1
- package/dist/{TimelinePanel.d.ts → pages/assistant/components/TimelinePanel/index.d.ts} +1 -1
- package/dist/{ResearchAssistant.d.ts → pages/assistant/index.d.ts} +0 -1
- package/dist/{recorder-Da1VSLid.js → recorder-ClSMnnGL.js} +67 -59
- package/dist/recorder-ClSMnnGL.js.map +1 -0
- package/dist/sdk.d.ts +6 -3
- package/dist/sdk.js +27 -9
- package/dist/sdk.js.map +1 -1
- package/dist/style.css +1 -10
- package/dist/{automation → utils/automation}/timeline-case.d.ts +1 -1
- package/dist/{runtime.d.ts → utils/diagnostics/runtime.d.ts} +1 -0
- package/package.json +2 -2
- package/dist/AssistantAvatar.d.ts +0 -1
- package/dist/ResearchAssistant-DAsgcwcG.js +0 -1757
- package/dist/ResearchAssistant-DAsgcwcG.js.map +0 -1
- package/dist/recorder-Da1VSLid.js.map +0 -1
- /package/dist/{FloatingPanel.d.ts → layouts/FloatingPanel/index.d.ts} +0 -0
- /package/dist/{useOverlayScrollbars.d.ts → layouts/FloatingPanel/useOverlayScrollbars.d.ts} +0 -0
- /package/dist/{automation/AutomationPanel.d.ts → pages/assistant/components/AutomationPanel/index.d.ts} +0 -0
- /package/dist/{automation → utils/automation}/recorder.d.ts +0 -0
- /package/dist/{automation → utils/automation}/schema.d.ts +0 -0
- /package/dist/{performance.d.ts → utils/diagnostics/performance.d.ts} +0 -0
- /package/dist/{privacy.d.ts → utils/diagnostics/privacy.d.ts} +0 -0
- /package/dist/{snapshot.d.ts → utils/diagnostics/snapshot.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -6,38 +6,119 @@ Installable research assistant with gz-ui components, diagnostics, recording, as
|
|
|
6
6
|
npm install gz-research-assistant @chenhui996/gg-ui @ant-design/icons antd react react-dom
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+
## React component
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { ResearchAssistant, type ResearchAssistantProps } from 'gz-research-assistant';
|
|
13
|
+
import '@chenhui996/gg-ui/gg-ui.css';
|
|
14
|
+
import 'gz-research-assistant/style.css';
|
|
15
|
+
|
|
16
|
+
// Keep callback references stable (module scope or useCallback).
|
|
17
|
+
const options: ResearchAssistantProps = {
|
|
18
|
+
developer: true,
|
|
19
|
+
bridgeUrl: '/__laya-pilot',
|
|
20
|
+
themeMode: 'gold-dark',
|
|
21
|
+
runtimeOptions: {
|
|
22
|
+
isBusinessFailure: (body) =>
|
|
23
|
+
!!body && typeof body === 'object' && 'code' in body && body.code !== 0,
|
|
24
|
+
ignoreRequest: (url) => url.pathname.startsWith('/telemetry/'),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Render only after login; unmount on logout.
|
|
29
|
+
<ResearchAssistant {...options} sessionKey={userId} />;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Imperative SDK
|
|
33
|
+
|
|
9
34
|
```tsx
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
ResearchAssistant,
|
|
13
|
-
startAssistant,
|
|
14
|
-
assistantRuntime,
|
|
15
|
-
recorder,
|
|
16
|
-
} from 'gz-research-assistant';
|
|
35
|
+
import { mountAssistant } from 'gz-research-assistant/sdk';
|
|
17
36
|
import '@chenhui996/gg-ui/gg-ui.css';
|
|
18
37
|
import 'gz-research-assistant/style.css';
|
|
19
38
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}, []);
|
|
29
|
-
return <ResearchAssistant developer bridgeUrl="/__laya-pilot" />;
|
|
30
|
-
}
|
|
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.
|
|
31
47
|
```
|
|
32
48
|
|
|
33
|
-
|
|
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.
|
|
50
|
+
|
|
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.
|
|
52
|
+
|
|
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.
|
|
54
|
+
|
|
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.
|
|
34
56
|
|
|
35
|
-
|
|
57
|
+
### Migrating from 0.1.0
|
|
36
58
|
|
|
37
|
-
|
|
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.
|
|
60
|
+
|
|
61
|
+
## Shared automation dependency
|
|
62
|
+
|
|
63
|
+
Version 0.1.2 adds **自主探索** above the recording tools, shared by React and SDK. Select a host-authorized page, allow test-data writes if needed, explore, download the upstream Excel workbook, then import it for fresh-session replay. The Node host uses `gz-laya-pilot@0.1.1` through `createAgentBridge()` → `runAgent()` → the pinned upstream `runWorkflow`; generation and replay both use local Laya, with real Playwright assertions and evidence. The local model still refuses the English `Credit limit` field in one independent fixture; that CRUD flow and the full cross-backend acceptance remain failing. See [setup, boundaries and actual acceptance results](https://github.com/chenhui996/gz-zd-web/blob/codex/research-assistant/docs/研发小蜜自主探索.md).
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
React <ResearchAssistant> ─┐
|
|
67
|
+
├→ shared Assistant → recorder / assertion UI
|
|
68
|
+
SDK mountAssistant ───────┘ ├→ gz-laya-pilot/browser (semantic targets)
|
|
69
|
+
├→ gz-laya-pilot/schema (case validation)
|
|
70
|
+
└→ HTTP bridge → Node gz-laya-pilot.runCase
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`gz-laya-pilot@0.1.1` 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.
|
|
38
74
|
|
|
39
75
|
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.
|
|
40
76
|
|
|
41
77
|
Timeline data stays in memory (300 events / 60 requests / 15 minutes), with private inputs excluded and JSON previews redacted. Timeline text is presentation only. Passive history never reconstructs input values or runnable selectors. Active recordings store structured targets and actions; add `data-testid`, proper labels or `data-assistant-label` to improve semantics. Closed Shadow DOM and cross-origin frames require host adapters.
|
|
42
78
|
|
|
43
79
|
OverlayScrollbars handles scroll visibility/dragging. Performance warnings are bounded heuristics, not proof of a memory leak. rrweb visual replay and OpenTelemetry trace correlation are optional future integrations, not silently enabled collection.
|
|
80
|
+
|
|
81
|
+
## Verifying parity in this repository
|
|
82
|
+
|
|
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/`.
|
|
84
|
+
|
|
85
|
+
## 源码组织约定
|
|
86
|
+
|
|
87
|
+
遵循本仓库的 [项目目录结构规范](https://github.com/chenhui996/gz-zd-web/blob/codex/research-assistant/docs/项目目录结构规范.md),按职责和业务模块组织。小蜜是嵌入式组件,`pages/assistant` 表示浮窗内的功能视图,不另外引入路由,也不建立没有实际用途的空目录。
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
src/
|
|
91
|
+
├─ index.ts / sdk.tsx / core.ts # npm、SDK、无 UI 能力的稳定公开入口
|
|
92
|
+
├─ App.tsx / App.module.less # 会话与 gg-ui 主题 token,样式就近存放
|
|
93
|
+
├─ App.test.tsx # 入口一致性测试
|
|
94
|
+
├─ api/ # 回放服务通信、知识问答适配协议
|
|
95
|
+
├─ components/
|
|
96
|
+
│ └─ AssistantAvatar/ # 复用的小机器人组件
|
|
97
|
+
│ ├─ index.tsx
|
|
98
|
+
│ └─ index.module.less
|
|
99
|
+
├─ layouts/
|
|
100
|
+
│ └─ FloatingPanel/ # 浮窗布局、滚动条 Hook、就近测试
|
|
101
|
+
│ ├─ index.tsx
|
|
102
|
+
│ └─ index.module.less
|
|
103
|
+
├─ pages/
|
|
104
|
+
│ └─ assistant/
|
|
105
|
+
│ ├─ index.tsx # 主界面与页签装配
|
|
106
|
+
│ ├─ index.module.less # 当前页面样式及页面内复用的布局样式
|
|
107
|
+
│ └─ components/ # 页面私有组件,每个目录均有 TSX + module.less
|
|
108
|
+
│ ├─ AutomationPanel/
|
|
109
|
+
│ ├─ AgentPanel/
|
|
110
|
+
│ ├─ AssertionEditor/
|
|
111
|
+
│ ├─ StepSupplement/
|
|
112
|
+
│ ├─ TimelinePanel/
|
|
113
|
+
│ └─ PerformancePanel/
|
|
114
|
+
└─ utils/
|
|
115
|
+
├─ diagnostics/ # 采集、脱敏、快照、性能规则及就近测试
|
|
116
|
+
└─ automation/ # 录制、用例协议、时间线转换及就近测试
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- `pages` 负责视图,页面专用组件放在该页面的 `components` 下;`layouts` 负责浮窗容器,`components` 存放复用组件,`api` 负责通信,`utils` 负责非 UI 能力。工具逻辑不依赖 React 或视图,测试与实现就近存放。
|
|
120
|
+
- 宿主只能从包的公开入口导入;包内按实际依赖直接引用文件,避免为每层增加重复转发的 `index.ts`。跨业务复用限于模型和协议,不让面板相互嵌套依赖。
|
|
121
|
+
- 有自有样式的组件使用同目录的 `index.tsx` 和 `index.module.less`,TSX 统一通过 `import styles from './index.module.less'` 导入。禁止把组件样式集中到远处的 `shared/styles`,也不使用普通 `.less` 的副作用导入。
|
|
122
|
+
- 组件的专属样式及响应式规则放在自己的 module 中;页面内共用的间距、字段、按钮行等通过 CSS Modules 的 `composes` 显式复用页面样式,避免复制声明。不要通过 Less 汇总导入所有组件样式。
|
|
123
|
+
- `:global(...)` 仅用于 gg-ui/OverlayScrollbars 内部类名,必须受本地类名约束。滚动逻辑和浏览器检查使用 `data-assistant-part`、`data-expanded` 等稳定标记,不依赖生成的 CSS 类名。
|
|
124
|
+
- 目录或样式迁移不得改变小机器人 SVG、界面布局、行为及公开 API。新增功能沿用所属模块,不再堆回源码根目录。
|