@pellux/goodvibes-sdk 0.25.7 → 0.25.8
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/_internal/contracts/artifacts/operator-contract.json +100 -4
- package/dist/_internal/contracts/generated/foundation-metadata.d.ts +2 -2
- package/dist/_internal/contracts/generated/foundation-metadata.js +2 -2
- package/dist/_internal/contracts/generated/operator-contract.d.ts.map +1 -1
- package/dist/_internal/contracts/generated/operator-contract.js +100 -4
- package/dist/_internal/contracts/generated/operator-method-ids.d.ts +1 -1
- package/dist/_internal/contracts/generated/operator-method-ids.d.ts.map +1 -1
- package/dist/_internal/contracts/generated/operator-method-ids.js +1 -0
- package/dist/_internal/daemon/context.d.ts +1 -0
- package/dist/_internal/daemon/context.d.ts.map +1 -1
- package/dist/_internal/daemon/media-route-types.d.ts +10 -0
- package/dist/_internal/daemon/media-route-types.d.ts.map +1 -1
- package/dist/_internal/daemon/media-routes.d.ts +1 -1
- package/dist/_internal/daemon/media-routes.d.ts.map +1 -1
- package/dist/_internal/daemon/media-routes.js +91 -10
- package/dist/_internal/daemon/operator.d.ts +1 -1
- package/dist/_internal/daemon/operator.d.ts.map +1 -1
- package/dist/_internal/daemon/operator.js +2 -0
- package/dist/_internal/platform/adapters/ntfy/index.js +13 -2
- package/dist/_internal/platform/adapters/types.d.ts +2 -0
- package/dist/_internal/platform/adapters/types.d.ts.map +1 -1
- package/dist/_internal/platform/batch/index.d.ts +4 -0
- package/dist/_internal/platform/batch/index.d.ts.map +1 -0
- package/dist/_internal/platform/batch/index.js +2 -0
- package/dist/_internal/platform/batch/manager.d.ts +41 -0
- package/dist/_internal/platform/batch/manager.d.ts.map +1 -0
- package/dist/_internal/platform/batch/manager.js +400 -0
- package/dist/_internal/platform/batch/types.d.ts +85 -0
- package/dist/_internal/platform/batch/types.d.ts.map +1 -0
- package/dist/_internal/platform/batch/types.js +10 -0
- package/dist/_internal/platform/channels/builtin/plugins.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/plugins.js +1 -0
- package/dist/_internal/platform/channels/reply-pipeline.d.ts +9 -1
- package/dist/_internal/platform/channels/reply-pipeline.d.ts.map +1 -1
- package/dist/_internal/platform/channels/reply-pipeline.js +156 -6
- package/dist/_internal/platform/config/schema-domain-core.d.ts +6 -0
- package/dist/_internal/platform/config/schema-domain-core.d.ts.map +1 -1
- package/dist/_internal/platform/config/schema-domain-core.js +30 -0
- package/dist/_internal/platform/config/schema-domain-runtime.d.ts +19 -0
- package/dist/_internal/platform/config/schema-domain-runtime.d.ts.map +1 -1
- package/dist/_internal/platform/config/schema-domain-runtime.js +118 -0
- package/dist/_internal/platform/config/schema-types.d.ts +33 -2
- package/dist/_internal/platform/config/schema-types.d.ts.map +1 -1
- package/dist/_internal/platform/config/schema.d.ts.map +1 -1
- package/dist/_internal/platform/config/schema.js +3 -0
- package/dist/_internal/platform/control-plane/method-catalog-media.d.ts.map +1 -1
- package/dist/_internal/platform/control-plane/method-catalog-media.js +17 -0
- package/dist/_internal/platform/control-plane/routes/operator.d.ts +1 -1
- package/dist/_internal/platform/control-plane/routes/operator.d.ts.map +1 -1
- package/dist/_internal/platform/control-plane/routes/operator.js +2 -0
- package/dist/_internal/platform/daemon/facade-composition.d.ts +2 -0
- package/dist/_internal/platform/daemon/facade-composition.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/facade-composition.js +10 -0
- package/dist/_internal/platform/daemon/http/batch-routes.d.ts +8 -0
- package/dist/_internal/platform/daemon/http/batch-routes.d.ts.map +1 -0
- package/dist/_internal/platform/daemon/http/batch-routes.js +113 -0
- package/dist/_internal/platform/daemon/http/router-route-contexts.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/http/router-route-contexts.js +1 -0
- package/dist/_internal/platform/daemon/http/router.d.ts +4 -0
- package/dist/_internal/platform/daemon/http/router.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/http/router.js +15 -0
- package/dist/_internal/platform/daemon/http/runtime-route-types.d.ts +2 -0
- package/dist/_internal/platform/daemon/http/runtime-route-types.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/surface-actions.d.ts +6 -0
- package/dist/_internal/platform/daemon/surface-actions.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/surface-actions.js +13 -0
- package/dist/_internal/platform/daemon/surface-delivery.d.ts +3 -0
- package/dist/_internal/platform/daemon/surface-delivery.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/surface-delivery.js +42 -6
- package/dist/_internal/platform/daemon/types.d.ts +2 -0
- package/dist/_internal/platform/daemon/types.d.ts.map +1 -1
- package/dist/_internal/platform/providers/anthropic.d.ts +13 -1
- package/dist/_internal/platform/providers/anthropic.d.ts.map +1 -1
- package/dist/_internal/platform/providers/anthropic.js +219 -1
- package/dist/_internal/platform/providers/interface.d.ts +48 -0
- package/dist/_internal/platform/providers/interface.d.ts.map +1 -1
- package/dist/_internal/platform/providers/openai.d.ts +13 -1
- package/dist/_internal/platform/providers/openai.d.ts.map +1 -1
- package/dist/_internal/platform/providers/openai.js +189 -1
- package/dist/_internal/platform/version.js +1 -1
- package/dist/_internal/platform/voice/index.d.ts +1 -1
- package/dist/_internal/platform/voice/index.d.ts.map +1 -1
- package/dist/_internal/platform/voice/providers/elevenlabs.d.ts.map +1 -1
- package/dist/_internal/platform/voice/providers/elevenlabs.js +150 -4
- package/dist/_internal/platform/voice/service.d.ts +2 -1
- package/dist/_internal/platform/voice/service.d.ts.map +1 -1
- package/dist/_internal/platform/voice/service.js +7 -0
- package/dist/_internal/platform/voice/types.d.ts +18 -1
- package/dist/_internal/platform/voice/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/workers.d.ts +40 -0
- package/dist/workers.d.ts.map +1 -0
- package/dist/workers.js +144 -0
- package/package.json +5 -1
|
@@ -7,7 +7,7 @@ import { withRetry } from '../utils/retry.js';
|
|
|
7
7
|
import { logger } from '../utils/logger.js';
|
|
8
8
|
import { instrumentedLlmCall } from '../runtime/llm-observability.js';
|
|
9
9
|
import { toAnthropicTools, toAnthropicMessages, fromAnthropicContent, } from './tool-formats.js';
|
|
10
|
-
import { toProviderError } from '../utils/error-display.js';
|
|
10
|
+
import { summarizeError, toProviderError } from '../utils/error-display.js';
|
|
11
11
|
import { instrumentedFetch } from '../utils/fetch-with-timeout.js';
|
|
12
12
|
import { toRecord } from '../utils/record-coerce.js';
|
|
13
13
|
const ANTHROPIC_API_BASE = 'https://api.anthropic.com/v1';
|
|
@@ -48,11 +48,20 @@ function clampMaxTokens(model, requested) {
|
|
|
48
48
|
export class AnthropicProvider {
|
|
49
49
|
name = 'anthropic';
|
|
50
50
|
models = [];
|
|
51
|
+
batch;
|
|
51
52
|
apiKey;
|
|
52
53
|
cacheHitTracker;
|
|
53
54
|
constructor(apiKey, cacheHitTracker = NOOP_CACHE_HIT_TRACKER) {
|
|
54
55
|
this.apiKey = apiKey;
|
|
55
56
|
this.cacheHitTracker = cacheHitTracker;
|
|
57
|
+
this.batch = {
|
|
58
|
+
kind: 'provider-batch',
|
|
59
|
+
endpoints: ['/v1/messages/batches'],
|
|
60
|
+
createChatBatch: (input) => this.createChatBatch(input),
|
|
61
|
+
retrieveBatch: (providerBatchId) => this.retrieveBatch(providerBatchId),
|
|
62
|
+
cancelBatch: (providerBatchId) => this.cancelBatch(providerBatchId),
|
|
63
|
+
getResults: (providerBatchId) => this.getBatchResults(providerBatchId),
|
|
64
|
+
};
|
|
56
65
|
}
|
|
57
66
|
async chat(params) {
|
|
58
67
|
const { messages, tools, model, maxTokens, signal, systemPrompt, onDelta, reasoningEffort } = params;
|
|
@@ -392,6 +401,15 @@ export class AnthropicProvider {
|
|
|
392
401
|
toolCalling: true,
|
|
393
402
|
parallelTools: true,
|
|
394
403
|
promptCaching: true,
|
|
404
|
+
batch: {
|
|
405
|
+
supported: true,
|
|
406
|
+
discount: 'Provider-side Message Batches pricing is discounted versus live API pricing where Anthropic offers the discount.',
|
|
407
|
+
completionWindow: '24h',
|
|
408
|
+
endpoints: ['/v1/messages/batches'],
|
|
409
|
+
maxRequestsPerProviderBatch: 100_000,
|
|
410
|
+
maxInputBytes: 256 * 1024 * 1024,
|
|
411
|
+
notes: ['Batch requests are asynchronous and non-streaming. Results are correlated by custom_id.'],
|
|
412
|
+
},
|
|
395
413
|
notes: ['Anthropic prompt caching and thinking budgets are handled natively.'],
|
|
396
414
|
},
|
|
397
415
|
policy: {
|
|
@@ -403,6 +421,206 @@ export class AnthropicProvider {
|
|
|
403
421
|
},
|
|
404
422
|
};
|
|
405
423
|
}
|
|
424
|
+
isConfigured() {
|
|
425
|
+
return this.apiKey.trim().length > 0;
|
|
426
|
+
}
|
|
427
|
+
async createChatBatch(input) {
|
|
428
|
+
const res = await instrumentedFetch(`${ANTHROPIC_API_BASE}/messages/batches`, {
|
|
429
|
+
method: 'POST',
|
|
430
|
+
headers: this.batchHeaders(),
|
|
431
|
+
body: JSON.stringify({
|
|
432
|
+
requests: input.requests.map((request) => ({
|
|
433
|
+
custom_id: request.customId,
|
|
434
|
+
params: this.toAnthropicBatchMessageParams(request.params),
|
|
435
|
+
})),
|
|
436
|
+
}),
|
|
437
|
+
});
|
|
438
|
+
const body = await this.readJsonResponse(res, 'create batch');
|
|
439
|
+
return {
|
|
440
|
+
providerBatchId: String(body['id'] ?? ''),
|
|
441
|
+
status: this.mapAnthropicBatchStatus(body),
|
|
442
|
+
raw: body,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
async retrieveBatch(providerBatchId) {
|
|
446
|
+
const res = await instrumentedFetch(`${ANTHROPIC_API_BASE}/messages/batches/${encodeURIComponent(providerBatchId)}`, {
|
|
447
|
+
method: 'GET',
|
|
448
|
+
headers: this.batchHeaders(),
|
|
449
|
+
});
|
|
450
|
+
const body = await this.readJsonResponse(res, 'retrieve batch');
|
|
451
|
+
return {
|
|
452
|
+
providerBatchId: String(body['id'] ?? providerBatchId),
|
|
453
|
+
status: this.mapAnthropicBatchStatus(body),
|
|
454
|
+
resultAvailable: typeof body['results_url'] === 'string' && body['results_url'].length > 0,
|
|
455
|
+
raw: body,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
async cancelBatch(providerBatchId) {
|
|
459
|
+
const res = await instrumentedFetch(`${ANTHROPIC_API_BASE}/messages/batches/${encodeURIComponent(providerBatchId)}/cancel`, {
|
|
460
|
+
method: 'POST',
|
|
461
|
+
headers: this.batchHeaders(),
|
|
462
|
+
});
|
|
463
|
+
const body = await this.readJsonResponse(res, 'cancel batch');
|
|
464
|
+
return {
|
|
465
|
+
providerBatchId: String(body['id'] ?? providerBatchId),
|
|
466
|
+
status: this.mapAnthropicBatchStatus(body),
|
|
467
|
+
resultAvailable: typeof body['results_url'] === 'string' && body['results_url'].length > 0,
|
|
468
|
+
raw: body,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
async getBatchResults(providerBatchId) {
|
|
472
|
+
const retrieveRes = await instrumentedFetch(`${ANTHROPIC_API_BASE}/messages/batches/${encodeURIComponent(providerBatchId)}`, {
|
|
473
|
+
method: 'GET',
|
|
474
|
+
headers: this.batchHeaders(),
|
|
475
|
+
});
|
|
476
|
+
const batch = await this.readJsonResponse(retrieveRes, 'retrieve batch results');
|
|
477
|
+
const resultsUrl = typeof batch['results_url'] === 'string' ? batch['results_url'] : '';
|
|
478
|
+
if (!resultsUrl)
|
|
479
|
+
return [];
|
|
480
|
+
const resultsRes = await instrumentedFetch(resultsUrl, {
|
|
481
|
+
method: 'GET',
|
|
482
|
+
headers: this.batchHeaders({ accept: 'application/jsonl' }),
|
|
483
|
+
});
|
|
484
|
+
if (!resultsRes.ok) {
|
|
485
|
+
const text = await resultsRes.text().catch(() => 'unknown error');
|
|
486
|
+
throw new ProviderError(formatAnthropicErrorText(resultsRes.status, text), {
|
|
487
|
+
statusCode: resultsRes.status,
|
|
488
|
+
provider: this.name,
|
|
489
|
+
operation: 'batch.results',
|
|
490
|
+
phase: 'request',
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
const text = await resultsRes.text();
|
|
494
|
+
const lines = text.split('\n').map((line) => line.trim()).filter(Boolean);
|
|
495
|
+
const results = [];
|
|
496
|
+
for (const line of lines) {
|
|
497
|
+
try {
|
|
498
|
+
results.push(this.parseAnthropicBatchResult(JSON.parse(line)));
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
results.push({
|
|
502
|
+
customId: `unparseable:${crypto.randomUUID()}`,
|
|
503
|
+
status: 'failed',
|
|
504
|
+
error: { message: `Unable to parse Anthropic batch result line: ${summarizeError(error)}` },
|
|
505
|
+
raw: line,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return results;
|
|
510
|
+
}
|
|
511
|
+
batchHeaders(extra) {
|
|
512
|
+
return {
|
|
513
|
+
'Content-Type': 'application/json',
|
|
514
|
+
'anthropic-version': ANTHROPIC_API_VERSION,
|
|
515
|
+
'x-api-key': this.apiKey,
|
|
516
|
+
...(extra?.accept ? { Accept: extra.accept } : {}),
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
toAnthropicBatchMessageParams(params) {
|
|
520
|
+
const resolvedModel = normalizeAnthropicModel(params.model);
|
|
521
|
+
const body = {
|
|
522
|
+
model: resolvedModel,
|
|
523
|
+
max_tokens: clampMaxTokens(resolvedModel, params.maxTokens ?? 8192),
|
|
524
|
+
messages: toAnthropicMessages(params.messages),
|
|
525
|
+
};
|
|
526
|
+
if (params.systemPrompt) {
|
|
527
|
+
body['system'] = [{ type: 'text', text: params.systemPrompt }];
|
|
528
|
+
}
|
|
529
|
+
if (params.tools && params.tools.length > 0) {
|
|
530
|
+
body['tools'] = toAnthropicTools(params.tools);
|
|
531
|
+
}
|
|
532
|
+
if (params.reasoningEffort && params.reasoningEffort !== 'instant') {
|
|
533
|
+
const budget = REASONING_BUDGET_MAP[params.reasoningEffort];
|
|
534
|
+
if (budget !== undefined && budget > 0) {
|
|
535
|
+
body['thinking'] = { type: 'enabled', budget_tokens: budget };
|
|
536
|
+
const currentMax = body['max_tokens'] ?? 8192;
|
|
537
|
+
if (currentMax <= budget)
|
|
538
|
+
body['max_tokens'] = budget + 4096;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return body;
|
|
542
|
+
}
|
|
543
|
+
mapAnthropicBatchStatus(body) {
|
|
544
|
+
const status = typeof body['processing_status'] === 'string' ? body['processing_status'] : '';
|
|
545
|
+
if (status === 'ended')
|
|
546
|
+
return 'completed';
|
|
547
|
+
if (status === 'canceling')
|
|
548
|
+
return 'cancelled';
|
|
549
|
+
if (status === 'in_progress')
|
|
550
|
+
return 'running';
|
|
551
|
+
const archivedAt = body['archived_at'];
|
|
552
|
+
if (archivedAt != null)
|
|
553
|
+
return 'cancelled';
|
|
554
|
+
return 'submitted';
|
|
555
|
+
}
|
|
556
|
+
async readJsonResponse(res, operation) {
|
|
557
|
+
const text = await res.text().catch(() => 'unknown error');
|
|
558
|
+
if (!res.ok) {
|
|
559
|
+
throw new ProviderError(formatAnthropicErrorText(res.status, text), {
|
|
560
|
+
statusCode: res.status,
|
|
561
|
+
provider: this.name,
|
|
562
|
+
operation: `batch.${operation}`,
|
|
563
|
+
phase: 'request',
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
try {
|
|
567
|
+
return JSON.parse(text);
|
|
568
|
+
}
|
|
569
|
+
catch {
|
|
570
|
+
throw new ProviderError(`Anthropic batch ${operation} returned invalid JSON.`, {
|
|
571
|
+
statusCode: 502,
|
|
572
|
+
provider: this.name,
|
|
573
|
+
operation: `batch.${operation}`,
|
|
574
|
+
phase: 'response',
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
parseAnthropicBatchResult(parsed) {
|
|
579
|
+
const customId = typeof parsed['custom_id'] === 'string' ? parsed['custom_id'] : `unknown:${crypto.randomUUID()}`;
|
|
580
|
+
const result = toRecord(parsed['result']);
|
|
581
|
+
const type = typeof result['type'] === 'string' ? result['type'] : '';
|
|
582
|
+
if (type === 'succeeded') {
|
|
583
|
+
const message = toRecord(result['message']);
|
|
584
|
+
return {
|
|
585
|
+
customId,
|
|
586
|
+
status: 'succeeded',
|
|
587
|
+
response: this.anthropicBatchMessageToChatResponse(message),
|
|
588
|
+
raw: parsed,
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
const status = type === 'canceled' ? 'cancelled' : type === 'expired' ? 'expired' : 'failed';
|
|
592
|
+
const error = toRecord(result['error']);
|
|
593
|
+
return {
|
|
594
|
+
customId,
|
|
595
|
+
status,
|
|
596
|
+
error: {
|
|
597
|
+
message: typeof error['message'] === 'string' ? error['message'] : `Anthropic batch request ${type || 'failed'}`,
|
|
598
|
+
...(typeof error['type'] === 'string' ? { code: error['type'] } : {}),
|
|
599
|
+
raw: result,
|
|
600
|
+
},
|
|
601
|
+
raw: parsed,
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
anthropicBatchMessageToChatResponse(message) {
|
|
605
|
+
const content = Array.isArray(message['content'])
|
|
606
|
+
? message['content']
|
|
607
|
+
: [];
|
|
608
|
+
const { text, toolCalls } = fromAnthropicContent(content);
|
|
609
|
+
const usage = toRecord(message['usage']);
|
|
610
|
+
const rawStopReason = typeof message['stop_reason'] === 'string' ? message['stop_reason'] : undefined;
|
|
611
|
+
return {
|
|
612
|
+
content: text,
|
|
613
|
+
toolCalls,
|
|
614
|
+
usage: {
|
|
615
|
+
inputTokens: typeof usage['input_tokens'] === 'number' ? usage['input_tokens'] : 0,
|
|
616
|
+
outputTokens: typeof usage['output_tokens'] === 'number' ? usage['output_tokens'] : 0,
|
|
617
|
+
...(typeof usage['cache_read_input_tokens'] === 'number' ? { cacheReadTokens: usage['cache_read_input_tokens'] } : {}),
|
|
618
|
+
...(typeof usage['cache_creation_input_tokens'] === 'number' ? { cacheWriteTokens: usage['cache_creation_input_tokens'] } : {}),
|
|
619
|
+
},
|
|
620
|
+
stopReason: rawStopReason ? mapAnthropicStopReason(rawStopReason) : (text ? 'completed' : 'unknown'),
|
|
621
|
+
...(rawStopReason ? { providerStopReason: rawStopReason } : {}),
|
|
622
|
+
};
|
|
623
|
+
}
|
|
406
624
|
}
|
|
407
625
|
function formatAnthropicErrorText(status, text) {
|
|
408
626
|
try {
|
|
@@ -48,6 +48,7 @@ export interface ProviderRuntimeMetadata {
|
|
|
48
48
|
readonly toolCalling: boolean;
|
|
49
49
|
readonly parallelTools: boolean;
|
|
50
50
|
readonly promptCaching?: boolean;
|
|
51
|
+
readonly batch?: ProviderBatchRuntimeMetadata;
|
|
51
52
|
readonly cost?: ProviderUsageCostMetadata;
|
|
52
53
|
readonly notes?: readonly string[];
|
|
53
54
|
};
|
|
@@ -83,10 +84,57 @@ export interface ProviderEmbeddingResult {
|
|
|
83
84
|
readonly modelId?: string;
|
|
84
85
|
readonly metadata?: Record<string, unknown>;
|
|
85
86
|
}
|
|
87
|
+
export interface ProviderBatchRuntimeMetadata {
|
|
88
|
+
readonly supported: boolean;
|
|
89
|
+
readonly discount?: string;
|
|
90
|
+
readonly completionWindow?: string;
|
|
91
|
+
readonly endpoints?: readonly string[];
|
|
92
|
+
readonly maxRequestsPerProviderBatch?: number;
|
|
93
|
+
readonly maxInputBytes?: number;
|
|
94
|
+
readonly notes?: readonly string[];
|
|
95
|
+
}
|
|
96
|
+
export type ProviderBatchStatus = 'queued' | 'submitted' | 'running' | 'completed' | 'failed' | 'cancelled' | 'expired';
|
|
97
|
+
export interface ProviderBatchChatRequest {
|
|
98
|
+
readonly customId: string;
|
|
99
|
+
readonly params: Omit<ChatRequest, 'signal' | 'onDelta'>;
|
|
100
|
+
}
|
|
101
|
+
export interface ProviderBatchCreateInput {
|
|
102
|
+
readonly requests: readonly ProviderBatchChatRequest[];
|
|
103
|
+
readonly metadata?: Record<string, string>;
|
|
104
|
+
readonly completionWindow?: '24h';
|
|
105
|
+
}
|
|
106
|
+
export interface ProviderBatchCreateResult {
|
|
107
|
+
readonly providerBatchId: string;
|
|
108
|
+
readonly status: ProviderBatchStatus;
|
|
109
|
+
readonly raw?: unknown;
|
|
110
|
+
}
|
|
111
|
+
export interface ProviderBatchPollResult extends ProviderBatchCreateResult {
|
|
112
|
+
readonly resultAvailable: boolean;
|
|
113
|
+
}
|
|
114
|
+
export interface ProviderBatchResult {
|
|
115
|
+
readonly customId: string;
|
|
116
|
+
readonly status: 'succeeded' | 'failed' | 'cancelled' | 'expired';
|
|
117
|
+
readonly response?: ChatResponse;
|
|
118
|
+
readonly error?: {
|
|
119
|
+
readonly message: string;
|
|
120
|
+
readonly code?: string;
|
|
121
|
+
readonly raw?: unknown;
|
|
122
|
+
};
|
|
123
|
+
readonly raw?: unknown;
|
|
124
|
+
}
|
|
125
|
+
export interface ProviderBatchAdapter {
|
|
126
|
+
readonly kind: 'provider-batch';
|
|
127
|
+
readonly endpoints: readonly string[];
|
|
128
|
+
createChatBatch(input: ProviderBatchCreateInput): Promise<ProviderBatchCreateResult>;
|
|
129
|
+
retrieveBatch(providerBatchId: string): Promise<ProviderBatchPollResult>;
|
|
130
|
+
cancelBatch?(providerBatchId: string): Promise<ProviderBatchPollResult>;
|
|
131
|
+
getResults(providerBatchId: string): Promise<readonly ProviderBatchResult[]>;
|
|
132
|
+
}
|
|
86
133
|
/** Contract all LLM providers must implement. */
|
|
87
134
|
export interface LLMProvider {
|
|
88
135
|
readonly name: string;
|
|
89
136
|
readonly models: string[];
|
|
137
|
+
readonly batch?: ProviderBatchAdapter;
|
|
90
138
|
/**
|
|
91
139
|
* Optional self-declared capability overrides for this provider instance.
|
|
92
140
|
* When present, these take precedence over the built-in `PROVIDER_DEFAULTS`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/providers/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAA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;IACF,wEAAwE;IACxE,UAAU,EAAE,cAAc,CAAC;IAC3B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LLMProvider, ChatRequest, ChatResponse, ProviderEmbeddingRequest, ProviderEmbeddingResult, ProviderRuntimeMetadata, ProviderRuntimeMetadataDeps } from './interface.js';
|
|
1
|
+
import type { LLMProvider, ChatRequest, ChatResponse, ProviderEmbeddingRequest, ProviderEmbeddingResult, ProviderBatchAdapter, ProviderRuntimeMetadata, ProviderRuntimeMetadataDeps } from './interface.js';
|
|
2
2
|
import type { CacheHitTracker } from './cache-strategy.js';
|
|
3
3
|
/**
|
|
4
4
|
* OpenAIProvider — wraps the official `openai` npm package.
|
|
@@ -7,12 +7,24 @@ import type { CacheHitTracker } from './cache-strategy.js';
|
|
|
7
7
|
export declare class OpenAIProvider implements LLMProvider {
|
|
8
8
|
readonly name = "openai";
|
|
9
9
|
readonly models: string[];
|
|
10
|
+
readonly batch: ProviderBatchAdapter;
|
|
10
11
|
private client;
|
|
12
|
+
private readonly apiKey;
|
|
11
13
|
private readonly embeddingModel;
|
|
12
14
|
private readonly cacheHitTracker;
|
|
13
15
|
constructor(apiKey: string, cacheHitTracker?: Pick<CacheHitTracker, 'recordTurn'>);
|
|
14
16
|
chat(params: ChatRequest): Promise<ChatResponse>;
|
|
15
17
|
embed(request: ProviderEmbeddingRequest): Promise<ProviderEmbeddingResult>;
|
|
18
|
+
isConfigured(): boolean;
|
|
16
19
|
describeRuntime(deps: ProviderRuntimeMetadataDeps): Promise<ProviderRuntimeMetadata>;
|
|
20
|
+
private createChatBatch;
|
|
21
|
+
private retrieveBatch;
|
|
22
|
+
private cancelBatch;
|
|
23
|
+
private getBatchResults;
|
|
24
|
+
private toOpenAIBatchChatBody;
|
|
25
|
+
private mapOpenAIBatchStatus;
|
|
26
|
+
private readOpenAIBatchResultFile;
|
|
27
|
+
private parseOpenAIBatchResult;
|
|
28
|
+
private openAIBatchBodyToChatResponse;
|
|
17
29
|
}
|
|
18
30
|
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/providers/openai.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,YAAY,EAEZ,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC5B,MAAM,gBAAgB,CAAC;AAYxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAQ3D;;;GAGG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/providers/openai.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,YAAY,EAEZ,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EAKpB,uBAAuB,EACvB,2BAA2B,EAC5B,MAAM,gBAAgB,CAAC;AAYxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAQ3D;;;GAGG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;IAC/B,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IAErC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4B;IAC3D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAsC;gBAE1D,MAAM,EAAE,MAAM,EAAE,eAAe,GAAE,IAAI,CAAC,eAAe,EAAE,YAAY,CAA0B;IAcnG,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA4HhD,KAAK,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IA8BhF,YAAY,IAAI,OAAO;IAIjB,eAAe,CAAC,IAAI,EAAE,2BAA2B,GAAG,OAAO,CAAC,uBAAuB,CAAC;YA+C5E,eAAe;YAyBf,aAAa;YAUb,WAAW;YAUX,eAAe;IAY7B,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,oBAAoB;YASd,yBAAyB;IAuBvC,OAAO,CAAC,sBAAsB;IA2B9B,OAAO,CAAC,6BAA6B;CAkCtC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import OpenAI from 'openai';
|
|
1
|
+
import OpenAI, { toFile } from 'openai';
|
|
2
2
|
import { mapOpenAIStopReason } from './stop-reason-maps.js';
|
|
3
3
|
import { ProviderError } from '../types/errors.js';
|
|
4
4
|
import { withRetry } from '../utils/retry.js';
|
|
@@ -15,12 +15,23 @@ const NOOP_CACHE_HIT_TRACKER = {
|
|
|
15
15
|
export class OpenAIProvider {
|
|
16
16
|
name = 'openai';
|
|
17
17
|
models = [];
|
|
18
|
+
batch;
|
|
18
19
|
client;
|
|
20
|
+
apiKey;
|
|
19
21
|
embeddingModel = 'text-embedding-3-small';
|
|
20
22
|
cacheHitTracker;
|
|
21
23
|
constructor(apiKey, cacheHitTracker = NOOP_CACHE_HIT_TRACKER) {
|
|
24
|
+
this.apiKey = apiKey;
|
|
22
25
|
this.client = new OpenAI({ apiKey });
|
|
23
26
|
this.cacheHitTracker = cacheHitTracker;
|
|
27
|
+
this.batch = {
|
|
28
|
+
kind: 'provider-batch',
|
|
29
|
+
endpoints: ['/v1/chat/completions'],
|
|
30
|
+
createChatBatch: (input) => this.createChatBatch(input),
|
|
31
|
+
retrieveBatch: (providerBatchId) => this.retrieveBatch(providerBatchId),
|
|
32
|
+
cancelBatch: (providerBatchId) => this.cancelBatch(providerBatchId),
|
|
33
|
+
getResults: (providerBatchId) => this.getBatchResults(providerBatchId),
|
|
34
|
+
};
|
|
24
35
|
}
|
|
25
36
|
async chat(params) {
|
|
26
37
|
const { messages, tools, model, maxTokens, signal, systemPrompt, onDelta, reasoningEffort: _reasoningEffort } = params;
|
|
@@ -163,6 +174,9 @@ export class OpenAIProvider {
|
|
|
163
174
|
},
|
|
164
175
|
};
|
|
165
176
|
}
|
|
177
|
+
isConfigured() {
|
|
178
|
+
return this.apiKey.trim().length > 0;
|
|
179
|
+
}
|
|
166
180
|
async describeRuntime(deps) {
|
|
167
181
|
const configured = Boolean(process.env.OPENAI_API_KEY || process.env.OPENAI_KEY);
|
|
168
182
|
const { buildStandardProviderAuthRoutes } = await import('./runtime-metadata.js');
|
|
@@ -189,6 +203,15 @@ export class OpenAIProvider {
|
|
|
189
203
|
streaming: true,
|
|
190
204
|
toolCalling: true,
|
|
191
205
|
parallelTools: true,
|
|
206
|
+
batch: {
|
|
207
|
+
supported: true,
|
|
208
|
+
discount: 'Provider-side Batch API pricing is discounted versus live API pricing where OpenAI offers the discount.',
|
|
209
|
+
completionWindow: '24h',
|
|
210
|
+
endpoints: ['/v1/chat/completions'],
|
|
211
|
+
maxRequestsPerProviderBatch: 50_000,
|
|
212
|
+
maxInputBytes: 200 * 1024 * 1024,
|
|
213
|
+
notes: ['Batch requests are asynchronous and non-streaming. Results are correlated by custom_id.'],
|
|
214
|
+
},
|
|
192
215
|
notes: ['Embeddings use the OpenAI embeddings API.'],
|
|
193
216
|
},
|
|
194
217
|
policy: {
|
|
@@ -200,4 +223,169 @@ export class OpenAIProvider {
|
|
|
200
223
|
},
|
|
201
224
|
};
|
|
202
225
|
}
|
|
226
|
+
async createChatBatch(input) {
|
|
227
|
+
const lines = input.requests.map((request) => JSON.stringify({
|
|
228
|
+
custom_id: request.customId,
|
|
229
|
+
method: 'POST',
|
|
230
|
+
url: '/v1/chat/completions',
|
|
231
|
+
body: this.toOpenAIBatchChatBody(request.params),
|
|
232
|
+
})).join('\n') + '\n';
|
|
233
|
+
const file = await this.client.files.create({
|
|
234
|
+
file: await toFile(new Blob([lines], { type: 'application/jsonl' }), 'goodvibes-openai-chat-batch.jsonl'),
|
|
235
|
+
purpose: 'batch',
|
|
236
|
+
});
|
|
237
|
+
const metadata = input.metadata && Object.keys(input.metadata).length > 0 ? input.metadata : undefined;
|
|
238
|
+
const batch = await this.client.batches.create({
|
|
239
|
+
input_file_id: file.id,
|
|
240
|
+
endpoint: '/v1/chat/completions',
|
|
241
|
+
completion_window: input.completionWindow ?? '24h',
|
|
242
|
+
...(metadata ? { metadata } : {}),
|
|
243
|
+
});
|
|
244
|
+
return {
|
|
245
|
+
providerBatchId: batch.id,
|
|
246
|
+
status: this.mapOpenAIBatchStatus(batch.status),
|
|
247
|
+
raw: batch,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
async retrieveBatch(providerBatchId) {
|
|
251
|
+
const batch = await this.client.batches.retrieve(providerBatchId);
|
|
252
|
+
return {
|
|
253
|
+
providerBatchId: batch.id,
|
|
254
|
+
status: this.mapOpenAIBatchStatus(batch.status),
|
|
255
|
+
resultAvailable: typeof batch.output_file_id === 'string' || typeof batch.error_file_id === 'string',
|
|
256
|
+
raw: batch,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
async cancelBatch(providerBatchId) {
|
|
260
|
+
const batch = await this.client.batches.cancel(providerBatchId);
|
|
261
|
+
return {
|
|
262
|
+
providerBatchId: batch.id,
|
|
263
|
+
status: this.mapOpenAIBatchStatus(batch.status),
|
|
264
|
+
resultAvailable: typeof batch.output_file_id === 'string' || typeof batch.error_file_id === 'string',
|
|
265
|
+
raw: batch,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
async getBatchResults(providerBatchId) {
|
|
269
|
+
const batch = await this.client.batches.retrieve(providerBatchId);
|
|
270
|
+
const results = [];
|
|
271
|
+
if (typeof batch.output_file_id === 'string' && batch.output_file_id.length > 0) {
|
|
272
|
+
results.push(...await this.readOpenAIBatchResultFile(batch.output_file_id, false));
|
|
273
|
+
}
|
|
274
|
+
if (typeof batch.error_file_id === 'string' && batch.error_file_id.length > 0) {
|
|
275
|
+
results.push(...await this.readOpenAIBatchResultFile(batch.error_file_id, true));
|
|
276
|
+
}
|
|
277
|
+
return results;
|
|
278
|
+
}
|
|
279
|
+
toOpenAIBatchChatBody(params) {
|
|
280
|
+
const openaiMessages = toOpenAIMessages(params.messages, params.systemPrompt);
|
|
281
|
+
const openaiTools = params.tools && params.tools.length > 0 ? toOpenAITools(params.tools) : undefined;
|
|
282
|
+
return {
|
|
283
|
+
model: params.model,
|
|
284
|
+
messages: openaiMessages,
|
|
285
|
+
...(openaiTools ? { tools: openaiTools } : {}),
|
|
286
|
+
...(params.maxTokens ? { max_tokens: params.maxTokens } : {}),
|
|
287
|
+
stream: false,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
mapOpenAIBatchStatus(status) {
|
|
291
|
+
if (status === 'completed')
|
|
292
|
+
return 'completed';
|
|
293
|
+
if (status === 'failed')
|
|
294
|
+
return 'failed';
|
|
295
|
+
if (status === 'cancelled' || status === 'cancelling')
|
|
296
|
+
return 'cancelled';
|
|
297
|
+
if (status === 'expired')
|
|
298
|
+
return 'expired';
|
|
299
|
+
if (status === 'in_progress' || status === 'finalizing')
|
|
300
|
+
return 'running';
|
|
301
|
+
return 'submitted';
|
|
302
|
+
}
|
|
303
|
+
async readOpenAIBatchResultFile(fileId, forceFailed) {
|
|
304
|
+
const response = await this.client.files.content(fileId);
|
|
305
|
+
const text = await response.text();
|
|
306
|
+
const lines = text.split('\n').map((line) => line.trim()).filter(Boolean);
|
|
307
|
+
const results = [];
|
|
308
|
+
for (const line of lines) {
|
|
309
|
+
try {
|
|
310
|
+
const parsed = JSON.parse(line);
|
|
311
|
+
results.push(this.parseOpenAIBatchResult(parsed, forceFailed));
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
results.push({
|
|
315
|
+
customId: `unparseable:${crypto.randomUUID()}`,
|
|
316
|
+
status: 'failed',
|
|
317
|
+
error: {
|
|
318
|
+
message: `Unable to parse OpenAI batch result line: ${summarizeError(error)}`,
|
|
319
|
+
},
|
|
320
|
+
raw: line,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return results;
|
|
325
|
+
}
|
|
326
|
+
parseOpenAIBatchResult(parsed, forceFailed) {
|
|
327
|
+
const customId = typeof parsed['custom_id'] === 'string' ? parsed['custom_id'] : `unknown:${crypto.randomUUID()}`;
|
|
328
|
+
const response = toRecord(parsed['response']);
|
|
329
|
+
const statusCode = typeof response['status_code'] === 'number' ? response['status_code'] : 0;
|
|
330
|
+
const body = toRecord(response['body']);
|
|
331
|
+
const error = parsed['error'] ?? body['error'];
|
|
332
|
+
if (forceFailed || statusCode >= 400 || error !== undefined) {
|
|
333
|
+
const errorRecord = toRecord(error);
|
|
334
|
+
return {
|
|
335
|
+
customId,
|
|
336
|
+
status: 'failed',
|
|
337
|
+
error: {
|
|
338
|
+
message: typeof errorRecord['message'] === 'string' ? errorRecord['message'] : `OpenAI batch request failed${statusCode ? ` with status ${statusCode}` : ''}`,
|
|
339
|
+
...(typeof errorRecord['code'] === 'string' ? { code: errorRecord['code'] } : {}),
|
|
340
|
+
raw: error ?? parsed,
|
|
341
|
+
},
|
|
342
|
+
raw: parsed,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
customId,
|
|
347
|
+
status: 'succeeded',
|
|
348
|
+
response: this.openAIBatchBodyToChatResponse(body),
|
|
349
|
+
raw: parsed,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
openAIBatchBodyToChatResponse(body) {
|
|
353
|
+
const choices = Array.isArray(body['choices']) ? body['choices'] : [];
|
|
354
|
+
const firstChoice = toRecord(choices[0]);
|
|
355
|
+
const message = toRecord(firstChoice['message']);
|
|
356
|
+
const content = message['content'];
|
|
357
|
+
const responseText = typeof content === 'string'
|
|
358
|
+
? content
|
|
359
|
+
: Array.isArray(content)
|
|
360
|
+
? content.map((part) => {
|
|
361
|
+
const record = toRecord(part);
|
|
362
|
+
return typeof record['text'] === 'string' ? record['text'] : '';
|
|
363
|
+
}).join('')
|
|
364
|
+
: '';
|
|
365
|
+
const rawToolCalls = Array.isArray(message['tool_calls'])
|
|
366
|
+
? message['tool_calls'].map((entry) => toRecord(entry))
|
|
367
|
+
: [];
|
|
368
|
+
const usage = toRecord(body['usage']);
|
|
369
|
+
const promptDetails = toRecord(usage['prompt_tokens_details']);
|
|
370
|
+
const rawFinishReason = typeof firstChoice['finish_reason'] === 'string' ? firstChoice['finish_reason'] : undefined;
|
|
371
|
+
const stopReason = rawFinishReason ? mapOpenAIStopReason(rawFinishReason) : (responseText ? 'completed' : 'unknown');
|
|
372
|
+
return {
|
|
373
|
+
content: responseText,
|
|
374
|
+
toolCalls: rawToolCalls.length > 0 ? fromOpenAIToolCalls(rawToolCalls) : [],
|
|
375
|
+
usage: {
|
|
376
|
+
inputTokens: typeof usage['prompt_tokens'] === 'number' ? usage['prompt_tokens'] : 0,
|
|
377
|
+
outputTokens: typeof usage['completion_tokens'] === 'number' ? usage['completion_tokens'] : 0,
|
|
378
|
+
...(typeof promptDetails['cached_tokens'] === 'number' && promptDetails['cached_tokens'] > 0
|
|
379
|
+
? { cacheReadTokens: promptDetails['cached_tokens'] }
|
|
380
|
+
: {}),
|
|
381
|
+
},
|
|
382
|
+
stopReason,
|
|
383
|
+
...(rawFinishReason ? { providerStopReason: rawFinishReason } : {}),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function toRecord(value) {
|
|
388
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
389
|
+
? value
|
|
390
|
+
: {};
|
|
203
391
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
let version = '0.25.
|
|
3
|
+
let version = '0.25.8';
|
|
4
4
|
try {
|
|
5
5
|
const pkg = JSON.parse(readFileSync(join(import.meta.dir, '..', '..', 'package.json'), 'utf-8'));
|
|
6
6
|
version = pkg.version ?? version;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { VoiceAudioArtifact, VoiceAudioFormat, VoiceDescriptor, VoiceProvider, VoiceProviderCapability, VoiceProviderState, VoiceProviderStatus, VoiceRealtimeSession, VoiceRealtimeSessionRequest, VoiceSynthesisRequest, VoiceSynthesisResult, VoiceTranscriptionRequest, VoiceTranscriptionResult, } from './types.js';
|
|
1
|
+
export type { VoiceAudioArtifact, VoiceAudioChunk, VoiceAudioFormat, VoiceDescriptor, VoiceProvider, VoiceProviderCapability, VoiceProviderState, VoiceProviderStatus, VoiceRealtimeSession, VoiceRealtimeSessionRequest, VoiceSynthesisRequest, VoiceSynthesisResult, VoiceSynthesisStreamResult, VoiceTranscriptionRequest, VoiceTranscriptionResult, } from './types.js';
|
|
2
2
|
export { VoiceProviderRegistry } from './provider-registry.js';
|
|
3
3
|
export type { VoiceProviderDescriptor } from './provider-registry.js';
|
|
4
4
|
export { VoiceService } from './service.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/voice/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/voice/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elevenlabs.d.ts","sourceRoot":"","sources":["../../../../../src/_internal/platform/voice/providers/elevenlabs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"elevenlabs.d.ts","sourceRoot":"","sources":["../../../../../src/_internal/platform/voice/providers/elevenlabs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,aAAa,EAKd,MAAM,aAAa,CAAC;AA0LrB,wBAAgB,wBAAwB,IAAI,aAAa,CAgWxD"}
|