modality-ai 0.7.4 → 0.7.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/dist/index.js CHANGED
@@ -126465,16 +126465,31 @@ class ModalityClientImpl {
126465
126465
  }
126466
126466
  }
126467
126467
  parseContent(toolResult) {
126468
- try {
126469
- const content = toolResult?.content?.[0];
126470
- if (content?.type === "text" && content.text) {
126471
- return JSON.parse(content.text);
126468
+ const blocks = Array.isArray(toolResult?.content) ? toolResult.content : [];
126469
+ const parsed = blocks.filter((b) => b?.type === "text" && b.text).map((b) => {
126470
+ try {
126471
+ return JSON.parse(b.text);
126472
+ } catch {
126473
+ return b.text;
126472
126474
  }
126473
- return content ?? toolResult;
126474
- } catch {
126475
- const content = toolResult?.content?.[0];
126476
- return content?.text ?? content ?? toolResult;
126475
+ });
126476
+ if (parsed.length === 0) {
126477
+ return toolResult?.content?.[0] ?? toolResult;
126478
+ }
126479
+ const objects = parsed.filter((p) => typeof p === "object" && p !== null && !Array.isArray(p));
126480
+ const extras = parsed.filter((p) => typeof p !== "object" || p === null || Array.isArray(p));
126481
+ if (objects.length === 0) {
126482
+ return parsed.length === 1 ? parsed[0] : parsed;
126483
+ }
126484
+ const merged = Object.assign({}, ...objects);
126485
+ if (extras.length > 0) {
126486
+ const key = objects.some((o) => ("_extra" in o)) ? "__extra" : "_extra";
126487
+ merged[key] = extras.length === 1 ? extras[0] : extras;
126488
+ }
126489
+ if (merged.success === undefined) {
126490
+ merged.success = toolResult?.isError !== true;
126477
126491
  }
126492
+ return merged;
126478
126493
  }
126479
126494
  }
126480
126495
  function http(url3, timeout, options) {
@@ -47,6 +47,19 @@ declare class ModalityClientImpl {
47
47
  callStream(method: string, params?: any, callback?: (p: any) => void): ReadableStream;
48
48
  close(): Promise<void>;
49
49
  listTools(): Promise<ListToolsResult>;
50
+ /**
51
+ * Parse a CallToolResult into a plain value.
52
+ *
53
+ * modality-kit's `formatSuccessResponse(data, meta)` splits results across
54
+ * text blocks — block 0 is the envelope (`{message}`), blocks 1+ carry the
55
+ * payload — so ALL text blocks are parsed and object blocks shallow-merged
56
+ * (later blocks win on key collisions). Non-object blocks (e.g. the
57
+ * `DEBUG=1` "Response size" note) are collected under `_extra` (or
58
+ * `__extra` when the tool's payload already carries `_extra`).
59
+ *
60
+ * The merged object always carries `success`: derived from the MCP-level
61
+ * `isError` flag unless the tool set it explicitly.
62
+ */
50
63
  parseContent(toolResult: any): unknown;
51
64
  }
52
65
  export type ModalityClientInstance = ModalityClientImpl;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.4",
2
+ "version": "0.7.5",
3
3
  "name": "modality-ai",
4
4
  "repository": {
5
5
  "type": "git",