lingxios 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/README.md +54 -0
  2. package/db/schema.sql +306 -0
  3. package/dist/src/app/artifacts.d.ts +8 -0
  4. package/dist/src/app/artifacts.js +114 -0
  5. package/dist/src/app/artifacts.js.map +1 -0
  6. package/dist/src/app/doctor.d.ts +22 -0
  7. package/dist/src/app/doctor.js +44 -0
  8. package/dist/src/app/doctor.js.map +1 -0
  9. package/dist/src/app/index.d.ts +123 -0
  10. package/dist/src/app/index.js +291 -0
  11. package/dist/src/app/index.js.map +1 -0
  12. package/dist/src/app/input.d.ts +22 -0
  13. package/dist/src/app/input.js +60 -0
  14. package/dist/src/app/input.js.map +1 -0
  15. package/dist/src/app/recover-wait.d.ts +5 -0
  16. package/dist/src/app/recover-wait.js +59 -0
  17. package/dist/src/app/recover-wait.js.map +1 -0
  18. package/dist/src/app/resources.d.ts +5 -0
  19. package/dist/src/app/resources.js +9 -0
  20. package/dist/src/app/resources.js.map +1 -0
  21. package/dist/src/app/storage.d.ts +2 -0
  22. package/dist/src/app/storage.js +41 -0
  23. package/dist/src/app/storage.js.map +1 -0
  24. package/dist/src/cli/doctor.d.ts +2 -0
  25. package/dist/src/cli/doctor.js +20 -0
  26. package/dist/src/cli/doctor.js.map +1 -0
  27. package/dist/src/cli/eval.d.ts +2 -0
  28. package/dist/src/cli/eval.js +44 -0
  29. package/dist/src/cli/eval.js.map +1 -0
  30. package/dist/src/config.d.ts +22 -0
  31. package/dist/src/config.js +56 -0
  32. package/dist/src/config.js.map +1 -0
  33. package/dist/src/context/attachments.d.ts +10 -0
  34. package/dist/src/context/attachments.js +18 -0
  35. package/dist/src/context/attachments.js.map +1 -0
  36. package/dist/src/context/document-text.d.ts +1 -0
  37. package/dist/src/context/document-text.js +29 -0
  38. package/dist/src/context/document-text.js.map +1 -0
  39. package/dist/src/context/document-worker.d.ts +1 -0
  40. package/dist/src/context/document-worker.js +62 -0
  41. package/dist/src/context/document-worker.js.map +1 -0
  42. package/dist/src/context/evidence.d.ts +19 -0
  43. package/dist/src/context/evidence.js +37 -0
  44. package/dist/src/context/evidence.js.map +1 -0
  45. package/dist/src/context/request.d.ts +21 -0
  46. package/dist/src/context/request.js +32 -0
  47. package/dist/src/context/request.js.map +1 -0
  48. package/dist/src/context/research-evidence.d.ts +4 -0
  49. package/dist/src/context/research-evidence.js +24 -0
  50. package/dist/src/context/research-evidence.js.map +1 -0
  51. package/dist/src/context/resource-checks.d.ts +7 -0
  52. package/dist/src/context/resource-checks.js +15 -0
  53. package/dist/src/context/resource-checks.js.map +1 -0
  54. package/dist/src/context/task-contract.d.ts +11 -0
  55. package/dist/src/context/task-contract.js +23 -0
  56. package/dist/src/context/task-contract.js.map +1 -0
  57. package/dist/src/context/text.d.ts +2 -0
  58. package/dist/src/context/text.js +7 -0
  59. package/dist/src/context/text.js.map +1 -0
  60. package/dist/src/control-plane/http-server.d.ts +22 -0
  61. package/dist/src/control-plane/http-server.js +196 -0
  62. package/dist/src/control-plane/http-server.js.map +1 -0
  63. package/dist/src/control-plane/memory-store.d.ts +71 -0
  64. package/dist/src/control-plane/memory-store.js +389 -0
  65. package/dist/src/control-plane/memory-store.js.map +1 -0
  66. package/dist/src/control-plane/pg-store.d.ts +62 -0
  67. package/dist/src/control-plane/pg-store.js +386 -0
  68. package/dist/src/control-plane/pg-store.js.map +1 -0
  69. package/dist/src/control-plane/service.d.ts +52 -0
  70. package/dist/src/control-plane/service.js +630 -0
  71. package/dist/src/control-plane/service.js.map +1 -0
  72. package/dist/src/control-plane/stores.d.ts +184 -0
  73. package/dist/src/control-plane/stores.js +19 -0
  74. package/dist/src/control-plane/stores.js.map +1 -0
  75. package/dist/src/errors.d.ts +66 -0
  76. package/dist/src/errors.js +102 -0
  77. package/dist/src/errors.js.map +1 -0
  78. package/dist/src/eval/calibration.d.ts +16 -0
  79. package/dist/src/eval/calibration.js +28 -0
  80. package/dist/src/eval/calibration.js.map +1 -0
  81. package/dist/src/eval/index.d.ts +40 -0
  82. package/dist/src/eval/index.js +40 -0
  83. package/dist/src/eval/index.js.map +1 -0
  84. package/dist/src/eval/review.d.ts +20 -0
  85. package/dist/src/eval/review.js +49 -0
  86. package/dist/src/eval/review.js.map +1 -0
  87. package/dist/src/host/http-client.d.ts +48 -0
  88. package/dist/src/host/http-client.js +127 -0
  89. package/dist/src/host/http-client.js.map +1 -0
  90. package/dist/src/host/port.d.ts +26 -0
  91. package/dist/src/host/port.js +2 -0
  92. package/dist/src/host/port.js.map +1 -0
  93. package/dist/src/index.d.ts +17 -0
  94. package/dist/src/index.js +9 -0
  95. package/dist/src/index.js.map +1 -0
  96. package/dist/src/integrations/lingxiloop/actions.d.ts +25 -0
  97. package/dist/src/integrations/lingxiloop/actions.js +77 -0
  98. package/dist/src/integrations/lingxiloop/actions.js.map +1 -0
  99. package/dist/src/integrations/lingxiloop/app.d.ts +167 -0
  100. package/dist/src/integrations/lingxiloop/app.js +434 -0
  101. package/dist/src/integrations/lingxiloop/app.js.map +1 -0
  102. package/dist/src/integrations/lingxiloop/approvals.d.ts +148 -0
  103. package/dist/src/integrations/lingxiloop/approvals.js +540 -0
  104. package/dist/src/integrations/lingxiloop/approvals.js.map +1 -0
  105. package/dist/src/integrations/lingxiloop/attachments.d.ts +8 -0
  106. package/dist/src/integrations/lingxiloop/attachments.js +38 -0
  107. package/dist/src/integrations/lingxiloop/attachments.js.map +1 -0
  108. package/dist/src/integrations/lingxiloop/calendar-approvals.d.ts +21 -0
  109. package/dist/src/integrations/lingxiloop/calendar-approvals.js +126 -0
  110. package/dist/src/integrations/lingxiloop/calendar-approvals.js.map +1 -0
  111. package/dist/src/integrations/lingxiloop/calendar-writes.d.ts +15 -0
  112. package/dist/src/integrations/lingxiloop/calendar-writes.js +79 -0
  113. package/dist/src/integrations/lingxiloop/calendar-writes.js.map +1 -0
  114. package/dist/src/integrations/lingxiloop/calendar.d.ts +19 -0
  115. package/dist/src/integrations/lingxiloop/calendar.js +43 -0
  116. package/dist/src/integrations/lingxiloop/calendar.js.map +1 -0
  117. package/dist/src/integrations/lingxiloop/canvas-events.d.ts +7 -0
  118. package/dist/src/integrations/lingxiloop/canvas-events.js +53 -0
  119. package/dist/src/integrations/lingxiloop/canvas-events.js.map +1 -0
  120. package/dist/src/integrations/lingxiloop/canvas-summary.d.ts +5 -0
  121. package/dist/src/integrations/lingxiloop/canvas-summary.js +52 -0
  122. package/dist/src/integrations/lingxiloop/canvas-summary.js.map +1 -0
  123. package/dist/src/integrations/lingxiloop/canvas-work-report.d.ts +12 -0
  124. package/dist/src/integrations/lingxiloop/canvas-work-report.js +120 -0
  125. package/dist/src/integrations/lingxiloop/canvas-work-report.js.map +1 -0
  126. package/dist/src/integrations/lingxiloop/canvas-work.d.ts +11 -0
  127. package/dist/src/integrations/lingxiloop/canvas-work.js +306 -0
  128. package/dist/src/integrations/lingxiloop/canvas-work.js.map +1 -0
  129. package/dist/src/integrations/lingxiloop/canvas.d.ts +12 -0
  130. package/dist/src/integrations/lingxiloop/canvas.js +79 -0
  131. package/dist/src/integrations/lingxiloop/canvas.js.map +1 -0
  132. package/dist/src/integrations/lingxiloop/chat.d.ts +11 -0
  133. package/dist/src/integrations/lingxiloop/chat.js +46 -0
  134. package/dist/src/integrations/lingxiloop/chat.js.map +1 -0
  135. package/dist/src/integrations/lingxiloop/document-approvals.d.ts +21 -0
  136. package/dist/src/integrations/lingxiloop/document-approvals.js +75 -0
  137. package/dist/src/integrations/lingxiloop/document-approvals.js.map +1 -0
  138. package/dist/src/integrations/lingxiloop/document-content.d.ts +80 -0
  139. package/dist/src/integrations/lingxiloop/document-content.js +195 -0
  140. package/dist/src/integrations/lingxiloop/document-content.js.map +1 -0
  141. package/dist/src/integrations/lingxiloop/document-writes.d.ts +8 -0
  142. package/dist/src/integrations/lingxiloop/document-writes.js +49 -0
  143. package/dist/src/integrations/lingxiloop/document-writes.js.map +1 -0
  144. package/dist/src/integrations/lingxiloop/documents.d.ts +22 -0
  145. package/dist/src/integrations/lingxiloop/documents.js +38 -0
  146. package/dist/src/integrations/lingxiloop/documents.js.map +1 -0
  147. package/dist/src/integrations/lingxiloop/event-outbox.d.ts +5 -0
  148. package/dist/src/integrations/lingxiloop/event-outbox.js +47 -0
  149. package/dist/src/integrations/lingxiloop/event-outbox.js.map +1 -0
  150. package/dist/src/integrations/lingxiloop/index.d.ts +3 -0
  151. package/dist/src/integrations/lingxiloop/index.js +3 -0
  152. package/dist/src/integrations/lingxiloop/index.js.map +1 -0
  153. package/dist/src/integrations/lingxiloop/learning-attempts.d.ts +13 -0
  154. package/dist/src/integrations/lingxiloop/learning-attempts.js +58 -0
  155. package/dist/src/integrations/lingxiloop/learning-attempts.js.map +1 -0
  156. package/dist/src/integrations/lingxiloop/learning-evaluation.d.ts +8 -0
  157. package/dist/src/integrations/lingxiloop/learning-evaluation.js +64 -0
  158. package/dist/src/integrations/lingxiloop/learning-evaluation.js.map +1 -0
  159. package/dist/src/integrations/lingxiloop/learning-evidence.d.ts +7 -0
  160. package/dist/src/integrations/lingxiloop/learning-evidence.js +88 -0
  161. package/dist/src/integrations/lingxiloop/learning-evidence.js.map +1 -0
  162. package/dist/src/integrations/lingxiloop/learning-missions.d.ts +18 -0
  163. package/dist/src/integrations/lingxiloop/learning-missions.js +95 -0
  164. package/dist/src/integrations/lingxiloop/learning-missions.js.map +1 -0
  165. package/dist/src/integrations/lingxiloop/learning.d.ts +22 -0
  166. package/dist/src/integrations/lingxiloop/learning.js +150 -0
  167. package/dist/src/integrations/lingxiloop/learning.js.map +1 -0
  168. package/dist/src/integrations/lingxiloop/memory.d.ts +14 -0
  169. package/dist/src/integrations/lingxiloop/memory.js +133 -0
  170. package/dist/src/integrations/lingxiloop/memory.js.map +1 -0
  171. package/dist/src/integrations/lingxiloop/polls.d.ts +9 -0
  172. package/dist/src/integrations/lingxiloop/polls.js +47 -0
  173. package/dist/src/integrations/lingxiloop/polls.js.map +1 -0
  174. package/dist/src/integrations/lingxiloop/presentations.d.ts +11 -0
  175. package/dist/src/integrations/lingxiloop/presentations.js +34 -0
  176. package/dist/src/integrations/lingxiloop/presentations.js.map +1 -0
  177. package/dist/src/integrations/lingxiloop/questionnaire.d.ts +21 -0
  178. package/dist/src/integrations/lingxiloop/questionnaire.js +57 -0
  179. package/dist/src/integrations/lingxiloop/questionnaire.js.map +1 -0
  180. package/dist/src/integrations/lingxiloop/research.d.ts +19 -0
  181. package/dist/src/integrations/lingxiloop/research.js +20 -0
  182. package/dist/src/integrations/lingxiloop/research.js.map +1 -0
  183. package/dist/src/integrations/lingxiloop/routines.d.ts +91 -0
  184. package/dist/src/integrations/lingxiloop/routines.js +198 -0
  185. package/dist/src/integrations/lingxiloop/routines.js.map +1 -0
  186. package/dist/src/integrations/lingxiloop/service-contracts.d.ts +1045 -0
  187. package/dist/src/integrations/lingxiloop/service-contracts.js +2 -0
  188. package/dist/src/integrations/lingxiloop/service-contracts.js.map +1 -0
  189. package/dist/src/integrations/lingxiloop/teacher-context.d.ts +32 -0
  190. package/dist/src/integrations/lingxiloop/teacher-context.js +25 -0
  191. package/dist/src/integrations/lingxiloop/teacher-context.js.map +1 -0
  192. package/dist/src/integrations/lingxiloop/teacher-digest.d.ts +13 -0
  193. package/dist/src/integrations/lingxiloop/teacher-digest.js +152 -0
  194. package/dist/src/integrations/lingxiloop/teacher-digest.js.map +1 -0
  195. package/dist/src/integrations/lingxiloop/teacher-preview.d.ts +22 -0
  196. package/dist/src/integrations/lingxiloop/teacher-preview.js +41 -0
  197. package/dist/src/integrations/lingxiloop/teacher-preview.js.map +1 -0
  198. package/dist/src/integrations/lingxiloop/teacher.d.ts +24 -0
  199. package/dist/src/integrations/lingxiloop/teacher.js +224 -0
  200. package/dist/src/integrations/lingxiloop/teacher.js.map +1 -0
  201. package/dist/src/kernel/manager.d.ts +52 -0
  202. package/dist/src/kernel/manager.js +407 -0
  203. package/dist/src/kernel/manager.js.map +1 -0
  204. package/dist/src/logging.d.ts +21 -0
  205. package/dist/src/logging.js +54 -0
  206. package/dist/src/logging.js.map +1 -0
  207. package/dist/src/memory/evidence.d.ts +6 -0
  208. package/dist/src/memory/evidence.js +43 -0
  209. package/dist/src/memory/evidence.js.map +1 -0
  210. package/dist/src/memory/processor.d.ts +3 -0
  211. package/dist/src/memory/processor.js +66 -0
  212. package/dist/src/memory/processor.js.map +1 -0
  213. package/dist/src/memory/semantic.d.ts +19 -0
  214. package/dist/src/memory/semantic.js +93 -0
  215. package/dist/src/memory/semantic.js.map +1 -0
  216. package/dist/src/memory/store.d.ts +20 -0
  217. package/dist/src/memory/store.js +34 -0
  218. package/dist/src/memory/store.js.map +1 -0
  219. package/dist/src/memory/synthesis.d.ts +24 -0
  220. package/dist/src/memory/synthesis.js +138 -0
  221. package/dist/src/memory/synthesis.js.map +1 -0
  222. package/dist/src/metrics.d.ts +43 -0
  223. package/dist/src/metrics.js +130 -0
  224. package/dist/src/metrics.js.map +1 -0
  225. package/dist/src/model/driver.d.ts +60 -0
  226. package/dist/src/model/driver.js +2 -0
  227. package/dist/src/model/driver.js.map +1 -0
  228. package/dist/src/model/embeddings.d.ts +24 -0
  229. package/dist/src/model/embeddings.js +97 -0
  230. package/dist/src/model/embeddings.js.map +1 -0
  231. package/dist/src/model/openai.d.ts +45 -0
  232. package/dist/src/model/openai.js +340 -0
  233. package/dist/src/model/openai.js.map +1 -0
  234. package/dist/src/outcome/assessment.d.ts +16 -0
  235. package/dist/src/outcome/assessment.js +45 -0
  236. package/dist/src/outcome/assessment.js.map +1 -0
  237. package/dist/src/outcome/content-check.d.ts +19 -0
  238. package/dist/src/outcome/content-check.js +44 -0
  239. package/dist/src/outcome/content-check.js.map +1 -0
  240. package/dist/src/outcome/envelope.d.ts +34 -0
  241. package/dist/src/outcome/envelope.js +42 -0
  242. package/dist/src/outcome/envelope.js.map +1 -0
  243. package/dist/src/protocol/constants.d.ts +25 -0
  244. package/dist/src/protocol/constants.js +26 -0
  245. package/dist/src/protocol/constants.js.map +1 -0
  246. package/dist/src/protocol/kernel-wire.d.ts +74 -0
  247. package/dist/src/protocol/kernel-wire.js +2 -0
  248. package/dist/src/protocol/kernel-wire.js.map +1 -0
  249. package/dist/src/protocol/outcome.d.ts +16 -0
  250. package/dist/src/protocol/outcome.js +14 -0
  251. package/dist/src/protocol/outcome.js.map +1 -0
  252. package/dist/src/protocol/types.d.ts +266 -0
  253. package/dist/src/protocol/types.js +19 -0
  254. package/dist/src/protocol/types.js.map +1 -0
  255. package/dist/src/research/address.d.ts +2 -0
  256. package/dist/src/research/address.js +32 -0
  257. package/dist/src/research/address.js.map +1 -0
  258. package/dist/src/research/fetch.d.ts +7 -0
  259. package/dist/src/research/fetch.js +83 -0
  260. package/dist/src/research/fetch.js.map +1 -0
  261. package/dist/src/research/index.d.ts +26 -0
  262. package/dist/src/research/index.js +109 -0
  263. package/dist/src/research/index.js.map +1 -0
  264. package/dist/src/runtime/compaction.d.ts +41 -0
  265. package/dist/src/runtime/compaction.js +86 -0
  266. package/dist/src/runtime/compaction.js.map +1 -0
  267. package/dist/src/runtime/corrections.d.ts +20 -0
  268. package/dist/src/runtime/corrections.js +27 -0
  269. package/dist/src/runtime/corrections.js.map +1 -0
  270. package/dist/src/runtime/policy.d.ts +42 -0
  271. package/dist/src/runtime/policy.js +91 -0
  272. package/dist/src/runtime/policy.js.map +1 -0
  273. package/dist/src/runtime/resource-refresh.d.ts +8 -0
  274. package/dist/src/runtime/resource-refresh.js +37 -0
  275. package/dist/src/runtime/resource-refresh.js.map +1 -0
  276. package/dist/src/runtime/runtime.d.ts +51 -0
  277. package/dist/src/runtime/runtime.js +804 -0
  278. package/dist/src/runtime/runtime.js.map +1 -0
  279. package/dist/src/runtime/tool.d.ts +13 -0
  280. package/dist/src/runtime/tool.js +42 -0
  281. package/dist/src/runtime/tool.js.map +1 -0
  282. package/dist/src/ui/index.d.ts +27 -0
  283. package/dist/src/ui/index.js +54 -0
  284. package/dist/src/ui/index.js.map +1 -0
  285. package/dist/src/versions.d.ts +9 -0
  286. package/dist/src/versions.js +11 -0
  287. package/dist/src/versions.js.map +1 -0
  288. package/dist/src/worker/index.d.ts +3 -0
  289. package/dist/src/worker/index.js +57 -0
  290. package/dist/src/worker/index.js.map +1 -0
  291. package/dist/src/worker/main.d.ts +2 -0
  292. package/dist/src/worker/main.js +9 -0
  293. package/dist/src/worker/main.js.map +1 -0
  294. package/dist/src/worker/worker.d.ts +45 -0
  295. package/dist/src/worker/worker.js +154 -0
  296. package/dist/src/worker/worker.js.map +1 -0
  297. package/kernel/runner.py +507 -0
  298. package/package.json +83 -0
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Minimal in-process metrics registry with Prometheus text exposition.
3
+ * Counters, gauges, and fixed-bucket histograms — enough for operational
4
+ * dashboards without pulling in a client library.
5
+ */
6
+ function labelKey(labels) {
7
+ const entries = Object.entries(labels).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
8
+ return entries.map(([k, v]) => `${k}="${v.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n')}"`).join(',');
9
+ }
10
+ class Counter {
11
+ name;
12
+ help;
13
+ series = new Map();
14
+ constructor(name, help) {
15
+ this.name = name;
16
+ this.help = help;
17
+ }
18
+ inc(labels = {}, delta = 1) {
19
+ const key = labelKey(labels);
20
+ this.series.set(key, (this.series.get(key) ?? 0) + delta);
21
+ }
22
+ expose() {
23
+ const lines = [`# HELP ${this.name} ${this.help}`, `# TYPE ${this.name} counter`];
24
+ for (const [key, value] of this.series)
25
+ lines.push(`${this.name}${key ? `{${key}}` : ''} ${value}`);
26
+ if (this.series.size === 0)
27
+ lines.push(`${this.name} 0`);
28
+ return lines;
29
+ }
30
+ }
31
+ class Gauge {
32
+ name;
33
+ help;
34
+ series = new Map();
35
+ constructor(name, help) {
36
+ this.name = name;
37
+ this.help = help;
38
+ }
39
+ set(value, labels = {}) {
40
+ this.series.set(labelKey(labels), value);
41
+ }
42
+ expose() {
43
+ const lines = [`# HELP ${this.name} ${this.help}`, `# TYPE ${this.name} gauge`];
44
+ for (const [key, value] of this.series)
45
+ lines.push(`${this.name}${key ? `{${key}}` : ''} ${value}`);
46
+ if (this.series.size === 0)
47
+ lines.push(`${this.name} 0`);
48
+ return lines;
49
+ }
50
+ }
51
+ class Histogram {
52
+ name;
53
+ help;
54
+ buckets;
55
+ counts = new Map();
56
+ sums = new Map();
57
+ totals = new Map();
58
+ constructor(name, help, buckets) {
59
+ this.name = name;
60
+ this.help = help;
61
+ this.buckets = buckets;
62
+ }
63
+ observe(value, labels = {}) {
64
+ const key = labelKey(labels);
65
+ let counts = this.counts.get(key);
66
+ if (!counts) {
67
+ counts = this.buckets.map(() => 0);
68
+ this.counts.set(key, counts);
69
+ }
70
+ for (const [index, bound] of this.buckets.entries()) {
71
+ if (value <= bound)
72
+ counts[index] = (counts[index] ?? 0) + 1;
73
+ }
74
+ this.sums.set(key, (this.sums.get(key) ?? 0) + value);
75
+ this.totals.set(key, (this.totals.get(key) ?? 0) + 1);
76
+ }
77
+ expose() {
78
+ const lines = [`# HELP ${this.name} ${this.help}`, `# TYPE ${this.name} histogram`];
79
+ for (const [key, counts] of this.counts) {
80
+ const prefix = key ? `${key},` : '';
81
+ for (const [index, bound] of this.buckets.entries()) {
82
+ lines.push(`${this.name}_bucket{${prefix}le="${bound}"} ${counts[index] ?? 0}`);
83
+ }
84
+ lines.push(`${this.name}_bucket{${prefix}le="+Inf"} ${this.totals.get(key) ?? 0}`);
85
+ lines.push(`${this.name}_sum${key ? `{${key}}` : ''} ${this.sums.get(key) ?? 0}`);
86
+ lines.push(`${this.name}_count${key ? `{${key}}` : ''} ${this.totals.get(key) ?? 0}`);
87
+ }
88
+ return lines;
89
+ }
90
+ }
91
+ export class MetricsRegistry {
92
+ counters = new Map();
93
+ gauges = new Map();
94
+ histograms = new Map();
95
+ counter(name, help) {
96
+ let metric = this.counters.get(name);
97
+ if (!metric) {
98
+ metric = new Counter(name, help);
99
+ this.counters.set(name, metric);
100
+ }
101
+ return metric;
102
+ }
103
+ gauge(name, help) {
104
+ let metric = this.gauges.get(name);
105
+ if (!metric) {
106
+ metric = new Gauge(name, help);
107
+ this.gauges.set(name, metric);
108
+ }
109
+ return metric;
110
+ }
111
+ histogram(name, help, buckets) {
112
+ let metric = this.histograms.get(name);
113
+ if (!metric) {
114
+ metric = new Histogram(name, help, buckets);
115
+ this.histograms.set(name, metric);
116
+ }
117
+ return metric;
118
+ }
119
+ expose() {
120
+ const lines = [];
121
+ for (const metric of this.counters.values())
122
+ lines.push(...metric.expose());
123
+ for (const metric of this.gauges.values())
124
+ lines.push(...metric.expose());
125
+ for (const metric of this.histograms.values())
126
+ lines.push(...metric.expose());
127
+ return `${lines.join('\n')}\n`;
128
+ }
129
+ }
130
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,SAAS,QAAQ,CAAC,MAAmB;IACnC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACvF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC3H,CA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(OpenAI-compatible, Anthropic, test fakes) live behind it.
4
+ */
5
+ import type { ModelItem } from '../protocol/types.js';
6
+ export interface ModelUsage {
7
+ available: boolean;
8
+ inputTokens: number;
9
+ outputTokens: number;
10
+ }
11
+ export interface ModelTurnResult {
12
+ /** Structured final response; the runtime validates it against the captured request. */
13
+ finalCandidate?: string;
14
+ /** Items to append to session history (assistant text and/or tool calls). */
15
+ output: ModelItem[];
16
+ /** Full assistant text of this turn ('' when the turn is a tool call). */
17
+ text: string;
18
+ model?: string;
19
+ usage: ModelUsage;
20
+ diagnostics?: Record<string, unknown>;
21
+ }
22
+ export interface ModelTurnRequest {
23
+ instructions: string;
24
+ items: readonly ModelItem[];
25
+ signal?: AbortSignal | undefined;
26
+ /** Called as assistant text streams; used for latency, not for delivery. */
27
+ onTextDelta?: ((delta: string) => void) | undefined;
28
+ }
29
+ export interface StructuredCallRequest {
30
+ instructions: string;
31
+ input: unknown;
32
+ signal?: AbortSignal | undefined;
33
+ }
34
+ export interface StructuredCallResult {
35
+ value: unknown;
36
+ model: string;
37
+ usage: ModelUsage;
38
+ }
39
+ export interface CompactionRequest {
40
+ instructions: string;
41
+ items: readonly ModelItem[];
42
+ signal?: AbortSignal | undefined;
43
+ }
44
+ export interface CompactionResult {
45
+ value: string;
46
+ model: string;
47
+ usage: ModelUsage;
48
+ }
49
+ export interface ModelDriver {
50
+ readonly modelId?: string;
51
+ readonly contextWindowTokens?: number;
52
+ readonly maxOutputTokens?: number;
53
+ readonly toolDefinitionTokens?: number;
54
+ /** One agent-loop turn: one Python call or a structured final candidate. */
55
+ run(request: ModelTurnRequest): Promise<ModelTurnResult>;
56
+ /** One-shot JSON-mode call for auxiliary pipelines. */
57
+ structured(request: StructuredCallRequest): Promise<StructuredCallResult>;
58
+ /** Summarize `items` into a continuity summary for context compaction. */
59
+ compact(request: CompactionRequest): Promise<CompactionResult>;
60
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/model/driver.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ export interface EmbeddingOptions {
2
+ id: string;
3
+ apiKey: string;
4
+ baseUrl?: string;
5
+ dimensions?: number;
6
+ requestTimeoutMs?: number;
7
+ }
8
+ /** One bounded request. Durable indexing work, rather than the HTTP client, owns retries. */
9
+ export declare class OpenAIEmbeddingDriver {
10
+ private readonly options;
11
+ readonly cacheKey: string;
12
+ private readonly endpoint;
13
+ private readonly timeoutMs;
14
+ constructor(options: EmbeddingOptions);
15
+ embed(input: readonly string[], signal?: AbortSignal): Promise<{
16
+ model: string;
17
+ vectors: number[][];
18
+ usage: {
19
+ available: boolean;
20
+ inputTokens: number;
21
+ totalTokens: number;
22
+ };
23
+ }>;
24
+ }
@@ -0,0 +1,97 @@
1
+ import { createHash } from 'node:crypto';
2
+ /** One bounded request. Durable indexing work, rather than the HTTP client, owns retries. */
3
+ export class OpenAIEmbeddingDriver {
4
+ options;
5
+ cacheKey;
6
+ endpoint;
7
+ timeoutMs;
8
+ constructor(options) {
9
+ this.options = options;
10
+ this.options = { ...options };
11
+ if (!options.id?.trim() || !options.apiKey?.trim())
12
+ throw new Error('embedding model id and apiKey are required');
13
+ let url;
14
+ try {
15
+ url = new URL(options.baseUrl ?? 'https://api.openai.com/v1');
16
+ }
17
+ catch {
18
+ throw new Error('invalid embedding base URL');
19
+ }
20
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash)
21
+ throw new Error('invalid embedding base URL');
22
+ this.endpoint = `${url.href.replace(/\/+$/, '')}/embeddings`;
23
+ this.timeoutMs = options.requestTimeoutMs ?? 15_000;
24
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs < 1 || this.timeoutMs > 60_000)
25
+ throw new Error('invalid embedding timeout');
26
+ if (options.dimensions !== undefined && (!Number.isSafeInteger(options.dimensions) || options.dimensions < 1 || options.dimensions > 4096))
27
+ throw new Error('invalid embedding dimensions');
28
+ this.cacheKey = createHash('sha256').update(JSON.stringify([this.endpoint, options.id, options.dimensions ?? null])).digest('hex');
29
+ }
30
+ async embed(input, signal) {
31
+ // UTF-8 bytes conservatively bound input tokens without a tokenizer dependency.
32
+ if (!Array.isArray(input) || !input.length || input.length > 32
33
+ || input.some(text => typeof text !== 'string' || !text.trim() || Buffer.byteLength(text) > 8000))
34
+ throw new Error('embedding input requires 1-32 nonempty strings of at most 8000 UTF-8 bytes');
35
+ const combined = AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(this.timeoutMs)]);
36
+ combined.throwIfAborted();
37
+ const response = await fetch(this.endpoint, { method: 'POST', redirect: 'error', signal: combined,
38
+ headers: { 'content-type': 'application/json', authorization: `Bearer ${this.options.apiKey}` },
39
+ body: JSON.stringify({ model: this.options.id, input, encoding_format: 'float',
40
+ ...(this.options.dimensions === undefined ? {} : { dimensions: this.options.dimensions }) }) });
41
+ if (!response.ok) {
42
+ await response.body?.cancel();
43
+ // Provider error bodies may echo credentials or input; never persist them in work errors.
44
+ throw new Error(`embedding provider returned HTTP ${response.status}`);
45
+ }
46
+ if (!response.body)
47
+ throw new Error('embedding provider returned no response body');
48
+ const reader = response.body.getReader();
49
+ const chunks = [];
50
+ let size = 0;
51
+ try {
52
+ while (true) {
53
+ const { done, value } = await reader.read();
54
+ if (done)
55
+ break;
56
+ size += value.byteLength;
57
+ if (size > 4 * 1024 * 1024)
58
+ throw new Error('embedding response exceeds 4 MiB');
59
+ chunks.push(value);
60
+ }
61
+ }
62
+ finally {
63
+ await reader.cancel().catch(() => { });
64
+ reader.releaseLock();
65
+ }
66
+ combined.throwIfAborted();
67
+ let result;
68
+ try {
69
+ result = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks)));
70
+ }
71
+ catch {
72
+ throw new Error('embedding provider returned invalid JSON');
73
+ }
74
+ if (!result || typeof result !== 'object' || typeof result.model !== 'string' || !result.model.trim() || result.model.length > 256
75
+ || !Array.isArray(result.data) || result.data.length !== input.length)
76
+ throw new Error('invalid embedding response envelope');
77
+ const vectors = new Array(input.length);
78
+ let dimensions = this.options.dimensions;
79
+ for (const item of result.data) {
80
+ if (!item || !Number.isSafeInteger(item.index) || item.index < 0 || item.index >= input.length || vectors[item.index]
81
+ || !Array.isArray(item.embedding) || item.embedding.length < 1 || item.embedding.length > 4096
82
+ || item.embedding.some((value) => typeof value !== 'number' || !Number.isFinite(value)))
83
+ throw new Error('invalid embedding vector or index');
84
+ dimensions ??= item.embedding.length;
85
+ if (item.embedding.length !== dimensions)
86
+ throw new Error('embedding dimensions do not match');
87
+ const norm = Math.hypot(...item.embedding);
88
+ if (!Number.isFinite(norm) || norm === 0)
89
+ throw new Error('embedding vector has invalid magnitude');
90
+ vectors[item.index] = item.embedding.map((value) => value / norm);
91
+ }
92
+ const prompt = result.usage?.prompt_tokens, total = result.usage?.total_tokens;
93
+ const available = Number.isSafeInteger(prompt) && Number(prompt) >= 0 && Number.isSafeInteger(total) && Number(total) >= Number(prompt);
94
+ return { model: result.model, vectors, usage: { available, inputTokens: available ? Number(prompt) : 0, totalTokens: available ? Number(total) : 0 } };
95
+ }
96
+ }
97
+ //# sourceMappingURL=embeddings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embeddings.js","sourceRoot":"","sources":["../../../src/model/embeddings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAUxC,6FAA6F;AAC7F,MAAM,OAAO,qBAAqB;IAKH;IAJpB,QAAQ,CAAQ;IACR,QAAQ,CAAQ;IAChB,SAAS,CAAQ;IAElC,YAA6B,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;QACpD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,CAAA;QAC7B,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,E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AAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IACxJ,CAAC;CACF"}
@@ -0,0 +1,45 @@
1
+ import type { CompactionRequest, CompactionResult, ModelDriver, ModelTurnRequest, ModelTurnResult, StructuredCallRequest, StructuredCallResult } from './driver.js';
2
+ export declare const DEFAULT_MODEL: {
3
+ readonly id: "deepseek-ai/DeepSeek-V4-Flash";
4
+ readonly baseUrl: "https://api.siliconflow.cn/v1";
5
+ readonly reasoningEffort: "high";
6
+ };
7
+ export interface OpenAIDriverOptions {
8
+ apiKey: string;
9
+ baseUrl?: string;
10
+ reasoningEffort?: 'high' | 'max';
11
+ /** Max attempts per request across retryable failures (429/5xx/network). */
12
+ maxAttempts?: number;
13
+ /** Base backoff in ms; grows exponentially with full jitter. */
14
+ retryBaseMs?: number;
15
+ /** Per-request timeout in ms (wall clock, including streaming). */
16
+ requestTimeoutMs?: number;
17
+ maxOutputTokens?: number;
18
+ contextWindowTokens?: number;
19
+ fetchImpl?: typeof fetch;
20
+ /** Injectable sleep for tests. */
21
+ sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
22
+ }
23
+ /** Parse bounded `text/event-stream` bodies into `data:` payload strings. */
24
+ export declare function sseDataEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<string>;
25
+ export declare class OpenAIChatDriver implements ModelDriver {
26
+ readonly modelId: string;
27
+ private readonly options;
28
+ readonly contextWindowTokens: number;
29
+ readonly maxOutputTokens: number;
30
+ readonly toolDefinitionTokens: number;
31
+ private readonly baseUrl;
32
+ private readonly maxAttempts;
33
+ private readonly retryBaseMs;
34
+ private readonly requestTimeoutMs;
35
+ private readonly fetchImpl;
36
+ private readonly sleep;
37
+ constructor(modelId: string, options: OpenAIDriverOptions);
38
+ private request;
39
+ private backoffMs;
40
+ private consumeStream;
41
+ private usageOf;
42
+ run(request: ModelTurnRequest): Promise<ModelTurnResult>;
43
+ structured(request: StructuredCallRequest): Promise<StructuredCallResult>;
44
+ compact(request: CompactionRequest): Promise<CompactionResult>;
45
+ }