@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,123 @@
|
|
|
1
|
+
import type { CompilerContext, NormalizedIntent, AttemptRecord, ResolutionOption } from "../../domain/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* LLM Result types - tri-state result for LLM operations
|
|
4
|
+
*
|
|
5
|
+
* Per FDR-C002: LLM is an untrusted proposer.
|
|
6
|
+
* These results represent what the LLM returned, not validated output.
|
|
7
|
+
*/
|
|
8
|
+
export type LLMResult<T> = {
|
|
9
|
+
ok: true;
|
|
10
|
+
data: T;
|
|
11
|
+
} | {
|
|
12
|
+
ok: "resolution";
|
|
13
|
+
reason: string;
|
|
14
|
+
options: ResolutionOption[];
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
error: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Segment result
|
|
21
|
+
*/
|
|
22
|
+
export type SegmentResult = LLMResult<{
|
|
23
|
+
segments: string[];
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Normalize result
|
|
27
|
+
*/
|
|
28
|
+
export type NormalizeResult = LLMResult<{
|
|
29
|
+
intents: NormalizedIntent[];
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Propose result
|
|
33
|
+
*/
|
|
34
|
+
export type ProposeResult = LLMResult<{
|
|
35
|
+
draft: unknown;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* LLM Adapter interface - abstracts over different LLM providers
|
|
39
|
+
*
|
|
40
|
+
* Per SPEC.md §6: Effect handler contracts define the interface between
|
|
41
|
+
* Compiler and LLM. This adapter interface mirrors those contracts.
|
|
42
|
+
*/
|
|
43
|
+
export interface LLMAdapter {
|
|
44
|
+
/**
|
|
45
|
+
* Segment natural language text into requirement segments
|
|
46
|
+
*
|
|
47
|
+
* @param params.text - Input text to segment
|
|
48
|
+
* @returns Segmented text or error
|
|
49
|
+
*/
|
|
50
|
+
segment(params: {
|
|
51
|
+
text: string;
|
|
52
|
+
}): Promise<SegmentResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Normalize segments into structured intents
|
|
55
|
+
*
|
|
56
|
+
* @param params.segments - Text segments to normalize
|
|
57
|
+
* @param params.schema - Target schema (for context)
|
|
58
|
+
* @param params.context - Additional context
|
|
59
|
+
* @returns Normalized intents, resolution request, or error
|
|
60
|
+
*/
|
|
61
|
+
normalize(params: {
|
|
62
|
+
segments: string[];
|
|
63
|
+
schema: unknown;
|
|
64
|
+
context?: CompilerContext;
|
|
65
|
+
}): Promise<NormalizeResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Propose a DomainDraft from intents
|
|
68
|
+
*
|
|
69
|
+
* Per FDR-C002: Output is a proposal, not a validated schema.
|
|
70
|
+
*
|
|
71
|
+
* @param params.schema - Target schema structure
|
|
72
|
+
* @param params.intents - Normalized intents to implement
|
|
73
|
+
* @param params.history - Previous failed attempts (for retry feedback)
|
|
74
|
+
* @param params.context - Additional context
|
|
75
|
+
* @param params.resolution - Resolution selection (if resuming from resolution)
|
|
76
|
+
* @returns Draft proposal, resolution request, or error
|
|
77
|
+
*/
|
|
78
|
+
propose(params: {
|
|
79
|
+
schema: unknown;
|
|
80
|
+
intents: NormalizedIntent[];
|
|
81
|
+
history: AttemptRecord[];
|
|
82
|
+
context?: CompilerContext;
|
|
83
|
+
resolution?: string;
|
|
84
|
+
}): Promise<ProposeResult>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* LLM Adapter configuration
|
|
88
|
+
*/
|
|
89
|
+
export interface LLMAdapterConfig {
|
|
90
|
+
/**
|
|
91
|
+
* Model identifier
|
|
92
|
+
* @example 'claude-sonnet-4-20250514'
|
|
93
|
+
*/
|
|
94
|
+
model: string;
|
|
95
|
+
/**
|
|
96
|
+
* Maximum tokens for generation
|
|
97
|
+
* @default 4096
|
|
98
|
+
*/
|
|
99
|
+
maxTokens?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Temperature for generation (0.0 - 1.0)
|
|
102
|
+
* Lower = more deterministic for structured output
|
|
103
|
+
* @default 0.1
|
|
104
|
+
*/
|
|
105
|
+
temperature?: number;
|
|
106
|
+
/**
|
|
107
|
+
* API timeout in milliseconds
|
|
108
|
+
* @default 60000
|
|
109
|
+
*/
|
|
110
|
+
timeout?: number;
|
|
111
|
+
/**
|
|
112
|
+
* Custom system prompt prefix (optional)
|
|
113
|
+
* Prepended to all system prompts
|
|
114
|
+
*/
|
|
115
|
+
systemPromptPrefix?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Default LLM configuration
|
|
119
|
+
*
|
|
120
|
+
* Uses low temperature for structured JSON output consistency.
|
|
121
|
+
*/
|
|
122
|
+
export declare const DEFAULT_LLM_CONFIG: Required<LLMAdapterConfig>;
|
|
123
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/effects/llm/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IACnB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACrB;IAAE,EAAE,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,gBAAgB,EAAE,CAAA;CAAE,GACjE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC;IAAE,OAAO,EAAE,gBAAgB,EAAE,CAAA;CAAE,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAE1D;;;;;;;OAOG;IACH,SAAS,CAAC,MAAM,EAAE;QAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;QAChB,OAAO,CAAC,EAAE,eAAe,CAAC;KAC3B,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAE7B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,EAAE;QACd,MAAM,EAAE,OAAO,CAAC;QAChB,OAAO,EAAE,gBAAgB,EAAE,CAAC;QAC5B,OAAO,EAAE,aAAa,EAAE,CAAC;QACzB,OAAO,CAAC,EAAE,eAAe,CAAC;QAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,gBAAgB,CAMzD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default LLM configuration
|
|
3
|
+
*
|
|
4
|
+
* Uses low temperature for structured JSON output consistency.
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_LLM_CONFIG = {
|
|
7
|
+
model: "claude-sonnet-4-20250514",
|
|
8
|
+
maxTokens: 4096,
|
|
9
|
+
temperature: 0.1,
|
|
10
|
+
timeout: 60000,
|
|
11
|
+
systemPromptPrefix: "",
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/effects/llm/adapter.ts"],"names":[],"mappings":"AAuHA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA+B;IAC5D,KAAK,EAAE,0BAA0B;IACjC,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,GAAG;IAChB,OAAO,EAAE,KAAK;IACd,kBAAkB,EAAE,EAAE;CACvB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { LLMAdapter, LLMAdapterConfig, SegmentResult, NormalizeResult, ProposeResult } from "./adapter.js";
|
|
2
|
+
import type { CompilerContext, NormalizedIntent, AttemptRecord } from "../../domain/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Anthropic adapter options
|
|
5
|
+
*/
|
|
6
|
+
export interface AnthropicAdapterOptions extends Partial<LLMAdapterConfig> {
|
|
7
|
+
/**
|
|
8
|
+
* Anthropic API key
|
|
9
|
+
* Falls back to ANTHROPIC_API_KEY environment variable
|
|
10
|
+
*/
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Anthropic Claude adapter for LLM operations
|
|
15
|
+
*
|
|
16
|
+
* Per FDR-C011: LLM interactions are effect handlers, not direct calls.
|
|
17
|
+
* This adapter implements the LLMAdapter interface for use with effect handlers.
|
|
18
|
+
*/
|
|
19
|
+
export declare class AnthropicAdapter implements LLMAdapter {
|
|
20
|
+
private client;
|
|
21
|
+
private config;
|
|
22
|
+
constructor(options?: AnthropicAdapterOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Segment natural language text into requirement segments
|
|
25
|
+
*/
|
|
26
|
+
segment(params: {
|
|
27
|
+
text: string;
|
|
28
|
+
}): Promise<SegmentResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Normalize segments into structured intents
|
|
31
|
+
*/
|
|
32
|
+
normalize(params: {
|
|
33
|
+
segments: string[];
|
|
34
|
+
schema: unknown;
|
|
35
|
+
context?: CompilerContext;
|
|
36
|
+
}): Promise<NormalizeResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Propose a DomainDraft from intents
|
|
39
|
+
*
|
|
40
|
+
* Per FDR-C002: LLM output is an untrusted proposal.
|
|
41
|
+
*/
|
|
42
|
+
propose(params: {
|
|
43
|
+
schema: unknown;
|
|
44
|
+
intents: NormalizedIntent[];
|
|
45
|
+
history: AttemptRecord[];
|
|
46
|
+
context?: CompilerContext;
|
|
47
|
+
resolution?: string;
|
|
48
|
+
}): Promise<ProposeResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Extract text content from Anthropic response
|
|
51
|
+
*/
|
|
52
|
+
private extractTextContent;
|
|
53
|
+
/**
|
|
54
|
+
* Format error for consistent error messages
|
|
55
|
+
*/
|
|
56
|
+
private formatError;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create an Anthropic adapter with options
|
|
60
|
+
*
|
|
61
|
+
* @param options - Adapter configuration options
|
|
62
|
+
* @returns LLMAdapter instance
|
|
63
|
+
*/
|
|
64
|
+
export declare function createAnthropicAdapter(options?: AnthropicAdapterOptions): LLMAdapter;
|
|
65
|
+
//# sourceMappingURL=anthropic-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-adapter.d.ts","sourceRoot":"","sources":["../../../src/effects/llm/anthropic-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,aAAa,EACd,MAAM,cAAc,CAAC;AAUtB,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE9F;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IACxE;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MAAM,CAA6B;gBAE/B,OAAO,GAAE,uBAA4B;IAejD;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAwC/D;;OAEG;IACG,SAAS,CAAC,MAAM,EAAE;QACtB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;QAChB,OAAO,CAAC,EAAE,eAAe,CAAC;KAC3B,GAAG,OAAO,CAAC,eAAe,CAAC;IAmD5B;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE;QACpB,MAAM,EAAE,OAAO,CAAC;QAChB,OAAO,EAAE,gBAAgB,EAAE,CAAC;QAC5B,OAAO,EAAE,aAAa,EAAE,CAAC;QACzB,OAAO,CAAC,EAAE,eAAe,CAAC;QAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,aAAa,CAAC;IA8C1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;OAEG;IACH,OAAO,CAAC,WAAW;CASpB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,UAAU,CAEpF"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
+
import { DEFAULT_LLM_CONFIG } from "./adapter.js";
|
|
3
|
+
import { createSegmentPrompt, createNormalizePrompt, createProposePrompt } from "./prompts/index.js";
|
|
4
|
+
import { parseJSONResponse, extractResolutionRequest, validateSegmentsResponse, validateIntentsResponse, validateDraftResponse, } from "./parser.js";
|
|
5
|
+
/**
|
|
6
|
+
* Anthropic Claude adapter for LLM operations
|
|
7
|
+
*
|
|
8
|
+
* Per FDR-C011: LLM interactions are effect handlers, not direct calls.
|
|
9
|
+
* This adapter implements the LLMAdapter interface for use with effect handlers.
|
|
10
|
+
*/
|
|
11
|
+
export class AnthropicAdapter {
|
|
12
|
+
client;
|
|
13
|
+
config;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.client = new Anthropic({
|
|
16
|
+
apiKey: options.apiKey,
|
|
17
|
+
timeout: options.timeout ?? DEFAULT_LLM_CONFIG.timeout,
|
|
18
|
+
});
|
|
19
|
+
this.config = {
|
|
20
|
+
model: options.model ?? DEFAULT_LLM_CONFIG.model,
|
|
21
|
+
maxTokens: options.maxTokens ?? DEFAULT_LLM_CONFIG.maxTokens,
|
|
22
|
+
temperature: options.temperature ?? DEFAULT_LLM_CONFIG.temperature,
|
|
23
|
+
timeout: options.timeout ?? DEFAULT_LLM_CONFIG.timeout,
|
|
24
|
+
systemPromptPrefix: options.systemPromptPrefix ?? DEFAULT_LLM_CONFIG.systemPromptPrefix,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Segment natural language text into requirement segments
|
|
29
|
+
*/
|
|
30
|
+
async segment(params) {
|
|
31
|
+
try {
|
|
32
|
+
const { systemPrompt, userPrompt } = createSegmentPrompt(params.text);
|
|
33
|
+
const response = await this.client.messages.create({
|
|
34
|
+
model: this.config.model,
|
|
35
|
+
max_tokens: this.config.maxTokens,
|
|
36
|
+
temperature: this.config.temperature,
|
|
37
|
+
system: this.config.systemPromptPrefix + systemPrompt,
|
|
38
|
+
messages: [{ role: "user", content: userPrompt }],
|
|
39
|
+
});
|
|
40
|
+
const content = this.extractTextContent(response);
|
|
41
|
+
// Check for resolution request (unlikely for segmentation, but possible)
|
|
42
|
+
const resolution = extractResolutionRequest(content);
|
|
43
|
+
if (resolution) {
|
|
44
|
+
return {
|
|
45
|
+
ok: "resolution",
|
|
46
|
+
reason: resolution.reason,
|
|
47
|
+
options: resolution.options,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const parseResult = parseJSONResponse(content);
|
|
51
|
+
if (!parseResult.ok) {
|
|
52
|
+
return { ok: false, error: parseResult.error };
|
|
53
|
+
}
|
|
54
|
+
const validateResult = validateSegmentsResponse(parseResult.data);
|
|
55
|
+
if (!validateResult.ok) {
|
|
56
|
+
return { ok: false, error: validateResult.error };
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, data: { segments: validateResult.data.segments } };
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return { ok: false, error: this.formatError(error) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Normalize segments into structured intents
|
|
66
|
+
*/
|
|
67
|
+
async normalize(params) {
|
|
68
|
+
try {
|
|
69
|
+
const { systemPrompt, userPrompt } = createNormalizePrompt(params.segments, params.schema, params.context);
|
|
70
|
+
const response = await this.client.messages.create({
|
|
71
|
+
model: this.config.model,
|
|
72
|
+
max_tokens: this.config.maxTokens,
|
|
73
|
+
temperature: this.config.temperature,
|
|
74
|
+
system: this.config.systemPromptPrefix + systemPrompt,
|
|
75
|
+
messages: [{ role: "user", content: userPrompt }],
|
|
76
|
+
});
|
|
77
|
+
const content = this.extractTextContent(response);
|
|
78
|
+
// Check for resolution request
|
|
79
|
+
const resolution = extractResolutionRequest(content);
|
|
80
|
+
if (resolution) {
|
|
81
|
+
return {
|
|
82
|
+
ok: "resolution",
|
|
83
|
+
reason: resolution.reason,
|
|
84
|
+
options: resolution.options,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const parseResult = parseJSONResponse(content);
|
|
88
|
+
if (!parseResult.ok) {
|
|
89
|
+
return { ok: false, error: parseResult.error };
|
|
90
|
+
}
|
|
91
|
+
const validateResult = validateIntentsResponse(parseResult.data);
|
|
92
|
+
if (!validateResult.ok) {
|
|
93
|
+
return { ok: false, error: validateResult.error };
|
|
94
|
+
}
|
|
95
|
+
// Cast to NormalizedIntent
|
|
96
|
+
const intents = validateResult.data.intents.map((i) => ({
|
|
97
|
+
kind: i.kind,
|
|
98
|
+
description: i.description,
|
|
99
|
+
confidence: i.confidence,
|
|
100
|
+
}));
|
|
101
|
+
return { ok: true, data: { intents } };
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return { ok: false, error: this.formatError(error) };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Propose a DomainDraft from intents
|
|
109
|
+
*
|
|
110
|
+
* Per FDR-C002: LLM output is an untrusted proposal.
|
|
111
|
+
*/
|
|
112
|
+
async propose(params) {
|
|
113
|
+
try {
|
|
114
|
+
const { systemPrompt, userPrompt } = createProposePrompt(params.schema, params.intents, params.history, params.context, params.resolution);
|
|
115
|
+
const response = await this.client.messages.create({
|
|
116
|
+
model: this.config.model,
|
|
117
|
+
max_tokens: this.config.maxTokens,
|
|
118
|
+
temperature: this.config.temperature,
|
|
119
|
+
system: this.config.systemPromptPrefix + systemPrompt,
|
|
120
|
+
messages: [{ role: "user", content: userPrompt }],
|
|
121
|
+
});
|
|
122
|
+
const content = this.extractTextContent(response);
|
|
123
|
+
// Check for resolution request
|
|
124
|
+
const resolution = extractResolutionRequest(content);
|
|
125
|
+
if (resolution) {
|
|
126
|
+
return {
|
|
127
|
+
ok: "resolution",
|
|
128
|
+
reason: resolution.reason,
|
|
129
|
+
options: resolution.options,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const parseResult = parseJSONResponse(content);
|
|
133
|
+
if (!parseResult.ok) {
|
|
134
|
+
return { ok: false, error: parseResult.error };
|
|
135
|
+
}
|
|
136
|
+
const validateResult = validateDraftResponse(parseResult.data);
|
|
137
|
+
if (!validateResult.ok) {
|
|
138
|
+
return { ok: false, error: validateResult.error };
|
|
139
|
+
}
|
|
140
|
+
return { ok: true, data: { draft: validateResult.data.draft } };
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
return { ok: false, error: this.formatError(error) };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Extract text content from Anthropic response
|
|
148
|
+
*/
|
|
149
|
+
extractTextContent(response) {
|
|
150
|
+
const textBlock = response.content.find((block) => block.type === "text");
|
|
151
|
+
if (!textBlock || textBlock.type !== "text") {
|
|
152
|
+
throw new Error("No text content in response");
|
|
153
|
+
}
|
|
154
|
+
return textBlock.text;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Format error for consistent error messages
|
|
158
|
+
*/
|
|
159
|
+
formatError(error) {
|
|
160
|
+
if (error instanceof Anthropic.APIError) {
|
|
161
|
+
return `Anthropic API error: ${error.message} (${error.status})`;
|
|
162
|
+
}
|
|
163
|
+
if (error instanceof Error) {
|
|
164
|
+
return error.message;
|
|
165
|
+
}
|
|
166
|
+
return String(error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Create an Anthropic adapter with options
|
|
171
|
+
*
|
|
172
|
+
* @param options - Adapter configuration options
|
|
173
|
+
* @returns LLMAdapter instance
|
|
174
|
+
*/
|
|
175
|
+
export function createAnthropicAdapter(options) {
|
|
176
|
+
return new AnthropicAdapter(options);
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=anthropic-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-adapter.js","sourceRoot":"","sources":["../../../src/effects/llm/anthropic-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAQ1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACrG,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAcrB;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAY;IAClB,MAAM,C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CAAC;QACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAiC;IACtE,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { LLMAdapter } from "./adapter.js";
|
|
2
|
+
import type { CompilerResolutionPolicy } from "../../domain/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* LLM Effect Handler result
|
|
5
|
+
*
|
|
6
|
+
* Effect handlers return an action to dispatch, which the Host will execute.
|
|
7
|
+
*/
|
|
8
|
+
export interface EffectHandlerResult {
|
|
9
|
+
action: string;
|
|
10
|
+
input: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* LLM Effect Handler type
|
|
14
|
+
*/
|
|
15
|
+
export type LLMEffectHandler = (params: Record<string, unknown>) => Promise<EffectHandlerResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Create LLM segment effect handler
|
|
18
|
+
*
|
|
19
|
+
* Handles 'llm:segment' effect - segments input text into requirements.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createSegmentHandler(adapter: LLMAdapter): LLMEffectHandler;
|
|
22
|
+
/**
|
|
23
|
+
* Create LLM normalize effect handler
|
|
24
|
+
*
|
|
25
|
+
* Handles 'llm:normalize' effect - normalizes segments into intents.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createNormalizeHandler(adapter: LLMAdapter, policy: CompilerResolutionPolicy): LLMEffectHandler;
|
|
28
|
+
/**
|
|
29
|
+
* Create LLM propose effect handler
|
|
30
|
+
*
|
|
31
|
+
* Handles 'llm:propose' effect - generates a DomainDraft from intents.
|
|
32
|
+
*
|
|
33
|
+
* Per FDR-C002: LLM output is an untrusted proposal.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createProposeHandler(adapter: LLMAdapter, policy: CompilerResolutionPolicy): LLMEffectHandler;
|
|
36
|
+
/**
|
|
37
|
+
* Create all LLM effect handlers
|
|
38
|
+
*
|
|
39
|
+
* @param adapter - LLM adapter instance
|
|
40
|
+
* @param policy - Resolution policy
|
|
41
|
+
* @returns Record of effect type to handler
|
|
42
|
+
*/
|
|
43
|
+
export declare function createLLMEffectHandlers(adapter: LLMAdapter, policy: CompilerResolutionPolicy): Record<string, LLMEffectHandler>;
|
|
44
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/effects/llm/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAIV,wBAAwB,EACzB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElC;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,UAAU,GAAG,gBAAgB,CAmC1E;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,wBAAwB,GAC/B,gBAAgB,CAkClB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,wBAAwB,GAC/B,gBAAgB,CAqClB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,wBAAwB,GAC/B,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAMlC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create LLM segment effect handler
|
|
3
|
+
*
|
|
4
|
+
* Handles 'llm:segment' effect - segments input text into requirements.
|
|
5
|
+
*/
|
|
6
|
+
export function createSegmentHandler(adapter) {
|
|
7
|
+
return async (params) => {
|
|
8
|
+
const text = params.text;
|
|
9
|
+
if (process.env.DEBUG) {
|
|
10
|
+
console.log("[LLM:segment] Starting segmentation for text:", text.slice(0, 100));
|
|
11
|
+
}
|
|
12
|
+
const result = await adapter.segment({ text });
|
|
13
|
+
if (process.env.DEBUG) {
|
|
14
|
+
console.log("[LLM:segment] Result:", JSON.stringify(result, null, 2));
|
|
15
|
+
}
|
|
16
|
+
if (result.ok === true) {
|
|
17
|
+
return {
|
|
18
|
+
action: "receiveSegments",
|
|
19
|
+
input: { segments: result.data.segments },
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (result.ok === "resolution") {
|
|
23
|
+
return {
|
|
24
|
+
action: "requestResolution",
|
|
25
|
+
input: { reason: result.reason, options: result.options },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// Error case - discard with segmentation failed
|
|
29
|
+
console.error("[LLM:segment] Segmentation failed:", result.error);
|
|
30
|
+
return {
|
|
31
|
+
action: "discard",
|
|
32
|
+
input: { reason: "SEGMENTATION_FAILED", error: result.error },
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create LLM normalize effect handler
|
|
38
|
+
*
|
|
39
|
+
* Handles 'llm:normalize' effect - normalizes segments into intents.
|
|
40
|
+
*/
|
|
41
|
+
export function createNormalizeHandler(adapter, policy) {
|
|
42
|
+
return async (params) => {
|
|
43
|
+
const segments = params.segments;
|
|
44
|
+
const schema = params.schema;
|
|
45
|
+
const context = params.context;
|
|
46
|
+
const result = await adapter.normalize({ segments, schema, context });
|
|
47
|
+
if (result.ok === true) {
|
|
48
|
+
return {
|
|
49
|
+
action: "receiveIntents",
|
|
50
|
+
input: { intents: result.data.intents },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (result.ok === "resolution") {
|
|
54
|
+
if (policy.onResolutionRequired === "discard") {
|
|
55
|
+
return {
|
|
56
|
+
action: "discard",
|
|
57
|
+
input: { reason: "RESOLUTION_REQUIRED_BUT_DISABLED" },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
action: "requestResolution",
|
|
62
|
+
input: { reason: result.reason, options: result.options },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Error case - treat as segmentation failed (normalization is part of that phase)
|
|
66
|
+
return {
|
|
67
|
+
action: "discard",
|
|
68
|
+
input: { reason: "SEGMENTATION_FAILED" },
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create LLM propose effect handler
|
|
74
|
+
*
|
|
75
|
+
* Handles 'llm:propose' effect - generates a DomainDraft from intents.
|
|
76
|
+
*
|
|
77
|
+
* Per FDR-C002: LLM output is an untrusted proposal.
|
|
78
|
+
*/
|
|
79
|
+
export function createProposeHandler(adapter, policy) {
|
|
80
|
+
return async (params) => {
|
|
81
|
+
const schema = params.schema;
|
|
82
|
+
const intents = params.intents;
|
|
83
|
+
const history = params.history;
|
|
84
|
+
const context = params.context;
|
|
85
|
+
const resolution = params.resolution;
|
|
86
|
+
const result = await adapter.propose({ schema, intents, history, context, resolution });
|
|
87
|
+
if (result.ok === true) {
|
|
88
|
+
return {
|
|
89
|
+
action: "receiveDraft",
|
|
90
|
+
input: { draft: result.data.draft },
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (result.ok === "resolution") {
|
|
94
|
+
if (policy.onResolutionRequired === "discard") {
|
|
95
|
+
return {
|
|
96
|
+
action: "discard",
|
|
97
|
+
input: { reason: "RESOLUTION_REQUIRED_BUT_DISABLED" },
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
action: "requestResolution",
|
|
102
|
+
input: { reason: result.reason, options: result.options },
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Error case - will be handled by retry logic
|
|
106
|
+
// Return a draft that will fail validation to trigger retry
|
|
107
|
+
return {
|
|
108
|
+
action: "receiveDraft",
|
|
109
|
+
input: { draft: { _error: result.error } },
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create all LLM effect handlers
|
|
115
|
+
*
|
|
116
|
+
* @param adapter - LLM adapter instance
|
|
117
|
+
* @param policy - Resolution policy
|
|
118
|
+
* @returns Record of effect type to handler
|
|
119
|
+
*/
|
|
120
|
+
export function createLLMEffectHandlers(adapter, policy) {
|
|
121
|
+
return {
|
|
122
|
+
"llm:segment": createSegmentHandler(adapter),
|
|
123
|
+
"llm:normalize": createNormalizeHandler(adapter, policy),
|
|
124
|
+
"llm:propose": createProposeHandler(adapter, policy),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../../src/effects/llm/handlers.ts"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAmB;IACtD,OAAO,KAAK,EAAE,MAA+B,EAAgC,EAAE;QAC7E,MAAM,IAAI,GAAG,MAAM,CAAC,IAAc,CAAC;QAEnC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,+CAA+C,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACnF,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAA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AAE,CAAC,CAAC;QAExF,IAAI,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;YACvB,OAAO;gBACL,MAAM,EAAE,cAAc;gBACtB,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE;aACpC,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,CAAC,EAAE,KAAK,YAAY,EAAE,CAAC;YAC/B,IAAI,MAAM,CAAC,oBAAoB,KAAK,SAAS,EAAE,CAAC;gBAC9C,OAAO;oBACL,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,EAAE,MAAM,EAAE,kCAAkC,EAAE;iBACtD,CAAC;YACJ,CAAC;YACD,OAAO;gBACL,MAAM,EAAE,mBAAmB;gBAC3B,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE;aAC1D,CAAC;QACJ,CAAC;QAED,8CAA8C;QAC9C,4DAA4D;QAC5D,OAAO;YACL,MAAM,EAAE,cAAc;YACtB,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE;SAC3C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAmB,EACnB,MAAgC;IAEhC,OAAO;QACL,aAAa,EAAE,oBAAoB,CAAC,OAAO,CAAC;QAC5C,eAAe,EAAE,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC;QACxD,aAAa,EAAE,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC;KACrD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { LLMAdapter, LLMAdapterConfig, LLMResult, SegmentResult, NormalizeResult, ProposeResult, } from "./adapter.js";
|
|
2
|
+
export { DEFAULT_LLM_CONFIG } from "./adapter.js";
|
|
3
|
+
export { AnthropicAdapter, createAnthropicAdapter, type AnthropicAdapterOptions, } from "./anthropic-adapter.js";
|
|
4
|
+
export { createSegmentHandler, createNormalizeHandler, createProposeHandler, createLLMEffectHandlers, type LLMEffectHandler, type EffectHandlerResult, } from "./handlers.js";
|
|
5
|
+
export { parseJSONResponse, extractResolutionRequest, validateSegmentsResponse, validateIntentsResponse, validateDraftResponse, type ParseResult, type ResolutionRequest, } from "./parser.js";
|
|
6
|
+
export { createSegmentPrompt, createNormalizePrompt, createProposePrompt } from "./prompts/index.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/effects/llm/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACzB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,KAAK,WAAW,EAChB,KAAK,iBAAiB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { DEFAULT_LLM_CONFIG } from "./adapter.js";
|
|
2
|
+
// Anthropic adapter
|
|
3
|
+
export { AnthropicAdapter, createAnthropicAdapter, } from "./anthropic-adapter.js";
|
|
4
|
+
// Handlers
|
|
5
|
+
export { createSegmentHandler, createNormalizeHandler, createProposeHandler, createLLMEffectHandlers, } from "./handlers.js";
|
|
6
|
+
// Parser
|
|
7
|
+
export { parseJSONResponse, extractResolutionRequest, validateSegmentsResponse, validateIntentsResponse, validateDraftResponse, } from "./parser.js";
|
|
8
|
+
// Prompts
|
|
9
|
+
export { createSegmentPrompt, createNormalizePrompt, createProposePrompt } from "./prompts/index.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/effects/llm/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,oBAAoB;AACpB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC;AAEhC,WAAW;AACX,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,GAGxB,MAAM,eAAe,CAAC;AAEvB,SAAS;AACT,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GAGtB,MAAM,aAAa,CAAC;AAErB,UAAU;AACV,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
|