@chanl/scenarios-core 0.4.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/LICENSE +21 -0
  2. package/dist/__tests__/e2e/test-helpers.d.ts +79 -0
  3. package/dist/__tests__/e2e/test-helpers.d.ts.map +1 -0
  4. package/dist/__tests__/e2e/test-helpers.js +162 -0
  5. package/dist/__tests__/e2e/test-helpers.js.map +1 -0
  6. package/dist/adapters/adapter-registry.d.ts +14 -0
  7. package/dist/adapters/adapter-registry.d.ts.map +1 -0
  8. package/dist/adapters/adapter-registry.js +53 -0
  9. package/dist/adapters/adapter-registry.js.map +1 -0
  10. package/dist/adapters/agent-adapter.interface.d.ts +70 -0
  11. package/dist/adapters/agent-adapter.interface.d.ts.map +1 -0
  12. package/dist/adapters/agent-adapter.interface.js +3 -0
  13. package/dist/adapters/agent-adapter.interface.js.map +1 -0
  14. package/dist/adapters/anthropic.adapter.d.ts +17 -0
  15. package/dist/adapters/anthropic.adapter.d.ts.map +1 -0
  16. package/dist/adapters/anthropic.adapter.js +145 -0
  17. package/dist/adapters/anthropic.adapter.js.map +1 -0
  18. package/dist/adapters/http.adapter.d.ts +17 -0
  19. package/dist/adapters/http.adapter.d.ts.map +1 -0
  20. package/dist/adapters/http.adapter.js +95 -0
  21. package/dist/adapters/http.adapter.js.map +1 -0
  22. package/dist/adapters/index.d.ts +6 -0
  23. package/dist/adapters/index.d.ts.map +1 -0
  24. package/dist/adapters/index.js +22 -0
  25. package/dist/adapters/index.js.map +1 -0
  26. package/dist/adapters/openai.adapter.d.ts +17 -0
  27. package/dist/adapters/openai.adapter.d.ts.map +1 -0
  28. package/dist/adapters/openai.adapter.js +133 -0
  29. package/dist/adapters/openai.adapter.js.map +1 -0
  30. package/dist/dataset/convert.d.ts +28 -0
  31. package/dist/dataset/convert.d.ts.map +1 -0
  32. package/dist/dataset/convert.js +94 -0
  33. package/dist/dataset/convert.js.map +1 -0
  34. package/dist/dataset/formats/dpo.d.ts +41 -0
  35. package/dist/dataset/formats/dpo.d.ts.map +1 -0
  36. package/dist/dataset/formats/dpo.js +79 -0
  37. package/dist/dataset/formats/dpo.js.map +1 -0
  38. package/dist/dataset/formats/index.d.ts +4 -0
  39. package/dist/dataset/formats/index.d.ts.map +1 -0
  40. package/dist/dataset/formats/index.js +13 -0
  41. package/dist/dataset/formats/index.js.map +1 -0
  42. package/dist/dataset/formats/openai.d.ts +29 -0
  43. package/dist/dataset/formats/openai.d.ts.map +1 -0
  44. package/dist/dataset/formats/openai.js +98 -0
  45. package/dist/dataset/formats/openai.js.map +1 -0
  46. package/dist/dataset/formats/sharegpt.d.ts +31 -0
  47. package/dist/dataset/formats/sharegpt.d.ts.map +1 -0
  48. package/dist/dataset/formats/sharegpt.js +76 -0
  49. package/dist/dataset/formats/sharegpt.js.map +1 -0
  50. package/dist/dataset/index.d.ts +4 -0
  51. package/dist/dataset/index.d.ts.map +1 -0
  52. package/dist/dataset/index.js +20 -0
  53. package/dist/dataset/index.js.map +1 -0
  54. package/dist/dataset/types.d.ts +108 -0
  55. package/dist/dataset/types.d.ts.map +1 -0
  56. package/dist/dataset/types.js +7 -0
  57. package/dist/dataset/types.js.map +1 -0
  58. package/dist/execution/agent-config-resolver.d.ts +44 -0
  59. package/dist/execution/agent-config-resolver.d.ts.map +1 -0
  60. package/dist/execution/agent-config-resolver.js +76 -0
  61. package/dist/execution/agent-config-resolver.js.map +1 -0
  62. package/dist/execution/execution-processor.d.ts +75 -0
  63. package/dist/execution/execution-processor.d.ts.map +1 -0
  64. package/dist/execution/execution-processor.js +569 -0
  65. package/dist/execution/execution-processor.js.map +1 -0
  66. package/dist/execution/execution.module.d.ts +3 -0
  67. package/dist/execution/execution.module.d.ts.map +1 -0
  68. package/dist/execution/execution.module.js +56 -0
  69. package/dist/execution/execution.module.js.map +1 -0
  70. package/dist/execution/execution.service.d.ts +52 -0
  71. package/dist/execution/execution.service.d.ts.map +1 -0
  72. package/dist/execution/execution.service.js +182 -0
  73. package/dist/execution/execution.service.js.map +1 -0
  74. package/dist/execution/index.d.ts +11 -0
  75. package/dist/execution/index.d.ts.map +1 -0
  76. package/dist/execution/index.js +30 -0
  77. package/dist/execution/index.js.map +1 -0
  78. package/dist/execution/interfaces/job-data.interface.d.ts +38 -0
  79. package/dist/execution/interfaces/job-data.interface.d.ts.map +1 -0
  80. package/dist/execution/interfaces/job-data.interface.js +3 -0
  81. package/dist/execution/interfaces/job-data.interface.js.map +1 -0
  82. package/dist/execution/judge-llm.d.ts +35 -0
  83. package/dist/execution/judge-llm.d.ts.map +1 -0
  84. package/dist/execution/judge-llm.js +129 -0
  85. package/dist/execution/judge-llm.js.map +1 -0
  86. package/dist/execution/llm-config-resolver.d.ts +26 -0
  87. package/dist/execution/llm-config-resolver.d.ts.map +1 -0
  88. package/dist/execution/llm-config-resolver.js +99 -0
  89. package/dist/execution/llm-config-resolver.js.map +1 -0
  90. package/dist/execution/persona-llm.d.ts +29 -0
  91. package/dist/execution/persona-llm.d.ts.map +1 -0
  92. package/dist/execution/persona-llm.js +98 -0
  93. package/dist/execution/persona-llm.js.map +1 -0
  94. package/dist/execution/persona-strategy-registry.d.ts +14 -0
  95. package/dist/execution/persona-strategy-registry.d.ts.map +1 -0
  96. package/dist/execution/persona-strategy-registry.js +51 -0
  97. package/dist/execution/persona-strategy-registry.js.map +1 -0
  98. package/dist/execution/persona-strategy.interface.d.ts +88 -0
  99. package/dist/execution/persona-strategy.interface.d.ts.map +1 -0
  100. package/dist/execution/persona-strategy.interface.js +3 -0
  101. package/dist/execution/persona-strategy.interface.js.map +1 -0
  102. package/dist/execution/queue-producer.service.d.ts +21 -0
  103. package/dist/execution/queue-producer.service.d.ts.map +1 -0
  104. package/dist/execution/queue-producer.service.js +60 -0
  105. package/dist/execution/queue-producer.service.js.map +1 -0
  106. package/dist/execution/queues.config.d.ts +39 -0
  107. package/dist/execution/queues.config.d.ts.map +1 -0
  108. package/dist/execution/queues.config.js +43 -0
  109. package/dist/execution/queues.config.js.map +1 -0
  110. package/dist/execution/strategies/default.strategy.d.ts +11 -0
  111. package/dist/execution/strategies/default.strategy.d.ts.map +1 -0
  112. package/dist/execution/strategies/default.strategy.js +31 -0
  113. package/dist/execution/strategies/default.strategy.js.map +1 -0
  114. package/dist/execution/strategies/reactive.strategy.d.ts +28 -0
  115. package/dist/execution/strategies/reactive.strategy.d.ts.map +1 -0
  116. package/dist/execution/strategies/reactive.strategy.js +220 -0
  117. package/dist/execution/strategies/reactive.strategy.js.map +1 -0
  118. package/dist/execution/template-renderer.d.ts +52 -0
  119. package/dist/execution/template-renderer.d.ts.map +1 -0
  120. package/dist/execution/template-renderer.js +90 -0
  121. package/dist/execution/template-renderer.js.map +1 -0
  122. package/dist/generation/index.d.ts +2 -0
  123. package/dist/generation/index.d.ts.map +1 -0
  124. package/dist/generation/index.js +6 -0
  125. package/dist/generation/index.js.map +1 -0
  126. package/dist/generation/scenario-generator.service.d.ts +77 -0
  127. package/dist/generation/scenario-generator.service.d.ts.map +1 -0
  128. package/dist/generation/scenario-generator.service.js +272 -0
  129. package/dist/generation/scenario-generator.service.js.map +1 -0
  130. package/dist/index.d.ts +10 -0
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.js +27 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/personas/dto/create-persona.dto.d.ts +61 -0
  135. package/dist/personas/dto/create-persona.dto.d.ts.map +1 -0
  136. package/dist/personas/dto/create-persona.dto.js +146 -0
  137. package/dist/personas/dto/create-persona.dto.js.map +1 -0
  138. package/dist/personas/dto/index.d.ts +3 -0
  139. package/dist/personas/dto/index.d.ts.map +1 -0
  140. package/dist/personas/dto/index.js +19 -0
  141. package/dist/personas/dto/index.js.map +1 -0
  142. package/dist/personas/dto/update-persona.dto.d.ts +8 -0
  143. package/dist/personas/dto/update-persona.dto.d.ts.map +1 -0
  144. package/dist/personas/dto/update-persona.dto.js +29 -0
  145. package/dist/personas/dto/update-persona.dto.js.map +1 -0
  146. package/dist/personas/index.d.ts +6 -0
  147. package/dist/personas/index.d.ts.map +1 -0
  148. package/dist/personas/index.js +22 -0
  149. package/dist/personas/index.js.map +1 -0
  150. package/dist/personas/persona.controller.d.ts +69 -0
  151. package/dist/personas/persona.controller.d.ts.map +1 -0
  152. package/dist/personas/persona.controller.js +282 -0
  153. package/dist/personas/persona.controller.js.map +1 -0
  154. package/dist/personas/persona.module.d.ts +3 -0
  155. package/dist/personas/persona.module.d.ts.map +1 -0
  156. package/dist/personas/persona.module.js +28 -0
  157. package/dist/personas/persona.module.js.map +1 -0
  158. package/dist/personas/persona.service.d.ts +85 -0
  159. package/dist/personas/persona.service.d.ts.map +1 -0
  160. package/dist/personas/persona.service.js +382 -0
  161. package/dist/personas/persona.service.js.map +1 -0
  162. package/dist/personas/schemas/persona.schema.d.ts +90 -0
  163. package/dist/personas/schemas/persona.schema.d.ts.map +1 -0
  164. package/dist/personas/schemas/persona.schema.js +321 -0
  165. package/dist/personas/schemas/persona.schema.js.map +1 -0
  166. package/dist/scenarios/controllers/scenario-execution.controller.d.ts +48 -0
  167. package/dist/scenarios/controllers/scenario-execution.controller.d.ts.map +1 -0
  168. package/dist/scenarios/controllers/scenario-execution.controller.js +260 -0
  169. package/dist/scenarios/controllers/scenario-execution.controller.js.map +1 -0
  170. package/dist/scenarios/controllers/scenario.controller.d.ts +81 -0
  171. package/dist/scenarios/controllers/scenario.controller.d.ts.map +1 -0
  172. package/dist/scenarios/controllers/scenario.controller.js +345 -0
  173. package/dist/scenarios/controllers/scenario.controller.js.map +1 -0
  174. package/dist/scenarios/dto/create-scenario.dto.d.ts +31 -0
  175. package/dist/scenarios/dto/create-scenario.dto.d.ts.map +1 -0
  176. package/dist/scenarios/dto/create-scenario.dto.js +102 -0
  177. package/dist/scenarios/dto/create-scenario.dto.js.map +1 -0
  178. package/dist/scenarios/dto/execute-scenario.dto.d.ts +34 -0
  179. package/dist/scenarios/dto/execute-scenario.dto.d.ts.map +1 -0
  180. package/dist/scenarios/dto/execute-scenario.dto.js +150 -0
  181. package/dist/scenarios/dto/execute-scenario.dto.js.map +1 -0
  182. package/dist/scenarios/dto/index.d.ts +4 -0
  183. package/dist/scenarios/dto/index.d.ts.map +1 -0
  184. package/dist/scenarios/dto/index.js +20 -0
  185. package/dist/scenarios/dto/index.js.map +1 -0
  186. package/dist/scenarios/dto/update-scenario.dto.d.ts +6 -0
  187. package/dist/scenarios/dto/update-scenario.dto.d.ts.map +1 -0
  188. package/dist/scenarios/dto/update-scenario.dto.js +9 -0
  189. package/dist/scenarios/dto/update-scenario.dto.js.map +1 -0
  190. package/dist/scenarios/index.d.ts +9 -0
  191. package/dist/scenarios/index.d.ts.map +1 -0
  192. package/dist/scenarios/index.js +25 -0
  193. package/dist/scenarios/index.js.map +1 -0
  194. package/dist/scenarios/scenario.module.d.ts +3 -0
  195. package/dist/scenarios/scenario.module.d.ts.map +1 -0
  196. package/dist/scenarios/scenario.module.js +42 -0
  197. package/dist/scenarios/scenario.module.js.map +1 -0
  198. package/dist/scenarios/schemas/scenario-execution.schema.d.ts +133 -0
  199. package/dist/scenarios/schemas/scenario-execution.schema.d.ts.map +1 -0
  200. package/dist/scenarios/schemas/scenario-execution.schema.js +292 -0
  201. package/dist/scenarios/schemas/scenario-execution.schema.js.map +1 -0
  202. package/dist/scenarios/schemas/scenario.schema.d.ts +106 -0
  203. package/dist/scenarios/schemas/scenario.schema.d.ts.map +1 -0
  204. package/dist/scenarios/schemas/scenario.schema.js +205 -0
  205. package/dist/scenarios/schemas/scenario.schema.js.map +1 -0
  206. package/dist/scenarios/services/scenario-execution.service.d.ts +73 -0
  207. package/dist/scenarios/services/scenario-execution.service.d.ts.map +1 -0
  208. package/dist/scenarios/services/scenario-execution.service.js +505 -0
  209. package/dist/scenarios/services/scenario-execution.service.js.map +1 -0
  210. package/dist/scenarios/services/scenario.service.d.ts +110 -0
  211. package/dist/scenarios/services/scenario.service.d.ts.map +1 -0
  212. package/dist/scenarios/services/scenario.service.js +608 -0
  213. package/dist/scenarios/services/scenario.service.js.map +1 -0
  214. package/dist/simulator/index.d.ts +2 -0
  215. package/dist/simulator/index.d.ts.map +1 -0
  216. package/dist/simulator/index.js +18 -0
  217. package/dist/simulator/index.js.map +1 -0
  218. package/dist/simulator/persona-simulator.service.d.ts +81 -0
  219. package/dist/simulator/persona-simulator.service.d.ts.map +1 -0
  220. package/dist/simulator/persona-simulator.service.js +358 -0
  221. package/dist/simulator/persona-simulator.service.js.map +1 -0
  222. package/dist/templates/dto/create-template.dto.d.ts +16 -0
  223. package/dist/templates/dto/create-template.dto.d.ts.map +1 -0
  224. package/dist/templates/dto/create-template.dto.js +75 -0
  225. package/dist/templates/dto/create-template.dto.js.map +1 -0
  226. package/dist/templates/dto/index.d.ts +4 -0
  227. package/dist/templates/dto/index.d.ts.map +1 -0
  228. package/dist/templates/dto/index.js +10 -0
  229. package/dist/templates/dto/index.js.map +1 -0
  230. package/dist/templates/dto/instantiate-template.dto.d.ts +7 -0
  231. package/dist/templates/dto/instantiate-template.dto.d.ts.map +1 -0
  232. package/dist/templates/dto/instantiate-template.dto.js +38 -0
  233. package/dist/templates/dto/instantiate-template.dto.js.map +1 -0
  234. package/dist/templates/dto/update-template.dto.d.ts +6 -0
  235. package/dist/templates/dto/update-template.dto.d.ts.map +1 -0
  236. package/dist/templates/dto/update-template.dto.js +9 -0
  237. package/dist/templates/dto/update-template.dto.js.map +1 -0
  238. package/dist/templates/index.d.ts +6 -0
  239. package/dist/templates/index.d.ts.map +1 -0
  240. package/dist/templates/index.js +22 -0
  241. package/dist/templates/index.js.map +1 -0
  242. package/dist/templates/scenario-template.controller.d.ts +42 -0
  243. package/dist/templates/scenario-template.controller.d.ts.map +1 -0
  244. package/dist/templates/scenario-template.controller.js +148 -0
  245. package/dist/templates/scenario-template.controller.js.map +1 -0
  246. package/dist/templates/scenario-template.module.d.ts +3 -0
  247. package/dist/templates/scenario-template.module.d.ts.map +1 -0
  248. package/dist/templates/scenario-template.module.js +30 -0
  249. package/dist/templates/scenario-template.module.js.map +1 -0
  250. package/dist/templates/scenario-template.service.d.ts +50 -0
  251. package/dist/templates/scenario-template.service.d.ts.map +1 -0
  252. package/dist/templates/scenario-template.service.js +497 -0
  253. package/dist/templates/scenario-template.service.js.map +1 -0
  254. package/dist/templates/schemas/scenario-template.schema.d.ts +59 -0
  255. package/dist/templates/schemas/scenario-template.schema.d.ts.map +1 -0
  256. package/dist/templates/schemas/scenario-template.schema.js +132 -0
  257. package/dist/templates/schemas/scenario-template.schema.js.map +1 -0
  258. package/dist/tool-fixtures/dto/create-tool-fixture.dto.d.ts +18 -0
  259. package/dist/tool-fixtures/dto/create-tool-fixture.dto.d.ts.map +1 -0
  260. package/dist/tool-fixtures/dto/create-tool-fixture.dto.js +46 -0
  261. package/dist/tool-fixtures/dto/create-tool-fixture.dto.js.map +1 -0
  262. package/dist/tool-fixtures/dto/index.d.ts +4 -0
  263. package/dist/tool-fixtures/dto/index.d.ts.map +1 -0
  264. package/dist/tool-fixtures/dto/index.js +20 -0
  265. package/dist/tool-fixtures/dto/index.js.map +1 -0
  266. package/dist/tool-fixtures/dto/tool-fixture-filter.dto.d.ts +6 -0
  267. package/dist/tool-fixtures/dto/tool-fixture-filter.dto.d.ts.map +1 -0
  268. package/dist/tool-fixtures/dto/tool-fixture-filter.dto.js +33 -0
  269. package/dist/tool-fixtures/dto/tool-fixture-filter.dto.js.map +1 -0
  270. package/dist/tool-fixtures/dto/update-tool-fixture.dto.d.ts +6 -0
  271. package/dist/tool-fixtures/dto/update-tool-fixture.dto.d.ts.map +1 -0
  272. package/dist/tool-fixtures/dto/update-tool-fixture.dto.js +9 -0
  273. package/dist/tool-fixtures/dto/update-tool-fixture.dto.js.map +1 -0
  274. package/dist/tool-fixtures/index.d.ts +7 -0
  275. package/dist/tool-fixtures/index.d.ts.map +1 -0
  276. package/dist/tool-fixtures/index.js +23 -0
  277. package/dist/tool-fixtures/index.js.map +1 -0
  278. package/dist/tool-fixtures/mock-resolver.service.d.ts +48 -0
  279. package/dist/tool-fixtures/mock-resolver.service.d.ts.map +1 -0
  280. package/dist/tool-fixtures/mock-resolver.service.js +99 -0
  281. package/dist/tool-fixtures/mock-resolver.service.js.map +1 -0
  282. package/dist/tool-fixtures/schemas/tool-fixture.schema.d.ts +35 -0
  283. package/dist/tool-fixtures/schemas/tool-fixture.schema.d.ts.map +1 -0
  284. package/dist/tool-fixtures/schemas/tool-fixture.schema.js +87 -0
  285. package/dist/tool-fixtures/schemas/tool-fixture.schema.js.map +1 -0
  286. package/dist/tool-fixtures/tool-fixture.controller.d.ts +45 -0
  287. package/dist/tool-fixtures/tool-fixture.controller.d.ts.map +1 -0
  288. package/dist/tool-fixtures/tool-fixture.controller.js +223 -0
  289. package/dist/tool-fixtures/tool-fixture.controller.js.map +1 -0
  290. package/dist/tool-fixtures/tool-fixture.module.d.ts +3 -0
  291. package/dist/tool-fixtures/tool-fixture.module.d.ts.map +1 -0
  292. package/dist/tool-fixtures/tool-fixture.module.js +31 -0
  293. package/dist/tool-fixtures/tool-fixture.module.js.map +1 -0
  294. package/dist/tool-fixtures/tool-fixture.service.d.ts +59 -0
  295. package/dist/tool-fixtures/tool-fixture.service.d.ts.map +1 -0
  296. package/dist/tool-fixtures/tool-fixture.service.js +198 -0
  297. package/dist/tool-fixtures/tool-fixture.service.js.map +1 -0
  298. package/package.json +47 -0
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpAdapter = void 0;
4
+ class HttpAdapter {
5
+ constructor() {
6
+ this.name = 'HTTP';
7
+ this.type = 'http';
8
+ this.config = {};
9
+ this.connected = false;
10
+ }
11
+ async connect(config) {
12
+ if (!config.endpoint) {
13
+ throw new Error('HTTP adapter requires endpoint URL');
14
+ }
15
+ this.config = { ...config };
16
+ this.connected = true;
17
+ }
18
+ async sendMessage(message, history) {
19
+ if (!this.connected) {
20
+ throw new Error('HTTP adapter not connected. Call connect() first.');
21
+ }
22
+ const start = Date.now();
23
+ const headers = {
24
+ 'Content-Type': 'application/json',
25
+ ...this.config.headers,
26
+ };
27
+ if (this.config.apiKey) {
28
+ headers['Authorization'] = `Bearer ${this.config.apiKey}`;
29
+ }
30
+ const requestBody = {
31
+ message,
32
+ history,
33
+ systemPrompt: this.config.systemPrompt,
34
+ model: this.config.model,
35
+ temperature: this.config.temperature,
36
+ };
37
+ if (this.config.tools?.length) {
38
+ requestBody.tools = this.config.tools;
39
+ }
40
+ const response = await fetch(this.config.endpoint, {
41
+ method: 'POST',
42
+ headers,
43
+ body: JSON.stringify(requestBody),
44
+ });
45
+ if (!response.ok) {
46
+ const error = await response.text();
47
+ throw new Error(`HTTP endpoint error (${response.status}): ${error}`);
48
+ }
49
+ const data = await response.json();
50
+ const latencyMs = Date.now() - start;
51
+ // Support multiple response formats
52
+ const content = typeof data === 'string'
53
+ ? data
54
+ : data.content || data.message || data.response || data.text || '';
55
+ // Normalize tool calls to include an id field
56
+ const rawToolCalls = data.toolCalls || data.tool_calls;
57
+ const toolCalls = rawToolCalls?.map((tc, idx) => ({
58
+ id: tc.id || `http_call_${idx}`,
59
+ name: tc.name,
60
+ arguments: tc.arguments || {},
61
+ ...(tc.result !== undefined ? { result: tc.result } : {}),
62
+ }));
63
+ return {
64
+ content,
65
+ latencyMs,
66
+ toolCalls: toolCalls?.length ? toolCalls : undefined,
67
+ metadata: data.metadata || {},
68
+ };
69
+ }
70
+ formatToolResult(toolCallId, toolName, result) {
71
+ return {
72
+ role: 'user',
73
+ content: typeof result === 'string' ? result : JSON.stringify(result),
74
+ providerData: {
75
+ toolCallId,
76
+ toolName,
77
+ isToolResult: true,
78
+ },
79
+ };
80
+ }
81
+ buildToolCallHistory(response, resolvedResults) {
82
+ const messages = [];
83
+ messages.push({ role: 'assistant', content: response.content || '' });
84
+ for (const r of resolvedResults) {
85
+ messages.push(this.formatToolResult(r.id, r.name, r.result));
86
+ }
87
+ return messages;
88
+ }
89
+ async disconnect() {
90
+ this.connected = false;
91
+ this.config = {};
92
+ }
93
+ }
94
+ exports.HttpAdapter = HttpAdapter;
95
+ //# sourceMappingURL=http.adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.adapter.js","sourceRoot":"","sources":["../../src/adapters/http.adapter.ts"],"names":[],"mappings":";;;AAOA,MAAa,WAAW;IAAxB;QACW,SAAI,GAAG,MAAM,CAAC;QACd,SAAI,GAAG,MAAM,CAAC;QAEf,WAAM,GAAuB,EAAE,CAAC;QAChC,cAAS,GAAG,KAAK,CAAC;IA0G5B,CAAC;IAxGC,KAAK,CAAC,OAAO,CAAC,MAA0B;QACtC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,WAAW,CACf,OAAe,EACf,OAAuB;QAEvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEzB,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO;SACvB,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACvB,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC5D,CAAC;QAED,MAAM,WAAW,GAAwB;YACvC,OAAO;YACP,OAAO;YACP,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;YACtC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;YACxB,WAAW,EAAE,I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IACnB,CAAC;CACF;AA/GD,kCA+GC"}
@@ -0,0 +1,6 @@
1
+ export * from './agent-adapter.interface';
2
+ export * from './adapter-registry';
3
+ export * from './openai.adapter';
4
+ export * from './anthropic.adapter';
5
+ export * from './http.adapter';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./agent-adapter.interface"), exports);
18
+ __exportStar(require("./adapter-registry"), exports);
19
+ __exportStar(require("./openai.adapter"), exports);
20
+ __exportStar(require("./anthropic.adapter"), exports);
21
+ __exportStar(require("./http.adapter"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,qDAAmC;AACnC,mDAAiC;AACjC,sDAAoC;AACpC,iDAA+B"}
@@ -0,0 +1,17 @@
1
+ import { AgentAdapter, AgentAdapterConfig, AgentMessage, AgentResponse } from './agent-adapter.interface';
2
+ export declare class OpenAIAdapter implements AgentAdapter {
3
+ readonly name = "OpenAI";
4
+ readonly type = "openai";
5
+ private config;
6
+ private connected;
7
+ connect(config: AgentAdapterConfig): Promise<void>;
8
+ sendMessage(message: string, history: AgentMessage[]): Promise<AgentResponse>;
9
+ formatToolResult(toolCallId: string, _toolName: string, result: any): AgentMessage;
10
+ buildToolCallHistory(response: AgentResponse, resolvedResults: Array<{
11
+ id: string;
12
+ name: string;
13
+ result: any;
14
+ }>): AgentMessage[];
15
+ disconnect(): Promise<void>;
16
+ }
17
+ //# sourceMappingURL=openai.adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/openai.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACd,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,aAAc,YAAW,YAAY;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,IAAI,YAAY;IAEzB,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,SAAS,CAAS;IAEpB,OAAO,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBlD,WAAW,CACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,YAAY,EAAE,GACtB,OAAO,CAAC,aAAa,CAAC;IAoFzB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,YAAY;IAWlF,oBAAoB,CAClB,QAAQ,EAAE,aAAa,EACvB,eAAe,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,CAAC,GAChE,YAAY,EAAE;IAoBX,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAIlC"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAIAdapter = void 0;
4
+ class OpenAIAdapter {
5
+ constructor() {
6
+ this.name = 'OpenAI';
7
+ this.type = 'openai';
8
+ this.config = {};
9
+ this.connected = false;
10
+ }
11
+ async connect(config) {
12
+ if (!config.apiKey) {
13
+ throw new Error('OpenAI adapter requires apiKey');
14
+ }
15
+ this.config = {
16
+ model: 'gpt-4o',
17
+ temperature: 0.7,
18
+ maxTokens: 1024,
19
+ endpoint: 'https://api.openai.com/v1/chat/completions',
20
+ ...config,
21
+ };
22
+ // Defense-in-depth: AgentConfigResolver strips undefined values, but
23
+ // guard against endpoint being wiped if config is assembled elsewhere.
24
+ if (!this.config.endpoint) {
25
+ this.config.endpoint = 'https://api.openai.com/v1/chat/completions';
26
+ }
27
+ this.connected = true;
28
+ }
29
+ async sendMessage(message, history) {
30
+ if (!this.connected) {
31
+ throw new Error('OpenAI adapter not connected. Call connect() first.');
32
+ }
33
+ const messages = [];
34
+ if (this.config.systemPrompt) {
35
+ messages.push({ role: 'system', content: this.config.systemPrompt });
36
+ }
37
+ for (const msg of history) {
38
+ if (msg.providerData) {
39
+ // Pass through provider-specific message structure (e.g. assistant
40
+ // messages with tool_calls, or tool-role result messages)
41
+ messages.push({ role: msg.role, content: msg.content, ...msg.providerData });
42
+ }
43
+ else {
44
+ messages.push({ role: msg.role, content: msg.content });
45
+ }
46
+ }
47
+ messages.push({ role: 'user', content: message });
48
+ const start = Date.now();
49
+ const requestBody = {
50
+ model: this.config.model,
51
+ messages,
52
+ temperature: this.config.temperature,
53
+ max_tokens: this.config.maxTokens,
54
+ };
55
+ if (this.config.tools?.length) {
56
+ requestBody.tools = this.config.tools.map((t) => ({
57
+ type: 'function',
58
+ function: {
59
+ name: t.name,
60
+ description: t.description,
61
+ parameters: t.parameters,
62
+ },
63
+ }));
64
+ }
65
+ const response = await fetch(this.config.endpoint, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/json',
69
+ Authorization: `Bearer ${this.config.apiKey}`,
70
+ ...this.config.headers,
71
+ },
72
+ body: JSON.stringify(requestBody),
73
+ });
74
+ if (!response.ok) {
75
+ const error = await response.text();
76
+ throw new Error(`OpenAI API error (${response.status}): ${error}`);
77
+ }
78
+ const data = await response.json();
79
+ const latencyMs = Date.now() - start;
80
+ const choice = data.choices?.[0];
81
+ const rawToolCalls = choice?.message?.tool_calls;
82
+ const toolCalls = rawToolCalls?.map((tc) => ({
83
+ id: tc.id,
84
+ name: tc.function.name,
85
+ arguments: JSON.parse(tc.function.arguments || '{}'),
86
+ }));
87
+ return {
88
+ content: choice?.message?.content || '',
89
+ latencyMs,
90
+ toolCalls: toolCalls?.length ? toolCalls : undefined,
91
+ metadata: {
92
+ model: data.model,
93
+ usage: data.usage,
94
+ finishReason: choice?.finish_reason,
95
+ // Preserve raw tool_calls so the caller can rebuild history
96
+ // with providerData for multi-turn tool use
97
+ ...(rawToolCalls ? { rawToolCalls } : {}),
98
+ },
99
+ };
100
+ }
101
+ formatToolResult(toolCallId, _toolName, result) {
102
+ return {
103
+ role: 'user',
104
+ content: typeof result === 'string' ? result : JSON.stringify(result),
105
+ providerData: {
106
+ role: 'tool',
107
+ tool_call_id: toolCallId,
108
+ },
109
+ };
110
+ }
111
+ buildToolCallHistory(response, resolvedResults) {
112
+ const messages = [];
113
+ // 1. Assistant message with raw tool_calls from OpenAI's response
114
+ messages.push({
115
+ role: 'assistant',
116
+ content: response.content || '',
117
+ providerData: response.metadata?.rawToolCalls
118
+ ? { tool_calls: response.metadata.rawToolCalls }
119
+ : undefined,
120
+ });
121
+ // 2. One tool-role message per result
122
+ for (const r of resolvedResults) {
123
+ messages.push(this.formatToolResult(r.id, r.name, r.result));
124
+ }
125
+ return messages;
126
+ }
127
+ async disconnect() {
128
+ this.connected = false;
129
+ this.config = {};
130
+ }
131
+ }
132
+ exports.OpenAIAdapter = OpenAIAdapter;
133
+ //# sourceMappingURL=openai.adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.adapter.js","sourceRoot":"","sources":["../../src/adapters/openai.adapter.ts"],"names":[],"mappings":";;;AAOA,MAAa,aAAa;IAA1B;QACW,SAAI,GAAG,QAAQ,CAAC;QAChB,SAAI,GAAG,QAAQ,CAAC;QAEjB,WAAM,GAAuB,EAAE,CAAC;QAChC,cAAS,GAAG,KAAK,CAAC;IAkJ5B,CAAC;IAhJC,KAAK,CAAC,OAAO,CAAC,MAA0B;QACtC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QACD,IAAI,CAAC,MAAM,GAAG;YACZ,KAAK,EAAE,QAAQ;YACf,WAAW,EAAE,GAAG;YAChB,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,4CAA4C;YACtD,GAAG,MAAM;SACV,CAAC;QACF,qEAAqE;QACrE,uEAAuE;QACvE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,4CAA4C,CAAC;QACtE,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,WAAW,CACf,OAAe,EACf,OAAuB;QAEvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,MAAM,QAAQ,GAA+B,EAAE,CAAC;QAEhD,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;YAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE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AAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;CACF;AAvJD,sCAuJC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Converts execution stepResults into a normalized ConversationRecord
3
+ * suitable for format-specific exporters.
4
+ *
5
+ * This is the bridge between chanl-eval's internal transcript format
6
+ * and the universal training data formats.
7
+ */
8
+ import type { StepResult } from '../scenarios/schemas/scenario-execution.schema';
9
+ import type { ConversationRecord, ConversationMetadata, ToolDefinition } from './types';
10
+ export interface ConvertOptions {
11
+ /** The system prompt of the agent under test */
12
+ systemPrompt?: string;
13
+ /** Tool definitions used during the conversation */
14
+ tools?: ToolDefinition[];
15
+ /** Metadata about the execution */
16
+ metadata: ConversationMetadata;
17
+ }
18
+ /**
19
+ * Convert an array of StepResults (from a completed execution) into
20
+ * a normalized ConversationRecord for dataset export.
21
+ *
22
+ * Mapping:
23
+ * - role: 'persona' → role: 'user'
24
+ * - role: 'agent' → role: 'assistant'
25
+ * - role: 'tool' → split into assistant tool_call + tool result messages
26
+ */
27
+ export declare function stepResultsToConversation(stepResults: StepResult[], options: ConvertOptions): ConversationRecord;
28
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/dataset/convert.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAC;AACjF,OAAO,KAAK,EACV,kBAAkB,EAElB,oBAAoB,EACpB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,mCAAmC;IACnC,QAAQ,EAAE,oBAAoB,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,UAAU,EAAE,EACzB,OAAO,EAAE,cAAc,GACtB,kBAAkB,CA8EpB"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /**
3
+ * Converts execution stepResults into a normalized ConversationRecord
4
+ * suitable for format-specific exporters.
5
+ *
6
+ * This is the bridge between chanl-eval's internal transcript format
7
+ * and the universal training data formats.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.stepResultsToConversation = stepResultsToConversation;
11
+ /**
12
+ * Convert an array of StepResults (from a completed execution) into
13
+ * a normalized ConversationRecord for dataset export.
14
+ *
15
+ * Mapping:
16
+ * - role: 'persona' → role: 'user'
17
+ * - role: 'agent' → role: 'assistant'
18
+ * - role: 'tool' → split into assistant tool_call + tool result messages
19
+ */
20
+ function stepResultsToConversation(stepResults, options) {
21
+ const messages = [];
22
+ let toolCallCounter = 0;
23
+ for (let i = 0; i < stepResults.length; i++) {
24
+ const step = stepResults[i];
25
+ if (!step.actualResponse && !step.toolCalls?.length)
26
+ continue;
27
+ switch (step.role) {
28
+ case 'persona':
29
+ messages.push({
30
+ role: 'user',
31
+ content: step.actualResponse || '',
32
+ });
33
+ break;
34
+ case 'agent':
35
+ messages.push({
36
+ role: 'assistant',
37
+ content: step.actualResponse || '',
38
+ });
39
+ break;
40
+ case 'tool': {
41
+ // Tool steps contain both the call and result.
42
+ // We need to emit:
43
+ // 1. An assistant message with tool_calls (if not already emitted)
44
+ // 2. A tool result message for each call
45
+ if (step.toolCalls?.length) {
46
+ for (const tc of step.toolCalls) {
47
+ const callId = `call_${++toolCallCounter}`;
48
+ // Check if the previous message is an assistant with tool_calls
49
+ // that already includes this call — avoid duplicating
50
+ const prev = messages[messages.length - 1];
51
+ if (prev?.role === 'assistant' && prev.toolCalls?.some((c) => c.name === tc.name)) {
52
+ // Already have the assistant tool call, just add the result
53
+ const existingCall = prev.toolCalls.find((c) => c.name === tc.name);
54
+ messages.push({
55
+ role: 'tool',
56
+ content: typeof tc.result === 'string' ? tc.result : JSON.stringify(tc.result ?? {}),
57
+ toolCallId: existingCall?.id || callId,
58
+ });
59
+ }
60
+ else {
61
+ // Emit assistant message with tool_calls
62
+ messages.push({
63
+ role: 'assistant',
64
+ content: '',
65
+ toolCalls: [{
66
+ id: callId,
67
+ name: tc.name,
68
+ arguments: tc.arguments || {},
69
+ }],
70
+ });
71
+ // Emit tool result
72
+ messages.push({
73
+ role: 'tool',
74
+ content: typeof tc.result === 'string' ? tc.result : JSON.stringify(tc.result ?? {}),
75
+ toolCallId: callId,
76
+ });
77
+ }
78
+ }
79
+ }
80
+ break;
81
+ }
82
+ default:
83
+ // Skip unknown roles
84
+ break;
85
+ }
86
+ }
87
+ return {
88
+ messages,
89
+ systemPrompt: options.systemPrompt,
90
+ tools: options.tools,
91
+ metadata: options.metadata,
92
+ };
93
+ }
94
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/dataset/convert.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AA4BH,8DAiFC;AA1FD;;;;;;;;GAQG;AACH,SAAgB,yBAAyB,CACvC,WAAyB,EACzB,OAAuB;IAEvB,MAAM,QAAQ,GAA0B,EAAE,CAAC;IAC3C,IAAI,eAAe,GAAG,CAAC,CAAC;IAExB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM;YAAE,SAAS;QAE9D,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,SAAS;gBACZ,QAAQ,CAAC,IAAI,CAAC;oBACZ,IAAI,EAAE,MAAM;oB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MAAM;6BACvC,CAAC,CAAC;wBACL,CAAC;6BAAM,CAAC;4BACN,yCAAyC;4BACzC,QAAQ,CAAC,IAAI,CAAC;gCACZ,IAAI,EAAE,WAAW;gCACjB,OAAO,EAAE,EAAE;gCACX,SAAS,EAAE,CAAC;wCACV,EAAE,EAAE,MAAM;wCACV,IAAI,EAAE,EAAE,CAAC,IAAI;wCACb,SAAS,EAAE,EAAE,CAAC,SAAS,IAAI,EAAE;qCAC9B,CAAC;6BACH,CAAC,CAAC;4BACH,mBAAmB;4BACnB,QAAQ,CAAC,IAAI,CAAC;gCACZ,IAAI,EAAE,MAAM;gCACZ,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC;gCACpF,UAAU,EAAE,MAAM;6BACnB,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;gBACH,CAAC;gBACD,MAAM;YACR,CAAC;YAED;gBACE,qBAAqB;gBACrB,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO;QACL,QAAQ;QACR,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * DPO (Direct Preference Optimization) format converter.
3
+ *
4
+ * Produces JSONL where each line is a preference pair:
5
+ * {"input": {"messages": [...]}, "preferred_output": [...], "non_preferred_output": [...]}
6
+ *
7
+ * Compatible with: OpenAI DPO fine-tuning, Together AI preference, TRL DPOTrainer.
8
+ *
9
+ * DPO requires TWO executions of the same scenario — one scored higher than the other.
10
+ * The higher-scored execution's assistant responses become preferred_output.
11
+ *
12
+ * Spec: https://platform.openai.com/docs/guides/direct-preference-optimization
13
+ */
14
+ import type { ConversationRecord, DPOLine } from '../types';
15
+ export interface DPOFormatOptions {
16
+ /** Override system prompt. Pass null to omit. */
17
+ systemPrompt?: string | null;
18
+ /**
19
+ * Minimum score delta between preferred and non-preferred.
20
+ * Pairs with less separation are skipped.
21
+ * Default: 0 (include all pairs).
22
+ */
23
+ minScoreDelta?: number;
24
+ }
25
+ /**
26
+ * Create a DPO preference pair from two ConversationRecords of the same scenario.
27
+ *
28
+ * The higher-scored conversation's assistant responses are preferred.
29
+ * Returns null if the pair doesn't meet the minScoreDelta threshold.
30
+ *
31
+ * Strategy: Extract the LAST assistant response from each conversation
32
+ * as the preference signal, with all preceding messages as shared input.
33
+ * This works because both conversations start from the same scenario
34
+ * (same persona opening → same initial user messages).
35
+ */
36
+ export declare function toDPO(conversationA: ConversationRecord, conversationB: ConversationRecord, options?: DPOFormatOptions): DPOLine | null;
37
+ /**
38
+ * Serialize to JSONL string (one line).
39
+ */
40
+ export declare function toDPOJsonl(conversationA: ConversationRecord, conversationB: ConversationRecord, options?: DPOFormatOptions): string | null;
41
+ //# sourceMappingURL=dpo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dpo.d.ts","sourceRoot":"","sources":["../../../src/dataset/formats/dpo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CACnB,aAAa,EAAE,kBAAkB,EACjC,aAAa,EAAE,kBAAkB,EACjC,OAAO,GAAE,gBAAqB,GAC7B,OAAO,GAAG,IAAI,CAmDhB;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,aAAa,EAAE,kBAAkB,EACjC,aAAa,EAAE,kBAAkB,EACjC,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,IAAI,CAGf"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * DPO (Direct Preference Optimization) format converter.
4
+ *
5
+ * Produces JSONL where each line is a preference pair:
6
+ * {"input": {"messages": [...]}, "preferred_output": [...], "non_preferred_output": [...]}
7
+ *
8
+ * Compatible with: OpenAI DPO fine-tuning, Together AI preference, TRL DPOTrainer.
9
+ *
10
+ * DPO requires TWO executions of the same scenario — one scored higher than the other.
11
+ * The higher-scored execution's assistant responses become preferred_output.
12
+ *
13
+ * Spec: https://platform.openai.com/docs/guides/direct-preference-optimization
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.toDPO = toDPO;
17
+ exports.toDPOJsonl = toDPOJsonl;
18
+ /**
19
+ * Create a DPO preference pair from two ConversationRecords of the same scenario.
20
+ *
21
+ * The higher-scored conversation's assistant responses are preferred.
22
+ * Returns null if the pair doesn't meet the minScoreDelta threshold.
23
+ *
24
+ * Strategy: Extract the LAST assistant response from each conversation
25
+ * as the preference signal, with all preceding messages as shared input.
26
+ * This works because both conversations start from the same scenario
27
+ * (same persona opening → same initial user messages).
28
+ */
29
+ function toDPO(conversationA, conversationB, options = {}) {
30
+ const scoreA = conversationA.metadata.score ?? 0;
31
+ const scoreB = conversationB.metadata.score ?? 0;
32
+ const minDelta = options.minScoreDelta ?? 0;
33
+ // Ensure sufficient score separation
34
+ if (Math.abs(scoreA - scoreB) < minDelta) {
35
+ return null;
36
+ }
37
+ const [preferred, nonPreferred] = scoreA >= scoreB
38
+ ? [conversationA, conversationB]
39
+ : [conversationB, conversationA];
40
+ const systemPrompt = options.systemPrompt !== undefined
41
+ ? options.systemPrompt
42
+ : preferred.systemPrompt;
43
+ // Build shared input from user messages (persona turns)
44
+ const inputMessages = [];
45
+ if (systemPrompt) {
46
+ inputMessages.push({ role: 'system', content: systemPrompt });
47
+ }
48
+ // Use the preferred conversation's user messages as the input context.
49
+ // Both conversations should share similar user turns (same scenario+persona)
50
+ // but the preferred one is canonical.
51
+ for (const msg of preferred.messages) {
52
+ if (msg.role === 'user') {
53
+ inputMessages.push({ role: 'user', content: msg.content });
54
+ }
55
+ }
56
+ // Extract all assistant responses from each conversation
57
+ const preferredOutputs = preferred.messages
58
+ .filter((m) => m.role === 'assistant' && m.content && !m.toolCalls?.length)
59
+ .map((m) => ({ role: 'assistant', content: m.content }));
60
+ const nonPreferredOutputs = nonPreferred.messages
61
+ .filter((m) => m.role === 'assistant' && m.content && !m.toolCalls?.length)
62
+ .map((m) => ({ role: 'assistant', content: m.content }));
63
+ if (!preferredOutputs.length || !nonPreferredOutputs.length) {
64
+ return null;
65
+ }
66
+ return {
67
+ input: { messages: inputMessages },
68
+ preferred_output: preferredOutputs,
69
+ non_preferred_output: nonPreferredOutputs,
70
+ };
71
+ }
72
+ /**
73
+ * Serialize to JSONL string (one line).
74
+ */
75
+ function toDPOJsonl(conversationA, conversationB, options = {}) {
76
+ const line = toDPO(conversationA, conversationB, options);
77
+ return line ? JSON.stringify(line) : null;
78
+ }
79
+ //# sourceMappingURL=dpo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dpo.js","sourceRoot":"","sources":["../../../src/dataset/formats/dpo.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AA0BH,sBAuDC;AAKD,gCAOC;AA9ED;;;;;;;;;;GAUG;AACH,SAAgB,KAAK,CACnB,aAAiC,EACjC,aAAiC,EACjC,UAA4B,EAAE;IAE9B,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC;IAE5C,qCAAqC;IACrC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM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AY,CAAC,QAAQ;SAC9C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC;SAC1E,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAoB,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAEpE,IAAI,CAAC,gBAAgB,CAAC,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,KAAK,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE;QAClC,gBAAgB,EAAE,gBAAgB;QAClC,oBAAoB,EAAE,mBAAmB;KAC1C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CACxB,aAAiC,EACjC,aAAiC,EACjC,UAA4B,EAAE;IAE9B,MAAM,IAAI,GAAG,KAAK,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { toOpenAIChat, toOpenAIChatJsonl, type OpenAIFormatOptions } from './openai';
2
+ export { toShareGPT, toShareGPTJsonl, type ShareGPTFormatOptions } from './sharegpt';
3
+ export { toDPO, toDPOJsonl, type DPOFormatOptions } from './dpo';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dataset/formats/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDPOJsonl = exports.toDPO = exports.toShareGPTJsonl = exports.toShareGPT = exports.toOpenAIChatJsonl = exports.toOpenAIChat = void 0;
4
+ var openai_1 = require("./openai");
5
+ Object.defineProperty(exports, "toOpenAIChat", { enumerable: true, get: function () { return openai_1.toOpenAIChat; } });
6
+ Object.defineProperty(exports, "toOpenAIChatJsonl", { enumerable: true, get: function () { return openai_1.toOpenAIChatJsonl; } });
7
+ var sharegpt_1 = require("./sharegpt");
8
+ Object.defineProperty(exports, "toShareGPT", { enumerable: true, get: function () { return sharegpt_1.toShareGPT; } });
9
+ Object.defineProperty(exports, "toShareGPTJsonl", { enumerable: true, get: function () { return sharegpt_1.toShareGPTJsonl; } });
10
+ var dpo_1 = require("./dpo");
11
+ Object.defineProperty(exports, "toDPO", { enumerable: true, get: function () { return dpo_1.toDPO; } });
12
+ Object.defineProperty(exports, "toDPOJsonl", { enumerable: true, get: function () { return dpo_1.toDPOJsonl; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dataset/formats/index.ts"],"names":[],"mappings":";;;AAAA,mCAAqF;AAA5E,sGAAA,YAAY,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AACxC,uCAAqF;AAA5E,sGAAA,UAAU,OAAA;AAAE,2GAAA,eAAe,OAAA;AACpC,6BAAiE;AAAxD,4FAAA,KAAK,OAAA;AAAE,iGAAA,UAAU,OAAA"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * OpenAI Chat Completion fine-tuning format.
3
+ *
4
+ * Produces JSONL where each line is:
5
+ * {"messages": [{"role": "system", ...}, {"role": "user", ...}, {"role": "assistant", ...}]}
6
+ *
7
+ * With tools (openai-tools format), also includes:
8
+ * {"tools": [...], "messages": [...assistant with tool_calls..., ...tool results...]}
9
+ *
10
+ * Compatible with: OpenAI, Together AI, Fireworks, Axolotl, Unsloth, LLaMA Factory.
11
+ *
12
+ * Spec: https://platform.openai.com/docs/guides/supervised-fine-tuning
13
+ */
14
+ import type { ConversationRecord, OpenAIChatLine } from '../types';
15
+ export interface OpenAIFormatOptions {
16
+ /** Include tool definitions and tool call messages */
17
+ includeTools?: boolean;
18
+ /** Override system prompt. Pass null to omit. */
19
+ systemPrompt?: string | null;
20
+ }
21
+ /**
22
+ * Convert a ConversationRecord to an OpenAI fine-tuning JSONL line.
23
+ */
24
+ export declare function toOpenAIChat(record: ConversationRecord, options?: OpenAIFormatOptions): OpenAIChatLine;
25
+ /**
26
+ * Serialize to JSONL string (one line).
27
+ */
28
+ export declare function toOpenAIChatJsonl(record: ConversationRecord, options?: OpenAIFormatOptions): string;
29
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/dataset/formats/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEnE,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,mBAAwB,GAChC,cAAc,CAgFhB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,mBAAwB,GAChC,MAAM,CAER"}