@arcteninc/core 0.0.42 → 0.0.43
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAgent.d.ts","sourceRoot":"","sources":["../../src/lib/useAgent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EAGf,MAAM,oBAAoB,CAAC;AAE5B,wBAAgB,QAAQ,CAAC,EACvB,UAAqC,EACrC,aAAmC,EACnC,WAAW,EAAE,aAAa,EAC1B,cAAsB,EACtB,IAAI,EACJ,KAAU,EACV,SAAc,EACd,YAAY,EACZ,YAAiB,EACjB,eAAoB,EACpB,cAAc,EAAE,qBAAqB,EACrC,UAAU,EACV,QAAQ,EACR,UAAU,GACX,GAAE,eAAoB,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"useAgent.d.ts","sourceRoot":"","sources":["../../src/lib/useAgent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EAGf,MAAM,oBAAoB,CAAC;AAE5B,wBAAgB,QAAQ,CAAC,EACvB,UAAqC,EACrC,aAAmC,EACnC,WAAW,EAAE,aAAa,EAC1B,cAAsB,EACtB,IAAI,EACJ,KAAU,EACV,SAAc,EACd,YAAY,EACZ,YAAiB,EACjB,eAAoB,EACpB,cAAc,EAAE,qBAAqB,EACrC,UAAU,EACV,QAAQ,EACR,UAAU,GACX,GAAE,eAAoB,GAAG,cAAc,CAodvC"}
|
|
@@ -28,6 +28,10 @@ interface BuildTimeFunctionMetadata {
|
|
|
28
28
|
returnType?: string;
|
|
29
29
|
isAsync?: boolean;
|
|
30
30
|
}
|
|
31
|
+
interface BuildTimeMetadata {
|
|
32
|
+
functions: Record<string, BuildTimeFunctionMetadata>;
|
|
33
|
+
toolOrder?: string[];
|
|
34
|
+
}
|
|
31
35
|
/**
|
|
32
36
|
* Extract tool metadata from functions using build-time generated metadata
|
|
33
37
|
* Automatically preserves original function names to survive minification
|
|
@@ -37,6 +41,6 @@ interface BuildTimeFunctionMetadata {
|
|
|
37
41
|
* @returns Array of tool metadata - tools without metadata are filtered out (with a warning)
|
|
38
42
|
* @throws Error if buildTimeMeta is not provided
|
|
39
43
|
*/
|
|
40
|
-
export declare function extractToolsMetadata(functions: Function[], buildTimeMeta?: Record<string, BuildTimeFunctionMetadata> | null): ToolMetadata[];
|
|
44
|
+
export declare function extractToolsMetadata(functions: Function[], buildTimeMeta?: Record<string, BuildTimeFunctionMetadata> | BuildTimeMetadata | null): ToolMetadata[];
|
|
41
45
|
export {};
|
|
42
46
|
//# sourceMappingURL=extract-tool-metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-tool-metadata.d.ts","sourceRoot":"","sources":["../../src/utils/extract-tool-metadata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,eAAO,MAAM,oBAAoB,eAA6C,CAAC;AAE/E;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC,CAGnF;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,GAAG,CAAC;CACjB;AAGD,UAAU,yBAAyB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,GAAG,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA+
|
|
1
|
+
{"version":3,"file":"extract-tool-metadata.d.ts","sourceRoot":"","sources":["../../src/utils/extract-tool-metadata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,eAAO,MAAM,oBAAoB,eAA6C,CAAC;AAE/E;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC,CAGnF;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,GAAG,CAAC;CACjB;AAGD,UAAU,yBAAyB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,GAAG,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAGD,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IACrD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AA+DD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,QAAQ,EAAE,EACrB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,GAAG,iBAAiB,GAAG,IAAI,GACnF,YAAY,EAAE,CAoEhB"}
|
package/package.json
CHANGED
|
@@ -42,10 +42,12 @@ interface GeneratedMetadata {
|
|
|
42
42
|
generated: string;
|
|
43
43
|
discoveredFrom: string[];
|
|
44
44
|
functions: Record<string, FunctionMetadata>;
|
|
45
|
+
toolOrder?: string[]; // Ordered array of tool names as they appear in components
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
interface ToolUsage {
|
|
48
49
|
toolNames: Set<string>;
|
|
50
|
+
toolOrder: string[]; // Ordered array of tool names as they appear in the component
|
|
49
51
|
file: string;
|
|
50
52
|
component: 'ArctenAgent' | 'useAgent';
|
|
51
53
|
}
|
|
@@ -70,8 +72,9 @@ function extractToolNamesFromExpression(
|
|
|
70
72
|
expr: ts.Expression,
|
|
71
73
|
sourceFile: ts.SourceFile,
|
|
72
74
|
variableMap: Map<string, ts.Expression>
|
|
73
|
-
): Set<string
|
|
75
|
+
): { names: Set<string>; order: string[] } {
|
|
74
76
|
const toolNames = new Set<string>();
|
|
77
|
+
const toolOrder: string[] = []; // Preserve order
|
|
75
78
|
const visited = new Set<ts.Node>();
|
|
76
79
|
|
|
77
80
|
function extractFromExpr(node: ts.Node): void {
|
|
@@ -95,13 +98,19 @@ function extractToolNamesFromExpression(
|
|
|
95
98
|
// Direct identifier: toolName
|
|
96
99
|
const name = element.text;
|
|
97
100
|
if (name && name !== 'undefined' && name !== 'null') {
|
|
98
|
-
toolNames.
|
|
101
|
+
if (!toolNames.has(name)) {
|
|
102
|
+
toolNames.add(name);
|
|
103
|
+
toolOrder.push(name); // Preserve order
|
|
104
|
+
}
|
|
99
105
|
}
|
|
100
106
|
} else if (ts.isPropertyAccessExpression(element)) {
|
|
101
107
|
// Property access: tools.getOrders -> extract "getOrders"
|
|
102
108
|
const propName = element.name.text;
|
|
103
109
|
if (propName) {
|
|
104
|
-
toolNames.
|
|
110
|
+
if (!toolNames.has(propName)) {
|
|
111
|
+
toolNames.add(propName);
|
|
112
|
+
toolOrder.push(propName); // Preserve order
|
|
113
|
+
}
|
|
105
114
|
}
|
|
106
115
|
} else if (ts.isElementAccessExpression(element)) {
|
|
107
116
|
// Element access: tools['getOrders'] -> extract the property name if it's a string literal
|
|
@@ -109,7 +118,10 @@ function extractToolNamesFromExpression(
|
|
|
109
118
|
if (ts.isStringLiteral(indexExpr) || ts.isNumericLiteral(indexExpr)) {
|
|
110
119
|
const name = indexExpr.text;
|
|
111
120
|
if (name && name !== 'undefined' && name !== 'null') {
|
|
112
|
-
toolNames.
|
|
121
|
+
if (!toolNames.has(name)) {
|
|
122
|
+
toolNames.add(name);
|
|
123
|
+
toolOrder.push(name); // Preserve order
|
|
124
|
+
}
|
|
113
125
|
}
|
|
114
126
|
} else {
|
|
115
127
|
// For dynamic access like tools[someVar], recursively extract
|
|
@@ -134,7 +146,10 @@ function extractToolNamesFromExpression(
|
|
|
134
146
|
// If not in variableMap, it might be a function declaration name
|
|
135
147
|
// Add it directly as a tool name (findFunctionDefinition will find it later)
|
|
136
148
|
if (varName && varName !== 'undefined' && varName !== 'null') {
|
|
137
|
-
toolNames.
|
|
149
|
+
if (!toolNames.has(varName)) {
|
|
150
|
+
toolNames.add(varName);
|
|
151
|
+
toolOrder.push(varName);
|
|
152
|
+
}
|
|
138
153
|
}
|
|
139
154
|
}
|
|
140
155
|
return;
|
|
@@ -143,7 +158,10 @@ function extractToolNamesFromExpression(
|
|
|
143
158
|
// Property access: wrappedTools.getRAGInfo
|
|
144
159
|
if (ts.isPropertyAccessExpression(node)) {
|
|
145
160
|
const propName = node.name.text;
|
|
146
|
-
toolNames.
|
|
161
|
+
if (!toolNames.has(propName)) {
|
|
162
|
+
toolNames.add(propName);
|
|
163
|
+
toolOrder.push(propName);
|
|
164
|
+
}
|
|
147
165
|
return;
|
|
148
166
|
}
|
|
149
167
|
|
|
@@ -185,7 +203,7 @@ function extractToolNamesFromExpression(
|
|
|
185
203
|
}
|
|
186
204
|
|
|
187
205
|
extractFromExpr(expr);
|
|
188
|
-
return toolNames;
|
|
206
|
+
return { names: toolNames, order: toolOrder };
|
|
189
207
|
}
|
|
190
208
|
|
|
191
209
|
/**
|
|
@@ -249,7 +267,7 @@ function extractToolNamesFromFile(
|
|
|
249
267
|
const expr = attr.initializer.expression;
|
|
250
268
|
if (expr) {
|
|
251
269
|
const extracted = extractToolNamesFromExpression(expr, sourceFile, variableMap);
|
|
252
|
-
extracted.forEach(name => toolNames.add(name));
|
|
270
|
+
extracted.names.forEach(name => toolNames.add(name));
|
|
253
271
|
}
|
|
254
272
|
}
|
|
255
273
|
}
|
|
@@ -257,8 +275,26 @@ function extractToolNamesFromFile(
|
|
|
257
275
|
}
|
|
258
276
|
|
|
259
277
|
if (toolNames.size > 0) {
|
|
278
|
+
// Collect ordered tool names from all attributes
|
|
279
|
+
const allToolOrder: string[] = [];
|
|
280
|
+
for (const attr of attributes) {
|
|
281
|
+
if (ts.isJsxAttribute(attr)) {
|
|
282
|
+
const attrName = attr.name.getText(sourceFile);
|
|
283
|
+
if (attrName === 'tools' || attrName === 'safeTools') {
|
|
284
|
+
if (attr.initializer && ts.isJsxExpression(attr.initializer)) {
|
|
285
|
+
const expr = attr.initializer.expression;
|
|
286
|
+
if (expr) {
|
|
287
|
+
const extracted = extractToolNamesFromExpression(expr, sourceFile, variableMap);
|
|
288
|
+
allToolOrder.push(...extracted.order);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
260
295
|
usages.push({
|
|
261
296
|
toolNames,
|
|
297
|
+
toolOrder: allToolOrder,
|
|
262
298
|
file: sourceFile.fileName,
|
|
263
299
|
component: 'ArctenAgent',
|
|
264
300
|
});
|
|
@@ -284,7 +320,7 @@ function extractToolNamesFromFile(
|
|
|
284
320
|
sourceFile,
|
|
285
321
|
variableMap
|
|
286
322
|
);
|
|
287
|
-
extracted.forEach(name => toolNames.add(name));
|
|
323
|
+
extracted.names.forEach(name => toolNames.add(name));
|
|
288
324
|
}
|
|
289
325
|
}
|
|
290
326
|
}
|
|
@@ -292,8 +328,30 @@ function extractToolNamesFromFile(
|
|
|
292
328
|
}
|
|
293
329
|
|
|
294
330
|
if (toolNames.size > 0) {
|
|
331
|
+
// Collect ordered tool names from tools and safeTools properties
|
|
332
|
+
const allToolOrder: string[] = [];
|
|
333
|
+
if (node.arguments.length > 0) {
|
|
334
|
+
const arg = node.arguments[0];
|
|
335
|
+
if (ts.isObjectLiteralExpression(arg)) {
|
|
336
|
+
for (const prop of arg.properties) {
|
|
337
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
338
|
+
const propName = prop.name.getText(sourceFile);
|
|
339
|
+
if (propName === 'tools' || propName === 'safeTools') {
|
|
340
|
+
const extracted = extractToolNamesFromExpression(
|
|
341
|
+
prop.initializer,
|
|
342
|
+
sourceFile,
|
|
343
|
+
variableMap
|
|
344
|
+
);
|
|
345
|
+
allToolOrder.push(...extracted.order);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
295
352
|
usages.push({
|
|
296
353
|
toolNames,
|
|
354
|
+
toolOrder: allToolOrder,
|
|
297
355
|
file: sourceFile.fileName,
|
|
298
356
|
component: 'useAgent',
|
|
299
357
|
});
|
|
@@ -1426,11 +1484,38 @@ async function autoDiscoverAndExtract(projectRoot: string, outputPath: string) {
|
|
|
1426
1484
|
}
|
|
1427
1485
|
}
|
|
1428
1486
|
|
|
1487
|
+
// Collect tool order from all usage sites (preserve discovery order)
|
|
1488
|
+
// Use the first occurrence order from the first usage site as the canonical order
|
|
1489
|
+
const toolOrder: string[] = [];
|
|
1490
|
+
if (allToolUsages.length > 0) {
|
|
1491
|
+
// Use the order from the first usage site (most common case: single agent)
|
|
1492
|
+
// For multiple agents, this gives a consistent ordering
|
|
1493
|
+
const firstUsage = allToolUsages[0];
|
|
1494
|
+
if (firstUsage.toolOrder && firstUsage.toolOrder.length > 0) {
|
|
1495
|
+
// Add tools in the order they appear, but only if they have metadata
|
|
1496
|
+
for (const toolName of firstUsage.toolOrder) {
|
|
1497
|
+
if (functionsMap[toolName] && !toolOrder.includes(toolName)) {
|
|
1498
|
+
toolOrder.push(toolName);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
// Add any remaining tools that weren't in the first usage's order
|
|
1503
|
+
for (const toolName of Object.keys(functionsMap)) {
|
|
1504
|
+
if (!toolOrder.includes(toolName)) {
|
|
1505
|
+
toolOrder.push(toolName);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
} else {
|
|
1509
|
+
// Fallback: use the order tools were discovered
|
|
1510
|
+
toolOrder.push(...Object.keys(functionsMap));
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1429
1513
|
// Generate output
|
|
1430
1514
|
const output: GeneratedMetadata = {
|
|
1431
1515
|
generated: new Date().toISOString(),
|
|
1432
1516
|
discoveredFrom: Array.from(new Set(discoveredFrom)),
|
|
1433
1517
|
functions: functionsMap,
|
|
1518
|
+
toolOrder: toolOrder.length > 0 ? toolOrder : undefined,
|
|
1434
1519
|
};
|
|
1435
1520
|
|
|
1436
1521
|
const outputDir = path.dirname(outputPath);
|