@hilbras/sdk 0.26.0 → 0.26.6

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 (251) hide show
  1. package/README.md +1 -1
  2. package/dist/catalog/provider-catalog.json +92 -57
  3. package/dist/features/agent/index.d.ts +13 -0
  4. package/dist/features/agent/index.d.ts.map +1 -0
  5. package/dist/features/agent/index.js +12 -0
  6. package/dist/features/agent/index.js.map +1 -0
  7. package/dist/features/agent/plan-and-execute.d.ts +49 -0
  8. package/dist/features/agent/plan-and-execute.d.ts.map +1 -0
  9. package/dist/features/agent/plan-and-execute.js +184 -0
  10. package/dist/features/agent/plan-and-execute.js.map +1 -0
  11. package/dist/features/agent/react.d.ts +49 -0
  12. package/dist/features/agent/react.d.ts.map +1 -0
  13. package/dist/features/agent/react.js +165 -0
  14. package/dist/features/agent/react.js.map +1 -0
  15. package/dist/features/agent/tool-loop.d.ts +58 -0
  16. package/dist/features/agent/tool-loop.d.ts.map +1 -0
  17. package/dist/features/agent/tool-loop.js +217 -0
  18. package/dist/features/agent/tool-loop.js.map +1 -0
  19. package/dist/features/agent/types.d.ts +136 -0
  20. package/dist/features/agent/types.d.ts.map +1 -0
  21. package/dist/features/agent/types.js +7 -0
  22. package/dist/features/agent/types.js.map +1 -0
  23. package/dist/features/eval/evaluate.d.ts +39 -0
  24. package/dist/features/eval/evaluate.d.ts.map +1 -0
  25. package/dist/features/eval/evaluate.js +153 -0
  26. package/dist/features/eval/evaluate.js.map +1 -0
  27. package/dist/features/eval/index.d.ts +9 -0
  28. package/dist/features/eval/index.d.ts.map +1 -0
  29. package/dist/features/eval/index.js +8 -0
  30. package/dist/features/eval/index.js.map +1 -0
  31. package/dist/features/eval/metrics.d.ts +38 -0
  32. package/dist/features/eval/metrics.d.ts.map +1 -0
  33. package/dist/features/eval/metrics.js +133 -0
  34. package/dist/features/eval/metrics.js.map +1 -0
  35. package/dist/features/eval/types.d.ts +116 -0
  36. package/dist/features/eval/types.d.ts.map +1 -0
  37. package/dist/features/eval/types.js +7 -0
  38. package/dist/features/eval/types.js.map +1 -0
  39. package/dist/features/fine-tune/formatters.d.ts +11 -0
  40. package/dist/features/fine-tune/formatters.d.ts.map +1 -0
  41. package/dist/features/fine-tune/formatters.js +155 -0
  42. package/dist/features/fine-tune/formatters.js.map +1 -0
  43. package/dist/features/fine-tune/index.d.ts +10 -0
  44. package/dist/features/fine-tune/index.d.ts.map +1 -0
  45. package/dist/features/fine-tune/index.js +9 -0
  46. package/dist/features/fine-tune/index.js.map +1 -0
  47. package/dist/features/fine-tune/quality.d.ts +37 -0
  48. package/dist/features/fine-tune/quality.d.ts.map +1 -0
  49. package/dist/features/fine-tune/quality.js +97 -0
  50. package/dist/features/fine-tune/quality.js.map +1 -0
  51. package/dist/features/fine-tune/split.d.ts +23 -0
  52. package/dist/features/fine-tune/split.d.ts.map +1 -0
  53. package/dist/features/fine-tune/split.js +43 -0
  54. package/dist/features/fine-tune/split.js.map +1 -0
  55. package/dist/features/fine-tune/types.d.ts +85 -0
  56. package/dist/features/fine-tune/types.d.ts.map +1 -0
  57. package/dist/features/fine-tune/types.js +5 -0
  58. package/dist/features/fine-tune/types.js.map +1 -0
  59. package/dist/features/rag/chunker.d.ts +42 -0
  60. package/dist/features/rag/chunker.d.ts.map +1 -0
  61. package/dist/features/rag/chunker.js +115 -0
  62. package/dist/features/rag/chunker.js.map +1 -0
  63. package/dist/features/rag/in-memory-store.d.ts +21 -0
  64. package/dist/features/rag/in-memory-store.d.ts.map +1 -0
  65. package/dist/features/rag/in-memory-store.js +81 -0
  66. package/dist/features/rag/in-memory-store.js.map +1 -0
  67. package/dist/features/rag/index.d.ts +15 -0
  68. package/dist/features/rag/index.d.ts.map +1 -0
  69. package/dist/features/rag/index.js +14 -0
  70. package/dist/features/rag/index.js.map +1 -0
  71. package/dist/features/rag/pipeline.d.ts +92 -0
  72. package/dist/features/rag/pipeline.d.ts.map +1 -0
  73. package/dist/features/rag/pipeline.js +102 -0
  74. package/dist/features/rag/pipeline.js.map +1 -0
  75. package/dist/features/rag/retriever.d.ts +71 -0
  76. package/dist/features/rag/retriever.d.ts.map +1 -0
  77. package/dist/features/rag/retriever.js +99 -0
  78. package/dist/features/rag/retriever.js.map +1 -0
  79. package/dist/features/rag/vector-store.d.ts +43 -0
  80. package/dist/features/rag/vector-store.d.ts.map +1 -0
  81. package/dist/features/rag/vector-store.js +8 -0
  82. package/dist/features/rag/vector-store.js.map +1 -0
  83. package/dist/frameworks/angular/angular-shim.d.ts +19 -0
  84. package/dist/frameworks/angular/angular-shim.d.ts.map +1 -0
  85. package/dist/frameworks/angular/angular-shim.js +22 -0
  86. package/dist/frameworks/angular/angular-shim.js.map +1 -0
  87. package/dist/frameworks/angular/chat.service.d.ts +53 -0
  88. package/dist/frameworks/angular/chat.service.d.ts.map +1 -0
  89. package/dist/frameworks/angular/chat.service.js +154 -0
  90. package/dist/frameworks/angular/chat.service.js.map +1 -0
  91. package/dist/frameworks/angular/completion.service.d.ts +34 -0
  92. package/dist/frameworks/angular/completion.service.d.ts.map +1 -0
  93. package/dist/frameworks/angular/completion.service.js +114 -0
  94. package/dist/frameworks/angular/completion.service.js.map +1 -0
  95. package/dist/frameworks/angular/index.d.ts +12 -0
  96. package/dist/frameworks/angular/index.d.ts.map +1 -0
  97. package/dist/frameworks/angular/index.js +9 -0
  98. package/dist/frameworks/angular/index.js.map +1 -0
  99. package/dist/frameworks/angular/object.service.d.ts +34 -0
  100. package/dist/frameworks/angular/object.service.d.ts.map +1 -0
  101. package/dist/frameworks/angular/object.service.js +119 -0
  102. package/dist/frameworks/angular/object.service.js.map +1 -0
  103. package/dist/frameworks/astro/endpoints.d.ts +42 -0
  104. package/dist/frameworks/astro/endpoints.d.ts.map +1 -0
  105. package/dist/frameworks/astro/endpoints.js +75 -0
  106. package/dist/frameworks/astro/endpoints.js.map +1 -0
  107. package/dist/frameworks/astro/hooks.d.ts +29 -0
  108. package/dist/frameworks/astro/hooks.d.ts.map +1 -0
  109. package/dist/frameworks/astro/hooks.js +80 -0
  110. package/dist/frameworks/astro/hooks.js.map +1 -0
  111. package/dist/frameworks/astro/index.d.ts +8 -0
  112. package/dist/frameworks/astro/index.d.ts.map +1 -0
  113. package/dist/frameworks/astro/index.js +8 -0
  114. package/dist/frameworks/astro/index.js.map +1 -0
  115. package/dist/frameworks/nextjs/client.d.ts +13 -0
  116. package/dist/frameworks/nextjs/client.d.ts.map +1 -0
  117. package/dist/frameworks/nextjs/client.js +8 -0
  118. package/dist/frameworks/nextjs/client.js.map +1 -0
  119. package/dist/frameworks/nextjs/index.d.ts +21 -0
  120. package/dist/frameworks/nextjs/index.d.ts.map +1 -0
  121. package/dist/frameworks/nextjs/index.js +20 -0
  122. package/dist/frameworks/nextjs/index.js.map +1 -0
  123. package/dist/frameworks/nextjs/route-handlers.d.ts +62 -0
  124. package/dist/frameworks/nextjs/route-handlers.d.ts.map +1 -0
  125. package/dist/frameworks/nextjs/route-handlers.js +74 -0
  126. package/dist/frameworks/nextjs/route-handlers.js.map +1 -0
  127. package/dist/frameworks/nextjs/server.d.ts +78 -0
  128. package/dist/frameworks/nextjs/server.d.ts.map +1 -0
  129. package/dist/frameworks/nextjs/server.js +89 -0
  130. package/dist/frameworks/nextjs/server.js.map +1 -0
  131. package/dist/frameworks/nextjs/signal-shim.d.ts +9 -0
  132. package/dist/frameworks/nextjs/signal-shim.d.ts.map +1 -0
  133. package/dist/frameworks/nextjs/signal-shim.js +14 -0
  134. package/dist/frameworks/nextjs/signal-shim.js.map +1 -0
  135. package/dist/frameworks/nextjs/use-chat.d.ts +22 -0
  136. package/dist/frameworks/nextjs/use-chat.d.ts.map +1 -0
  137. package/dist/frameworks/nextjs/use-chat.js +89 -0
  138. package/dist/frameworks/nextjs/use-chat.js.map +1 -0
  139. package/dist/frameworks/nextjs/use-completion.d.ts +18 -0
  140. package/dist/frameworks/nextjs/use-completion.d.ts.map +1 -0
  141. package/dist/frameworks/nextjs/use-completion.js +67 -0
  142. package/dist/frameworks/nextjs/use-completion.js.map +1 -0
  143. package/dist/frameworks/qwik/index.d.ts +11 -0
  144. package/dist/frameworks/qwik/index.d.ts.map +1 -0
  145. package/dist/frameworks/qwik/index.js +11 -0
  146. package/dist/frameworks/qwik/index.js.map +1 -0
  147. package/dist/frameworks/qwik/signal-shim.d.ts +11 -0
  148. package/dist/frameworks/qwik/signal-shim.d.ts.map +1 -0
  149. package/dist/frameworks/qwik/signal-shim.js +15 -0
  150. package/dist/frameworks/qwik/signal-shim.js.map +1 -0
  151. package/dist/frameworks/qwik/use-chat.d.ts +28 -0
  152. package/dist/frameworks/qwik/use-chat.d.ts.map +1 -0
  153. package/dist/frameworks/qwik/use-chat.js +91 -0
  154. package/dist/frameworks/qwik/use-chat.js.map +1 -0
  155. package/dist/frameworks/qwik/use-completion.d.ts +20 -0
  156. package/dist/frameworks/qwik/use-completion.d.ts.map +1 -0
  157. package/dist/frameworks/qwik/use-completion.js +69 -0
  158. package/dist/frameworks/qwik/use-completion.js.map +1 -0
  159. package/dist/frameworks/react/index.d.ts +14 -0
  160. package/dist/frameworks/react/index.d.ts.map +1 -0
  161. package/dist/frameworks/react/index.js +10 -0
  162. package/dist/frameworks/react/index.js.map +1 -0
  163. package/dist/frameworks/react/stream-parser.d.ts +8 -0
  164. package/dist/frameworks/react/stream-parser.d.ts.map +1 -0
  165. package/dist/frameworks/react/stream-parser.js +42 -0
  166. package/dist/frameworks/react/stream-parser.js.map +1 -0
  167. package/dist/frameworks/react/use-chat.d.ts +19 -0
  168. package/dist/frameworks/react/use-chat.d.ts.map +1 -0
  169. package/dist/frameworks/react/use-chat.js +173 -0
  170. package/dist/frameworks/react/use-chat.js.map +1 -0
  171. package/dist/frameworks/react/use-completion.d.ts +11 -0
  172. package/dist/frameworks/react/use-completion.d.ts.map +1 -0
  173. package/dist/frameworks/react/use-completion.js +91 -0
  174. package/dist/frameworks/react/use-completion.js.map +1 -0
  175. package/dist/frameworks/react/use-object.d.ts +45 -0
  176. package/dist/frameworks/react/use-object.d.ts.map +1 -0
  177. package/dist/frameworks/react/use-object.js +100 -0
  178. package/dist/frameworks/react/use-object.js.map +1 -0
  179. package/dist/frameworks/remix/actions.d.ts +38 -0
  180. package/dist/frameworks/remix/actions.d.ts.map +1 -0
  181. package/dist/frameworks/remix/actions.js +72 -0
  182. package/dist/frameworks/remix/actions.js.map +1 -0
  183. package/dist/frameworks/remix/hooks.d.ts +40 -0
  184. package/dist/frameworks/remix/hooks.d.ts.map +1 -0
  185. package/dist/frameworks/remix/hooks.js +97 -0
  186. package/dist/frameworks/remix/hooks.js.map +1 -0
  187. package/dist/frameworks/remix/index.d.ts +8 -0
  188. package/dist/frameworks/remix/index.d.ts.map +1 -0
  189. package/dist/frameworks/remix/index.js +8 -0
  190. package/dist/frameworks/remix/index.js.map +1 -0
  191. package/dist/frameworks/solid/index.d.ts +13 -0
  192. package/dist/frameworks/solid/index.d.ts.map +1 -0
  193. package/dist/frameworks/solid/index.js +13 -0
  194. package/dist/frameworks/solid/index.js.map +1 -0
  195. package/dist/frameworks/solid/solid-shim.d.ts +13 -0
  196. package/dist/frameworks/solid/solid-shim.d.ts.map +1 -0
  197. package/dist/frameworks/solid/solid-shim.js +15 -0
  198. package/dist/frameworks/solid/solid-shim.js.map +1 -0
  199. package/dist/frameworks/solid/use-chat.d.ts +28 -0
  200. package/dist/frameworks/solid/use-chat.d.ts.map +1 -0
  201. package/dist/frameworks/solid/use-chat.js +91 -0
  202. package/dist/frameworks/solid/use-chat.js.map +1 -0
  203. package/dist/frameworks/solid/use-completion.d.ts +20 -0
  204. package/dist/frameworks/solid/use-completion.d.ts.map +1 -0
  205. package/dist/frameworks/solid/use-completion.js +66 -0
  206. package/dist/frameworks/solid/use-completion.js.map +1 -0
  207. package/dist/frameworks/solid/use-object.d.ts +19 -0
  208. package/dist/frameworks/solid/use-object.d.ts.map +1 -0
  209. package/dist/frameworks/solid/use-object.js +70 -0
  210. package/dist/frameworks/solid/use-object.js.map +1 -0
  211. package/dist/frameworks/svelte/index.d.ts +15 -0
  212. package/dist/frameworks/svelte/index.d.ts.map +1 -0
  213. package/dist/frameworks/svelte/index.js +11 -0
  214. package/dist/frameworks/svelte/index.js.map +1 -0
  215. package/dist/frameworks/svelte/stream-parser.d.ts +8 -0
  216. package/dist/frameworks/svelte/stream-parser.d.ts.map +1 -0
  217. package/dist/frameworks/svelte/stream-parser.js +42 -0
  218. package/dist/frameworks/svelte/stream-parser.js.map +1 -0
  219. package/dist/frameworks/svelte/use-chat.d.ts +31 -0
  220. package/dist/frameworks/svelte/use-chat.d.ts.map +1 -0
  221. package/dist/frameworks/svelte/use-chat.js +146 -0
  222. package/dist/frameworks/svelte/use-chat.js.map +1 -0
  223. package/dist/frameworks/svelte/use-completion.d.ts +25 -0
  224. package/dist/frameworks/svelte/use-completion.d.ts.map +1 -0
  225. package/dist/frameworks/svelte/use-completion.js +108 -0
  226. package/dist/frameworks/svelte/use-completion.js.map +1 -0
  227. package/dist/frameworks/svelte/use-object.d.ts +28 -0
  228. package/dist/frameworks/svelte/use-object.d.ts.map +1 -0
  229. package/dist/frameworks/svelte/use-object.js +122 -0
  230. package/dist/frameworks/svelte/use-object.js.map +1 -0
  231. package/dist/frameworks/vue/index.d.ts +12 -0
  232. package/dist/frameworks/vue/index.d.ts.map +1 -0
  233. package/dist/frameworks/vue/index.js +10 -0
  234. package/dist/frameworks/vue/index.js.map +1 -0
  235. package/dist/frameworks/vue/stream-parser.d.ts +8 -0
  236. package/dist/frameworks/vue/stream-parser.d.ts.map +1 -0
  237. package/dist/frameworks/vue/stream-parser.js +42 -0
  238. package/dist/frameworks/vue/stream-parser.js.map +1 -0
  239. package/dist/frameworks/vue/use-chat.d.ts +64 -0
  240. package/dist/frameworks/vue/use-chat.d.ts.map +1 -0
  241. package/dist/frameworks/vue/use-chat.js +119 -0
  242. package/dist/frameworks/vue/use-chat.js.map +1 -0
  243. package/dist/frameworks/vue/use-completion.d.ts +18 -0
  244. package/dist/frameworks/vue/use-completion.d.ts.map +1 -0
  245. package/dist/frameworks/vue/use-completion.js +87 -0
  246. package/dist/frameworks/vue/use-completion.js.map +1 -0
  247. package/dist/frameworks/vue/use-object.d.ts +22 -0
  248. package/dist/frameworks/vue/use-object.d.ts.map +1 -0
  249. package/dist/frameworks/vue/use-object.js +101 -0
  250. package/dist/frameworks/vue/use-object.js.map +1 -0
  251. package/package.json +97 -1
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @hilbras/agent — Agent Types
3
+ *
4
+ * Core types for the agent framework.
5
+ */
6
+ export interface AgentTool {
7
+ name: string;
8
+ description: string;
9
+ parameters: Record<string, unknown>;
10
+ execute: (params: Record<string, unknown>, context: ToolContext) => Promise<unknown>;
11
+ }
12
+ export interface ToolContext {
13
+ /** Current step number (0-indexed) */
14
+ step: number;
15
+ /** Maximum allowed steps */
16
+ maxSteps: number;
17
+ /** Total cost so far in dollars */
18
+ totalCost: number;
19
+ /** Budget limit in dollars (null = no limit) */
20
+ budget: number | null;
21
+ /** Whether this tool call needs approval */
22
+ needsApproval: boolean;
23
+ /** Signal for cancellation */
24
+ signal?: AbortSignal;
25
+ }
26
+ export interface AgentStep {
27
+ /** Step number */
28
+ step: number;
29
+ /** LLM response content */
30
+ content: string;
31
+ /** Tool calls made in this step */
32
+ toolCalls: ToolCallRecord[];
33
+ /** Whether the agent wants to continue */
34
+ done: boolean;
35
+ /** Token usage for this step */
36
+ usage: StepUsage;
37
+ }
38
+ export interface ToolCallRecord {
39
+ /** Tool name */
40
+ name: string;
41
+ /** Arguments passed to the tool */
42
+ args: Record<string, unknown>;
43
+ /** Tool result */
44
+ result: unknown;
45
+ /** Error if tool failed */
46
+ error?: string;
47
+ /** Whether this call was approved by the user */
48
+ approved?: boolean;
49
+ }
50
+ export interface StepUsage {
51
+ promptTokens: number;
52
+ completionTokens: number;
53
+ totalTokens: number;
54
+ estimatedCost: number;
55
+ }
56
+ export interface AgentResult {
57
+ /** Final answer from the agent */
58
+ answer: string;
59
+ /** All steps taken */
60
+ steps: AgentStep[];
61
+ /** Total steps taken */
62
+ totalSteps: number;
63
+ /** Whether the agent completed within budget */
64
+ withinBudget: boolean;
65
+ /** Total cost in dollars */
66
+ totalCost: number;
67
+ /** Total token usage */
68
+ usage: StepUsage;
69
+ /** Whether the agent was interrupted (e.g., by approval) */
70
+ interrupted: boolean;
71
+ }
72
+ export interface AgentConfig {
73
+ /** Provider name */
74
+ provider: string;
75
+ /** Model ID */
76
+ model: string;
77
+ /** Maximum number of steps (default: 10) */
78
+ maxSteps?: number;
79
+ /** Budget limit in dollars (null = no limit) */
80
+ budget?: number | null;
81
+ /** System prompt */
82
+ systemPrompt?: string;
83
+ /** Temperature (default: 0) */
84
+ temperature?: number;
85
+ /** Abort signal */
86
+ signal?: AbortSignal;
87
+ /** Whether to stream intermediate steps */
88
+ stream?: boolean;
89
+ }
90
+ export interface ApprovalRequest {
91
+ /** Step number */
92
+ step: number;
93
+ /** Tool name */
94
+ toolName: string;
95
+ /** Arguments */
96
+ args: Record<string, unknown>;
97
+ /** Approve or reject */
98
+ approve: boolean;
99
+ }
100
+ export type AgentEvent = {
101
+ type: "step_start";
102
+ step: number;
103
+ } | {
104
+ type: "step_complete";
105
+ step: AgentStep;
106
+ } | {
107
+ type: "tool_call";
108
+ step: number;
109
+ tool: string;
110
+ args: Record<string, unknown>;
111
+ } | {
112
+ type: "tool_result";
113
+ step: number;
114
+ tool: string;
115
+ result: unknown;
116
+ } | {
117
+ type: "approval_needed";
118
+ step: number;
119
+ tool: string;
120
+ args: Record<string, unknown>;
121
+ } | {
122
+ type: "approval_granted";
123
+ step: number;
124
+ tool: string;
125
+ } | {
126
+ type: "approval_rejected";
127
+ step: number;
128
+ tool: string;
129
+ } | {
130
+ type: "done";
131
+ result: AgentResult;
132
+ } | {
133
+ type: "error";
134
+ error: Error;
135
+ };
136
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/features/agent/types.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IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAChF;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GACtF;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @hilbras/agent — Agent Types
3
+ *
4
+ * Core types for the agent framework.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/features/agent/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @hilbras/eval — Evaluate
3
+ *
4
+ * Core evaluation function that runs metrics against a dataset.
5
+ */
6
+ import type { EvalDataset, EvalConfig, EvalResult } from "./types.js";
7
+ export declare class UnknownMetricError extends Error {
8
+ constructor(metric: string);
9
+ }
10
+ /**
11
+ * Evaluate a dataset against metrics.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const result = await evaluate({
16
+ * dataset: {
17
+ * name: "math-qa",
18
+ * items: [
19
+ * { id: "1", input: "What is 2+2?", expected: "4" },
20
+ * { id: "2", input: "What is 3+3?", expected: "6" },
21
+ * ],
22
+ * },
23
+ * config: {
24
+ * metrics: [
25
+ * { name: "exact_match", threshold: 1 },
26
+ * { name: "contains", threshold: 0.5 },
27
+ * ],
28
+ * },
29
+ * });
30
+ * console.log(result.passRate); // 1.0
31
+ * ```
32
+ */
33
+ export declare function evaluate(params: {
34
+ dataset: EvalDataset;
35
+ config: EvalConfig;
36
+ /** Function to generate output from input */
37
+ generate: (input: string) => Promise<string>;
38
+ }): Promise<EvalResult>;
39
+ //# sourceMappingURL=evaluate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../src/features/eval/evaluate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EAEX,UAAU,EACV,UAAU,EAKX,MAAM,YAAY,CAAC;AAgBpB,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,MAAM,EAAE,MAAM,EAGzB;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,QAAQ,CAAC,MAAM,EAAE;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,UAAU,CAAC;IACnB,6CAA6C;IAC7C,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9C,GAAG,OAAO,CAAC,UAAU,CAAC,CAmHtB"}
@@ -0,0 +1,153 @@
1
+ /**
2
+ * @hilbras/eval — Evaluate
3
+ *
4
+ * Core evaluation function that runs metrics against a dataset.
5
+ */
6
+ import { exactMatch, contains, similarity, toxicity, coherence } from "./metrics.js";
7
+ function getMetricFn(name, config) {
8
+ switch (name) {
9
+ case "exact_match": return exactMatch;
10
+ case "contains": return contains;
11
+ case "similarity": return similarity;
12
+ case "toxicity": return toxicity;
13
+ case "coherence": return coherence;
14
+ default:
15
+ if (config?.custom)
16
+ return config.custom;
17
+ throw new UnknownMetricError(name);
18
+ }
19
+ }
20
+ export class UnknownMetricError extends Error {
21
+ constructor(metric) {
22
+ super(`Unknown metric "${metric}". Use built-in metrics (exact_match, contains, similarity, toxicity, coherence) or provide a custom function.`);
23
+ this.name = "UnknownMetricError";
24
+ }
25
+ }
26
+ /**
27
+ * Evaluate a dataset against metrics.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const result = await evaluate({
32
+ * dataset: {
33
+ * name: "math-qa",
34
+ * items: [
35
+ * { id: "1", input: "What is 2+2?", expected: "4" },
36
+ * { id: "2", input: "What is 3+3?", expected: "6" },
37
+ * ],
38
+ * },
39
+ * config: {
40
+ * metrics: [
41
+ * { name: "exact_match", threshold: 1 },
42
+ * { name: "contains", threshold: 0.5 },
43
+ * ],
44
+ * },
45
+ * });
46
+ * console.log(result.passRate); // 1.0
47
+ * ```
48
+ */
49
+ export async function evaluate(params) {
50
+ const { dataset, config, generate } = params;
51
+ const { metrics: metricConfigs, concurrency = 5, signal, onEvent } = config;
52
+ const startTime = Date.now();
53
+ const results = [];
54
+ // Process items with concurrency limit
55
+ const queue = [...dataset.items.entries()];
56
+ const active = [];
57
+ async function processItem(index, item) {
58
+ if (signal?.aborted)
59
+ return;
60
+ onEvent?.({ type: "item_start", index, item });
61
+ let output;
62
+ try {
63
+ output = await generate(item.input);
64
+ }
65
+ catch (error) {
66
+ const result = {
67
+ item,
68
+ output: "",
69
+ metrics: [],
70
+ passed: false,
71
+ error: error.message,
72
+ };
73
+ results[index] = result;
74
+ onEvent?.({ type: "item_complete", index, result });
75
+ return;
76
+ }
77
+ // Compute metrics
78
+ const metricResults = [];
79
+ let allPassed = true;
80
+ for (const metricConfig of metricConfigs) {
81
+ if (signal?.aborted)
82
+ break;
83
+ const threshold = metricConfig.threshold ?? 0.7;
84
+ const metricFn = getMetricFn(metricConfig.name, metricConfig);
85
+ try {
86
+ const metricResult = await metricFn(output, item);
87
+ // Override threshold
88
+ metricResult.passed = metricResult.score >= threshold;
89
+ metricResults.push(metricResult);
90
+ if (!metricResult.passed)
91
+ allPassed = false;
92
+ onEvent?.({ type: "metric_complete", index, metric: metricResult });
93
+ }
94
+ catch (error) {
95
+ metricResults.push({
96
+ name: metricConfig.name,
97
+ score: 0,
98
+ passed: false,
99
+ explanation: error.message,
100
+ });
101
+ allPassed = false;
102
+ }
103
+ }
104
+ const result = {
105
+ item,
106
+ output,
107
+ metrics: metricResults,
108
+ passed: allPassed,
109
+ };
110
+ results[index] = result;
111
+ onEvent?.({ type: "item_complete", index, result });
112
+ }
113
+ // Process with concurrency
114
+ while (queue.length > 0 || active.length > 0) {
115
+ while (active.length < concurrency && queue.length > 0) {
116
+ const [index, item] = queue.shift();
117
+ const p = processItem(index, item).then(() => {
118
+ active.splice(active.indexOf(p), 1);
119
+ });
120
+ active.push(p);
121
+ }
122
+ if (active.length > 0) {
123
+ await Promise.race(active);
124
+ }
125
+ }
126
+ // Compute aggregates
127
+ const validResults = results.filter(Boolean);
128
+ const totalItems = validResults.length;
129
+ const passedItems = validResults.filter((r) => r.passed).length;
130
+ const aggregates = {};
131
+ for (const metricConfig of metricConfigs) {
132
+ const metricScores = validResults
133
+ .map((r) => r.metrics.find((m) => m.name === metricConfig.name))
134
+ .filter(Boolean)
135
+ .map((m) => m.score);
136
+ aggregates[metricConfig.name] = metricScores.length > 0
137
+ ? metricScores.reduce((a, b) => a + b, 0) / metricScores.length
138
+ : 0;
139
+ }
140
+ const evalResult = {
141
+ dataset: dataset.name,
142
+ items: validResults,
143
+ aggregates,
144
+ passRate: totalItems > 0 ? passedItems / totalItems : 0,
145
+ totalItems,
146
+ passedItems,
147
+ failedItems: totalItems - passedItems,
148
+ durationMs: Date.now() - startTime,
149
+ };
150
+ onEvent?.({ type: "complete", result: evalResult });
151
+ return evalResult;
152
+ }
153
+ //# sourceMappingURL=evaluate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../../src/features/eval/evaluate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAErF,SAAS,WAAW,CAAC,IAAY,EAAE,MAAqB;IACtD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,aAAa,EAAE,OAAO,UAAU,CAAC;QACtC,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;QACjC,KAAK,YAAY,EAAE,OAAO,UAAU,CAAC;QACrC,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;QACjC,KAAK,WAAW,EAAE,OAAO,SAAS,CAAC;QACnC;YACE,IAAI,MAAM,EAAE,MAAM;gBAAE,OAAO,MAAM,CAAC,MAAM,CAAC;YACzC,MAAM,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,MAAc;QACxB,KAAK,CAAC,mBAAmB,MAAM,gHAAgH,CAAC,CAAC;QACjJ,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,MAK9B;IACC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAC7C,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAE5E,MAAM,SAAS,G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ED,MAAM,UAAU,GAAe;QAC7B,OAAO,EAAE,OAAO,CAAC,IAAI;QACrB,KAAK,EAAE,YAAY;QACnB,UAAU;QACV,QAAQ,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QACvD,UAAU;QACV,WAAW;QACX,WAAW,EAAE,UAAU,GAAG,WAAW;QACrC,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;KACnC,CAAC;IAEF,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACpD,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @hilbras/eval — Evaluation & Testing Framework
3
+ *
4
+ * LLM output evaluation with built-in metrics and custom metric support.
5
+ */
6
+ export { evaluate, UnknownMetricError } from "./evaluate.js";
7
+ export { exactMatch, contains, similarity, toxicity, coherence, llmJudge } from "./metrics.js";
8
+ export type { EvalDataset, EvalDatasetItem, EvalConfig, EvalResult, EvalItemResult, MetricConfig, MetricResult, MetricName, EvalEvent, } from "./types.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/eval/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC/F,YAAY,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,SAAS,GACV,MAAM,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @hilbras/eval — Evaluation & Testing Framework
3
+ *
4
+ * LLM output evaluation with built-in metrics and custom metric support.
5
+ */
6
+ export { evaluate, UnknownMetricError } from "./evaluate.js";
7
+ export { exactMatch, contains, similarity, toxicity, coherence, llmJudge } from "./metrics.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/features/eval/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @hilbras/eval — Metrics
3
+ *
4
+ * Built-in metrics for evaluating LLM outputs.
5
+ */
6
+ import type { MetricResult, EvalDatasetItem } from "./types.js";
7
+ /**
8
+ * Exact string match (case-insensitive, trimmed).
9
+ */
10
+ export declare function exactMatch(output: string, item: EvalDatasetItem): MetricResult;
11
+ /**
12
+ * Output contains expected substring.
13
+ */
14
+ export declare function contains(output: string, item: EvalDatasetItem): MetricResult;
15
+ /**
16
+ * Semantic similarity using simple word overlap (Jaccard).
17
+ * For production, use embeddings-based similarity.
18
+ */
19
+ export declare function similarity(output: string, item: EvalDatasetItem): MetricResult;
20
+ /**
21
+ * Toxicity check — detects common toxic phrases.
22
+ * Simple heuristic; for production use a dedicated toxicity model.
23
+ */
24
+ export declare function toxicity(output: string, _item: EvalDatasetItem): MetricResult;
25
+ /**
26
+ * Coherence check — simple heuristic based on sentence structure.
27
+ */
28
+ export declare function coherence(output: string, _item: EvalDatasetItem): MetricResult;
29
+ /**
30
+ * LLM-as-judge metric — uses an LLM to evaluate the output.
31
+ */
32
+ export declare function llmJudge(llm: (messages: Array<{
33
+ role: string;
34
+ content: string;
35
+ }>) => Promise<{
36
+ content: string;
37
+ }>): (output: string, item: EvalDatasetItem) => Promise<MetricResult>;
38
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/features/eval/metrics.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEhE;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,YAAY,CAS9E;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,YAAY,CAS5E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,YAAY,CAkB9E;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,YAAY,CAiB7E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,YAAY,CAgB9E;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,KAAK,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,YAEnE,MAAM,QAAQ,eAAe,KAAG,OAAO,CAAC,YAAY,CAAC,CAuC5E"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @hilbras/eval — Metrics
3
+ *
4
+ * Built-in metrics for evaluating LLM outputs.
5
+ */
6
+ /**
7
+ * Exact string match (case-insensitive, trimmed).
8
+ */
9
+ export function exactMatch(output, item) {
10
+ const passed = item.expected !== undefined &&
11
+ output.trim().toLowerCase() === item.expected.trim().toLowerCase();
12
+ return {
13
+ name: "exact_match",
14
+ score: passed ? 1 : 0,
15
+ passed,
16
+ explanation: passed ? "Exact match" : `Expected "${item.expected}", got "${output.trim()}"`,
17
+ };
18
+ }
19
+ /**
20
+ * Output contains expected substring.
21
+ */
22
+ export function contains(output, item) {
23
+ const passed = item.expected !== undefined &&
24
+ output.toLowerCase().includes(item.expected.toLowerCase());
25
+ return {
26
+ name: "contains",
27
+ score: passed ? 1 : 0,
28
+ passed,
29
+ explanation: passed ? "Contains expected substring" : `Missing "${item.expected}"`,
30
+ };
31
+ }
32
+ /**
33
+ * Semantic similarity using simple word overlap (Jaccard).
34
+ * For production, use embeddings-based similarity.
35
+ */
36
+ export function similarity(output, item) {
37
+ if (!item.expected) {
38
+ return { name: "similarity", score: 0, passed: false, explanation: "No expected output" };
39
+ }
40
+ const wordsA = new Set(output.toLowerCase().split(/\s+/).filter(Boolean));
41
+ const wordsB = new Set(item.expected.toLowerCase().split(/\s+/).filter(Boolean));
42
+ const intersection = new Set([...wordsA].filter((w) => wordsB.has(w)));
43
+ const union = new Set([...wordsA, ...wordsB]);
44
+ const score = union.size === 0 ? 0 : intersection.size / union.size;
45
+ const passed = score >= 0.5;
46
+ return {
47
+ name: "similarity",
48
+ score,
49
+ passed,
50
+ explanation: `Jaccard similarity: ${score.toFixed(3)}`,
51
+ };
52
+ }
53
+ /**
54
+ * Toxicity check — detects common toxic phrases.
55
+ * Simple heuristic; for production use a dedicated toxicity model.
56
+ */
57
+ export function toxicity(output, _item) {
58
+ const toxicPatterns = [
59
+ /\b(hate|kill|die|stupid|idiot|dumb)\b/i,
60
+ /\b(racist|sexist|homophobic)\b/i,
61
+ /\b(threat|attack|harm)\b/i,
62
+ ];
63
+ const detected = toxicPatterns.some((p) => p.test(output));
64
+ const score = detected ? 1 : 0; // 1 = toxic (bad)
65
+ const passed = !detected; // pass if NOT toxic
66
+ return {
67
+ name: "toxicity",
68
+ score,
69
+ passed,
70
+ explanation: detected ? "Toxic content detected" : "No toxic content",
71
+ };
72
+ }
73
+ /**
74
+ * Coherence check — simple heuristic based on sentence structure.
75
+ */
76
+ export function coherence(output, _item) {
77
+ const sentences = output.split(/[.!?]+/).filter((s) => s.trim().length > 0);
78
+ const words = output.split(/\s+/).filter(Boolean);
79
+ const avgSentenceLength = words.length / Math.max(sentences.length, 1);
80
+ // Very short or very long sentences suggest poor coherence
81
+ const score = avgSentenceLength >= 3 && avgSentenceLength <= 40 ? 1 :
82
+ avgSentenceLength >= 1 && avgSentenceLength <= 60 ? 0.7 : 0.3;
83
+ const passed = score >= 0.7;
84
+ return {
85
+ name: "coherence",
86
+ score,
87
+ passed,
88
+ explanation: `Avg sentence length: ${avgSentenceLength.toFixed(1)} words`,
89
+ };
90
+ }
91
+ /**
92
+ * LLM-as-judge metric — uses an LLM to evaluate the output.
93
+ */
94
+ export function llmJudge(llm) {
95
+ return async (output, item) => {
96
+ const contextStr = item.context?.length ? `\n\nContext:\n${item.context.join("\n")}` : "";
97
+ const expectedStr = item.expected ? `\n\nExpected:\n${item.expected}` : "";
98
+ const prompt = `You are an evaluation judge. Rate the following output on a scale of 0-1.
99
+
100
+ Input: ${item.input}${contextStr}${expectedStr}
101
+
102
+ Output to evaluate:
103
+ ${output}
104
+
105
+ Respond with ONLY a JSON object:
106
+ {"score": <0-1>, "explanation": "<brief explanation>"}`;
107
+ try {
108
+ const response = await llm([{ role: "user", content: prompt }]);
109
+ const match = response.content.match(/\{[^}]+\}/);
110
+ if (match) {
111
+ const parsed = JSON.parse(match[0]);
112
+ const score = Math.max(0, Math.min(1, Number(parsed.score) || 0));
113
+ return {
114
+ name: "llm_judge",
115
+ score,
116
+ passed: score >= 0.7,
117
+ explanation: parsed.explanation || "",
118
+ raw: parsed,
119
+ };
120
+ }
121
+ }
122
+ catch {
123
+ // Fall through to default
124
+ }
125
+ return {
126
+ name: "llm_judge",
127
+ score: 0,
128
+ passed: false,
129
+ explanation: "Failed to get LLM judge evaluation",
130
+ };
131
+ };
132
+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