@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
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two-Phase Conversational Assistant Pattern
|
|
3
|
+
*
|
|
4
|
+
* Provides a declarative API for building conversational agents that gather
|
|
5
|
+
* information naturally through dialogue (Phase 1), then extract structured
|
|
6
|
+
* data when ready (Phase 2).
|
|
7
|
+
*
|
|
8
|
+
* This pattern solves the "JSON every turn" anti-pattern where LLMs are asked
|
|
9
|
+
* to return JSON on every conversational turn, fighting their natural
|
|
10
|
+
* conversational behavior.
|
|
11
|
+
*/
|
|
12
|
+
import { type z } from 'zod';
|
|
13
|
+
import type { Agent, ConversationalContext } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Defines a single piece of information to gather
|
|
16
|
+
*/
|
|
17
|
+
export interface FactorDefinition {
|
|
18
|
+
/** Unique name for this factor (e.g., "musicPreference") */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Human-readable description of what this factor represents */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Data type of this factor */
|
|
23
|
+
type: 'string' | 'enum' | 'boolean' | 'number';
|
|
24
|
+
/** Valid enum values (required if type is 'enum') */
|
|
25
|
+
values?: string[];
|
|
26
|
+
/** Whether this factor is required to proceed to extraction phase */
|
|
27
|
+
required?: boolean;
|
|
28
|
+
/** Weight/importance multiplier (default: 1) */
|
|
29
|
+
weight?: number;
|
|
30
|
+
/** Guidance for handling user input that doesn't map to valid values */
|
|
31
|
+
clarificationHint?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Natural language mappings from common user phrases to formal values
|
|
34
|
+
* Example: { "big house": "large-house", "flat": "apartment" }
|
|
35
|
+
*/
|
|
36
|
+
naturalLanguageMappings?: Record<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
* Examples of valid values to help the LLM understand
|
|
39
|
+
* Example: ["classical", "jazz", "rock"]
|
|
40
|
+
*/
|
|
41
|
+
examples?: string[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for Phase 1: Gathering
|
|
45
|
+
*/
|
|
46
|
+
export interface GatheringPhaseConfig {
|
|
47
|
+
/** Conversational tone (e.g., "friendly", "professional", "enthusiastic") */
|
|
48
|
+
tone?: string;
|
|
49
|
+
/** Factors to gather during conversation */
|
|
50
|
+
factors: FactorDefinition[];
|
|
51
|
+
/**
|
|
52
|
+
* Function to determine if enough information has been gathered
|
|
53
|
+
* Default: all required factors are present
|
|
54
|
+
*/
|
|
55
|
+
readinessCheck?: (profile: Record<string, unknown>) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Custom guidance to include in the gathering phase prompt
|
|
58
|
+
* Use this to add domain-specific context or instructions
|
|
59
|
+
*/
|
|
60
|
+
customGuidance?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Whether to prioritize certain factors in conversation flow
|
|
63
|
+
* If provided, LLM will ask about these factors early
|
|
64
|
+
*/
|
|
65
|
+
priorityFactors?: string[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Configuration for Phase 2: Extraction
|
|
69
|
+
*/
|
|
70
|
+
export interface ExtractionPhaseConfig {
|
|
71
|
+
/**
|
|
72
|
+
* Optional function to generate recommendations/results from gathered profile
|
|
73
|
+
* This is called after structured extraction to enhance the output
|
|
74
|
+
*/
|
|
75
|
+
generateRecommendations?: (profile: Record<string, unknown>) => unknown;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to use Structured Outputs API (OpenAI gpt-4o-2024-08-06+)
|
|
78
|
+
* for 100% schema adherence. Default: false
|
|
79
|
+
*/
|
|
80
|
+
useStructuredOutputs?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Custom prompt for extraction phase
|
|
83
|
+
* If not provided, a default extraction prompt is generated
|
|
84
|
+
*/
|
|
85
|
+
customExtractionPrompt?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Complete configuration for two-phase conversational assistant
|
|
89
|
+
*/
|
|
90
|
+
export interface TwoPhaseConversationalConfig<TInput, TOutput> {
|
|
91
|
+
/** Unique name for the agent */
|
|
92
|
+
name: string;
|
|
93
|
+
/** Human-readable description of what the agent does */
|
|
94
|
+
description: string;
|
|
95
|
+
/** Semantic version (e.g., "1.0.0") */
|
|
96
|
+
version: string;
|
|
97
|
+
/** Zod schema for input validation */
|
|
98
|
+
inputSchema: z.ZodType<TInput>;
|
|
99
|
+
/** Zod schema for output validation (used in extraction phase) */
|
|
100
|
+
outputSchema: z.ZodType<TOutput>;
|
|
101
|
+
/** Gathering phase configuration */
|
|
102
|
+
gatheringPhase: GatheringPhaseConfig;
|
|
103
|
+
/** Extraction phase configuration */
|
|
104
|
+
extractionPhase: ExtractionPhaseConfig;
|
|
105
|
+
/** Whether this agent can be mocked in tests (default: true) */
|
|
106
|
+
mockable?: boolean;
|
|
107
|
+
/** Additional metadata */
|
|
108
|
+
metadata?: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Generates the system prompt for Phase 1: Gathering
|
|
112
|
+
*/
|
|
113
|
+
export declare function generateGatheringPrompt(config: GatheringPhaseConfig): string;
|
|
114
|
+
/**
|
|
115
|
+
* Generates the system prompt for Phase 2: Extraction
|
|
116
|
+
*/
|
|
117
|
+
export declare function generateExtractionPrompt(config: ExtractionPhaseConfig, gatheredProfile: Record<string, unknown>): string;
|
|
118
|
+
/**
|
|
119
|
+
* Defines a two-phase conversational assistant agent.
|
|
120
|
+
*
|
|
121
|
+
* Phase 1 (Gathering): Natural conversation to collect information
|
|
122
|
+
* - No JSON output required
|
|
123
|
+
* - Conversational text responses
|
|
124
|
+
* - Accumulates factors informally
|
|
125
|
+
*
|
|
126
|
+
* Phase 2 (Extraction): Structured data extraction
|
|
127
|
+
* - JSON output with schema validation
|
|
128
|
+
* - Triggered when readiness check passes
|
|
129
|
+
* - Uses Structured Outputs API if configured
|
|
130
|
+
*
|
|
131
|
+
* @param config - Two-phase configuration
|
|
132
|
+
* @param handler - Optional custom handler (if you want full control)
|
|
133
|
+
* @returns Agent with validated execute function and manifest
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const breedAdvisor = defineTwoPhaseConversationalAssistant({
|
|
138
|
+
* name: 'breed-advisor',
|
|
139
|
+
* description: 'Helps users find their perfect cat breed',
|
|
140
|
+
* version: '1.0.0',
|
|
141
|
+
* inputSchema: BreedAdvisorInputSchema,
|
|
142
|
+
* gatheringPhase: {
|
|
143
|
+
* tone: 'enthusiastic',
|
|
144
|
+
* factors: [
|
|
145
|
+
* {
|
|
146
|
+
* name: 'musicPreference',
|
|
147
|
+
* description: 'User\'s music taste',
|
|
148
|
+
* type: 'enum',
|
|
149
|
+
* values: ['classical', 'jazz', 'rock', 'pop'],
|
|
150
|
+
* required: true,
|
|
151
|
+
* weight: 2,
|
|
152
|
+
* },
|
|
153
|
+
* {
|
|
154
|
+
* name: 'livingSpace',
|
|
155
|
+
* type: 'enum',
|
|
156
|
+
* values: ['apartment', 'house', 'farm'],
|
|
157
|
+
* naturalLanguageMappings: {
|
|
158
|
+
* 'flat': 'apartment',
|
|
159
|
+
* 'big house': 'house',
|
|
160
|
+
* },
|
|
161
|
+
* },
|
|
162
|
+
* ],
|
|
163
|
+
* readinessCheck: (profile) => Object.keys(profile).length >= 4,
|
|
164
|
+
* },
|
|
165
|
+
* extractionPhase: {
|
|
166
|
+
* outputSchema: BreedRecommendationSchema,
|
|
167
|
+
* generateRecommendations: matchBreeds,
|
|
168
|
+
* },
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function defineTwoPhaseConversationalAssistant<TInput, TOutput>(config: TwoPhaseConversationalConfig<TInput, TOutput>, handler?: (input: TInput, ctx: ConversationalContext) => Promise<TOutput>): Agent<TInput, TOutput>;
|
|
173
|
+
//# sourceMappingURL=two-phase-conversational.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"two-phase-conversational.d.ts","sourceRoot":"","sources":["../src/two-phase-conversational.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAO7B,OAAO,KAAK,EAAE,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IAEb,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,+BAA+B;IAC/B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IAE/C,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,wEAAwE;IACxE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjD;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAE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AAuB,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CA6E5E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,qBAAqB,EAC7B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvC,MAAM,CAaR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,qCAAqC,CAAC,MAAM,EAAE,OAAO,EACnE,MAAM,EAAE,4BAA4B,CAAC,MAAM,EAAE,OAAO,CAAC,EACrD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,qBAAqB,KAAK,OAAO,CAAC,OAAO,CAAC,GACxE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAuExB"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two-Phase Conversational Assistant Pattern
|
|
3
|
+
*
|
|
4
|
+
* Provides a declarative API for building conversational agents that gather
|
|
5
|
+
* information naturally through dialogue (Phase 1), then extract structured
|
|
6
|
+
* data when ready (Phase 2).
|
|
7
|
+
*
|
|
8
|
+
* This pattern solves the "JSON every turn" anti-pattern where LLMs are asked
|
|
9
|
+
* to return JSON on every conversational turn, fighting their natural
|
|
10
|
+
* conversational behavior.
|
|
11
|
+
*/
|
|
12
|
+
import { buildManifest, createAsyncExecuteWrapperWithContext, createConversationalContextMapper, } from './execute-wrapper.js';
|
|
13
|
+
/**
|
|
14
|
+
* Generates the system prompt for Phase 1: Gathering
|
|
15
|
+
*/
|
|
16
|
+
export function generateGatheringPrompt(config) {
|
|
17
|
+
const { tone, factors, customGuidance, priorityFactors } = config;
|
|
18
|
+
const toneValue = tone ?? 'friendly';
|
|
19
|
+
// Build factor descriptions
|
|
20
|
+
const factorDescriptions = factors
|
|
21
|
+
.map((factor) => {
|
|
22
|
+
const factorDesc = factor.description ?? factor.name;
|
|
23
|
+
let desc = `- **${factor.name}**: ${factorDesc}`;
|
|
24
|
+
if (factor.type === 'enum' && factor.values) {
|
|
25
|
+
const quotedValues = factor.values.map((v) => `"${v}"`).join(', ');
|
|
26
|
+
desc += `\n Valid values: ${quotedValues}`;
|
|
27
|
+
}
|
|
28
|
+
if (factor.clarificationHint) {
|
|
29
|
+
desc += `\n ${factor.clarificationHint}`;
|
|
30
|
+
}
|
|
31
|
+
if (factor.naturalLanguageMappings) {
|
|
32
|
+
const mappings = Object.entries(factor.naturalLanguageMappings)
|
|
33
|
+
.map(([phrase, value]) => {
|
|
34
|
+
const mapping = `"${phrase}" → "${value}"`;
|
|
35
|
+
return mapping;
|
|
36
|
+
})
|
|
37
|
+
.join(', ');
|
|
38
|
+
desc += `\n Natural language mappings: ${mappings}`;
|
|
39
|
+
}
|
|
40
|
+
if (factor.required) {
|
|
41
|
+
desc += '\n (REQUIRED)';
|
|
42
|
+
}
|
|
43
|
+
return desc;
|
|
44
|
+
})
|
|
45
|
+
.join('\n\n');
|
|
46
|
+
// Build priority guidance
|
|
47
|
+
const priorityGuidance = priorityFactors
|
|
48
|
+
? `\nPrioritize asking about these factors early: ${priorityFactors.join(', ')}`
|
|
49
|
+
: '';
|
|
50
|
+
// Build enum validation rules
|
|
51
|
+
const enumFactors = factors.filter((f) => f.type === 'enum');
|
|
52
|
+
let enumGuidance = '';
|
|
53
|
+
if (enumFactors.length > 0) {
|
|
54
|
+
const enumRules = enumFactors
|
|
55
|
+
.map((f) => {
|
|
56
|
+
const quotedValues = f.values?.map((v) => `"${v}"`).join(', ') ?? '';
|
|
57
|
+
const fieldName = f.name;
|
|
58
|
+
return `- **${fieldName}**: ONLY use these exact values: ${quotedValues}
|
|
59
|
+
- If user mentions a value NOT in this list, DO NOT set ${fieldName} in your response
|
|
60
|
+
- Instead, ask the user to choose from the valid options
|
|
61
|
+
- Provide context about which valid option might fit their intent`;
|
|
62
|
+
})
|
|
63
|
+
.join('\n');
|
|
64
|
+
enumGuidance = `\n\nCRITICAL ENUM VALIDATION RULES:\n${enumRules}`;
|
|
65
|
+
}
|
|
66
|
+
return `You are a ${toneValue} conversational assistant.
|
|
67
|
+
|
|
68
|
+
Your task is to gather the following information through natural conversation:
|
|
69
|
+
|
|
70
|
+
${factorDescriptions}${priorityGuidance}
|
|
71
|
+
|
|
72
|
+
CONVERSATION GUIDELINES:
|
|
73
|
+
- Ask questions naturally, one topic at a time
|
|
74
|
+
- Extract information from user responses
|
|
75
|
+
- Track what you've learned across conversation turns
|
|
76
|
+
- When the user provides information, acknowledge it and move to the next factor
|
|
77
|
+
- Be patient and adapt to the user's communication style${enumGuidance}
|
|
78
|
+
|
|
79
|
+
${customGuidance ? `ADDITIONAL GUIDANCE:\n${customGuidance}\n` : ''}
|
|
80
|
+
READINESS INDICATOR:
|
|
81
|
+
- When you have gathered enough information (at minimum, all required factors), acknowledge this to the user
|
|
82
|
+
- Example: "I have enough information now! Ready to see the results?"
|
|
83
|
+
- Wait for user confirmation before proceeding to recommendations`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generates the system prompt for Phase 2: Extraction
|
|
87
|
+
*/
|
|
88
|
+
export function generateExtractionPrompt(config, gatheredProfile) {
|
|
89
|
+
if (config.customExtractionPrompt) {
|
|
90
|
+
return config.customExtractionPrompt;
|
|
91
|
+
}
|
|
92
|
+
return `You are a data extraction assistant.
|
|
93
|
+
|
|
94
|
+
Extract and validate the following profile information into structured format:
|
|
95
|
+
|
|
96
|
+
${JSON.stringify(gatheredProfile, null, 2)}
|
|
97
|
+
|
|
98
|
+
Return ONLY a valid JSON object matching the expected schema.
|
|
99
|
+
Ensure all values match their expected types and constraints.`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Defines a two-phase conversational assistant agent.
|
|
103
|
+
*
|
|
104
|
+
* Phase 1 (Gathering): Natural conversation to collect information
|
|
105
|
+
* - No JSON output required
|
|
106
|
+
* - Conversational text responses
|
|
107
|
+
* - Accumulates factors informally
|
|
108
|
+
*
|
|
109
|
+
* Phase 2 (Extraction): Structured data extraction
|
|
110
|
+
* - JSON output with schema validation
|
|
111
|
+
* - Triggered when readiness check passes
|
|
112
|
+
* - Uses Structured Outputs API if configured
|
|
113
|
+
*
|
|
114
|
+
* @param config - Two-phase configuration
|
|
115
|
+
* @param handler - Optional custom handler (if you want full control)
|
|
116
|
+
* @returns Agent with validated execute function and manifest
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const breedAdvisor = defineTwoPhaseConversationalAssistant({
|
|
121
|
+
* name: 'breed-advisor',
|
|
122
|
+
* description: 'Helps users find their perfect cat breed',
|
|
123
|
+
* version: '1.0.0',
|
|
124
|
+
* inputSchema: BreedAdvisorInputSchema,
|
|
125
|
+
* gatheringPhase: {
|
|
126
|
+
* tone: 'enthusiastic',
|
|
127
|
+
* factors: [
|
|
128
|
+
* {
|
|
129
|
+
* name: 'musicPreference',
|
|
130
|
+
* description: 'User\'s music taste',
|
|
131
|
+
* type: 'enum',
|
|
132
|
+
* values: ['classical', 'jazz', 'rock', 'pop'],
|
|
133
|
+
* required: true,
|
|
134
|
+
* weight: 2,
|
|
135
|
+
* },
|
|
136
|
+
* {
|
|
137
|
+
* name: 'livingSpace',
|
|
138
|
+
* type: 'enum',
|
|
139
|
+
* values: ['apartment', 'house', 'farm'],
|
|
140
|
+
* naturalLanguageMappings: {
|
|
141
|
+
* 'flat': 'apartment',
|
|
142
|
+
* 'big house': 'house',
|
|
143
|
+
* },
|
|
144
|
+
* },
|
|
145
|
+
* ],
|
|
146
|
+
* readinessCheck: (profile) => Object.keys(profile).length >= 4,
|
|
147
|
+
* },
|
|
148
|
+
* extractionPhase: {
|
|
149
|
+
* outputSchema: BreedRecommendationSchema,
|
|
150
|
+
* generateRecommendations: matchBreeds,
|
|
151
|
+
* },
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function defineTwoPhaseConversationalAssistant(config, handler) {
|
|
156
|
+
// Generate system prompts
|
|
157
|
+
const gatheringPrompt = generateGatheringPrompt(config.gatheringPhase);
|
|
158
|
+
// Build manifest
|
|
159
|
+
const manifest = buildManifest(config, 'two-phase-conversational-assistant', {
|
|
160
|
+
mockable: config.mockable ?? true,
|
|
161
|
+
gatheringPhase: {
|
|
162
|
+
tone: config.gatheringPhase.tone,
|
|
163
|
+
factorCount: config.gatheringPhase.factors.length,
|
|
164
|
+
requiredFactors: config.gatheringPhase.factors.filter((f) => f.required).map((f) => f.name),
|
|
165
|
+
priorityFactors: config.gatheringPhase.priorityFactors,
|
|
166
|
+
},
|
|
167
|
+
extractionPhase: {
|
|
168
|
+
useStructuredOutputs: config.extractionPhase.useStructuredOutputs ?? false,
|
|
169
|
+
},
|
|
170
|
+
systemPrompt: {
|
|
171
|
+
gathering: gatheringPrompt,
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
// If custom handler provided, use it
|
|
175
|
+
if (handler) {
|
|
176
|
+
const execute = createAsyncExecuteWrapperWithContext(config, handler, createConversationalContextMapper(config.mockable ?? true));
|
|
177
|
+
return {
|
|
178
|
+
name: config.name,
|
|
179
|
+
execute,
|
|
180
|
+
manifest,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
// Default implementation: Two-phase pattern
|
|
184
|
+
const defaultHandler = async (_input, ctx) => {
|
|
185
|
+
// Check if gathering prompt is in history
|
|
186
|
+
const hasGatheringPrompt = ctx.history.some((msg) => msg.role === 'system' && msg.content.includes(gatheringPrompt));
|
|
187
|
+
if (!hasGatheringPrompt) {
|
|
188
|
+
ctx.addToHistory('system', gatheringPrompt);
|
|
189
|
+
}
|
|
190
|
+
// Determine current phase from session state or conversation history
|
|
191
|
+
// This would need access to session state from input
|
|
192
|
+
// For now, this is a placeholder - actual implementation would handle phase management
|
|
193
|
+
// Phase 1: Gathering
|
|
194
|
+
// Phase 2: Extraction
|
|
195
|
+
throw new Error('Default two-phase handler not yet implemented. ' +
|
|
196
|
+
'Please provide a custom handler or use the generated prompts manually.');
|
|
197
|
+
};
|
|
198
|
+
const execute = createAsyncExecuteWrapperWithContext(config, defaultHandler, createConversationalContextMapper(config.mockable ?? true));
|
|
199
|
+
return {
|
|
200
|
+
name: config.name,
|
|
201
|
+
execute,
|
|
202
|
+
manifest,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=two-phase-conversational.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"two-phase-conversational.js","sourceRoot":"","sources":["../src/two-phase-conversational.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EACL,aAAa,EACb,oCAAoC,EACpC,iCAAiC,GAClC,MAAM,sBAAsB,CAAC;AA6H9B;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAA4B;IAClE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAClE,MAAM,SAAS,GAAG,IAAI,IAAI,UAAU,CAAC;IAErC,4BAA4B;IAC5B,MAAM,kBAAkB,GAAG,OAAO;SAC/B,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACd,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC;QACrD,IAAI,IAAI,GAAG,OAAO,MAAM,CAAC,IAAI,OAAO,UAAU,EAAE,CAAC;QAEjD,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAC5C,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnE,IAAI,IAAI,qBAAqB,YAAY,EAAE,CAAC;QAC9C,CAAC;QAED,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;YAC7B,IAAI,I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AAC,CAC3D,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO;QACP,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the VAT agent runtime framework
|
|
3
|
+
*/
|
|
4
|
+
import type { z } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an executable agent with a defined input/output contract
|
|
7
|
+
*/
|
|
8
|
+
export interface Agent<TInput, TOutput> {
|
|
9
|
+
/** Unique name for the agent */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Execute the agent with validated input */
|
|
12
|
+
execute: (input: TInput, ...args: unknown[]) => TOutput | Promise<TOutput>;
|
|
13
|
+
/** Metadata describing the agent's interface and capabilities */
|
|
14
|
+
manifest: AgentManifest;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Base configuration shared by all agent types
|
|
18
|
+
* Eliminates duplication across archetype config interfaces
|
|
19
|
+
*/
|
|
20
|
+
export interface BaseAgentConfig<TInput, TOutput> {
|
|
21
|
+
/** Unique name for the agent */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Human-readable description of what the agent does */
|
|
24
|
+
description: string;
|
|
25
|
+
/** Semantic version (e.g., "1.0.0") */
|
|
26
|
+
version: string;
|
|
27
|
+
/** Zod schema for input validation */
|
|
28
|
+
inputSchema: z.ZodType<TInput>;
|
|
29
|
+
/** Zod schema for output validation */
|
|
30
|
+
outputSchema: z.ZodType<TOutput>;
|
|
31
|
+
/** Additional metadata */
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents a pure function agent with synchronous execution
|
|
36
|
+
*/
|
|
37
|
+
export interface PureFunctionAgent<TInput, TOutput> extends Agent<TInput, TOutput> {
|
|
38
|
+
/** Execute the agent synchronously with validated input */
|
|
39
|
+
execute: (input: TInput) => TOutput;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Metadata describing an agent's interface and capabilities
|
|
43
|
+
*/
|
|
44
|
+
export interface AgentManifest {
|
|
45
|
+
/** Unique name for the agent */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Human-readable description of what the agent does */
|
|
48
|
+
description: string;
|
|
49
|
+
/** Semantic version (e.g., "1.0.0") */
|
|
50
|
+
version: string;
|
|
51
|
+
/** JSON Schema for input validation */
|
|
52
|
+
inputSchema: Record<string, unknown>;
|
|
53
|
+
/** JSON Schema for output validation */
|
|
54
|
+
outputSchema: Record<string, unknown>;
|
|
55
|
+
/** Agent archetype (e.g., "pure-function", "llm-analyzer") */
|
|
56
|
+
archetype: string;
|
|
57
|
+
/** Additional metadata (model, temperature, mockable, etc.) */
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Message format for LLM communication
|
|
62
|
+
*/
|
|
63
|
+
export interface Message {
|
|
64
|
+
/** Message role (system, user, assistant) */
|
|
65
|
+
role: 'system' | 'user' | 'assistant';
|
|
66
|
+
/** Message content */
|
|
67
|
+
content: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Context provided to LLM-based agents
|
|
71
|
+
*/
|
|
72
|
+
export interface LLMAnalyzerContext {
|
|
73
|
+
/** Whether this agent can be mocked in tests */
|
|
74
|
+
mockable: boolean;
|
|
75
|
+
/** LLM model identifier (optional) */
|
|
76
|
+
model?: string;
|
|
77
|
+
/** Temperature for LLM generation (0-1, optional) */
|
|
78
|
+
temperature?: number;
|
|
79
|
+
/** Function to call the LLM with a prompt or messages */
|
|
80
|
+
callLLM: (prompt: string | Message[]) => Promise<string>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Context provided to conversational assistant agents
|
|
84
|
+
*/
|
|
85
|
+
export interface ConversationalContext {
|
|
86
|
+
/** Whether this agent can be mocked in tests */
|
|
87
|
+
mockable: boolean;
|
|
88
|
+
/** Conversation history */
|
|
89
|
+
history: Message[];
|
|
90
|
+
/** Add a message to conversation history */
|
|
91
|
+
addToHistory: (role: 'system' | 'user' | 'assistant', content: string) => void;
|
|
92
|
+
/** Function to call the LLM with messages */
|
|
93
|
+
callLLM: (messages: Message[]) => Promise<string>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Context provided to agentic researcher agents
|
|
97
|
+
*/
|
|
98
|
+
export interface ResearcherContext {
|
|
99
|
+
/** Whether this agent can be mocked in tests */
|
|
100
|
+
mockable: boolean;
|
|
101
|
+
/** Available tools for research */
|
|
102
|
+
tools: Record<string, Function>;
|
|
103
|
+
/** Function to call the LLM with a prompt */
|
|
104
|
+
callLLM: (prompt: string) => Promise<string>;
|
|
105
|
+
/** Function to call a tool by name */
|
|
106
|
+
callTool: (toolName: string, input: unknown) => Promise<unknown>;
|
|
107
|
+
/** Current iteration count */
|
|
108
|
+
iterationCount: number;
|
|
109
|
+
/** Maximum allowed iterations */
|
|
110
|
+
maxIterations: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Retry options for function calls
|
|
114
|
+
*/
|
|
115
|
+
export interface RetryOptions {
|
|
116
|
+
/** Maximum number of retry attempts */
|
|
117
|
+
maxAttempts?: number;
|
|
118
|
+
/** Delay between retries in milliseconds */
|
|
119
|
+
delayMs?: number;
|
|
120
|
+
/** Backoff multiplier for exponential backoff */
|
|
121
|
+
backoffMultiplier?: number;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Context provided to function orchestrator agents
|
|
125
|
+
*/
|
|
126
|
+
export interface OrchestratorContext {
|
|
127
|
+
/** Call another agent by name */
|
|
128
|
+
call: <T, R>(agentName: string, input: T) => Promise<R>;
|
|
129
|
+
/** Execute multiple calls in parallel */
|
|
130
|
+
parallel: <T>(calls: Array<() => Promise<T>>) => Promise<T[]>;
|
|
131
|
+
/** Retry a function call with exponential backoff */
|
|
132
|
+
retry: <T>(fn: () => Promise<T>, options?: RetryOptions) => Promise<T>;
|
|
133
|
+
/** Shared state for the orchestration */
|
|
134
|
+
state: Map<string, unknown>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Context provided to LLM coordinator agents
|
|
138
|
+
*/
|
|
139
|
+
export interface CoordinatorContext {
|
|
140
|
+
/** Whether this agent can be mocked in tests */
|
|
141
|
+
mockable: boolean;
|
|
142
|
+
/** Call another agent by name */
|
|
143
|
+
call: <T, R>(agentName: string, input: T) => Promise<R>;
|
|
144
|
+
/** Function to call the LLM with a prompt */
|
|
145
|
+
callLLM: (prompt: string) => Promise<string>;
|
|
146
|
+
/** Route to different paths based on LLM decision */
|
|
147
|
+
route: (decision: string, routes: Record<string, () => Promise<unknown>>) => Promise<unknown>;
|
|
148
|
+
/** Shared state for coordination */
|
|
149
|
+
state: Map<string, unknown>;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Context provided to function event consumer agents
|
|
153
|
+
*/
|
|
154
|
+
export interface EventConsumerContext {
|
|
155
|
+
/** Type of the event being consumed */
|
|
156
|
+
eventType: string;
|
|
157
|
+
/** Data payload of the event */
|
|
158
|
+
eventData: unknown;
|
|
159
|
+
/** Shared state for the consumer */
|
|
160
|
+
state: Map<string, unknown>;
|
|
161
|
+
/** Emit a new event */
|
|
162
|
+
emit: (eventType: string, data: unknown) => Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Context provided to LLM event handler agents
|
|
166
|
+
*/
|
|
167
|
+
export interface LLMEventHandlerContext {
|
|
168
|
+
/** Whether this agent can be mocked in tests */
|
|
169
|
+
mockable: boolean;
|
|
170
|
+
/** Type of the event being handled */
|
|
171
|
+
eventType: string;
|
|
172
|
+
/** Data payload of the event */
|
|
173
|
+
eventData: unknown;
|
|
174
|
+
/** Function to call the LLM with a prompt */
|
|
175
|
+
callLLM: (prompt: string) => Promise<string>;
|
|
176
|
+
/** Emit a new event */
|
|
177
|
+
emit: (eventType: string, data: unknown) => Promise<void>;
|
|
178
|
+
/** Shared state for the handler */
|
|
179
|
+
state: Map<string, unknown>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Context provided to external event integrator agents
|
|
183
|
+
*/
|
|
184
|
+
export interface ExternalEventContext {
|
|
185
|
+
/** Emit an event to external systems */
|
|
186
|
+
emit: (eventType: string, data: unknown) => Promise<void>;
|
|
187
|
+
/** Wait for an external event with timeout */
|
|
188
|
+
waitFor: <T>(eventType: string, timeoutMs: number) => Promise<T>;
|
|
189
|
+
/** Timeout in milliseconds (optional) */
|
|
190
|
+
timeoutMs?: number;
|
|
191
|
+
/** Action to take on timeout: approve, reject, or error */
|
|
192
|
+
onTimeout?: 'approve' | 'reject' | 'error';
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,KAAK,CAAC,MAAM,EAAE,OAAO;IACpC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,6CAA6C;IAC7C,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3E,iEAAiE;IACjE,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,MAAM,EAAE,OAAO;IAC9C,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;IAEpB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAEhB,sCAAsC;IACtC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC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IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,QAAQ,EAAE,OAAO,CAAC;IAElB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAElB,gCAAgC;IAChC,SAAS,EAAE,OAAO,CAAC;IAEnB,6CAA6C;IAC7C,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAE7C,uBAAuB;IACvB,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1D,mCAAmC;IACnC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1D,8CAA8C;IAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAEjE,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;CAC5C"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vibe-agent-toolkit/agent-runtime",
|
|
3
|
+
"version": "0.1.2-rc.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Runtime framework for building and executing portable AI agents",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"agent",
|
|
8
|
+
"runtime",
|
|
9
|
+
"ai",
|
|
10
|
+
"llm",
|
|
11
|
+
"portable",
|
|
12
|
+
"toolkit"
|
|
13
|
+
],
|
|
14
|
+
"author": "Jeff Dutton",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./session/test-helpers": {
|
|
24
|
+
"types": "./dist/session/test-helpers/index.d.ts",
|
|
25
|
+
"import": "./dist/session/test-helpers/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:watch": "vitest",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"clean": "rimraf dist *.tsbuildinfo"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@vibe-agent-toolkit/agent-schema": "0.1.2-rc.3",
|
|
41
|
+
"@vibe-agent-toolkit/utils": "0.1.2-rc.3",
|
|
42
|
+
"zod": "^3.23.8",
|
|
43
|
+
"zod-to-json-schema": "^3.23.5"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"rimraf": "^6.0.1",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vitest": "^3.2.4"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/jdutton/vibe-agent-toolkit.git"
|
|
56
|
+
}
|
|
57
|
+
}
|