@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.
Files changed (71) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +198 -0
  3. package/dist/__tests__/bunny-agent.test.d.ts +2 -0
  4. package/dist/__tests__/bunny-agent.test.d.ts.map +1 -0
  5. package/dist/__tests__/bunny-agent.test.js +274 -0
  6. package/dist/__tests__/bunny-agent.test.js.map +1 -0
  7. package/dist/__tests__/coding-run.test.d.ts +2 -0
  8. package/dist/__tests__/coding-run.test.d.ts.map +1 -0
  9. package/dist/__tests__/coding-run.test.js +27 -0
  10. package/dist/__tests__/coding-run.test.js.map +1 -0
  11. package/dist/__tests__/daemon-health.test.d.ts +2 -0
  12. package/dist/__tests__/daemon-health.test.d.ts.map +1 -0
  13. package/dist/__tests__/daemon-health.test.js +113 -0
  14. package/dist/__tests__/daemon-health.test.js.map +1 -0
  15. package/dist/__tests__/env.test.d.ts +2 -0
  16. package/dist/__tests__/env.test.d.ts.map +1 -0
  17. package/dist/__tests__/env.test.js +82 -0
  18. package/dist/__tests__/env.test.js.map +1 -0
  19. package/dist/__tests__/local-sandbox.test.d.ts +2 -0
  20. package/dist/__tests__/local-sandbox.test.d.ts.map +1 -0
  21. package/dist/__tests__/local-sandbox.test.js +274 -0
  22. package/dist/__tests__/local-sandbox.test.js.map +1 -0
  23. package/dist/__tests__/signal-integration.test.d.ts +2 -0
  24. package/dist/__tests__/signal-integration.test.d.ts.map +1 -0
  25. package/dist/__tests__/signal-integration.test.js +135 -0
  26. package/dist/__tests__/signal-integration.test.js.map +1 -0
  27. package/dist/__tests__/transcript.test.d.ts +2 -0
  28. package/dist/__tests__/transcript.test.d.ts.map +1 -0
  29. package/dist/__tests__/transcript.test.js +144 -0
  30. package/dist/__tests__/transcript.test.js.map +1 -0
  31. package/dist/__tests__/types.test.d.ts +2 -0
  32. package/dist/__tests__/types.test.d.ts.map +1 -0
  33. package/dist/__tests__/types.test.js +148 -0
  34. package/dist/__tests__/types.test.js.map +1 -0
  35. package/dist/bunny-agent.d.ts +50 -0
  36. package/dist/bunny-agent.d.ts.map +1 -0
  37. package/dist/bunny-agent.js +206 -0
  38. package/dist/bunny-agent.js.map +1 -0
  39. package/dist/coding-run.d.ts +40 -0
  40. package/dist/coding-run.d.ts.map +1 -0
  41. package/dist/coding-run.js +111 -0
  42. package/dist/coding-run.js.map +1 -0
  43. package/dist/constants.d.ts +7 -0
  44. package/dist/constants.d.ts.map +1 -0
  45. package/dist/constants.js +7 -0
  46. package/dist/constants.js.map +1 -0
  47. package/dist/daemon-health.d.ts +16 -0
  48. package/dist/daemon-health.d.ts.map +1 -0
  49. package/dist/daemon-health.js +66 -0
  50. package/dist/daemon-health.js.map +1 -0
  51. package/dist/env.d.ts +55 -0
  52. package/dist/env.d.ts.map +1 -0
  53. package/dist/env.js +113 -0
  54. package/dist/env.js.map +1 -0
  55. package/dist/index.d.ts +13 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +10 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/local-sandbox.d.ts +83 -0
  60. package/dist/local-sandbox.d.ts.map +1 -0
  61. package/dist/local-sandbox.js +364 -0
  62. package/dist/local-sandbox.js.map +1 -0
  63. package/dist/transcript.d.ts +112 -0
  64. package/dist/transcript.d.ts.map +1 -0
  65. package/dist/transcript.js +176 -0
  66. package/dist/transcript.js.map +1 -0
  67. package/dist/types.d.ts +249 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/types.js +2 -0
  70. package/dist/types.js.map +1 -0
  71. package/package.json +50 -0
@@ -0,0 +1,112 @@
1
+ import type { TranscriptEntry, TranscriptWriter } from "./types.js";
2
+ /**
3
+ * JSONL Transcript Writer
4
+ *
5
+ * Writes transcript entries as JSONL (JSON Lines) format for debugging and replay.
6
+ * Each line is a valid JSON object representing a transcript entry.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { JsonlTranscriptWriter } from "@bunny-agent/manager";
11
+ *
12
+ * const writer = new JsonlTranscriptWriter("./transcript.jsonl");
13
+ *
14
+ * const agent = new BunnyAgent({ ... });
15
+ * const response = await agent.stream({
16
+ * messages,
17
+ * transcriptWriter: writer,
18
+ * });
19
+ *
20
+ * // After streaming completes
21
+ * await writer.close();
22
+ * ```
23
+ */
24
+ export declare class JsonlTranscriptWriter implements TranscriptWriter {
25
+ private readonly filePath;
26
+ private readonly stream;
27
+ private closed;
28
+ /**
29
+ * Create a new JSONL transcript writer
30
+ * @param filePath - Path to write the JSONL file
31
+ * @param options - Writer options
32
+ */
33
+ constructor(filePath: string, options?: {
34
+ append?: boolean;
35
+ });
36
+ /**
37
+ * Write a transcript entry as a JSONL line
38
+ */
39
+ write(entry: TranscriptEntry): void;
40
+ /**
41
+ * Close the writer and flush pending data
42
+ */
43
+ close(): Promise<void>;
44
+ /**
45
+ * Get the file path of the transcript
46
+ */
47
+ getFilePath(): string;
48
+ }
49
+ /**
50
+ * In-memory transcript writer for testing and debugging
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const writer = new MemoryTranscriptWriter();
55
+ * const response = await agent.stream({ messages, transcriptWriter: writer });
56
+ *
57
+ * // Access entries after streaming
58
+ * console.log(writer.getEntries());
59
+ * ```
60
+ */
61
+ export declare class MemoryTranscriptWriter implements TranscriptWriter {
62
+ private readonly entries;
63
+ write(entry: TranscriptEntry): void;
64
+ /**
65
+ * Get all recorded entries
66
+ */
67
+ getEntries(): ReadonlyArray<TranscriptEntry>;
68
+ /**
69
+ * Get entries as JSONL string
70
+ */
71
+ toJsonl(): string;
72
+ /**
73
+ * Get only chunk entries with decoded text
74
+ */
75
+ getChunks(): string[];
76
+ /**
77
+ * Get the full streamed output as a single string
78
+ */
79
+ getFullOutput(): string;
80
+ /**
81
+ * Clear all entries
82
+ */
83
+ clear(): void;
84
+ }
85
+ /**
86
+ * Console transcript writer for debugging
87
+ * Outputs transcript entries to console in a readable format
88
+ */
89
+ export declare class ConsoleTranscriptWriter implements TranscriptWriter {
90
+ private readonly prefix;
91
+ constructor(prefix?: string);
92
+ write(entry: TranscriptEntry): void;
93
+ }
94
+ /**
95
+ * Multi-writer that writes to multiple transcript writers
96
+ * Useful for both logging and recording simultaneously
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const writer = new MultiTranscriptWriter([
101
+ * new JsonlTranscriptWriter("./transcript.jsonl"),
102
+ * new ConsoleTranscriptWriter(),
103
+ * ]);
104
+ * ```
105
+ */
106
+ export declare class MultiTranscriptWriter implements TranscriptWriter {
107
+ private readonly writers;
108
+ constructor(writers: TranscriptWriter[]);
109
+ write(entry: TranscriptEntry): Promise<void>;
110
+ close(): Promise<void>;
111
+ }
112
+ //# sourceMappingURL=transcript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../src/transcript.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,qBAAsB,YAAW,gBAAgB;IAC5D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACS,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAO;IAQhE;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAQnC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAe5B;;OAEG;IACH,WAAW,IAAI,MAAM;CAGtB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,sBAAuB,YAAW,gBAAgB;IAC7D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IAEjD,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAInC;;OAEG;IACH,UAAU,IAAI,aAAa,CAAC,eAAe,CAAC;IAI5C;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;OAEG;IACH,SAAS,IAAI,MAAM,EAAE;IAMrB;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,gBAAgB;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,SAAiB;IAInC,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;CAmBpC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,qBAAsB,YAAW,gBAAgB;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;gBAEjC,OAAO,EAAE,gBAAgB,EAAE;IAIjC,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
@@ -0,0 +1,176 @@
1
+ import * as fs from "node:fs";
2
+ /**
3
+ * JSONL Transcript Writer
4
+ *
5
+ * Writes transcript entries as JSONL (JSON Lines) format for debugging and replay.
6
+ * Each line is a valid JSON object representing a transcript entry.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { JsonlTranscriptWriter } from "@bunny-agent/manager";
11
+ *
12
+ * const writer = new JsonlTranscriptWriter("./transcript.jsonl");
13
+ *
14
+ * const agent = new BunnyAgent({ ... });
15
+ * const response = await agent.stream({
16
+ * messages,
17
+ * transcriptWriter: writer,
18
+ * });
19
+ *
20
+ * // After streaming completes
21
+ * await writer.close();
22
+ * ```
23
+ */
24
+ export class JsonlTranscriptWriter {
25
+ filePath;
26
+ stream;
27
+ closed = false;
28
+ /**
29
+ * Create a new JSONL transcript writer
30
+ * @param filePath - Path to write the JSONL file
31
+ * @param options - Writer options
32
+ */
33
+ constructor(filePath, options = {}) {
34
+ this.filePath = filePath;
35
+ this.stream = fs.createWriteStream(filePath, {
36
+ flags: options.append ? "a" : "w",
37
+ encoding: "utf-8",
38
+ });
39
+ }
40
+ /**
41
+ * Write a transcript entry as a JSONL line
42
+ */
43
+ write(entry) {
44
+ if (this.closed) {
45
+ throw new Error("TranscriptWriter is closed");
46
+ }
47
+ const line = JSON.stringify(entry) + "\n";
48
+ this.stream.write(line);
49
+ }
50
+ /**
51
+ * Close the writer and flush pending data
52
+ */
53
+ async close() {
54
+ if (this.closed)
55
+ return;
56
+ this.closed = true;
57
+ return new Promise((resolve, reject) => {
58
+ this.stream.end((error) => {
59
+ if (error) {
60
+ reject(error);
61
+ }
62
+ else {
63
+ resolve();
64
+ }
65
+ });
66
+ });
67
+ }
68
+ /**
69
+ * Get the file path of the transcript
70
+ */
71
+ getFilePath() {
72
+ return this.filePath;
73
+ }
74
+ }
75
+ /**
76
+ * In-memory transcript writer for testing and debugging
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const writer = new MemoryTranscriptWriter();
81
+ * const response = await agent.stream({ messages, transcriptWriter: writer });
82
+ *
83
+ * // Access entries after streaming
84
+ * console.log(writer.getEntries());
85
+ * ```
86
+ */
87
+ export class MemoryTranscriptWriter {
88
+ entries = [];
89
+ write(entry) {
90
+ this.entries.push(entry);
91
+ }
92
+ /**
93
+ * Get all recorded entries
94
+ */
95
+ getEntries() {
96
+ return this.entries;
97
+ }
98
+ /**
99
+ * Get entries as JSONL string
100
+ */
101
+ toJsonl() {
102
+ return this.entries.map((e) => JSON.stringify(e)).join("\n") + "\n";
103
+ }
104
+ /**
105
+ * Get only chunk entries with decoded text
106
+ */
107
+ getChunks() {
108
+ return this.entries
109
+ .filter((e) => e.type === "chunk" && e.text)
110
+ .map((e) => e.text);
111
+ }
112
+ /**
113
+ * Get the full streamed output as a single string
114
+ */
115
+ getFullOutput() {
116
+ return this.getChunks().join("");
117
+ }
118
+ /**
119
+ * Clear all entries
120
+ */
121
+ clear() {
122
+ this.entries.length = 0;
123
+ }
124
+ }
125
+ /**
126
+ * Console transcript writer for debugging
127
+ * Outputs transcript entries to console in a readable format
128
+ */
129
+ export class ConsoleTranscriptWriter {
130
+ prefix;
131
+ constructor(prefix = "[Transcript]") {
132
+ this.prefix = prefix;
133
+ }
134
+ write(entry) {
135
+ const timestamp = new Date(entry.timestamp).toISOString();
136
+ const type = entry.type.toUpperCase().padEnd(8);
137
+ if (entry.type === "chunk" && entry.text) {
138
+ // For chunks, show the text content
139
+ console.log(`${this.prefix} ${timestamp} ${type} ${entry.text}`);
140
+ }
141
+ else if (entry.type === "error") {
142
+ console.error(`${this.prefix} ${timestamp} ${type} ${entry.text ?? entry.data}`);
143
+ }
144
+ else if (entry.metadata) {
145
+ console.log(`${this.prefix} ${timestamp} ${type} ${JSON.stringify(entry.metadata)}`);
146
+ }
147
+ else {
148
+ console.log(`${this.prefix} ${timestamp} ${type}`);
149
+ }
150
+ }
151
+ }
152
+ /**
153
+ * Multi-writer that writes to multiple transcript writers
154
+ * Useful for both logging and recording simultaneously
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * const writer = new MultiTranscriptWriter([
159
+ * new JsonlTranscriptWriter("./transcript.jsonl"),
160
+ * new ConsoleTranscriptWriter(),
161
+ * ]);
162
+ * ```
163
+ */
164
+ export class MultiTranscriptWriter {
165
+ writers;
166
+ constructor(writers) {
167
+ this.writers = writers;
168
+ }
169
+ async write(entry) {
170
+ await Promise.all(this.writers.map((w) => w.write(entry)));
171
+ }
172
+ async close() {
173
+ await Promise.all(this.writers.map((w) => (w.close ? w.close() : Promise.resolve())));
174
+ }
175
+ }
176
+ //# sourceMappingURL=transcript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.js","sourceRoot":"","sources":["../src/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAG9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,qBAAqB;IACf,QAAQ,CAAS;IACjB,MAA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AC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CACnE,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Volume info (for backends that support persistent volumes)
3
+ */
4
+ export interface Volume {
5
+ volumeId: string;
6
+ /** Space ID from the backend (e.g. Sandock space id when volume is tied to a space) */
7
+ spaceId?: string;
8
+ mountPath: string;
9
+ /** Optional display name (e.g. volume name from config) */
10
+ name?: string;
11
+ }
12
+ /**
13
+ * Options for executing a command in the sandbox
14
+ */
15
+ export interface ExecOptions {
16
+ /** Working directory for the command */
17
+ cwd?: string;
18
+ /**
19
+ * Environment variables for normal `exec` (merged into the subprocess env).
20
+ * Not used by {@link streamCodingRunFromSandbox} — put runner vars in
21
+ * {@link BunnyAgentCodingRunBody.env} instead.
22
+ */
23
+ env?: Record<string, string>;
24
+ /** Timeout in milliseconds */
25
+ timeout?: number;
26
+ /** AbortSignal for cancelling the operation */
27
+ signal?: AbortSignal;
28
+ }
29
+ /**
30
+ * JSON body for bunny-agent-daemon `POST /api/coding/run` (same shape as apps/daemon).
31
+ */
32
+ export interface BunnyAgentCodingRunBody {
33
+ runner?: string;
34
+ model?: string;
35
+ userInput: string;
36
+ systemPrompt?: string;
37
+ maxTurns?: number;
38
+ allowedTools?: string[];
39
+ resume?: string;
40
+ skillPaths?: string[];
41
+ cwd?: string;
42
+ /**
43
+ * Extra env vars merged into the runner subprocess env (after daemon `process.env`).
44
+ * String keys and string values only; invalid entries are dropped by the daemon.
45
+ */
46
+ env?: Record<string, string>;
47
+ /** Skip tool approval checks (bypass permissions). */
48
+ yolo?: boolean;
49
+ }
50
+ /**
51
+ * Represents a handle to an active sandbox instance
52
+ */
53
+ export interface SandboxHandle {
54
+ /**
55
+ * Get the sandbox instance ID (available after attach).
56
+ * Returns null for local sandboxes that don't have a remote ID.
57
+ */
58
+ getSandboxId(): string | null;
59
+ /**
60
+ * Get the volume mounts for this sandbox (available after attach).
61
+ * Returns null for sandboxes that don't support volumes.
62
+ */
63
+ getVolumes(): Volume[] | null;
64
+ /**
65
+ * Get the working directory for this sandbox handle
66
+ * @returns The working directory path
67
+ */
68
+ getWorkdir(): string;
69
+ /**
70
+ * Execute a command in the sandbox and stream the output
71
+ * @param command - The command and arguments to execute
72
+ * @param opts - Execution options
73
+ * @returns An async iterable of stdout chunks
74
+ */
75
+ exec(command: string[], opts?: ExecOptions): AsyncIterable<Uint8Array>;
76
+ /**
77
+ * Upload files to the sandbox
78
+ * @param files - Array of files to upload
79
+ * @param targetDir - Target directory in the sandbox
80
+ */
81
+ upload(files: Array<{
82
+ path: string;
83
+ content: Uint8Array | string;
84
+ }>, targetDir: string): Promise<void>;
85
+ /**
86
+ * Read a file from the sandbox
87
+ * @param filePath - Path to the file in the sandbox
88
+ * @returns The file content as a string
89
+ */
90
+ readFile(filePath: string): Promise<string>;
91
+ /**
92
+ * Destroy the sandbox and release resources
93
+ */
94
+ destroy(): Promise<void>;
95
+ }
96
+ /**
97
+ * Question for AskUserQuestion tool
98
+ */
99
+ export interface Question {
100
+ question: string;
101
+ header?: string;
102
+ options?: Array<{
103
+ label: string;
104
+ description?: string;
105
+ }>;
106
+ multiSelect?: boolean;
107
+ }
108
+ /**
109
+ * Adapter interface for sandbox implementations
110
+ */
111
+ export interface SandboxAdapter {
112
+ /**
113
+ * Attach to or create a sandbox
114
+ * @returns A handle to the sandbox
115
+ */
116
+ attach(): Promise<SandboxHandle>;
117
+ /**
118
+ * Get the current handle if already attached, or null if not attached yet.
119
+ * @returns A handle to the sandbox if already attached, null otherwise
120
+ */
121
+ getHandle(): SandboxHandle | null;
122
+ /**
123
+ * Get the environment variables configured for this sandbox.
124
+ * These will be passed to all commands executed in the sandbox.
125
+ */
126
+ getEnv?(): Record<string, string>;
127
+ /**
128
+ * Get the working directory configured for this sandbox.
129
+ */
130
+ getWorkdir?(): string;
131
+ /**
132
+ * Get the runner command to execute in the sandbox.
133
+ * Returns the command array (e.g., ["bunny-agent", "run"] or ["node", "/path/to/bundle.mjs", "run"])
134
+ */
135
+ getRunnerCommand?(): string[];
136
+ }
137
+ /**
138
+ * Output format types
139
+ * - "text": Plain text output (final result only)
140
+ * - "json": Single JSON result object
141
+ * - "stream-json": Realtime streaming JSON (NDJSON)
142
+ * - "stream": SSE-based AI SDK UI Data Stream format
143
+ */
144
+ export type OutputFormat = "text" | "json" | "stream-json" | "stream";
145
+ /**
146
+ * Specification for the agent runner
147
+ */
148
+ export interface RunnerSpec {
149
+ /** The model to use */
150
+ model: string;
151
+ /**
152
+ * CLI runner type: which implementation to use when running `bunny-agent run`
153
+ * (e.g. claude, pi, codex, gemini, opencode). Default is "claude".
154
+ */
155
+ runnerType?: "claude" | "pi" | "codex" | "gemini" | "opencode";
156
+ /** Optional system prompt override (overrides template's CLAUDE.md) */
157
+ systemPrompt?: string;
158
+ /** Maximum number of conversation turns */
159
+ maxTurns?: number;
160
+ /** Allowed tools (undefined means all tools, or use template's settings) */
161
+ allowedTools?: string[];
162
+ /** Output format for streaming responses */
163
+ outputFormat?: OutputFormat;
164
+ /** Additional skill paths (files or directories) for pi runner */
165
+ skillPaths?: string[];
166
+ /**
167
+ * When true, skip all tool approval checks (bypass permissions).
168
+ * When false (default), runner pauses before executing any tool and waits for approval
169
+ * via the .bunny-agent/approvals/{toolUseID}.json file mechanism.
170
+ */
171
+ yolo?: boolean;
172
+ }
173
+ /**
174
+ * Options for creating a BunnyAgent instance
175
+ */
176
+ export interface BunnyAgentOptions {
177
+ /** Sandbox adapter to use */
178
+ sandbox: SandboxAdapter;
179
+ /** Runner specification */
180
+ runner: RunnerSpec;
181
+ /** Environment variables to pass to the sandbox */
182
+ env?: Record<string, string>;
183
+ }
184
+ /**
185
+ * A message in the conversation
186
+ */
187
+ export interface Message {
188
+ /** Role of the message sender */
189
+ role: "user" | "assistant" | "system";
190
+ /** Content of the message */
191
+ content: string | Array<{
192
+ type: "text";
193
+ text: string;
194
+ } | {
195
+ type: "image";
196
+ data: string;
197
+ mimeType: string;
198
+ }>;
199
+ }
200
+ /**
201
+ * Input for streaming a task
202
+ */
203
+ export interface StreamInput {
204
+ /** Messages to send to the agent */
205
+ messages: Message[];
206
+ /** Workspace configuration */
207
+ workspace?: {
208
+ /** Path to the workspace directory */
209
+ path?: string;
210
+ };
211
+ /** Content type for the response (defaults to text/event-stream) */
212
+ contentType?: string;
213
+ /** Transcript writer for recording all streamed data (optional) */
214
+ transcriptWriter?: TranscriptWriter;
215
+ /** Runner session ID to resume a previous conversation (from assistant message metadata) */
216
+ resume?: string;
217
+ /** AbortSignal for cancelling the operation */
218
+ signal?: AbortSignal;
219
+ }
220
+ /**
221
+ * A single transcript entry
222
+ */
223
+ export interface TranscriptEntry {
224
+ /** ISO 8601 timestamp */
225
+ timestamp: string;
226
+ /** Type of entry */
227
+ type: "chunk" | "metadata" | "error" | "start" | "end";
228
+ /** Raw data (base64 encoded for binary) */
229
+ data?: string;
230
+ /** Decoded text (if data is text) */
231
+ text?: string;
232
+ /** Additional metadata */
233
+ metadata?: Record<string, unknown>;
234
+ }
235
+ /**
236
+ * Interface for writing transcript entries
237
+ */
238
+ export interface TranscriptWriter {
239
+ /**
240
+ * Write a transcript entry
241
+ * @param entry - The entry to write
242
+ */
243
+ write(entry: TranscriptEntry): void | Promise<void>;
244
+ /**
245
+ * Close the writer and flush any pending data
246
+ */
247
+ close?(): void | Promise<void>;
248
+ }
249
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WA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,CAAC;IAClB,oBAAoB;IACpB,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;IACvD,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;OAEG;IACH,KAAK,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@bunny-agent/manager",
3
+ "version": "0.9.28",
4
+ "description": "BunnyAgent Manager - Manages sandbox and runner lifecycle, defines core interfaces",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/vikadata/bunny-agent.git",
21
+ "directory": "packages/manager"
22
+ },
23
+ "keywords": [
24
+ "sandbox",
25
+ "agent",
26
+ "bunny-agent",
27
+ "runner",
28
+ "manager"
29
+ ],
30
+ "license": "Apache-2.0",
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "engines": {
35
+ "node": ">=20.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^20.10.0",
39
+ "typescript": "^5.3.0",
40
+ "vitest": "^1.6.1"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc",
44
+ "dev": "tsc --watch",
45
+ "clean": "rm -rf dist",
46
+ "typecheck": "tsc --noEmit",
47
+ "lint": "echo 'no lint configured'",
48
+ "test": "vitest run --passWithNoTests"
49
+ }
50
+ }