nuabase 2.3.2 → 2.3.3

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.
@@ -154,7 +154,7 @@ function requireLlmResponseExtraction() {
154
154
  hasRequiredLlmResponseExtraction = 1;
155
155
  Object.defineProperty(llmResponseExtraction, "__esModule", { value: true });
156
156
  llmResponseExtraction.extractThinkingFromResponse = extractThinkingFromResponse;
157
- llmResponseExtraction.extractJsonFromMarkdown = extractJsonFromMarkdown;
157
+ llmResponseExtraction.parseJsonFromLlmResponse = parseJsonFromLlmResponse;
158
158
  function extractThinkingFromResponse(input) {
159
159
  const startTag = "<think>";
160
160
  const endTag = "</think>";
@@ -184,25 +184,71 @@ function requireLlmResponseExtraction() {
184
184
  cleanedResponse
185
185
  };
186
186
  }
187
- function extractJsonFromMarkdown(input) {
187
+ function parseJsonFromLlmResponse(input) {
188
188
  const trimmed = input.trim();
189
189
  const codeFence = "```";
190
190
  const jsonFence = "```json";
191
- if (trimmed.startsWith(jsonFence)) {
192
- const startIndex = jsonFence.length;
193
- const endIndex = trimmed.lastIndexOf(codeFence);
194
- if (endIndex > startIndex) {
195
- return trimmed.substring(startIndex, endIndex).trim();
191
+ const lastJsonFence = trimmed.lastIndexOf(jsonFence);
192
+ if (lastJsonFence !== -1) {
193
+ const startIndex = lastJsonFence + jsonFence.length;
194
+ const endIndex = trimmed.indexOf(codeFence, startIndex);
195
+ if (endIndex !== -1) {
196
+ try {
197
+ return JSON.parse(trimmed.substring(startIndex, endIndex).trim());
198
+ } catch {
199
+ }
196
200
  }
197
201
  }
198
- if (trimmed.startsWith(codeFence) && !trimmed.startsWith(jsonFence)) {
199
- const startIndex = codeFence.length;
200
- const endIndex = trimmed.lastIndexOf(codeFence);
201
- if (endIndex > startIndex) {
202
- return trimmed.substring(startIndex, endIndex).trim();
202
+ const firstCodeFence = trimmed.indexOf(codeFence);
203
+ if (firstCodeFence !== -1) {
204
+ const startIndex = firstCodeFence + codeFence.length;
205
+ const endIndex = trimmed.indexOf(codeFence, startIndex);
206
+ if (endIndex !== -1) {
207
+ try {
208
+ return JSON.parse(trimmed.substring(startIndex, endIndex).trim());
209
+ } catch {
210
+ }
203
211
  }
204
212
  }
205
- return input;
213
+ const matchingClose = new Array(trimmed.length).fill(-1);
214
+ const stack = [];
215
+ let inString = false;
216
+ for (let k = 0; k < trimmed.length; k++) {
217
+ if (inString) {
218
+ if (trimmed[k] === "\\")
219
+ k++;
220
+ else if (trimmed[k] === '"')
221
+ inString = false;
222
+ continue;
223
+ }
224
+ if (trimmed[k] === '"') {
225
+ inString = true;
226
+ continue;
227
+ }
228
+ if (trimmed[k] === "{" || trimmed[k] === "[") {
229
+ stack.push(k);
230
+ } else if (trimmed[k] === "}" || trimmed[k] === "]") {
231
+ if (stack.length > 0) {
232
+ const open = stack.pop();
233
+ const expected = trimmed[open] === "{" ? "}" : "]";
234
+ if (trimmed[k] === expected)
235
+ matchingClose[open] = k;
236
+ }
237
+ }
238
+ }
239
+ for (let i = 0; i < trimmed.length; i++) {
240
+ if (trimmed[i] !== "{" && trimmed[i] !== "[")
241
+ continue;
242
+ const j = matchingClose[i];
243
+ if (j === -1)
244
+ continue;
245
+ try {
246
+ return JSON.parse(trimmed.substring(i, j + 1));
247
+ } catch {
248
+ continue;
249
+ }
250
+ }
251
+ return JSON.parse(trimmed);
206
252
  }
207
253
  return llmResponseExtraction;
208
254
  }
@@ -224,9 +270,8 @@ function requireCallLlmService() {
224
270
  const response = providerResponse.text;
225
271
  let parsedResponse;
226
272
  try {
227
- let { thinking, cleanedResponse } = (0, llm_response_extraction_1.extractThinkingFromResponse)(response);
228
- cleanedResponse = (0, llm_response_extraction_1.extractJsonFromMarkdown)(cleanedResponse);
229
- parsedResponse = JSON.parse(cleanedResponse);
273
+ const { cleanedResponse } = (0, llm_response_extraction_1.extractThinkingFromResponse)(response);
274
+ parsedResponse = (0, llm_response_extraction_1.parseJsonFromLlmResponse)(cleanedResponse);
230
275
  } catch (parseError) {
231
276
  const errorMessage2 = `Failed to parse LLM response as JSON: ${parseError instanceof Error ? parseError.message : "Unknown parsing error"}`;
232
277
  throw new Error(`${errorMessage2}
@@ -5504,6 +5549,7 @@ function requirePattern () {
5504
5549
  hasRequiredPattern = 1;
5505
5550
  Object.defineProperty(pattern, "__esModule", { value: true });
5506
5551
  const code_1 = requireCode();
5552
+ const util_1 = requireUtil();
5507
5553
  const codegen_1 = requireCodegen();
5508
5554
  const error = {
5509
5555
  message: ({ schemaCode }) => (0, codegen_1.str) `must match pattern "${schemaCode}"`,
@@ -5516,11 +5562,19 @@ function requirePattern () {
5516
5562
  $data: true,
5517
5563
  error,
5518
5564
  code(cxt) {
5519
- const { data, $data, schema, schemaCode, it } = cxt;
5520
- // TODO regexp should be wrapped in try/catchs
5565
+ const { gen, data, $data, schema, schemaCode, it } = cxt;
5521
5566
  const u = it.opts.unicodeRegExp ? "u" : "";
5522
- const regExp = $data ? (0, codegen_1._) `(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
5523
- cxt.fail$data((0, codegen_1._) `!${regExp}.test(${data})`);
5567
+ if ($data) {
5568
+ const { regExp } = it.opts.code;
5569
+ const regExpCode = regExp.code === "new RegExp" ? (0, codegen_1._) `new RegExp` : (0, util_1.useFunc)(gen, regExp);
5570
+ const valid = gen.let("valid");
5571
+ gen.try(() => gen.assign(valid, (0, codegen_1._) `${regExpCode}(${schemaCode}, ${u}).test(${data})`), () => gen.assign(valid, false));
5572
+ cxt.fail$data((0, codegen_1._) `!${valid}`);
5573
+ }
5574
+ else {
5575
+ const regExp = (0, code_1.usePattern)(cxt, schema);
5576
+ cxt.fail$data((0, codegen_1._) `!${regExp}.test(${data})`);
5577
+ }
5524
5578
  },
5525
5579
  };
5526
5580
  pattern.default = def;
@@ -9386,9 +9440,9 @@ function requireAjvInstances() {
9386
9440
  };
9387
9441
  Object.defineProperty(ajvInstances, "__esModule", { value: true });
9388
9442
  ajvInstances.ajvInstances = void 0;
9389
- const ajv_1 = __importDefault(requireAjv());
9390
- const _2019_js_1 = __importDefault(require_2019());
9391
- const _2020_js_1 = __importDefault(require_2020());
9443
+ const ajv_1 = __importDefault(/* @__PURE__ */ requireAjv());
9444
+ const _2019_js_1 = __importDefault(/* @__PURE__ */ require_2019());
9445
+ const _2020_js_1 = __importDefault(/* @__PURE__ */ require_2020());
9392
9446
  const json_schema_draft_07_json_1 = __importDefault(require$$3$2);
9393
9447
  const json_schema_draft_06_json_1 = __importDefault(require$$4);
9394
9448
  const ajvOptions = {
@@ -9468,7 +9522,9 @@ function requireModelInfo() {
9468
9522
  exports$1.parseCanonicalModelName = parseCanonicalModelName;
9469
9523
  exports$1.CANONICAL_MODELS = [
9470
9524
  "qwen3-30b-a3b-instruct-2507",
9525
+ "claude-opus-4-7",
9471
9526
  "claude-sonnet-4-6",
9527
+ "claude-haiku-4-5",
9472
9528
  "qwen3-vl-235b-a22b-instruct",
9473
9529
  "qwen3-max",
9474
9530
  "gpt-5",
@@ -9476,7 +9532,8 @@ function requireModelInfo() {
9476
9532
  "gemini-2.5-flash",
9477
9533
  "qwen3-coder-flash",
9478
9534
  "gpt-oss-120b",
9479
- "kimi-k2.5"
9535
+ "kimi-k2.5",
9536
+ "kimi-k2.6"
9480
9537
  ];
9481
9538
  const CANONICAL_SET = new Set(exports$1.CANONICAL_MODELS);
9482
9539
  exports$1.SUPPORTED_MODELS = {
@@ -9500,12 +9557,24 @@ function requireModelInfo() {
9500
9557
  providerModelName: "qwen/qwen3-30b-a3b-instruct-2507"
9501
9558
  }
9502
9559
  ],
9560
+ "claude-opus-4-7": [
9561
+ {
9562
+ provider: "openrouter",
9563
+ providerModelName: "anthropic/claude-opus-4.7"
9564
+ }
9565
+ ],
9503
9566
  "claude-sonnet-4-6": [
9504
9567
  {
9505
9568
  provider: "openrouter",
9506
9569
  providerModelName: "anthropic/claude-sonnet-4.6"
9507
9570
  }
9508
9571
  ],
9572
+ "claude-haiku-4-5": [
9573
+ {
9574
+ provider: "openrouter",
9575
+ providerModelName: "anthropic/claude-haiku-4.5"
9576
+ }
9577
+ ],
9509
9578
  "qwen3-vl-235b-a22b-instruct": [
9510
9579
  {
9511
9580
  provider: "openrouter",
@@ -9555,6 +9624,12 @@ function requireModelInfo() {
9555
9624
  provider: "openrouter",
9556
9625
  providerModelName: "moonshotai/kimi-k2.5"
9557
9626
  }
9627
+ ],
9628
+ "kimi-k2.6": [
9629
+ {
9630
+ provider: "openrouter",
9631
+ providerModelName: "moonshotai/kimi-k2.6"
9632
+ }
9558
9633
  ]
9559
9634
  };
9560
9635
  function parseCanonicalModelName(requestedModel) {
@@ -9575,6 +9650,15 @@ function requireModelInfo() {
9575
9650
  case "sonnet":
9576
9651
  m2 = "claude-sonnet-4-6";
9577
9652
  break;
9653
+ case "opus":
9654
+ m2 = "claude-opus-4-7";
9655
+ break;
9656
+ case "haiku":
9657
+ m2 = "claude-haiku-4-5";
9658
+ break;
9659
+ case "kimi":
9660
+ m2 = "kimi-k2.6";
9661
+ break;
9578
9662
  case "gpt":
9579
9663
  m2 = "gpt-5";
9580
9664
  break;
@@ -153,7 +153,7 @@ function requireLlmResponseExtraction() {
153
153
  hasRequiredLlmResponseExtraction = 1;
154
154
  Object.defineProperty(llmResponseExtraction, "__esModule", { value: true });
155
155
  llmResponseExtraction.extractThinkingFromResponse = extractThinkingFromResponse;
156
- llmResponseExtraction.extractJsonFromMarkdown = extractJsonFromMarkdown;
156
+ llmResponseExtraction.parseJsonFromLlmResponse = parseJsonFromLlmResponse;
157
157
  function extractThinkingFromResponse(input) {
158
158
  const startTag = "<think>";
159
159
  const endTag = "</think>";
@@ -183,25 +183,71 @@ function requireLlmResponseExtraction() {
183
183
  cleanedResponse
184
184
  };
185
185
  }
186
- function extractJsonFromMarkdown(input) {
186
+ function parseJsonFromLlmResponse(input) {
187
187
  const trimmed = input.trim();
188
188
  const codeFence = "```";
189
189
  const jsonFence = "```json";
190
- if (trimmed.startsWith(jsonFence)) {
191
- const startIndex = jsonFence.length;
192
- const endIndex = trimmed.lastIndexOf(codeFence);
193
- if (endIndex > startIndex) {
194
- return trimmed.substring(startIndex, endIndex).trim();
190
+ const lastJsonFence = trimmed.lastIndexOf(jsonFence);
191
+ if (lastJsonFence !== -1) {
192
+ const startIndex = lastJsonFence + jsonFence.length;
193
+ const endIndex = trimmed.indexOf(codeFence, startIndex);
194
+ if (endIndex !== -1) {
195
+ try {
196
+ return JSON.parse(trimmed.substring(startIndex, endIndex).trim());
197
+ } catch {
198
+ }
195
199
  }
196
200
  }
197
- if (trimmed.startsWith(codeFence) && !trimmed.startsWith(jsonFence)) {
198
- const startIndex = codeFence.length;
199
- const endIndex = trimmed.lastIndexOf(codeFence);
200
- if (endIndex > startIndex) {
201
- return trimmed.substring(startIndex, endIndex).trim();
201
+ const firstCodeFence = trimmed.indexOf(codeFence);
202
+ if (firstCodeFence !== -1) {
203
+ const startIndex = firstCodeFence + codeFence.length;
204
+ const endIndex = trimmed.indexOf(codeFence, startIndex);
205
+ if (endIndex !== -1) {
206
+ try {
207
+ return JSON.parse(trimmed.substring(startIndex, endIndex).trim());
208
+ } catch {
209
+ }
202
210
  }
203
211
  }
204
- return input;
212
+ const matchingClose = new Array(trimmed.length).fill(-1);
213
+ const stack = [];
214
+ let inString = false;
215
+ for (let k = 0; k < trimmed.length; k++) {
216
+ if (inString) {
217
+ if (trimmed[k] === "\\")
218
+ k++;
219
+ else if (trimmed[k] === '"')
220
+ inString = false;
221
+ continue;
222
+ }
223
+ if (trimmed[k] === '"') {
224
+ inString = true;
225
+ continue;
226
+ }
227
+ if (trimmed[k] === "{" || trimmed[k] === "[") {
228
+ stack.push(k);
229
+ } else if (trimmed[k] === "}" || trimmed[k] === "]") {
230
+ if (stack.length > 0) {
231
+ const open = stack.pop();
232
+ const expected = trimmed[open] === "{" ? "}" : "]";
233
+ if (trimmed[k] === expected)
234
+ matchingClose[open] = k;
235
+ }
236
+ }
237
+ }
238
+ for (let i = 0; i < trimmed.length; i++) {
239
+ if (trimmed[i] !== "{" && trimmed[i] !== "[")
240
+ continue;
241
+ const j = matchingClose[i];
242
+ if (j === -1)
243
+ continue;
244
+ try {
245
+ return JSON.parse(trimmed.substring(i, j + 1));
246
+ } catch {
247
+ continue;
248
+ }
249
+ }
250
+ return JSON.parse(trimmed);
205
251
  }
206
252
  return llmResponseExtraction;
207
253
  }
@@ -223,9 +269,8 @@ function requireCallLlmService() {
223
269
  const response = providerResponse.text;
224
270
  let parsedResponse;
225
271
  try {
226
- let { thinking, cleanedResponse } = (0, llm_response_extraction_1.extractThinkingFromResponse)(response);
227
- cleanedResponse = (0, llm_response_extraction_1.extractJsonFromMarkdown)(cleanedResponse);
228
- parsedResponse = JSON.parse(cleanedResponse);
272
+ const { cleanedResponse } = (0, llm_response_extraction_1.extractThinkingFromResponse)(response);
273
+ parsedResponse = (0, llm_response_extraction_1.parseJsonFromLlmResponse)(cleanedResponse);
229
274
  } catch (parseError) {
230
275
  const errorMessage2 = `Failed to parse LLM response as JSON: ${parseError instanceof Error ? parseError.message : "Unknown parsing error"}`;
231
276
  throw new Error(`${errorMessage2}
@@ -5503,6 +5548,7 @@ function requirePattern () {
5503
5548
  hasRequiredPattern = 1;
5504
5549
  Object.defineProperty(pattern, "__esModule", { value: true });
5505
5550
  const code_1 = requireCode();
5551
+ const util_1 = requireUtil();
5506
5552
  const codegen_1 = requireCodegen();
5507
5553
  const error = {
5508
5554
  message: ({ schemaCode }) => (0, codegen_1.str) `must match pattern "${schemaCode}"`,
@@ -5515,11 +5561,19 @@ function requirePattern () {
5515
5561
  $data: true,
5516
5562
  error,
5517
5563
  code(cxt) {
5518
- const { data, $data, schema, schemaCode, it } = cxt;
5519
- // TODO regexp should be wrapped in try/catchs
5564
+ const { gen, data, $data, schema, schemaCode, it } = cxt;
5520
5565
  const u = it.opts.unicodeRegExp ? "u" : "";
5521
- const regExp = $data ? (0, codegen_1._) `(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
5522
- cxt.fail$data((0, codegen_1._) `!${regExp}.test(${data})`);
5566
+ if ($data) {
5567
+ const { regExp } = it.opts.code;
5568
+ const regExpCode = regExp.code === "new RegExp" ? (0, codegen_1._) `new RegExp` : (0, util_1.useFunc)(gen, regExp);
5569
+ const valid = gen.let("valid");
5570
+ gen.try(() => gen.assign(valid, (0, codegen_1._) `${regExpCode}(${schemaCode}, ${u}).test(${data})`), () => gen.assign(valid, false));
5571
+ cxt.fail$data((0, codegen_1._) `!${valid}`);
5572
+ }
5573
+ else {
5574
+ const regExp = (0, code_1.usePattern)(cxt, schema);
5575
+ cxt.fail$data((0, codegen_1._) `!${regExp}.test(${data})`);
5576
+ }
5523
5577
  },
5524
5578
  };
5525
5579
  pattern.default = def;
@@ -9385,9 +9439,9 @@ function requireAjvInstances() {
9385
9439
  };
9386
9440
  Object.defineProperty(ajvInstances, "__esModule", { value: true });
9387
9441
  ajvInstances.ajvInstances = void 0;
9388
- const ajv_1 = __importDefault(requireAjv());
9389
- const _2019_js_1 = __importDefault(require_2019());
9390
- const _2020_js_1 = __importDefault(require_2020());
9442
+ const ajv_1 = __importDefault(/* @__PURE__ */ requireAjv());
9443
+ const _2019_js_1 = __importDefault(/* @__PURE__ */ require_2019());
9444
+ const _2020_js_1 = __importDefault(/* @__PURE__ */ require_2020());
9391
9445
  const json_schema_draft_07_json_1 = __importDefault(require$$3$2);
9392
9446
  const json_schema_draft_06_json_1 = __importDefault(require$$4);
9393
9447
  const ajvOptions = {
@@ -9467,7 +9521,9 @@ function requireModelInfo() {
9467
9521
  exports$1.parseCanonicalModelName = parseCanonicalModelName;
9468
9522
  exports$1.CANONICAL_MODELS = [
9469
9523
  "qwen3-30b-a3b-instruct-2507",
9524
+ "claude-opus-4-7",
9470
9525
  "claude-sonnet-4-6",
9526
+ "claude-haiku-4-5",
9471
9527
  "qwen3-vl-235b-a22b-instruct",
9472
9528
  "qwen3-max",
9473
9529
  "gpt-5",
@@ -9475,7 +9531,8 @@ function requireModelInfo() {
9475
9531
  "gemini-2.5-flash",
9476
9532
  "qwen3-coder-flash",
9477
9533
  "gpt-oss-120b",
9478
- "kimi-k2.5"
9534
+ "kimi-k2.5",
9535
+ "kimi-k2.6"
9479
9536
  ];
9480
9537
  const CANONICAL_SET = new Set(exports$1.CANONICAL_MODELS);
9481
9538
  exports$1.SUPPORTED_MODELS = {
@@ -9499,12 +9556,24 @@ function requireModelInfo() {
9499
9556
  providerModelName: "qwen/qwen3-30b-a3b-instruct-2507"
9500
9557
  }
9501
9558
  ],
9559
+ "claude-opus-4-7": [
9560
+ {
9561
+ provider: "openrouter",
9562
+ providerModelName: "anthropic/claude-opus-4.7"
9563
+ }
9564
+ ],
9502
9565
  "claude-sonnet-4-6": [
9503
9566
  {
9504
9567
  provider: "openrouter",
9505
9568
  providerModelName: "anthropic/claude-sonnet-4.6"
9506
9569
  }
9507
9570
  ],
9571
+ "claude-haiku-4-5": [
9572
+ {
9573
+ provider: "openrouter",
9574
+ providerModelName: "anthropic/claude-haiku-4.5"
9575
+ }
9576
+ ],
9508
9577
  "qwen3-vl-235b-a22b-instruct": [
9509
9578
  {
9510
9579
  provider: "openrouter",
@@ -9554,6 +9623,12 @@ function requireModelInfo() {
9554
9623
  provider: "openrouter",
9555
9624
  providerModelName: "moonshotai/kimi-k2.5"
9556
9625
  }
9626
+ ],
9627
+ "kimi-k2.6": [
9628
+ {
9629
+ provider: "openrouter",
9630
+ providerModelName: "moonshotai/kimi-k2.6"
9631
+ }
9557
9632
  ]
9558
9633
  };
9559
9634
  function parseCanonicalModelName(requestedModel) {
@@ -9574,6 +9649,15 @@ function requireModelInfo() {
9574
9649
  case "sonnet":
9575
9650
  m2 = "claude-sonnet-4-6";
9576
9651
  break;
9652
+ case "opus":
9653
+ m2 = "claude-opus-4-7";
9654
+ break;
9655
+ case "haiku":
9656
+ m2 = "claude-haiku-4-5";
9657
+ break;
9658
+ case "kimi":
9659
+ m2 = "kimi-k2.6";
9660
+ break;
9577
9661
  case "gpt":
9578
9662
  m2 = "gpt-5";
9579
9663
  break;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuabase",
3
3
  "description": "Nuabase TypeScript client to create typed functions from LLM prompts",
4
- "version": "2.3.2",
4
+ "version": "2.3.3",
5
5
  "type": "module",
6
6
  "author": "Jasim A Basheer <jasim@nuabase.com>",
7
7
  "engines": {