@contractspec/integration.providers-impls 3.8.8 → 3.8.10
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/analytics.js +1 -2
- package/dist/calendar.js +1 -2
- package/dist/database.js +1 -2
- package/dist/email.js +1 -2
- package/dist/embedding.js +1 -2
- package/dist/health.js +1 -2
- package/dist/impls/async-event-queue.js +1 -48
- package/dist/impls/composio-fallback-resolver.js +1 -579
- package/dist/impls/composio-mcp.js +1 -163
- package/dist/impls/composio-proxies.js +1 -310
- package/dist/impls/composio-sdk.js +1 -77
- package/dist/impls/composio-types.js +1 -53
- package/dist/impls/elevenlabs-voice.js +1 -104
- package/dist/impls/fal-voice.js +1 -117
- package/dist/impls/fathom-meeting-recorder.js +2 -289
- package/dist/impls/fathom-meeting-recorder.mapper.js +1 -107
- package/dist/impls/fathom-meeting-recorder.utils.js +1 -74
- package/dist/impls/fathom-meeting-recorder.webhooks.js +1 -31
- package/dist/impls/fireflies-meeting-recorder.js +5 -203
- package/dist/impls/fireflies-meeting-recorder.queries.js +4 -14
- package/dist/impls/fireflies-meeting-recorder.utils.js +1 -44
- package/dist/impls/gcs-storage.js +1 -99
- package/dist/impls/gmail-inbound.js +1 -229
- package/dist/impls/gmail-outbound.js +25 -137
- package/dist/impls/google-calendar.js +1 -193
- package/dist/impls/gradium-voice.js +1 -95
- package/dist/impls/granola-meeting-recorder.js +3 -514
- package/dist/impls/granola-meeting-recorder.mcp.js +1 -280
- package/dist/impls/health/base-health-provider.js +1 -617
- package/dist/impls/health/hybrid-health-providers.js +1 -1089
- package/dist/impls/health/official-health-providers.js +1 -969
- package/dist/impls/health/provider-normalizers.js +1 -288
- package/dist/impls/health/providers.js +1 -1095
- package/dist/impls/health-provider-factory.js +1 -1309
- package/dist/impls/index.js +42 -7448
- package/dist/impls/jira.js +1 -126
- package/dist/impls/linear.js +1 -85
- package/dist/impls/messaging-github.js +1 -111
- package/dist/impls/messaging-slack.js +1 -81
- package/dist/impls/messaging-telegram.js +1 -48
- package/dist/impls/messaging-whatsapp-meta.js +1 -53
- package/dist/impls/messaging-whatsapp-twilio.js +1 -83
- package/dist/impls/mistral-conversational.js +2 -477
- package/dist/impls/mistral-conversational.session.js +2 -207
- package/dist/impls/mistral-embedding.js +1 -45
- package/dist/impls/mistral-llm.js +1 -271
- package/dist/impls/mistral-stt.js +1 -168
- package/dist/impls/notion.js +1 -162
- package/dist/impls/posthog-reader.js +1 -161
- package/dist/impls/posthog-utils.js +1 -40
- package/dist/impls/posthog.js +1 -324
- package/dist/impls/postmark-email.js +1 -62
- package/dist/impls/powens-client.js +1 -197
- package/dist/impls/powens-openbanking.js +1 -428
- package/dist/impls/provider-factory.js +18 -6268
- package/dist/impls/qdrant-vector.js +1 -80
- package/dist/impls/stripe-payments.js +1 -230
- package/dist/impls/supabase-psql.js +1 -152
- package/dist/impls/supabase-vector.js +9 -298
- package/dist/impls/tldv-meeting-recorder.js +2 -147
- package/dist/impls/twilio-sms.js +1 -67
- package/dist/index.js +42 -7495
- package/dist/llm.js +1 -2
- package/dist/meeting-recorder.js +1 -2
- package/dist/messaging.js +1 -2
- package/dist/node/analytics.js +1 -2
- package/dist/node/calendar.js +1 -2
- package/dist/node/database.js +1 -2
- package/dist/node/email.js +1 -2
- package/dist/node/embedding.js +1 -2
- package/dist/node/health.js +1 -2
- package/dist/node/impls/async-event-queue.js +1 -49
- package/dist/node/impls/composio-fallback-resolver.js +1 -580
- package/dist/node/impls/composio-mcp.js +1 -164
- package/dist/node/impls/composio-proxies.js +1 -311
- package/dist/node/impls/composio-sdk.js +1 -78
- package/dist/node/impls/composio-types.js +1 -54
- package/dist/node/impls/elevenlabs-voice.js +1 -105
- package/dist/node/impls/fal-voice.js +1 -118
- package/dist/node/impls/fathom-meeting-recorder.js +2 -290
- package/dist/node/impls/fathom-meeting-recorder.mapper.js +1 -108
- package/dist/node/impls/fathom-meeting-recorder.utils.js +1 -75
- package/dist/node/impls/fathom-meeting-recorder.webhooks.js +1 -32
- package/dist/node/impls/fireflies-meeting-recorder.js +5 -204
- package/dist/node/impls/fireflies-meeting-recorder.queries.js +4 -15
- package/dist/node/impls/fireflies-meeting-recorder.utils.js +1 -45
- package/dist/node/impls/gcs-storage.js +1 -100
- package/dist/node/impls/gmail-inbound.js +1 -230
- package/dist/node/impls/gmail-outbound.js +25 -138
- package/dist/node/impls/google-calendar.js +1 -194
- package/dist/node/impls/gradium-voice.js +1 -96
- package/dist/node/impls/granola-meeting-recorder.js +3 -515
- package/dist/node/impls/granola-meeting-recorder.mcp.js +1 -281
- package/dist/node/impls/health/base-health-provider.js +1 -618
- package/dist/node/impls/health/hybrid-health-providers.js +1 -1090
- package/dist/node/impls/health/official-health-providers.js +1 -970
- package/dist/node/impls/health/provider-normalizers.js +1 -289
- package/dist/node/impls/health/providers.js +1 -1096
- package/dist/node/impls/health-provider-factory.js +1 -1310
- package/dist/node/impls/index.js +42 -7449
- package/dist/node/impls/jira.js +1 -127
- package/dist/node/impls/linear.js +1 -86
- package/dist/node/impls/messaging-github.js +1 -112
- package/dist/node/impls/messaging-slack.js +1 -82
- package/dist/node/impls/messaging-telegram.js +1 -49
- package/dist/node/impls/messaging-whatsapp-meta.js +1 -54
- package/dist/node/impls/messaging-whatsapp-twilio.js +1 -84
- package/dist/node/impls/mistral-conversational.js +2 -478
- package/dist/node/impls/mistral-conversational.session.js +2 -208
- package/dist/node/impls/mistral-embedding.js +1 -46
- package/dist/node/impls/mistral-llm.js +1 -272
- package/dist/node/impls/mistral-stt.js +1 -169
- package/dist/node/impls/notion.js +1 -163
- package/dist/node/impls/posthog-reader.js +1 -162
- package/dist/node/impls/posthog-utils.js +1 -41
- package/dist/node/impls/posthog.js +1 -325
- package/dist/node/impls/postmark-email.js +1 -63
- package/dist/node/impls/powens-client.js +1 -198
- package/dist/node/impls/powens-openbanking.js +1 -429
- package/dist/node/impls/provider-factory.js +18 -6269
- package/dist/node/impls/qdrant-vector.js +1 -81
- package/dist/node/impls/stripe-payments.js +1 -231
- package/dist/node/impls/supabase-psql.js +1 -153
- package/dist/node/impls/supabase-vector.js +9 -299
- package/dist/node/impls/tldv-meeting-recorder.js +2 -148
- package/dist/node/impls/twilio-sms.js +1 -68
- package/dist/node/index.js +42 -7496
- package/dist/node/llm.js +1 -2
- package/dist/node/meeting-recorder.js +1 -2
- package/dist/node/messaging.js +1 -2
- package/dist/node/openbanking.js +1 -2
- package/dist/node/payments.js +1 -2
- package/dist/node/project-management.js +1 -2
- package/dist/node/secrets/provider.js +1 -14
- package/dist/node/sms.js +1 -2
- package/dist/node/storage.js +1 -2
- package/dist/node/vector-store.js +1 -2
- package/dist/node/voice.js +1 -2
- package/dist/openbanking.js +1 -2
- package/dist/payments.js +1 -2
- package/dist/project-management.js +1 -2
- package/dist/secrets/provider.js +1 -13
- package/dist/sms.js +1 -2
- package/dist/storage.js +1 -2
- package/dist/vector-store.js +1 -2
- package/dist/voice.js +1 -2
- package/package.json +17 -17
|
@@ -1,46 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
-
|
|
4
|
-
// src/impls/mistral-embedding.ts
|
|
5
|
-
import { Mistral } from "@mistralai/mistralai";
|
|
6
|
-
|
|
7
|
-
class MistralEmbeddingProvider {
|
|
8
|
-
client;
|
|
9
|
-
defaultModel;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
if (!options.apiKey) {
|
|
12
|
-
throw new Error("MistralEmbeddingProvider requires an apiKey");
|
|
13
|
-
}
|
|
14
|
-
this.client = options.client ?? new Mistral({
|
|
15
|
-
apiKey: options.apiKey,
|
|
16
|
-
serverURL: options.serverURL
|
|
17
|
-
});
|
|
18
|
-
this.defaultModel = options.defaultModel ?? "mistral-embed";
|
|
19
|
-
}
|
|
20
|
-
async embedDocuments(documents, options) {
|
|
21
|
-
if (documents.length === 0)
|
|
22
|
-
return [];
|
|
23
|
-
const model = options?.model ?? this.defaultModel;
|
|
24
|
-
const response = await this.client.embeddings.create({
|
|
25
|
-
model,
|
|
26
|
-
inputs: documents.map((doc) => doc.text)
|
|
27
|
-
});
|
|
28
|
-
return response.data.map((item, index) => ({
|
|
29
|
-
id: documents[index]?.id ?? (item.index != null ? `embedding-${item.index}` : `embedding-${index}`),
|
|
30
|
-
vector: item.embedding ?? [],
|
|
31
|
-
dimensions: item.embedding?.length ?? 0,
|
|
32
|
-
model: response.model,
|
|
33
|
-
metadata: documents[index]?.metadata ? Object.fromEntries(Object.entries(documents[index]?.metadata ?? {}).map(([key, value]) => [key, String(value)])) : undefined
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
async embedQuery(query, options) {
|
|
37
|
-
const [result] = await this.embedDocuments([{ id: "query", text: query }], options);
|
|
38
|
-
if (!result) {
|
|
39
|
-
throw new Error("Failed to compute embedding for query");
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export {
|
|
45
|
-
MistralEmbeddingProvider
|
|
46
|
-
};
|
|
1
|
+
import{createRequire as s}from"node:module";var b=s(import.meta.url);import{Mistral as l}from"@mistralai/mistralai";class o{client;defaultModel;constructor(e){if(!e.apiKey)throw Error("MistralEmbeddingProvider requires an apiKey");this.client=e.client??new l({apiKey:e.apiKey,serverURL:e.serverURL}),this.defaultModel=e.defaultModel??"mistral-embed"}async embedDocuments(e,d){if(e.length===0)return[];let i=d?.model??this.defaultModel,n=await this.client.embeddings.create({model:i,inputs:e.map((r)=>r.text)});return n.data.map((r,t)=>({id:e[t]?.id??(r.index!=null?`embedding-${r.index}`:`embedding-${t}`),vector:r.embedding??[],dimensions:r.embedding?.length??0,model:n.model,metadata:e[t]?.metadata?Object.fromEntries(Object.entries(e[t]?.metadata??{}).map(([a,m])=>[a,String(m)])):void 0}))}async embedQuery(e,d){let[i]=await this.embedDocuments([{id:"query",text:e}],d);if(!i)throw Error("Failed to compute embedding for query");return i}}export{o as MistralEmbeddingProvider};
|
|
@@ -1,272 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
-
|
|
4
|
-
// src/impls/mistral-llm.ts
|
|
5
|
-
import { Mistral } from "@mistralai/mistralai";
|
|
6
|
-
|
|
7
|
-
class MistralLLMProvider {
|
|
8
|
-
client;
|
|
9
|
-
defaultModel;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
if (!options.apiKey) {
|
|
12
|
-
throw new Error("MistralLLMProvider requires an apiKey");
|
|
13
|
-
}
|
|
14
|
-
this.client = options.client ?? new Mistral({
|
|
15
|
-
apiKey: options.apiKey,
|
|
16
|
-
serverURL: options.serverURL,
|
|
17
|
-
userAgent: options.userAgentSuffix ? `${options.userAgentSuffix}` : undefined
|
|
18
|
-
});
|
|
19
|
-
this.defaultModel = options.defaultModel ?? "mistral-large-latest";
|
|
20
|
-
}
|
|
21
|
-
async chat(messages, options = {}) {
|
|
22
|
-
const request = this.buildChatRequest(messages, options);
|
|
23
|
-
const response = await this.client.chat.complete(request);
|
|
24
|
-
return this.buildLLMResponse(response);
|
|
25
|
-
}
|
|
26
|
-
async* stream(messages, options = {}) {
|
|
27
|
-
const request = this.buildChatRequest(messages, options);
|
|
28
|
-
request.stream = true;
|
|
29
|
-
const stream = await this.client.chat.stream(request);
|
|
30
|
-
const aggregatedParts = [];
|
|
31
|
-
const aggregatedToolCalls = [];
|
|
32
|
-
let usage;
|
|
33
|
-
let finishReason;
|
|
34
|
-
for await (const event of stream) {
|
|
35
|
-
for (const choice of event.data.choices) {
|
|
36
|
-
const delta = choice.delta;
|
|
37
|
-
if (typeof delta.content === "string") {
|
|
38
|
-
if (delta.content.length > 0) {
|
|
39
|
-
aggregatedParts.push({ type: "text", text: delta.content });
|
|
40
|
-
yield {
|
|
41
|
-
type: "message_delta",
|
|
42
|
-
delta: { type: "text", text: delta.content },
|
|
43
|
-
index: choice.index
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
} else if (Array.isArray(delta.content)) {
|
|
47
|
-
for (const chunk of delta.content) {
|
|
48
|
-
if (chunk.type === "text" && "text" in chunk) {
|
|
49
|
-
aggregatedParts.push({ type: "text", text: chunk.text });
|
|
50
|
-
yield {
|
|
51
|
-
type: "message_delta",
|
|
52
|
-
delta: { type: "text", text: chunk.text },
|
|
53
|
-
index: choice.index
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (delta.toolCalls) {
|
|
59
|
-
let localIndex = 0;
|
|
60
|
-
for (const call of delta.toolCalls) {
|
|
61
|
-
const toolCall = this.fromMistralToolCall(call, localIndex);
|
|
62
|
-
aggregatedToolCalls.push(toolCall);
|
|
63
|
-
yield {
|
|
64
|
-
type: "tool_call",
|
|
65
|
-
call: toolCall,
|
|
66
|
-
index: choice.index
|
|
67
|
-
};
|
|
68
|
-
localIndex += 1;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (choice.finishReason && choice.finishReason !== "null") {
|
|
72
|
-
finishReason = choice.finishReason;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (event.data.usage) {
|
|
76
|
-
const usageEntry = this.fromUsage(event.data.usage);
|
|
77
|
-
if (usageEntry) {
|
|
78
|
-
usage = usageEntry;
|
|
79
|
-
yield { type: "usage", usage: usageEntry };
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const message = {
|
|
84
|
-
role: "assistant",
|
|
85
|
-
content: aggregatedParts.length ? aggregatedParts : [{ type: "text", text: "" }]
|
|
86
|
-
};
|
|
87
|
-
if (aggregatedToolCalls.length > 0) {
|
|
88
|
-
message.content = [
|
|
89
|
-
...aggregatedToolCalls,
|
|
90
|
-
...aggregatedParts.length ? aggregatedParts : []
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
yield {
|
|
94
|
-
type: "end",
|
|
95
|
-
response: {
|
|
96
|
-
message,
|
|
97
|
-
usage,
|
|
98
|
-
finishReason: mapFinishReason(finishReason)
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
async countTokens(_messages) {
|
|
103
|
-
throw new Error("Mistral API does not currently support token counting");
|
|
104
|
-
}
|
|
105
|
-
buildChatRequest(messages, options) {
|
|
106
|
-
const model = options.model ?? this.defaultModel;
|
|
107
|
-
const mappedMessages = messages.map((message) => this.toMistralMessage(message));
|
|
108
|
-
const request = {
|
|
109
|
-
model,
|
|
110
|
-
messages: mappedMessages
|
|
111
|
-
};
|
|
112
|
-
if (options.temperature != null) {
|
|
113
|
-
request.temperature = options.temperature;
|
|
114
|
-
}
|
|
115
|
-
if (options.topP != null) {
|
|
116
|
-
request.topP = options.topP;
|
|
117
|
-
}
|
|
118
|
-
if (options.maxOutputTokens != null) {
|
|
119
|
-
request.maxTokens = options.maxOutputTokens;
|
|
120
|
-
}
|
|
121
|
-
if (options.stopSequences?.length) {
|
|
122
|
-
request.stop = options.stopSequences.length === 1 ? options.stopSequences[0] : options.stopSequences;
|
|
123
|
-
}
|
|
124
|
-
if (options.tools?.length) {
|
|
125
|
-
request.tools = options.tools.map((tool) => ({
|
|
126
|
-
type: "function",
|
|
127
|
-
function: {
|
|
128
|
-
name: tool.name,
|
|
129
|
-
description: tool.description,
|
|
130
|
-
parameters: typeof tool.inputSchema === "object" && tool.inputSchema !== null ? tool.inputSchema : {}
|
|
131
|
-
}
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
if (options.responseFormat === "json") {
|
|
135
|
-
request.responseFormat = { type: "json_object" };
|
|
136
|
-
}
|
|
137
|
-
return request;
|
|
138
|
-
}
|
|
139
|
-
buildLLMResponse(response) {
|
|
140
|
-
const firstChoice = response.choices[0];
|
|
141
|
-
if (!firstChoice) {
|
|
142
|
-
return {
|
|
143
|
-
message: {
|
|
144
|
-
role: "assistant",
|
|
145
|
-
content: [{ type: "text", text: "" }]
|
|
146
|
-
},
|
|
147
|
-
usage: this.fromUsage(response.usage),
|
|
148
|
-
raw: response
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
const message = this.fromAssistantMessage(firstChoice.message);
|
|
152
|
-
return {
|
|
153
|
-
message,
|
|
154
|
-
usage: this.fromUsage(response.usage),
|
|
155
|
-
finishReason: mapFinishReason(firstChoice.finishReason),
|
|
156
|
-
raw: response
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
fromUsage(usage) {
|
|
160
|
-
if (!usage)
|
|
161
|
-
return;
|
|
162
|
-
return {
|
|
163
|
-
promptTokens: usage.promptTokens ?? 0,
|
|
164
|
-
completionTokens: usage.completionTokens ?? 0,
|
|
165
|
-
totalTokens: usage.totalTokens ?? 0
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
fromAssistantMessage(message) {
|
|
169
|
-
const parts = [];
|
|
170
|
-
if (typeof message.content === "string") {
|
|
171
|
-
parts.push({ type: "text", text: message.content });
|
|
172
|
-
} else if (Array.isArray(message.content)) {
|
|
173
|
-
message.content.forEach((chunk) => {
|
|
174
|
-
if (chunk.type === "text" && "text" in chunk) {
|
|
175
|
-
parts.push({ type: "text", text: chunk.text });
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
const toolCalls = message.toolCalls?.map((call, index) => this.fromMistralToolCall(call, index)) ?? [];
|
|
180
|
-
if (toolCalls.length > 0) {
|
|
181
|
-
parts.splice(0, 0, ...toolCalls);
|
|
182
|
-
}
|
|
183
|
-
if (parts.length === 0) {
|
|
184
|
-
parts.push({ type: "text", text: "" });
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
role: "assistant",
|
|
188
|
-
content: parts
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
fromMistralToolCall(call, index) {
|
|
192
|
-
const args = typeof call.function.arguments === "string" ? call.function.arguments : JSON.stringify(call.function.arguments);
|
|
193
|
-
return {
|
|
194
|
-
type: "tool-call",
|
|
195
|
-
id: call.id ?? `tool-call-${index}`,
|
|
196
|
-
name: call.function.name,
|
|
197
|
-
arguments: args
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
toMistralMessage(message) {
|
|
201
|
-
const textContent = this.extractText(message.content);
|
|
202
|
-
const toolCalls = this.extractToolCalls(message);
|
|
203
|
-
switch (message.role) {
|
|
204
|
-
case "system":
|
|
205
|
-
return {
|
|
206
|
-
role: "system",
|
|
207
|
-
content: textContent ?? ""
|
|
208
|
-
};
|
|
209
|
-
case "user":
|
|
210
|
-
return {
|
|
211
|
-
role: "user",
|
|
212
|
-
content: textContent ?? ""
|
|
213
|
-
};
|
|
214
|
-
case "assistant":
|
|
215
|
-
return {
|
|
216
|
-
role: "assistant",
|
|
217
|
-
content: toolCalls.length > 0 ? null : textContent ?? "",
|
|
218
|
-
toolCalls: toolCalls.length > 0 ? toolCalls : undefined
|
|
219
|
-
};
|
|
220
|
-
case "tool":
|
|
221
|
-
return {
|
|
222
|
-
role: "tool",
|
|
223
|
-
content: textContent ?? "",
|
|
224
|
-
toolCallId: message.toolCallId ?? toolCalls[0]?.id
|
|
225
|
-
};
|
|
226
|
-
default:
|
|
227
|
-
return {
|
|
228
|
-
role: "user",
|
|
229
|
-
content: textContent ?? ""
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
extractText(parts) {
|
|
234
|
-
const textParts = parts.filter((part) => part.type === "text").map((part) => part.text);
|
|
235
|
-
if (textParts.length === 0)
|
|
236
|
-
return null;
|
|
237
|
-
return textParts.join("");
|
|
238
|
-
}
|
|
239
|
-
extractToolCalls(message) {
|
|
240
|
-
const toolCallParts = message.content.filter((part) => part.type === "tool-call");
|
|
241
|
-
return toolCallParts.map((call, index) => ({
|
|
242
|
-
id: call.id ?? `call_${index}`,
|
|
243
|
-
type: "function",
|
|
244
|
-
index,
|
|
245
|
-
function: {
|
|
246
|
-
name: call.name,
|
|
247
|
-
arguments: call.arguments
|
|
248
|
-
}
|
|
249
|
-
}));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
function mapFinishReason(reason) {
|
|
253
|
-
if (!reason)
|
|
254
|
-
return;
|
|
255
|
-
const normalized = reason.toLowerCase();
|
|
256
|
-
switch (normalized) {
|
|
257
|
-
case "stop":
|
|
258
|
-
return "stop";
|
|
259
|
-
case "length":
|
|
260
|
-
return "length";
|
|
261
|
-
case "tool_call":
|
|
262
|
-
case "tool_calls":
|
|
263
|
-
return "tool_call";
|
|
264
|
-
case "content_filter":
|
|
265
|
-
return "content_filter";
|
|
266
|
-
default:
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
export {
|
|
271
|
-
MistralLLMProvider
|
|
272
|
-
};
|
|
1
|
+
import{createRequire as g}from"node:module";var x=g(import.meta.url);import{Mistral as h}from"@mistralai/mistralai";class M{client;defaultModel;constructor(t){if(!t.apiKey)throw Error("MistralLLMProvider requires an apiKey");this.client=t.client??new h({apiKey:t.apiKey,serverURL:t.serverURL,userAgent:t.userAgentSuffix?`${t.userAgentSuffix}`:void 0}),this.defaultModel=t.defaultModel??"mistral-large-latest"}async chat(t,e={}){let n=this.buildChatRequest(t,e),o=await this.client.chat.complete(n);return this.buildLLMResponse(o)}async*stream(t,e={}){let n=this.buildChatRequest(t,e);n.stream=!0;let o=await this.client.chat.stream(n),s=[],a=[],u,p;for await(let c of o){for(let r of c.data.choices){let l=r.delta;if(typeof l.content==="string"){if(l.content.length>0)s.push({type:"text",text:l.content}),yield{type:"message_delta",delta:{type:"text",text:l.content},index:r.index}}else if(Array.isArray(l.content)){for(let i of l.content)if(i.type==="text"&&"text"in i)s.push({type:"text",text:i.text}),yield{type:"message_delta",delta:{type:"text",text:i.text},index:r.index}}if(l.toolCalls){let i=0;for(let L of l.toolCalls){let m=this.fromMistralToolCall(L,i);a.push(m),yield{type:"tool_call",call:m,index:r.index},i+=1}}if(r.finishReason&&r.finishReason!=="null")p=r.finishReason}if(c.data.usage){let r=this.fromUsage(c.data.usage);if(r)u=r,yield{type:"usage",usage:r}}}let f={role:"assistant",content:s.length?s:[{type:"text",text:""}]};if(a.length>0)f.content=[...a,...s.length?s:[]];yield{type:"end",response:{message:f,usage:u,finishReason:d(p)}}}async countTokens(t){throw Error("Mistral API does not currently support token counting")}buildChatRequest(t,e){let n=e.model??this.defaultModel,o=t.map((a)=>this.toMistralMessage(a)),s={model:n,messages:o};if(e.temperature!=null)s.temperature=e.temperature;if(e.topP!=null)s.topP=e.topP;if(e.maxOutputTokens!=null)s.maxTokens=e.maxOutputTokens;if(e.stopSequences?.length)s.stop=e.stopSequences.length===1?e.stopSequences[0]:e.stopSequences;if(e.tools?.length)s.tools=e.tools.map((a)=>({type:"function",function:{name:a.name,description:a.description,parameters:typeof a.inputSchema==="object"&&a.inputSchema!==null?a.inputSchema:{}}}));if(e.responseFormat==="json")s.responseFormat={type:"json_object"};return s}buildLLMResponse(t){let e=t.choices[0];if(!e?.message)return{message:{role:"assistant",content:[{type:"text",text:""}]},usage:this.fromUsage(t.usage),raw:t};return{message:this.fromAssistantMessage(e.message),usage:this.fromUsage(t.usage),finishReason:d(e.finishReason),raw:t}}fromUsage(t){if(!t)return;return{promptTokens:t.promptTokens??0,completionTokens:t.completionTokens??0,totalTokens:t.totalTokens??0}}fromAssistantMessage(t){let e=[];if(typeof t.content==="string")e.push({type:"text",text:t.content});else if(Array.isArray(t.content))t.content.forEach((o)=>{if(o.type==="text"&&"text"in o)e.push({type:"text",text:o.text})});let n=t.toolCalls?.map((o,s)=>this.fromMistralToolCall(o,s))??[];if(n.length>0)e.splice(0,0,...n);if(e.length===0)e.push({type:"text",text:""});return{role:"assistant",content:e}}fromMistralToolCall(t,e){let n=typeof t.function.arguments==="string"?t.function.arguments:JSON.stringify(t.function.arguments);return{type:"tool-call",id:t.id??`tool-call-${e}`,name:t.function.name,arguments:n}}toMistralMessage(t){let e=this.extractText(t.content),n=this.extractToolCalls(t);switch(t.role){case"system":return{role:"system",content:e??""};case"user":return{role:"user",content:e??""};case"assistant":return{role:"assistant",content:n.length>0?null:e??"",toolCalls:n.length>0?n:void 0};case"tool":return{role:"tool",content:e??"",toolCallId:t.toolCallId??n[0]?.id};default:return{role:"user",content:e??""}}}extractText(t){let e=t.filter((n)=>n.type==="text").map((n)=>n.text);if(e.length===0)return null;return e.join("")}extractToolCalls(t){return t.content.filter((n)=>n.type==="tool-call").map((n,o)=>({id:n.id??`call_${o}`,type:"function",index:o,function:{name:n.name,arguments:n.arguments}}))}}function d(t){if(!t)return;switch(t.toLowerCase()){case"stop":return"stop";case"length":return"length";case"tool_call":case"tool_calls":return"tool_call";case"content_filter":return"content_filter";default:return}}export{M as MistralLLMProvider};
|
|
@@ -1,169 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
-
|
|
4
|
-
// src/impls/mistral-stt.ts
|
|
5
|
-
var DEFAULT_BASE_URL = "https://api.mistral.ai/v1";
|
|
6
|
-
var DEFAULT_MODEL = "voxtral-mini-latest";
|
|
7
|
-
var AUDIO_MIME_BY_FORMAT = {
|
|
8
|
-
mp3: "audio/mpeg",
|
|
9
|
-
wav: "audio/wav",
|
|
10
|
-
ogg: "audio/ogg",
|
|
11
|
-
pcm: "audio/pcm",
|
|
12
|
-
opus: "audio/opus"
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
class MistralSttProvider {
|
|
16
|
-
apiKey;
|
|
17
|
-
defaultModel;
|
|
18
|
-
defaultLanguage;
|
|
19
|
-
baseUrl;
|
|
20
|
-
fetchImpl;
|
|
21
|
-
constructor(options) {
|
|
22
|
-
if (!options.apiKey) {
|
|
23
|
-
throw new Error("MistralSttProvider requires an apiKey");
|
|
24
|
-
}
|
|
25
|
-
this.apiKey = options.apiKey;
|
|
26
|
-
this.defaultModel = options.defaultModel ?? DEFAULT_MODEL;
|
|
27
|
-
this.defaultLanguage = options.defaultLanguage;
|
|
28
|
-
this.baseUrl = normalizeBaseUrl(options.serverURL ?? DEFAULT_BASE_URL);
|
|
29
|
-
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
30
|
-
}
|
|
31
|
-
async transcribe(input) {
|
|
32
|
-
const formData = new FormData;
|
|
33
|
-
const model = input.model ?? this.defaultModel;
|
|
34
|
-
const mimeType = AUDIO_MIME_BY_FORMAT[input.audio.format] ?? "audio/wav";
|
|
35
|
-
const fileName = `audio.${input.audio.format}`;
|
|
36
|
-
const audioBytes = new Uint8Array(input.audio.data);
|
|
37
|
-
const blob = new Blob([audioBytes], { type: mimeType });
|
|
38
|
-
formData.append("file", blob, fileName);
|
|
39
|
-
formData.append("model", model);
|
|
40
|
-
formData.append("response_format", "verbose_json");
|
|
41
|
-
const language = input.language ?? this.defaultLanguage;
|
|
42
|
-
if (language) {
|
|
43
|
-
formData.append("language", language);
|
|
44
|
-
}
|
|
45
|
-
const response = await this.fetchImpl(`${this.baseUrl}/audio/transcriptions`, {
|
|
46
|
-
method: "POST",
|
|
47
|
-
headers: {
|
|
48
|
-
Authorization: `Bearer ${this.apiKey}`
|
|
49
|
-
},
|
|
50
|
-
body: formData
|
|
51
|
-
});
|
|
52
|
-
if (!response.ok) {
|
|
53
|
-
const body = await response.text();
|
|
54
|
-
throw new Error(`Mistral transcription request failed (${response.status}): ${body}`);
|
|
55
|
-
}
|
|
56
|
-
const payload = await response.json();
|
|
57
|
-
return toTranscriptionResult(payload, input);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function toTranscriptionResult(payload, input) {
|
|
61
|
-
const record = asRecord(payload);
|
|
62
|
-
const text = readString(record, "text") ?? "";
|
|
63
|
-
const language = readString(record, "language") ?? input.language ?? "unknown";
|
|
64
|
-
const segments = parseSegments(record);
|
|
65
|
-
if (segments.length === 0 && text.length > 0) {
|
|
66
|
-
segments.push({
|
|
67
|
-
text,
|
|
68
|
-
startMs: 0,
|
|
69
|
-
endMs: input.audio.durationMs ?? 0
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
const durationMs = input.audio.durationMs ?? segments.reduce((max, segment) => Math.max(max, segment.endMs), 0);
|
|
73
|
-
const topLevelWords = parseWordTimings(record.words);
|
|
74
|
-
const flattenedWords = segments.flatMap((segment) => segment.wordTimings ?? []);
|
|
75
|
-
const wordTimings = topLevelWords.length > 0 ? topLevelWords : flattenedWords.length > 0 ? flattenedWords : undefined;
|
|
76
|
-
const speakers = dedupeSpeakers(segments);
|
|
77
|
-
return {
|
|
78
|
-
text,
|
|
79
|
-
segments,
|
|
80
|
-
language,
|
|
81
|
-
durationMs,
|
|
82
|
-
speakers: speakers.length > 0 ? speakers : undefined,
|
|
83
|
-
wordTimings
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function parseSegments(record) {
|
|
87
|
-
if (!Array.isArray(record.segments)) {
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
const parsed = [];
|
|
91
|
-
for (const entry of record.segments) {
|
|
92
|
-
const segmentRecord = asRecord(entry);
|
|
93
|
-
const text = readString(segmentRecord, "text");
|
|
94
|
-
if (!text) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
const startSeconds = readNumber(segmentRecord, "start") ?? 0;
|
|
98
|
-
const endSeconds = readNumber(segmentRecord, "end") ?? startSeconds;
|
|
99
|
-
parsed.push({
|
|
100
|
-
text,
|
|
101
|
-
startMs: secondsToMs(startSeconds),
|
|
102
|
-
endMs: secondsToMs(endSeconds),
|
|
103
|
-
speakerId: readString(segmentRecord, "speaker") ?? undefined,
|
|
104
|
-
confidence: readNumber(segmentRecord, "confidence"),
|
|
105
|
-
wordTimings: parseWordTimings(segmentRecord.words)
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return parsed;
|
|
109
|
-
}
|
|
110
|
-
function parseWordTimings(value) {
|
|
111
|
-
if (!Array.isArray(value)) {
|
|
112
|
-
return [];
|
|
113
|
-
}
|
|
114
|
-
const words = [];
|
|
115
|
-
for (const entry of value) {
|
|
116
|
-
const wordRecord = asRecord(entry);
|
|
117
|
-
const word = readString(wordRecord, "word");
|
|
118
|
-
const startSeconds = readNumber(wordRecord, "start");
|
|
119
|
-
const endSeconds = readNumber(wordRecord, "end");
|
|
120
|
-
if (!word || startSeconds == null || endSeconds == null) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
words.push({
|
|
124
|
-
word,
|
|
125
|
-
startMs: secondsToMs(startSeconds),
|
|
126
|
-
endMs: secondsToMs(endSeconds),
|
|
127
|
-
confidence: readNumber(wordRecord, "confidence")
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
return words;
|
|
131
|
-
}
|
|
132
|
-
function dedupeSpeakers(segments) {
|
|
133
|
-
const seen = new Set;
|
|
134
|
-
const speakers = [];
|
|
135
|
-
for (const segment of segments) {
|
|
136
|
-
if (!segment.speakerId || seen.has(segment.speakerId)) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
seen.add(segment.speakerId);
|
|
140
|
-
speakers.push({
|
|
141
|
-
id: segment.speakerId,
|
|
142
|
-
name: segment.speakerName
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
return speakers;
|
|
146
|
-
}
|
|
147
|
-
function normalizeBaseUrl(url) {
|
|
148
|
-
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
149
|
-
}
|
|
150
|
-
function asRecord(value) {
|
|
151
|
-
if (value && typeof value === "object") {
|
|
152
|
-
return value;
|
|
153
|
-
}
|
|
154
|
-
return {};
|
|
155
|
-
}
|
|
156
|
-
function readString(record, key) {
|
|
157
|
-
const value = record[key];
|
|
158
|
-
return typeof value === "string" ? value : undefined;
|
|
159
|
-
}
|
|
160
|
-
function readNumber(record, key) {
|
|
161
|
-
const value = record[key];
|
|
162
|
-
return typeof value === "number" ? value : undefined;
|
|
163
|
-
}
|
|
164
|
-
function secondsToMs(value) {
|
|
165
|
-
return Math.round(value * 1000);
|
|
166
|
-
}
|
|
167
|
-
export {
|
|
168
|
-
MistralSttProvider
|
|
169
|
-
};
|
|
1
|
+
import{createRequire as w}from"node:module";var A=w(import.meta.url);var y={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",pcm:"audio/pcm",opus:"audio/opus"};class M{apiKey;defaultModel;defaultLanguage;baseUrl;fetchImpl;constructor(e){if(!e.apiKey)throw Error("MistralSttProvider requires an apiKey");this.apiKey=e.apiKey,this.defaultModel=e.defaultModel??"voxtral-mini-latest",this.defaultLanguage=e.defaultLanguage,this.baseUrl=R(e.serverURL??"https://api.mistral.ai/v1"),this.fetchImpl=e.fetchImpl??fetch}async transcribe(e){let t=new FormData,r=e.model??this.defaultModel,n=y[e.audio.format]??"audio/wav",o=`audio.${e.audio.format}`,s=new Uint8Array(e.audio.data),a=new Blob([s],{type:n});t.append("file",a,o),t.append("model",r),t.append("response_format","verbose_json");let c=e.language??this.defaultLanguage;if(c)t.append("language",c);let i=await this.fetchImpl(`${this.baseUrl}/audio/transcriptions`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:t});if(!i.ok){let p=await i.text();throw Error(`Mistral transcription request failed (${i.status}): ${p}`)}let f=await i.json();return S(f,e)}}function S(e,t){let r=m(e),n=u(r,"text")??"",o=u(r,"language")??t.language??"unknown",s=k(r);if(s.length===0&&n.length>0)s.push({text:n,startMs:0,endMs:t.audio.durationMs??0});let a=t.audio.durationMs??s.reduce((l,h)=>Math.max(l,h.endMs),0),c=T(r.words),i=s.flatMap((l)=>l.wordTimings??[]),f=c.length>0?c:i.length>0?i:void 0,p=v(s);return{text:n,segments:s,language:o,durationMs:a,speakers:p.length>0?p:void 0,wordTimings:f}}function k(e){if(!Array.isArray(e.segments))return[];let t=[];for(let r of e.segments){let n=m(r),o=u(n,"text");if(!o)continue;let s=d(n,"start")??0,a=d(n,"end")??s;t.push({text:o,startMs:g(s),endMs:g(a),speakerId:u(n,"speaker")??void 0,confidence:d(n,"confidence"),wordTimings:T(n.words)})}return t}function T(e){if(!Array.isArray(e))return[];let t=[];for(let r of e){let n=m(r),o=u(n,"word"),s=d(n,"start"),a=d(n,"end");if(!o||s==null||a==null)continue;t.push({word:o,startMs:g(s),endMs:g(a),confidence:d(n,"confidence")})}return t}function v(e){let t=new Set,r=[];for(let n of e){if(!n.speakerId||t.has(n.speakerId))continue;t.add(n.speakerId),r.push({id:n.speakerId,name:n.speakerName})}return r}function R(e){return e.endsWith("/")?e.slice(0,-1):e}function m(e){if(e&&typeof e==="object")return e;return{}}function u(e,t){let r=e[t];return typeof r==="string"?r:void 0}function d(e,t){let r=e[t];return typeof r==="number"?r:void 0}function g(e){return Math.round(e*1000)}export{M as MistralSttProvider};
|
|
@@ -1,163 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
-
|
|
4
|
-
// src/impls/notion.ts
|
|
5
|
-
import { Client } from "@notionhq/client";
|
|
6
|
-
|
|
7
|
-
class NotionProjectManagementProvider {
|
|
8
|
-
client;
|
|
9
|
-
defaults;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.client = options.client ?? new Client({ auth: options.apiKey });
|
|
12
|
-
this.defaults = {
|
|
13
|
-
databaseId: options.databaseId,
|
|
14
|
-
summaryParentPageId: options.summaryParentPageId,
|
|
15
|
-
titleProperty: options.titleProperty,
|
|
16
|
-
statusProperty: options.statusProperty,
|
|
17
|
-
priorityProperty: options.priorityProperty,
|
|
18
|
-
tagsProperty: options.tagsProperty,
|
|
19
|
-
dueDateProperty: options.dueDateProperty,
|
|
20
|
-
descriptionProperty: options.descriptionProperty
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async createWorkItem(input) {
|
|
24
|
-
if (input.type === "summary" && this.defaults.summaryParentPageId) {
|
|
25
|
-
return this.createSummaryPage(input);
|
|
26
|
-
}
|
|
27
|
-
const databaseId = this.defaults.databaseId;
|
|
28
|
-
if (!databaseId) {
|
|
29
|
-
throw new Error("Notion databaseId is required to create work items.");
|
|
30
|
-
}
|
|
31
|
-
const titleProperty = this.defaults.titleProperty ?? "Name";
|
|
32
|
-
const properties = {
|
|
33
|
-
[titleProperty]: buildTitleProperty(input.title)
|
|
34
|
-
};
|
|
35
|
-
applySelect(properties, this.defaults.statusProperty, input.status);
|
|
36
|
-
applySelect(properties, this.defaults.priorityProperty, input.priority);
|
|
37
|
-
applyMultiSelect(properties, this.defaults.tagsProperty, input.tags);
|
|
38
|
-
applyDate(properties, this.defaults.dueDateProperty, input.dueDate);
|
|
39
|
-
applyRichText(properties, this.defaults.descriptionProperty, input.description);
|
|
40
|
-
const page = await this.client.pages.create({
|
|
41
|
-
parent: { type: "database_id", database_id: databaseId },
|
|
42
|
-
properties
|
|
43
|
-
});
|
|
44
|
-
return {
|
|
45
|
-
id: page.id,
|
|
46
|
-
title: input.title,
|
|
47
|
-
url: "url" in page ? page.url : undefined,
|
|
48
|
-
status: input.status,
|
|
49
|
-
priority: input.priority,
|
|
50
|
-
tags: input.tags,
|
|
51
|
-
projectId: databaseId,
|
|
52
|
-
externalId: input.externalId,
|
|
53
|
-
metadata: input.metadata
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
async createWorkItems(items) {
|
|
57
|
-
const created = [];
|
|
58
|
-
for (const item of items) {
|
|
59
|
-
created.push(await this.createWorkItem(item));
|
|
60
|
-
}
|
|
61
|
-
return created;
|
|
62
|
-
}
|
|
63
|
-
async createSummaryPage(input) {
|
|
64
|
-
const parentId = this.defaults.summaryParentPageId;
|
|
65
|
-
if (!parentId) {
|
|
66
|
-
throw new Error("Notion summaryParentPageId is required for summaries.");
|
|
67
|
-
}
|
|
68
|
-
const summaryProperties = {
|
|
69
|
-
title: buildTitleProperty(input.title)
|
|
70
|
-
};
|
|
71
|
-
const page = await this.client.pages.create({
|
|
72
|
-
parent: { type: "page_id", page_id: parentId },
|
|
73
|
-
properties: summaryProperties
|
|
74
|
-
});
|
|
75
|
-
if (input.description) {
|
|
76
|
-
const children = buildParagraphBlocks(input.description);
|
|
77
|
-
if (children.length > 0) {
|
|
78
|
-
await this.client.blocks.children.append({
|
|
79
|
-
block_id: page.id,
|
|
80
|
-
children
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
id: page.id,
|
|
86
|
-
title: input.title,
|
|
87
|
-
url: "url" in page ? page.url : undefined,
|
|
88
|
-
status: input.status,
|
|
89
|
-
priority: input.priority,
|
|
90
|
-
tags: input.tags,
|
|
91
|
-
projectId: parentId,
|
|
92
|
-
externalId: input.externalId,
|
|
93
|
-
metadata: input.metadata
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function buildTitleProperty(title) {
|
|
98
|
-
return {
|
|
99
|
-
title: [
|
|
100
|
-
{
|
|
101
|
-
type: "text",
|
|
102
|
-
text: { content: title }
|
|
103
|
-
}
|
|
104
|
-
]
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function buildRichText(text) {
|
|
108
|
-
return {
|
|
109
|
-
rich_text: [
|
|
110
|
-
{
|
|
111
|
-
type: "text",
|
|
112
|
-
text: { content: text }
|
|
113
|
-
}
|
|
114
|
-
]
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function applySelect(properties, property, value) {
|
|
118
|
-
if (!property || !value)
|
|
119
|
-
return;
|
|
120
|
-
const next = {
|
|
121
|
-
select: { name: value }
|
|
122
|
-
};
|
|
123
|
-
properties[property] = next;
|
|
124
|
-
}
|
|
125
|
-
function applyMultiSelect(properties, property, values) {
|
|
126
|
-
if (!property || !values || values.length === 0)
|
|
127
|
-
return;
|
|
128
|
-
const next = {
|
|
129
|
-
multi_select: values.map((value) => ({ name: value }))
|
|
130
|
-
};
|
|
131
|
-
properties[property] = next;
|
|
132
|
-
}
|
|
133
|
-
function applyDate(properties, property, value) {
|
|
134
|
-
if (!property || !value)
|
|
135
|
-
return;
|
|
136
|
-
const next = {
|
|
137
|
-
date: { start: value.toISOString() }
|
|
138
|
-
};
|
|
139
|
-
properties[property] = next;
|
|
140
|
-
}
|
|
141
|
-
function applyRichText(properties, property, value) {
|
|
142
|
-
if (!property || !value)
|
|
143
|
-
return;
|
|
144
|
-
properties[property] = buildRichText(value);
|
|
145
|
-
}
|
|
146
|
-
function buildParagraphBlocks(text) {
|
|
147
|
-
const lines = text.split(/\r?\n/).filter((line) => line.trim());
|
|
148
|
-
return lines.map((line) => ({
|
|
149
|
-
object: "block",
|
|
150
|
-
type: "paragraph",
|
|
151
|
-
paragraph: {
|
|
152
|
-
rich_text: [
|
|
153
|
-
{
|
|
154
|
-
type: "text",
|
|
155
|
-
text: { content: line }
|
|
156
|
-
}
|
|
157
|
-
]
|
|
158
|
-
}
|
|
159
|
-
}));
|
|
160
|
-
}
|
|
161
|
-
export {
|
|
162
|
-
NotionProjectManagementProvider
|
|
163
|
-
};
|
|
1
|
+
import{createRequire as s}from"node:module";var u=s(import.meta.url);import{Client as c}from"@notionhq/client";class d{client;defaults;constructor(t){this.client=t.client??new c({auth:t.apiKey}),this.defaults={databaseId:t.databaseId,summaryParentPageId:t.summaryParentPageId,titleProperty:t.titleProperty,statusProperty:t.statusProperty,priorityProperty:t.priorityProperty,tagsProperty:t.tagsProperty,dueDateProperty:t.dueDateProperty,descriptionProperty:t.descriptionProperty}}async createWorkItem(t){if(t.type==="summary"&&this.defaults.summaryParentPageId)return this.createSummaryPage(t);let e=this.defaults.databaseId;if(!e)throw Error("Notion databaseId is required to create work items.");let o={[this.defaults.titleProperty??"Name"]:n(t.title)};i(o,this.defaults.statusProperty,t.status),i(o,this.defaults.priorityProperty,t.priority),l(o,this.defaults.tagsProperty,t.tags),P(o,this.defaults.dueDateProperty,t.dueDate),y(o,this.defaults.descriptionProperty,t.description);let a=await this.client.pages.create({parent:{type:"database_id",database_id:e},properties:o});return{id:a.id,title:t.title,url:"url"in a?a.url:void 0,status:t.status,priority:t.priority,tags:t.tags,projectId:e,externalId:t.externalId,metadata:t.metadata}}async createWorkItems(t){let e=[];for(let r of t)e.push(await this.createWorkItem(r));return e}async createSummaryPage(t){let e=this.defaults.summaryParentPageId;if(!e)throw Error("Notion summaryParentPageId is required for summaries.");let r={title:n(t.title)},o=await this.client.pages.create({parent:{type:"page_id",page_id:e},properties:r});if(t.description){let a=m(t.description);if(a.length>0)await this.client.blocks.children.append({block_id:o.id,children:a})}return{id:o.id,title:t.title,url:"url"in o?o.url:void 0,status:t.status,priority:t.priority,tags:t.tags,projectId:e,externalId:t.externalId,metadata:t.metadata}}}function n(t){return{title:[{type:"text",text:{content:t}}]}}function p(t){return{rich_text:[{type:"text",text:{content:t}}]}}function i(t,e,r){if(!e||!r)return;let o={select:{name:r}};t[e]=o}function l(t,e,r){if(!e||!r||r.length===0)return;let o={multi_select:r.map((a)=>({name:a}))};t[e]=o}function P(t,e,r){if(!e||!r)return;let o={date:{start:r.toISOString()}};t[e]=o}function y(t,e,r){if(!e||!r)return;t[e]=p(r)}function m(t){return t.split(/\r?\n/).filter((r)=>r.trim()).map((r)=>({object:"block",type:"paragraph",paragraph:{rich_text:[{type:"text",text:{content:r}}]}}))}export{d as NotionProjectManagementProvider};
|