This commit is contained in:
Oleg Maslov
2026-09-02 10:14:22 +02:00
parent 0c3e2ead3b
commit b20b138fe4
771 changed files with 161561 additions and 9027 deletions

View File

@@ -13,6 +13,9 @@
"build": "tsc",
"test": "node ../../node_modules/vitest/vitest.mjs run --root ../.. --config vitest.config.ts packages/sdk/tests"
},
"dependencies": {
"@waggle/shared": "*"
},
"devDependencies": {
"typescript": "^5.9.3",
"vitest": "^4.0.18"

View File

@@ -8,6 +8,7 @@
import { EventEmitter } from 'events';
import { existsSync } from 'fs';
import { join } from 'path';
import { RISK_LEVELS, riskAtLeast, type RiskLevel } from '@waggle/shared';
import type { PluginManifest } from './plugin-manifest.js';
// ---------------------------------------------------------------------------
@@ -22,6 +23,8 @@ export interface PluginToolDef {
name: string;
description: string;
parameters: Record<string, unknown>;
/** Optional declaration; runtime normalization enforces a medium floor. */
riskLevel?: RiskLevel;
}
/** A fully-hydrated tool with an execute function, created during activation */
@@ -29,9 +32,18 @@ export interface PluginTool {
name: string;
description: string;
parameters: Record<string, unknown>;
riskLevel: RiskLevel;
execute: (args: Record<string, unknown>) => Promise<string>;
}
function normalizePluginToolRisk(value: unknown): RiskLevel {
if ((RISK_LEVELS as readonly unknown[]).includes(value)) {
const declared = value as RiskLevel;
if (riskAtLeast(declared, 'medium')) return declared;
}
return 'medium';
}
/** Extended manifest that includes tool declarations */
export interface PluginManifestWithTools extends PluginManifest {
tools?: PluginToolDef[];
@@ -130,6 +142,7 @@ export class PluginRuntime extends EventEmitter {
name: def.name,
description: def.description,
parameters: def.parameters,
riskLevel: normalizePluginToolRisk(def.riskLevel),
execute: executor(def),
}));

View File

@@ -102,7 +102,12 @@ describe('PluginManager', () => {
afterEach(() => {
for (const dir of tempDirs) {
fs.rmSync(dir, { recursive: true, force: true });
fs.rmSync(dir, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 100,
});
}
tempDirs.length = 0;
});