@yolo-labs/core-types 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +645 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain text content block.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The most common content block type, representing a segment of text
|
|
6
|
+
* in a conversation message.
|
|
7
|
+
*/
|
|
8
|
+
interface TextBlock {
|
|
9
|
+
type: 'text';
|
|
10
|
+
text: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Image content block with inline base64-encoded data.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Used when the image data is available directly, e.g. from a file upload
|
|
17
|
+
* or canvas capture. The `media_type` should be a valid MIME type such as
|
|
18
|
+
* `image/png`, `image/jpeg`, `image/gif`, or `image/webp`.
|
|
19
|
+
*/
|
|
20
|
+
interface ImageBlockBase64 {
|
|
21
|
+
type: 'image';
|
|
22
|
+
source: {
|
|
23
|
+
type: 'base64';
|
|
24
|
+
media_type: string;
|
|
25
|
+
data: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Image content block referenced by URL.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Used when the image is hosted at a publicly accessible URL.
|
|
33
|
+
* The provider adapter is responsible for fetching or passing through the URL.
|
|
34
|
+
*/
|
|
35
|
+
interface ImageBlockUrl {
|
|
36
|
+
type: 'image';
|
|
37
|
+
source: {
|
|
38
|
+
type: 'url';
|
|
39
|
+
url: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** An image block, either base64-encoded or URL-referenced. */
|
|
43
|
+
type ImageBlock = ImageBlockBase64 | ImageBlockUrl;
|
|
44
|
+
/**
|
|
45
|
+
* File content block with base64-encoded data and optional filename.
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* Represents non-image file attachments (e.g. PDFs, CSVs). Not all providers
|
|
49
|
+
* support file blocks natively; adapters may convert them to text references.
|
|
50
|
+
*/
|
|
51
|
+
interface FileBlock {
|
|
52
|
+
type: 'file';
|
|
53
|
+
source: {
|
|
54
|
+
type: 'base64';
|
|
55
|
+
media_type: string;
|
|
56
|
+
data: string;
|
|
57
|
+
name?: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Tool use content block representing an assistant's tool call in conversation history.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* When the assistant decides to invoke a tool, the response includes one or more
|
|
65
|
+
* `ToolUseBlock` entries alongside any `TextBlock` entries. The `id` is provider-assigned
|
|
66
|
+
* and must be referenced by the corresponding {@link ToolResultBlock}.
|
|
67
|
+
*/
|
|
68
|
+
interface ToolUseBlock {
|
|
69
|
+
type: 'tool_use';
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
input: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Tool result content block representing the output of a tool execution.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* After executing one or more tool calls, the results are sent back as a user message
|
|
79
|
+
* containing `ToolResultBlock` entries. The `tool_use_id` must match the `id` from the
|
|
80
|
+
* corresponding {@link ToolUseBlock} so the provider can correlate calls with results.
|
|
81
|
+
*/
|
|
82
|
+
interface ToolResultBlock {
|
|
83
|
+
type: 'tool_result';
|
|
84
|
+
tool_use_id: string;
|
|
85
|
+
content: string;
|
|
86
|
+
is_error?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/** Union of all supported multimodal content block types. */
|
|
89
|
+
type ContentBlock = TextBlock | ImageBlock | FileBlock | ToolUseBlock | ToolResultBlock;
|
|
90
|
+
/**
|
|
91
|
+
* A conversation message with a role and multimodal content.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* Content can be a plain string for text-only messages, or an array of
|
|
95
|
+
* {@link ContentBlock} for multimodal messages containing images or files.
|
|
96
|
+
*/
|
|
97
|
+
interface Message {
|
|
98
|
+
role: 'user' | 'assistant';
|
|
99
|
+
content: string | ContentBlock[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Emitted when the agent begins processing a request. */
|
|
103
|
+
interface AgentStartEvent {
|
|
104
|
+
type: 'agent_start';
|
|
105
|
+
sessionId: string;
|
|
106
|
+
timestamp: string;
|
|
107
|
+
}
|
|
108
|
+
/** Streamed fragment of the agent's internal reasoning. */
|
|
109
|
+
interface ThoughtDeltaEvent {
|
|
110
|
+
type: 'thought_delta';
|
|
111
|
+
text: string;
|
|
112
|
+
}
|
|
113
|
+
/** Streamed fragment of the agent's visible text output. */
|
|
114
|
+
interface TextDeltaEvent {
|
|
115
|
+
type: 'text_delta';
|
|
116
|
+
text: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Emitted when the agent invokes a tool with its resolved name and input.
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* The `input` field contains the fully parsed JSON input for the tool.
|
|
123
|
+
* This event is emitted after the tool input has been fully accumulated
|
|
124
|
+
* from `tool_input_delta` events.
|
|
125
|
+
*/
|
|
126
|
+
interface ToolCallEvent {
|
|
127
|
+
type: 'tool_call';
|
|
128
|
+
toolCallId: string;
|
|
129
|
+
name: string;
|
|
130
|
+
input: Record<string, unknown>;
|
|
131
|
+
}
|
|
132
|
+
/** Streamed fragment of a tool call's input as it is being constructed. */
|
|
133
|
+
interface ToolInputDeltaEvent {
|
|
134
|
+
type: 'tool_input_delta';
|
|
135
|
+
toolCallId: string;
|
|
136
|
+
partialInput: string;
|
|
137
|
+
}
|
|
138
|
+
/** Reports incremental progress of a long-running tool execution. */
|
|
139
|
+
interface ToolProgressEvent {
|
|
140
|
+
type: 'tool_progress';
|
|
141
|
+
toolCallId: string;
|
|
142
|
+
message: string;
|
|
143
|
+
percentage?: number;
|
|
144
|
+
metadata?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Emitted when a tool finishes execution, carrying its output or error.
|
|
148
|
+
*
|
|
149
|
+
* @remarks
|
|
150
|
+
* Check `success` to determine whether the tool completed normally.
|
|
151
|
+
* On failure, the `error` field contains a human-readable description.
|
|
152
|
+
* Tool results are fed back into the conversation for the next AI turn.
|
|
153
|
+
*/
|
|
154
|
+
interface ToolResultEvent {
|
|
155
|
+
type: 'tool_result';
|
|
156
|
+
toolCallId: string;
|
|
157
|
+
name: string;
|
|
158
|
+
success: boolean;
|
|
159
|
+
output: unknown;
|
|
160
|
+
error?: string;
|
|
161
|
+
}
|
|
162
|
+
/** General-purpose status notification for session-level state changes. */
|
|
163
|
+
interface StatusUpdateEvent {
|
|
164
|
+
type: 'status_update';
|
|
165
|
+
status: string;
|
|
166
|
+
message?: string;
|
|
167
|
+
metadata?: Record<string, unknown>;
|
|
168
|
+
}
|
|
169
|
+
/** Emitted when an error occurs, indicating whether the session can recover. */
|
|
170
|
+
interface ErrorEvent {
|
|
171
|
+
type: 'error';
|
|
172
|
+
error: string;
|
|
173
|
+
code?: string;
|
|
174
|
+
recoverable: boolean;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Emitted when the agent finishes processing, optionally including token usage.
|
|
178
|
+
*
|
|
179
|
+
* @remarks
|
|
180
|
+
* Always the last event in a generation session. The `usage` field is
|
|
181
|
+
* populated when the provider reports token counts and turn information.
|
|
182
|
+
*/
|
|
183
|
+
interface AgentCompleteEvent {
|
|
184
|
+
type: 'agent_complete';
|
|
185
|
+
sessionId: string;
|
|
186
|
+
timestamp: string;
|
|
187
|
+
usage?: {
|
|
188
|
+
inputTokens: number;
|
|
189
|
+
outputTokens: number;
|
|
190
|
+
totalTurns: number;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Discriminated union of all session lifecycle and streaming events.
|
|
195
|
+
*
|
|
196
|
+
* @remarks
|
|
197
|
+
* Use the `type` field to discriminate between event variants.
|
|
198
|
+
* Events are emitted in order through the `AsyncIterable` returned
|
|
199
|
+
* by {@link agentLoop}.
|
|
200
|
+
*/
|
|
201
|
+
type SessionEvent = AgentStartEvent | ThoughtDeltaEvent | TextDeltaEvent | ToolCallEvent | ToolInputDeltaEvent | ToolProgressEvent | ToolResultEvent | StatusUpdateEvent | ErrorEvent | AgentCompleteEvent;
|
|
202
|
+
|
|
203
|
+
/** Represents a file with its path, content, and optional encoding. */
|
|
204
|
+
interface FileEntry {
|
|
205
|
+
path: string;
|
|
206
|
+
content: string;
|
|
207
|
+
encoding?: 'utf-8' | 'base64';
|
|
208
|
+
}
|
|
209
|
+
/** Result of a command execution, including exit code and captured output streams. */
|
|
210
|
+
interface CommandResult {
|
|
211
|
+
exitCode: number;
|
|
212
|
+
stdout: string;
|
|
213
|
+
stderr: string;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Abstraction for file system operations and command execution within a sandboxed environment.
|
|
217
|
+
*
|
|
218
|
+
* @remarks
|
|
219
|
+
* Implementations include {@link InMemorySandbox} (virtual filesystem),
|
|
220
|
+
* {@link NodeVMSandbox} (isolated VM), and {@link LocalSandboxProvider}
|
|
221
|
+
* (host filesystem). The optional `build`, `create`, `destroy`, and `reset`
|
|
222
|
+
* methods support lifecycle management for stateful sandbox environments.
|
|
223
|
+
*/
|
|
224
|
+
interface SandboxProvider {
|
|
225
|
+
readFile(path: string): Promise<string>;
|
|
226
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
227
|
+
deleteFile(path: string): Promise<void>;
|
|
228
|
+
listFiles(path: string): Promise<string[]>;
|
|
229
|
+
mkdir(path: string): Promise<void>;
|
|
230
|
+
executeCommand(command: string, options?: CommandExecutionOptions): Promise<CommandResult>;
|
|
231
|
+
build?(options?: Record<string, unknown>): Promise<CommandResult>;
|
|
232
|
+
create?(): Promise<void>;
|
|
233
|
+
destroy?(): Promise<void>;
|
|
234
|
+
reset?(): Promise<void>;
|
|
235
|
+
}
|
|
236
|
+
/** Options for configuring command execution, including working directory, environment, and timeout. */
|
|
237
|
+
interface CommandExecutionOptions {
|
|
238
|
+
cwd?: string;
|
|
239
|
+
env?: Record<string, string>;
|
|
240
|
+
timeout?: number;
|
|
241
|
+
onStdout?: (data: string) => void;
|
|
242
|
+
onStderr?: (data: string) => void;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Execution context provided to tools during invocation within a sandbox session.
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* Every tool receives a `SandboxContext` as its second argument. The context
|
|
249
|
+
* provides access to the sandbox filesystem, the current session ID, environment
|
|
250
|
+
* variables, and optional metadata.
|
|
251
|
+
*/
|
|
252
|
+
interface SandboxContext {
|
|
253
|
+
sandbox: SandboxProvider;
|
|
254
|
+
sessionId: string;
|
|
255
|
+
env: Record<string, string>;
|
|
256
|
+
metadata?: Record<string, unknown>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Canonical tool definition format sent to AI providers.
|
|
261
|
+
*
|
|
262
|
+
* @remarks
|
|
263
|
+
* The `inputSchema` must be a valid JSON Schema object describing the
|
|
264
|
+
* tool's expected input parameters. Provider adapters translate this
|
|
265
|
+
* into their native tool format (e.g. Anthropic `input_schema`, OpenAI
|
|
266
|
+
* `function.parameters`, Google `functionDeclarations`).
|
|
267
|
+
*/
|
|
268
|
+
interface ToolDefinition {
|
|
269
|
+
name: string;
|
|
270
|
+
description: string;
|
|
271
|
+
inputSchema: Record<string, unknown>;
|
|
272
|
+
}
|
|
273
|
+
/** Result returned after a tool execution, including output and optional error details. */
|
|
274
|
+
interface ToolResult {
|
|
275
|
+
success: boolean;
|
|
276
|
+
output: unknown;
|
|
277
|
+
preview?: string;
|
|
278
|
+
error?: string;
|
|
279
|
+
metadata?: Record<string, unknown>;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* An executable tool with its schema and an execute method that runs within a sandbox.
|
|
283
|
+
*
|
|
284
|
+
* @remarks
|
|
285
|
+
* Register tools with a {@link ToolRegistry} to make them available to the
|
|
286
|
+
* agent loop. The `execute` method receives validated input, a sandbox context,
|
|
287
|
+
* and an optional progress callback for long-running operations.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* const myTool: Tool = {
|
|
292
|
+
* name: 'greet',
|
|
293
|
+
* description: 'Returns a greeting',
|
|
294
|
+
* inputSchema: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },
|
|
295
|
+
* async execute(input, context) {
|
|
296
|
+
* return { success: true, output: `Hello, ${input.name}!` };
|
|
297
|
+
* },
|
|
298
|
+
* };
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
interface Tool {
|
|
302
|
+
name: string;
|
|
303
|
+
description: string;
|
|
304
|
+
inputSchema: Record<string, unknown>;
|
|
305
|
+
execute(input: Record<string, unknown>, context: SandboxContext, onProgress?: (progress: ToolProgressInfo) => void): Promise<ToolResult>;
|
|
306
|
+
}
|
|
307
|
+
/** Progress information emitted during long-running tool execution. */
|
|
308
|
+
interface ToolProgressInfo {
|
|
309
|
+
message: string;
|
|
310
|
+
percentage?: number;
|
|
311
|
+
metadata?: Record<string, unknown>;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Registry for managing and executing tools by name.
|
|
315
|
+
*
|
|
316
|
+
* @remarks
|
|
317
|
+
* Use {@link ToolRegistryImpl} as the default implementation. The registry
|
|
318
|
+
* provides runtime registration/unregistration, lookup, and serialization
|
|
319
|
+
* of tools to the AI provider's tool definition format.
|
|
320
|
+
*/
|
|
321
|
+
interface ToolRegistry {
|
|
322
|
+
register(tool: Tool): void;
|
|
323
|
+
unregister(name: string): void;
|
|
324
|
+
get(name: string): Tool | undefined;
|
|
325
|
+
list(): Tool[];
|
|
326
|
+
toAIToolDefinitions(): ToolDefinition[];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Parameters for creating an AI message.
|
|
331
|
+
*
|
|
332
|
+
* @remarks
|
|
333
|
+
* This is the canonical, provider-agnostic format for requesting a message
|
|
334
|
+
* from an AI model. Each provider adapter translates these parameters into
|
|
335
|
+
* the provider's native API format.
|
|
336
|
+
*/
|
|
337
|
+
interface CreateMessageParams {
|
|
338
|
+
model: string;
|
|
339
|
+
messages: Message[];
|
|
340
|
+
system?: string;
|
|
341
|
+
tools?: ToolDefinition[];
|
|
342
|
+
maxTokens?: number;
|
|
343
|
+
temperature?: number;
|
|
344
|
+
topP?: number;
|
|
345
|
+
stopSequences?: string[];
|
|
346
|
+
metadata?: Record<string, unknown>;
|
|
347
|
+
}
|
|
348
|
+
/** Emitted when a new content block (text or tool use) begins in the stream. */
|
|
349
|
+
interface ContentBlockStartEvent {
|
|
350
|
+
type: 'content_block_start';
|
|
351
|
+
index: number;
|
|
352
|
+
contentBlock: {
|
|
353
|
+
type: 'text' | 'tool_use';
|
|
354
|
+
id?: string;
|
|
355
|
+
name?: string;
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/** Emitted when an incremental delta (text, thinking, or tool input JSON) is received for a content block. */
|
|
359
|
+
interface ContentBlockDeltaEvent {
|
|
360
|
+
type: 'content_block_delta';
|
|
361
|
+
index: number;
|
|
362
|
+
delta: {
|
|
363
|
+
type: 'text_delta';
|
|
364
|
+
text: string;
|
|
365
|
+
} | {
|
|
366
|
+
type: 'thinking_delta';
|
|
367
|
+
thinking: string;
|
|
368
|
+
} | {
|
|
369
|
+
type: 'input_json_delta';
|
|
370
|
+
partial_json: string;
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/** Emitted when a content block has finished streaming. */
|
|
374
|
+
interface ContentBlockStopEvent {
|
|
375
|
+
type: 'content_block_stop';
|
|
376
|
+
index: number;
|
|
377
|
+
}
|
|
378
|
+
/** Emitted at the beginning of a streamed message, containing message metadata and initial usage. */
|
|
379
|
+
interface MessageStartEvent {
|
|
380
|
+
type: 'message_start';
|
|
381
|
+
message: {
|
|
382
|
+
id: string;
|
|
383
|
+
model: string;
|
|
384
|
+
role: 'assistant';
|
|
385
|
+
usage?: {
|
|
386
|
+
input_tokens: number;
|
|
387
|
+
output_tokens: number;
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
/** Emitted near the end of a message with the stop reason and final token usage. */
|
|
392
|
+
interface MessageDeltaEvent {
|
|
393
|
+
type: 'message_delta';
|
|
394
|
+
delta: {
|
|
395
|
+
stop_reason: string | null;
|
|
396
|
+
};
|
|
397
|
+
usage?: {
|
|
398
|
+
output_tokens: number;
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/** Emitted when the message stream has fully completed. */
|
|
402
|
+
interface MessageStopEvent {
|
|
403
|
+
type: 'message_stop';
|
|
404
|
+
}
|
|
405
|
+
/** Emitted when an error occurs during message streaming. */
|
|
406
|
+
interface StreamErrorEvent {
|
|
407
|
+
type: 'error';
|
|
408
|
+
error: {
|
|
409
|
+
type: string;
|
|
410
|
+
message: string;
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
/** Union of all provider-agnostic stream events emitted during message creation. */
|
|
414
|
+
type StreamEvent = MessageStartEvent | ContentBlockStartEvent | ContentBlockDeltaEvent | ContentBlockStopEvent | MessageDeltaEvent | MessageStopEvent | StreamErrorEvent;
|
|
415
|
+
/**
|
|
416
|
+
* Provider-agnostic interface for AI model interaction via streaming message creation.
|
|
417
|
+
*
|
|
418
|
+
* @remarks
|
|
419
|
+
* Implement this interface to add support for a new AI provider.
|
|
420
|
+
* The `createMessage` method must return an `AsyncIterable` of canonical
|
|
421
|
+
* {@link StreamEvent} objects. Provider adapters for Anthropic, OpenAI,
|
|
422
|
+
* and Google are included in `@yolo-labs/core-providers`.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* const provider: AIProvider = new AnthropicProvider({ apiKey: '...' });
|
|
427
|
+
* for await (const event of provider.createMessage(params)) {
|
|
428
|
+
* console.log(event.type);
|
|
429
|
+
* }
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
interface AIProvider {
|
|
433
|
+
createMessage(params: CreateMessageParams): AsyncIterable<StreamEvent>;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* User request initiating a generation session.
|
|
438
|
+
*
|
|
439
|
+
* @remarks
|
|
440
|
+
* Pass to {@link agentLoop} to start a generation. The `sessionId` is
|
|
441
|
+
* auto-generated if omitted. Provide `context.conversationHistory` to
|
|
442
|
+
* resume an existing conversation.
|
|
443
|
+
*/
|
|
444
|
+
interface GenerationRequest {
|
|
445
|
+
prompt: string;
|
|
446
|
+
sessionId?: string;
|
|
447
|
+
context?: Record<string, unknown>;
|
|
448
|
+
model?: string;
|
|
449
|
+
system?: string;
|
|
450
|
+
maxTokens?: number;
|
|
451
|
+
temperature?: number;
|
|
452
|
+
tools?: ToolDefinition[];
|
|
453
|
+
metadata?: Record<string, unknown>;
|
|
454
|
+
}
|
|
455
|
+
/** Stateful session tracking conversation history, tool calls, and metadata. */
|
|
456
|
+
interface GenerationSession {
|
|
457
|
+
id: string;
|
|
458
|
+
userId?: string;
|
|
459
|
+
conversationHistory: Message[];
|
|
460
|
+
fileSystemSnapshot?: Record<string, string>;
|
|
461
|
+
toolCallLog: ToolCallLogEntry[];
|
|
462
|
+
metadata: Record<string, unknown>;
|
|
463
|
+
createdAt: string;
|
|
464
|
+
updatedAt: string;
|
|
465
|
+
}
|
|
466
|
+
/** Record of a single tool invocation and its result within a session. */
|
|
467
|
+
interface ToolCallLogEntry {
|
|
468
|
+
toolCallId: string;
|
|
469
|
+
name: string;
|
|
470
|
+
input: Record<string, unknown>;
|
|
471
|
+
output: unknown;
|
|
472
|
+
success: boolean;
|
|
473
|
+
timestamp: string;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Persistence layer for creating, retrieving, and updating generation sessions.
|
|
477
|
+
*
|
|
478
|
+
* @remarks
|
|
479
|
+
* Implement this interface to persist sessions to a database. An in-memory
|
|
480
|
+
* implementation ({@link InMemorySessionStore}) is provided for development
|
|
481
|
+
* and testing.
|
|
482
|
+
*/
|
|
483
|
+
interface SessionStore {
|
|
484
|
+
create(session: Omit<GenerationSession, 'id' | 'createdAt' | 'updatedAt'>): Promise<GenerationSession>;
|
|
485
|
+
get(id: string): Promise<GenerationSession | undefined>;
|
|
486
|
+
update(id: string, updates: Partial<GenerationSession>): Promise<GenerationSession>;
|
|
487
|
+
delete(id: string): Promise<void>;
|
|
488
|
+
listByUser(userId: string): Promise<GenerationSession[]>;
|
|
489
|
+
appendEvent(sessionId: string, event: SessionEvent): Promise<void>;
|
|
490
|
+
getEventsSince(sessionId: string, eventId?: string): Promise<SessionEvent[]>;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** Versioned prompt entry with content, metadata, and tags. */
|
|
494
|
+
interface PromptRecord {
|
|
495
|
+
key: string;
|
|
496
|
+
content: string;
|
|
497
|
+
version: number;
|
|
498
|
+
metadata: Record<string, unknown>;
|
|
499
|
+
tags: string[];
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Storage backend for managing prompt records by key or tags.
|
|
503
|
+
*
|
|
504
|
+
* @remarks
|
|
505
|
+
* Implementations include {@link YamlPromptStore} (file-based) and
|
|
506
|
+
* {@link DatabasePromptStore} (abstract base for DB-backed stores).
|
|
507
|
+
*/
|
|
508
|
+
interface PromptStore {
|
|
509
|
+
get(key: string): Promise<PromptRecord | undefined>;
|
|
510
|
+
list(): Promise<PromptRecord[]>;
|
|
511
|
+
upsert(record: PromptRecord): Promise<PromptRecord>;
|
|
512
|
+
delete(key: string): Promise<void>;
|
|
513
|
+
queryByTags(tags: string[]): Promise<PromptRecord[]>;
|
|
514
|
+
}
|
|
515
|
+
/** Variables and metadata passed to the prompt assembler during rendering. */
|
|
516
|
+
interface PromptAssemblerContext {
|
|
517
|
+
variables: Record<string, string>;
|
|
518
|
+
metadata?: Record<string, unknown>;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Combines and renders prompt records into a final prompt string.
|
|
522
|
+
*
|
|
523
|
+
* @remarks
|
|
524
|
+
* Supports `{{variable}}` interpolation and `{{#if var}}...{{/if}}`
|
|
525
|
+
* conditional sections. Use {@link PromptAssemblerImpl} as the default
|
|
526
|
+
* implementation.
|
|
527
|
+
*/
|
|
528
|
+
interface PromptAssembler {
|
|
529
|
+
assemble(keys: string[], context: PromptAssemblerContext): Promise<string>;
|
|
530
|
+
assembleByTags(tags: string[], context: PromptAssemblerContext): Promise<string>;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** A single variable declaration within a template, including its default and requirement flag. */
|
|
534
|
+
interface TemplateVariable {
|
|
535
|
+
name: string;
|
|
536
|
+
description?: string;
|
|
537
|
+
default?: string;
|
|
538
|
+
required: boolean;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Blueprint describing a scaffoldable project template with files and variables.
|
|
542
|
+
*
|
|
543
|
+
* @remarks
|
|
544
|
+
* A template definition is loaded from a `template.yaml` manifest file.
|
|
545
|
+
* The `files` map contains relative paths to their file contents.
|
|
546
|
+
* Variables declared in `variables` can be substituted with `{{var}}`
|
|
547
|
+
* placeholders in both file paths and file contents during scaffolding.
|
|
548
|
+
*/
|
|
549
|
+
interface TemplateDefinition {
|
|
550
|
+
id: string;
|
|
551
|
+
name: string;
|
|
552
|
+
description: string;
|
|
553
|
+
files: Record<string, string>;
|
|
554
|
+
variables: TemplateVariable[];
|
|
555
|
+
tags?: string[];
|
|
556
|
+
metadata?: Record<string, unknown>;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Backend for listing, retrieving, and scaffolding project templates.
|
|
560
|
+
*
|
|
561
|
+
* @remarks
|
|
562
|
+
* Implementations include {@link FileSystemTemplateProvider} (local directory)
|
|
563
|
+
* and {@link GitTemplateProvider} (clones from git repos on demand).
|
|
564
|
+
*/
|
|
565
|
+
interface TemplateProvider {
|
|
566
|
+
list(): Promise<TemplateDefinition[]>;
|
|
567
|
+
get(id: string): Promise<TemplateDefinition | undefined>;
|
|
568
|
+
scaffold(id: string, variables: Record<string, string>): Promise<Record<string, string>>;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Configuration for initializing a headless agent runtime instance.
|
|
573
|
+
*
|
|
574
|
+
* @remarks
|
|
575
|
+
* Pass to {@link createHeadlessAgent} to create an agent. Set `sandbox`
|
|
576
|
+
* to `'local'` when the agent operates directly on the host filesystem.
|
|
577
|
+
* The `idlePolicy` controls behavior when the task queue is empty:
|
|
578
|
+
* `'wait'` keeps the agent alive, `'shutdown'` exits automatically.
|
|
579
|
+
*/
|
|
580
|
+
interface HeadlessAgentConfig {
|
|
581
|
+
provider: AIProvider;
|
|
582
|
+
tools: Tool[];
|
|
583
|
+
prompts: PromptStore | {
|
|
584
|
+
system?: string;
|
|
585
|
+
inline?: string[];
|
|
586
|
+
};
|
|
587
|
+
sandbox: SandboxProvider | 'local';
|
|
588
|
+
sessionStore?: SessionStore;
|
|
589
|
+
initialTask?: string;
|
|
590
|
+
maxConcurrentTasks?: number;
|
|
591
|
+
idlePolicy?: 'wait' | 'shutdown';
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Discriminated union of inbound command messages the agent accepts.
|
|
595
|
+
*
|
|
596
|
+
* @remarks
|
|
597
|
+
* Commands are received via an {@link AgentTransport}. Use `type` to
|
|
598
|
+
* discriminate between variants: `task` submits work, `interrupt` cancels
|
|
599
|
+
* in-progress work, `shutdown` finishes current work then exits, `abort`
|
|
600
|
+
* exits immediately, `context_inject` adds runtime context,
|
|
601
|
+
* `context_clear` resets conversation history, and
|
|
602
|
+
* `status_query` requests a status report.
|
|
603
|
+
*/
|
|
604
|
+
type AgentCommand = {
|
|
605
|
+
type: 'task';
|
|
606
|
+
prompt: string;
|
|
607
|
+
context?: Record<string, unknown>;
|
|
608
|
+
} | {
|
|
609
|
+
type: 'interrupt';
|
|
610
|
+
} | {
|
|
611
|
+
type: 'shutdown';
|
|
612
|
+
} | {
|
|
613
|
+
type: 'abort';
|
|
614
|
+
} | {
|
|
615
|
+
type: 'context_inject';
|
|
616
|
+
key: string;
|
|
617
|
+
value: unknown;
|
|
618
|
+
} | {
|
|
619
|
+
type: 'context_clear';
|
|
620
|
+
} | {
|
|
621
|
+
type: 'status_query';
|
|
622
|
+
};
|
|
623
|
+
/** Outbound status report describing the agent's current state and progress. */
|
|
624
|
+
interface AgentStatus {
|
|
625
|
+
state: 'idle' | 'working' | 'shutting_down' | 'error';
|
|
626
|
+
currentTask?: string;
|
|
627
|
+
queueDepth: number;
|
|
628
|
+
uptime: number;
|
|
629
|
+
tasksCompleted: number;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Pluggable I/O transport for sending commands to and receiving events from the agent.
|
|
633
|
+
*
|
|
634
|
+
* @remarks
|
|
635
|
+
* Implementations include {@link StdioTransport} (JSON lines over stdin/stdout),
|
|
636
|
+
* {@link MessagePortTransport} (postMessage for Web Workers), and
|
|
637
|
+
* {@link HttpTransport} (HTTP server with SSE streaming).
|
|
638
|
+
*/
|
|
639
|
+
interface AgentTransport {
|
|
640
|
+
onCommand(handler: (cmd: AgentCommand) => void): void;
|
|
641
|
+
emit(event: SessionEvent | AgentStatus): void;
|
|
642
|
+
close(): Promise<void>;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export type { AIProvider, AgentCommand, AgentCompleteEvent, AgentStartEvent, AgentStatus, AgentTransport, CommandExecutionOptions, CommandResult, ContentBlock, ContentBlockDeltaEvent, ContentBlockStartEvent, ContentBlockStopEvent, CreateMessageParams, ErrorEvent, FileBlock, FileEntry, GenerationRequest, GenerationSession, HeadlessAgentConfig, ImageBlock, ImageBlockBase64, ImageBlockUrl, Message, MessageDeltaEvent, MessageStartEvent, MessageStopEvent, PromptAssembler, PromptAssemblerContext, PromptRecord, PromptStore, SandboxContext, SandboxProvider, SessionEvent, SessionStore, StatusUpdateEvent, StreamErrorEvent, StreamEvent, TemplateDefinition, TemplateProvider, TemplateVariable, TextBlock, TextDeltaEvent, ThoughtDeltaEvent, Tool, ToolCallEvent, ToolCallLogEntry, ToolDefinition, ToolInputDeltaEvent, ToolProgressEvent, ToolProgressInfo, ToolRegistry, ToolResult, ToolResultBlock, ToolResultEvent, ToolUseBlock };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yolo-labs/core-types",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"tsup": "^8.0.0",
|
|
18
|
+
"typescript": "^5.5.0"
|
|
19
|
+
},
|
|
20
|
+
"description": "Shared TypeScript interfaces and type definitions for yolo-core",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/yolo-labs-hq/monorepo.git",
|
|
25
|
+
"directory": "yolo-core/packages/types"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/yolo-labs-hq/monorepo/tree/main/yolo-core#readme",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/yolo-labs-hq/monorepo/issues"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
38
|
+
}
|
|
39
|
+
}
|