@lssm/integration.providers-impls 0.0.0-canary-20251217062139 → 0.0.0-canary-20251217072406
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/_virtual/rolldown_runtime.js +42 -1
- package/dist/impls/elevenlabs-voice.js +95 -1
- package/dist/impls/gcs-storage.js +88 -1
- package/dist/impls/gmail-inbound.js +200 -1
- package/dist/impls/gmail-outbound.js +104 -5
- package/dist/impls/google-calendar.js +154 -1
- package/dist/impls/index.js +16 -1
- package/dist/impls/mistral-embedding.js +41 -1
- package/dist/impls/mistral-llm.js +247 -1
- package/dist/impls/postmark-email.js +55 -1
- package/dist/impls/powens-client.js +171 -1
- package/dist/impls/powens-openbanking.js +218 -1
- package/dist/impls/provider-factory.js +142 -1
- package/dist/impls/qdrant-vector.js +69 -1
- package/dist/impls/stripe-payments.js +202 -1
- package/dist/impls/twilio-sms.js +58 -1
- package/dist/index.js +17 -1
- package/dist/runtime/dist/secrets/provider.js +58 -1
- package/dist/secrets/provider.js +3 -1
- package/package.json +5 -5
|
@@ -1 +1,154 @@
|
|
|
1
|
-
import{google
|
|
1
|
+
import { google } from "googleapis";
|
|
2
|
+
|
|
3
|
+
//#region src/impls/google-calendar.ts
|
|
4
|
+
var GoogleCalendarProvider = class {
|
|
5
|
+
calendar;
|
|
6
|
+
defaultCalendarId;
|
|
7
|
+
auth;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.auth = options.auth;
|
|
10
|
+
this.calendar = options.calendar ?? google.calendar({
|
|
11
|
+
version: "v3",
|
|
12
|
+
auth: options.auth
|
|
13
|
+
});
|
|
14
|
+
this.defaultCalendarId = options.calendarId ?? "primary";
|
|
15
|
+
}
|
|
16
|
+
async listEvents(query) {
|
|
17
|
+
const response = await this.calendar.events.list({
|
|
18
|
+
calendarId: query.calendarId ?? this.defaultCalendarId,
|
|
19
|
+
timeMin: query.timeMin?.toISOString(),
|
|
20
|
+
timeMax: query.timeMax?.toISOString(),
|
|
21
|
+
maxResults: query.maxResults,
|
|
22
|
+
pageToken: query.pageToken,
|
|
23
|
+
singleEvents: true,
|
|
24
|
+
orderBy: "startTime",
|
|
25
|
+
auth: this.auth
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
events: response.data.items?.map((item) => this.fromGoogleEvent(query.calendarId ?? this.defaultCalendarId, item)) ?? [],
|
|
29
|
+
nextPageToken: response.data.nextPageToken ?? void 0
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async createEvent(input) {
|
|
33
|
+
const calendarId = input.calendarId ?? this.defaultCalendarId;
|
|
34
|
+
const response = await this.calendar.events.insert({
|
|
35
|
+
calendarId,
|
|
36
|
+
requestBody: this.toGoogleEvent(input),
|
|
37
|
+
conferenceDataVersion: input.conference?.create ? 1 : void 0,
|
|
38
|
+
auth: this.auth
|
|
39
|
+
});
|
|
40
|
+
return this.fromGoogleEvent(calendarId, response.data);
|
|
41
|
+
}
|
|
42
|
+
async updateEvent(calendarId, eventId, input) {
|
|
43
|
+
const response = await this.calendar.events.patch({
|
|
44
|
+
calendarId: calendarId ?? this.defaultCalendarId,
|
|
45
|
+
eventId,
|
|
46
|
+
requestBody: this.toGoogleEvent(input),
|
|
47
|
+
conferenceDataVersion: input.conference?.create ? 1 : void 0,
|
|
48
|
+
auth: this.auth
|
|
49
|
+
});
|
|
50
|
+
return this.fromGoogleEvent(calendarId, response.data);
|
|
51
|
+
}
|
|
52
|
+
async deleteEvent(calendarId, eventId) {
|
|
53
|
+
await this.calendar.events.delete({
|
|
54
|
+
calendarId: calendarId ?? this.defaultCalendarId,
|
|
55
|
+
eventId,
|
|
56
|
+
auth: this.auth
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
fromGoogleEvent(calendarId, event) {
|
|
60
|
+
const start = parseDateTime(event.start);
|
|
61
|
+
const end = parseDateTime(event.end);
|
|
62
|
+
const attendees = event.attendees?.map((attendee) => ({
|
|
63
|
+
email: attendee.email ?? "",
|
|
64
|
+
name: attendee.displayName ?? void 0,
|
|
65
|
+
optional: attendee.optional ?? void 0,
|
|
66
|
+
responseStatus: normalizeResponseStatus(attendee.responseStatus)
|
|
67
|
+
})) ?? [];
|
|
68
|
+
const reminders = event.reminders?.overrides?.map((reminder) => ({
|
|
69
|
+
method: reminder.method ?? "popup",
|
|
70
|
+
minutesBeforeStart: reminder.minutes ?? 0
|
|
71
|
+
})) ?? [];
|
|
72
|
+
const metadata = buildMetadata(event);
|
|
73
|
+
return {
|
|
74
|
+
id: event.id ?? "",
|
|
75
|
+
calendarId,
|
|
76
|
+
title: event.summary ?? "",
|
|
77
|
+
description: event.description ?? void 0,
|
|
78
|
+
location: event.location ?? void 0,
|
|
79
|
+
start,
|
|
80
|
+
end,
|
|
81
|
+
allDay: event.start?.date ? true : void 0,
|
|
82
|
+
attendees,
|
|
83
|
+
reminders,
|
|
84
|
+
conferenceLink: event.hangoutLink ?? event.conferenceData?.entryPoints?.find((entry) => entry.uri)?.uri ?? void 0,
|
|
85
|
+
metadata,
|
|
86
|
+
createdAt: event.created ? new Date(event.created) : void 0,
|
|
87
|
+
updatedAt: event.updated ? new Date(event.updated) : void 0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
toGoogleEvent(input) {
|
|
91
|
+
const event = {};
|
|
92
|
+
if ("title" in input && input.title) event.summary = input.title;
|
|
93
|
+
if (input.description !== void 0) event.description = input.description;
|
|
94
|
+
if (input.location !== void 0) event.location = input.location;
|
|
95
|
+
if (input.start) event.start = formatDateTime(input.start, input.allDay);
|
|
96
|
+
if (input.end) event.end = formatDateTime(input.end, input.allDay);
|
|
97
|
+
if (input.attendees) event.attendees = input.attendees.map((attendee) => ({
|
|
98
|
+
email: attendee.email,
|
|
99
|
+
displayName: attendee.name,
|
|
100
|
+
optional: attendee.optional,
|
|
101
|
+
responseStatus: attendee.responseStatus
|
|
102
|
+
}));
|
|
103
|
+
if (input.reminders) event.reminders = {
|
|
104
|
+
useDefault: false,
|
|
105
|
+
overrides: input.reminders.map((reminder) => ({
|
|
106
|
+
method: reminder.method,
|
|
107
|
+
minutes: reminder.minutesBeforeStart
|
|
108
|
+
}))
|
|
109
|
+
};
|
|
110
|
+
if (input.conference?.create) event.conferenceData = { createRequest: { requestId: `conf-${Date.now()}` } };
|
|
111
|
+
if (input.metadata) event.extendedProperties = {
|
|
112
|
+
...event.extendedProperties ?? {},
|
|
113
|
+
private: {
|
|
114
|
+
...event.extendedProperties?.private ?? {},
|
|
115
|
+
...input.metadata
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return event;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
function parseDateTime(time) {
|
|
122
|
+
if (!time) return /* @__PURE__ */ new Date();
|
|
123
|
+
if (time.dateTime) return new Date(time.dateTime);
|
|
124
|
+
if (time.date) return /* @__PURE__ */ new Date(`${time.date}T00:00:00`);
|
|
125
|
+
return /* @__PURE__ */ new Date();
|
|
126
|
+
}
|
|
127
|
+
function formatDateTime(date, allDay) {
|
|
128
|
+
if (allDay) return { date: date.toISOString().slice(0, 10) };
|
|
129
|
+
return { dateTime: date.toISOString() };
|
|
130
|
+
}
|
|
131
|
+
function normalizeResponseStatus(status) {
|
|
132
|
+
if (!status) return void 0;
|
|
133
|
+
return [
|
|
134
|
+
"needsAction",
|
|
135
|
+
"declined",
|
|
136
|
+
"tentative",
|
|
137
|
+
"accepted"
|
|
138
|
+
].includes(status) ? status : void 0;
|
|
139
|
+
}
|
|
140
|
+
function buildMetadata(event) {
|
|
141
|
+
const metadata = {};
|
|
142
|
+
if (event.status) metadata.status = event.status;
|
|
143
|
+
if (event.htmlLink) metadata.htmlLink = event.htmlLink;
|
|
144
|
+
if (event.iCalUID) metadata.iCalUID = event.iCalUID;
|
|
145
|
+
if (event.etag) metadata.etag = event.etag;
|
|
146
|
+
if (event.conferenceData?.conferenceSolution?.name) metadata.conferenceSolution = event.conferenceData.conferenceSolution.name;
|
|
147
|
+
if (event.extendedProperties?.private) Object.entries(event.extendedProperties.private).forEach(([key, value]) => {
|
|
148
|
+
if (typeof value === "string") metadata[`extended.${key}`] = value;
|
|
149
|
+
});
|
|
150
|
+
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
export { GoogleCalendarProvider };
|
package/dist/impls/index.js
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MistralLLMProvider } from "./mistral-llm.js";
|
|
2
|
+
import { MistralEmbeddingProvider } from "./mistral-embedding.js";
|
|
3
|
+
import { QdrantVectorProvider } from "./qdrant-vector.js";
|
|
4
|
+
import { GoogleCloudStorageProvider } from "./gcs-storage.js";
|
|
5
|
+
import { StripePaymentsProvider } from "./stripe-payments.js";
|
|
6
|
+
import { PostmarkEmailProvider } from "./postmark-email.js";
|
|
7
|
+
import { TwilioSmsProvider } from "./twilio-sms.js";
|
|
8
|
+
import { ElevenLabsVoiceProvider } from "./elevenlabs-voice.js";
|
|
9
|
+
import { PowensClient, PowensClientError } from "./powens-client.js";
|
|
10
|
+
import { PowensOpenBankingProvider } from "./powens-openbanking.js";
|
|
11
|
+
import { IntegrationProviderFactory } from "./provider-factory.js";
|
|
12
|
+
import { GmailInboundProvider } from "./gmail-inbound.js";
|
|
13
|
+
import { GmailOutboundProvider } from "./gmail-outbound.js";
|
|
14
|
+
import { GoogleCalendarProvider } from "./google-calendar.js";
|
|
15
|
+
|
|
16
|
+
export { ElevenLabsVoiceProvider, GmailInboundProvider, GmailOutboundProvider, GoogleCalendarProvider, GoogleCloudStorageProvider, IntegrationProviderFactory, MistralEmbeddingProvider, MistralLLMProvider, PostmarkEmailProvider, PowensClient, PowensClientError, PowensOpenBankingProvider, QdrantVectorProvider, StripePaymentsProvider, TwilioSmsProvider };
|
|
@@ -1 +1,41 @@
|
|
|
1
|
-
import{Mistral
|
|
1
|
+
import { Mistral } from "@mistralai/mistralai";
|
|
2
|
+
|
|
3
|
+
//#region src/impls/mistral-embedding.ts
|
|
4
|
+
var MistralEmbeddingProvider = class {
|
|
5
|
+
client;
|
|
6
|
+
defaultModel;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (!options.apiKey) throw new Error("MistralEmbeddingProvider requires an apiKey");
|
|
9
|
+
this.client = options.client ?? new Mistral({
|
|
10
|
+
apiKey: options.apiKey,
|
|
11
|
+
serverURL: options.serverURL
|
|
12
|
+
});
|
|
13
|
+
this.defaultModel = options.defaultModel ?? "mistral-embed";
|
|
14
|
+
}
|
|
15
|
+
async embedDocuments(documents, options) {
|
|
16
|
+
if (documents.length === 0) return [];
|
|
17
|
+
const model = options?.model ?? this.defaultModel;
|
|
18
|
+
const response = await this.client.embeddings.create({
|
|
19
|
+
model,
|
|
20
|
+
inputs: documents.map((doc) => doc.text)
|
|
21
|
+
});
|
|
22
|
+
return response.data.map((item, index) => ({
|
|
23
|
+
id: documents[index]?.id ?? (item.index != null ? `embedding-${item.index}` : `embedding-${index}`),
|
|
24
|
+
vector: item.embedding ?? [],
|
|
25
|
+
dimensions: item.embedding?.length ?? 0,
|
|
26
|
+
model: response.model,
|
|
27
|
+
metadata: documents[index]?.metadata ? Object.fromEntries(Object.entries(documents[index]?.metadata ?? {}).map(([key, value]) => [key, String(value)])) : void 0
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
async embedQuery(query, options) {
|
|
31
|
+
const [result] = await this.embedDocuments([{
|
|
32
|
+
id: "query",
|
|
33
|
+
text: query
|
|
34
|
+
}], options);
|
|
35
|
+
if (!result) throw new Error("Failed to compute embedding for query");
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { MistralEmbeddingProvider };
|
|
@@ -1 +1,247 @@
|
|
|
1
|
-
import{Mistral
|
|
1
|
+
import { Mistral } from "@mistralai/mistralai";
|
|
2
|
+
|
|
3
|
+
//#region src/impls/mistral-llm.ts
|
|
4
|
+
var MistralLLMProvider = class {
|
|
5
|
+
client;
|
|
6
|
+
defaultModel;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (!options.apiKey) throw new Error("MistralLLMProvider requires an apiKey");
|
|
9
|
+
this.client = options.client ?? new Mistral({
|
|
10
|
+
apiKey: options.apiKey,
|
|
11
|
+
serverURL: options.serverURL,
|
|
12
|
+
userAgent: options.userAgentSuffix ? `${options.userAgentSuffix}` : void 0
|
|
13
|
+
});
|
|
14
|
+
this.defaultModel = options.defaultModel ?? "mistral-large-latest";
|
|
15
|
+
}
|
|
16
|
+
async chat(messages, options = {}) {
|
|
17
|
+
const request = this.buildChatRequest(messages, options);
|
|
18
|
+
const response = await this.client.chat.complete(request);
|
|
19
|
+
return this.buildLLMResponse(response);
|
|
20
|
+
}
|
|
21
|
+
async *stream(messages, options = {}) {
|
|
22
|
+
const request = this.buildChatRequest(messages, options);
|
|
23
|
+
request.stream = true;
|
|
24
|
+
const stream = await this.client.chat.stream(request);
|
|
25
|
+
const aggregatedParts = [];
|
|
26
|
+
const aggregatedToolCalls = [];
|
|
27
|
+
let usage;
|
|
28
|
+
let finishReason;
|
|
29
|
+
for await (const event of stream) {
|
|
30
|
+
for (const choice of event.data.choices) {
|
|
31
|
+
const delta = choice.delta;
|
|
32
|
+
if (typeof delta.content === "string") {
|
|
33
|
+
if (delta.content.length > 0) {
|
|
34
|
+
aggregatedParts.push({
|
|
35
|
+
type: "text",
|
|
36
|
+
text: delta.content
|
|
37
|
+
});
|
|
38
|
+
yield {
|
|
39
|
+
type: "message_delta",
|
|
40
|
+
delta: {
|
|
41
|
+
type: "text",
|
|
42
|
+
text: delta.content
|
|
43
|
+
},
|
|
44
|
+
index: choice.index
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
} else if (Array.isArray(delta.content)) {
|
|
48
|
+
for (const chunk of delta.content) if (chunk.type === "text" && "text" in chunk) {
|
|
49
|
+
aggregatedParts.push({
|
|
50
|
+
type: "text",
|
|
51
|
+
text: chunk.text
|
|
52
|
+
});
|
|
53
|
+
yield {
|
|
54
|
+
type: "message_delta",
|
|
55
|
+
delta: {
|
|
56
|
+
type: "text",
|
|
57
|
+
text: chunk.text
|
|
58
|
+
},
|
|
59
|
+
index: choice.index
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (delta.toolCalls) {
|
|
64
|
+
let localIndex = 0;
|
|
65
|
+
for (const call of delta.toolCalls) {
|
|
66
|
+
const toolCall = this.fromMistralToolCall(call, localIndex);
|
|
67
|
+
aggregatedToolCalls.push(toolCall);
|
|
68
|
+
yield {
|
|
69
|
+
type: "tool_call",
|
|
70
|
+
call: toolCall,
|
|
71
|
+
index: choice.index
|
|
72
|
+
};
|
|
73
|
+
localIndex += 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (choice.finishReason && choice.finishReason !== "null") finishReason = choice.finishReason;
|
|
77
|
+
}
|
|
78
|
+
if (event.data.usage) {
|
|
79
|
+
const usageEntry = this.fromUsage(event.data.usage);
|
|
80
|
+
if (usageEntry) {
|
|
81
|
+
usage = usageEntry;
|
|
82
|
+
yield {
|
|
83
|
+
type: "usage",
|
|
84
|
+
usage: usageEntry
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const message = {
|
|
90
|
+
role: "assistant",
|
|
91
|
+
content: aggregatedParts.length ? aggregatedParts : [{
|
|
92
|
+
type: "text",
|
|
93
|
+
text: ""
|
|
94
|
+
}]
|
|
95
|
+
};
|
|
96
|
+
if (aggregatedToolCalls.length > 0) message.content = [...aggregatedToolCalls, ...aggregatedParts.length ? aggregatedParts : []];
|
|
97
|
+
yield {
|
|
98
|
+
type: "end",
|
|
99
|
+
response: {
|
|
100
|
+
message,
|
|
101
|
+
usage,
|
|
102
|
+
finishReason: mapFinishReason(finishReason)
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async countTokens(messages) {
|
|
107
|
+
throw new Error("Mistral API does not currently support token counting");
|
|
108
|
+
}
|
|
109
|
+
buildChatRequest(messages, options) {
|
|
110
|
+
const request = {
|
|
111
|
+
model: options.model ?? this.defaultModel,
|
|
112
|
+
messages: messages.map((message) => this.toMistralMessage(message))
|
|
113
|
+
};
|
|
114
|
+
if (options.temperature != null) request.temperature = options.temperature;
|
|
115
|
+
if (options.topP != null) request.topP = options.topP;
|
|
116
|
+
if (options.maxOutputTokens != null) request.maxTokens = options.maxOutputTokens;
|
|
117
|
+
if (options.stopSequences?.length) request.stop = options.stopSequences.length === 1 ? options.stopSequences[0] : options.stopSequences;
|
|
118
|
+
if (options.tools?.length) request.tools = options.tools.map((tool) => ({
|
|
119
|
+
type: "function",
|
|
120
|
+
function: {
|
|
121
|
+
name: tool.name,
|
|
122
|
+
description: tool.description,
|
|
123
|
+
parameters: typeof tool.inputSchema === "object" && tool.inputSchema !== null ? tool.inputSchema : {}
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
if (options.responseFormat === "json") request.responseFormat = { type: "json_object" };
|
|
127
|
+
return request;
|
|
128
|
+
}
|
|
129
|
+
buildLLMResponse(response) {
|
|
130
|
+
const firstChoice = response.choices[0];
|
|
131
|
+
if (!firstChoice) return {
|
|
132
|
+
message: {
|
|
133
|
+
role: "assistant",
|
|
134
|
+
content: [{
|
|
135
|
+
type: "text",
|
|
136
|
+
text: ""
|
|
137
|
+
}]
|
|
138
|
+
},
|
|
139
|
+
usage: this.fromUsage(response.usage),
|
|
140
|
+
raw: response
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
message: this.fromAssistantMessage(firstChoice.message),
|
|
144
|
+
usage: this.fromUsage(response.usage),
|
|
145
|
+
finishReason: mapFinishReason(firstChoice.finishReason),
|
|
146
|
+
raw: response
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
fromUsage(usage) {
|
|
150
|
+
if (!usage) return void 0;
|
|
151
|
+
return {
|
|
152
|
+
promptTokens: usage.promptTokens ?? 0,
|
|
153
|
+
completionTokens: usage.completionTokens ?? 0,
|
|
154
|
+
totalTokens: usage.totalTokens ?? 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
fromAssistantMessage(message) {
|
|
158
|
+
const parts = [];
|
|
159
|
+
if (typeof message.content === "string") parts.push({
|
|
160
|
+
type: "text",
|
|
161
|
+
text: message.content
|
|
162
|
+
});
|
|
163
|
+
else if (Array.isArray(message.content)) message.content.forEach((chunk) => {
|
|
164
|
+
if (chunk.type === "text" && "text" in chunk) parts.push({
|
|
165
|
+
type: "text",
|
|
166
|
+
text: chunk.text
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
const toolCalls = message.toolCalls?.map((call, index) => this.fromMistralToolCall(call, index)) ?? [];
|
|
170
|
+
if (toolCalls.length > 0) parts.splice(0, 0, ...toolCalls);
|
|
171
|
+
if (parts.length === 0) parts.push({
|
|
172
|
+
type: "text",
|
|
173
|
+
text: ""
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
role: "assistant",
|
|
177
|
+
content: parts
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
fromMistralToolCall(call, index) {
|
|
181
|
+
const args = typeof call.function.arguments === "string" ? call.function.arguments : JSON.stringify(call.function.arguments);
|
|
182
|
+
return {
|
|
183
|
+
type: "tool-call",
|
|
184
|
+
id: call.id ?? `tool-call-${index}`,
|
|
185
|
+
name: call.function.name,
|
|
186
|
+
arguments: args
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
toMistralMessage(message) {
|
|
190
|
+
const textContent = this.extractText(message.content);
|
|
191
|
+
const toolCalls = this.extractToolCalls(message);
|
|
192
|
+
switch (message.role) {
|
|
193
|
+
case "system": return {
|
|
194
|
+
role: "system",
|
|
195
|
+
content: textContent ?? ""
|
|
196
|
+
};
|
|
197
|
+
case "user": return {
|
|
198
|
+
role: "user",
|
|
199
|
+
content: textContent ?? ""
|
|
200
|
+
};
|
|
201
|
+
case "assistant": return {
|
|
202
|
+
role: "assistant",
|
|
203
|
+
content: toolCalls.length > 0 ? null : textContent ?? "",
|
|
204
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : void 0
|
|
205
|
+
};
|
|
206
|
+
case "tool": return {
|
|
207
|
+
role: "tool",
|
|
208
|
+
content: textContent ?? "",
|
|
209
|
+
toolCallId: message.toolCallId ?? toolCalls[0]?.id
|
|
210
|
+
};
|
|
211
|
+
default: return {
|
|
212
|
+
role: "user",
|
|
213
|
+
content: textContent ?? ""
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
extractText(parts) {
|
|
218
|
+
const textParts = parts.filter((part) => part.type === "text").map((part) => part.text);
|
|
219
|
+
if (textParts.length === 0) return null;
|
|
220
|
+
return textParts.join("");
|
|
221
|
+
}
|
|
222
|
+
extractToolCalls(message) {
|
|
223
|
+
return message.content.filter((part) => part.type === "tool-call").map((call, index) => ({
|
|
224
|
+
id: call.id ?? `call_${index}`,
|
|
225
|
+
type: "function",
|
|
226
|
+
index,
|
|
227
|
+
function: {
|
|
228
|
+
name: call.name,
|
|
229
|
+
arguments: call.arguments
|
|
230
|
+
}
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
function mapFinishReason(reason) {
|
|
235
|
+
if (!reason) return void 0;
|
|
236
|
+
switch (reason.toLowerCase()) {
|
|
237
|
+
case "stop": return "stop";
|
|
238
|
+
case "length": return "length";
|
|
239
|
+
case "tool_call":
|
|
240
|
+
case "tool_calls": return "tool_call";
|
|
241
|
+
case "content_filter": return "content_filter";
|
|
242
|
+
default: return;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
export { MistralLLMProvider };
|
|
@@ -1 +1,55 @@
|
|
|
1
|
-
import{ServerClient
|
|
1
|
+
import { ServerClient } from "postmark";
|
|
2
|
+
|
|
3
|
+
//#region src/impls/postmark-email.ts
|
|
4
|
+
var PostmarkEmailProvider = class {
|
|
5
|
+
client;
|
|
6
|
+
defaultFromEmail;
|
|
7
|
+
messageStream;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.client = options.client ?? new ServerClient(options.serverToken, { useHttps: true });
|
|
10
|
+
this.defaultFromEmail = options.defaultFromEmail;
|
|
11
|
+
this.messageStream = options.messageStream;
|
|
12
|
+
}
|
|
13
|
+
async sendEmail(message) {
|
|
14
|
+
const request = {
|
|
15
|
+
From: formatAddress(message.from) ?? this.defaultFromEmail,
|
|
16
|
+
To: message.to.map((addr) => formatAddress(addr)).join(", "),
|
|
17
|
+
Cc: message.cc?.map((addr) => formatAddress(addr)).join(", ") || void 0,
|
|
18
|
+
Bcc: message.bcc?.map((addr) => formatAddress(addr)).join(", ") || void 0,
|
|
19
|
+
ReplyTo: message.replyTo ? formatAddress(message.replyTo) : void 0,
|
|
20
|
+
Subject: message.subject,
|
|
21
|
+
TextBody: message.textBody,
|
|
22
|
+
HtmlBody: message.htmlBody,
|
|
23
|
+
Headers: message.headers ? Object.entries(message.headers).map(([name, value]) => ({
|
|
24
|
+
Name: name,
|
|
25
|
+
Value: value
|
|
26
|
+
})) : void 0,
|
|
27
|
+
MessageStream: this.messageStream,
|
|
28
|
+
Attachments: buildAttachments(message)
|
|
29
|
+
};
|
|
30
|
+
const response = await this.client.sendEmail(request);
|
|
31
|
+
return {
|
|
32
|
+
id: response.MessageID,
|
|
33
|
+
providerMessageId: response.MessageID,
|
|
34
|
+
queuedAt: new Date(response.SubmittedAt ?? (/* @__PURE__ */ new Date()).toISOString())
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function formatAddress(address) {
|
|
39
|
+
if (address.name) return `"${address.name}" <${address.email}>`;
|
|
40
|
+
return address.email;
|
|
41
|
+
}
|
|
42
|
+
function buildAttachments(message) {
|
|
43
|
+
if (!message.attachments?.length) return void 0;
|
|
44
|
+
return message.attachments.filter((attachment) => attachment.data).map((attachment) => ({
|
|
45
|
+
Name: attachment.filename,
|
|
46
|
+
Content: Buffer.from(attachment.data ?? new Uint8Array()).toString("base64"),
|
|
47
|
+
ContentType: attachment.contentType,
|
|
48
|
+
ContentID: null,
|
|
49
|
+
ContentLength: attachment.sizeBytes,
|
|
50
|
+
Disposition: "attachment"
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { PostmarkEmailProvider };
|