@mastra/code-sdk 1.2.0-alpha.10 → 1.2.0-alpha.14
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/CHANGELOG.md +54 -0
- package/dist/agents/model.d.ts.map +1 -1
- package/dist/agents/model.js +4 -1
- package/dist/agents/model.js.map +1 -1
- package/dist/agents/modes/plan.js +2 -2
- package/dist/agents/modes/plan.js.map +1 -1
- package/dist/agents/prompts/index.d.ts.map +1 -1
- package/dist/agents/prompts/index.js +4 -1
- package/dist/agents/prompts/index.js.map +1 -1
- package/dist/agents/prompts/plan.d.ts +1 -1
- package/dist/agents/prompts/plan.d.ts.map +1 -1
- package/dist/agents/prompts/plan.js +2 -2
- package/dist/agents/prompts/plan.js.map +1 -1
- package/dist/agents/prompts/tool-guidance.d.ts +2 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -1
- package/dist/agents/prompts/tool-guidance.js +3 -2
- package/dist/agents/prompts/tool-guidance.js.map +1 -1
- package/dist/agents/tool-availability.d.ts.map +1 -1
- package/dist/agents/tool-availability.js +9 -4
- package/dist/agents/tool-availability.js.map +1 -1
- package/dist/agents/tools.js +1 -1
- package/dist/headless/cli.d.ts.map +1 -1
- package/dist/headless/cli.js +3 -0
- package/dist/headless/cli.js.map +1 -1
- package/dist/index.d.ts +68 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +173 -61
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +64 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +3 -1
- package/dist/plugin.js.map +1 -1
- package/dist/plugins/loader.d.ts +7 -3
- package/dist/plugins/loader.d.ts.map +1 -1
- package/dist/plugins/loader.js +53 -1
- package/dist/plugins/loader.js.map +1 -1
- package/dist/plugins/manager.d.ts +36 -2
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/plugins/manager.js +74 -2
- package/dist/plugins/manager.js.map +1 -1
- package/dist/plugins/signal-lane.d.ts +58 -0
- package/dist/plugins/signal-lane.d.ts.map +1 -0
- package/dist/plugins/signal-lane.js +166 -0
- package/dist/plugins/signal-lane.js.map +1 -0
- package/dist/plugins/types.d.ts +36 -0
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/utils/plans.d.ts +9 -6
- package/dist/utils/plans.d.ts.map +1 -1
- package/dist/utils/plans.js +11 -11
- package/dist/utils/plans.js.map +1 -1
- package/package.json +11 -11
package/dist/plugins/loader.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getPluginRoot } from "./paths.js";
|
|
2
2
|
import { loadPluginRegistry, mergePluginRegistries } from "./registry.js";
|
|
3
|
+
import { isSignalProvider } from "@mastra/core/signals";
|
|
3
4
|
import fs from "fs";
|
|
4
5
|
import path from "path";
|
|
5
6
|
import { pathToFileURL } from "url";
|
|
@@ -43,9 +44,13 @@ async function loadPluginRecord(record, options) {
|
|
|
43
44
|
cwd: options.projectRoot,
|
|
44
45
|
scope: record.scope,
|
|
45
46
|
pluginDir,
|
|
46
|
-
config: configValues
|
|
47
|
+
config: configValues,
|
|
48
|
+
getController: options.runtime?.getController,
|
|
49
|
+
getActiveSession: options.runtime?.getActiveSession
|
|
47
50
|
};
|
|
48
51
|
const { tools, renderConfigs } = await resolvePluginTools(plugin, context);
|
|
52
|
+
const processors = await resolvePluginProcessors(plugin, context);
|
|
53
|
+
const signalProviders = await resolvePluginSignalProviders(plugin, context);
|
|
49
54
|
const instructions = await resolvePluginInstructions(plugin, context);
|
|
50
55
|
return {
|
|
51
56
|
...record,
|
|
@@ -57,6 +62,8 @@ async function loadPluginRecord(record, options) {
|
|
|
57
62
|
tools,
|
|
58
63
|
renderConfigs,
|
|
59
64
|
toolNames: Object.keys(tools).sort(),
|
|
65
|
+
processors,
|
|
66
|
+
signalProviders,
|
|
60
67
|
skillPaths: resolveExistingAssetDirs(pluginRoot, "skills"),
|
|
61
68
|
commandPaths: resolveExistingAssetDirs(pluginRoot, "commands"),
|
|
62
69
|
configSchema,
|
|
@@ -114,6 +121,8 @@ function validatePluginExport(value) {
|
|
|
114
121
|
const plugin = value;
|
|
115
122
|
if (typeof plugin.id !== "string" || plugin.id.trim().length === 0) throw new Error("Plugin id must be a non-empty string");
|
|
116
123
|
if (plugin.tools !== void 0 && typeof plugin.tools !== "object" && typeof plugin.tools !== "function") throw new Error("Plugin tools must be an object or function");
|
|
124
|
+
if (plugin.processors !== void 0 && typeof plugin.processors !== "object" && typeof plugin.processors !== "function") throw new Error("Plugin processors must be an array, object, or function");
|
|
125
|
+
if (plugin.signalProviders !== void 0 && !Array.isArray(plugin.signalProviders) && typeof plugin.signalProviders !== "function") throw new Error("Plugin signal providers must be an array or function");
|
|
117
126
|
return plugin;
|
|
118
127
|
}
|
|
119
128
|
async function resolvePluginTools(plugin, context) {
|
|
@@ -125,6 +134,49 @@ async function resolvePluginTools(plugin, context) {
|
|
|
125
134
|
if (!entries || typeof entries !== "object" || Array.isArray(entries)) throw new Error("Plugin tools function must return an object");
|
|
126
135
|
return normalizePluginToolEntries(entries);
|
|
127
136
|
}
|
|
137
|
+
/** Mirrors {@link resolvePluginTools}: object-or-function, resolved with the same context. */
|
|
138
|
+
async function resolvePluginProcessors(plugin, context) {
|
|
139
|
+
if (!plugin.processors) return {
|
|
140
|
+
input: [],
|
|
141
|
+
output: []
|
|
142
|
+
};
|
|
143
|
+
const entries = typeof plugin.processors === "function" ? await plugin.processors(context) : plugin.processors;
|
|
144
|
+
if (!entries || typeof entries !== "object") throw new Error("Plugin processors function must return an array or object");
|
|
145
|
+
return normalizePluginProcessorEntries(entries);
|
|
146
|
+
}
|
|
147
|
+
async function resolvePluginSignalProviders(plugin, context) {
|
|
148
|
+
if (!plugin.signalProviders) return [];
|
|
149
|
+
const entries = typeof plugin.signalProviders === "function" ? await plugin.signalProviders(context) : plugin.signalProviders;
|
|
150
|
+
if (!Array.isArray(entries)) throw new Error("Plugin signal providers function must return an array");
|
|
151
|
+
for (const [index, provider] of entries.entries()) if (!isPluginSignalProvider(provider)) throw new Error(`Plugin signal provider at index ${index} must be a SignalProvider (an object with an id that implements connect, startPolling, stop and __registerMastra)`);
|
|
152
|
+
return entries;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Structural, not `instanceof`.
|
|
156
|
+
*
|
|
157
|
+
* A plugin that depends on a published provider package — the motivating case, a plugin wrapping
|
|
158
|
+
* `@mastra/github-signals` — installs that package's own copy of `@mastra/core`, so its provider is
|
|
159
|
+
* never an instance of the `SignalProvider` class Mastra Code loaded. `isSignalProvider` would reject
|
|
160
|
+
* a perfectly working provider. Nothing in the lifecycle needs class identity: the lane only calls
|
|
161
|
+
* these methods, so the methods are what is checked.
|
|
162
|
+
*/
|
|
163
|
+
function isPluginSignalProvider(value) {
|
|
164
|
+
if (isSignalProvider(value)) return true;
|
|
165
|
+
if (!value || typeof value !== "object") return false;
|
|
166
|
+
const candidate = value;
|
|
167
|
+
return typeof candidate.id === "string" && candidate.id.length > 0 && typeof candidate.connect === "function" && typeof candidate.startPolling === "function" && typeof candidate.stop === "function" && typeof candidate.__registerMastra === "function";
|
|
168
|
+
}
|
|
169
|
+
/** A bare array is shorthand for the input lane, the common case. */
|
|
170
|
+
function normalizePluginProcessorEntries(entries) {
|
|
171
|
+
const input = Array.isArray(entries) ? entries : entries.input ?? [];
|
|
172
|
+
const output = Array.isArray(entries) ? [] : entries.output ?? [];
|
|
173
|
+
if (!Array.isArray(input) || !Array.isArray(output)) throw new Error("Plugin processor lanes must be arrays");
|
|
174
|
+
for (const processor of [...input, ...output]) if (!processor || typeof processor !== "object" || typeof processor.id !== "string") throw new Error("Plugin processors must be objects with an id");
|
|
175
|
+
return {
|
|
176
|
+
input,
|
|
177
|
+
output
|
|
178
|
+
};
|
|
179
|
+
}
|
|
128
180
|
async function resolvePluginInstructions(plugin, context) {
|
|
129
181
|
if (plugin.instructions === void 0) return void 0;
|
|
130
182
|
const instructions = typeof plugin.instructions === "function" ? await plugin.instructions(context) : plugin.instructions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","names":[],"sources":["../../src/plugins/loader.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type {\n MastraCodePlugin,\n MastraCodePluginConfigSchema,\n MastraCodePluginConfigValues,\n MastraCodePluginContext,\n MastraCodePluginToolEntries,\n MastraCodePluginTools,\n MastraCodeToolRenderConfig,\n} from '../plugin.js';\nimport { getPluginRoot } from './paths.js';\nimport type { PluginPathOptions } from './paths.js';\nimport { loadPluginRegistry, mergePluginRegistries } from './registry.js';\nimport type { LoadedPlugin, PluginRegistry, ScopedInstalledPluginRecord } from './types.js';\n\nexport type LoadPluginsOptions = PluginPathOptions & {\n globalRegistry?: PluginRegistry;\n projectRegistry?: PluginRegistry;\n};\n\nexport async function loadPlugins(options: LoadPluginsOptions): Promise<LoadedPlugin[]> {\n const globalRegistry =\n options.globalRegistry ?? loadPluginRegistry(path.join(getPluginRoot('global', options), 'plugins.json'));\n const projectRegistry =\n options.projectRegistry ?? loadPluginRegistry(path.join(getPluginRoot('project', options), 'plugins.json'));\n const records = mergePluginRegistries(globalRegistry, projectRegistry);\n const loaded: LoadedPlugin[] = [];\n\n for (const record of records) {\n if (record.blocked) {\n loaded.push({ ...record, status: 'blocked', tools: {}, toolNames: [] });\n continue;\n }\n if (!record.enabled) {\n loaded.push({ ...record, status: 'inactive', tools: {}, toolNames: [] });\n continue;\n }\n\n loaded.push(await loadPluginRecord(record, options));\n }\n\n return markToolConflicts(loaded);\n}\n\nexport async function loadPluginRecord(\n record: ScopedInstalledPluginRecord,\n options: PluginPathOptions,\n): Promise<LoadedPlugin> {\n try {\n const entryPath = resolvePluginEntryPath(record, options);\n const plugin = await importPluginModule(entryPath);\n if (plugin.id !== record.id) {\n throw new Error(`Plugin id mismatch: registry has \"${record.id}\" but module exports \"${plugin.id}\"`);\n }\n\n const configSchema = validatePluginConfigSchema(plugin.config);\n const configValues = resolvePluginConfigValues(configSchema, record.config);\n const pluginDir = path.dirname(entryPath);\n const pluginRoot = resolvePluginRoot(record, options);\n const context: MastraCodePluginContext = {\n cwd: options.projectRoot,\n scope: record.scope,\n pluginDir,\n config: configValues,\n };\n const { tools, renderConfigs } = await resolvePluginTools(plugin, context);\n const instructions = await resolvePluginInstructions(plugin, context);\n\n return {\n ...record,\n name: plugin.name,\n version: plugin.version ?? record.version,\n description: plugin.description,\n instructions,\n status: 'active',\n tools,\n renderConfigs,\n toolNames: Object.keys(tools).sort(),\n skillPaths: resolveExistingAssetDirs(pluginRoot, 'skills'),\n commandPaths: resolveExistingAssetDirs(pluginRoot, 'commands'),\n configSchema,\n configValues,\n };\n } catch (error) {\n return {\n ...record,\n status: 'load failed',\n error: error instanceof Error ? error.message : String(error),\n tools: {},\n toolNames: [],\n };\n }\n}\n\nexport async function loadPluginFromEntry(entryPath: string): Promise<MastraCodePlugin> {\n return validatePluginExport(await importPluginModule(entryPath));\n}\n\nexport function resolvePluginRoot(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string {\n const scopeRoot = path.resolve(getPluginRoot(record.scope, options));\n const pluginRoot = path.resolve(path.isAbsolute(record.path) ? record.path : path.join(scopeRoot, record.path));\n if (record.source === 'github' && !isInsideDirectory(pluginRoot, scopeRoot)) {\n throw new Error(`Plugin path for \"${record.id}\" must be inside the ${record.scope} plugin directory`);\n }\n return pluginRoot;\n}\n\nexport function resolvePluginEntryPath(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string {\n const pluginRoot = resolvePluginRoot(record, options);\n const entryPath = path.resolve(pluginRoot, record.entry);\n if (!isInsideDirectory(entryPath, pluginRoot)) {\n throw new Error(`Plugin entry for \"${record.id}\" must be inside the plugin directory`);\n }\n return entryPath;\n}\n\nexport function isInsideDirectory(targetPath: string, root: string): boolean {\n const resolvedTarget = path.resolve(targetPath);\n const resolvedRoot = path.resolve(root);\n return resolvedTarget === resolvedRoot || resolvedTarget.startsWith(resolvedRoot + path.sep);\n}\n\nfunction resolveExistingAssetDirs(pluginRoot: string, dirname: 'skills' | 'commands'): string[] {\n const dir = path.join(pluginRoot, dirname);\n try {\n return fs.statSync(dir).isDirectory() ? [dir] : [];\n } catch {\n return [];\n }\n}\n\nasync function importPluginModule(entryPath: string): Promise<MastraCodePlugin> {\n if (path.extname(entryPath) !== '.ts') {\n throw new Error(\n `Unsupported plugin entry extension \"${path.extname(entryPath)}\". V1 plugins must use .ts entries.`,\n );\n }\n\n const url = pathToFileURL(entryPath);\n const stat = fs.statSync(entryPath, { bigint: true });\n url.searchParams.set('mtimeNs', stat.mtimeNs.toString());\n url.searchParams.set('size', stat.size.toString());\n const mod = (await import(url.href)) as { default?: unknown; plugin?: unknown };\n return validatePluginExport(mod.default ?? mod.plugin);\n}\n\nfunction validatePluginExport(value: unknown): MastraCodePlugin {\n if (!value || typeof value !== 'object') {\n throw new Error('Plugin module must export a plugin object as default or named \"plugin\" export');\n }\n\n const plugin = value as MastraCodePlugin;\n if (typeof plugin.id !== 'string' || plugin.id.trim().length === 0) {\n throw new Error('Plugin id must be a non-empty string');\n }\n\n if (plugin.tools !== undefined && typeof plugin.tools !== 'object' && typeof plugin.tools !== 'function') {\n throw new Error('Plugin tools must be an object or function');\n }\n\n return plugin;\n}\n\nasync function resolvePluginTools(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<{ tools: MastraCodePluginTools; renderConfigs: Record<string, MastraCodeToolRenderConfig> }> {\n if (!plugin.tools) return { tools: {}, renderConfigs: {} };\n const entries = typeof plugin.tools === 'function' ? await plugin.tools(context) : plugin.tools;\n if (!entries || typeof entries !== 'object' || Array.isArray(entries)) {\n throw new Error('Plugin tools function must return an object');\n }\n return normalizePluginToolEntries(entries);\n}\n\nasync function resolvePluginInstructions(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<string | undefined> {\n if (plugin.instructions === undefined) return undefined;\n const instructions =\n typeof plugin.instructions === 'function' ? await plugin.instructions(context) : plugin.instructions;\n if (typeof instructions !== 'string') {\n throw new Error('Plugin instructions must be a string');\n }\n const trimmed = instructions.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction normalizePluginToolEntries(entries: MastraCodePluginToolEntries): {\n tools: MastraCodePluginTools;\n renderConfigs: Record<string, MastraCodeToolRenderConfig>;\n} {\n const tools: MastraCodePluginTools = {};\n const renderConfigs: Record<string, MastraCodeToolRenderConfig> = {};\n for (const [name, entry] of Object.entries(entries)) {\n if (!isToolEntryObject(entry)) {\n throw new Error(`Plugin tool \"${name}\" must be an object with a tool property`);\n }\n tools[name] = entry.tool;\n if (entry.render) renderConfigs[name] = entry.render;\n }\n return { tools, renderConfigs };\n}\n\nfunction isToolEntryObject(entry: MastraCodePluginToolEntries[string]): entry is MastraCodePluginToolEntries[string] {\n if (!entry || typeof entry !== 'object' || !('tool' in entry)) return false;\n const tool = (entry as { tool?: unknown }).tool;\n return !!tool && typeof tool === 'object' && !Array.isArray(tool);\n}\n\nfunction validatePluginConfigSchema(schema: unknown): MastraCodePluginConfigSchema | undefined {\n if (!schema || typeof schema !== 'object' || Array.isArray(schema)) return undefined;\n const validated: MastraCodePluginConfigSchema = {};\n for (const [key, option] of Object.entries(schema)) {\n if (!option || typeof option !== 'object' || Array.isArray(option)) continue;\n const record = option as Record<string, unknown>;\n if (record.type !== 'model' && record.type !== 'boolean' && record.type !== 'string') continue;\n validated[key] = {\n type: record.type,\n ...(typeof record.label === 'string' ? { label: record.label } : {}),\n ...(typeof record.description === 'string' ? { description: record.description } : {}),\n ...(typeof record.default === 'string' || typeof record.default === 'boolean' ? { default: record.default } : {}),\n };\n }\n return Object.keys(validated).length > 0 ? validated : undefined;\n}\n\nfunction resolvePluginConfigValues(\n schema: MastraCodePluginConfigSchema | undefined,\n recordValues: Record<string, unknown> | undefined,\n): MastraCodePluginConfigValues {\n const values: MastraCodePluginConfigValues = {};\n if (!schema) return values;\n for (const [key, option] of Object.entries(schema)) {\n const value = recordValues?.[key];\n if (option.type === 'boolean') {\n values[key] = typeof value === 'boolean' ? value : typeof option.default === 'boolean' ? option.default : false;\n continue;\n }\n values[key] = typeof value === 'string' ? value : typeof option.default === 'string' ? option.default : undefined;\n }\n return values;\n}\n\nexport function collectActivePluginTools(plugins: LoadedPlugin[]): MastraCodePluginTools {\n const tools: MastraCodePluginTools = {};\n for (const plugin of plugins) {\n if (plugin.status !== 'active') continue;\n for (const [name, tool] of Object.entries(plugin.tools)) {\n if (!(name in tools)) {\n tools[name] = tool;\n }\n }\n }\n return tools;\n}\n\nfunction markToolConflicts(plugins: LoadedPlugin[]): LoadedPlugin[] {\n const seen = new Map<string, string>();\n return plugins.map(plugin => {\n if (plugin.status !== 'active') return plugin;\n const conflicts = plugin.toolNames.filter(toolName => seen.has(toolName));\n for (const toolName of plugin.toolNames) {\n if (!seen.has(toolName)) seen.set(toolName, plugin.id);\n }\n return conflicts.length > 0 ? { ...plugin, status: 'conflicted', conflicts } : plugin;\n });\n}\n"],"mappings":";;;;;;AAuBA,eAAsB,YAAY,SAAsD;CAKtF,MAAM,UAAU,sBAHd,QAAQ,kBAAkB,mBAAmB,KAAK,KAAK,cAAc,UAAU,OAAO,GAAG,cAAc,CAAC,GAExG,QAAQ,mBAAmB,mBAAmB,KAAK,KAAK,cAAc,WAAW,OAAO,GAAG,cAAc,CAAC,CACvC;CACrE,MAAM,SAAyB,CAAC;CAEhC,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,OAAO,SAAS;GAClB,OAAO,KAAK;IAAE,GAAG;IAAQ,QAAQ;IAAW,OAAO,CAAC;IAAG,WAAW,CAAC;GAAE,CAAC;GACtE;EACF;EACA,IAAI,CAAC,OAAO,SAAS;GACnB,OAAO,KAAK;IAAE,GAAG;IAAQ,QAAQ;IAAY,OAAO,CAAC;IAAG,WAAW,CAAC;GAAE,CAAC;GACvE;EACF;EAEA,OAAO,KAAK,MAAM,iBAAiB,QAAQ,OAAO,CAAC;CACrD;CAEA,OAAO,kBAAkB,MAAM;AACjC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YAAY,YAAY,OAAO,UAAU;GAC1G;EACF;EACA,OAAO,OAAO,OAAO,UAAU,WAAW,QAAQ,OAAO,OAAO,YAAY,WAAW,OAAO,UAAU,KAAA;CAC1G;CACA,OAAO;AACT;AAEA,SAAgB,yBAAyB,SAAgD;CACvF,MAAM,QAA+B,CAAC;CACtC,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,OAAO,WAAW,UAAU;EAChC,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,OAAO,KAAK,GACpD,IAAI,EAAE,QAAQ,QACZ,MAAM,QAAQ;CAGpB;CACA,OAAO;AACT;AAEA,SAAS,kBAAkB,SAAyC;CAClE,MAAM,uBAAO,IAAI,IAAoB;CACrC,OAAO,QAAQ,KAAI,WAAU;EAC3B,IAAI,OAAO,WAAW,UAAU,OAAO;EACvC,MAAM,YAAY,OAAO,UAAU,QAAO,aAAY,KAAK,IAAI,QAAQ,CAAC;EACxE,KAAK,MAAM,YAAY,OAAO,WAC5B,IAAI,CAAC,KAAK,IAAI,QAAQ,GAAG,KAAK,IAAI,UAAU,OAAO,EAAE;EAEvD,OAAO,UAAU,SAAS,IAAI;GAAE,GAAG;GAAQ,QAAQ;GAAc;EAAU,IAAI;CACjF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"loader.js","names":[],"sources":["../../src/plugins/loader.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport { isSignalProvider } from '@mastra/core/signals';\nimport type { SignalProvider } from '@mastra/core/signals';\n\nimport type {\n MastraCodePlugin,\n MastraCodePluginConfigSchema,\n MastraCodePluginConfigValues,\n MastraCodePluginContext,\n MastraCodePluginProcessorEntries,\n MastraCodePluginRuntime,\n MastraCodePluginSignalProviderEntries,\n MastraCodePluginToolEntries,\n MastraCodePluginTools,\n MastraCodeToolRenderConfig,\n} from '../plugin.js';\nimport { getPluginRoot } from './paths.js';\nimport type { PluginPathOptions } from './paths.js';\nimport { loadPluginRegistry, mergePluginRegistries } from './registry.js';\nimport type { LoadedPlugin, LoadedPluginProcessors, PluginRegistry, ScopedInstalledPluginRecord } from './types.js';\n\nexport type LoadPluginRecordOptions = PluginPathOptions & {\n /** Lazy accessors for Mastra Code's runtime, passed on to plugin field resolvers. */\n runtime?: MastraCodePluginRuntime;\n};\n\nexport type LoadPluginsOptions = LoadPluginRecordOptions & {\n globalRegistry?: PluginRegistry;\n projectRegistry?: PluginRegistry;\n};\n\nexport async function loadPlugins(options: LoadPluginsOptions): Promise<LoadedPlugin[]> {\n const globalRegistry =\n options.globalRegistry ?? loadPluginRegistry(path.join(getPluginRoot('global', options), 'plugins.json'));\n const projectRegistry =\n options.projectRegistry ?? loadPluginRegistry(path.join(getPluginRoot('project', options), 'plugins.json'));\n const records = mergePluginRegistries(globalRegistry, projectRegistry);\n const loaded: LoadedPlugin[] = [];\n\n for (const record of records) {\n if (record.blocked) {\n loaded.push({ ...record, status: 'blocked', tools: {}, toolNames: [] });\n continue;\n }\n if (!record.enabled) {\n loaded.push({ ...record, status: 'inactive', tools: {}, toolNames: [] });\n continue;\n }\n\n loaded.push(await loadPluginRecord(record, options));\n }\n\n return markToolConflicts(loaded);\n}\n\nexport async function loadPluginRecord(\n record: ScopedInstalledPluginRecord,\n options: LoadPluginRecordOptions,\n): Promise<LoadedPlugin> {\n try {\n const entryPath = resolvePluginEntryPath(record, options);\n const plugin = await importPluginModule(entryPath);\n if (plugin.id !== record.id) {\n throw new Error(`Plugin id mismatch: registry has \"${record.id}\" but module exports \"${plugin.id}\"`);\n }\n\n const configSchema = validatePluginConfigSchema(plugin.config);\n const configValues = resolvePluginConfigValues(configSchema, record.config);\n const pluginDir = path.dirname(entryPath);\n const pluginRoot = resolvePluginRoot(record, options);\n const context: MastraCodePluginContext = {\n cwd: options.projectRoot,\n scope: record.scope,\n pluginDir,\n config: configValues,\n // Accessors, not instances: plugins load before the controller and the\n // session exist, so a plugin resolves these when it needs them, not now.\n getController: options.runtime?.getController,\n getActiveSession: options.runtime?.getActiveSession,\n };\n const { tools, renderConfigs } = await resolvePluginTools(plugin, context);\n const processors = await resolvePluginProcessors(plugin, context);\n const signalProviders = await resolvePluginSignalProviders(plugin, context);\n const instructions = await resolvePluginInstructions(plugin, context);\n\n return {\n ...record,\n name: plugin.name,\n version: plugin.version ?? record.version,\n description: plugin.description,\n instructions,\n status: 'active',\n tools,\n renderConfigs,\n toolNames: Object.keys(tools).sort(),\n processors,\n signalProviders,\n skillPaths: resolveExistingAssetDirs(pluginRoot, 'skills'),\n commandPaths: resolveExistingAssetDirs(pluginRoot, 'commands'),\n configSchema,\n configValues,\n };\n } catch (error) {\n return {\n ...record,\n status: 'load failed',\n error: error instanceof Error ? error.message : String(error),\n tools: {},\n toolNames: [],\n };\n }\n}\n\nexport async function loadPluginFromEntry(entryPath: string): Promise<MastraCodePlugin> {\n return validatePluginExport(await importPluginModule(entryPath));\n}\n\nexport function resolvePluginRoot(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string {\n const scopeRoot = path.resolve(getPluginRoot(record.scope, options));\n const pluginRoot = path.resolve(path.isAbsolute(record.path) ? record.path : path.join(scopeRoot, record.path));\n if (record.source === 'github' && !isInsideDirectory(pluginRoot, scopeRoot)) {\n throw new Error(`Plugin path for \"${record.id}\" must be inside the ${record.scope} plugin directory`);\n }\n return pluginRoot;\n}\n\nexport function resolvePluginEntryPath(record: ScopedInstalledPluginRecord, options: PluginPathOptions): string {\n const pluginRoot = resolvePluginRoot(record, options);\n const entryPath = path.resolve(pluginRoot, record.entry);\n if (!isInsideDirectory(entryPath, pluginRoot)) {\n throw new Error(`Plugin entry for \"${record.id}\" must be inside the plugin directory`);\n }\n return entryPath;\n}\n\nexport function isInsideDirectory(targetPath: string, root: string): boolean {\n const resolvedTarget = path.resolve(targetPath);\n const resolvedRoot = path.resolve(root);\n return resolvedTarget === resolvedRoot || resolvedTarget.startsWith(resolvedRoot + path.sep);\n}\n\nfunction resolveExistingAssetDirs(pluginRoot: string, dirname: 'skills' | 'commands'): string[] {\n const dir = path.join(pluginRoot, dirname);\n try {\n return fs.statSync(dir).isDirectory() ? [dir] : [];\n } catch {\n return [];\n }\n}\n\nasync function importPluginModule(entryPath: string): Promise<MastraCodePlugin> {\n if (path.extname(entryPath) !== '.ts') {\n throw new Error(\n `Unsupported plugin entry extension \"${path.extname(entryPath)}\". V1 plugins must use .ts entries.`,\n );\n }\n\n const url = pathToFileURL(entryPath);\n const stat = fs.statSync(entryPath, { bigint: true });\n url.searchParams.set('mtimeNs', stat.mtimeNs.toString());\n url.searchParams.set('size', stat.size.toString());\n const mod = (await import(url.href)) as { default?: unknown; plugin?: unknown };\n return validatePluginExport(mod.default ?? mod.plugin);\n}\n\nfunction validatePluginExport(value: unknown): MastraCodePlugin {\n if (!value || typeof value !== 'object') {\n throw new Error('Plugin module must export a plugin object as default or named \"plugin\" export');\n }\n\n const plugin = value as MastraCodePlugin;\n if (typeof plugin.id !== 'string' || plugin.id.trim().length === 0) {\n throw new Error('Plugin id must be a non-empty string');\n }\n\n if (plugin.tools !== undefined && typeof plugin.tools !== 'object' && typeof plugin.tools !== 'function') {\n throw new Error('Plugin tools must be an object or function');\n }\n\n if (\n plugin.processors !== undefined &&\n typeof plugin.processors !== 'object' &&\n typeof plugin.processors !== 'function'\n ) {\n throw new Error('Plugin processors must be an array, object, or function');\n }\n\n if (\n plugin.signalProviders !== undefined &&\n !Array.isArray(plugin.signalProviders) &&\n typeof plugin.signalProviders !== 'function'\n ) {\n throw new Error('Plugin signal providers must be an array or function');\n }\n\n return plugin;\n}\n\nasync function resolvePluginTools(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<{ tools: MastraCodePluginTools; renderConfigs: Record<string, MastraCodeToolRenderConfig> }> {\n if (!plugin.tools) return { tools: {}, renderConfigs: {} };\n const entries = typeof plugin.tools === 'function' ? await plugin.tools(context) : plugin.tools;\n if (!entries || typeof entries !== 'object' || Array.isArray(entries)) {\n throw new Error('Plugin tools function must return an object');\n }\n return normalizePluginToolEntries(entries);\n}\n\n/** Mirrors {@link resolvePluginTools}: object-or-function, resolved with the same context. */\nasync function resolvePluginProcessors(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<LoadedPluginProcessors> {\n if (!plugin.processors) return { input: [], output: [] };\n const entries = typeof plugin.processors === 'function' ? await plugin.processors(context) : plugin.processors;\n if (!entries || typeof entries !== 'object') {\n throw new Error('Plugin processors function must return an array or object');\n }\n return normalizePluginProcessorEntries(entries);\n}\n\nasync function resolvePluginSignalProviders(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<MastraCodePluginSignalProviderEntries> {\n if (!plugin.signalProviders) return [];\n const entries =\n typeof plugin.signalProviders === 'function' ? await plugin.signalProviders(context) : plugin.signalProviders;\n if (!Array.isArray(entries)) {\n throw new Error('Plugin signal providers function must return an array');\n }\n for (const [index, provider] of entries.entries()) {\n if (!isPluginSignalProvider(provider)) {\n throw new Error(\n `Plugin signal provider at index ${index} must be a SignalProvider (an object with an id that implements connect, startPolling, stop and __registerMastra)`,\n );\n }\n }\n return entries;\n}\n\n/**\n * Structural, not `instanceof`.\n *\n * A plugin that depends on a published provider package — the motivating case, a plugin wrapping\n * `@mastra/github-signals` — installs that package's own copy of `@mastra/core`, so its provider is\n * never an instance of the `SignalProvider` class Mastra Code loaded. `isSignalProvider` would reject\n * a perfectly working provider. Nothing in the lifecycle needs class identity: the lane only calls\n * these methods, so the methods are what is checked.\n */\nfunction isPluginSignalProvider(value: unknown): value is SignalProvider<string> {\n if (isSignalProvider(value)) return true;\n if (!value || typeof value !== 'object') return false;\n const candidate = value as Partial<SignalProvider<string>> & { __registerMastra?: unknown };\n return (\n typeof candidate.id === 'string' &&\n candidate.id.length > 0 &&\n typeof candidate.connect === 'function' &&\n typeof candidate.startPolling === 'function' &&\n typeof candidate.stop === 'function' &&\n typeof candidate.__registerMastra === 'function'\n );\n}\n\n/** A bare array is shorthand for the input lane, the common case. */\nfunction normalizePluginProcessorEntries(entries: MastraCodePluginProcessorEntries): LoadedPluginProcessors {\n const input = Array.isArray(entries) ? entries : (entries.input ?? []);\n const output = Array.isArray(entries) ? [] : (entries.output ?? []);\n if (!Array.isArray(input) || !Array.isArray(output)) {\n throw new Error('Plugin processor lanes must be arrays');\n }\n for (const processor of [...input, ...output]) {\n if (!processor || typeof processor !== 'object' || typeof processor.id !== 'string') {\n throw new Error('Plugin processors must be objects with an id');\n }\n }\n return { input, output };\n}\n\nasync function resolvePluginInstructions(\n plugin: MastraCodePlugin,\n context: MastraCodePluginContext,\n): Promise<string | undefined> {\n if (plugin.instructions === undefined) return undefined;\n const instructions =\n typeof plugin.instructions === 'function' ? await plugin.instructions(context) : plugin.instructions;\n if (typeof instructions !== 'string') {\n throw new Error('Plugin instructions must be a string');\n }\n const trimmed = instructions.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction normalizePluginToolEntries(entries: MastraCodePluginToolEntries): {\n tools: MastraCodePluginTools;\n renderConfigs: Record<string, MastraCodeToolRenderConfig>;\n} {\n const tools: MastraCodePluginTools = {};\n const renderConfigs: Record<string, MastraCodeToolRenderConfig> = {};\n for (const [name, entry] of Object.entries(entries)) {\n if (!isToolEntryObject(entry)) {\n throw new Error(`Plugin tool \"${name}\" must be an object with a tool property`);\n }\n tools[name] = entry.tool;\n if (entry.render) renderConfigs[name] = entry.render;\n }\n return { tools, renderConfigs };\n}\n\nfunction isToolEntryObject(entry: MastraCodePluginToolEntries[string]): entry is MastraCodePluginToolEntries[string] {\n if (!entry || typeof entry !== 'object' || !('tool' in entry)) return false;\n const tool = (entry as { tool?: unknown }).tool;\n return !!tool && typeof tool === 'object' && !Array.isArray(tool);\n}\n\nfunction validatePluginConfigSchema(schema: unknown): MastraCodePluginConfigSchema | undefined {\n if (!schema || typeof schema !== 'object' || Array.isArray(schema)) return undefined;\n const validated: MastraCodePluginConfigSchema = {};\n for (const [key, option] of Object.entries(schema)) {\n if (!option || typeof option !== 'object' || Array.isArray(option)) continue;\n const record = option as Record<string, unknown>;\n if (record.type !== 'model' && record.type !== 'boolean' && record.type !== 'string') continue;\n validated[key] = {\n type: record.type,\n ...(typeof record.label === 'string' ? { label: record.label } : {}),\n ...(typeof record.description === 'string' ? { description: record.description } : {}),\n ...(typeof record.default === 'string' || typeof record.default === 'boolean' ? { default: record.default } : {}),\n };\n }\n return Object.keys(validated).length > 0 ? validated : undefined;\n}\n\nfunction resolvePluginConfigValues(\n schema: MastraCodePluginConfigSchema | undefined,\n recordValues: Record<string, unknown> | undefined,\n): MastraCodePluginConfigValues {\n const values: MastraCodePluginConfigValues = {};\n if (!schema) return values;\n for (const [key, option] of Object.entries(schema)) {\n const value = recordValues?.[key];\n if (option.type === 'boolean') {\n values[key] = typeof value === 'boolean' ? value : typeof option.default === 'boolean' ? option.default : false;\n continue;\n }\n values[key] = typeof value === 'string' ? value : typeof option.default === 'string' ? option.default : undefined;\n }\n return values;\n}\n\nexport function collectActivePluginTools(plugins: LoadedPlugin[]): MastraCodePluginTools {\n const tools: MastraCodePluginTools = {};\n for (const plugin of plugins) {\n if (plugin.status !== 'active') continue;\n for (const [name, tool] of Object.entries(plugin.tools)) {\n if (!(name in tools)) {\n tools[name] = tool;\n }\n }\n }\n return tools;\n}\n\nfunction markToolConflicts(plugins: LoadedPlugin[]): LoadedPlugin[] {\n const seen = new Map<string, string>();\n return plugins.map(plugin => {\n if (plugin.status !== 'active') return plugin;\n const conflicts = plugin.toolNames.filter(toolName => seen.has(toolName));\n for (const toolName of plugin.toolNames) {\n if (!seen.has(toolName)) seen.set(toolName, plugin.id);\n }\n return conflicts.length > 0 ? { ...plugin, status: 'conflicted', conflicts } : plugin;\n });\n}\n"],"mappings":";;;;;;;AAkCA,eAAsB,YAAY,SAAsD;CAKtF,MAAM,UAAU,sBAHd,QAAQ,kBAAkB,mBAAmB,KAAK,KAAK,cAAc,UAAU,OAAO,GAAG,cAAc,CAAC,GAExG,QAAQ,mBAAmB,mBAAmB,KAAK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D;CACvF,MAAM,QAA+B,CAAC;CACtC,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,OAAO,WAAW,UAAU;EAChC,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,OAAO,KAAK,GACpD,IAAI,EAAE,QAAQ,QACZ,MAAM,QAAQ;CAGpB;CACA,OAAO;AACT;AAEA,SAAS,kBAAkB,SAAyC;CAClE,MAAM,uBAAO,IAAI,IAAoB;CACrC,OAAO,QAAQ,KAAI,WAAU;EAC3B,IAAI,OAAO,WAAW,UAAU,OAAO;EACvC,MAAM,YAAY,OAAO,UAAU,QAAO,aAAY,KAAK,IAAI,QAAQ,CAAC;EACxE,KAAK,MAAM,YAAY,OAAO,WAC5B,IAAI,CAAC,KAAK,IAAI,QAAQ,GAAG,KAAK,IAAI,UAAU,OAAO,EAAE;EAEvD,OAAO,UAAU,SAAS,IAAI;GAAE,GAAG;GAAQ,QAAQ;GAAc;EAAU,IAAI;CACjF,CAAC;AACH"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SignalProvider } from '@mastra/core/signals';
|
|
2
|
+
import type { MastraCodePluginConfigValue, MastraCodePluginRuntime } from '../plugin.js';
|
|
2
3
|
import { discoverLocalPlugins } from './install.js';
|
|
3
4
|
import type { InstallPluginOptions } from './install.js';
|
|
4
5
|
import type { PluginPathOptions } from './paths.js';
|
|
5
|
-
import type { LoadedPlugin, PluginScope } from './types.js';
|
|
6
|
+
import type { LoadedPlugin, PluginContribution, PluginProcessorEntries, PluginScope } from './types.js';
|
|
6
7
|
type PluginManagerOptions = PluginPathOptions & {
|
|
7
8
|
githubCliPath?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Lazy accessors for Mastra Code's runtime, handed to plugin field resolvers on
|
|
11
|
+
* every load and reload.
|
|
12
|
+
*/
|
|
13
|
+
runtime?: MastraCodePluginRuntime;
|
|
8
14
|
};
|
|
9
15
|
export declare class PluginManager {
|
|
10
16
|
private readonly options;
|
|
@@ -14,12 +20,23 @@ export declare class PluginManager {
|
|
|
14
20
|
private readonly toolRenderConfigs;
|
|
15
21
|
private readonly watchedLocalEntries;
|
|
16
22
|
private readonly localEntryVersions;
|
|
23
|
+
/** Last known git HEAD per GitHub checkout, kept current by the poller. */
|
|
24
|
+
private readonly githubCheckoutHeads;
|
|
17
25
|
private githubPollTimer;
|
|
18
26
|
private githubPollInFlight;
|
|
19
27
|
private reloadInFlight;
|
|
20
28
|
private readonly reloadListeners;
|
|
21
29
|
private readonly githubUpdateListeners;
|
|
30
|
+
private runtime;
|
|
22
31
|
constructor(options: PluginManagerOptions);
|
|
32
|
+
/**
|
|
33
|
+
* Publish (or replace) the runtime accessors handed to plugin field resolvers.
|
|
34
|
+
* Takes effect on the next load or reload. `createMastraCode` calls this for
|
|
35
|
+
* every manager it uses — including an injected one — so a manager constructed
|
|
36
|
+
* without a runtime still exposes `getController`/`getActiveSession` to plugins.
|
|
37
|
+
* A manager shared across controllers sees the most recent controller's accessors.
|
|
38
|
+
*/
|
|
39
|
+
setRuntime(runtime: MastraCodePluginRuntime): void;
|
|
23
40
|
onReload(listener: (plugins: LoadedPlugin[]) => void | Promise<void>): () => void;
|
|
24
41
|
/** Notified with the display names of GitHub plugins that were updated by the background poll. */
|
|
25
42
|
onGithubPluginsUpdated(listener: (pluginNames: string[]) => void | Promise<void>): () => void;
|
|
@@ -31,7 +48,24 @@ export declare class PluginManager {
|
|
|
31
48
|
getPluginSkillPaths(): string[];
|
|
32
49
|
getPluginCommandPaths(): string[];
|
|
33
50
|
getPluginInstructions(): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Processors contributed by active plugins, tagged with the plugin that owns
|
|
53
|
+
* each one. Reads already-resolved state — no filesystem access — because the
|
|
54
|
+
* agent's processor lanes call this before every request.
|
|
55
|
+
*/
|
|
56
|
+
getPluginProcessors(): PluginProcessorEntries;
|
|
57
|
+
/** Signal providers contributed by active plugins, tagged with their owning plugin. */
|
|
58
|
+
getPluginSignalProviders(): PluginContribution<SignalProvider<string>>[];
|
|
59
|
+
private collectActive;
|
|
34
60
|
private notifyReloadListeners;
|
|
61
|
+
/**
|
|
62
|
+
* Stamps each plugin with a value that changes when its contributions should
|
|
63
|
+
* be rebuilt. Runs on every reload, so it stays off the network: GitHub heads
|
|
64
|
+
* come from the cache the poller keeps current and cost one `git rev-parse`
|
|
65
|
+
* per checkout the first time it is seen.
|
|
66
|
+
*/
|
|
67
|
+
private stampLoadedPlugins;
|
|
68
|
+
private readSourceStamp;
|
|
35
69
|
private updatePluginRenderConfigs;
|
|
36
70
|
private updatePluginTools;
|
|
37
71
|
private createLiveToolProxy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/plugins/manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/plugins/manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,KAAK,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEzF,OAAO,EAAE,oBAAoB,EAAoE,MAAM,cAAc,CAAC;AACtH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAIzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAaxG,KAAK,oBAAoB,GAAG,iBAAiB,GAAG;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACnC,CAAC;AAEF,qBAAa,aAAa;IAgBZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAfpC,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,Q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I,CAAC;IAkBV,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBrE"}
|
package/dist/plugins/manager.js
CHANGED
|
@@ -27,13 +27,27 @@ var PluginManager = class {
|
|
|
27
27
|
toolRenderConfigs = /* @__PURE__ */ new Map();
|
|
28
28
|
watchedLocalEntries = /* @__PURE__ */ new Set();
|
|
29
29
|
localEntryVersions = /* @__PURE__ */ new Map();
|
|
30
|
+
/** Last known git HEAD per GitHub checkout, kept current by the poller. */
|
|
31
|
+
githubCheckoutHeads = /* @__PURE__ */ new Map();
|
|
30
32
|
githubPollTimer;
|
|
31
33
|
githubPollInFlight;
|
|
32
34
|
reloadInFlight;
|
|
33
35
|
reloadListeners = /* @__PURE__ */ new Set();
|
|
34
36
|
githubUpdateListeners = /* @__PURE__ */ new Set();
|
|
37
|
+
runtime;
|
|
35
38
|
constructor(options) {
|
|
36
39
|
this.options = options;
|
|
40
|
+
this.runtime = options.runtime;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Publish (or replace) the runtime accessors handed to plugin field resolvers.
|
|
44
|
+
* Takes effect on the next load or reload. `createMastraCode` calls this for
|
|
45
|
+
* every manager it uses — including an injected one — so a manager constructed
|
|
46
|
+
* without a runtime still exposes `getController`/`getActiveSession` to plugins.
|
|
47
|
+
* A manager shared across controllers sees the most recent controller's accessors.
|
|
48
|
+
*/
|
|
49
|
+
setRuntime(runtime) {
|
|
50
|
+
this.runtime = runtime;
|
|
37
51
|
}
|
|
38
52
|
onReload(listener) {
|
|
39
53
|
this.reloadListeners.add(listener);
|
|
@@ -47,7 +61,11 @@ var PluginManager = class {
|
|
|
47
61
|
async reload() {
|
|
48
62
|
if (this.reloadInFlight) return this.reloadInFlight;
|
|
49
63
|
this.reloadInFlight = (async () => {
|
|
50
|
-
this.loadedPlugins = await loadPlugins(
|
|
64
|
+
this.loadedPlugins = await loadPlugins({
|
|
65
|
+
...this.options,
|
|
66
|
+
runtime: this.runtime
|
|
67
|
+
});
|
|
68
|
+
await this.stampLoadedPlugins(this.loadedPlugins);
|
|
51
69
|
this.updateLocalEntryWatchers(this.loadedPlugins);
|
|
52
70
|
this.updateGithubPoller(this.loadedPlugins);
|
|
53
71
|
this.updatePluginRenderConfigs(this.loadedPlugins);
|
|
@@ -81,9 +99,60 @@ var PluginManager = class {
|
|
|
81
99
|
getPluginInstructions() {
|
|
82
100
|
return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" && plugin.instructions ? [plugin.instructions] : []);
|
|
83
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Processors contributed by active plugins, tagged with the plugin that owns
|
|
104
|
+
* each one. Reads already-resolved state — no filesystem access — because the
|
|
105
|
+
* agent's processor lanes call this before every request.
|
|
106
|
+
*/
|
|
107
|
+
getPluginProcessors() {
|
|
108
|
+
return {
|
|
109
|
+
input: this.collectActive((plugin) => plugin.processors?.input ?? []),
|
|
110
|
+
output: this.collectActive((plugin) => plugin.processors?.output ?? [])
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Signal providers contributed by active plugins, tagged with their owning plugin. */
|
|
114
|
+
getPluginSignalProviders() {
|
|
115
|
+
return this.collectActive((plugin) => plugin.signalProviders ?? []);
|
|
116
|
+
}
|
|
117
|
+
collectActive(select) {
|
|
118
|
+
return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" ? select(plugin).map((value) => ({
|
|
119
|
+
pluginId: plugin.id,
|
|
120
|
+
versionStamp: plugin.versionStamp ?? "",
|
|
121
|
+
value
|
|
122
|
+
})) : []);
|
|
123
|
+
}
|
|
84
124
|
async notifyReloadListeners(plugins) {
|
|
85
125
|
await Promise.all([...this.reloadListeners].map((listener) => Promise.resolve(listener(plugins))));
|
|
86
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Stamps each plugin with a value that changes when its contributions should
|
|
129
|
+
* be rebuilt. Runs on every reload, so it stays off the network: GitHub heads
|
|
130
|
+
* come from the cache the poller keeps current and cost one `git rev-parse`
|
|
131
|
+
* per checkout the first time it is seen.
|
|
132
|
+
*/
|
|
133
|
+
async stampLoadedPlugins(plugins) {
|
|
134
|
+
for (const plugin of plugins) plugin.versionStamp = [
|
|
135
|
+
plugin.status,
|
|
136
|
+
await this.readSourceStamp(plugin),
|
|
137
|
+
JSON.stringify(plugin.configValues ?? {})
|
|
138
|
+
].join("|");
|
|
139
|
+
}
|
|
140
|
+
async readSourceStamp(plugin) {
|
|
141
|
+
try {
|
|
142
|
+
if (plugin.source === "github") {
|
|
143
|
+
const checkoutPath = this.resolvePluginSourcePath(plugin);
|
|
144
|
+
let head = this.githubCheckoutHeads.get(checkoutPath);
|
|
145
|
+
if (head === void 0) {
|
|
146
|
+
head = await this.readGitHead(checkoutPath);
|
|
147
|
+
this.githubCheckoutHeads.set(checkoutPath, head);
|
|
148
|
+
}
|
|
149
|
+
return head;
|
|
150
|
+
}
|
|
151
|
+
return getEntryVersion(resolvePluginEntryPath(plugin, this.options));
|
|
152
|
+
} catch {
|
|
153
|
+
return "";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
87
156
|
updatePluginRenderConfigs(plugins) {
|
|
88
157
|
this.toolRenderConfigs.clear();
|
|
89
158
|
for (const plugin of plugins) {
|
|
@@ -188,6 +257,7 @@ var PluginManager = class {
|
|
|
188
257
|
const before = await this.readGitHead(checkoutPath);
|
|
189
258
|
const checkoutChanged = await this.refreshGithubCheckout(plugin, checkoutPath, before);
|
|
190
259
|
const after = await this.readGitHead(checkoutPath);
|
|
260
|
+
this.githubCheckoutHeads.set(checkoutPath, after);
|
|
191
261
|
if (checkoutChanged || before !== after) changedCheckouts.add(checkoutPath);
|
|
192
262
|
}
|
|
193
263
|
if (changedCheckouts.size === 0) return false;
|
|
@@ -311,7 +381,7 @@ var PluginManager = class {
|
|
|
311
381
|
}
|
|
312
382
|
resolvePluginSourcePath(plugin) {
|
|
313
383
|
const paths = getPluginScopePaths(plugin.scope, this.options);
|
|
314
|
-
return path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path);
|
|
384
|
+
return path.resolve(path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path));
|
|
315
385
|
}
|
|
316
386
|
async readGitHead(cwd) {
|
|
317
387
|
const { stdout } = await execa("git", ["rev-parse", "HEAD"], gitExecOptions(cwd));
|
|
@@ -333,6 +403,7 @@ var PluginManager = class {
|
|
|
333
403
|
...this.options,
|
|
334
404
|
...options
|
|
335
405
|
});
|
|
406
|
+
this.githubCheckoutHeads.clear();
|
|
336
407
|
await this.reload();
|
|
337
408
|
return id;
|
|
338
409
|
}
|
|
@@ -374,6 +445,7 @@ var PluginManager = class {
|
|
|
374
445
|
recursive: true,
|
|
375
446
|
force: true
|
|
376
447
|
});
|
|
448
|
+
this.githubCheckoutHeads.delete(checkoutPath);
|
|
377
449
|
}
|
|
378
450
|
await this.reload();
|
|
379
451
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","names":[],"sources":["../../src/plugins/manager.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { execa } from 'execa';\n\nimport type { MastraCodePluginConfigValue } from '../plugin.js';\nimport { getEntryPackageRoot, installPluginDependenciesForEntry } from './dependencies.js';\nimport { discoverLocalPlugins, installGithubPlugin, installLocalPlugin, NON_INTERACTIVE_GIT_ENV } from './install.js';\nimport type { InstallPluginOptions } from './install.js';\nimport { collectActivePluginTools, isInsideDirectory, loadPlugins, resolvePluginEntryPath } from './loader.js';\nimport { ensureMastraCodePackageLink } from './package-link.js';\nimport { getPluginScopePaths } from './paths.js';\nimport type { PluginPathOptions } from './paths.js';\nimport { loadPluginRegistry, removePluginRecord, savePluginRegistry, setPluginRecord } from './registry.js';\nimport type { LoadedPlugin, PluginScope } from './types.js';\n\nconst GITHUB_PLUGIN_POLL_INTERVAL_MS = 60_000;\n\nfunction gitExecOptions(cwd: string) {\n return { cwd, env: NON_INTERACTIVE_GIT_ENV };\n}\n\nfunction getEntryVersion(entryPath: string): string {\n const stat = fs.statSync(entryPath, { bigint: true });\n return `${stat.mtimeNs}:${stat.size}`;\n}\n\ntype PluginManagerOptions = PluginPathOptions & {\n githubCliPath?: string;\n};\n\nexport class PluginManager {\n private loadedPlugins: LoadedPlugin[] = [];\n private readonly pluginTools: ReturnType<typeof collectActivePluginTools> = {};\n private readonly rawPluginTools: ReturnType<typeof collectActivePluginTools> = {};\n private readonly toolRenderConfigs = new Map<string, NonNullable<LoadedPlugin['renderConfigs']>[string]>();\n private readonly watchedLocalEntries = new Set<string>();\n private readonly localEntryVersions = new Map<string, string>();\n private githubPollTimer: ReturnType<typeof setInterval> | undefined;\n private githubPollInFlight: Promise<boolean> | undefined;\n private reloadInFlight: Promise<LoadedPlugin[]> | undefined;\n private readonly reloadListeners = new Set<(plugins: LoadedPlugin[]) => void | Promise<void>>();\n private readonly githubUpdateListeners = new Set<(pluginNames: string[]) => void | Promise<void>>();\n\n constructor(private readonly options: PluginManagerOptions) {}\n\n onReload(listener: (plugins: LoadedPlugin[]) => void | Promise<void>): () => void {\n this.reloadListeners.add(listener);\n return () => this.reloadListeners.delete(listener);\n }\n\n /** Notified with the display names of GitHub plugins that were updated by the background poll. */\n onGithubPluginsUpdated(listener: (pluginNames: string[]) => void | Promise<void>): () => void {\n this.githubUpdateListeners.add(listener);\n return () => this.githubUpdateListeners.delete(listener);\n }\n\n async reload(): Promise<LoadedPlugin[]> {\n if (this.reloadInFlight) return this.reloadInFlight;\n\n this.reloadInFlight = (async () => {\n this.loadedPlugins = await loadPlugins(this.options);\n this.updateLocalEntryWatchers(this.loadedPlugins);\n this.updateGithubPoller(this.loadedPlugins);\n this.updatePluginRenderConfigs(this.loadedPlugins);\n this.updatePluginTools(collectActivePluginTools(this.loadedPlugins));\n await this.notifyReloadListeners(this.loadedPlugins);\n return this.loadedPlugins;\n })().finally(() => {\n this.reloadInFlight = undefined;\n });\n\n return this.reloadInFlight;\n }\n\n async listPlugins(): Promise<LoadedPlugin[]> {\n if (this.loadedPlugins.length === 0) {\n await this.reload();\n }\n return this.loadedPlugins;\n }\n\n getLoadedPlugins(): LoadedPlugin[] {\n return this.loadedPlugins;\n }\n\n getPluginTools() {\n return this.pluginTools;\n }\n\n getToolRenderConfig(toolName: string) {\n return this.toolRenderConfigs.get(toolName);\n }\n\n getPluginSkillPaths(): string[] {\n return this.loadedPlugins.flatMap(plugin => (plugin.status === 'active' ? (plugin.skillPaths ?? []) : []));\n }\n\n getPluginCommandPaths(): string[] {\n return this.loadedPlugins.flatMap(plugin => (plugin.status === 'active' ? (plugin.commandPaths ?? []) : []));\n }\n\n getPluginInstructions(): string[] {\n return this.loadedPlugins.flatMap(plugin =>\n plugin.status === 'active' && plugin.instructions ? [plugin.instructions] : [],\n );\n }\n\n private async notifyReloadListeners(plugins: LoadedPlugin[]): Promise<void> {\n await Promise.all([...this.reloadListeners].map(listener => Promise.resolve(listener(plugins))));\n }\n\n private updatePluginRenderConfigs(plugins: LoadedPlugin[]): void {\n this.toolRenderConfigs.clear();\n for (const plugin of plugins) {\n if (plugin.status !== 'active') continue;\n for (const [toolName, renderConfig] of Object.entries(plugin.renderConfigs ?? {})) {\n if (!this.toolRenderConfigs.has(toolName)) {\n this.toolRenderConfigs.set(toolName, renderConfig);\n }\n }\n }\n }\n\n private updatePluginTools(nextTools: ReturnType<typeof collectActivePluginTools>): void {\n for (const name of Object.keys(this.rawPluginTools)) {\n if (!(name in nextTools)) {\n delete this.rawPluginTools[name];\n delete this.pluginTools[name];\n }\n }\n\n for (const [name, tool] of Object.entries(nextTools)) {\n this.rawPluginTools[name] = tool;\n if (!this.pluginTools[name]) {\n this.pluginTools[name] = this.createLiveToolProxy(name);\n }\n this.syncLiveToolProxy(name, tool);\n }\n }\n\n private createLiveToolProxy(toolName: string) {\n return {\n execute: async (...args: any[]) => {\n await this.reloadChangedLocalPlugins();\n const latestTool = this.rawPluginTools[toolName];\n if (!latestTool?.execute) {\n throw new Error(`Plugin tool \"${toolName}\" is no longer available`);\n }\n return (latestTool.execute as (...args: any[]) => unknown)(...args);\n },\n } as LoadedPlugin['tools'][string];\n }\n\n private syncLiveToolProxy(toolName: string, tool: LoadedPlugin['tools'][string]): void {\n const proxy = this.pluginTools[toolName];\n if (!proxy) return;\n const mutableProxy = proxy as unknown as Record<string, unknown>;\n for (const key of Object.keys(mutableProxy)) {\n delete mutableProxy[key];\n }\n Object.assign(proxy, tool);\n proxy.execute = this.createLiveToolProxy(toolName).execute;\n }\n\n private async reloadChangedLocalPlugins(): Promise<void> {\n for (const plugin of this.loadedPlugins) {\n if (plugin.source !== 'local' || plugin.status !== 'active') continue;\n const entryPath = resolvePluginEntryPath(plugin, this.options);\n const currentVersion = getEntryVersion(entryPath);\n if (this.localEntryVersions.get(entryPath) !== currentVersion) {\n await this.reload();\n return;\n }\n }\n }\n\n private updateLocalEntryWatchers(plugins: LoadedPlugin[]): void {\n const nextEntries = new Set<string>();\n for (const plugin of plugins) {\n if (plugin.source !== 'local' || plugin.status !== 'active') continue;\n let entryPath: string;\n let entryVersion: string;\n try {\n entryPath = resolvePluginEntryPath(plugin, this.options);\n entryVersion = getEntryVersion(entryPath);\n } catch {\n continue;\n }\n nextEntries.add(entryPath);\n this.localEntryVersions.set(entryPath, entryVersion);\n if (this.watchedLocalEntries.has(entryPath)) continue;\n\n const watcher = fs.watchFile(entryPath, { interval: 500 }, (current, previous) => {\n if (current.mtimeMs === previous.mtimeMs) return;\n void this.reload().catch(() => undefined);\n });\n watcher.unref?.();\n this.watchedLocalEntries.add(entryPath);\n }\n\n for (const entryPath of this.watchedLocalEntries) {\n if (nextEntries.has(entryPath)) continue;\n fs.unwatchFile(entryPath);\n this.watchedLocalEntries.delete(entryPath);\n this.localEntryVersions.delete(entryPath);\n }\n }\n\n private updateGithubPoller(plugins: LoadedPlugin[]): void {\n const hasGithubPlugin = plugins.some(\n plugin => plugin.source === 'github' && plugin.status !== 'inactive' && plugin.status !== 'blocked',\n );\n if (hasGithubPlugin && !this.githubPollTimer) {\n this.githubPollTimer = setInterval(() => {\n void this.pollGithubSourcesForUpdates().catch(() => undefined);\n }, GITHUB_PLUGIN_POLL_INTERVAL_MS);\n this.githubPollTimer.unref?.();\n }\n if (!hasGithubPlugin && this.githubPollTimer) {\n clearInterval(this.githubPollTimer);\n this.githubPollTimer = undefined;\n }\n }\n\n async pollGithubSourcesForUpdates(): Promise<boolean> {\n if (this.githubPollInFlight) return this.githubPollInFlight;\n this.githubPollInFlight = this.pollGithubSourcesForUpdatesOnce().finally(() => {\n this.githubPollInFlight = undefined;\n });\n return this.githubPollInFlight;\n }\n\n private async pollGithubSourcesForUpdatesOnce(): Promise<boolean> {\n const changedCheckouts = new Set<string>();\n const seen = new Set<string>();\n for (const plugin of this.loadedPlugins) {\n if (plugin.source !== 'github' || plugin.status === 'inactive' || plugin.status === 'blocked') continue;\n const checkoutPath = this.resolvePluginSourcePath(plugin);\n if (seen.has(checkoutPath) || !fs.existsSync(path.join(checkoutPath, '.git'))) continue;\n seen.add(checkoutPath);\n\n const before = await this.readGitHead(checkoutPath);\n const checkoutChanged = await this.refreshGithubCheckout(plugin, checkoutPath, before);\n const after = await this.readGitHead(checkoutPath);\n if (checkoutChanged || before !== after) changedCheckouts.add(checkoutPath);\n }\n\n if (changedCheckouts.size === 0) return false;\n\n await this.reload();\n // Derive names from the reloaded state so a manifest display-name change reports the new name.\n // Multiple plugins can share one checkout — report every plugin whose source changed.\n const updatedPluginNames = this.loadedPlugins\n .filter(\n plugin =>\n plugin.source === 'github' &&\n plugin.status !== 'inactive' &&\n plugin.status !== 'blocked' &&\n changedCheckouts.has(this.resolvePluginSourcePath(plugin)),\n )\n .map(plugin => plugin.name ?? plugin.id);\n await this.notifyGithubUpdateListeners(updatedPluginNames);\n return true;\n }\n\n private async notifyGithubUpdateListeners(pluginNames: string[]): Promise<void> {\n await Promise.all([...this.githubUpdateListeners].map(listener => Promise.resolve(listener(pluginNames))));\n }\n\n private async refreshGithubCheckout(\n plugin: LoadedPlugin,\n checkoutPath: string,\n currentHead: string,\n ): Promise<boolean> {\n await execa('git', ['fetch', 'origin'], gitExecOptions(checkoutPath));\n const upstream = await this.resolveGitUpstream(checkoutPath, plugin.ref);\n if (!upstream) return false;\n const [localOnly, remoteOnly] = await this.readGitAheadBehind(checkoutPath, upstream);\n const hasLocalChanges = await this.hasGitWorkingTreeChanges(checkoutPath);\n\n if (localOnly > 0 || hasLocalChanges) {\n await this.backupGitCheckout(checkoutPath, currentHead, hasLocalChanges);\n }\n\n if (remoteOnly > 0 || localOnly > 0 || hasLocalChanges) {\n await execa('git', ['reset', '--hard', upstream], gitExecOptions(checkoutPath));\n try {\n await installPluginDependenciesForEntry(checkoutPath, plugin.entry);\n ensureMastraCodePackageLink(getEntryPackageRoot(checkoutPath, plugin.entry));\n } catch (error) {\n await execa('git', ['reset', '--hard', currentHead], gitExecOptions(checkoutPath));\n throw error;\n }\n return true;\n }\n\n return false;\n }\n\n private async backupGitCheckout(\n checkoutPath: string,\n currentHead: string,\n includeWorkingTree: boolean,\n ): Promise<void> {\n const backupBranch = this.createGitBackupBranchName(currentHead);\n\n if (includeWorkingTree) {\n const currentBranch = await this.readGitCurrentBranch(checkoutPath);\n await execa('git', ['switch', '-c', backupBranch], gitExecOptions(checkoutPath));\n await execa('git', ['add', '-A'], gitExecOptions(checkoutPath));\n const hasStagedChanges = await this.hasGitStagedChanges(checkoutPath);\n if (hasStagedChanges) {\n await execa(\n 'git',\n [\n '-c',\n 'user.name=Mastra Code',\n '-c',\n 'user.email=noreply@mastra.ai',\n 'commit',\n '-m',\n 'chore: backup local plugin checkout changes',\n ],\n gitExecOptions(checkoutPath),\n );\n }\n await this.restoreGitCheckout(checkoutPath, currentBranch, currentHead);\n return;\n }\n\n await execa('git', ['branch', backupBranch, 'HEAD'], gitExecOptions(checkoutPath));\n }\n\n private async resolveGitUpstream(cwd: string, installedRef?: string): Promise<string | undefined> {\n try {\n const { stdout } = await execa(\n 'git',\n ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'],\n gitExecOptions(cwd),\n );\n return stdout.trim();\n } catch {\n return installedRef ? undefined : 'origin/main';\n }\n }\n\n private async readGitAheadBehind(cwd: string, upstream: string): Promise<[number, number]> {\n const { stdout } = await execa(\n 'git',\n ['rev-list', '--left-right', '--count', `HEAD...${upstream}`],\n gitExecOptions(cwd),\n );\n const [ahead = '0', behind = '0'] = stdout.trim().split(/\\s+/);\n return [Number(ahead) || 0, Number(behind) || 0];\n }\n\n private async hasGitWorkingTreeChanges(cwd: string): Promise<boolean> {\n const { stdout } = await execa('git', ['status', '--porcelain'], gitExecOptions(cwd));\n return stdout.trim().length > 0;\n }\n\n private async hasGitStagedChanges(cwd: string): Promise<boolean> {\n try {\n await execa('git', ['diff', '--cached', '--quiet'], gitExecOptions(cwd));\n return false;\n } catch {\n return true;\n }\n }\n\n private async restoreGitCheckout(cwd: string, branch: string | undefined, fallbackHead: string): Promise<void> {\n if (branch) {\n await execa('git', ['switch', branch], gitExecOptions(cwd));\n return;\n }\n await execa('git', ['checkout', fallbackHead], gitExecOptions(cwd));\n }\n\n private async readGitCurrentBranch(cwd: string): Promise<string | undefined> {\n const { stdout } = await execa('git', ['branch', '--show-current'], gitExecOptions(cwd));\n const branch = stdout.trim();\n return branch.length > 0 ? branch : undefined;\n }\n\n private createGitBackupBranchName(currentHead: string): string {\n const timestamp = new Date().toISOString().replace(/[:.]/g, '-');\n return `mastracode/plugin-backup/${timestamp}-${currentHead.slice(0, 8)}`;\n }\n\n private resolvePluginSourcePath(plugin: LoadedPlugin): string {\n const paths = getPluginScopePaths(plugin.scope, this.options);\n return path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path);\n }\n\n private async readGitHead(cwd: string): Promise<string> {\n const { stdout } = await execa('git', ['rev-parse', 'HEAD'], gitExecOptions(cwd));\n return stdout.trim();\n }\n\n discoverLocal(searchRoot = '.'): ReturnType<typeof discoverLocalPlugins> {\n return discoverLocalPlugins(searchRoot, this.options);\n }\n\n async installLocal(\n localPath: string,\n scope: PluginScope,\n options: Pick<InstallPluginOptions, 'entry'> = {},\n ): Promise<string> {\n const id = await installLocalPlugin(localPath, scope, { ...this.options, ...options });\n await this.reload();\n return id;\n }\n\n async installGithub(\n url: string,\n scope: PluginScope,\n options: Pick<InstallPluginOptions, 'entry' | 'ref' | 'onOutput' | 'signal'> = {},\n ): Promise<string> {\n const id = await installGithubPlugin(url, scope, { ...this.options, ...options });\n await this.reload();\n return id;\n }\n\n async setEnabled(pluginId: string, scope: PluginScope, enabled: boolean): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, { ...record, enabled }));\n await this.reload();\n }\n\n async setConfigValue(\n pluginId: string,\n scope: PluginScope,\n key: string,\n value: MastraCodePluginConfigValue,\n ): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n const config = { ...(record.config ?? {}) };\n if (value === undefined || value === '') {\n delete config[key];\n } else {\n config[key] = value;\n }\n const nextRecord = { ...record, config: Object.keys(config).length > 0 ? config : undefined };\n savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, nextRecord));\n await this.reload();\n }\n\n async uninstall(pluginId: string, scope: PluginScope): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n\n savePluginRegistry(paths.registryPath, removePluginRecord(registry, pluginId));\n if (record.source === 'github') {\n const checkoutPath = path.resolve(\n path.isAbsolute(record.path) ? record.path : path.join(paths.root, record.path),\n );\n const githubSourcesPath = path.resolve(paths.sourcesPath, 'github');\n if (isInsideDirectory(checkoutPath, githubSourcesPath)) {\n fs.rmSync(checkoutPath, { recursive: true, force: true });\n }\n }\n await this.reload();\n }\n}\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,iCAAiC;AAEvC,SAAS,eAAe,KAAa;CACnC,OAAO;EAAE;EAAK,KAAK;CAAwB;AAC7C;AAEA,SAAS,gBAAgB,WAA2B;CAClD,MAAM,OAAO,GAAG,SAAS,WAAW,EAAE,QAAQ,KAAK,CAAC;CACpD,OAAO,GAAG,KAAK,QAAQ,GAAG,KAAK;AACjC;AAMA,IAAa,gBAAb,MAA2B;CAaI;CAZ7B,gBAAwC,CAAC;CACzC,cAA4E,CAAC;CAC7E,iBAA+E,CAAC;CAChF,oCAAqC,IAAI,IAAgE;CACzG,sCAAuC,IAAI,IAAY;CACvD,qCAAsC,IAAI,IAAoB;CAC9D;CACA;CACA;CACA,kCAAmC,IAAI,IAAuD;CAC9F,wCAAyC,IAAI,IAAqD;CAElG,YAAY,SAAgD;EAA/B,KAAA,UAAA;CAAgC;CAE7D,SAAS,UAAyE;EAChF,KAAK,gBAAgB,IAAI,QAAQ;EACjC,aAAa,KAAK,gBAAgB,OAAO,QAAQ;CACnD;;CAGA,uBAAuB,UAAuE;EAC5F,KAAK,sBAAsB,IAAI,QAAQ;EACvC,aAAa,KAAK,sBAAsB,OAAO,QAAQ;CACzD;CAEA,MAAM,SAAkC;EACtC,IAAI,KAAK,gBAAgB,OAAO,KAAK;EAErC,KAAK,kBAAkB,YAAY;GACjC,KAAK,gBAAgB,MAAM,YAAY,KAAK,OAAO;GACnD,KAAK,yBAAyB,KAAK,aAAa;GAChD,KAAK,mBAAmB,KAAK,aAAa;GAC1C,KAAK,0BAA0B,KAAK,aAAa;GACjD,KAAK,kBAAkB,yBAAyB,KAAK,aAAa,CAAC;GACnE,MAAM,KAAK,sBAAsB,KAAK,aAAa;GACnD,OAAO,KA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,EAAG;EAC1C,IAAI,UAAU,KAAA,KAAa,UAAU,IACnC,OAAO,OAAO;OAEd,OAAO,OAAO;EAEhB,MAAM,aAAa;GAAE,GAAG;GAAQ,QAAQ,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,IAAI,SAAS,KAAA;EAAU;EAC5F,mBAAmB,MAAM,cAAc,gBAAgB,UAAU,UAAU,UAAU,CAAC;EACtF,MAAM,KAAK,OAAO;CACpB;CAEA,MAAM,UAAU,UAAkB,OAAmC;EACnE,MAAM,QAAQ,oBAAoB,OAAO,KAAK,OAAO;EACrD,MAAM,WAAW,mBAAmB,MAAM,YAAY;EACtD,MAAM,SAAS,SAAS,QAAQ;EAChC,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,WAAW,SAAS,wBAAwB,MAAM,OAAO;EAG3E,mBAAmB,MAAM,cAAc,mBAAmB,UAAU,QAAQ,CAAC;EAC7E,IAAI,OAAO,WAAW,UAAU;GAC9B,MAAM,eAAe,KAAK,QACxB,KAAK,WAAW,OAAO,IAAI,IAAI,OAAO,OAAO,KAAK,KAAK,MAAM,MAAM,OAAO,IAAI,CAChF;GAEA,IAAI,kBAAkB,cADI,KAAK,QAAQ,MAAM,aAAa,QACN,CAAC,GACnD,GAAG,OAAO,cAAc;IAAE,WAAW;IAAM,OAAO;GAAK,CAAC;EAE5D;EACA,MAAM,KAAK,OAAO;CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"manager.js","names":[],"sources":["../../src/plugins/manager.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport type { SignalProvider } from '@mastra/core/signals';\nimport { execa } from 'execa';\n\nimport type { MastraCodePluginConfigValue, MastraCodePluginRuntime } from '../plugin.js';\nimport { getEntryPackageRoot, installPluginDependenciesForEntry } from './dependencies.js';\nimport { discoverLocalPlugins, installGithubPlugin, installLocalPlugin, NON_INTERACTIVE_GIT_ENV } from './install.js';\nimport type { InstallPluginOptions } from './install.js';\nimport { collectActivePluginTools, isInsideDirectory, loadPlugins, resolvePluginEntryPath } from './loader.js';\nimport { ensureMastraCodePackageLink } from './package-link.js';\nimport { getPluginScopePaths } from './paths.js';\nimport type { PluginPathOptions } from './paths.js';\nimport { loadPluginRegistry, removePluginRecord, savePluginRegistry, setPluginRecord } from './registry.js';\nimport type { LoadedPlugin, PluginContribution, PluginProcessorEntries, PluginScope } from './types.js';\n\nconst GITHUB_PLUGIN_POLL_INTERVAL_MS = 60_000;\n\nfunction gitExecOptions(cwd: string) {\n return { cwd, env: NON_INTERACTIVE_GIT_ENV };\n}\n\nfunction getEntryVersion(entryPath: string): string {\n const stat = fs.statSync(entryPath, { bigint: true });\n return `${stat.mtimeNs}:${stat.size}`;\n}\n\ntype PluginManagerOptions = PluginPathOptions & {\n githubCliPath?: string;\n /**\n * Lazy accessors for Mastra Code's runtime, handed to plugin field resolvers on\n * every load and reload.\n */\n runtime?: MastraCodePluginRuntime;\n};\n\nexport class PluginManager {\n private loadedPlugins: LoadedPlugin[] = [];\n private readonly pluginTools: ReturnType<typeof collectActivePluginTools> = {};\n private readonly rawPluginTools: ReturnType<typeof collectActivePluginTools> = {};\n private readonly toolRenderConfigs = new Map<string, NonNullable<LoadedPlugin['renderConfigs']>[string]>();\n private readonly watchedLocalEntries = new Set<string>();\n private readonly localEntryVersions = new Map<string, string>();\n /** Last known git HEAD per GitHub checkout, kept current by the poller. */\n private readonly githubCheckoutHeads = new Map<string, string>();\n private githubPollTimer: ReturnType<typeof setInterval> | undefined;\n private githubPollInFlight: Promise<boolean> | undefined;\n private reloadInFlight: Promise<LoadedPlugin[]> | undefined;\n private readonly reloadListeners = new Set<(plugins: LoadedPlugin[]) => void | Promise<void>>();\n private readonly githubUpdateListeners = new Set<(pluginNames: string[]) => void | Promise<void>>();\n private runtime: MastraCodePluginRuntime | undefined;\n\n constructor(private readonly options: PluginManagerOptions) {\n this.runtime = options.runtime;\n }\n\n /**\n * Publish (or replace) the runtime accessors handed to plugin field resolvers.\n * Takes effect on the next load or reload. `createMastraCode` calls this for\n * every manager it uses — including an injected one — so a manager constructed\n * without a runtime still exposes `getController`/`getActiveSession` to plugins.\n * A manager shared across controllers sees the most recent controller's accessors.\n */\n setRuntime(runtime: MastraCodePluginRuntime): void {\n this.runtime = runtime;\n }\n\n onReload(listener: (plugins: LoadedPlugin[]) => void | Promise<void>): () => void {\n this.reloadListeners.add(listener);\n return () => this.reloadListeners.delete(listener);\n }\n\n /** Notified with the display names of GitHub plugins that were updated by the background poll. */\n onGithubPluginsUpdated(listener: (pluginNames: string[]) => void | Promise<void>): () => void {\n this.githubUpdateListeners.add(listener);\n return () => this.githubUpdateListeners.delete(listener);\n }\n\n async reload(): Promise<LoadedPlugin[]> {\n if (this.reloadInFlight) return this.reloadInFlight;\n\n this.reloadInFlight = (async () => {\n this.loadedPlugins = await loadPlugins({ ...this.options, runtime: this.runtime });\n await this.stampLoadedPlugins(this.loadedPlugins);\n this.updateLocalEntryWatchers(this.loadedPlugins);\n this.updateGithubPoller(this.loadedPlugins);\n this.updatePluginRenderConfigs(this.loadedPlugins);\n this.updatePluginTools(collectActivePluginTools(this.loadedPlugins));\n await this.notifyReloadListeners(this.loadedPlugins);\n return this.loadedPlugins;\n })().finally(() => {\n this.reloadInFlight = undefined;\n });\n\n return this.reloadInFlight;\n }\n\n async listPlugins(): Promise<LoadedPlugin[]> {\n if (this.loadedPlugins.length === 0) {\n await this.reload();\n }\n return this.loadedPlugins;\n }\n\n getLoadedPlugins(): LoadedPlugin[] {\n return this.loadedPlugins;\n }\n\n getPluginTools() {\n return this.pluginTools;\n }\n\n getToolRenderConfig(toolName: string) {\n return this.toolRenderConfigs.get(toolName);\n }\n\n getPluginSkillPaths(): string[] {\n return this.loadedPlugins.flatMap(plugin => (plugin.status === 'active' ? (plugin.skillPaths ?? []) : []));\n }\n\n getPluginCommandPaths(): string[] {\n return this.loadedPlugins.flatMap(plugin => (plugin.status === 'active' ? (plugin.commandPaths ?? []) : []));\n }\n\n getPluginInstructions(): string[] {\n return this.loadedPlugins.flatMap(plugin =>\n plugin.status === 'active' && plugin.instructions ? [plugin.instructions] : [],\n );\n }\n\n /**\n * Processors contributed by active plugins, tagged with the plugin that owns\n * each one. Reads already-resolved state — no filesystem access — because the\n * agent's processor lanes call this before every request.\n */\n getPluginProcessors(): PluginProcessorEntries {\n return {\n input: this.collectActive(plugin => plugin.processors?.input ?? []),\n output: this.collectActive(plugin => plugin.processors?.output ?? []),\n };\n }\n\n /** Signal providers contributed by active plugins, tagged with their owning plugin. */\n getPluginSignalProviders(): PluginContribution<SignalProvider<string>>[] {\n return this.collectActive(plugin => plugin.signalProviders ?? []);\n }\n\n private collectActive<TValue>(select: (plugin: LoadedPlugin) => TValue[]): PluginContribution<TValue>[] {\n return this.loadedPlugins.flatMap(plugin =>\n plugin.status === 'active'\n ? select(plugin).map(value => ({ pluginId: plugin.id, versionStamp: plugin.versionStamp ?? '', value }))\n : [],\n );\n }\n\n private async notifyReloadListeners(plugins: LoadedPlugin[]): Promise<void> {\n await Promise.all([...this.reloadListeners].map(listener => Promise.resolve(listener(plugins))));\n }\n\n /**\n * Stamps each plugin with a value that changes when its contributions should\n * be rebuilt. Runs on every reload, so it stays off the network: GitHub heads\n * come from the cache the poller keeps current and cost one `git rev-parse`\n * per checkout the first time it is seen.\n */\n private async stampLoadedPlugins(plugins: LoadedPlugin[]): Promise<void> {\n for (const plugin of plugins) {\n plugin.versionStamp = [\n plugin.status,\n await this.readSourceStamp(plugin),\n JSON.stringify(plugin.configValues ?? {}),\n ].join('|');\n }\n }\n\n private async readSourceStamp(plugin: LoadedPlugin): Promise<string> {\n try {\n if (plugin.source === 'github') {\n const checkoutPath = this.resolvePluginSourcePath(plugin);\n let head = this.githubCheckoutHeads.get(checkoutPath);\n if (head === undefined) {\n head = await this.readGitHead(checkoutPath);\n this.githubCheckoutHeads.set(checkoutPath, head);\n }\n return head;\n }\n return getEntryVersion(resolvePluginEntryPath(plugin, this.options));\n } catch {\n // A plugin that failed to load has no readable source. Its stamp is then\n // status + config, which is enough to notice when it starts working.\n return '';\n }\n }\n\n private updatePluginRenderConfigs(plugins: LoadedPlugin[]): void {\n this.toolRenderConfigs.clear();\n for (const plugin of plugins) {\n if (plugin.status !== 'active') continue;\n for (const [toolName, renderConfig] of Object.entries(plugin.renderConfigs ?? {})) {\n if (!this.toolRenderConfigs.has(toolName)) {\n this.toolRenderConfigs.set(toolName, renderConfig);\n }\n }\n }\n }\n\n private updatePluginTools(nextTools: ReturnType<typeof collectActivePluginTools>): void {\n for (const name of Object.keys(this.rawPluginTools)) {\n if (!(name in nextTools)) {\n delete this.rawPluginTools[name];\n delete this.pluginTools[name];\n }\n }\n\n for (const [name, tool] of Object.entries(nextTools)) {\n this.rawPluginTools[name] = tool;\n if (!this.pluginTools[name]) {\n this.pluginTools[name] = this.createLiveToolProxy(name);\n }\n this.syncLiveToolProxy(name, tool);\n }\n }\n\n private createLiveToolProxy(toolName: string) {\n return {\n execute: async (...args: any[]) => {\n await this.reloadChangedLocalPlugins();\n const latestTool = this.rawPluginTools[toolName];\n if (!latestTool?.execute) {\n throw new Error(`Plugin tool \"${toolName}\" is no longer available`);\n }\n return (latestTool.execute as (...args: any[]) => unknown)(...args);\n },\n } as LoadedPlugin['tools'][string];\n }\n\n private syncLiveToolProxy(toolName: string, tool: LoadedPlugin['tools'][string]): void {\n const proxy = this.pluginTools[toolName];\n if (!proxy) return;\n const mutableProxy = proxy as unknown as Record<string, unknown>;\n for (const key of Object.keys(mutableProxy)) {\n delete mutableProxy[key];\n }\n Object.assign(proxy, tool);\n proxy.execute = this.createLiveToolProxy(toolName).execute;\n }\n\n private async reloadChangedLocalPlugins(): Promise<void> {\n for (const plugin of this.loadedPlugins) {\n if (plugin.source !== 'local' || plugin.status !== 'active') continue;\n const entryPath = resolvePluginEntryPath(plugin, this.options);\n const currentVersion = getEntryVersion(entryPath);\n if (this.localEntryVersions.get(entryPath) !== currentVersion) {\n await this.reload();\n return;\n }\n }\n }\n\n private updateLocalEntryWatchers(plugins: LoadedPlugin[]): void {\n const nextEntries = new Set<string>();\n for (const plugin of plugins) {\n if (plugin.source !== 'local' || plugin.status !== 'active') continue;\n let entryPath: string;\n let entryVersion: string;\n try {\n entryPath = resolvePluginEntryPath(plugin, this.options);\n entryVersion = getEntryVersion(entryPath);\n } catch {\n continue;\n }\n nextEntries.add(entryPath);\n this.localEntryVersions.set(entryPath, entryVersion);\n if (this.watchedLocalEntries.has(entryPath)) continue;\n\n const watcher = fs.watchFile(entryPath, { interval: 500 }, (current, previous) => {\n if (current.mtimeMs === previous.mtimeMs) return;\n void this.reload().catch(() => undefined);\n });\n watcher.unref?.();\n this.watchedLocalEntries.add(entryPath);\n }\n\n for (const entryPath of this.watchedLocalEntries) {\n if (nextEntries.has(entryPath)) continue;\n fs.unwatchFile(entryPath);\n this.watchedLocalEntries.delete(entryPath);\n this.localEntryVersions.delete(entryPath);\n }\n }\n\n private updateGithubPoller(plugins: LoadedPlugin[]): void {\n const hasGithubPlugin = plugins.some(\n plugin => plugin.source === 'github' && plugin.status !== 'inactive' && plugin.status !== 'blocked',\n );\n if (hasGithubPlugin && !this.githubPollTimer) {\n this.githubPollTimer = setInterval(() => {\n void this.pollGithubSourcesForUpdates().catch(() => undefined);\n }, GITHUB_PLUGIN_POLL_INTERVAL_MS);\n this.githubPollTimer.unref?.();\n }\n if (!hasGithubPlugin && this.githubPollTimer) {\n clearInterval(this.githubPollTimer);\n this.githubPollTimer = undefined;\n }\n }\n\n async pollGithubSourcesForUpdates(): Promise<boolean> {\n if (this.githubPollInFlight) return this.githubPollInFlight;\n this.githubPollInFlight = this.pollGithubSourcesForUpdatesOnce().finally(() => {\n this.githubPollInFlight = undefined;\n });\n return this.githubPollInFlight;\n }\n\n private async pollGithubSourcesForUpdatesOnce(): Promise<boolean> {\n const changedCheckouts = new Set<string>();\n const seen = new Set<string>();\n for (const plugin of this.loadedPlugins) {\n if (plugin.source !== 'github' || plugin.status === 'inactive' || plugin.status === 'blocked') continue;\n const checkoutPath = this.resolvePluginSourcePath(plugin);\n if (seen.has(checkoutPath) || !fs.existsSync(path.join(checkoutPath, '.git'))) continue;\n seen.add(checkoutPath);\n\n const before = await this.readGitHead(checkoutPath);\n const checkoutChanged = await this.refreshGithubCheckout(plugin, checkoutPath, before);\n const after = await this.readGitHead(checkoutPath);\n // Feed the cache before reloading: the stamp is computed during reload and\n // has to see the new head, or a real update would look unchanged.\n this.githubCheckoutHeads.set(checkoutPath, after);\n if (checkoutChanged || before !== after) changedCheckouts.add(checkoutPath);\n }\n\n if (changedCheckouts.size === 0) return false;\n\n await this.reload();\n // Derive names from the reloaded state so a manifest display-name change reports the new name.\n // Multiple plugins can share one checkout — report every plugin whose source changed.\n const updatedPluginNames = this.loadedPlugins\n .filter(\n plugin =>\n plugin.source === 'github' &&\n plugin.status !== 'inactive' &&\n plugin.status !== 'blocked' &&\n changedCheckouts.has(this.resolvePluginSourcePath(plugin)),\n )\n .map(plugin => plugin.name ?? plugin.id);\n await this.notifyGithubUpdateListeners(updatedPluginNames);\n return true;\n }\n\n private async notifyGithubUpdateListeners(pluginNames: string[]): Promise<void> {\n await Promise.all([...this.githubUpdateListeners].map(listener => Promise.resolve(listener(pluginNames))));\n }\n\n private async refreshGithubCheckout(\n plugin: LoadedPlugin,\n checkoutPath: string,\n currentHead: string,\n ): Promise<boolean> {\n await execa('git', ['fetch', 'origin'], gitExecOptions(checkoutPath));\n const upstream = await this.resolveGitUpstream(checkoutPath, plugin.ref);\n if (!upstream) return false;\n const [localOnly, remoteOnly] = await this.readGitAheadBehind(checkoutPath, upstream);\n const hasLocalChanges = await this.hasGitWorkingTreeChanges(checkoutPath);\n\n if (localOnly > 0 || hasLocalChanges) {\n await this.backupGitCheckout(checkoutPath, currentHead, hasLocalChanges);\n }\n\n if (remoteOnly > 0 || localOnly > 0 || hasLocalChanges) {\n await execa('git', ['reset', '--hard', upstream], gitExecOptions(checkoutPath));\n try {\n await installPluginDependenciesForEntry(checkoutPath, plugin.entry);\n ensureMastraCodePackageLink(getEntryPackageRoot(checkoutPath, plugin.entry));\n } catch (error) {\n await execa('git', ['reset', '--hard', currentHead], gitExecOptions(checkoutPath));\n throw error;\n }\n return true;\n }\n\n return false;\n }\n\n private async backupGitCheckout(\n checkoutPath: string,\n currentHead: string,\n includeWorkingTree: boolean,\n ): Promise<void> {\n const backupBranch = this.createGitBackupBranchName(currentHead);\n\n if (includeWorkingTree) {\n const currentBranch = await this.readGitCurrentBranch(checkoutPath);\n await execa('git', ['switch', '-c', backupBranch], gitExecOptions(checkoutPath));\n await execa('git', ['add', '-A'], gitExecOptions(checkoutPath));\n const hasStagedChanges = await this.hasGitStagedChanges(checkoutPath);\n if (hasStagedChanges) {\n await execa(\n 'git',\n [\n '-c',\n 'user.name=Mastra Code',\n '-c',\n 'user.email=noreply@mastra.ai',\n 'commit',\n '-m',\n 'chore: backup local plugin checkout changes',\n ],\n gitExecOptions(checkoutPath),\n );\n }\n await this.restoreGitCheckout(checkoutPath, currentBranch, currentHead);\n return;\n }\n\n await execa('git', ['branch', backupBranch, 'HEAD'], gitExecOptions(checkoutPath));\n }\n\n private async resolveGitUpstream(cwd: string, installedRef?: string): Promise<string | undefined> {\n try {\n const { stdout } = await execa(\n 'git',\n ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'],\n gitExecOptions(cwd),\n );\n return stdout.trim();\n } catch {\n return installedRef ? undefined : 'origin/main';\n }\n }\n\n private async readGitAheadBehind(cwd: string, upstream: string): Promise<[number, number]> {\n const { stdout } = await execa(\n 'git',\n ['rev-list', '--left-right', '--count', `HEAD...${upstream}`],\n gitExecOptions(cwd),\n );\n const [ahead = '0', behind = '0'] = stdout.trim().split(/\\s+/);\n return [Number(ahead) || 0, Number(behind) || 0];\n }\n\n private async hasGitWorkingTreeChanges(cwd: string): Promise<boolean> {\n const { stdout } = await execa('git', ['status', '--porcelain'], gitExecOptions(cwd));\n return stdout.trim().length > 0;\n }\n\n private async hasGitStagedChanges(cwd: string): Promise<boolean> {\n try {\n await execa('git', ['diff', '--cached', '--quiet'], gitExecOptions(cwd));\n return false;\n } catch {\n return true;\n }\n }\n\n private async restoreGitCheckout(cwd: string, branch: string | undefined, fallbackHead: string): Promise<void> {\n if (branch) {\n await execa('git', ['switch', branch], gitExecOptions(cwd));\n return;\n }\n await execa('git', ['checkout', fallbackHead], gitExecOptions(cwd));\n }\n\n private async readGitCurrentBranch(cwd: string): Promise<string | undefined> {\n const { stdout } = await execa('git', ['branch', '--show-current'], gitExecOptions(cwd));\n const branch = stdout.trim();\n return branch.length > 0 ? branch : undefined;\n }\n\n private createGitBackupBranchName(currentHead: string): string {\n const timestamp = new Date().toISOString().replace(/[:.]/g, '-');\n return `mastracode/plugin-backup/${timestamp}-${currentHead.slice(0, 8)}`;\n }\n\n private resolvePluginSourcePath(plugin: LoadedPlugin): string {\n const paths = getPluginScopePaths(plugin.scope, this.options);\n // Normalized so cache keys derived here match the `path.resolve`-normalized\n // key that `uninstall` deletes with.\n return path.resolve(path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path));\n }\n\n private async readGitHead(cwd: string): Promise<string> {\n const { stdout } = await execa('git', ['rev-parse', 'HEAD'], gitExecOptions(cwd));\n return stdout.trim();\n }\n\n discoverLocal(searchRoot = '.'): ReturnType<typeof discoverLocalPlugins> {\n return discoverLocalPlugins(searchRoot, this.options);\n }\n\n async installLocal(\n localPath: string,\n scope: PluginScope,\n options: Pick<InstallPluginOptions, 'entry'> = {},\n ): Promise<string> {\n const id = await installLocalPlugin(localPath, scope, { ...this.options, ...options });\n await this.reload();\n return id;\n }\n\n async installGithub(\n url: string,\n scope: PluginScope,\n options: Pick<InstallPluginOptions, 'entry' | 'ref' | 'onOutput' | 'signal'> = {},\n ): Promise<string> {\n const id = await installGithubPlugin(url, scope, { ...this.options, ...options });\n // Installing over an existing checkout replaces it at the same path, so the\n // cached head would make a genuinely different commit stamp as unchanged and\n // leave the previous signal providers running.\n this.githubCheckoutHeads.clear();\n await this.reload();\n return id;\n }\n\n async setEnabled(pluginId: string, scope: PluginScope, enabled: boolean): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, { ...record, enabled }));\n await this.reload();\n }\n\n async setConfigValue(\n pluginId: string,\n scope: PluginScope,\n key: string,\n value: MastraCodePluginConfigValue,\n ): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n const config = { ...(record.config ?? {}) };\n if (value === undefined || value === '') {\n delete config[key];\n } else {\n config[key] = value;\n }\n const nextRecord = { ...record, config: Object.keys(config).length > 0 ? config : undefined };\n savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, nextRecord));\n await this.reload();\n }\n\n async uninstall(pluginId: string, scope: PluginScope): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n\n savePluginRegistry(paths.registryPath, removePluginRecord(registry, pluginId));\n if (record.source === 'github') {\n const checkoutPath = path.resolve(\n path.isAbsolute(record.path) ? record.path : path.join(paths.root, record.path),\n );\n const githubSourcesPath = path.resolve(paths.sourcesPath, 'github');\n if (isInsideDirectory(checkoutPath, githubSourcesPath)) {\n fs.rmSync(checkoutPath, { recursive: true, force: true });\n }\n this.githubCheckoutHeads.delete(checkoutPath);\n }\n await this.reload();\n }\n}\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,iCAAiC;AAEvC,SAAS,eAAe,KAAa;CACnC,OAAO;EAAE;EAAK,KAAK;CAAwB;AAC7C;AAEA,SAAS,gBAA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,UAAU,CAAC;EACtF,MAAM,KAAK,OAAO;CACpB;CAEA,MAAM,UAAU,UAAkB,OAAmC;EACnE,MAAM,QAAQ,oBAAoB,OAAO,KAAK,OAAO;EACrD,MAAM,WAAW,mBAAmB,MAAM,YAAY;EACtD,MAAM,SAAS,SAAS,QAAQ;EAChC,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,WAAW,SAAS,wBAAwB,MAAM,OAAO;EAG3E,mBAAmB,MAAM,cAAc,mBAAmB,UAAU,QAAQ,CAAC;EAC7E,IAAI,OAAO,WAAW,UAAU;GAC9B,MAAM,eAAe,KAAK,QACxB,KAAK,WAAW,OAAO,IAAI,IAAI,OAAO,OAAO,KAAK,KAAK,MAAM,MAAM,OAAO,IAAI,CAChF;GAEA,IAAI,kBAAkB,cADI,KAAK,QAAQ,MAAM,aAAa,QACN,CAAC,GACnD,GAAG,OAAO,cAAc;IAAE,WAAW;IAAM,OAAO;GAAK,CAAC;GAE1D,KAAK,oBAAoB,OAAO,YAAY;EAC9C;EACA,MAAM,KAAK,OAAO;CACpB;AACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Agent } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
import type { InputProcessorOrWorkflow, OutputProcessorOrWorkflow } from '@mastra/core/processors';
|
|
4
|
+
import type { SignalProvider } from '@mastra/core/signals';
|
|
5
|
+
import type { PluginContribution } from './types.js';
|
|
6
|
+
export type PluginSignalLaneOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Ids of providers Mastra Code wires itself (through the Agent constructor).
|
|
9
|
+
* The lane refuses to start a provider that collides with one of them:
|
|
10
|
+
* two live instances of the same provider silently clobber each other's
|
|
11
|
+
* polling, and the built-ins are invisible to the lane's own registry.
|
|
12
|
+
*/
|
|
13
|
+
reservedProviderIds?: string[];
|
|
14
|
+
onError?: (message: string, error: unknown) => void;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Owns the lifecycle of signal providers contributed by plugins.
|
|
18
|
+
*
|
|
19
|
+
* Providers are long-lived; processors are per-request. The Agent constructor
|
|
20
|
+
* conflates the two — it harvests a provider's processors into a closure that
|
|
21
|
+
* can never be undone — so plugin providers are deliberately kept out of the
|
|
22
|
+
* `signals` array and driven from here instead, through the same public methods
|
|
23
|
+
* the constructor uses. That is what makes a provider removable when its plugin
|
|
24
|
+
* is disabled, updated or uninstalled.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PluginSignalLane {
|
|
27
|
+
#private;
|
|
28
|
+
constructor(options?: PluginSignalLaneOptions);
|
|
29
|
+
getInputProcessors(): readonly InputProcessorOrWorkflow[];
|
|
30
|
+
getOutputProcessors(): readonly OutputProcessorOrWorkflow[];
|
|
31
|
+
/**
|
|
32
|
+
* Reconciles the live providers against a freshly loaded plugin list.
|
|
33
|
+
*
|
|
34
|
+
* A plugin whose stamp is unchanged keeps the provider instance it already
|
|
35
|
+
* has, and the freshly resolved one is dropped without ever being registered,
|
|
36
|
+
* connected or polled — reload re-runs every plugin's resolver, so unchanged
|
|
37
|
+
* plugins hand over new instances on every call.
|
|
38
|
+
*
|
|
39
|
+
* Providers of plugins that went inactive, failed to load or were uninstalled
|
|
40
|
+
* are absent from the contributions and get stopped here.
|
|
41
|
+
*/
|
|
42
|
+
sync(contributions: PluginContribution<SignalProvider<string>>[]): void;
|
|
43
|
+
/**
|
|
44
|
+
* Called once Mastra exists. Providers resolved before then are registered and
|
|
45
|
+
* started here — without a Mastra instance a provider has no storage, and
|
|
46
|
+
* nothing else will ever hand it one: the Agent propagates Mastra only to the
|
|
47
|
+
* providers in its own `signals` array, which these deliberately are not in.
|
|
48
|
+
*/
|
|
49
|
+
setMastra(mastra: Mastra, agent: Agent): void;
|
|
50
|
+
/**
|
|
51
|
+
* Retires every live provider and empties both processor lanes. The inverse of
|
|
52
|
+
* `sync()`, for a caller that is done with this lane — an embedder sharing one
|
|
53
|
+
* `PluginManager` across controllers would otherwise leave a controller's
|
|
54
|
+
* providers polling after it is gone.
|
|
55
|
+
*/
|
|
56
|
+
stopAll(): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=signal-lane.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-lane.d.ts","sourceRoot":"","sources":["../../src/plugins/signal-lane.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AASrD,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACrD,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,gBAAgB;;gBAYf,OAAO,GAAE,uBAA4B;IASjD,kBAAkB,IAAI,SAAS,wBAAwB,EAAE;IAIzD,mBAAmB,IAAI,SAAS,yBAAyB,EAAE;IAI3D;;;;;;;;;;OAUG;IACH,IAAI,CAAC,aAAa,EAAE,kBAAkB,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,IAAI;IA+BvE;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAO7C;;;;;OAKG;IACH,OAAO,IAAI,IAAI;CAyGhB"}
|