@bunny-agent/manager 0.9.28
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 +201 -0
- package/README.md +198 -0
- package/dist/__tests__/bunny-agent.test.d.ts +2 -0
- package/dist/__tests__/bunny-agent.test.d.ts.map +1 -0
- package/dist/__tests__/bunny-agent.test.js +274 -0
- package/dist/__tests__/bunny-agent.test.js.map +1 -0
- package/dist/__tests__/coding-run.test.d.ts +2 -0
- package/dist/__tests__/coding-run.test.d.ts.map +1 -0
- package/dist/__tests__/coding-run.test.js +27 -0
- package/dist/__tests__/coding-run.test.js.map +1 -0
- package/dist/__tests__/daemon-health.test.d.ts +2 -0
- package/dist/__tests__/daemon-health.test.d.ts.map +1 -0
- package/dist/__tests__/daemon-health.test.js +113 -0
- package/dist/__tests__/daemon-health.test.js.map +1 -0
- package/dist/__tests__/env.test.d.ts +2 -0
- package/dist/__tests__/env.test.d.ts.map +1 -0
- package/dist/__tests__/env.test.js +82 -0
- package/dist/__tests__/env.test.js.map +1 -0
- package/dist/__tests__/local-sandbox.test.d.ts +2 -0
- package/dist/__tests__/local-sandbox.test.d.ts.map +1 -0
- package/dist/__tests__/local-sandbox.test.js +274 -0
- package/dist/__tests__/local-sandbox.test.js.map +1 -0
- package/dist/__tests__/signal-integration.test.d.ts +2 -0
- package/dist/__tests__/signal-integration.test.d.ts.map +1 -0
- package/dist/__tests__/signal-integration.test.js +135 -0
- package/dist/__tests__/signal-integration.test.js.map +1 -0
- package/dist/__tests__/transcript.test.d.ts +2 -0
- package/dist/__tests__/transcript.test.d.ts.map +1 -0
- package/dist/__tests__/transcript.test.js +144 -0
- package/dist/__tests__/transcript.test.js.map +1 -0
- package/dist/__tests__/types.test.d.ts +2 -0
- package/dist/__tests__/types.test.d.ts.map +1 -0
- package/dist/__tests__/types.test.js +148 -0
- package/dist/__tests__/types.test.js.map +1 -0
- package/dist/bunny-agent.d.ts +50 -0
- package/dist/bunny-agent.d.ts.map +1 -0
- package/dist/bunny-agent.js +206 -0
- package/dist/bunny-agent.js.map +1 -0
- package/dist/coding-run.d.ts +40 -0
- package/dist/coding-run.d.ts.map +1 -0
- package/dist/coding-run.js +111 -0
- package/dist/coding-run.js.map +1 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/daemon-health.d.ts +16 -0
- package/dist/daemon-health.d.ts.map +1 -0
- package/dist/daemon-health.js +66 -0
- package/dist/daemon-health.js.map +1 -0
- package/dist/env.d.ts +55 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +113 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/local-sandbox.d.ts +83 -0
- package/dist/local-sandbox.d.ts.map +1 -0
- package/dist/local-sandbox.js +364 -0
- package/dist/local-sandbox.js.map +1 -0
- package/dist/transcript.d.ts +112 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/transcript.js +176 -0
- package/dist/transcript.js.map +1 -0
- package/dist/types.d.ts +249 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# @bunny-agent/manager
|
|
2
|
+
|
|
3
|
+
> ⚠️ **Deprecated (exec-based transport)**
|
|
4
|
+
>
|
|
5
|
+
> `@bunny-agent/manager` works by spawning `bunny-agent run` CLI inside a sandbox via `exec()`. This approach is being superseded by **`@bunny-agent/daemon`** — a unified HTTP gateway that runs inside the sandbox and exposes the same capabilities over a clean REST API.
|
|
6
|
+
>
|
|
7
|
+
> **Prefer `createBunnyAgent` with an explicit `daemonUrl` from `@bunny-agent/sdk`** when using the HTTP daemon.
|
|
8
|
+
>
|
|
9
|
+
> This package remains supported for sandboxes that only provide `exec()` capability (E2B, Daytona, etc.) and has no planned removal date.
|
|
10
|
+
|
|
11
|
+
Core manager package for Bunny Agent - manages sandbox and runner lifecycle, defines core interfaces.
|
|
12
|
+
|
|
13
|
+
This package is the core runtime that wires **sandbox adapters** + a **runner spec** into an AI SDK UI stream you can consume from your server or CLI.
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
`@bunny-agent/manager` is the foundational package that provides:
|
|
18
|
+
|
|
19
|
+
- **Bunny Agent**: Main class for managing sandboxed agent instances
|
|
20
|
+
- **Core Interfaces**: `SandboxAdapter`, `SandboxHandle`, `RunnerSpec`, etc.
|
|
21
|
+
- **Transcript Writers**: Tools for logging agent execution (JSONL, Memory, Console, Multi)
|
|
22
|
+
- **Type Definitions**: Shared types for messages, streams, and sandbox operations
|
|
23
|
+
|
|
24
|
+
This package is typically used as a dependency by higher-level packages like `@bunny-agent/sdk` and sandbox adapters.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @bunny-agent/manager
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quickstart
|
|
33
|
+
|
|
34
|
+
### Basic Usage
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { Bunny Agent } from '@bunny-agent/manager';
|
|
38
|
+
import { E2BSandbox } from '@bunny-agent/sandbox-e2b';
|
|
39
|
+
|
|
40
|
+
const agent = new BunnyAgent({
|
|
41
|
+
sandbox: new E2BSandbox({ apiKey: 'xxx' }),
|
|
42
|
+
runner: {
|
|
43
|
+
model: 'claude-sonnet-4-20250514',
|
|
44
|
+
outputFormat: 'stream',
|
|
45
|
+
},
|
|
46
|
+
env: {
|
|
47
|
+
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY!,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Stream a task
|
|
52
|
+
const stream = await agent.stream({
|
|
53
|
+
messages: [
|
|
54
|
+
{ role: 'user', content: 'Create a hello world program' }
|
|
55
|
+
],
|
|
56
|
+
workspace: {
|
|
57
|
+
path: '/workspace',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Read the stream
|
|
62
|
+
const reader = stream.getReader();
|
|
63
|
+
while (true) {
|
|
64
|
+
const { done, value } = await reader.read();
|
|
65
|
+
if (done) break;
|
|
66
|
+
process.stdout.write(value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Cleanup
|
|
70
|
+
await agent.destroy();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### With Transcript Logging
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { Bunny Agent, JsonlTranscriptWriter } from '@bunny-agent/manager';
|
|
77
|
+
|
|
78
|
+
const transcriptWriter = new JsonlTranscriptWriter('./transcript.jsonl');
|
|
79
|
+
|
|
80
|
+
const stream = await agent.stream({
|
|
81
|
+
messages: [{ role: 'user', content: 'Do something' }],
|
|
82
|
+
workspace: { path: '/workspace' },
|
|
83
|
+
transcriptWriter,
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Upload Files
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
await agent.uploadFiles([
|
|
91
|
+
{ path: 'hello.txt', content: 'Hello World!' },
|
|
92
|
+
{ path: 'data.json', content: JSON.stringify({ key: 'value' }) },
|
|
93
|
+
], '/workspace');
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Core Interfaces
|
|
97
|
+
|
|
98
|
+
### SandboxAdapter
|
|
99
|
+
|
|
100
|
+
Interface that sandbox implementations must follow:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
interface SandboxAdapter {
|
|
104
|
+
attach(): Promise<SandboxHandle>;
|
|
105
|
+
getHandle(): SandboxHandle | null;
|
|
106
|
+
getEnv?(): Record<string, string>;
|
|
107
|
+
getWorkdir?(): string;
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### SandboxHandle
|
|
112
|
+
|
|
113
|
+
Interface for interacting with an attached sandbox:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
interface SandboxHandle {
|
|
117
|
+
exec(command: string[], opts?: ExecOptions): AsyncIterable<Uint8Array>;
|
|
118
|
+
upload(files: Array<{ path: string; content: Uint8Array | string }>, targetDir: string): Promise<void>;
|
|
119
|
+
readFile?(filePath: string): Promise<string>;
|
|
120
|
+
runCommand?(command: string): Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
121
|
+
destroy(): Promise<void>;
|
|
122
|
+
getWorkdir?(): string;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### RunnerSpec
|
|
127
|
+
|
|
128
|
+
Specification for the runner to execute inside the sandbox:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
interface RunnerSpec {
|
|
132
|
+
model: string;
|
|
133
|
+
systemPrompt?: string;
|
|
134
|
+
maxTurns?: number;
|
|
135
|
+
allowedTools?: string[];
|
|
136
|
+
outputFormat?: 'stream' | 'json';
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Transcript Writers
|
|
141
|
+
|
|
142
|
+
Available transcript writers:
|
|
143
|
+
|
|
144
|
+
- **JsonlTranscriptWriter**: Write to JSONL file
|
|
145
|
+
- **MemoryTranscriptWriter**: Store in memory
|
|
146
|
+
- **ConsoleTranscriptWriter**: Log to console
|
|
147
|
+
- **MultiTranscriptWriter**: Write to multiple writers
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import {
|
|
151
|
+
JsonlTranscriptWriter,
|
|
152
|
+
MemoryTranscriptWriter,
|
|
153
|
+
MultiTranscriptWriter
|
|
154
|
+
} from '@bunny-agent/manager';
|
|
155
|
+
|
|
156
|
+
const transcriptWriter = new MultiTranscriptWriter([
|
|
157
|
+
new JsonlTranscriptWriter('./transcript.jsonl'),
|
|
158
|
+
new ConsoleTranscriptWriter(),
|
|
159
|
+
]);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## API Reference
|
|
163
|
+
|
|
164
|
+
### Bunny Agent
|
|
165
|
+
|
|
166
|
+
#### Constructor
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
new BunnyAgent(options: BunnyAgentOptions)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Options:**
|
|
173
|
+
- `sandbox` (required): A SandboxAdapter instance
|
|
174
|
+
- `runner` (required): RunnerSpec configuration
|
|
175
|
+
- `env`: Environment variables for the sandbox
|
|
176
|
+
|
|
177
|
+
#### Methods
|
|
178
|
+
|
|
179
|
+
**stream(input: StreamInput): Promise<ReadableStream<Uint8Array>>**
|
|
180
|
+
|
|
181
|
+
Stream a task through the agent. Returns a ReadableStream of AI SDK UI messages.
|
|
182
|
+
|
|
183
|
+
**uploadFiles(files: Array<{ path: string; content: Uint8Array | string }>, targetDir?: string): Promise<void>**
|
|
184
|
+
|
|
185
|
+
Upload files to the agent's workspace.
|
|
186
|
+
|
|
187
|
+
**destroy(): Promise<void>**
|
|
188
|
+
|
|
189
|
+
Destroy the sandbox and release resources.
|
|
190
|
+
|
|
191
|
+
## Requirements
|
|
192
|
+
|
|
193
|
+
- Node.js 20+
|
|
194
|
+
- A sandbox adapter (@bunny-agent/sandbox-e2b, @bunny-agent/sandbox-local, etc.)
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
Apache-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bunny-agent.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/bunny-agent.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { BunnyAgent } from "../bunny-agent.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create an async iterable from data
|
|
5
|
+
*/
|
|
6
|
+
function createAsyncIterable(data) {
|
|
7
|
+
return {
|
|
8
|
+
[Symbol.asyncIterator]: () => {
|
|
9
|
+
let index = 0;
|
|
10
|
+
return {
|
|
11
|
+
async next() {
|
|
12
|
+
if (index < data.length) {
|
|
13
|
+
return { value: data[index++], done: false };
|
|
14
|
+
}
|
|
15
|
+
return { value: undefined, done: true };
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Mock sandbox adapter for testing
|
|
23
|
+
*/
|
|
24
|
+
function createMockSandbox() {
|
|
25
|
+
const handle = {
|
|
26
|
+
getWorkdir: vi.fn().mockReturnValue("/workspace"),
|
|
27
|
+
getSandboxId: vi.fn().mockReturnValue(null),
|
|
28
|
+
getVolumes: vi.fn().mockReturnValue(null),
|
|
29
|
+
exec: vi
|
|
30
|
+
.fn()
|
|
31
|
+
.mockReturnValue(createAsyncIterable([new TextEncoder().encode("test output")])),
|
|
32
|
+
upload: vi.fn().mockResolvedValue(undefined),
|
|
33
|
+
readFile: vi.fn().mockResolvedValue(""),
|
|
34
|
+
destroy: vi.fn().mockResolvedValue(undefined),
|
|
35
|
+
};
|
|
36
|
+
const adapter = {
|
|
37
|
+
attach: vi.fn().mockResolvedValue(handle),
|
|
38
|
+
getHandle: vi.fn().mockReturnValue(handle),
|
|
39
|
+
handle,
|
|
40
|
+
};
|
|
41
|
+
return adapter;
|
|
42
|
+
}
|
|
43
|
+
describe("BunnyAgent", () => {
|
|
44
|
+
describe("stream", () => {
|
|
45
|
+
it("should attach to sandbox and execute command", async () => {
|
|
46
|
+
const sandbox = createMockSandbox();
|
|
47
|
+
const agent = new BunnyAgent({
|
|
48
|
+
sandbox,
|
|
49
|
+
runner: {
|
|
50
|
+
model: "claude-sonnet-4-20250514",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const stream = await agent.stream({
|
|
54
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
55
|
+
});
|
|
56
|
+
expect(sandbox.attach).toHaveBeenCalledWith();
|
|
57
|
+
expect(stream).toBeInstanceOf(ReadableStream);
|
|
58
|
+
});
|
|
59
|
+
it("should use default workspace path", async () => {
|
|
60
|
+
const sandbox = createMockSandbox();
|
|
61
|
+
const agent = new BunnyAgent({
|
|
62
|
+
sandbox,
|
|
63
|
+
runner: {
|
|
64
|
+
model: "claude-sonnet-4-20250514",
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
await agent.stream({
|
|
68
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
69
|
+
});
|
|
70
|
+
expect(sandbox.handle.exec).toHaveBeenCalledWith(expect.arrayContaining(["--cwd", "/workspace"]), expect.objectContaining({ cwd: "/workspace" }));
|
|
71
|
+
});
|
|
72
|
+
it("should use workspace path from sandbox handle", async () => {
|
|
73
|
+
const sandbox = createMockSandbox();
|
|
74
|
+
const agent = new BunnyAgent({
|
|
75
|
+
sandbox,
|
|
76
|
+
runner: {
|
|
77
|
+
model: "claude-sonnet-4-20250514",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
await agent.stream({
|
|
81
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
82
|
+
});
|
|
83
|
+
// Should use the workdir from handle.getWorkdir() (which returns "/workspace")
|
|
84
|
+
expect(sandbox.handle.exec).toHaveBeenCalledWith(expect.arrayContaining(["--cwd", "/workspace"]), expect.objectContaining({ cwd: "/workspace" }));
|
|
85
|
+
});
|
|
86
|
+
it("should include user message in command", async () => {
|
|
87
|
+
const sandbox = createMockSandbox();
|
|
88
|
+
const agent = new BunnyAgent({
|
|
89
|
+
sandbox,
|
|
90
|
+
runner: {
|
|
91
|
+
model: "claude-sonnet-4-20250514",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
await agent.stream({
|
|
95
|
+
messages: [{ role: "user", content: "Create a file" }],
|
|
96
|
+
});
|
|
97
|
+
expect(sandbox.handle.exec).toHaveBeenCalledWith(expect.arrayContaining(["Create a file"]), expect.any(Object));
|
|
98
|
+
});
|
|
99
|
+
it("should pass through stdout without modification", async () => {
|
|
100
|
+
const testData = "test streaming data";
|
|
101
|
+
const sandbox = createMockSandbox();
|
|
102
|
+
// Override exec to return test data using proper async iterable
|
|
103
|
+
sandbox.handle.exec = vi
|
|
104
|
+
.fn()
|
|
105
|
+
.mockReturnValue(createAsyncIterable([new TextEncoder().encode(testData)]));
|
|
106
|
+
const agent = new BunnyAgent({
|
|
107
|
+
sandbox,
|
|
108
|
+
runner: {
|
|
109
|
+
model: "claude-sonnet-4-20250514",
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const stream = await agent.stream({
|
|
113
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
114
|
+
});
|
|
115
|
+
const reader = stream.getReader();
|
|
116
|
+
const { value } = await reader.read();
|
|
117
|
+
const text = new TextDecoder().decode(value);
|
|
118
|
+
expect(text).toBe(testData);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe("uploadFiles", () => {
|
|
122
|
+
it("should upload files to the sandbox", async () => {
|
|
123
|
+
const sandbox = createMockSandbox();
|
|
124
|
+
const agent = new BunnyAgent({
|
|
125
|
+
sandbox,
|
|
126
|
+
runner: {
|
|
127
|
+
model: "claude-sonnet-4-20250514",
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
await agent.uploadFiles([{ path: "test.txt", content: "Hello, World!" }]);
|
|
131
|
+
expect(sandbox.handle.upload).toHaveBeenCalledWith([{ path: "test.txt", content: "Hello, World!" }], "/workspace");
|
|
132
|
+
});
|
|
133
|
+
it("should upload files to custom directory", async () => {
|
|
134
|
+
const sandbox = createMockSandbox();
|
|
135
|
+
const agent = new BunnyAgent({
|
|
136
|
+
sandbox,
|
|
137
|
+
runner: {
|
|
138
|
+
model: "claude-sonnet-4-20250514",
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
await agent.uploadFiles([{ path: "test.txt", content: "Hello, World!" }], "/custom/dir");
|
|
142
|
+
expect(sandbox.handle.upload).toHaveBeenCalledWith([{ path: "test.txt", content: "Hello, World!" }], "/custom/dir");
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe("destroy", () => {
|
|
146
|
+
it("should destroy the sandbox", async () => {
|
|
147
|
+
const sandbox = createMockSandbox();
|
|
148
|
+
const agent = new BunnyAgent({
|
|
149
|
+
sandbox,
|
|
150
|
+
runner: {
|
|
151
|
+
model: "claude-sonnet-4-20250514",
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
// First attach to sandbox
|
|
155
|
+
await agent.stream({
|
|
156
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
157
|
+
});
|
|
158
|
+
// Then destroy
|
|
159
|
+
await agent.destroy();
|
|
160
|
+
expect(sandbox.handle.destroy).toHaveBeenCalled();
|
|
161
|
+
});
|
|
162
|
+
it("should do nothing if not attached", async () => {
|
|
163
|
+
const sandbox = createMockSandbox();
|
|
164
|
+
const agent = new BunnyAgent({
|
|
165
|
+
sandbox,
|
|
166
|
+
runner: {
|
|
167
|
+
model: "claude-sonnet-4-20250514",
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
// Destroy without attaching first
|
|
171
|
+
await agent.destroy();
|
|
172
|
+
expect(sandbox.handle.destroy).not.toHaveBeenCalled();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe("AbortSignal support", () => {
|
|
176
|
+
it("should pass signal to exec()", async () => {
|
|
177
|
+
const sandbox = createMockSandbox();
|
|
178
|
+
const agent = new BunnyAgent({
|
|
179
|
+
sandbox,
|
|
180
|
+
runner: {
|
|
181
|
+
model: "claude-sonnet-4-20250514",
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
const controller = new AbortController();
|
|
185
|
+
const signal = controller.signal;
|
|
186
|
+
await agent.stream({
|
|
187
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
188
|
+
signal,
|
|
189
|
+
});
|
|
190
|
+
expect(sandbox.handle.exec).toHaveBeenCalledWith(expect.any(Array), expect.objectContaining({ signal }));
|
|
191
|
+
});
|
|
192
|
+
it("should throw error if signal is already aborted", async () => {
|
|
193
|
+
const sandbox = createMockSandbox();
|
|
194
|
+
const agent = new BunnyAgent({
|
|
195
|
+
sandbox,
|
|
196
|
+
runner: {
|
|
197
|
+
model: "claude-sonnet-4-20250514",
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
const controller = new AbortController();
|
|
201
|
+
controller.abort();
|
|
202
|
+
const signal = controller.signal;
|
|
203
|
+
await expect(agent.stream({
|
|
204
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
205
|
+
signal,
|
|
206
|
+
})).rejects.toThrow("Operation was aborted");
|
|
207
|
+
});
|
|
208
|
+
it("should pass signal to exec()", async () => {
|
|
209
|
+
const sandbox = createMockSandbox();
|
|
210
|
+
const controller = new AbortController();
|
|
211
|
+
sandbox.handle.exec = vi
|
|
212
|
+
.fn()
|
|
213
|
+
.mockReturnValue(createAsyncIterable([new TextEncoder().encode("test output")]));
|
|
214
|
+
const agent = new BunnyAgent({
|
|
215
|
+
sandbox,
|
|
216
|
+
runner: {
|
|
217
|
+
model: "claude-sonnet-4-20250514",
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
await agent.stream({
|
|
221
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
222
|
+
signal: controller.signal,
|
|
223
|
+
});
|
|
224
|
+
// Verify signal was passed to exec
|
|
225
|
+
expect(sandbox.handle.exec).toHaveBeenCalledWith(expect.any(Array), expect.objectContaining({
|
|
226
|
+
signal: controller.signal,
|
|
227
|
+
}));
|
|
228
|
+
});
|
|
229
|
+
it("should handle AbortError from exec() gracefully", async () => {
|
|
230
|
+
const sandbox = createMockSandbox();
|
|
231
|
+
const transcriptEntries = [];
|
|
232
|
+
const mockTranscriptWriter = {
|
|
233
|
+
write: vi.fn().mockImplementation((entry) => {
|
|
234
|
+
transcriptEntries.push(entry);
|
|
235
|
+
return Promise.resolve();
|
|
236
|
+
}),
|
|
237
|
+
};
|
|
238
|
+
// Create a mock that throws AbortError
|
|
239
|
+
sandbox.handle.exec = vi.fn().mockReturnValue({
|
|
240
|
+
[Symbol.asyncIterator]: async function* () {
|
|
241
|
+
yield new TextEncoder().encode("chunk1");
|
|
242
|
+
const error = new Error("The operation was aborted");
|
|
243
|
+
error.name = "AbortError";
|
|
244
|
+
throw error;
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
const agent = new BunnyAgent({
|
|
248
|
+
sandbox,
|
|
249
|
+
runner: {
|
|
250
|
+
model: "claude-sonnet-4-20250514",
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
const stream = await agent.stream({
|
|
254
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
255
|
+
transcriptWriter: mockTranscriptWriter,
|
|
256
|
+
});
|
|
257
|
+
const reader = stream.getReader();
|
|
258
|
+
// Read first chunk
|
|
259
|
+
await reader.read();
|
|
260
|
+
// Try to read next chunk - should throw
|
|
261
|
+
await expect(reader.read()).rejects.toThrow();
|
|
262
|
+
// Check that start entry was written
|
|
263
|
+
const startEntry = transcriptEntries.find((entry) => entry.type === "start");
|
|
264
|
+
expect(startEntry).toBeDefined();
|
|
265
|
+
// Check that at least one chunk was written
|
|
266
|
+
const chunkEntry = transcriptEntries.find((entry) => entry.type === "chunk");
|
|
267
|
+
expect(chunkEntry).toBeDefined();
|
|
268
|
+
// AbortError should NOT create an error entry - just stops cleanly
|
|
269
|
+
const errorEntry = transcriptEntries.find((entry) => entry.type === "error");
|
|
270
|
+
expect(errorEntry).toBeUndefined();
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
//# sourceMappingURL=bunny-agent.test.js.map
|