@meistrari/chat-nuxt 1.2.3 → 1.3.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 (80) hide show
  1. package/README.md +70 -38
  2. package/dist/module.d.mts +24 -1
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +38 -29
  5. package/dist/runtime/components/MeistrariChatEmbed.d.vue.ts +3 -1
  6. package/dist/runtime/components/MeistrariChatEmbed.vue +5 -3
  7. package/dist/runtime/components/MeistrariChatEmbed.vue.d.ts +3 -1
  8. package/dist/runtime/components/chat/thinking-indicator.vue +28 -17
  9. package/dist/runtime/composables/useEmbedConfig.d.ts +5 -0
  10. package/dist/runtime/composables/useEmbedConfig.js +11 -3
  11. package/dist/runtime/embed/components/ChatConfigurationModal.vue +8 -6
  12. package/dist/runtime/embed/components/ChatEmbed.d.vue.ts +3 -1
  13. package/dist/runtime/embed/components/ChatEmbed.vue +13 -12
  14. package/dist/runtime/embed/components/ChatEmbed.vue.d.ts +3 -1
  15. package/dist/runtime/embed/components/ChatEmbedInner.vue +5 -1
  16. package/dist/runtime/server/api/conversations/[id]/messages/[messageId]/retry.post.js +7 -4
  17. package/dist/runtime/server/api/conversations/[id]/messages/index.post.js +7 -4
  18. package/dist/runtime/server/api/conversations/[id]/usage.get.js +1 -1
  19. package/dist/runtime/server/api/conversations/generate-title.post.js +18 -5
  20. package/dist/runtime/server/api/workspace/usage.get.js +1 -1
  21. package/dist/runtime/server/db/index.d.ts +20 -3
  22. package/dist/runtime/server/db/index.js +87 -10
  23. package/dist/runtime/server/db/schema/_schema.d.ts +2 -0
  24. package/dist/runtime/server/db/schema/_schema.js +3 -0
  25. package/dist/runtime/server/db/schema/conversation-usage.d.ts +1 -1
  26. package/dist/runtime/server/db/schema/conversation-usage.js +3 -2
  27. package/dist/runtime/server/db/schema/conversations.d.ts +1 -1
  28. package/dist/runtime/server/db/schema/conversations.js +3 -2
  29. package/dist/runtime/server/db/schema/external-skills.d.ts +1 -1
  30. package/dist/runtime/server/db/schema/external-skills.js +3 -2
  31. package/dist/runtime/server/db/schema/index.d.ts +1 -0
  32. package/dist/runtime/server/db/schema/index.js +1 -0
  33. package/dist/runtime/server/db/schema/messages.d.ts +1 -1
  34. package/dist/runtime/server/db/schema/messages.js +3 -2
  35. package/dist/runtime/server/db/schema/workspace-settings.d.ts +1 -1
  36. package/dist/runtime/server/db/schema/workspace-settings.js +3 -2
  37. package/dist/runtime/server/plugins/init-db.d.ts +2 -0
  38. package/dist/runtime/server/plugins/init-db.js +11 -0
  39. package/dist/runtime/server/utils/billing.d.ts +26 -4
  40. package/dist/runtime/server/utils/billing.js +52 -13
  41. package/dist/runtime/server/utils/chat-workspace-settings.js +1 -1
  42. package/dist/runtime/utils/chat-loading-messages.d.ts +12 -0
  43. package/dist/runtime/utils/chat-loading-messages.js +40 -0
  44. package/dist/runtime/utils/features.d.ts +6 -0
  45. package/dist/runtime/utils/features.js +15 -0
  46. package/dist/types.d.mts +1 -1
  47. package/drizzle/0000_material_hiroim.sql +28 -0
  48. package/drizzle/0001_famous_scalphunter.sql +1 -0
  49. package/drizzle/0002_gorgeous_big_bertha.sql +1 -0
  50. package/drizzle/0003_massive_forge.sql +2 -0
  51. package/drizzle/0004_absent_black_tom.sql +2 -0
  52. package/drizzle/0005_first_kid_colt.sql +1 -0
  53. package/drizzle/0006_sloppy_mauler.sql +13 -0
  54. package/drizzle/0007_grey_rhino.sql +1 -0
  55. package/drizzle/0008_chilly_blue_blade.sql +27 -0
  56. package/drizzle/0009_cultured_maddog.sql +16 -0
  57. package/drizzle/0010_small_barracuda.sql +1 -0
  58. package/drizzle/0011_fat_lady_mastermind.sql +6 -0
  59. package/drizzle/0012_puzzling_rick_jones.sql +1 -0
  60. package/drizzle/0013_blue_gwen_stacy.sql +11 -0
  61. package/drizzle/meta/0000_snapshot.json +239 -0
  62. package/drizzle/meta/0001_snapshot.json +245 -0
  63. package/drizzle/meta/0002_snapshot.json +251 -0
  64. package/drizzle/meta/0003_snapshot.json +263 -0
  65. package/drizzle/meta/0004_snapshot.json +275 -0
  66. package/drizzle/meta/0005_snapshot.json +281 -0
  67. package/drizzle/meta/0006_snapshot.json +320 -0
  68. package/drizzle/meta/0007_snapshot.json +326 -0
  69. package/drizzle/meta/0008_snapshot.json +539 -0
  70. package/drizzle/meta/0009_snapshot.json +646 -0
  71. package/drizzle/meta/0010_snapshot.json +653 -0
  72. package/drizzle/meta/0011_snapshot.json +689 -0
  73. package/drizzle/meta/0012_snapshot.json +695 -0
  74. package/drizzle/meta/0013_snapshot.json +699 -0
  75. package/drizzle/meta/_journal.json +104 -0
  76. package/package.json +5 -3
  77. package/dist/runtime/server/tasks/send-daily-usage-report.d.ts +0 -2
  78. package/dist/runtime/server/tasks/send-daily-usage-report.js +0 -74
  79. package/dist/runtime/server/utils/auth-api.d.ts +0 -1
  80. package/dist/runtime/server/utils/auth-api.js +0 -27
@@ -0,0 +1,104 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "postgresql",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1765492759988,
9
+ "tag": "0000_material_hiroim",
10
+ "breakpoints": true
11
+ },
12
+ {
13
+ "idx": 1,
14
+ "version": "7",
15
+ "when": 1765825389642,
16
+ "tag": "0001_famous_scalphunter",
17
+ "breakpoints": true
18
+ },
19
+ {
20
+ "idx": 2,
21
+ "version": "7",
22
+ "when": 1765834823758,
23
+ "tag": "0002_gorgeous_big_bertha",
24
+ "breakpoints": true
25
+ },
26
+ {
27
+ "idx": 3,
28
+ "version": "7",
29
+ "when": 1765893180360,
30
+ "tag": "0003_massive_forge",
31
+ "breakpoints": true
32
+ },
33
+ {
34
+ "idx": 4,
35
+ "version": "7",
36
+ "when": 1768788722671,
37
+ "tag": "0004_absent_black_tom",
38
+ "breakpoints": true
39
+ },
40
+ {
41
+ "idx": 5,
42
+ "version": "7",
43
+ "when": 1768872040029,
44
+ "tag": "0005_first_kid_colt",
45
+ "breakpoints": true
46
+ },
47
+ {
48
+ "idx": 6,
49
+ "version": "7",
50
+ "when": 1769631447508,
51
+ "tag": "0006_sloppy_mauler",
52
+ "breakpoints": true
53
+ },
54
+ {
55
+ "idx": 7,
56
+ "version": "7",
57
+ "when": 1769698874653,
58
+ "tag": "0007_grey_rhino",
59
+ "breakpoints": true
60
+ },
61
+ {
62
+ "idx": 8,
63
+ "version": "7",
64
+ "when": 1770161996712,
65
+ "tag": "0008_chilly_blue_blade",
66
+ "breakpoints": true
67
+ },
68
+ {
69
+ "idx": 9,
70
+ "version": "7",
71
+ "when": 1772564921279,
72
+ "tag": "0009_cultured_maddog",
73
+ "breakpoints": true
74
+ },
75
+ {
76
+ "idx": 10,
77
+ "version": "7",
78
+ "when": 1773150630796,
79
+ "tag": "0010_small_barracuda",
80
+ "breakpoints": true
81
+ },
82
+ {
83
+ "idx": 11,
84
+ "version": "7",
85
+ "when": 1773254272382,
86
+ "tag": "0011_fat_lady_mastermind",
87
+ "breakpoints": true
88
+ },
89
+ {
90
+ "idx": 12,
91
+ "version": "7",
92
+ "when": 1775667164749,
93
+ "tag": "0012_puzzling_rick_jones",
94
+ "breakpoints": true
95
+ },
96
+ {
97
+ "idx": 13,
98
+ "version": "7",
99
+ "when": 1777485763311,
100
+ "tag": "0013_blue_gwen_stacy",
101
+ "breakpoints": true
102
+ }
103
+ ]
104
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/chat-nuxt",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -20,7 +20,8 @@
20
20
  "main": "./dist/module.mjs",
21
21
  "types": "./dist/types.d.mts",
22
22
  "files": [
23
- "dist"
23
+ "dist",
24
+ "drizzle"
24
25
  ],
25
26
  "scripts": {
26
27
  "build": "mkdir -p .nuxt && { [ -f .nuxt/tsconfig.json ] || printf '{}' > .nuxt/tsconfig.json; } && { [ -f .nuxt/tsconfig.server.json ] || printf '{}' > .nuxt/tsconfig.server.json; } && nuxt-module-build build",
@@ -40,9 +41,10 @@
40
41
  "vue": "^3.5.0"
41
42
  },
42
43
  "dependencies": {
44
+ "@electric-sql/pglite": "^0.2.15",
43
45
  "@iconify-json/ph": "^1.2.2",
44
46
  "@iconify/vue": "^5.0.0",
45
- "@meistrari/auth-nuxt": "^3.5.0",
47
+ "@meistrari/auth-nuxt": "3.5.0",
46
48
  "@meistrari/logger": "^2.1.3",
47
49
  "@meistrari/mise-en-place": "^2.5.1",
48
50
  "@meistrari/tela-sdk-js": "^2.8.0",
@@ -1,2 +0,0 @@
1
- declare const _default: import("nitropack").Task<string>;
2
- export default _default;
@@ -1,74 +0,0 @@
1
- import { defineTask, useRuntimeConfig } from "nitropack/runtime";
2
- import { and, gte, lte, sql } from "drizzle-orm";
3
- import { useDb, schema } from "../db/index.js";
4
- import { sendSlackMessage, formatUsageReport } from "../utils/slack.js";
5
- import { getWorkspaceInfo, transformCostForBilling } from "../utils/billing.js";
6
- export default defineTask({
7
- meta: {
8
- name: "send-daily-usage-report",
9
- description: "Sends daily usage report to Slack"
10
- },
11
- async run() {
12
- const config = useRuntimeConfig();
13
- const slackWebhookUrl = config.slackWebhookUrl;
14
- if (!slackWebhookUrl) {
15
- return { result: "No webhook configured" };
16
- }
17
- const db = useDb();
18
- const now = /* @__PURE__ */ new Date();
19
- const startOfToday = new Date(now);
20
- startOfToday.setUTCHours(3, 0, 0, 0);
21
- const endOfReport = new Date(now);
22
- endOfReport.setUTCHours(23, 0, 0, 0);
23
- const rawWorkspaceUsage = await db.select({
24
- workspaceId: schema.conversationUsage.workspaceId,
25
- totalTokens: sql`SUM(${schema.conversationUsage.totalTokens})::int`,
26
- totalCost: sql`SUM(${schema.conversationUsage.totalCost}::numeric)::float`,
27
- promptTokens: sql`SUM(${schema.conversationUsage.promptTokens})::int`,
28
- completionTokens: sql`SUM(${schema.conversationUsage.completionTokens})::int`,
29
- promptCost: sql`SUM(${schema.conversationUsage.promptCost}::numeric)::float`,
30
- completionCost: sql`SUM(${schema.conversationUsage.completionCost}::numeric)::float`,
31
- conversationCount: sql`COUNT(DISTINCT ${schema.conversationUsage.conversationId})::int`,
32
- userCount: sql`COUNT(DISTINCT ${schema.conversationUsage.userId})::int`
33
- }).from(schema.conversationUsage).where(
34
- and(
35
- gte(schema.conversationUsage.createdAt, startOfToday),
36
- lte(schema.conversationUsage.createdAt, endOfReport)
37
- )
38
- ).groupBy(schema.conversationUsage.workspaceId).orderBy(sql`SUM(${schema.conversationUsage.totalCost}::numeric) DESC`);
39
- if (rawWorkspaceUsage.length === 0) {
40
- return { result: "No usage data" };
41
- }
42
- const workspaceUsage = await Promise.all(
43
- rawWorkspaceUsage.map(async (usage) => {
44
- const { billing, name } = await getWorkspaceInfo(usage.workspaceId);
45
- const transformedCosts = transformCostForBilling({
46
- promptCost: usage.promptCost,
47
- completionCost: usage.completionCost,
48
- totalCost: usage.totalCost,
49
- promptTokens: usage.promptTokens,
50
- completionTokens: usage.completionTokens
51
- }, billing);
52
- return {
53
- workspaceId: usage.workspaceId,
54
- workspaceName: name,
55
- totalTokens: usage.totalTokens,
56
- totalCost: transformedCosts.totalCost,
57
- rawCost: usage.totalCost,
58
- promptTokens: usage.promptTokens,
59
- completionTokens: usage.completionTokens,
60
- conversationCount: usage.conversationCount,
61
- userCount: usage.userCount,
62
- billingMode: billing.mode
63
- };
64
- })
65
- );
66
- const message = formatUsageReport(workspaceUsage, startOfToday);
67
- const sent = await sendSlackMessage(slackWebhookUrl, message);
68
- if (sent) {
69
- return { result: `Sent report for ${workspaceUsage.length} workspaces` };
70
- } else {
71
- return { result: "Failed to send report" };
72
- }
73
- }
74
- });
@@ -1 +0,0 @@
1
- export declare function authApiFetch<T>(path: string, options?: RequestInit): Promise<T>;
@@ -1,27 +0,0 @@
1
- import { createError } from "h3";
2
- import { useRuntimeConfig } from "nitropack/runtime";
3
- import { logger } from "#chat-runtime/server/utils/logger";
4
- export async function authApiFetch(path, options) {
5
- const config = useRuntimeConfig();
6
- if (!config.authApiSecret) {
7
- throw createError({ statusCode: 500, statusMessage: "AUTH_API_SECRET not configured" });
8
- }
9
- const start = performance.now();
10
- const response = await fetch(`${config.authApiUrl}${path}`, {
11
- ...options,
12
- headers: {
13
- "Authorization": `Bearer ${config.authApiSecret}`,
14
- "Content-Type": "application/json",
15
- ...options?.headers
16
- }
17
- });
18
- if (!response.ok) {
19
- logger.error({ status: response.status, statusText: response.statusText, path }, "Auth API request failed");
20
- throw createError({
21
- statusCode: response.status,
22
- statusMessage: `Auth API error: ${response.statusText}`
23
- });
24
- }
25
- logger.debug({ path, durationMs: Math.round(performance.now() - start) }, "Auth API request succeeded");
26
- return response.json();
27
- }