@arcteninc/core 0.0.62 → 0.0.63
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/package.json
CHANGED
|
@@ -102,6 +102,12 @@ function extractToolNamesFromExpression(
|
|
|
102
102
|
function extractFromExpr(node: ts.Node): void {
|
|
103
103
|
if (visited.has(node)) return;
|
|
104
104
|
visited.add(node);
|
|
105
|
+
|
|
106
|
+
// Handle type assertions: (expr as any)
|
|
107
|
+
if (ts.isAsExpression(node)) {
|
|
108
|
+
extractFromExpr(node.expression);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
105
111
|
|
|
106
112
|
// Direct array literal: [tool1, tool2]
|
|
107
113
|
if (ts.isArrayLiteralExpression(node)) {
|
|
@@ -132,9 +138,12 @@ function extractToolNamesFromExpression(
|
|
|
132
138
|
// Try to resolve the module to find the actual function name
|
|
133
139
|
const resolvedName = resolvePropertyAccess(element, sourceFile, program);
|
|
134
140
|
const finalName = resolvedName || propName;
|
|
135
|
-
if
|
|
136
|
-
|
|
137
|
-
|
|
141
|
+
// Only add if it's a valid identifier name
|
|
142
|
+
if (finalName && finalName !== 'undefined' && finalName !== 'null' && finalName !== 'any') {
|
|
143
|
+
if (!toolNames.has(finalName)) {
|
|
144
|
+
toolNames.add(finalName);
|
|
145
|
+
toolOrder.push(finalName); // Preserve order
|
|
146
|
+
}
|
|
138
147
|
}
|
|
139
148
|
}
|
|
140
149
|
} else if (ts.isElementAccessExpression(element)) {
|
|
@@ -189,9 +198,12 @@ function extractToolNamesFromExpression(
|
|
|
189
198
|
// Try to resolve the module to find the actual function name
|
|
190
199
|
const resolvedName = resolvePropertyAccess(node, sourceFile, program);
|
|
191
200
|
const finalName = resolvedName || propName;
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
201
|
+
// Only add if it's a valid identifier name (not empty, not a keyword)
|
|
202
|
+
if (finalName && finalName !== 'undefined' && finalName !== 'null' && finalName !== 'any') {
|
|
203
|
+
if (!toolNames.has(finalName)) {
|
|
204
|
+
toolNames.add(finalName);
|
|
205
|
+
toolOrder.push(finalName);
|
|
206
|
+
}
|
|
195
207
|
}
|
|
196
208
|
return;
|
|
197
209
|
}
|
|
@@ -315,6 +327,7 @@ function buildVariableMap(sourceFile: ts.SourceFile): Map<string, ts.Expression>
|
|
|
315
327
|
|
|
316
328
|
/**
|
|
317
329
|
* Extract tools from useMemo callback, handling both arrow functions and regular functions
|
|
330
|
+
* Also handles type assertions like `as any`
|
|
318
331
|
*/
|
|
319
332
|
function extractToolsFromUseMemo(
|
|
320
333
|
useMemoCall: ts.CallExpression,
|
|
@@ -325,34 +338,45 @@ function extractToolsFromUseMemo(
|
|
|
325
338
|
|
|
326
339
|
const firstArg = useMemoCall.arguments[0];
|
|
327
340
|
|
|
341
|
+
function extractFromBody(body: ts.Expression | ts.Block): ts.Expression | null {
|
|
342
|
+
if (ts.isBlock(body)) {
|
|
343
|
+
// Block body: () => { return [...] }
|
|
344
|
+
for (const stmt of body.statements) {
|
|
345
|
+
if (ts.isReturnStatement(stmt) && stmt.expression) {
|
|
346
|
+
return unwrapTypeAssertion(stmt.expression);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
// Expression body: () => [...]
|
|
351
|
+
return unwrapTypeAssertion(body);
|
|
352
|
+
}
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
|
|
328
356
|
// Arrow function: () => [...]
|
|
329
357
|
if (ts.isArrowFunction(firstArg)) {
|
|
330
358
|
if (firstArg.body) {
|
|
331
|
-
|
|
332
|
-
// Block body: () => { return [...] }
|
|
333
|
-
for (const stmt of firstArg.body.statements) {
|
|
334
|
-
if (ts.isReturnStatement(stmt) && stmt.expression) {
|
|
335
|
-
return stmt.expression;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
} else {
|
|
339
|
-
// Expression body: () => [...]
|
|
340
|
-
return firstArg.body;
|
|
341
|
-
}
|
|
359
|
+
return extractFromBody(firstArg.body);
|
|
342
360
|
}
|
|
343
361
|
}
|
|
344
362
|
// Regular function: function() { return [...] }
|
|
345
363
|
else if (ts.isFunctionExpression(firstArg) && firstArg.body) {
|
|
346
|
-
|
|
347
|
-
if (ts.isReturnStatement(stmt) && stmt.expression) {
|
|
348
|
-
return stmt.expression;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
364
|
+
return extractFromBody(firstArg.body);
|
|
351
365
|
}
|
|
352
366
|
|
|
353
367
|
return null;
|
|
354
368
|
}
|
|
355
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Unwrap type assertions like `as any`, `as ToolFunction[]`, etc.
|
|
372
|
+
*/
|
|
373
|
+
function unwrapTypeAssertion(expr: ts.Expression): ts.Expression {
|
|
374
|
+
if (ts.isAsExpression(expr)) {
|
|
375
|
+
return expr.expression;
|
|
376
|
+
}
|
|
377
|
+
return expr;
|
|
378
|
+
}
|
|
379
|
+
|
|
356
380
|
/**
|
|
357
381
|
* Extract tool names from ArctenAgent or useAgent usage
|
|
358
382
|
*/
|