chrometools-mcp 3.3.8 → 3.4.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.
@@ -0,0 +1,174 @@
1
+ /**
2
+ * utils/openapi/type-mapper.js
3
+ *
4
+ * Maps OpenAPI types to TypeScript and Python types.
5
+ */
6
+
7
+ /**
8
+ * Type mapper for OpenAPI → target language
9
+ */
10
+ export class TypeMapper {
11
+ /**
12
+ * Convert OpenAPI schema to TypeScript type string
13
+ * @param {Object} schema - OpenAPI schema object
14
+ * @param {string} [schemaName] - named schema reference
15
+ * @returns {string} - TypeScript type
16
+ */
17
+ static toTypeScript(schema, schemaName = null) {
18
+ if (!schema) return 'any';
19
+
20
+ // Named reference (already resolved but carried as name)
21
+ if (schemaName && !schema.type && !schema.oneOf && !schema.anyOf && !schema.allOf) {
22
+ return schemaName;
23
+ }
24
+
25
+ // Circular ref
26
+ if (schema.$circularRef) return schema.$circularRef;
27
+
28
+ // Nullable wrapper
29
+ const nullable = schema.nullable === true;
30
+ let type = this._toTypeScriptInner(schema);
31
+ if (nullable) type = `${type} | null`;
32
+ return type;
33
+ }
34
+
35
+ static _toTypeScriptInner(schema) {
36
+ // Enum
37
+ if (schema.enum && schema.type === 'string') {
38
+ // Inline enum - return union of literals
39
+ return schema.enum.map(v => `'${v}'`).join(' | ');
40
+ }
41
+
42
+ // oneOf / anyOf → union
43
+ if (schema.oneOf) {
44
+ return schema.oneOf.map(s => this.toTypeScript(s)).join(' | ');
45
+ }
46
+ if (schema.anyOf) {
47
+ return schema.anyOf.map(s => this.toTypeScript(s)).join(' | ');
48
+ }
49
+
50
+ // allOf → intersection
51
+ if (schema.allOf) {
52
+ return schema.allOf.map(s => this.toTypeScript(s)).join(' & ');
53
+ }
54
+
55
+ // Array
56
+ if (schema.type === 'array') {
57
+ const itemType = schema.items ? this.toTypeScript(schema.items) : 'any';
58
+ return `${itemType}[]`;
59
+ }
60
+
61
+ // Object with additionalProperties → Record
62
+ if (schema.type === 'object' && schema.additionalProperties && !schema.properties) {
63
+ const valueType = typeof schema.additionalProperties === 'object'
64
+ ? this.toTypeScript(schema.additionalProperties)
65
+ : 'any';
66
+ return `Record<string, ${valueType}>`;
67
+ }
68
+
69
+ // Primitive types
70
+ switch (schema.type) {
71
+ case 'string':
72
+ if (schema.format === 'binary') return 'Blob';
73
+ return 'string';
74
+ case 'integer':
75
+ case 'number':
76
+ return 'number';
77
+ case 'boolean':
78
+ return 'boolean';
79
+ case 'object':
80
+ return 'Record<string, unknown>';
81
+ default:
82
+ return 'any';
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Convert OpenAPI schema to Python type string
88
+ * @param {Object} schema - OpenAPI schema object
89
+ * @param {string} [schemaName] - named schema reference
90
+ * @returns {string} - Python type
91
+ */
92
+ static toPython(schema, schemaName = null) {
93
+ if (!schema) return 'Any';
94
+
95
+ if (schemaName && !schema.type && !schema.oneOf && !schema.anyOf && !schema.allOf) {
96
+ return schemaName;
97
+ }
98
+
99
+ if (schema.$circularRef) return `'${schema.$circularRef}'`;
100
+
101
+ const nullable = schema.nullable === true;
102
+ let type = this._toPythonInner(schema);
103
+ if (nullable) type = `Optional[${type}]`;
104
+ return type;
105
+ }
106
+
107
+ static _toPythonInner(schema) {
108
+ // Enum
109
+ if (schema.enum && schema.type === 'string') {
110
+ return 'str';
111
+ }
112
+
113
+ // oneOf / anyOf → Union
114
+ if (schema.oneOf) {
115
+ const types = schema.oneOf.map(s => this.toPython(s));
116
+ return `Union[${types.join(', ')}]`;
117
+ }
118
+ if (schema.anyOf) {
119
+ const types = schema.anyOf.map(s => this.toPython(s));
120
+ return `Union[${types.join(', ')}]`;
121
+ }
122
+
123
+ // allOf → just merge (first named type or Any)
124
+ if (schema.allOf) {
125
+ const types = schema.allOf.map(s => this.toPython(s));
126
+ return types[0] || 'Any';
127
+ }
128
+
129
+ // Array
130
+ if (schema.type === 'array') {
131
+ const itemType = schema.items ? this.toPython(schema.items) : 'Any';
132
+ return `List[${itemType}]`;
133
+ }
134
+
135
+ // Object with additionalProperties → Dict
136
+ if (schema.type === 'object' && schema.additionalProperties && !schema.properties) {
137
+ const valueType = typeof schema.additionalProperties === 'object'
138
+ ? this.toPython(schema.additionalProperties)
139
+ : 'Any';
140
+ return `Dict[str, ${valueType}]`;
141
+ }
142
+
143
+ // Primitive types
144
+ switch (schema.type) {
145
+ case 'string':
146
+ if (schema.format === 'date-time') return 'datetime';
147
+ if (schema.format === 'date') return 'date';
148
+ if (schema.format === 'binary') return 'bytes';
149
+ return 'str';
150
+ case 'integer':
151
+ return 'int';
152
+ case 'number':
153
+ return 'float';
154
+ case 'boolean':
155
+ return 'bool';
156
+ case 'object':
157
+ return 'Dict[str, Any]';
158
+ default:
159
+ return 'Any';
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Map a parameter type for method signatures
165
+ * @param {Object} param - OpenAPI parameter object
166
+ * @param {string} language - 'typescript' | 'python'
167
+ * @returns {string}
168
+ */
169
+ static mapParamType(param, language) {
170
+ const schema = param.schema || param;
171
+ if (language === 'typescript') return this.toTypeScript(schema);
172
+ return this.toPython(schema);
173
+ }
174
+ }
@@ -278,10 +278,20 @@ export function formatDiagnosticsForAI(diagnostics) {
278
278
 
279
279
  // Page navigation detection (form submit in non-SPA apps)
280
280
  if (diagnostics.navigation) {
281
- output += `\n\n🔄 Page navigation detected (form submit):`;
282
- output += `\n From: ${diagnostics.navigation.from}`;
283
- output += `\n To: ${diagnostics.navigation.to}`;
284
- output += `\n → This indicates a successful form POST with page reload`;
281
+ const to = diagnostics.navigation.to || '';
282
+ const isAuthRedirect = /login|signin|auth/i.test(to)
283
+ && /[?&](returnUrl|return_url|redirect|next)/i.test(to);
284
+ if (isAuthRedirect) {
285
+ output += `\n\n⚠️ AUTH REDIRECT detected:`;
286
+ output += `\n From: ${diagnostics.navigation.from}`;
287
+ output += `\n To: ${diagnostics.navigation.to}`;
288
+ output += `\n → Session not established. Ensure login completes and cookies are set before navigating to protected routes.`;
289
+ } else {
290
+ output += `\n\n🔄 Page navigation detected (form submit):`;
291
+ output += `\n From: ${diagnostics.navigation.from}`;
292
+ output += `\n To: ${diagnostics.navigation.to}`;
293
+ output += `\n → This indicates a successful form POST with page reload`;
294
+ }
285
295
  }
286
296
 
287
297
  // Network activity - show all tracked requests (GET/POST/PUT/PATCH/DELETE)
package/nul DELETED
File without changes