@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.
Files changed (147) hide show
  1. package/.omc/state/last-tool-error.json +7 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.turbo/turbo-test.log +24 -0
  4. package/LICENSE +21 -0
  5. package/dist/__tests__/budget.test.d.ts +2 -0
  6. package/dist/__tests__/budget.test.d.ts.map +1 -0
  7. package/dist/__tests__/budget.test.js +96 -0
  8. package/dist/__tests__/budget.test.js.map +1 -0
  9. package/dist/__tests__/classify.test.d.ts +2 -0
  10. package/dist/__tests__/classify.test.d.ts.map +1 -0
  11. package/dist/__tests__/classify.test.js +72 -0
  12. package/dist/__tests__/classify.test.js.map +1 -0
  13. package/dist/__tests__/eval-runner.test.d.ts +2 -0
  14. package/dist/__tests__/eval-runner.test.d.ts.map +1 -0
  15. package/dist/__tests__/eval-runner.test.js +171 -0
  16. package/dist/__tests__/eval-runner.test.js.map +1 -0
  17. package/dist/__tests__/extract.test.d.ts +2 -0
  18. package/dist/__tests__/extract.test.d.ts.map +1 -0
  19. package/dist/__tests__/extract.test.js +79 -0
  20. package/dist/__tests__/extract.test.js.map +1 -0
  21. package/dist/__tests__/find-gaps.test.d.ts +2 -0
  22. package/dist/__tests__/find-gaps.test.d.ts.map +1 -0
  23. package/dist/__tests__/find-gaps.test.js +82 -0
  24. package/dist/__tests__/find-gaps.test.js.map +1 -0
  25. package/dist/__tests__/generate.test.d.ts +2 -0
  26. package/dist/__tests__/generate.test.d.ts.map +1 -0
  27. package/dist/__tests__/generate.test.js +68 -0
  28. package/dist/__tests__/generate.test.js.map +1 -0
  29. package/dist/__tests__/improve-prompt.test.d.ts +2 -0
  30. package/dist/__tests__/improve-prompt.test.d.ts.map +1 -0
  31. package/dist/__tests__/improve-prompt.test.js +32 -0
  32. package/dist/__tests__/improve-prompt.test.js.map +1 -0
  33. package/dist/__tests__/intent-impact.test.d.ts +2 -0
  34. package/dist/__tests__/intent-impact.test.d.ts.map +1 -0
  35. package/dist/__tests__/intent-impact.test.js +51 -0
  36. package/dist/__tests__/intent-impact.test.js.map +1 -0
  37. package/dist/__tests__/judge.test.d.ts +2 -0
  38. package/dist/__tests__/judge.test.d.ts.map +1 -0
  39. package/dist/__tests__/judge.test.js +61 -0
  40. package/dist/__tests__/judge.test.js.map +1 -0
  41. package/dist/__tests__/score.test.d.ts +2 -0
  42. package/dist/__tests__/score.test.d.ts.map +1 -0
  43. package/dist/__tests__/score.test.js +50 -0
  44. package/dist/__tests__/score.test.js.map +1 -0
  45. package/dist/__tests__/staleness.test.d.ts +2 -0
  46. package/dist/__tests__/staleness.test.d.ts.map +1 -0
  47. package/dist/__tests__/staleness.test.js +66 -0
  48. package/dist/__tests__/staleness.test.js.map +1 -0
  49. package/dist/budget.d.ts +13 -0
  50. package/dist/budget.d.ts.map +1 -0
  51. package/dist/budget.js +40 -0
  52. package/dist/budget.js.map +1 -0
  53. package/dist/eval/runner.d.ts +34 -0
  54. package/dist/eval/runner.d.ts.map +1 -0
  55. package/dist/eval/runner.js +128 -0
  56. package/dist/eval/runner.js.map +1 -0
  57. package/dist/functions/classify.d.ts +5 -0
  58. package/dist/functions/classify.d.ts.map +1 -0
  59. package/dist/functions/classify.js +43 -0
  60. package/dist/functions/classify.js.map +1 -0
  61. package/dist/functions/extract.d.ts +5 -0
  62. package/dist/functions/extract.d.ts.map +1 -0
  63. package/dist/functions/extract.js +57 -0
  64. package/dist/functions/extract.js.map +1 -0
  65. package/dist/functions/find-gaps.d.ts +5 -0
  66. package/dist/functions/find-gaps.d.ts.map +1 -0
  67. package/dist/functions/find-gaps.js +51 -0
  68. package/dist/functions/find-gaps.js.map +1 -0
  69. package/dist/functions/generate.d.ts +5 -0
  70. package/dist/functions/generate.d.ts.map +1 -0
  71. package/dist/functions/generate.js +39 -0
  72. package/dist/functions/generate.js.map +1 -0
  73. package/dist/functions/improve-prompt.d.ts +5 -0
  74. package/dist/functions/improve-prompt.d.ts.map +1 -0
  75. package/dist/functions/improve-prompt.js +38 -0
  76. package/dist/functions/improve-prompt.js.map +1 -0
  77. package/dist/functions/index.d.ts +11 -0
  78. package/dist/functions/index.d.ts.map +1 -0
  79. package/dist/functions/index.js +11 -0
  80. package/dist/functions/index.js.map +1 -0
  81. package/dist/functions/intent-impact.d.ts +5 -0
  82. package/dist/functions/intent-impact.d.ts.map +1 -0
  83. package/dist/functions/intent-impact.js +45 -0
  84. package/dist/functions/intent-impact.js.map +1 -0
  85. package/dist/functions/judge.d.ts +5 -0
  86. package/dist/functions/judge.d.ts.map +1 -0
  87. package/dist/functions/judge.js +32 -0
  88. package/dist/functions/judge.js.map +1 -0
  89. package/dist/functions/model-factory.d.ts +4 -0
  90. package/dist/functions/model-factory.d.ts.map +1 -0
  91. package/dist/functions/model-factory.js +52 -0
  92. package/dist/functions/model-factory.js.map +1 -0
  93. package/dist/functions/score.d.ts +5 -0
  94. package/dist/functions/score.d.ts.map +1 -0
  95. package/dist/functions/score.js +47 -0
  96. package/dist/functions/score.js.map +1 -0
  97. package/dist/functions/staleness.d.ts +5 -0
  98. package/dist/functions/staleness.d.ts.map +1 -0
  99. package/dist/functions/staleness.js +45 -0
  100. package/dist/functions/staleness.js.map +1 -0
  101. package/dist/functions/usage.d.ts +8 -0
  102. package/dist/functions/usage.d.ts.map +1 -0
  103. package/dist/functions/usage.js +13 -0
  104. package/dist/functions/usage.js.map +1 -0
  105. package/dist/index.d.ts +8 -0
  106. package/dist/index.d.ts.map +1 -0
  107. package/dist/index.js +6 -0
  108. package/dist/index.js.map +1 -0
  109. package/dist/provider.d.ts +10 -0
  110. package/dist/provider.d.ts.map +1 -0
  111. package/dist/provider.js +32 -0
  112. package/dist/provider.js.map +1 -0
  113. package/dist/types.d.ts +207 -0
  114. package/dist/types.d.ts.map +1 -0
  115. package/dist/types.js +2 -0
  116. package/dist/types.js.map +1 -0
  117. package/package.json +41 -0
  118. package/src/__tests__/budget.test.ts +103 -0
  119. package/src/__tests__/classify.test.ts +90 -0
  120. package/src/__tests__/eval-runner.test.ts +199 -0
  121. package/src/__tests__/extract.test.ts +92 -0
  122. package/src/__tests__/find-gaps.test.ts +93 -0
  123. package/src/__tests__/generate.test.ts +92 -0
  124. package/src/__tests__/improve-prompt.test.ts +42 -0
  125. package/src/__tests__/intent-impact.test.ts +62 -0
  126. package/src/__tests__/judge.test.ts +78 -0
  127. package/src/__tests__/score.test.ts +61 -0
  128. package/src/__tests__/staleness.test.ts +77 -0
  129. package/src/budget.ts +47 -0
  130. package/src/eval/runner.ts +163 -0
  131. package/src/functions/classify.ts +54 -0
  132. package/src/functions/extract.ts +72 -0
  133. package/src/functions/find-gaps.ts +65 -0
  134. package/src/functions/generate.ts +51 -0
  135. package/src/functions/improve-prompt.ts +48 -0
  136. package/src/functions/index.ts +10 -0
  137. package/src/functions/intent-impact.ts +56 -0
  138. package/src/functions/judge.ts +41 -0
  139. package/src/functions/model-factory.ts +60 -0
  140. package/src/functions/score.ts +56 -0
  141. package/src/functions/staleness.ts +54 -0
  142. package/src/functions/usage.ts +25 -0
  143. package/src/index.ts +47 -0
  144. package/src/provider.ts +41 -0
  145. package/src/types.ts +225 -0
  146. package/tsconfig.json +5 -0
  147. 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
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": { "outDir": "dist", "rootDir": "src" },
4
+ "include": ["src"]
5
+ }
@@ -0,0 +1,2 @@
1
+ import { defineConfig } from "vitest/config";
2
+ export default defineConfig({ test: { include: ["src/__tests__/**/*.test.ts"] } });