@portel/photon-core 1.3.0 → 1.4.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/generator.d.ts +236 -2
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +30 -0
- 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 +26 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp-client.d.ts +39 -0
- package/dist/mcp-client.d.ts.map +1 -1
- package/dist/mcp-client.js +213 -0
- package/dist/mcp-client.js.map +1 -1
- package/dist/photon-config.d.ts +86 -0
- package/dist/photon-config.d.ts.map +1 -0
- package/dist/photon-config.js +156 -0
- package/dist/photon-config.js.map +1 -0
- package/dist/schema-extractor.d.ts +99 -1
- package/dist/schema-extractor.d.ts.map +1 -1
- package/dist/schema-extractor.js +311 -5
- package/dist/schema-extractor.js.map +1 -1
- package/dist/stateful.d.ts +238 -0
- package/dist/stateful.d.ts.map +1 -0
- package/dist/stateful.js +469 -0
- package/dist/stateful.js.map +1 -0
- package/dist/types.d.ts +260 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -2
- package/src/generator.ts +270 -2
- package/src/index.ts +73 -1
- package/src/mcp-client.ts +254 -0
- package/src/photon-config.ts +201 -0
- package/src/schema-extractor.ts +353 -6
- package/src/stateful.ts +659 -0
- package/src/types.ts +289 -0
package/src/types.ts
CHANGED
|
@@ -52,6 +52,8 @@ export interface ExtractedSchema {
|
|
|
52
52
|
isGenerator?: boolean;
|
|
53
53
|
/** Yield information for generator methods (used by REST APIs) */
|
|
54
54
|
yields?: YieldInfo[];
|
|
55
|
+
/** True if this is a stateful workflow (supports checkpoint/resume) */
|
|
56
|
+
isStateful?: boolean;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export interface PhotonMCPClass {
|
|
@@ -67,6 +69,27 @@ export interface ConstructorParam {
|
|
|
67
69
|
isOptional: boolean;
|
|
68
70
|
hasDefault: boolean;
|
|
69
71
|
defaultValue?: any;
|
|
72
|
+
/** True if type is string, number, or boolean (inject from env var) */
|
|
73
|
+
isPrimitive: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Injection type for constructor parameters
|
|
78
|
+
*/
|
|
79
|
+
export type InjectionType = 'env' | 'mcp' | 'photon';
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resolved injection info for a constructor parameter
|
|
83
|
+
*/
|
|
84
|
+
export interface ResolvedInjection {
|
|
85
|
+
param: ConstructorParam;
|
|
86
|
+
injectionType: InjectionType;
|
|
87
|
+
/** For 'mcp' - the MCP dependency info */
|
|
88
|
+
mcpDependency?: MCPDependency;
|
|
89
|
+
/** For 'photon' - the Photon dependency info */
|
|
90
|
+
photonDependency?: PhotonDependency;
|
|
91
|
+
/** For 'env' - the environment variable name */
|
|
92
|
+
envVarName?: string;
|
|
70
93
|
}
|
|
71
94
|
|
|
72
95
|
/**
|
|
@@ -103,6 +126,123 @@ export interface MCPDependency {
|
|
|
103
126
|
env?: Record<string, string>;
|
|
104
127
|
}
|
|
105
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Photon Dependency declaration from @photon tag
|
|
131
|
+
* Format: @photon <name> <source>
|
|
132
|
+
*
|
|
133
|
+
* Source formats (following marketplace conventions):
|
|
134
|
+
* - Marketplace: rss-feed (from configured marketplace)
|
|
135
|
+
* - GitHub shorthand: portel-dev/photons/rss-feed
|
|
136
|
+
* - npm package: npm:@portel/rss-feed-photon
|
|
137
|
+
* - Local path: ./my-local-photon.photon.ts
|
|
138
|
+
*
|
|
139
|
+
* Example:
|
|
140
|
+
* ```typescript
|
|
141
|
+
* /**
|
|
142
|
+
* * @photon rssFeed rss-feed
|
|
143
|
+
* * @photon custom ./my-photon.photon.ts
|
|
144
|
+
* *\/
|
|
145
|
+
* export default class MyWorkflow {
|
|
146
|
+
* constructor(private rssFeed: any) {}
|
|
147
|
+
*
|
|
148
|
+
* async run() {
|
|
149
|
+
* const items = await this.rssFeed.read({ url: '...' });
|
|
150
|
+
* }
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export interface PhotonDependency {
|
|
155
|
+
/** Local name to use for accessing this Photon (e.g., 'rssFeed') */
|
|
156
|
+
name: string;
|
|
157
|
+
/** Source identifier (marketplace name, GitHub shorthand, npm package, or path) */
|
|
158
|
+
source: string;
|
|
159
|
+
/** Resolved source type */
|
|
160
|
+
sourceType: 'marketplace' | 'github' | 'npm' | 'local';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ════════════════════════════════════════════════════════════════════════════
|
|
164
|
+
// PHOTON ASSETS - Static files referenced via @ui, @prompt, @resource
|
|
165
|
+
// ════════════════════════════════════════════════════════════════════════════
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* UI Asset - HTML/React UI for MCP Apps
|
|
169
|
+
*
|
|
170
|
+
* Declared via @ui annotation:
|
|
171
|
+
* ```
|
|
172
|
+
* /** @ui preferences-form ./ui/preferences.html *\/
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* Referenced in tools via @ui JSDoc or EmitUI yield
|
|
176
|
+
*/
|
|
177
|
+
export interface UIAsset {
|
|
178
|
+
/** Asset identifier (e.g., 'preferences-form') */
|
|
179
|
+
id: string;
|
|
180
|
+
/** Relative path from asset folder (e.g., './ui/preferences.html') */
|
|
181
|
+
path: string;
|
|
182
|
+
/** Resolved absolute path (set by loader) */
|
|
183
|
+
resolvedPath?: string;
|
|
184
|
+
/** MIME type (detected from extension) */
|
|
185
|
+
mimeType?: string;
|
|
186
|
+
/** Tool this UI is linked to (from method @ui annotation) */
|
|
187
|
+
linkedTool?: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Prompt Asset - Static MCP Prompt template
|
|
192
|
+
*
|
|
193
|
+
* Declared via @prompt annotation:
|
|
194
|
+
* ```
|
|
195
|
+
* /** @prompt system ./prompts/system.md *\/
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export interface PromptAsset {
|
|
199
|
+
/** Asset identifier (e.g., 'system') */
|
|
200
|
+
id: string;
|
|
201
|
+
/** Relative path from asset folder */
|
|
202
|
+
path: string;
|
|
203
|
+
/** Resolved absolute path (set by loader) */
|
|
204
|
+
resolvedPath?: string;
|
|
205
|
+
/** Prompt description (from file frontmatter or annotation) */
|
|
206
|
+
description?: string;
|
|
207
|
+
/** Prompt arguments schema (from file frontmatter) */
|
|
208
|
+
arguments?: Record<string, { type: string; description?: string; required?: boolean }>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Resource Asset - Static MCP Resource
|
|
213
|
+
*
|
|
214
|
+
* Declared via @resource annotation:
|
|
215
|
+
* ```
|
|
216
|
+
* /** @resource config ./resources/config.json *\/
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export interface ResourceAsset {
|
|
220
|
+
/** Asset identifier (e.g., 'config') */
|
|
221
|
+
id: string;
|
|
222
|
+
/** Relative path from asset folder */
|
|
223
|
+
path: string;
|
|
224
|
+
/** Resolved absolute path (set by loader) */
|
|
225
|
+
resolvedPath?: string;
|
|
226
|
+
/** MIME type (detected from extension) */
|
|
227
|
+
mimeType?: string;
|
|
228
|
+
/** Resource description */
|
|
229
|
+
description?: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* All assets extracted from a Photon
|
|
234
|
+
*/
|
|
235
|
+
export interface PhotonAssets {
|
|
236
|
+
/** UI assets for MCP Apps */
|
|
237
|
+
ui: UIAsset[];
|
|
238
|
+
/** Static prompt templates */
|
|
239
|
+
prompts: PromptAsset[];
|
|
240
|
+
/** Static resources */
|
|
241
|
+
resources: ResourceAsset[];
|
|
242
|
+
/** Asset folder path (e.g., './my-photon/') */
|
|
243
|
+
assetFolder?: string;
|
|
244
|
+
}
|
|
245
|
+
|
|
106
246
|
/**
|
|
107
247
|
* Template type - for text generation with variable substitution
|
|
108
248
|
* Maps to MCP Prompts, HTTP template endpoints, CLI help generators, etc.
|
|
@@ -179,4 +319,153 @@ export interface StaticInfo {
|
|
|
179
319
|
export interface PhotonMCPClassExtended extends PhotonMCPClass {
|
|
180
320
|
templates: TemplateInfo[];
|
|
181
321
|
statics: StaticInfo[];
|
|
322
|
+
/** Assets from the Photon's asset folder (UI, prompts, resources) */
|
|
323
|
+
assets?: PhotonAssets;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
327
|
+
// STATEFUL WORKFLOW TYPES
|
|
328
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* State log entry types for JSONL persistence
|
|
332
|
+
*/
|
|
333
|
+
export type StateLogType = 'start' | 'emit' | 'checkpoint' | 'ask' | 'answer' | 'return' | 'error';
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Base state log entry
|
|
337
|
+
*/
|
|
338
|
+
interface StateLogBase {
|
|
339
|
+
/** Entry type */
|
|
340
|
+
t: StateLogType;
|
|
341
|
+
/** Timestamp (Unix ms) */
|
|
342
|
+
ts: number;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Workflow start entry
|
|
347
|
+
*/
|
|
348
|
+
export interface StateLogStart extends StateLogBase {
|
|
349
|
+
t: 'start';
|
|
350
|
+
/** Tool/method name being executed */
|
|
351
|
+
tool: string;
|
|
352
|
+
/** Input parameters */
|
|
353
|
+
params: Record<string, any>;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Emit entry (status, progress, etc.)
|
|
358
|
+
*/
|
|
359
|
+
export interface StateLogEmit extends StateLogBase {
|
|
360
|
+
t: 'emit';
|
|
361
|
+
/** Emit type (status, progress, stream, log, etc.) */
|
|
362
|
+
emit: string;
|
|
363
|
+
/** Emit message */
|
|
364
|
+
message?: string;
|
|
365
|
+
/** Additional emit data */
|
|
366
|
+
data?: any;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Checkpoint entry - marks safe resume point with state snapshot
|
|
371
|
+
*/
|
|
372
|
+
export interface StateLogCheckpoint extends StateLogBase {
|
|
373
|
+
t: 'checkpoint';
|
|
374
|
+
/** Checkpoint ID (auto-generated or explicit) */
|
|
375
|
+
id: string;
|
|
376
|
+
/** Accumulated state at this point */
|
|
377
|
+
state: Record<string, any>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Ask entry - input request
|
|
382
|
+
*/
|
|
383
|
+
export interface StateLogAsk extends StateLogBase {
|
|
384
|
+
t: 'ask';
|
|
385
|
+
/** Ask ID */
|
|
386
|
+
id: string;
|
|
387
|
+
/** Ask type (text, confirm, select, etc.) */
|
|
388
|
+
ask: string;
|
|
389
|
+
/** Ask message */
|
|
390
|
+
message: string;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Answer entry - input response
|
|
395
|
+
*/
|
|
396
|
+
export interface StateLogAnswer extends StateLogBase {
|
|
397
|
+
t: 'answer';
|
|
398
|
+
/** Ask ID this answers */
|
|
399
|
+
id: string;
|
|
400
|
+
/** User's response value */
|
|
401
|
+
value: any;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Return entry - workflow completion
|
|
406
|
+
*/
|
|
407
|
+
export interface StateLogReturn extends StateLogBase {
|
|
408
|
+
t: 'return';
|
|
409
|
+
/** Final return value */
|
|
410
|
+
value: any;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Error entry - workflow failed
|
|
415
|
+
*/
|
|
416
|
+
export interface StateLogError extends StateLogBase {
|
|
417
|
+
t: 'error';
|
|
418
|
+
/** Error message */
|
|
419
|
+
message: string;
|
|
420
|
+
/** Error stack trace */
|
|
421
|
+
stack?: string;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Union of all state log entry types
|
|
426
|
+
*/
|
|
427
|
+
export type StateLogEntry =
|
|
428
|
+
| StateLogStart
|
|
429
|
+
| StateLogEmit
|
|
430
|
+
| StateLogCheckpoint
|
|
431
|
+
| StateLogAsk
|
|
432
|
+
| StateLogAnswer
|
|
433
|
+
| StateLogReturn
|
|
434
|
+
| StateLogError;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Workflow run status
|
|
438
|
+
*/
|
|
439
|
+
export type WorkflowStatus = 'running' | 'waiting' | 'completed' | 'failed' | 'paused';
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Workflow run metadata
|
|
443
|
+
*/
|
|
444
|
+
export interface WorkflowRun {
|
|
445
|
+
/** Unique run ID */
|
|
446
|
+
runId: string;
|
|
447
|
+
/** Photon name */
|
|
448
|
+
photon: string;
|
|
449
|
+
/** Tool/method name */
|
|
450
|
+
tool: string;
|
|
451
|
+
/** Input parameters */
|
|
452
|
+
params: Record<string, any>;
|
|
453
|
+
/** Current status */
|
|
454
|
+
status: WorkflowStatus;
|
|
455
|
+
/** Start timestamp */
|
|
456
|
+
startedAt: number;
|
|
457
|
+
/** Last update timestamp */
|
|
458
|
+
updatedAt: number;
|
|
459
|
+
/** Completion timestamp (if completed/failed) */
|
|
460
|
+
completedAt?: number;
|
|
461
|
+
/** Final result (if completed) */
|
|
462
|
+
result?: any;
|
|
463
|
+
/** Error message (if failed) */
|
|
464
|
+
error?: string;
|
|
465
|
+
/** Last checkpoint state */
|
|
466
|
+
lastCheckpoint?: {
|
|
467
|
+
id: string;
|
|
468
|
+
state: Record<string, any>;
|
|
469
|
+
ts: number;
|
|
470
|
+
};
|
|
182
471
|
}
|