@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/types.d.ts CHANGED
@@ -48,6 +48,8 @@ export interface ExtractedSchema {
48
48
  isGenerator?: boolean;
49
49
  /** Yield information for generator methods (used by REST APIs) */
50
50
  yields?: YieldInfo[];
51
+ /** True if this is a stateful workflow (supports checkpoint/resume) */
52
+ isStateful?: boolean;
51
53
  }
52
54
  export interface PhotonMCPClass {
53
55
  name: string;
@@ -61,6 +63,25 @@ export interface ConstructorParam {
61
63
  isOptional: boolean;
62
64
  hasDefault: boolean;
63
65
  defaultValue?: any;
66
+ /** True if type is string, number, or boolean (inject from env var) */
67
+ isPrimitive: boolean;
68
+ }
69
+ /**
70
+ * Injection type for constructor parameters
71
+ */
72
+ export type InjectionType = 'env' | 'mcp' | 'photon';
73
+ /**
74
+ * Resolved injection info for a constructor parameter
75
+ */
76
+ export interface ResolvedInjection {
77
+ param: ConstructorParam;
78
+ injectionType: InjectionType;
79
+ /** For 'mcp' - the MCP dependency info */
80
+ mcpDependency?: MCPDependency;
81
+ /** For 'photon' - the Photon dependency info */
82
+ photonDependency?: PhotonDependency;
83
+ /** For 'env' - the environment variable name */
84
+ envVarName?: string;
64
85
  }
65
86
  /**
66
87
  * MCP Dependency declaration from @mcp tag
@@ -95,6 +116,118 @@ export interface MCPDependency {
95
116
  /** Environment variables to pass (from @env tags) */
96
117
  env?: Record<string, string>;
97
118
  }
119
+ /**
120
+ * Photon Dependency declaration from @photon tag
121
+ * Format: @photon <name> <source>
122
+ *
123
+ * Source formats (following marketplace conventions):
124
+ * - Marketplace: rss-feed (from configured marketplace)
125
+ * - GitHub shorthand: portel-dev/photons/rss-feed
126
+ * - npm package: npm:@portel/rss-feed-photon
127
+ * - Local path: ./my-local-photon.photon.ts
128
+ *
129
+ * Example:
130
+ * ```typescript
131
+ * /**
132
+ * * @photon rssFeed rss-feed
133
+ * * @photon custom ./my-photon.photon.ts
134
+ * *\/
135
+ * export default class MyWorkflow {
136
+ * constructor(private rssFeed: any) {}
137
+ *
138
+ * async run() {
139
+ * const items = await this.rssFeed.read({ url: '...' });
140
+ * }
141
+ * }
142
+ * ```
143
+ */
144
+ export interface PhotonDependency {
145
+ /** Local name to use for accessing this Photon (e.g., 'rssFeed') */
146
+ name: string;
147
+ /** Source identifier (marketplace name, GitHub shorthand, npm package, or path) */
148
+ source: string;
149
+ /** Resolved source type */
150
+ sourceType: 'marketplace' | 'github' | 'npm' | 'local';
151
+ }
152
+ /**
153
+ * UI Asset - HTML/React UI for MCP Apps
154
+ *
155
+ * Declared via @ui annotation:
156
+ * ```
157
+ * /** @ui preferences-form ./ui/preferences.html *\/
158
+ * ```
159
+ *
160
+ * Referenced in tools via @ui JSDoc or EmitUI yield
161
+ */
162
+ export interface UIAsset {
163
+ /** Asset identifier (e.g., 'preferences-form') */
164
+ id: string;
165
+ /** Relative path from asset folder (e.g., './ui/preferences.html') */
166
+ path: string;
167
+ /** Resolved absolute path (set by loader) */
168
+ resolvedPath?: string;
169
+ /** MIME type (detected from extension) */
170
+ mimeType?: string;
171
+ /** Tool this UI is linked to (from method @ui annotation) */
172
+ linkedTool?: string;
173
+ }
174
+ /**
175
+ * Prompt Asset - Static MCP Prompt template
176
+ *
177
+ * Declared via @prompt annotation:
178
+ * ```
179
+ * /** @prompt system ./prompts/system.md *\/
180
+ * ```
181
+ */
182
+ export interface PromptAsset {
183
+ /** Asset identifier (e.g., 'system') */
184
+ id: string;
185
+ /** Relative path from asset folder */
186
+ path: string;
187
+ /** Resolved absolute path (set by loader) */
188
+ resolvedPath?: string;
189
+ /** Prompt description (from file frontmatter or annotation) */
190
+ description?: string;
191
+ /** Prompt arguments schema (from file frontmatter) */
192
+ arguments?: Record<string, {
193
+ type: string;
194
+ description?: string;
195
+ required?: boolean;
196
+ }>;
197
+ }
198
+ /**
199
+ * Resource Asset - Static MCP Resource
200
+ *
201
+ * Declared via @resource annotation:
202
+ * ```
203
+ * /** @resource config ./resources/config.json *\/
204
+ * ```
205
+ */
206
+ export interface ResourceAsset {
207
+ /** Asset identifier (e.g., 'config') */
208
+ id: string;
209
+ /** Relative path from asset folder */
210
+ path: string;
211
+ /** Resolved absolute path (set by loader) */
212
+ resolvedPath?: string;
213
+ /** MIME type (detected from extension) */
214
+ mimeType?: string;
215
+ /** Resource description */
216
+ description?: string;
217
+ }
218
+ /**
219
+ * All assets extracted from a Photon
220
+ */
221
+ export interface PhotonAssets {
222
+ /** UI assets for MCP Apps */
223
+ ui: UIAsset[];
224
+ /** Static prompt templates */
225
+ prompts: PromptAsset[];
226
+ /** Static resources */
227
+ resources: ResourceAsset[];
228
+ /** Asset folder path (e.g., './my-photon/') */
229
+ assetFolder?: string;
230
+ }
98
231
  /**
99
232
  * Template type - for text generation with variable substitution
100
233
  * Maps to MCP Prompts, HTTP template endpoints, CLI help generators, etc.
@@ -167,5 +300,132 @@ export interface StaticInfo {
167
300
  export interface PhotonMCPClassExtended extends PhotonMCPClass {
168
301
  templates: TemplateInfo[];
169
302
  statics: StaticInfo[];
303
+ /** Assets from the Photon's asset folder (UI, prompts, resources) */
304
+ assets?: PhotonAssets;
305
+ }
306
+ /**
307
+ * State log entry types for JSONL persistence
308
+ */
309
+ export type StateLogType = 'start' | 'emit' | 'checkpoint' | 'ask' | 'answer' | 'return' | 'error';
310
+ /**
311
+ * Base state log entry
312
+ */
313
+ interface StateLogBase {
314
+ /** Entry type */
315
+ t: StateLogType;
316
+ /** Timestamp (Unix ms) */
317
+ ts: number;
318
+ }
319
+ /**
320
+ * Workflow start entry
321
+ */
322
+ export interface StateLogStart extends StateLogBase {
323
+ t: 'start';
324
+ /** Tool/method name being executed */
325
+ tool: string;
326
+ /** Input parameters */
327
+ params: Record<string, any>;
328
+ }
329
+ /**
330
+ * Emit entry (status, progress, etc.)
331
+ */
332
+ export interface StateLogEmit extends StateLogBase {
333
+ t: 'emit';
334
+ /** Emit type (status, progress, stream, log, etc.) */
335
+ emit: string;
336
+ /** Emit message */
337
+ message?: string;
338
+ /** Additional emit data */
339
+ data?: any;
340
+ }
341
+ /**
342
+ * Checkpoint entry - marks safe resume point with state snapshot
343
+ */
344
+ export interface StateLogCheckpoint extends StateLogBase {
345
+ t: 'checkpoint';
346
+ /** Checkpoint ID (auto-generated or explicit) */
347
+ id: string;
348
+ /** Accumulated state at this point */
349
+ state: Record<string, any>;
350
+ }
351
+ /**
352
+ * Ask entry - input request
353
+ */
354
+ export interface StateLogAsk extends StateLogBase {
355
+ t: 'ask';
356
+ /** Ask ID */
357
+ id: string;
358
+ /** Ask type (text, confirm, select, etc.) */
359
+ ask: string;
360
+ /** Ask message */
361
+ message: string;
362
+ }
363
+ /**
364
+ * Answer entry - input response
365
+ */
366
+ export interface StateLogAnswer extends StateLogBase {
367
+ t: 'answer';
368
+ /** Ask ID this answers */
369
+ id: string;
370
+ /** User's response value */
371
+ value: any;
372
+ }
373
+ /**
374
+ * Return entry - workflow completion
375
+ */
376
+ export interface StateLogReturn extends StateLogBase {
377
+ t: 'return';
378
+ /** Final return value */
379
+ value: any;
380
+ }
381
+ /**
382
+ * Error entry - workflow failed
383
+ */
384
+ export interface StateLogError extends StateLogBase {
385
+ t: 'error';
386
+ /** Error message */
387
+ message: string;
388
+ /** Error stack trace */
389
+ stack?: string;
390
+ }
391
+ /**
392
+ * Union of all state log entry types
393
+ */
394
+ export type StateLogEntry = StateLogStart | StateLogEmit | StateLogCheckpoint | StateLogAsk | StateLogAnswer | StateLogReturn | StateLogError;
395
+ /**
396
+ * Workflow run status
397
+ */
398
+ export type WorkflowStatus = 'running' | 'waiting' | 'completed' | 'failed' | 'paused';
399
+ /**
400
+ * Workflow run metadata
401
+ */
402
+ export interface WorkflowRun {
403
+ /** Unique run ID */
404
+ runId: string;
405
+ /** Photon name */
406
+ photon: string;
407
+ /** Tool/method name */
408
+ tool: string;
409
+ /** Input parameters */
410
+ params: Record<string, any>;
411
+ /** Current status */
412
+ status: WorkflowStatus;
413
+ /** Start timestamp */
414
+ startedAt: number;
415
+ /** Last update timestamp */
416
+ updatedAt: number;
417
+ /** Completion timestamp (if completed/failed) */
418
+ completedAt?: number;
419
+ /** Final result (if completed) */
420
+ result?: any;
421
+ /** Error message (if failed) */
422
+ error?: string;
423
+ /** Last checkpoint state */
424
+ lastCheckpoint?: {
425
+ id: string;
426
+ state: Record<string, any>;
427
+ ts: number;
428
+ };
170
429
  }
430
+ export {};
171
431
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,MAAM,YAAY,GACpB,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAChD,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAC7C,MAAM,GAAG,QAAQ,MAAM,EAAE,CAAC;AAE9B,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CA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AM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,qBAAqB;IACrB,MAAM,EAAE,cAAc,CAAC;IACvB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,cAAc,CAAC,EAAE;QACf,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC3B,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC;CACH"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmHH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAY,EAAE,CAAC,GAAe,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAa,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA+PH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAY,EAAE,CAAC,GAAe,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portel/photon-core",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Core library for parsing, loading, and managing .photon.ts files - runtime-agnostic foundation for building custom Photon runtimes",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,7 +8,9 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.js",
13
+ "default": "./dist/index.js"
12
14
  }
13
15
  },
14
16
  "files": [
package/src/generator.ts CHANGED
@@ -279,6 +279,174 @@ export interface AskDate extends AskBase {
279
279
  default?: string;
280
280
  }
281
281
 
282
+ /**
283
+ * JSON Schema property definition for form fields
284
+ */
285
+ export interface FormSchemaProperty {
286
+ type: 'string' | 'number' | 'integer' | 'boolean';
287
+ title?: string;
288
+ description?: string;
289
+ default?: any;
290
+ // String constraints
291
+ minLength?: number;
292
+ maxLength?: number;
293
+ pattern?: string;
294
+ format?: 'email' | 'uri' | 'date' | 'date-time';
295
+ // Number constraints
296
+ minimum?: number;
297
+ maximum?: number;
298
+ // Enum (single select)
299
+ enum?: string[];
300
+ // Enum with titles (single select)
301
+ oneOf?: Array<{ const: string; title: string }>;
302
+ }
303
+
304
+ /**
305
+ * JSON Schema for array (multi-select)
306
+ */
307
+ export interface FormSchemaArrayProperty {
308
+ type: 'array';
309
+ title?: string;
310
+ description?: string;
311
+ minItems?: number;
312
+ maxItems?: number;
313
+ items: {
314
+ type?: 'string';
315
+ enum?: string[];
316
+ anyOf?: Array<{ const: string; title: string }>;
317
+ };
318
+ default?: string[];
319
+ }
320
+
321
+ /**
322
+ * Full form schema (flat object only per MCP spec)
323
+ */
324
+ export interface FormSchema {
325
+ type: 'object';
326
+ properties: Record<string, FormSchemaProperty | FormSchemaArrayProperty>;
327
+ required?: string[];
328
+ }
329
+
330
+ /**
331
+ * Form-based input - multi-field structured data with JSON Schema
332
+ *
333
+ * Aligned with MCP elicitation spec (form mode).
334
+ * Schema is limited to flat objects with primitive properties.
335
+ *
336
+ * @example
337
+ * // Simple form
338
+ * const contact = yield {
339
+ * ask: 'form',
340
+ * id: 'contact',
341
+ * message: 'Enter your contact details',
342
+ * schema: {
343
+ * type: 'object',
344
+ * properties: {
345
+ * name: { type: 'string', title: 'Full Name' },
346
+ * email: { type: 'string', format: 'email', title: 'Email' },
347
+ * subscribe: { type: 'boolean', title: 'Subscribe to newsletter', default: true }
348
+ * },
349
+ * required: ['name', 'email']
350
+ * }
351
+ * };
352
+ *
353
+ * @example
354
+ * // With enum selection
355
+ * const preferences = yield {
356
+ * ask: 'form',
357
+ * id: 'prefs',
358
+ * message: 'Configure your preferences',
359
+ * schema: {
360
+ * type: 'object',
361
+ * properties: {
362
+ * theme: {
363
+ * type: 'string',
364
+ * title: 'Theme',
365
+ * oneOf: [
366
+ * { const: 'light', title: 'Light Mode' },
367
+ * { const: 'dark', title: 'Dark Mode' },
368
+ * { const: 'auto', title: 'System Default' }
369
+ * ],
370
+ * default: 'auto'
371
+ * },
372
+ * notifications: {
373
+ * type: 'array',
374
+ * title: 'Notification Types',
375
+ * items: {
376
+ * anyOf: [
377
+ * { const: 'email', title: 'Email' },
378
+ * { const: 'push', title: 'Push' },
379
+ * { const: 'sms', title: 'SMS' }
380
+ * ]
381
+ * },
382
+ * default: ['email']
383
+ * }
384
+ * }
385
+ * }
386
+ * };
387
+ */
388
+ export interface AskForm extends AskBase {
389
+ ask: 'form';
390
+ /** JSON Schema defining the form fields */
391
+ schema: FormSchema;
392
+ }
393
+
394
+ /**
395
+ * URL-based input - opens browser for OAuth or credential collection
396
+ *
397
+ * Aligned with MCP elicitation spec (url mode).
398
+ * User is redirected to a URL for authentication, then returns.
399
+ *
400
+ * Security: URL opens in secure browser context (not embedded webview).
401
+ * The URL should NOT contain sensitive data.
402
+ *
403
+ * @example
404
+ * // OAuth flow
405
+ * const auth = yield {
406
+ * ask: 'url',
407
+ * id: 'github_auth',
408
+ * message: 'Authenticate with GitHub to continue',
409
+ * url: 'https://github.com/login/oauth/authorize?client_id=...'
410
+ * };
411
+ *
412
+ * @example
413
+ * // API key collection via secure form
414
+ * const result = yield {
415
+ * ask: 'url',
416
+ * id: 'api_key',
417
+ * message: 'Enter your API key securely',
418
+ * url: 'https://myservice.com/collect-api-key?callback=...'
419
+ * };
420
+ */
421
+ export interface AskUrl extends AskBase {
422
+ ask: 'url';
423
+ /** URL to open in browser */
424
+ url: string;
425
+ /**
426
+ * Unique ID for this elicitation (for async completion).
427
+ * If not provided, one will be generated.
428
+ */
429
+ elicitationId?: string;
430
+ }
431
+
432
+ /**
433
+ * Elicitation response action (MCP-aligned)
434
+ */
435
+ export type ElicitAction = 'accept' | 'decline' | 'cancel';
436
+
437
+ /**
438
+ * Result from a form or url elicitation (MCP-aligned)
439
+ *
440
+ * Different from the simpler ElicitResult in elicit.ts which is for
441
+ * native OS dialogs. This follows the MCP elicitation protocol.
442
+ */
443
+ export interface FormElicitResult<T = any> {
444
+ /** User's action */
445
+ action: ElicitAction;
446
+ /** Form content (only present when action is 'accept' and mode is 'form') */
447
+ content?: T;
448
+ }
449
+
282
450
  /**
283
451
  * Union of all ask (input) yield types
284
452
  */
@@ -289,7 +457,9 @@ export type AskYield =
289
457
  | AskSelect
290
458
  | AskNumber
291
459
  | AskFile
292
- | AskDate;
460
+ | AskDate
461
+ | AskForm
462
+ | AskUrl;
293
463
 
294
464
  // ══════════════════════════════════════════════════════════════════════════════
295
465
  // EMIT YIELDS - Output to user (fire and forget)
@@ -443,6 +613,52 @@ export interface EmitArtifact {
443
613
  mimeType?: string;
444
614
  }
445
615
 
616
+ /**
617
+ * UI render - display a UI asset from the Photon's asset folder
618
+ *
619
+ * For MCP Apps (SEP-1865) - renders interactive UI templates
620
+ * The runtime will resolve the asset path and serve the UI appropriately.
621
+ *
622
+ * @example
623
+ * // Show a form UI after a tool runs
624
+ * yield {
625
+ * emit: 'ui',
626
+ * id: 'preferences',
627
+ * title: 'Configure Preferences',
628
+ * data: { currentTheme: 'dark', volume: 80 }
629
+ * };
630
+ *
631
+ * @example
632
+ * // Show inline HTML content
633
+ * yield {
634
+ * emit: 'ui',
635
+ * inline: '<div class="result"><h2>Success!</h2></div>',
636
+ * mimeType: 'text/html'
637
+ * };
638
+ */
639
+ export interface EmitUI {
640
+ emit: 'ui';
641
+ /**
642
+ * UI asset ID (references @ui annotation in Photon)
643
+ * Must match an @ui declared asset: @ui preferences ./ui/preferences.html
644
+ */
645
+ id?: string;
646
+ /** Title for the UI panel/dialog */
647
+ title?: string;
648
+ /** Data to pass to the UI template (available as window.__photon_data__) */
649
+ data?: Record<string, any>;
650
+ /** Inline HTML/JSX content (alternative to id) */
651
+ inline?: string;
652
+ /** MIME type for inline content */
653
+ mimeType?: 'text/html' | 'text/jsx' | 'application/json';
654
+ /** Display mode */
655
+ mode?: 'panel' | 'dialog' | 'fullscreen' | 'inline';
656
+ /** Width hint (CSS value or number in px) */
657
+ width?: string | number;
658
+ /** Height hint (CSS value or number in px) */
659
+ height?: string | number;
660
+ }
661
+
446
662
  /**
447
663
  * Union of all emit (output) yield types
448
664
  */
@@ -453,17 +669,49 @@ export type EmitYield =
453
669
  | EmitLog
454
670
  | EmitToast
455
671
  | EmitThinking
456
- | EmitArtifact;
672
+ | EmitArtifact
673
+ | EmitUI;
457
674
 
458
675
  // ══════════════════════════════════════════════════════════════════════════════
459
676
  // COMBINED TYPES
460
677
  // ══════════════════════════════════════════════════════════════════════════════
461
678
 
679
+ /**
680
+ * Checkpoint yield - marks a safe resume point for stateful workflows
681
+ *
682
+ * Place checkpoints AFTER side effects to ensure idempotency on resume.
683
+ *
684
+ * @example
685
+ * // After a side effect, checkpoint to preserve state
686
+ * const posted = await this.slack.post_message({ ... });
687
+ * yield { checkpoint: true, state: { step: 1, messageTs: posted.ts } };
688
+ */
689
+ export interface CheckpointYield {
690
+ /** Marker for checkpoint yield */
691
+ checkpoint: true;
692
+ /** State snapshot to preserve (accumulated data at this point) */
693
+ state: Record<string, any>;
694
+ /** Optional checkpoint ID (auto-generated if not provided) */
695
+ id?: string;
696
+ }
697
+
698
+ /**
699
+ * Type guard for checkpoint yields
700
+ */
701
+ export function isCheckpointYield(y: any): y is CheckpointYield {
702
+ return y && 'checkpoint' in y && y.checkpoint === true;
703
+ }
704
+
462
705
  /**
463
706
  * All possible yield types from a photon generator
464
707
  */
465
708
  export type PhotonYield = AskYield | EmitYield;
466
709
 
710
+ /**
711
+ * Extended yield type including checkpoint (for stateful workflows)
712
+ */
713
+ export type StatefulYield = PhotonYield | CheckpointYield;
714
+
467
715
  // ══════════════════════════════════════════════════════════════════════════════
468
716
  // TYPE GUARDS - Check what kind of yield we have
469
717
  // ══════════════════════════════════════════════════════════════════════════════
@@ -805,6 +1053,26 @@ function getMockValue(ask: AskYield): any {
805
1053
  return null;
806
1054
  case 'date':
807
1055
  return (ask as AskDate).default || new Date().toISOString();
1056
+ case 'form':
1057
+ // Return object with defaults from schema
1058
+ const form = ask as AskForm;
1059
+ const result: Record<string, any> = {};
1060
+ for (const [key, prop] of Object.entries(form.schema.properties)) {
1061
+ if ('default' in prop && prop.default !== undefined) {
1062
+ result[key] = prop.default;
1063
+ } else if (prop.type === 'string') {
1064
+ result[key] = '';
1065
+ } else if (prop.type === 'number' || prop.type === 'integer') {
1066
+ result[key] = 0;
1067
+ } else if (prop.type === 'boolean') {
1068
+ result[key] = false;
1069
+ } else if (prop.type === 'array') {
1070
+ result[key] = [];
1071
+ }
1072
+ }
1073
+ return { action: 'accept', content: result };
1074
+ case 'url':
1075
+ return { action: 'accept' };
808
1076
  default:
809
1077
  return null;
810
1078
  }