@electric-agent/studio 1.5.0 → 1.12.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/dist/api-schemas.d.ts +225 -0
- package/dist/api-schemas.d.ts.map +1 -0
- package/dist/api-schemas.js +95 -0
- package/dist/api-schemas.js.map +1 -0
- package/dist/bridge/claude-code-base.d.ts +121 -0
- package/dist/bridge/claude-code-base.d.ts.map +1 -0
- package/dist/bridge/claude-code-base.js +263 -0
- package/dist/bridge/claude-code-base.js.map +1 -0
- package/dist/bridge/claude-code-docker.d.ts +13 -73
- package/dist/bridge/claude-code-docker.d.ts.map +1 -1
- package/dist/bridge/claude-code-docker.js +91 -302
- package/dist/bridge/claude-code-docker.js.map +1 -1
- package/dist/bridge/claude-code-sprites.d.ts +12 -59
- package/dist/bridge/claude-code-sprites.d.ts.map +1 -1
- package/dist/bridge/claude-code-sprites.js +88 -281
- package/dist/bridge/claude-code-sprites.js.map +1 -1
- package/dist/bridge/claude-md-generator.d.ts +22 -5
- package/dist/bridge/claude-md-generator.d.ts.map +1 -1
- package/dist/bridge/claude-md-generator.js +81 -213
- package/dist/bridge/claude-md-generator.js.map +1 -1
- package/dist/bridge/codex-docker.d.ts +56 -51
- package/dist/bridge/codex-docker.js +222 -230
- package/dist/bridge/codex-json-parser.d.ts +11 -11
- package/dist/bridge/codex-json-parser.js +231 -238
- package/dist/bridge/codex-md-generator.d.ts +3 -3
- package/dist/bridge/codex-md-generator.js +42 -32
- package/dist/bridge/codex-sprites.d.ts +50 -45
- package/dist/bridge/codex-sprites.js +212 -222
- package/dist/bridge/daytona.d.ts +25 -25
- package/dist/bridge/daytona.js +131 -136
- package/dist/bridge/docker-stdio.d.ts +21 -21
- package/dist/bridge/docker-stdio.js +126 -132
- package/dist/bridge/hosted.d.ts +3 -2
- package/dist/bridge/hosted.d.ts.map +1 -1
- package/dist/bridge/hosted.js +4 -0
- package/dist/bridge/hosted.js.map +1 -1
- package/dist/bridge/message-parser.d.ts +24 -0
- package/dist/bridge/message-parser.d.ts.map +1 -0
- package/dist/bridge/message-parser.js +39 -0
- package/dist/bridge/message-parser.js.map +1 -0
- package/dist/bridge/role-skills.d.ts +25 -0
- package/dist/bridge/role-skills.d.ts.map +1 -0
- package/dist/bridge/role-skills.js +120 -0
- package/dist/bridge/role-skills.js.map +1 -0
- package/dist/bridge/room-messaging-skill.d.ts +11 -0
- package/dist/bridge/room-messaging-skill.d.ts.map +1 -0
- package/dist/bridge/room-messaging-skill.js +41 -0
- package/dist/bridge/room-messaging-skill.js.map +1 -0
- package/dist/bridge/sprites.d.ts +22 -22
- package/dist/bridge/sprites.js +123 -128
- package/dist/bridge/stream-json-parser.js +12 -5
- package/dist/bridge/stream-json-parser.js.map +1 -1
- package/dist/bridge/types.d.ts +4 -10
- package/dist/bridge/types.d.ts.map +1 -1
- package/dist/client/assets/index-BfvQSMwH.css +1 -0
- package/dist/client/assets/index-CiwD5LkP.js +235 -0
- package/dist/client/index.html +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/invite-code.d.ts +5 -0
- package/dist/invite-code.d.ts.map +1 -0
- package/dist/invite-code.js +14 -0
- package/dist/invite-code.js.map +1 -0
- package/dist/project-utils.d.ts.map +1 -1
- package/dist/project-utils.js.map +1 -1
- package/dist/registry.d.ts +11 -4
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/room-router.d.ts +73 -0
- package/dist/room-router.d.ts.map +1 -0
- package/dist/room-router.js +345 -0
- package/dist/room-router.js.map +1 -0
- package/dist/sandbox/docker.d.ts.map +1 -1
- package/dist/sandbox/docker.js +5 -6
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/index.d.ts +0 -1
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +0 -1
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/sprites.d.ts.map +1 -1
- package/dist/sandbox/sprites.js +40 -10
- package/dist/sandbox/sprites.js.map +1 -1
- package/dist/sandbox/types.d.ts +4 -2
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/server.d.ts +12 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +824 -309
- package/dist/server.js.map +1 -1
- package/dist/session-auth.d.ts +9 -0
- package/dist/session-auth.d.ts.map +1 -1
- package/dist/session-auth.js +30 -0
- package/dist/session-auth.js.map +1 -1
- package/dist/sessions.d.ts +7 -1
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js.map +1 -1
- package/dist/streams.d.ts +2 -6
- package/dist/streams.d.ts.map +1 -1
- package/dist/streams.js +6 -17
- package/dist/streams.js.map +1 -1
- package/dist/validate.d.ts +10 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +24 -0
- package/dist/validate.js.map +1 -0
- package/package.json +6 -9
- package/dist/client/assets/index-DDzmxYub.js +0 -234
- package/dist/client/assets/index-DcP7prsZ.css +0 -1
|
@@ -8,52 +8,57 @@
|
|
|
8
8
|
* Codex runs in one-shot mode (`codex exec --json`) and exits after completing.
|
|
9
9
|
* On iterate (follow-up message), the bridge respawns Codex with the new prompt.
|
|
10
10
|
*/
|
|
11
|
-
import type { EngineEvent } from "@electric-agent/protocol"
|
|
12
|
-
import type { Sprite } from "@fly/sprites"
|
|
13
|
-
import type { StreamConnectionInfo } from "../streams.js"
|
|
14
|
-
import type { SessionBridge } from "./types.js"
|
|
11
|
+
import type { EngineEvent } from "@electric-agent/protocol"
|
|
12
|
+
import type { Sprite } from "@fly/sprites"
|
|
13
|
+
import type { StreamConnectionInfo } from "../streams.js"
|
|
14
|
+
import type { SessionBridge } from "./types.js"
|
|
15
15
|
export interface CodexSpritesConfig {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
/** Initial prompt (the user's app description or task) */
|
|
17
|
+
prompt: string
|
|
18
|
+
/** Working directory inside the sprite */
|
|
19
|
+
cwd: string
|
|
20
|
+
/** Model to use (default: o4-mini) */
|
|
21
|
+
model?: string
|
|
22
|
+
/** Additional CLI flags */
|
|
23
|
+
extraFlags?: string[]
|
|
24
24
|
}
|
|
25
25
|
export declare class CodexSpritesBridge implements SessionBridge {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
26
|
+
readonly sessionId: string
|
|
27
|
+
readonly streamUrl: string
|
|
28
|
+
readonly streamHeaders: Record<string, string>
|
|
29
|
+
private sprite
|
|
30
|
+
private config
|
|
31
|
+
private writer
|
|
32
|
+
private parser
|
|
33
|
+
private agentEventCallbacks
|
|
34
|
+
private completeCallbacks
|
|
35
|
+
private closed
|
|
36
|
+
private cmd
|
|
37
|
+
/** Codex thread ID captured from thread.started — used for resume */
|
|
38
|
+
private codexThreadId
|
|
39
|
+
/** Whether a Codex process is currently running */
|
|
40
|
+
private running
|
|
41
|
+
/** Whether the parser already emitted a session_end */
|
|
42
|
+
private resultReceived
|
|
43
|
+
constructor(
|
|
44
|
+
sessionId: string,
|
|
45
|
+
connection: StreamConnectionInfo,
|
|
46
|
+
sprite: Sprite,
|
|
47
|
+
config: CodexSpritesConfig,
|
|
48
|
+
)
|
|
49
|
+
emit(event: EngineEvent): Promise<void>
|
|
50
|
+
sendCommand(cmd: Record<string, unknown>): Promise<void>
|
|
51
|
+
sendGateResponse(_gate: string, _value: Record<string, unknown>): Promise<void>
|
|
52
|
+
onAgentEvent(cb: (event: EngineEvent) => void): void
|
|
53
|
+
onComplete(cb: (success: boolean) => void): void
|
|
54
|
+
start(): Promise<void>
|
|
55
|
+
close(): void
|
|
56
|
+
/**
|
|
57
|
+
* Spawn a new Codex process. Called for both the initial prompt
|
|
58
|
+
* and follow-up iterate messages.
|
|
59
|
+
*/
|
|
60
|
+
private spawnCodex
|
|
61
|
+
private handleLine
|
|
62
|
+
private dispatchEvent
|
|
58
63
|
}
|
|
59
|
-
//# sourceMappingURL=codex-sprites.d.ts.map
|
|
64
|
+
//# sourceMappingURL=codex-sprites.d.ts.map
|
|
@@ -8,230 +8,220 @@
|
|
|
8
8
|
* Codex runs in one-shot mode (`codex exec --json`) and exits after completing.
|
|
9
9
|
* On iterate (follow-up message), the bridge respawns Codex with the new prompt.
|
|
10
10
|
*/
|
|
11
|
-
import * as readline from "node:readline"
|
|
12
|
-
import { DurableStream } from "@durable-streams/client"
|
|
13
|
-
import { ts } from "@electric-agent/protocol"
|
|
14
|
-
import { SpriteCommand } from "@fly/sprites"
|
|
15
|
-
import { createCodexJsonParser } from "./codex-json-parser.js"
|
|
11
|
+
import * as readline from "node:readline"
|
|
12
|
+
import { DurableStream } from "@durable-streams/client"
|
|
13
|
+
import { ts } from "@electric-agent/protocol"
|
|
14
|
+
import { SpriteCommand } from "@fly/sprites"
|
|
15
|
+
import { createCodexJsonParser } from "./codex-json-parser.js"
|
|
16
16
|
export class CodexSpritesBridge {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
for (const cb of this.completeCallbacks) {
|
|
217
|
-
try {
|
|
218
|
-
cb(success);
|
|
219
|
-
}
|
|
220
|
-
catch {
|
|
221
|
-
// Swallow callback errors
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
17
|
+
sessionId
|
|
18
|
+
streamUrl
|
|
19
|
+
streamHeaders
|
|
20
|
+
sprite
|
|
21
|
+
config
|
|
22
|
+
writer
|
|
23
|
+
parser = createCodexJsonParser()
|
|
24
|
+
agentEventCallbacks = []
|
|
25
|
+
completeCallbacks = []
|
|
26
|
+
closed = false
|
|
27
|
+
cmd = null
|
|
28
|
+
/** Codex thread ID captured from thread.started — used for resume */
|
|
29
|
+
codexThreadId = null
|
|
30
|
+
/** Whether a Codex process is currently running */
|
|
31
|
+
running = false
|
|
32
|
+
/** Whether the parser already emitted a session_end */
|
|
33
|
+
resultReceived = false
|
|
34
|
+
constructor(sessionId, connection, sprite, config) {
|
|
35
|
+
this.sessionId = sessionId
|
|
36
|
+
this.streamUrl = connection.url
|
|
37
|
+
this.streamHeaders = connection.headers
|
|
38
|
+
this.sprite = sprite
|
|
39
|
+
this.config = config
|
|
40
|
+
this.writer = new DurableStream({
|
|
41
|
+
url: connection.url,
|
|
42
|
+
headers: connection.headers,
|
|
43
|
+
contentType: "application/json",
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
async emit(event) {
|
|
47
|
+
if (this.closed) return
|
|
48
|
+
const msg = { source: "server", ...event }
|
|
49
|
+
await this.writer.append(JSON.stringify(msg))
|
|
50
|
+
}
|
|
51
|
+
async sendCommand(cmd) {
|
|
52
|
+
if (this.closed) return
|
|
53
|
+
if (cmd.command === "iterate" && typeof cmd.request === "string") {
|
|
54
|
+
this.spawnCodex(cmd.request)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
console.log(`[codex-sprites] Ignoring unsupported command: ${cmd.command}`)
|
|
58
|
+
}
|
|
59
|
+
async sendGateResponse(_gate, _value) {
|
|
60
|
+
// Codex exec --json doesn't support stdin user messages mid-run
|
|
61
|
+
}
|
|
62
|
+
onAgentEvent(cb) {
|
|
63
|
+
this.agentEventCallbacks.push(cb)
|
|
64
|
+
}
|
|
65
|
+
onComplete(cb) {
|
|
66
|
+
this.completeCallbacks.push(cb)
|
|
67
|
+
}
|
|
68
|
+
async start() {
|
|
69
|
+
if (this.closed) return
|
|
70
|
+
this.spawnCodex(this.config.prompt)
|
|
71
|
+
}
|
|
72
|
+
close() {
|
|
73
|
+
this.closed = true
|
|
74
|
+
if (this.cmd) {
|
|
75
|
+
try {
|
|
76
|
+
this.cmd.kill()
|
|
77
|
+
} catch {
|
|
78
|
+
// Process may already be dead
|
|
79
|
+
}
|
|
80
|
+
this.cmd = null
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// -----------------------------------------------------------------------
|
|
84
|
+
// Private helpers
|
|
85
|
+
// -----------------------------------------------------------------------
|
|
86
|
+
/**
|
|
87
|
+
* Spawn a new Codex process. Called for both the initial prompt
|
|
88
|
+
* and follow-up iterate messages.
|
|
89
|
+
*/
|
|
90
|
+
spawnCodex(prompt) {
|
|
91
|
+
// Kill any existing process
|
|
92
|
+
if (this.cmd) {
|
|
93
|
+
try {
|
|
94
|
+
this.cmd.kill()
|
|
95
|
+
} catch {
|
|
96
|
+
// Already dead
|
|
97
|
+
}
|
|
98
|
+
this.cmd = null
|
|
99
|
+
}
|
|
100
|
+
// Reset parser state for the new process
|
|
101
|
+
this.parser = createCodexJsonParser()
|
|
102
|
+
this.resultReceived = false
|
|
103
|
+
this.running = true
|
|
104
|
+
const model = this.config.model ?? "o4-mini"
|
|
105
|
+
// Build the codex CLI command
|
|
106
|
+
const codexArgs = [
|
|
107
|
+
"exec",
|
|
108
|
+
"--json",
|
|
109
|
+
"--full-auto",
|
|
110
|
+
"--model",
|
|
111
|
+
model,
|
|
112
|
+
...(this.config.extraFlags ?? []),
|
|
113
|
+
"-q",
|
|
114
|
+
prompt,
|
|
115
|
+
]
|
|
116
|
+
// Escape for bash — use bash -c with properly escaped args
|
|
117
|
+
const escapedArgs = codexArgs.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ")
|
|
118
|
+
const fullCmd = `source /etc/profile.d/npm-global.sh 2>/dev/null; source /etc/profile.d/electric-agent.sh 2>/dev/null; cd '${this.config.cwd}' && codex ${escapedArgs}`
|
|
119
|
+
// Use SpriteCommand with tty:true (for streaming)
|
|
120
|
+
this.cmd = new SpriteCommand(this.sprite, "bash", ["-c", fullCmd], {
|
|
121
|
+
tty: true,
|
|
122
|
+
})
|
|
123
|
+
this.cmd.start()
|
|
124
|
+
console.log(`[codex-sprites] Started: session=${this.sessionId}`)
|
|
125
|
+
const currentCmd = this.cmd
|
|
126
|
+
// Read stdout line by line (exec --json NDJSON)
|
|
127
|
+
const rl = readline.createInterface({
|
|
128
|
+
input: currentCmd.stdout,
|
|
129
|
+
terminal: false,
|
|
130
|
+
})
|
|
131
|
+
rl.on("line", (line) => {
|
|
132
|
+
if (this.closed) return
|
|
133
|
+
this.handleLine(line)
|
|
134
|
+
})
|
|
135
|
+
// Log stderr
|
|
136
|
+
const stderrRl = readline.createInterface({
|
|
137
|
+
input: currentCmd.stderr,
|
|
138
|
+
terminal: false,
|
|
139
|
+
})
|
|
140
|
+
stderrRl.on("line", (line) => {
|
|
141
|
+
if (!this.closed) {
|
|
142
|
+
console.error(`[codex-sprites:stderr] ${line}`)
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
// Handle process exit — defer to let pending readline events flush first
|
|
146
|
+
currentCmd.on("exit", (code) => {
|
|
147
|
+
console.log(`[codex-sprites] Process exited: code=${code} session=${this.sessionId}`)
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
// Capture thread ID from parser state before marking not running
|
|
150
|
+
if (this.parser.state.threadId) {
|
|
151
|
+
this.codexThreadId = this.parser.state.threadId
|
|
152
|
+
}
|
|
153
|
+
this.running = false
|
|
154
|
+
// Emit session_end if the parser didn't already
|
|
155
|
+
if (!this.closed && !this.resultReceived) {
|
|
156
|
+
const endEvent = {
|
|
157
|
+
type: "session_end",
|
|
158
|
+
success: code === 0,
|
|
159
|
+
ts: ts(),
|
|
160
|
+
}
|
|
161
|
+
this.dispatchEvent(endEvent)
|
|
162
|
+
}
|
|
163
|
+
}, 100)
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
handleLine(line) {
|
|
167
|
+
// Strip ANSI escape sequences and terminal control chars added by tty mode
|
|
168
|
+
const cleaned = stripAnsi(line).trim()
|
|
169
|
+
if (!cleaned) return
|
|
170
|
+
const events = this.parser.parse(cleaned)
|
|
171
|
+
for (const event of events) {
|
|
172
|
+
this.dispatchEvent(event)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
dispatchEvent(event) {
|
|
176
|
+
const msg = { source: "agent", ...event }
|
|
177
|
+
this.writer.append(JSON.stringify(msg)).catch(() => {})
|
|
178
|
+
// Track session_end to prevent duplicates
|
|
179
|
+
if (event.type === "session_end") {
|
|
180
|
+
this.resultReceived = true
|
|
181
|
+
}
|
|
182
|
+
// Detect dev:start in Bash tool_use → emit app_ready for the UI preview
|
|
183
|
+
if (event.type === "pre_tool_use" && event.tool_name === "Bash") {
|
|
184
|
+
const cmd = event.tool_input?.command
|
|
185
|
+
if (typeof cmd === "string" && /\bdev:start\b/.test(cmd)) {
|
|
186
|
+
const appReady = { type: "app_ready", ts: ts() }
|
|
187
|
+
const appReadyMsg = { source: "agent", ...appReady }
|
|
188
|
+
this.writer.append(JSON.stringify(appReadyMsg)).catch(() => {})
|
|
189
|
+
for (const cb of this.agentEventCallbacks) {
|
|
190
|
+
try {
|
|
191
|
+
cb(appReady)
|
|
192
|
+
} catch {
|
|
193
|
+
// Swallow
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
for (const cb of this.agentEventCallbacks) {
|
|
199
|
+
try {
|
|
200
|
+
cb(event)
|
|
201
|
+
} catch {
|
|
202
|
+
// Swallow callback errors
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (event.type === "session_end" && "success" in event) {
|
|
206
|
+
const success = event.success
|
|
207
|
+
for (const cb of this.completeCallbacks) {
|
|
208
|
+
try {
|
|
209
|
+
cb(success)
|
|
210
|
+
} catch {
|
|
211
|
+
// Swallow callback errors
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
226
216
|
}
|
|
227
217
|
/** Strip ANSI escape sequences and control characters from tty output */
|
|
228
218
|
function stripAnsi(str) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
219
|
+
const ESC = "\x1b"
|
|
220
|
+
const csi = new RegExp(`${ESC}\\[[0-9;]*[a-zA-Z]`, "g")
|
|
221
|
+
const osc1 = new RegExp(`${ESC}\\][^\\x07]*\\x07`, "g")
|
|
222
|
+
const osc2 = new RegExp(`${ESC}\\][^${ESC}]*${ESC}\\\\`, "g")
|
|
223
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: strip C0 control chars except \n \r
|
|
224
|
+
const ctrl = /[\x00-\x09\x0b\x0c\x0e-\x1f\x7f]/g
|
|
225
|
+
return str.replace(csi, "").replace(osc1, "").replace(osc2, "").replace(ctrl, "")
|
|
236
226
|
}
|
|
237
|
-
//# sourceMappingURL=codex-sprites.js.map
|
|
227
|
+
//# sourceMappingURL=codex-sprites.js.map
|
package/dist/bridge/daytona.d.ts
CHANGED
|
@@ -6,30 +6,30 @@
|
|
|
6
6
|
* the Daytona session (for agent communication). The agent inside the
|
|
7
7
|
* sandbox uses the stdio adapter — no outbound internet required.
|
|
8
8
|
*/
|
|
9
|
-
import type { Sandbox } from "@daytonaio/sdk"
|
|
10
|
-
import type { EngineEvent } from "@electric-agent/protocol"
|
|
11
|
-
import type { StreamConnectionInfo } from "../streams.js"
|
|
12
|
-
import type { SessionBridge } from "./types.js"
|
|
9
|
+
import type { Sandbox } from "@daytonaio/sdk"
|
|
10
|
+
import type { EngineEvent } from "@electric-agent/protocol"
|
|
11
|
+
import type { StreamConnectionInfo } from "../streams.js"
|
|
12
|
+
import type { SessionBridge } from "./types.js"
|
|
13
13
|
export declare class DaytonaSessionBridge implements SessionBridge {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
readonly sessionId: string
|
|
15
|
+
readonly streamUrl: string
|
|
16
|
+
readonly streamHeaders: Record<string, string>
|
|
17
|
+
private sandbox
|
|
18
|
+
private writer
|
|
19
|
+
private agentEventCallbacks
|
|
20
|
+
private completeCallbacks
|
|
21
|
+
private closed
|
|
22
|
+
private cmdId
|
|
23
|
+
private stdoutBuffer
|
|
24
|
+
constructor(sessionId: string, connection: StreamConnectionInfo, sandbox: Sandbox)
|
|
25
|
+
emit(event: EngineEvent): Promise<void>
|
|
26
|
+
sendCommand(cmd: Record<string, unknown>): Promise<void>
|
|
27
|
+
sendGateResponse(gate: string, value: Record<string, unknown>): Promise<void>
|
|
28
|
+
onAgentEvent(cb: (event: EngineEvent) => void): void
|
|
29
|
+
onComplete(cb: (success: boolean) => void): void
|
|
30
|
+
start(): Promise<void>
|
|
31
|
+
private pollLogs
|
|
32
|
+
private handleStdout
|
|
33
|
+
close(): void
|
|
34
34
|
}
|
|
35
|
-
//# sourceMappingURL=daytona.d.ts.map
|
|
35
|
+
//# sourceMappingURL=daytona.d.ts.map
|