@manifesto-ai/compiler 1.0.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/README.md +313 -0
- package/dist/__tests__/domain.test.d.ts +2 -0
- package/dist/__tests__/domain.test.d.ts.map +1 -0
- package/dist/__tests__/domain.test.js +56 -0
- package/dist/__tests__/domain.test.js.map +1 -0
- package/dist/__tests__/effects.test.d.ts +2 -0
- package/dist/__tests__/effects.test.d.ts.map +1 -0
- package/dist/__tests__/effects.test.js +145 -0
- package/dist/__tests__/effects.test.js.map +1 -0
- package/dist/__tests__/helpers/mock-adapter.d.ts +47 -0
- package/dist/__tests__/helpers/mock-adapter.d.ts.map +1 -0
- package/dist/__tests__/helpers/mock-adapter.js +135 -0
- package/dist/__tests__/helpers/mock-adapter.js.map +1 -0
- package/dist/__tests__/integration.test.d.ts +2 -0
- package/dist/__tests__/integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration.test.js +220 -0
- package/dist/__tests__/integration.test.js.map +1 -0
- package/dist/__tests__/parser.test.d.ts +2 -0
- package/dist/__tests__/parser.test.d.ts.map +1 -0
- package/dist/__tests__/parser.test.js +118 -0
- package/dist/__tests__/parser.test.js.map +1 -0
- package/dist/__tests__/telemetry.test.d.ts +2 -0
- package/dist/__tests__/telemetry.test.d.ts.map +1 -0
- package/dist/__tests__/telemetry.test.js +207 -0
- package/dist/__tests__/telemetry.test.js.map +1 -0
- package/dist/api/compiler.d.ts +86 -0
- package/dist/api/compiler.d.ts.map +1 -0
- package/dist/api/compiler.js +302 -0
- package/dist/api/compiler.js.map +1 -0
- package/dist/api/factory.d.ts +27 -0
- package/dist/api/factory.d.ts.map +1 -0
- package/dist/api/factory.js +60 -0
- package/dist/api/factory.js.map +1 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +3 -0
- package/dist/api/index.js.map +1 -0
- package/dist/cli/App.d.ts +10 -0
- package/dist/cli/App.d.ts.map +1 -0
- package/dist/cli/App.js +75 -0
- package/dist/cli/App.js.map +1 -0
- package/dist/cli/components/Error.d.ts +10 -0
- package/dist/cli/components/Error.d.ts.map +1 -0
- package/dist/cli/components/Error.js +21 -0
- package/dist/cli/components/Error.js.map +1 -0
- package/dist/cli/components/Header.d.ts +10 -0
- package/dist/cli/components/Header.d.ts.map +1 -0
- package/dist/cli/components/Header.js +11 -0
- package/dist/cli/components/Header.js.map +1 -0
- package/dist/cli/components/Metrics.d.ts +10 -0
- package/dist/cli/components/Metrics.d.ts.map +1 -0
- package/dist/cli/components/Metrics.js +29 -0
- package/dist/cli/components/Metrics.js.map +1 -0
- package/dist/cli/components/Progress.d.ts +10 -0
- package/dist/cli/components/Progress.d.ts.map +1 -0
- package/dist/cli/components/Progress.js +37 -0
- package/dist/cli/components/Progress.js.map +1 -0
- package/dist/cli/components/Resolution.d.ts +11 -0
- package/dist/cli/components/Resolution.d.ts.map +1 -0
- package/dist/cli/components/Resolution.js +26 -0
- package/dist/cli/components/Resolution.js.map +1 -0
- package/dist/cli/components/Result.d.ts +10 -0
- package/dist/cli/components/Result.d.ts.map +1 -0
- package/dist/cli/components/Result.js +38 -0
- package/dist/cli/components/Result.js.map +1 -0
- package/dist/cli/components/StatusBar.d.ts +10 -0
- package/dist/cli/components/StatusBar.d.ts.map +1 -0
- package/dist/cli/components/StatusBar.js +21 -0
- package/dist/cli/components/StatusBar.js.map +1 -0
- package/dist/cli/hooks/useCompiler.d.ts +22 -0
- package/dist/cli/hooks/useCompiler.d.ts.map +1 -0
- package/dist/cli/hooks/useCompiler.js +214 -0
- package/dist/cli/hooks/useCompiler.js.map +1 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +178 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/types.d.ts +96 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +26 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/domain/domain.d.ts +76 -0
- package/dist/domain/domain.d.ts.map +1 -0
- package/dist/domain/domain.js +251 -0
- package/dist/domain/domain.js.map +1 -0
- package/dist/domain/index.d.ts +4 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +4 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/domain/schema.d.ts +198 -0
- package/dist/domain/schema.d.ts.map +1 -0
- package/dist/domain/schema.js +131 -0
- package/dist/domain/schema.js.map +1 -0
- package/dist/domain/types.d.ts +360 -0
- package/dist/domain/types.d.ts.map +1 -0
- package/dist/domain/types.js +2 -0
- package/dist/domain/types.js.map +1 -0
- package/dist/effects/builder/index.d.ts +2 -0
- package/dist/effects/builder/index.d.ts.map +1 -0
- package/dist/effects/builder/index.js +2 -0
- package/dist/effects/builder/index.js.map +1 -0
- package/dist/effects/builder/validate-handler.d.ts +27 -0
- package/dist/effects/builder/validate-handler.d.ts.map +1 -0
- package/dist/effects/builder/validate-handler.js +153 -0
- package/dist/effects/builder/validate-handler.js.map +1 -0
- package/dist/effects/index.d.ts +3 -0
- package/dist/effects/index.d.ts.map +1 -0
- package/dist/effects/index.js +5 -0
- package/dist/effects/index.js.map +1 -0
- package/dist/effects/llm/adapter.d.ts +123 -0
- package/dist/effects/llm/adapter.d.ts.map +1 -0
- package/dist/effects/llm/adapter.js +13 -0
- package/dist/effects/llm/adapter.js.map +1 -0
- package/dist/effects/llm/anthropic-adapter.d.ts +65 -0
- package/dist/effects/llm/anthropic-adapter.d.ts.map +1 -0
- package/dist/effects/llm/anthropic-adapter.js +178 -0
- package/dist/effects/llm/anthropic-adapter.js.map +1 -0
- package/dist/effects/llm/handlers.d.ts +44 -0
- package/dist/effects/llm/handlers.d.ts.map +1 -0
- package/dist/effects/llm/handlers.js +127 -0
- package/dist/effects/llm/handlers.js.map +1 -0
- package/dist/effects/llm/index.d.ts +7 -0
- package/dist/effects/llm/index.d.ts.map +1 -0
- package/dist/effects/llm/index.js +10 -0
- package/dist/effects/llm/index.js.map +1 -0
- package/dist/effects/llm/openai-adapter.d.ts +59 -0
- package/dist/effects/llm/openai-adapter.d.ts.map +1 -0
- package/dist/effects/llm/openai-adapter.js +206 -0
- package/dist/effects/llm/openai-adapter.js.map +1 -0
- package/dist/effects/llm/parser.d.ts +63 -0
- package/dist/effects/llm/parser.d.ts.map +1 -0
- package/dist/effects/llm/parser.js +177 -0
- package/dist/effects/llm/parser.js.map +1 -0
- package/dist/effects/llm/prompts/index.d.ts +4 -0
- package/dist/effects/llm/prompts/index.d.ts.map +1 -0
- package/dist/effects/llm/prompts/index.js +4 -0
- package/dist/effects/llm/prompts/index.js.map +1 -0
- package/dist/effects/llm/prompts/normalize.d.ts +19 -0
- package/dist/effects/llm/prompts/normalize.d.ts.map +1 -0
- package/dist/effects/llm/prompts/normalize.js +98 -0
- package/dist/effects/llm/prompts/normalize.js.map +1 -0
- package/dist/effects/llm/prompts/propose.d.ts +21 -0
- package/dist/effects/llm/prompts/propose.d.ts.map +1 -0
- package/dist/effects/llm/prompts/propose.js +326 -0
- package/dist/effects/llm/prompts/propose.js.map +1 -0
- package/dist/effects/llm/prompts/segment.d.ts +16 -0
- package/dist/effects/llm/prompts/segment.d.ts.map +1 -0
- package/dist/effects/llm/prompts/segment.js +57 -0
- package/dist/effects/llm/prompts/segment.js.map +1 -0
- package/dist/effects/types.d.ts +10 -0
- package/dist/effects/types.d.ts.map +1 -0
- package/dist/effects/types.js +2 -0
- package/dist/effects/types.js.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create normalization prompt
|
|
3
|
+
*
|
|
4
|
+
* @param segments - Text segments to normalize
|
|
5
|
+
* @param schema - Target schema (for context)
|
|
6
|
+
* @param context - Additional context
|
|
7
|
+
*/
|
|
8
|
+
export function createNormalizePrompt(segments, schema, context) {
|
|
9
|
+
const schemaDescription = schema ? describeSchema(schema) : "";
|
|
10
|
+
const contextSection = context ? formatContext(context) : "";
|
|
11
|
+
const systemPrompt = `You are a requirements normalization assistant for the Manifesto domain modeling system.
|
|
12
|
+
|
|
13
|
+
Your task is to convert requirement segments into structured intents that map to Manifesto domain concepts.
|
|
14
|
+
|
|
15
|
+
## Intent Kinds
|
|
16
|
+
|
|
17
|
+
- **state**: A field that stores data (e.g., "user name", "order items", "is active")
|
|
18
|
+
- **computed**: A value derived from state (e.g., "total price", "is valid", "user count")
|
|
19
|
+
- **action**: An operation that changes state (e.g., "create user", "add item", "complete order")
|
|
20
|
+
- **constraint**: A rule that must hold (e.g., "price must be positive", "name is required")
|
|
21
|
+
|
|
22
|
+
## Output Format
|
|
23
|
+
|
|
24
|
+
You MUST respond with valid JSON only. No markdown code blocks, no explanations.
|
|
25
|
+
|
|
26
|
+
{
|
|
27
|
+
"intents": [
|
|
28
|
+
{
|
|
29
|
+
"kind": "state" | "computed" | "action" | "constraint",
|
|
30
|
+
"description": "Clear description of the intent",
|
|
31
|
+
"confidence": 0.0-1.0
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
## Ambiguity Handling
|
|
37
|
+
|
|
38
|
+
If you encounter ambiguity that requires clarification, respond with:
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
"resolution_required": true,
|
|
42
|
+
"reason": "Description of the ambiguity",
|
|
43
|
+
"options": [
|
|
44
|
+
{ "id": "option1", "description": "First interpretation", "preview": "What this would mean" },
|
|
45
|
+
{ "id": "option2", "description": "Second interpretation", "preview": "What this would mean" }
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
## Confidence Guidelines
|
|
50
|
+
|
|
51
|
+
- 1.0: Unambiguous, directly stated requirement
|
|
52
|
+
- 0.8-0.9: Clear intent with minor inference
|
|
53
|
+
- 0.6-0.7: Reasonable interpretation with some ambiguity
|
|
54
|
+
- Below 0.6: Consider requesting resolution
|
|
55
|
+
|
|
56
|
+
${schemaDescription ? `## Target Schema Structure\n\n${schemaDescription}` : ""}
|
|
57
|
+
${contextSection}`;
|
|
58
|
+
const userPrompt = `Normalize these requirement segments into structured intents:
|
|
59
|
+
|
|
60
|
+
${segments.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
61
|
+
|
|
62
|
+
Respond with JSON only.`;
|
|
63
|
+
return { systemPrompt, userPrompt };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Format context for prompt
|
|
67
|
+
*/
|
|
68
|
+
function formatContext(context) {
|
|
69
|
+
const parts = [];
|
|
70
|
+
if (context.domainName) {
|
|
71
|
+
parts.push(`Domain: ${context.domainName}`);
|
|
72
|
+
}
|
|
73
|
+
if (context.existingActions?.length) {
|
|
74
|
+
parts.push(`Existing Actions: ${context.existingActions.join(", ")}`);
|
|
75
|
+
}
|
|
76
|
+
if (context.glossary && Object.keys(context.glossary).length > 0) {
|
|
77
|
+
parts.push("Glossary:");
|
|
78
|
+
for (const [term, definition] of Object.entries(context.glossary)) {
|
|
79
|
+
parts.push(` - ${term}: ${definition}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return parts.length > 0 ? `\n## Context\n\n${parts.join("\n")}` : "";
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Describe schema for prompt context
|
|
86
|
+
*/
|
|
87
|
+
function describeSchema(schema) {
|
|
88
|
+
if (!schema || typeof schema !== "object") {
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return `Target schema structure:\n\`\`\`json\n${JSON.stringify(schema, null, 2)}\n\`\`\``;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../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C,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACxB,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClE,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACvE,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,MAAe;IACrC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC;QACH,OAAO,yCAAyC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC;IAC5F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CompilerContext, NormalizedIntent, AttemptRecord } from "../../../domain/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Proposal prompt template
|
|
4
|
+
*
|
|
5
|
+
* Generates DomainDraft JSON from normalized intents.
|
|
6
|
+
*/
|
|
7
|
+
export interface ProposePromptResult {
|
|
8
|
+
systemPrompt: string;
|
|
9
|
+
userPrompt: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create proposal prompt
|
|
13
|
+
*
|
|
14
|
+
* @param schema - Target schema structure
|
|
15
|
+
* @param intents - Normalized intents to implement
|
|
16
|
+
* @param history - Previous failed attempts
|
|
17
|
+
* @param context - Additional context
|
|
18
|
+
* @param resolution - Resolution selection (if any)
|
|
19
|
+
*/
|
|
20
|
+
export declare function createProposePrompt(schema: unknown, intents: NormalizedIntent[], history: AttemptRecord[], context?: CompilerContext, resolution?: string): ProposePromptResult;
|
|
21
|
+
//# sourceMappingURL=propose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propose.d.ts","sourceRoot":"","sources":["../../../../src/effects/llm/prompts/propose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EAEd,MAAM,0BAA0B,CAAC;AAElC;;;;GAIG;AAEH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,gBAAgB,EAAE,EAC3B,OAAO,EAAE,aAAa,EAAE,EACxB,OAAO,CAAC,EAAE,eAAe,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,mBAAmB,CAwLrB"}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create proposal prompt
|
|
3
|
+
*
|
|
4
|
+
* @param schema - Target schema structure
|
|
5
|
+
* @param intents - Normalized intents to implement
|
|
6
|
+
* @param history - Previous failed attempts
|
|
7
|
+
* @param context - Additional context
|
|
8
|
+
* @param resolution - Resolution selection (if any)
|
|
9
|
+
*/
|
|
10
|
+
export function createProposePrompt(schema, intents, history, context, resolution) {
|
|
11
|
+
const historySection = formatAttemptHistory(history);
|
|
12
|
+
const resolutionSection = resolution
|
|
13
|
+
? `\n## Resolution Applied\n\nThe user selected: "${resolution}"\nApply this decision in your proposal.\n`
|
|
14
|
+
: "";
|
|
15
|
+
const systemPrompt = `You are a DomainSchema proposal assistant for the Manifesto domain modeling system.
|
|
16
|
+
|
|
17
|
+
## YOUR ROLE: UNTRUSTED PROPOSER
|
|
18
|
+
|
|
19
|
+
CRITICAL: You are an UNTRUSTED PROPOSER, not a decision-maker.
|
|
20
|
+
|
|
21
|
+
- Your output will NEVER be executed directly
|
|
22
|
+
- The Builder (constitutional validator) will judge your proposals
|
|
23
|
+
- When multiple valid interpretations exist, you MUST request resolution
|
|
24
|
+
- Making an arbitrary choice when uncertain is FAILURE
|
|
25
|
+
- Requesting clarification is SUCCESS
|
|
26
|
+
|
|
27
|
+
DO NOT:
|
|
28
|
+
- Guess when uncertain about structural design
|
|
29
|
+
- Make "reasonable assumptions" about ambiguous requirements
|
|
30
|
+
- Choose "the most common approach" when alternatives are equally valid
|
|
31
|
+
- Fill in gaps with conventions or best practices
|
|
32
|
+
|
|
33
|
+
DO:
|
|
34
|
+
- Identify structural ambiguities explicitly
|
|
35
|
+
- Request resolution when confidence is low or multiple valid designs exist
|
|
36
|
+
- Provide multiple valid options for humans/AI to choose from
|
|
37
|
+
|
|
38
|
+
## RESPONSE FORMAT (CHOOSE ONE)
|
|
39
|
+
|
|
40
|
+
You MUST respond with exactly ONE of these JSON formats:
|
|
41
|
+
|
|
42
|
+
### Format A: Draft Proposal (when confident)
|
|
43
|
+
{
|
|
44
|
+
"draft": { ...DomainSchema... }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
### Format B: Resolution Request (when uncertain)
|
|
48
|
+
{
|
|
49
|
+
"resolution_required": true,
|
|
50
|
+
"reason": "Clear explanation of the ambiguity",
|
|
51
|
+
"options": [
|
|
52
|
+
{"id": "option-1", "description": "First interpretation", "preview": "How this would be modeled"},
|
|
53
|
+
{"id": "option-2", "description": "Second interpretation", "preview": "How this would be modeled"}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
IMPORTANT: Do NOT mix these formats. Do NOT include "draft" when requesting resolution.
|
|
58
|
+
|
|
59
|
+
## WHEN TO REQUEST RESOLUTION
|
|
60
|
+
|
|
61
|
+
Request resolution if ANY of these conditions apply:
|
|
62
|
+
|
|
63
|
+
1. **Low Confidence Intent**: Any intent with confidence < 0.7
|
|
64
|
+
2. **Conflicting Intents**: Two intents that could contradict each other
|
|
65
|
+
3. **Structural Ambiguity**: Multiple valid ways to model the same requirement
|
|
66
|
+
4. **Rule Location Uncertainty**: Unclear if rule belongs in state/computed/action/available
|
|
67
|
+
5. **Authority Ambiguity**: Unclear who can perform an action or under what conditions
|
|
68
|
+
6. **Temporal Logic**: Time-based rules with unclear trigger mechanism (effect vs computed vs scheduler)
|
|
69
|
+
7. **State Machine Complexity**: Multiple valid state transition designs
|
|
70
|
+
|
|
71
|
+
### Examples of Structural Ambiguity
|
|
72
|
+
|
|
73
|
+
Example 1 - State vs Computed:
|
|
74
|
+
Intent: "Show whether user can submit form"
|
|
75
|
+
- Option A: Computed value derived from validation state
|
|
76
|
+
- Option B: Explicit state field updated by actions
|
|
77
|
+
→ REQUEST RESOLUTION
|
|
78
|
+
|
|
79
|
+
Example 2 - Rule Location:
|
|
80
|
+
Intent: "Active accounts cannot be deactivated"
|
|
81
|
+
- Option A: Constraint in action's "available" guard
|
|
82
|
+
- Option B: Conditional check in action's flow
|
|
83
|
+
- Option C: Computed value that actions reference
|
|
84
|
+
→ REQUEST RESOLUTION
|
|
85
|
+
|
|
86
|
+
Example 3 - Authority:
|
|
87
|
+
Intent: "Admin can bypass email verification"
|
|
88
|
+
- Option A: Separate admin action with different flow
|
|
89
|
+
- Option B: Same action with role-based conditional in flow
|
|
90
|
+
- Option C: Boolean flag in action input
|
|
91
|
+
→ REQUEST RESOLUTION
|
|
92
|
+
|
|
93
|
+
Example 4 - Temporal:
|
|
94
|
+
Intent: "Verification link expires after 24 hours"
|
|
95
|
+
- Option A: Effect that schedules expiration event
|
|
96
|
+
- Option B: Computed value checking timestamp difference
|
|
97
|
+
- Option C: Action triggered by external scheduler
|
|
98
|
+
→ REQUEST RESOLUTION
|
|
99
|
+
|
|
100
|
+
## TECHNICAL RULES
|
|
101
|
+
|
|
102
|
+
1. Output MUST be valid JSON
|
|
103
|
+
2. Do NOT output TypeScript code - output JSON data only
|
|
104
|
+
3. All expressions use the ExprNode format (e.g., {"kind": "get", "path": "state.fieldName"})
|
|
105
|
+
4. All flows use the FlowNode format (e.g., {"kind": "patch", "op": "set", "path": "state.x", "value": {...}})
|
|
106
|
+
5. Paths must use dot notation: "state.fieldName", "computed.derivedValue"
|
|
107
|
+
|
|
108
|
+
## DomainSchema Structure
|
|
109
|
+
|
|
110
|
+
${getDomainSchemaStructure()}
|
|
111
|
+
|
|
112
|
+
## ExprNode Examples
|
|
113
|
+
|
|
114
|
+
Literal value:
|
|
115
|
+
{"kind": "lit", "value": 42}
|
|
116
|
+
|
|
117
|
+
Get state field:
|
|
118
|
+
{"kind": "get", "path": "state.userName"}
|
|
119
|
+
|
|
120
|
+
Comparison:
|
|
121
|
+
{"kind": "eq", "left": {"kind": "get", "path": "state.status"}, "right": {"kind": "lit", "value": "active"}}
|
|
122
|
+
|
|
123
|
+
Logical AND:
|
|
124
|
+
{"kind": "and", "args": [{"kind": "get", "path": "computed.isValid"}, {"kind": "get", "path": "computed.hasPermission"}]}
|
|
125
|
+
|
|
126
|
+
## FlowNode Examples
|
|
127
|
+
|
|
128
|
+
Set a field:
|
|
129
|
+
{"kind": "patch", "op": "set", "path": "state.name", "value": {"kind": "get", "path": "input.name"}}
|
|
130
|
+
|
|
131
|
+
Conditional:
|
|
132
|
+
{"kind": "if", "cond": {...}, "then": {...}, "else": {...}}
|
|
133
|
+
|
|
134
|
+
Sequence:
|
|
135
|
+
{"kind": "seq", "steps": [{...}, {...}]}
|
|
136
|
+
|
|
137
|
+
Effect (external operation):
|
|
138
|
+
{"kind": "effect", "type": "http:fetch", "params": {"url": {"kind": "lit", "value": "https://api.example.com"}}}
|
|
139
|
+
|
|
140
|
+
## Output Format
|
|
141
|
+
|
|
142
|
+
{
|
|
143
|
+
"draft": {
|
|
144
|
+
"id": "domain-unique-id",
|
|
145
|
+
"version": "1.0.0",
|
|
146
|
+
"hash": "",
|
|
147
|
+
"state": {
|
|
148
|
+
"fields": {
|
|
149
|
+
"fieldName": {
|
|
150
|
+
"type": "string",
|
|
151
|
+
"required": true,
|
|
152
|
+
"description": "..."
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
"computed": {
|
|
157
|
+
"fields": {
|
|
158
|
+
"computed.derivedValue": {
|
|
159
|
+
"deps": ["state.fieldName"],
|
|
160
|
+
"expr": {"kind": "get", "path": "state.fieldName"},
|
|
161
|
+
"description": "..."
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"actions": {
|
|
166
|
+
"actionName": {
|
|
167
|
+
"flow": {"kind": "seq", "steps": [...]},
|
|
168
|
+
"input": {...},
|
|
169
|
+
"available": {...},
|
|
170
|
+
"description": "..."
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
${historySection}
|
|
177
|
+
${resolutionSection}`;
|
|
178
|
+
const userPrompt = `Generate a DomainSchema draft from these intents:
|
|
179
|
+
|
|
180
|
+
${intents
|
|
181
|
+
.map((intent, i) => `${i + 1}. [${intent.kind}] ${intent.description} (confidence: ${intent.confidence})`)
|
|
182
|
+
.join("\n")}
|
|
183
|
+
|
|
184
|
+
${context?.domainName ? `Domain Name: ${context.domainName}` : ""}
|
|
185
|
+
|
|
186
|
+
Respond with JSON only. Use Format A (draft) if confident, or Format B (resolution_required) if uncertain.`;
|
|
187
|
+
return { systemPrompt, userPrompt };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get DomainSchema structure documentation
|
|
191
|
+
*/
|
|
192
|
+
function getDomainSchemaStructure() {
|
|
193
|
+
return `The DomainSchema must conform to this structure:
|
|
194
|
+
|
|
195
|
+
{
|
|
196
|
+
"id": "string (unique identifier, URI or UUID)",
|
|
197
|
+
"version": "string (semantic version, e.g., '1.0.0')",
|
|
198
|
+
"hash": "string (leave empty, will be computed)",
|
|
199
|
+
"state": {
|
|
200
|
+
"fields": {
|
|
201
|
+
"<fieldName>": {
|
|
202
|
+
"type": "string | number | boolean | null | object | array | { enum: [...] }",
|
|
203
|
+
"required": "boolean",
|
|
204
|
+
"default": "any (optional)",
|
|
205
|
+
"description": "string (optional)",
|
|
206
|
+
"fields": "Record<string, FieldSpec> (for object type)",
|
|
207
|
+
"items": "FieldSpec (for array type)"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
"computed": {
|
|
212
|
+
"fields": {
|
|
213
|
+
"computed.<name>": {
|
|
214
|
+
"deps": ["state.field1", "state.field2", ...],
|
|
215
|
+
"expr": "ExprNode",
|
|
216
|
+
"description": "string (optional)"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
"actions": {
|
|
221
|
+
"<actionName>": {
|
|
222
|
+
"flow": "FlowNode",
|
|
223
|
+
"input": "FieldSpec (optional)",
|
|
224
|
+
"available": "ExprNode (optional, must return boolean)",
|
|
225
|
+
"description": "string (optional)"
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
"meta": {
|
|
229
|
+
"name": "string (optional)",
|
|
230
|
+
"description": "string (optional)",
|
|
231
|
+
"authors": ["string"] (optional)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
## Type Reference
|
|
236
|
+
|
|
237
|
+
### FieldSpec types
|
|
238
|
+
- "string": Text value
|
|
239
|
+
- "number": Numeric value
|
|
240
|
+
- "boolean": true/false
|
|
241
|
+
- "null": Null value
|
|
242
|
+
- "object": Nested object (requires "fields")
|
|
243
|
+
- "array": Array (requires "items")
|
|
244
|
+
- {"enum": ["value1", "value2"]}: Enumerated values
|
|
245
|
+
|
|
246
|
+
### ExprNode kinds
|
|
247
|
+
- lit: Literal value {"kind": "lit", "value": <any>}
|
|
248
|
+
- get: Get value {"kind": "get", "path": "<semantic.path>"}
|
|
249
|
+
- eq/neq/gt/gte/lt/lte: Comparisons
|
|
250
|
+
- and/or/not: Logical operators
|
|
251
|
+
- add/sub/mul/div/mod: Arithmetic
|
|
252
|
+
- concat/substring: String operations
|
|
253
|
+
- len/at/first/last/slice/includes/filter/map/find/every/some: Array operations
|
|
254
|
+
- keys/values/entries/merge: Object operations
|
|
255
|
+
- typeof/isNull/coalesce: Type operations
|
|
256
|
+
- if: Conditional {"kind": "if", "cond": <expr>, "then": <expr>, "else": <expr>}
|
|
257
|
+
|
|
258
|
+
### FlowNode kinds
|
|
259
|
+
- seq: Sequence {"kind": "seq", "steps": [<flow>, ...]}
|
|
260
|
+
- if: Conditional {"kind": "if", "cond": <expr>, "then": <flow>, "else": <flow>?}
|
|
261
|
+
- patch: State mutation {"kind": "patch", "op": "set|unset|merge", "path": "<path>", "value": <expr>?}
|
|
262
|
+
- effect: External operation {"kind": "effect", "type": "<type>", "params": {<key>: <expr>}}
|
|
263
|
+
- call: Call flow {"kind": "call", "flow": "<flowName>"}
|
|
264
|
+
- halt: Stop normally {"kind": "halt", "reason": "<string>?"}
|
|
265
|
+
- fail: Stop with error {"kind": "fail", "code": "<code>", "message": <expr>?}`;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Format attempt history for retry prompts
|
|
269
|
+
*/
|
|
270
|
+
function formatAttemptHistory(history) {
|
|
271
|
+
if (history.length === 0) {
|
|
272
|
+
return "";
|
|
273
|
+
}
|
|
274
|
+
const formatted = history
|
|
275
|
+
.map((attempt) => {
|
|
276
|
+
const diagnosticsText = attempt.diagnostics
|
|
277
|
+
? formatDiagnosticsForPrompt(attempt.diagnostics)
|
|
278
|
+
: "No diagnostics available";
|
|
279
|
+
return `### Attempt ${attempt.attemptNumber + 1}
|
|
280
|
+
Hash: ${attempt.draftHash}
|
|
281
|
+
${diagnosticsText}`;
|
|
282
|
+
})
|
|
283
|
+
.join("\n\n");
|
|
284
|
+
return `
|
|
285
|
+
## Previous Failed Attempts
|
|
286
|
+
|
|
287
|
+
IMPORTANT: Review these failed attempts and their diagnostics carefully.
|
|
288
|
+
Do NOT repeat the same mistakes. Address each error mentioned.
|
|
289
|
+
|
|
290
|
+
${formatted}
|
|
291
|
+
`;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Format diagnostics for inclusion in prompts
|
|
295
|
+
*/
|
|
296
|
+
function formatDiagnosticsForPrompt(diagnostics) {
|
|
297
|
+
const sections = [];
|
|
298
|
+
if (diagnostics.errors.length > 0) {
|
|
299
|
+
sections.push("**ERRORS (must fix):**");
|
|
300
|
+
sections.push(diagnostics.errors
|
|
301
|
+
.map((d) => {
|
|
302
|
+
const parts = [`- [${d.code}] ${d.message}`];
|
|
303
|
+
if (d.path)
|
|
304
|
+
parts.push(` Location: ${d.path}`);
|
|
305
|
+
if (d.suggestion)
|
|
306
|
+
parts.push(` Suggestion: ${d.suggestion}`);
|
|
307
|
+
return parts.join("\n");
|
|
308
|
+
})
|
|
309
|
+
.join("\n"));
|
|
310
|
+
}
|
|
311
|
+
if (diagnostics.warnings.length > 0) {
|
|
312
|
+
sections.push("**WARNINGS (should fix):**");
|
|
313
|
+
sections.push(diagnostics.warnings
|
|
314
|
+
.map((d) => {
|
|
315
|
+
const parts = [`- [${d.code}] ${d.message}`];
|
|
316
|
+
if (d.path)
|
|
317
|
+
parts.push(` Location: ${d.path}`);
|
|
318
|
+
if (d.suggestion)
|
|
319
|
+
parts.push(` Suggestion: ${d.suggestion}`);
|
|
320
|
+
return parts.join("\n");
|
|
321
|
+
})
|
|
322
|
+
.join("\n"));
|
|
323
|
+
}
|
|
324
|
+
return sections.length > 0 ? sections.join("\n\n") : "No specific diagnostics available.";
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=propose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propose.js","sourceRoot":"","sources":["../../../../src/effects/llm/prompts/propose.ts"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAe,EACf,OAA2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X,WAAW,CAAC,QAAQ;aACjB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7C,IAAI,CAAC,CAAC,IAAI;gBAAE,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YAChD,IAAI,CAAC,CAAC,UAAU;gBAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;YAC9D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CACd,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,oCAAoC,CAAC;AAC5F,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Segmentation prompt template
|
|
3
|
+
*
|
|
4
|
+
* Segments natural language requirements into atomic requirement statements.
|
|
5
|
+
*/
|
|
6
|
+
export interface SegmentPromptResult {
|
|
7
|
+
systemPrompt: string;
|
|
8
|
+
userPrompt: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create segmentation prompt
|
|
12
|
+
*
|
|
13
|
+
* @param text - Natural language text to segment
|
|
14
|
+
*/
|
|
15
|
+
export declare function createSegmentPrompt(text: string): SegmentPromptResult;
|
|
16
|
+
//# sourceMappingURL=segment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segment.d.ts","sourceRoot":"","sources":["../../../../src/effects/llm/prompts/segment.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CA+CrE"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Segmentation prompt template
|
|
3
|
+
*
|
|
4
|
+
* Segments natural language requirements into atomic requirement statements.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Create segmentation prompt
|
|
8
|
+
*
|
|
9
|
+
* @param text - Natural language text to segment
|
|
10
|
+
*/
|
|
11
|
+
export function createSegmentPrompt(text) {
|
|
12
|
+
const systemPrompt = `You are a requirements segmentation assistant for the Manifesto domain modeling system.
|
|
13
|
+
|
|
14
|
+
Your task is to decompose natural language requirements into discrete, atomic requirement segments.
|
|
15
|
+
|
|
16
|
+
## Rules
|
|
17
|
+
|
|
18
|
+
1. Each segment should describe ONE requirement (state field, computed value, action, or constraint)
|
|
19
|
+
2. Preserve the original meaning - do not infer or add requirements
|
|
20
|
+
3. Split compound sentences into separate segments
|
|
21
|
+
4. Remove filler words and normalize language
|
|
22
|
+
5. Keep technical terms and domain-specific vocabulary intact
|
|
23
|
+
|
|
24
|
+
## Output Format
|
|
25
|
+
|
|
26
|
+
You MUST respond with valid JSON only. No markdown code blocks, no explanations.
|
|
27
|
+
|
|
28
|
+
{
|
|
29
|
+
"segments": [
|
|
30
|
+
"First requirement segment",
|
|
31
|
+
"Second requirement segment"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
Input: "The system should track user names and emails. When a user registers, send a welcome email. The total user count should be displayed."
|
|
38
|
+
|
|
39
|
+
Output:
|
|
40
|
+
{
|
|
41
|
+
"segments": [
|
|
42
|
+
"Track user name as a string field",
|
|
43
|
+
"Track user email as a string field",
|
|
44
|
+
"When user registers, send welcome email",
|
|
45
|
+
"Display total user count as computed value"
|
|
46
|
+
]
|
|
47
|
+
}`;
|
|
48
|
+
const userPrompt = `Segment the following requirements into atomic segments:
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
${text}
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
Respond with JSON only.`;
|
|
55
|
+
return { systemPrompt, userPrompt };
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=segment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segment.js","sourceRoot":"","sources":["../../../../src/effects/llm/prompts/segment.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmCrB,CAAC;IAED,MAAM,UAAU,GAAG;;;EAGnB,IAAI;;;wBAGkB,CAAC;IAEvB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EffectHandlerResult } from "./llm/handlers.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generic effect handler type
|
|
4
|
+
*/
|
|
5
|
+
export type EffectHandler = (params: Record<string, unknown>) => Promise<EffectHandlerResult>;
|
|
6
|
+
/**
|
|
7
|
+
* Effect handler registry
|
|
8
|
+
*/
|
|
9
|
+
export type EffectHandlerRegistry = Record<string, EffectHandler>;
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/effects/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAE9F;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/effects/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @manifesto-ai/compiler
|
|
3
|
+
*
|
|
4
|
+
* Natural language to Manifesto DomainSchema compiler.
|
|
5
|
+
*
|
|
6
|
+
* Implemented as a Manifesto Application (dogfooding per FDR-C001).
|
|
7
|
+
*
|
|
8
|
+
* @example Using Anthropic (built-in)
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createCompiler } from '@manifesto-ai/compiler';
|
|
11
|
+
*
|
|
12
|
+
* const compiler = createCompiler({
|
|
13
|
+
* anthropic: { apiKey: process.env.ANTHROPIC_API_KEY },
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* compiler.subscribe((state) => {
|
|
17
|
+
* if (state.status === 'success') {
|
|
18
|
+
* console.log('Compiled schema:', state.result);
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* await compiler.start({
|
|
23
|
+
* text: 'Track user name and email. Allow users to update their profile.',
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example Using custom LLM adapter (e.g., OpenAI)
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { createCompiler, type LLMAdapter } from '@manifesto-ai/compiler';
|
|
30
|
+
* import OpenAI from 'openai';
|
|
31
|
+
*
|
|
32
|
+
* // Implement your own adapter
|
|
33
|
+
* const openaiAdapter: LLMAdapter = {
|
|
34
|
+
* async segment({ text }) {
|
|
35
|
+
* const openai = new OpenAI();
|
|
36
|
+
* const response = await openai.chat.completions.create({ ... });
|
|
37
|
+
* return { ok: true, data: { segments: [...] } };
|
|
38
|
+
* },
|
|
39
|
+
* async normalize({ segments, schema, context }) {
|
|
40
|
+
* // ...
|
|
41
|
+
* },
|
|
42
|
+
* async propose({ schema, intents, history, context, resolution }) {
|
|
43
|
+
* // ...
|
|
44
|
+
* },
|
|
45
|
+
* };
|
|
46
|
+
*
|
|
47
|
+
* const compiler = createCompiler({
|
|
48
|
+
* llmAdapter: openaiAdapter, // Inject custom adapter
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export { createCompiler } from "./api/factory.js";
|
|
53
|
+
export { ManifestoCompiler } from "./api/compiler.js";
|
|
54
|
+
export type { Compiler, CompilerOptions, CompilerSnapshot, CompilerState, CompileInput, CompilerStatus, Unsubscribe, CompilerResolutionPolicy, ResolutionOption, DiscardReason, CompilerContext, NormalizedIntent, AttemptRecord, CompilerDiagnostics, CompilerDiagnostic, CompilerTelemetry, LLMAdapter, LLMResult, SegmentResult, NormalizeResult, ProposeResult, } from "./domain/types.js";
|
|
55
|
+
export { CompilerDomain, INITIAL_STATE } from "./domain/domain.js";
|
|
56
|
+
export { CompilerStateSchema } from "./domain/schema.js";
|
|
57
|
+
export { createAnthropicAdapter, AnthropicAdapter, type AnthropicAdapterOptions, } from "./effects/llm/anthropic-adapter.js";
|
|
58
|
+
export { createOpenAIAdapter, OpenAIAdapter, type OpenAIAdapterOptions, } from "./effects/llm/openai-adapter.js";
|
|
59
|
+
export { DEFAULT_LLM_CONFIG, type LLMAdapterConfig } from "./effects/llm/adapter.js";
|
|
60
|
+
export { createLLMEffectHandlers, createSegmentHandler, createNormalizeHandler, createProposeHandler, type LLMEffectHandler, type EffectHandlerResult, } from "./effects/llm/handlers.js";
|
|
61
|
+
export { createBuilderValidateHandler, type BuilderValidateHandler, type ValidateResult, } from "./effects/builder/validate-handler.js";
|
|
62
|
+
export { createSegmentPrompt, createNormalizePrompt, createProposePrompt, } from "./effects/llm/prompts/index.js";
|
|
63
|
+
export { parseJSONResponse, extractResolutionRequest, validateSegmentsResponse, validateIntentsResponse, validateDraftResponse, type ParseResult, type ResolutionRequest, } from "./effects/llm/parser.js";
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAMH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAMtD,YAAY,EAEV,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EAGX,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EAGb,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAGlB,iBAAiB,EAGjB,UAAU,EACV,SAAS,EACT,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAMzD,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,KAAK,oBAAoB,GAC1B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAMrF,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACzB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,4BAA4B,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,c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