@bunny-agent/sdk 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 +323 -0
- package/dist/index.d.ts +241 -0
- package/dist/index.js +790 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +438 -0
- package/dist/react/index.js +445 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { BunnyAgentOptions, SandboxAdapter, RunnerSpec } from '@bunny-agent/manager';
|
|
2
|
+
export { DEFAULT_BUNNY_AGENT_DAEMON_URL, IsBunnyAgentDaemonHealthyOptions, LocalSandbox, LocalSandboxOptions, Message, RunnerEnvParams, RunnerType, SandboxAdapter, SandboxHandle, TranscriptEntry, buildRunnerEnv, isBunnyAgentDaemonHealthy } from '@bunny-agent/manager';
|
|
3
|
+
import { LanguageModelV3StreamPart, LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3, EmbeddingModelV3, ImageModelV3 } from '@ai-sdk/provider';
|
|
4
|
+
export { LanguageModelV3StreamPart } from '@ai-sdk/provider';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Artifact Processor result
|
|
8
|
+
*/
|
|
9
|
+
interface ArtifactResult {
|
|
10
|
+
artifactId: string;
|
|
11
|
+
content: string;
|
|
12
|
+
mimeType?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Stream writer interface for writing data parts
|
|
16
|
+
*/
|
|
17
|
+
interface StreamWriter {
|
|
18
|
+
write(chunk: {
|
|
19
|
+
type: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
data?: unknown;
|
|
22
|
+
transient?: boolean;
|
|
23
|
+
}): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Artifact Processor interface
|
|
27
|
+
*/
|
|
28
|
+
interface ArtifactProcessor {
|
|
29
|
+
/**
|
|
30
|
+
* Invoked when a stream part is received
|
|
31
|
+
* @param event - Stream part event
|
|
32
|
+
* @param sessionId - Current session ID (taskId)
|
|
33
|
+
*/
|
|
34
|
+
onChange(event: LanguageModelV3StreamPart, sessionId: string): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Question structure for AskUserQuestion tool
|
|
38
|
+
*/
|
|
39
|
+
interface Question {
|
|
40
|
+
question: string;
|
|
41
|
+
header?: string;
|
|
42
|
+
options?: Array<{
|
|
43
|
+
label: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
}>;
|
|
46
|
+
multiSelect?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Parameters for submitting an answer
|
|
50
|
+
*/
|
|
51
|
+
interface SubmitAnswerParams {
|
|
52
|
+
/** Tool call ID from the AskUserQuestion tool */
|
|
53
|
+
toolCallId: string;
|
|
54
|
+
/** Original questions from the tool */
|
|
55
|
+
questions: Question[];
|
|
56
|
+
/** User's answers keyed by question text */
|
|
57
|
+
answers: Record<string, string>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Logger interface for custom logging.
|
|
61
|
+
*/
|
|
62
|
+
interface Logger {
|
|
63
|
+
debug: (message: string) => void;
|
|
64
|
+
info: (message: string) => void;
|
|
65
|
+
warn: (message: string) => void;
|
|
66
|
+
error: (message: string) => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* CLI runner type passed to `bunny-agent run --runner <runnerType>`.
|
|
70
|
+
*/
|
|
71
|
+
type BunnyAgentRunnerType = "claude" | "pi" | "codex" | "gemini" | "opencode";
|
|
72
|
+
/**
|
|
73
|
+
* AI Provider specific settings that extend BunnyAgentOptions.
|
|
74
|
+
* Requires a `sandbox`. Optional `daemonUrl` streams via bunny-agent-daemon HTTP
|
|
75
|
+
* (`POST /api/coding/run`) inside the sandbox. The SDK does **not** probe `/healthz`
|
|
76
|
+
* on each request — call `isBunnyAgentDaemonHealthy` (re-exported from
|
|
77
|
+
* `@bunny-agent/sdk`) when you want to check readiness and omit `daemonUrl` to fall
|
|
78
|
+
* back to the CLI runner, or set `daemonUrl` and handle HTTP errors yourself.
|
|
79
|
+
*/
|
|
80
|
+
interface BunnyAgentProviderSettings extends Omit<BunnyAgentOptions, "runner" | "sandboxId" | "sandbox"> {
|
|
81
|
+
/** Required. All transports run relative to this adapter. */
|
|
82
|
+
sandbox: SandboxAdapter;
|
|
83
|
+
/**
|
|
84
|
+
* bunny-agent-daemon base URL **inside** the sandbox (e.g. BunnyAgent image:
|
|
85
|
+
* `http://127.0.0.1:3080`). When set, the SDK uses HTTP streaming only (no
|
|
86
|
+
* automatic health probe or CLI fallback).
|
|
87
|
+
*/
|
|
88
|
+
daemonUrl?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Which runner implementation to use: claude (default), pi, codex, gemini, opencode.
|
|
91
|
+
* Maps to `bunny-agent run --runner <runnerType>`.
|
|
92
|
+
*/
|
|
93
|
+
runnerType?: BunnyAgentRunnerType;
|
|
94
|
+
/** Working directory for CLI operations inside the sandbox. */
|
|
95
|
+
cwd?: string;
|
|
96
|
+
/** Resume session ID for multi-turn conversation. */
|
|
97
|
+
resume?: string;
|
|
98
|
+
/** Enable verbose logging for debugging. */
|
|
99
|
+
verbose?: boolean;
|
|
100
|
+
/** Custom logger for handling warnings and errors. */
|
|
101
|
+
logger?: Logger | false;
|
|
102
|
+
/** Artifact processors for handling artifact events. */
|
|
103
|
+
artifactProcessors?: ArtifactProcessor[];
|
|
104
|
+
/** Limit the number of back-and-forth iterations */
|
|
105
|
+
maxTurns?: number;
|
|
106
|
+
/** Optional system prompt override (overrides template's default) */
|
|
107
|
+
systemPrompt?: string;
|
|
108
|
+
/** Additional skill paths (files or directories) for pi runner */
|
|
109
|
+
skillPaths?: string[];
|
|
110
|
+
/** Allowed tools for the runner (undefined = template defaults). */
|
|
111
|
+
allowedTools?: string[];
|
|
112
|
+
/** Skip tool approval checks (bypass permissions). */
|
|
113
|
+
yolo?: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Model identifier: user passes whatever the runner expects (e.g. Claude model id, Pi model id).
|
|
117
|
+
*/
|
|
118
|
+
type BunnyAgentModelId = string;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Options for creating a BunnyAgent language model instance.
|
|
122
|
+
*/
|
|
123
|
+
interface BunnyAgentLanguageModelOptions {
|
|
124
|
+
id: BunnyAgentModelId;
|
|
125
|
+
options: BunnyAgentProviderSettings & {
|
|
126
|
+
runner: RunnerSpec;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* BunnyAgent Language Model implementation for AI SDK.
|
|
131
|
+
*/
|
|
132
|
+
declare class BunnyAgentLanguageModel implements LanguageModelV3 {
|
|
133
|
+
readonly specificationVersion: "v3";
|
|
134
|
+
readonly provider: string;
|
|
135
|
+
readonly modelId: string;
|
|
136
|
+
readonly supportedUrls: Record<string, RegExp[]>;
|
|
137
|
+
private readonly options;
|
|
138
|
+
private readonly logger;
|
|
139
|
+
private sessionId;
|
|
140
|
+
private toolNameMap;
|
|
141
|
+
private legacyTextPartCounter;
|
|
142
|
+
constructor(modelOptions: BunnyAgentLanguageModelOptions);
|
|
143
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
144
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
145
|
+
private resetStreamState;
|
|
146
|
+
private buildCodingRunBody;
|
|
147
|
+
private buildStreamResult;
|
|
148
|
+
private createLanguageModelStreamFromSseReader;
|
|
149
|
+
private parseSSEBuffer;
|
|
150
|
+
private parseSSEData;
|
|
151
|
+
private convertPromptToMessages;
|
|
152
|
+
private mapFinishReason;
|
|
153
|
+
private convertUsage;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* BunnyAgent provider interface that extends the AI SDK's ProviderV3.
|
|
158
|
+
*/
|
|
159
|
+
interface BunnyAgentProvider extends ProviderV3 {
|
|
160
|
+
(modelId: BunnyAgentModelId, options?: Partial<BunnyAgentProviderSettings>): LanguageModelV3;
|
|
161
|
+
languageModel(modelId: BunnyAgentModelId, options?: Partial<BunnyAgentProviderSettings>): LanguageModelV3;
|
|
162
|
+
chat(modelId: BunnyAgentModelId, options?: Partial<BunnyAgentProviderSettings>): LanguageModelV3;
|
|
163
|
+
embeddingModel(modelId: string): EmbeddingModelV3;
|
|
164
|
+
textEmbeddingModel(modelId: string): EmbeddingModelV3;
|
|
165
|
+
imageModel(modelId: string): ImageModelV3;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Creates a BunnyAgent provider instance with the specified configuration.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* import { createBunnyAgent } from '@bunny-agent/sdk';
|
|
173
|
+
* import { E2BSandbox } from '@bunny-agent/sandbox-e2b';
|
|
174
|
+
* import { generateText } from 'ai';
|
|
175
|
+
*
|
|
176
|
+
* const bunnyAgent = createBunnyAgent({
|
|
177
|
+
* sandbox: new E2BSandbox({ apiKey: process.env.E2B_API_KEY! }),
|
|
178
|
+
* env: {
|
|
179
|
+
* ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY!,
|
|
180
|
+
* },
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* const { text } = await generateText({
|
|
184
|
+
* model: bunnyAgent('sonnet'),
|
|
185
|
+
* prompt: 'Create a hello world program',
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare function createBunnyAgent(defaultOptions: BunnyAgentProviderSettings): BunnyAgentProvider;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Options for submitAnswer
|
|
193
|
+
*/
|
|
194
|
+
interface SubmitAnswerOptions {
|
|
195
|
+
/**
|
|
196
|
+
* Optional base path prefix for approval files
|
|
197
|
+
* @default ".bunny-agent/approvals"
|
|
198
|
+
*/
|
|
199
|
+
basePath?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Submit user's answer for an AskUserQuestion tool call.
|
|
203
|
+
* Writes the answer file to `.bunny-agent/approvals/{toolCallId}.json` in the sandbox workdir.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* import { submitAnswer } from "@bunny-agent/sdk";
|
|
208
|
+
*
|
|
209
|
+
* await submitAnswer(sandbox, {
|
|
210
|
+
* toolCallId: "tool-456",
|
|
211
|
+
* questions: [...],
|
|
212
|
+
* answers: { "Question 1": "Answer 1" },
|
|
213
|
+
* });
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare function submitAnswer(sandbox: SandboxAdapter, params: SubmitAnswerParams, options?: SubmitAnswerOptions): Promise<void>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @bunny-agent/sdk
|
|
220
|
+
*
|
|
221
|
+
* BunnyAgent SDK - AI Provider and React hooks for building AI chat interfaces.
|
|
222
|
+
*
|
|
223
|
+
* Main entry point exports the AI provider (backend).
|
|
224
|
+
* React hooks are available via "@bunny-agent/sdk/react".
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* // Backend - Provider
|
|
229
|
+
* import { createBunnyAgent } from "@bunny-agent/sdk";
|
|
230
|
+
* const bunnyAgent = createBunnyAgent({ sandbox, env });
|
|
231
|
+
* const model = bunnyAgent("sonnet");
|
|
232
|
+
*
|
|
233
|
+
* // Frontend - React hooks
|
|
234
|
+
* import { useBunnyAgentChat } from "@bunny-agent/sdk/react";
|
|
235
|
+
* const { messages, sendMessage } = useBunnyAgentChat({ apiEndpoint: "/api/ai" });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
declare const VERSION = "0.1.0";
|
|
240
|
+
|
|
241
|
+
export { type ArtifactProcessor, type ArtifactResult, BunnyAgentLanguageModel, type BunnyAgentLanguageModelOptions, type BunnyAgentModelId, type BunnyAgentProvider, type BunnyAgentProviderSettings, type Logger, type Question, type StreamWriter, type SubmitAnswerOptions, type SubmitAnswerParams, VERSION, createBunnyAgent, submitAnswer };
|