@optiaxiom/proteus 0.1.6 → 0.1.7

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.
@@ -2,7 +2,7 @@
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { Disclosure, DisclosureTrigger, Box, Group, Text, DisclosureContent, Heading, Tooltip } from '@optiaxiom/react';
4
4
  import { useControllableState } from '@radix-ui/react-use-controllable-state';
5
- import { get, set } from 'jsonpointer';
5
+ import { set } from 'jsonpointer';
6
6
  import { useState, useRef, useEffect } from 'react';
7
7
  import { useEffectEvent } from '../hooks/useEffectEvent.js';
8
8
  import { downloadFile } from '../proteus-image/downloadFile.js';
@@ -49,15 +49,6 @@ function ProteusDocumentShell({
49
49
  await onToolCall?.(event.tool);
50
50
  } else if ("message" in event) {
51
51
  await onMessage?.(event.message);
52
- } else if (event.action === "message-from") {
53
- const items = get(data, event.path);
54
- if (!Array.isArray(items)) {
55
- throw new Error(
56
- `Expected array at "${event.path}" for message-from action`
57
- );
58
- }
59
- const message = items.map((item) => `${item.name}: ${item.value || "[Not specified]"}`).join("\n");
60
- await onMessage?.(message);
61
52
  } else if (event.action === "download") {
62
53
  if (typeof event.url === "string") {
63
54
  await downloadFile(event.url);
@@ -2,6 +2,7 @@
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { ProteusElement } from '../proteus-element/ProteusElement.js';
4
4
  import { getProteusValue } from './getProteusValue.js';
5
+ import { evaluateCondition } from './resolveProteusValue.js';
5
6
 
6
7
  function resolveProteusProp(value, data, parentPath) {
7
8
  if (typeof value !== "object" || value === null) {
@@ -33,6 +34,16 @@ function resolveProteusProp(value, data, parentPath) {
33
34
  return row;
34
35
  });
35
36
  }
37
+ if ("$type" in value && value.$type === "Show" && "when" in value && "children" in value) {
38
+ const conditions = Array.isArray(value.when) ? value.when : [value.when];
39
+ const shouldShow = conditions.every(
40
+ (condition) => evaluateCondition(condition, data, parentPath)
41
+ );
42
+ if (!shouldShow) {
43
+ return void 0;
44
+ }
45
+ return resolveProteusProp(value.children, data, parentPath);
46
+ }
36
47
  return "$type" in value || Array.isArray(value) && value.some((v) => v && typeof v === "object" && "$type" in v) ? /* @__PURE__ */ jsx(ProteusElement, { element: value }) : value;
37
48
  }
38
49
 
@@ -1,32 +1,106 @@
1
1
  "use client";
2
2
  import { getProteusValue } from './getProteusValue.js';
3
3
 
4
- function resolveProteusValue(value, data, parentPath) {
5
- if (typeof value !== "object" || value === null) {
6
- return value;
4
+ function evaluateCondition(condition, data, parentPath) {
5
+ if (!condition) {
6
+ return true;
7
7
  }
8
- if ("$type" in value && value.$type === "Value" && "path" in value && typeof value.path === "string") {
9
- return getProteusValue(
10
- data,
11
- value,
12
- parentPath
8
+ if ("and" in condition) {
9
+ return condition.and.every(
10
+ (cond) => evaluateCondition(cond, data, parentPath)
13
11
  );
14
12
  }
15
- if ("$type" in value && value.$type === "Map" && "path" in value && typeof value.path === "string" && "children" in value) {
16
- const array = getProteusValue(
17
- data,
18
- { path: value.path },
19
- parentPath
13
+ if ("or" in condition) {
14
+ return condition.or.some(
15
+ (cond) => evaluateCondition(cond, data, parentPath)
20
16
  );
21
- if (!Array.isArray(array)) {
22
- return value;
17
+ }
18
+ if ("!!" in condition) {
19
+ const value = resolveProteusValue(condition["!!"], data, parentPath);
20
+ return !!value;
21
+ }
22
+ if ("!" in condition) {
23
+ const value = resolveProteusValue(condition["!"], data, parentPath);
24
+ return !value;
25
+ }
26
+ if ("==" in condition) {
27
+ const [left, right] = condition["=="];
28
+ return resolveProteusValue(left, data, parentPath) === resolveProteusValue(right, data, parentPath);
29
+ } else if ("!=" in condition) {
30
+ const [left, right] = condition["!="];
31
+ return resolveProteusValue(left, data, parentPath) !== resolveProteusValue(right, data, parentPath);
32
+ } else if ("<" in condition) {
33
+ const [left, right] = condition["<"];
34
+ const leftVal = resolveProteusValue(left, data, parentPath);
35
+ const rightVal = resolveProteusValue(right, data, parentPath);
36
+ return typeof leftVal === "number" && typeof rightVal === "number" && leftVal < rightVal;
37
+ } else if ("<=" in condition) {
38
+ const [left, right] = condition["<="];
39
+ const leftVal = resolveProteusValue(left, data, parentPath);
40
+ const rightVal = resolveProteusValue(right, data, parentPath);
41
+ return typeof leftVal === "number" && typeof rightVal === "number" && leftVal <= rightVal;
42
+ } else if (">" in condition) {
43
+ const [left, right] = condition[">"];
44
+ const leftVal = resolveProteusValue(left, data, parentPath);
45
+ const rightVal = resolveProteusValue(right, data, parentPath);
46
+ return typeof leftVal === "number" && typeof rightVal === "number" && leftVal > rightVal;
47
+ } else if (">=" in condition) {
48
+ const [left, right] = condition[">="];
49
+ const leftVal = resolveProteusValue(left, data, parentPath);
50
+ const rightVal = resolveProteusValue(right, data, parentPath);
51
+ return typeof leftVal === "number" && typeof rightVal === "number" && leftVal >= rightVal;
52
+ }
53
+ return false;
54
+ }
55
+ function resolveProteusValue(value, data, parentPath) {
56
+ if (typeof value !== "object" || value === null) {
57
+ return value;
58
+ }
59
+ if ("$type" in value) {
60
+ if (value.$type === "Value" && "path" in value && typeof value.path === "string") {
61
+ return getProteusValue(
62
+ data,
63
+ value,
64
+ parentPath
65
+ );
66
+ }
67
+ if (value.$type === "Map" && "path" in value && typeof value.path === "string" && "children" in value) {
68
+ const array = getProteusValue(
69
+ data,
70
+ { path: value.path },
71
+ parentPath
72
+ );
73
+ if (!Array.isArray(array)) {
74
+ return value;
75
+ }
76
+ const resolvedPath = value.path.startsWith("/") ? value.path : `${parentPath}/${value.path}`;
77
+ const items = array.map(
78
+ (_, index) => resolveProteusValue(value.children, data, `${resolvedPath}/${index}`)
79
+ );
80
+ if ("separator" in value) {
81
+ const sep = resolveProteusValue(value.separator, data, parentPath);
82
+ return items.join(typeof sep === "string" ? sep : "");
83
+ }
84
+ return items;
85
+ }
86
+ if (value.$type === "Show" && "when" in value && "children" in value) {
87
+ const conditions = Array.isArray(value.when) ? value.when : [value.when];
88
+ const shouldShow = conditions.every(
89
+ (condition) => evaluateCondition(condition, data, parentPath)
90
+ );
91
+ if (!shouldShow) {
92
+ return void 0;
93
+ }
94
+ return resolveProteusValue(value.children, data, parentPath);
95
+ }
96
+ if (value.$type === "Concat" && "children" in value) {
97
+ if (!Array.isArray(value.children)) {
98
+ return value;
99
+ }
100
+ return value.children.map((child) => resolveProteusValue(child, data, parentPath)).filter((v) => v !== void 0).join("");
23
101
  }
24
- const resolvedPath = value.path.startsWith("/") ? value.path : `${parentPath}/${value.path}`;
25
- return array.map(
26
- (_, index) => resolveProteusValue(value.children, data, `${resolvedPath}/${index}`)
27
- );
28
102
  }
29
103
  return value;
30
104
  }
31
105
 
32
- export { resolveProteusValue };
106
+ export { evaluateCondition, resolveProteusValue };
@@ -4,10 +4,10 @@ import { resolveProteusValue } from './resolveProteusValue.js';
4
4
 
5
5
  function useResolveProteusValues(props) {
6
6
  const { data } = useProteusDocumentContext(
7
- "@optiaxiom/react/useResolvedProteusProps"
7
+ "@optiaxiom/react/useResolveProteusValues"
8
8
  );
9
9
  const { path: parentPath } = useProteusDocumentPathContext(
10
- "@optiaxiom/react/useResolvedProteusProps"
10
+ "@optiaxiom/react/useResolveProteusValues"
11
11
  );
12
12
  const resolved = {};
13
13
  for (const [key, value] of Object.entries(props)) {
@@ -2,7 +2,7 @@
2
2
  import { jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { useProteusDocumentContext } from '../proteus-document/ProteusDocumentContext.js';
4
4
  import { useProteusDocumentPathContext } from '../proteus-document/ProteusDocumentPathContext.js';
5
- import { resolveProteusValue } from '../proteus-document/resolveProteusValue.js';
5
+ import { evaluateCondition } from '../proteus-document/resolveProteusValue.js';
6
6
 
7
7
  function ProteusShow({ children, when }) {
8
8
  const { data } = useProteusDocumentContext("@optiaxiom/proteus/ProteusShow");
@@ -18,53 +18,6 @@ function ProteusShow({ children, when }) {
18
18
  }
19
19
  return /* @__PURE__ */ jsx(Fragment, { children });
20
20
  }
21
- function evaluateCondition(condition, data, parentPath) {
22
- if (!condition) {
23
- return true;
24
- }
25
- if ("and" in condition) {
26
- return condition.and.every(
27
- (cond) => evaluateCondition(cond, data, parentPath)
28
- );
29
- }
30
- if ("or" in condition) {
31
- return condition.or.some(
32
- (cond) => evaluateCondition(cond, data, parentPath)
33
- );
34
- }
35
- if ("!!" in condition) {
36
- const value = resolveProteusValue(condition["!!"], data, parentPath);
37
- return !!value;
38
- }
39
- if ("==" in condition) {
40
- const [left, right] = condition["=="];
41
- return resolveProteusValue(left, data, parentPath) === resolveProteusValue(right, data, parentPath);
42
- } else if ("!=" in condition) {
43
- const [left, right] = condition["!="];
44
- return resolveProteusValue(left, data, parentPath) !== resolveProteusValue(right, data, parentPath);
45
- } else if ("<" in condition) {
46
- const [left, right] = condition["<"];
47
- const leftVal = resolveProteusValue(left, data, parentPath);
48
- const rightVal = resolveProteusValue(right, data, parentPath);
49
- return typeof leftVal === "number" && typeof rightVal === "number" && leftVal < rightVal;
50
- } else if ("<=" in condition) {
51
- const [left, right] = condition["<="];
52
- const leftVal = resolveProteusValue(left, data, parentPath);
53
- const rightVal = resolveProteusValue(right, data, parentPath);
54
- return typeof leftVal === "number" && typeof rightVal === "number" && leftVal <= rightVal;
55
- } else if (">" in condition) {
56
- const [left, right] = condition[">"];
57
- const leftVal = resolveProteusValue(left, data, parentPath);
58
- const rightVal = resolveProteusValue(right, data, parentPath);
59
- return typeof leftVal === "number" && typeof rightVal === "number" && leftVal > rightVal;
60
- } else if (">=" in condition) {
61
- const [left, right] = condition[">="];
62
- const leftVal = resolveProteusValue(left, data, parentPath);
63
- const rightVal = resolveProteusValue(right, data, parentPath);
64
- return typeof leftVal === "number" && typeof rightVal === "number" && leftVal >= rightVal;
65
- }
66
- return false;
67
- }
68
21
  ProteusShow.displayName = "@optiaxiom/proteus/ProteusShow";
69
22
 
70
23
  export { ProteusShow };
@@ -2400,6 +2400,35 @@ var definitions = {
2400
2400
  ],
2401
2401
  type: "object"
2402
2402
  },
2403
+ {
2404
+ additionalProperties: false,
2405
+ properties: {
2406
+ "!": {
2407
+ anyOf: [
2408
+ {
2409
+ type: "string"
2410
+ },
2411
+ {
2412
+ type: "number"
2413
+ },
2414
+ {
2415
+ type: "boolean"
2416
+ },
2417
+ {
2418
+ type: "null"
2419
+ },
2420
+ {
2421
+ $ref: "#/definitions/ProteusValue"
2422
+ }
2423
+ ],
2424
+ description: "Falsy check - returns true if value is falsy (null, undefined, false, 0, or empty string)"
2425
+ }
2426
+ },
2427
+ required: [
2428
+ "!"
2429
+ ],
2430
+ type: "object"
2431
+ },
2403
2432
  {
2404
2433
  additionalProperties: false,
2405
2434
  properties: {
@@ -2665,6 +2694,9 @@ var definitions = {
2665
2694
  {
2666
2695
  $ref: "#/definitions/ProteusChart"
2667
2696
  },
2697
+ {
2698
+ $ref: "#/definitions/ProteusConcat"
2699
+ },
2668
2700
  {
2669
2701
  $ref: "#/definitions/ProteusDataTable"
2670
2702
  },
@@ -2752,8 +2784,18 @@ var definitions = {
2752
2784
  description: "Client-side message action",
2753
2785
  properties: {
2754
2786
  message: {
2755
- description: "Message to send to LLM via sendNewMessage()",
2756
- type: "string"
2787
+ anyOf: [
2788
+ {
2789
+ $ref: "#/definitions/ProteusMap"
2790
+ },
2791
+ {
2792
+ $ref: "#/definitions/ProteusValue"
2793
+ },
2794
+ {
2795
+ type: "string"
2796
+ }
2797
+ ],
2798
+ description: "Message to send to LLM via sendNewMessage(). Can be a string, a Value reference, or a Map expression."
2757
2799
  }
2758
2800
  },
2759
2801
  required: [
@@ -2790,26 +2832,6 @@ var definitions = {
2790
2832
  "url"
2791
2833
  ],
2792
2834
  type: "object"
2793
- },
2794
- {
2795
- additionalProperties: false,
2796
- description: "Client-side component action - collects name/value pairs from a data array and sends as a message",
2797
- properties: {
2798
- action: {
2799
- "const": "message-from",
2800
- description: "The action type",
2801
- type: "string"
2802
- },
2803
- path: {
2804
- description: "JSON pointer to an array of objects with name and value fields",
2805
- type: "string"
2806
- }
2807
- },
2808
- required: [
2809
- "action",
2810
- "path"
2811
- ],
2812
- type: "object"
2813
2835
  }
2814
2836
  ],
2815
2837
  description: "Handler for user interactions - a server-side tool call, client-side message, or client-side component action"
@@ -4524,6 +4546,32 @@ var definitions = {
4524
4546
  ],
4525
4547
  type: "object"
4526
4548
  },
4549
+ ProteusConcat: {
4550
+ additionalProperties: false,
4551
+ properties: {
4552
+ $type: {
4553
+ "const": "Concat"
4554
+ },
4555
+ children: {
4556
+ description: "Array of values to concatenate into a single string. Each item is resolved and joined together.",
4557
+ items: {
4558
+ anyOf: [
4559
+ {
4560
+ $ref: "#/definitions/ProteusNode"
4561
+ },
4562
+ {
4563
+ type: "string"
4564
+ }
4565
+ ]
4566
+ },
4567
+ type: "array"
4568
+ }
4569
+ },
4570
+ required: [
4571
+ "$type"
4572
+ ],
4573
+ type: "object"
4574
+ },
4527
4575
  ProteusDataTable: {
4528
4576
  additionalProperties: false,
4529
4577
  examples: [
@@ -2392,6 +2392,34 @@ var definitions = {
2392
2392
  ],
2393
2393
  type: "object"
2394
2394
  },
2395
+ {
2396
+ properties: {
2397
+ "!": {
2398
+ anyOf: [
2399
+ {
2400
+ type: "string"
2401
+ },
2402
+ {
2403
+ type: "number"
2404
+ },
2405
+ {
2406
+ type: "boolean"
2407
+ },
2408
+ {
2409
+ type: "null"
2410
+ },
2411
+ {
2412
+ $ref: "#/definitions/ProteusValue"
2413
+ }
2414
+ ],
2415
+ description: "Falsy check - returns true if value is falsy (null, undefined, false, 0, or empty string)"
2416
+ }
2417
+ },
2418
+ required: [
2419
+ "!"
2420
+ ],
2421
+ type: "object"
2422
+ },
2395
2423
  {
2396
2424
  properties: {
2397
2425
  and: {
@@ -2654,6 +2682,9 @@ var definitions = {
2654
2682
  {
2655
2683
  $ref: "#/definitions/ProteusChart"
2656
2684
  },
2685
+ {
2686
+ $ref: "#/definitions/ProteusConcat"
2687
+ },
2657
2688
  {
2658
2689
  $ref: "#/definitions/ProteusDataTable"
2659
2690
  },
@@ -2739,8 +2770,18 @@ var definitions = {
2739
2770
  description: "Client-side message action",
2740
2771
  properties: {
2741
2772
  message: {
2742
- description: "Message to send to LLM via sendNewMessage()",
2743
- type: "string"
2773
+ anyOf: [
2774
+ {
2775
+ $ref: "#/definitions/ProteusMap"
2776
+ },
2777
+ {
2778
+ $ref: "#/definitions/ProteusValue"
2779
+ },
2780
+ {
2781
+ type: "string"
2782
+ }
2783
+ ],
2784
+ description: "Message to send to LLM via sendNewMessage(). Can be a string, a Value reference, or a Map expression."
2744
2785
  }
2745
2786
  },
2746
2787
  required: [
@@ -2776,25 +2817,6 @@ var definitions = {
2776
2817
  "url"
2777
2818
  ],
2778
2819
  type: "object"
2779
- },
2780
- {
2781
- description: "Client-side component action - collects name/value pairs from a data array and sends as a message",
2782
- properties: {
2783
- action: {
2784
- "const": "message-from",
2785
- description: "The action type",
2786
- type: "string"
2787
- },
2788
- path: {
2789
- description: "JSON pointer to an array of objects with name and value fields",
2790
- type: "string"
2791
- }
2792
- },
2793
- required: [
2794
- "action",
2795
- "path"
2796
- ],
2797
- type: "object"
2798
2820
  }
2799
2821
  ],
2800
2822
  description: "Handler for user interactions - a server-side tool call, client-side message, or client-side component action"
@@ -4498,6 +4520,31 @@ var definitions = {
4498
4520
  ],
4499
4521
  type: "object"
4500
4522
  },
4523
+ ProteusConcat: {
4524
+ properties: {
4525
+ $type: {
4526
+ "const": "Concat"
4527
+ },
4528
+ children: {
4529
+ description: "Array of values to concatenate into a single string. Each item is resolved and joined together.",
4530
+ items: {
4531
+ anyOf: [
4532
+ {
4533
+ $ref: "#/definitions/ProteusNode"
4534
+ },
4535
+ {
4536
+ type: "string"
4537
+ }
4538
+ ]
4539
+ },
4540
+ type: "array"
4541
+ }
4542
+ },
4543
+ required: [
4544
+ "$type"
4545
+ ],
4546
+ type: "object"
4547
+ },
4501
4548
  ProteusDataTable: {
4502
4549
  examples: [
4503
4550
  {
package/dist/index.d.ts CHANGED
@@ -109,20 +109,10 @@ declare namespace ProteusSelect {
109
109
  var displayName: string;
110
110
  }
111
111
 
112
- type ProteusShowProps = {
113
- children?: ReactNode;
114
- /**
115
- * Single condition or array of conditions (AND logic). Each condition is an
116
- * object with one operator key.
117
- */
118
- when: ProteusCondition;
119
- };
120
- type ComparisonValue = boolean | null | number | string | {
121
- $type: "Value";
122
- path: string;
123
- };
124
112
  type ProteusCondition = {
125
113
  "!!": ComparisonValue;
114
+ } | {
115
+ "!": ComparisonValue;
126
116
  } | {
127
117
  "!=": ComparisonValue[];
128
118
  } | {
@@ -140,6 +130,19 @@ type ProteusCondition = {
140
130
  } | {
141
131
  or: ProteusCondition[];
142
132
  };
133
+ type ComparisonValue = boolean | null | number | string | {
134
+ $type: "Value";
135
+ path: string;
136
+ };
137
+
138
+ type ProteusShowProps = {
139
+ children?: ReactNode;
140
+ /**
141
+ * Single condition or array of conditions (AND logic). Each condition is an
142
+ * object with one operator key.
143
+ */
144
+ when: ProteusCondition;
145
+ };
143
146
  declare function ProteusShow({ children, when }: ProteusShowProps): react_jsx_runtime.JSX.Element | null;
144
147
  declare namespace ProteusShow {
145
148
  var displayName: string;
@@ -223,9 +226,6 @@ type ProteusEventHandler = {
223
226
  url: (ProteusValueProps & {
224
227
  $type: "Value";
225
228
  }) | string | string[];
226
- } | {
227
- action: "message-from";
228
- path: string;
229
229
  } | {
230
230
  message: string;
231
231
  } | {