@retab/node 0.0.48 → 0.0.52

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 (263) hide show
  1. package/README.md +8 -215
  2. package/dist/api/client.d.ts +2 -2
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +2 -2
  5. package/dist/api/documents/client.d.ts +3 -3
  6. package/dist/api/documents/client.d.ts.map +1 -1
  7. package/dist/api/documents/client.js +3 -3
  8. package/dist/api/projects/client.d.ts +15 -0
  9. package/dist/api/projects/client.d.ts.map +1 -0
  10. package/dist/api/projects/client.js +43 -0
  11. package/dist/api/projects/documents/client.d.ts +12 -0
  12. package/dist/api/projects/documents/client.d.ts.map +1 -0
  13. package/dist/api/projects/documents/client.js +39 -0
  14. package/dist/api/projects/iterations/client.d.ts +17 -0
  15. package/dist/api/projects/iterations/client.d.ts.map +1 -0
  16. package/dist/api/projects/iterations/client.js +64 -0
  17. package/dist/client.d.ts +1 -0
  18. package/dist/client.d.ts.map +1 -1
  19. package/dist/client.js +6 -1
  20. package/dist/generated_types.d.ts +17837 -40090
  21. package/dist/generated_types.d.ts.map +1 -1
  22. package/dist/generated_types.js +309 -979
  23. package/dist/index.d.ts +7 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -2
  26. package/dist/types.d.ts +188 -80
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/types.js +22 -1
  29. package/package.json +6 -9
  30. package/dist/api/consensus/client.d.ts +0 -7
  31. package/dist/api/consensus/client.d.ts.map +0 -1
  32. package/dist/api/consensus/client.js +0 -14
  33. package/dist/errors.d.ts +0 -34
  34. package/dist/errors.d.ts.map +0 -1
  35. package/dist/errors.js +0 -53
  36. package/dist/resource.d.ts +0 -12
  37. package/dist/resource.d.ts.map +0 -1
  38. package/dist/resource.js +0 -19
  39. package/dist/resources/consensus/completions.d.ts +0 -66
  40. package/dist/resources/consensus/completions.d.ts.map +0 -1
  41. package/dist/resources/consensus/completions.js +0 -84
  42. package/dist/resources/consensus/index.d.ts +0 -72
  43. package/dist/resources/consensus/index.d.ts.map +0 -1
  44. package/dist/resources/consensus/index.js +0 -76
  45. package/dist/resources/consensus/responses.d.ts +0 -69
  46. package/dist/resources/consensus/responses.d.ts.map +0 -1
  47. package/dist/resources/consensus/responses.js +0 -99
  48. package/dist/resources/documents/extractions.d.ts +0 -74
  49. package/dist/resources/documents/extractions.d.ts.map +0 -1
  50. package/dist/resources/documents/extractions.js +0 -196
  51. package/dist/resources/documents/index.d.ts +0 -21
  52. package/dist/resources/documents/index.d.ts.map +0 -1
  53. package/dist/resources/documents/index.js +0 -55
  54. package/dist/resources/evaluations/documents.d.ts +0 -40
  55. package/dist/resources/evaluations/documents.d.ts.map +0 -1
  56. package/dist/resources/evaluations/documents.js +0 -123
  57. package/dist/resources/evaluations/index.d.ts +0 -14
  58. package/dist/resources/evaluations/index.d.ts.map +0 -1
  59. package/dist/resources/evaluations/index.js +0 -17
  60. package/dist/resources/evaluations/iterations.d.ts +0 -50
  61. package/dist/resources/evaluations/iterations.d.ts.map +0 -1
  62. package/dist/resources/evaluations/iterations.js +0 -156
  63. package/dist/resources/files.d.ts +0 -82
  64. package/dist/resources/files.d.ts.map +0 -1
  65. package/dist/resources/files.js +0 -150
  66. package/dist/resources/finetuning.d.ts +0 -105
  67. package/dist/resources/finetuning.d.ts.map +0 -1
  68. package/dist/resources/finetuning.js +0 -181
  69. package/dist/resources/index.d.ts +0 -11
  70. package/dist/resources/index.d.ts.map +0 -1
  71. package/dist/resources/index.js +0 -10
  72. package/dist/resources/models.d.ts +0 -57
  73. package/dist/resources/models.d.ts.map +0 -1
  74. package/dist/resources/models.js +0 -72
  75. package/dist/resources/processors/automations/endpoints.d.ts +0 -90
  76. package/dist/resources/processors/automations/endpoints.d.ts.map +0 -1
  77. package/dist/resources/processors/automations/endpoints.js +0 -145
  78. package/dist/resources/processors/automations/index.d.ts +0 -7
  79. package/dist/resources/processors/automations/index.d.ts.map +0 -1
  80. package/dist/resources/processors/automations/index.js +0 -6
  81. package/dist/resources/processors/automations/links.d.ts +0 -90
  82. package/dist/resources/processors/automations/links.d.ts.map +0 -1
  83. package/dist/resources/processors/automations/links.js +0 -149
  84. package/dist/resources/processors/automations/logs.d.ts +0 -35
  85. package/dist/resources/processors/automations/logs.d.ts.map +0 -1
  86. package/dist/resources/processors/automations/logs.js +0 -60
  87. package/dist/resources/processors/automations/mailboxes.d.ts +0 -102
  88. package/dist/resources/processors/automations/mailboxes.d.ts.map +0 -1
  89. package/dist/resources/processors/automations/mailboxes.js +0 -157
  90. package/dist/resources/processors/automations/outlook.d.ts +0 -114
  91. package/dist/resources/processors/automations/outlook.d.ts.map +0 -1
  92. package/dist/resources/processors/automations/outlook.js +0 -170
  93. package/dist/resources/processors/automations/tests.d.ts +0 -58
  94. package/dist/resources/processors/automations/tests.d.ts.map +0 -1
  95. package/dist/resources/processors/automations/tests.js +0 -90
  96. package/dist/resources/processors/index.d.ts +0 -303
  97. package/dist/resources/processors/index.d.ts.map +0 -1
  98. package/dist/resources/processors/index.js +0 -261
  99. package/dist/resources/schemas.d.ts +0 -63
  100. package/dist/resources/schemas.d.ts.map +0 -1
  101. package/dist/resources/schemas.js +0 -183
  102. package/dist/resources/secrets/external_api_keys.d.ts +0 -61
  103. package/dist/resources/secrets/external_api_keys.d.ts.map +0 -1
  104. package/dist/resources/secrets/external_api_keys.js +0 -120
  105. package/dist/resources/secrets/index.d.ts +0 -14
  106. package/dist/resources/secrets/index.d.ts.map +0 -1
  107. package/dist/resources/secrets/index.js +0 -17
  108. package/dist/resources/secrets/webhooks.d.ts +0 -73
  109. package/dist/resources/secrets/webhooks.d.ts.map +0 -1
  110. package/dist/resources/secrets/webhooks.js +0 -145
  111. package/dist/resources/usage.d.ts +0 -223
  112. package/dist/resources/usage.d.ts.map +0 -1
  113. package/dist/resources/usage.js +0 -310
  114. package/dist/types/ai_models.d.ts +0 -389
  115. package/dist/types/ai_models.d.ts.map +0 -1
  116. package/dist/types/ai_models.js +0 -145
  117. package/dist/types/automations/cron.d.ts +0 -28
  118. package/dist/types/automations/cron.d.ts.map +0 -1
  119. package/dist/types/automations/cron.js +0 -1
  120. package/dist/types/automations/endpoints.d.ts +0 -13
  121. package/dist/types/automations/endpoints.d.ts.map +0 -1
  122. package/dist/types/automations/endpoints.js +0 -1
  123. package/dist/types/automations/index.d.ts +0 -7
  124. package/dist/types/automations/index.d.ts.map +0 -1
  125. package/dist/types/automations/index.js +0 -6
  126. package/dist/types/automations/links.d.ts +0 -15
  127. package/dist/types/automations/links.d.ts.map +0 -1
  128. package/dist/types/automations/links.js +0 -1
  129. package/dist/types/automations/mailboxes.d.ts +0 -18
  130. package/dist/types/automations/mailboxes.d.ts.map +0 -1
  131. package/dist/types/automations/mailboxes.js +0 -1
  132. package/dist/types/automations/outlook.d.ts +0 -37
  133. package/dist/types/automations/outlook.d.ts.map +0 -1
  134. package/dist/types/automations/outlook.js +0 -1
  135. package/dist/types/automations/webhooks.d.ts +0 -13
  136. package/dist/types/automations/webhooks.d.ts.map +0 -1
  137. package/dist/types/automations/webhooks.js +0 -1
  138. package/dist/types/browser_canvas.d.ts +0 -4
  139. package/dist/types/browser_canvas.d.ts.map +0 -1
  140. package/dist/types/browser_canvas.js +0 -2
  141. package/dist/types/chat.d.ts +0 -99
  142. package/dist/types/chat.d.ts.map +0 -1
  143. package/dist/types/chat.js +0 -20
  144. package/dist/types/consensus.d.ts +0 -10
  145. package/dist/types/consensus.d.ts.map +0 -1
  146. package/dist/types/consensus.js +0 -1
  147. package/dist/types/db/annotations.d.ts +0 -108
  148. package/dist/types/db/annotations.d.ts.map +0 -1
  149. package/dist/types/db/annotations.js +0 -6
  150. package/dist/types/db/files.d.ts +0 -133
  151. package/dist/types/db/files.d.ts.map +0 -1
  152. package/dist/types/db/files.js +0 -5
  153. package/dist/types/documents/extractions.d.ts +0 -1849
  154. package/dist/types/documents/extractions.d.ts.map +0 -1
  155. package/dist/types/documents/extractions.js +0 -211
  156. package/dist/types/documents/processing.d.ts +0 -249
  157. package/dist/types/documents/processing.d.ts.map +0 -1
  158. package/dist/types/documents/processing.js +0 -6
  159. package/dist/types/evaluations/iterations.d.ts +0 -41
  160. package/dist/types/evaluations/iterations.d.ts.map +0 -1
  161. package/dist/types/evaluations/iterations.js +0 -1
  162. package/dist/types/jobs/base.d.ts +0 -162
  163. package/dist/types/jobs/base.d.ts.map +0 -1
  164. package/dist/types/jobs/base.js +0 -6
  165. package/dist/types/jobs/specialized.d.ts +0 -200
  166. package/dist/types/jobs/specialized.d.ts.map +0 -1
  167. package/dist/types/jobs/specialized.js +0 -37
  168. package/dist/types/logs.d.ts +0 -92
  169. package/dist/types/logs.d.ts.map +0 -1
  170. package/dist/types/logs.js +0 -1
  171. package/dist/types/mime.d.ts +0 -426
  172. package/dist/types/mime.d.ts.map +0 -1
  173. package/dist/types/mime.js +0 -48
  174. package/dist/types/modalities.d.ts +0 -31
  175. package/dist/types/modalities.d.ts.map +0 -1
  176. package/dist/types/modalities.js +0 -109
  177. package/dist/types/pagination.d.ts +0 -5
  178. package/dist/types/pagination.d.ts.map +0 -1
  179. package/dist/types/pagination.js +0 -1
  180. package/dist/types/schemas/enhancement.d.ts +0 -250
  181. package/dist/types/schemas/enhancement.d.ts.map +0 -1
  182. package/dist/types/schemas/enhancement.js +0 -6
  183. package/dist/types/schemas/generate.d.ts +0 -160
  184. package/dist/types/schemas/generate.d.ts.map +0 -1
  185. package/dist/types/schemas/generate.js +0 -19
  186. package/dist/types/schemas/object.d.ts +0 -116
  187. package/dist/types/schemas/object.d.ts.map +0 -1
  188. package/dist/types/schemas/object.js +0 -861
  189. package/dist/types/secrets/external_api_keys.d.ts +0 -27
  190. package/dist/types/secrets/external_api_keys.d.ts.map +0 -1
  191. package/dist/types/secrets/external_api_keys.js +0 -11
  192. package/dist/types/secrets/index.d.ts +0 -2
  193. package/dist/types/secrets/index.d.ts.map +0 -1
  194. package/dist/types/secrets/index.js +0 -1
  195. package/dist/types/standards.d.ts +0 -37
  196. package/dist/types/standards.d.ts.map +0 -1
  197. package/dist/types/standards.js +0 -1
  198. package/dist/utils/ai_models.d.ts +0 -10
  199. package/dist/utils/ai_models.d.ts.map +0 -1
  200. package/dist/utils/ai_models.js +0 -183
  201. package/dist/utils/batch_processing.d.ts +0 -227
  202. package/dist/utils/batch_processing.d.ts.map +0 -1
  203. package/dist/utils/batch_processing.js +0 -268
  204. package/dist/utils/benchmarking.d.ts +0 -115
  205. package/dist/utils/benchmarking.d.ts.map +0 -1
  206. package/dist/utils/benchmarking.js +0 -355
  207. package/dist/utils/chat.d.ts +0 -70
  208. package/dist/utils/chat.d.ts.map +0 -1
  209. package/dist/utils/chat.js +0 -79
  210. package/dist/utils/cost_calculation.d.ts +0 -26
  211. package/dist/utils/cost_calculation.d.ts.map +0 -1
  212. package/dist/utils/cost_calculation.js +0 -99
  213. package/dist/utils/datasets.d.ts +0 -135
  214. package/dist/utils/datasets.d.ts.map +0 -1
  215. package/dist/utils/datasets.js +0 -359
  216. package/dist/utils/display.d.ts +0 -108
  217. package/dist/utils/display.d.ts.map +0 -1
  218. package/dist/utils/display.js +0 -244
  219. package/dist/utils/hash.d.ts +0 -18
  220. package/dist/utils/hash.d.ts.map +0 -1
  221. package/dist/utils/hash.js +0 -31
  222. package/dist/utils/hashing.d.ts +0 -18
  223. package/dist/utils/hashing.d.ts.map +0 -1
  224. package/dist/utils/hashing.js +0 -28
  225. package/dist/utils/index.d.ts +0 -8
  226. package/dist/utils/index.d.ts.map +0 -1
  227. package/dist/utils/index.js +0 -10
  228. package/dist/utils/json_schema.d.ts +0 -18
  229. package/dist/utils/json_schema.d.ts.map +0 -1
  230. package/dist/utils/json_schema.js +0 -334
  231. package/dist/utils/json_schema_utils.d.ts +0 -42
  232. package/dist/utils/json_schema_utils.d.ts.map +0 -1
  233. package/dist/utils/json_schema_utils.js +0 -212
  234. package/dist/utils/jsonl.d.ts +0 -60
  235. package/dist/utils/jsonl.d.ts.map +0 -1
  236. package/dist/utils/jsonl.js +0 -259
  237. package/dist/utils/mime.d.ts +0 -6
  238. package/dist/utils/mime.d.ts.map +0 -1
  239. package/dist/utils/mime.js +0 -129
  240. package/dist/utils/model_cards.d.ts +0 -219
  241. package/dist/utils/model_cards.d.ts.map +0 -1
  242. package/dist/utils/model_cards.js +0 -462
  243. package/dist/utils/prompt_optimization.d.ts +0 -96
  244. package/dist/utils/prompt_optimization.d.ts.map +0 -1
  245. package/dist/utils/prompt_optimization.js +0 -275
  246. package/dist/utils/responses.d.ts +0 -35
  247. package/dist/utils/responses.d.ts.map +0 -1
  248. package/dist/utils/responses.js +0 -37
  249. package/dist/utils/stream.d.ts +0 -13
  250. package/dist/utils/stream.d.ts.map +0 -1
  251. package/dist/utils/stream.js +0 -64
  252. package/dist/utils/stream_context_managers.d.ts +0 -147
  253. package/dist/utils/stream_context_managers.d.ts.map +0 -1
  254. package/dist/utils/stream_context_managers.js +0 -380
  255. package/dist/utils/usage.d.ts +0 -57
  256. package/dist/utils/usage.d.ts.map +0 -1
  257. package/dist/utils/usage.js +0 -97
  258. package/dist/utils/webhook_secrets.d.ts +0 -59
  259. package/dist/utils/webhook_secrets.d.ts.map +0 -1
  260. package/dist/utils/webhook_secrets.js +0 -107
  261. package/dist/utils/zod_to_json_schema.d.ts +0 -11
  262. package/dist/utils/zod_to_json_schema.d.ts.map +0 -1
  263. package/dist/utils/zod_to_json_schema.js +0 -123
@@ -1,334 +0,0 @@
1
- import fs from 'fs';
2
- import crypto from 'crypto';
3
- // Hash generation utilities
4
- export function generateBlake2bHashFromString(input) {
5
- // Using sha256 as Node.js doesn't have built-in blake2b
6
- return crypto.createHash('sha256').update(input).digest('hex').substring(0, 16);
7
- }
8
- export function generateSchemaDataId(jsonSchema) {
9
- const cleanedSchema = cleanSchema(JSON.parse(JSON.stringify(jsonSchema)), true, ['description', 'default', 'title', 'required', 'examples', 'deprecated', 'readOnly', 'writeOnly']);
10
- return 'sch_data_id_' + generateBlake2bHashFromString(JSON.stringify(cleanedSchema, Object.keys(cleanedSchema).sort()));
11
- }
12
- export function generateSchemaId(jsonSchema) {
13
- return 'sch_id_' + generateBlake2bHashFromString(JSON.stringify(jsonSchema, Object.keys(jsonSchema).sort()));
14
- }
15
- // Schema cleaning utilities
16
- export function cleanSchema(schema, removeCustomFields = true, fieldsToRemove = []) {
17
- const cleaned = { ...schema };
18
- // Remove specified fields
19
- for (const field of fieldsToRemove) {
20
- delete cleaned[field];
21
- }
22
- // Remove custom fields (starting with X-)
23
- if (removeCustomFields) {
24
- for (const key of Object.keys(cleaned)) {
25
- if (key.startsWith('X-')) {
26
- delete cleaned[key];
27
- }
28
- }
29
- }
30
- // Recursively clean nested objects
31
- for (const [key, value] of Object.entries(cleaned)) {
32
- if (typeof value === 'object' && value !== null) {
33
- if (Array.isArray(value)) {
34
- cleaned[key] = value.map(item => typeof item === 'object' && item !== null
35
- ? cleanSchema(item, removeCustomFields, fieldsToRemove)
36
- : item);
37
- }
38
- else {
39
- cleaned[key] = cleanSchema(value, removeCustomFields, fieldsToRemove);
40
- }
41
- }
42
- }
43
- return cleaned;
44
- }
45
- // JSON Schema loading utilities
46
- export function loadJsonSchema(jsonSchema) {
47
- if (typeof jsonSchema === 'string') {
48
- if (fs.existsSync(jsonSchema)) {
49
- return JSON.parse(fs.readFileSync(jsonSchema, 'utf-8'));
50
- }
51
- return JSON.parse(jsonSchema);
52
- }
53
- return jsonSchema;
54
- }
55
- // Schema expansion utilities
56
- export function expandRefs(schema) {
57
- const expanded = { ...schema };
58
- const definitions = expanded.$defs || expanded.definitions || {};
59
- function resolveRef(obj) {
60
- if (typeof obj === 'object' && obj !== null) {
61
- if (obj.$ref && typeof obj.$ref === 'string') {
62
- const refPath = obj.$ref;
63
- if (refPath.startsWith('#/$defs/')) {
64
- const defName = refPath.replace('#/$defs/', '');
65
- if (definitions[defName]) {
66
- return resolveRef(definitions[defName]);
67
- }
68
- }
69
- return obj;
70
- }
71
- if (Array.isArray(obj)) {
72
- return obj.map(resolveRef);
73
- }
74
- const resolved = {};
75
- for (const [key, value] of Object.entries(obj)) {
76
- resolved[key] = resolveRef(value);
77
- }
78
- return resolved;
79
- }
80
- return obj;
81
- }
82
- return resolveRef(expanded);
83
- }
84
- // Reasoning schema creation
85
- export function createReasoningSchema(schema) {
86
- const enhanced = JSON.parse(JSON.stringify(schema));
87
- function addReasoningFields(obj, path = '') {
88
- if (typeof obj === 'object' && obj !== null && !Array.isArray(obj)) {
89
- const enhanced = { ...obj };
90
- // Add reasoning field for this level
91
- const reasoningFieldName = path ? `reasoning___${path.split('.').pop()}` : 'reasoning___root';
92
- enhanced.properties = enhanced.properties || {};
93
- enhanced.properties[reasoningFieldName] = {
94
- type: 'string',
95
- description: 'Reasoning for extraction decisions at this level',
96
- 'X-ReasoningPrompt': 'Explain your reasoning for the extracted data',
97
- };
98
- // Recursively process properties
99
- if (enhanced.properties) {
100
- for (const [key, value] of Object.entries(enhanced.properties)) {
101
- if (key.startsWith('reasoning___'))
102
- continue;
103
- enhanced.properties[key] = addReasoningFields(value, path ? `${path}.${key}` : key);
104
- }
105
- }
106
- // Handle array items
107
- if (enhanced.items) {
108
- enhanced.items = addReasoningFields(enhanced.items, `${path}.*`);
109
- }
110
- return enhanced;
111
- }
112
- return obj;
113
- }
114
- return addReasoningFields(enhanced);
115
- }
116
- // Validation utilities
117
- export function validateCurrency(currencyCode) {
118
- if (currencyCode == null)
119
- return null;
120
- const code = String(currencyCode).trim();
121
- if (!code)
122
- return null;
123
- // Basic currency code validation (ISO 4217)
124
- const validCurrencies = ['USD', 'EUR', 'GBP', 'JPY', 'AUD', 'CAD', 'CHF', 'CNY'];
125
- return validCurrencies.includes(code.toUpperCase()) ? code.toUpperCase() : null;
126
- }
127
- export function validateCountryCode(value) {
128
- if (value == null)
129
- return null;
130
- const code = String(value).trim();
131
- if (!code)
132
- return null;
133
- // Basic country code validation (ISO 3166)
134
- const validCountries = ['US', 'CA', 'GB', 'FR', 'DE', 'JP', 'AU', 'IT', 'ES', 'NL'];
135
- return validCountries.includes(code.toUpperCase()) ? code.toUpperCase() : null;
136
- }
137
- export function validateEmailRegex(value) {
138
- if (value == null)
139
- return null;
140
- const email = String(value).trim();
141
- if (!email)
142
- return null;
143
- const pattern = /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/;
144
- return pattern.test(email) ? email.toLowerCase() : null;
145
- }
146
- export function validatePhoneNumber(value) {
147
- if (value == null)
148
- return null;
149
- const phone = String(value).trim();
150
- if (!phone)
151
- return null;
152
- // Basic phone number validation
153
- const pattern = /^\+?[1-9]\d{1,14}$/;
154
- return pattern.test(phone.replace(/\s|-/g, '')) ? phone : null;
155
- }
156
- // Filter auxiliary fields from JSON
157
- export function filterAuxiliaryFieldsJson(jsonData) {
158
- // Handle string input by parsing it first
159
- let data;
160
- if (typeof jsonData === 'string') {
161
- try {
162
- data = JSON.parse(jsonData);
163
- }
164
- catch (e) {
165
- // If parsing fails, return the string as-is (it might not be JSON)
166
- return jsonData;
167
- }
168
- }
169
- else {
170
- data = jsonData;
171
- }
172
- if (typeof data === 'object' && data !== null) {
173
- if (Array.isArray(data)) {
174
- return data.map(filterAuxiliaryFieldsJson);
175
- }
176
- const filtered = {};
177
- for (const [key, value] of Object.entries(data)) {
178
- if (!key.startsWith('reasoning___') && !key.startsWith('quote___') && !key.startsWith('X-')) {
179
- filtered[key] = filterAuxiliaryFieldsJson(value);
180
- }
181
- }
182
- return filtered;
183
- }
184
- return data;
185
- }
186
- // Convert JSON Schema to TypeScript interface
187
- export function jsonSchemaToTypescriptInterface(schema, addFieldDescription = true) {
188
- function getTypeScriptType(property) {
189
- if (property.type === 'string')
190
- return 'string';
191
- if (property.type === 'number' || property.type === 'integer')
192
- return 'number';
193
- if (property.type === 'boolean')
194
- return 'boolean';
195
- if (property.type === 'array') {
196
- const itemType = property.items ? getTypeScriptType(property.items) : 'any';
197
- return `${itemType}[]`;
198
- }
199
- if (property.type === 'object') {
200
- return 'Record<string, any>';
201
- }
202
- return 'any';
203
- }
204
- function generateInterface(obj, interfaceName = 'Schema') {
205
- let result = `interface ${interfaceName} {\n`;
206
- if (obj.properties) {
207
- for (const [key, property] of Object.entries(obj.properties)) {
208
- const prop = property;
209
- const optional = !obj.required || !obj.required.includes(key) ? '?' : '';
210
- const type = getTypeScriptType(prop);
211
- if (addFieldDescription && prop.description) {
212
- result += ` /** ${prop.description} */\n`;
213
- }
214
- result += ` ${key}${optional}: ${type};\n`;
215
- }
216
- }
217
- result += '}';
218
- return result;
219
- }
220
- return generateInterface(schema);
221
- }
222
- // Convert JSON Schema to NLP data structure
223
- export function jsonSchemaToNlpDataStructure(schema) {
224
- function processObject(obj, indent = 0) {
225
- const spaces = ' '.repeat(indent);
226
- let result = '';
227
- if (obj.properties) {
228
- for (const [key, property] of Object.entries(obj.properties)) {
229
- const prop = property;
230
- const optional = !obj.required || !obj.required.includes(key);
231
- const suffix = optional ? ' (optional)' : ' (required)';
232
- result += `${spaces}- ${key}${suffix}`;
233
- if (prop.description) {
234
- result += `: ${prop.description}`;
235
- }
236
- result += '\n';
237
- if (prop.type === 'object' && prop.properties) {
238
- result += processObject(prop, indent + 1);
239
- }
240
- else if (prop.type === 'array' && prop.items) {
241
- result += `${spaces} Items:\n`;
242
- if (prop.items.type === 'object') {
243
- result += processObject(prop.items, indent + 2);
244
- }
245
- else {
246
- result += `${spaces} Type: ${prop.items.type || 'any'}\n`;
247
- }
248
- }
249
- }
250
- }
251
- return result;
252
- }
253
- return processObject(schema);
254
- }
255
- // Convert JSON Schema to strict OpenAI schema
256
- export function jsonSchemaToStrictOpenaiSchema(schema) {
257
- const strict = JSON.parse(JSON.stringify(schema));
258
- function makeStrict(obj) {
259
- if (typeof obj === 'object' && obj !== null) {
260
- if (obj.type === 'object' && obj.properties) {
261
- // Ensure all properties are required for strict mode
262
- obj.required = Object.keys(obj.properties);
263
- obj.additionalProperties = false;
264
- for (const property of Object.values(obj.properties)) {
265
- makeStrict(property);
266
- }
267
- }
268
- else if (obj.type === 'array' && obj.items) {
269
- makeStrict(obj.items);
270
- }
271
- }
272
- return obj;
273
- }
274
- return makeStrict(strict);
275
- }
276
- // Unflatten dictionary utility
277
- export function unflattenDict(flatDict, separator = '.') {
278
- const result = {};
279
- for (const [key, value] of Object.entries(flatDict)) {
280
- const keys = key.split(separator);
281
- let current = result;
282
- for (let i = 0; i < keys.length - 1; i++) {
283
- const k = keys[i];
284
- if (!(k in current)) {
285
- current[k] = {};
286
- }
287
- current = current[k];
288
- }
289
- current[keys[keys.length - 1]] = value;
290
- }
291
- return result;
292
- }
293
- // Schema to TypeScript type utility
294
- export function schemaToTsType(schema, definitions = {}, visited = new Set(), depth = 0, maxDepth = 10, addFieldDescription = true) {
295
- if (depth > maxDepth)
296
- return 'any';
297
- if (schema.$ref) {
298
- const refName = schema.$ref.replace('#/$defs/', '');
299
- if (visited.has(refName))
300
- return refName;
301
- if (definitions[refName]) {
302
- visited.add(refName);
303
- return schemaToTsType(definitions[refName], definitions, visited, depth + 1, maxDepth, addFieldDescription);
304
- }
305
- return 'any';
306
- }
307
- switch (schema.type) {
308
- case 'string':
309
- return 'string';
310
- case 'number':
311
- case 'integer':
312
- return 'number';
313
- case 'boolean':
314
- return 'boolean';
315
- case 'array':
316
- if (schema.items) {
317
- const itemType = schemaToTsType(schema.items, definitions, visited, depth + 1, maxDepth, addFieldDescription);
318
- return `${itemType}[]`;
319
- }
320
- return 'any[]';
321
- case 'object':
322
- if (schema.properties) {
323
- const props = Object.entries(schema.properties).map(([key, prop]) => {
324
- const optional = !schema.required || !schema.required.includes(key) ? '?' : '';
325
- const propType = schemaToTsType(prop, definitions, visited, depth + 1, maxDepth, addFieldDescription);
326
- return `${key}${optional}: ${propType}`;
327
- });
328
- return `{ ${props.join('; ')} }`;
329
- }
330
- return 'Record<string, any>';
331
- default:
332
- return 'any';
333
- }
334
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Clean a schema by removing specified fields and custom fields.
3
- */
4
- export declare function cleanSchema(jsonSchema: Record<string, any>, options?: {
5
- removeCustomFields?: boolean;
6
- fieldsToRemove?: string[];
7
- }): Record<string, any>;
8
- /**
9
- * Generate a schema data ID (hash of schema data, ignoring prompt/description/default fields).
10
- * Uses Python-compatible JSON formatting with spaces and recursive key sorting.
11
- */
12
- export declare function generateSchemaDataId(jsonSchema: Record<string, any>): string;
13
- /**
14
- * Generate a schema ID (hash of the complete schema).
15
- * Uses Python-compatible JSON formatting (sort_keys=True, default separators).
16
- */
17
- export declare function generateSchemaId(jsonSchema: Record<string, any>): string;
18
- /**
19
- * Navigate a JSON path in a schema and get the value at that path.
20
- */
21
- export declare function getValueAtPath(obj: any, path: string): any;
22
- /**
23
- * Navigate a JSON path in a schema and set the value at that path.
24
- */
25
- export declare function setValueAtPath(obj: any, path: string, value: any): void;
26
- /**
27
- * Find attribute in schema using a pattern-based search.
28
- */
29
- export declare function getPatternAttribute(jsonSchema: Record<string, any>, pattern: string, attribute: 'X-FieldPrompt' | 'X-ReasoningPrompt' | 'type'): string | null;
30
- /**
31
- * Set attribute in schema using a pattern-based search.
32
- */
33
- export declare function setPatternAttribute(jsonSchema: Record<string, any>, pattern: string, attribute: 'X-FieldPrompt' | 'X-ReasoningPrompt' | 'X-SystemPrompt' | 'description', value: string): void;
34
- /**
35
- * Load a JSON schema from either a dictionary, JSON string, or file path.
36
- *
37
- * @param jsonSchema - Either a dictionary containing the schema, a JSON string, or a path to a JSON file
38
- * @returns The loaded JSON schema
39
- * @throws Error if the schema file contains invalid JSON or doesn't exist
40
- */
41
- export declare function loadJsonSchema(jsonSchema: Record<string, any> | string): Record<string, any>;
42
- //# sourceMappingURL=json_schema_utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json_schema_utils.d.ts","sourceRoot":"","sources":["../../src/utils/json_schema_utils.ts"],"names":[],"mappings":"AAoBA;;GAEG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,OAAO,GAAE;IACP,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,GACL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAkCrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAkB5E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAOxE;AA2BD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAa1D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAavE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,eAAe,GAAG,mBAAmB,GAAG,MAAM,GACxD,MAAM,GAAG,IAAI,CAaf;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,eAAe,GAAG,mBAAmB,GAAG,gBAAgB,GAAG,aAAa,EACnF,KAAK,EAAE,MAAM,GACZ,IAAI,CAgBN;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA0B5F"}
@@ -1,212 +0,0 @@
1
- import * as fs from 'fs';
2
- import { generateBlake2bHashFromString } from './hash.js';
3
- /**
4
- * Recursively sort all object keys to match Python's json.dumps(sort_keys=True).
5
- */
6
- function sortKeysRecursively(obj) {
7
- if (Array.isArray(obj)) {
8
- return obj.map(sortKeysRecursively);
9
- }
10
- else if (obj !== null && typeof obj === 'object') {
11
- return Object.keys(obj)
12
- .sort()
13
- .reduce((result, key) => {
14
- result[key] = sortKeysRecursively(obj[key]);
15
- return result;
16
- }, {});
17
- }
18
- return obj;
19
- }
20
- /**
21
- * Clean a schema by removing specified fields and custom fields.
22
- */
23
- export function cleanSchema(jsonSchema, options = {}) {
24
- if (!jsonSchema || typeof jsonSchema !== 'object') {
25
- throw new Error('Invalid schema provided');
26
- }
27
- const { removeCustomFields = false, fieldsToRemove = [] } = options;
28
- const cleaned = JSON.parse(JSON.stringify(jsonSchema)); // Deep clone
29
- function cleanObject(obj) {
30
- if (typeof obj !== 'object' || obj === null) {
31
- return obj;
32
- }
33
- if (Array.isArray(obj)) {
34
- return obj.map(cleanObject);
35
- }
36
- const result = {};
37
- for (const [key, value] of Object.entries(obj)) {
38
- // Skip custom fields (starting with X-)
39
- if (removeCustomFields && key.startsWith('X-')) {
40
- continue;
41
- }
42
- // Skip specified fields to remove
43
- if (fieldsToRemove.includes(key)) {
44
- continue;
45
- }
46
- result[key] = cleanObject(value);
47
- }
48
- return result;
49
- }
50
- return cleanObject(cleaned);
51
- }
52
- /**
53
- * Generate a schema data ID (hash of schema data, ignoring prompt/description/default fields).
54
- * Uses Python-compatible JSON formatting with spaces and recursive key sorting.
55
- */
56
- export function generateSchemaDataId(jsonSchema) {
57
- const cleanedSchema = cleanSchema(jsonSchema, {
58
- removeCustomFields: true,
59
- fieldsToRemove: [
60
- 'description',
61
- 'default',
62
- 'title',
63
- 'required',
64
- 'examples',
65
- 'deprecated',
66
- 'readOnly',
67
- 'writeOnly'
68
- ]
69
- });
70
- const sortedSchema = sortKeysRecursively(cleanedSchema);
71
- const hashInput = pythonJsonStringify(sortedSchema);
72
- return 'sch_data_id_' + generateBlake2bHashFromString(hashInput);
73
- }
74
- /**
75
- * Generate a schema ID (hash of the complete schema).
76
- * Uses Python-compatible JSON formatting (sort_keys=True, default separators).
77
- */
78
- export function generateSchemaId(jsonSchema) {
79
- if (!jsonSchema || typeof jsonSchema !== 'object') {
80
- throw new Error('Invalid schema provided');
81
- }
82
- const sortedSchema = sortKeysRecursively(jsonSchema);
83
- const hashInput = pythonJsonStringify(sortedSchema);
84
- return 'sch_id_' + generateBlake2bHashFromString(hashInput);
85
- }
86
- /**
87
- * Stringify JSON to match Python's json.dumps() format exactly.
88
- * Python uses separators (',', ': ') by default.
89
- */
90
- function pythonJsonStringify(obj) {
91
- if (obj === null)
92
- return 'null';
93
- if (typeof obj === 'boolean')
94
- return obj.toString();
95
- if (typeof obj === 'number')
96
- return obj.toString();
97
- if (typeof obj === 'string')
98
- return `"${obj}"`;
99
- if (Array.isArray(obj)) {
100
- const items = obj.map(pythonJsonStringify);
101
- return `[${items.join(', ')}]`;
102
- }
103
- if (typeof obj === 'object') {
104
- const pairs = Object.keys(obj)
105
- .sort() // Ensure sorted keys
106
- .map(key => `"${key}": ${pythonJsonStringify(obj[key])}`);
107
- return `{${pairs.join(', ')}}`;
108
- }
109
- return 'null';
110
- }
111
- /**
112
- * Navigate a JSON path in a schema and get the value at that path.
113
- */
114
- export function getValueAtPath(obj, path) {
115
- const parts = path.split('.');
116
- let current = obj;
117
- for (const part of parts) {
118
- if (current && typeof current === 'object' && part in current) {
119
- current = current[part];
120
- }
121
- else {
122
- return null;
123
- }
124
- }
125
- return current;
126
- }
127
- /**
128
- * Navigate a JSON path in a schema and set the value at that path.
129
- */
130
- export function setValueAtPath(obj, path, value) {
131
- const parts = path.split('.');
132
- let current = obj;
133
- for (let i = 0; i < parts.length - 1; i++) {
134
- const part = parts[i];
135
- if (!current[part] || typeof current[part] !== 'object') {
136
- current[part] = {};
137
- }
138
- current = current[part];
139
- }
140
- current[parts[parts.length - 1]] = value;
141
- }
142
- /**
143
- * Find attribute in schema using a pattern-based search.
144
- */
145
- export function getPatternAttribute(jsonSchema, pattern, attribute) {
146
- // Simple implementation - look for pattern in properties
147
- if (jsonSchema.properties && typeof jsonSchema.properties === 'object') {
148
- for (const [key, value] of Object.entries(jsonSchema.properties)) {
149
- if (key.includes(pattern) || pattern === key) {
150
- if (typeof value === 'object' && value !== null && attribute in value) {
151
- return value[attribute];
152
- }
153
- }
154
- }
155
- }
156
- return null;
157
- }
158
- /**
159
- * Set attribute in schema using a pattern-based search.
160
- */
161
- export function setPatternAttribute(jsonSchema, pattern, attribute, value) {
162
- // Simple implementation - set in root or in matching properties
163
- if (attribute === 'X-SystemPrompt') {
164
- jsonSchema[attribute] = value;
165
- return;
166
- }
167
- if (jsonSchema.properties && typeof jsonSchema.properties === 'object') {
168
- for (const [key, propValue] of Object.entries(jsonSchema.properties)) {
169
- if (key.includes(pattern) || pattern === key) {
170
- if (typeof propValue === 'object' && propValue !== null) {
171
- propValue[attribute] = value;
172
- }
173
- }
174
- }
175
- }
176
- }
177
- /**
178
- * Load a JSON schema from either a dictionary, JSON string, or file path.
179
- *
180
- * @param jsonSchema - Either a dictionary containing the schema, a JSON string, or a path to a JSON file
181
- * @returns The loaded JSON schema
182
- * @throws Error if the schema file contains invalid JSON or doesn't exist
183
- */
184
- export function loadJsonSchema(jsonSchema) {
185
- if (typeof jsonSchema === 'string') {
186
- // Check if it's a file path or JSON string
187
- if (jsonSchema.trim().startsWith('{') || jsonSchema.trim().startsWith('[')) {
188
- // It's a JSON string
189
- try {
190
- return JSON.parse(jsonSchema);
191
- }
192
- catch (error) {
193
- throw new Error(`Invalid JSON string: ${error}`);
194
- }
195
- }
196
- else {
197
- // It's a file path
198
- try {
199
- const fileContent = fs.readFileSync(jsonSchema, 'utf-8');
200
- return JSON.parse(fileContent);
201
- }
202
- catch (error) {
203
- if (error.code === 'ENOENT') {
204
- throw new Error(`Schema file not found: ${jsonSchema}`);
205
- }
206
- throw new Error(`Error reading or parsing schema file: ${error}`);
207
- }
208
- }
209
- }
210
- // It's already an object
211
- return jsonSchema;
212
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * JSONL (JSON Lines) utilities for handling line-delimited JSON data
3
- * Equivalent to Python's jsonlutils.py
4
- */
5
- export interface JSONLOptions {
6
- encoding?: BufferEncoding;
7
- highWaterMark?: number;
8
- }
9
- /**
10
- * Read JSONL file and return array of parsed objects
11
- */
12
- export declare function readJSONL(filePath: string, options?: JSONLOptions): Promise<any[]>;
13
- /**
14
- * Write array of objects to JSONL file
15
- */
16
- export declare function writeJSONL(filePath: string, data: any[], options?: JSONLOptions): Promise<void>;
17
- /**
18
- * Append single object to JSONL file
19
- */
20
- export declare function appendJSONL(filePath: string, data: any, options?: JSONLOptions): Promise<void>;
21
- /**
22
- * Stream JSONL file processing with transformation
23
- */
24
- export declare function streamJSONL<T, R>(inputPath: string, outputPath: string, transform: (item: T) => R | Promise<R>, options?: JSONLOptions): Promise<void>;
25
- /**
26
- * Validate JSONL file format
27
- */
28
- export declare function validateJSONL(filePath: string): Promise<{
29
- valid: boolean;
30
- errors: string[];
31
- }>;
32
- /**
33
- * Count lines in JSONL file
34
- */
35
- export declare function countJSONL(filePath: string): Promise<number>;
36
- /**
37
- * Split JSONL file into chunks
38
- */
39
- export declare function splitJSONL(inputPath: string, outputDir: string, chunkSize: number, options?: JSONLOptions): Promise<string[]>;
40
- /**
41
- * Merge multiple JSONL files
42
- */
43
- export declare function mergeJSONL(inputPaths: string[], outputPath: string, options?: JSONLOptions): Promise<void>;
44
- /**
45
- * Filter JSONL file based on predicate
46
- */
47
- export declare function filterJSONL<T>(inputPath: string, outputPath: string, predicate: (item: T) => boolean | Promise<boolean>, options?: JSONLOptions): Promise<number>;
48
- declare const _default: {
49
- readJSONL: typeof readJSONL;
50
- writeJSONL: typeof writeJSONL;
51
- appendJSONL: typeof appendJSONL;
52
- streamJSONL: typeof streamJSONL;
53
- validateJSONL: typeof validateJSONL;
54
- countJSONL: typeof countJSONL;
55
- splitJSONL: typeof splitJSONL;
56
- mergeJSONL: typeof mergeJSONL;
57
- filterJSONL: typeof filterJSONL;
58
- };
59
- export default _default;
60
- //# sourceMappingURL=jsonl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../../src/utils/jsonl.ts"],"names":[],"mappings":"AAMA;;;GAGG;AAEH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAsB5F;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzG;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAcxG;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACpC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACtC,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAqCf;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA+BnG;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBlE;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CA4CnB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,UAAU,EAAE,MAAM,EAAE,EACpB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CA0Bf;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EAClD,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,MAAM,CAAC,CAgCjB;;;;;;;;;;;;AAED,wBAUE"}