@supersolutions/super-chat-core 0.4.1 → 0.4.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.
package/dist/index.js CHANGED
@@ -4864,7 +4864,7 @@ async function executeToolCall(call, opts) {
4864
4864
  return {
4865
4865
  callId: call.callId,
4866
4866
  name: call.name,
4867
- output,
4867
+ output: explainMissingInput(tool, call.input, output, result.failure),
4868
4868
  ...card ? { card } : {},
4869
4869
  ...result.failure ? { failure: result.failure } : {},
4870
4870
  ...result.unlockTools?.length ? { unlockTools: result.unlockTools } : {},
@@ -4875,7 +4875,7 @@ async function executeToolCall(call, opts) {
4875
4875
  return {
4876
4876
  callId: call.callId,
4877
4877
  name: call.name,
4878
- output: compactError(err),
4878
+ output: explainMissingInput(tool, call.input, compactError(err), err.kind === "cancelled" ? "denied" : err.kind === "timeout" ? "timeout" : "execution-error"),
4879
4879
  failure: err.kind === "cancelled" ? "denied" : "execution-error",
4880
4880
  ms: Date.now() - started
4881
4881
  };
@@ -4883,6 +4883,35 @@ async function executeToolCall(call, opts) {
4883
4883
  settled = true;
4884
4884
  }
4885
4885
  }
4886
+ var NOT_ABOUT_INPUT = /* @__PURE__ */ new Set(["denied", "timeout", "not-found"]);
4887
+ var MAX_DESCRIBED = 200;
4888
+ function explainMissingInput(tool, input, output, failure) {
4889
+ if (failure && NOT_ABOUT_INPUT.has(failure)) return output;
4890
+ if (typeof output !== "object" || output === null || Array.isArray(output)) return output;
4891
+ const out = output;
4892
+ const failed2 = failure !== void 0 || typeof out.error === "string" && out.ok !== true;
4893
+ if (!failed2 || "missing" in out || "expected" in out) return output;
4894
+ const schema = tool.inputSchema;
4895
+ const required = Array.isArray(schema?.required) ? schema.required.filter((k) => typeof k === "string") : [];
4896
+ if (!required.length) return output;
4897
+ const given = typeof input === "object" && input !== null && !Array.isArray(input) ? input : {};
4898
+ const missing = required.filter((k) => given[k] === void 0 || given[k] === null);
4899
+ if (!missing.length) return output;
4900
+ const props2 = typeof schema?.properties === "object" && schema.properties !== null ? schema.properties : {};
4901
+ const expected = {};
4902
+ for (const key of missing) expected[key] = describeProperty(props2[key]);
4903
+ return { ...out, missing, expected };
4904
+ }
4905
+ function describeProperty(raw) {
4906
+ if (typeof raw !== "object" || raw === null) return {};
4907
+ const p = raw;
4908
+ const d = {};
4909
+ for (const k of ["type", "enum", "minimum", "maximum"]) if (p[k] !== void 0) d[k] = p[k];
4910
+ if (typeof p.description === "string") {
4911
+ d.description = p.description.length > MAX_DESCRIBED ? `${p.description.slice(0, MAX_DESCRIBED)}\u2026` : p.description;
4912
+ }
4913
+ return d;
4914
+ }
4886
4915
  async function executeToolCalls(calls, opts) {
4887
4916
  const toolIndex = opts.toolIndex ?? new Map(opts.tools.map((t) => [t.name, t]));
4888
4917
  const callOpts = opts.toolIndex ? opts : { ...opts, toolIndex };
@@ -5563,10 +5592,11 @@ function createVisualizeTool(opts) {
5563
5592
  const full = { ...spec ?? {}, kind };
5564
5593
  const verdict = cards.validate(full);
5565
5594
  if (!verdict.ok) {
5595
+ const shape = verdict.expected ?? cards.get(kind)?.summary;
5566
5596
  return {
5567
5597
  // Returned as data, not thrown: the model reads the correction and
5568
5598
  // retries with a valid spec on the next step.
5569
- output: { ok: false, error: verdict.error, ...verdict.expected ? { expected: verdict.expected } : {} },
5599
+ output: { ok: false, error: verdict.error, ...shape ? { expected: shape } : {} },
5570
5600
  failure: "invalid-input"
5571
5601
  };
5572
5602
  }