agentlang 0.0.66 → 0.0.68
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/README.md +9 -9
- package/out/api/http.d.ts.map +1 -1
- package/out/api/http.js +2 -1
- package/out/api/http.js.map +1 -1
- package/out/cli/main.d.ts.map +1 -1
- package/out/cli/main.js +7 -1
- package/out/cli/main.js.map +1 -1
- package/out/language/generated/ast.d.ts +1 -1
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +2 -1
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/generated/grammar.js +1 -1
- package/out/language/main.cjs +2 -2
- package/out/language/main.cjs.map +2 -2
- package/out/runtime/defs.d.ts +58 -0
- package/out/runtime/defs.d.ts.map +1 -1
- package/out/runtime/defs.js +172 -0
- package/out/runtime/defs.js.map +1 -1
- package/out/runtime/exec-graph.d.ts +17 -0
- package/out/runtime/exec-graph.d.ts.map +1 -0
- package/out/runtime/exec-graph.js +434 -0
- package/out/runtime/exec-graph.js.map +1 -0
- package/out/runtime/interpreter.d.ts +38 -3
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +165 -73
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/module.d.ts +1 -0
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +14 -6
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts +0 -1
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +0 -1
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/modules/auth.d.ts.map +1 -1
- package/out/runtime/modules/auth.js +13 -13
- package/out/runtime/modules/auth.js.map +1 -1
- package/out/runtime/resolvers/interface.d.ts +1 -0
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js +5 -0
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/utils/runtime.d.ts +1 -0
- package/out/utils/runtime.d.ts.map +1 -1
- package/out/utils/runtime.js +4 -0
- package/out/utils/runtime.js.map +1 -1
- package/package.json +180 -156
- package/src/api/http.ts +2 -1
- package/src/cli/main.ts +8 -1
- package/src/language/agentlang.langium +3 -2
- package/src/language/generated/ast.ts +3 -3
- package/src/language/generated/grammar.ts +1 -1
- package/src/runtime/defs.ts +210 -0
- package/src/runtime/exec-graph.ts +518 -0
- package/src/runtime/interpreter.ts +202 -81
- package/src/runtime/module.ts +15 -6
- package/src/runtime/modules/ai.ts +0 -2
- package/src/runtime/modules/auth.ts +25 -18
- package/src/runtime/resolvers/interface.ts +5 -0
- package/src/utils/runtime.ts +6 -0
package/src/runtime/defs.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Expr, Pattern, Statement } from '../language/generated/ast.js';
|
|
2
|
+
|
|
1
3
|
export const PathAttributeName: string = '__path__';
|
|
2
4
|
export const PathAttributeNameQuery: string = '__path__?';
|
|
3
5
|
export const ParentAttributeName: string = '__parent__';
|
|
@@ -90,3 +92,211 @@ export function setSubscriptionFn(f: Function) {
|
|
|
90
92
|
|
|
91
93
|
export const ForceReadPermFlag = 'f-r-f';
|
|
92
94
|
export const FlowSuspensionTag = `--`;
|
|
95
|
+
|
|
96
|
+
export enum SubGraphType {
|
|
97
|
+
EVENT,
|
|
98
|
+
IF,
|
|
99
|
+
FOR_EACH,
|
|
100
|
+
DELETE,
|
|
101
|
+
PURGE,
|
|
102
|
+
RETURN,
|
|
103
|
+
AGENT,
|
|
104
|
+
NONE,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export class ExecGraphNode {
|
|
108
|
+
code: Statement | Pattern | Expr;
|
|
109
|
+
codeStr: string | undefined;
|
|
110
|
+
subGraphIndex: number;
|
|
111
|
+
subGraphType: SubGraphType;
|
|
112
|
+
|
|
113
|
+
constructor(
|
|
114
|
+
statement: Statement | Pattern | Expr,
|
|
115
|
+
subGraphIndex: number = -1,
|
|
116
|
+
subGraphType: SubGraphType = SubGraphType.NONE
|
|
117
|
+
) {
|
|
118
|
+
this.code = statement;
|
|
119
|
+
this.codeStr = this.code.$cstNode?.text;
|
|
120
|
+
this.subGraphType = subGraphType;
|
|
121
|
+
this.subGraphIndex = subGraphIndex;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
asObject(): any {
|
|
125
|
+
const r: any = { code: this.codeStr };
|
|
126
|
+
if (this.subGraphType != SubGraphType.NONE) {
|
|
127
|
+
r.type = SubGraphType[this.subGraphType];
|
|
128
|
+
}
|
|
129
|
+
return r;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export class ExecGraph {
|
|
134
|
+
private rootNodes: ExecGraphNode[];
|
|
135
|
+
private subGraphs: ExecGraph[];
|
|
136
|
+
private parentGraph: ExecGraph | undefined = undefined;
|
|
137
|
+
private activeModuleName: string | undefined;
|
|
138
|
+
private hasAgentsFlag: boolean = false;
|
|
139
|
+
private loopBody: boolean = false;
|
|
140
|
+
|
|
141
|
+
static Empty = new ExecGraph();
|
|
142
|
+
|
|
143
|
+
static isEmpty(g: ExecGraph): boolean {
|
|
144
|
+
return Object.is(ExecGraph.Empty, g);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
constructor() {
|
|
148
|
+
this.rootNodes = new Array<ExecGraphNode>();
|
|
149
|
+
this.subGraphs = new Array<ExecGraph>();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
pushNode(node: ExecGraphNode): ExecGraph {
|
|
153
|
+
this.rootNodes.push(node);
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
pushSubGraph(execGraph: ExecGraph): ExecGraph {
|
|
158
|
+
execGraph.parentGraph = this;
|
|
159
|
+
this.subGraphs.push(execGraph);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getSubGraphsLength(): number {
|
|
164
|
+
return this.subGraphs.length;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
getLastSubGraphIndex(): number {
|
|
168
|
+
return this.subGraphs.length - 1;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
fetchSubGraphAt(index: number): ExecGraph {
|
|
172
|
+
if (index < 0 || index >= this.subGraphs.length) {
|
|
173
|
+
throw new Error(`Invalid sub-graph index: ${index}`);
|
|
174
|
+
}
|
|
175
|
+
return this.subGraphs[index];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
fetchForEachBodySubGraph(): ExecGraph {
|
|
179
|
+
return this.fetchSubGraphAt(this.subGraphs.length - 1);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
fetchIfConsequentSubGraph(): ExecGraph {
|
|
183
|
+
if (this.subGraphs.length >= 2) {
|
|
184
|
+
return this.fetchSubGraphAt(this.subGraphs.length - 2);
|
|
185
|
+
} else {
|
|
186
|
+
return this.fetchSubGraphAt(this.subGraphs.length - 1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
fetchIfAlternativeSubGraph(): ExecGraph | undefined {
|
|
191
|
+
if (this.subGraphs.length >= 2) {
|
|
192
|
+
return this.fetchSubGraphAt(this.subGraphs.length - 1);
|
|
193
|
+
} else {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
getRootNodes(): ExecGraphNode[] {
|
|
199
|
+
return this.rootNodes;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
setActiveModuleName(moduleName: string | undefined): ExecGraph {
|
|
203
|
+
if (moduleName) this.activeModuleName = moduleName;
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getActiveModuleName(): string | undefined {
|
|
208
|
+
return this.activeModuleName;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
getParentGraph(): ExecGraph | undefined {
|
|
212
|
+
return this.parentGraph;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
setHasAgents(flag: boolean): ExecGraph {
|
|
216
|
+
this.hasAgentsFlag = flag;
|
|
217
|
+
if (this.parentGraph) {
|
|
218
|
+
this.parentGraph.setHasAgents(flag);
|
|
219
|
+
}
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
hasAgents(): boolean {
|
|
224
|
+
return this.hasAgentsFlag;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
canCache(): boolean {
|
|
228
|
+
return !this.hasAgentsFlag;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
setIsLoopBody(): ExecGraph {
|
|
232
|
+
this.loopBody = true;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
isLoopBody(): boolean {
|
|
237
|
+
return this.loopBody;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
asObject(): any[] {
|
|
241
|
+
const nodeObjs = new Array<any>();
|
|
242
|
+
this.rootNodes.forEach((node: ExecGraphNode) => {
|
|
243
|
+
const n = node.asObject();
|
|
244
|
+
if (node.subGraphIndex >= 0) {
|
|
245
|
+
const g = this.subGraphs[node.subGraphIndex];
|
|
246
|
+
const gobj = g.asObject();
|
|
247
|
+
if (node.subGraphType == SubGraphType.FOR_EACH) {
|
|
248
|
+
const stmt = node.code as Statement;
|
|
249
|
+
n.var = stmt.pattern.forEach?.var;
|
|
250
|
+
n.source = gobj;
|
|
251
|
+
n.body = g.fetchForEachBodySubGraph().asObject();
|
|
252
|
+
} else if (node.subGraphType == SubGraphType.IF) {
|
|
253
|
+
n.condition = gobj;
|
|
254
|
+
n.body = g.fetchIfConsequentSubGraph().asObject();
|
|
255
|
+
const a = g.fetchIfAlternativeSubGraph();
|
|
256
|
+
if (a) {
|
|
257
|
+
n.else = a.asObject();
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
n.subGraph = gobj;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
nodeObjs.push(n);
|
|
264
|
+
});
|
|
265
|
+
return nodeObjs;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export class ExecGraphWalker {
|
|
270
|
+
private offset = 0;
|
|
271
|
+
private maxOffset: number;
|
|
272
|
+
private rootNodes;
|
|
273
|
+
|
|
274
|
+
constructor(execGraph: ExecGraph) {
|
|
275
|
+
this.rootNodes = execGraph.getRootNodes();
|
|
276
|
+
this.maxOffset = this.rootNodes.length;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
hasNext(): boolean {
|
|
280
|
+
return this.offset < this.maxOffset;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
nextNode(): ExecGraphNode {
|
|
284
|
+
if (this.offset < this.maxOffset) {
|
|
285
|
+
return this.rootNodes[this.offset++];
|
|
286
|
+
}
|
|
287
|
+
throw new Error('End of execution-graph');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
currentNode(): ExecGraphNode {
|
|
291
|
+
if (this.offset > 0) {
|
|
292
|
+
return this.rootNodes[this.offset - 1];
|
|
293
|
+
} else {
|
|
294
|
+
return this.rootNodes[0];
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
reset(): ExecGraphWalker {
|
|
299
|
+
this.offset = 0;
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
}
|