agentlang 0.0.21 → 0.0.23
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/runtime/agents/impl/openai.d.ts +1 -1
- package/out/runtime/agents/impl/openai.d.ts.map +1 -1
- package/out/runtime/agents/impl/openai.js +6 -1
- package/out/runtime/agents/impl/openai.js.map +1 -1
- package/out/runtime/agents/provider.d.ts +1 -1
- package/out/runtime/agents/provider.d.ts.map +1 -1
- package/out/runtime/agents/provider.js +5 -1
- package/out/runtime/agents/provider.js.map +1 -1
- package/out/runtime/defs.d.ts +0 -1
- package/out/runtime/defs.d.ts.map +1 -1
- package/out/runtime/defs.js +0 -1
- package/out/runtime/defs.js.map +1 -1
- package/out/runtime/docs.d.ts +3 -0
- package/out/runtime/docs.d.ts.map +1 -0
- package/out/runtime/docs.js +51 -0
- package/out/runtime/docs.js.map +1 -0
- package/out/runtime/integrations.js +1 -1
- package/out/runtime/interpreter.d.ts +3 -0
- package/out/runtime/interpreter.d.ts.map +1 -1
- package/out/runtime/interpreter.js +28 -5
- package/out/runtime/interpreter.js.map +1 -1
- package/out/runtime/jsmodules.js +1 -1
- package/out/runtime/jsmodules.js.map +1 -1
- package/out/runtime/module.d.ts +1 -1
- package/out/runtime/module.d.ts.map +1 -1
- package/out/runtime/module.js +9 -11
- package/out/runtime/module.js.map +1 -1
- package/out/runtime/modules/ai.d.ts +5 -0
- package/out/runtime/modules/ai.d.ts.map +1 -1
- package/out/runtime/modules/ai.js +70 -20
- package/out/runtime/modules/ai.js.map +1 -1
- 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 +23 -2
- package/out/runtime/resolvers/interface.js.map +1 -1
- package/out/runtime/resolvers/sqldb/database.js +1 -1
- package/out/runtime/resolvers/sqldb/database.js.map +1 -1
- package/out/runtime/resolvers/sqldb/impl.js +2 -2
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -1
- package/out/runtime/util.js +1 -1
- package/package.json +1 -1
- package/src/runtime/agents/impl/openai.ts +6 -1
- package/src/runtime/agents/provider.ts +6 -2
- package/src/runtime/defs.ts +0 -1
- package/src/runtime/docs.ts +57 -0
- package/src/runtime/integrations.ts +1 -1
- package/src/runtime/interpreter.ts +32 -4
- package/src/runtime/jsmodules.ts +1 -1
- package/src/runtime/module.ts +9 -17
- package/src/runtime/modules/ai.ts +77 -18
- package/src/runtime/resolvers/interface.ts +37 -2
- package/src/runtime/resolvers/sqldb/database.ts +1 -1
- package/src/runtime/resolvers/sqldb/impl.ts +2 -2
- package/src/runtime/util.ts +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getFileSystem } from '../utils/fs-utils.js';
|
|
2
|
+
import { logger } from './logger.js';
|
|
3
|
+
|
|
4
|
+
const DocFetchers = new Map<string, Function>();
|
|
5
|
+
|
|
6
|
+
export function registerDocFetcher(scheme: string, fetcher: Function): string {
|
|
7
|
+
DocFetchers.set(scheme, fetcher);
|
|
8
|
+
return scheme;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getDocFetcher(scheme: string): Function | undefined {
|
|
12
|
+
const f = DocFetchers.get(scheme);
|
|
13
|
+
if (f) {
|
|
14
|
+
return f;
|
|
15
|
+
}
|
|
16
|
+
logger.warn(`No fetcher for ${scheme}`);
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function fetchDoc(url: string): Promise<string | undefined> {
|
|
21
|
+
const idx = url.indexOf(':/');
|
|
22
|
+
const scheme = idx <= 0 ? 'file' : url.substring(0, idx);
|
|
23
|
+
const f = getDocFetcher(scheme);
|
|
24
|
+
if (f) return await f(url);
|
|
25
|
+
else return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function httpFetcher(url: string): Promise<string | undefined> {
|
|
29
|
+
try {
|
|
30
|
+
const response = await fetch(url, {
|
|
31
|
+
method: 'GET',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
logger.error(
|
|
36
|
+
`Failed to fetch document ${url}, HTTP error! status: ${response.status} ${response.text} ${response.statusText}`
|
|
37
|
+
);
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return await response.text();
|
|
41
|
+
} catch (reason: any) {
|
|
42
|
+
logger.error(`Failed to fetch document ${url}: ${reason}`);
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function fetchFile(path: string): Promise<string> {
|
|
48
|
+
const fs = await getFileSystem();
|
|
49
|
+
if (path.startsWith('.')) {
|
|
50
|
+
path = `${process.cwd()}${path.substring(1)}`;
|
|
51
|
+
}
|
|
52
|
+
return fs.readFile(path);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
registerDocFetcher('http', httpFetcher);
|
|
56
|
+
registerDocFetcher('https', httpFetcher);
|
|
57
|
+
registerDocFetcher('file', fetchFile);
|
|
@@ -51,7 +51,7 @@ async function loginToIntegManager(
|
|
|
51
51
|
): Promise<any> {
|
|
52
52
|
const defaultHdr = { 'Content-Type': 'application/json' };
|
|
53
53
|
if (username && password && username.length > 0) {
|
|
54
|
-
const apiUrl = `${host}/
|
|
54
|
+
const apiUrl = `${host}/agentlang.auth/login`;
|
|
55
55
|
const data = { email: username, password: password };
|
|
56
56
|
const response = await fetch(apiUrl, {
|
|
57
57
|
method: 'POST',
|
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
isFqName,
|
|
60
60
|
isPath,
|
|
61
61
|
isString,
|
|
62
|
+
makeCoreModuleName,
|
|
62
63
|
makeFqName,
|
|
63
64
|
Path,
|
|
64
65
|
QuerySuffix,
|
|
@@ -82,6 +83,7 @@ import {
|
|
|
82
83
|
} from './modules/core.js';
|
|
83
84
|
import { invokeModuleFn } from './jsmodules.js';
|
|
84
85
|
import { invokeOpenApiEvent, isOpenApiEventInstance } from './openapi.js';
|
|
86
|
+
import { fetchDoc } from './docs.js';
|
|
85
87
|
|
|
86
88
|
export type Result = any;
|
|
87
89
|
|
|
@@ -547,6 +549,10 @@ export async function evaluate(
|
|
|
547
549
|
}
|
|
548
550
|
await evaluateStatements(wf.statements, env, continuation);
|
|
549
551
|
return env.getLastResult();
|
|
552
|
+
} else if (isAgentEventInstance(eventInstance)) {
|
|
553
|
+
env = new Environment(eventInstance.name + '.env', activeEnv);
|
|
554
|
+
await handleAgentInvocation(eventInstance, env);
|
|
555
|
+
if (continuation) continuation(env.getLastResult());
|
|
550
556
|
} else if (isOpenApiEventInstance(eventInstance)) {
|
|
551
557
|
env = new Environment(eventInstance.name + '.env', activeEnv);
|
|
552
558
|
await handleOpenApiEvent(eventInstance, env);
|
|
@@ -1192,12 +1198,32 @@ async function evaluateCrudMap(crud: CrudMap, env: Environment): Promise<void> {
|
|
|
1192
1198
|
} else if (isEventInstance(inst)) {
|
|
1193
1199
|
if (isAgentEventInstance(inst)) await handleAgentInvocation(inst, env);
|
|
1194
1200
|
else if (isOpenApiEventInstance(inst)) await handleOpenApiEvent(inst, env);
|
|
1201
|
+
else if (isDocEventInstance(inst)) await handleDocEvent(inst, env);
|
|
1195
1202
|
else await evaluate(inst, (result: Result) => env.setLastResult(result), env);
|
|
1196
1203
|
} else {
|
|
1197
1204
|
env.setLastResult(inst);
|
|
1198
1205
|
}
|
|
1199
1206
|
}
|
|
1200
1207
|
|
|
1208
|
+
const CoreAIModuleName = makeCoreModuleName('ai');
|
|
1209
|
+
const DocEventName = `${CoreAIModuleName}/doc`;
|
|
1210
|
+
|
|
1211
|
+
function isDocEventInstance(inst: Instance): boolean {
|
|
1212
|
+
return isInstanceOfType(inst, DocEventName);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
async function handleDocEvent(inst: Instance, env: Environment): Promise<void> {
|
|
1216
|
+
const s = await fetchDoc(inst.lookup('url'));
|
|
1217
|
+
if (s) {
|
|
1218
|
+
const title = inst.lookup('title');
|
|
1219
|
+
await parseAndEvaluateStatement(
|
|
1220
|
+
`{${CoreAIModuleName}/Document {title "${title}", content "${s}"}}`,
|
|
1221
|
+
undefined,
|
|
1222
|
+
env
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1201
1227
|
function triggerTimer(timerInst: Instance): Instance {
|
|
1202
1228
|
const dur = timerInst.lookup('duration');
|
|
1203
1229
|
const unit = timerInst.lookup('unit');
|
|
@@ -1315,7 +1341,9 @@ const MAX_PLANNER_RETRIES = 3;
|
|
|
1315
1341
|
|
|
1316
1342
|
async function handleAgentInvocation(agentEventInst: Instance, env: Environment): Promise<void> {
|
|
1317
1343
|
const agent: AgentInstance = await findAgentByName(agentEventInst.name, env);
|
|
1318
|
-
|
|
1344
|
+
const origMsg: any = agentEventInst.lookup('message');
|
|
1345
|
+
const msg: string = isString(origMsg) ? origMsg : agentInputAsString(origMsg);
|
|
1346
|
+
await agent.invoke(msg, env);
|
|
1319
1347
|
const r: string | undefined = env.getLastResult();
|
|
1320
1348
|
const isPlanner = agent.isPlanner();
|
|
1321
1349
|
let result: string | undefined = isPlanner ? cleanupAgentResponse(r) : r;
|
|
@@ -1713,7 +1741,7 @@ async function runPreCreateEvents(inst: Instance, env: Environment) {
|
|
|
1713
1741
|
await runPrePostEvents(CrudType.CREATE, true, inst, env);
|
|
1714
1742
|
}
|
|
1715
1743
|
|
|
1716
|
-
async function runPostCreateEvents(inst: Instance, env: Environment) {
|
|
1744
|
+
export async function runPostCreateEvents(inst: Instance, env: Environment) {
|
|
1717
1745
|
if (inst.requireAudit()) {
|
|
1718
1746
|
await addCreateAudit(inst.getPath(), env);
|
|
1719
1747
|
}
|
|
@@ -1724,7 +1752,7 @@ async function runPreUpdateEvents(inst: Instance, env: Environment) {
|
|
|
1724
1752
|
await runPrePostEvents(CrudType.UPDATE, true, inst, env);
|
|
1725
1753
|
}
|
|
1726
1754
|
|
|
1727
|
-
async function runPostUpdateEvents(inst: Instance, env: Environment) {
|
|
1755
|
+
export async function runPostUpdateEvents(inst: Instance, env: Environment) {
|
|
1728
1756
|
if (inst.requireAudit()) {
|
|
1729
1757
|
await addUpdateAudit(inst.getPath(), undefined, env);
|
|
1730
1758
|
}
|
|
@@ -1735,7 +1763,7 @@ async function runPreDeleteEvents(inst: Instance, env: Environment) {
|
|
|
1735
1763
|
await runPrePostEvents(CrudType.DELETE, true, inst, env);
|
|
1736
1764
|
}
|
|
1737
1765
|
|
|
1738
|
-
async function runPostDeleteEvents(inst: Instance, env: Environment) {
|
|
1766
|
+
export async function runPostDeleteEvents(inst: Instance, env: Environment) {
|
|
1739
1767
|
if (inst.requireAudit()) {
|
|
1740
1768
|
await addDeleteAudit(inst.getPath(), undefined, env);
|
|
1741
1769
|
}
|
package/src/runtime/jsmodules.ts
CHANGED
|
@@ -39,7 +39,7 @@ export async function importModule(path: string, name: string, moduleFileName?:
|
|
|
39
39
|
}
|
|
40
40
|
path = `${s}${sep}${path}`;
|
|
41
41
|
}
|
|
42
|
-
if ((path.startsWith(sep) || path.startsWith('.'))
|
|
42
|
+
if (!(path.startsWith(sep) || path.startsWith('.'))) {
|
|
43
43
|
path = process.cwd() + sep + path;
|
|
44
44
|
}
|
|
45
45
|
const m = await import(/* @vite-ignore */ path);
|
package/src/runtime/module.ts
CHANGED
|
@@ -44,12 +44,7 @@ import {
|
|
|
44
44
|
} from './util.js';
|
|
45
45
|
import { parseStatement } from '../language/parser.js';
|
|
46
46
|
import { ActiveSessionInfo, AdminSession } from './auth/defs.js';
|
|
47
|
-
import {
|
|
48
|
-
DefaultIdAttributeName,
|
|
49
|
-
FetchModuleFn,
|
|
50
|
-
PathAttributeName,
|
|
51
|
-
SetSubscription,
|
|
52
|
-
} from './defs.js';
|
|
47
|
+
import { FetchModuleFn, PathAttributeName, SetSubscription } from './defs.js';
|
|
53
48
|
import { logger } from './logger.js';
|
|
54
49
|
|
|
55
50
|
export class ModuleEntry {
|
|
@@ -809,8 +804,13 @@ export class Agent extends Record {
|
|
|
809
804
|
return this;
|
|
810
805
|
}
|
|
811
806
|
|
|
812
|
-
getTools(): string {
|
|
813
|
-
|
|
807
|
+
getTools(): string[] | undefined {
|
|
808
|
+
const tools = this.attributes.get('tools');
|
|
809
|
+
if (tools) {
|
|
810
|
+
return tools.split(',');
|
|
811
|
+
} else {
|
|
812
|
+
return undefined;
|
|
813
|
+
}
|
|
814
814
|
}
|
|
815
815
|
|
|
816
816
|
removeTools(): Agent {
|
|
@@ -874,14 +874,6 @@ export class Entity extends Record {
|
|
|
874
874
|
parentEntryName?: string
|
|
875
875
|
) {
|
|
876
876
|
super(name, moduleName, scm, parentEntryName);
|
|
877
|
-
const idattr = this.getIdAttributeName();
|
|
878
|
-
if (idattr == undefined) {
|
|
879
|
-
const attrSpec: AttributeSpec = {
|
|
880
|
-
type: 'UUID',
|
|
881
|
-
properties: new Map().set('default', 'uuid()').set('id', true),
|
|
882
|
-
};
|
|
883
|
-
this.schema.set(DefaultIdAttributeName, attrSpec);
|
|
884
|
-
}
|
|
885
877
|
}
|
|
886
878
|
|
|
887
879
|
setRbacSpecifications(rbac: RbacSpecification[]): Entity {
|
|
@@ -2659,7 +2651,7 @@ const EventAgentName = 'event-agent-name';
|
|
|
2659
2651
|
export function defineAgentEvent(moduleName: string, agentName: string) {
|
|
2660
2652
|
const module = fetchModule(moduleName);
|
|
2661
2653
|
const event: Record = new Event(agentName, moduleName);
|
|
2662
|
-
event.addAttribute('message', { type: '
|
|
2654
|
+
event.addAttribute('message', { type: 'Any' });
|
|
2663
2655
|
event.addAttribute('chatId', { type: 'String' });
|
|
2664
2656
|
event.addMeta(IsAgentEventMeta, 'y');
|
|
2665
2657
|
event.addMeta(EventAgentName, agentName);
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { isFqName, makeCoreModuleName, makeFqName, splitFqName } from '../util.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Environment,
|
|
4
|
+
GlobalEnvironment,
|
|
5
|
+
makeEventEvaluator,
|
|
6
|
+
parseAndEvaluateStatement,
|
|
7
|
+
} from '../interpreter.js';
|
|
3
8
|
import { fetchModule, Instance, instanceToObject, isModule } from '../module.js';
|
|
4
9
|
import { provider } from '../agents/registry.js';
|
|
5
10
|
import {
|
|
@@ -35,6 +40,7 @@ entity ${AgentEntityName} {
|
|
|
35
40
|
documents String @optional, // comma-separated list of document names
|
|
36
41
|
channels String @optional, // comma-separated list of channel names
|
|
37
42
|
output String @optional, // fq-name of another agent to which the result will be pushed
|
|
43
|
+
role String @optional,
|
|
38
44
|
llm String
|
|
39
45
|
}
|
|
40
46
|
|
|
@@ -57,6 +63,11 @@ entity Document {
|
|
|
57
63
|
content String,
|
|
58
64
|
@meta {"fullTextSearch": "*"}
|
|
59
65
|
}
|
|
66
|
+
|
|
67
|
+
event doc {
|
|
68
|
+
title String,
|
|
69
|
+
url String
|
|
70
|
+
}
|
|
60
71
|
`;
|
|
61
72
|
|
|
62
73
|
export const AgentFqName = makeFqName(CoreAIModuleName, AgentEntityName);
|
|
@@ -74,15 +85,46 @@ export class AgentInstance {
|
|
|
74
85
|
channels: string | undefined;
|
|
75
86
|
runWorkflows: boolean = true;
|
|
76
87
|
output: string | undefined;
|
|
88
|
+
role: string | undefined;
|
|
89
|
+
private toolsArray: string[] | undefined = undefined;
|
|
90
|
+
private hasModuleTools = false;
|
|
77
91
|
|
|
78
92
|
private constructor() {}
|
|
79
93
|
|
|
80
94
|
static FromInstance(agentInstance: Instance): AgentInstance {
|
|
81
|
-
|
|
95
|
+
const agent: AgentInstance = instanceToObject<AgentInstance>(
|
|
96
|
+
agentInstance,
|
|
97
|
+
new AgentInstance()
|
|
98
|
+
);
|
|
99
|
+
let finalTools: string | undefined = undefined;
|
|
100
|
+
if (agent.tools) finalTools = agent.tools;
|
|
101
|
+
if (agent.channels) {
|
|
102
|
+
if (finalTools) {
|
|
103
|
+
finalTools = `${finalTools},${agent.channels}`;
|
|
104
|
+
} else {
|
|
105
|
+
finalTools = agent.channels;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (finalTools) {
|
|
109
|
+
agent.toolsArray = finalTools.split(',');
|
|
110
|
+
}
|
|
111
|
+
if (agent.toolsArray) {
|
|
112
|
+
for (let i = 0; i < agent.toolsArray.length; ++i) {
|
|
113
|
+
const n = agent.toolsArray[i];
|
|
114
|
+
if (isFqName(n)) {
|
|
115
|
+
const parts = splitFqName(n);
|
|
116
|
+
agent.hasModuleTools = isModule(parts.getModuleName());
|
|
117
|
+
} else {
|
|
118
|
+
agent.hasModuleTools = isModule(n);
|
|
119
|
+
}
|
|
120
|
+
if (agent.hasModuleTools) break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return agent;
|
|
82
124
|
}
|
|
83
125
|
|
|
84
126
|
isPlanner(): boolean {
|
|
85
|
-
return
|
|
127
|
+
return this.hasModuleTools || this.type == 'planner';
|
|
86
128
|
}
|
|
87
129
|
|
|
88
130
|
async invoke(message: string, env: Environment) {
|
|
@@ -95,7 +137,8 @@ export class AgentInstance {
|
|
|
95
137
|
if (sess) {
|
|
96
138
|
msgs = sess.lookup('messages');
|
|
97
139
|
} else {
|
|
98
|
-
|
|
140
|
+
const msg = this.role ? `role: ${this.role}\n ${this.instruction}` : this.instruction;
|
|
141
|
+
msgs = [systemMessage(msg)];
|
|
99
142
|
}
|
|
100
143
|
if (msgs) {
|
|
101
144
|
try {
|
|
@@ -107,7 +150,8 @@ export class AgentInstance {
|
|
|
107
150
|
msgs[0] = newSysMsg;
|
|
108
151
|
}
|
|
109
152
|
msgs.push(humanMessage(await this.maybeAddRelevantDocuments(message, env)));
|
|
110
|
-
const
|
|
153
|
+
const externalToolSpecs = this.getExternalToolSpecs();
|
|
154
|
+
const response: AIResponse = await p.invoke(msgs, externalToolSpecs);
|
|
111
155
|
msgs.push(assistantMessage(response.content));
|
|
112
156
|
if (isplnr) {
|
|
113
157
|
msgs[0] = sysMsg;
|
|
@@ -123,16 +167,32 @@ export class AgentInstance {
|
|
|
123
167
|
}
|
|
124
168
|
}
|
|
125
169
|
|
|
170
|
+
private getExternalToolSpecs(): any[] | undefined {
|
|
171
|
+
let result: any[] | undefined = undefined;
|
|
172
|
+
if (this.toolsArray) {
|
|
173
|
+
this.toolsArray.forEach((n: string) => {
|
|
174
|
+
const v = GlobalEnvironment.lookup(n);
|
|
175
|
+
if (v) {
|
|
176
|
+
if (result == undefined) {
|
|
177
|
+
result = new Array<any>();
|
|
178
|
+
}
|
|
179
|
+
result.push(v);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
|
|
126
186
|
private async maybeAddRelevantDocuments(message: string, env: Environment): Promise<string> {
|
|
127
187
|
if (this.documents && this.documents.length > 0) {
|
|
128
188
|
const s = `${message}. Relevant documents are: ${this.documents}`;
|
|
129
|
-
const result: any[] = await parseHelper(`{
|
|
189
|
+
const result: any[] = await parseHelper(`{${CoreAIModuleName}/Document? "${s}"}`, env);
|
|
130
190
|
if (result && result.length > 0) {
|
|
131
191
|
const docs: Instance[] = [];
|
|
132
192
|
for (let i = 0; i < result.length; ++i) {
|
|
133
193
|
const v: any = result[i];
|
|
134
194
|
const r: Instance[] = await parseHelper(
|
|
135
|
-
`{
|
|
195
|
+
`{${CoreAIModuleName}/Document {${PathAttributeNameQuery} "${v.id}"}}`,
|
|
136
196
|
env
|
|
137
197
|
);
|
|
138
198
|
if (r && r.length > 0) {
|
|
@@ -153,20 +213,17 @@ export class AgentInstance {
|
|
|
153
213
|
return message;
|
|
154
214
|
}
|
|
155
215
|
|
|
216
|
+
private static ToolsCache = new Map<string, string>();
|
|
217
|
+
|
|
156
218
|
private toolsAsString(): string {
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
if (finalTools) {
|
|
161
|
-
finalTools = `${finalTools},${this.channels}`;
|
|
162
|
-
} else {
|
|
163
|
-
finalTools = this.channels;
|
|
164
|
-
}
|
|
219
|
+
const cachedTools = AgentInstance.ToolsCache.get(this.name);
|
|
220
|
+
if (cachedTools) {
|
|
221
|
+
return cachedTools;
|
|
165
222
|
}
|
|
166
|
-
if (
|
|
223
|
+
if (this.toolsArray) {
|
|
167
224
|
const tooldefs = new Array<string>();
|
|
168
225
|
const slimModules = new Map<string, string[]>();
|
|
169
|
-
|
|
226
|
+
this.toolsArray.forEach((n: string) => {
|
|
170
227
|
let moduleName: string | undefined;
|
|
171
228
|
let entryName: string | undefined;
|
|
172
229
|
if (isFqName(n)) {
|
|
@@ -193,7 +250,9 @@ export class AgentInstance {
|
|
|
193
250
|
slimModules.forEach((defs: string[], modName: string) => {
|
|
194
251
|
tooldefs.push(`module ${modName}\n${defs.join('\n')}`);
|
|
195
252
|
});
|
|
196
|
-
|
|
253
|
+
const agentTools = tooldefs.join('\n');
|
|
254
|
+
AgentInstance.ToolsCache.set(this.name, agentTools);
|
|
255
|
+
return agentTools;
|
|
197
256
|
} else {
|
|
198
257
|
return '';
|
|
199
258
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Environment,
|
|
3
|
+
evaluate,
|
|
4
|
+
runPostCreateEvents,
|
|
5
|
+
runPostDeleteEvents,
|
|
6
|
+
runPostUpdateEvents,
|
|
7
|
+
} from '../interpreter.js';
|
|
2
8
|
import { logger } from '../logger.js';
|
|
3
9
|
import {
|
|
4
10
|
Instance,
|
|
@@ -7,7 +13,7 @@ import {
|
|
|
7
13
|
newInstanceAttributes,
|
|
8
14
|
Relationship,
|
|
9
15
|
} from '../module.js';
|
|
10
|
-
import { splitFqName } from '../util.js';
|
|
16
|
+
import { CrudType, splitFqName } from '../util.js';
|
|
11
17
|
|
|
12
18
|
export class ResolverAuthInfo {
|
|
13
19
|
userId: string;
|
|
@@ -191,6 +197,35 @@ export class Resolver {
|
|
|
191
197
|
return undefined;
|
|
192
198
|
}
|
|
193
199
|
|
|
200
|
+
private async onOutOfBandCrud(
|
|
201
|
+
inst: Instance,
|
|
202
|
+
operation: CrudType,
|
|
203
|
+
env: Environment
|
|
204
|
+
): Promise<any> {
|
|
205
|
+
switch (operation) {
|
|
206
|
+
case CrudType.CREATE:
|
|
207
|
+
return await runPostCreateEvents(inst, env);
|
|
208
|
+
case CrudType.UPDATE:
|
|
209
|
+
return await runPostUpdateEvents(inst, env);
|
|
210
|
+
case CrudType.DELETE:
|
|
211
|
+
return await runPostDeleteEvents(inst, env);
|
|
212
|
+
default:
|
|
213
|
+
return inst;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public async onCreate(inst: Instance, env: Environment): Promise<any> {
|
|
218
|
+
return this.onOutOfBandCrud(inst, CrudType.CREATE, env);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public async onUpdate(inst: Instance, env: Environment): Promise<any> {
|
|
222
|
+
return this.onOutOfBandCrud(inst, CrudType.UPDATE, env);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public async onDelete(inst: Instance, env: Environment): Promise<any> {
|
|
226
|
+
return this.onOutOfBandCrud(inst, CrudType.DELETE, env);
|
|
227
|
+
}
|
|
228
|
+
|
|
194
229
|
public async onSubscription(result: any): Promise<any> {
|
|
195
230
|
if (result != undefined) {
|
|
196
231
|
try {
|
|
@@ -768,7 +768,7 @@ export async function getManyByJoin(
|
|
|
768
768
|
function intoSpecToSql(intoSpec: Map<string, string>): string {
|
|
769
769
|
const cols = new Array<string>();
|
|
770
770
|
intoSpec.forEach((v: string, k: string) => {
|
|
771
|
-
cols.push(`${v} AS ${k}`);
|
|
771
|
+
cols.push(`${v} AS "${k}"`);
|
|
772
772
|
});
|
|
773
773
|
return cols.join(', ');
|
|
774
774
|
}
|
|
@@ -94,8 +94,8 @@ export class SqlDbResolver extends Resolver {
|
|
|
94
94
|
const idAttrName: string | undefined = maybeFindIdAttributeName(inst);
|
|
95
95
|
ensureOneToOneAttributes(inst);
|
|
96
96
|
const attrs: InstanceAttributes = inst.attributes;
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
const idAttrVal: any = idAttrName ? attrs.get(idAttrName) : crypto.randomUUID();
|
|
98
|
+
if (idAttrVal != undefined) {
|
|
99
99
|
const pp: string | undefined = attrs.get(PathAttributeName);
|
|
100
100
|
const n: string = `${inst.moduleName}/${inst.name}`;
|
|
101
101
|
let p: string = '';
|
package/src/runtime/util.ts
CHANGED
|
@@ -207,7 +207,7 @@ export const DefaultModuleName = 'agentlang';
|
|
|
207
207
|
export const DefaultModules = new Set();
|
|
208
208
|
|
|
209
209
|
export function makeCoreModuleName(n: string): string {
|
|
210
|
-
return DefaultModuleName + '
|
|
210
|
+
return DefaultModuleName + '.' + n;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
const InitFunctions: Function[] = [];
|