@portel/photon-core 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-ui.js.map +1 -1
- package/dist/base.d.ts +39 -0
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +49 -0
- package/dist/base.js.map +1 -1
- package/dist/generator.d.ts +12 -1
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/mixins.d.ts.map +1 -1
- package/dist/mixins.js +20 -0
- package/dist/mixins.js.map +1 -1
- package/dist/photon-loader-lite.d.ts +54 -0
- package/dist/photon-loader-lite.d.ts.map +1 -0
- package/dist/photon-loader-lite.js +436 -0
- package/dist/photon-loader-lite.js.map +1 -0
- package/dist/schedule.d.ts +157 -0
- package/dist/schedule.d.ts.map +1 -0
- package/dist/schedule.js +283 -0
- package/dist/schedule.js.map +1 -0
- package/dist/schema-extractor.d.ts +10 -6
- package/dist/schema-extractor.d.ts.map +1 -1
- package/dist/schema-extractor.js +63 -25
- package/dist/schema-extractor.js.map +1 -1
- package/dist/types.d.ts +11 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/auto-ui.ts +2 -2
- package/src/base.ts +51 -0
- package/src/generator.ts +14 -1
- package/src/index.ts +15 -1
- package/src/mixins.ts +22 -0
- package/src/photon-loader-lite.ts +594 -0
- package/src/schedule.ts +365 -0
- package/src/schema-extractor.ts +73 -25
- package/src/types.ts +7 -1
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Photon Loader Lite — Direct TypeScript API
|
|
3
|
+
*
|
|
4
|
+
* Load a .photon.ts file and get a fully-enhanced instance with all
|
|
5
|
+
* runtime features: middleware, memory, scheduling, events, __meta.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { photon } from '@portel/photon-core';
|
|
10
|
+
*
|
|
11
|
+
* const todo = await photon('./todo.photon.ts');
|
|
12
|
+
* await todo.add({ title: 'Buy milk' });
|
|
13
|
+
* // ✅ @cached, @throttled, @retry all work
|
|
14
|
+
* // ✅ this.memory, this.schedule work
|
|
15
|
+
* // ✅ @stateful events emitted, __meta attached
|
|
16
|
+
* // ✅ @photon dependencies recursively loaded
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import * as fs from 'fs/promises';
|
|
20
|
+
import * as path from 'path';
|
|
21
|
+
import { pathToFileURL } from 'url';
|
|
22
|
+
import { compilePhotonTS } from './compiler.js';
|
|
23
|
+
import { findPhotonClass } from './class-detection.js';
|
|
24
|
+
import { SchemaExtractor } from './schema-extractor.js';
|
|
25
|
+
import { buildMiddlewareChain, builtinRegistry, MiddlewareRegistry, } from './middleware.js';
|
|
26
|
+
import { withPhotonCapabilities } from './mixins.js';
|
|
27
|
+
import { toEnvVarName, parseEnvValue } from './env-utils.js';
|
|
28
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
29
|
+
// Loading state (cycle detection, caching)
|
|
30
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
31
|
+
/** Currently-loading photon paths for cycle detection */
|
|
32
|
+
const loadingPaths = new Set();
|
|
33
|
+
/** Cache of loaded photon instances (keyed by absolutePath::instanceName) */
|
|
34
|
+
const instanceCache = new Map();
|
|
35
|
+
/** Dedup concurrent loads */
|
|
36
|
+
const loadPromises = new Map();
|
|
37
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
38
|
+
// Main API
|
|
39
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
40
|
+
/**
|
|
41
|
+
* Load a .photon.ts file and return a fully-enhanced instance.
|
|
42
|
+
*
|
|
43
|
+
* The returned object has all methods working with middleware (@cached, @retry, etc.),
|
|
44
|
+
* memory, scheduling, @stateful event emission, and cross-photon calls.
|
|
45
|
+
*
|
|
46
|
+
* @param filePath Path to the .photon.ts file (absolute or relative to cwd)
|
|
47
|
+
* @param options Optional configuration
|
|
48
|
+
* @returns Enhanced photon instance with all runtime features
|
|
49
|
+
*/
|
|
50
|
+
export async function photon(filePath, options = {}) {
|
|
51
|
+
// Resolve to absolute path
|
|
52
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
53
|
+
? filePath
|
|
54
|
+
: path.resolve(process.cwd(), filePath);
|
|
55
|
+
const instanceName = options.instanceName || '';
|
|
56
|
+
const cacheKey = instanceName ? `${absolutePath}::${instanceName}` : absolutePath;
|
|
57
|
+
// Cycle detection (must come before dedup check to avoid deadlock)
|
|
58
|
+
if (loadingPaths.has(absolutePath)) {
|
|
59
|
+
const chain = Array.from(loadingPaths).concat(absolutePath).join(' → ');
|
|
60
|
+
throw new Error(`Circular @photon dependency: ${chain}`);
|
|
61
|
+
}
|
|
62
|
+
// Return cached instance
|
|
63
|
+
if (instanceCache.has(cacheKey)) {
|
|
64
|
+
return instanceCache.get(cacheKey);
|
|
65
|
+
}
|
|
66
|
+
// Dedup concurrent loads
|
|
67
|
+
if (loadPromises.has(cacheKey)) {
|
|
68
|
+
return loadPromises.get(cacheKey);
|
|
69
|
+
}
|
|
70
|
+
const promise = loadPhotonInternal(absolutePath, cacheKey, options);
|
|
71
|
+
loadPromises.set(cacheKey, promise);
|
|
72
|
+
try {
|
|
73
|
+
const result = await promise;
|
|
74
|
+
instanceCache.set(cacheKey, result);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
loadPromises.delete(cacheKey);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Clear the photon instance cache. Useful for testing.
|
|
83
|
+
*/
|
|
84
|
+
export function clearPhotonCache() {
|
|
85
|
+
instanceCache.clear();
|
|
86
|
+
}
|
|
87
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
88
|
+
// Internal pipeline
|
|
89
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
90
|
+
async function loadPhotonInternal(absolutePath, cacheKey, options) {
|
|
91
|
+
loadingPaths.add(absolutePath);
|
|
92
|
+
try {
|
|
93
|
+
// 1. Read source
|
|
94
|
+
const source = await fs.readFile(absolutePath, 'utf-8');
|
|
95
|
+
// 2. Compile TypeScript → JavaScript
|
|
96
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
|
|
97
|
+
const cacheDir = path.join(homeDir, '.photon', 'cache');
|
|
98
|
+
const compiledPath = await compilePhotonTS(absolutePath, { cacheDir });
|
|
99
|
+
// 3. Import compiled module
|
|
100
|
+
const moduleUrl = pathToFileURL(compiledPath).href;
|
|
101
|
+
const module = await import(moduleUrl);
|
|
102
|
+
// 4. Find the Photon class
|
|
103
|
+
const PhotonClass = findPhotonClass(module);
|
|
104
|
+
if (!PhotonClass) {
|
|
105
|
+
throw new Error(`No Photon class found in ${absolutePath}`);
|
|
106
|
+
}
|
|
107
|
+
// 5. Derive photon name from file path
|
|
108
|
+
const photonName = derivePhotonName(absolutePath);
|
|
109
|
+
// 6. Extract schema for middleware and metadata
|
|
110
|
+
const extractor = new SchemaExtractor();
|
|
111
|
+
const metadata = extractor.extractAllFromSource(source);
|
|
112
|
+
const toolSchemas = metadata.tools;
|
|
113
|
+
// 7. Resolve constructor injections
|
|
114
|
+
const injections = extractor.resolveInjections(source, photonName);
|
|
115
|
+
const constructorArgs = await resolveConstructorArgs(injections, photonName, absolutePath, options);
|
|
116
|
+
// 8. Enhance class with capabilities (for plain classes)
|
|
117
|
+
const EnhancedClass = withPhotonCapabilities(PhotonClass);
|
|
118
|
+
// 9. Instantiate
|
|
119
|
+
const instance = new EnhancedClass(...constructorArgs);
|
|
120
|
+
// 10. Set photon identity
|
|
121
|
+
instance._photonName = photonName;
|
|
122
|
+
if (options.instanceName) {
|
|
123
|
+
instance.instanceName = options.instanceName;
|
|
124
|
+
}
|
|
125
|
+
if (options.sessionId) {
|
|
126
|
+
instance._sessionId = options.sessionId;
|
|
127
|
+
}
|
|
128
|
+
// 11. Wire reactive collections
|
|
129
|
+
wireReactiveCollections(instance);
|
|
130
|
+
// 12. Wrap @stateful methods (event emission + __meta)
|
|
131
|
+
wrapStatefulMethods(instance, source, options.onEvent);
|
|
132
|
+
// 13. Inject MCP factory if provided
|
|
133
|
+
if (options.mcpFactory && typeof instance.setMCPFactory === 'function') {
|
|
134
|
+
instance.setMCPFactory(options.mcpFactory);
|
|
135
|
+
}
|
|
136
|
+
// 14. Inject cross-photon call handler (in-process resolution)
|
|
137
|
+
instance._callHandler = async (targetPhotonName, method, params) => {
|
|
138
|
+
const targetPath = resolvePhotonPath(targetPhotonName, absolutePath);
|
|
139
|
+
const target = await photon(targetPath, {
|
|
140
|
+
baseDir: options.baseDir,
|
|
141
|
+
mcpFactory: options.mcpFactory,
|
|
142
|
+
sessionId: options.sessionId,
|
|
143
|
+
});
|
|
144
|
+
return target[method](params);
|
|
145
|
+
};
|
|
146
|
+
// 15. Call onInitialize lifecycle hook
|
|
147
|
+
if (typeof instance.onInitialize === 'function') {
|
|
148
|
+
await instance.onInitialize();
|
|
149
|
+
}
|
|
150
|
+
// 16. Build middleware proxy
|
|
151
|
+
const proxy = buildMiddlewareProxy(instance, photonName, toolSchemas, options);
|
|
152
|
+
return proxy;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
loadingPaths.delete(absolutePath);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
159
|
+
// Constructor injection
|
|
160
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
161
|
+
async function resolveConstructorArgs(injections, photonName, currentPath, options) {
|
|
162
|
+
const values = [];
|
|
163
|
+
const missing = [];
|
|
164
|
+
for (const injection of injections) {
|
|
165
|
+
const { param, injectionType } = injection;
|
|
166
|
+
switch (injectionType) {
|
|
167
|
+
case 'photon': {
|
|
168
|
+
// Recursive photon loading
|
|
169
|
+
const dep = injection.photonDependency;
|
|
170
|
+
const depPath = resolvePhotonDepPath(dep.source, dep.sourceType, currentPath);
|
|
171
|
+
const depInstance = await photon(depPath, {
|
|
172
|
+
baseDir: options.baseDir,
|
|
173
|
+
mcpFactory: options.mcpFactory,
|
|
174
|
+
instanceName: dep.instanceName,
|
|
175
|
+
sessionId: options.sessionId,
|
|
176
|
+
});
|
|
177
|
+
values.push(depInstance);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case 'mcp': {
|
|
181
|
+
// MCP dependencies require a factory
|
|
182
|
+
if (!options.mcpFactory) {
|
|
183
|
+
throw new Error(`Photon "${photonName}" requires MCP dependency "${param.name}" but no mcpFactory was provided. ` +
|
|
184
|
+
`Pass { mcpFactory } in the options to photon().`);
|
|
185
|
+
}
|
|
186
|
+
// Will be resolved by the instance's mcp() method at call time
|
|
187
|
+
values.push(undefined);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case 'env': {
|
|
191
|
+
const envVarName = injection.envVarName || toEnvVarName(photonName, param.name);
|
|
192
|
+
const envValue = process.env[envVarName];
|
|
193
|
+
if (envValue !== undefined) {
|
|
194
|
+
values.push(parseEnvValue(envValue, param.type));
|
|
195
|
+
}
|
|
196
|
+
else if (param.hasDefault || param.isOptional) {
|
|
197
|
+
values.push(undefined);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
missing.push({ paramName: param.name, envVarName, type: param.type });
|
|
201
|
+
values.push(undefined);
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case 'state': {
|
|
206
|
+
// State injection — use default value (state is loaded by the class itself)
|
|
207
|
+
values.push(undefined);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
default:
|
|
211
|
+
values.push(undefined);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (missing.length > 0) {
|
|
215
|
+
const envList = missing.map(m => ` ${m.envVarName} (${m.paramName}: ${m.type})`).join('\n');
|
|
216
|
+
console.warn(`⚠️ ${photonName}: Missing environment variables:\n${envList}\n` +
|
|
217
|
+
`Some methods may fail until these are set.`);
|
|
218
|
+
}
|
|
219
|
+
return values;
|
|
220
|
+
}
|
|
221
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
222
|
+
// Reactive collection wiring
|
|
223
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
224
|
+
function wireReactiveCollections(instance) {
|
|
225
|
+
const emit = typeof instance.emit === 'function'
|
|
226
|
+
? instance.emit.bind(instance)
|
|
227
|
+
: null;
|
|
228
|
+
if (!emit)
|
|
229
|
+
return;
|
|
230
|
+
for (const key of Object.keys(instance)) {
|
|
231
|
+
const value = instance[key];
|
|
232
|
+
if (!value || typeof value !== 'object')
|
|
233
|
+
continue;
|
|
234
|
+
const ctorName = value.constructor?.name;
|
|
235
|
+
if (ctorName === 'ReactiveArray' ||
|
|
236
|
+
ctorName === 'ReactiveMap' ||
|
|
237
|
+
ctorName === 'ReactiveSet' ||
|
|
238
|
+
ctorName === 'Collection') {
|
|
239
|
+
value._propertyName = key;
|
|
240
|
+
value._emitter = emit;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
245
|
+
// @stateful method wrapping
|
|
246
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
247
|
+
function wrapStatefulMethods(instance, source, onEvent) {
|
|
248
|
+
if (!/@stateful\b/i.test(source))
|
|
249
|
+
return;
|
|
250
|
+
// Skip framework-injected methods from withPhotonCapabilities
|
|
251
|
+
const frameworkMethods = new Set([
|
|
252
|
+
'emit', 'call', 'mcp', 'setMCPFactory', 'onInitialize', 'onShutdown',
|
|
253
|
+
]);
|
|
254
|
+
// Walk the prototype chain to find all public methods
|
|
255
|
+
// (withPhotonCapabilities creates a subclass, so methods may be on grandparent prototype)
|
|
256
|
+
const methodNames = [];
|
|
257
|
+
const seen = new Set();
|
|
258
|
+
let proto = Object.getPrototypeOf(instance);
|
|
259
|
+
while (proto && proto !== Object.prototype) {
|
|
260
|
+
for (const name of Object.getOwnPropertyNames(proto)) {
|
|
261
|
+
if (seen.has(name) || name === 'constructor' || name.startsWith('_'))
|
|
262
|
+
continue;
|
|
263
|
+
if (frameworkMethods.has(name))
|
|
264
|
+
continue;
|
|
265
|
+
seen.add(name);
|
|
266
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
267
|
+
if (descriptor && typeof descriptor.value === 'function') {
|
|
268
|
+
methodNames.push(name);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
proto = Object.getPrototypeOf(proto);
|
|
272
|
+
}
|
|
273
|
+
if (methodNames.length === 0)
|
|
274
|
+
return;
|
|
275
|
+
for (const methodName of methodNames) {
|
|
276
|
+
const original = instance[methodName];
|
|
277
|
+
if (typeof original !== 'function')
|
|
278
|
+
continue;
|
|
279
|
+
instance[methodName] = function (...args) {
|
|
280
|
+
const paramNames = extractParamNames(original);
|
|
281
|
+
const params = Object.fromEntries(paramNames.map((name, i) => [name, args[i]]));
|
|
282
|
+
const result = original.apply(this, args);
|
|
283
|
+
// Handle both sync and async results
|
|
284
|
+
const attachMeta = (res) => {
|
|
285
|
+
if (res && typeof res === 'object' && !Array.isArray(res) && !res.__meta) {
|
|
286
|
+
const timestamp = new Date().toISOString();
|
|
287
|
+
Object.defineProperty(res, '__meta', {
|
|
288
|
+
value: {
|
|
289
|
+
createdAt: timestamp,
|
|
290
|
+
createdBy: methodName,
|
|
291
|
+
modifiedAt: null,
|
|
292
|
+
modifiedBy: null,
|
|
293
|
+
modifications: [],
|
|
294
|
+
},
|
|
295
|
+
enumerable: false,
|
|
296
|
+
writable: true,
|
|
297
|
+
configurable: true,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
// Emit event
|
|
301
|
+
if (onEvent) {
|
|
302
|
+
const event = {
|
|
303
|
+
method: methodName,
|
|
304
|
+
params,
|
|
305
|
+
result: res,
|
|
306
|
+
timestamp: new Date().toISOString(),
|
|
307
|
+
};
|
|
308
|
+
if (this.instanceName) {
|
|
309
|
+
event.instance = this.instanceName;
|
|
310
|
+
}
|
|
311
|
+
onEvent(event);
|
|
312
|
+
}
|
|
313
|
+
return res;
|
|
314
|
+
};
|
|
315
|
+
// Support async methods (most common case)
|
|
316
|
+
if (result && typeof result.then === 'function') {
|
|
317
|
+
return result.then(attachMeta);
|
|
318
|
+
}
|
|
319
|
+
return attachMeta(result);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Extract parameter names from a function signature string
|
|
325
|
+
*/
|
|
326
|
+
function extractParamNames(fn) {
|
|
327
|
+
const fnStr = fn.toString();
|
|
328
|
+
const match = fnStr.match(/\(([^)]*)\)/);
|
|
329
|
+
if (!match?.[1])
|
|
330
|
+
return [];
|
|
331
|
+
return match[1]
|
|
332
|
+
.split(',')
|
|
333
|
+
.map(param => {
|
|
334
|
+
const cleaned = param
|
|
335
|
+
.trim()
|
|
336
|
+
.split('=')[0] // Remove default value
|
|
337
|
+
.split(':')[0] // Remove type annotations
|
|
338
|
+
.trim();
|
|
339
|
+
return cleaned;
|
|
340
|
+
})
|
|
341
|
+
.filter(name => name && name !== 'this');
|
|
342
|
+
}
|
|
343
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
344
|
+
// Middleware proxy
|
|
345
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
346
|
+
function buildMiddlewareProxy(instance, photonName, toolSchemas, options) {
|
|
347
|
+
// Build tool lookup: method name → schema
|
|
348
|
+
const toolMap = new Map();
|
|
349
|
+
for (const schema of toolSchemas) {
|
|
350
|
+
toolMap.set(schema.name, schema);
|
|
351
|
+
}
|
|
352
|
+
// Middleware state stores (shared across calls)
|
|
353
|
+
const stateStores = new Map();
|
|
354
|
+
// Build combined registry (builtins only for now; custom middleware can be added later)
|
|
355
|
+
const registry = new MiddlewareRegistry();
|
|
356
|
+
for (const name of builtinRegistry.names()) {
|
|
357
|
+
registry.register(builtinRegistry.get(name));
|
|
358
|
+
}
|
|
359
|
+
return new Proxy(instance, {
|
|
360
|
+
get(target, prop, receiver) {
|
|
361
|
+
const value = Reflect.get(target, prop, receiver);
|
|
362
|
+
if (typeof value !== 'function')
|
|
363
|
+
return value;
|
|
364
|
+
if (typeof prop !== 'string')
|
|
365
|
+
return value;
|
|
366
|
+
// Skip internal/private methods
|
|
367
|
+
if (prop.startsWith('_') || prop === 'constructor') {
|
|
368
|
+
return value.bind(target);
|
|
369
|
+
}
|
|
370
|
+
const schema = toolMap.get(prop);
|
|
371
|
+
const declarations = schema?.middleware || [];
|
|
372
|
+
// No middleware — return bound method directly
|
|
373
|
+
if (declarations.length === 0) {
|
|
374
|
+
return value.bind(target);
|
|
375
|
+
}
|
|
376
|
+
// Return a function that applies middleware on each call
|
|
377
|
+
return (...args) => {
|
|
378
|
+
const ctx = {
|
|
379
|
+
photon: photonName,
|
|
380
|
+
tool: prop,
|
|
381
|
+
instance: options.instanceName || 'default',
|
|
382
|
+
params: args[0] ?? {},
|
|
383
|
+
};
|
|
384
|
+
const execute = () => value.apply(target, args);
|
|
385
|
+
const chain = buildMiddlewareChain(execute, declarations, registry, stateStores, ctx);
|
|
386
|
+
return chain();
|
|
387
|
+
};
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
392
|
+
// Path utilities
|
|
393
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
394
|
+
/**
|
|
395
|
+
* Derive a photon name from a file path.
|
|
396
|
+
* e.g., '/path/to/todo.photon.ts' → 'todo'
|
|
397
|
+
*/
|
|
398
|
+
function derivePhotonName(filePath) {
|
|
399
|
+
const basename = path.basename(filePath);
|
|
400
|
+
return basename
|
|
401
|
+
.replace(/\.photon\.(ts|js|mjs)$/, '')
|
|
402
|
+
.replace(/\.(ts|js|mjs)$/, '');
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Resolve a photon dependency source to an absolute path.
|
|
406
|
+
*/
|
|
407
|
+
function resolvePhotonDepPath(source, sourceType, currentPhotonPath) {
|
|
408
|
+
if (sourceType === 'local') {
|
|
409
|
+
if (source.startsWith('./') || source.startsWith('../')) {
|
|
410
|
+
return path.resolve(path.dirname(currentPhotonPath), source);
|
|
411
|
+
}
|
|
412
|
+
return source;
|
|
413
|
+
}
|
|
414
|
+
// For marketplace photons, look in ~/.photon/photons/<name>/
|
|
415
|
+
if (sourceType === 'marketplace') {
|
|
416
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
|
|
417
|
+
return path.join(homeDir, '.photon', 'photons', source, `${source}.photon.ts`);
|
|
418
|
+
}
|
|
419
|
+
// npm and github sources — for now, throw a helpful error
|
|
420
|
+
throw new Error(`Cannot resolve ${sourceType} photon dependency "${source}" in lite loader. ` +
|
|
421
|
+
`Only local paths and marketplace photons are supported. ` +
|
|
422
|
+
`Use the full runtime for npm/github dependencies.`);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Resolve a photon name to a path for cross-photon calls.
|
|
426
|
+
* Searches: sibling files, then ~/.photon/photons/
|
|
427
|
+
*/
|
|
428
|
+
function resolvePhotonPath(photonName, callerPath) {
|
|
429
|
+
// Try sibling file first
|
|
430
|
+
const dir = path.dirname(callerPath);
|
|
431
|
+
const siblingPath = path.join(dir, `${photonName}.photon.ts`);
|
|
432
|
+
// We can't do sync fs.existsSync in an async context cleanly,
|
|
433
|
+
// so just return the sibling path — the load will fail with a clear error if not found
|
|
434
|
+
return siblingPath;
|
|
435
|
+
}
|
|
436
|
+
//# sourceMappingURL=photon-loader-lite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"photon-loader-lite.js","sourceRoot":"","sources":["../src/photon-loader-lite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAA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,GAAG,MAAM,YAAY,CAAC,CAAC;IACjF,CAAC;IAED,0DAA0D;IAC1D,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,uBAAuB,MAAM,oBAAoB;QAC7E,0DAA0D;QAC1D,mDAAmD,CACpD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,iBAAiB,CAAC,UAAkB,EAAE,UAAkB;IAC/D,yBAAyB;IACzB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,YAAY,CAAC,CAAC;IAE9D,8DAA8D;IAC9D,uFAAuF;IACvF,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Scheduling System
|
|
3
|
+
*
|
|
4
|
+
* Programmatic scheduling for photons — create, pause, resume, and cancel
|
|
5
|
+
* scheduled tasks at runtime. Available as `this.schedule` on Photon.
|
|
6
|
+
*
|
|
7
|
+
* Complements static `@scheduled`/`@cron` JSDoc tags with dynamic scheduling.
|
|
8
|
+
* Schedules persist to disk; the daemon reads and executes them.
|
|
9
|
+
*
|
|
10
|
+
* Storage: ~/.photon/schedules/{photonId}/{taskId}.json
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* export default class Cleanup extends Photon {
|
|
15
|
+
* async setup() {
|
|
16
|
+
* await this.schedule.create({
|
|
17
|
+
* name: 'nightly-cleanup',
|
|
18
|
+
* schedule: '0 0 * * *',
|
|
19
|
+
* method: 'purge',
|
|
20
|
+
* params: { olderThan: 30 },
|
|
21
|
+
* });
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* async purge({ olderThan }: { olderThan: number }) {
|
|
25
|
+
* // ... cleanup logic
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type ScheduleStatus = 'active' | 'paused' | 'completed' | 'error';
|
|
31
|
+
export interface ScheduledTask {
|
|
32
|
+
/** Unique task ID */
|
|
33
|
+
id: string;
|
|
34
|
+
/** Human-readable name */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Optional description */
|
|
37
|
+
description?: string;
|
|
38
|
+
/** Cron expression (5-field: minute hour day month weekday) */
|
|
39
|
+
cron: string;
|
|
40
|
+
/** Method name on this photon to call */
|
|
41
|
+
method: string;
|
|
42
|
+
/** Parameters to pass to the method */
|
|
43
|
+
params: Record<string, any>;
|
|
44
|
+
/** Execute once then mark completed */
|
|
45
|
+
fireOnce: boolean;
|
|
46
|
+
/** Maximum number of executions (0 = unlimited) */
|
|
47
|
+
maxExecutions: number;
|
|
48
|
+
/** Current status */
|
|
49
|
+
status: ScheduleStatus;
|
|
50
|
+
/** ISO timestamp of creation */
|
|
51
|
+
createdAt: string;
|
|
52
|
+
/** ISO timestamp of last execution */
|
|
53
|
+
lastExecutionAt?: string;
|
|
54
|
+
/** Total execution count */
|
|
55
|
+
executionCount: number;
|
|
56
|
+
/** Error message if status is 'error' */
|
|
57
|
+
errorMessage?: string;
|
|
58
|
+
/** Photon that owns this task */
|
|
59
|
+
photonId: string;
|
|
60
|
+
}
|
|
61
|
+
export interface CreateScheduleOptions {
|
|
62
|
+
/** Human-readable name (must be unique per photon) */
|
|
63
|
+
name: string;
|
|
64
|
+
/** Cron expression (5-field) or shorthand: '@hourly', '@daily', '@weekly', '@monthly' */
|
|
65
|
+
schedule: string;
|
|
66
|
+
/** Method name on this photon to invoke */
|
|
67
|
+
method: string;
|
|
68
|
+
/** Parameters to pass to the method */
|
|
69
|
+
params?: Record<string, any>;
|
|
70
|
+
/** Optional description */
|
|
71
|
+
description?: string;
|
|
72
|
+
/** Execute once then auto-complete (default: false) */
|
|
73
|
+
fireOnce?: boolean;
|
|
74
|
+
/** Maximum executions before auto-complete (0 = unlimited, default: 0) */
|
|
75
|
+
maxExecutions?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface UpdateScheduleOptions {
|
|
78
|
+
/** New cron schedule */
|
|
79
|
+
schedule?: string;
|
|
80
|
+
/** New method name */
|
|
81
|
+
method?: string;
|
|
82
|
+
/** New parameters */
|
|
83
|
+
params?: Record<string, any>;
|
|
84
|
+
/** New description */
|
|
85
|
+
description?: string;
|
|
86
|
+
/** Update fire-once flag */
|
|
87
|
+
fireOnce?: boolean;
|
|
88
|
+
/** Update max executions */
|
|
89
|
+
maxExecutions?: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Runtime Schedule Provider
|
|
93
|
+
*
|
|
94
|
+
* Provides CRUD operations for scheduled tasks.
|
|
95
|
+
* Tasks are persisted as JSON files that the daemon watches and executes.
|
|
96
|
+
*/
|
|
97
|
+
export declare class ScheduleProvider {
|
|
98
|
+
private _photonId;
|
|
99
|
+
constructor(photonId: string);
|
|
100
|
+
/**
|
|
101
|
+
* Create a new scheduled task
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* await this.schedule.create({
|
|
106
|
+
* name: 'daily-report',
|
|
107
|
+
* schedule: '0 9 * * *',
|
|
108
|
+
* method: 'generate',
|
|
109
|
+
* params: { format: 'pdf' },
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
create(options: CreateScheduleOptions): Promise<ScheduledTask>;
|
|
114
|
+
/**
|
|
115
|
+
* Get a scheduled task by ID
|
|
116
|
+
*/
|
|
117
|
+
get(taskId: string): Promise<ScheduledTask | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Get a scheduled task by name
|
|
120
|
+
*/
|
|
121
|
+
getByName(name: string): Promise<ScheduledTask | null>;
|
|
122
|
+
/**
|
|
123
|
+
* List all scheduled tasks, optionally filtered by status
|
|
124
|
+
*/
|
|
125
|
+
list(status?: ScheduleStatus): Promise<ScheduledTask[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Update an existing scheduled task
|
|
128
|
+
*/
|
|
129
|
+
update(taskId: string, updates: UpdateScheduleOptions): Promise<ScheduledTask>;
|
|
130
|
+
/**
|
|
131
|
+
* Pause a scheduled task (stops execution until resumed)
|
|
132
|
+
*/
|
|
133
|
+
pause(taskId: string): Promise<ScheduledTask>;
|
|
134
|
+
/**
|
|
135
|
+
* Resume a paused scheduled task
|
|
136
|
+
*/
|
|
137
|
+
resume(taskId: string): Promise<ScheduledTask>;
|
|
138
|
+
/**
|
|
139
|
+
* Cancel (delete) a scheduled task
|
|
140
|
+
*/
|
|
141
|
+
cancel(taskId: string): Promise<boolean>;
|
|
142
|
+
/**
|
|
143
|
+
* Cancel a scheduled task by name
|
|
144
|
+
*/
|
|
145
|
+
cancelByName(name: string): Promise<boolean>;
|
|
146
|
+
/**
|
|
147
|
+
* Check if a schedule with the given name exists
|
|
148
|
+
*/
|
|
149
|
+
has(name: string): Promise<boolean>;
|
|
150
|
+
/**
|
|
151
|
+
* Cancel all scheduled tasks for this photon
|
|
152
|
+
*/
|
|
153
|
+
cancelAll(): Promise<number>;
|
|
154
|
+
/** @internal */
|
|
155
|
+
private _save;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=schedule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../src/schedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AASH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC;AAEzE,MAAM,WAAW,aAAa;IAC5B,qBAAqB;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,M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