@sourcepress/ai 0.1.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/.omc/state/last-tool-error.json +7 -0
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +24 -0
- package/LICENSE +21 -0
- package/dist/__tests__/budget.test.d.ts +2 -0
- package/dist/__tests__/budget.test.d.ts.map +1 -0
- package/dist/__tests__/budget.test.js +96 -0
- package/dist/__tests__/budget.test.js.map +1 -0
- package/dist/__tests__/classify.test.d.ts +2 -0
- package/dist/__tests__/classify.test.d.ts.map +1 -0
- package/dist/__tests__/classify.test.js +72 -0
- package/dist/__tests__/classify.test.js.map +1 -0
- package/dist/__tests__/eval-runner.test.d.ts +2 -0
- package/dist/__tests__/eval-runner.test.d.ts.map +1 -0
- package/dist/__tests__/eval-runner.test.js +171 -0
- package/dist/__tests__/eval-runner.test.js.map +1 -0
- package/dist/__tests__/extract.test.d.ts +2 -0
- package/dist/__tests__/extract.test.d.ts.map +1 -0
- package/dist/__tests__/extract.test.js +79 -0
- package/dist/__tests__/extract.test.js.map +1 -0
- package/dist/__tests__/find-gaps.test.d.ts +2 -0
- package/dist/__tests__/find-gaps.test.d.ts.map +1 -0
- package/dist/__tests__/find-gaps.test.js +82 -0
- package/dist/__tests__/find-gaps.test.js.map +1 -0
- package/dist/__tests__/generate.test.d.ts +2 -0
- package/dist/__tests__/generate.test.d.ts.map +1 -0
- package/dist/__tests__/generate.test.js +68 -0
- package/dist/__tests__/generate.test.js.map +1 -0
- package/dist/__tests__/improve-prompt.test.d.ts +2 -0
- package/dist/__tests__/improve-prompt.test.d.ts.map +1 -0
- package/dist/__tests__/improve-prompt.test.js +32 -0
- package/dist/__tests__/improve-prompt.test.js.map +1 -0
- package/dist/__tests__/intent-impact.test.d.ts +2 -0
- package/dist/__tests__/intent-impact.test.d.ts.map +1 -0
- package/dist/__tests__/intent-impact.test.js +51 -0
- package/dist/__tests__/intent-impact.test.js.map +1 -0
- package/dist/__tests__/judge.test.d.ts +2 -0
- package/dist/__tests__/judge.test.d.ts.map +1 -0
- package/dist/__tests__/judge.test.js +61 -0
- package/dist/__tests__/judge.test.js.map +1 -0
- package/dist/__tests__/score.test.d.ts +2 -0
- package/dist/__tests__/score.test.d.ts.map +1 -0
- package/dist/__tests__/score.test.js +50 -0
- package/dist/__tests__/score.test.js.map +1 -0
- package/dist/__tests__/staleness.test.d.ts +2 -0
- package/dist/__tests__/staleness.test.d.ts.map +1 -0
- package/dist/__tests__/staleness.test.js +66 -0
- package/dist/__tests__/staleness.test.js.map +1 -0
- package/dist/budget.d.ts +13 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +40 -0
- package/dist/budget.js.map +1 -0
- package/dist/eval/runner.d.ts +34 -0
- package/dist/eval/runner.d.ts.map +1 -0
- package/dist/eval/runner.js +128 -0
- package/dist/eval/runner.js.map +1 -0
- package/dist/functions/classify.d.ts +5 -0
- package/dist/functions/classify.d.ts.map +1 -0
- package/dist/functions/classify.js +43 -0
- package/dist/functions/classify.js.map +1 -0
- package/dist/functions/extract.d.ts +5 -0
- package/dist/functions/extract.d.ts.map +1 -0
- package/dist/functions/extract.js +57 -0
- package/dist/functions/extract.js.map +1 -0
- package/dist/functions/find-gaps.d.ts +5 -0
- package/dist/functions/find-gaps.d.ts.map +1 -0
- package/dist/functions/find-gaps.js +51 -0
- package/dist/functions/find-gaps.js.map +1 -0
- package/dist/functions/generate.d.ts +5 -0
- package/dist/functions/generate.d.ts.map +1 -0
- package/dist/functions/generate.js +39 -0
- package/dist/functions/generate.js.map +1 -0
- package/dist/functions/improve-prompt.d.ts +5 -0
- package/dist/functions/improve-prompt.d.ts.map +1 -0
- package/dist/functions/improve-prompt.js +38 -0
- package/dist/functions/improve-prompt.js.map +1 -0
- package/dist/functions/index.d.ts +11 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/index.js +11 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/intent-impact.d.ts +5 -0
- package/dist/functions/intent-impact.d.ts.map +1 -0
- package/dist/functions/intent-impact.js +45 -0
- package/dist/functions/intent-impact.js.map +1 -0
- package/dist/functions/judge.d.ts +5 -0
- package/dist/functions/judge.d.ts.map +1 -0
- package/dist/functions/judge.js +32 -0
- package/dist/functions/judge.js.map +1 -0
- package/dist/functions/model-factory.d.ts +4 -0
- package/dist/functions/model-factory.d.ts.map +1 -0
- package/dist/functions/model-factory.js +52 -0
- package/dist/functions/model-factory.js.map +1 -0
- package/dist/functions/score.d.ts +5 -0
- package/dist/functions/score.d.ts.map +1 -0
- package/dist/functions/score.js +47 -0
- package/dist/functions/score.js.map +1 -0
- package/dist/functions/staleness.d.ts +5 -0
- package/dist/functions/staleness.d.ts.map +1 -0
- package/dist/functions/staleness.js +45 -0
- package/dist/functions/staleness.js.map +1 -0
- package/dist/functions/usage.d.ts +8 -0
- package/dist/functions/usage.d.ts.map +1 -0
- package/dist/functions/usage.js +13 -0
- package/dist/functions/usage.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +10 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +32 -0
- package/dist/provider.js.map +1 -0
- package/dist/types.d.ts +207 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
- package/src/__tests__/budget.test.ts +103 -0
- package/src/__tests__/classify.test.ts +90 -0
- package/src/__tests__/eval-runner.test.ts +199 -0
- package/src/__tests__/extract.test.ts +92 -0
- package/src/__tests__/find-gaps.test.ts +93 -0
- package/src/__tests__/generate.test.ts +92 -0
- package/src/__tests__/improve-prompt.test.ts +42 -0
- package/src/__tests__/intent-impact.test.ts +62 -0
- package/src/__tests__/judge.test.ts +78 -0
- package/src/__tests__/score.test.ts +61 -0
- package/src/__tests__/staleness.test.ts +77 -0
- package/src/budget.ts +47 -0
- package/src/eval/runner.ts +163 -0
- package/src/functions/classify.ts +54 -0
- package/src/functions/extract.ts +72 -0
- package/src/functions/find-gaps.ts +65 -0
- package/src/functions/generate.ts +51 -0
- package/src/functions/improve-prompt.ts +48 -0
- package/src/functions/index.ts +10 -0
- package/src/functions/intent-impact.ts +56 -0
- package/src/functions/judge.ts +41 -0
- package/src/functions/model-factory.ts +60 -0
- package/src/functions/score.ts +56 -0
- package/src/functions/staleness.ts +54 -0
- package/src/functions/usage.ts +25 -0
- package/src/index.ts +47 -0
- package/src/provider.ts +41 -0
- package/src/types.ts +225 -0
- package/tsconfig.json +5 -0
- package/vitest.config.ts +2 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { Entity } from "@sourcepress/core";
|
|
2
|
+
|
|
3
|
+
export interface AIProviderConfig {
|
|
4
|
+
provider: "anthropic" | "openai" | "local";
|
|
5
|
+
model: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface BudgetConfig {
|
|
11
|
+
daily_limit_usd: number;
|
|
12
|
+
warn_at_usd?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BudgetStatus {
|
|
16
|
+
spent_today_usd: number;
|
|
17
|
+
limit_usd: number;
|
|
18
|
+
warn_at_usd: number;
|
|
19
|
+
remaining_usd: number;
|
|
20
|
+
is_over_limit: boolean;
|
|
21
|
+
is_warned: boolean;
|
|
22
|
+
reset_at: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TokenUsage {
|
|
26
|
+
input_tokens: number;
|
|
27
|
+
output_tokens: number;
|
|
28
|
+
estimated_cost_usd: number;
|
|
29
|
+
function_name: string;
|
|
30
|
+
timestamp: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 1. Classify
|
|
34
|
+
export interface ClassifyInput {
|
|
35
|
+
text: string;
|
|
36
|
+
available_types?: string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ClassifyResult {
|
|
40
|
+
quality: "structured" | "draft" | "thoughts";
|
|
41
|
+
quality_score: number;
|
|
42
|
+
type: string;
|
|
43
|
+
reasoning: string;
|
|
44
|
+
usage: TokenUsage;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 2. Extract
|
|
48
|
+
export interface ExtractInput {
|
|
49
|
+
text: string;
|
|
50
|
+
file_path: string;
|
|
51
|
+
existing_entities?: Entity[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ExtractedEntityResult {
|
|
55
|
+
type: string;
|
|
56
|
+
name: string;
|
|
57
|
+
aliases: string[];
|
|
58
|
+
confidence: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface ExtractedRelationResult {
|
|
62
|
+
from_entity: string;
|
|
63
|
+
to_entity: string;
|
|
64
|
+
relation_type: string;
|
|
65
|
+
confidence: number;
|
|
66
|
+
evidence: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ExtractResult {
|
|
70
|
+
entities: ExtractedEntityResult[];
|
|
71
|
+
relations: ExtractedRelationResult[];
|
|
72
|
+
usage: TokenUsage;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 3. Score
|
|
76
|
+
export interface ScoreInput {
|
|
77
|
+
content: string;
|
|
78
|
+
intent: string;
|
|
79
|
+
collection_name?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ScoreResult {
|
|
83
|
+
score: number;
|
|
84
|
+
issues: string[];
|
|
85
|
+
strengths: string[];
|
|
86
|
+
usage: TokenUsage;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 4. Judge
|
|
90
|
+
export interface JudgeInput {
|
|
91
|
+
draft: string;
|
|
92
|
+
gold_standard: string;
|
|
93
|
+
judge_prompt: string;
|
|
94
|
+
intent?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface JudgeResult {
|
|
98
|
+
score: number;
|
|
99
|
+
reasoning: string;
|
|
100
|
+
usage: TokenUsage;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 5. Detect staleness
|
|
104
|
+
export interface StalenessInput {
|
|
105
|
+
content: string;
|
|
106
|
+
content_generated_at: string;
|
|
107
|
+
source_texts: Array<{ path: string; text: string; updated_at: string }>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface StalenessResult {
|
|
111
|
+
stale: boolean;
|
|
112
|
+
reason: string;
|
|
113
|
+
stale_sources: string[];
|
|
114
|
+
confidence: number;
|
|
115
|
+
usage: TokenUsage;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 6. Intent impact
|
|
119
|
+
export interface IntentImpactInput {
|
|
120
|
+
changed_intent: string;
|
|
121
|
+
previous_intent: string;
|
|
122
|
+
content_pages: Array<{ path: string; text: string }>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface IntentImpactResult {
|
|
126
|
+
affected_pages: Array<{ path: string; impact: "high" | "medium" | "low"; reason: string }>;
|
|
127
|
+
summary: string;
|
|
128
|
+
usage: TokenUsage;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 7. Find gaps (AI-assisted)
|
|
132
|
+
export interface FindGapsInput {
|
|
133
|
+
entities: Entity[];
|
|
134
|
+
relations: Array<{ from: string; to: string; type: string }>;
|
|
135
|
+
existing_content: Array<{ path: string; title: string; summary: string }>;
|
|
136
|
+
business_context?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface FindGapsResult {
|
|
140
|
+
gaps: Array<{
|
|
141
|
+
entity_name: string;
|
|
142
|
+
entity_type: string;
|
|
143
|
+
suggested_content_type: string;
|
|
144
|
+
priority: "high" | "medium" | "low";
|
|
145
|
+
reason: string;
|
|
146
|
+
}>;
|
|
147
|
+
usage: TokenUsage;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface IntelligenceProvider {
|
|
151
|
+
classify(input: ClassifyInput): Promise<ClassifyResult>;
|
|
152
|
+
extract(input: ExtractInput): Promise<ExtractResult>;
|
|
153
|
+
score(input: ScoreInput): Promise<ScoreResult>;
|
|
154
|
+
judge(input: JudgeInput): Promise<JudgeResult>;
|
|
155
|
+
detectStaleness(input: StalenessInput): Promise<StalenessResult>;
|
|
156
|
+
analyzeIntentImpact(input: IntentImpactInput): Promise<IntentImpactResult>;
|
|
157
|
+
findGaps(input: FindGapsInput): Promise<FindGapsResult>;
|
|
158
|
+
generate(input: GenerateInput): Promise<GenerateResult>;
|
|
159
|
+
improvePrompt(input: ImprovePromptInput): Promise<ImprovePromptResult>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 8. Generate content
|
|
163
|
+
export interface GenerateInput {
|
|
164
|
+
content_type: string;
|
|
165
|
+
generation_prompt: string;
|
|
166
|
+
knowledge_context: string;
|
|
167
|
+
intent?: string;
|
|
168
|
+
collection_schema?: Record<string, unknown>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface GenerateResult {
|
|
172
|
+
content: string;
|
|
173
|
+
frontmatter: Record<string, unknown>;
|
|
174
|
+
usage: TokenUsage;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 9. Improve prompt
|
|
178
|
+
export interface ImprovePromptInput {
|
|
179
|
+
current_prompt: string;
|
|
180
|
+
judge_reasoning: string;
|
|
181
|
+
judge_score: number;
|
|
182
|
+
content_type: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface ImprovePromptResult {
|
|
186
|
+
improved_prompt: string;
|
|
187
|
+
changes_summary: string;
|
|
188
|
+
usage: TokenUsage;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Eval types
|
|
192
|
+
export interface EvalResult {
|
|
193
|
+
id: string;
|
|
194
|
+
content_type: string;
|
|
195
|
+
prompt_version: string;
|
|
196
|
+
score: number;
|
|
197
|
+
status: "keep" | "discard" | "improved";
|
|
198
|
+
reasoning: string;
|
|
199
|
+
iteration: number;
|
|
200
|
+
generated_content?: string;
|
|
201
|
+
timestamp: string;
|
|
202
|
+
total_usage: TokenUsage;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface EvalRunConfig {
|
|
206
|
+
content_type: string;
|
|
207
|
+
knowledge_context: string;
|
|
208
|
+
gold_standard: string;
|
|
209
|
+
judge_prompt: string;
|
|
210
|
+
generation_prompt: string;
|
|
211
|
+
intent?: string;
|
|
212
|
+
threshold: number;
|
|
213
|
+
max_iterations: number;
|
|
214
|
+
collection_schema?: Record<string, unknown>;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface EvalRunResult {
|
|
218
|
+
iterations: EvalResult[];
|
|
219
|
+
final_score: number;
|
|
220
|
+
final_status: "keep" | "discard";
|
|
221
|
+
final_content?: string;
|
|
222
|
+
final_prompt: string;
|
|
223
|
+
prompt_improved: boolean;
|
|
224
|
+
total_usage: TokenUsage;
|
|
225
|
+
}
|
package/tsconfig.json
ADDED
package/vitest.config.ts
ADDED