@mirodan/ai-insight 0.1.5 → 0.1.6

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/module.js CHANGED
@@ -1,26 +1,26 @@
1
- import { addComponent as e, addPlugin as t, addServerHandler as n, createResolver as r, defineNuxtModule as i } from "@nuxt/kit";
1
+ import { addComponent as e, addServerHandler as t, createResolver as n, defineNuxtModule as r } from "@nuxt/kit";
2
2
  //#region src/module.ts
3
- var a = i({
3
+ var i = r({
4
4
  meta: { name: "@mirodan/ai-insight" },
5
5
  defaults: { endpoint: "https://api.mirodan.ai/v1/insight" },
6
- setup(i, a) {
7
- let o = r(import.meta.url);
8
- a.options.runtimeConfig.aiInsight = {
6
+ setup(r, i) {
7
+ let a = n(import.meta.url);
8
+ i.options.runtimeConfig.aiInsight = {
9
9
  key: "",
10
- endpoint: i.endpoint
10
+ endpoint: r.endpoint
11
11
  }, e({
12
12
  name: "AiInsight",
13
- filePath: o.resolve("./runtime/components/AiInsight.vue")
13
+ filePath: a.resolve("./runtime/components/AiInsight.vue")
14
14
  }), e({
15
15
  name: "AiInsightDialog",
16
- filePath: o.resolve("./runtime/components/AiInsightDialog.vue")
17
- }), n({
16
+ filePath: a.resolve("./runtime/components/AiInsightDialog.vue")
17
+ }), t({
18
18
  route: "/api/ai-insight/proxy",
19
- handler: o.resolve("./runtime/server/proxy.post.ts")
20
- }), t(o.resolve("./runtime/plugins/i18n.ts"));
19
+ handler: a.resolve("./runtime/server/proxy.post.ts")
20
+ });
21
21
  }
22
22
  });
23
23
  //#endregion
24
- export { a as default };
24
+ export { i as default };
25
25
 
26
26
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","names":[],"sources":["../src/module.ts"],"sourcesContent":["import { defineNuxtModule, createResolver, addComponent, addServerHandler, addPlugin } from '@nuxt/kit'\n\nexport default defineNuxtModule({\n meta: { name: '@mirodan/ai-insight' },\n defaults: { endpoint: 'https://api.mirodan.ai/v1/insight' },\n setup(options, nuxt) {\n const resolver = createResolver(import.meta.url)\n\n nuxt.options.runtimeConfig.aiInsight = {\n key: '',\n endpoint: options.endpoint\n }\n\n addComponent({\n name: 'AiInsight',\n filePath: resolver.resolve('./runtime/components/AiInsight.vue')\n })\n\n addComponent({\n name: 'AiInsightDialog',\n filePath: resolver.resolve('./runtime/components/AiInsightDialog.vue')\n })\n\n addServerHandler({\n route: '/api/ai-insight/proxy',\n handler: resolver.resolve('./runtime/server/proxy.post.ts')\n })\n\n addPlugin(resolver.resolve('./runtime/plugins/i18n.ts'))\n }\n})\n"],"mappings":";;AAEA,IAAA,IAAe,EAAiB;CAC9B,MAAM,EAAE,MAAM,sBAAsB;CACpC,UAAU,EAAE,UAAU,oCAAoC;CAC1D,MAAM,GAAS,GAAM;EACnB,IAAM,IAAW,EAAe,YAAY,GAAG;EAsB/C,AApBA,EAAK,QAAQ,cAAc,YAAY;GACrC,KAAK;GACL,UAAU,EAAQ;EACpB,GAEA,EAAa;GACX,MAAM;GACN,UAAU,EAAS,QAAQ,oCAAoC;EACjE,CAAC,GAED,EAAa;GACX,MAAM;GACN,UAAU,EAAS,QAAQ,0CAA0C;EACvE,CAAC,GAED,EAAiB;GACf,OAAO;GACP,SAAS,EAAS,QAAQ,gCAAgC;EAC5D,CAAC,GAED,EAAU,EAAS,QAAQ,2BAA2B,CAAC;CACzD;AACF,CAAC"}
1
+ {"version":3,"file":"module.js","names":[],"sources":["../src/module.ts"],"sourcesContent":["import { defineNuxtModule, createResolver, addComponent, addServerHandler } from '@nuxt/kit'\n\nexport default defineNuxtModule({\n meta: { name: '@mirodan/ai-insight' },\n defaults: { endpoint: 'https://api.mirodan.ai/v1/insight' },\n setup(options, nuxt) {\n const resolver = createResolver(import.meta.url)\n\n nuxt.options.runtimeConfig.aiInsight = {\n key: '',\n endpoint: options.endpoint\n }\n\n addComponent({\n name: 'AiInsight',\n filePath: resolver.resolve('./runtime/components/AiInsight.vue')\n })\n\n addComponent({\n name: 'AiInsightDialog',\n filePath: resolver.resolve('./runtime/components/AiInsightDialog.vue')\n })\n\n addServerHandler({\n route: '/api/ai-insight/proxy',\n handler: resolver.resolve('./runtime/server/proxy.post.ts')\n })\n }\n})\n"],"mappings":";;AAEA,IAAA,IAAe,EAAiB;CAC9B,MAAM,EAAE,MAAM,sBAAsB;CACpC,UAAU,EAAE,UAAU,oCAAoC;CAC1D,MAAM,GAAS,GAAM;EACnB,IAAM,IAAW,EAAe,YAAY,GAAG;EAiB/C,AAfA,EAAK,QAAQ,cAAc,YAAY;GACrC,KAAK;GACL,UAAU,EAAQ;EACpB,GAEA,EAAa;GACX,MAAM;GACN,UAAU,EAAS,QAAQ,oCAAoC;EACjE,CAAC,GAED,EAAa;GACX,MAAM;GACN,UAAU,EAAS,QAAQ,0CAA0C;EACvE,CAAC,GAED,EAAiB;GACf,OAAO;GACP,SAAS,EAAS,QAAQ,gCAAgC;EAC5D,CAAC;CACH;AACF,CAAC"}
@@ -1,5 +1,9 @@
1
1
  <script setup lang="ts">
2
2
  import { ref } from 'vue'
3
+ import { useI18n } from 'vue-i18n'
4
+ import { messages } from '../i18n/messages'
5
+
6
+ const { t } = useI18n({ messages, useScope: 'local' })
3
7
 
4
8
  interface Props {
5
9
  data: unknown
@@ -20,7 +24,7 @@ const dialogOpen = ref(false)
20
24
  :class="position === 'top' ? 'bottom-full left-1/2 -translate-x-1/2 mb-2' : 'top-full left-1/2 -translate-x-1/2 mt-2'"
21
25
  @click="dialogOpen = true"
22
26
  >
23
- <span>AI анализ</span>
27
+ <span>{{ t('aiInsight.title') }}</span>
24
28
  <UIcon
25
29
  name="i-lucide-brain"
26
30
  class="size-3.5"
@@ -3,8 +3,9 @@ import { ref, watch, onMounted, nextTick } from 'vue'
3
3
  import { useDraggable } from '@vueuse/core'
4
4
  import { useI18n } from 'vue-i18n'
5
5
  import { parseUIMessageStream } from '../utils/parseUIMessageStream'
6
+ import { messages } from '../i18n/messages'
6
7
 
7
- const { t, locale: i18nLocale } = useI18n()
8
+ const { t, locale: i18nLocale } = useI18n({ messages, useScope: 'local' })
8
9
 
9
10
  interface Props {
10
11
  open: boolean
@@ -82,7 +83,7 @@ async function loadInsight() {
82
83
  let msg = t('aiInsight.requestError', { status: response.status })
83
84
  try {
84
85
  const json = await response.json()
85
- msg = json.statusMessage || json.message || msg
86
+ msg = json.message || json.statusMessage || msg
86
87
  } catch {
87
88
  const text = await response.text().catch(() => '')
88
89
  if (text) msg = text
@@ -1,4 +1,24 @@
1
- import { tError } from './_errors.js'
1
+ import { defineEventHandler, createError, getHeader, setHeaders, readBody } from 'h3'
2
+ import { useRuntimeConfig } from '#imports'
3
+
4
+ const tErrorMessages: Record<string, Record<string, string>> = {
5
+ ru: {
6
+ CONFIG_ENDPOINT_MISSING: 'Не указан endpoint AI Insight',
7
+ CONFIG_KEY_MISSING: 'Не указан API-ключ AI Insight',
8
+ BACKEND_UNREACHABLE: 'Не удалось подключиться к AI Insight',
9
+ BACKEND_ERROR: 'Ошибка AI Insight'
10
+ },
11
+ en: {
12
+ CONFIG_ENDPOINT_MISSING: 'AI Insight endpoint is not configured',
13
+ CONFIG_KEY_MISSING: 'AI Insight API key is not configured',
14
+ BACKEND_UNREACHABLE: 'Failed to reach AI Insight backend',
15
+ BACKEND_ERROR: 'AI Insight error'
16
+ }
17
+ }
18
+
19
+ function tError(key: string, lang: string): string {
20
+ return tErrorMessages[lang === 'en' ? 'en' : 'ru']?.[key] || key
21
+ }
2
22
 
3
23
  export default defineEventHandler(async (event) => {
4
24
  const config = useRuntimeConfig(event)
@@ -9,10 +29,10 @@ export default defineEventHandler(async (event) => {
9
29
  const lang = getHeader(event, 'accept-language')?.slice(0, 2) || 'ru'
10
30
 
11
31
  if (!endpoint) {
12
- throw createError({ statusCode: 500, statusMessage: tError('CONFIG_ENDPOINT_MISSING', lang) })
32
+ throw createError({ statusCode: 500, message: tError('CONFIG_ENDPOINT_MISSING', lang) })
13
33
  }
14
34
  if (!hasKey) {
15
- throw createError({ statusCode: 500, statusMessage: tError('CONFIG_KEY_MISSING', lang) })
35
+ throw createError({ statusCode: 500, message: tError('CONFIG_KEY_MISSING', lang) })
16
36
  }
17
37
 
18
38
  console.log('[ai-insight/proxy] →', endpoint, 'key:', hasKey ? 'yes' : 'NO KEY', 'data:', typeof body?.data, 'prompt:', body?.prompt?.slice(0, 80))
@@ -34,7 +54,7 @@ export default defineEventHandler(async (event) => {
34
54
  })
35
55
  } catch (fetchErr) {
36
56
  console.error('[ai-insight/proxy] fetch error:', fetchErr)
37
- throw createError({ statusCode: 502, statusMessage: tError('BACKEND_UNREACHABLE', lang) })
57
+ throw createError({ statusCode: 502, message: tError('BACKEND_UNREACHABLE', lang) })
38
58
  }
39
59
 
40
60
  console.log('[ai-insight/proxy] ←', response.status, response.statusText)
@@ -48,7 +68,7 @@ export default defineEventHandler(async (event) => {
48
68
  } catch {
49
69
  detail = text || response.statusText
50
70
  }
51
- throw createError({ statusCode: response.status, statusMessage: detail || tError('BACKEND_ERROR', lang) })
71
+ throw createError({ statusCode: response.status, message: detail || tError('BACKEND_ERROR', lang) })
52
72
  }
53
73
 
54
74
  setHeaders(event, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirodan/ai-insight",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "AI-powered insight tooltip component for Mirodan",
5
5
  "type": "module",
6
6
  "main": "./dist/module.js",
@@ -1,12 +0,0 @@
1
- import { defineNuxtPlugin } from '#imports'
2
- import { messages } from '../i18n/messages'
3
-
4
- export default defineNuxtPlugin((nuxtApp) => {
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- const i18n: any = nuxtApp.vueApp.config.globalProperties.$i18n
7
- if (i18n?.mergeLocaleMessage) {
8
- for (const [locale, msg] of Object.entries(messages)) {
9
- i18n.mergeLocaleMessage(locale, msg)
10
- }
11
- }
12
- })
@@ -1,18 +0,0 @@
1
- const messages = {
2
- ru: {
3
- CONFIG_ENDPOINT_MISSING: 'Не указан endpoint AI Insight',
4
- CONFIG_KEY_MISSING: 'Не указан API-ключ AI Insight',
5
- BACKEND_UNREACHABLE: 'Не удалось подключиться к AI Insight',
6
- BACKEND_ERROR: 'Ошибка AI Insight'
7
- },
8
- en: {
9
- CONFIG_ENDPOINT_MISSING: 'AI Insight endpoint is not configured',
10
- CONFIG_KEY_MISSING: 'AI Insight API key is not configured',
11
- BACKEND_UNREACHABLE: 'Failed to reach AI Insight backend',
12
- BACKEND_ERROR: 'AI Insight error'
13
- }
14
- }
15
-
16
- export function tError(key, lang) {
17
- return messages[lang === 'en' ? 'en' : 'ru']?.[key] || key
18
- }