@sprucelabs/spruce-agent-plugin 0.0.2 → 0.0.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.
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { BootCallback, HealthCheckItem, Skill, SkillFeature } from '@sprucelabs/spruce-skill-utils';
|
|
2
2
|
export declare class AgentFeature implements SkillFeature {
|
|
3
3
|
private skill;
|
|
4
|
+
private log;
|
|
5
|
+
private onBootHandler?;
|
|
4
6
|
constructor(skill: Skill);
|
|
5
7
|
static doesFileExist(path: string): boolean;
|
|
6
8
|
execute(): Promise<void>;
|
|
7
|
-
private
|
|
9
|
+
private triggerOnBoot;
|
|
10
|
+
private registerPlatformAgent;
|
|
8
11
|
private connectToApi;
|
|
9
12
|
private parseName;
|
|
10
13
|
private InvalidPromptFileError;
|
|
@@ -14,7 +17,7 @@ export declare class AgentFeature implements SkillFeature {
|
|
|
14
17
|
isInstalled(): Promise<boolean>;
|
|
15
18
|
destroy(): Promise<void>;
|
|
16
19
|
isBooted(): boolean;
|
|
17
|
-
onBoot(
|
|
20
|
+
onBoot(cb: BootCallback): void;
|
|
18
21
|
}
|
|
19
22
|
declare const _default: (skill: Skill) => void;
|
|
20
23
|
export default _default;
|
|
@@ -12,6 +12,7 @@ import SpruceError from '../errors/SpruceError.js';
|
|
|
12
12
|
export class AgentFeature {
|
|
13
13
|
constructor(skill) {
|
|
14
14
|
this.skill = skill;
|
|
15
|
+
this.log = skill.buildLog('Agent.Feature');
|
|
15
16
|
}
|
|
16
17
|
static doesFileExist(path) {
|
|
17
18
|
return diskUtil.doesFileExist(path);
|
|
@@ -20,13 +21,21 @@ export class AgentFeature {
|
|
|
20
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
22
|
const prompt = this.readSystemPromptFile();
|
|
22
23
|
if (!prompt) {
|
|
24
|
+
yield this.triggerOnBoot();
|
|
23
25
|
return;
|
|
24
26
|
}
|
|
25
27
|
const name = this.parseName(prompt);
|
|
26
|
-
yield this.
|
|
28
|
+
yield this.registerPlatformAgent(name, prompt);
|
|
29
|
+
yield this.triggerOnBoot();
|
|
27
30
|
});
|
|
28
31
|
}
|
|
29
|
-
|
|
32
|
+
triggerOnBoot() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
var _a;
|
|
35
|
+
yield ((_a = this.onBootHandler) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
registerPlatformAgent(name, prompt) {
|
|
30
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
40
|
const client = yield this.connectToApi();
|
|
32
41
|
yield client.emitAndFlattenResponses('register-agent::v2020_12_25', {
|
|
@@ -37,6 +46,7 @@ export class AgentFeature {
|
|
|
37
46
|
},
|
|
38
47
|
},
|
|
39
48
|
});
|
|
49
|
+
this.log.info(`Agent registration complete.`);
|
|
40
50
|
});
|
|
41
51
|
}
|
|
42
52
|
connectToApi() {
|
|
@@ -55,6 +65,7 @@ export class AgentFeature {
|
|
|
55
65
|
if (!name) {
|
|
56
66
|
throw this.InvalidPromptFileError();
|
|
57
67
|
}
|
|
68
|
+
this.log.info(`System Agent Name: ${name}`);
|
|
58
69
|
return name;
|
|
59
70
|
}
|
|
60
71
|
InvalidPromptFileError() {
|
|
@@ -64,10 +75,13 @@ export class AgentFeature {
|
|
|
64
75
|
});
|
|
65
76
|
}
|
|
66
77
|
readSystemPromptFile() {
|
|
78
|
+
this.log.info('Checking for system prompt file...');
|
|
67
79
|
const promptPath = this.resolvePlatformPromptPath();
|
|
68
80
|
if (!promptPath) {
|
|
81
|
+
this.log.info('No system prompt file found.');
|
|
69
82
|
return false;
|
|
70
83
|
}
|
|
84
|
+
this.log.info(`System prompt file found at ${promptPath}.`);
|
|
71
85
|
const prompt = diskUtil.readFile(promptPath);
|
|
72
86
|
return prompt;
|
|
73
87
|
}
|
|
@@ -116,7 +130,9 @@ export class AgentFeature {
|
|
|
116
130
|
isBooted() {
|
|
117
131
|
return true;
|
|
118
132
|
}
|
|
119
|
-
onBoot(
|
|
133
|
+
onBoot(cb) {
|
|
134
|
+
this.onBootHandler = cb;
|
|
135
|
+
}
|
|
120
136
|
}
|
|
121
137
|
export default (skill) => {
|
|
122
138
|
skill.registerFeature('agent', new AgentFeature(skill));
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { BootCallback, HealthCheckItem, Skill, SkillFeature } from '@sprucelabs/spruce-skill-utils';
|
|
2
2
|
export declare class AgentFeature implements SkillFeature {
|
|
3
3
|
private skill;
|
|
4
|
+
private log;
|
|
5
|
+
private onBootHandler?;
|
|
4
6
|
constructor(skill: Skill);
|
|
5
7
|
static doesFileExist(path: string): boolean;
|
|
6
8
|
execute(): Promise<void>;
|
|
7
|
-
private
|
|
9
|
+
private triggerOnBoot;
|
|
10
|
+
private registerPlatformAgent;
|
|
8
11
|
private connectToApi;
|
|
9
12
|
private parseName;
|
|
10
13
|
private InvalidPromptFileError;
|
|
@@ -14,7 +17,7 @@ export declare class AgentFeature implements SkillFeature {
|
|
|
14
17
|
isInstalled(): Promise<boolean>;
|
|
15
18
|
destroy(): Promise<void>;
|
|
16
19
|
isBooted(): boolean;
|
|
17
|
-
onBoot(
|
|
20
|
+
onBoot(cb: BootCallback): void;
|
|
18
21
|
}
|
|
19
22
|
declare const _default: (skill: Skill) => void;
|
|
20
23
|
export default _default;
|
|
@@ -9,6 +9,7 @@ const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
|
9
9
|
class AgentFeature {
|
|
10
10
|
constructor(skill) {
|
|
11
11
|
this.skill = skill;
|
|
12
|
+
this.log = skill.buildLog('Agent.Feature');
|
|
12
13
|
}
|
|
13
14
|
static doesFileExist(path) {
|
|
14
15
|
return spruce_skill_utils_1.diskUtil.doesFileExist(path);
|
|
@@ -16,12 +17,17 @@ class AgentFeature {
|
|
|
16
17
|
async execute() {
|
|
17
18
|
const prompt = this.readSystemPromptFile();
|
|
18
19
|
if (!prompt) {
|
|
20
|
+
await this.triggerOnBoot();
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
21
23
|
const name = this.parseName(prompt);
|
|
22
|
-
await this.
|
|
24
|
+
await this.registerPlatformAgent(name, prompt);
|
|
25
|
+
await this.triggerOnBoot();
|
|
23
26
|
}
|
|
24
|
-
async
|
|
27
|
+
async triggerOnBoot() {
|
|
28
|
+
await this.onBootHandler?.();
|
|
29
|
+
}
|
|
30
|
+
async registerPlatformAgent(name, prompt) {
|
|
25
31
|
const client = await this.connectToApi();
|
|
26
32
|
await client.emitAndFlattenResponses('register-agent::v2020_12_25', {
|
|
27
33
|
payload: {
|
|
@@ -31,6 +37,7 @@ class AgentFeature {
|
|
|
31
37
|
},
|
|
32
38
|
},
|
|
33
39
|
});
|
|
40
|
+
this.log.info(`Agent registration complete.`);
|
|
34
41
|
}
|
|
35
42
|
async connectToApi() {
|
|
36
43
|
const events = this.skill.getFeatureByCode('event');
|
|
@@ -45,6 +52,7 @@ class AgentFeature {
|
|
|
45
52
|
if (!name) {
|
|
46
53
|
throw this.InvalidPromptFileError();
|
|
47
54
|
}
|
|
55
|
+
this.log.info(`System Agent Name: ${name}`);
|
|
48
56
|
return name;
|
|
49
57
|
}
|
|
50
58
|
InvalidPromptFileError() {
|
|
@@ -54,10 +62,13 @@ class AgentFeature {
|
|
|
54
62
|
});
|
|
55
63
|
}
|
|
56
64
|
readSystemPromptFile() {
|
|
65
|
+
this.log.info('Checking for system prompt file...');
|
|
57
66
|
const promptPath = this.resolvePlatformPromptPath();
|
|
58
67
|
if (!promptPath) {
|
|
68
|
+
this.log.info('No system prompt file found.');
|
|
59
69
|
return false;
|
|
60
70
|
}
|
|
71
|
+
this.log.info(`System prompt file found at ${promptPath}.`);
|
|
61
72
|
const prompt = spruce_skill_utils_1.diskUtil.readFile(promptPath);
|
|
62
73
|
return prompt;
|
|
63
74
|
}
|
|
@@ -100,7 +111,9 @@ class AgentFeature {
|
|
|
100
111
|
isBooted() {
|
|
101
112
|
return true;
|
|
102
113
|
}
|
|
103
|
-
onBoot(
|
|
114
|
+
onBoot(cb) {
|
|
115
|
+
this.onBootHandler = cb;
|
|
116
|
+
}
|
|
104
117
|
}
|
|
105
118
|
exports.AgentFeature = AgentFeature;
|
|
106
119
|
exports.default = (skill) => {
|