@od-oneapp/analytics 2026.1.1301

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 (184) hide show
  1. package/README.md +509 -0
  2. package/dist/ai-YMnynb-t.mjs +3347 -0
  3. package/dist/ai-YMnynb-t.mjs.map +1 -0
  4. package/dist/chunk-DQk6qfdC.mjs +18 -0
  5. package/dist/client-CTzJVFU5.mjs +9 -0
  6. package/dist/client-CTzJVFU5.mjs.map +1 -0
  7. package/dist/client-CcFTauAh.mjs +54 -0
  8. package/dist/client-CcFTauAh.mjs.map +1 -0
  9. package/dist/client-CeOLjbac.mjs +281 -0
  10. package/dist/client-CeOLjbac.mjs.map +1 -0
  11. package/dist/client-D339NFJS.mjs +267 -0
  12. package/dist/client-D339NFJS.mjs.map +1 -0
  13. package/dist/client-next.d.mts +62 -0
  14. package/dist/client-next.d.mts.map +1 -0
  15. package/dist/client-next.mjs +525 -0
  16. package/dist/client-next.mjs.map +1 -0
  17. package/dist/client.d.mts +30 -0
  18. package/dist/client.d.mts.map +1 -0
  19. package/dist/client.mjs +186 -0
  20. package/dist/client.mjs.map +1 -0
  21. package/dist/config-DPS6bSYo.d.mts +34 -0
  22. package/dist/config-DPS6bSYo.d.mts.map +1 -0
  23. package/dist/config-P6P5adJg.mjs +287 -0
  24. package/dist/config-P6P5adJg.mjs.map +1 -0
  25. package/dist/console-8bND3mMU.mjs +128 -0
  26. package/dist/console-8bND3mMU.mjs.map +1 -0
  27. package/dist/ecommerce-Cgu4wlux.mjs +993 -0
  28. package/dist/ecommerce-Cgu4wlux.mjs.map +1 -0
  29. package/dist/emitters-6-nKo8i-.mjs +208 -0
  30. package/dist/emitters-6-nKo8i-.mjs.map +1 -0
  31. package/dist/emitters-DldkVSPp.d.mts +12 -0
  32. package/dist/emitters-DldkVSPp.d.mts.map +1 -0
  33. package/dist/index-BfNWgfa5.d.mts +1494 -0
  34. package/dist/index-BfNWgfa5.d.mts.map +1 -0
  35. package/dist/index-BkIWe--N.d.mts +953 -0
  36. package/dist/index-BkIWe--N.d.mts.map +1 -0
  37. package/dist/index-jPzXRn52.d.mts +184 -0
  38. package/dist/index-jPzXRn52.d.mts.map +1 -0
  39. package/dist/manager-DvRRjza6.d.mts +76 -0
  40. package/dist/manager-DvRRjza6.d.mts.map +1 -0
  41. package/dist/posthog-bootstrap-CYfIy_WS.mjs +1769 -0
  42. package/dist/posthog-bootstrap-CYfIy_WS.mjs.map +1 -0
  43. package/dist/posthog-bootstrap-DWxFrxlt.d.mts +81 -0
  44. package/dist/posthog-bootstrap-DWxFrxlt.d.mts.map +1 -0
  45. package/dist/providers-http-client.d.mts +37 -0
  46. package/dist/providers-http-client.d.mts.map +1 -0
  47. package/dist/providers-http-client.mjs +320 -0
  48. package/dist/providers-http-client.mjs.map +1 -0
  49. package/dist/providers-http-server.d.mts +31 -0
  50. package/dist/providers-http-server.d.mts.map +1 -0
  51. package/dist/providers-http-server.mjs +297 -0
  52. package/dist/providers-http-server.mjs.map +1 -0
  53. package/dist/providers-http.d.mts +46 -0
  54. package/dist/providers-http.d.mts.map +1 -0
  55. package/dist/providers-http.mjs +4 -0
  56. package/dist/server-edge.d.mts +9 -0
  57. package/dist/server-edge.d.mts.map +1 -0
  58. package/dist/server-edge.mjs +373 -0
  59. package/dist/server-edge.mjs.map +1 -0
  60. package/dist/server-next.d.mts +67 -0
  61. package/dist/server-next.d.mts.map +1 -0
  62. package/dist/server-next.mjs +193 -0
  63. package/dist/server-next.mjs.map +1 -0
  64. package/dist/server.d.mts +10 -0
  65. package/dist/server.mjs +7 -0
  66. package/dist/service-cYtBBL8x.mjs +945 -0
  67. package/dist/service-cYtBBL8x.mjs.map +1 -0
  68. package/dist/shared.d.mts +16 -0
  69. package/dist/shared.d.mts.map +1 -0
  70. package/dist/shared.mjs +93 -0
  71. package/dist/shared.mjs.map +1 -0
  72. package/dist/types-BxBnNQ0V.d.mts +354 -0
  73. package/dist/types-BxBnNQ0V.d.mts.map +1 -0
  74. package/dist/types-CBvxUEaF.d.mts +216 -0
  75. package/dist/types-CBvxUEaF.d.mts.map +1 -0
  76. package/dist/types.d.mts +4 -0
  77. package/dist/types.mjs +0 -0
  78. package/dist/vercel-types-lwakUfoI.d.mts +102 -0
  79. package/dist/vercel-types-lwakUfoI.d.mts.map +1 -0
  80. package/package.json +129 -0
  81. package/src/client/index.ts +164 -0
  82. package/src/client/manager.ts +71 -0
  83. package/src/client/next/components.tsx +270 -0
  84. package/src/client/next/hooks.ts +217 -0
  85. package/src/client/next/manager.ts +141 -0
  86. package/src/client/next.ts +144 -0
  87. package/src/client-next.ts +101 -0
  88. package/src/client.ts +89 -0
  89. package/src/examples/ai-sdk-patterns.ts +583 -0
  90. package/src/examples/emitter-patterns.ts +476 -0
  91. package/src/examples/nextjs-emitter-patterns.tsx +403 -0
  92. package/src/next/app-router.tsx +564 -0
  93. package/src/next/client.ts +419 -0
  94. package/src/next/index.ts +84 -0
  95. package/src/next/middleware.ts +429 -0
  96. package/src/next/rsc.tsx +300 -0
  97. package/src/next/server.ts +253 -0
  98. package/src/next/types.d.ts +220 -0
  99. package/src/providers/base-provider.ts +419 -0
  100. package/src/providers/console/client.ts +10 -0
  101. package/src/providers/console/index.ts +152 -0
  102. package/src/providers/console/server.ts +6 -0
  103. package/src/providers/console/types.ts +15 -0
  104. package/src/providers/http/client.ts +464 -0
  105. package/src/providers/http/index.ts +30 -0
  106. package/src/providers/http/server.ts +396 -0
  107. package/src/providers/http/types.ts +135 -0
  108. package/src/providers/posthog/client.ts +518 -0
  109. package/src/providers/posthog/index.ts +11 -0
  110. package/src/providers/posthog/server.ts +329 -0
  111. package/src/providers/posthog/types.ts +104 -0
  112. package/src/providers/segment/client.ts +113 -0
  113. package/src/providers/segment/index.ts +11 -0
  114. package/src/providers/segment/server.ts +115 -0
  115. package/src/providers/segment/types.ts +51 -0
  116. package/src/providers/vercel/client.ts +102 -0
  117. package/src/providers/vercel/index.ts +11 -0
  118. package/src/providers/vercel/server.ts +89 -0
  119. package/src/providers/vercel/types.ts +27 -0
  120. package/src/server/index.ts +103 -0
  121. package/src/server/manager.ts +62 -0
  122. package/src/server/next.ts +210 -0
  123. package/src/server-edge.ts +442 -0
  124. package/src/server-next.ts +39 -0
  125. package/src/server.ts +106 -0
  126. package/src/shared/emitters/ai/README.md +981 -0
  127. package/src/shared/emitters/ai/events/agent.ts +130 -0
  128. package/src/shared/emitters/ai/events/artifacts.ts +167 -0
  129. package/src/shared/emitters/ai/events/chat.ts +126 -0
  130. package/src/shared/emitters/ai/events/chatbot-ecommerce.ts +133 -0
  131. package/src/shared/emitters/ai/events/completion.ts +103 -0
  132. package/src/shared/emitters/ai/events/content-generation.ts +347 -0
  133. package/src/shared/emitters/ai/events/conversation.ts +332 -0
  134. package/src/shared/emitters/ai/events/product-features.ts +1402 -0
  135. package/src/shared/emitters/ai/events/streaming.ts +114 -0
  136. package/src/shared/emitters/ai/events/tool.ts +93 -0
  137. package/src/shared/emitters/ai/index.ts +69 -0
  138. package/src/shared/emitters/ai/track-ai-sdk.ts +74 -0
  139. package/src/shared/emitters/ai/track-ai.ts +50 -0
  140. package/src/shared/emitters/ai/types.ts +1041 -0
  141. package/src/shared/emitters/ai/utils.ts +468 -0
  142. package/src/shared/emitters/ecommerce/events/cart-checkout.ts +106 -0
  143. package/src/shared/emitters/ecommerce/events/coupon.ts +49 -0
  144. package/src/shared/emitters/ecommerce/events/engagement.ts +61 -0
  145. package/src/shared/emitters/ecommerce/events/marketplace.ts +119 -0
  146. package/src/shared/emitters/ecommerce/events/order.ts +199 -0
  147. package/src/shared/emitters/ecommerce/events/product.ts +205 -0
  148. package/src/shared/emitters/ecommerce/events/registry.ts +123 -0
  149. package/src/shared/emitters/ecommerce/events/wishlist-sharing.ts +140 -0
  150. package/src/shared/emitters/ecommerce/index.ts +46 -0
  151. package/src/shared/emitters/ecommerce/track-ecommerce.ts +53 -0
  152. package/src/shared/emitters/ecommerce/types.ts +314 -0
  153. package/src/shared/emitters/ecommerce/utils.ts +216 -0
  154. package/src/shared/emitters/emitter-types.ts +974 -0
  155. package/src/shared/emitters/emitters.ts +292 -0
  156. package/src/shared/emitters/helpers.ts +419 -0
  157. package/src/shared/emitters/index.ts +66 -0
  158. package/src/shared/index.ts +142 -0
  159. package/src/shared/ingestion/index.ts +66 -0
  160. package/src/shared/ingestion/schemas.ts +386 -0
  161. package/src/shared/ingestion/service.ts +628 -0
  162. package/src/shared/node22-features.ts +848 -0
  163. package/src/shared/providers/console-provider.ts +160 -0
  164. package/src/shared/types/base-types.ts +54 -0
  165. package/src/shared/types/console-types.ts +19 -0
  166. package/src/shared/types/posthog-types.ts +131 -0
  167. package/src/shared/types/segment-types.ts +15 -0
  168. package/src/shared/types/types.ts +397 -0
  169. package/src/shared/types/vercel-types.ts +19 -0
  170. package/src/shared/utils/config-client.ts +19 -0
  171. package/src/shared/utils/config.ts +250 -0
  172. package/src/shared/utils/emitter-adapter.ts +212 -0
  173. package/src/shared/utils/manager.test.ts +36 -0
  174. package/src/shared/utils/manager.ts +1322 -0
  175. package/src/shared/utils/posthog-bootstrap.ts +136 -0
  176. package/src/shared/utils/posthog-client-utils.ts +48 -0
  177. package/src/shared/utils/posthog-next-utils.ts +282 -0
  178. package/src/shared/utils/posthog-server-utils.ts +210 -0
  179. package/src/shared/utils/rate-limit.ts +289 -0
  180. package/src/shared/utils/security.ts +545 -0
  181. package/src/shared/utils/validation-client.ts +161 -0
  182. package/src/shared/utils/validation.ts +399 -0
  183. package/src/shared.ts +155 -0
  184. package/src/types/index.ts +62 -0
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @fileoverview Agent-related AI SDK v6 events
3
+ * Agent-related AI SDK v6 events
4
+ */
5
+
6
+ import { trackAISDK } from '../track-ai-sdk';
7
+ import {
8
+ type AgentProperties,
9
+ AI_SDK_EVENTS,
10
+ type AISdkEventSpec,
11
+ type CompletionProperties,
12
+ } from '../types';
13
+ import {
14
+ cleanProperties,
15
+ normalizeBaseProperties,
16
+ normalizeTokenUsage,
17
+ validateRequiredProperties,
18
+ } from '../utils';
19
+
20
+ import type { EmitterOptions, EmitterTrackPayload } from '../../emitter-types';
21
+
22
+ /**
23
+ * Track when an AI agent is created
24
+ */
25
+ export function agentCreated(
26
+ properties: AgentProperties,
27
+ options?: EmitterOptions,
28
+ ): EmitterTrackPayload {
29
+ validateRequiredProperties(properties, ['model_id']);
30
+
31
+ const normalizedProps = {
32
+ ...normalizeBaseProperties(properties),
33
+ agent_type: properties.agent_type,
34
+ system_prompt_length: properties.system_prompt_length,
35
+ tools_available: properties.tools_available,
36
+ tools_count: properties.tools_count,
37
+ };
38
+
39
+ const eventSpec: AISdkEventSpec = {
40
+ name: AI_SDK_EVENTS.AGENT_CREATED,
41
+ category: 'ai-sdk',
42
+ properties: cleanProperties(normalizedProps),
43
+ requiredProperties: ['model_id'],
44
+ };
45
+
46
+ return trackAISDK(eventSpec, options);
47
+ }
48
+
49
+ /**
50
+ * Track when an AI agent execution starts
51
+ */
52
+ export function agentExecutionStarted(
53
+ properties: AgentProperties,
54
+ options?: EmitterOptions,
55
+ ): EmitterTrackPayload {
56
+ validateRequiredProperties(properties, ['model_id', 'agent_id']);
57
+
58
+ const normalizedProps = {
59
+ ...normalizeBaseProperties(properties),
60
+ agent_type: properties.agent_type,
61
+ };
62
+
63
+ const eventSpec: AISdkEventSpec = {
64
+ name: AI_SDK_EVENTS.AGENT_EXECUTION_STARTED,
65
+ category: 'ai-sdk',
66
+ properties: cleanProperties(normalizedProps),
67
+ requiredProperties: ['model_id', 'agent_id'],
68
+ };
69
+
70
+ return trackAISDK(eventSpec, options);
71
+ }
72
+
73
+ /**
74
+ * Track when an AI agent execution completes successfully
75
+ */
76
+ export function agentExecutionCompleted(
77
+ properties: CompletionProperties,
78
+ options?: EmitterOptions,
79
+ ): EmitterTrackPayload {
80
+ validateRequiredProperties(properties, ['model_id', 'agent_id', 'status']);
81
+
82
+ const normalizedProps = {
83
+ ...normalizeBaseProperties(properties),
84
+ ...normalizeTokenUsage(properties),
85
+ completion_type: properties.completion_type,
86
+ status: properties.status,
87
+ total_duration_ms: properties.total_duration_ms,
88
+ step_count: properties.step_count,
89
+ finish_reason: properties.finish_reason,
90
+ has_tools: properties.has_tools,
91
+ };
92
+
93
+ const eventSpec: AISdkEventSpec = {
94
+ name: AI_SDK_EVENTS.AGENT_EXECUTION_COMPLETED,
95
+ category: 'ai-sdk',
96
+ properties: cleanProperties(normalizedProps),
97
+ requiredProperties: ['model_id', 'agent_id', 'status'],
98
+ };
99
+
100
+ return trackAISDK(eventSpec, options);
101
+ }
102
+
103
+ /**
104
+ * Track when an AI agent execution fails
105
+ */
106
+ export function agentExecutionFailed(
107
+ properties: CompletionProperties & { error_message: string },
108
+ options?: EmitterOptions,
109
+ ): EmitterTrackPayload {
110
+ validateRequiredProperties(properties, ['model_id', 'agent_id', 'error_message']);
111
+
112
+ const normalizedProps = {
113
+ ...normalizeBaseProperties(properties),
114
+ ...normalizeTokenUsage(properties),
115
+ completion_type: properties.completion_type,
116
+ status: 'failed' as const,
117
+ error_message: properties.error_message,
118
+ retry_count: properties.retry_count,
119
+ total_duration_ms: properties.total_duration_ms,
120
+ };
121
+
122
+ const eventSpec: AISdkEventSpec = {
123
+ name: AI_SDK_EVENTS.AGENT_EXECUTION_FAILED,
124
+ category: 'ai-sdk',
125
+ properties: cleanProperties(normalizedProps),
126
+ requiredProperties: ['model_id', 'agent_id', 'error_message'],
127
+ };
128
+
129
+ return trackAISDK(eventSpec, options);
130
+ }
@@ -0,0 +1,167 @@
1
+ /**
2
+ * @fileoverview Artifacts & Canvas Events
3
+ * Artifacts & Canvas Events
4
+ *
5
+ * Interactive artifacts and canvas mode features (Claude-style).
6
+ * Track creation, editing, execution, and interaction with artifacts.
7
+ */
8
+
9
+ import { createAITracker } from '../track-ai';
10
+ import { AI_EVENTS, type ArtifactProperties, type CanvasProperties } from '../types';
11
+
12
+ /**
13
+ * Track artifact creation
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * ai.ARTIFACT_CREATED({
18
+ * conversation_id: 'conv_123',
19
+ * model_id: 'claude-3-5-sonnet',
20
+ * artifact_id: 'art_001',
21
+ * artifact_type: 'react-component',
22
+ * action: 'create',
23
+ * language: 'tsx',
24
+ * content_length: 850,
25
+ * });
26
+ * ```
27
+ */
28
+ export const ARTIFACT_CREATED = createAITracker<ArtifactProperties>(properties => ({
29
+ name: AI_EVENTS.ARTIFACT_CREATED,
30
+ category: 'artifacts',
31
+ properties,
32
+ requiredProperties: ['action', 'artifact_type'],
33
+ }));
34
+
35
+ /**
36
+ * Track artifact editing
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * ai.ARTIFACT_EDITED({
41
+ * conversation_id: 'conv_123',
42
+ * model_id: 'claude-3-5-sonnet',
43
+ * artifact_id: 'art_001',
44
+ * artifact_type: 'react-component',
45
+ * action: 'edit',
46
+ * version: 2,
47
+ * changes_description: 'Updated button styling',
48
+ * });
49
+ * ```
50
+ */
51
+ export const ARTIFACT_EDITED = createAITracker<ArtifactProperties>(properties => ({
52
+ name: AI_EVENTS.ARTIFACT_EDITED,
53
+ category: 'artifacts',
54
+ properties,
55
+ requiredProperties: ['action', 'artifact_type'],
56
+ }));
57
+
58
+ /**
59
+ * Track artifact execution
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * ai.ARTIFACT_EXECUTED({
64
+ * conversation_id: 'conv_123',
65
+ * model_id: 'claude-3-5-sonnet',
66
+ * artifact_id: 'art_001',
67
+ * artifact_type: 'code',
68
+ * action: 'execute',
69
+ * execution_status: 'success',
70
+ * execution_time_ms: 150,
71
+ * });
72
+ * ```
73
+ */
74
+ export const ARTIFACT_EXECUTED = createAITracker<ArtifactProperties>(properties => ({
75
+ name: AI_EVENTS.ARTIFACT_EXECUTED,
76
+ category: 'artifacts',
77
+ properties,
78
+ requiredProperties: ['action', 'artifact_type'],
79
+ }));
80
+
81
+ /**
82
+ * Track artifact publishing
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * ai.ARTIFACT_PUBLISHED({
87
+ * conversation_id: 'conv_123',
88
+ * model_id: 'claude-3-5-sonnet',
89
+ * artifact_id: 'art_001',
90
+ * artifact_type: 'visualization',
91
+ * action: 'publish',
92
+ * visibility: 'public',
93
+ * publish_platform: 'web',
94
+ * });
95
+ * ```
96
+ */
97
+ export const ARTIFACT_PUBLISHED = createAITracker<ArtifactProperties>(properties => ({
98
+ name: AI_EVENTS.ARTIFACT_PUBLISHED,
99
+ category: 'artifacts',
100
+ properties,
101
+ requiredProperties: ['action', 'artifact_type'],
102
+ }));
103
+
104
+ /**
105
+ * Track artifact forking
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * ai.ARTIFACT_FORKED({
110
+ * conversation_id: 'conv_123',
111
+ * model_id: 'claude-3-5-sonnet',
112
+ * artifact_id: 'art_001',
113
+ * artifact_type: 'react-component',
114
+ * action: 'fork',
115
+ * new_artifact_id: 'art_002',
116
+ * fork_reason: 'experiment',
117
+ * });
118
+ * ```
119
+ */
120
+ export const ARTIFACT_FORKED = createAITracker<ArtifactProperties>(properties => ({
121
+ name: AI_EVENTS.ARTIFACT_FORKED,
122
+ category: 'artifacts',
123
+ properties,
124
+ requiredProperties: ['action', 'artifact_type'],
125
+ }));
126
+
127
+ /**
128
+ * Track canvas mode opened
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * ai.CANVAS_OPENED({
133
+ * conversation_id: 'conv_123',
134
+ * model_id: 'claude-3-5-sonnet',
135
+ * canvas_type: 'code',
136
+ * initial_content_length: 500,
137
+ * canvas_size: 'full-screen',
138
+ * });
139
+ * ```
140
+ */
141
+ export const CANVAS_OPENED = createAITracker<CanvasProperties>(properties => ({
142
+ name: AI_EVENTS.CANVAS_OPENED,
143
+ category: 'artifacts',
144
+ properties,
145
+ requiredProperties: ['action'],
146
+ }));
147
+
148
+ /**
149
+ * Track live preview toggle
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * ai.LIVE_PREVIEW_TOGGLED({
154
+ * conversation_id: 'conv_123',
155
+ * model_id: 'claude-3-5-net',
156
+ * artifact_id: 'art_001',
157
+ * preview_enabled: true,
158
+ * preview_type: 'browser',
159
+ * });
160
+ * ```
161
+ */
162
+ export const LIVE_PREVIEW_TOGGLED = createAITracker<CanvasProperties>(properties => ({
163
+ name: AI_EVENTS.LIVE_PREVIEW_TOGGLED,
164
+ category: 'artifacts',
165
+ properties,
166
+ requiredProperties: ['action'],
167
+ }));
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @fileoverview Chat-related AI SDK v6 events
3
+ * Chat-related AI SDK v6 events
4
+ */
5
+
6
+ import { trackAISDK } from '../track-ai-sdk';
7
+ import {
8
+ AI_SDK_EVENTS,
9
+ type AISdkEventSpec,
10
+ type ChatMessageProperties,
11
+ type SessionProperties,
12
+ } from '../types';
13
+ import { cleanProperties, normalizeBaseProperties, validateRequiredProperties } from '../utils';
14
+
15
+ import type { EmitterOptions, EmitterTrackPayload } from '../../emitter-types';
16
+
17
+ /**
18
+ * Track when a chat session starts
19
+ */
20
+ export function chatSessionStarted(
21
+ properties: SessionProperties,
22
+ options?: EmitterOptions,
23
+ ): EmitterTrackPayload {
24
+ validateRequiredProperties(properties, ['model_id', 'session_id']);
25
+
26
+ const normalizedProps = {
27
+ ...normalizeBaseProperties(properties),
28
+ session_type: properties.session_type,
29
+ };
30
+
31
+ const eventSpec: AISdkEventSpec = {
32
+ name: AI_SDK_EVENTS.CHAT_SESSION_STARTED,
33
+ category: 'ai-sdk',
34
+ properties: cleanProperties(normalizedProps),
35
+ requiredProperties: ['model_id', 'session_id'],
36
+ };
37
+
38
+ return trackAISDK(eventSpec, options);
39
+ }
40
+
41
+ /**
42
+ * Track when a chat session ends
43
+ */
44
+ export function chatSessionEnded(
45
+ properties: SessionProperties,
46
+ options?: EmitterOptions,
47
+ ): EmitterTrackPayload {
48
+ validateRequiredProperties(properties, ['model_id', 'session_id']);
49
+
50
+ const normalizedProps = {
51
+ ...normalizeBaseProperties(properties),
52
+ duration_ms: properties.duration_ms,
53
+ message_count: properties.message_count,
54
+ tool_calls_count: properties.tool_calls_count,
55
+ total_tokens: properties.total_tokens,
56
+ session_end_reason: properties.session_end_reason,
57
+ };
58
+
59
+ const eventSpec: AISdkEventSpec = {
60
+ name: AI_SDK_EVENTS.CHAT_SESSION_ENDED,
61
+ category: 'ai-sdk',
62
+ properties: cleanProperties(normalizedProps),
63
+ requiredProperties: ['model_id', 'session_id'],
64
+ };
65
+
66
+ return trackAISDK(eventSpec, options);
67
+ }
68
+
69
+ /**
70
+ * Track when a user sends a chat message
71
+ */
72
+ export function chatMessageSent(
73
+ properties: ChatMessageProperties,
74
+ options?: EmitterOptions,
75
+ ): EmitterTrackPayload {
76
+ validateRequiredProperties(properties, ['model_id', 'message_role']);
77
+
78
+ const normalizedProps = {
79
+ ...normalizeBaseProperties(properties),
80
+ message_id: properties.message_id,
81
+ message_role: properties.message_role,
82
+ message_length: properties.message_length,
83
+ message_index: properties.message_index,
84
+ has_images: properties.has_images,
85
+ parent_message_id: properties.parent_message_id,
86
+ };
87
+
88
+ const eventSpec: AISdkEventSpec = {
89
+ name: AI_SDK_EVENTS.CHAT_MESSAGE_SENT,
90
+ category: 'ai-sdk',
91
+ properties: cleanProperties(normalizedProps),
92
+ requiredProperties: ['model_id', 'message_role'],
93
+ };
94
+
95
+ return trackAISDK(eventSpec, options);
96
+ }
97
+
98
+ /**
99
+ * Track when the assistant's chat message is received
100
+ */
101
+ export function chatMessageReceived(
102
+ properties: ChatMessageProperties,
103
+ options?: EmitterOptions,
104
+ ): EmitterTrackPayload {
105
+ validateRequiredProperties(properties, ['model_id', 'message_role']);
106
+
107
+ const normalizedProps = {
108
+ ...normalizeBaseProperties(properties),
109
+ message_id: properties.message_id,
110
+ message_role: properties.message_role,
111
+ message_length: properties.message_length,
112
+ message_index: properties.message_index,
113
+ finish_reason: properties.finish_reason,
114
+ response_time_ms: properties.response_time_ms,
115
+ is_streaming: properties.is_streaming,
116
+ };
117
+
118
+ const eventSpec: AISdkEventSpec = {
119
+ name: AI_SDK_EVENTS.CHAT_MESSAGE_RECEIVED,
120
+ category: 'ai-sdk',
121
+ properties: cleanProperties(normalizedProps),
122
+ requiredProperties: ['model_id', 'message_role'],
123
+ };
124
+
125
+ return trackAISDK(eventSpec, options);
126
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @fileoverview E-commerce chatbot-specific AI SDK v6 events
3
+ * E-commerce chatbot-specific AI SDK v6 events
4
+ */
5
+
6
+ import { trackAISDK } from '../track-ai-sdk';
7
+ import { AI_SDK_EVENTS, type AISdkEventSpec, type ChatbotEcommerceProperties } from '../types';
8
+ import {
9
+ cleanProperties,
10
+ detectChatbotIntent,
11
+ normalizeBaseProperties,
12
+ truncateArray,
13
+ validateRequiredProperties,
14
+ } from '../utils';
15
+
16
+ import type { EmitterOptions, EmitterTrackPayload } from '../../emitter-types';
17
+
18
+ /**
19
+ * Maximum number of product IDs to include in chatbot ecommerce events.
20
+ * Limits payload size and prevents excessive data in analytics.
21
+ */
22
+ export const MAX_PRODUCT_IDS = 20;
23
+
24
+ /**
25
+ * Track when chatbot detects user intent
26
+ */
27
+ export function chatbotIntentDetected(
28
+ properties: ChatbotEcommerceProperties & { message: string },
29
+ options?: EmitterOptions,
30
+ ): EmitterTrackPayload {
31
+ validateRequiredProperties(properties, ['model_id', 'message']);
32
+
33
+ // Auto-detect intent if not provided
34
+ const intent = properties.intent_detected ?? detectChatbotIntent(properties.message);
35
+
36
+ const normalizedProps = {
37
+ ...normalizeBaseProperties(properties),
38
+ intent_detected: intent,
39
+ };
40
+
41
+ const eventSpec: AISdkEventSpec = {
42
+ name: AI_SDK_EVENTS.CHATBOT_INTENT_DETECTED,
43
+ category: 'ai-sdk',
44
+ properties: cleanProperties(normalizedProps),
45
+ requiredProperties: ['model_id'],
46
+ };
47
+
48
+ return trackAISDK(eventSpec, options);
49
+ }
50
+
51
+ /**
52
+ * Track when chatbot assists with cart operations
53
+ */
54
+ export function chatbotCartAssisted(
55
+ properties: ChatbotEcommerceProperties,
56
+ options?: EmitterOptions,
57
+ ): EmitterTrackPayload {
58
+ validateRequiredProperties(properties, ['model_id', 'cart_id']);
59
+
60
+ const normalizedProps = {
61
+ ...normalizeBaseProperties(properties),
62
+ cart_id: properties.cart_id,
63
+ cart_value: properties.cart_value,
64
+ product_count: properties.product_count,
65
+ product_ids: properties.product_ids
66
+ ? truncateArray(properties.product_ids, MAX_PRODUCT_IDS)
67
+ : undefined,
68
+ intent_detected: properties.intent_detected,
69
+ };
70
+
71
+ const eventSpec: AISdkEventSpec = {
72
+ name: AI_SDK_EVENTS.CHATBOT_CART_ASSISTED,
73
+ category: 'ai-sdk',
74
+ properties: cleanProperties(normalizedProps),
75
+ requiredProperties: ['model_id', 'cart_id'],
76
+ };
77
+
78
+ return trackAISDK(eventSpec, options);
79
+ }
80
+
81
+ /**
82
+ * Track when chatbot assists with order-related queries
83
+ */
84
+ export function chatbotOrderAssisted(
85
+ properties: ChatbotEcommerceProperties,
86
+ options?: EmitterOptions,
87
+ ): EmitterTrackPayload {
88
+ validateRequiredProperties(properties, ['model_id', 'order_id']);
89
+
90
+ const normalizedProps = {
91
+ ...normalizeBaseProperties(properties),
92
+ order_id: properties.order_id,
93
+ intent_detected: properties.intent_detected,
94
+ };
95
+
96
+ const eventSpec: AISdkEventSpec = {
97
+ name: AI_SDK_EVENTS.CHATBOT_ORDER_ASSISTED,
98
+ category: 'ai-sdk',
99
+ properties: cleanProperties(normalizedProps),
100
+ requiredProperties: ['model_id', 'order_id'],
101
+ };
102
+
103
+ return trackAISDK(eventSpec, options);
104
+ }
105
+
106
+ /**
107
+ * Track when chatbot shows product recommendations
108
+ */
109
+ export function chatbotProductRecommended(
110
+ properties: ChatbotEcommerceProperties,
111
+ options?: EmitterOptions,
112
+ ): EmitterTrackPayload {
113
+ validateRequiredProperties(properties, ['model_id', 'product_ids']);
114
+
115
+ const normalizedProps = {
116
+ ...normalizeBaseProperties(properties),
117
+ product_count: properties.product_count ?? properties.product_ids?.length,
118
+ product_ids: properties.product_ids
119
+ ? truncateArray(properties.product_ids, MAX_PRODUCT_IDS)
120
+ : undefined,
121
+ recommendation_shown: true,
122
+ intent_detected: properties.intent_detected,
123
+ };
124
+
125
+ const eventSpec: AISdkEventSpec = {
126
+ name: AI_SDK_EVENTS.CHATBOT_PRODUCT_RECOMMENDED,
127
+ category: 'ai-sdk',
128
+ properties: cleanProperties(normalizedProps),
129
+ requiredProperties: ['model_id', 'product_ids'],
130
+ };
131
+
132
+ return trackAISDK(eventSpec, options);
133
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @fileoverview Completion-related AI SDK v6 events
3
+ * Completion-related AI SDK v6 events
4
+ */
5
+
6
+ import { trackAISDK } from '../track-ai-sdk';
7
+ import { AI_SDK_EVENTS, type AISdkEventSpec, type CompletionProperties } from '../types';
8
+ import {
9
+ cleanProperties,
10
+ normalizeBaseProperties,
11
+ normalizeModelConfig,
12
+ normalizeTokenUsage,
13
+ validateRequiredProperties,
14
+ } from '../utils';
15
+
16
+ import type { EmitterOptions, EmitterTrackPayload } from '../../emitter-types';
17
+
18
+ /**
19
+ * Track when a completion is requested
20
+ */
21
+ export function completionRequested(
22
+ properties: CompletionProperties,
23
+ options?: EmitterOptions,
24
+ ): EmitterTrackPayload {
25
+ validateRequiredProperties(properties, ['model_id', 'completion_type']);
26
+
27
+ const normalizedProps = {
28
+ ...normalizeBaseProperties(properties),
29
+ ...normalizeModelConfig(properties),
30
+ completion_type: properties.completion_type,
31
+ prompt_length: properties.prompt_length,
32
+ has_tools: properties.has_tools,
33
+ };
34
+
35
+ const eventSpec: AISdkEventSpec = {
36
+ name: AI_SDK_EVENTS.COMPLETION_REQUESTED,
37
+ category: 'ai-sdk',
38
+ properties: cleanProperties(normalizedProps),
39
+ requiredProperties: ['model_id', 'completion_type'],
40
+ };
41
+
42
+ return trackAISDK(eventSpec, options);
43
+ }
44
+
45
+ /**
46
+ * Track when a completion is successfully generated
47
+ */
48
+ export function completionGenerated(
49
+ properties: CompletionProperties,
50
+ options?: EmitterOptions,
51
+ ): EmitterTrackPayload {
52
+ validateRequiredProperties(properties, ['model_id', 'completion_type', 'status']);
53
+
54
+ const normalizedProps = {
55
+ ...normalizeBaseProperties(properties),
56
+ ...normalizeTokenUsage(properties),
57
+ ...normalizeModelConfig(properties),
58
+ completion_type: properties.completion_type,
59
+ status: properties.status,
60
+ finish_reason: properties.finish_reason,
61
+ total_duration_ms: properties.total_duration_ms,
62
+ step_count: properties.step_count,
63
+ retry_count: properties.retry_count,
64
+ };
65
+
66
+ const eventSpec: AISdkEventSpec = {
67
+ name: AI_SDK_EVENTS.COMPLETION_GENERATED,
68
+ category: 'ai-sdk',
69
+ properties: cleanProperties(normalizedProps),
70
+ requiredProperties: ['model_id', 'completion_type', 'status'],
71
+ };
72
+
73
+ return trackAISDK(eventSpec, options);
74
+ }
75
+
76
+ /**
77
+ * Track when a completion fails
78
+ */
79
+ export function completionFailed(
80
+ properties: CompletionProperties & { error_message: string },
81
+ options?: EmitterOptions,
82
+ ): EmitterTrackPayload {
83
+ validateRequiredProperties(properties, ['model_id', 'completion_type', 'error_message']);
84
+
85
+ const normalizedProps = {
86
+ ...normalizeBaseProperties(properties),
87
+ ...normalizeTokenUsage(properties),
88
+ completion_type: properties.completion_type,
89
+ status: 'failed' as const,
90
+ error_message: properties.error_message,
91
+ retry_count: properties.retry_count,
92
+ total_duration_ms: properties.total_duration_ms,
93
+ };
94
+
95
+ const eventSpec: AISdkEventSpec = {
96
+ name: AI_SDK_EVENTS.COMPLETION_FAILED,
97
+ category: 'ai-sdk',
98
+ properties: cleanProperties(normalizedProps),
99
+ requiredProperties: ['model_id', 'completion_type', 'error_message'],
100
+ };
101
+
102
+ return trackAISDK(eventSpec, options);
103
+ }