bs-agent 0.0.12 → 0.0.15
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/agent-CyJqP9_x.d.cts +305 -0
- package/dist/agent-CyJqP9_x.d.ts +305 -0
- package/dist/core/index.cjs +62 -18
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +3 -120
- package/dist/core/index.d.ts +3 -120
- package/dist/core/index.js +62 -18
- package/dist/core/index.js.map +1 -1
- package/dist/react/index.cjs +688 -427
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +28 -28
- package/dist/react/index.d.ts +28 -28
- package/dist/react/index.js +688 -427
- package/dist/react/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/types-DryLPWU9.d.cts +0 -160
- package/dist/types-DryLPWU9.d.ts +0 -160
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { ZodSchema } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unified tool type discriminator.
|
|
5
|
+
*/
|
|
6
|
+
type ToolType = "flow" | "node" | "mcp" | "client" | "builtin" | "agent";
|
|
7
|
+
type StreamEventMeta = {
|
|
8
|
+
executionId: string;
|
|
9
|
+
sequence: number;
|
|
10
|
+
timestamp?: number;
|
|
11
|
+
agentId: string;
|
|
12
|
+
};
|
|
13
|
+
type TextDeltaEvent = {
|
|
14
|
+
type: "text_delta";
|
|
15
|
+
data: string;
|
|
16
|
+
meta: StreamEventMeta;
|
|
17
|
+
};
|
|
18
|
+
type ReasoningDeltaEvent = {
|
|
19
|
+
type: "reasoning_delta";
|
|
20
|
+
data: {
|
|
21
|
+
delta: string;
|
|
22
|
+
index: number;
|
|
23
|
+
};
|
|
24
|
+
meta: StreamEventMeta;
|
|
25
|
+
};
|
|
26
|
+
type AgentHandoffEvent = {
|
|
27
|
+
type: "agent_handoff";
|
|
28
|
+
data: {
|
|
29
|
+
agentName: string;
|
|
30
|
+
};
|
|
31
|
+
meta: StreamEventMeta;
|
|
32
|
+
};
|
|
33
|
+
type ToolCallStartEvent = {
|
|
34
|
+
type: "tool_call_start";
|
|
35
|
+
data: {
|
|
36
|
+
callId: string;
|
|
37
|
+
toolName: string;
|
|
38
|
+
toolType: ToolType;
|
|
39
|
+
inputs?: any;
|
|
40
|
+
serverName?: string;
|
|
41
|
+
paused?: boolean;
|
|
42
|
+
};
|
|
43
|
+
meta: StreamEventMeta;
|
|
44
|
+
};
|
|
45
|
+
type ToolCallEndEvent = {
|
|
46
|
+
type: "tool_call_end";
|
|
47
|
+
data: {
|
|
48
|
+
callId: string;
|
|
49
|
+
toolName: string;
|
|
50
|
+
toolType: ToolType;
|
|
51
|
+
result?: any;
|
|
52
|
+
error?: string;
|
|
53
|
+
executionTime?: number;
|
|
54
|
+
};
|
|
55
|
+
meta: StreamEventMeta;
|
|
56
|
+
};
|
|
57
|
+
type RunErrorEvent = {
|
|
58
|
+
type: "run_error";
|
|
59
|
+
data: {
|
|
60
|
+
message: string;
|
|
61
|
+
code?: string;
|
|
62
|
+
};
|
|
63
|
+
meta: StreamEventMeta;
|
|
64
|
+
};
|
|
65
|
+
type StreamEvent = TextDeltaEvent | ReasoningDeltaEvent | AgentHandoffEvent | ToolCallStartEvent | ToolCallEndEvent | RunErrorEvent;
|
|
66
|
+
/** Branded session ID type. */
|
|
67
|
+
type SessionId = string & {
|
|
68
|
+
readonly __brand: unique symbol;
|
|
69
|
+
};
|
|
70
|
+
/** Configuration for the BuildShipAgent constructor. */
|
|
71
|
+
interface AgentConfig {
|
|
72
|
+
/** Your BuildShip agent ID. */
|
|
73
|
+
agentId: string;
|
|
74
|
+
/** Access key if your agent requires authentication. */
|
|
75
|
+
accessKey?: string;
|
|
76
|
+
/** Custom API base URL. Defaults to `https://api.buildship.run`. */
|
|
77
|
+
baseUrl?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Options for agent execution. */
|
|
80
|
+
interface ExecuteOptions {
|
|
81
|
+
/** Additional context variables for the prompt. */
|
|
82
|
+
context?: Record<string, any>;
|
|
83
|
+
/** Custom headers to include in the request. */
|
|
84
|
+
headers?: Record<string, string>;
|
|
85
|
+
/** Additional top-level properties to merge into the request body. */
|
|
86
|
+
body?: Record<string, any>;
|
|
87
|
+
/** Fired internally when session ID is extracted from response headers. */
|
|
88
|
+
onSessionId?: (sessionId: string, sessionName?: string) => void;
|
|
89
|
+
}
|
|
90
|
+
/** Callbacks for streaming responses. */
|
|
91
|
+
interface StreamCallbacks {
|
|
92
|
+
/** Called for each text chunk from the agent. */
|
|
93
|
+
onText?: (text: string) => void;
|
|
94
|
+
/** Called for each reasoning chunk (models with chain-of-thought). */
|
|
95
|
+
onReasoning?: (delta: string, index: number) => void;
|
|
96
|
+
/** Called when control is handed off to a sub-agent. */
|
|
97
|
+
onAgentHandoff?: (agentName: string) => void;
|
|
98
|
+
/** Called when a tool execution starts. */
|
|
99
|
+
onToolStart?: (toolName: string, toolType: ToolType) => void;
|
|
100
|
+
/** Called when a tool execution completes. */
|
|
101
|
+
onToolEnd?: (toolName: string, result?: any, error?: string) => void;
|
|
102
|
+
/** Called when agent pauses for a blocking client tool. */
|
|
103
|
+
onPaused?: (toolName: string, args: any) => void;
|
|
104
|
+
/** Called when the stream completes successfully. */
|
|
105
|
+
onComplete?: (fullText: string) => void;
|
|
106
|
+
/** Called if an error occurs during streaming. */
|
|
107
|
+
onError?: (error: Error) => void;
|
|
108
|
+
/** Called for every stream event. Useful for advanced consumers (e.g. debug panels). */
|
|
109
|
+
onEvent?: (event: StreamEvent) => void;
|
|
110
|
+
}
|
|
111
|
+
/** A client-side tool that the agent can invoke. */
|
|
112
|
+
interface ClientTool {
|
|
113
|
+
/** Tool name — must match the name the agent knows. */
|
|
114
|
+
name: string;
|
|
115
|
+
/** Description of what the tool does. */
|
|
116
|
+
description: string;
|
|
117
|
+
/**
|
|
118
|
+
* Tool parameters — accepts a **Zod schema** or a raw JSON Schema object.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Zod
|
|
122
|
+
* parameters: z.object({ message: z.string() })
|
|
123
|
+
*
|
|
124
|
+
* // JSON Schema
|
|
125
|
+
* parameters: { type: "object", properties: { message: { type: "string" } } }
|
|
126
|
+
*/
|
|
127
|
+
parameters: ZodSchema | Record<string, any>;
|
|
128
|
+
/** If true, agent pauses until result is provided. */
|
|
129
|
+
await?: boolean;
|
|
130
|
+
/** Handler function. If provided with `await: true`, auto-resumes. */
|
|
131
|
+
handler?: (args: any) => any | Promise<any>;
|
|
132
|
+
}
|
|
133
|
+
/** Information about a paused tool call. */
|
|
134
|
+
interface PausedToolInfo {
|
|
135
|
+
callId: string;
|
|
136
|
+
toolName: string;
|
|
137
|
+
args: any;
|
|
138
|
+
}
|
|
139
|
+
/** @internal Body sent to the /executeAgent endpoint. */
|
|
140
|
+
interface ExecuteRequestBody {
|
|
141
|
+
input?: string;
|
|
142
|
+
stream: true;
|
|
143
|
+
clientTools?: Array<{
|
|
144
|
+
name: string;
|
|
145
|
+
description: string;
|
|
146
|
+
parameters: Record<string, any>;
|
|
147
|
+
await?: boolean;
|
|
148
|
+
}>;
|
|
149
|
+
toolCallResult?: {
|
|
150
|
+
callId: string;
|
|
151
|
+
result: any;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** @internal Options passed to the internal stream executor. */
|
|
155
|
+
interface StreamOptions {
|
|
156
|
+
url: string;
|
|
157
|
+
body: ExecuteRequestBody;
|
|
158
|
+
headers: Record<string, string>;
|
|
159
|
+
callbacks: StreamCallbacks;
|
|
160
|
+
clientTools: Map<string, ClientTool>;
|
|
161
|
+
signal?: AbortSignal;
|
|
162
|
+
/** Called when session ID is received from response headers. */
|
|
163
|
+
onSessionId?: (sessionId: SessionId, sessionName?: string) => void;
|
|
164
|
+
/** Called when paused tool info is detected. */
|
|
165
|
+
onPaused?: (info: PausedToolInfo) => void;
|
|
166
|
+
/** Called to auto-resume after a client tool handler completes. */
|
|
167
|
+
onAutoResume?: (callId: string, result: any) => void;
|
|
168
|
+
/** Called with the raw Response object after the HTTP request completes. */
|
|
169
|
+
onResponse?: (response: Response) => void;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Represents a conversation session with a BuildShip agent.
|
|
174
|
+
*
|
|
175
|
+
* Sessions maintain history across multiple turns and support
|
|
176
|
+
* pause/resume for blocking client tools.
|
|
177
|
+
*/
|
|
178
|
+
declare class AgentSession {
|
|
179
|
+
/** @internal */ private _agent;
|
|
180
|
+
/** @internal */ private _sessionId;
|
|
181
|
+
/** @internal */ private _paused;
|
|
182
|
+
/** @internal */ private _pausedToolInfo;
|
|
183
|
+
/** @internal */ private _abortController;
|
|
184
|
+
/** @internal */
|
|
185
|
+
constructor(agent: BuildShipAgent, sessionId?: SessionId);
|
|
186
|
+
/**
|
|
187
|
+
* Send a message in this session.
|
|
188
|
+
*
|
|
189
|
+
* @param message - The message to send
|
|
190
|
+
* @param callbacks - Event handlers for the stream
|
|
191
|
+
* @param callbacks - Event handlers for the stream
|
|
192
|
+
* @param options - Optional settings like context, headers, or body
|
|
193
|
+
* @returns This session (for chaining)
|
|
194
|
+
*/
|
|
195
|
+
execute(message: string, callbacks: StreamCallbacks, options?: ExecuteOptions): Promise<AgentSession>;
|
|
196
|
+
/**
|
|
197
|
+
* Resume a paused session with a tool result.
|
|
198
|
+
*
|
|
199
|
+
* @param result - The result to send back to the agent
|
|
200
|
+
* @param callbacks - Event handlers for the resumed stream
|
|
201
|
+
* @param options - Optional settings like headers or body
|
|
202
|
+
* @returns This session (for chaining)
|
|
203
|
+
*/
|
|
204
|
+
resume(result: any, callbacks: StreamCallbacks, options?: Omit<ExecuteOptions, "context">): Promise<AgentSession>;
|
|
205
|
+
/**
|
|
206
|
+
* Resume a session with an explicit tool call ID and result.
|
|
207
|
+
*
|
|
208
|
+
* Unlike `resume()`, this does NOT require the session to be in a paused state,
|
|
209
|
+
* making it suitable for external resume flows (e.g. React widget submissions)
|
|
210
|
+
* where the session object may have been re-created.
|
|
211
|
+
*
|
|
212
|
+
* @param callId - The tool call ID to resume
|
|
213
|
+
* @param result - The result to send back to the agent
|
|
214
|
+
* @param callbacks - Event handlers for the resumed stream
|
|
215
|
+
* @param options - Optional settings like headers or body
|
|
216
|
+
* @returns This session (for chaining)
|
|
217
|
+
*/
|
|
218
|
+
resumeWithCallId(callId: string, result: any, callbacks: StreamCallbacks, options?: Omit<ExecuteOptions, "context">): Promise<AgentSession>;
|
|
219
|
+
/**
|
|
220
|
+
* Check if this session is waiting for a tool result.
|
|
221
|
+
*/
|
|
222
|
+
isPaused(): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Get information about the paused tool call.
|
|
225
|
+
* Returns `null` if the session is not paused.
|
|
226
|
+
*/
|
|
227
|
+
getPausedTool(): PausedToolInfo | null;
|
|
228
|
+
/**
|
|
229
|
+
* Get the session ID.
|
|
230
|
+
* May be `undefined` if the session hasn't executed yet.
|
|
231
|
+
*/
|
|
232
|
+
getSessionId(): SessionId;
|
|
233
|
+
/**
|
|
234
|
+
* Cancel the current streaming operation.
|
|
235
|
+
*/
|
|
236
|
+
abort(): void;
|
|
237
|
+
/** @internal */
|
|
238
|
+
private _run;
|
|
239
|
+
/** @internal */
|
|
240
|
+
private _getClientToolDefs;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Main entry point for interacting with a BuildShip agent.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* import { BuildShipAgent } from "buildship-agent-sdk/core";
|
|
249
|
+
*
|
|
250
|
+
* const agent = new BuildShipAgent({
|
|
251
|
+
* agentId: "your-agent-id",
|
|
252
|
+
* accessKey: "your-access-key",
|
|
253
|
+
* });
|
|
254
|
+
*
|
|
255
|
+
* const session = await agent.execute("Hello!", {
|
|
256
|
+
* onText: (text) => console.log(text),
|
|
257
|
+
* onComplete: (fullText) => console.log("Done!", fullText),
|
|
258
|
+
* });
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare class BuildShipAgent {
|
|
262
|
+
/** @internal */ readonly _agentId: string;
|
|
263
|
+
/** @internal */ readonly _accessKey?: string;
|
|
264
|
+
/** @internal */ readonly _baseUrl: string;
|
|
265
|
+
/** @internal */ readonly _clientTools: Map<string, ClientTool>;
|
|
266
|
+
constructor(config: AgentConfig);
|
|
267
|
+
/**
|
|
268
|
+
* The URL for the agent's execute endpoint.
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
get _url(): string;
|
|
272
|
+
/**
|
|
273
|
+
* Build the authorization / common headers.
|
|
274
|
+
* @internal
|
|
275
|
+
*/
|
|
276
|
+
_buildHeaders(sessionId?: SessionId): Record<string, string>;
|
|
277
|
+
/**
|
|
278
|
+
* Start a new conversation.
|
|
279
|
+
*
|
|
280
|
+
* Creates a fresh session and sends the first message.
|
|
281
|
+
*
|
|
282
|
+
* @param message - The message to send
|
|
283
|
+
* @param callbacks - Event handlers for the stream
|
|
284
|
+
* @param options - Optional execution settings (context, headers, body, onSessionId)
|
|
285
|
+
* @returns The new session
|
|
286
|
+
*/
|
|
287
|
+
execute(message: string, callbacks: StreamCallbacks, options?: ExecuteOptions): Promise<AgentSession>;
|
|
288
|
+
/**
|
|
289
|
+
* Get an existing session by ID to continue a conversation.
|
|
290
|
+
*
|
|
291
|
+
* @param sessionId - The session ID from a previous conversation
|
|
292
|
+
* @returns The session object
|
|
293
|
+
*/
|
|
294
|
+
session(sessionId: SessionId | string): AgentSession;
|
|
295
|
+
/**
|
|
296
|
+
* Register a client-side tool that the agent can call.
|
|
297
|
+
*/
|
|
298
|
+
registerClientTool(tool: ClientTool): void;
|
|
299
|
+
/**
|
|
300
|
+
* Remove a registered client tool.
|
|
301
|
+
*/
|
|
302
|
+
unregisterClientTool(name: string): void;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export { AgentSession as A, BuildShipAgent as B, type ClientTool as C, type ExecuteRequestBody as E, type PausedToolInfo as P, type ReasoningDeltaEvent as R, type StreamOptions as S, type ToolType as T, type AgentConfig as a, type SessionId as b, type StreamCallbacks as c, type StreamEvent as d, type StreamEventMeta as e, type TextDeltaEvent as f, type AgentHandoffEvent as g, type ToolCallStartEvent as h, type ToolCallEndEvent as i, type RunErrorEvent as j };
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { ZodSchema } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unified tool type discriminator.
|
|
5
|
+
*/
|
|
6
|
+
type ToolType = "flow" | "node" | "mcp" | "client" | "builtin" | "agent";
|
|
7
|
+
type StreamEventMeta = {
|
|
8
|
+
executionId: string;
|
|
9
|
+
sequence: number;
|
|
10
|
+
timestamp?: number;
|
|
11
|
+
agentId: string;
|
|
12
|
+
};
|
|
13
|
+
type TextDeltaEvent = {
|
|
14
|
+
type: "text_delta";
|
|
15
|
+
data: string;
|
|
16
|
+
meta: StreamEventMeta;
|
|
17
|
+
};
|
|
18
|
+
type ReasoningDeltaEvent = {
|
|
19
|
+
type: "reasoning_delta";
|
|
20
|
+
data: {
|
|
21
|
+
delta: string;
|
|
22
|
+
index: number;
|
|
23
|
+
};
|
|
24
|
+
meta: StreamEventMeta;
|
|
25
|
+
};
|
|
26
|
+
type AgentHandoffEvent = {
|
|
27
|
+
type: "agent_handoff";
|
|
28
|
+
data: {
|
|
29
|
+
agentName: string;
|
|
30
|
+
};
|
|
31
|
+
meta: StreamEventMeta;
|
|
32
|
+
};
|
|
33
|
+
type ToolCallStartEvent = {
|
|
34
|
+
type: "tool_call_start";
|
|
35
|
+
data: {
|
|
36
|
+
callId: string;
|
|
37
|
+
toolName: string;
|
|
38
|
+
toolType: ToolType;
|
|
39
|
+
inputs?: any;
|
|
40
|
+
serverName?: string;
|
|
41
|
+
paused?: boolean;
|
|
42
|
+
};
|
|
43
|
+
meta: StreamEventMeta;
|
|
44
|
+
};
|
|
45
|
+
type ToolCallEndEvent = {
|
|
46
|
+
type: "tool_call_end";
|
|
47
|
+
data: {
|
|
48
|
+
callId: string;
|
|
49
|
+
toolName: string;
|
|
50
|
+
toolType: ToolType;
|
|
51
|
+
result?: any;
|
|
52
|
+
error?: string;
|
|
53
|
+
executionTime?: number;
|
|
54
|
+
};
|
|
55
|
+
meta: StreamEventMeta;
|
|
56
|
+
};
|
|
57
|
+
type RunErrorEvent = {
|
|
58
|
+
type: "run_error";
|
|
59
|
+
data: {
|
|
60
|
+
message: string;
|
|
61
|
+
code?: string;
|
|
62
|
+
};
|
|
63
|
+
meta: StreamEventMeta;
|
|
64
|
+
};
|
|
65
|
+
type StreamEvent = TextDeltaEvent | ReasoningDeltaEvent | AgentHandoffEvent | ToolCallStartEvent | ToolCallEndEvent | RunErrorEvent;
|
|
66
|
+
/** Branded session ID type. */
|
|
67
|
+
type SessionId = string & {
|
|
68
|
+
readonly __brand: unique symbol;
|
|
69
|
+
};
|
|
70
|
+
/** Configuration for the BuildShipAgent constructor. */
|
|
71
|
+
interface AgentConfig {
|
|
72
|
+
/** Your BuildShip agent ID. */
|
|
73
|
+
agentId: string;
|
|
74
|
+
/** Access key if your agent requires authentication. */
|
|
75
|
+
accessKey?: string;
|
|
76
|
+
/** Custom API base URL. Defaults to `https://api.buildship.run`. */
|
|
77
|
+
baseUrl?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Options for agent execution. */
|
|
80
|
+
interface ExecuteOptions {
|
|
81
|
+
/** Additional context variables for the prompt. */
|
|
82
|
+
context?: Record<string, any>;
|
|
83
|
+
/** Custom headers to include in the request. */
|
|
84
|
+
headers?: Record<string, string>;
|
|
85
|
+
/** Additional top-level properties to merge into the request body. */
|
|
86
|
+
body?: Record<string, any>;
|
|
87
|
+
/** Fired internally when session ID is extracted from response headers. */
|
|
88
|
+
onSessionId?: (sessionId: string, sessionName?: string) => void;
|
|
89
|
+
}
|
|
90
|
+
/** Callbacks for streaming responses. */
|
|
91
|
+
interface StreamCallbacks {
|
|
92
|
+
/** Called for each text chunk from the agent. */
|
|
93
|
+
onText?: (text: string) => void;
|
|
94
|
+
/** Called for each reasoning chunk (models with chain-of-thought). */
|
|
95
|
+
onReasoning?: (delta: string, index: number) => void;
|
|
96
|
+
/** Called when control is handed off to a sub-agent. */
|
|
97
|
+
onAgentHandoff?: (agentName: string) => void;
|
|
98
|
+
/** Called when a tool execution starts. */
|
|
99
|
+
onToolStart?: (toolName: string, toolType: ToolType) => void;
|
|
100
|
+
/** Called when a tool execution completes. */
|
|
101
|
+
onToolEnd?: (toolName: string, result?: any, error?: string) => void;
|
|
102
|
+
/** Called when agent pauses for a blocking client tool. */
|
|
103
|
+
onPaused?: (toolName: string, args: any) => void;
|
|
104
|
+
/** Called when the stream completes successfully. */
|
|
105
|
+
onComplete?: (fullText: string) => void;
|
|
106
|
+
/** Called if an error occurs during streaming. */
|
|
107
|
+
onError?: (error: Error) => void;
|
|
108
|
+
/** Called for every stream event. Useful for advanced consumers (e.g. debug panels). */
|
|
109
|
+
onEvent?: (event: StreamEvent) => void;
|
|
110
|
+
}
|
|
111
|
+
/** A client-side tool that the agent can invoke. */
|
|
112
|
+
interface ClientTool {
|
|
113
|
+
/** Tool name — must match the name the agent knows. */
|
|
114
|
+
name: string;
|
|
115
|
+
/** Description of what the tool does. */
|
|
116
|
+
description: string;
|
|
117
|
+
/**
|
|
118
|
+
* Tool parameters — accepts a **Zod schema** or a raw JSON Schema object.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Zod
|
|
122
|
+
* parameters: z.object({ message: z.string() })
|
|
123
|
+
*
|
|
124
|
+
* // JSON Schema
|
|
125
|
+
* parameters: { type: "object", properties: { message: { type: "string" } } }
|
|
126
|
+
*/
|
|
127
|
+
parameters: ZodSchema | Record<string, any>;
|
|
128
|
+
/** If true, agent pauses until result is provided. */
|
|
129
|
+
await?: boolean;
|
|
130
|
+
/** Handler function. If provided with `await: true`, auto-resumes. */
|
|
131
|
+
handler?: (args: any) => any | Promise<any>;
|
|
132
|
+
}
|
|
133
|
+
/** Information about a paused tool call. */
|
|
134
|
+
interface PausedToolInfo {
|
|
135
|
+
callId: string;
|
|
136
|
+
toolName: string;
|
|
137
|
+
args: any;
|
|
138
|
+
}
|
|
139
|
+
/** @internal Body sent to the /executeAgent endpoint. */
|
|
140
|
+
interface ExecuteRequestBody {
|
|
141
|
+
input?: string;
|
|
142
|
+
stream: true;
|
|
143
|
+
clientTools?: Array<{
|
|
144
|
+
name: string;
|
|
145
|
+
description: string;
|
|
146
|
+
parameters: Record<string, any>;
|
|
147
|
+
await?: boolean;
|
|
148
|
+
}>;
|
|
149
|
+
toolCallResult?: {
|
|
150
|
+
callId: string;
|
|
151
|
+
result: any;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** @internal Options passed to the internal stream executor. */
|
|
155
|
+
interface StreamOptions {
|
|
156
|
+
url: string;
|
|
157
|
+
body: ExecuteRequestBody;
|
|
158
|
+
headers: Record<string, string>;
|
|
159
|
+
callbacks: StreamCallbacks;
|
|
160
|
+
clientTools: Map<string, ClientTool>;
|
|
161
|
+
signal?: AbortSignal;
|
|
162
|
+
/** Called when session ID is received from response headers. */
|
|
163
|
+
onSessionId?: (sessionId: SessionId, sessionName?: string) => void;
|
|
164
|
+
/** Called when paused tool info is detected. */
|
|
165
|
+
onPaused?: (info: PausedToolInfo) => void;
|
|
166
|
+
/** Called to auto-resume after a client tool handler completes. */
|
|
167
|
+
onAutoResume?: (callId: string, result: any) => void;
|
|
168
|
+
/** Called with the raw Response object after the HTTP request completes. */
|
|
169
|
+
onResponse?: (response: Response) => void;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Represents a conversation session with a BuildShip agent.
|
|
174
|
+
*
|
|
175
|
+
* Sessions maintain history across multiple turns and support
|
|
176
|
+
* pause/resume for blocking client tools.
|
|
177
|
+
*/
|
|
178
|
+
declare class AgentSession {
|
|
179
|
+
/** @internal */ private _agent;
|
|
180
|
+
/** @internal */ private _sessionId;
|
|
181
|
+
/** @internal */ private _paused;
|
|
182
|
+
/** @internal */ private _pausedToolInfo;
|
|
183
|
+
/** @internal */ private _abortController;
|
|
184
|
+
/** @internal */
|
|
185
|
+
constructor(agent: BuildShipAgent, sessionId?: SessionId);
|
|
186
|
+
/**
|
|
187
|
+
* Send a message in this session.
|
|
188
|
+
*
|
|
189
|
+
* @param message - The message to send
|
|
190
|
+
* @param callbacks - Event handlers for the stream
|
|
191
|
+
* @param callbacks - Event handlers for the stream
|
|
192
|
+
* @param options - Optional settings like context, headers, or body
|
|
193
|
+
* @returns This session (for chaining)
|
|
194
|
+
*/
|
|
195
|
+
execute(message: string, callbacks: StreamCallbacks, options?: ExecuteOptions): Promise<AgentSession>;
|
|
196
|
+
/**
|
|
197
|
+
* Resume a paused session with a tool result.
|
|
198
|
+
*
|
|
199
|
+
* @param result - The result to send back to the agent
|
|
200
|
+
* @param callbacks - Event handlers for the resumed stream
|
|
201
|
+
* @param options - Optional settings like headers or body
|
|
202
|
+
* @returns This session (for chaining)
|
|
203
|
+
*/
|
|
204
|
+
resume(result: any, callbacks: StreamCallbacks, options?: Omit<ExecuteOptions, "context">): Promise<AgentSession>;
|
|
205
|
+
/**
|
|
206
|
+
* Resume a session with an explicit tool call ID and result.
|
|
207
|
+
*
|
|
208
|
+
* Unlike `resume()`, this does NOT require the session to be in a paused state,
|
|
209
|
+
* making it suitable for external resume flows (e.g. React widget submissions)
|
|
210
|
+
* where the session object may have been re-created.
|
|
211
|
+
*
|
|
212
|
+
* @param callId - The tool call ID to resume
|
|
213
|
+
* @param result - The result to send back to the agent
|
|
214
|
+
* @param callbacks - Event handlers for the resumed stream
|
|
215
|
+
* @param options - Optional settings like headers or body
|
|
216
|
+
* @returns This session (for chaining)
|
|
217
|
+
*/
|
|
218
|
+
resumeWithCallId(callId: string, result: any, callbacks: StreamCallbacks, options?: Omit<ExecuteOptions, "context">): Promise<AgentSession>;
|
|
219
|
+
/**
|
|
220
|
+
* Check if this session is waiting for a tool result.
|
|
221
|
+
*/
|
|
222
|
+
isPaused(): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Get information about the paused tool call.
|
|
225
|
+
* Returns `null` if the session is not paused.
|
|
226
|
+
*/
|
|
227
|
+
getPausedTool(): PausedToolInfo | null;
|
|
228
|
+
/**
|
|
229
|
+
* Get the session ID.
|
|
230
|
+
* May be `undefined` if the session hasn't executed yet.
|
|
231
|
+
*/
|
|
232
|
+
getSessionId(): SessionId;
|
|
233
|
+
/**
|
|
234
|
+
* Cancel the current streaming operation.
|
|
235
|
+
*/
|
|
236
|
+
abort(): void;
|
|
237
|
+
/** @internal */
|
|
238
|
+
private _run;
|
|
239
|
+
/** @internal */
|
|
240
|
+
private _getClientToolDefs;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Main entry point for interacting with a BuildShip agent.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* import { BuildShipAgent } from "buildship-agent-sdk/core";
|
|
249
|
+
*
|
|
250
|
+
* const agent = new BuildShipAgent({
|
|
251
|
+
* agentId: "your-agent-id",
|
|
252
|
+
* accessKey: "your-access-key",
|
|
253
|
+
* });
|
|
254
|
+
*
|
|
255
|
+
* const session = await agent.execute("Hello!", {
|
|
256
|
+
* onText: (text) => console.log(text),
|
|
257
|
+
* onComplete: (fullText) => console.log("Done!", fullText),
|
|
258
|
+
* });
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare class BuildShipAgent {
|
|
262
|
+
/** @internal */ readonly _agentId: string;
|
|
263
|
+
/** @internal */ readonly _accessKey?: string;
|
|
264
|
+
/** @internal */ readonly _baseUrl: string;
|
|
265
|
+
/** @internal */ readonly _clientTools: Map<string, ClientTool>;
|
|
266
|
+
constructor(config: AgentConfig);
|
|
267
|
+
/**
|
|
268
|
+
* The URL for the agent's execute endpoint.
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
get _url(): string;
|
|
272
|
+
/**
|
|
273
|
+
* Build the authorization / common headers.
|
|
274
|
+
* @internal
|
|
275
|
+
*/
|
|
276
|
+
_buildHeaders(sessionId?: SessionId): Record<string, string>;
|
|
277
|
+
/**
|
|
278
|
+
* Start a new conversation.
|
|
279
|
+
*
|
|
280
|
+
* Creates a fresh session and sends the first message.
|
|
281
|
+
*
|
|
282
|
+
* @param message - The message to send
|
|
283
|
+
* @param callbacks - Event handlers for the stream
|
|
284
|
+
* @param options - Optional execution settings (context, headers, body, onSessionId)
|
|
285
|
+
* @returns The new session
|
|
286
|
+
*/
|
|
287
|
+
execute(message: string, callbacks: StreamCallbacks, options?: ExecuteOptions): Promise<AgentSession>;
|
|
288
|
+
/**
|
|
289
|
+
* Get an existing session by ID to continue a conversation.
|
|
290
|
+
*
|
|
291
|
+
* @param sessionId - The session ID from a previous conversation
|
|
292
|
+
* @returns The session object
|
|
293
|
+
*/
|
|
294
|
+
session(sessionId: SessionId | string): AgentSession;
|
|
295
|
+
/**
|
|
296
|
+
* Register a client-side tool that the agent can call.
|
|
297
|
+
*/
|
|
298
|
+
registerClientTool(tool: ClientTool): void;
|
|
299
|
+
/**
|
|
300
|
+
* Remove a registered client tool.
|
|
301
|
+
*/
|
|
302
|
+
unregisterClientTool(name: string): void;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export { AgentSession as A, BuildShipAgent as B, type ClientTool as C, type ExecuteRequestBody as E, type PausedToolInfo as P, type ReasoningDeltaEvent as R, type StreamOptions as S, type ToolType as T, type AgentConfig as a, type SessionId as b, type StreamCallbacks as c, type StreamEvent as d, type StreamEventMeta as e, type TextDeltaEvent as f, type AgentHandoffEvent as g, type ToolCallStartEvent as h, type ToolCallEndEvent as i, type RunErrorEvent as j };
|