@elizaos/cli 1.2.4 → 1.2.7
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/dist/bun-exec-KJOLGZOL.js +21 -0
- package/dist/{chunk-2XI6N7KN.js → chunk-2ZF5OAMV.js} +322 -69
- package/dist/chunk-3YTIOEFK.js +202 -0
- package/dist/chunk-AQ6OMR2A.js +14 -0
- package/dist/{chunk-JZG5QBNT.js → chunk-E54G6FI7.js} +32 -6
- package/dist/{chunk-PSSTO76B.js → chunk-KKAK7OQA.js} +100 -104
- package/dist/chunk-Y5IA2UZ2.js +154 -0
- package/dist/commands/agent/actions/index.js +4 -3
- package/dist/commands/agent/index.js +4 -3
- package/dist/commands/create/actions/index.d.ts +6 -2
- package/dist/commands/create/actions/index.js +8 -7
- package/dist/commands/create/index.js +6 -6
- package/dist/commands/shared/index.js +1 -1
- package/dist/index.js +323 -258
- package/dist/{plugin-creator-5CER524N.js → plugin-creator-Y2NWASXI.js} +16 -15
- package/dist/{registry-SN5V2VXR.js → registry-K2OCCRXO.js} +4 -3
- package/dist/templates/plugin-quick-starter/README.md +214 -0
- package/dist/templates/plugin-quick-starter/bunfig.toml +10 -0
- package/dist/templates/plugin-quick-starter/package.json +76 -0
- package/dist/templates/plugin-quick-starter/scripts/install-test-deps.js +53 -0
- package/dist/templates/plugin-quick-starter/src/__tests__/plugin.test.ts +209 -0
- package/dist/templates/plugin-quick-starter/src/__tests__/test-utils.ts +162 -0
- package/dist/templates/plugin-quick-starter/src/index.ts +4 -0
- package/dist/templates/plugin-quick-starter/src/plugin.ts +272 -0
- package/dist/templates/plugin-quick-starter/tsconfig.build.json +11 -0
- package/dist/templates/plugin-quick-starter/tsconfig.json +28 -0
- package/dist/templates/plugin-quick-starter/tsup.config.ts +20 -0
- package/dist/templates/plugin-starter/package.json +2 -2
- package/dist/templates/plugin-starter/scripts/install-test-deps.js +7 -3
- package/dist/templates/plugin-starter/src/__tests__/build-order.test.ts +51 -0
- package/dist/templates/plugin-starter/src/__tests__/vite-config-utils.ts +33 -0
- package/dist/templates/plugin-starter/src/plugin.ts +13 -15
- package/dist/templates/plugin-starter/tsup.config.ts +1 -1
- package/dist/templates/plugin-starter/vite.config.ts +1 -1
- package/dist/templates/project-starter/package.json +4 -4
- package/dist/templates/project-starter/scripts/install-test-deps.js +7 -3
- package/dist/templates/project-starter/src/__tests__/build-order.test.ts +59 -0
- package/dist/templates/project-starter/src/__tests__/character-plugin-ordering.test.ts +11 -110
- package/dist/templates/project-starter/src/__tests__/vite-config-utils.ts +33 -0
- package/dist/templates/project-starter/src/character.ts +14 -17
- package/dist/templates/project-starter/tsup.config.ts +1 -1
- package/dist/templates/project-tee-starter/package.json +3 -3
- package/dist/templates/project-tee-starter/src/character.ts +3 -0
- package/dist/{utils-DTW3XU6O.js → utils-QSRUVLAT.js} +4 -3
- package/package.json +6 -6
- package/templates/plugin-quick-starter/README.md +214 -0
- package/templates/plugin-quick-starter/bunfig.toml +10 -0
- package/templates/plugin-quick-starter/package.json +76 -0
- package/templates/plugin-quick-starter/scripts/install-test-deps.js +53 -0
- package/templates/plugin-quick-starter/src/__tests__/plugin.test.ts +209 -0
- package/templates/plugin-quick-starter/src/__tests__/test-utils.ts +162 -0
- package/templates/plugin-quick-starter/src/index.ts +4 -0
- package/templates/plugin-quick-starter/src/plugin.ts +272 -0
- package/templates/plugin-quick-starter/tsconfig.build.json +11 -0
- package/templates/plugin-quick-starter/tsconfig.json +28 -0
- package/templates/plugin-quick-starter/tsup.config.ts +20 -0
- package/templates/plugin-starter/package.json +2 -2
- package/templates/plugin-starter/scripts/install-test-deps.js +7 -3
- package/templates/plugin-starter/src/__tests__/build-order.test.ts +51 -0
- package/templates/plugin-starter/src/__tests__/vite-config-utils.ts +33 -0
- package/templates/plugin-starter/src/plugin.ts +13 -15
- package/templates/plugin-starter/tsup.config.ts +1 -1
- package/templates/plugin-starter/vite.config.ts +1 -1
- package/templates/project-starter/package.json +4 -4
- package/templates/project-starter/scripts/install-test-deps.js +7 -3
- package/templates/project-starter/src/__tests__/build-order.test.ts +59 -0
- package/templates/project-starter/src/__tests__/character-plugin-ordering.test.ts +11 -110
- package/templates/project-starter/src/__tests__/vite-config-utils.ts +33 -0
- package/templates/project-starter/src/character.ts +14 -17
- package/templates/project-starter/tsup.config.ts +1 -1
- package/templates/project-tee-starter/package.json +3 -3
- package/templates/project-tee-starter/src/character.ts +3 -0
- package/dist/chunk-5DYKNYEY.js +0 -2262
- package/dist/chunk-XB5JBFO6.js +0 -41
- package/dist/chunk-ZWDXDKSA.js +0 -281
- package/dist/setup-UQOWDHFN.js +0 -20
- package/dist/templates/plugin-starter/dist/index.js +0 -391
- package/dist/templates/plugin-starter/dist/index.js.map +0 -1
- package/templates/plugin-starter/dist/.vite/manifest.json +0 -11
- package/templates/plugin-starter/dist/index.d.ts +0 -14
- package/templates/plugin-starter/dist/index.js +0 -391
- package/templates/plugin-starter/dist/index.js.map +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# Plugin Quick Starter
|
|
2
|
+
|
|
3
|
+
A minimal backend-only plugin template for ElizaOS. This template provides a clean starting point for creating simple plugins without frontend complexity.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This quick-starter template is ideal for:
|
|
8
|
+
|
|
9
|
+
- Backend-only plugins
|
|
10
|
+
- Simple API integrations
|
|
11
|
+
- Services and providers
|
|
12
|
+
- Actions without UI components
|
|
13
|
+
- Lightweight extensions
|
|
14
|
+
|
|
15
|
+
## Structure
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
plugin-quick-starter/
|
|
19
|
+
├── src/
|
|
20
|
+
│ ├── __tests__/ # Unit tests
|
|
21
|
+
│ │ ├── plugin.test.ts
|
|
22
|
+
│ │ └── test-utils.ts
|
|
23
|
+
│ ├── plugin.ts # Main plugin implementation
|
|
24
|
+
│ ├── tests.ts # Plugin test suite
|
|
25
|
+
│ └── index.ts # Plugin export
|
|
26
|
+
├── scripts/
|
|
27
|
+
│ └── install-test-deps.js # Test dependency installer
|
|
28
|
+
├── tsup.config.ts # Build configuration
|
|
29
|
+
├── tsconfig.json # TypeScript config
|
|
30
|
+
├── package.json # Minimal dependencies
|
|
31
|
+
└── README.md # This file
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Getting Started
|
|
35
|
+
|
|
36
|
+
1. **Create your plugin:**
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
elizaos create my-plugin
|
|
40
|
+
# Select: Plugin
|
|
41
|
+
# Select: Quick Plugin (Backend Only)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
2. **Navigate to your plugin:**
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
cd my-plugin
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
3. **Install dependencies:**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
bun install
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
4. **Start development:**
|
|
57
|
+
```bash
|
|
58
|
+
bun run dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Key Features
|
|
62
|
+
|
|
63
|
+
### Minimal Dependencies
|
|
64
|
+
|
|
65
|
+
- Only essential packages (`@elizaos/core`, `zod`)
|
|
66
|
+
- No frontend frameworks or build tools
|
|
67
|
+
- Fast installation and builds
|
|
68
|
+
|
|
69
|
+
### Simple Testing
|
|
70
|
+
|
|
71
|
+
- Unit tests only with Bun test runner
|
|
72
|
+
- No E2E or component testing overhead
|
|
73
|
+
- Quick test execution
|
|
74
|
+
|
|
75
|
+
### Backend Focus
|
|
76
|
+
|
|
77
|
+
- API routes for server-side functionality
|
|
78
|
+
- Services for state management
|
|
79
|
+
- Actions for agent capabilities
|
|
80
|
+
- Providers for contextual data
|
|
81
|
+
|
|
82
|
+
## Plugin Components
|
|
83
|
+
|
|
84
|
+
### Actions
|
|
85
|
+
|
|
86
|
+
Define agent capabilities:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const myAction: Action = {
|
|
90
|
+
name: 'MY_ACTION',
|
|
91
|
+
description: 'Description of what this action does',
|
|
92
|
+
validate: async (runtime, message, state) => {
|
|
93
|
+
// Validation logic
|
|
94
|
+
return true;
|
|
95
|
+
},
|
|
96
|
+
handler: async (runtime, message, state, options, callback) => {
|
|
97
|
+
// Action implementation
|
|
98
|
+
return { success: true, data: {} };
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Services
|
|
104
|
+
|
|
105
|
+
Manage plugin state:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
export class MyService extends Service {
|
|
109
|
+
static serviceType = 'my-service';
|
|
110
|
+
|
|
111
|
+
async start() {
|
|
112
|
+
// Initialize service
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async stop() {
|
|
116
|
+
// Cleanup
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Providers
|
|
122
|
+
|
|
123
|
+
Supply contextual information:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const myProvider: Provider = {
|
|
127
|
+
name: 'MY_PROVIDER',
|
|
128
|
+
description: 'Provides contextual data',
|
|
129
|
+
get: async (runtime, message, state) => {
|
|
130
|
+
return {
|
|
131
|
+
text: 'Provider data',
|
|
132
|
+
values: {},
|
|
133
|
+
data: {},
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### API Routes
|
|
140
|
+
|
|
141
|
+
Backend endpoints:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
routes: [
|
|
145
|
+
{
|
|
146
|
+
name: 'api-endpoint',
|
|
147
|
+
path: '/api/endpoint',
|
|
148
|
+
type: 'GET',
|
|
149
|
+
handler: async (req, res) => {
|
|
150
|
+
res.json({ data: 'response' });
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Development Commands
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# Start in development mode with hot reload
|
|
160
|
+
bun run dev
|
|
161
|
+
|
|
162
|
+
# Start in production mode
|
|
163
|
+
bun run start
|
|
164
|
+
|
|
165
|
+
# Build the plugin
|
|
166
|
+
bun run build
|
|
167
|
+
|
|
168
|
+
# Run tests
|
|
169
|
+
bun test
|
|
170
|
+
|
|
171
|
+
# Format code
|
|
172
|
+
bun run format
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Testing
|
|
176
|
+
|
|
177
|
+
Write unit tests in `src/__tests__/`:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { describe, it, expect } from 'bun:test';
|
|
181
|
+
|
|
182
|
+
describe('My Plugin', () => {
|
|
183
|
+
it('should work correctly', () => {
|
|
184
|
+
expect(true).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Publishing
|
|
190
|
+
|
|
191
|
+
1. Update `package.json` with your plugin details
|
|
192
|
+
2. Build your plugin: `bun run build`
|
|
193
|
+
3. Publish: `elizaos publish`
|
|
194
|
+
|
|
195
|
+
## When to Use Quick Starter
|
|
196
|
+
|
|
197
|
+
Use this template when you need:
|
|
198
|
+
|
|
199
|
+
- ✅ Backend-only functionality
|
|
200
|
+
- ✅ Simple API integrations
|
|
201
|
+
- ✅ Lightweight plugins
|
|
202
|
+
- ✅ Fast development cycles
|
|
203
|
+
- ✅ Minimal dependencies
|
|
204
|
+
|
|
205
|
+
Consider the full plugin-starter if you need:
|
|
206
|
+
|
|
207
|
+
- ❌ React frontend components
|
|
208
|
+
- ❌ Complex UI interactions
|
|
209
|
+
- ❌ E2E testing with Cypress
|
|
210
|
+
- ❌ Frontend build pipeline
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
This template is part of the ElizaOS project.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elizaos/plugin-quick-starter",
|
|
3
|
+
"description": "Quick backend-only plugin template for ElizaOS",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"packageType": "plugin",
|
|
11
|
+
"platform": "node",
|
|
12
|
+
"license": "UNLICENSED",
|
|
13
|
+
"author": "${GITHUB_USERNAME}",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"plugin",
|
|
16
|
+
"elizaos"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": ""
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://elizaos.ai",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/${GITHUB_USERNAME}/${PLUGINNAME}/issues"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
".npmignore",
|
|
39
|
+
"package.json",
|
|
40
|
+
"tsup.config.ts"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@elizaos/core": "1.2.7",
|
|
44
|
+
"zod": "^3.24.4"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@elizaos/cli": "latest",
|
|
48
|
+
"dotenv": "16.4.5",
|
|
49
|
+
"prettier": "3.5.3",
|
|
50
|
+
"tsup": "8.5.0",
|
|
51
|
+
"typescript": "5.8.2"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"start": "elizaos start",
|
|
55
|
+
"dev": "elizaos dev",
|
|
56
|
+
"build": "tsc --noEmit && tsup",
|
|
57
|
+
"test": "bun test",
|
|
58
|
+
"format": "prettier --write ./src"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"resolutions": {
|
|
64
|
+
"zod": "^3.24.4"
|
|
65
|
+
},
|
|
66
|
+
"agentConfig": {
|
|
67
|
+
"pluginType": "elizaos:plugin:1.0.0",
|
|
68
|
+
"pluginParameters": {
|
|
69
|
+
"API_KEY": {
|
|
70
|
+
"type": "string",
|
|
71
|
+
"description": "API key for the service"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"gitHead": "d5bd5c43bfebeb7ac02f9e029f924cb6cd5c2ec7"
|
|
76
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync, readFileSync } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
const testDependencies = {
|
|
7
|
+
'@elizaos/core': 'latest',
|
|
8
|
+
'@elizaos/test-utils': 'latest',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function isInstalled(packageName) {
|
|
12
|
+
try {
|
|
13
|
+
const packageJsonPath = join(process.cwd(), 'package.json');
|
|
14
|
+
if (existsSync(packageJsonPath)) {
|
|
15
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
16
|
+
const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
17
|
+
return packageName in deps;
|
|
18
|
+
}
|
|
19
|
+
} catch (error) {
|
|
20
|
+
// Silent fail, will install if error
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function installTestDependencies() {
|
|
26
|
+
const missingDeps = Object.entries(testDependencies)
|
|
27
|
+
.filter(([name]) => !isInstalled(name))
|
|
28
|
+
.map(([name, version]) => `${name}@${version}`);
|
|
29
|
+
|
|
30
|
+
if (missingDeps.length === 0) {
|
|
31
|
+
console.log('✓ Test dependencies already installed');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log('Installing test dependencies...');
|
|
36
|
+
try {
|
|
37
|
+
const proc = Bun.spawnSync(['bun', 'add', '-d', ...missingDeps], {
|
|
38
|
+
stdout: 'inherit',
|
|
39
|
+
stderr: 'inherit',
|
|
40
|
+
cwd: process.cwd(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (proc.exitCode !== 0) {
|
|
44
|
+
throw new Error('bun add command failed');
|
|
45
|
+
}
|
|
46
|
+
console.log('✓ Test dependencies installed successfully');
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('Failed to install test dependencies:', error.message);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
installTestDependencies();
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { describe, expect, it, spyOn, beforeEach, afterEach, beforeAll, afterAll } from 'bun:test';
|
|
2
|
+
import { starterPlugin, StarterService } from '../index';
|
|
3
|
+
import { ModelType, logger, type IAgentRuntime, type Service } from '@elizaos/core';
|
|
4
|
+
import dotenv from 'dotenv';
|
|
5
|
+
|
|
6
|
+
// Setup environment variables
|
|
7
|
+
dotenv.config();
|
|
8
|
+
|
|
9
|
+
// Need to spy on logger for documentation
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
spyOn(logger, 'info');
|
|
12
|
+
spyOn(logger, 'error');
|
|
13
|
+
spyOn(logger, 'warn');
|
|
14
|
+
spyOn(logger, 'debug');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterAll(() => {
|
|
18
|
+
// No global restore needed in bun:test
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Create a real runtime for testing
|
|
22
|
+
function createRealRuntime(): Partial<IAgentRuntime> {
|
|
23
|
+
const services = new Map<string, Service>();
|
|
24
|
+
|
|
25
|
+
// Create a real service instance if needed
|
|
26
|
+
const createService = (serviceType: string): Service | null => {
|
|
27
|
+
if (serviceType === StarterService.serviceType) {
|
|
28
|
+
return new StarterService({
|
|
29
|
+
character: {
|
|
30
|
+
name: 'Test Character',
|
|
31
|
+
system: 'You are a helpful assistant for testing.',
|
|
32
|
+
},
|
|
33
|
+
} as IAgentRuntime);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
character: {
|
|
40
|
+
name: 'Test Character',
|
|
41
|
+
system: 'You are a helpful assistant for testing.',
|
|
42
|
+
bio: 'A test character for unit testing',
|
|
43
|
+
plugins: [],
|
|
44
|
+
settings: {},
|
|
45
|
+
},
|
|
46
|
+
getSetting: (key: string) => null,
|
|
47
|
+
db: {
|
|
48
|
+
get: async (key: string) => null,
|
|
49
|
+
set: async (key: string, value: unknown) => true,
|
|
50
|
+
delete: async (key: string) => true,
|
|
51
|
+
getKeys: async (pattern: string) => [],
|
|
52
|
+
},
|
|
53
|
+
getService: <T extends Service>(serviceType: string): T | null => {
|
|
54
|
+
// Log the service request for debugging
|
|
55
|
+
logger.debug(`Requesting service: ${serviceType}`);
|
|
56
|
+
|
|
57
|
+
// Get from cache or create new
|
|
58
|
+
if (!services.has(serviceType)) {
|
|
59
|
+
logger.debug(`Creating new service: ${serviceType}`);
|
|
60
|
+
const service = createService(serviceType);
|
|
61
|
+
if (service) {
|
|
62
|
+
services.set(serviceType, service);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (services.get(serviceType) as T) || null;
|
|
67
|
+
},
|
|
68
|
+
registerService: async (ServiceClass: typeof Service): Promise<void> => {
|
|
69
|
+
logger.debug(`Registering service: ${ServiceClass.serviceType}`);
|
|
70
|
+
const runtime = {
|
|
71
|
+
character: {
|
|
72
|
+
name: 'Test Character',
|
|
73
|
+
system: 'You are a helpful assistant for testing.',
|
|
74
|
+
bio: 'A test character for unit testing',
|
|
75
|
+
},
|
|
76
|
+
} as IAgentRuntime;
|
|
77
|
+
const service = await ServiceClass.start(runtime);
|
|
78
|
+
services.set(ServiceClass.serviceType, service);
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('Plugin Configuration', () => {
|
|
84
|
+
it('should have correct plugin metadata', () => {
|
|
85
|
+
expect(starterPlugin.name).toBe('plugin-quick-starter');
|
|
86
|
+
expect(starterPlugin.description).toBe('Quick backend-only plugin template for elizaOS');
|
|
87
|
+
expect(starterPlugin.config).toBeDefined();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should include the EXAMPLE_PLUGIN_VARIABLE in config', () => {
|
|
91
|
+
expect(starterPlugin.config).toHaveProperty('EXAMPLE_PLUGIN_VARIABLE');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should initialize properly', async () => {
|
|
95
|
+
const originalEnv = process.env.EXAMPLE_PLUGIN_VARIABLE;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
process.env.EXAMPLE_PLUGIN_VARIABLE = 'test-value';
|
|
99
|
+
|
|
100
|
+
// Initialize with config - using real runtime
|
|
101
|
+
const runtime = createRealRuntime();
|
|
102
|
+
|
|
103
|
+
if (starterPlugin.init) {
|
|
104
|
+
await starterPlugin.init(
|
|
105
|
+
{ EXAMPLE_PLUGIN_VARIABLE: 'test-value' },
|
|
106
|
+
runtime as IAgentRuntime
|
|
107
|
+
);
|
|
108
|
+
expect(true).toBe(true); // If we got here, init succeeded
|
|
109
|
+
}
|
|
110
|
+
} finally {
|
|
111
|
+
process.env.EXAMPLE_PLUGIN_VARIABLE = originalEnv;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should have a valid config', () => {
|
|
116
|
+
expect(starterPlugin.config).toBeDefined();
|
|
117
|
+
if (starterPlugin.config) {
|
|
118
|
+
// Check if the config has expected EXAMPLE_PLUGIN_VARIABLE property
|
|
119
|
+
expect(Object.keys(starterPlugin.config)).toContain('EXAMPLE_PLUGIN_VARIABLE');
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('Plugin Models', () => {
|
|
125
|
+
it('should have TEXT_SMALL model defined', () => {
|
|
126
|
+
expect(starterPlugin.models?.[ModelType.TEXT_SMALL]).toBeDefined();
|
|
127
|
+
if (starterPlugin.models) {
|
|
128
|
+
expect(typeof starterPlugin.models[ModelType.TEXT_SMALL]).toBe('function');
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should have TEXT_LARGE model defined', () => {
|
|
133
|
+
expect(starterPlugin.models?.[ModelType.TEXT_LARGE]).toBeDefined();
|
|
134
|
+
if (starterPlugin.models) {
|
|
135
|
+
expect(typeof starterPlugin.models[ModelType.TEXT_LARGE]).toBe('function');
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should return a response from TEXT_SMALL model', async () => {
|
|
140
|
+
if (starterPlugin.models?.[ModelType.TEXT_SMALL]) {
|
|
141
|
+
const runtime = createRealRuntime();
|
|
142
|
+
const result = await starterPlugin.models[ModelType.TEXT_SMALL](runtime as IAgentRuntime, {
|
|
143
|
+
prompt: 'test',
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Check that we get a non-empty string response
|
|
147
|
+
expect(result).toBeTruthy();
|
|
148
|
+
expect(typeof result).toBe('string');
|
|
149
|
+
expect(result.length).toBeGreaterThan(10);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('StarterService', () => {
|
|
155
|
+
it('should start the service', async () => {
|
|
156
|
+
const runtime = createRealRuntime();
|
|
157
|
+
const startResult = await StarterService.start(runtime as IAgentRuntime);
|
|
158
|
+
|
|
159
|
+
expect(startResult).toBeDefined();
|
|
160
|
+
expect(startResult.constructor.name).toBe('StarterService');
|
|
161
|
+
|
|
162
|
+
// Test real functionality - check stop method is available
|
|
163
|
+
expect(typeof startResult.stop).toBe('function');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('should stop the service', async () => {
|
|
167
|
+
const runtime = createRealRuntime();
|
|
168
|
+
|
|
169
|
+
// Start the service to get the actual instance
|
|
170
|
+
const service = await StarterService.start(runtime as IAgentRuntime);
|
|
171
|
+
|
|
172
|
+
// Spy on the real service's stop method
|
|
173
|
+
const stopSpy = spyOn(service, 'stop');
|
|
174
|
+
|
|
175
|
+
// Mock getService to return our spied service
|
|
176
|
+
const originalGetService = runtime.getService;
|
|
177
|
+
runtime.getService = <T extends Service>(serviceType: string): T | null => {
|
|
178
|
+
if (serviceType === StarterService.serviceType) {
|
|
179
|
+
return service as T;
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// Call the static stop method
|
|
185
|
+
await StarterService.stop(runtime as IAgentRuntime);
|
|
186
|
+
|
|
187
|
+
// Verify the service's stop method was called
|
|
188
|
+
expect(stopSpy).toHaveBeenCalled();
|
|
189
|
+
|
|
190
|
+
// Restore original getService
|
|
191
|
+
runtime.getService = originalGetService;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should throw an error when stopping a non-existent service', async () => {
|
|
195
|
+
const runtime = createRealRuntime();
|
|
196
|
+
// Don't register a service, so getService will return null
|
|
197
|
+
|
|
198
|
+
// We'll patch the getService function to ensure it returns null
|
|
199
|
+
const originalGetService = runtime.getService;
|
|
200
|
+
runtime.getService = () => null;
|
|
201
|
+
|
|
202
|
+
await expect(StarterService.stop(runtime as IAgentRuntime)).rejects.toThrow(
|
|
203
|
+
'Starter service not found'
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
// Restore original getService function
|
|
207
|
+
runtime.getService = originalGetService;
|
|
208
|
+
});
|
|
209
|
+
});
|