@reminix/runtime 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +0,0 @@
1
- /**
2
- * Registry for auto-discovering agents, tools, and prompts from directories
3
- */
4
- import type { AgentHandler, ToolHandler } from './types';
5
- export interface Registry {
6
- agents: Record<string, AgentHandler>;
7
- tools: Record<string, ToolHandler>;
8
- prompts: Record<string, unknown>;
9
- }
10
- /**
11
- * Auto-discover and load handlers from a directory structure
12
- *
13
- * Expected structure:
14
- * handler/
15
- * agents/
16
- * chatbot.ts
17
- * assistant.ts
18
- * tools/
19
- * search.ts
20
- * prompts/
21
- * system.ts
22
- */
23
- export declare function discoverRegistry(handlerPath: string): Promise<Registry>;
24
- //# sourceMappingURL=registry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEzD,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CA4E7E"}
package/dist/registry.js DELETED
@@ -1,208 +0,0 @@
1
- /**
2
- * Registry for auto-discovering agents, tools, and prompts from directories
3
- */
4
- import { readdir, stat } from 'fs/promises';
5
- import { join, extname, basename } from 'path';
6
- import { pathToFileURL } from 'url';
7
- import { loadHandler } from './loader';
8
- /**
9
- * Auto-discover and load handlers from a directory structure
10
- *
11
- * Expected structure:
12
- * handler/
13
- * agents/
14
- * chatbot.ts
15
- * assistant.ts
16
- * tools/
17
- * search.ts
18
- * prompts/
19
- * system.ts
20
- */
21
- export async function discoverRegistry(handlerPath) {
22
- const registry = {
23
- agents: {},
24
- tools: {},
25
- prompts: {},
26
- };
27
- try {
28
- // Check if path exists and is a directory
29
- const stats = await stat(handlerPath);
30
- if (!stats.isDirectory()) {
31
- throw new Error(`Handler path must be a directory: ${handlerPath}`);
32
- }
33
- // Discover agents
34
- const agentsPath = join(handlerPath, 'agents');
35
- try {
36
- const agentsStats = await stat(agentsPath);
37
- if (agentsStats.isDirectory()) {
38
- const agents = await loadDirectory(agentsPath);
39
- // Filter to only AgentHandler types
40
- for (const [key, value] of Object.entries(agents)) {
41
- if (typeof value === 'function') {
42
- registry.agents[key] = value;
43
- }
44
- }
45
- }
46
- }
47
- catch {
48
- // agents/ directory doesn't exist, skip
49
- }
50
- // Discover tools
51
- const toolsPath = join(handlerPath, 'tools');
52
- try {
53
- const toolsStats = await stat(toolsPath);
54
- if (toolsStats.isDirectory()) {
55
- const tools = await loadDirectory(toolsPath);
56
- // Filter to only ToolHandler types
57
- for (const [key, value] of Object.entries(tools)) {
58
- if (typeof value === 'function') {
59
- registry.tools[key] = value;
60
- }
61
- }
62
- }
63
- }
64
- catch {
65
- // tools/ directory doesn't exist, skip
66
- }
67
- // Discover prompts
68
- const promptsPath = join(handlerPath, 'prompts');
69
- try {
70
- const promptsStats = await stat(promptsPath);
71
- if (promptsStats.isDirectory()) {
72
- const prompts = await loadDirectory(promptsPath);
73
- registry.prompts = prompts;
74
- }
75
- }
76
- catch {
77
- // prompts/ directory doesn't exist, skip
78
- }
79
- // Validate that at least something was discovered
80
- if (Object.keys(registry.agents).length === 0 &&
81
- Object.keys(registry.tools).length === 0 &&
82
- Object.keys(registry.prompts).length === 0) {
83
- throw new Error(`No agents, tools, or prompts found in directory: ${handlerPath}`);
84
- }
85
- return registry;
86
- }
87
- catch (error) {
88
- if (error instanceof Error) {
89
- throw new Error(`Failed to discover registry from "${handlerPath}": ${error.message}`);
90
- }
91
- throw error;
92
- }
93
- }
94
- /**
95
- * Load all handler files from a directory
96
- * Filename (without extension) becomes the key in the registry
97
- */
98
- async function loadDirectory(dirPath) {
99
- const handlers = {};
100
- try {
101
- const entries = await readdir(dirPath);
102
- for (const entry of entries) {
103
- const fullPath = join(dirPath, entry);
104
- const stats = await stat(fullPath);
105
- // Skip if not a file
106
- if (!stats.isFile()) {
107
- continue;
108
- }
109
- // Only process TypeScript/JavaScript files
110
- const ext = extname(entry);
111
- if (ext !== '.ts' && ext !== '.js' && ext !== '.mjs') {
112
- continue;
113
- }
114
- // Extract the key from filename (without extension)
115
- const key = entry.replace(ext, '');
116
- try {
117
- // Try loading as a handler file (expects agents/tools/prompts exports)
118
- const loaded = await loadHandler(fullPath);
119
- // Merge agents, tools, and prompts into the registry
120
- if (loaded.agents) {
121
- const agentKeys = Object.keys(loaded.agents);
122
- if (agentKeys.length === 1) {
123
- handlers[key] = loaded.agents[agentKeys[0]];
124
- }
125
- else {
126
- for (const agentKey of agentKeys) {
127
- handlers[`${key}.${agentKey}`] = loaded.agents[agentKey];
128
- }
129
- }
130
- }
131
- if (loaded.tools) {
132
- const toolKeys = Object.keys(loaded.tools);
133
- if (toolKeys.length === 1) {
134
- handlers[key] = loaded.tools[toolKeys[0]];
135
- }
136
- else {
137
- for (const toolKey of toolKeys) {
138
- handlers[`${key}.${toolKey}`] = loaded.tools[toolKey];
139
- }
140
- }
141
- }
142
- if (loaded.prompts) {
143
- const promptKeys = Object.keys(loaded.prompts);
144
- if (promptKeys.length === 1) {
145
- handlers[key] = loaded.prompts[promptKeys[0]];
146
- }
147
- else {
148
- for (const promptKey of promptKeys) {
149
- handlers[`${key}.${promptKey}`] = loaded.prompts[promptKey];
150
- }
151
- }
152
- }
153
- }
154
- catch {
155
- // If loadHandler fails, try loading as direct export
156
- // This handles files that export functions directly (e.g., export const chatbot)
157
- try {
158
- const fileUrl = pathToFileURL(fullPath).href;
159
- const module = await import(fileUrl);
160
- // Determine type based on directory name
161
- const dirName = basename(dirPath);
162
- // Check for direct exports matching the directory type
163
- if (dirName === 'agents') {
164
- // Look for exported function with same name as file, or any exported function
165
- const exportedFunction = module[key] || module.default;
166
- if (typeof exportedFunction === 'function') {
167
- handlers[key] = exportedFunction;
168
- }
169
- }
170
- else if (dirName === 'tools') {
171
- const exportedFunction = module[key] || module.default;
172
- if (typeof exportedFunction === 'function') {
173
- handlers[key] = exportedFunction;
174
- }
175
- }
176
- else if (dirName === 'prompts') {
177
- // For prompts, accept any export (function, object, string, etc.)
178
- // Try to get export with same name as file, or default, or any named export
179
- const exportedValue = module[key] || module.default;
180
- if (exportedValue !== undefined) {
181
- handlers[key] = exportedValue;
182
- }
183
- else {
184
- // Check if module has any exports (excluding default module properties)
185
- const moduleKeys = Object.keys(module).filter((k) => k !== 'default' && !k.startsWith('__'));
186
- if (moduleKeys.length > 0) {
187
- // Use the first export, or the module itself if it's a simple object
188
- handlers[key] = module[moduleKeys[0]] || module;
189
- }
190
- }
191
- }
192
- }
193
- catch {
194
- // Skip this file if both methods fail
195
- continue;
196
- }
197
- }
198
- }
199
- return handlers;
200
- }
201
- catch (error) {
202
- if (error instanceof Error) {
203
- throw new Error(`Failed to load directory "${dirPath}": ${error.message}`);
204
- }
205
- throw error;
206
- }
207
- }
208
- //# sourceMappingURL=registry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AASvC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAA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