mdi-llmkit 0.1.0 → 1.0.1

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 (36) hide show
  1. package/README.md +116 -34
  2. package/dist/src/comparison/compareLists.d.ts +97 -0
  3. package/dist/src/comparison/compareLists.js +375 -0
  4. package/dist/src/comparison/index.d.ts +1 -0
  5. package/dist/src/comparison/index.js +1 -0
  6. package/dist/src/gptApi/functions.d.ts +21 -0
  7. package/dist/src/gptApi/functions.js +154 -0
  8. package/dist/src/gptApi/gptConversation.d.ts +43 -0
  9. package/dist/src/gptApi/gptConversation.js +146 -0
  10. package/dist/src/gptApi/index.d.ts +3 -0
  11. package/dist/src/gptApi/index.js +3 -0
  12. package/dist/src/gptApi/jsonSchemaFormat.d.ts +14 -0
  13. package/dist/src/gptApi/jsonSchemaFormat.js +198 -0
  14. package/dist/src/index.d.ts +3 -0
  15. package/dist/src/index.js +3 -0
  16. package/dist/src/jsonSurgery/jsonSurgery.d.ts +81 -0
  17. package/dist/src/jsonSurgery/jsonSurgery.js +776 -0
  18. package/dist/src/jsonSurgery/placemarkedJSON.d.ts +57 -0
  19. package/dist/src/jsonSurgery/placemarkedJSON.js +151 -0
  20. package/dist/tests/comparison/compareLists.test.d.ts +1 -0
  21. package/dist/tests/comparison/compareLists.test.js +434 -0
  22. package/dist/tests/gptApi/gptConversation.test.d.ts +1 -0
  23. package/dist/tests/gptApi/gptConversation.test.js +157 -0
  24. package/dist/tests/gptApi/gptSubmit.test.d.ts +1 -0
  25. package/dist/tests/gptApi/gptSubmit.test.js +161 -0
  26. package/dist/tests/gptApi/jsonSchemaFormat.test.d.ts +1 -0
  27. package/dist/tests/gptApi/jsonSchemaFormat.test.js +372 -0
  28. package/dist/tests/jsonSurgery/jsonSurgery.test.d.ts +1 -0
  29. package/dist/tests/jsonSurgery/jsonSurgery.test.js +729 -0
  30. package/dist/tests/jsonSurgery/placemarkedJSON.test.d.ts +1 -0
  31. package/dist/tests/jsonSurgery/placemarkedJSON.test.js +209 -0
  32. package/dist/tests/setupEnv.d.ts +1 -0
  33. package/dist/tests/setupEnv.js +4 -0
  34. package/dist/tests/subpathExports.test.d.ts +1 -0
  35. package/dist/tests/subpathExports.test.js +47 -0
  36. package/package.json +18 -5
@@ -0,0 +1,372 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { JSON_BOOLEAN, JSON_INTEGER, JSON_NUMBER, JSON_STRING, JSONSchemaFormat, } from '../../src/gptApi/jsonSchemaFormat.js';
3
+ describe('JSONSchemaFormat', () => {
4
+ it('expands object schema with primitive fields', () => {
5
+ const result = JSONSchemaFormat('response', {
6
+ title: 'Human-readable title',
7
+ age: JSON_INTEGER,
8
+ score: JSON_NUMBER,
9
+ enabled: JSON_BOOLEAN,
10
+ }, 'Structured response payload');
11
+ expect(result).toEqual({
12
+ format: {
13
+ type: 'json_schema',
14
+ strict: true,
15
+ name: 'response',
16
+ description: 'Structured response payload',
17
+ schema: {
18
+ type: 'object',
19
+ additionalProperties: false,
20
+ required: ['title', 'age', 'score', 'enabled'],
21
+ properties: {
22
+ title: { type: 'string', description: 'Human-readable title' },
23
+ age: { type: 'integer' },
24
+ score: { type: 'number' },
25
+ enabled: { type: 'boolean' },
26
+ },
27
+ },
28
+ },
29
+ });
30
+ });
31
+ it('wraps non-object root schema with provided name', () => {
32
+ const result = JSONSchemaFormat('answer', JSON_STRING);
33
+ expect(result).toEqual({
34
+ format: {
35
+ type: 'json_schema',
36
+ strict: true,
37
+ name: 'answer',
38
+ schema: {
39
+ type: 'object',
40
+ additionalProperties: false,
41
+ required: ['answer'],
42
+ properties: {
43
+ answer: { type: 'string' },
44
+ },
45
+ },
46
+ },
47
+ });
48
+ });
49
+ it('supports enum shorthand from string list', () => {
50
+ const result = JSONSchemaFormat('answer_enum', {
51
+ mode: ['fast', 'safe', 'balanced'],
52
+ });
53
+ expect(result).toEqual({
54
+ format: {
55
+ type: 'json_schema',
56
+ strict: true,
57
+ name: 'answer_enum',
58
+ schema: {
59
+ type: 'object',
60
+ additionalProperties: false,
61
+ required: ['mode'],
62
+ properties: {
63
+ mode: {
64
+ type: 'string',
65
+ enum: ['fast', 'safe', 'balanced'],
66
+ },
67
+ },
68
+ },
69
+ },
70
+ });
71
+ });
72
+ it('supports metadata tuple style for array bounds and item description', () => {
73
+ const result = JSONSchemaFormat('test_schema', {
74
+ tags: ['Tag collection', [1, 5], ['Single tag']],
75
+ });
76
+ expect(result).toEqual({
77
+ format: {
78
+ type: 'json_schema',
79
+ strict: true,
80
+ name: 'test_schema',
81
+ schema: {
82
+ type: 'object',
83
+ additionalProperties: false,
84
+ required: ['tags'],
85
+ properties: {
86
+ tags: {
87
+ type: 'array',
88
+ description: 'Tag collection',
89
+ minItems: 1,
90
+ maxItems: 5,
91
+ items: { type: 'string', description: 'Single tag' },
92
+ },
93
+ },
94
+ },
95
+ },
96
+ });
97
+ });
98
+ it('infers integer and enum via tuple metadata', () => {
99
+ const result = JSONSchemaFormat('test_schema', {
100
+ age: ['Age in years', [0, 120], []],
101
+ color: ['Preferred color', ['red', 'green', 'blue'], []],
102
+ });
103
+ expect(result).toEqual({
104
+ format: {
105
+ type: 'json_schema',
106
+ strict: true,
107
+ name: 'test_schema',
108
+ schema: {
109
+ type: 'object',
110
+ additionalProperties: false,
111
+ required: ['age', 'color'],
112
+ properties: {
113
+ age: {
114
+ type: 'integer',
115
+ description: 'Age in years',
116
+ minimum: 0,
117
+ maximum: 120,
118
+ },
119
+ color: {
120
+ type: 'string',
121
+ description: 'Preferred color',
122
+ enum: ['red', 'green', 'blue'],
123
+ },
124
+ },
125
+ },
126
+ },
127
+ });
128
+ });
129
+ it('supports number type with range metadata when explicitly marked', () => {
130
+ const result = JSONSchemaFormat('test_schema', {
131
+ confidence: ['Confidence score', [0.0, 1.0], JSON_NUMBER],
132
+ });
133
+ expect(result).toEqual({
134
+ format: {
135
+ type: 'json_schema',
136
+ strict: true,
137
+ name: 'test_schema',
138
+ schema: {
139
+ type: 'object',
140
+ additionalProperties: false,
141
+ required: ['confidence'],
142
+ properties: {
143
+ confidence: {
144
+ type: 'number',
145
+ description: 'Confidence score',
146
+ minimum: 0.0,
147
+ maximum: 1.0,
148
+ },
149
+ },
150
+ },
151
+ },
152
+ });
153
+ });
154
+ it('supports one-sided numeric bounds', () => {
155
+ const result = JSONSchemaFormat('test_schema', {
156
+ min_only: ['Minimum only', [0, null], []],
157
+ max_only: ['Maximum only', [null, 10], []],
158
+ });
159
+ expect(result).toEqual({
160
+ format: {
161
+ type: 'json_schema',
162
+ strict: true,
163
+ name: 'test_schema',
164
+ schema: {
165
+ type: 'object',
166
+ additionalProperties: false,
167
+ required: ['min_only', 'max_only'],
168
+ properties: {
169
+ min_only: {
170
+ type: 'integer',
171
+ description: 'Minimum only',
172
+ minimum: 0,
173
+ },
174
+ max_only: {
175
+ type: 'integer',
176
+ description: 'Maximum only',
177
+ maximum: 10,
178
+ },
179
+ },
180
+ },
181
+ },
182
+ });
183
+ });
184
+ it('supports nested recursive schemas', () => {
185
+ const result = JSONSchemaFormat('nested_schema', {
186
+ groups: [
187
+ {
188
+ name: 'Group name',
189
+ members: [
190
+ {
191
+ id: JSON_INTEGER,
192
+ roles: ['admin', 'viewer'],
193
+ tags: ['Tag label'],
194
+ profile: {
195
+ active: JSON_BOOLEAN,
196
+ scores: [JSON_NUMBER],
197
+ },
198
+ },
199
+ ],
200
+ },
201
+ ],
202
+ });
203
+ expect(result).toEqual({
204
+ format: {
205
+ type: 'json_schema',
206
+ strict: true,
207
+ name: 'nested_schema',
208
+ schema: {
209
+ type: 'object',
210
+ additionalProperties: false,
211
+ required: ['groups'],
212
+ properties: {
213
+ groups: {
214
+ type: 'array',
215
+ items: {
216
+ type: 'object',
217
+ additionalProperties: false,
218
+ required: ['name', 'members'],
219
+ properties: {
220
+ name: {
221
+ type: 'string',
222
+ description: 'Group name',
223
+ },
224
+ members: {
225
+ type: 'array',
226
+ items: {
227
+ type: 'object',
228
+ additionalProperties: false,
229
+ required: ['id', 'roles', 'tags', 'profile'],
230
+ properties: {
231
+ id: { type: 'integer' },
232
+ roles: { type: 'string', enum: ['admin', 'viewer'] },
233
+ tags: {
234
+ type: 'array',
235
+ items: { type: 'string', description: 'Tag label' },
236
+ },
237
+ profile: {
238
+ type: 'object',
239
+ additionalProperties: false,
240
+ required: ['active', 'scores'],
241
+ properties: {
242
+ active: { type: 'boolean' },
243
+ scores: {
244
+ type: 'array',
245
+ items: { type: 'number' },
246
+ },
247
+ },
248
+ },
249
+ },
250
+ },
251
+ },
252
+ },
253
+ },
254
+ },
255
+ },
256
+ },
257
+ },
258
+ });
259
+ });
260
+ it('supports nested recursive schemas with inner tuple metadata', () => {
261
+ const result = JSONSchemaFormat('nested_schema_with_metadata', {
262
+ groups: [
263
+ {
264
+ name: 'Group name',
265
+ members: [
266
+ 'Members list',
267
+ [1, null],
268
+ [
269
+ {
270
+ id: JSON_INTEGER,
271
+ score: ['Member score', [0.0, 1.0], JSON_NUMBER],
272
+ aliases: ['Alias list', [0, 3], ['Alias text']],
273
+ history: [
274
+ {
275
+ year: ['Year', [1900, 2100], JSON_INTEGER],
276
+ tags: ['History tags', [0, 5], ['Tag text']],
277
+ },
278
+ ],
279
+ },
280
+ ],
281
+ ],
282
+ },
283
+ ],
284
+ });
285
+ expect(result).toEqual({
286
+ format: {
287
+ type: 'json_schema',
288
+ strict: true,
289
+ name: 'nested_schema_with_metadata',
290
+ schema: {
291
+ type: 'object',
292
+ additionalProperties: false,
293
+ required: ['groups'],
294
+ properties: {
295
+ groups: {
296
+ type: 'array',
297
+ items: {
298
+ type: 'object',
299
+ additionalProperties: false,
300
+ required: ['name', 'members'],
301
+ properties: {
302
+ name: {
303
+ type: 'string',
304
+ description: 'Group name',
305
+ },
306
+ members: {
307
+ type: 'array',
308
+ description: 'Members list',
309
+ minItems: 1,
310
+ items: {
311
+ type: 'object',
312
+ additionalProperties: false,
313
+ required: ['id', 'score', 'aliases', 'history'],
314
+ properties: {
315
+ id: { type: 'integer' },
316
+ score: {
317
+ type: 'number',
318
+ description: 'Member score',
319
+ minimum: 0.0,
320
+ maximum: 1.0,
321
+ },
322
+ aliases: {
323
+ type: 'array',
324
+ description: 'Alias list',
325
+ minItems: 0,
326
+ maxItems: 3,
327
+ items: {
328
+ type: 'string',
329
+ description: 'Alias text',
330
+ },
331
+ },
332
+ history: {
333
+ type: 'array',
334
+ items: {
335
+ type: 'object',
336
+ additionalProperties: false,
337
+ required: ['year', 'tags'],
338
+ properties: {
339
+ year: {
340
+ type: 'integer',
341
+ description: 'Year',
342
+ minimum: 1900,
343
+ maximum: 2100,
344
+ },
345
+ tags: {
346
+ type: 'array',
347
+ description: 'History tags',
348
+ minItems: 0,
349
+ maxItems: 5,
350
+ items: {
351
+ type: 'string',
352
+ description: 'Tag text',
353
+ },
354
+ },
355
+ },
356
+ },
357
+ },
358
+ },
359
+ },
360
+ },
361
+ },
362
+ },
363
+ },
364
+ },
365
+ },
366
+ },
367
+ });
368
+ });
369
+ it('throws for unsupported schema values', () => {
370
+ expect(() => JSONSchemaFormat('test_schema', { bad: Symbol('x') })).toThrow('Unrecognized type for schema value');
371
+ });
372
+ });
@@ -0,0 +1 @@
1
+ export {};