@keak/sdk 1.0.4 → 1.0.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/index.cjs.js +100 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -1
- package/dist/toolbar/KeakToolbar.d.ts.map +1 -1
- package/dist/toolbar/utils/keakCodeClient.d.ts +28 -0
- package/dist/toolbar/utils/keakCodeClient.d.ts.map +1 -1
- package/dist/toolbar.js +100 -0
- package/dist/toolbar.js.map +1 -1
- package/package.json +1 -1
- package/src/plugins/next.cjs +184 -76
- package/src/plugins/webpack-loader-babel/index.js +199 -0
- package/dist/KeakToolbarShadow.d.ts +0 -21
- package/dist/KeakToolbarShadow.d.ts.map +0 -1
- package/dist/services/telemetry/index.d.ts +0 -20
- package/dist/services/telemetry/index.d.ts.map +0 -1
- package/dist/services/telemetry/telemetryService.d.ts +0 -66
- package/dist/services/telemetry/telemetryService.d.ts.map +0 -1
- package/dist/services/telemetry/types.d.ts +0 -64
- package/dist/services/telemetry/types.d.ts.map +0 -1
package/src/plugins/next.cjs
CHANGED
|
@@ -28,9 +28,11 @@ function withKeak(nextConfig = {}) {
|
|
|
28
28
|
console.log('[Keak] webpack() called with options:', { dev: options.dev, isServer: options.isServer });
|
|
29
29
|
const { dev, isServer } = options;
|
|
30
30
|
|
|
31
|
-
// Only inject in development mode and
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// Only inject in development mode (both client and server)
|
|
32
|
+
// Server components also need attributes for source mapping
|
|
33
|
+
if (dev) {
|
|
34
|
+
console.log('[Keak] Configuring Keak webpack loader for source injection...');
|
|
35
|
+
console.log('[Keak] DEBUG: dev=', dev, 'isServer=', isServer, 'processing:', isServer ? 'server build' : 'client build');
|
|
34
36
|
|
|
35
37
|
// Helper function to resolve modules from the project's node_modules
|
|
36
38
|
const resolveFromProject = (moduleName) => {
|
|
@@ -46,89 +48,195 @@ function withKeak(nextConfig = {}) {
|
|
|
46
48
|
}
|
|
47
49
|
};
|
|
48
50
|
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
51
|
+
// Ensure module.rules exists
|
|
52
|
+
config.module = config.module || {};
|
|
53
|
+
config.module.rules = config.module.rules || [];
|
|
54
|
+
|
|
55
|
+
// Add Keak loader to run pre-SWC for client code
|
|
56
|
+
// The loader resolves from .keak/webpack-loader-babel which is copied by keak-code during project setup.
|
|
57
|
+
const fs = require('fs');
|
|
58
|
+
const pathModule = require('path');
|
|
59
|
+
|
|
60
|
+
console.log('[Keak] About to resolve loader path...');
|
|
61
|
+
console.log('[Keak] Current working directory:', process.cwd());
|
|
62
|
+
|
|
63
|
+
// Try to find the loader in the project's .keak directory (copied by keak-code setup)
|
|
64
|
+
// Using the Babel-based loader that runs BEFORE SWC (pre-compilation)
|
|
65
|
+
const projectKeakLoader = pathModule.resolve(process.cwd(), '.keak/webpack-loader-babel/index.js');
|
|
66
|
+
|
|
67
|
+
let keakLoaderPath;
|
|
68
|
+
let loaderSource = 'unknown';
|
|
69
|
+
|
|
70
|
+
// Check if loader exists in project .keak directory
|
|
71
|
+
try {
|
|
72
|
+
if (fs.existsSync(projectKeakLoader)) {
|
|
73
|
+
console.log('[Keak] Found loader in project .keak directory');
|
|
74
|
+
keakLoaderPath = projectKeakLoader;
|
|
75
|
+
loaderSource = 'project';
|
|
76
|
+
} else {
|
|
77
|
+
// Fallback to project loader path even if it doesn't exist yet
|
|
78
|
+
console.warn('[Keak] Loader not found, using fallback path:', projectKeakLoader);
|
|
79
|
+
keakLoaderPath = projectKeakLoader;
|
|
80
|
+
loaderSource = 'fallback';
|
|
77
81
|
}
|
|
82
|
+
} catch (pathError) {
|
|
83
|
+
console.error('[Keak] Error resolving loader path:', pathError.message);
|
|
84
|
+
keakLoaderPath = projectKeakLoader;
|
|
85
|
+
loaderSource = 'error';
|
|
86
|
+
}
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
console.log('[Keak] ✅ Loader path resolved:', keakLoaderPath, '(source:', loaderSource, ')');
|
|
89
|
+
console.log('[Keak] About to inspect webpack rules...');
|
|
90
|
+
console.log('[Keak] DEBUG: config exists?', !!config);
|
|
91
|
+
console.log('[Keak] DEBUG: config.module exists?', !!config.module);
|
|
92
|
+
console.log('[Keak] DEBUG: config.module.rules exists?', !!(config.module && config.module.rules));
|
|
93
|
+
console.log('[Keak] DEBUG: config.module.rules is array?', Array.isArray(config.module && config.module.rules));
|
|
94
|
+
|
|
95
|
+
// Wrap everything in try-catch to catch any errors
|
|
96
|
+
try {
|
|
97
|
+
console.log('[Keak] DEBUG: Entering try block');
|
|
98
|
+
console.log('[Keak] DEBUG: config.module exists?', !!config.module);
|
|
99
|
+
console.log('[Keak] DEBUG: config.module.rules exists?', !!(config.module && config.module.rules));
|
|
100
|
+
console.log('[Keak] Total webpack rules:', config.module && config.module.rules ? config.module.rules.length : 'undefined');
|
|
101
|
+
|
|
102
|
+
if (!config.module || !config.module.rules) {
|
|
103
|
+
console.error('[Keak] ❌ ERROR: config.module.rules is undefined!');
|
|
104
|
+
return config;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Log first few rules to understand structure
|
|
108
|
+
try {
|
|
109
|
+
console.log('[Keak] First few rules structure:');
|
|
110
|
+
config.module.rules.slice(0, 5).forEach((r, i) => {
|
|
111
|
+
console.log(`[Keak] Rule ${i}:`, {
|
|
112
|
+
hasOneOf: Array.isArray(r.oneOf),
|
|
113
|
+
oneOfLength: Array.isArray(r.oneOf) ? r.oneOf.length : 'N/A',
|
|
114
|
+
test: r.test ? r.test.toString().substring(0, 50) : 'no test',
|
|
115
|
+
hasUse: !!r.use,
|
|
116
|
+
useType: r.use ? (Array.isArray(r.use) ? 'array' : typeof r.use) : 'none'
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.log('[Keak] Error logging rules:', e.message);
|
|
100
121
|
}
|
|
101
|
-
});
|
|
102
122
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
// Based on Next.js webpack structure: Find the oneOf array and add our loader
|
|
124
|
+
// Next.js uses oneOf arrays to process files - we need to add our loader there
|
|
125
|
+
let loaderAdded = false;
|
|
126
|
+
|
|
127
|
+
console.log('[Keak] Attempting Strategy 1: Finding oneOf rule...');
|
|
128
|
+
// Strategy 1: Find the oneOf rule (recommended approach from web search)
|
|
129
|
+
const oneOfRule = config.module.rules.find((rule) => Array.isArray(rule.oneOf));
|
|
130
|
+
console.log('[Keak] Strategy 1 result:', oneOfRule ? 'Found oneOf rule' : 'No oneOf rule found');
|
|
131
|
+
|
|
132
|
+
if (oneOfRule && oneOfRule.oneOf) {
|
|
133
|
+
console.log(`[Keak] ✅ Found oneOf array with ${oneOfRule.oneOf.length} entries`);
|
|
134
|
+
|
|
135
|
+
// Add our loader to the BEGINNING of oneOf array so it runs BEFORE SWC
|
|
136
|
+
// This transforms raw JSX to inject attributes before compilation
|
|
137
|
+
const preRule = {
|
|
138
|
+
test: /\.[jt]sx?$/,
|
|
139
|
+
exclude: [
|
|
140
|
+
/node_modules/,
|
|
141
|
+
/\.next\//,
|
|
142
|
+
/webpack/,
|
|
143
|
+
/next\/dist/
|
|
144
|
+
// NOTE: Removed /\.server\.[jt]sx?$/ exclusion to process server components
|
|
145
|
+
],
|
|
146
|
+
enforce: 'pre', // Run BEFORE SWC (pre-compilation)
|
|
147
|
+
use: [
|
|
148
|
+
{
|
|
149
|
+
loader: keakLoaderPath,
|
|
150
|
+
options: {
|
|
151
|
+
projectRoot: process.cwd(),
|
|
152
|
+
includeElementIndex: true,
|
|
153
|
+
devWarnings: dev,
|
|
154
|
+
skipPatterns: [
|
|
155
|
+
// NOTE: Removed /(\.server\.[jt]sx?$)/ to process server components
|
|
156
|
+
/webpack/,
|
|
157
|
+
/\.next\//,
|
|
158
|
+
/next\/dist/
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Add to the BEGINNING of oneOf array (runs before SWC processes files)
|
|
166
|
+
oneOfRule.oneOf.unshift(preRule);
|
|
167
|
+
|
|
168
|
+
console.log(`[Keak] ✅ Added pre-compilation loader to oneOf array (now ${oneOfRule.oneOf.length} entries, runs before SWC)`);
|
|
169
|
+
loaderAdded = true;
|
|
170
|
+
} else {
|
|
171
|
+
console.log('[Keak] No oneOf array found, trying alternative approaches...');
|
|
172
|
+
|
|
173
|
+
// Strategy 2: Look for rules with oneOf property (nested)
|
|
174
|
+
for (let i = 0; i < config.module.rules.length; i++) {
|
|
175
|
+
const rule = config.module.rules[i];
|
|
176
|
+
if (rule.oneOf && Array.isArray(rule.oneOf)) {
|
|
177
|
+
console.log(`[Keak] Found oneOf in rule ${i} with ${rule.oneOf.length} entries`);
|
|
178
|
+
|
|
179
|
+
// Add pre-compilation loader to the BEGINNING of this oneOf array
|
|
180
|
+
rule.oneOf.unshift({
|
|
181
|
+
test: /\.[jt]sx?$/,
|
|
182
|
+
exclude: [/node_modules/, /\.next\//, /webpack/, /next\/dist/],
|
|
183
|
+
enforce: 'pre', // Run BEFORE SWC
|
|
184
|
+
use: [
|
|
122
185
|
{
|
|
123
|
-
|
|
186
|
+
loader: keakLoaderPath,
|
|
187
|
+
options: {
|
|
188
|
+
projectRoot: process.cwd(),
|
|
189
|
+
includeElementIndex: true,
|
|
190
|
+
devWarnings: dev,
|
|
191
|
+
skipPatterns: [] // Process all files including server components
|
|
192
|
+
}
|
|
124
193
|
}
|
|
125
194
|
]
|
|
126
|
-
|
|
127
|
-
|
|
195
|
+
});
|
|
196
|
+
console.log(`[Keak] ✅ Added pre-compilation loader to oneOf array (now ${rule.oneOf.length} entries)`);
|
|
197
|
+
loaderAdded = true;
|
|
198
|
+
break;
|
|
128
199
|
}
|
|
129
200
|
}
|
|
130
|
-
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Strategy 3: Fallback - Add as new rule with enforce: 'pre' at top level
|
|
204
|
+
// This is less ideal but should still work
|
|
205
|
+
if (!loaderAdded) {
|
|
206
|
+
console.log('[Keak] Fallback: Adding pre-compilation loader rule to top-level rules');
|
|
207
|
+
config.module.rules.unshift({
|
|
208
|
+
test: /\.[jt]sx?$/,
|
|
209
|
+
exclude: [/node_modules/, /\.next\//, /webpack/, /next\/dist/],
|
|
210
|
+
enforce: 'pre', // Run BEFORE SWC
|
|
211
|
+
use: [
|
|
212
|
+
{
|
|
213
|
+
loader: keakLoaderPath,
|
|
214
|
+
options: {
|
|
215
|
+
projectRoot: process.cwd(),
|
|
216
|
+
includeElementIndex: true,
|
|
217
|
+
devWarnings: dev,
|
|
218
|
+
skipPatterns: [] // Process all files including server components
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
]
|
|
222
|
+
});
|
|
223
|
+
console.log('[Keak] ✅ Added pre-compilation loader rule with enforce:pre (fallback)');
|
|
224
|
+
loaderAdded = true;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!loaderAdded) {
|
|
228
|
+
console.error('[Keak] ❌ ERROR: Failed to add loader using any strategy!');
|
|
229
|
+
} else {
|
|
230
|
+
console.log('[Keak] ✅ Loader successfully added to webpack config');
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
console.error('[Keak] ❌ ERROR in loader injection block:', error);
|
|
234
|
+
console.error('[Keak] Error message:', error.message);
|
|
235
|
+
console.error('[Keak] Error stack:', error.stack);
|
|
236
|
+
// Don't throw - let webpack continue even if loader injection fails
|
|
131
237
|
}
|
|
238
|
+
} else {
|
|
239
|
+
console.log('[Keak] Skipping loader injection - dev:', dev, 'isServer:', isServer);
|
|
132
240
|
}
|
|
133
241
|
|
|
134
242
|
// Call the original webpack config function if it exists
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webpack loader that uses Babel to inject Keak source attributes into JSX
|
|
3
|
+
* This runs BEFORE SWC compilation to add data-keak-src, data-keak-component, and data-keak-idx attributes
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const babelParser = require('@babel/parser');
|
|
8
|
+
const babelTraverse = require('@babel/traverse').default;
|
|
9
|
+
const babelGenerator = require('@babel/generator').default;
|
|
10
|
+
const t = require('@babel/types');
|
|
11
|
+
|
|
12
|
+
let elementIndexMap = new Map(); // Track element index per file
|
|
13
|
+
|
|
14
|
+
module.exports = function keakLoaderBabel(source) {
|
|
15
|
+
// Make loader cacheable for better performance
|
|
16
|
+
this.cacheable(true);
|
|
17
|
+
|
|
18
|
+
const resourcePath = this.resourcePath;
|
|
19
|
+
const options = this.getOptions() || {};
|
|
20
|
+
const { projectRoot = process.cwd(), includeElementIndex = true, devWarnings = false } = options;
|
|
21
|
+
|
|
22
|
+
// Skip if not a JSX/TSX file
|
|
23
|
+
if (!/\.(jsx|tsx|js|ts)$/.test(resourcePath)) {
|
|
24
|
+
return source;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Skip files based on skip patterns
|
|
28
|
+
const skipPatterns = options.skipPatterns || [];
|
|
29
|
+
if (skipPatterns.some(pattern => {
|
|
30
|
+
const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
|
|
31
|
+
return regex.test(resourcePath);
|
|
32
|
+
})) {
|
|
33
|
+
return source;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
console.log(`[keak-loader-pre] Processing ${path.relative(projectRoot || process.cwd(), resourcePath)} with Babel AST`);
|
|
38
|
+
|
|
39
|
+
// Reset element index for this file
|
|
40
|
+
if (includeElementIndex) {
|
|
41
|
+
elementIndexMap.set(resourcePath, 0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Parse the source code
|
|
45
|
+
const ast = babelParser.parse(source, {
|
|
46
|
+
sourceType: 'module',
|
|
47
|
+
plugins: [
|
|
48
|
+
'jsx',
|
|
49
|
+
'typescript',
|
|
50
|
+
'decorators-legacy',
|
|
51
|
+
'classProperties',
|
|
52
|
+
'objectRestSpread',
|
|
53
|
+
'functionBind',
|
|
54
|
+
'exportDefaultFrom',
|
|
55
|
+
'exportNamespaceFrom',
|
|
56
|
+
'dynamicImport',
|
|
57
|
+
'nullishCoalescingOperator',
|
|
58
|
+
'optionalChaining',
|
|
59
|
+
'topLevelAwait'
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
let elementCount = 0;
|
|
64
|
+
let skipFile = false;
|
|
65
|
+
|
|
66
|
+
// First pass: Check for next/font imports (Babel/SWC conflict)
|
|
67
|
+
babelTraverse(ast, {
|
|
68
|
+
ImportDeclaration(importPath) {
|
|
69
|
+
const source = importPath.node.source.value;
|
|
70
|
+
if (source.includes('next/font') || source.includes('@next/font')) {
|
|
71
|
+
skipFile = true;
|
|
72
|
+
importPath.stop();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (skipFile) {
|
|
78
|
+
if (devWarnings) {
|
|
79
|
+
console.log(`[keak-loader-pre] ⚠️ Skipping ${path.relative(projectRoot || process.cwd(), resourcePath)} (contains next/font)`);
|
|
80
|
+
}
|
|
81
|
+
return source;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Second pass: Transform JSX elements
|
|
85
|
+
babelTraverse(ast, {
|
|
86
|
+
JSXOpeningElement(nodePath) {
|
|
87
|
+
const node = nodePath.node;
|
|
88
|
+
|
|
89
|
+
// Skip if element already has keak source attribute
|
|
90
|
+
const hasKeakSrc = node.attributes.some(attr =>
|
|
91
|
+
t.isJSXAttribute(attr) &&
|
|
92
|
+
t.isJSXIdentifier(attr.name) &&
|
|
93
|
+
attr.name.name === 'data-keak-src'
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
if (hasKeakSrc) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Get source location
|
|
101
|
+
const loc = node.loc;
|
|
102
|
+
if (!loc) return;
|
|
103
|
+
|
|
104
|
+
// Create relative path from project root
|
|
105
|
+
const relativePath = path.relative(projectRoot || process.cwd(), resourcePath).replace(/\\/g, '/');
|
|
106
|
+
|
|
107
|
+
// Create source location string: "file:line:column"
|
|
108
|
+
const sourceLocation = `${relativePath}:${loc.start.line}:${loc.start.column}`;
|
|
109
|
+
|
|
110
|
+
// Get element name
|
|
111
|
+
let tagName = '';
|
|
112
|
+
let componentName = '';
|
|
113
|
+
|
|
114
|
+
if (t.isJSXIdentifier(node.name)) {
|
|
115
|
+
tagName = node.name.name;
|
|
116
|
+
// Try to find component name from parent scope
|
|
117
|
+
const parentFunction = nodePath.getFunctionParent();
|
|
118
|
+
if (parentFunction && parentFunction.isFunctionDeclaration()) {
|
|
119
|
+
componentName = parentFunction.node.id?.name || '';
|
|
120
|
+
} else if (parentFunction && parentFunction.isArrowFunctionExpression()) {
|
|
121
|
+
const parentVar = parentFunction.getFunctionParent();
|
|
122
|
+
if (parentVar && parentVar.isVariableDeclarator() && t.isIdentifier(parentVar.node.id)) {
|
|
123
|
+
componentName = parentVar.node.id.name;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} else if (t.isJSXMemberExpression(node.name)) {
|
|
127
|
+
tagName = node.name.property.name;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Only instrument DOM elements (lowercase) or all elements if configured
|
|
131
|
+
const isDOMElement = /^[a-z]/.test(tagName);
|
|
132
|
+
|
|
133
|
+
if (!isDOMElement && !options.instrumentComponents) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Get element index if enabled
|
|
138
|
+
let elementIdx = null;
|
|
139
|
+
if (includeElementIndex) {
|
|
140
|
+
const currentIndex = elementIndexMap.get(resourcePath) || 0;
|
|
141
|
+
elementIdx = currentIndex;
|
|
142
|
+
elementIndexMap.set(resourcePath, currentIndex + 1);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Create attributes to inject
|
|
146
|
+
const attributesToAdd = [
|
|
147
|
+
t.jsxAttribute(
|
|
148
|
+
t.jsxIdentifier('data-keak-src'),
|
|
149
|
+
t.stringLiteral(sourceLocation)
|
|
150
|
+
)
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
// Add component name if available
|
|
154
|
+
if (componentName) {
|
|
155
|
+
attributesToAdd.push(
|
|
156
|
+
t.jsxAttribute(
|
|
157
|
+
t.jsxIdentifier('data-keak-component'),
|
|
158
|
+
t.stringLiteral(componentName)
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Add element index if enabled
|
|
164
|
+
if (elementIdx !== null) {
|
|
165
|
+
attributesToAdd.push(
|
|
166
|
+
t.jsxAttribute(
|
|
167
|
+
t.jsxIdentifier('data-keak-idx'),
|
|
168
|
+
t.stringLiteral(String(elementIdx))
|
|
169
|
+
)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Add attributes to the node
|
|
174
|
+
node.attributes.push(...attributesToAdd);
|
|
175
|
+
elementCount++;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Generate the transformed code
|
|
180
|
+
const output = babelGenerator(ast, {
|
|
181
|
+
retainLines: false,
|
|
182
|
+
compact: false,
|
|
183
|
+
sourceMaps: false
|
|
184
|
+
}, source);
|
|
185
|
+
|
|
186
|
+
if (elementCount > 0) {
|
|
187
|
+
console.log(`[keak-loader-pre] ✓ Injected attributes into ${elementCount} elements in ${path.relative(projectRoot || process.cwd(), resourcePath)}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return output.code;
|
|
191
|
+
} catch (error) {
|
|
192
|
+
// If transformation fails, return original source
|
|
193
|
+
console.error(`[keak-loader-pre] ❌ Error processing ${resourcePath}:`, error.message);
|
|
194
|
+
if (devWarnings) {
|
|
195
|
+
console.error('[keak-loader-pre] Stack:', error.stack);
|
|
196
|
+
}
|
|
197
|
+
return source;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export interface KeakToolbarShadowProps {
|
|
3
|
-
/** Initial position of the toolbar */
|
|
4
|
-
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
5
|
-
/** Theme variant */
|
|
6
|
-
theme?: "light" | "dark" | "auto" | "high-contrast" | "cluely";
|
|
7
|
-
/** API key for Keak services */
|
|
8
|
-
apiKey?: string;
|
|
9
|
-
/** Custom z-index for the toolbar */
|
|
10
|
-
zIndex?: number;
|
|
11
|
-
/** Callback when toolbar is mounted */
|
|
12
|
-
onMount?: (shadowRoot: ShadowRoot) => void;
|
|
13
|
-
/** Callback when toolbar is unmounted */
|
|
14
|
-
onUnmount?: () => void;
|
|
15
|
-
/** Custom CSS variables to override theme */
|
|
16
|
-
customTheme?: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
export declare function KeakToolbarShadow({ position, theme, apiKey, zIndex, // max practical z-index
|
|
19
|
-
onMount, onUnmount, customTheme }: KeakToolbarShadowProps): React.ReactPortal | null;
|
|
20
|
-
export { KeakToolbarShadow as KeakToolbar };
|
|
21
|
-
//# sourceMappingURL=KeakToolbarShadow.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeakToolbarShadow.d.ts","sourceRoot":"","sources":["../src/KeakToolbarShadow.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,MAAM,WAAW,sBAAsB;IACrC,sCAAsC;IACtC,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,CAAA;IACpE,oBAAoB;IACpB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,GAAG,QAAQ,CAAA;IAC9D,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uCAAuC;IACvC,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAA;IAC1C,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrC;AAED,wBAAgB,iBAAiB,CAAC,EAChC,QAAyB,EACzB,KAAc,EACd,MAAM,EACN,MAAmB,EAAE,wBAAwB;AAC7C,OAAO,EACP,SAAS,EACT,WAAW,EACZ,EAAE,sBAAsB,4BAmKxB;AAGD,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,CAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Telemetry Service
|
|
3
|
-
*
|
|
4
|
-
* Handles all telemetry tracking for the Keak SDK, including:
|
|
5
|
-
* - Session management
|
|
6
|
-
* - Generation tracking (AI requests)
|
|
7
|
-
* - Variant management (AI outputs)
|
|
8
|
-
* - User interactions (previews, accepts, rejects)
|
|
9
|
-
*/
|
|
10
|
-
import { TelemetryService } from "./telemetryService";
|
|
11
|
-
import { GenerationType, VariantOutcome } from "./types";
|
|
12
|
-
import type { InitialVariantData as _InitialVariantData } from "./types";
|
|
13
|
-
export declare const telemetry: TelemetryService & {
|
|
14
|
-
GenerationType: typeof GenerationType;
|
|
15
|
-
VariantOutcome: typeof VariantOutcome;
|
|
16
|
-
};
|
|
17
|
-
export declare namespace TelemetryTypes {
|
|
18
|
-
type InitialVariantData = _InitialVariantData;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/telemetry/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAKzE,eAAO,MAAM,SAAS;;;CAGpB,CAAC;AAMH,yBAAiB,cAAc,CAAC;IAC9B,KAAY,kBAAkB,GAAG,mBAAmB,CAAC;CACtD"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ChatStartEvent, TelemetryConfig, UserContext } from './types';
|
|
2
|
-
import { GenerationStartEvent, GenerationCompleteEvent, VariantUpdates } from './types';
|
|
3
|
-
export declare class TelemetryService {
|
|
4
|
-
private supabase;
|
|
5
|
-
private enabled;
|
|
6
|
-
private currentSessionId;
|
|
7
|
-
/**
|
|
8
|
-
* Initialize the telemetry service
|
|
9
|
-
*/
|
|
10
|
-
initialize(config: TelemetryConfig): void;
|
|
11
|
-
/**
|
|
12
|
-
* Check if telemetry is enabled and configured
|
|
13
|
-
*/
|
|
14
|
-
private isReady;
|
|
15
|
-
/**
|
|
16
|
-
* Handle errors gracefully
|
|
17
|
-
*/
|
|
18
|
-
private handleError;
|
|
19
|
-
/**
|
|
20
|
-
* Start a new session or return existing session ID
|
|
21
|
-
*/
|
|
22
|
-
startSession(userContext?: UserContext): Promise<string | null>;
|
|
23
|
-
/**
|
|
24
|
-
* Get the current session ID
|
|
25
|
-
*/
|
|
26
|
-
getCurrentSessionId(): string | null;
|
|
27
|
-
/**
|
|
28
|
-
* End the current session
|
|
29
|
-
*/
|
|
30
|
-
endSession(): void;
|
|
31
|
-
/**
|
|
32
|
-
* Start a new chat or select existing chat
|
|
33
|
-
*/
|
|
34
|
-
trackChatStart(event: ChatStartEvent): Promise<{
|
|
35
|
-
chatId: string | null;
|
|
36
|
-
}>;
|
|
37
|
-
/**
|
|
38
|
-
* Track the start of a generation (AI request)
|
|
39
|
-
* Creates chat if needed and generation record
|
|
40
|
-
*/
|
|
41
|
-
trackGenerationStart(event: GenerationStartEvent): Promise<{
|
|
42
|
-
generationId: string | null;
|
|
43
|
-
}>;
|
|
44
|
-
/**
|
|
45
|
-
* Track the completion of a generation
|
|
46
|
-
* Updates generation with metrics, inserts variants, and updates context with complexity
|
|
47
|
-
*/
|
|
48
|
-
trackGenerationComplete(event: GenerationCompleteEvent): Promise<{
|
|
49
|
-
variantId: string | null;
|
|
50
|
-
}>;
|
|
51
|
-
updateVariant(variantId: string, updates: VariantUpdates): Promise<void>;
|
|
52
|
-
trackVariantAccept(variantId: string): Promise<void>;
|
|
53
|
-
trackVariantRetry(variantId: string): Promise<void>;
|
|
54
|
-
trackVariantFollowup(variantId: string): Promise<void>;
|
|
55
|
-
trackVariantPreview(variantId: string, new_code: string): Promise<void>;
|
|
56
|
-
trackChatClear(chatId: string): Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Disable telemetry
|
|
59
|
-
*/
|
|
60
|
-
disable(): void;
|
|
61
|
-
/**
|
|
62
|
-
* Enable telemetry
|
|
63
|
-
*/
|
|
64
|
-
enable(): void;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=telemetryService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"telemetryService.d.ts","sourceRoot":"","sources":["../../../src/services/telemetry/telemetryService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAkB,MAAM,SAAS,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMxF,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,gBAAgB,CAAuB;IAE/C;;OAEG;IACH,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI;IAoBzC;;OAEG;IACH,OAAO,CAAC,OAAO;IAOf;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;OAEG;IACG,YAAY,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA2BrE;;OAEG;IACH,mBAAmB,IAAI,MAAM,GAAG,IAAI;IAIpC;;OAEG;IACH,UAAU,IAAI,IAAI;IAQlB;;MAEE;IACI,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAoC/E;;;OAGG;IACG,oBAAoB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC;QAC7D,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAC9B,CAAC;IAsBF;;;OAGG;IACG,uBAAuB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IA0C9F,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBxE,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BvE,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBnD;;OAEG;IACH,OAAO,IAAI,IAAI;IAIf;;OAEG;IACH,MAAM,IAAI,IAAI;CAKjB"}
|