@alquimia-ai/tools 1.13.2 → 2.0.1
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/actions/index.d.mts +7 -17
- package/dist/actions/index.d.ts +7 -17
- package/dist/actions/index.js +45 -152
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/index.mjs +45 -152
- package/dist/actions/index.mjs.map +1 -1
- package/dist/adapters/fetch.d.mts +12 -0
- package/dist/adapters/fetch.d.ts +12 -0
- package/dist/adapters/fetch.js +44 -0
- package/dist/adapters/fetch.js.map +1 -0
- package/dist/adapters/fetch.mjs +23 -0
- package/dist/adapters/fetch.mjs.map +1 -0
- package/dist/adapters/index.d.mts +11 -0
- package/dist/adapters/index.d.ts +11 -0
- package/dist/adapters/index.js +19 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +1 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/adapters/next.d.mts +10 -0
- package/dist/adapters/next.d.ts +10 -0
- package/dist/adapters/next.js +42 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/next.mjs +21 -0
- package/dist/adapters/next.mjs.map +1 -0
- package/dist/hooks/index.d.mts +22 -2
- package/dist/hooks/index.d.ts +22 -2
- package/dist/hooks/index.js +243 -40
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +234 -41
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.d.mts +49 -0
- package/dist/next/index.d.ts +49 -0
- package/dist/next/index.js +332 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/index.mjs +309 -0
- package/dist/next/index.mjs.map +1 -0
- package/dist/providers/index.d.mts +7 -3
- package/dist/providers/index.d.ts +7 -3
- package/dist/providers/index.js +15 -14
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +15 -14
- package/dist/providers/index.mjs.map +1 -1
- package/dist/proxy.d.mts +15 -0
- package/dist/proxy.d.ts +15 -0
- package/dist/proxy.js +147 -0
- package/dist/proxy.js.map +1 -0
- package/dist/proxy.mjs +126 -0
- package/dist/proxy.mjs.map +1 -0
- package/dist/sdk/index.d.mts +8 -14
- package/dist/sdk/index.d.ts +8 -14
- package/dist/sdk/index.js +47 -47
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +47 -47
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/services/index.d.mts +25 -3
- package/dist/services/index.d.ts +25 -3
- package/package.json +35 -5
- package/dist/providers/elastic/index.d.mts +0 -23
- package/dist/providers/elastic/index.d.ts +0 -23
- package/dist/providers/elastic/index.js +0 -102
- package/dist/providers/elastic/index.js.map +0 -1
- package/dist/providers/elastic/index.mjs +0 -69
- package/dist/providers/elastic/index.mjs.map +0 -1
- package/dist/services/apm/index.d.mts +0 -26
- package/dist/services/apm/index.d.ts +0 -26
- package/dist/services/apm/index.js +0 -86
- package/dist/services/apm/index.js.map +0 -1
- package/dist/services/apm/index.mjs +0 -63
- package/dist/services/apm/index.mjs.map +0 -1
package/dist/sdk/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sdk/index.ts","../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["export { default as AlquimiaSDK } from './alquimia-sdk';","import axios, { AxiosInstance } from \"axios\";\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from \"../providers\";\nimport { AttachmentPayload, TTSResult } from \"../types\";\ninterface AlquimiaSDKConfig {\n apiKey: string;\n chatUrl: string;\n streamUrl: string;\n attachmentUrl: string;\n assistantId: string;\n}\n\n\nclass AlquimiaSDK {\n private config: AlquimiaSDKConfig;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n private streamId: string | null = null;\n private evaluationStrategy: string | null = null;\n private tools: any = [];\n private extraData: any = null;\n private assistantConfig: any = null;\n private forceProfile: any = {};\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider\n private stableDiffusionProvider?: StableDiffusionProvider\n private analyzeCharacterizationProvider?: CharacterizationProvider\n private ratingsProvider?: RatingsProvider\n private loggerProvider?: LoggerProvider\n private enforceCharacterization?: boolean\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n \n constructor(config: AlquimiaSDKConfig, enforceCharacterization: boolean = true) {\n this.config = config;\n this.enforceCharacterization = enforceCharacterization;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status) {\n if (this.loggerProvider) {\n await this.loggerProvider.logError(\n 'Server Error',\n error,\n {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data\n }\n );\n }\n }\n return Promise.reject(error);\n }\n );\n \n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n static configure(\n apiKey: string,\n inferUrl: string,\n streamUrl: string,\n attachmentUrl: string,\n assistantId: string,\n ): AlquimiaSDKConfig {\n return {\n apiKey,\n chatUrl: `${inferUrl}/chat/${assistantId}`,\n streamUrl: `${streamUrl}`,\n attachmentUrl: attachmentUrl,\n assistantId: assistantId,\n };\n }\n\n widthConversationId(conversationId: string ): AlquimiaSDK {\n this.conversationId = conversationId\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider\n return this\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider\n return this\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider\n return this\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider\n return this\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n getEvaluationStrategy(): string | null {\n return this.evaluationStrategy;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraData(extraData: any): AlquimiaSDK {\n this.extraData = extraData;\n return this;\n }\n\n withForceProfile(forceProfile: any): AlquimiaSDK {\n this.forceProfile = forceProfile;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error(\"Whisper provider not initialized\");\n }\n return this.whisperProvider.textToSpeech(text)\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error(\"Whisper provider not initialized\");\n }\n return this.whisperProvider.speechToText(audio)\n }\n\n async sendMessage(query: string, traceParent?: string) {\n if (!this.conversationId) {\n throw new Error(\"Conversation not initialized\");\n }\n\n const initMessage = {\n query,\n session_id: this.conversationId,\n ...(this.extraData && { extra_data: this.extraData }),\n force_profile: this.forceProfile,\n ...(this.assistantConfig && { config: this.assistantConfig }),\n tools: this.tools,\n user_id: this.userId,\n attachments: this.attachments,\n };\n\n const result = (await this.axiosInstance.post(this.config.chatUrl, initMessage, {\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-trace-parent\": traceParent || \"\",\n },\n })).data\n\n this.evaluationStrategy = result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id || null;\n this.streamId = result.stream_id;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this\n }\n\n async generateImage(query: string) {\n if (!this.stableDiffusionProvider) {\n throw new Error(\"Stable Diffusion provider not initialized\");\n }\n return this.stableDiffusionProvider.generateImage(query)\n }\n\n async analyzeCharacterization(text: string) {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error(\"analyze characterization provider not initialized\");\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text)\n }\n\n async rate(data: any) {\n if (!this.ratingsProvider) {\n throw new Error(\"ratings provider not initialized\");\n }\n return this.ratingsProvider.rate(data)\n }\n\n async logInfo(message: string, data: any) {\n if (!this.loggerProvider) {\n throw new Error(\"logger provider not initialized\");\n }\n return this.loggerProvider.logInfo(message, data)\n }\n\n async logError(message: string, error: Error, data: any) {\n if (!this.loggerProvider) {\n throw new Error(\"logger provider not initialized\");\n }\n return this.loggerProvider.logError(message, error, data)\n }\n\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, attachmentId: string): Promise<void> {\n if (!this.config.attachmentUrl) {\n throw new Error(\"Attachment URL not configured\");\n }\n if (!this.streamId || !attachmentId) {\n throw new Error(\"Stream or attachment ID not initialized\");\n }\n const url = `${this.config.attachmentUrl}/${this.streamId}/${attachmentId}`;\n const formData = new FormData();\n formData.append(\"file\", file);\n await this.axiosInstance.post(url, formData, {\n headers: { \"Content-Type\": \"multipart/form-data\" },\n });\n }\n\n getUrlStream() {\n return `${this.config.streamUrl}/${this.streamId}`;\n }\n\n getStreamId() {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;AAkBrC,IAAM,cAAN,MAAkB;AAAA,EAqBhB,YAAY,QAA2B,0BAAmC,MAAM;AAlBhF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AACnC,SAAQ,WAA0B;AAClC,SAAQ,qBAAoC;AAC5C,SAAQ,QAAa,CAAC;AACtB,SAAQ,YAAiB;AACzB,SAAQ,kBAAuB;AAC/B,SAAQ,eAAoB,CAAC;AAC7B,SAAQ,SAAwB;AAOhC,SAAQ,cAAmC,CAAC;AAC5C,SAAQ,sBAAgC,CAAC;AAGvC,SAAK,SA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,cAAqC;AACtE,QAAI,CAAC,KAAK,OAAO,eAAe;AAC9B,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AACA,QAAI,CAAC,KAAK,YAAY,CAAC,cAAc;AACnC,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AACA,UAAM,MAAM,GAAG,KAAK,OAAO,aAAa,IAAI,KAAK,QAAQ,IAAI,YAAY;AACzE,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,QAAQ,IAAI;AAC5B,UAAM,KAAK,cAAc,KAAK,KAAK,UAAU;AAAA,MAC3C,SAAS,EAAE,gBAAgB,sBAAsB;AAAA,IACnD,CAAC;AAAA,EACH;AAAA,EAEA,eAAe;AACb,WAAO,GAAG,KAAK,OAAO,SAAS,IAAI,KAAK,QAAQ;AAAA,EAClD;AAAA,EAEA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":["axios"]}
|
|
1
|
+
{"version":3,"sources":["../../src/sdk/index.ts","../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["export { default as AlquimiaSDK } from './alquimia-sdk';","import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n private streamId: string | null = null;\n private evaluationStrategy: string | null = null;\n private tools: any = [];\n private extraData: any = null;\n private assistantConfig: any = null;\n private forceProfile: any = {};\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraData(extraData: any): AlquimiaSDK {\n this.extraData = extraData;\n return this;\n }\n\n withForceProfile(forceProfile: any): AlquimiaSDK {\n this.forceProfile = forceProfile;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n getEvaluationStrategy(): string | null {\n return this.evaluationStrategy;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const initMessage = {\n query,\n session_id: this.conversationId,\n ...(this.extraData && { extra_data: this.extraData }),\n force_profile: this.forceProfile,\n ...(this.assistantConfig && { config: this.assistantConfig }),\n tools: this.tools,\n user_id: this.userId,\n attachments: this.attachments,\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n },\n })\n ).data;\n\n this.evaluationStrategy =\n result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id ?? null;\n this.streamId = result.stream_id;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, attachmentId: string): Promise<void> {\n if (!this.streamId || !attachmentId) {\n throw new Error('Stream or attachment ID not initialized');\n }\n const url = this.adapter.resolveAttachmentUrl(this.streamId, attachmentId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: { 'Content-Type': 'multipart/form-data', ...adapterHeaders },\n });\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAqC;AAWrC,IAAM,cAAN,MAAkB;AAAA,EAsBhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AAtBF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AACnC,SAAQ,WAA0B;AAClC,SAAQ,qBAAoC;AAC5C,SAAQ,QAAa,CAAC;AACtB,SAAQ,YAAiB;AACzB,SAAQ,kBAAuB;AAC/B,SAAQ,eAAoB,CAAC;AAC7B,SAAQ,SAAwB;AAOhC,SAAQ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S,SAAS,OAAO,IAAI;AAAA,EAC1D;AAAA,EAEA,yBAAmC;AACjC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,iBAAiB,MAAY,cAAqC;AACtE,QAAI,CAAC,KAAK,YAAY,CAAC,cAAc;AACnC,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AACA,UAAM,MAAM,KAAK,QAAQ,qBAAqB,KAAK,UAAU,YAAY;AACzE,UAAM,iBAAiB,KAAK,QAAQ,aAAa,KAAK,CAAC;AACvD,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,QAAQ,IAAI;AAC5B,UAAM,KAAK,cAAc,KAAK,KAAK,UAAU;AAAA,MAC3C,SAAS,EAAE,gBAAgB,uBAAuB,GAAG,eAAe;AAAA,IACtE,CAAC;AAAA,EACH;AAAA,EAEA,eAAuB;AACrB,QAAI,CAAC,KAAK,UAAU;AAClB,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AACA,WAAO,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AAAA,EACpD;AAAA,EAEA,cAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":["axios"]}
|
package/dist/sdk/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/sdk/alquimia-sdk.ts
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
var AlquimiaSDK = class {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(assistantId, adapter, options = {}) {
|
|
5
5
|
this.conversationId = null;
|
|
6
6
|
this.sessionId = null;
|
|
7
7
|
this.streamId = null;
|
|
@@ -13,26 +13,29 @@ var AlquimiaSDK = class {
|
|
|
13
13
|
this.userId = null;
|
|
14
14
|
this.attachments = [];
|
|
15
15
|
this.attachmentResponses = [];
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (!assistantId) {
|
|
17
|
+
throw new Error("AlquimiaSDK: assistantId is required");
|
|
18
|
+
}
|
|
19
|
+
if (!adapter) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
"AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()"
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
this.assistantId = assistantId;
|
|
25
|
+
this.adapter = adapter;
|
|
26
|
+
this.enforceCharacterization = options.enforceCharacterization ?? true;
|
|
18
27
|
this.axiosInstance = axios.create();
|
|
19
28
|
this.axiosInstance.interceptors.response.use(
|
|
20
29
|
(response) => response,
|
|
21
30
|
async (error) => {
|
|
22
|
-
if (error.response?.status) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
data: error.config.data,
|
|
31
|
-
status: error.response.status,
|
|
32
|
-
responseData: error.response.data
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
}
|
|
31
|
+
if (error.response?.status && this.loggerProvider) {
|
|
32
|
+
await this.loggerProvider.logError("Server Error", error, {
|
|
33
|
+
url: error.config.url,
|
|
34
|
+
method: error.config.method,
|
|
35
|
+
data: error.config.data,
|
|
36
|
+
status: error.response.status,
|
|
37
|
+
responseData: error.response.data
|
|
38
|
+
});
|
|
36
39
|
}
|
|
37
40
|
return Promise.reject(error);
|
|
38
41
|
}
|
|
@@ -40,16 +43,7 @@ var AlquimiaSDK = class {
|
|
|
40
43
|
this.textToSpeech = this.textToSpeech.bind(this);
|
|
41
44
|
this.speechToText = this.speechToText.bind(this);
|
|
42
45
|
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
apiKey,
|
|
46
|
-
chatUrl: `${inferUrl}/chat/${assistantId}`,
|
|
47
|
-
streamUrl: `${streamUrl}`,
|
|
48
|
-
attachmentUrl,
|
|
49
|
-
assistantId
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
widthConversationId(conversationId) {
|
|
46
|
+
withConversationId(conversationId) {
|
|
53
47
|
this.conversationId = conversationId;
|
|
54
48
|
return this;
|
|
55
49
|
}
|
|
@@ -77,12 +71,6 @@ var AlquimiaSDK = class {
|
|
|
77
71
|
this.loggerProvider = provider;
|
|
78
72
|
return this;
|
|
79
73
|
}
|
|
80
|
-
getEnforceCharacterization() {
|
|
81
|
-
return this.enforceCharacterization ?? true;
|
|
82
|
-
}
|
|
83
|
-
getEvaluationStrategy() {
|
|
84
|
-
return this.evaluationStrategy;
|
|
85
|
-
}
|
|
86
74
|
withTools(tools) {
|
|
87
75
|
this.tools = tools;
|
|
88
76
|
return this;
|
|
@@ -103,6 +91,12 @@ var AlquimiaSDK = class {
|
|
|
103
91
|
this.userId = userId;
|
|
104
92
|
return this;
|
|
105
93
|
}
|
|
94
|
+
getEnforceCharacterization() {
|
|
95
|
+
return this.enforceCharacterization ?? true;
|
|
96
|
+
}
|
|
97
|
+
getEvaluationStrategy() {
|
|
98
|
+
return this.evaluationStrategy;
|
|
99
|
+
}
|
|
106
100
|
textToSpeech(text) {
|
|
107
101
|
if (!this.whisperProvider) {
|
|
108
102
|
throw new Error("Whisper provider not initialized");
|
|
@@ -117,8 +111,12 @@ var AlquimiaSDK = class {
|
|
|
117
111
|
}
|
|
118
112
|
async sendMessage(query, traceParent) {
|
|
119
113
|
if (!this.conversationId) {
|
|
120
|
-
throw new Error(
|
|
114
|
+
throw new Error(
|
|
115
|
+
"Conversation not initialized. Call withConversationId() before sendMessage()"
|
|
116
|
+
);
|
|
121
117
|
}
|
|
118
|
+
const inferUrl = this.adapter.resolveInferUrl(this.assistantId);
|
|
119
|
+
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
122
120
|
const initMessage = {
|
|
123
121
|
query,
|
|
124
122
|
session_id: this.conversationId,
|
|
@@ -129,13 +127,14 @@ var AlquimiaSDK = class {
|
|
|
129
127
|
user_id: this.userId,
|
|
130
128
|
attachments: this.attachments
|
|
131
129
|
};
|
|
132
|
-
const result = (await this.axiosInstance.post(
|
|
130
|
+
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
133
131
|
headers: {
|
|
134
132
|
"Content-Type": "application/json",
|
|
135
|
-
"x-trace-parent": traceParent || ""
|
|
133
|
+
"x-trace-parent": traceParent || "",
|
|
134
|
+
...adapterHeaders
|
|
136
135
|
}
|
|
137
136
|
})).data;
|
|
138
|
-
this.evaluationStrategy = result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id
|
|
137
|
+
this.evaluationStrategy = result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id ?? null;
|
|
139
138
|
this.streamId = result.stream_id;
|
|
140
139
|
this.attachmentResponses = result.attachments ?? [];
|
|
141
140
|
this.attachments = [];
|
|
@@ -149,25 +148,25 @@ var AlquimiaSDK = class {
|
|
|
149
148
|
}
|
|
150
149
|
async analyzeCharacterization(text) {
|
|
151
150
|
if (!this.analyzeCharacterizationProvider) {
|
|
152
|
-
throw new Error("
|
|
151
|
+
throw new Error("Analyze characterization provider not initialized");
|
|
153
152
|
}
|
|
154
153
|
return this.analyzeCharacterizationProvider.analyzeCharacterization(text);
|
|
155
154
|
}
|
|
156
155
|
async rate(data) {
|
|
157
156
|
if (!this.ratingsProvider) {
|
|
158
|
-
throw new Error("
|
|
157
|
+
throw new Error("Ratings provider not initialized");
|
|
159
158
|
}
|
|
160
159
|
return this.ratingsProvider.rate(data);
|
|
161
160
|
}
|
|
162
161
|
async logInfo(message, data) {
|
|
163
162
|
if (!this.loggerProvider) {
|
|
164
|
-
throw new Error("
|
|
163
|
+
throw new Error("Logger provider not initialized");
|
|
165
164
|
}
|
|
166
165
|
return this.loggerProvider.logInfo(message, data);
|
|
167
166
|
}
|
|
168
167
|
async logError(message, error, data) {
|
|
169
168
|
if (!this.loggerProvider) {
|
|
170
|
-
throw new Error("
|
|
169
|
+
throw new Error("Logger provider not initialized");
|
|
171
170
|
}
|
|
172
171
|
return this.loggerProvider.logError(message, error, data);
|
|
173
172
|
}
|
|
@@ -175,21 +174,22 @@ var AlquimiaSDK = class {
|
|
|
175
174
|
return this.attachmentResponses;
|
|
176
175
|
}
|
|
177
176
|
async uploadAttachment(file, attachmentId) {
|
|
178
|
-
if (!this.config.attachmentUrl) {
|
|
179
|
-
throw new Error("Attachment URL not configured");
|
|
180
|
-
}
|
|
181
177
|
if (!this.streamId || !attachmentId) {
|
|
182
178
|
throw new Error("Stream or attachment ID not initialized");
|
|
183
179
|
}
|
|
184
|
-
const url =
|
|
180
|
+
const url = this.adapter.resolveAttachmentUrl(this.streamId, attachmentId);
|
|
181
|
+
const adapterHeaders = this.adapter.getHeaders?.() ?? {};
|
|
185
182
|
const formData = new FormData();
|
|
186
183
|
formData.append("file", file);
|
|
187
184
|
await this.axiosInstance.post(url, formData, {
|
|
188
|
-
headers: { "Content-Type": "multipart/form-data" }
|
|
185
|
+
headers: { "Content-Type": "multipart/form-data", ...adapterHeaders }
|
|
189
186
|
});
|
|
190
187
|
}
|
|
191
188
|
getUrlStream() {
|
|
192
|
-
|
|
189
|
+
if (!this.streamId) {
|
|
190
|
+
throw new Error("Stream ID not initialized. Call sendMessage() first");
|
|
191
|
+
}
|
|
192
|
+
return this.adapter.resolveStreamUrl(this.streamId);
|
|
193
193
|
}
|
|
194
194
|
getStreamId() {
|
|
195
195
|
return this.streamId;
|
package/dist/sdk/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from \"../providers\";\nimport { AttachmentPayload, TTSResult } from \"../types\";\ninterface AlquimiaSDKConfig {\n apiKey: string;\n chatUrl: string;\n streamUrl: string;\n attachmentUrl: string;\n assistantId: string;\n}\n\n\nclass AlquimiaSDK {\n private config: AlquimiaSDKConfig;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n private streamId: string | null = null;\n private evaluationStrategy: string | null = null;\n private tools: any = [];\n private extraData: any = null;\n private assistantConfig: any = null;\n private forceProfile: any = {};\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider\n private stableDiffusionProvider?: StableDiffusionProvider\n private analyzeCharacterizationProvider?: CharacterizationProvider\n private ratingsProvider?: RatingsProvider\n private loggerProvider?: LoggerProvider\n private enforceCharacterization?: boolean\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n \n constructor(config: AlquimiaSDKConfig, enforceCharacterization: boolean = true) {\n this.config = config;\n this.enforceCharacterization = enforceCharacterization;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status) {\n if (this.loggerProvider) {\n await this.loggerProvider.logError(\n 'Server Error',\n error,\n {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data\n }\n );\n }\n }\n return Promise.reject(error);\n }\n );\n \n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n static configure(\n apiKey: string,\n inferUrl: string,\n streamUrl: string,\n attachmentUrl: string,\n assistantId: string,\n ): AlquimiaSDKConfig {\n return {\n apiKey,\n chatUrl: `${inferUrl}/chat/${assistantId}`,\n streamUrl: `${streamUrl}`,\n attachmentUrl: attachmentUrl,\n assistantId: assistantId,\n };\n }\n\n widthConversationId(conversationId: string ): AlquimiaSDK {\n this.conversationId = conversationId\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider\n return this\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider\n return this\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider\n return this\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider\n return this\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n getEvaluationStrategy(): string | null {\n return this.evaluationStrategy;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraData(extraData: any): AlquimiaSDK {\n this.extraData = extraData;\n return this;\n }\n\n withForceProfile(forceProfile: any): AlquimiaSDK {\n this.forceProfile = forceProfile;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error(\"Whisper provider not initialized\");\n }\n return this.whisperProvider.textToSpeech(text)\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error(\"Whisper provider not initialized\");\n }\n return this.whisperProvider.speechToText(audio)\n }\n\n async sendMessage(query: string, traceParent?: string) {\n if (!this.conversationId) {\n throw new Error(\"Conversation not initialized\");\n }\n\n const initMessage = {\n query,\n session_id: this.conversationId,\n ...(this.extraData && { extra_data: this.extraData }),\n force_profile: this.forceProfile,\n ...(this.assistantConfig && { config: this.assistantConfig }),\n tools: this.tools,\n user_id: this.userId,\n attachments: this.attachments,\n };\n\n const result = (await this.axiosInstance.post(this.config.chatUrl, initMessage, {\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-trace-parent\": traceParent || \"\",\n },\n })).data\n\n this.evaluationStrategy = result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id || null;\n this.streamId = result.stream_id;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this\n }\n\n async generateImage(query: string) {\n if (!this.stableDiffusionProvider) {\n throw new Error(\"Stable Diffusion provider not initialized\");\n }\n return this.stableDiffusionProvider.generateImage(query)\n }\n\n async analyzeCharacterization(text: string) {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error(\"analyze characterization provider not initialized\");\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text)\n }\n\n async rate(data: any) {\n if (!this.ratingsProvider) {\n throw new Error(\"ratings provider not initialized\");\n }\n return this.ratingsProvider.rate(data)\n }\n\n async logInfo(message: string, data: any) {\n if (!this.loggerProvider) {\n throw new Error(\"logger provider not initialized\");\n }\n return this.loggerProvider.logInfo(message, data)\n }\n\n async logError(message: string, error: Error, data: any) {\n if (!this.loggerProvider) {\n throw new Error(\"logger provider not initialized\");\n }\n return this.loggerProvider.logError(message, error, data)\n }\n\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, attachmentId: string): Promise<void> {\n if (!this.config.attachmentUrl) {\n throw new Error(\"Attachment URL not configured\");\n }\n if (!this.streamId || !attachmentId) {\n throw new Error(\"Stream or attachment ID not initialized\");\n }\n const url = `${this.config.attachmentUrl}/${this.streamId}/${attachmentId}`;\n const formData = new FormData();\n formData.append(\"file\", file);\n await this.axiosInstance.post(url, formData, {\n headers: { \"Content-Type\": \"multipart/form-data\" },\n });\n }\n\n getUrlStream() {\n return `${this.config.streamUrl}/${this.streamId}`;\n }\n\n getStreamId() {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";AAAA,OAAO,WAA8B;AAkBrC,IAAM,cAAN,MAAkB;AAAA,EAqBhB,YAAY,QAA2B,0BAAmC,MAAM;AAlBhF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AACnC,SAAQ,WAA0B;AAClC,SAAQ,qBAAoC;AAC5C,SAAQ,QAAa,CAAC;AACtB,SAAQ,YAAiB;AACzB,SAAQ,kBAAuB;AAC/B,SAAQ,eAAoB,CAAC;AAC7B,SAAQ,SAAwB;AAOhC,SAAQ,cAAmC,CAAC;AAC5C,SAAQ,sBAAgC,CA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BAAiB,MAAY,cAAqC;AACtE,QAAI,CAAC,KAAK,OAAO,eAAe;AAC9B,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AACA,QAAI,CAAC,KAAK,YAAY,CAAC,cAAc;AACnC,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AACA,UAAM,MAAM,GAAG,KAAK,OAAO,aAAa,IAAI,KAAK,QAAQ,IAAI,YAAY;AACzE,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,QAAQ,IAAI;AAC5B,UAAM,KAAK,cAAc,KAAK,KAAK,UAAU;AAAA,MAC3C,SAAS,EAAE,gBAAgB,sBAAsB;AAAA,IACnD,CAAC;AAAA,EACH;AAAA,EAEA,eAAe;AACb,WAAO,GAAG,KAAK,OAAO,SAAS,IAAI,KAAK,QAAQ;AAAA,EAClD;AAAA,EAEA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/sdk/alquimia-sdk.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport {\n StableDiffusionProvider,\n WhisperProvider,\n CharacterizationProvider,\n RatingsProvider,\n LoggerProvider,\n} from '../providers';\nimport { AttachmentPayload, TTSResult } from '../types';\nimport type { AlquimiaAdapter, AlquimiaSDKOptions } from '../adapters';\n\nclass AlquimiaSDK {\n private adapter: AlquimiaAdapter;\n private assistantId: string;\n private axiosInstance: AxiosInstance;\n private conversationId: string | null = null;\n private sessionId: string | null = null;\n private streamId: string | null = null;\n private evaluationStrategy: string | null = null;\n private tools: any = [];\n private extraData: any = null;\n private assistantConfig: any = null;\n private forceProfile: any = {};\n private userId: string | null = null;\n private whisperProvider?: WhisperProvider;\n private stableDiffusionProvider?: StableDiffusionProvider;\n private analyzeCharacterizationProvider?: CharacterizationProvider;\n private ratingsProvider?: RatingsProvider;\n private loggerProvider?: LoggerProvider;\n private enforceCharacterization?: boolean;\n private attachments: AttachmentPayload[] = [];\n private attachmentResponses: string[] = [];\n\n constructor(\n assistantId: string,\n adapter: AlquimiaAdapter,\n options: AlquimiaSDKOptions = {}\n ) {\n if (!assistantId) {\n throw new Error('AlquimiaSDK: assistantId is required');\n }\n if (!adapter) {\n throw new Error(\n 'AlquimiaSDK: adapter is required. Use createNextJsAdapter() or createFetchAdapter()'\n );\n }\n\n this.assistantId = assistantId;\n this.adapter = adapter;\n this.enforceCharacterization = options.enforceCharacterization ?? true;\n\n this.axiosInstance = axios.create();\n this.axiosInstance.interceptors.response.use(\n (response) => response,\n async (error) => {\n if (error.response?.status && this.loggerProvider) {\n await this.loggerProvider.logError('Server Error', error, {\n url: error.config.url,\n method: error.config.method,\n data: error.config.data,\n status: error.response.status,\n responseData: error.response.data,\n });\n }\n return Promise.reject(error);\n }\n );\n\n this.textToSpeech = this.textToSpeech.bind(this);\n this.speechToText = this.speechToText.bind(this);\n }\n\n withConversationId(conversationId: string): AlquimiaSDK {\n this.conversationId = conversationId;\n return this;\n }\n\n withAttachments(attachments: AttachmentPayload[]): AlquimiaSDK {\n this.attachments = attachments;\n return this;\n }\n\n withWhisperProvider(provider: WhisperProvider): AlquimiaSDK {\n this.whisperProvider = provider;\n return this;\n }\n\n withStableDiffusionProvider(provider: StableDiffusionProvider): AlquimiaSDK {\n this.stableDiffusionProvider = provider;\n return this;\n }\n\n withAnalyzeCharacterizationProvider(provider: CharacterizationProvider): AlquimiaSDK {\n this.analyzeCharacterizationProvider = provider;\n return this;\n }\n\n withRatingsProvider(provider: RatingsProvider): AlquimiaSDK {\n this.ratingsProvider = provider;\n return this;\n }\n\n withLoggerProvider(provider: LoggerProvider): AlquimiaSDK {\n this.loggerProvider = provider;\n return this;\n }\n\n withTools(tools: any): AlquimiaSDK {\n this.tools = tools;\n return this;\n }\n\n withExtraData(extraData: any): AlquimiaSDK {\n this.extraData = extraData;\n return this;\n }\n\n withForceProfile(forceProfile: any): AlquimiaSDK {\n this.forceProfile = forceProfile;\n return this;\n }\n\n withAssistantConfig(assistantConfig: any): AlquimiaSDK {\n this.assistantConfig = assistantConfig;\n return this;\n }\n\n withUserId(userId: string): AlquimiaSDK {\n this.userId = userId;\n return this;\n }\n\n getEnforceCharacterization(): boolean {\n return this.enforceCharacterization ?? true;\n }\n\n getEvaluationStrategy(): string | null {\n return this.evaluationStrategy;\n }\n\n textToSpeech(text: string): Promise<TTSResult> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.textToSpeech(text);\n }\n\n speechToText(audio: string): Promise<string> {\n if (!this.whisperProvider) {\n throw new Error('Whisper provider not initialized');\n }\n return this.whisperProvider.speechToText(audio);\n }\n\n async sendMessage(query: string, traceParent?: string): Promise<AlquimiaSDK> {\n if (!this.conversationId) {\n throw new Error(\n 'Conversation not initialized. Call withConversationId() before sendMessage()'\n );\n }\n\n const inferUrl = this.adapter.resolveInferUrl(this.assistantId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n\n const initMessage = {\n query,\n session_id: this.conversationId,\n ...(this.extraData && { extra_data: this.extraData }),\n force_profile: this.forceProfile,\n ...(this.assistantConfig && { config: this.assistantConfig }),\n tools: this.tools,\n user_id: this.userId,\n attachments: this.attachments,\n };\n\n const result = (\n await this.axiosInstance.post(inferUrl, initMessage, {\n headers: {\n 'Content-Type': 'application/json',\n 'x-trace-parent': traceParent || '',\n ...adapterHeaders,\n },\n })\n ).data;\n\n this.evaluationStrategy =\n result?.config?.dante?.profile?.evaluation_strategy?.evaluation_strategy_id ?? null;\n this.streamId = result.stream_id;\n this.attachmentResponses = result.attachments ?? [];\n this.attachments = [];\n\n return this;\n }\n\n async generateImage(query: string): Promise<string> {\n if (!this.stableDiffusionProvider) {\n throw new Error('Stable Diffusion provider not initialized');\n }\n return this.stableDiffusionProvider.generateImage(query);\n }\n\n async analyzeCharacterization(text: string): Promise<Record<string, any>> {\n if (!this.analyzeCharacterizationProvider) {\n throw new Error('Analyze characterization provider not initialized');\n }\n return this.analyzeCharacterizationProvider.analyzeCharacterization(text);\n }\n\n async rate(data: any): Promise<Record<string, any>> {\n if (!this.ratingsProvider) {\n throw new Error('Ratings provider not initialized');\n }\n return this.ratingsProvider.rate(data);\n }\n\n async logInfo(message: string, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logInfo(message, data);\n }\n\n async logError(message: string, error: Error, data: any): Promise<void> {\n if (!this.loggerProvider) {\n throw new Error('Logger provider not initialized');\n }\n return this.loggerProvider.logError(message, error, data);\n }\n\n getAttachmentResponses(): string[] {\n return this.attachmentResponses;\n }\n\n async uploadAttachment(file: File, attachmentId: string): Promise<void> {\n if (!this.streamId || !attachmentId) {\n throw new Error('Stream or attachment ID not initialized');\n }\n const url = this.adapter.resolveAttachmentUrl(this.streamId, attachmentId);\n const adapterHeaders = this.adapter.getHeaders?.() ?? {};\n const formData = new FormData();\n formData.append('file', file);\n await this.axiosInstance.post(url, formData, {\n headers: { 'Content-Type': 'multipart/form-data', ...adapterHeaders },\n });\n }\n\n getUrlStream(): string {\n if (!this.streamId) {\n throw new Error('Stream ID not initialized. Call sendMessage() first');\n }\n return this.adapter.resolveStreamUrl(this.streamId);\n }\n\n getStreamId(): string | null {\n return this.streamId;\n }\n}\n\nexport default AlquimiaSDK;\n"],"mappings":";AAAA,OAAO,WAA8B;AAWrC,IAAM,cAAN,MAAkB;AAAA,EAsBhB,YACE,aACA,SACA,UAA8B,CAAC,GAC/B;AAtBF,SAAQ,iBAAgC;AACxC,SAAQ,YAA2B;AACnC,SAAQ,WAA0B;AAClC,SAAQ,qBAAoC;AAC5C,SAAQ,QAAa,CAAC;AACtB,SAAQ,YAAiB;AACzB,SAAQ,kBAAuB;AAC/B,SAAQ,eAAoB,CAAC;AAC7B,SAAQ,SAAwB;AAOhC,SAAQ,cAAmC,CAAC;AAC5C,SAAQ,sBAAgC,CAAC;AAOvC,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,sCAAsC;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,MAAY,cAAqC;AACtE,QAAI,CAAC,KAAK,YAAY,CAAC,cAAc;AACnC,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AACA,UAAM,MAAM,KAAK,QAAQ,qBAAqB,KAAK,UAAU,YAAY;AACzE,UAAM,iBAAiB,KAAK,QAAQ,aAAa,KAAK,CAAC;AACvD,UAAM,WAAW,IAAI,SAAS;AAC9B,aAAS,OAAO,QAAQ,IAAI;AAC5B,UAAM,KAAK,cAAc,KAAK,KAAK,UAAU;AAAA,MAC3C,SAAS,EAAE,gBAAgB,uBAAuB,GAAG,eAAe;AAAA,IACtE,CAAC;AAAA,EACH;AAAA,EAEA,eAAuB;AACrB,QAAI,CAAC,KAAK,UAAU;AAClB,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE;AACA,WAAO,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AAAA,EACpD;AAAA,EAEA,cAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":[]}
|
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import '../types/index.mjs';
|
|
1
|
+
import { Transaction } from '@elastic/apm-rum';
|
|
2
|
+
import { ApmSpan } from '../types/index.mjs';
|
|
4
3
|
import 'ai';
|
|
4
|
+
|
|
5
|
+
interface APMInitializerProps {
|
|
6
|
+
serviceName: string;
|
|
7
|
+
serverUrl?: string;
|
|
8
|
+
serverUrlPrefix?: string | undefined;
|
|
9
|
+
logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
10
|
+
environment: string;
|
|
11
|
+
ignoreUrls?: Array<string | RegExp>;
|
|
12
|
+
}
|
|
13
|
+
type LabelValue = string | number | boolean | null;
|
|
14
|
+
interface TransactionLabels {
|
|
15
|
+
[key: string]: LabelValue;
|
|
16
|
+
}
|
|
17
|
+
declare function APMInitializer({ serviceName, serverUrl, serverUrlPrefix, logLevel, environment, ignoreUrls }: APMInitializerProps): null;
|
|
18
|
+
declare function handleApmTransaction(name: string, type: string, labels: TransactionLabels, callback: () => Promise<void> | void): Promise<void>;
|
|
19
|
+
declare function traceError(error: string | Error, labels?: TransactionLabels, customMessage?: string): void;
|
|
20
|
+
declare const startManagedTransaction: (name: string, type: string | undefined, spanName: string, spanType?: string) => {
|
|
21
|
+
transaction: Transaction | undefined;
|
|
22
|
+
span: ApmSpan | undefined;
|
|
23
|
+
traceParentId: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { APMInitializer, handleApmTransaction, startManagedTransaction, traceError };
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import '../types/index.js';
|
|
1
|
+
import { Transaction } from '@elastic/apm-rum';
|
|
2
|
+
import { ApmSpan } from '../types/index.js';
|
|
4
3
|
import 'ai';
|
|
4
|
+
|
|
5
|
+
interface APMInitializerProps {
|
|
6
|
+
serviceName: string;
|
|
7
|
+
serverUrl?: string;
|
|
8
|
+
serverUrlPrefix?: string | undefined;
|
|
9
|
+
logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
10
|
+
environment: string;
|
|
11
|
+
ignoreUrls?: Array<string | RegExp>;
|
|
12
|
+
}
|
|
13
|
+
type LabelValue = string | number | boolean | null;
|
|
14
|
+
interface TransactionLabels {
|
|
15
|
+
[key: string]: LabelValue;
|
|
16
|
+
}
|
|
17
|
+
declare function APMInitializer({ serviceName, serverUrl, serverUrlPrefix, logLevel, environment, ignoreUrls }: APMInitializerProps): null;
|
|
18
|
+
declare function handleApmTransaction(name: string, type: string, labels: TransactionLabels, callback: () => Promise<void> | void): Promise<void>;
|
|
19
|
+
declare function traceError(error: string | Error, labels?: TransactionLabels, customMessage?: string): void;
|
|
20
|
+
declare const startManagedTransaction: (name: string, type: string | undefined, spanName: string, spanType?: string) => {
|
|
21
|
+
transaction: Transaction | undefined;
|
|
22
|
+
span: ApmSpan | undefined;
|
|
23
|
+
traceParentId: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { APMInitializer, handleApmTransaction, startManagedTransaction, traceError };
|
package/package.json
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alquimia-ai/tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"author": "Alquimia AI",
|
|
5
5
|
"description": "tools for Alquimia SDK",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"exports": {
|
|
9
|
+
"./adapters": {
|
|
10
|
+
"types": "./dist/adapters/index.d.ts",
|
|
11
|
+
"import": "./dist/adapters/index.mjs",
|
|
12
|
+
"require": "./dist/adapters/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./adapters/next": {
|
|
15
|
+
"types": "./dist/adapters/next.d.ts",
|
|
16
|
+
"import": "./dist/adapters/next.mjs",
|
|
17
|
+
"require": "./dist/adapters/next.js"
|
|
18
|
+
},
|
|
19
|
+
"./adapters/fetch": {
|
|
20
|
+
"types": "./dist/adapters/fetch.d.ts",
|
|
21
|
+
"import": "./dist/adapters/fetch.mjs",
|
|
22
|
+
"require": "./dist/adapters/fetch.js"
|
|
23
|
+
},
|
|
24
|
+
"./next": {
|
|
25
|
+
"types": "./dist/next/index.d.ts",
|
|
26
|
+
"import": "./dist/next/index.mjs",
|
|
27
|
+
"require": "./dist/next/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./proxy": {
|
|
30
|
+
"types": "./dist/proxy.d.ts",
|
|
31
|
+
"import": "./dist/proxy.mjs",
|
|
32
|
+
"require": "./dist/proxy.js"
|
|
33
|
+
},
|
|
9
34
|
"./sdk": {
|
|
10
35
|
"types": "./dist/sdk/index.d.ts",
|
|
11
36
|
"import": "./dist/sdk/index.mjs",
|
|
@@ -51,9 +76,9 @@
|
|
|
51
76
|
"scripts": {
|
|
52
77
|
"lint": "eslint . --max-warnings 0",
|
|
53
78
|
"generate:component": "turbo gen react-component",
|
|
54
|
-
"build": "tsup
|
|
79
|
+
"build": "tsup",
|
|
55
80
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
56
|
-
"dev": "tsup
|
|
81
|
+
"dev": "tsup --watch"
|
|
57
82
|
},
|
|
58
83
|
"files": [
|
|
59
84
|
"dist/**",
|
|
@@ -88,8 +113,13 @@
|
|
|
88
113
|
"react": "^18.2.0"
|
|
89
114
|
},
|
|
90
115
|
"peerDependencies": {
|
|
91
|
-
"next": "^14.2.15",
|
|
92
116
|
"react": ">=18.0.0",
|
|
93
|
-
"react-dom": ">=18.0.0"
|
|
117
|
+
"react-dom": ">=18.0.0",
|
|
118
|
+
"next": ">=14.0.0"
|
|
119
|
+
},
|
|
120
|
+
"peerDependenciesMeta": {
|
|
121
|
+
"next": {
|
|
122
|
+
"optional": true
|
|
123
|
+
}
|
|
94
124
|
}
|
|
95
125
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { L as LoggerProvider } from '../../providers-0Gi78uNQ.mjs';
|
|
2
|
-
import '../../types/index.mjs';
|
|
3
|
-
import '@elastic/apm-rum';
|
|
4
|
-
import 'ai';
|
|
5
|
-
|
|
6
|
-
interface ElasticLoggerConfig {
|
|
7
|
-
endpoint: string;
|
|
8
|
-
username: string;
|
|
9
|
-
password: string;
|
|
10
|
-
index?: string;
|
|
11
|
-
esVersion?: number;
|
|
12
|
-
flushBytes?: number;
|
|
13
|
-
}
|
|
14
|
-
declare class ElasticLoggerProvider extends LoggerProvider {
|
|
15
|
-
private logger;
|
|
16
|
-
private constructor();
|
|
17
|
-
static create(config: ElasticLoggerConfig): Promise<ElasticLoggerProvider>;
|
|
18
|
-
private initialize;
|
|
19
|
-
logInfo(message: string, data?: Record<string, any>): void;
|
|
20
|
-
logError(message: string, error: Error, data?: Record<string, any>): void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { ElasticLoggerProvider };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { L as LoggerProvider } from '../../providers-BJTXCtI3.js';
|
|
2
|
-
import '../../types/index.js';
|
|
3
|
-
import '@elastic/apm-rum';
|
|
4
|
-
import 'ai';
|
|
5
|
-
|
|
6
|
-
interface ElasticLoggerConfig {
|
|
7
|
-
endpoint: string;
|
|
8
|
-
username: string;
|
|
9
|
-
password: string;
|
|
10
|
-
index?: string;
|
|
11
|
-
esVersion?: number;
|
|
12
|
-
flushBytes?: number;
|
|
13
|
-
}
|
|
14
|
-
declare class ElasticLoggerProvider extends LoggerProvider {
|
|
15
|
-
private logger;
|
|
16
|
-
private constructor();
|
|
17
|
-
static create(config: ElasticLoggerConfig): Promise<ElasticLoggerProvider>;
|
|
18
|
-
private initialize;
|
|
19
|
-
logInfo(message: string, data?: Record<string, any>): void;
|
|
20
|
-
logError(message: string, error: Error, data?: Record<string, any>): void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { ElasticLoggerProvider };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/providers/elastic/index.ts
|
|
31
|
-
var elastic_exports = {};
|
|
32
|
-
__export(elastic_exports, {
|
|
33
|
-
ElasticLoggerProvider: () => ElasticLoggerProvider
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(elastic_exports);
|
|
36
|
-
|
|
37
|
-
// src/providers/providers.ts
|
|
38
|
-
var LoggerProvider = class {
|
|
39
|
-
constructor(config) {
|
|
40
|
-
this.config = config;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// src/providers/elastic/elastic-search.ts
|
|
45
|
-
var import_pino = __toESM(require("pino"));
|
|
46
|
-
var ElasticLoggerProvider = class _ElasticLoggerProvider extends LoggerProvider {
|
|
47
|
-
constructor(config) {
|
|
48
|
-
super(config);
|
|
49
|
-
this.logger = console;
|
|
50
|
-
}
|
|
51
|
-
static async create(config) {
|
|
52
|
-
const provider = new _ElasticLoggerProvider(config);
|
|
53
|
-
await provider.initialize(config);
|
|
54
|
-
return provider;
|
|
55
|
-
}
|
|
56
|
-
async initialize(config) {
|
|
57
|
-
if (typeof window === "undefined") {
|
|
58
|
-
const [pinoElastic] = await Promise.all([
|
|
59
|
-
import("pino-elasticsearch")
|
|
60
|
-
]);
|
|
61
|
-
const streamToElastic = pinoElastic.default({
|
|
62
|
-
index: config.index || "logs-index",
|
|
63
|
-
node: config.endpoint,
|
|
64
|
-
esVersion: config.esVersion || 7,
|
|
65
|
-
flushBytes: config.flushBytes || 1e3,
|
|
66
|
-
auth: {
|
|
67
|
-
username: config.username || "",
|
|
68
|
-
password: config.password || ""
|
|
69
|
-
},
|
|
70
|
-
tls: {
|
|
71
|
-
rejectUnauthorized: false
|
|
72
|
-
},
|
|
73
|
-
op_type: "create"
|
|
74
|
-
});
|
|
75
|
-
streamToElastic.on("error", (err) => {
|
|
76
|
-
console.error("Elasticsearch stream error:", err);
|
|
77
|
-
});
|
|
78
|
-
streamToElastic.on("insertError", (err) => {
|
|
79
|
-
console.error("Elasticsearch insert error:", err);
|
|
80
|
-
});
|
|
81
|
-
streamToElastic.on("insert", () => {
|
|
82
|
-
console.log("Successfully sent log to Elasticsearch");
|
|
83
|
-
});
|
|
84
|
-
this.logger = (0, import_pino.default)({
|
|
85
|
-
level: "info",
|
|
86
|
-
timestamp: () => `,"time":"${(/* @__PURE__ */ new Date()).toISOString()}"`
|
|
87
|
-
}, streamToElastic);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
logInfo(message, data) {
|
|
91
|
-
this.logger.info({ ...data }, message);
|
|
92
|
-
}
|
|
93
|
-
logError(message, error, data) {
|
|
94
|
-
const errorDetails = {
|
|
95
|
-
message: error.message,
|
|
96
|
-
name: error.name,
|
|
97
|
-
stack: error.stack
|
|
98
|
-
};
|
|
99
|
-
this.logger.error({ error, ...data, ...errorDetails }, message);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/providers/elastic/index.ts","../../../src/providers/providers.ts","../../../src/providers/elastic/elastic-search.ts"],"sourcesContent":["export * from \"./elastic-search\";","import { TTSResult } from \"../types\";\n\nexport abstract class GenerativeProvider {\n private config: Record<string, any>;\n\n constructor(config: Record<string, any>) {\n this.config = config;\n }\n}\n\nexport abstract class WhisperProvider {\n protected config: Record<string, any>;\n\n constructor(config: Record<string, any>) {\n this.config = config;\n }\n\n abstract textToSpeech(text: string): Promise<TTSResult>\n\n abstract speechToText(audio: string): Promise<string>\n} \n\nexport abstract class StableDiffusionProvider {\n protected config: Record<string, any>;\n\n constructor(config: Record<string, any>) {\n this.config = config;\n }\n\n abstract generateImage(query: string): Promise<string>\n}\n\nexport abstract class CharacterizationProvider {\n protected config: Record<string, any>;\n\n constructor(config: Record<string, any>) {\n this.config = config;\n }\n\n abstract analyzeCharacterization(text: string): Promise<Record<string, any>>\n}\n\nexport abstract class RatingsProvider {\n protected config: Record<string, any>;\n\n constructor(config: Record<string, any>) {\n this.config = config;\n }\n\n abstract rate(data: Record<string, any>): Promise<Record<string, any>>;\n}\n\nexport abstract class LoggerProvider {\n protected config: Record<string, any>;\n\n constructor(config: Record<string, any>) {\n this.config = config;\n }\n\n abstract logInfo(message: string, data?: Record<string, any>): void;\n abstract logError(message: string, error: Error, data?: Record<string, any>): void;\n}\n","import { LoggerProvider } from \"../providers\";\nimport pino from \"pino\";\n\ninterface ElasticLoggerConfig {\n endpoint: string;\n username: string;\n password: string;\n index?: string;\n esVersion?: number;\n flushBytes?: number;\n}\n\nclass ElasticLoggerProvider extends LoggerProvider {\n private logger: pino.Logger;\n\n private constructor(config: ElasticLoggerConfig) {\n super(config);\n this.logger = console as any;\n }\n\n public static async create(config: ElasticLoggerConfig): Promise<ElasticLoggerProvider> {\n const provider = new ElasticLoggerProvider(config);\n await provider.initialize(config);\n return provider;\n }\n\n private async initialize(config: ElasticLoggerConfig) {\n if (typeof window === 'undefined') {\n const [pinoElastic] = await Promise.all([\n import('pino-elasticsearch')\n ]);\n\n const streamToElastic = pinoElastic.default({\n index: config.index || \"logs-index\",\n node: config.endpoint,\n esVersion: config.esVersion || 7,\n flushBytes: config.flushBytes || 1000,\n auth: {\n username: config.username || \"\",\n password: config.password || \"\",\n },\n tls: {\n rejectUnauthorized: false,\n },\n op_type: 'create',\n });\n\n streamToElastic.on('error', (err) => {\n console.error('Elasticsearch stream error:', err);\n });\n\n streamToElastic.on('insertError', (err) => {\n console.error('Elasticsearch insert error:', err);\n });\n\n streamToElastic.on('insert', () => {\n console.log('Successfully sent log to Elasticsearch');\n });\n\n\n this.logger = pino({\n level: 'info',\n timestamp: () => `,\"time\":\"${new Date().toISOString()}\"`,\n }, streamToElastic);\n }\n }\n\n logInfo(message: string, data?: Record<string, any>): void {\n this.logger.info({ ...data }, message);\n }\n\n logError(message: string, error: Error, data?: Record<string, any>): void {\n const errorDetails = {\n message: error.message,\n name: error.name,\n stack: error.stack,\n };\n this.logger.error({ error, ...data, ...errorDetails }, message);\n }\n}\n\nexport { ElasticLoggerProvider };"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoDO,IAAe,iBAAf,MAA8B;AAAA,EAGjC,YAAY,QAA6B;AACrC,SAAK,SAAS;AAAA,EAClB;AAIJ;;;AC5DA,kBAAiB;AAWjB,IAAM,wBAAN,MAAM,+BAA8B,eAAe;AAAA,EAGzC,YAAY,QAA6B;AAC/C,UAAM,MAAM;AACZ,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,aAAoB,OAAO,QAA6D;AACtF,UAAM,WAAW,IAAI,uBAAsB,MAAM;AACjD,UAAM,SAAS,WAAW,MAAM;AAChC,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,WAAW,QAA6B;AACpD,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,CAAC,WAAW,IAAI,MAAM,QAAQ,IAAI;AAAA,QACtC,OAAO,oBAAoB;AAAA,MAC7B,CAAC;AAED,YAAM,kBAAkB,YAAY,QAAQ;AAAA,QAC1C,OAAO,OAAO,SAAS;AAAA,QACvB,MAAM,OAAO;AAAA,QACb,WAAW,OAAO,aAAa;AAAA,QAC/B,YAAY,OAAO,cAAc;AAAA,QAC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