@stelis/say-ur-intent 0.0.6 → 0.0.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.
@@ -1,9 +1,62 @@
1
1
  import { mainnetPackageIds } from "@mysten/deepbook-v3";
2
- export const CONTRACT_NAME_REGISTRY = [
2
+ import { MOVE_STDLIB_ADDRESS, normalizeSuiAddress, SUI_CLOCK_OBJECT_ID, SUI_COIN_REGISTRY_OBJECT_ID, SUI_DENY_LIST_OBJECT_ID, SUI_FRAMEWORK_ADDRESS, SUI_RANDOM_OBJECT_ID, SUI_SYSTEM_ADDRESS, SUI_SYSTEM_STATE_OBJECT_ID } from "@mysten/sui/utils";
3
+ /** Packages, relabeled only where they appear as a `<address>::...` path. */
4
+ export const PACKAGE_NAME_REGISTRY = [
3
5
  {
4
6
  address: mainnetPackageIds.DEEPBOOK_PACKAGE_ID,
5
7
  name: "@deepbook/core",
6
8
  source: "deepbook_v3_sdk_mainnet_package_id"
9
+ },
10
+ {
11
+ address: MOVE_STDLIB_ADDRESS,
12
+ name: "std",
13
+ source: "sui_sdk_move_stdlib_address"
14
+ },
15
+ {
16
+ address: SUI_FRAMEWORK_ADDRESS,
17
+ name: "sui",
18
+ source: "sui_sdk_framework_address"
19
+ },
20
+ {
21
+ address: SUI_SYSTEM_ADDRESS,
22
+ name: "sui_system",
23
+ source: "sui_sdk_system_address"
24
+ }
25
+ ];
26
+ /** Well-known shared system objects, relabeled only as a bare object id. */
27
+ export const OBJECT_NAME_REGISTRY = [
28
+ {
29
+ address: SUI_SYSTEM_STATE_OBJECT_ID,
30
+ name: "SuiSystemState",
31
+ source: "sui_sdk_system_state_object_id"
32
+ },
33
+ {
34
+ address: SUI_CLOCK_OBJECT_ID,
35
+ name: "Clock",
36
+ source: "sui_sdk_clock_object_id"
37
+ },
38
+ {
39
+ address: SUI_RANDOM_OBJECT_ID,
40
+ name: "Random",
41
+ source: "sui_sdk_random_object_id"
42
+ },
43
+ {
44
+ address: SUI_DENY_LIST_OBJECT_ID,
45
+ name: "DenyList",
46
+ source: "sui_sdk_deny_list_object_id"
47
+ },
48
+ {
49
+ address: SUI_COIN_REGISTRY_OBJECT_ID,
50
+ name: "CoinRegistry",
51
+ source: "sui_sdk_coin_registry_object_id"
52
+ },
53
+ {
54
+ // Address-based balances (coin reservation / fast path) reference the
55
+ // accumulator root object. @mysten/sui defines this id only internally as
56
+ // normalizeSuiAddress("0xacc") (not an exported constant), so mirror it here.
57
+ address: normalizeSuiAddress("0xacc"),
58
+ name: "AccumulatorRoot",
59
+ source: "sui_accumulator_root_object_id_0xacc"
7
60
  }
8
61
  ];
9
62
  /**
@@ -20,37 +73,53 @@ function normalizeContractAddress(value) {
20
73
  }
21
74
  return `0x${body.padStart(64, "0")}`;
22
75
  }
23
- const NAME_BY_ADDRESS = new Map(CONTRACT_NAME_REGISTRY.flatMap((entry) => {
24
- const normalized = normalizeContractAddress(entry.address);
25
- return normalized === undefined ? [] : [[normalized, entry.name]];
26
- }));
76
+ function buildNameMap(entries) {
77
+ return new Map(entries.flatMap((entry) => {
78
+ const normalized = normalizeContractAddress(entry.address);
79
+ return normalized === undefined ? [] : [[normalized, entry.name]];
80
+ }));
81
+ }
82
+ const PACKAGE_NAME_BY_ADDRESS = buildNameMap(PACKAGE_NAME_REGISTRY);
83
+ const OBJECT_NAME_BY_ADDRESS = buildNameMap(OBJECT_NAME_REGISTRY);
27
84
  /**
28
- * Replace every registered package address in PTB Mermaid label text with its
29
- * registered name. Only exact normalized-address matches are replaced; unknown
30
- * addresses are left unchanged. Mermaid node ids are synthetic (`command0`,
31
- * `input0`, ...) and the address only appears inside quoted label text.
85
+ * Replace registered addresses in PTB Mermaid label text with their display
86
+ * names. Mermaid node ids are synthetic (`command0`, `input0`, ...), so an
87
+ * address only appears inside quoted label text, and matching is context-aware:
32
88
  *
33
- * Registered names are Move Registry names like `@deepbook/core`. Mermaid v11
34
- * reads a literal `@` as node/edge metadata syntax even inside a quoted label
35
- * and crashes the renderer, so the inserted name's `@` is written as the Mermaid
36
- * decimal entity `#64;`, which renders as `@` without a literal `@` in the
37
- * source. The copyable Mermaid source keeps raw addresses (it is built from the
38
- * unmodified text), so this only affects the named, rendered graph.
89
+ * - A package is relabeled only where it is a path prefix (`<address>::`), the
90
+ * form a MoveCall target or type path takes never a bare object id.
91
+ * - A well-known object is relabeled only where it is a bare id (not followed by
92
+ * `::`), the form an object input takes never a package path.
93
+ *
94
+ * Unknown addresses are left unchanged. Matching uses the full `0x` + 64-hex
95
+ * address form the PTB renderer (`@zktx.io/ptb-model`) emits; the registry keys
96
+ * are normalized to that same form.
97
+ *
98
+ * Registered package names may be Move Registry names like `@deepbook/core`;
99
+ * Mermaid v11 reads a literal `@` as node/edge metadata syntax even inside a
100
+ * quoted label and crashes the renderer, so an inserted `@` is written as the
101
+ * decimal entity `#64;`, which renders as `@` without a literal `@`. The copyable
102
+ * Mermaid source keeps raw addresses (it is built from the unmodified text), so
103
+ * this only affects the rendered graph.
39
104
  */
40
105
  export function applyContractNamesToMermaid(mermaidText) {
41
106
  let text = mermaidText;
42
- for (const [address, name] of NAME_BY_ADDRESS) {
43
- if (text.includes(address)) {
44
- text = text.split(address).join(mermaidSafeName(name));
45
- }
107
+ // Packages: only in path position (`<address>::...`).
108
+ for (const [address, name] of PACKAGE_NAME_BY_ADDRESS) {
109
+ text = text.split(`${address}::`).join(`${mermaidSafeName(name)}::`);
110
+ }
111
+ // Objects: only as a bare id (anything but a `::` path prefix).
112
+ for (const [address, name] of OBJECT_NAME_BY_ADDRESS) {
113
+ const safe = mermaidSafeName(name);
114
+ text = text.replace(new RegExp(`${address}(?!::)`, "g"), () => safe);
46
115
  }
47
116
  return text;
48
117
  }
49
118
  /**
50
119
  * Escape characters that break Mermaid label parsing. A literal `@` triggers
51
120
  * Mermaid v11 node/edge metadata syntax (even inside quotes) and throws, so it
52
- * is written as the `#64;` decimal entity, which renders as `@`. Other Move
53
- * Registry name characters (letters, `/`, `-`, `_`, `.`, `:`) are valid in
121
+ * is written as the `#64;` decimal entity, which renders as `@`. The other
122
+ * registered label characters (letters, `/`, `-`, `_`, `.`, `:`) are valid in
54
123
  * Mermaid label text.
55
124
  */
56
125
  function mermaidSafeName(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelis/say-ur-intent",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "mcpName": "io.github.stelis-dev/say-ur-intent",
5
5
  "description": "Say Ur Intent is a local-first toolkit for helping AI applications and users inspect Sui DeFi actions before execution.",
6
6
  "license": "MIT",