@contractspec/integration.providers-impls 1.56.1 → 1.58.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.
Files changed (238) hide show
  1. package/README.md +115 -1
  2. package/dist/analytics.d.ts +2 -0
  3. package/dist/analytics.d.ts.map +1 -0
  4. package/dist/analytics.js +3 -0
  5. package/dist/calendar.d.ts +1 -7
  6. package/dist/calendar.d.ts.map +1 -1
  7. package/dist/calendar.js +3 -3
  8. package/dist/database.d.ts +2 -0
  9. package/dist/database.d.ts.map +1 -0
  10. package/dist/database.js +3 -0
  11. package/dist/email.d.ts +1 -7
  12. package/dist/email.d.ts.map +1 -1
  13. package/dist/email.js +3 -3
  14. package/dist/embedding.d.ts +1 -7
  15. package/dist/embedding.d.ts.map +1 -1
  16. package/dist/embedding.js +3 -3
  17. package/dist/impls/elevenlabs-voice.d.ts +14 -18
  18. package/dist/impls/elevenlabs-voice.d.ts.map +1 -1
  19. package/dist/impls/elevenlabs-voice.js +98 -88
  20. package/dist/impls/fal-voice.d.ts +25 -0
  21. package/dist/impls/fal-voice.d.ts.map +1 -0
  22. package/dist/impls/fal-voice.js +113 -0
  23. package/dist/impls/fathom-meeting-recorder.d.ts +38 -0
  24. package/dist/impls/fathom-meeting-recorder.d.ts.map +1 -0
  25. package/dist/impls/fathom-meeting-recorder.js +288 -0
  26. package/dist/impls/fathom-meeting-recorder.mapper.d.ts +5 -0
  27. package/dist/impls/fathom-meeting-recorder.mapper.d.ts.map +1 -0
  28. package/dist/impls/fathom-meeting-recorder.mapper.js +106 -0
  29. package/dist/impls/fathom-meeting-recorder.types.d.ts +20 -0
  30. package/dist/impls/fathom-meeting-recorder.types.d.ts.map +1 -0
  31. package/dist/impls/fathom-meeting-recorder.types.js +1 -0
  32. package/dist/impls/fathom-meeting-recorder.utils.d.ts +11 -0
  33. package/dist/impls/fathom-meeting-recorder.utils.d.ts.map +1 -0
  34. package/dist/impls/fathom-meeting-recorder.utils.js +73 -0
  35. package/dist/impls/fathom-meeting-recorder.webhooks.d.ts +4 -0
  36. package/dist/impls/fathom-meeting-recorder.webhooks.d.ts.map +1 -0
  37. package/dist/impls/fathom-meeting-recorder.webhooks.js +30 -0
  38. package/dist/impls/fireflies-meeting-recorder.d.ts +24 -0
  39. package/dist/impls/fireflies-meeting-recorder.d.ts.map +1 -0
  40. package/dist/impls/fireflies-meeting-recorder.js +275 -0
  41. package/dist/impls/fireflies-meeting-recorder.queries.d.ts +4 -0
  42. package/dist/impls/fireflies-meeting-recorder.queries.d.ts.map +1 -0
  43. package/dist/impls/fireflies-meeting-recorder.queries.js +86 -0
  44. package/dist/impls/fireflies-meeting-recorder.types.d.ts +32 -0
  45. package/dist/impls/fireflies-meeting-recorder.types.d.ts.map +1 -0
  46. package/dist/impls/fireflies-meeting-recorder.types.js +1 -0
  47. package/dist/impls/fireflies-meeting-recorder.utils.d.ts +5 -0
  48. package/dist/impls/fireflies-meeting-recorder.utils.d.ts.map +1 -0
  49. package/dist/impls/fireflies-meeting-recorder.utils.js +43 -0
  50. package/dist/impls/gcs-storage.d.ts +18 -22
  51. package/dist/impls/gcs-storage.d.ts.map +1 -1
  52. package/dist/impls/gcs-storage.js +92 -84
  53. package/dist/impls/gmail-inbound.d.ts +20 -24
  54. package/dist/impls/gmail-inbound.d.ts.map +1 -1
  55. package/dist/impls/gmail-inbound.js +212 -185
  56. package/dist/impls/gmail-outbound.d.ts +12 -16
  57. package/dist/impls/gmail-outbound.d.ts.map +1 -1
  58. package/dist/impls/gmail-outbound.js +126 -92
  59. package/dist/impls/google-calendar.d.ts +17 -21
  60. package/dist/impls/google-calendar.d.ts.map +1 -1
  61. package/dist/impls/google-calendar.js +182 -145
  62. package/dist/impls/gradium-voice.d.ts +24 -0
  63. package/dist/impls/gradium-voice.d.ts.map +1 -0
  64. package/dist/impls/gradium-voice.js +91 -0
  65. package/dist/impls/granola-meeting-recorder.d.ts +34 -0
  66. package/dist/impls/granola-meeting-recorder.d.ts.map +1 -0
  67. package/dist/impls/granola-meeting-recorder.js +513 -0
  68. package/dist/impls/granola-meeting-recorder.mcp.d.ts +25 -0
  69. package/dist/impls/granola-meeting-recorder.mcp.d.ts.map +1 -0
  70. package/dist/impls/granola-meeting-recorder.mcp.js +279 -0
  71. package/dist/impls/granola-meeting-recorder.types.d.ts +61 -0
  72. package/dist/impls/granola-meeting-recorder.types.d.ts.map +1 -0
  73. package/dist/impls/granola-meeting-recorder.types.js +1 -0
  74. package/dist/impls/index.d.ts +28 -15
  75. package/dist/impls/index.d.ts.map +1 -0
  76. package/dist/impls/index.js +4659 -16
  77. package/dist/impls/jira.d.ts +21 -0
  78. package/dist/impls/jira.d.ts.map +1 -0
  79. package/dist/impls/jira.js +125 -0
  80. package/dist/impls/linear.d.ts +20 -0
  81. package/dist/impls/linear.d.ts.map +1 -0
  82. package/dist/impls/linear.js +84 -0
  83. package/dist/impls/mistral-embedding.d.ts +17 -21
  84. package/dist/impls/mistral-embedding.d.ts.map +1 -1
  85. package/dist/impls/mistral-embedding.js +41 -39
  86. package/dist/impls/mistral-llm.d.ts +25 -29
  87. package/dist/impls/mistral-llm.d.ts.map +1 -1
  88. package/dist/impls/mistral-llm.js +266 -244
  89. package/dist/impls/notion.d.ts +23 -0
  90. package/dist/impls/notion.d.ts.map +1 -0
  91. package/dist/impls/notion.js +161 -0
  92. package/dist/impls/posthog-reader.d.ts +22 -0
  93. package/dist/impls/posthog-reader.d.ts.map +1 -0
  94. package/dist/impls/posthog-reader.js +160 -0
  95. package/dist/impls/posthog-utils.d.ts +5 -0
  96. package/dist/impls/posthog-utils.d.ts.map +1 -0
  97. package/dist/impls/posthog-utils.js +39 -0
  98. package/dist/impls/posthog.d.ts +36 -0
  99. package/dist/impls/posthog.d.ts.map +1 -0
  100. package/dist/impls/posthog.js +323 -0
  101. package/dist/impls/postmark-email.d.ts +13 -17
  102. package/dist/impls/postmark-email.d.ts.map +1 -1
  103. package/dist/impls/postmark-email.js +55 -50
  104. package/dist/impls/powens-client.d.ts +111 -114
  105. package/dist/impls/powens-client.d.ts.map +1 -1
  106. package/dist/impls/powens-client.js +194 -170
  107. package/dist/impls/powens-openbanking.d.ts +22 -26
  108. package/dist/impls/powens-openbanking.d.ts.map +1 -1
  109. package/dist/impls/powens-openbanking.js +425 -217
  110. package/dist/impls/provider-factory.d.ts +29 -25
  111. package/dist/impls/provider-factory.d.ts.map +1 -1
  112. package/dist/impls/provider-factory.js +4074 -136
  113. package/dist/impls/qdrant-vector.d.ts +18 -22
  114. package/dist/impls/qdrant-vector.d.ts.map +1 -1
  115. package/dist/impls/qdrant-vector.js +76 -69
  116. package/dist/impls/stripe-payments.d.ts +22 -26
  117. package/dist/impls/stripe-payments.d.ts.map +1 -1
  118. package/dist/impls/stripe-payments.js +219 -193
  119. package/dist/impls/supabase-psql.d.ts +24 -0
  120. package/dist/impls/supabase-psql.d.ts.map +1 -0
  121. package/dist/impls/supabase-psql.js +151 -0
  122. package/dist/impls/supabase-vector.d.ts +32 -0
  123. package/dist/impls/supabase-vector.d.ts.map +1 -0
  124. package/dist/impls/supabase-vector.js +324 -0
  125. package/dist/impls/tldv-meeting-recorder.d.ts +21 -0
  126. package/dist/impls/tldv-meeting-recorder.d.ts.map +1 -0
  127. package/dist/impls/tldv-meeting-recorder.js +146 -0
  128. package/dist/impls/twilio-sms.d.ts +14 -17
  129. package/dist/impls/twilio-sms.d.ts.map +1 -1
  130. package/dist/impls/twilio-sms.js +62 -55
  131. package/dist/index.d.ts +15 -43
  132. package/dist/index.d.ts.map +1 -1
  133. package/dist/index.js +4700 -69
  134. package/dist/llm.d.ts +1 -7
  135. package/dist/llm.d.ts.map +1 -1
  136. package/dist/llm.js +3 -3
  137. package/dist/meeting-recorder.d.ts +2 -0
  138. package/dist/meeting-recorder.d.ts.map +1 -0
  139. package/dist/meeting-recorder.js +3 -0
  140. package/dist/node/analytics.js +2 -0
  141. package/dist/node/calendar.js +2 -0
  142. package/dist/node/database.js +2 -0
  143. package/dist/node/email.js +2 -0
  144. package/dist/node/embedding.js +2 -0
  145. package/dist/node/impls/elevenlabs-voice.js +102 -0
  146. package/dist/node/impls/fal-voice.js +112 -0
  147. package/dist/node/impls/fathom-meeting-recorder.js +287 -0
  148. package/dist/node/impls/fathom-meeting-recorder.mapper.js +105 -0
  149. package/dist/node/impls/fathom-meeting-recorder.types.js +0 -0
  150. package/dist/node/impls/fathom-meeting-recorder.utils.js +72 -0
  151. package/dist/node/impls/fathom-meeting-recorder.webhooks.js +29 -0
  152. package/dist/node/impls/fireflies-meeting-recorder.js +274 -0
  153. package/dist/node/impls/fireflies-meeting-recorder.queries.js +85 -0
  154. package/dist/node/impls/fireflies-meeting-recorder.types.js +0 -0
  155. package/dist/node/impls/fireflies-meeting-recorder.utils.js +42 -0
  156. package/dist/node/impls/gcs-storage.js +97 -0
  157. package/dist/node/impls/gmail-inbound.js +227 -0
  158. package/dist/node/impls/gmail-outbound.js +139 -0
  159. package/dist/node/impls/google-calendar.js +191 -0
  160. package/dist/node/impls/gradium-voice.js +90 -0
  161. package/dist/node/impls/granola-meeting-recorder.js +512 -0
  162. package/dist/node/impls/granola-meeting-recorder.mcp.js +278 -0
  163. package/dist/node/impls/granola-meeting-recorder.types.js +0 -0
  164. package/dist/node/impls/index.js +4658 -0
  165. package/dist/node/impls/jira.js +124 -0
  166. package/dist/node/impls/linear.js +83 -0
  167. package/dist/node/impls/mistral-embedding.js +43 -0
  168. package/dist/node/impls/mistral-llm.js +269 -0
  169. package/dist/node/impls/notion.js +160 -0
  170. package/dist/node/impls/posthog-reader.js +159 -0
  171. package/dist/node/impls/posthog-utils.js +38 -0
  172. package/dist/node/impls/posthog.js +322 -0
  173. package/dist/node/impls/postmark-email.js +60 -0
  174. package/dist/node/impls/powens-client.js +195 -0
  175. package/dist/node/impls/powens-openbanking.js +426 -0
  176. package/dist/node/impls/provider-factory.js +4080 -0
  177. package/dist/node/impls/qdrant-vector.js +78 -0
  178. package/dist/node/impls/stripe-payments.js +228 -0
  179. package/dist/node/impls/supabase-psql.js +150 -0
  180. package/dist/node/impls/supabase-vector.js +323 -0
  181. package/dist/node/impls/tldv-meeting-recorder.js +145 -0
  182. package/dist/node/impls/twilio-sms.js +65 -0
  183. package/dist/node/index.js +4699 -0
  184. package/dist/node/llm.js +2 -0
  185. package/dist/node/meeting-recorder.js +2 -0
  186. package/dist/node/openbanking.js +2 -0
  187. package/dist/node/payments.js +2 -0
  188. package/dist/node/project-management.js +2 -0
  189. package/dist/node/runtime.js +0 -0
  190. package/dist/node/secrets/provider.js +11 -0
  191. package/dist/node/sms.js +2 -0
  192. package/dist/node/storage.js +2 -0
  193. package/dist/node/vector-store.js +2 -0
  194. package/dist/node/voice.js +2 -0
  195. package/dist/openbanking.d.ts +1 -7
  196. package/dist/openbanking.d.ts.map +1 -1
  197. package/dist/openbanking.js +3 -3
  198. package/dist/payments.d.ts +1 -7
  199. package/dist/payments.d.ts.map +1 -1
  200. package/dist/payments.js +3 -3
  201. package/dist/project-management.d.ts +2 -0
  202. package/dist/project-management.d.ts.map +1 -0
  203. package/dist/project-management.js +3 -0
  204. package/dist/runtime.d.ts +2 -2
  205. package/dist/runtime.d.ts.map +1 -0
  206. package/dist/runtime.js +1 -0
  207. package/dist/secrets/provider.d.ts +3 -2
  208. package/dist/secrets/provider.d.ts.map +1 -0
  209. package/dist/secrets/provider.js +12 -3
  210. package/dist/sms.d.ts +1 -7
  211. package/dist/sms.d.ts.map +1 -1
  212. package/dist/sms.js +3 -3
  213. package/dist/storage.d.ts +1 -7
  214. package/dist/storage.d.ts.map +1 -1
  215. package/dist/storage.js +3 -3
  216. package/dist/vector-store.d.ts +1 -7
  217. package/dist/vector-store.d.ts.map +1 -1
  218. package/dist/vector-store.js +3 -3
  219. package/dist/voice.d.ts +1 -7
  220. package/dist/voice.d.ts.map +1 -1
  221. package/dist/voice.js +3 -3
  222. package/package.json +419 -76
  223. package/dist/_virtual/rolldown_runtime.js +0 -36
  224. package/dist/impls/elevenlabs-voice.js.map +0 -1
  225. package/dist/impls/gcs-storage.js.map +0 -1
  226. package/dist/impls/gmail-inbound.js.map +0 -1
  227. package/dist/impls/gmail-outbound.js.map +0 -1
  228. package/dist/impls/google-calendar.js.map +0 -1
  229. package/dist/impls/mistral-embedding.js.map +0 -1
  230. package/dist/impls/mistral-llm.js.map +0 -1
  231. package/dist/impls/postmark-email.js.map +0 -1
  232. package/dist/impls/powens-client.js.map +0 -1
  233. package/dist/impls/powens-openbanking.js.map +0 -1
  234. package/dist/impls/provider-factory.js.map +0 -1
  235. package/dist/impls/qdrant-vector.js.map +0 -1
  236. package/dist/impls/stripe-payments.js.map +0 -1
  237. package/dist/impls/twilio-sms.js.map +0 -1
  238. package/dist/index.js.map +0 -1
@@ -1,248 +1,270 @@
1
+ // @bun
2
+ // src/impls/mistral-llm.ts
1
3
  import { Mistral } from "@mistralai/mistralai";
2
4
 
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
- };
5
+ class MistralLLMProvider {
6
+ client;
7
+ defaultModel;
8
+ constructor(options) {
9
+ if (!options.apiKey) {
10
+ throw new Error("MistralLLMProvider requires an apiKey");
11
+ }
12
+ this.client = options.client ?? new Mistral({
13
+ apiKey: options.apiKey,
14
+ serverURL: options.serverURL,
15
+ userAgent: options.userAgentSuffix ? `${options.userAgentSuffix}` : undefined
16
+ });
17
+ this.defaultModel = options.defaultModel ?? "mistral-large-latest";
18
+ }
19
+ async chat(messages, options = {}) {
20
+ const request = this.buildChatRequest(messages, options);
21
+ const response = await this.client.chat.complete(request);
22
+ return this.buildLLMResponse(response);
23
+ }
24
+ async* stream(messages, options = {}) {
25
+ const request = this.buildChatRequest(messages, options);
26
+ request.stream = true;
27
+ const stream = await this.client.chat.stream(request);
28
+ const aggregatedParts = [];
29
+ const aggregatedToolCalls = [];
30
+ let usage;
31
+ let finishReason;
32
+ for await (const event of stream) {
33
+ for (const choice of event.data.choices) {
34
+ const delta = choice.delta;
35
+ if (typeof delta.content === "string") {
36
+ if (delta.content.length > 0) {
37
+ aggregatedParts.push({ type: "text", text: delta.content });
38
+ yield {
39
+ type: "message_delta",
40
+ delta: { type: "text", text: delta.content },
41
+ index: choice.index
42
+ };
43
+ }
44
+ } else if (Array.isArray(delta.content)) {
45
+ for (const chunk of delta.content) {
46
+ if (chunk.type === "text" && "text" in chunk) {
47
+ aggregatedParts.push({ type: "text", text: chunk.text });
48
+ yield {
49
+ type: "message_delta",
50
+ delta: { type: "text", text: chunk.text },
51
+ index: choice.index
52
+ };
53
+ }
54
+ }
55
+ }
56
+ if (delta.toolCalls) {
57
+ let localIndex = 0;
58
+ for (const call of delta.toolCalls) {
59
+ const toolCall = this.fromMistralToolCall(call, localIndex);
60
+ aggregatedToolCalls.push(toolCall);
61
+ yield {
62
+ type: "tool_call",
63
+ call: toolCall,
64
+ index: choice.index
65
+ };
66
+ localIndex += 1;
67
+ }
68
+ }
69
+ if (choice.finishReason && choice.finishReason !== "null") {
70
+ finishReason = choice.finishReason;
71
+ }
72
+ }
73
+ if (event.data.usage) {
74
+ const usageEntry = this.fromUsage(event.data.usage);
75
+ if (usageEntry) {
76
+ usage = usageEntry;
77
+ yield { type: "usage", usage: usageEntry };
78
+ }
79
+ }
80
+ }
81
+ const message = {
82
+ role: "assistant",
83
+ content: aggregatedParts.length ? aggregatedParts : [{ type: "text", text: "" }]
84
+ };
85
+ if (aggregatedToolCalls.length > 0) {
86
+ message.content = [
87
+ ...aggregatedToolCalls,
88
+ ...aggregatedParts.length ? aggregatedParts : []
89
+ ];
90
+ }
91
+ yield {
92
+ type: "end",
93
+ response: {
94
+ message,
95
+ usage,
96
+ finishReason: mapFinishReason(finishReason)
97
+ }
98
+ };
99
+ }
100
+ async countTokens(_messages) {
101
+ throw new Error("Mistral API does not currently support token counting");
102
+ }
103
+ buildChatRequest(messages, options) {
104
+ const model = options.model ?? this.defaultModel;
105
+ const mappedMessages = messages.map((message) => this.toMistralMessage(message));
106
+ const request = {
107
+ model,
108
+ messages: mappedMessages
109
+ };
110
+ if (options.temperature != null) {
111
+ request.temperature = options.temperature;
112
+ }
113
+ if (options.topP != null) {
114
+ request.topP = options.topP;
115
+ }
116
+ if (options.maxOutputTokens != null) {
117
+ request.maxTokens = options.maxOutputTokens;
118
+ }
119
+ if (options.stopSequences?.length) {
120
+ request.stop = options.stopSequences.length === 1 ? options.stopSequences[0] : options.stopSequences;
121
+ }
122
+ if (options.tools?.length) {
123
+ request.tools = options.tools.map((tool) => ({
124
+ type: "function",
125
+ function: {
126
+ name: tool.name,
127
+ description: tool.description,
128
+ parameters: typeof tool.inputSchema === "object" && tool.inputSchema !== null ? tool.inputSchema : {}
129
+ }
130
+ }));
131
+ }
132
+ if (options.responseFormat === "json") {
133
+ request.responseFormat = { type: "json_object" };
134
+ }
135
+ return request;
136
+ }
137
+ buildLLMResponse(response) {
138
+ const firstChoice = response.choices[0];
139
+ if (!firstChoice) {
140
+ return {
141
+ message: {
142
+ role: "assistant",
143
+ content: [{ type: "text", text: "" }]
144
+ },
145
+ usage: this.fromUsage(response.usage),
146
+ raw: response
147
+ };
148
+ }
149
+ const message = this.fromAssistantMessage(firstChoice.message);
150
+ return {
151
+ message,
152
+ usage: this.fromUsage(response.usage),
153
+ finishReason: mapFinishReason(firstChoice.finishReason),
154
+ raw: response
155
+ };
156
+ }
157
+ fromUsage(usage) {
158
+ if (!usage)
159
+ return;
160
+ return {
161
+ promptTokens: usage.promptTokens ?? 0,
162
+ completionTokens: usage.completionTokens ?? 0,
163
+ totalTokens: usage.totalTokens ?? 0
164
+ };
165
+ }
166
+ fromAssistantMessage(message) {
167
+ const parts = [];
168
+ if (typeof message.content === "string") {
169
+ parts.push({ type: "text", text: message.content });
170
+ } else if (Array.isArray(message.content)) {
171
+ message.content.forEach((chunk) => {
172
+ if (chunk.type === "text" && "text" in chunk) {
173
+ parts.push({ type: "text", text: chunk.text });
174
+ }
175
+ });
176
+ }
177
+ const toolCalls = message.toolCalls?.map((call, index) => this.fromMistralToolCall(call, index)) ?? [];
178
+ if (toolCalls.length > 0) {
179
+ parts.splice(0, 0, ...toolCalls);
180
+ }
181
+ if (parts.length === 0) {
182
+ parts.push({ type: "text", text: "" });
183
+ }
184
+ return {
185
+ role: "assistant",
186
+ content: parts
187
+ };
188
+ }
189
+ fromMistralToolCall(call, index) {
190
+ const args = typeof call.function.arguments === "string" ? call.function.arguments : JSON.stringify(call.function.arguments);
191
+ return {
192
+ type: "tool-call",
193
+ id: call.id ?? `tool-call-${index}`,
194
+ name: call.function.name,
195
+ arguments: args
196
+ };
197
+ }
198
+ toMistralMessage(message) {
199
+ const textContent = this.extractText(message.content);
200
+ const toolCalls = this.extractToolCalls(message);
201
+ switch (message.role) {
202
+ case "system":
203
+ return {
204
+ role: "system",
205
+ content: textContent ?? ""
206
+ };
207
+ case "user":
208
+ return {
209
+ role: "user",
210
+ content: textContent ?? ""
211
+ };
212
+ case "assistant":
213
+ return {
214
+ role: "assistant",
215
+ content: toolCalls.length > 0 ? null : textContent ?? "",
216
+ toolCalls: toolCalls.length > 0 ? toolCalls : undefined
217
+ };
218
+ case "tool":
219
+ return {
220
+ role: "tool",
221
+ content: textContent ?? "",
222
+ toolCallId: message.toolCallId ?? toolCalls[0]?.id
223
+ };
224
+ default:
225
+ return {
226
+ role: "user",
227
+ content: textContent ?? ""
228
+ };
229
+ }
230
+ }
231
+ extractText(parts) {
232
+ const textParts = parts.filter((part) => part.type === "text").map((part) => part.text);
233
+ if (textParts.length === 0)
234
+ return null;
235
+ return textParts.join("");
236
+ }
237
+ extractToolCalls(message) {
238
+ const toolCallParts = message.content.filter((part) => part.type === "tool-call");
239
+ return toolCallParts.map((call, index) => ({
240
+ id: call.id ?? `call_${index}`,
241
+ type: "function",
242
+ index,
243
+ function: {
244
+ name: call.name,
245
+ arguments: call.arguments
246
+ }
247
+ }));
248
+ }
249
+ }
234
250
  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
- }
251
+ if (!reason)
252
+ return;
253
+ const normalized = reason.toLowerCase();
254
+ switch (normalized) {
255
+ case "stop":
256
+ return "stop";
257
+ case "length":
258
+ return "length";
259
+ case "tool_call":
260
+ case "tool_calls":
261
+ return "tool_call";
262
+ case "content_filter":
263
+ return "content_filter";
264
+ default:
265
+ return;
266
+ }
244
267
  }
245
-
246
- //#endregion
247
- export { MistralLLMProvider };
248
- //# sourceMappingURL=mistral-llm.js.map
268
+ export {
269
+ MistralLLMProvider
270
+ };
@@ -0,0 +1,23 @@
1
+ import { Client } from '@notionhq/client';
2
+ import type { ProjectManagementProvider, ProjectManagementWorkItem, ProjectManagementWorkItemInput } from '../project-management';
3
+ export interface NotionProjectManagementProviderOptions {
4
+ apiKey: string;
5
+ databaseId?: string;
6
+ summaryParentPageId?: string;
7
+ titleProperty?: string;
8
+ statusProperty?: string;
9
+ priorityProperty?: string;
10
+ tagsProperty?: string;
11
+ dueDateProperty?: string;
12
+ descriptionProperty?: string;
13
+ client?: Client;
14
+ }
15
+ export declare class NotionProjectManagementProvider implements ProjectManagementProvider {
16
+ private readonly client;
17
+ private readonly defaults;
18
+ constructor(options: NotionProjectManagementProviderOptions);
19
+ createWorkItem(input: ProjectManagementWorkItemInput): Promise<ProjectManagementWorkItem>;
20
+ createWorkItems(items: ProjectManagementWorkItemInput[]): Promise<ProjectManagementWorkItem[]>;
21
+ private createSummaryPage;
22
+ }
23
+ //# sourceMappingURL=notion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notion.d.ts","sourceRoot":"","sources":["../../src/impls/notion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EACzB,8BAA8B,EAC/B,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,sCAAsC;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAwBD,qBAAa,+BAAgC,YAAW,yBAAyB;IAC/E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGvB;gBAEU,OAAO,EAAE,sCAAsC;IAcrD,cAAc,CAClB,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,yBAAyB,CAAC;IA2C/B,eAAe,CACnB,KAAK,EAAE,8BAA8B,EAAE,GACtC,OAAO,CAAC,yBAAyB,EAAE,CAAC;YAQzB,iBAAiB;CAsChC"}