@contractspec/integration.providers-impls 3.7.6 → 3.8.2

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.
Files changed (36) hide show
  1. package/README.md +80 -241
  2. package/dist/impls/composio-fallback-resolver.d.ts +4 -4
  3. package/dist/impls/composio-fallback-resolver.js +73 -73
  4. package/dist/impls/composio-mcp.d.ts +1 -1
  5. package/dist/impls/composio-proxies.d.ts +5 -5
  6. package/dist/impls/composio-sdk.d.ts +1 -1
  7. package/dist/impls/elevenlabs-voice.d.ts +1 -1
  8. package/dist/impls/fal-voice.d.ts +1 -1
  9. package/dist/impls/gcs-storage.d.ts +1 -1
  10. package/dist/impls/gmail-inbound.d.ts +1 -1
  11. package/dist/impls/gradium-voice.d.ts +2 -2
  12. package/dist/impls/health/base-health-provider.d.ts +1 -1
  13. package/dist/impls/health/official-health-providers.d.ts +1 -1
  14. package/dist/impls/health/providers.d.ts +1 -1
  15. package/dist/impls/health-provider-factory.d.ts +1 -1
  16. package/dist/impls/index.d.ts +31 -30
  17. package/dist/impls/index.js +2189 -2138
  18. package/dist/impls/messaging-telegram.d.ts +13 -0
  19. package/dist/impls/messaging-telegram.js +49 -0
  20. package/dist/impls/mistral-conversational.d.ts +1 -1
  21. package/dist/impls/mistral-conversational.js +159 -159
  22. package/dist/impls/posthog-reader.d.ts +1 -1
  23. package/dist/impls/provider-factory.d.ts +11 -11
  24. package/dist/impls/provider-factory.js +2116 -2066
  25. package/dist/index.d.ts +12 -12
  26. package/dist/index.js +2197 -2146
  27. package/dist/node/impls/composio-fallback-resolver.js +73 -73
  28. package/dist/node/impls/index.js +2189 -2138
  29. package/dist/node/impls/messaging-telegram.js +49 -0
  30. package/dist/node/impls/mistral-conversational.js +159 -159
  31. package/dist/node/impls/provider-factory.js +2116 -2066
  32. package/dist/node/index.js +2197 -2146
  33. package/dist/node/secrets/provider.js +2 -2
  34. package/dist/secrets/provider.d.ts +2 -2
  35. package/dist/secrets/provider.js +2 -2
  36. package/package.json +25 -13
@@ -0,0 +1,13 @@
1
+ import type { MessagingProvider, MessagingSendInput, MessagingSendResult } from '../messaging';
2
+ export interface TelegramMessagingProviderOptions {
3
+ botToken: string;
4
+ defaultChatId?: string;
5
+ apiBaseUrl?: string;
6
+ }
7
+ export declare class TelegramMessagingProvider implements MessagingProvider {
8
+ private readonly botToken;
9
+ private readonly defaultChatId?;
10
+ private readonly apiBaseUrl;
11
+ constructor(options: TelegramMessagingProviderOptions);
12
+ sendMessage(input: MessagingSendInput): Promise<MessagingSendResult>;
13
+ }
@@ -0,0 +1,49 @@
1
+ // @bun
2
+ var __require = import.meta.require;
3
+
4
+ // src/impls/messaging-telegram.ts
5
+ class TelegramMessagingProvider {
6
+ botToken;
7
+ defaultChatId;
8
+ apiBaseUrl;
9
+ constructor(options) {
10
+ this.botToken = options.botToken;
11
+ this.defaultChatId = options.defaultChatId;
12
+ this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
13
+ }
14
+ async sendMessage(input) {
15
+ const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
16
+ if (!chatId) {
17
+ throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
18
+ }
19
+ const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
20
+ const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
21
+ method: "POST",
22
+ headers: {
23
+ "content-type": "application/json"
24
+ },
25
+ body: JSON.stringify({
26
+ chat_id: chatId,
27
+ text: input.text,
28
+ message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
29
+ })
30
+ });
31
+ const body = await response.json();
32
+ const providerMessageId = body.result?.message_id;
33
+ if (!response.ok || !body.ok || providerMessageId == null) {
34
+ throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
35
+ }
36
+ return {
37
+ id: `telegram:${chatId}:${providerMessageId}`,
38
+ providerMessageId: String(providerMessageId),
39
+ status: "sent",
40
+ sentAt: new Date,
41
+ metadata: {
42
+ chatId: String(body.result?.chat?.id ?? chatId)
43
+ }
44
+ };
45
+ }
46
+ }
47
+ export {
48
+ TelegramMessagingProvider
49
+ };
@@ -1,5 +1,5 @@
1
- import { type MistralSttProviderOptions } from './mistral-stt';
2
1
  import type { ConversationalProvider, ConversationalSession, ConversationalSessionConfig, STTProvider, Voice } from '../voice';
2
+ import { type MistralSttProviderOptions } from './mistral-stt';
3
3
  export interface MistralConversationalProviderOptions {
4
4
  apiKey: string;
5
5
  defaultModel?: string;
@@ -45,6 +45,165 @@ class AsyncEventQueue {
45
45
  }
46
46
  }
47
47
 
48
+ // src/impls/mistral-conversational.session.ts
49
+ class MistralConversationSession {
50
+ events;
51
+ queue = new AsyncEventQueue;
52
+ turns = [];
53
+ history = [];
54
+ sessionId = crypto.randomUUID();
55
+ startedAt = Date.now();
56
+ sessionConfig;
57
+ defaultModel;
58
+ complete;
59
+ sttProvider;
60
+ pending = Promise.resolve();
61
+ closed = false;
62
+ closedSummary;
63
+ constructor(options) {
64
+ this.sessionConfig = options.sessionConfig;
65
+ this.defaultModel = options.defaultModel;
66
+ this.complete = options.complete;
67
+ this.sttProvider = options.sttProvider;
68
+ this.events = this.queue;
69
+ this.queue.push({
70
+ type: "session_started",
71
+ sessionId: this.sessionId
72
+ });
73
+ }
74
+ sendAudio(chunk) {
75
+ if (this.closed) {
76
+ return;
77
+ }
78
+ this.pending = this.pending.then(async () => {
79
+ const transcription = await this.sttProvider.transcribe({
80
+ audio: {
81
+ data: chunk,
82
+ format: this.sessionConfig.inputFormat ?? "pcm",
83
+ sampleRateHz: 16000
84
+ },
85
+ language: this.sessionConfig.language
86
+ });
87
+ const transcriptText = transcription.text.trim();
88
+ if (transcriptText.length > 0) {
89
+ await this.handleUserText(transcriptText);
90
+ }
91
+ }).catch((error) => {
92
+ this.emitError(error);
93
+ });
94
+ }
95
+ sendText(text) {
96
+ if (this.closed) {
97
+ return;
98
+ }
99
+ const normalized = text.trim();
100
+ if (normalized.length === 0) {
101
+ return;
102
+ }
103
+ this.pending = this.pending.then(() => this.handleUserText(normalized)).catch((error) => {
104
+ this.emitError(error);
105
+ });
106
+ }
107
+ interrupt() {
108
+ if (this.closed) {
109
+ return;
110
+ }
111
+ this.queue.push({
112
+ type: "error",
113
+ error: new Error("Interrupt is not supported for non-streaming sessions.")
114
+ });
115
+ }
116
+ async close() {
117
+ if (this.closedSummary) {
118
+ return this.closedSummary;
119
+ }
120
+ this.closed = true;
121
+ await this.pending;
122
+ const durationMs = Date.now() - this.startedAt;
123
+ const summary = {
124
+ sessionId: this.sessionId,
125
+ durationMs,
126
+ turns: this.turns.map((turn) => ({
127
+ role: turn.role === "assistant" ? "agent" : turn.role,
128
+ text: turn.text,
129
+ startMs: turn.startMs,
130
+ endMs: turn.endMs
131
+ })),
132
+ transcript: this.turns.map((turn) => `${turn.role}: ${turn.text}`).join(`
133
+ `)
134
+ };
135
+ this.closedSummary = summary;
136
+ this.queue.push({
137
+ type: "session_ended",
138
+ reason: "closed_by_client",
139
+ durationMs
140
+ });
141
+ this.queue.close();
142
+ return summary;
143
+ }
144
+ async handleUserText(text) {
145
+ if (this.closed) {
146
+ return;
147
+ }
148
+ const userStart = Date.now();
149
+ this.queue.push({ type: "user_speech_started" });
150
+ this.queue.push({ type: "user_speech_ended", transcript: text });
151
+ this.queue.push({
152
+ type: "transcript",
153
+ role: "user",
154
+ text,
155
+ timestamp: userStart
156
+ });
157
+ this.turns.push({
158
+ role: "user",
159
+ text,
160
+ startMs: userStart,
161
+ endMs: Date.now()
162
+ });
163
+ this.history.push({ role: "user", content: text });
164
+ const assistantStart = Date.now();
165
+ const assistantText = await this.complete(this.history, {
166
+ ...this.sessionConfig,
167
+ llmModel: this.sessionConfig.llmModel ?? this.defaultModel
168
+ });
169
+ if (this.closed) {
170
+ return;
171
+ }
172
+ const normalizedAssistantText = assistantText.trim();
173
+ const finalAssistantText = normalizedAssistantText.length > 0 ? normalizedAssistantText : "I was unable to produce a response.";
174
+ this.queue.push({
175
+ type: "agent_speech_started",
176
+ text: finalAssistantText
177
+ });
178
+ this.queue.push({
179
+ type: "transcript",
180
+ role: "agent",
181
+ text: finalAssistantText,
182
+ timestamp: assistantStart
183
+ });
184
+ this.queue.push({ type: "agent_speech_ended" });
185
+ this.turns.push({
186
+ role: "assistant",
187
+ text: finalAssistantText,
188
+ startMs: assistantStart,
189
+ endMs: Date.now()
190
+ });
191
+ this.history.push({ role: "assistant", content: finalAssistantText });
192
+ }
193
+ emitError(error) {
194
+ if (this.closed) {
195
+ return;
196
+ }
197
+ this.queue.push({ type: "error", error: toError(error) });
198
+ }
199
+ }
200
+ function toError(error) {
201
+ if (error instanceof Error) {
202
+ return error;
203
+ }
204
+ return new Error(String(error));
205
+ }
206
+
48
207
  // src/impls/mistral-stt.ts
49
208
  var DEFAULT_BASE_URL = "https://api.mistral.ai/v1";
50
209
  var DEFAULT_MODEL = "voxtral-mini-latest";
@@ -209,165 +368,6 @@ function secondsToMs(value) {
209
368
  return Math.round(value * 1000);
210
369
  }
211
370
 
212
- // src/impls/mistral-conversational.session.ts
213
- class MistralConversationSession {
214
- events;
215
- queue = new AsyncEventQueue;
216
- turns = [];
217
- history = [];
218
- sessionId = crypto.randomUUID();
219
- startedAt = Date.now();
220
- sessionConfig;
221
- defaultModel;
222
- complete;
223
- sttProvider;
224
- pending = Promise.resolve();
225
- closed = false;
226
- closedSummary;
227
- constructor(options) {
228
- this.sessionConfig = options.sessionConfig;
229
- this.defaultModel = options.defaultModel;
230
- this.complete = options.complete;
231
- this.sttProvider = options.sttProvider;
232
- this.events = this.queue;
233
- this.queue.push({
234
- type: "session_started",
235
- sessionId: this.sessionId
236
- });
237
- }
238
- sendAudio(chunk) {
239
- if (this.closed) {
240
- return;
241
- }
242
- this.pending = this.pending.then(async () => {
243
- const transcription = await this.sttProvider.transcribe({
244
- audio: {
245
- data: chunk,
246
- format: this.sessionConfig.inputFormat ?? "pcm",
247
- sampleRateHz: 16000
248
- },
249
- language: this.sessionConfig.language
250
- });
251
- const transcriptText = transcription.text.trim();
252
- if (transcriptText.length > 0) {
253
- await this.handleUserText(transcriptText);
254
- }
255
- }).catch((error) => {
256
- this.emitError(error);
257
- });
258
- }
259
- sendText(text) {
260
- if (this.closed) {
261
- return;
262
- }
263
- const normalized = text.trim();
264
- if (normalized.length === 0) {
265
- return;
266
- }
267
- this.pending = this.pending.then(() => this.handleUserText(normalized)).catch((error) => {
268
- this.emitError(error);
269
- });
270
- }
271
- interrupt() {
272
- if (this.closed) {
273
- return;
274
- }
275
- this.queue.push({
276
- type: "error",
277
- error: new Error("Interrupt is not supported for non-streaming sessions.")
278
- });
279
- }
280
- async close() {
281
- if (this.closedSummary) {
282
- return this.closedSummary;
283
- }
284
- this.closed = true;
285
- await this.pending;
286
- const durationMs = Date.now() - this.startedAt;
287
- const summary = {
288
- sessionId: this.sessionId,
289
- durationMs,
290
- turns: this.turns.map((turn) => ({
291
- role: turn.role === "assistant" ? "agent" : turn.role,
292
- text: turn.text,
293
- startMs: turn.startMs,
294
- endMs: turn.endMs
295
- })),
296
- transcript: this.turns.map((turn) => `${turn.role}: ${turn.text}`).join(`
297
- `)
298
- };
299
- this.closedSummary = summary;
300
- this.queue.push({
301
- type: "session_ended",
302
- reason: "closed_by_client",
303
- durationMs
304
- });
305
- this.queue.close();
306
- return summary;
307
- }
308
- async handleUserText(text) {
309
- if (this.closed) {
310
- return;
311
- }
312
- const userStart = Date.now();
313
- this.queue.push({ type: "user_speech_started" });
314
- this.queue.push({ type: "user_speech_ended", transcript: text });
315
- this.queue.push({
316
- type: "transcript",
317
- role: "user",
318
- text,
319
- timestamp: userStart
320
- });
321
- this.turns.push({
322
- role: "user",
323
- text,
324
- startMs: userStart,
325
- endMs: Date.now()
326
- });
327
- this.history.push({ role: "user", content: text });
328
- const assistantStart = Date.now();
329
- const assistantText = await this.complete(this.history, {
330
- ...this.sessionConfig,
331
- llmModel: this.sessionConfig.llmModel ?? this.defaultModel
332
- });
333
- if (this.closed) {
334
- return;
335
- }
336
- const normalizedAssistantText = assistantText.trim();
337
- const finalAssistantText = normalizedAssistantText.length > 0 ? normalizedAssistantText : "I was unable to produce a response.";
338
- this.queue.push({
339
- type: "agent_speech_started",
340
- text: finalAssistantText
341
- });
342
- this.queue.push({
343
- type: "transcript",
344
- role: "agent",
345
- text: finalAssistantText,
346
- timestamp: assistantStart
347
- });
348
- this.queue.push({ type: "agent_speech_ended" });
349
- this.turns.push({
350
- role: "assistant",
351
- text: finalAssistantText,
352
- startMs: assistantStart,
353
- endMs: Date.now()
354
- });
355
- this.history.push({ role: "assistant", content: finalAssistantText });
356
- }
357
- emitError(error) {
358
- if (this.closed) {
359
- return;
360
- }
361
- this.queue.push({ type: "error", error: toError(error) });
362
- }
363
- }
364
- function toError(error) {
365
- if (error instanceof Error) {
366
- return error;
367
- }
368
- return new Error(String(error));
369
- }
370
-
371
371
  // src/impls/mistral-conversational.ts
372
372
  var DEFAULT_BASE_URL2 = "https://api.mistral.ai/v1";
373
373
  var DEFAULT_MODEL2 = "mistral-small-latest";
@@ -1,4 +1,4 @@
1
- import type { AnalyticsReader, AnalyticsQueryInput, AnalyticsQueryResult, AnalyticsRequest, AnalyticsResponse, AnalyticsEvent, AnalyticsPerson, AnalyticsInsight, AnalyticsCohort, AnalyticsFeatureFlag, AnalyticsAnnotation, GetEventsInput, GetPersonsInput, GetInsightsInput, GetInsightResultInput, GetCohortsInput, GetFeatureFlagsInput, GetAnnotationsInput, PaginatedResponse } from '../analytics';
1
+ import type { AnalyticsAnnotation, AnalyticsCohort, AnalyticsEvent, AnalyticsFeatureFlag, AnalyticsInsight, AnalyticsPerson, AnalyticsQueryInput, AnalyticsQueryResult, AnalyticsReader, AnalyticsRequest, AnalyticsResponse, GetAnnotationsInput, GetCohortsInput, GetEventsInput, GetFeatureFlagsInput, GetInsightResultInput, GetInsightsInput, GetPersonsInput, PaginatedResponse } from '../analytics';
2
2
  export interface PosthogReaderClient {
3
3
  request<T = unknown>(request: AnalyticsRequest): Promise<AnalyticsResponse<T>>;
4
4
  }
@@ -1,21 +1,21 @@
1
1
  import type { IntegrationContext } from '@contractspec/integration.runtime/runtime';
2
- import type { IntegrationTransportType } from '@contractspec/lib.contracts-integrations/integrations/transport';
3
2
  import type { IntegrationAuthType } from '@contractspec/lib.contracts-integrations/integrations/auth';
4
- import type { PaymentsProvider } from '../payments';
5
- import type { EmailOutboundProvider } from '../email';
6
- import type { SmsProvider } from '../sms';
7
- import type { MessagingProvider } from '../messaging';
8
- import type { VectorStoreProvider } from '../vector-store';
3
+ import type { IntegrationTransportType } from '@contractspec/lib.contracts-integrations/integrations/transport';
9
4
  import type { AnalyticsProvider } from '../analytics';
10
5
  import type { DatabaseProvider } from '../database';
11
- import type { ObjectStorageProvider } from '../storage';
12
- import type { ConversationalProvider, STTProvider, TTSProvider } from '../voice';
13
- import type { LLMProvider } from '../llm';
6
+ import type { EmailOutboundProvider } from '../email';
14
7
  import type { EmbeddingProvider } from '../embedding';
8
+ import type { HealthProvider } from '../health';
9
+ import type { LLMProvider } from '../llm';
10
+ import type { MeetingRecorderProvider } from '../meeting-recorder';
11
+ import type { MessagingProvider } from '../messaging';
15
12
  import type { OpenBankingProvider } from '../openbanking';
13
+ import type { PaymentsProvider } from '../payments';
16
14
  import type { ProjectManagementProvider } from '../project-management';
17
- import type { MeetingRecorderProvider } from '../meeting-recorder';
18
- import type { HealthProvider } from '../health';
15
+ import type { SmsProvider } from '../sms';
16
+ import type { ObjectStorageProvider } from '../storage';
17
+ import type { VectorStoreProvider } from '../vector-store';
18
+ import type { ConversationalProvider, STTProvider, TTSProvider } from '../voice';
19
19
  import type { ComposioFallbackResolver } from './composio-fallback-resolver';
20
20
  /**
21
21
  * Resolved transport, auth, and version context for a provider invocation.