@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.
- package/README.md +509 -0
- package/dist/ai-YMnynb-t.mjs +3347 -0
- package/dist/ai-YMnynb-t.mjs.map +1 -0
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/client-CTzJVFU5.mjs +9 -0
- package/dist/client-CTzJVFU5.mjs.map +1 -0
- package/dist/client-CcFTauAh.mjs +54 -0
- package/dist/client-CcFTauAh.mjs.map +1 -0
- package/dist/client-CeOLjbac.mjs +281 -0
- package/dist/client-CeOLjbac.mjs.map +1 -0
- package/dist/client-D339NFJS.mjs +267 -0
- package/dist/client-D339NFJS.mjs.map +1 -0
- package/dist/client-next.d.mts +62 -0
- package/dist/client-next.d.mts.map +1 -0
- package/dist/client-next.mjs +525 -0
- package/dist/client-next.mjs.map +1 -0
- package/dist/client.d.mts +30 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +186 -0
- package/dist/client.mjs.map +1 -0
- package/dist/config-DPS6bSYo.d.mts +34 -0
- package/dist/config-DPS6bSYo.d.mts.map +1 -0
- package/dist/config-P6P5adJg.mjs +287 -0
- package/dist/config-P6P5adJg.mjs.map +1 -0
- package/dist/console-8bND3mMU.mjs +128 -0
- package/dist/console-8bND3mMU.mjs.map +1 -0
- package/dist/ecommerce-Cgu4wlux.mjs +993 -0
- package/dist/ecommerce-Cgu4wlux.mjs.map +1 -0
- package/dist/emitters-6-nKo8i-.mjs +208 -0
- package/dist/emitters-6-nKo8i-.mjs.map +1 -0
- package/dist/emitters-DldkVSPp.d.mts +12 -0
- package/dist/emitters-DldkVSPp.d.mts.map +1 -0
- package/dist/index-BfNWgfa5.d.mts +1494 -0
- package/dist/index-BfNWgfa5.d.mts.map +1 -0
- package/dist/index-BkIWe--N.d.mts +953 -0
- package/dist/index-BkIWe--N.d.mts.map +1 -0
- package/dist/index-jPzXRn52.d.mts +184 -0
- package/dist/index-jPzXRn52.d.mts.map +1 -0
- package/dist/manager-DvRRjza6.d.mts +76 -0
- package/dist/manager-DvRRjza6.d.mts.map +1 -0
- package/dist/posthog-bootstrap-CYfIy_WS.mjs +1769 -0
- package/dist/posthog-bootstrap-CYfIy_WS.mjs.map +1 -0
- package/dist/posthog-bootstrap-DWxFrxlt.d.mts +81 -0
- package/dist/posthog-bootstrap-DWxFrxlt.d.mts.map +1 -0
- package/dist/providers-http-client.d.mts +37 -0
- package/dist/providers-http-client.d.mts.map +1 -0
- package/dist/providers-http-client.mjs +320 -0
- package/dist/providers-http-client.mjs.map +1 -0
- package/dist/providers-http-server.d.mts +31 -0
- package/dist/providers-http-server.d.mts.map +1 -0
- package/dist/providers-http-server.mjs +297 -0
- package/dist/providers-http-server.mjs.map +1 -0
- package/dist/providers-http.d.mts +46 -0
- package/dist/providers-http.d.mts.map +1 -0
- package/dist/providers-http.mjs +4 -0
- package/dist/server-edge.d.mts +9 -0
- package/dist/server-edge.d.mts.map +1 -0
- package/dist/server-edge.mjs +373 -0
- package/dist/server-edge.mjs.map +1 -0
- package/dist/server-next.d.mts +67 -0
- package/dist/server-next.d.mts.map +1 -0
- package/dist/server-next.mjs +193 -0
- package/dist/server-next.mjs.map +1 -0
- package/dist/server.d.mts +10 -0
- package/dist/server.mjs +7 -0
- package/dist/service-cYtBBL8x.mjs +945 -0
- package/dist/service-cYtBBL8x.mjs.map +1 -0
- package/dist/shared.d.mts +16 -0
- package/dist/shared.d.mts.map +1 -0
- package/dist/shared.mjs +93 -0
- package/dist/shared.mjs.map +1 -0
- package/dist/types-BxBnNQ0V.d.mts +354 -0
- package/dist/types-BxBnNQ0V.d.mts.map +1 -0
- package/dist/types-CBvxUEaF.d.mts +216 -0
- package/dist/types-CBvxUEaF.d.mts.map +1 -0
- package/dist/types.d.mts +4 -0
- package/dist/types.mjs +0 -0
- package/dist/vercel-types-lwakUfoI.d.mts +102 -0
- package/dist/vercel-types-lwakUfoI.d.mts.map +1 -0
- package/package.json +129 -0
- package/src/client/index.ts +164 -0
- package/src/client/manager.ts +71 -0
- package/src/client/next/components.tsx +270 -0
- package/src/client/next/hooks.ts +217 -0
- package/src/client/next/manager.ts +141 -0
- package/src/client/next.ts +144 -0
- package/src/client-next.ts +101 -0
- package/src/client.ts +89 -0
- package/src/examples/ai-sdk-patterns.ts +583 -0
- package/src/examples/emitter-patterns.ts +476 -0
- package/src/examples/nextjs-emitter-patterns.tsx +403 -0
- package/src/next/app-router.tsx +564 -0
- package/src/next/client.ts +419 -0
- package/src/next/index.ts +84 -0
- package/src/next/middleware.ts +429 -0
- package/src/next/rsc.tsx +300 -0
- package/src/next/server.ts +253 -0
- package/src/next/types.d.ts +220 -0
- package/src/providers/base-provider.ts +419 -0
- package/src/providers/console/client.ts +10 -0
- package/src/providers/console/index.ts +152 -0
- package/src/providers/console/server.ts +6 -0
- package/src/providers/console/types.ts +15 -0
- package/src/providers/http/client.ts +464 -0
- package/src/providers/http/index.ts +30 -0
- package/src/providers/http/server.ts +396 -0
- package/src/providers/http/types.ts +135 -0
- package/src/providers/posthog/client.ts +518 -0
- package/src/providers/posthog/index.ts +11 -0
- package/src/providers/posthog/server.ts +329 -0
- package/src/providers/posthog/types.ts +104 -0
- package/src/providers/segment/client.ts +113 -0
- package/src/providers/segment/index.ts +11 -0
- package/src/providers/segment/server.ts +115 -0
- package/src/providers/segment/types.ts +51 -0
- package/src/providers/vercel/client.ts +102 -0
- package/src/providers/vercel/index.ts +11 -0
- package/src/providers/vercel/server.ts +89 -0
- package/src/providers/vercel/types.ts +27 -0
- package/src/server/index.ts +103 -0
- package/src/server/manager.ts +62 -0
- package/src/server/next.ts +210 -0
- package/src/server-edge.ts +442 -0
- package/src/server-next.ts +39 -0
- package/src/server.ts +106 -0
- package/src/shared/emitters/ai/README.md +981 -0
- package/src/shared/emitters/ai/events/agent.ts +130 -0
- package/src/shared/emitters/ai/events/artifacts.ts +167 -0
- package/src/shared/emitters/ai/events/chat.ts +126 -0
- package/src/shared/emitters/ai/events/chatbot-ecommerce.ts +133 -0
- package/src/shared/emitters/ai/events/completion.ts +103 -0
- package/src/shared/emitters/ai/events/content-generation.ts +347 -0
- package/src/shared/emitters/ai/events/conversation.ts +332 -0
- package/src/shared/emitters/ai/events/product-features.ts +1402 -0
- package/src/shared/emitters/ai/events/streaming.ts +114 -0
- package/src/shared/emitters/ai/events/tool.ts +93 -0
- package/src/shared/emitters/ai/index.ts +69 -0
- package/src/shared/emitters/ai/track-ai-sdk.ts +74 -0
- package/src/shared/emitters/ai/track-ai.ts +50 -0
- package/src/shared/emitters/ai/types.ts +1041 -0
- package/src/shared/emitters/ai/utils.ts +468 -0
- package/src/shared/emitters/ecommerce/events/cart-checkout.ts +106 -0
- package/src/shared/emitters/ecommerce/events/coupon.ts +49 -0
- package/src/shared/emitters/ecommerce/events/engagement.ts +61 -0
- package/src/shared/emitters/ecommerce/events/marketplace.ts +119 -0
- package/src/shared/emitters/ecommerce/events/order.ts +199 -0
- package/src/shared/emitters/ecommerce/events/product.ts +205 -0
- package/src/shared/emitters/ecommerce/events/registry.ts +123 -0
- package/src/shared/emitters/ecommerce/events/wishlist-sharing.ts +140 -0
- package/src/shared/emitters/ecommerce/index.ts +46 -0
- package/src/shared/emitters/ecommerce/track-ecommerce.ts +53 -0
- package/src/shared/emitters/ecommerce/types.ts +314 -0
- package/src/shared/emitters/ecommerce/utils.ts +216 -0
- package/src/shared/emitters/emitter-types.ts +974 -0
- package/src/shared/emitters/emitters.ts +292 -0
- package/src/shared/emitters/helpers.ts +419 -0
- package/src/shared/emitters/index.ts +66 -0
- package/src/shared/index.ts +142 -0
- package/src/shared/ingestion/index.ts +66 -0
- package/src/shared/ingestion/schemas.ts +386 -0
- package/src/shared/ingestion/service.ts +628 -0
- package/src/shared/node22-features.ts +848 -0
- package/src/shared/providers/console-provider.ts +160 -0
- package/src/shared/types/base-types.ts +54 -0
- package/src/shared/types/console-types.ts +19 -0
- package/src/shared/types/posthog-types.ts +131 -0
- package/src/shared/types/segment-types.ts +15 -0
- package/src/shared/types/types.ts +397 -0
- package/src/shared/types/vercel-types.ts +19 -0
- package/src/shared/utils/config-client.ts +19 -0
- package/src/shared/utils/config.ts +250 -0
- package/src/shared/utils/emitter-adapter.ts +212 -0
- package/src/shared/utils/manager.test.ts +36 -0
- package/src/shared/utils/manager.ts +1322 -0
- package/src/shared/utils/posthog-bootstrap.ts +136 -0
- package/src/shared/utils/posthog-client-utils.ts +48 -0
- package/src/shared/utils/posthog-next-utils.ts +282 -0
- package/src/shared/utils/posthog-server-utils.ts +210 -0
- package/src/shared/utils/rate-limit.ts +289 -0
- package/src/shared/utils/security.ts +545 -0
- package/src/shared/utils/validation-client.ts +161 -0
- package/src/shared/utils/validation.ts +399 -0
- package/src/shared.ts +155 -0
- package/src/types/index.ts +62 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Content Generation Events
|
|
3
|
+
* Content Generation Events
|
|
4
|
+
*
|
|
5
|
+
* All types of AI-generated content: code, images, summaries, translations, etc.
|
|
6
|
+
* These track what the AI creates, not what users do with it.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createAITracker } from '../track-ai';
|
|
10
|
+
import {
|
|
11
|
+
AI_EVENTS,
|
|
12
|
+
type CodeGenerationProperties,
|
|
13
|
+
type ContentGenerationProperties,
|
|
14
|
+
type ImageGenerationProperties,
|
|
15
|
+
type SummaryProperties,
|
|
16
|
+
} from '../types';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Track code generation
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* ai.CODE_GENERATED({
|
|
24
|
+
* conversation_id: 'conv_123',
|
|
25
|
+
* model_id: 'gpt-4',
|
|
26
|
+
* language: 'typescript',
|
|
27
|
+
* code_length: 450,
|
|
28
|
+
* code_type: 'function',
|
|
29
|
+
* has_explanation: true,
|
|
30
|
+
* has_tests: false,
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const CODE_GENERATED = createAITracker<CodeGenerationProperties>(properties => ({
|
|
35
|
+
name: AI_EVENTS.CODE_GENERATED,
|
|
36
|
+
category: 'content-generation',
|
|
37
|
+
properties,
|
|
38
|
+
requiredProperties: ['task_type'],
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Track code explanation
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* ai.CODE_EXPLAINED({
|
|
47
|
+
* conversation_id: 'conv_123',
|
|
48
|
+
* model_id: 'claude-3-5-sonnet',
|
|
49
|
+
* language: 'python',
|
|
50
|
+
* code_length: 200,
|
|
51
|
+
* explanation_length: 500,
|
|
52
|
+
* explanation_type: 'detailed',
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export const CODE_EXPLAINED = createAITracker<CodeGenerationProperties>(properties => ({
|
|
57
|
+
name: AI_EVENTS.CODE_EXPLAINED,
|
|
58
|
+
category: 'content-generation',
|
|
59
|
+
properties,
|
|
60
|
+
requiredProperties: ['task_type'],
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Track code debugging assistance
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* ai.CODE_DEBUGGED({
|
|
69
|
+
* conversation_id: 'conv_123',
|
|
70
|
+
* model_id: 'gpt-4',
|
|
71
|
+
* language: 'javascript',
|
|
72
|
+
* code_length: 300,
|
|
73
|
+
* issues_found: 3,
|
|
74
|
+
* fixes_suggested: 3,
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export const CODE_DEBUGGED = createAITracker<CodeGenerationProperties>(properties => ({
|
|
79
|
+
name: AI_EVENTS.CODE_DEBUGGED,
|
|
80
|
+
category: 'content-generation',
|
|
81
|
+
properties,
|
|
82
|
+
requiredProperties: ['task_type'],
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Track code refactoring suggestions
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* ai.CODE_REFACTORED({
|
|
91
|
+
* conversation_id: 'conv_123',
|
|
92
|
+
* model_id: 'claude-3-5-sonnet',
|
|
93
|
+
* language: 'typescript',
|
|
94
|
+
* code_length: 500,
|
|
95
|
+
* refactor_type: 'extract-function',
|
|
96
|
+
* improvements_suggested: 5,
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export const CODE_REFACTORED = createAITracker<CodeGenerationProperties>(properties => ({
|
|
101
|
+
name: AI_EVENTS.CODE_REFACTORED,
|
|
102
|
+
category: 'content-generation',
|
|
103
|
+
properties,
|
|
104
|
+
requiredProperties: ['task_type'],
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Track code translation between languages
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* ai.CODE_TRANSLATED({
|
|
113
|
+
* conversation_id: 'conv_123',
|
|
114
|
+
* model_id: 'gpt-4',
|
|
115
|
+
* language: 'typescript',
|
|
116
|
+
* code_length: 350,
|
|
117
|
+
* source_language: 'python',
|
|
118
|
+
* target_language: 'typescript',
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export const CODE_TRANSLATED = createAITracker<CodeGenerationProperties>(properties => ({
|
|
123
|
+
name: AI_EVENTS.CODE_TRANSLATED,
|
|
124
|
+
category: 'content-generation',
|
|
125
|
+
properties,
|
|
126
|
+
requiredProperties: ['task_type'],
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Track image generation
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* ai.IMAGE_GENERATED({
|
|
135
|
+
* conversation_id: 'conv_123',
|
|
136
|
+
* model_id: 'dall-e-3',
|
|
137
|
+
* image_type: 'generated',
|
|
138
|
+
* prompt_length: 80,
|
|
139
|
+
* image_format: 'png',
|
|
140
|
+
* image_size: '1024x1024',
|
|
141
|
+
* generation_time_ms: 5000,
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export const IMAGE_GENERATED = createAITracker<ImageGenerationProperties>(properties => ({
|
|
146
|
+
name: AI_EVENTS.IMAGE_GENERATED,
|
|
147
|
+
category: 'content-generation',
|
|
148
|
+
properties,
|
|
149
|
+
requiredProperties: [],
|
|
150
|
+
}));
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Track image editing
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* ai.IMAGE_EDITED({
|
|
158
|
+
* conversation_id: 'conv_123',
|
|
159
|
+
* model_id: 'dall-e-3',
|
|
160
|
+
* image_type: 'edited',
|
|
161
|
+
* edit_type: 'inpaint',
|
|
162
|
+
* prompt_length: 50,
|
|
163
|
+
* image_format: 'png',
|
|
164
|
+
* });
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export const IMAGE_EDITED = createAITracker<ImageGenerationProperties>(properties => ({
|
|
168
|
+
name: AI_EVENTS.IMAGE_EDITED,
|
|
169
|
+
category: 'content-generation',
|
|
170
|
+
properties,
|
|
171
|
+
requiredProperties: [],
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Track general text generation
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* ai.TEXT_GENERATED({
|
|
180
|
+
* conversation_id: 'conv_123',
|
|
181
|
+
* model_id: 'claude-3-5-sonnet',
|
|
182
|
+
* content_type: 'article',
|
|
183
|
+
* content_length: 1500,
|
|
184
|
+
* content_format: 'markdown',
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export const TEXT_GENERATED = createAITracker<ContentGenerationProperties>(properties => ({
|
|
189
|
+
name: AI_EVENTS.TEXT_GENERATED,
|
|
190
|
+
category: 'content-generation',
|
|
191
|
+
properties,
|
|
192
|
+
requiredProperties: [],
|
|
193
|
+
}));
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Track summary generation
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* ai.SUMMARY_GENERATED({
|
|
201
|
+
* conversation_id: 'conv_123',
|
|
202
|
+
* model_id: 'gpt-4',
|
|
203
|
+
* source_type: 'document',
|
|
204
|
+
* source_length: 5000,
|
|
205
|
+
* summary_length: 300,
|
|
206
|
+
* summary_type: 'bullet-points',
|
|
207
|
+
* compression_ratio: 16.7,
|
|
208
|
+
* });
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export const SUMMARY_GENERATED = createAITracker<SummaryProperties>(properties => ({
|
|
212
|
+
name: AI_EVENTS.SUMMARY_GENERATED,
|
|
213
|
+
category: 'content-generation',
|
|
214
|
+
properties,
|
|
215
|
+
requiredProperties: ['input_length', 'output_length', 'summary_type'],
|
|
216
|
+
}));
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Track text translation
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* ai.TRANSLATION_GENERATED({
|
|
224
|
+
* conversation_id: 'conv_123',
|
|
225
|
+
* model_id: 'claude-3-5-sonnet',
|
|
226
|
+
* content_type: 'translation',
|
|
227
|
+
* content_length: 450,
|
|
228
|
+
* source_language: 'english',
|
|
229
|
+
* target_language: 'spanish',
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export const TRANSLATION_GENERATED = createAITracker<ContentGenerationProperties>(properties => ({
|
|
234
|
+
name: AI_EVENTS.TRANSLATION_GENERATED,
|
|
235
|
+
category: 'content-generation',
|
|
236
|
+
properties,
|
|
237
|
+
requiredProperties: [],
|
|
238
|
+
}));
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Track text completion
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* ai.COMPLETION_GENERATED({
|
|
246
|
+
* conversation_id: 'conv_123',
|
|
247
|
+
* model_id: 'gpt-4',
|
|
248
|
+
* content_type: 'completion',
|
|
249
|
+
* content_length: 200,
|
|
250
|
+
* completion_type: 'sentence',
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
export const COMPLETION_GENERATED = createAITracker<ContentGenerationProperties>(properties => ({
|
|
255
|
+
name: AI_EVENTS.COMPLETION_GENERATED,
|
|
256
|
+
category: 'content-generation',
|
|
257
|
+
properties,
|
|
258
|
+
requiredProperties: [],
|
|
259
|
+
}));
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Track content rewrite
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* ai.REWRITE_GENERATED({
|
|
267
|
+
* conversation_id: 'conv_123',
|
|
268
|
+
* model_id: 'claude-3-5-sonnet',
|
|
269
|
+
* content_type: 'rewrite',
|
|
270
|
+
* content_length: 350,
|
|
271
|
+
* original_length: 300,
|
|
272
|
+
* rewrite_style: 'formal',
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
export const REWRITE_GENERATED = createAITracker<ContentGenerationProperties>(properties => ({
|
|
277
|
+
name: AI_EVENTS.REWRITE_GENERATED,
|
|
278
|
+
category: 'content-generation',
|
|
279
|
+
properties,
|
|
280
|
+
requiredProperties: [],
|
|
281
|
+
}));
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Track email draft assistance
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* ai.EMAIL_DRAFTED({
|
|
289
|
+
* conversation_id: 'conv_123',
|
|
290
|
+
* model_id: 'gpt-4',
|
|
291
|
+
* content_type: 'email',
|
|
292
|
+
* content_length: 400,
|
|
293
|
+
* email_type: 'professional',
|
|
294
|
+
* has_subject: true,
|
|
295
|
+
* });
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export const EMAIL_DRAFTED = createAITracker<ContentGenerationProperties>(properties => ({
|
|
299
|
+
name: AI_EVENTS.EMAIL_DRAFTED,
|
|
300
|
+
category: 'content-generation',
|
|
301
|
+
properties,
|
|
302
|
+
requiredProperties: [],
|
|
303
|
+
}));
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Track document creation
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* ai.DOCUMENT_CREATED({
|
|
311
|
+
* conversation_id: 'conv_123',
|
|
312
|
+
* model_id: 'claude-3-5-sonnet',
|
|
313
|
+
* content_type: 'document',
|
|
314
|
+
* content_length: 2500,
|
|
315
|
+
* content_format: 'markdown',
|
|
316
|
+
* document_type: 'report',
|
|
317
|
+
* });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export const DOCUMENT_CREATED = createAITracker<ContentGenerationProperties>(properties => ({
|
|
321
|
+
name: AI_EVENTS.DOCUMENT_CREATED,
|
|
322
|
+
category: 'content-generation',
|
|
323
|
+
properties,
|
|
324
|
+
requiredProperties: [],
|
|
325
|
+
}));
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Track outline creation
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* ai.OUTLINE_CREATED({
|
|
333
|
+
* conversation_id: 'conv_123',
|
|
334
|
+
* model_id: 'gpt-4',
|
|
335
|
+
* content_type: 'outline',
|
|
336
|
+
* content_length: 600,
|
|
337
|
+
* section_count: 8,
|
|
338
|
+
* outline_depth: 3,
|
|
339
|
+
* });
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
export const OUTLINE_CREATED = createAITracker<ContentGenerationProperties>(properties => ({
|
|
343
|
+
name: AI_EVENTS.OUTLINE_CREATED,
|
|
344
|
+
category: 'content-generation',
|
|
345
|
+
properties,
|
|
346
|
+
requiredProperties: [],
|
|
347
|
+
}));
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Conversation & Messaging Events
|
|
3
|
+
* Conversation & Messaging Events
|
|
4
|
+
*
|
|
5
|
+
* Core conversation lifecycle and message management for ChatGPT-style products.
|
|
6
|
+
* Includes conversation start/end, messaging, regeneration, branching, and streaming.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createAITracker } from '../track-ai';
|
|
10
|
+
import {
|
|
11
|
+
AI_EVENTS,
|
|
12
|
+
type BranchProperties,
|
|
13
|
+
type ConversationProperties,
|
|
14
|
+
type MessageProperties,
|
|
15
|
+
type RegenerationProperties,
|
|
16
|
+
type StopGenerationProperties,
|
|
17
|
+
type StreamingSDKProperties,
|
|
18
|
+
} from '../types';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Track conversation start
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* ai.CONVERSATION_STARTED({
|
|
26
|
+
* conversation_id: 'conv_123',
|
|
27
|
+
* model_id: 'claude-3-5-sonnet',
|
|
28
|
+
* conversation_type: 'chat',
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const CONVERSATION_STARTED = createAITracker<ConversationProperties>(properties => ({
|
|
33
|
+
name: AI_EVENTS.CONVERSATION_STARTED,
|
|
34
|
+
category: 'conversation',
|
|
35
|
+
properties,
|
|
36
|
+
requiredProperties: [],
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Track conversation resume
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* ai.CONVERSATION_RESUMED({
|
|
45
|
+
* conversation_id: 'conv_123',
|
|
46
|
+
* model_id: 'gpt-4',
|
|
47
|
+
* last_active_timestamp: '2024-01-15T10:30:00Z',
|
|
48
|
+
* message_count: 15,
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const CONVERSATION_RESUMED = createAITracker<ConversationProperties>(properties => ({
|
|
53
|
+
name: AI_EVENTS.CONVERSATION_RESUMED,
|
|
54
|
+
category: 'conversation',
|
|
55
|
+
properties,
|
|
56
|
+
requiredProperties: [],
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Track conversation end
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* ai.CONVERSATION_ENDED({
|
|
65
|
+
* conversation_id: 'conv_123',
|
|
66
|
+
* model_id: 'claude-3-5-sonnet',
|
|
67
|
+
* end_reason: 'user-ended',
|
|
68
|
+
* duration_ms: 180000,
|
|
69
|
+
* message_count: 25,
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const CONVERSATION_ENDED = createAITracker<ConversationProperties>(properties => ({
|
|
74
|
+
name: AI_EVENTS.CONVERSATION_ENDED,
|
|
75
|
+
category: 'conversation',
|
|
76
|
+
properties,
|
|
77
|
+
requiredProperties: [],
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Track user message sent
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* ai.MESSAGE_SENT({
|
|
86
|
+
* conversation_id: 'conv_123',
|
|
87
|
+
* message_id: 'msg_456',
|
|
88
|
+
* model_id: 'gpt-4',
|
|
89
|
+
* message_role: 'user',
|
|
90
|
+
* message_length: 50,
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export const MESSAGE_SENT = createAITracker<MessageProperties>(properties => ({
|
|
95
|
+
name: AI_EVENTS.MESSAGE_SENT,
|
|
96
|
+
category: 'conversation',
|
|
97
|
+
properties,
|
|
98
|
+
requiredProperties: ['message_role'],
|
|
99
|
+
}));
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Track AI message received
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* ai.MESSAGE_RECEIVED({
|
|
107
|
+
* conversation_id: 'conv_123',
|
|
108
|
+
* message_id: 'msg_457',
|
|
109
|
+
* model_id: 'claude-3-5-sonnet',
|
|
110
|
+
* message_role: 'assistant',
|
|
111
|
+
* message_length: 250,
|
|
112
|
+
* response_time_ms: 850,
|
|
113
|
+
* finish_reason: 'stop',
|
|
114
|
+
* input_tokens: 450,
|
|
115
|
+
* output_tokens: 320,
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export const MESSAGE_RECEIVED = createAITracker<MessageProperties>(properties => ({
|
|
120
|
+
name: AI_EVENTS.MESSAGE_RECEIVED,
|
|
121
|
+
category: 'conversation',
|
|
122
|
+
properties,
|
|
123
|
+
requiredProperties: ['message_role'],
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Track message regeneration
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* ai.MESSAGE_REGENERATED({
|
|
132
|
+
* conversation_id: 'conv_123',
|
|
133
|
+
* model_id: 'gpt-4',
|
|
134
|
+
* original_message_id: 'msg_457',
|
|
135
|
+
* attempt_number: 2,
|
|
136
|
+
* reason: 'user-requested',
|
|
137
|
+
* temperature_adjusted: true,
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export const MESSAGE_REGENERATED = createAITracker<RegenerationProperties>(properties => ({
|
|
142
|
+
name: AI_EVENTS.MESSAGE_REGENERATED,
|
|
143
|
+
category: 'conversation',
|
|
144
|
+
properties,
|
|
145
|
+
requiredProperties: ['original_message_id'],
|
|
146
|
+
}));
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Track message edit
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* ai.MESSAGE_EDITED({
|
|
154
|
+
* conversation_id: 'conv_123',
|
|
155
|
+
* message_id: 'msg_456',
|
|
156
|
+
* model_id: 'claude-3-5-sonnet',
|
|
157
|
+
* edit_type: 'user-edit',
|
|
158
|
+
* original_length: 50,
|
|
159
|
+
* new_length: 75,
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export const MESSAGE_EDITED = createAITracker<MessageProperties>(properties => ({
|
|
164
|
+
name: AI_EVENTS.MESSAGE_EDITED,
|
|
165
|
+
category: 'conversation',
|
|
166
|
+
properties,
|
|
167
|
+
requiredProperties: ['message_role'],
|
|
168
|
+
}));
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Track message deletion
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* ai.MESSAGE_DELETED({
|
|
176
|
+
* conversation_id: 'conv_123',
|
|
177
|
+
* message_id: 'msg_458',
|
|
178
|
+
* model_id: 'gpt-4',
|
|
179
|
+
* message_role: 'assistant',
|
|
180
|
+
* deleted_by: 'user',
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export const MESSAGE_DELETED = createAITracker<MessageProperties>(properties => ({
|
|
185
|
+
name: AI_EVENTS.MESSAGE_DELETED,
|
|
186
|
+
category: 'conversation',
|
|
187
|
+
properties,
|
|
188
|
+
requiredProperties: ['message_role'],
|
|
189
|
+
}));
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Track conversation branch creation
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* ai.BRANCH_CREATED({
|
|
197
|
+
* conversation_id: 'conv_123',
|
|
198
|
+
* model_id: 'gpt-4',
|
|
199
|
+
* branch_point_message_id: 'msg_457',
|
|
200
|
+
* original_conversation_id: 'conv_123',
|
|
201
|
+
* new_conversation_id: 'conv_124',
|
|
202
|
+
* reason: 'explore-alternative',
|
|
203
|
+
* });
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
export const BRANCH_CREATED = createAITracker<BranchProperties>(properties => ({
|
|
207
|
+
name: AI_EVENTS.BRANCH_CREATED,
|
|
208
|
+
category: 'conversation',
|
|
209
|
+
properties,
|
|
210
|
+
requiredProperties: [
|
|
211
|
+
'branch_point_message_id',
|
|
212
|
+
'new_conversation_id',
|
|
213
|
+
'original_conversation_id',
|
|
214
|
+
],
|
|
215
|
+
}));
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Track conversation branch merge
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* ai.BRANCH_MERGED({
|
|
223
|
+
* conversation_id: 'conv_123',
|
|
224
|
+
* model_id: 'claude-3-5-sonnet',
|
|
225
|
+
* branch_point_message_id: 'msg_457',
|
|
226
|
+
* original_conversation_id: 'conv_123',
|
|
227
|
+
* new_conversation_id: 'conv_124',
|
|
228
|
+
* merge_strategy: 'keep-both',
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export const BRANCH_MERGED = createAITracker<BranchProperties>(properties => ({
|
|
233
|
+
name: AI_EVENTS.BRANCH_MERGED,
|
|
234
|
+
category: 'conversation',
|
|
235
|
+
properties,
|
|
236
|
+
requiredProperties: [
|
|
237
|
+
'branch_point_message_id',
|
|
238
|
+
'new_conversation_id',
|
|
239
|
+
'original_conversation_id',
|
|
240
|
+
],
|
|
241
|
+
}));
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Track stop generation (user interrupts response)
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* ai.STOP_GENERATION({
|
|
249
|
+
* conversation_id: 'conv_123',
|
|
250
|
+
* message_id: 'msg_458',
|
|
251
|
+
* model_id: 'gpt-4',
|
|
252
|
+
* partial_length: 120,
|
|
253
|
+
* stop_reason: 'user-interrupted',
|
|
254
|
+
* tokens_used_at_stop: 150,
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
export const STOP_GENERATION = createAITracker<StopGenerationProperties>(properties => ({
|
|
259
|
+
name: AI_EVENTS.STOP_GENERATION,
|
|
260
|
+
category: 'conversation',
|
|
261
|
+
properties,
|
|
262
|
+
requiredProperties: [],
|
|
263
|
+
}));
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Track streaming start
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* ai.STREAMING_STARTED({
|
|
271
|
+
* conversation_id: 'conv_123',
|
|
272
|
+
* message_id: 'msg_459',
|
|
273
|
+
* model_id: 'claude-3-5-sonnet',
|
|
274
|
+
* stream_type: 'text',
|
|
275
|
+
* });
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
export const STREAMING_STARTED = createAITracker<StreamingSDKProperties>(properties => ({
|
|
279
|
+
name: AI_EVENTS.STREAMING_STARTED,
|
|
280
|
+
category: 'conversation',
|
|
281
|
+
properties,
|
|
282
|
+
requiredProperties: [],
|
|
283
|
+
}));
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Track streaming chunk received (sample, not every chunk)
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* // Sample every 10th chunk
|
|
291
|
+
* if (chunkCount % 10 === 0) {
|
|
292
|
+
* ai.STREAMING_CHUNK_RECEIVED({
|
|
293
|
+
* conversation_id: 'conv_123',
|
|
294
|
+
* message_id: 'msg_459',
|
|
295
|
+
* model_id: 'gpt-4',
|
|
296
|
+
* stream_type: 'text',
|
|
297
|
+
* chunk_index: chunkCount,
|
|
298
|
+
* chunk_size_bytes: 256,
|
|
299
|
+
* });
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
export const STREAMING_CHUNK_RECEIVED = createAITracker<StreamingSDKProperties>(properties => ({
|
|
304
|
+
name: AI_EVENTS.STREAMING_CHUNK_RECEIVED,
|
|
305
|
+
category: 'conversation',
|
|
306
|
+
properties,
|
|
307
|
+
requiredProperties: [],
|
|
308
|
+
}));
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Track streaming completion
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* ai.STREAMING_COMPLETED({
|
|
316
|
+
* conversation_id: 'conv_123',
|
|
317
|
+
* message_id: 'msg_459',
|
|
318
|
+
* model_id: 'claude-3-5-sonnet',
|
|
319
|
+
* stream_type: 'text',
|
|
320
|
+
* chunk_count: 45,
|
|
321
|
+
* total_bytes: 11520,
|
|
322
|
+
* stream_duration_ms: 3200,
|
|
323
|
+
* chunks_per_second: 14.06,
|
|
324
|
+
* });
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
export const STREAMING_COMPLETED = createAITracker<StreamingSDKProperties>(properties => ({
|
|
328
|
+
name: AI_EVENTS.STREAMING_COMPLETED,
|
|
329
|
+
category: 'conversation',
|
|
330
|
+
properties,
|
|
331
|
+
requiredProperties: [],
|
|
332
|
+
}));
|