agentlang 0.0.18 → 0.0.20
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/out/cli/main.d.ts.map +1 -1
- package/out/cli/main.js +35 -6
- package/out/cli/main.js.map +1 -1
- package/out/language/generated/ast.d.ts +23 -4
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +29 -1
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/generated/grammar.d.ts.map +1 -1
- package/out/language/generated/grammar.js +251 -171
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/main.cjs +271 -172
- package/out/language/main.cjs.map +2 -2
- package/out/language/parser.d.ts +1 -0
- package/out/language/parser.d.ts.map +1 -1
- package/out/language/parser.js +25 -9
- package/out/language/parser.js.map +1 -1
- package/out/runtime/agents/common.d.ts +1 -1
- package/out/runtime/agents/common.d.ts.map +1 -1
- package/out/runtime/agents/common.js +4 -1
- package/out/runtime/agents/common.js.map +1 -1
- package/out/runtime/agents/impl/anthropic.d.ts +54 -0
- package/out/runtime/agents/impl/anthropic.d.ts.map +1 -1
- package/out/runtime/agents/impl/anthropic.js +109 -3
- package/out/runtime/agents/impl/anthropic.js.map +1 -1
- package/out/runtime/auth/cognito.d.ts +1 -1
- package/out/runtime/auth/cognito.d.ts.map +1 -1
- package/out/runtime/auth/cognito.js +1 -1
- package/out/runtime/auth/cognito.js.map +1 -1
- package/out/runtime/defs.d.ts +4 -0
- package/out/runtime/defs.d.ts.map +1 -1
- package/out/runtime/defs.js +8 -0
- package/out/runtime/defs.js.map +1 -1
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +87 -25
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/jsmodules.d.ts +0 -1
- package/out/runtime/jsmodules.d.ts.map +1 -1
- package/out/runtime/jsmodules.js +26 -34
- package/out/runtime/jsmodules.js.map +1 -1
- package/out/runtime/loader.d.ts.map +1 -1
- package/out/runtime/loader.js +58 -50
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/module.d.ts +2 -2
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +19 -3
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts +1 -0
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +7 -1
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/modules/core.js +1 -1
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/openapi.d.ts +16 -0
- package/out/runtime/openapi.d.ts.map +1 -0
- package/out/runtime/openapi.js +51 -0
- package/out/runtime/openapi.js.map +1 -0
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js +11 -5
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/registry.d.ts +1 -2
- package/out/runtime/resolvers/registry.d.ts.map +1 -1
- package/out/runtime/resolvers/registry.js +2 -1
- package/out/runtime/resolvers/registry.js.map +1 -1
- package/out/runtime/state.d.ts +23 -0
- package/out/runtime/state.d.ts.map +1 -1
- package/out/runtime/state.js +7 -0
- package/out/runtime/state.js.map +1 -1
- package/out/runtime/util.d.ts +1 -0
- package/out/runtime/util.d.ts.map +1 -1
- package/out/runtime/util.js +20 -0
- package/out/runtime/util.js.map +1 -1
- package/out/syntaxes/agentlang.monarch.js +1 -1
- package/out/syntaxes/agentlang.monarch.js.map +1 -1
- package/package.json +3 -6
- package/src/cli/main.ts +34 -6
- package/src/language/agentlang.langium +9 -3
- package/src/language/generated/ast.ts +55 -4
- package/src/language/generated/grammar.ts +251 -171
- package/src/language/parser.ts +30 -9
- package/src/runtime/agents/common.ts +4 -1
- package/src/runtime/agents/impl/anthropic.ts +190 -4
- package/src/runtime/auth/cognito.ts +1 -1
- package/src/runtime/defs.ts +12 -0
- package/src/runtime/interpreter.ts +87 -24
- package/src/runtime/jsmodules.ts +26 -37
- package/src/runtime/loader.ts +63 -55
- package/src/runtime/module.ts +27 -3
- package/src/runtime/modules/ai.ts +8 -2
- package/src/runtime/modules/core.ts +1 -1
- package/src/runtime/openapi.ts +74 -0
- package/src/runtime/resolvers/interface.ts +14 -9
- package/src/runtime/resolvers/registry.ts +3 -2
- package/src/runtime/state.ts +9 -0
- package/src/runtime/util.ts +22 -0
- package/src/syntaxes/agentlang.monarch.ts +1 -1
- package/out/cli/docs.d.ts +0 -2
- package/out/cli/docs.d.ts.map +0 -1
- package/out/cli/docs.js +0 -236
- package/out/cli/docs.js.map +0 -1
- package/out/cli/openapi-docs.yml +0 -695
- package/out/index.d.ts +0 -19
- package/out/index.d.ts.map +0 -1
- package/out/index.js +0 -25
- package/out/index.js.map +0 -1
package/src/cli/main.ts
CHANGED
|
@@ -24,6 +24,9 @@ import { ModuleDefinition } from '../language/generated/ast.js';
|
|
|
24
24
|
import { z } from 'zod';
|
|
25
25
|
import { Config, setAppConfig } from '../runtime/state.js';
|
|
26
26
|
import { prepareIntegrations } from '../runtime/integrations.js';
|
|
27
|
+
import { isNodeEnv } from '../utils/runtime.js';
|
|
28
|
+
import { OpenAPIClientAxios } from 'openapi-client-axios';
|
|
29
|
+
import { registerOpenApiModule } from '../runtime/openapi.js';
|
|
27
30
|
|
|
28
31
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
29
32
|
|
|
@@ -115,6 +118,9 @@ export const runModule = async (fileName: string): Promise<void> => {
|
|
|
115
118
|
config.integrations.connections
|
|
116
119
|
);
|
|
117
120
|
}
|
|
121
|
+
if (config.openapi) {
|
|
122
|
+
await loadOpenApiSpec(config.openapi);
|
|
123
|
+
}
|
|
118
124
|
} catch (err) {
|
|
119
125
|
if (err instanceof z.ZodError) {
|
|
120
126
|
console.log(chalk.red('Config validation failed:'));
|
|
@@ -127,13 +133,21 @@ export const runModule = async (fileName: string): Promise<void> => {
|
|
|
127
133
|
throw err;
|
|
128
134
|
}
|
|
129
135
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
try {
|
|
137
|
+
const r: boolean = await runPreInitTasks();
|
|
138
|
+
if (!r) {
|
|
139
|
+
throw new Error('Failed to initialize runtime');
|
|
140
|
+
}
|
|
141
|
+
await load(fileName, undefined, async (appSpec?: ApplicationSpec) => {
|
|
142
|
+
await runPostInitTasks(appSpec, config);
|
|
143
|
+
});
|
|
144
|
+
} catch (err: any) {
|
|
145
|
+
if (isNodeEnv && chalk) {
|
|
146
|
+
console.error(chalk.red(err));
|
|
147
|
+
} else {
|
|
148
|
+
console.error(err);
|
|
149
|
+
}
|
|
133
150
|
}
|
|
134
|
-
await load(fileName, undefined, async (appSpec?: ApplicationSpec) => {
|
|
135
|
-
await runPostInitTasks(appSpec, config);
|
|
136
|
-
});
|
|
137
151
|
};
|
|
138
152
|
|
|
139
153
|
export async function internAndRunModule(
|
|
@@ -148,3 +162,17 @@ export async function internAndRunModule(
|
|
|
148
162
|
await runPostInitTasks(appSpec);
|
|
149
163
|
return rm;
|
|
150
164
|
}
|
|
165
|
+
|
|
166
|
+
async function loadOpenApiSpec(openApiConfig: any[]) {
|
|
167
|
+
for (let i = 0; i < openApiConfig.length; ++i) {
|
|
168
|
+
const cfg: any = openApiConfig[i];
|
|
169
|
+
const api = new OpenAPIClientAxios({ definition: cfg.specUrl });
|
|
170
|
+
await api.init();
|
|
171
|
+
const client = await api.getClient();
|
|
172
|
+
client.defaults.baseURL = cfg.baseUrl
|
|
173
|
+
? cfg.baseUrl
|
|
174
|
+
: cfg.specUrl.substring(0, cfg.specUrl.lastIndexOf('/'));
|
|
175
|
+
const n = await registerOpenApiModule(cfg.name, { api: api, client: client });
|
|
176
|
+
logger.info(`OpenAPI module '${n}' registered`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -92,7 +92,11 @@ Literal: (id=ID | num=Decimal | str=STRING | ref=Ref | bool=Boolean | fnCall=FnC
|
|
|
92
92
|
|
|
93
93
|
fragment Body: '{' '}' | '{' (statements+=Statement (';' statements+=Statement)*)+ '}' | '{' statements+=Statement ';'+ '}' | statements+=Statement;
|
|
94
94
|
|
|
95
|
-
WorkflowDefinition: 'workflow' name=ID Body
|
|
95
|
+
WorkflowDefinition: 'workflow' name=ID Body hints+=WorkflowHint*;
|
|
96
|
+
|
|
97
|
+
WorkflowHint: subs=WorkflowSubsHint;
|
|
98
|
+
|
|
99
|
+
WorkflowSubsHint: '@subs' '(' resolverName=ID ')';
|
|
96
100
|
|
|
97
101
|
Pattern: expr=Expr | crudMap=CrudMap | if=If | forEach=ForEach | delete=Delete | purge=Purge | fullTextSearch=FullTextSearch | return=Return;
|
|
98
102
|
|
|
@@ -123,13 +127,13 @@ FullTextSearch: '{' name=QueryId query=Literal options=MapLiteral? '}';
|
|
|
123
127
|
|
|
124
128
|
Return: 'return' pat=Pattern;
|
|
125
129
|
|
|
126
|
-
AgentDefinition: 'agent' name=
|
|
130
|
+
AgentDefinition: 'agent' name=GenericName (body=AgentDefBody? | '{''}');
|
|
127
131
|
|
|
128
132
|
AgentDefBody: '{' (attributes+=AgentPropertyDef (',' attributes+=AgentPropertyDef)*)+ '}';
|
|
129
133
|
|
|
130
134
|
AgentPropertyDef: name=ID value=Literal;
|
|
131
135
|
|
|
132
|
-
ResolverDefinition: 'resolver' name=
|
|
136
|
+
ResolverDefinition: 'resolver' name=GenericName '[' (paths+=GenericName (',' paths+=GenericName)*)+ ']'
|
|
133
137
|
'{' (methods+=ResolverMethodSpec (',' methods+=ResolverMethodSpec)*)+ '}';
|
|
134
138
|
|
|
135
139
|
ResolverMethodSpec: key=ResolverMethodName fn=ResolverFnName;
|
|
@@ -193,6 +197,8 @@ Ref returns string: ID '.' (Ref | ID);
|
|
|
193
197
|
|
|
194
198
|
QualifiedName returns string: Ref | ID;
|
|
195
199
|
|
|
200
|
+
GenericName returns string: ID | STRING;
|
|
201
|
+
|
|
196
202
|
terminal ID returns string: NAME ('/' NAME)?;
|
|
197
203
|
|
|
198
204
|
// recognize an identifier
|
|
@@ -52,6 +52,7 @@ export type AgentlangKeywordNames =
|
|
|
52
52
|
| "@oneof"
|
|
53
53
|
| "@rbac"
|
|
54
54
|
| "@ref"
|
|
55
|
+
| "@subs"
|
|
55
56
|
| "@then"
|
|
56
57
|
| "@upsert"
|
|
57
58
|
| "@with_unique"
|
|
@@ -136,6 +137,12 @@ export function isExpr(item: unknown): item is Expr {
|
|
|
136
137
|
return reflection.isInstance(item, Expr);
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
export type GenericName = string;
|
|
141
|
+
|
|
142
|
+
export function isGenericName(item: unknown): item is GenericName {
|
|
143
|
+
return (typeof item === 'string' && (/(([_a-zA-Z][\w_]*)(\/([_a-zA-Z][\w_]*))?)/.test(item) || /("(((\\([\s\S]))|((?!(((\\|")|\r)|\n))[\s\S]*?))|(\r?\n))*")/.test(item)));
|
|
144
|
+
}
|
|
145
|
+
|
|
139
146
|
export type PrimExpr = Group | Literal | NegExpr | NotExpr;
|
|
140
147
|
|
|
141
148
|
export const PrimExpr = 'PrimExpr';
|
|
@@ -217,7 +224,7 @@ export interface AgentDefinition extends langium.AstNode {
|
|
|
217
224
|
readonly $container: ModuleDefinition;
|
|
218
225
|
readonly $type: 'AgentDefinition';
|
|
219
226
|
body?: AgentDefBody;
|
|
220
|
-
name:
|
|
227
|
+
name: GenericName;
|
|
221
228
|
}
|
|
222
229
|
|
|
223
230
|
export const AgentDefinition = 'AgentDefinition';
|
|
@@ -960,8 +967,8 @@ export interface ResolverDefinition extends langium.AstNode {
|
|
|
960
967
|
readonly $container: ModuleDefinition;
|
|
961
968
|
readonly $type: 'ResolverDefinition';
|
|
962
969
|
methods: Array<ResolverMethodSpec>;
|
|
963
|
-
name:
|
|
964
|
-
paths: Array<
|
|
970
|
+
name: GenericName;
|
|
971
|
+
paths: Array<GenericName>;
|
|
965
972
|
}
|
|
966
973
|
|
|
967
974
|
export const ResolverDefinition = 'ResolverDefinition';
|
|
@@ -1138,6 +1145,7 @@ export function isTriggerEntry(item: unknown): item is TriggerEntry {
|
|
|
1138
1145
|
export interface WorkflowDefinition extends langium.AstNode {
|
|
1139
1146
|
readonly $container: ModuleDefinition;
|
|
1140
1147
|
readonly $type: 'WorkflowDefinition';
|
|
1148
|
+
hints: Array<WorkflowHint>;
|
|
1141
1149
|
name: string;
|
|
1142
1150
|
statements: Array<Statement>;
|
|
1143
1151
|
}
|
|
@@ -1148,6 +1156,30 @@ export function isWorkflowDefinition(item: unknown): item is WorkflowDefinition
|
|
|
1148
1156
|
return reflection.isInstance(item, WorkflowDefinition);
|
|
1149
1157
|
}
|
|
1150
1158
|
|
|
1159
|
+
export interface WorkflowHint extends langium.AstNode {
|
|
1160
|
+
readonly $container: WorkflowDefinition;
|
|
1161
|
+
readonly $type: 'WorkflowHint';
|
|
1162
|
+
subs: WorkflowSubsHint;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
export const WorkflowHint = 'WorkflowHint';
|
|
1166
|
+
|
|
1167
|
+
export function isWorkflowHint(item: unknown): item is WorkflowHint {
|
|
1168
|
+
return reflection.isInstance(item, WorkflowHint);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
export interface WorkflowSubsHint extends langium.AstNode {
|
|
1172
|
+
readonly $container: WorkflowHint;
|
|
1173
|
+
readonly $type: 'WorkflowSubsHint';
|
|
1174
|
+
resolverName: string;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
export const WorkflowSubsHint = 'WorkflowSubsHint';
|
|
1178
|
+
|
|
1179
|
+
export function isWorkflowSubsHint(item: unknown): item is WorkflowSubsHint {
|
|
1180
|
+
return reflection.isInstance(item, WorkflowSubsHint);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1151
1183
|
export type AgentlangAstType = {
|
|
1152
1184
|
ActionEntry: ActionEntry
|
|
1153
1185
|
AfterTriggerDefinition: AfterTriggerDefinition
|
|
@@ -1228,12 +1260,14 @@ export type AgentlangAstType = {
|
|
|
1228
1260
|
TriggerDefinition: TriggerDefinition
|
|
1229
1261
|
TriggerEntry: TriggerEntry
|
|
1230
1262
|
WorkflowDefinition: WorkflowDefinition
|
|
1263
|
+
WorkflowHint: WorkflowHint
|
|
1264
|
+
WorkflowSubsHint: WorkflowSubsHint
|
|
1231
1265
|
}
|
|
1232
1266
|
|
|
1233
1267
|
export class AgentlangAstReflection extends langium.AbstractAstReflection {
|
|
1234
1268
|
|
|
1235
1269
|
getAllTypes(): string[] {
|
|
1236
|
-
return [ActionEntry, AfterTriggerDefinition, AgentDefBody, AgentDefinition, AgentPropertyDef, AliasSpec, ArrayLiteral, AsyncFnCall, AttributeDefinition, AttributeValueExpression, BeforeTriggerDefinition, BinExpr, CatchSpec, CompositeUniqueDefinition, CrudMap, CrudMapBody, Definition, Delete, Else, EntityActionsDefinitions, EntityDefinition, EnumSpec, EventDefinition, Expr, ExtendsClause, FnCall, ForEach, FullTextSearch, Group, Handler, If, Import, KvPair, KvPairs, Literal, MapEntry, MapKey, MapLiteral, MetaDefinition, ModuleDefinition, NegExpr, NodeDefinition, NotExpr, OneOfSpec, Pattern, PrePostTriggerDefinition, PrimExpr, PropertyDefinition, Purge, RbacAllowSpec, RbacExpressionSpec, RbacOpr, RbacRolesSpec, RbacSpecDefinition, RbacSpecEntries, RbacSpecEntry, RecordDefinition, RecordExtraDefinition, RecordSchemaDefinition, RefSpec, RelNodes, RelationshipDefinition, RelationshipPattern, ResolverDefinition, ResolverFnName, ResolverMethodName, ResolverMethodSpec, Return, RuntimeHint, SchemaDefinition, SelectIntoEntry, SelectIntoSpec, SetAttribute, StandaloneStatement, Statement, ThenSpec, TriggerDefinition, TriggerEntry, WorkflowDefinition];
|
|
1270
|
+
return [ActionEntry, AfterTriggerDefinition, AgentDefBody, AgentDefinition, AgentPropertyDef, AliasSpec, ArrayLiteral, AsyncFnCall, AttributeDefinition, AttributeValueExpression, BeforeTriggerDefinition, BinExpr, CatchSpec, CompositeUniqueDefinition, CrudMap, CrudMapBody, Definition, Delete, Else, EntityActionsDefinitions, EntityDefinition, EnumSpec, EventDefinition, Expr, ExtendsClause, FnCall, ForEach, FullTextSearch, Group, Handler, If, Import, KvPair, KvPairs, Literal, MapEntry, MapKey, MapLiteral, MetaDefinition, ModuleDefinition, NegExpr, NodeDefinition, NotExpr, OneOfSpec, Pattern, PrePostTriggerDefinition, PrimExpr, PropertyDefinition, Purge, RbacAllowSpec, RbacExpressionSpec, RbacOpr, RbacRolesSpec, RbacSpecDefinition, RbacSpecEntries, RbacSpecEntry, RecordDefinition, RecordExtraDefinition, RecordSchemaDefinition, RefSpec, RelNodes, RelationshipDefinition, RelationshipPattern, ResolverDefinition, ResolverFnName, ResolverMethodName, ResolverMethodSpec, Return, RuntimeHint, SchemaDefinition, SelectIntoEntry, SelectIntoSpec, SetAttribute, StandaloneStatement, Statement, ThenSpec, TriggerDefinition, TriggerEntry, WorkflowDefinition, WorkflowHint, WorkflowSubsHint];
|
|
1237
1271
|
}
|
|
1238
1272
|
|
|
1239
1273
|
protected override computeIsSubtype(subtype: string, supertype: string): boolean {
|
|
@@ -1953,11 +1987,28 @@ export class AgentlangAstReflection extends langium.AbstractAstReflection {
|
|
|
1953
1987
|
return {
|
|
1954
1988
|
name: WorkflowDefinition,
|
|
1955
1989
|
properties: [
|
|
1990
|
+
{ name: 'hints', defaultValue: [] },
|
|
1956
1991
|
{ name: 'name' },
|
|
1957
1992
|
{ name: 'statements', defaultValue: [] }
|
|
1958
1993
|
]
|
|
1959
1994
|
};
|
|
1960
1995
|
}
|
|
1996
|
+
case WorkflowHint: {
|
|
1997
|
+
return {
|
|
1998
|
+
name: WorkflowHint,
|
|
1999
|
+
properties: [
|
|
2000
|
+
{ name: 'subs' }
|
|
2001
|
+
]
|
|
2002
|
+
};
|
|
2003
|
+
}
|
|
2004
|
+
case WorkflowSubsHint: {
|
|
2005
|
+
return {
|
|
2006
|
+
name: WorkflowSubsHint,
|
|
2007
|
+
properties: [
|
|
2008
|
+
{ name: 'resolverName' }
|
|
2009
|
+
]
|
|
2010
|
+
};
|
|
2011
|
+
}
|
|
1961
2012
|
default: {
|
|
1962
2013
|
return {
|
|
1963
2014
|
name: type,
|