@niscorp/cortex 0.1.4 → 0.1.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @niscorp/cortex
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - e7c45c3: A tool call whose arguments fail their schema is told which field is wrong, as an output is. The loop printed zod's top-level issues as they were, so a union in a tool's input came back as `: Invalid input`; it now goes through `flattenSchemaIssues`, as output does (`view.title: Invalid input: expected string, received undefined`).
8
+
9
+ `flattenSchemaIssues` reports a record key that breaks its rule with the rule's own message (`scores.Bad: keys are lower-case letters`) instead of zod's outer `Invalid key in record`. `SchemaIssue` gains two optional fields, `issues` and `origin`, which zod's issues already carry.
10
+
11
+ How a branch of a failed union is chosen is unchanged.
12
+
13
+ **What to change:** nothing.
14
+
3
15
  ## 0.1.4
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -177,6 +177,9 @@ var pickBranch = (branches) => branches.reduce((best, branch) => {
177
177
  });
178
178
  var flattenSchemaIssues = (issues, prefix = []) => issues.flatMap((issue) => {
179
179
  const path = [...prefix, ...issue.path];
180
+ if (issue.code === "invalid_key" && issue.origin === "record" && issue.issues && issue.issues.length > 0) {
181
+ return flattenSchemaIssues(issue.issues, path);
182
+ }
180
183
  if (issue.code !== "invalid_union" || !issue.errors || issue.errors.length === 0) return [{ ...issue, path }];
181
184
  return flattenSchemaIssues(pickBranch(issue.errors), path);
182
185
  });
@@ -504,7 +507,7 @@ var runLoop = async (cfg) => {
504
507
  if (repaired.success) parsedArgs = repaired;
505
508
  }
506
509
  if (!parsedArgs.success) {
507
- const issues = parsedArgs.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
510
+ const issues = flattenSchemaIssues(parsedArgs.error.issues).map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
508
511
  const hint = typeof args === "string" ? ' (your arguments arrived as ONE STRING \u2014 call again with a plain JSON object, e.g. {"key": "value"})' : isEmptyObject(args) ? ` (your arguments arrived EMPTY \u2014 nothing was sent. Call ${toolId} again with its arguments filled in, as its parameters describe)` : "";
509
512
  record(
510
513
  call,