yiyan-browser-agent 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 doubao-browser-agent contributors
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 ADDED
@@ -0,0 +1,145 @@
1
+ # doubao-browser-agent
2
+
3
+ NPM package for interacting with Doubao (豆包) web version via Playwright.
4
+
5
+ ## Features
6
+
7
+ - Automated browser interaction with Doubao web version
8
+ - Automatic Chrome profile management for login persistence
9
+ - Retry mechanism for network failures
10
+ - CLI and Node.js API support
11
+ - TypeScript support with full type definitions
12
+
13
+ ## Prerequisites
14
+
15
+ 1. **Chrome browser** installed on your system
16
+ 2. **Logged into Doubao** (https://www.doubao.com/chat/) in your Chrome browser at least once
17
+
18
+ The package uses your Chrome profile to maintain login state, so you need to login manually first.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install doubao-browser-agent
24
+ ```
25
+
26
+ ## Node.js API Usage
27
+
28
+ ```typescript
29
+ import { DoubaoAgent } from 'doubao-browser-agent';
30
+
31
+ // Create agent instance
32
+ const agent = new DoubaoAgent({
33
+ timeout: 120000, // Timeout in milliseconds (default: 120000)
34
+ retryCount: 3, // Retry count (default: 3)
35
+ });
36
+
37
+ // Send a question and get answer
38
+ try {
39
+ const answer = await agent.ask('What is TypeScript?');
40
+ console.log('Answer:', answer);
41
+ } catch (error) {
42
+ console.error('Error:', error.message);
43
+ }
44
+
45
+ // Check login status
46
+ const status = agent.status();
47
+ console.log('Logged in:', status.loggedIn);
48
+ console.log('Profile path:', status.profilePath);
49
+
50
+ // Clear saved profile (if needed)
51
+ await agent.reset();
52
+ ```
53
+
54
+ ## CLI Usage
55
+
56
+ ```bash
57
+ # Send a question
58
+ doubao-agent ask "What is TypeScript?"
59
+
60
+ # With options
61
+ doubao-agent ask "Explain Promise" --timeout 60000 --retry 5
62
+
63
+ # Check login status
64
+ doubao-agent status
65
+
66
+ # Clear saved profile
67
+ doubao-agent reset
68
+
69
+ # Show help
70
+ doubao-agent --help
71
+ ```
72
+
73
+ ## API Documentation
74
+
75
+ ### `DoubaoAgent`
76
+
77
+ Main class for interacting with Doubao.
78
+
79
+ #### Constructor
80
+
81
+ ```typescript
82
+ new DoubaoAgent(options?: DoubaoAgentOptions)
83
+ ```
84
+
85
+ **Options:**
86
+ - `timeout?: number` - Timeout in milliseconds (default: 120000)
87
+ - `retryCount?: number` - Number of retry attempts (default: 3)
88
+ - `profileDir?: string` - Custom directory for storing Chrome profile copy
89
+ - `chromePath?: string` - Custom Chrome executable path
90
+
91
+ #### Methods
92
+
93
+ ##### `ask(question: string): Promise<string>`
94
+
95
+ Send a question to Doubao and return the answer.
96
+
97
+ ##### `status(): { loggedIn: boolean; profilePath: string }`
98
+
99
+ Check the login status (whether profile exists).
100
+
101
+ ##### `reset(): Promise<void>`
102
+
103
+ Clear the saved profile copy.
104
+
105
+ ### Error Types
106
+
107
+ The package throws `DoubaoAgentError` with the following error types:
108
+
109
+ | Type | Description |
110
+ |------|-------------|
111
+ | `BROWSER_LAUNCH` | Failed to launch Chrome browser |
112
+ | `PROFILE_COPY` | Failed to copy Chrome profile |
113
+ | `TIMEOUT` | Timeout while waiting for response |
114
+ | `NETWORK` | Network or connection error |
115
+
116
+ ```typescript
117
+ import { DoubaoAgentError } from 'doubao-browser-agent';
118
+
119
+ try {
120
+ const answer = await agent.ask('Hello');
121
+ } catch (error) {
122
+ if (error instanceof DoubaoAgentError) {
123
+ console.log('Error type:', error.type);
124
+ console.log('Error message:', error.message);
125
+ }
126
+ }
127
+ ```
128
+
129
+ ## How It Works
130
+
131
+ 1. On first run, the package copies your Chrome profile to a temporary directory
132
+ 2. Launches Chrome in headless mode with the copied profile
133
+ 3. Navigates to Doubao chat page
134
+ 4. Sends your question and waits for response
135
+ 5. Extracts the response and closes the browser
136
+
137
+ ## Supported Platforms
138
+
139
+ - Windows (Chrome paths: `C:/Program Files/Google/Chrome/Application/chrome.exe`)
140
+ - macOS (Chrome paths: `/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`)
141
+ - Linux (Chrome paths: `/usr/bin/google-chrome`, `/usr/bin/chrome`)
142
+
143
+ ## License
144
+
145
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { C as CliOutput } from './types-BhQ78DYf.js';
2
+
3
+ /** CLI 帮助信息 */
4
+ declare function printHelp(): void;
5
+ /** 解析后的 CLI 参数 */
6
+ interface ParsedArgs {
7
+ command: 'ask' | 'status' | 'reset' | 'login' | 'help' | null;
8
+ question?: string;
9
+ timeout?: number;
10
+ retry?: number;
11
+ headless?: boolean;
12
+ }
13
+ /**
14
+ * 解析 CLI 参数
15
+ */
16
+ declare function parseCliArgs(args: string[]): ParsedArgs;
17
+ /**
18
+ * 格式化 CLI 输出为 JSON
19
+ */
20
+ declare function formatCliOutput(output: CliOutput): string;
21
+ /**
22
+ * CLI 主入口
23
+ */
24
+ declare function runCli(args: string[]): Promise<void>;
25
+
26
+ export { formatCliOutput, parseCliArgs, printHelp, runCli };