@tinyclaw/plugins 1.0.1-dev.3004a38
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 +19 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +71 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @tinyclaw/plugins
|
|
2
|
+
|
|
3
|
+
Config-driven plugin loader and validator for [Tiny Claw](https://github.com/warengonzaga/tinyclaw) — your autonomous AI companion.
|
|
4
|
+
|
|
5
|
+
Provides `loadPlugins` which dynamically imports enabled plugins by package name, validates them, and returns them grouped by type (channels, providers, tools).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @tinyclaw/plugins
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Part of Tiny Claw
|
|
14
|
+
|
|
15
|
+
This package is part of the [Tiny Claw](https://github.com/warengonzaga/tinyclaw) monorepo.
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
GPL-3.0 — see [LICENSE](../../LICENSE) for details.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Loader
|
|
3
|
+
*
|
|
4
|
+
* Discovers installed Tiny Claw plugins by dynamically importing package names
|
|
5
|
+
* from the `plugins.enabled` config array, validates them, and returns them
|
|
6
|
+
* grouped by type.
|
|
7
|
+
*
|
|
8
|
+
* Discovery is config-driven (not filesystem-based) so plugins explicitly
|
|
9
|
+
* opt in via their pairing flow. Import failures are non-fatal — logged and
|
|
10
|
+
* skipped so the rest of the system boots normally.
|
|
11
|
+
*/
|
|
12
|
+
import type { ChannelPlugin, ProviderPlugin, ToolsPlugin, ConfigManagerInterface } from '@tinyclaw/types';
|
|
13
|
+
export interface LoadedPlugins {
|
|
14
|
+
channels: ChannelPlugin[];
|
|
15
|
+
providers: ProviderPlugin[];
|
|
16
|
+
tools: ToolsPlugin[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Load all enabled plugins.
|
|
20
|
+
*
|
|
21
|
+
* @param configManager - Used to read the `plugins.enabled` list
|
|
22
|
+
* @returns Grouped loaded plugin instances
|
|
23
|
+
*/
|
|
24
|
+
export declare function loadPlugins(configManager: ConfigManagerInterface): Promise<LoadedPlugins>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Loader
|
|
3
|
+
*
|
|
4
|
+
* Discovers installed Tiny Claw plugins by dynamically importing package names
|
|
5
|
+
* from the `plugins.enabled` config array, validates them, and returns them
|
|
6
|
+
* grouped by type.
|
|
7
|
+
*
|
|
8
|
+
* Discovery is config-driven (not filesystem-based) so plugins explicitly
|
|
9
|
+
* opt in via their pairing flow. Import failures are non-fatal — logged and
|
|
10
|
+
* skipped so the rest of the system boots normally.
|
|
11
|
+
*/
|
|
12
|
+
import { logger } from '@tinyclaw/logger';
|
|
13
|
+
/**
|
|
14
|
+
* Load all enabled plugins.
|
|
15
|
+
*
|
|
16
|
+
* @param configManager - Used to read the `plugins.enabled` list
|
|
17
|
+
* @returns Grouped loaded plugin instances
|
|
18
|
+
*/
|
|
19
|
+
export async function loadPlugins(configManager) {
|
|
20
|
+
const result = { channels: [], providers: [], tools: [] };
|
|
21
|
+
const enabledIds = configManager.get('plugins.enabled') ?? [];
|
|
22
|
+
if (enabledIds.length === 0) {
|
|
23
|
+
logger.info('No plugins configured');
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
logger.info('Loading plugins', { count: enabledIds.length, ids: enabledIds });
|
|
27
|
+
for (const id of enabledIds) {
|
|
28
|
+
try {
|
|
29
|
+
const mod = await import(id);
|
|
30
|
+
const plugin = mod.default;
|
|
31
|
+
if (!plugin || typeof plugin !== 'object') {
|
|
32
|
+
logger.warn(`Plugin "${id}" has no default export — skipping`);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!isValidPlugin(plugin)) {
|
|
36
|
+
logger.warn(`Plugin "${id}" failed validation — skipping`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
switch (plugin.type) {
|
|
40
|
+
case 'channel':
|
|
41
|
+
result.channels.push(plugin);
|
|
42
|
+
logger.info(`Loaded channel plugin: ${plugin.name} (${plugin.id})`);
|
|
43
|
+
break;
|
|
44
|
+
case 'provider':
|
|
45
|
+
result.providers.push(plugin);
|
|
46
|
+
logger.info(`Loaded provider plugin: ${plugin.name} (${plugin.id})`);
|
|
47
|
+
break;
|
|
48
|
+
case 'tools':
|
|
49
|
+
result.tools.push(plugin);
|
|
50
|
+
logger.info(`Loaded tools plugin: ${plugin.name} (${plugin.id})`);
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
logger.warn(`Plugin "${id}" has unknown type — skipping`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
logger.warn(`Failed to load plugin "${id}": ${err.message}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/** Minimal structural validation for a plugin object. */
|
|
63
|
+
function isValidPlugin(obj) {
|
|
64
|
+
if (!obj || typeof obj !== 'object')
|
|
65
|
+
return false;
|
|
66
|
+
const p = obj;
|
|
67
|
+
return (typeof p.id === 'string' &&
|
|
68
|
+
typeof p.name === 'string' &&
|
|
69
|
+
typeof p.type === 'string' &&
|
|
70
|
+
['channel', 'provider', 'tools'].includes(p.type));
|
|
71
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tinyclaw/plugins",
|
|
3
|
+
"version": "1.0.1-dev.3004a38",
|
|
4
|
+
"description": "Config-driven plugin loader and validator for Tiny Claw",
|
|
5
|
+
"license": "GPL-3.0",
|
|
6
|
+
"author": "Waren Gonzaga",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/warengonzaga/tinyclaw.git",
|
|
16
|
+
"directory": "packages/plugins"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/warengonzaga/tinyclaw/tree/main/packages/plugins#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/warengonzaga/tinyclaw/issues"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"tinyclaw",
|
|
24
|
+
"plugins",
|
|
25
|
+
"loader"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@tinyclaw/types": "workspace:*",
|
|
32
|
+
"@tinyclaw/logger": "workspace:*"
|
|
33
|
+
}
|
|
34
|
+
}
|