@cogenta/agents 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 (293) hide show
  1. package/dist/agents/define.d.ts +9 -0
  2. package/dist/agents/define.d.ts.map +1 -0
  3. package/dist/agents/define.js +25 -0
  4. package/dist/agents/define.js.map +1 -0
  5. package/dist/agents/registry.d.ts +29 -0
  6. package/dist/agents/registry.d.ts.map +1 -0
  7. package/dist/agents/registry.js +50 -0
  8. package/dist/agents/registry.js.map +1 -0
  9. package/dist/agents/types.d.ts +36 -0
  10. package/dist/agents/types.d.ts.map +1 -0
  11. package/dist/agents/types.js +2 -0
  12. package/dist/agents/types.js.map +1 -0
  13. package/dist/audit/types.d.ts +23 -0
  14. package/dist/audit/types.d.ts.map +1 -0
  15. package/dist/audit/types.js +2 -0
  16. package/dist/audit/types.js.map +1 -0
  17. package/dist/audit/with-audit.d.ts +34 -0
  18. package/dist/audit/with-audit.d.ts.map +1 -0
  19. package/dist/audit/with-audit.js +65 -0
  20. package/dist/audit/with-audit.js.map +1 -0
  21. package/dist/autonomy/approval-queue.d.ts +13 -0
  22. package/dist/autonomy/approval-queue.d.ts.map +1 -0
  23. package/dist/autonomy/approval-queue.js +56 -0
  24. package/dist/autonomy/approval-queue.js.map +1 -0
  25. package/dist/autonomy/types.d.ts +36 -0
  26. package/dist/autonomy/types.d.ts.map +1 -0
  27. package/dist/autonomy/types.js +2 -0
  28. package/dist/autonomy/types.js.map +1 -0
  29. package/dist/autonomy/with-autonomy.d.ts +25 -0
  30. package/dist/autonomy/with-autonomy.d.ts.map +1 -0
  31. package/dist/autonomy/with-autonomy.js +77 -0
  32. package/dist/autonomy/with-autonomy.js.map +1 -0
  33. package/dist/budget/kill-switch.d.ts +14 -0
  34. package/dist/budget/kill-switch.d.ts.map +1 -0
  35. package/dist/budget/kill-switch.js +20 -0
  36. package/dist/budget/kill-switch.js.map +1 -0
  37. package/dist/budget/tracker.d.ts +15 -0
  38. package/dist/budget/tracker.d.ts.map +1 -0
  39. package/dist/budget/tracker.js +68 -0
  40. package/dist/budget/tracker.js.map +1 -0
  41. package/dist/budget/types.d.ts +35 -0
  42. package/dist/budget/types.d.ts.map +1 -0
  43. package/dist/budget/types.js +2 -0
  44. package/dist/budget/types.js.map +1 -0
  45. package/dist/eval/assert-threshold.d.ts +15 -0
  46. package/dist/eval/assert-threshold.d.ts.map +1 -0
  47. package/dist/eval/assert-threshold.js +27 -0
  48. package/dist/eval/assert-threshold.js.map +1 -0
  49. package/dist/eval/compare-prompt-versions.d.ts +17 -0
  50. package/dist/eval/compare-prompt-versions.d.ts.map +1 -0
  51. package/dist/eval/compare-prompt-versions.js +20 -0
  52. package/dist/eval/compare-prompt-versions.js.map +1 -0
  53. package/dist/eval/run-suite.d.ts +4 -0
  54. package/dist/eval/run-suite.d.ts.map +1 -0
  55. package/dist/eval/run-suite.js +18 -0
  56. package/dist/eval/run-suite.js.map +1 -0
  57. package/dist/eval/scorers.d.ts +13 -0
  58. package/dist/eval/scorers.d.ts.map +1 -0
  59. package/dist/eval/scorers.js +33 -0
  60. package/dist/eval/scorers.js.map +1 -0
  61. package/dist/eval/types.d.ts +27 -0
  62. package/dist/eval/types.d.ts.map +1 -0
  63. package/dist/eval/types.js +2 -0
  64. package/dist/eval/types.js.map +1 -0
  65. package/dist/identity/constitution.d.ts +17 -0
  66. package/dist/identity/constitution.d.ts.map +1 -0
  67. package/dist/identity/constitution.js +33 -0
  68. package/dist/identity/constitution.js.map +1 -0
  69. package/dist/identity/context.d.ts +49 -0
  70. package/dist/identity/context.d.ts.map +1 -0
  71. package/dist/identity/context.js +67 -0
  72. package/dist/identity/context.js.map +1 -0
  73. package/dist/index.d.ts +99 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +55 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/memory/file-store.d.ts +6 -0
  78. package/dist/memory/file-store.d.ts.map +1 -0
  79. package/dist/memory/file-store.js +94 -0
  80. package/dist/memory/file-store.js.map +1 -0
  81. package/dist/memory/from-approval.d.ts +20 -0
  82. package/dist/memory/from-approval.d.ts.map +1 -0
  83. package/dist/memory/from-approval.js +38 -0
  84. package/dist/memory/from-approval.js.map +1 -0
  85. package/dist/memory/memory-store.d.ts +4 -0
  86. package/dist/memory/memory-store.d.ts.map +1 -0
  87. package/dist/memory/memory-store.js +55 -0
  88. package/dist/memory/memory-store.js.map +1 -0
  89. package/dist/memory/types.d.ts +67 -0
  90. package/dist/memory/types.d.ts.map +1 -0
  91. package/dist/memory/types.js +2 -0
  92. package/dist/memory/types.js.map +1 -0
  93. package/dist/privacy/assert-provider-allowed.d.ts +10 -0
  94. package/dist/privacy/assert-provider-allowed.d.ts.map +1 -0
  95. package/dist/privacy/assert-provider-allowed.js +20 -0
  96. package/dist/privacy/assert-provider-allowed.js.map +1 -0
  97. package/dist/privacy/redact-fields.d.ts +11 -0
  98. package/dist/privacy/redact-fields.d.ts.map +1 -0
  99. package/dist/privacy/redact-fields.js +26 -0
  100. package/dist/privacy/redact-fields.js.map +1 -0
  101. package/dist/privacy/redact-text.d.ts +4 -0
  102. package/dist/privacy/redact-text.d.ts.map +1 -0
  103. package/dist/privacy/redact-text.js +26 -0
  104. package/dist/privacy/redact-text.js.map +1 -0
  105. package/dist/privacy/types.d.ts +23 -0
  106. package/dist/privacy/types.d.ts.map +1 -0
  107. package/dist/privacy/types.js +2 -0
  108. package/dist/privacy/types.js.map +1 -0
  109. package/dist/providers/anthropic.d.ts +57 -0
  110. package/dist/providers/anthropic.d.ts.map +1 -0
  111. package/dist/providers/anthropic.js +130 -0
  112. package/dist/providers/anthropic.js.map +1 -0
  113. package/dist/providers/google.d.ts +63 -0
  114. package/dist/providers/google.d.ts.map +1 -0
  115. package/dist/providers/google.js +144 -0
  116. package/dist/providers/google.js.map +1 -0
  117. package/dist/providers/openai.d.ts +56 -0
  118. package/dist/providers/openai.d.ts.map +1 -0
  119. package/dist/providers/openai.js +143 -0
  120. package/dist/providers/openai.js.map +1 -0
  121. package/dist/providers/registry.d.ts +31 -0
  122. package/dist/providers/registry.d.ts.map +1 -0
  123. package/dist/providers/registry.js +35 -0
  124. package/dist/providers/registry.js.map +1 -0
  125. package/dist/providers/types.d.ts +63 -0
  126. package/dist/providers/types.d.ts.map +1 -0
  127. package/dist/providers/types.js +10 -0
  128. package/dist/providers/types.js.map +1 -0
  129. package/dist/rag/chunking/chunk-document.d.ts +13 -0
  130. package/dist/rag/chunking/chunk-document.d.ts.map +1 -0
  131. package/dist/rag/chunking/chunk-document.js +51 -0
  132. package/dist/rag/chunking/chunk-document.js.map +1 -0
  133. package/dist/rag/chunking/incremental.d.ts +19 -0
  134. package/dist/rag/chunking/incremental.d.ts.map +1 -0
  135. package/dist/rag/chunking/incremental.js +24 -0
  136. package/dist/rag/chunking/incremental.js.map +1 -0
  137. package/dist/rag/chunking/types.d.ts +34 -0
  138. package/dist/rag/chunking/types.d.ts.map +1 -0
  139. package/dist/rag/chunking/types.js +2 -0
  140. package/dist/rag/chunking/types.js.map +1 -0
  141. package/dist/rag/embeddings/hashing-provider.d.ts +22 -0
  142. package/dist/rag/embeddings/hashing-provider.d.ts.map +1 -0
  143. package/dist/rag/embeddings/hashing-provider.js +53 -0
  144. package/dist/rag/embeddings/hashing-provider.js.map +1 -0
  145. package/dist/rag/embeddings/types.d.ts +16 -0
  146. package/dist/rag/embeddings/types.d.ts.map +1 -0
  147. package/dist/rag/embeddings/types.js +2 -0
  148. package/dist/rag/embeddings/types.js.map +1 -0
  149. package/dist/rag/index/bm25.d.ts +4 -0
  150. package/dist/rag/index/bm25.d.ts.map +1 -0
  151. package/dist/rag/index/bm25.js +38 -0
  152. package/dist/rag/index/bm25.js.map +1 -0
  153. package/dist/rag/index/memory-index.d.ts +12 -0
  154. package/dist/rag/index/memory-index.d.ts.map +1 -0
  155. package/dist/rag/index/memory-index.js +44 -0
  156. package/dist/rag/index/memory-index.js.map +1 -0
  157. package/dist/rag/index/rrf.d.ts +9 -0
  158. package/dist/rag/index/rrf.d.ts.map +1 -0
  159. package/dist/rag/index/rrf.js +20 -0
  160. package/dist/rag/index/rrf.js.map +1 -0
  161. package/dist/rag/index/types.d.ts +48 -0
  162. package/dist/rag/index/types.d.ts.map +1 -0
  163. package/dist/rag/index/types.js +2 -0
  164. package/dist/rag/index/types.js.map +1 -0
  165. package/dist/rag/index/vector-rank.d.ts +4 -0
  166. package/dist/rag/index/vector-rank.d.ts.map +1 -0
  167. package/dist/rag/index/vector-rank.js +27 -0
  168. package/dist/rag/index/vector-rank.js.map +1 -0
  169. package/dist/reversibility/diff.d.ts +17 -0
  170. package/dist/reversibility/diff.d.ts.map +1 -0
  171. package/dist/reversibility/diff.js +39 -0
  172. package/dist/reversibility/diff.js.map +1 -0
  173. package/dist/reversibility/receipt-store.d.ts +9 -0
  174. package/dist/reversibility/receipt-store.d.ts.map +1 -0
  175. package/dist/reversibility/receipt-store.js +34 -0
  176. package/dist/reversibility/receipt-store.js.map +1 -0
  177. package/dist/reversibility/revert.d.ts +18 -0
  178. package/dist/reversibility/revert.d.ts.map +1 -0
  179. package/dist/reversibility/revert.js +38 -0
  180. package/dist/reversibility/revert.js.map +1 -0
  181. package/dist/reversibility/types.d.ts +25 -0
  182. package/dist/reversibility/types.d.ts.map +1 -0
  183. package/dist/reversibility/types.js +2 -0
  184. package/dist/reversibility/types.js.map +1 -0
  185. package/dist/reversibility/with-receipts.d.ts +19 -0
  186. package/dist/reversibility/with-receipts.d.ts.map +1 -0
  187. package/dist/reversibility/with-receipts.js +35 -0
  188. package/dist/reversibility/with-receipts.js.map +1 -0
  189. package/dist/runtime/loop.d.ts +11 -0
  190. package/dist/runtime/loop.d.ts.map +1 -0
  191. package/dist/runtime/loop.js +116 -0
  192. package/dist/runtime/loop.js.map +1 -0
  193. package/dist/runtime/repetition.d.ts +16 -0
  194. package/dist/runtime/repetition.d.ts.map +1 -0
  195. package/dist/runtime/repetition.js +38 -0
  196. package/dist/runtime/repetition.js.map +1 -0
  197. package/dist/runtime/retry.d.ts +22 -0
  198. package/dist/runtime/retry.d.ts.map +1 -0
  199. package/dist/runtime/retry.js +69 -0
  200. package/dist/runtime/retry.js.map +1 -0
  201. package/dist/runtime/types.d.ts +78 -0
  202. package/dist/runtime/types.d.ts.map +1 -0
  203. package/dist/runtime/types.js +2 -0
  204. package/dist/runtime/types.js.map +1 -0
  205. package/dist/sandbox/types.d.ts +20 -0
  206. package/dist/sandbox/types.d.ts.map +1 -0
  207. package/dist/sandbox/types.js +2 -0
  208. package/dist/sandbox/types.js.map +1 -0
  209. package/dist/sandbox/with-sandbox.d.ts +26 -0
  210. package/dist/sandbox/with-sandbox.d.ts.map +1 -0
  211. package/dist/sandbox/with-sandbox.js +41 -0
  212. package/dist/sandbox/with-sandbox.js.map +1 -0
  213. package/dist/skills/file-store.d.ts +13 -0
  214. package/dist/skills/file-store.d.ts.map +1 -0
  215. package/dist/skills/file-store.js +73 -0
  216. package/dist/skills/file-store.js.map +1 -0
  217. package/dist/skills/frontmatter.d.ts +11 -0
  218. package/dist/skills/frontmatter.d.ts.map +1 -0
  219. package/dist/skills/frontmatter.js +46 -0
  220. package/dist/skills/frontmatter.js.map +1 -0
  221. package/dist/skills/types.d.ts +19 -0
  222. package/dist/skills/types.d.ts.map +1 -0
  223. package/dist/skills/types.js +2 -0
  224. package/dist/skills/types.js.map +1 -0
  225. package/dist/skin/generate.d.ts +22 -0
  226. package/dist/skin/generate.d.ts.map +1 -0
  227. package/dist/skin/generate.js +144 -0
  228. package/dist/skin/generate.js.map +1 -0
  229. package/dist/subagents/run-subagent.d.ts +10 -0
  230. package/dist/subagents/run-subagent.d.ts.map +1 -0
  231. package/dist/subagents/run-subagent.js +24 -0
  232. package/dist/subagents/run-subagent.js.map +1 -0
  233. package/dist/subagents/types.d.ts +13 -0
  234. package/dist/subagents/types.d.ts.map +1 -0
  235. package/dist/subagents/types.js +2 -0
  236. package/dist/subagents/types.js.map +1 -0
  237. package/dist/subagents/validate.d.ts +8 -0
  238. package/dist/subagents/validate.d.ts.map +1 -0
  239. package/dist/subagents/validate.js +32 -0
  240. package/dist/subagents/validate.js.map +1 -0
  241. package/dist/tools/core/agent-delegate.d.ts +34 -0
  242. package/dist/tools/core/agent-delegate.d.ts.map +1 -0
  243. package/dist/tools/core/agent-delegate.js +41 -0
  244. package/dist/tools/core/agent-delegate.js.map +1 -0
  245. package/dist/tools/core/content.d.ts +81 -0
  246. package/dist/tools/core/content.d.ts.map +1 -0
  247. package/dist/tools/core/content.js +121 -0
  248. package/dist/tools/core/content.js.map +1 -0
  249. package/dist/tools/core/http-fetch.d.ts +33 -0
  250. package/dist/tools/core/http-fetch.d.ts.map +1 -0
  251. package/dist/tools/core/http-fetch.js +63 -0
  252. package/dist/tools/core/http-fetch.js.map +1 -0
  253. package/dist/tools/core/media.d.ts +38 -0
  254. package/dist/tools/core/media.d.ts.map +1 -0
  255. package/dist/tools/core/media.js +93 -0
  256. package/dist/tools/core/media.js.map +1 -0
  257. package/dist/tools/core/site-config.d.ts +19 -0
  258. package/dist/tools/core/site-config.d.ts.map +1 -0
  259. package/dist/tools/core/site-config.js +37 -0
  260. package/dist/tools/core/site-config.js.map +1 -0
  261. package/dist/tools/define.d.ts +12 -0
  262. package/dist/tools/define.d.ts.map +1 -0
  263. package/dist/tools/define.js +28 -0
  264. package/dist/tools/define.js.map +1 -0
  265. package/dist/tools/manifest.d.ts +19 -0
  266. package/dist/tools/manifest.d.ts.map +1 -0
  267. package/dist/tools/manifest.js +70 -0
  268. package/dist/tools/manifest.js.map +1 -0
  269. package/dist/tools/registry.d.ts +8 -0
  270. package/dist/tools/registry.d.ts.map +1 -0
  271. package/dist/tools/registry.js +20 -0
  272. package/dist/tools/registry.js.map +1 -0
  273. package/dist/tools/types.d.ts +51 -0
  274. package/dist/tools/types.d.ts.map +1 -0
  275. package/dist/tools/types.js +2 -0
  276. package/dist/tools/types.js.map +1 -0
  277. package/dist/trace/capture.d.ts +19 -0
  278. package/dist/trace/capture.d.ts.map +1 -0
  279. package/dist/trace/capture.js +31 -0
  280. package/dist/trace/capture.js.map +1 -0
  281. package/dist/trace/file-store.d.ts +12 -0
  282. package/dist/trace/file-store.d.ts.map +1 -0
  283. package/dist/trace/file-store.js +78 -0
  284. package/dist/trace/file-store.js.map +1 -0
  285. package/dist/trace/memory-store.d.ts +9 -0
  286. package/dist/trace/memory-store.d.ts.map +1 -0
  287. package/dist/trace/memory-store.js +36 -0
  288. package/dist/trace/memory-store.js.map +1 -0
  289. package/dist/trace/types.d.ts +37 -0
  290. package/dist/trace/types.d.ts.map +1 -0
  291. package/dist/trace/types.js +2 -0
  292. package/dist/trace/types.js.map +1 -0
  293. package/package.json +44 -0
@@ -0,0 +1,143 @@
1
+ import { CogentaError } from '@cogenta/core';
2
+ const DEFAULT_BASE_URL = 'https://api.openai.com/v1/chat/completions';
3
+ const STOP_REASON = {
4
+ stop: 'end_turn',
5
+ tool_calls: 'tool_use',
6
+ length: 'max_tokens',
7
+ content_filter: 'stop_sequence',
8
+ };
9
+ function toOpenAiMessage(message) {
10
+ if (message.role === 'tool') {
11
+ if (message.toolCallId === undefined) {
12
+ throw new CogentaError({
13
+ code: 'PROVIDER_RESPONSE_INVALID',
14
+ message: 'A tool-role message is missing its toolCallId.',
15
+ hint: "Set toolCallId to the id the model's tool call carried.",
16
+ });
17
+ }
18
+ return { role: 'tool', content: message.content ?? '', tool_call_id: message.toolCallId };
19
+ }
20
+ const toolCalls = message.toolCalls ?? [];
21
+ return {
22
+ role: message.role,
23
+ content: message.content ?? null,
24
+ ...(toolCalls.length === 0
25
+ ? {}
26
+ : {
27
+ tool_calls: toolCalls.map((call) => ({
28
+ id: call.id,
29
+ type: 'function',
30
+ function: { name: call.name, arguments: JSON.stringify(call.input) },
31
+ })),
32
+ }),
33
+ };
34
+ }
35
+ /** Pure — no network. */
36
+ export function buildOpenAiRequest(request) {
37
+ const messages = [];
38
+ if (request.system !== undefined) {
39
+ messages.push({ role: 'system', content: request.system });
40
+ }
41
+ messages.push(...request.messages.map(toOpenAiMessage));
42
+ return {
43
+ model: request.model,
44
+ max_tokens: request.maxTokens,
45
+ messages,
46
+ ...(request.tools === undefined
47
+ ? {}
48
+ : {
49
+ tools: request.tools.map((tool) => ({
50
+ type: 'function',
51
+ function: {
52
+ name: tool.name,
53
+ description: tool.description,
54
+ parameters: tool.inputSchema,
55
+ },
56
+ })),
57
+ }),
58
+ ...(request.temperature === undefined ? {} : { temperature: request.temperature }),
59
+ };
60
+ }
61
+ /** Pure — no network. */
62
+ export function parseOpenAiResponse(body) {
63
+ const choice = body.choices[0];
64
+ if (choice === undefined) {
65
+ throw new CogentaError({
66
+ code: 'PROVIDER_RESPONSE_INVALID',
67
+ message: 'OpenAI returned no choices.',
68
+ hint: 'Retry the request; this is not something the caller can fix by itself.',
69
+ });
70
+ }
71
+ const toolCalls = (choice.message.tool_calls ?? []).map((call) => ({
72
+ id: call.id,
73
+ name: call.function.name,
74
+ input: parseArguments(call.function.arguments),
75
+ }));
76
+ return {
77
+ content: choice.message.content,
78
+ toolCalls,
79
+ stopReason: STOP_REASON[choice.finish_reason],
80
+ usage: { inputTokens: body.usage.prompt_tokens, outputTokens: body.usage.completion_tokens },
81
+ };
82
+ }
83
+ function parseArguments(raw) {
84
+ try {
85
+ const parsed = JSON.parse(raw);
86
+ return typeof parsed === 'object' && parsed !== null
87
+ ? parsed
88
+ : {};
89
+ }
90
+ catch (cause) {
91
+ throw new CogentaError({
92
+ code: 'PROVIDER_RESPONSE_INVALID',
93
+ message: "OpenAI's tool call arguments were not valid JSON.",
94
+ hint: 'This is a vendor-side malformed response; retry the request.',
95
+ cause,
96
+ });
97
+ }
98
+ }
99
+ /** API key injected at the runtime boundary — never in a prompt or tool input (rule R7). */
100
+ export function createOpenAiClient(config) {
101
+ const doFetch = config.fetchImpl ?? fetch;
102
+ const url = config.baseUrl ?? DEFAULT_BASE_URL;
103
+ return {
104
+ name: 'openai',
105
+ model: config.model,
106
+ async chat(request, options) {
107
+ const response = await doFetch(url, {
108
+ method: 'POST',
109
+ headers: {
110
+ 'content-type': 'application/json',
111
+ authorization: `Bearer ${config.apiKey}`,
112
+ },
113
+ body: JSON.stringify(buildOpenAiRequest(request)),
114
+ ...(options?.signal === undefined ? {} : { signal: options.signal }),
115
+ }).catch((cause) => {
116
+ throw new CogentaError({
117
+ code: 'PROVIDER_REQUEST_FAILED',
118
+ message: 'The request to OpenAI could not be sent.',
119
+ hint: 'Check network connectivity and COGENTA_OPENAI_API_KEY.',
120
+ cause,
121
+ });
122
+ });
123
+ if (response.status === 429) {
124
+ throw new CogentaError({
125
+ code: 'PROVIDER_RATE_LIMITED',
126
+ message: 'OpenAI rate-limited this request.',
127
+ hint: 'Retry with backoff, or lower callsPerHour for this agent.',
128
+ });
129
+ }
130
+ if (!response.ok) {
131
+ throw new CogentaError({
132
+ code: 'PROVIDER_REQUEST_FAILED',
133
+ message: `OpenAI returned status ${response.status}.`,
134
+ hint: 'Check the request and COGENTA_OPENAI_API_KEY.',
135
+ details: { status: response.status },
136
+ });
137
+ }
138
+ const body = (await response.json());
139
+ return parseOpenAiResponse(body);
140
+ },
141
+ };
142
+ }
143
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAW5C,MAAM,gBAAgB,GAAG,4CAA4C,CAAA;AAyCrE,MAAM,WAAW,GAA+E;IAC9F,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,UAAU;IACtB,MAAM,EAAE,YAAY;IACpB,cAAc,EAAE,eAAe;CAChC,CAAA;AAED,SAAS,eAAe,CAAC,OAAoB;IAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5B,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,YAAY,CAAC;gBACrB,IAAI,EAAE,2B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AC,OAAO,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;aACrE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAC1B,MAAM,IAAI,YAAY,CAAC;oBACrB,IAAI,EAAE,yBAAyB;oBAC/B,OAAO,EAAE,0CAA0C;oBACnD,IAAI,EAAE,wDAAwD;oBAC9D,KAAK;iBACN,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;YAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC5B,MAAM,IAAI,YAAY,CAAC;oBACrB,IAAI,EAAE,uBAAuB;oBAC7B,OAAO,EAAE,mCAAmC;oBAC5C,IAAI,EAAE,2DAA2D;iBAClE,CAAC,CAAA;YACJ,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,YAAY,CAAC;oBACrB,IAAI,EAAE,yBAAyB;oBAC/B,OAAO,EAAE,0BAA0B,QAAQ,CAAC,MAAM,GAAG;oBACrD,IAAI,EAAE,+CAA+C;oBACrD,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE;iBACrC,CAAC,CAAA;YACJ,CAAC;YAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAuB,CAAA;YAC1D,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { ProviderClient } from './types.js';
2
+ export declare const PROVIDER_NAMES: readonly ['anthropic', 'openai', 'google'];
3
+ export type ProviderName = (typeof PROVIDER_NAMES)[number];
4
+ export interface ProviderRegistryConfig {
5
+ readonly anthropic?: {
6
+ readonly apiKey: string;
7
+ readonly model: string;
8
+ readonly baseUrl?: string;
9
+ };
10
+ readonly openai?: {
11
+ readonly apiKey: string;
12
+ readonly model: string;
13
+ readonly baseUrl?: string;
14
+ };
15
+ readonly google?: {
16
+ readonly apiKey: string;
17
+ readonly model: string;
18
+ readonly baseUrl?: string;
19
+ };
20
+ }
21
+ /**
22
+ * One client per configured vendor — a site with no LLM provider configured
23
+ * simply has an empty registry, which is exactly what rule R2 requires ("le
24
+ * CMS fonctionne sans IA"): nothing here fails to construct, `get()` is what
25
+ * refuses, and only once an agent actually tries to run.
26
+ */
27
+ export declare function createProviderRegistry(config: ProviderRegistryConfig): {
28
+ readonly get: (name: ProviderName) => ProviderClient;
29
+ readonly has: (name: ProviderName) => boolean;
30
+ };
31
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/providers/registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,eAAO,MAAM,cAAc,YAAI,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAA;AACxE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1D,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE;QACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;QACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAC1B,CAAA;IACD,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAChG,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACjG;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,GAAG;IACtE,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,cAAc,CAAA;IACpD,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAA;CAC9C,CAqBA"}
@@ -0,0 +1,35 @@
1
+ import { CogentaError } from '@cogenta/core';
2
+ import { createAnthropicClient } from './anthropic.js';
3
+ import { createGoogleClient } from './google.js';
4
+ import { createOpenAiClient } from './openai.js';
5
+ export const PROVIDER_NAMES = ['anthropic', 'openai', 'google'];
6
+ /**
7
+ * One client per configured vendor — a site with no LLM provider configured
8
+ * simply has an empty registry, which is exactly what rule R2 requires ("le
9
+ * CMS fonctionne sans IA"): nothing here fails to construct, `get()` is what
10
+ * refuses, and only once an agent actually tries to run.
11
+ */
12
+ export function createProviderRegistry(config) {
13
+ const clients = new Map();
14
+ if (config.anthropic !== undefined)
15
+ clients.set('anthropic', createAnthropicClient(config.anthropic));
16
+ if (config.openai !== undefined)
17
+ clients.set('openai', createOpenAiClient(config.openai));
18
+ if (config.google !== undefined)
19
+ clients.set('google', createGoogleClient(config.google));
20
+ return {
21
+ has: (name) => clients.has(name),
22
+ get(name) {
23
+ const client = clients.get(name);
24
+ if (client === undefined) {
25
+ throw new CogentaError({
26
+ code: 'PROVIDER_UNKNOWN',
27
+ message: `No provider named "${name}" is configured for this site.`,
28
+ hint: 'Set the matching COGENTA_*_API_KEY, or choose a configured provider.',
29
+ });
30
+ }
31
+ return client;
32
+ },
33
+ };
34
+ }
35
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/providers/registry.ts"],"names":[],"mappings":"AAAA,OAA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CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * L4 task 1: the normalized shape every provider adapter speaks, so the
3
+ * execution loop (task 2) calls one interface regardless of vendor. Tool-
4
+ * calling wire formats differ enough between vendors (Anthropic's
5
+ * `tool_use` content blocks, OpenAI's `tool_calls` array, Google's
6
+ * `functionCall` parts) that this is the one place that difference is
7
+ * allowed to exist — everything above `ProviderClient` sees only this.
8
+ */
9
+ export type ChatRole = 'user' | 'assistant' | 'tool';
10
+ /** One tool invocation the model asked for — never executed here, only described. */
11
+ export interface ProviderToolCall {
12
+ readonly id: string;
13
+ readonly name: string;
14
+ readonly input: Readonly<Record<string, unknown>>;
15
+ }
16
+ export interface ChatMessage {
17
+ readonly role: ChatRole;
18
+ /** Absent (not empty-string) when a turn is tool calls with no accompanying text. */
19
+ readonly content?: string;
20
+ /** Set on an `assistant` message that requested tool calls. */
21
+ readonly toolCalls?: readonly ProviderToolCall[];
22
+ /** Set on a `tool` message: which call this is the result of. */
23
+ readonly toolCallId?: string;
24
+ /** Set on a `tool` message: the tool's name, some vendors require it alongside the id. */
25
+ readonly toolName?: string;
26
+ }
27
+ /** A tool's shape as the model sees it — `inputSchema` is JSON Schema, already converted from the Zod schema `defineTool` (Contract C) declares. */
28
+ export interface ProviderToolSpec {
29
+ readonly name: string;
30
+ readonly description: string;
31
+ readonly inputSchema: Readonly<Record<string, unknown>>;
32
+ }
33
+ export interface ChatRequest {
34
+ readonly model: string;
35
+ readonly system?: string;
36
+ readonly messages: readonly ChatMessage[];
37
+ readonly tools?: readonly ProviderToolSpec[];
38
+ readonly maxTokens: number;
39
+ readonly temperature?: number;
40
+ }
41
+ export type StopReason = 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence';
42
+ export interface TokenUsage {
43
+ readonly inputTokens: number;
44
+ readonly outputTokens: number;
45
+ }
46
+ export interface ChatResponse {
47
+ /** `null` when the turn is tool calls only, with no accompanying text. */
48
+ readonly content: string | null;
49
+ readonly toolCalls: readonly ProviderToolCall[];
50
+ readonly stopReason: StopReason;
51
+ readonly usage: TokenUsage;
52
+ }
53
+ export interface ChatOptions {
54
+ /** Cancels the underlying HTTP request — the execution loop's own timeout/cancellation (task 2) threads through here. */
55
+ readonly signal?: AbortSignal;
56
+ }
57
+ /** What every adapter implements — the execution loop (task 2) depends on this, never on a vendor SDK type directly. */
58
+ export interface ProviderClient {
59
+ readonly name: string;
60
+ readonly model: string;
61
+ chat(request: ChatRequest, options?: ChatOptions): Promise<ChatResponse>;
62
+ }
63
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAA;AAEpD,qFAAqF;AACrF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CAClD;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,qFAAqF;IACrF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAA;IAChD,iEAAiE;IACjE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,oJAAoJ;AACpJ,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,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+ /**
2
+ * L4 task 1: the normalized shape every provider adapter speaks, so the
3
+ * execution loop (task 2) calls one interface regardless of vendor. Tool-
4
+ * calling wire formats differ enough between vendors (Anthropic's
5
+ * `tool_use` content blocks, OpenAI's `tool_calls` array, Google's
6
+ * `functionCall` parts) that this is the one place that difference is
7
+ * allowed to exist — everything above `ProviderClient` sees only this.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,13 @@
1
+ import type { Chunk, ChunkableDocument } from './types.js';
2
+ /**
3
+ * "Découpage sémantique par bloc et par titre": a block is the atomic unit
4
+ * (never split mid-block) and a heading block always starts a new chunk
5
+ * (never folded into the section above it) — the two boundaries the lot
6
+ * names. Within those boundaries, consecutive blocks are packed into one
7
+ * chunk up to `maxChunkChars`, so a chunk stays one coherent section rather
8
+ * than one block each, which would starve retrieval of context.
9
+ */
10
+ export declare function chunkDocument(document: ChunkableDocument, options?: {
11
+ readonly maxChunkChars?: number;
12
+ }): readonly Chunk[];
13
+ //# sourceMappingURL=chunk-document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-document.d.ts","sourceRoot":"","sources":["../../../src/rag/chunking/chunk-document.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAc1D;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,SAAS,KAAK,EAAE,CAqClB"}
@@ -0,0 +1,51 @@
1
+ import { createHash } from 'node:crypto';
2
+ const DEFAULT_MAX_CHUNK_CHARS = 2000;
3
+ function hashText(text) {
4
+ return createHash('sha256').update(text, 'utf8').digest('hex');
5
+ }
6
+ /**
7
+ * "Découpage sémantique par bloc et par titre": a block is the atomic unit
8
+ * (never split mid-block) and a heading block always starts a new chunk
9
+ * (never folded into the section above it) — the two boundaries the lot
10
+ * names. Within those boundaries, consecutive blocks are packed into one
11
+ * chunk up to `maxChunkChars`, so a chunk stays one coherent section rather
12
+ * than one block each, which would starve retrieval of context.
13
+ */
14
+ export function chunkDocument(document, options) {
15
+ const maxChunkChars = options?.maxChunkChars ?? DEFAULT_MAX_CHUNK_CHARS;
16
+ const chunks = [];
17
+ let current = null;
18
+ function flush() {
19
+ if (current === null || current.blockIds.length === 0)
20
+ return;
21
+ // The document title is folded into every chunk's text, not just kept as
22
+ // metadata — retrieval otherwise loses which document/section a chunk
23
+ // belongs to once it is embedded and floating in a vector index.
24
+ const text = [document.title, ...current.texts].join('\n\n');
25
+ chunks.push({
26
+ id: `${document.documentId}:${current.blockIds.join(',')}`,
27
+ documentId: document.documentId,
28
+ blockIds: [...current.blockIds],
29
+ text,
30
+ hash: hashText(text),
31
+ });
32
+ current = null;
33
+ }
34
+ for (const block of document.blocks) {
35
+ const blockText = block.text.trim();
36
+ if (blockText === '')
37
+ continue;
38
+ if (block.isHeading === true)
39
+ flush();
40
+ if (current !== null && current.chars > 0 && current.chars + blockText.length > maxChunkChars) {
41
+ flush();
42
+ }
43
+ current ??= { blockIds: [], texts: [], chars: 0 };
44
+ current.blockIds.push(block.id);
45
+ current.texts.push(blockText);
46
+ current.chars += blockText.length;
47
+ }
48
+ flush();
49
+ return chunks;
50
+ }
51
+ //# sourceMappingURL=chunk-document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-document.js","sourceRoot":"","sources":["../../../src/rag/chunking/chunk-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,uBAAuB,GAAG,IAAI,CAAA;AAEpC,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,UAAU,CAAC,Q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CAAC,IAAI,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,GAAG,aAAa,EAAE,CAAC;YAC9F,KAAK,EAAE,CAAA;QACT,CAAC;QACD,OAAO,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;QACjD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC/B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC7B,OAAO,CAAC,KAAK,IAAI,SAAS,CAAC,MAAM,CAAA;IACnC,CAAC;IACD,KAAK,EAAE,CAAA;IAEP,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Chunk } from './types.js';
2
+ export interface IngestionPlan {
3
+ /** New chunk ids, and chunks whose text (hence hash) changed since the previous run — these need `EmbeddingProvider.embed()`. */
4
+ readonly toEmbed: readonly Chunk[];
5
+ /** Chunk ids present before but absent now — their vectors should be deleted from the index. */
6
+ readonly toRemove: readonly string[];
7
+ /** Same id, same hash — skipped entirely, "ré-embedding des seuls chunks modifiés". */
8
+ readonly unchanged: readonly Chunk[];
9
+ }
10
+ /**
11
+ * Compares one document's previous chunk set to its freshly re-chunked
12
+ * current set, by id and hash only — this is the whole incremental
13
+ * ingestion mechanism the lot asks for: "hash par chunk → ré-embedding des
14
+ * seuls chunks modifiés". No I/O here; the caller owns fetching `previous`
15
+ * from wherever the index stores it and calling the embedding provider and
16
+ * the index with the plan's three lists.
17
+ */
18
+ export declare function planIncrementalIngestion(previous: readonly Chunk[], next: readonly Chunk[]): IngestionPlan;
19
+ //# sourceMappingURL=incremental.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"incremental.d.ts","sourceRoot":"","sources":["../../../src/rag/chunking/incremental.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,WAAW,aAAa;IAC5B,iIAAiI;IACjI,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAA;IAClC,gGAAgG;IAChG,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,uFAAuF;IACvF,QAAQ,CAAC,SAAS,EAAE,SAAS,KAAK,EAAE,CAAA;CACrC;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,KAAK,EAAE,EAC1B,IAAI,EAAE,SAAS,KAAK,EAAE,GACrB,aAAa,CAef"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Compares one document's previous chunk set to its freshly re-chunked
3
+ * current set, by id and hash only — this is the whole incremental
4
+ * ingestion mechanism the lot asks for: "hash par chunk → ré-embedding des
5
+ * seuls chunks modifiés". No I/O here; the caller owns fetching `previous`
6
+ * from wherever the index stores it and calling the embedding provider and
7
+ * the index with the plan's three lists.
8
+ */
9
+ export function planIncrementalIngestion(previous, next) {
10
+ const previousById = new Map(previous.map((chunk) => [chunk.id, chunk]));
11
+ const nextIds = new Set(next.map((chunk) => chunk.id));
12
+ const toEmbed = [];
13
+ const unchanged = [];
14
+ for (const chunk of next) {
15
+ const prior = previousById.get(chunk.id);
16
+ if (prior === undefined || prior.hash !== chunk.hash)
17
+ toEmbed.push(chunk);
18
+ else
19
+ unchanged.push(chunk);
20
+ }
21
+ const toRemove = previous.filter((chunk) => !nextIds.has(chunk.id)).map((chunk) => chunk.id);
22
+ return { toEmbed, toRemove, unchanged };
23
+ }
24
+ //# sourceMappingURL=incremental.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"incremental.js","sourceRoot":"","sources":["../../../src/rag/chunking/incremental.ts"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA0B,EAC1B,IAAsB;IAEtB,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IACxE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;IAEtD,MAAM,OAAO,GAAY,EAAE,CAAA;IAC3B,MAAM,SAAS,GAAY,EAAE,CAAA;IAC7B,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QACxC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;YAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;;YACpE,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;IAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAE5F,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAA;AACzC,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Deliberately not `@cogenta/blocks`' own block union — the same reasoning
3
+ * `ContentServiceLike` (task 5) documents for content tools: a narrow
4
+ * structural shape the real block-flattening step (wherever content is read
5
+ * from, outside this package) can satisfy, instead of a hard dependency.
6
+ */
7
+ export interface ChunkableBlock {
8
+ readonly id: string;
9
+ /** A heading/title block — always starts a new chunk, never gets folded into the section above it. */
10
+ readonly isHeading?: boolean;
11
+ readonly text: string;
12
+ }
13
+ export interface ChunkableDocument {
14
+ readonly documentId: string;
15
+ readonly title: string;
16
+ readonly blocks: readonly ChunkableBlock[];
17
+ }
18
+ export interface Chunk {
19
+ /**
20
+ * `${documentId}:${blockIds.join(',')}` — identity comes from which blocks
21
+ * make up the chunk, not from its position or its text. An edit to a
22
+ * block's text keeps the same chunk id (so incremental ingestion sees "same
23
+ * chunk, new hash" rather than a spurious remove+add); a block moving to a
24
+ * different section, or a chunk boundary shifting, is a genuinely different
25
+ * chunk and gets a different id.
26
+ */
27
+ readonly id: string;
28
+ readonly documentId: string;
29
+ readonly blockIds: readonly string[];
30
+ readonly text: string;
31
+ /** SHA-256 of `text` — the only thing incremental ingestion compares to decide what needs re-embedding. */
32
+ readonly hash: string;
33
+ }
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/rag/chunking/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,sGAAsG;IACtG,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAA;CAC3C;AAED,MAAM,WAAW,KAAK;IACpB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,2GAA2G;IAC3G,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/rag/chunking/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import type { EmbeddingProvider } from './types.js';
2
+ /**
3
+ * The "hashing trick" (scikit-learn's `HashingVectorizer` is the same idea):
4
+ * a bag-of-words vector folded into a fixed size by hashing each token to a
5
+ * dimension and a sign, then L2-normalised for cosine similarity. Local, CPU,
6
+ * zero dependency, no model to download — deliberately not the
7
+ * `multilingual-e5-small` ONNX model the lot names as the eventual default.
8
+ *
9
+ * That adapter is deferred: the natural library for local ONNX text
10
+ * embeddings in Node, `@huggingface/transformers`, declares `sharp` as a
11
+ * hard (non-optional) direct dependency even for text-only use — the exact
12
+ * native-without-WASM-fallback failure R10 exists to prevent, breaking
13
+ * `pnpm install` on ARM/musl/shared hosting regardless of which backend is
14
+ * actually used at runtime. `EmbeddingProvider` is shaped so a real ONNX
15
+ * adapter can replace this one later (task 15/16's RAG index keys on
16
+ * `{provider, model, dimensions}`, not on how a vector was produced) once a
17
+ * `sharp`-free path exists — a follow-up, not this task's call to make.
18
+ */
19
+ export declare function createHashingEmbeddingProvider(options?: {
20
+ readonly dimensions?: number;
21
+ }): EmbeddingProvider;
22
+ //# sourceMappingURL=hashing-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashing-provider.d.ts","sourceRoot":"","sources":["../../../src/rag/embeddings/hashing-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AA8BnD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,CAAC,EAAE;IACvD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,GAAG,iBAAiB,CAUpB"}
@@ -0,0 +1,53 @@
1
+ const DEFAULT_DIMENSIONS = 256;
2
+ function tokenize(text) {
3
+ return text.toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
4
+ }
5
+ /** FNV-1a — deterministic, no dependency, good enough spread for a hashing-trick embedding. */
6
+ function hashToken(token) {
7
+ let hash = 0x811c9dc5;
8
+ for (let i = 0; i < token.length; i++) {
9
+ hash ^= token.charCodeAt(i);
10
+ hash = Math.imul(hash, 0x01000193);
11
+ }
12
+ return hash >>> 0;
13
+ }
14
+ function embedOne(text, dimensions) {
15
+ const vector = new Array(dimensions).fill(0);
16
+ for (const token of tokenize(text)) {
17
+ const hash = hashToken(token);
18
+ const index = hash % dimensions;
19
+ const sign = hash & 1 ? 1 : -1;
20
+ vector[index] = (vector[index] ?? 0) + sign;
21
+ }
22
+ const norm = Math.sqrt(vector.reduce((sum, value) => sum + value * value, 0));
23
+ return norm === 0 ? vector : vector.map((value) => value / norm);
24
+ }
25
+ /**
26
+ * The "hashing trick" (scikit-learn's `HashingVectorizer` is the same idea):
27
+ * a bag-of-words vector folded into a fixed size by hashing each token to a
28
+ * dimension and a sign, then L2-normalised for cosine similarity. Local, CPU,
29
+ * zero dependency, no model to download — deliberately not the
30
+ * `multilingual-e5-small` ONNX model the lot names as the eventual default.
31
+ *
32
+ * That adapter is deferred: the natural library for local ONNX text
33
+ * embeddings in Node, `@huggingface/transformers`, declares `sharp` as a
34
+ * hard (non-optional) direct dependency even for text-only use — the exact
35
+ * native-without-WASM-fallback failure R10 exists to prevent, breaking
36
+ * `pnpm install` on ARM/musl/shared hosting regardless of which backend is
37
+ * actually used at runtime. `EmbeddingProvider` is shaped so a real ONNX
38
+ * adapter can replace this one later (task 15/16's RAG index keys on
39
+ * `{provider, model, dimensions}`, not on how a vector was produced) once a
40
+ * `sharp`-free path exists — a follow-up, not this task's call to make.
41
+ */
42
+ export function createHashingEmbeddingProvider(options) {
43
+ const dimensions = options?.dimensions ?? DEFAULT_DIMENSIONS;
44
+ return {
45
+ provider: 'local-hashing',
46
+ model: 'feature-hashing-v1',
47
+ dimensions,
48
+ async embed(texts) {
49
+ return texts.map((text) => embedOne(text, dimensions));
50
+ },
51
+ };
52
+ }
53
+ //# sourceMappingURL=hashing-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashing-provider.js","sourceRoot":"","sources":["../../../src/rag/embeddings/hashing-provider.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAE9B,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAA;AAC1D,CAAC;AAED,+FAA+F;AAC/F,SAAS,SAAS,CAAC,KAAa;IAC9B,IAAI,IAAI,GAAG,UAAU,CAAA;IACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAC3B,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IACpC,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,CAAA;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,UAAkB;IAChD,MAAM,MAAM,GAAG,IAAI,KAAK,CAAS,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACpD,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;QAC7B,MAAM,KAAK,GAAG,IAAI,GAAG,UAAU,CAAA;QAC/B,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC9B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAA;IAC7C,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IAC7E,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;AAClE,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,8BAA8B,CAAC,OAE9C;IACC,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,kBAAkB,CAAA;IAC5D,OAAO;QACL,QAAQ,EAAE,eAAe;QACzB,KAAK,EAAE,oBAAoB;QAC3B,UAAU;QACV,KAAK,CAAC,KAAK,CAAC,KAAK;YACf,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAA;QACxD,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * L4 task 14. "L'index porte `{provider, model, dimensions}`. Changer de
3
+ * modèle crée un index parallèle" — this triple is the identity an index is
4
+ * built against, so every embedding call carries it, never just a bare
5
+ * vector.
6
+ */
7
+ export interface EmbeddingModelInfo {
8
+ readonly provider: string;
9
+ readonly model: string;
10
+ readonly dimensions: number;
11
+ }
12
+ export interface EmbeddingProvider extends EmbeddingModelInfo {
13
+ /** One vector per input text, same order, same length as `texts`. */
14
+ embed(texts: readonly string[]): Promise<readonly (readonly number[])[]>;
15
+ }
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/rag/embeddings/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D,qEAAqE;IACrE,KAAK,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,CAAA;CACzE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/rag/embeddings/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { IndexedChunk, RankedId } from './types.js';
2
+ /** Standard Okapi BM25 over each chunk's text — the keyword half of the hybrid search. */
3
+ export declare function bm25Rank(chunks: readonly IndexedChunk[], queryText: string): readonly RankedId[];
4
+ //# sourceMappingURL=bm25.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../../src/rag/index/bm25.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AASxD,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,QAAQ,EAAE,CAiChG"}