@contractspec/integration.providers-impls 2.9.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/dist/health.d.ts +1 -0
- package/dist/health.js +3 -0
- package/dist/impls/async-event-queue.d.ts +8 -0
- package/dist/impls/async-event-queue.js +47 -0
- package/dist/impls/health/base-health-provider.d.ts +98 -0
- package/dist/impls/health/base-health-provider.js +616 -0
- package/dist/impls/health/hybrid-health-providers.d.ts +34 -0
- package/dist/impls/health/hybrid-health-providers.js +1088 -0
- package/dist/impls/health/official-health-providers.d.ts +78 -0
- package/dist/impls/health/official-health-providers.js +968 -0
- package/dist/impls/health/provider-normalizers.d.ts +28 -0
- package/dist/impls/health/provider-normalizers.js +287 -0
- package/dist/impls/health/providers.d.ts +2 -0
- package/dist/impls/health/providers.js +1094 -0
- package/dist/impls/health-provider-factory.d.ts +3 -0
- package/dist/impls/health-provider-factory.js +1308 -0
- package/dist/impls/index.d.ts +8 -0
- package/dist/impls/index.js +2356 -176
- package/dist/impls/messaging-github.d.ts +17 -0
- package/dist/impls/messaging-github.js +110 -0
- package/dist/impls/messaging-slack.d.ts +14 -0
- package/dist/impls/messaging-slack.js +80 -0
- package/dist/impls/messaging-whatsapp-meta.d.ts +13 -0
- package/dist/impls/messaging-whatsapp-meta.js +52 -0
- package/dist/impls/messaging-whatsapp-twilio.d.ts +13 -0
- package/dist/impls/messaging-whatsapp-twilio.js +82 -0
- package/dist/impls/mistral-conversational.d.ts +23 -0
- package/dist/impls/mistral-conversational.js +476 -0
- package/dist/impls/mistral-conversational.session.d.ts +32 -0
- package/dist/impls/mistral-conversational.session.js +206 -0
- package/dist/impls/mistral-stt.d.ts +17 -0
- package/dist/impls/mistral-stt.js +167 -0
- package/dist/impls/provider-factory.d.ts +7 -1
- package/dist/impls/provider-factory.js +2338 -176
- package/dist/impls/stripe-payments.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2360 -174
- package/dist/messaging.d.ts +1 -0
- package/dist/messaging.js +3 -0
- package/dist/node/health.js +2 -0
- package/dist/node/impls/async-event-queue.js +46 -0
- package/dist/node/impls/health/base-health-provider.js +615 -0
- package/dist/node/impls/health/hybrid-health-providers.js +1087 -0
- package/dist/node/impls/health/official-health-providers.js +967 -0
- package/dist/node/impls/health/provider-normalizers.js +286 -0
- package/dist/node/impls/health/providers.js +1093 -0
- package/dist/node/impls/health-provider-factory.js +1307 -0
- package/dist/node/impls/index.js +2356 -176
- package/dist/node/impls/messaging-github.js +109 -0
- package/dist/node/impls/messaging-slack.js +79 -0
- package/dist/node/impls/messaging-whatsapp-meta.js +51 -0
- package/dist/node/impls/messaging-whatsapp-twilio.js +81 -0
- package/dist/node/impls/mistral-conversational.js +475 -0
- package/dist/node/impls/mistral-conversational.session.js +205 -0
- package/dist/node/impls/mistral-stt.js +166 -0
- package/dist/node/impls/provider-factory.js +2338 -176
- package/dist/node/impls/stripe-payments.js +1 -1
- package/dist/node/index.js +2360 -174
- package/dist/node/messaging.js +2 -0
- package/package.json +204 -12
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { STTProvider, STTTranscriptionInput, STTTranscriptionResult } from '../voice';
|
|
2
|
+
export interface MistralSttProviderOptions {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
defaultModel?: string;
|
|
5
|
+
defaultLanguage?: string;
|
|
6
|
+
serverURL?: string;
|
|
7
|
+
fetchImpl?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
export declare class MistralSttProvider implements STTProvider {
|
|
10
|
+
private readonly apiKey;
|
|
11
|
+
private readonly defaultModel;
|
|
12
|
+
private readonly defaultLanguage?;
|
|
13
|
+
private readonly baseUrl;
|
|
14
|
+
private readonly fetchImpl;
|
|
15
|
+
constructor(options: MistralSttProviderOptions);
|
|
16
|
+
transcribe(input: STTTranscriptionInput): Promise<STTTranscriptionResult>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/impls/mistral-stt.ts
|
|
3
|
+
var DEFAULT_BASE_URL = "https://api.mistral.ai/v1";
|
|
4
|
+
var DEFAULT_MODEL = "voxtral-mini-latest";
|
|
5
|
+
var AUDIO_MIME_BY_FORMAT = {
|
|
6
|
+
mp3: "audio/mpeg",
|
|
7
|
+
wav: "audio/wav",
|
|
8
|
+
ogg: "audio/ogg",
|
|
9
|
+
pcm: "audio/pcm",
|
|
10
|
+
opus: "audio/opus"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
class MistralSttProvider {
|
|
14
|
+
apiKey;
|
|
15
|
+
defaultModel;
|
|
16
|
+
defaultLanguage;
|
|
17
|
+
baseUrl;
|
|
18
|
+
fetchImpl;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
if (!options.apiKey) {
|
|
21
|
+
throw new Error("MistralSttProvider requires an apiKey");
|
|
22
|
+
}
|
|
23
|
+
this.apiKey = options.apiKey;
|
|
24
|
+
this.defaultModel = options.defaultModel ?? DEFAULT_MODEL;
|
|
25
|
+
this.defaultLanguage = options.defaultLanguage;
|
|
26
|
+
this.baseUrl = normalizeBaseUrl(options.serverURL ?? DEFAULT_BASE_URL);
|
|
27
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
28
|
+
}
|
|
29
|
+
async transcribe(input) {
|
|
30
|
+
const formData = new FormData;
|
|
31
|
+
const model = input.model ?? this.defaultModel;
|
|
32
|
+
const mimeType = AUDIO_MIME_BY_FORMAT[input.audio.format] ?? "audio/wav";
|
|
33
|
+
const fileName = `audio.${input.audio.format}`;
|
|
34
|
+
const audioBytes = new Uint8Array(input.audio.data);
|
|
35
|
+
const blob = new Blob([audioBytes], { type: mimeType });
|
|
36
|
+
formData.append("file", blob, fileName);
|
|
37
|
+
formData.append("model", model);
|
|
38
|
+
formData.append("response_format", "verbose_json");
|
|
39
|
+
const language = input.language ?? this.defaultLanguage;
|
|
40
|
+
if (language) {
|
|
41
|
+
formData.append("language", language);
|
|
42
|
+
}
|
|
43
|
+
const response = await this.fetchImpl(`${this.baseUrl}/audio/transcriptions`, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
47
|
+
},
|
|
48
|
+
body: formData
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const body = await response.text();
|
|
52
|
+
throw new Error(`Mistral transcription request failed (${response.status}): ${body}`);
|
|
53
|
+
}
|
|
54
|
+
const payload = await response.json();
|
|
55
|
+
return toTranscriptionResult(payload, input);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function toTranscriptionResult(payload, input) {
|
|
59
|
+
const record = asRecord(payload);
|
|
60
|
+
const text = readString(record, "text") ?? "";
|
|
61
|
+
const language = readString(record, "language") ?? input.language ?? "unknown";
|
|
62
|
+
const segments = parseSegments(record);
|
|
63
|
+
if (segments.length === 0 && text.length > 0) {
|
|
64
|
+
segments.push({
|
|
65
|
+
text,
|
|
66
|
+
startMs: 0,
|
|
67
|
+
endMs: input.audio.durationMs ?? 0
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const durationMs = input.audio.durationMs ?? segments.reduce((max, segment) => Math.max(max, segment.endMs), 0);
|
|
71
|
+
const topLevelWords = parseWordTimings(record.words);
|
|
72
|
+
const flattenedWords = segments.flatMap((segment) => segment.wordTimings ?? []);
|
|
73
|
+
const wordTimings = topLevelWords.length > 0 ? topLevelWords : flattenedWords.length > 0 ? flattenedWords : undefined;
|
|
74
|
+
const speakers = dedupeSpeakers(segments);
|
|
75
|
+
return {
|
|
76
|
+
text,
|
|
77
|
+
segments,
|
|
78
|
+
language,
|
|
79
|
+
durationMs,
|
|
80
|
+
speakers: speakers.length > 0 ? speakers : undefined,
|
|
81
|
+
wordTimings
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function parseSegments(record) {
|
|
85
|
+
if (!Array.isArray(record.segments)) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
const parsed = [];
|
|
89
|
+
for (const entry of record.segments) {
|
|
90
|
+
const segmentRecord = asRecord(entry);
|
|
91
|
+
const text = readString(segmentRecord, "text");
|
|
92
|
+
if (!text) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const startSeconds = readNumber(segmentRecord, "start") ?? 0;
|
|
96
|
+
const endSeconds = readNumber(segmentRecord, "end") ?? startSeconds;
|
|
97
|
+
parsed.push({
|
|
98
|
+
text,
|
|
99
|
+
startMs: secondsToMs(startSeconds),
|
|
100
|
+
endMs: secondsToMs(endSeconds),
|
|
101
|
+
speakerId: readString(segmentRecord, "speaker") ?? undefined,
|
|
102
|
+
confidence: readNumber(segmentRecord, "confidence"),
|
|
103
|
+
wordTimings: parseWordTimings(segmentRecord.words)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return parsed;
|
|
107
|
+
}
|
|
108
|
+
function parseWordTimings(value) {
|
|
109
|
+
if (!Array.isArray(value)) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
const words = [];
|
|
113
|
+
for (const entry of value) {
|
|
114
|
+
const wordRecord = asRecord(entry);
|
|
115
|
+
const word = readString(wordRecord, "word");
|
|
116
|
+
const startSeconds = readNumber(wordRecord, "start");
|
|
117
|
+
const endSeconds = readNumber(wordRecord, "end");
|
|
118
|
+
if (!word || startSeconds == null || endSeconds == null) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
words.push({
|
|
122
|
+
word,
|
|
123
|
+
startMs: secondsToMs(startSeconds),
|
|
124
|
+
endMs: secondsToMs(endSeconds),
|
|
125
|
+
confidence: readNumber(wordRecord, "confidence")
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return words;
|
|
129
|
+
}
|
|
130
|
+
function dedupeSpeakers(segments) {
|
|
131
|
+
const seen = new Set;
|
|
132
|
+
const speakers = [];
|
|
133
|
+
for (const segment of segments) {
|
|
134
|
+
if (!segment.speakerId || seen.has(segment.speakerId)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
seen.add(segment.speakerId);
|
|
138
|
+
speakers.push({
|
|
139
|
+
id: segment.speakerId,
|
|
140
|
+
name: segment.speakerName
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return speakers;
|
|
144
|
+
}
|
|
145
|
+
function normalizeBaseUrl(url) {
|
|
146
|
+
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
147
|
+
}
|
|
148
|
+
function asRecord(value) {
|
|
149
|
+
if (value && typeof value === "object") {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
function readString(record, key) {
|
|
155
|
+
const value = record[key];
|
|
156
|
+
return typeof value === "string" ? value : undefined;
|
|
157
|
+
}
|
|
158
|
+
function readNumber(record, key) {
|
|
159
|
+
const value = record[key];
|
|
160
|
+
return typeof value === "number" ? value : undefined;
|
|
161
|
+
}
|
|
162
|
+
function secondsToMs(value) {
|
|
163
|
+
return Math.round(value * 1000);
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
MistralSttProvider
|
|
167
|
+
};
|
|
@@ -2,29 +2,35 @@ import type { IntegrationContext } from '@contractspec/integration.runtime/runti
|
|
|
2
2
|
import type { PaymentsProvider } from '../payments';
|
|
3
3
|
import type { EmailOutboundProvider } from '../email';
|
|
4
4
|
import type { SmsProvider } from '../sms';
|
|
5
|
+
import type { MessagingProvider } from '../messaging';
|
|
5
6
|
import type { VectorStoreProvider } from '../vector-store';
|
|
6
7
|
import type { AnalyticsProvider } from '../analytics';
|
|
7
8
|
import type { DatabaseProvider } from '../database';
|
|
8
9
|
import type { ObjectStorageProvider } from '../storage';
|
|
9
|
-
import type { TTSProvider } from '../voice';
|
|
10
|
+
import type { ConversationalProvider, STTProvider, TTSProvider } from '../voice';
|
|
10
11
|
import type { LLMProvider } from '../llm';
|
|
11
12
|
import type { EmbeddingProvider } from '../embedding';
|
|
12
13
|
import type { OpenBankingProvider } from '../openbanking';
|
|
13
14
|
import type { ProjectManagementProvider } from '../project-management';
|
|
14
15
|
import type { MeetingRecorderProvider } from '../meeting-recorder';
|
|
16
|
+
import type { HealthProvider } from '../health';
|
|
15
17
|
export declare class IntegrationProviderFactory {
|
|
16
18
|
createPaymentsProvider(context: IntegrationContext): Promise<PaymentsProvider>;
|
|
17
19
|
createEmailOutboundProvider(context: IntegrationContext): Promise<EmailOutboundProvider>;
|
|
18
20
|
createSmsProvider(context: IntegrationContext): Promise<SmsProvider>;
|
|
21
|
+
createMessagingProvider(context: IntegrationContext): Promise<MessagingProvider>;
|
|
19
22
|
createVectorStoreProvider(context: IntegrationContext): Promise<VectorStoreProvider>;
|
|
20
23
|
createAnalyticsProvider(context: IntegrationContext): Promise<AnalyticsProvider>;
|
|
21
24
|
createDatabaseProvider(context: IntegrationContext): Promise<DatabaseProvider>;
|
|
22
25
|
createObjectStorageProvider(context: IntegrationContext): Promise<ObjectStorageProvider>;
|
|
23
26
|
createVoiceProvider(context: IntegrationContext): Promise<TTSProvider>;
|
|
27
|
+
createSttProvider(context: IntegrationContext): Promise<STTProvider>;
|
|
28
|
+
createConversationalProvider(context: IntegrationContext): Promise<ConversationalProvider>;
|
|
24
29
|
createProjectManagementProvider(context: IntegrationContext): Promise<ProjectManagementProvider>;
|
|
25
30
|
createMeetingRecorderProvider(context: IntegrationContext): Promise<MeetingRecorderProvider>;
|
|
26
31
|
createLlmProvider(context: IntegrationContext): Promise<LLMProvider>;
|
|
27
32
|
createEmbeddingProvider(context: IntegrationContext): Promise<EmbeddingProvider>;
|
|
28
33
|
createOpenBankingProvider(context: IntegrationContext): Promise<OpenBankingProvider>;
|
|
34
|
+
createHealthProvider(context: IntegrationContext): Promise<HealthProvider>;
|
|
29
35
|
private loadSecrets;
|
|
30
36
|
}
|