@soederpop/luca 0.1.3 → 0.2.1
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/.github/workflows/release.yaml +167 -0
- package/README.md +3 -0
- package/assistants/codingAssistant/ABOUT.md +3 -0
- package/assistants/codingAssistant/CORE.md +22 -17
- package/assistants/codingAssistant/hooks.ts +19 -2
- package/assistants/codingAssistant/tools.ts +1 -106
- package/assistants/inkbot/ABOUT.md +5 -0
- package/assistants/inkbot/CORE.md +2 -0
- package/bun.lock +20 -4
- package/commands/release.ts +75 -181
- package/docs/ideas/assistant-factory-pattern.md +142 -0
- package/package.json +3 -2
- package/src/agi/container.server.ts +10 -0
- package/src/agi/features/agent-memory.ts +694 -0
- package/src/agi/features/assistant.ts +1 -1
- package/src/agi/features/assistants-manager.ts +25 -0
- package/src/agi/features/browser-use.ts +30 -0
- package/src/agi/features/coding-tools.ts +175 -0
- package/src/agi/features/file-tools.ts +33 -26
- package/src/agi/features/skills-library.ts +28 -11
- package/src/bootstrap/generated.ts +1 -1
- package/src/cli/build-info.ts +2 -2
- package/src/clients/voicebox/index.ts +300 -0
- package/src/introspection/generated.agi.ts +1997 -789
- package/src/introspection/generated.node.ts +788 -736
- package/src/introspection/generated.web.ts +1 -1
- package/src/node/features/content-db.ts +54 -27
- package/src/node/features/process-manager.ts +50 -17
- package/src/python/generated.ts +1 -1
- package/src/scaffolds/generated.ts +1 -1
- package/test/assistant.test.ts +14 -5
- package/test-integration/memory.test.ts +204 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { ClientStateSchema, ClientOptionsSchema, ClientEventsSchema } from '@soederpop/luca/schemas/base.js'
|
|
3
|
+
import { Client } from "@soederpop/luca/client";
|
|
4
|
+
import { RestClient } from "../rest";
|
|
5
|
+
import type { ContainerContext } from "@soederpop/luca/container";
|
|
6
|
+
import type { NodeContainer } from "../../node/container.js";
|
|
7
|
+
|
|
8
|
+
declare module "@soederpop/luca/client" {
|
|
9
|
+
interface AvailableClients {
|
|
10
|
+
voicebox: typeof VoiceBoxClient;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const VoiceBoxClientOptionsSchema = ClientOptionsSchema.extend({
|
|
15
|
+
baseURL: z.string().optional().describe('VoiceBox server URL (falls back to VOICEBOX_URL env var, default http://127.0.0.1:17493)'),
|
|
16
|
+
defaultProfileId: z.string().optional().describe('Default voice profile ID for synthesis'),
|
|
17
|
+
defaultEngine: z.string().optional().default('qwen').describe('Default TTS engine (qwen, luxtts, chatterbox, chatterbox_turbo)'),
|
|
18
|
+
defaultModelSize: z.string().optional().default('1.7B').describe('Default model size (1.7B or 0.6B)'),
|
|
19
|
+
defaultLanguage: z.string().optional().default('en').describe('Default language code'),
|
|
20
|
+
})
|
|
21
|
+
export type VoiceBoxClientOptions = z.infer<typeof VoiceBoxClientOptionsSchema>
|
|
22
|
+
|
|
23
|
+
export const VoiceBoxClientStateSchema = ClientStateSchema.extend({
|
|
24
|
+
requestCount: z.number().default(0).describe('Total number of API requests made'),
|
|
25
|
+
characterCount: z.number().default(0).describe('Total characters sent for synthesis'),
|
|
26
|
+
lastRequestTime: z.number().nullable().default(null).describe('Timestamp of the last API request'),
|
|
27
|
+
})
|
|
28
|
+
export type VoiceBoxClientState = z.infer<typeof VoiceBoxClientStateSchema>
|
|
29
|
+
|
|
30
|
+
export const VoiceBoxClientEventsSchema = ClientEventsSchema.extend({
|
|
31
|
+
speech: z.tuple([z.object({
|
|
32
|
+
profileId: z.string(),
|
|
33
|
+
text: z.string(),
|
|
34
|
+
audioSize: z.number(),
|
|
35
|
+
})]).describe('Emitted after speech synthesis completes'),
|
|
36
|
+
profiles: z.tuple([z.array(z.any())]).describe('Emitted after listing profiles'),
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
export type EffectConfig = {
|
|
40
|
+
type: string
|
|
41
|
+
enabled?: boolean
|
|
42
|
+
params?: Record<string, any>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type SynthesizeOptions = {
|
|
46
|
+
profileId?: string
|
|
47
|
+
engine?: string
|
|
48
|
+
modelSize?: string
|
|
49
|
+
language?: string
|
|
50
|
+
instruct?: string
|
|
51
|
+
seed?: number
|
|
52
|
+
maxChunkChars?: number
|
|
53
|
+
crossfadeMs?: number
|
|
54
|
+
normalize?: boolean
|
|
55
|
+
effectsChain?: EffectConfig[]
|
|
56
|
+
disableCache?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* VoiceBox client — local TTS synthesis via VoiceBox.sh REST API (Qwen3-TTS).
|
|
61
|
+
*
|
|
62
|
+
* Provides methods for managing voice profiles and generating speech audio locally.
|
|
63
|
+
* Uses the streaming endpoint for synchronous synthesis (returns WAV buffer).
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const vb = container.client('voicebox')
|
|
68
|
+
* await vb.connect()
|
|
69
|
+
* const profiles = await vb.listProfiles()
|
|
70
|
+
* const audio = await vb.synthesize('Hello world', { profileId: profiles[0].id })
|
|
71
|
+
* // audio is a Buffer of WAV data
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export class VoiceBoxClient extends RestClient<VoiceBoxClientState, VoiceBoxClientOptions> {
|
|
75
|
+
static override shortcut = "clients.voicebox" as const
|
|
76
|
+
static override envVars = ['VOICEBOX_URL']
|
|
77
|
+
static override stateSchema = VoiceBoxClientStateSchema
|
|
78
|
+
static override optionsSchema = VoiceBoxClientOptionsSchema
|
|
79
|
+
static override eventsSchema = VoiceBoxClientEventsSchema
|
|
80
|
+
|
|
81
|
+
static { Client.register(this, 'voicebox') }
|
|
82
|
+
|
|
83
|
+
override get initialState(): VoiceBoxClientState {
|
|
84
|
+
return {
|
|
85
|
+
...super.initialState,
|
|
86
|
+
requestCount: 0,
|
|
87
|
+
characterCount: 0,
|
|
88
|
+
lastRequestTime: null,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
constructor(options: VoiceBoxClientOptions, context: ContainerContext) {
|
|
93
|
+
options = {
|
|
94
|
+
...options,
|
|
95
|
+
baseURL: options.baseURL || process.env.VOICEBOX_URL || 'http://127.0.0.1:17493',
|
|
96
|
+
}
|
|
97
|
+
super(options, context)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
override get container(): NodeContainer {
|
|
101
|
+
return super.container as unknown as NodeContainer
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private trackRequest(characters = 0) {
|
|
105
|
+
const requestCount = this.state.get('requestCount') || 0
|
|
106
|
+
const characterCount = this.state.get('characterCount') || 0
|
|
107
|
+
this.setState({
|
|
108
|
+
requestCount: requestCount + 1,
|
|
109
|
+
characterCount: characterCount + characters,
|
|
110
|
+
lastRequestTime: Date.now(),
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Validate the VoiceBox server is reachable by hitting the health endpoint.
|
|
116
|
+
*/
|
|
117
|
+
override async connect(): Promise<this> {
|
|
118
|
+
try {
|
|
119
|
+
const health = await this.get('/health')
|
|
120
|
+
if (health?.status !== 'ok' && health?.status !== 'healthy') {
|
|
121
|
+
// Accept any 200 response as healthy
|
|
122
|
+
}
|
|
123
|
+
await super.connect()
|
|
124
|
+
this.emit('connected' as any)
|
|
125
|
+
return this
|
|
126
|
+
} catch (error) {
|
|
127
|
+
this.emit('failure', error)
|
|
128
|
+
throw error
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* List all voice profiles.
|
|
134
|
+
*
|
|
135
|
+
* @returns Array of voice profile objects
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const profiles = await vb.listProfiles()
|
|
140
|
+
* console.log(profiles.map(p => `${p.name} (${p.sample_count} samples)`))
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
async listProfiles(): Promise<any[]> {
|
|
144
|
+
this.trackRequest()
|
|
145
|
+
const result = await this.get('/profiles')
|
|
146
|
+
const profiles = Array.isArray(result) ? result : []
|
|
147
|
+
this.emit('profiles', profiles)
|
|
148
|
+
return profiles
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Get a single voice profile by ID.
|
|
153
|
+
*/
|
|
154
|
+
async getProfile(profileId: string): Promise<any> {
|
|
155
|
+
this.trackRequest()
|
|
156
|
+
return this.get(`/profiles/${profileId}`)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Create a new voice profile.
|
|
161
|
+
*/
|
|
162
|
+
async createProfile(name: string, options: { description?: string; language?: string } = {}): Promise<any> {
|
|
163
|
+
this.trackRequest()
|
|
164
|
+
return this.post('/profiles', { name, ...options })
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* List available audio effects and their parameter definitions.
|
|
169
|
+
*/
|
|
170
|
+
async listEffects(): Promise<any> {
|
|
171
|
+
this.trackRequest()
|
|
172
|
+
return this.get('/effects/available')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Synthesize speech from text using the streaming endpoint.
|
|
177
|
+
* Returns audio as a WAV Buffer (synchronous — blocks until audio is ready).
|
|
178
|
+
*
|
|
179
|
+
* @param text - The text to convert to speech
|
|
180
|
+
* @param options - Profile, engine, model, and other synthesis options
|
|
181
|
+
* @returns Audio data as a WAV Buffer
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const audio = await vb.synthesize('Hello world', { profileId: 'abc-123' })
|
|
186
|
+
* // audio is a Buffer of WAV data
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
async synthesize(text: string, options: SynthesizeOptions = {}): Promise<Buffer> {
|
|
190
|
+
const profileId = options.profileId || this.options.defaultProfileId
|
|
191
|
+
if (!profileId) throw new Error('profileId is required for VoiceBox synthesis')
|
|
192
|
+
|
|
193
|
+
const engine = options.engine || this.options.defaultEngine || 'qwen'
|
|
194
|
+
const modelSize = options.modelSize || this.options.defaultModelSize || '1.7B'
|
|
195
|
+
const language = options.language || this.options.defaultLanguage || 'en'
|
|
196
|
+
|
|
197
|
+
const body: Record<string, any> = {
|
|
198
|
+
profile_id: profileId,
|
|
199
|
+
text,
|
|
200
|
+
language,
|
|
201
|
+
engine,
|
|
202
|
+
model_size: modelSize,
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (options.instruct) body.instruct = options.instruct
|
|
206
|
+
if (options.seed != null) body.seed = options.seed
|
|
207
|
+
if (options.maxChunkChars != null) body.max_chunk_chars = options.maxChunkChars
|
|
208
|
+
if (options.crossfadeMs != null) body.crossfade_ms = options.crossfadeMs
|
|
209
|
+
if (options.normalize != null) body.normalize = options.normalize
|
|
210
|
+
if (options.effectsChain) body.effects_chain = options.effectsChain
|
|
211
|
+
|
|
212
|
+
// Check disk cache
|
|
213
|
+
if (!options.disableCache) {
|
|
214
|
+
const { hashObject } = this.container.utils
|
|
215
|
+
const cacheKey = `voicebox:${hashObject({ text, profileId, engine, modelSize, language, instruct: options.instruct })}`
|
|
216
|
+
const diskCache = this.container.feature('diskCache')
|
|
217
|
+
|
|
218
|
+
if (await diskCache.has(cacheKey)) {
|
|
219
|
+
const cached = await diskCache.get(cacheKey)
|
|
220
|
+
const audioBuffer = Buffer.from(cached, 'base64')
|
|
221
|
+
this.emit('speech', { profileId, text, audioSize: audioBuffer.length })
|
|
222
|
+
return audioBuffer
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const audioBuffer = await this.fetchStreamAudio(body, text.length)
|
|
226
|
+
await diskCache.set(cacheKey, audioBuffer.toString('base64'))
|
|
227
|
+
this.emit('speech', { profileId, text, audioSize: audioBuffer.length })
|
|
228
|
+
return audioBuffer
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const audioBuffer = await this.fetchStreamAudio(body, text.length)
|
|
232
|
+
this.emit('speech', { profileId, text, audioSize: audioBuffer.length })
|
|
233
|
+
return audioBuffer
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Generate speech asynchronously (returns metadata, not audio).
|
|
238
|
+
* Use getAudio() to fetch the audio after generation completes.
|
|
239
|
+
*/
|
|
240
|
+
async generate(text: string, options: SynthesizeOptions = {}): Promise<any> {
|
|
241
|
+
const profileId = options.profileId || this.options.defaultProfileId
|
|
242
|
+
if (!profileId) throw new Error('profileId is required for VoiceBox generation')
|
|
243
|
+
|
|
244
|
+
const body: Record<string, any> = {
|
|
245
|
+
profile_id: profileId,
|
|
246
|
+
text,
|
|
247
|
+
language: options.language || this.options.defaultLanguage || 'en',
|
|
248
|
+
engine: options.engine || this.options.defaultEngine || 'qwen',
|
|
249
|
+
model_size: options.modelSize || this.options.defaultModelSize || '1.7B',
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (options.instruct) body.instruct = options.instruct
|
|
253
|
+
if (options.seed != null) body.seed = options.seed
|
|
254
|
+
if (options.effectsChain) body.effects_chain = options.effectsChain
|
|
255
|
+
|
|
256
|
+
this.trackRequest(text.length)
|
|
257
|
+
return this.post('/generate', body)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Fetch generated audio by generation ID. Returns WAV Buffer.
|
|
262
|
+
*/
|
|
263
|
+
async getAudio(generationId: string): Promise<Buffer> {
|
|
264
|
+
this.trackRequest()
|
|
265
|
+
const response = await this.axios({
|
|
266
|
+
method: 'GET',
|
|
267
|
+
url: `/audio/${generationId}`,
|
|
268
|
+
responseType: 'arraybuffer',
|
|
269
|
+
headers: { Accept: 'audio/wav' },
|
|
270
|
+
})
|
|
271
|
+
return Buffer.from(response.data)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Synthesize and write audio to a file.
|
|
276
|
+
*/
|
|
277
|
+
async say(text: string, outputPath: string, options: SynthesizeOptions = {}): Promise<string> {
|
|
278
|
+
const audio = await this.synthesize(text, options)
|
|
279
|
+
const resolvedPath = this.container.paths.resolve(outputPath)
|
|
280
|
+
await this.container.fs.writeFileAsync(resolvedPath, audio)
|
|
281
|
+
return resolvedPath
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private async fetchStreamAudio(body: Record<string, any>, charCount: number): Promise<Buffer> {
|
|
285
|
+
this.trackRequest(charCount)
|
|
286
|
+
const response = await this.axios({
|
|
287
|
+
method: 'POST',
|
|
288
|
+
url: '/generate/stream',
|
|
289
|
+
data: body,
|
|
290
|
+
responseType: 'arraybuffer',
|
|
291
|
+
headers: {
|
|
292
|
+
'Content-Type': 'application/json',
|
|
293
|
+
Accept: 'audio/wav',
|
|
294
|
+
},
|
|
295
|
+
})
|
|
296
|
+
return Buffer.from(response.data)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export default VoiceBoxClient
|