@vibe-agent-toolkit/agent-runtime 0.1.2-rc.3
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/README.md +295 -0
- package/dist/adapter-types.d.ts +48 -0
- package/dist/adapter-types.d.ts.map +1 -0
- package/dist/adapter-types.js +24 -0
- package/dist/adapter-types.js.map +1 -0
- package/dist/agent-helpers.d.ts +128 -0
- package/dist/agent-helpers.d.ts.map +1 -0
- package/dist/agent-helpers.js +291 -0
- package/dist/agent-helpers.js.map +1 -0
- package/dist/agentic-researcher.d.ts +63 -0
- package/dist/agentic-researcher.d.ts.map +1 -0
- package/dist/agentic-researcher.js +60 -0
- package/dist/agentic-researcher.js.map +1 -0
- package/dist/conversational-assistant.d.ts +57 -0
- package/dist/conversational-assistant.d.ts.map +1 -0
- package/dist/conversational-assistant.js +48 -0
- package/dist/conversational-assistant.js.map +1 -0
- package/dist/conversational-helpers.d.ts +26 -0
- package/dist/conversational-helpers.d.ts.map +1 -0
- package/dist/conversational-helpers.js +34 -0
- package/dist/conversational-helpers.js.map +1 -0
- package/dist/execute-wrapper.d.ts +59 -0
- package/dist/execute-wrapper.d.ts.map +1 -0
- package/dist/execute-wrapper.js +98 -0
- package/dist/execute-wrapper.js.map +1 -0
- package/dist/external-event-integrator.d.ts +66 -0
- package/dist/external-event-integrator.d.ts.map +1 -0
- package/dist/external-event-integrator.js +62 -0
- package/dist/external-event-integrator.js.map +1 -0
- package/dist/function-event-consumer.d.ts +60 -0
- package/dist/function-event-consumer.d.ts.map +1 -0
- package/dist/function-event-consumer.js +52 -0
- package/dist/function-event-consumer.js.map +1 -0
- package/dist/function-orchestrator.d.ts +45 -0
- package/dist/function-orchestrator.d.ts.map +1 -0
- package/dist/function-orchestrator.js +51 -0
- package/dist/function-orchestrator.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-analyzer.d.ts +58 -0
- package/dist/llm-analyzer.d.ts.map +1 -0
- package/dist/llm-analyzer.js +53 -0
- package/dist/llm-analyzer.js.map +1 -0
- package/dist/llm-coordinator.d.ts +62 -0
- package/dist/llm-coordinator.d.ts.map +1 -0
- package/dist/llm-coordinator.js +60 -0
- package/dist/llm-coordinator.js.map +1 -0
- package/dist/llm-event-handler.d.ts +67 -0
- package/dist/llm-event-handler.d.ts.map +1 -0
- package/dist/llm-event-handler.js +65 -0
- package/dist/llm-event-handler.js.map +1 -0
- package/dist/pure-function.d.ts +34 -0
- package/dist/pure-function.d.ts.map +1 -0
- package/dist/pure-function.js +40 -0
- package/dist/pure-function.js.map +1 -0
- package/dist/result-helpers.d.ts +80 -0
- package/dist/result-helpers.d.ts.map +1 -0
- package/dist/result-helpers.js +232 -0
- package/dist/result-helpers.js.map +1 -0
- package/dist/session/errors.d.ts +11 -0
- package/dist/session/errors.d.ts.map +1 -0
- package/dist/session/errors.js +15 -0
- package/dist/session/errors.js.map +1 -0
- package/dist/session/file-session-store.d.ts +46 -0
- package/dist/session/file-session-store.d.ts.map +1 -0
- package/dist/session/file-session-store.js +149 -0
- package/dist/session/file-session-store.js.map +1 -0
- package/dist/session/index.d.ts +12 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +13 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/memory-session-store.d.ts +35 -0
- package/dist/session/memory-session-store.d.ts.map +1 -0
- package/dist/session/memory-session-store.js +76 -0
- package/dist/session/memory-session-store.js.map +1 -0
- package/dist/session/session-store-helpers.d.ts +26 -0
- package/dist/session/session-store-helpers.d.ts.map +1 -0
- package/dist/session/session-store-helpers.js +54 -0
- package/dist/session/session-store-helpers.js.map +1 -0
- package/dist/session/test-helpers/index.d.ts +61 -0
- package/dist/session/test-helpers/index.d.ts.map +1 -0
- package/dist/session/test-helpers/index.js +167 -0
- package/dist/session/test-helpers/index.js.map +1 -0
- package/dist/session/types.d.ts +86 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +8 -0
- package/dist/session/types.js.map +1 -0
- package/dist/shared-validation.d.ts +21 -0
- package/dist/shared-validation.d.ts.map +1 -0
- package/dist/shared-validation.js +45 -0
- package/dist/shared-validation.js.map +1 -0
- package/dist/test-helpers.d.ts +50 -0
- package/dist/test-helpers.d.ts.map +1 -0
- package/dist/test-helpers.js +47 -0
- package/dist/test-helpers.js.map +1 -0
- package/dist/two-phase-conversational.d.ts +173 -0
- package/dist/two-phase-conversational.d.ts.map +1 -0
- package/dist/two-phase-conversational.js +205 -0
- package/dist/two-phase-conversational.js.map +1 -0
- package/dist/types.d.ts +194 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# @vibe-agent-toolkit/agent-runtime
|
|
2
|
+
|
|
3
|
+
Runtime framework for building portable AI agents across multiple agent archetypes.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Agent Archetypes**: Pre-defined patterns for common agent types
|
|
8
|
+
- **Type-Safe**: Full TypeScript support with Zod schema validation
|
|
9
|
+
- **Framework Agnostic**: Agents work with any LLM provider
|
|
10
|
+
- **Declarative Configuration**: Minimal boilerplate, maximum clarity
|
|
11
|
+
|
|
12
|
+
## Agent Archetypes
|
|
13
|
+
|
|
14
|
+
### 1. Pure Function Tool
|
|
15
|
+
Stateless, deterministic functions with no external dependencies.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { definePureFunction } from '@vibe-agent-toolkit/agent-runtime';
|
|
19
|
+
import { z } from 'zod';
|
|
20
|
+
|
|
21
|
+
export const haiku Validator = definePureFunction({
|
|
22
|
+
name: 'haiku-validator',
|
|
23
|
+
description: 'Validates haiku structure (5-7-5 syllables)',
|
|
24
|
+
version: '1.0.0',
|
|
25
|
+
inputSchema: z.object({ line1: z.string(), line2: z.string(), line3: z.string() }),
|
|
26
|
+
outputSchema: z.object({ valid: z.boolean(), errors: z.array(z.string()) }),
|
|
27
|
+
}, (input) => {
|
|
28
|
+
// Implementation
|
|
29
|
+
return { valid: true, errors: [] };
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. LLM Analyzer
|
|
34
|
+
Single LLM call for classification or extraction tasks.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { defineLLMAnalyzer } from '@vibe-agent-toolkit/agent-runtime';
|
|
38
|
+
|
|
39
|
+
export const photoAnalyzer = defineLLMAnalyzer({
|
|
40
|
+
name: 'photo-analyzer',
|
|
41
|
+
description: 'Analyzes cat photos using vision LLM',
|
|
42
|
+
version: '1.0.0',
|
|
43
|
+
inputSchema: PhotoInputSchema,
|
|
44
|
+
outputSchema: CatCharacteristicsSchema,
|
|
45
|
+
systemPrompt: 'You are an expert cat analyzer...',
|
|
46
|
+
}, async (input, ctx) => {
|
|
47
|
+
const analysis = await ctx.callLLM(`Analyze this cat: ${input.imagePath}`);
|
|
48
|
+
return JSON.parse(analysis);
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. Conversational Assistant
|
|
53
|
+
Multi-turn dialogue with conversation history.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { defineConversationalAssistant } from '@vibe-agent-toolkit/agent-runtime';
|
|
57
|
+
|
|
58
|
+
export const chatAgent = defineConversationalAssistant({
|
|
59
|
+
name: 'breed-advisor',
|
|
60
|
+
description: 'Helps users find their perfect cat breed',
|
|
61
|
+
version: '1.0.0',
|
|
62
|
+
inputSchema: InputSchema,
|
|
63
|
+
outputSchema: OutputSchema,
|
|
64
|
+
systemPrompt: 'You are a friendly cat breed advisor...',
|
|
65
|
+
}, async (input, ctx) => {
|
|
66
|
+
ctx.addToHistory('user', input.message);
|
|
67
|
+
const response = await ctx.callLLM(ctx.history);
|
|
68
|
+
ctx.addToHistory('assistant', response);
|
|
69
|
+
return { reply: response };
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 3a. Two-Phase Conversational Assistant ⭐ NEW
|
|
74
|
+
|
|
75
|
+
**Recommended pattern for conversational agents that gather information.**
|
|
76
|
+
|
|
77
|
+
The two-phase pattern solves the "JSON every turn" anti-pattern by separating:
|
|
78
|
+
- **Phase 1 (Gathering)**: Natural conversational text responses
|
|
79
|
+
- **Phase 2 (Extraction)**: Structured data extraction when ready
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { defineTwoPhaseConversationalAssistant } from '@vibe-agent-toolkit/agent-runtime';
|
|
83
|
+
|
|
84
|
+
export const breedAdvisor = defineTwoPhaseConversationalAssistant({
|
|
85
|
+
name: 'breed-advisor',
|
|
86
|
+
description: 'Helps users find their perfect cat breed',
|
|
87
|
+
version: '2.0.0',
|
|
88
|
+
inputSchema: BreedAdvisorInputSchema,
|
|
89
|
+
outputSchema: BreedAdvisorOutputSchema,
|
|
90
|
+
|
|
91
|
+
gatheringPhase: {
|
|
92
|
+
tone: 'enthusiastic',
|
|
93
|
+
factors: [
|
|
94
|
+
{
|
|
95
|
+
name: 'musicPreference',
|
|
96
|
+
type: 'enum',
|
|
97
|
+
values: ['classical', 'jazz', 'rock', 'pop'],
|
|
98
|
+
required: true,
|
|
99
|
+
clarificationHint: 'Ask which category fits best for non-standard genres',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'livingSpace',
|
|
103
|
+
type: 'enum',
|
|
104
|
+
values: ['apartment', 'house', 'farm'],
|
|
105
|
+
naturalLanguageMappings: {
|
|
106
|
+
'flat': 'apartment',
|
|
107
|
+
'big house': 'house',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
readinessCheck: (profile) => Object.keys(profile).length >= 4,
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
extractionPhase: {
|
|
115
|
+
generateRecommendations: (profile) => matchBreeds(profile),
|
|
116
|
+
useStructuredOutputs: false, // Set true for OpenAI gpt-4o-2024-08-06+
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Key Benefits:**
|
|
122
|
+
- **Declarative Configuration**: 200+ lines of manual prompts → 50 lines of config
|
|
123
|
+
- **Automatic Validation**: Enum guidance generated from factor definitions
|
|
124
|
+
- **Natural Language Mappings**: Common phrases → formal values
|
|
125
|
+
- **Priority Factors**: Guide conversation flow
|
|
126
|
+
|
|
127
|
+
See [docs/structured-outputs.md](../../docs/structured-outputs.md) for detailed pattern comparison and best practices.
|
|
128
|
+
|
|
129
|
+
### 4. Agentic Researcher
|
|
130
|
+
ReAct pattern with tool calling and iterative reasoning.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { defineAgenticResearcher } from '@vibe-agent-toolkit/agent-runtime';
|
|
134
|
+
|
|
135
|
+
export const researcher = defineAgenticResearcher({
|
|
136
|
+
name: 'breed-historian',
|
|
137
|
+
description: 'Researches cat breed history with web search',
|
|
138
|
+
version: '1.0.0',
|
|
139
|
+
inputSchema: ResearchInputSchema,
|
|
140
|
+
outputSchema: ResearchOutputSchema,
|
|
141
|
+
tools: {
|
|
142
|
+
webSearch: async (query: string) => { /* ... */ },
|
|
143
|
+
},
|
|
144
|
+
}, async (input, ctx) => {
|
|
145
|
+
// ReAct loop: Thought → Action → Observation
|
|
146
|
+
for (let i = 0; i < ctx.maxIterations; i++) {
|
|
147
|
+
const thought = await ctx.callLLM(`Research: ${input.query}`);
|
|
148
|
+
const result = await ctx.callTool('webSearch', thought);
|
|
149
|
+
// Process result...
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 5. Function Workflow Orchestrator
|
|
155
|
+
Deterministic multi-agent coordination.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { defineFunctionOrchestrator } from '@vibe-agent-toolkit/agent-runtime';
|
|
159
|
+
|
|
160
|
+
export const orchestrator = defineFunctionOrchestrator({
|
|
161
|
+
name: 'adoption-pipeline',
|
|
162
|
+
description: 'Coordinates multi-step adoption process',
|
|
163
|
+
version: '1.0.0',
|
|
164
|
+
inputSchema: AdoptionInputSchema,
|
|
165
|
+
outputSchema: AdoptionOutputSchema,
|
|
166
|
+
}, async (input, ctx) => {
|
|
167
|
+
// Call multiple agents in sequence
|
|
168
|
+
const analysis = await ctx.call('photo-analyzer', { image: input.photo });
|
|
169
|
+
const validation = await ctx.call('name-validator', { name: input.name });
|
|
170
|
+
const approval = await ctx.call('human-approval', { data: { analysis, validation } });
|
|
171
|
+
|
|
172
|
+
return { approved: approval.approved };
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 6. LLM Intelligent Coordinator
|
|
177
|
+
LLM-based routing decisions in workflows.
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { defineLLMCoordinator } from '@vibe-agent-toolkit/agent-runtime';
|
|
181
|
+
|
|
182
|
+
export const coordinator = defineLLMCoordinator({
|
|
183
|
+
name: 'smart-router',
|
|
184
|
+
description: 'Routes submissions based on complexity',
|
|
185
|
+
version: '1.0.0',
|
|
186
|
+
inputSchema: SubmissionSchema,
|
|
187
|
+
outputSchema: RoutingSchema,
|
|
188
|
+
systemPrompt: 'Route submissions to the right handler...',
|
|
189
|
+
}, async (input, ctx) => {
|
|
190
|
+
const decision = await ctx.callLLM(`Route: ${input.submission}`);
|
|
191
|
+
|
|
192
|
+
return ctx.route(decision, {
|
|
193
|
+
simple: async () => ctx.call('auto-approver', input),
|
|
194
|
+
complex: async () => ctx.call('human-review', input),
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 7. Function Event Consumer
|
|
200
|
+
Event-triggered execution without LLM.
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { defineFunctionEventConsumer } from '@vibe-agent-toolkit/agent-runtime';
|
|
204
|
+
|
|
205
|
+
export const processor = defineFunctionEventConsumer({
|
|
206
|
+
name: 'pedigree-processor',
|
|
207
|
+
description: 'Processes uploaded pedigree files',
|
|
208
|
+
version: '1.0.0',
|
|
209
|
+
inputSchema: FileEventSchema,
|
|
210
|
+
outputSchema: ProcessingResultSchema,
|
|
211
|
+
}, async (input, ctx) => {
|
|
212
|
+
const file = await parseFile(input.filePath);
|
|
213
|
+
await ctx.emit('pedigree-processed', { result: file });
|
|
214
|
+
return { status: 'processed' };
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 8. LLM Event Handler
|
|
219
|
+
Event-triggered with LLM processing.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { defineLLMEventHandler } from '@vibe-agent-toolkit/agent-runtime';
|
|
223
|
+
|
|
224
|
+
export const handler = defineLLMEventHandler({
|
|
225
|
+
name: 'triage-handler',
|
|
226
|
+
description: 'Triages incoming submissions with LLM',
|
|
227
|
+
version: '1.0.0',
|
|
228
|
+
inputSchema: SubmissionEventSchema,
|
|
229
|
+
outputSchema: TriageResultSchema,
|
|
230
|
+
systemPrompt: 'Triage submissions by urgency...',
|
|
231
|
+
}, async (input, ctx) => {
|
|
232
|
+
const priority = await ctx.callLLM(`Triage: ${input.submission}`);
|
|
233
|
+
await ctx.emit('submission-triaged', { priority });
|
|
234
|
+
return { priority };
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 9. External Event Integrator
|
|
239
|
+
Human-in-the-loop approval gates.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import { defineExternalEventIntegrator } from '@vibe-agent-toolkit/agent-runtime';
|
|
243
|
+
|
|
244
|
+
export const approvalGate = defineExternalEventIntegrator({
|
|
245
|
+
name: 'human-approval',
|
|
246
|
+
description: 'Waits for human approval',
|
|
247
|
+
version: '1.0.0',
|
|
248
|
+
inputSchema: ApprovalRequestSchema,
|
|
249
|
+
outputSchema: ApprovalResultSchema,
|
|
250
|
+
timeoutMs: 60000,
|
|
251
|
+
onTimeout: 'reject',
|
|
252
|
+
}, async (input, ctx) => {
|
|
253
|
+
await ctx.emit('approval-requested', input);
|
|
254
|
+
const result = await ctx.waitFor('approval-response', ctx.timeoutMs);
|
|
255
|
+
return result;
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Agent Manifest
|
|
260
|
+
|
|
261
|
+
Every agent exposes a manifest describing its interface:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
const agent = defineAgentType(config, handler);
|
|
265
|
+
|
|
266
|
+
console.log(agent.manifest);
|
|
267
|
+
// {
|
|
268
|
+
// name: 'agent-name',
|
|
269
|
+
// description: 'What this agent does',
|
|
270
|
+
// version: '1.0.0',
|
|
271
|
+
// archetype: 'archetype-name',
|
|
272
|
+
// inputSchema: { /* JSON Schema */ },
|
|
273
|
+
// outputSchema: { /* JSON Schema */ },
|
|
274
|
+
// metadata: { /* Additional info */ }
|
|
275
|
+
// }
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Runtime Adapters
|
|
279
|
+
|
|
280
|
+
Agents are framework-agnostic. Use runtime adapters to integrate with specific LLM frameworks:
|
|
281
|
+
|
|
282
|
+
- `@vibe-agent-toolkit/runtime-openai` - OpenAI SDK
|
|
283
|
+
- `@vibe-agent-toolkit/runtime-vercel-ai-sdk` - Vercel AI SDK
|
|
284
|
+
- `@vibe-agent-toolkit/runtime-langchain` - LangChain
|
|
285
|
+
- `@vibe-agent-toolkit/runtime-claude-agent-sdk` - Claude Agent SDK
|
|
286
|
+
|
|
287
|
+
See individual runtime packages for usage examples.
|
|
288
|
+
|
|
289
|
+
## Examples
|
|
290
|
+
|
|
291
|
+
See `@vibe-agent-toolkit/vat-example-cat-agents` for complete examples across all archetypes.
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { Agent, PureFunctionAgent } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for converting a pure function agent to a runtime-specific tool
|
|
5
|
+
*/
|
|
6
|
+
export interface ToolConversionConfig<TInput = unknown, TOutput = unknown> {
|
|
7
|
+
agent: PureFunctionAgent<TInput, TOutput>;
|
|
8
|
+
inputSchema: z.ZodType<TInput>;
|
|
9
|
+
outputSchema: z.ZodType<TOutput>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for converting an LLM analyzer agent to a runtime-specific function
|
|
13
|
+
*/
|
|
14
|
+
export interface LLMAnalyzerConversionConfig<TInput = unknown, TOutput = unknown> {
|
|
15
|
+
agent: Agent<TInput, TOutput>;
|
|
16
|
+
inputSchema: z.ZodType<TInput>;
|
|
17
|
+
outputSchema: z.ZodType<TOutput>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Batch conversion configuration for pure function tools
|
|
21
|
+
*/
|
|
22
|
+
export type ToolConversionConfigs = Record<string, ToolConversionConfig>;
|
|
23
|
+
/**
|
|
24
|
+
* Batch conversion configuration for LLM analyzer functions
|
|
25
|
+
*/
|
|
26
|
+
export type LLMAnalyzerConversionConfigs = Record<string, LLMAnalyzerConversionConfig>;
|
|
27
|
+
/**
|
|
28
|
+
* Generic batch conversion utility for converting multiple configs to results
|
|
29
|
+
* Eliminates code duplication in runtime adapters
|
|
30
|
+
*
|
|
31
|
+
* @param configs - Map of keys to conversion configurations
|
|
32
|
+
* @param converter - Function that converts a single config to a result
|
|
33
|
+
* @returns Map of keys to conversion results
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const tools = batchConvert(configs, (config) => {
|
|
38
|
+
* const { tool, metadata } = convertPureFunctionToTool(
|
|
39
|
+
* config.agent,
|
|
40
|
+
* config.inputSchema,
|
|
41
|
+
* config.outputSchema,
|
|
42
|
+
* );
|
|
43
|
+
* return { tool, metadata };
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function batchConvert<TConfig, TResult>(configs: Record<string, TConfig>, converter: (config: TConfig) => TResult): Record<string, TResult>;
|
|
48
|
+
//# sourceMappingURL=adapter-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-types.d.ts","sourceRoot":"","sources":["../src/adapter-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IACvE,KAAK,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAC9E,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAC3C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,GACtC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIzB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic batch conversion utility for converting multiple configs to results
|
|
3
|
+
* Eliminates code duplication in runtime adapters
|
|
4
|
+
*
|
|
5
|
+
* @param configs - Map of keys to conversion configurations
|
|
6
|
+
* @param converter - Function that converts a single config to a result
|
|
7
|
+
* @returns Map of keys to conversion results
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const tools = batchConvert(configs, (config) => {
|
|
12
|
+
* const { tool, metadata } = convertPureFunctionToTool(
|
|
13
|
+
* config.agent,
|
|
14
|
+
* config.inputSchema,
|
|
15
|
+
* config.outputSchema,
|
|
16
|
+
* );
|
|
17
|
+
* return { tool, metadata };
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function batchConvert(configs, converter) {
|
|
22
|
+
return Object.fromEntries(Object.entries(configs).map(([key, config]) => [key, converter(config)]));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=adapter-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-types.js","sourceRoot":"","sources":["../src/adapter-types.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAgC,EAChC,SAAuC;IAEvC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CACzE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions for creating agents.
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentResult, ExternalEventError, LLMError, OneShotAgentOutput } from '@vibe-agent-toolkit/agent-schema';
|
|
5
|
+
/**
|
|
6
|
+
* Validate agent input against a Zod schema.
|
|
7
|
+
*
|
|
8
|
+
* Returns parsed data on success, or OneShotAgentOutput error envelope on failure.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // For LLM agents
|
|
12
|
+
* const validatedOrError = validateAgentInput<MyInput, MyOutput, LLMError>(input, InputSchema, 'llm-invalid-output');
|
|
13
|
+
* if ('result' in validatedOrError) {
|
|
14
|
+
* return validatedOrError; // Validation error
|
|
15
|
+
* }
|
|
16
|
+
* const { characteristics, mockable } = validatedOrError;
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // For external event agents
|
|
20
|
+
* const validatedOrError = validateAgentInput<MyInput, MyOutput, ExternalEventError>(
|
|
21
|
+
* input,
|
|
22
|
+
* InputSchema,
|
|
23
|
+
* 'event-invalid-response'
|
|
24
|
+
* );
|
|
25
|
+
*/
|
|
26
|
+
export declare function validateAgentInput<TInput, TData, TError extends string = LLMError>(input: unknown, schema: {
|
|
27
|
+
safeParse: (data: unknown) => {
|
|
28
|
+
success: boolean;
|
|
29
|
+
data?: TInput;
|
|
30
|
+
};
|
|
31
|
+
}, invalidInputError?: TError): TInput | OneShotAgentOutput<TData, TError>;
|
|
32
|
+
/**
|
|
33
|
+
* Wrap LLM calls to catch expected failures and map to result errors.
|
|
34
|
+
*
|
|
35
|
+
* Handles common LLM failure modes:
|
|
36
|
+
* - API timeouts → 'llm-timeout'
|
|
37
|
+
* - Rate limits → 'llm-rate-limit'
|
|
38
|
+
* - Content policy → 'llm-refusal'
|
|
39
|
+
* - Invalid output → 'llm-invalid-output'
|
|
40
|
+
* - Service errors → 'llm-unavailable'
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const llmResult = await executeLLMCall(
|
|
44
|
+
* () => llm.chat.completions.create({...}),
|
|
45
|
+
* {
|
|
46
|
+
* parseOutput: (raw) => CatCharacteristicsSchema.parse(raw),
|
|
47
|
+
* timeoutMs: 30000,
|
|
48
|
+
* }
|
|
49
|
+
* );
|
|
50
|
+
*/
|
|
51
|
+
export declare function executeLLMCall<T>(fn: () => Promise<T>, options?: {
|
|
52
|
+
parseOutput?: (raw: unknown) => T;
|
|
53
|
+
timeoutMs?: number;
|
|
54
|
+
}): Promise<AgentResult<T, LLMError>>;
|
|
55
|
+
/**
|
|
56
|
+
* Execute an LLM analyzer agent with mock/real mode support.
|
|
57
|
+
*
|
|
58
|
+
* Eliminates boilerplate for LLM analyzer agents by handling:
|
|
59
|
+
* - Mock vs real mode switching
|
|
60
|
+
* - Metadata generation
|
|
61
|
+
* - Error handling with llm-unavailable fallback
|
|
62
|
+
* - Consistent return envelope structure
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // With real implementation
|
|
66
|
+
* execute: async (input) => {
|
|
67
|
+
* return executeLLMAnalyzer({
|
|
68
|
+
* mockable: input.mockable ?? true,
|
|
69
|
+
* mockFn: () => mockParseDescription(input.description),
|
|
70
|
+
* realFn: async () => callLLM(...),
|
|
71
|
+
* parseOutput: (raw) => CatCharacteristicsSchema.parse(JSON.parse(raw)),
|
|
72
|
+
* errorContext: 'Description parsing',
|
|
73
|
+
* });
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Mock-only (no real implementation)
|
|
78
|
+
* execute: async (input) => {
|
|
79
|
+
* return executeLLMAnalyzer({
|
|
80
|
+
* mockable: input.mockable ?? true,
|
|
81
|
+
* mockFn: () => mockGenerateName(input.characteristics),
|
|
82
|
+
* notImplementedMessage: 'Real LLM name generation requires runtime adapter',
|
|
83
|
+
* });
|
|
84
|
+
* }
|
|
85
|
+
*/
|
|
86
|
+
export declare function executeLLMAnalyzer<TData>(config: {
|
|
87
|
+
mockable: boolean;
|
|
88
|
+
mockFn: () => TData;
|
|
89
|
+
realFn?: () => Promise<unknown>;
|
|
90
|
+
parseOutput?: (raw: unknown) => TData;
|
|
91
|
+
errorContext?: string;
|
|
92
|
+
notImplementedMessage?: string;
|
|
93
|
+
}): Promise<OneShotAgentOutput<TData, LLMError>>;
|
|
94
|
+
/**
|
|
95
|
+
* Execute an external event integrator agent (HITL, webhook, etc).
|
|
96
|
+
*
|
|
97
|
+
* Handles common external event failure modes:
|
|
98
|
+
* - Timeouts waiting for response
|
|
99
|
+
* - System unavailable
|
|
100
|
+
* - Explicit rejection
|
|
101
|
+
* - Invalid responses
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* // With auto-response (testing)
|
|
105
|
+
* execute: async (input) => {
|
|
106
|
+
* return executeExternalEvent({
|
|
107
|
+
* autoResponse: input.autoResponse,
|
|
108
|
+
* handler: async () => requestApproval(input.prompt, input.context),
|
|
109
|
+
* timeoutMs: 60000,
|
|
110
|
+
* });
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // Production mode (waits for real human/external system)
|
|
115
|
+
* execute: async (input) => {
|
|
116
|
+
* return executeExternalEvent({
|
|
117
|
+
* handler: async () => requestApproval(input.prompt, input.context),
|
|
118
|
+
* timeoutMs: input.timeoutMs ?? 60000,
|
|
119
|
+
* });
|
|
120
|
+
* }
|
|
121
|
+
*/
|
|
122
|
+
export declare function executeExternalEvent<TData>(config: {
|
|
123
|
+
autoResponse?: TData;
|
|
124
|
+
handler: () => Promise<TData>;
|
|
125
|
+
timeoutMs?: number;
|
|
126
|
+
errorContext?: string;
|
|
127
|
+
}): Promise<OneShotAgentOutput<TData, ExternalEventError>>;
|
|
128
|
+
//# sourceMappingURL=agent-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-helpers.d.ts","sourceRoot":"","sources":["../src/agent-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,kBAAkB,EACnB,MAAM,kCAAkC,CAAC;AAQ1C;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,MAAM,GAAG,QAAQ,EAChF,KAAK,EAAE,OAAO,EACd,MAAM,EAAE;IAAE,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EAC7E,iBAAiB,GAAE,MAAuC,GACzD,MAAM,GAAG,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAQ5C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE;IACR,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GACA,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CA4BnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE;IACtD,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,KAAK,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,KAAK,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,GAAG,OAAO,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAoD/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE;IACxD,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,OAAO,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAoCzD"}
|