traw 0.2.4 → 0.2.6
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/package.json +1 -1
- package/readme.md +3 -3
- package/src/cli/index.ts +48 -71
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -30,9 +30,9 @@ Traw is a simple and fast neuro agent that browses the internet instead of you
|
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
# install the traw
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
bun add -g traw
|
|
34
|
+
# or
|
|
35
|
+
npm i -g traw
|
|
36
36
|
|
|
37
37
|
# auth the traw
|
|
38
38
|
bun run traw auth
|
package/src/cli/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
+
import { parseArgs } from "util"
|
|
2
3
|
import { Agent } from "../agent/agent"
|
|
3
4
|
import type { AgentConfig } from "../types"
|
|
4
5
|
import { log, setSilent } from "../utils/log"
|
|
@@ -9,6 +10,22 @@ import { checkFirstRun, markFirstRunDone, showStarBanner } from "../utils/first-
|
|
|
9
10
|
|
|
10
11
|
const DEFAULT_MO_PORT = 8804
|
|
11
12
|
|
|
13
|
+
const cliOptions = {
|
|
14
|
+
help: { type: "boolean" as const, short: "h" as const },
|
|
15
|
+
version: { type: "boolean" as const, short: "v" as const },
|
|
16
|
+
headless: { type: "boolean" as const },
|
|
17
|
+
headed: { type: "boolean" as const },
|
|
18
|
+
video: { type: "boolean" as const },
|
|
19
|
+
fast: { type: "boolean" as const },
|
|
20
|
+
debug: { type: "boolean" as const },
|
|
21
|
+
json: { type: "boolean" as const },
|
|
22
|
+
steps: { type: "string" as const },
|
|
23
|
+
mo: { type: "string" as const },
|
|
24
|
+
api: { type: "string" as const },
|
|
25
|
+
"api-key": { type: "string" as const },
|
|
26
|
+
model: { type: "string" as const },
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
const defaultConfig: AgentConfig = {
|
|
13
30
|
moUrl: `http://localhost:${DEFAULT_MO_PORT}`,
|
|
14
31
|
apiUrl: undefined,
|
|
@@ -94,28 +111,30 @@ async function registerAccount(moUrl: string): Promise<void> {
|
|
|
94
111
|
}
|
|
95
112
|
|
|
96
113
|
async function main() {
|
|
97
|
-
const
|
|
114
|
+
const { values, positionals } = parseArgs({
|
|
115
|
+
args: Bun.argv.slice(2),
|
|
116
|
+
options: cliOptions,
|
|
117
|
+
allowPositionals: true,
|
|
118
|
+
strict: false,
|
|
119
|
+
})
|
|
98
120
|
|
|
99
|
-
// show star banner on first run (non-blocking)
|
|
100
121
|
if (await checkFirstRun()) {
|
|
101
122
|
showStarBanner()
|
|
102
123
|
await markFirstRunDone()
|
|
103
124
|
}
|
|
104
125
|
|
|
105
|
-
if (
|
|
126
|
+
if (positionals.length === 0 || values.help) {
|
|
106
127
|
printHelp()
|
|
107
128
|
return
|
|
108
129
|
}
|
|
109
130
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// handle version command
|
|
113
|
-
if (cmd === "--version" || cmd === "-v") {
|
|
131
|
+
if (values.version) {
|
|
114
132
|
console.log(`traw ${VERSION}`)
|
|
115
133
|
return
|
|
116
134
|
}
|
|
117
135
|
|
|
118
|
-
|
|
136
|
+
const cmd = positionals[0]
|
|
137
|
+
|
|
119
138
|
if (cmd === "upd" || cmd === "update") {
|
|
120
139
|
log.info(`current version: ${VERSION}`)
|
|
121
140
|
log.info("checking for updates...")
|
|
@@ -136,14 +155,8 @@ async function main() {
|
|
|
136
155
|
return
|
|
137
156
|
}
|
|
138
157
|
|
|
139
|
-
// handle auth command
|
|
140
158
|
if (cmd === "auth") {
|
|
141
|
-
|
|
142
|
-
for (let i = 1; i < args.length; i++) {
|
|
143
|
-
if (args[i].startsWith("--mo=")) {
|
|
144
|
-
moUrl = args[i].split("=")[1]
|
|
145
|
-
}
|
|
146
|
-
}
|
|
159
|
+
const moUrl = typeof values.mo === "string" ? values.mo : defaultConfig.moUrl
|
|
147
160
|
|
|
148
161
|
if (!await ensureMo(moUrl)) {
|
|
149
162
|
process.exit(1)
|
|
@@ -165,63 +178,26 @@ async function main() {
|
|
|
165
178
|
process.exit(1)
|
|
166
179
|
}
|
|
167
180
|
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
if (arg === "--fast") {
|
|
187
|
-
config.model = "0727-106B-API"
|
|
188
|
-
config.thinking = false
|
|
189
|
-
continue
|
|
190
|
-
}
|
|
191
|
-
if (arg === "--debug") {
|
|
192
|
-
config.debug = true
|
|
193
|
-
continue
|
|
194
|
-
}
|
|
195
|
-
if (arg === "--json") {
|
|
196
|
-
config.jsonOutput = true
|
|
197
|
-
continue
|
|
198
|
-
}
|
|
199
|
-
if (arg.startsWith("--steps=")) {
|
|
200
|
-
config.maxSteps = parseInt(arg.split("=")[1])
|
|
201
|
-
continue
|
|
202
|
-
}
|
|
203
|
-
if (arg.startsWith("--mo=")) {
|
|
204
|
-
config.moUrl = arg.split("=")[1]
|
|
205
|
-
continue
|
|
206
|
-
}
|
|
207
|
-
if (arg.startsWith("--api=")) {
|
|
208
|
-
config.apiUrl = arg.split("=")[1]
|
|
209
|
-
continue
|
|
210
|
-
}
|
|
211
|
-
if (arg.startsWith("--api-key=")) {
|
|
212
|
-
config.apiKey = arg.split("=")[1]
|
|
213
|
-
continue
|
|
214
|
-
}
|
|
215
|
-
if (arg.startsWith("--model=")) {
|
|
216
|
-
config.model = arg.split("=")[1]
|
|
217
|
-
continue
|
|
218
|
-
}
|
|
219
|
-
if (!arg.startsWith("--")) {
|
|
220
|
-
goalParts.push(arg)
|
|
221
|
-
}
|
|
181
|
+
const moUrl = typeof values.mo === "string" ? values.mo : defaultConfig.moUrl
|
|
182
|
+
const apiUrl = typeof values.api === "string" ? values.api : undefined
|
|
183
|
+
const apiKey = typeof values["api-key"] === "string" ? values["api-key"] : defaultConfig.apiKey
|
|
184
|
+
const model = typeof values.model === "string" ? values.model : (values.fast ? "0727-106B-API" : defaultConfig.model)
|
|
185
|
+
const steps = typeof values.steps === "string" ? parseInt(values.steps) : defaultConfig.maxSteps
|
|
186
|
+
|
|
187
|
+
const config: AgentConfig = {
|
|
188
|
+
moUrl,
|
|
189
|
+
apiUrl,
|
|
190
|
+
apiKey,
|
|
191
|
+
model,
|
|
192
|
+
thinking: values.fast !== true,
|
|
193
|
+
headless: values.headed === true ? false : (values.headless === true || defaultConfig.headless),
|
|
194
|
+
recordVideo: values.video === true,
|
|
195
|
+
maxSteps: steps,
|
|
196
|
+
debug: values.debug === true,
|
|
197
|
+
jsonOutput: values.json === true,
|
|
222
198
|
}
|
|
223
199
|
|
|
224
|
-
const goal =
|
|
200
|
+
const goal = positionals.slice(1).join(" ")
|
|
225
201
|
if (!goal) {
|
|
226
202
|
log.error("provide a goal: bun run traw run \"your goal\"")
|
|
227
203
|
process.exit(1)
|
|
@@ -230,10 +206,11 @@ async function main() {
|
|
|
230
206
|
if (!config.jsonOutput) {
|
|
231
207
|
log.header(goal)
|
|
232
208
|
log.config({
|
|
233
|
-
|
|
209
|
+
mo: config.apiUrl || config.moUrl,
|
|
234
210
|
model: config.model,
|
|
235
211
|
headless: config.headless,
|
|
236
212
|
video: config.recordVideo,
|
|
213
|
+
vision: false,
|
|
237
214
|
steps: config.maxSteps,
|
|
238
215
|
})
|
|
239
216
|
} else {
|