@fluidframework/tree-agent 2.63.0-359461 → 2.63.0-359734
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/api-report/tree-agent.alpha.api.md +9 -2
- package/dist/agent.d.ts +0 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +21 -49
- package/dist/agent.js.map +1 -1
- package/dist/alpha.d.ts +1 -0
- package/dist/api.d.ts +18 -7
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/langchain.d.ts.map +1 -1
- package/dist/langchain.js +2 -3
- package/dist/langchain.js.map +1 -1
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +15 -17
- package/dist/prompt.js.map +1 -1
- package/dist/ses.d.ts +21 -0
- package/dist/ses.d.ts.map +1 -0
- package/dist/ses.js +64 -0
- package/dist/ses.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -1
- package/dist/utils.js.map +1 -1
- package/lib/agent.d.ts +0 -3
- package/lib/agent.d.ts.map +1 -1
- package/lib/agent.js +22 -50
- package/lib/agent.js.map +1 -1
- package/lib/alpha.d.ts +1 -0
- package/lib/api.d.ts +18 -7
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/langchain.d.ts.map +1 -1
- package/lib/langchain.js +2 -3
- package/lib/langchain.js.map +1 -1
- package/lib/prompt.d.ts.map +1 -1
- package/lib/prompt.js +15 -17
- package/lib/prompt.js.map +1 -1
- package/lib/ses.d.ts +21 -0
- package/lib/ses.d.ts.map +1 -0
- package/lib/ses.js +60 -0
- package/lib/ses.js.map +1 -0
- package/lib/utils.d.ts +4 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +14 -0
- package/lib/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/agent.ts +29 -61
- package/src/api.ts +19 -12
- package/src/index.ts +1 -0
- package/src/langchain.ts +2 -3
- package/src/prompt.ts +15 -17
- package/src/ses.ts +73 -0
- package/src/utils.ts +14 -0
- package/dist/functionParsing.d.ts +0 -13
- package/dist/functionParsing.d.ts.map +0 -1
- package/dist/functionParsing.js +0 -215
- package/dist/functionParsing.js.map +0 -1
- package/lib/functionParsing.d.ts +0 -13
- package/lib/functionParsing.d.ts.map +0 -1
- package/lib/functionParsing.js +0 -210
- package/lib/functionParsing.js.map +0 -1
- package/src/functionParsing.ts +0 -268
package/src/functionParsing.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/* eslint-disable @rushstack/no-new-null */
|
|
7
|
-
|
|
8
|
-
import { parse } from "acorn";
|
|
9
|
-
import type {
|
|
10
|
-
Program,
|
|
11
|
-
Statement,
|
|
12
|
-
ModuleDeclaration,
|
|
13
|
-
VariableDeclaration,
|
|
14
|
-
Expression,
|
|
15
|
-
AssignmentExpression,
|
|
16
|
-
Pattern,
|
|
17
|
-
Identifier,
|
|
18
|
-
Literal,
|
|
19
|
-
ExportNamedDeclaration,
|
|
20
|
-
ExportDefaultDeclaration,
|
|
21
|
-
FunctionDeclaration,
|
|
22
|
-
FunctionExpression,
|
|
23
|
-
ArrowFunctionExpression,
|
|
24
|
-
} from "acorn";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Finds the name of the first invocable function in the given code string.
|
|
28
|
-
*/
|
|
29
|
-
export function findInvocableFunctionName(code: string): string | undefined {
|
|
30
|
-
const program = parseProgram(code);
|
|
31
|
-
if (program === undefined) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
for (const node of program.body) {
|
|
36
|
-
const name = getNameFromTopLevelNode(node);
|
|
37
|
-
if (name !== undefined) {
|
|
38
|
-
return name;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Removes top-level export syntax so that the provided code can execute in a classic script context.
|
|
47
|
-
*/
|
|
48
|
-
export function stripExportSyntax(code: string): string {
|
|
49
|
-
const program = parseProgram(code);
|
|
50
|
-
if (program === undefined) {
|
|
51
|
-
return code;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const replacements: { start: number; end: number; replacement: string }[] = [];
|
|
55
|
-
for (const node of program.body) {
|
|
56
|
-
switch (node.type) {
|
|
57
|
-
case "ExportNamedDeclaration": {
|
|
58
|
-
if (node.declaration !== undefined && node.declaration !== null) {
|
|
59
|
-
replacements.push({
|
|
60
|
-
start: node.start,
|
|
61
|
-
end: node.declaration.start,
|
|
62
|
-
replacement: "",
|
|
63
|
-
});
|
|
64
|
-
} else {
|
|
65
|
-
replacements.push({ start: node.start, end: node.end, replacement: "" });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case "ExportDefaultDeclaration": {
|
|
71
|
-
const { declaration, start, end } = node;
|
|
72
|
-
if (
|
|
73
|
-
declaration.type === "FunctionDeclaration" ||
|
|
74
|
-
declaration.type === "FunctionExpression"
|
|
75
|
-
) {
|
|
76
|
-
replacements.push({
|
|
77
|
-
start,
|
|
78
|
-
end: declaration.start,
|
|
79
|
-
replacement: "",
|
|
80
|
-
});
|
|
81
|
-
} else {
|
|
82
|
-
replacements.push({ start, end, replacement: "" });
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case "ExportAllDeclaration": {
|
|
88
|
-
replacements.push({ start: node.start, end: node.end, replacement: "" });
|
|
89
|
-
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
// No default
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (replacements.length === 0) {
|
|
97
|
-
return code;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
replacements.sort((a, b) => b.start - a.start);
|
|
101
|
-
let sanitized = code;
|
|
102
|
-
for (const { start, end, replacement } of replacements) {
|
|
103
|
-
sanitized = `${sanitized.slice(0, start)}${replacement}${sanitized.slice(end)}`;
|
|
104
|
-
}
|
|
105
|
-
return sanitized;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
type TopLevelNode = Statement | ModuleDeclaration;
|
|
109
|
-
|
|
110
|
-
function parseProgram(code: string): Program | undefined {
|
|
111
|
-
try {
|
|
112
|
-
return parse(code, {
|
|
113
|
-
ecmaVersion: "latest",
|
|
114
|
-
sourceType: "module",
|
|
115
|
-
});
|
|
116
|
-
} catch {
|
|
117
|
-
try {
|
|
118
|
-
return parse(code, {
|
|
119
|
-
ecmaVersion: "latest",
|
|
120
|
-
sourceType: "script",
|
|
121
|
-
allowReturnOutsideFunction: true,
|
|
122
|
-
allowAwaitOutsideFunction: true,
|
|
123
|
-
allowSuperOutsideMethod: true,
|
|
124
|
-
});
|
|
125
|
-
} catch {
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function getNameFromTopLevelNode(node: TopLevelNode): string | undefined {
|
|
132
|
-
switch (node.type) {
|
|
133
|
-
case "FunctionDeclaration": {
|
|
134
|
-
return getFunctionIdentifier(node);
|
|
135
|
-
}
|
|
136
|
-
case "VariableDeclaration": {
|
|
137
|
-
return getNameFromVariableDeclaration(node);
|
|
138
|
-
}
|
|
139
|
-
case "ExpressionStatement": {
|
|
140
|
-
return getNameFromExpression(node.expression);
|
|
141
|
-
}
|
|
142
|
-
case "ExportNamedDeclaration": {
|
|
143
|
-
return getNameFromExportNamed(node);
|
|
144
|
-
}
|
|
145
|
-
case "ExportDefaultDeclaration": {
|
|
146
|
-
return getNameFromExportDefault(node);
|
|
147
|
-
}
|
|
148
|
-
default: {
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function getNameFromVariableDeclaration(node: VariableDeclaration): string | undefined {
|
|
155
|
-
for (const declarator of node.declarations) {
|
|
156
|
-
const name = getIdentifierFromPattern(declarator.id);
|
|
157
|
-
if (name === undefined) {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (isFunctionLikeExpression(declarator.init)) {
|
|
162
|
-
return name;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function getNameFromExpression(
|
|
170
|
-
expression: Expression | Literal | undefined,
|
|
171
|
-
): string | undefined {
|
|
172
|
-
if (!isAssignmentExpression(expression)) {
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (expression.operator !== "=") {
|
|
177
|
-
return undefined;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const target = getIdentifierFromPattern(expression.left);
|
|
181
|
-
if (target === undefined) {
|
|
182
|
-
return undefined;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return isFunctionLikeExpression(expression.right) ? target : undefined;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function getNameFromExportNamed(node: ExportNamedDeclaration): string | undefined {
|
|
189
|
-
const declaration = node.declaration;
|
|
190
|
-
if (declaration !== undefined && declaration !== null) {
|
|
191
|
-
if (declaration.type === "FunctionDeclaration") {
|
|
192
|
-
const name = getFunctionIdentifier(declaration);
|
|
193
|
-
if (name !== undefined) {
|
|
194
|
-
return name;
|
|
195
|
-
}
|
|
196
|
-
} else if (declaration.type === "VariableDeclaration") {
|
|
197
|
-
const name = getNameFromVariableDeclaration(declaration);
|
|
198
|
-
if (name !== undefined) {
|
|
199
|
-
return name;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (node.source === undefined || node.source === null) {
|
|
205
|
-
for (const specifier of node.specifiers) {
|
|
206
|
-
const localName = getIdentifierName(specifier.local);
|
|
207
|
-
if (localName !== undefined) {
|
|
208
|
-
return localName;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function getNameFromExportDefault(node: ExportDefaultDeclaration): string | undefined {
|
|
217
|
-
const declaration = node.declaration;
|
|
218
|
-
if (declaration.type === "Identifier") {
|
|
219
|
-
return declaration.name;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
declaration.type === "FunctionDeclaration" ||
|
|
224
|
-
declaration.type === "FunctionExpression"
|
|
225
|
-
) {
|
|
226
|
-
return getFunctionIdentifier(declaration);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return undefined;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function isAssignmentExpression(
|
|
233
|
-
expression: Expression | Literal | undefined,
|
|
234
|
-
): expression is AssignmentExpression {
|
|
235
|
-
return expression?.type === "AssignmentExpression";
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function getIdentifierFromPattern(pattern: Pattern): string | undefined {
|
|
239
|
-
if (pattern.type === "Identifier") {
|
|
240
|
-
return pattern.name;
|
|
241
|
-
}
|
|
242
|
-
return undefined;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function isFunctionLikeExpression(
|
|
246
|
-
expression: Expression | null | undefined,
|
|
247
|
-
): expression is FunctionExpression | ArrowFunctionExpression {
|
|
248
|
-
return (
|
|
249
|
-
expression?.type === "FunctionExpression" || expression?.type === "ArrowFunctionExpression"
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function getFunctionIdentifier(
|
|
254
|
-
fn: FunctionDeclaration | FunctionExpression | { id?: Identifier | null },
|
|
255
|
-
): string | undefined {
|
|
256
|
-
const id = fn.id;
|
|
257
|
-
if (id === undefined || id === null) {
|
|
258
|
-
return undefined;
|
|
259
|
-
}
|
|
260
|
-
return id.name;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function getIdentifierName(node: Identifier | Literal): string | undefined {
|
|
264
|
-
if (node.type === "Identifier") {
|
|
265
|
-
return node.name;
|
|
266
|
-
}
|
|
267
|
-
return undefined;
|
|
268
|
-
}
|