@modular-prompt/process 0.1.11

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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +166 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +5 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/modules/dialogue.d.ts +39 -0
  8. package/dist/modules/dialogue.d.ts.map +1 -0
  9. package/dist/modules/dialogue.js +106 -0
  10. package/dist/modules/dialogue.js.map +1 -0
  11. package/dist/modules/index.d.ts +9 -0
  12. package/dist/modules/index.d.ts.map +1 -0
  13. package/dist/modules/index.js +5 -0
  14. package/dist/modules/index.js.map +1 -0
  15. package/dist/modules/material.d.ts +21 -0
  16. package/dist/modules/material.d.ts.map +1 -0
  17. package/dist/modules/material.js +41 -0
  18. package/dist/modules/material.js.map +1 -0
  19. package/dist/modules/stream-processing.d.ts +26 -0
  20. package/dist/modules/stream-processing.d.ts.map +1 -0
  21. package/dist/modules/stream-processing.js +128 -0
  22. package/dist/modules/stream-processing.js.map +1 -0
  23. package/dist/modules/summarize.d.ts +32 -0
  24. package/dist/modules/summarize.d.ts.map +1 -0
  25. package/dist/modules/summarize.js +97 -0
  26. package/dist/modules/summarize.js.map +1 -0
  27. package/dist/workflows/agent-workflow.d.ts +55 -0
  28. package/dist/workflows/agent-workflow.d.ts.map +1 -0
  29. package/dist/workflows/agent-workflow.js +337 -0
  30. package/dist/workflows/agent-workflow.js.map +1 -0
  31. package/dist/workflows/agentic-workflow/agentic-workflow.d.ts +13 -0
  32. package/dist/workflows/agentic-workflow/agentic-workflow.d.ts.map +1 -0
  33. package/dist/workflows/agentic-workflow/agentic-workflow.js +235 -0
  34. package/dist/workflows/agentic-workflow/agentic-workflow.js.map +1 -0
  35. package/dist/workflows/agentic-workflow/index.d.ts +4 -0
  36. package/dist/workflows/agentic-workflow/index.d.ts.map +1 -0
  37. package/dist/workflows/agentic-workflow/index.js +5 -0
  38. package/dist/workflows/agentic-workflow/index.js.map +1 -0
  39. package/dist/workflows/agentic-workflow/modules/agentic.d.ts +12 -0
  40. package/dist/workflows/agentic-workflow/modules/agentic.d.ts.map +1 -0
  41. package/dist/workflows/agentic-workflow/modules/agentic.js +22 -0
  42. package/dist/workflows/agentic-workflow/modules/agentic.js.map +1 -0
  43. package/dist/workflows/agentic-workflow/modules/execution-freeform.d.ts +15 -0
  44. package/dist/workflows/agentic-workflow/modules/execution-freeform.d.ts.map +1 -0
  45. package/dist/workflows/agentic-workflow/modules/execution-freeform.js +140 -0
  46. package/dist/workflows/agentic-workflow/modules/execution-freeform.js.map +1 -0
  47. package/dist/workflows/agentic-workflow/modules/execution.d.ts +11 -0
  48. package/dist/workflows/agentic-workflow/modules/execution.d.ts.map +1 -0
  49. package/dist/workflows/agentic-workflow/modules/execution.js +180 -0
  50. package/dist/workflows/agentic-workflow/modules/execution.js.map +1 -0
  51. package/dist/workflows/agentic-workflow/modules/index.d.ts +6 -0
  52. package/dist/workflows/agentic-workflow/modules/index.d.ts.map +1 -0
  53. package/dist/workflows/agentic-workflow/modules/index.js +7 -0
  54. package/dist/workflows/agentic-workflow/modules/index.js.map +1 -0
  55. package/dist/workflows/agentic-workflow/modules/integration.d.ts +11 -0
  56. package/dist/workflows/agentic-workflow/modules/integration.d.ts.map +1 -0
  57. package/dist/workflows/agentic-workflow/modules/integration.js +85 -0
  58. package/dist/workflows/agentic-workflow/modules/integration.js.map +1 -0
  59. package/dist/workflows/agentic-workflow/modules/planning.d.ts +11 -0
  60. package/dist/workflows/agentic-workflow/modules/planning.d.ts.map +1 -0
  61. package/dist/workflows/agentic-workflow/modules/planning.js +103 -0
  62. package/dist/workflows/agentic-workflow/modules/planning.js.map +1 -0
  63. package/dist/workflows/agentic-workflow/types.d.ts +60 -0
  64. package/dist/workflows/agentic-workflow/types.d.ts.map +1 -0
  65. package/dist/workflows/agentic-workflow/types.js +2 -0
  66. package/dist/workflows/agentic-workflow/types.js.map +1 -0
  67. package/dist/workflows/concat-process-workflow.d.ts +29 -0
  68. package/dist/workflows/concat-process-workflow.d.ts.map +1 -0
  69. package/dist/workflows/concat-process-workflow.js +121 -0
  70. package/dist/workflows/concat-process-workflow.js.map +1 -0
  71. package/dist/workflows/dialogue-workflow.d.ts +25 -0
  72. package/dist/workflows/dialogue-workflow.d.ts.map +1 -0
  73. package/dist/workflows/dialogue-workflow.js +139 -0
  74. package/dist/workflows/dialogue-workflow.js.map +1 -0
  75. package/dist/workflows/index.d.ts +14 -0
  76. package/dist/workflows/index.d.ts.map +1 -0
  77. package/dist/workflows/index.js +13 -0
  78. package/dist/workflows/index.js.map +1 -0
  79. package/dist/workflows/self-prompting-workflow/index.d.ts +12 -0
  80. package/dist/workflows/self-prompting-workflow/index.d.ts.map +1 -0
  81. package/dist/workflows/self-prompting-workflow/index.js +11 -0
  82. package/dist/workflows/self-prompting-workflow/index.js.map +1 -0
  83. package/dist/workflows/self-prompting-workflow/modules/integration.d.ts +11 -0
  84. package/dist/workflows/self-prompting-workflow/modules/integration.d.ts.map +1 -0
  85. package/dist/workflows/self-prompting-workflow/modules/integration.js +82 -0
  86. package/dist/workflows/self-prompting-workflow/modules/integration.js.map +1 -0
  87. package/dist/workflows/self-prompting-workflow/modules/planning.d.ts +11 -0
  88. package/dist/workflows/self-prompting-workflow/modules/planning.d.ts.map +1 -0
  89. package/dist/workflows/self-prompting-workflow/modules/planning.js +108 -0
  90. package/dist/workflows/self-prompting-workflow/modules/planning.js.map +1 -0
  91. package/dist/workflows/self-prompting-workflow/self-prompting-workflow.d.ts +14 -0
  92. package/dist/workflows/self-prompting-workflow/self-prompting-workflow.d.ts.map +1 -0
  93. package/dist/workflows/self-prompting-workflow/self-prompting-workflow.js +250 -0
  94. package/dist/workflows/self-prompting-workflow/self-prompting-workflow.js.map +1 -0
  95. package/dist/workflows/self-prompting-workflow/types.d.ts +56 -0
  96. package/dist/workflows/self-prompting-workflow/types.d.ts.map +1 -0
  97. package/dist/workflows/self-prompting-workflow/types.js +2 -0
  98. package/dist/workflows/self-prompting-workflow/types.js.map +1 -0
  99. package/dist/workflows/stream-workflow.d.ts +17 -0
  100. package/dist/workflows/stream-workflow.d.ts.map +1 -0
  101. package/dist/workflows/stream-workflow.js +119 -0
  102. package/dist/workflows/stream-workflow.js.map +1 -0
  103. package/dist/workflows/summarize-workflow.d.ts +39 -0
  104. package/dist/workflows/summarize-workflow.d.ts.map +1 -0
  105. package/dist/workflows/summarize-workflow.js +152 -0
  106. package/dist/workflows/summarize-workflow.js.map +1 -0
  107. package/dist/workflows/types.d.ts +37 -0
  108. package/dist/workflows/types.d.ts.map +1 -0
  109. package/dist/workflows/types.js +25 -0
  110. package/dist/workflows/types.js.map +1 -0
  111. package/package.json +72 -0
@@ -0,0 +1,121 @@
1
+ import { compile } from '@modular-prompt/core';
2
+ import { WorkflowExecutionError } from './types.js';
3
+ /**
4
+ * Concat processing workflow - processes chunks independently and concatenates results
5
+ * Unlike stream processing which maintains state, concat treats each chunk independently
6
+ */
7
+ export async function concatProcess(driver, module, context, options = {}) {
8
+ const { batchSize = 1, separator = '\n', parallel = false } = options;
9
+ if (!context.chunks || context.chunks.length === 0) {
10
+ throw new Error('No chunks provided for processing');
11
+ }
12
+ // Use existing results or start fresh
13
+ const results = context.results ? [...context.results] : [];
14
+ let processedCount = context.processedCount || 0;
15
+ // Calculate starting point based on processed count
16
+ const startIndex = processedCount;
17
+ const remainingChunks = context.chunks.slice(startIndex);
18
+ if (parallel && batchSize === 1) {
19
+ // Process all remaining chunks in parallel
20
+ const promises = remainingChunks.map(async (chunk, index) => {
21
+ const chunkContext = {
22
+ chunks: [chunk],
23
+ processedCount: startIndex + index
24
+ };
25
+ const prompt = compile(module, chunkContext);
26
+ try {
27
+ const result = await driver.query(prompt);
28
+ // Check finish reason for dynamic failures
29
+ if (result.finishReason && result.finishReason !== 'stop') {
30
+ throw new WorkflowExecutionError(`Query failed with reason: ${result.finishReason}`, {
31
+ ...context,
32
+ results,
33
+ processedCount: startIndex + index
34
+ }, {
35
+ phase: 'parallel-process',
36
+ partialResult: results.length > 0 ? results.join(separator) : '',
37
+ finishReason: result.finishReason
38
+ });
39
+ }
40
+ return result.content;
41
+ }
42
+ catch (error) {
43
+ // If it's already a WorkflowExecutionError, re-throw
44
+ if (error instanceof WorkflowExecutionError) {
45
+ throw error;
46
+ }
47
+ throw new WorkflowExecutionError(error, {
48
+ ...context,
49
+ results,
50
+ processedCount: startIndex + index
51
+ }, {
52
+ phase: 'parallel-process',
53
+ partialResult: results.length > 0 ? results.join(separator) : ''
54
+ });
55
+ }
56
+ });
57
+ const parallelResults = await Promise.all(promises);
58
+ results.push(...parallelResults);
59
+ processedCount = context.chunks.length;
60
+ }
61
+ else {
62
+ // Process chunks sequentially, possibly in batches
63
+ for (let i = 0; i < remainingChunks.length; i += batchSize) {
64
+ const batch = remainingChunks.slice(i, Math.min(i + batchSize, remainingChunks.length));
65
+ const batchContext = {
66
+ chunks: batch,
67
+ results: results.length > 0 ? results : undefined,
68
+ processedCount: startIndex + i
69
+ };
70
+ const prompt = compile(module, batchContext);
71
+ try {
72
+ const queryResult = await driver.query(prompt);
73
+ // Check finish reason for dynamic failures
74
+ if (queryResult.finishReason && queryResult.finishReason !== 'stop') {
75
+ throw new WorkflowExecutionError(`Query failed with reason: ${queryResult.finishReason}`, {
76
+ ...context,
77
+ results,
78
+ processedCount
79
+ }, {
80
+ phase: 'sequential-process',
81
+ partialResult: results.length > 0 ? results.join(separator) : undefined,
82
+ finishReason: queryResult.finishReason
83
+ });
84
+ }
85
+ results.push(queryResult.content);
86
+ processedCount = startIndex + i + batch.length;
87
+ }
88
+ catch (error) {
89
+ // If it's already a WorkflowExecutionError, re-throw
90
+ if (error instanceof WorkflowExecutionError) {
91
+ throw error;
92
+ }
93
+ throw new WorkflowExecutionError(error, {
94
+ ...context,
95
+ results,
96
+ processedCount
97
+ }, {
98
+ phase: 'sequential-process',
99
+ partialResult: results.length > 0 ? results.join(separator) : undefined
100
+ });
101
+ }
102
+ }
103
+ }
104
+ // Concatenate results
105
+ const output = results.join(separator);
106
+ const finalContext = {
107
+ ...context,
108
+ results,
109
+ processedCount
110
+ };
111
+ return {
112
+ output,
113
+ context: finalContext,
114
+ metadata: {
115
+ chunksProcessed: processedCount,
116
+ resultsCount: results.length,
117
+ parallel
118
+ }
119
+ };
120
+ }
121
+ //# sourceMappingURL=concat-process-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concat-process-workflow.js","sourceRoot":"","sources":["../../src/workflows/concat-process-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,sBAAsB,EAAsC,MAAM,YAAY,CAAC;AA0BxF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAgB,EAChB,MAA0C,EAC1C,OAA6B,EAC7B,UAAgC,EAAE;IAGlC,MAAM,EACJ,SAAS,GAAG,CAAC,EACb,SAAS,GAAG,IAAI,EAChB,QAAQ,GAAG,KAAK,EACjB,GAAG,OAAO,CAAC;IAEZ,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IAED,sCAAsC;IACtC,MAAM,OAAO,GAAa,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,IAAI,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,CAAC,CAAC;IAEjD,oDAAoD;IACpD,MAAM,UAAU,GAAG,cAAc,CAAC;IAClC,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAEzD,IAAI,QAAQ,IAAI,SAAS,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AC3B,aAAa,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;wBACvE,YAAY,EAAE,WAAW,CAAC,YAAY;qBACvC,CACF,CAAC;gBACJ,CAAC;gBAED,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBAClC,cAAc,GAAG,UAAU,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;YACjD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,qDAAqD;gBACrD,IAAI,KAAK,YAAY,sBAAsB,EAAE,CAAC;oBAC5C,MAAM,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM,IAAI,sBAAsB,CAAC,KAAc,EAAE;oBAC/C,GAAG,OAAO;oBACV,OAAO;oBACP,cAAc;iBACf,EAAE;oBACD,KAAK,EAAE,oBAAoB;oBAC3B,aAAa,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;iBACxE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,sBAAsB;IACtB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAEvC,MAAM,YAAY,GAAyB;QACzC,GAAG,OAAO;QACV,OAAO;QACP,cAAc;KACf,CAAC;IAEF,OAAO;QACL,MAAM;QACN,OAAO,EAAE,YAAY;QACrB,QAAQ,EAAE;YACR,eAAe,EAAE,cAAc;YAC/B,YAAY,EAAE,OAAO,CAAC,MAAM;YAC5B,QAAQ;SACT;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { PromptModule } from '@modular-prompt/core';
2
+ import type { DialogueContext } from '../modules/dialogue.js';
3
+ import type { MaterialContext } from '../modules/material.js';
4
+ import { type AIDriver, type WorkflowResult } from './types.js';
5
+ /**
6
+ * Extended dialogue context with materials and preparation note
7
+ */
8
+ export interface DialogueWorkflowContext extends DialogueContext, MaterialContext {
9
+ preparationNote?: {
10
+ content: string;
11
+ };
12
+ }
13
+ /**
14
+ * Options for dialogue workflow
15
+ */
16
+ export interface DialogueWorkflowOptions {
17
+ twoPass?: boolean;
18
+ maintainState?: boolean;
19
+ includematerials?: boolean;
20
+ }
21
+ /**
22
+ * Dialogue workflow - handles conversational interactions with optional two-pass processing
23
+ */
24
+ export declare function dialogueProcess(driver: AIDriver, module: PromptModule<DialogueWorkflowContext>, context: DialogueWorkflowContext, options?: DialogueWorkflowOptions): Promise<WorkflowResult<DialogueWorkflowContext>>;
25
+ //# sourceMappingURL=dialogue-workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialogue-workflow.d.ts","sourceRoot":"","sources":["../../src/workflows/dialogue-workflow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAOzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAA0B,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,eAAe,EAAE,eAAe;IAC/E,eAAe,CAAC,EAAE;QAChB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,YAAY,CAAC,uBAAuB,CAAC,EAC7C,OAAO,EAAE,uBAAuB,EAChC,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC,CA8JlD"}
@@ -0,0 +1,139 @@
1
+ import { compile, merge } from '@modular-prompt/core';
2
+ import { firstOfTwoPassResponse, secondOfTwoPassResponse, withTalkState } from '../modules/dialogue.js';
3
+ import { withMaterials } from '../modules/material.js';
4
+ import { WorkflowExecutionError } from './types.js';
5
+ /**
6
+ * Dialogue workflow - handles conversational interactions with optional two-pass processing
7
+ */
8
+ export async function dialogueProcess(driver, module, context, options = {}) {
9
+ const { twoPass = false, maintainState = false, includematerials = false } = options;
10
+ // Build the module based on options
11
+ let workflowModule = module;
12
+ if (maintainState) {
13
+ workflowModule = merge(workflowModule, withTalkState);
14
+ }
15
+ if (includematerials && context.materials) {
16
+ workflowModule = merge(workflowModule, withMaterials);
17
+ }
18
+ if (twoPass) {
19
+ // First pass: Generate preparation notes
20
+ const firstPassModule = merge(workflowModule, firstOfTwoPassResponse);
21
+ const firstPassPrompt = compile(firstPassModule, context);
22
+ let preparationNote;
23
+ try {
24
+ const queryResult = await driver.query(firstPassPrompt);
25
+ // Check finish reason for dynamic failures
26
+ if (queryResult.finishReason && queryResult.finishReason !== 'stop') {
27
+ throw new WorkflowExecutionError(`Query failed with reason: ${queryResult.finishReason}`, context, {
28
+ phase: 'firstPass',
29
+ partialResult: '',
30
+ finishReason: queryResult.finishReason
31
+ });
32
+ }
33
+ preparationNote = queryResult.content;
34
+ }
35
+ catch (error) {
36
+ // If it's already a WorkflowExecutionError, re-throw
37
+ if (error instanceof WorkflowExecutionError) {
38
+ throw error;
39
+ }
40
+ // Preserve context on driver error for first pass
41
+ throw new WorkflowExecutionError(error, context, {
42
+ phase: 'firstPass',
43
+ partialResult: ''
44
+ });
45
+ }
46
+ // Update context with preparation note
47
+ const updatedContext = {
48
+ ...context,
49
+ preparationNote: { content: preparationNote }
50
+ };
51
+ // Second pass: Generate actual response
52
+ const secondPassModule = merge(workflowModule, secondOfTwoPassResponse);
53
+ const secondPassPrompt = compile(secondPassModule, updatedContext);
54
+ let response;
55
+ try {
56
+ const queryResult = await driver.query(secondPassPrompt);
57
+ // Check finish reason for dynamic failures
58
+ if (queryResult.finishReason && queryResult.finishReason !== 'stop') {
59
+ throw new WorkflowExecutionError(`Query failed with reason: ${queryResult.finishReason}`, updatedContext, {
60
+ phase: 'secondPass',
61
+ partialResult: preparationNote,
62
+ finishReason: queryResult.finishReason
63
+ });
64
+ }
65
+ response = queryResult.content;
66
+ }
67
+ catch (error) {
68
+ // If it's already a WorkflowExecutionError, re-throw
69
+ if (error instanceof WorkflowExecutionError) {
70
+ throw error;
71
+ }
72
+ // Preserve updated context (with preparation note) on driver error for second pass
73
+ throw new WorkflowExecutionError(error, updatedContext, {
74
+ phase: 'secondPass',
75
+ partialResult: preparationNote
76
+ });
77
+ }
78
+ // Update messages with the response
79
+ const finalContext = {
80
+ ...updatedContext,
81
+ messages: [
82
+ ...(context.messages || []),
83
+ { role: 'assistant', content: response }
84
+ ]
85
+ };
86
+ return {
87
+ output: response,
88
+ context: finalContext,
89
+ metadata: {
90
+ twoPass: true,
91
+ preparationNoteLength: preparationNote.length
92
+ }
93
+ };
94
+ }
95
+ else {
96
+ // Single pass response
97
+ const prompt = compile(workflowModule, context);
98
+ let response;
99
+ try {
100
+ const queryResult = await driver.query(prompt);
101
+ // Check finish reason for dynamic failures
102
+ if (queryResult.finishReason && queryResult.finishReason !== 'stop') {
103
+ throw new WorkflowExecutionError(`Query failed with reason: ${queryResult.finishReason}`, context, {
104
+ phase: 'singlePass',
105
+ partialResult: '',
106
+ finishReason: queryResult.finishReason
107
+ });
108
+ }
109
+ response = queryResult.content;
110
+ }
111
+ catch (error) {
112
+ // If it's already a WorkflowExecutionError, re-throw
113
+ if (error instanceof WorkflowExecutionError) {
114
+ throw error;
115
+ }
116
+ // Preserve context on driver error
117
+ throw new WorkflowExecutionError(error, context, {
118
+ phase: 'singlePass',
119
+ partialResult: ''
120
+ });
121
+ }
122
+ // Update context with new message
123
+ const finalContext = {
124
+ ...context,
125
+ messages: [
126
+ ...(context.messages || []),
127
+ { role: 'assistant', content: response }
128
+ ]
129
+ };
130
+ return {
131
+ output: response,
132
+ context: finalContext,
133
+ metadata: {
134
+ twoPass: false
135
+ }
136
+ };
137
+ }
138
+ }
139
+ //# sourceMappingURL=dialogue-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialogue-workflow.js","sourceRoot":"","sources":["../../src/workflows/dialogue-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAsC,MAAM,YAAY,CAAC;AAoBxF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAgB,EAChB,MAA6C,EAC7C,OAAgC,EAChC,UAAmC,EAAE;IAGrC,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,aAAa,GAAG,KAAK,EAAE,gBAAgB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAErF,oCAAoC;IACpC,IAAI,cAAc,GAAG,MAAM,CAAC;IAE5B,IAAI,aAAa,EAAE,CAAC;QAClB,cAAc,GAAG,KAAK,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,gBAAgB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QAC1C,cAAc,GAAG,KAAK,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,yCAAyC;QACzC,MAAM,eAAe,GAAG,KAAK,CAAC,cAAc,EAAE,sBAAsB,CAAC,CAAC;QACtE,MAAM,eAAe,GAAG,OAA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K,MAAM,EAAE,CAAC;gBACpE,MAAM,IAAI,sBAAsB,CAC9B,6BAA6B,WAAW,CAAC,YAAY,EAAE,EACvD,OAAO,EACP;oBACE,KAAK,EAAE,YAAY;oBACnB,aAAa,EAAE,EAAE;oBACjB,YAAY,EAAE,WAAW,CAAC,YAAY;iBACvC,CACF,CAAC;YACJ,CAAC;YAED,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qDAAqD;YACrD,IAAI,KAAK,YAAY,sBAAsB,EAAE,CAAC;gBAC5C,MAAM,KAAK,CAAC;YACd,CAAC;YACD,mCAAmC;YACnC,MAAM,IAAI,sBAAsB,CAAC,KAAc,EAAE,OAAO,EAAE;gBACxD,KAAK,EAAE,YAAY;gBACnB,aAAa,EAAE,EAAE;aAClB,CAAC,CAAC;QACL,CAAC;QAED,kCAAkC;QAClC,MAAM,YAAY,GAA4B;YAC5C,GAAG,OAAO;YACV,QAAQ,EAAE;gBACR,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;gBAC3B,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE;aACzC;SACF,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,YAAY;YACrB,QAAQ,EAAE;gBACR,OAAO,EAAE,KAAK;aACf;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ export type { AIDriver, WorkflowResult, WorkflowError, WorkflowExecutionError } from './types.js';
2
+ export { streamProcess } from './stream-workflow.js';
3
+ export type { StreamWorkflowOptions } from './stream-workflow.js';
4
+ export { dialogueProcess } from './dialogue-workflow.js';
5
+ export type { DialogueWorkflowContext, DialogueWorkflowOptions } from './dialogue-workflow.js';
6
+ export { summarizeProcess } from './summarize-workflow.js';
7
+ export type { SummarizeWorkflowContext, SummarizeWorkflowOptions } from './summarize-workflow.js';
8
+ export { concatProcess } from './concat-process-workflow.js';
9
+ export type { ConcatProcessContext, ConcatProcessOptions } from './concat-process-workflow.js';
10
+ export { agenticProcess } from './agentic-workflow/index.js';
11
+ export type { AgenticWorkflowContext, AgenticWorkflowOptions, ActionHandler } from './agentic-workflow/index.js';
12
+ export { agentProcess } from './agent-workflow.js';
13
+ export type { AgentWorkflowContext, AgentWorkflowOptions, AgentWorkflowActionHandler } from './agent-workflow.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,QAAQ,EACR,cAAc,EACd,aAAa,EACb,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAGlE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EACV,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,aAAa,EACd,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,13 @@
1
+ // Stream workflow
2
+ export { streamProcess } from './stream-workflow.js';
3
+ // Dialogue workflow
4
+ export { dialogueProcess } from './dialogue-workflow.js';
5
+ // Summarize workflow
6
+ export { summarizeProcess } from './summarize-workflow.js';
7
+ // Concat workflow
8
+ export { concatProcess } from './concat-process-workflow.js';
9
+ // Agentic workflow
10
+ export { agenticProcess } from './agentic-workflow/index.js';
11
+ // Simple agent workflow
12
+ export { agentProcess } from './agent-workflow.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflows/index.ts"],"names":[],"mappings":"AAQA,kBAAkB;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,oBAAoB;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAMzD,qBAAqB;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAM3D,kBAAkB;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAM7D,mBAAmB;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAO7D,wBAAwB;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Self-prompting workflow - AI generates complete prompts for each execution step
3
+ *
4
+ * This workflow is an alternative to agentic-workflow where the AI generates
5
+ * complete prompts (instructions + data arrays) during planning, and executes
6
+ * them directly without moduler-prompt compilation during execution phase.
7
+ */
8
+ export { selfPromptingProcess } from './self-prompting-workflow.js';
9
+ export { planning } from './modules/planning.js';
10
+ export { integration } from './modules/integration.js';
11
+ export type { SelfPromptingWorkflowContext, SelfPromptingWorkflowOptions, SelfPromptingPlan, SelfPromptingStep, SelfPromptingExecutionLog, ActionHandler } from './types.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/workflows/self-prompting-workflow/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EACV,4BAA4B,EAC5B,4BAA4B,EAC5B,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,aAAa,EACd,MAAM,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Self-prompting workflow - AI generates complete prompts for each execution step
3
+ *
4
+ * This workflow is an alternative to agentic-workflow where the AI generates
5
+ * complete prompts (instructions + data arrays) during planning, and executes
6
+ * them directly without moduler-prompt compilation during execution phase.
7
+ */
8
+ export { selfPromptingProcess } from './self-prompting-workflow.js';
9
+ export { planning } from './modules/planning.js';
10
+ export { integration } from './modules/integration.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/workflows/self-prompting-workflow/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { PromptModule } from '@modular-prompt/core';
2
+ import type { SelfPromptingWorkflowContext } from '../types.js';
3
+ /**
4
+ * Integration phase module for self-prompting workflow
5
+ * Phase-specific definitions for integrating all step results
6
+ *
7
+ * Should be merged with base module and user's module:
8
+ * merge(baseModule, integration, userModule)
9
+ */
10
+ export declare const integration: PromptModule<SelfPromptingWorkflowContext>;
11
+ //# sourceMappingURL=integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../../src/workflows/self-prompting-workflow/modules/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,4BAA4B,EAAqB,MAAM,aAAa,CAAC;AAEnF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,EAAE,YAAY,CAAC,4BAA4B,CAqFlE,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Integration phase module for self-prompting workflow
3
+ * Phase-specific definitions for integrating all step results
4
+ *
5
+ * Should be merged with base module and user's module:
6
+ * merge(baseModule, integration, userModule)
7
+ */
8
+ export const integration = {
9
+ methodology: [
10
+ '- **Current Phase: Integration**',
11
+ ' - Integrate results from all executed steps.',
12
+ ' - Generate the final output that achieves the overall objective.'
13
+ ],
14
+ instructions: [
15
+ {
16
+ type: 'subsection',
17
+ title: 'Integration Phase Process',
18
+ items: [
19
+ '- Integrate execution results from all steps in the "Execution Plan" to generate the final output',
20
+ '- Verify that the objective has been achieved',
21
+ '- Clearly describe important results from each step'
22
+ ]
23
+ },
24
+ {
25
+ type: 'subsection',
26
+ title: 'Execution Plan (All Steps Completed)',
27
+ items: [
28
+ (ctx) => {
29
+ if (!ctx.plan) {
30
+ return null;
31
+ }
32
+ return ctx.plan.steps.map((step) => {
33
+ const parts = [step.id];
34
+ // Tools
35
+ if (step.actions && step.actions.length > 0) {
36
+ const toolNames = step.actions.map(a => a.tool).join(', ');
37
+ parts.push(`(Tools: ${toolNames})`);
38
+ }
39
+ return `- ${parts.join(' ')}`;
40
+ });
41
+ }
42
+ ]
43
+ }
44
+ ],
45
+ state: [
46
+ (ctx) => {
47
+ const total = ctx.plan?.steps.length || 0;
48
+ return `All ${total} steps completed. Generating final output.`;
49
+ }
50
+ ],
51
+ inputs: [
52
+ (ctx) => ctx.inputs ? JSON.stringify(ctx.inputs, null, 2) : null
53
+ ],
54
+ materials: [
55
+ (ctx) => {
56
+ if (!ctx.executionLog || ctx.executionLog.length === 0) {
57
+ return null;
58
+ }
59
+ return ctx.executionLog.map((log) => {
60
+ const parts = [];
61
+ parts.push(`[Result]\n${log.result}`);
62
+ if (log.actionResult !== undefined) {
63
+ const actionResultStr = typeof log.actionResult === 'string'
64
+ ? log.actionResult
65
+ : JSON.stringify(log.actionResult, null, 2);
66
+ parts.push(`[Action Result]\n${actionResultStr}`);
67
+ }
68
+ return {
69
+ type: 'material',
70
+ id: `execution-result-${log.stepId}`,
71
+ title: `Execution result: ${log.stepId}`,
72
+ content: parts.join('\n\n')
73
+ };
74
+ });
75
+ }
76
+ ],
77
+ cue: [
78
+ 'Integrate all execution results to generate the final output.',
79
+ 'Summarize what was accomplished and provide the complete solution to the objective.'
80
+ ]
81
+ };
82
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.js","sourceRoot":"","sources":["../../../../src/workflows/self-prompting-workflow/modules/integration.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAA+C;IACrE,WAAW,EAAE;QACX,kCAAkC;QAClC,gDAAgD;QAChD,oEAAoE;KACrE;IAED,YAAY,EAAE;QACZ;YACE,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,2BAA2B;YAClC,KAAK,EAAE;gBACL,mGAAmG;gBACnG,+CAA+C;gBAC/C,qDAAqD;aACtD;SACF;QACD;YACE,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,sCAAsC;YAC7C,KAAK,EAAE;gBACL,CAAC,GAAG,EAAE,EAAE;oBACN,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;wBACd,OAAO,IAAI,CAAC;oBACd,CAAC;oBAED,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAuB,EAAE,EAAE;wBACpD,MAAM,KAAK,GAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;wBAElC,QAAQ;wBACR,IAAI,IAAI,C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O,GAAG,CAAC,YAAY,KAAK,QAAQ;wBAC1D,CAAC,CAAC,GAAG,CAAC,YAAY;wBAClB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;oBAC9C,KAAK,CAAC,IAAI,CAAC,oBAAoB,eAAe,EAAE,CAAC,CAAC;gBACpD,CAAC;gBAED,OAAO;oBACL,IAAI,EAAE,UAAmB;oBACzB,EAAE,EAAE,oBAAoB,GAAG,CAAC,MAAM,EAAE;oBACpC,KAAK,EAAE,qBAAqB,GAAG,CAAC,MAAM,EAAE;oBACxC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;iBAC5B,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF;IAED,GAAG,EAAE;QACH,+DAA+D;QAC/D,qFAAqF;KACtF;CACF,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { PromptModule } from '@modular-prompt/core';
2
+ import type { SelfPromptingWorkflowContext } from '../types.js';
3
+ /**
4
+ * Planning phase module for self-prompting workflow
5
+ * Phase-specific definitions for generating execution plan with complete prompts
6
+ *
7
+ * Should be merged with base module and user's module:
8
+ * merge(baseModule, planning, userModule)
9
+ */
10
+ export declare const planning: PromptModule<SelfPromptingWorkflowContext>;
11
+ //# sourceMappingURL=planning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planning.d.ts","sourceRoot":"","sources":["../../../../src/workflows/self-prompting-workflow/modules/planning.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,YAAY,CAAC,4BAA4B,CAwG/D,CAAC"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Planning phase module for self-prompting workflow
3
+ * Phase-specific definitions for generating execution plan with complete prompts
4
+ *
5
+ * Should be merged with base module and user's module:
6
+ * merge(baseModule, planning, userModule)
7
+ */
8
+ export const planning = {
9
+ terms: [
10
+ '- **Processing Step**: A unit of work to accomplish the objective (NOT a part of the deliverable)',
11
+ '- **Self-contained Prompt**: Complete instruction text for executing one step independently',
12
+ ' - Template structure:',
13
+ ' ```',
14
+ ' # Instructions',
15
+ ' [What to do, requirements]',
16
+ ' ',
17
+ ' # Data',
18
+ ' [All necessary data]',
19
+ ' ```'
20
+ ],
21
+ methodology: [
22
+ '- **Current Phase: Planning**',
23
+ ' - Generate an execution plan by breaking down the Objective and Instructions into 3-5 **processing steps**',
24
+ ' - For each processing step, generate a self-contained prompt',
25
+ ' - Output structured JSON text immediately, with no explanations or commentary'
26
+ ],
27
+ instructions: [
28
+ {
29
+ type: 'subsection',
30
+ title: 'Planning Requirements',
31
+ items: [
32
+ '- Break down the Objective and Instructions into 3-5 processing steps',
33
+ '- Each step must have: id, prompt',
34
+ ' - **id**: Unique identifier (step-1, step-2, ...)',
35
+ ' - **prompt**: Self-contained text following template:',
36
+ ' ```',
37
+ ' # Instructions',
38
+ ' [What to do]',
39
+ ' ',
40
+ ' # Data',
41
+ ' [All necessary data from Input Data section]',
42
+ ' ```',
43
+ ' - Include all data needed to execute the step',
44
+ ' - For steps depending on previous steps: mention "Results from step-X will be provided"',
45
+ '',
46
+ '**Output Format**',
47
+ '- Respond ONLY with valid JSON',
48
+ '- NO explanatory text',
49
+ '- NO markdown code blocks',
50
+ '- Start with { "steps": [ and end with ]}'
51
+ ]
52
+ }
53
+ ],
54
+ inputs: [
55
+ (ctx) => ctx.inputs ? JSON.stringify(ctx.inputs, null, 2) : null
56
+ ],
57
+ cue: [
58
+ 'Respond with JSON execution plan: {"steps": [{"id": "step-1", "prompt": "..."}, ...]}'
59
+ ],
60
+ schema: [
61
+ {
62
+ type: 'json',
63
+ content: {
64
+ type: 'object',
65
+ properties: {
66
+ steps: {
67
+ type: 'array',
68
+ items: {
69
+ type: 'object',
70
+ properties: {
71
+ id: {
72
+ type: 'string',
73
+ description: 'Unique step ID (e.g., step-1, step-2)'
74
+ },
75
+ prompt: {
76
+ type: 'string',
77
+ description: 'Self-contained prompt text following template: "# Instructions\\n[command]\\n[requirements]\\n\\n# Data\\n[all necessary data]"'
78
+ },
79
+ actions: {
80
+ type: 'array',
81
+ items: {
82
+ type: 'object',
83
+ properties: {
84
+ tool: {
85
+ type: 'string',
86
+ description: 'Tool name from available actions'
87
+ },
88
+ params: {
89
+ type: 'object',
90
+ description: 'Tool parameters (optional)'
91
+ }
92
+ },
93
+ required: ['tool']
94
+ },
95
+ description: 'External tools to use (optional, only if available actions exist)'
96
+ }
97
+ },
98
+ required: ['id', 'prompt']
99
+ },
100
+ description: 'List of processing steps to accomplish the objective'
101
+ }
102
+ },
103
+ required: ['steps']
104
+ }
105
+ }
106
+ ]
107
+ };
108
+ //# sourceMappingURL=planning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planning.js","sourceRoot":"","sources":["../../../../src/workflows/self-prompting-workflow/modules/planning.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAA+C;IAClE,KAAK,EAAE;QACL,mGAAmG;QACnG,6FAA6F;QAC7F,yBAAyB;QACzB,SAAS;QACT,oBAAoB;QACpB,gCAAgC;QAChC,MAAM;QACN,YAAY;QACZ,0BAA0B;QAC1B,SAAS;KACV;IAED,WAAW,EAAE;QACX,+BAA+B;QAC/B,8GAA8G;QAC9G,gEAAgE;QAChE,iFAAiF;KAClF;IAED,YAAY,EAAE;QACZ;YACE,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,uBAAuB;YAC9B,KAAK,EAAE;gBACL,uEAAuE;gBACvE,mCAAmC;gBACnC,qDAAqD;gBACrD,yDAAyD;gBACzD,SAAS;gBACT,oBAAoB;gBACpB,kBAAkB;gBAClB,MAAM;gBACN,YAAY;gBACZ,kDAAkD;gBAClD,SAAS;gBACT,i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AC"}
@@ -0,0 +1,14 @@
1
+ import type { PromptModule } from '@modular-prompt/core';
2
+ import type { AIDriver, WorkflowResult } from '../types.js';
3
+ import type { SelfPromptingWorkflowContext, SelfPromptingWorkflowOptions } from './types.js';
4
+ /**
5
+ * Self-prompting workflow - AI generates complete prompts for each step
6
+ *
7
+ * @param driver - AI driver for executing prompts
8
+ * @param module - User's prompt module (merged with phase modules internally)
9
+ * @param context - Workflow context
10
+ * @param options - Workflow options
11
+ * @returns Workflow result with final output and updated context
12
+ */
13
+ export declare function selfPromptingProcess(driver: AIDriver, module: PromptModule<SelfPromptingWorkflowContext>, context: SelfPromptingWorkflowContext, options?: SelfPromptingWorkflowOptions): Promise<WorkflowResult<SelfPromptingWorkflowContext>>;
14
+ //# sourceMappingURL=self-prompting-workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"self-prompting-workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/self-prompting-workflow/self-prompting-workflow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,sBAAsB,CAAC;AAEzE,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAK7B,MAAM,YAAY,CAAC;AAqQpB;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,YAAY,CAAC,4BAA4B,CAAC,EAClD,OAAO,EAAE,4BAA4B,EACrC,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,cAAc,CAAC,4BAA4B,CAAC,CAAC,CAmEvD"}