agentlang 0.10.2 → 0.10.4
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 +7 -14
- package/out/api/http.d.ts +4 -0
- package/out/api/http.d.ts.map +1 -1
- package/out/api/http.js +171 -26
- package/out/api/http.js.map +1 -1
- package/out/cli/main.d.ts.map +1 -1
- package/out/cli/main.js +3 -0
- package/out/cli/main.js.map +1 -1
- package/out/extension/main.cjs +250 -250
- package/out/extension/main.cjs.map +2 -2
- package/out/language/agentlang-validator.d.ts.map +1 -1
- package/out/language/agentlang-validator.js +4 -0
- package/out/language/agentlang-validator.js.map +1 -1
- package/out/language/error-reporter.d.ts +53 -0
- package/out/language/error-reporter.d.ts.map +1 -0
- package/out/language/error-reporter.js +879 -0
- package/out/language/error-reporter.js.map +1 -0
- package/out/language/generated/ast.d.ts +66 -6
- package/out/language/generated/ast.d.ts.map +1 -1
- package/out/language/generated/ast.js +48 -0
- 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 +320 -190
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/main.cjs +870 -694
- package/out/language/main.cjs.map +3 -3
- package/out/language/parser.d.ts +4 -2
- package/out/language/parser.d.ts.map +1 -1
- package/out/language/parser.js +31 -98
- package/out/language/parser.js.map +1 -1
- package/out/language/syntax.d.ts +2 -0
- package/out/language/syntax.d.ts.map +1 -1
- package/out/language/syntax.js +6 -0
- package/out/language/syntax.js.map +1 -1
- package/out/runtime/api.d.ts.map +1 -1
- package/out/runtime/api.js +22 -0
- package/out/runtime/api.js.map +1 -1
- package/out/runtime/defs.d.ts +1 -0
- package/out/runtime/defs.d.ts.map +1 -1
- package/out/runtime/defs.js +2 -1
- package/out/runtime/defs.js.map +1 -1
- package/out/runtime/document-retriever.d.ts +24 -0
- package/out/runtime/document-retriever.d.ts.map +1 -0
- package/out/runtime/document-retriever.js +258 -0
- package/out/runtime/document-retriever.js.map +1 -0
- package/out/runtime/embeddings/chunker.d.ts +18 -0
- package/out/runtime/embeddings/chunker.d.ts.map +1 -1
- package/out/runtime/embeddings/chunker.js +47 -15
- package/out/runtime/embeddings/chunker.js.map +1 -1
- package/out/runtime/embeddings/openai.d.ts.map +1 -1
- package/out/runtime/embeddings/openai.js +22 -9
- package/out/runtime/embeddings/openai.js.map +1 -1
- package/out/runtime/embeddings/provider.d.ts +1 -0
- package/out/runtime/embeddings/provider.d.ts.map +1 -1
- package/out/runtime/embeddings/provider.js +20 -1
- package/out/runtime/embeddings/provider.js.map +1 -1
- package/out/runtime/integration-client.d.ts +21 -0
- package/out/runtime/integration-client.d.ts.map +1 -0
- package/out/runtime/integration-client.js +112 -0
- package/out/runtime/integration-client.js.map +1 -0
- package/out/runtime/integrations.d.ts.map +1 -1
- package/out/runtime/integrations.js +20 -9
- package/out/runtime/integrations.js.map +1 -1
- package/out/runtime/interpreter.d.ts +1 -0
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +172 -19
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/loader.d.ts.map +1 -1
- package/out/runtime/loader.js +70 -7
- package/out/runtime/loader.js.map +1 -1
- package/out/runtime/logger.d.ts.map +1 -1
- package/out/runtime/logger.js +8 -1
- package/out/runtime/logger.js.map +1 -1
- package/out/runtime/module.d.ts +10 -0
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +68 -3
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts +9 -2
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +219 -67
- package/out/runtime/modules/ai.js.map +1 -1
- package/out/runtime/modules/core.d.ts.map +1 -1
- package/out/runtime/modules/core.js +3 -0
- package/out/runtime/modules/core.js.map +1 -1
- package/out/runtime/modules/messaging.d.ts +10 -0
- package/out/runtime/modules/messaging.d.ts.map +1 -0
- package/out/runtime/modules/messaging.js +210 -0
- package/out/runtime/modules/messaging.js.map +1 -0
- package/out/runtime/resolvers/interface.d.ts +4 -0
- package/out/runtime/resolvers/interface.d.ts.map +1 -1
- package/out/runtime/resolvers/interface.js +14 -1
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.d.ts +2 -0
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +142 -126
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/dbutil.js +8 -0
- package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.d.ts +1 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +7 -0
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/resolvers/vector/lancedb-store.d.ts +16 -0
- package/out/runtime/resolvers/vector/lancedb-store.d.ts.map +1 -0
- package/out/runtime/resolvers/vector/lancedb-store.js +159 -0
- package/out/runtime/resolvers/vector/lancedb-store.js.map +1 -0
- package/out/runtime/resolvers/vector/types.d.ts +32 -0
- package/out/runtime/resolvers/vector/types.d.ts.map +1 -0
- package/out/runtime/resolvers/vector/types.js +2 -0
- package/out/runtime/resolvers/vector/types.js.map +1 -0
- package/out/runtime/services/documentFetcher.d.ts.map +1 -1
- package/out/runtime/services/documentFetcher.js +21 -6
- package/out/runtime/services/documentFetcher.js.map +1 -1
- package/out/runtime/state.d.ts +19 -1
- package/out/runtime/state.d.ts.map +1 -1
- package/out/runtime/state.js +36 -1
- package/out/runtime/state.js.map +1 -1
- package/out/syntaxes/agentlang.monarch.js +1 -1
- package/out/syntaxes/agentlang.monarch.js.map +1 -1
- package/package.json +19 -19
- package/src/api/http.ts +197 -37
- package/src/cli/main.ts +3 -0
- package/src/language/agentlang-validator.ts +3 -0
- package/src/language/agentlang.langium +3 -1
- package/src/language/error-reporter.ts +1028 -0
- package/src/language/generated/ast.ts +77 -5
- package/src/language/generated/grammar.ts +320 -190
- package/src/language/parser.ts +31 -100
- package/src/language/syntax.ts +8 -0
- package/src/runtime/api.ts +31 -0
- package/src/runtime/defs.ts +2 -1
- package/src/runtime/document-retriever.ts +311 -0
- package/src/runtime/embeddings/chunker.ts +52 -14
- package/src/runtime/embeddings/openai.ts +27 -9
- package/src/runtime/embeddings/provider.ts +22 -1
- package/src/runtime/integration-client.ts +158 -0
- package/src/runtime/integrations.ts +20 -11
- package/src/runtime/interpreter.ts +164 -14
- package/src/runtime/loader.ts +83 -5
- package/src/runtime/logger.ts +12 -1
- package/src/runtime/module.ts +78 -3
- package/src/runtime/modules/ai.ts +263 -76
- package/src/runtime/modules/core.ts +4 -0
- package/src/runtime/modules/messaging.ts +228 -0
- package/src/runtime/resolvers/interface.ts +19 -1
- package/src/runtime/resolvers/sqldb/database.ts +158 -130
- package/src/runtime/resolvers/sqldb/dbutil.ts +8 -0
- package/src/runtime/resolvers/sqldb/impl.ts +8 -0
- package/src/runtime/resolvers/vector/lancedb-store.ts +187 -0
- package/src/runtime/resolvers/vector/types.ts +39 -0
- package/src/runtime/services/documentFetcher.ts +21 -6
- package/src/runtime/state.ts +40 -1
- package/src/syntaxes/agentlang.monarch.ts +1 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { makeCoreModuleName } from '../util.js';
|
|
2
|
+
import { Instance } from '../module.js';
|
|
3
|
+
import { GenericResolver, Resolver } from '../resolvers/interface.js';
|
|
4
|
+
import { registerResolver, setResolver } from '../resolvers/registry.js';
|
|
5
|
+
import { logger } from '../logger.js';
|
|
6
|
+
|
|
7
|
+
export const CoreMessagingModuleName = makeCoreModuleName('messaging');
|
|
8
|
+
|
|
9
|
+
function getAgentManagerUrl(): string {
|
|
10
|
+
return (
|
|
11
|
+
(globalThis as any).__agentmanager_url ||
|
|
12
|
+
process.env.AGENTMANAGER_URL ||
|
|
13
|
+
'http://localhost:3001'
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function pushNotification(_: Resolver, inst: Instance) {
|
|
18
|
+
const inbox = inst.lookup('inbox');
|
|
19
|
+
const subject = inst.lookup('subject');
|
|
20
|
+
const body = inst.lookup('body');
|
|
21
|
+
const fromKind = inst.lookup('fromKind') || 'employee';
|
|
22
|
+
const fromId = inst.lookup('fromId');
|
|
23
|
+
|
|
24
|
+
const url = `${getAgentManagerUrl()}/api/inboxes/${encodeURIComponent(inbox)}/messages`;
|
|
25
|
+
const payload = {
|
|
26
|
+
from: { kind: fromKind, id: fromId },
|
|
27
|
+
subject,
|
|
28
|
+
body,
|
|
29
|
+
kind: 'notification',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const response = await fetch(url, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
body: JSON.stringify(payload),
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
const text = await response.text();
|
|
40
|
+
logger.error(
|
|
41
|
+
`Failed to push notification to inbox ${inbox}: HTTP ${response.status} — ${text}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return inst;
|
|
45
|
+
} catch (err: any) {
|
|
46
|
+
logger.error(`Failed to push notification to inbox ${inbox}: ${err.message}`);
|
|
47
|
+
return inst;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function pushAction(_: Resolver, inst: Instance) {
|
|
52
|
+
const inbox = inst.lookup('inbox');
|
|
53
|
+
const subject = inst.lookup('subject');
|
|
54
|
+
const body = inst.lookup('body');
|
|
55
|
+
const fromKind = inst.lookup('fromKind') || 'employee';
|
|
56
|
+
const fromId = inst.lookup('fromId');
|
|
57
|
+
const responses: string[] = inst.lookup('responses') || [];
|
|
58
|
+
const continuationEvents: string[] = inst.lookup('continuationEvents') || [];
|
|
59
|
+
const inputPrompt: string | undefined = inst.lookup('inputPrompt');
|
|
60
|
+
|
|
61
|
+
// Zip responses and continuationEvents into a continuations map
|
|
62
|
+
const continuations: Record<string, { event: string }> = {};
|
|
63
|
+
for (let i = 0; i < responses.length; i++) {
|
|
64
|
+
const eventName = i < continuationEvents.length ? continuationEvents[i] : '';
|
|
65
|
+
if (eventName) {
|
|
66
|
+
continuations[responses[i]] = { event: eventName };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const url = `${getAgentManagerUrl()}/api/inboxes/${encodeURIComponent(inbox)}/messages`;
|
|
71
|
+
const payload: any = {
|
|
72
|
+
from: { kind: fromKind, id: fromId },
|
|
73
|
+
subject,
|
|
74
|
+
body,
|
|
75
|
+
kind: 'action',
|
|
76
|
+
action: {
|
|
77
|
+
responses,
|
|
78
|
+
continuations,
|
|
79
|
+
...(inputPrompt ? { inputPrompt } : {}),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const response = await fetch(url, {
|
|
85
|
+
method: 'POST',
|
|
86
|
+
headers: { 'Content-Type': 'application/json' },
|
|
87
|
+
body: JSON.stringify(payload),
|
|
88
|
+
});
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
const text = await response.text();
|
|
91
|
+
logger.error(`Failed to push action to inbox ${inbox}: HTTP ${response.status} — ${text}`);
|
|
92
|
+
}
|
|
93
|
+
return inst;
|
|
94
|
+
} catch (err: any) {
|
|
95
|
+
logger.error(`Failed to push action to inbox ${inbox}: ${err.message}`);
|
|
96
|
+
return inst;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function queryInbox(_: Resolver, inst: Instance, _queryAll: boolean) {
|
|
101
|
+
const inbox = inst.lookup('inbox');
|
|
102
|
+
const status: string | undefined = inst.lookup('status');
|
|
103
|
+
const kind: string | undefined = inst.lookup('kind');
|
|
104
|
+
const from: string | undefined = inst.lookup('from');
|
|
105
|
+
|
|
106
|
+
const params = new URLSearchParams();
|
|
107
|
+
if (status) params.set('status', status);
|
|
108
|
+
if (kind) params.set('kind', kind);
|
|
109
|
+
if (from) params.set('from', from);
|
|
110
|
+
|
|
111
|
+
const qs = params.toString();
|
|
112
|
+
const url = `${getAgentManagerUrl()}/api/inboxes/${encodeURIComponent(inbox)}/messages${qs ? '?' + qs : ''}`;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const response = await fetch(url);
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
const text = await response.text();
|
|
118
|
+
logger.error(`Failed to query inbox ${inbox}: HTTP ${response.status} — ${text}`);
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
return await response.json();
|
|
122
|
+
} catch (err: any) {
|
|
123
|
+
logger.error(`Failed to query inbox ${inbox}: ${err.message}`);
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default `module ${CoreMessagingModuleName}
|
|
129
|
+
|
|
130
|
+
record Notification {
|
|
131
|
+
inbox String,
|
|
132
|
+
subject String,
|
|
133
|
+
body String,
|
|
134
|
+
fromKind String @default("employee"),
|
|
135
|
+
fromId String
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
record Action {
|
|
139
|
+
inbox String,
|
|
140
|
+
subject String,
|
|
141
|
+
body String,
|
|
142
|
+
fromKind String @default("employee"),
|
|
143
|
+
fromId String,
|
|
144
|
+
responses String[],
|
|
145
|
+
continuationEvents String[] @optional,
|
|
146
|
+
inputPrompt String @optional
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
record InboxQuery {
|
|
150
|
+
inbox String,
|
|
151
|
+
status String @optional,
|
|
152
|
+
kind String @optional,
|
|
153
|
+
from String @optional
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@public event SendNotification extends Notification {}
|
|
157
|
+
workflow SendNotification {
|
|
158
|
+
{Notification {inbox SendNotification.inbox,
|
|
159
|
+
subject SendNotification.subject,
|
|
160
|
+
body SendNotification.body,
|
|
161
|
+
fromKind SendNotification.fromKind,
|
|
162
|
+
fromId SendNotification.fromId}}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@public event SendAction extends Action {}
|
|
166
|
+
workflow SendAction {
|
|
167
|
+
{Action {inbox SendAction.inbox,
|
|
168
|
+
subject SendAction.subject,
|
|
169
|
+
body SendAction.body,
|
|
170
|
+
fromKind SendAction.fromKind,
|
|
171
|
+
fromId SendAction.fromId,
|
|
172
|
+
responses SendAction.responses,
|
|
173
|
+
continuationEvents SendAction.continuationEvents,
|
|
174
|
+
inputPrompt SendAction.inputPrompt}}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@public event QueryInbox extends InboxQuery {}
|
|
178
|
+
workflow QueryInbox {
|
|
179
|
+
{InboxQuery {inbox? QueryInbox.inbox,
|
|
180
|
+
status? QueryInbox.status,
|
|
181
|
+
kind? QueryInbox.kind,
|
|
182
|
+
from? QueryInbox.from}}
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
|
|
186
|
+
export function initMessagingModule() {
|
|
187
|
+
const resolverName = 'agentlang.messaging/messagingResolver';
|
|
188
|
+
const resolver = new GenericResolver(resolverName, {
|
|
189
|
+
create: pushNotification,
|
|
190
|
+
upsert: undefined,
|
|
191
|
+
update: undefined,
|
|
192
|
+
query: queryInbox,
|
|
193
|
+
delete: undefined,
|
|
194
|
+
startTransaction: undefined,
|
|
195
|
+
commitTransaction: undefined,
|
|
196
|
+
rollbackTransaction: undefined,
|
|
197
|
+
});
|
|
198
|
+
registerResolver(resolverName, () => resolver);
|
|
199
|
+
setResolver('agentlang.messaging/Notification', resolverName);
|
|
200
|
+
|
|
201
|
+
const actionResolverName = 'agentlang.messaging/actionResolver';
|
|
202
|
+
const actionResolver = new GenericResolver(actionResolverName, {
|
|
203
|
+
create: pushAction,
|
|
204
|
+
upsert: undefined,
|
|
205
|
+
update: undefined,
|
|
206
|
+
query: undefined,
|
|
207
|
+
delete: undefined,
|
|
208
|
+
startTransaction: undefined,
|
|
209
|
+
commitTransaction: undefined,
|
|
210
|
+
rollbackTransaction: undefined,
|
|
211
|
+
});
|
|
212
|
+
registerResolver(actionResolverName, () => actionResolver);
|
|
213
|
+
setResolver('agentlang.messaging/Action', actionResolverName);
|
|
214
|
+
|
|
215
|
+
const queryResolverName = 'agentlang.messaging/queryResolver';
|
|
216
|
+
const queryResolver = new GenericResolver(queryResolverName, {
|
|
217
|
+
create: undefined,
|
|
218
|
+
upsert: undefined,
|
|
219
|
+
update: undefined,
|
|
220
|
+
query: queryInbox,
|
|
221
|
+
delete: undefined,
|
|
222
|
+
startTransaction: undefined,
|
|
223
|
+
commitTransaction: undefined,
|
|
224
|
+
rollbackTransaction: undefined,
|
|
225
|
+
});
|
|
226
|
+
registerResolver(queryResolverName, () => queryResolver);
|
|
227
|
+
setResolver('agentlang.messaging/InboxQuery', queryResolverName);
|
|
228
|
+
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from '../module.js';
|
|
17
17
|
import { CrudType, nameToPath, generateLoggerCallId } from '../util.js';
|
|
18
18
|
import { DefaultAuthInfo, ResolverAuthInfo } from './authinfo.js';
|
|
19
|
+
import { getIntegrationAuthHeaders } from '../integration-client.js';
|
|
19
20
|
|
|
20
21
|
export type JoinInfo = {
|
|
21
22
|
relationship: Relationship;
|
|
@@ -43,6 +44,7 @@ export class Resolver {
|
|
|
43
44
|
protected authInfo: ResolverAuthInfo = DefaultAuthInfo;
|
|
44
45
|
protected env: Environment | undefined;
|
|
45
46
|
protected name: string = 'default';
|
|
47
|
+
protected integrationName: string | undefined;
|
|
46
48
|
|
|
47
49
|
static Default = new Resolver();
|
|
48
50
|
|
|
@@ -50,6 +52,20 @@ export class Resolver {
|
|
|
50
52
|
if (name) this.name = name;
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
public setIntegrationName(name: string): Resolver {
|
|
56
|
+
this.integrationName = name;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public getIntegrationName(): string | undefined {
|
|
61
|
+
return this.integrationName;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public async getAuthHeaders(): Promise<Record<string, string>> {
|
|
65
|
+
if (!this.integrationName) return {};
|
|
66
|
+
return getIntegrationAuthHeaders(this.integrationName);
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
public setAuthInfo(authInfo: ResolverAuthInfo): Resolver {
|
|
54
70
|
this.authInfo = authInfo;
|
|
55
71
|
return this;
|
|
@@ -131,7 +147,9 @@ export class Resolver {
|
|
|
131
147
|
inst: Instance,
|
|
132
148
|
connectedAlias?: string
|
|
133
149
|
): Promise<any> {
|
|
134
|
-
return this.notImpl(
|
|
150
|
+
return this.notImpl(
|
|
151
|
+
`queryConnectedInstances(${relationship}, ${connectedInstance}, ${inst}, ${connectedAlias})`
|
|
152
|
+
);
|
|
135
153
|
}
|
|
136
154
|
|
|
137
155
|
public async queryByJoin(
|