@arcteninc/core 0.0.23 → 0.0.24

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcteninc/core",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -90,12 +90,18 @@ function extractToolNamesFromExpression(
90
90
  return;
91
91
  }
92
92
 
93
- // Variable reference: toolsList
93
+ // Variable reference: toolsList or function name: generateReport
94
94
  if (ts.isIdentifier(node)) {
95
95
  const varName = node.getText(sourceFile);
96
96
  const varExpr = variableMap.get(varName);
97
97
  if (varExpr) {
98
98
  extractFromExpr(varExpr);
99
+ } else {
100
+ // If not in variableMap, it might be a function declaration name
101
+ // Add it directly as a tool name (findFunctionDefinition will find it later)
102
+ if (varName && varName !== 'undefined' && varName !== 'null') {
103
+ toolNames.add(varName);
104
+ }
99
105
  }
100
106
  return;
101
107
  }
@@ -275,16 +281,38 @@ function findFunctionDefinition(
275
281
  functionName: string,
276
282
  sourceFile: ts.SourceFile,
277
283
  program: ts.Program
278
- ): { sourceFile: ts.SourceFile; node: ts.FunctionDeclaration } | null {
284
+ ): { sourceFile: ts.SourceFile; node: ts.FunctionDeclaration | ts.VariableDeclaration } | null {
279
285
  // First, check if it's defined in the current file
280
- let foundNode: ts.FunctionDeclaration | null = null;
286
+ let foundNode: ts.FunctionDeclaration | ts.VariableDeclaration | null = null;
281
287
 
282
288
  function visitForDefinition(node: ts.Node) {
289
+ // Function declaration: function generateReport() {}
283
290
  if (ts.isFunctionDeclaration(node) && node.name) {
284
291
  if (node.name.getText(sourceFile) === functionName) {
285
292
  foundNode = node;
286
293
  }
287
294
  }
295
+
296
+ // Variable declaration with arrow function: const addFilter = async () => {}
297
+ // or function expression: const addFilter = async function() {}
298
+ if (ts.isVariableStatement(node)) {
299
+ for (const declaration of node.declarationList.declarations) {
300
+ if (ts.isIdentifier(declaration.name)) {
301
+ const varName = declaration.name.getText(sourceFile);
302
+ if (varName === functionName && declaration.initializer) {
303
+ // Check if it's an arrow function or function expression
304
+ if (
305
+ ts.isArrowFunction(declaration.initializer) ||
306
+ ts.isFunctionExpression(declaration.initializer)
307
+ ) {
308
+ foundNode = declaration;
309
+ break;
310
+ }
311
+ }
312
+ }
313
+ }
314
+ }
315
+
288
316
  if (!foundNode) {
289
317
  ts.forEachChild(node, visitForDefinition);
290
318
  }
@@ -502,16 +530,46 @@ function serializeType(
502
530
  * Extract metadata from a function
503
531
  */
504
532
  function extractFunctionMetadata(
505
- node: ts.FunctionDeclaration,
533
+ node: ts.FunctionDeclaration | ts.VariableDeclaration,
506
534
  checker: ts.TypeChecker,
507
535
  sourceFile: ts.SourceFile
508
536
  ): FunctionMetadata | null {
509
- if (!node.name) {
537
+ let functionNode: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression | null = null;
538
+ let functionName: string;
539
+
540
+ // Handle FunctionDeclaration: function generateReport() {}
541
+ if (ts.isFunctionDeclaration(node)) {
542
+ if (!node.name) {
543
+ return null;
544
+ }
545
+ functionNode = node;
546
+ functionName = node.name.getText(sourceFile);
547
+ }
548
+ // Handle VariableDeclaration: const addFilter = async () => {}
549
+ else if (ts.isVariableDeclaration(node)) {
550
+ if (!ts.isIdentifier(node.name)) {
551
+ return null;
552
+ }
553
+ functionName = node.name.getText(sourceFile);
554
+
555
+ if (node.initializer) {
556
+ if (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) {
557
+ functionNode = node.initializer;
558
+ } else {
559
+ return null;
560
+ }
561
+ } else {
562
+ return null;
563
+ }
564
+ } else {
510
565
  return null;
511
566
  }
512
567
 
513
- const functionName = node.name.getText(sourceFile);
568
+ if (!functionNode) {
569
+ return null;
570
+ }
514
571
 
572
+ // Extract JSDoc comments
515
573
  const jsDocTags = ts.getJSDocTags(node);
516
574
  const jsDocComments = ts.getJSDocCommentsAndTags(node);
517
575
 
@@ -538,9 +596,24 @@ function extractFunctionMetadata(
538
596
 
539
597
  const properties: Record<string, JsonSchemaProperty> = {};
540
598
  const required: string[] = [];
541
- const isAsync = node.modifiers?.some(m => m.kind === ts.SyntaxKind.AsyncKeyword) || false;
542
-
543
- for (const param of node.parameters) {
599
+
600
+ // Check if async - works for both function declarations and arrow functions
601
+ const isAsync =
602
+ (ts.isFunctionDeclaration(node) && node.modifiers?.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) ||
603
+ (ts.isVariableDeclaration(node) && node.initializer && ts.isArrowFunction(node.initializer) &&
604
+ (node.initializer.modifiers?.some(m => m.kind === ts.SyntaxKind.AsyncKeyword) || false)) ||
605
+ (ts.isVariableDeclaration(node) && node.initializer && ts.isFunctionExpression(node.initializer) &&
606
+ (node.initializer.modifiers?.some(m => m.kind === ts.SyntaxKind.AsyncKeyword) || false)) ||
607
+ false;
608
+
609
+ // Extract parameters from the function node
610
+ const parameters = ts.isFunctionDeclaration(node)
611
+ ? node.parameters
612
+ : (ts.isArrowFunction(functionNode) || ts.isFunctionExpression(functionNode))
613
+ ? functionNode.parameters
614
+ : [];
615
+
616
+ for (const param of parameters) {
544
617
  const paramName = param.name.getText(sourceFile);
545
618
  const hasDefault = param.initializer !== undefined;
546
619
 
@@ -581,8 +654,16 @@ function extractFunctionMetadata(
581
654
  }
582
655
 
583
656
  let returnType = 'any';
584
- if (node.type) {
657
+ if (ts.isFunctionDeclaration(node) && node.type) {
585
658
  returnType = node.type.getText(sourceFile);
659
+ } else if (
660
+ ts.isVariableDeclaration(node) &&
661
+ node.initializer &&
662
+ (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer))
663
+ ) {
664
+ if (node.initializer.type) {
665
+ returnType = node.initializer.type.getText(sourceFile);
666
+ }
586
667
  }
587
668
 
588
669
  return {