traw 0.2.3 → 0.2.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/package.json +1 -1
- package/src/agent/agent.ts +6 -2
- package/src/api/mo-client.ts +25 -11
package/package.json
CHANGED
package/src/agent/agent.ts
CHANGED
|
@@ -72,9 +72,13 @@ export class Agent {
|
|
|
72
72
|
log.step(step + 1, this.config.maxSteps, state.url)
|
|
73
73
|
|
|
74
74
|
const thinkStart = Date.now()
|
|
75
|
+
let decision: { thought: string; action: Action }
|
|
75
76
|
log.receiveStart()
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
try {
|
|
78
|
+
decision = await this.think(state)
|
|
79
|
+
} finally {
|
|
80
|
+
log.receiveStop()
|
|
81
|
+
}
|
|
78
82
|
this.aiTime += Date.now() - thinkStart
|
|
79
83
|
|
|
80
84
|
log.thought(decision.thought)
|
package/src/api/mo-client.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class MoClient {
|
|
|
22
22
|
this.thinking = opts.thinking
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
async chat(messages: ChatMessage[]): Promise<string> {
|
|
25
|
+
async chat(messages: ChatMessage[], timeoutMs = 300000): Promise<string> {
|
|
26
26
|
const headers: Record<string, string> = {
|
|
27
27
|
"Content-Type": "application/json",
|
|
28
28
|
}
|
|
@@ -31,16 +31,30 @@ export class MoClient {
|
|
|
31
31
|
headers["Authorization"] = `Bearer ${this.apiKey}`
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
const controller = new AbortController()
|
|
35
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs)
|
|
36
|
+
|
|
37
|
+
let resp: Response
|
|
38
|
+
try {
|
|
39
|
+
resp = await fetch(`${this.url}/v1/chat/completions`, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers,
|
|
42
|
+
signal: controller.signal,
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
model: this.model,
|
|
45
|
+
messages,
|
|
46
|
+
stream: false,
|
|
47
|
+
thinking: this.thinking,
|
|
48
|
+
}),
|
|
49
|
+
})
|
|
50
|
+
} catch (err: any) {
|
|
51
|
+
clearTimeout(timeoutId)
|
|
52
|
+
if (err.name === "AbortError") {
|
|
53
|
+
throw new Error(`mo timeout: no response in ${timeoutMs / 1000}s`)
|
|
54
|
+
}
|
|
55
|
+
throw err
|
|
56
|
+
}
|
|
57
|
+
clearTimeout(timeoutId)
|
|
44
58
|
|
|
45
59
|
if (!resp.ok) {
|
|
46
60
|
const body = await resp.text()
|