@hivemindhq/core 0.4.0 → 0.5.0

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.
Files changed (85) hide show
  1. package/README.md +16 -16
  2. package/dist/{chunk-2RGM3KJL.js → chunk-K2544PJ5.js} +42 -20
  3. package/dist/chunk-K2544PJ5.js.map +1 -0
  4. package/dist/{chunk-P5E2XNDI.js → chunk-K4XDMY2V.js} +3 -3
  5. package/dist/{chunk-P5E2XNDI.js.map → chunk-K4XDMY2V.js.map} +1 -1
  6. package/dist/{chunk-ERZSVDIB.js → chunk-RW4JXOAM.js} +11 -3
  7. package/dist/chunk-RW4JXOAM.js.map +1 -0
  8. package/dist/chunk-VU3OPG32.js +907 -0
  9. package/dist/chunk-VU3OPG32.js.map +1 -0
  10. package/dist/components/index.d.ts +28 -3
  11. package/dist/components/index.js +2 -2
  12. package/dist/components/ui/index.js +2 -2
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +6 -6
  15. package/dist/utils/index.d.ts +312 -6
  16. package/dist/utils/index.js +2 -2
  17. package/package.json +15 -11
  18. package/src/components/AtomIcon.tsx +21 -0
  19. package/src/components/CryptoAmount.tsx +447 -0
  20. package/src/components/ErrorBanner.tsx +35 -0
  21. package/src/components/IpfsImage.tsx +21 -0
  22. package/src/components/LoadingDots.tsx +55 -0
  23. package/src/components/TripleAreaChart.tsx +108 -0
  24. package/src/components/TriplePositionsTornadoMinGraph.tsx +71 -0
  25. package/src/components/UnknownImage.tsx +55 -0
  26. package/src/components/index.ts +24 -0
  27. package/src/components/ui/alert.tsx +59 -0
  28. package/src/components/ui/avatar.tsx +47 -0
  29. package/src/components/ui/badge.tsx +35 -0
  30. package/src/components/ui/breadcrumb.tsx +108 -0
  31. package/src/components/ui/button.tsx +56 -0
  32. package/src/components/ui/card.tsx +75 -0
  33. package/src/components/ui/carousel.tsx +239 -0
  34. package/src/components/ui/chart.tsx +350 -0
  35. package/src/components/ui/checkbox.tsx +28 -0
  36. package/src/components/ui/collapsible.tsx +10 -0
  37. package/src/components/ui/command.tsx +177 -0
  38. package/src/components/ui/dialog.tsx +119 -0
  39. package/src/components/ui/dropdown-menu.tsx +202 -0
  40. package/src/components/ui/form.tsx +175 -0
  41. package/src/components/ui/index.ts +183 -0
  42. package/src/components/ui/input.tsx +21 -0
  43. package/src/components/ui/label.tsx +25 -0
  44. package/src/components/ui/loader.tsx +20 -0
  45. package/src/components/ui/pagination.tsx +104 -0
  46. package/src/components/ui/popover.tsx +45 -0
  47. package/src/components/ui/progress.tsx +25 -0
  48. package/src/components/ui/radio-group.tsx +42 -0
  49. package/src/components/ui/scroll-area.tsx +45 -0
  50. package/src/components/ui/select.tsx +178 -0
  51. package/src/components/ui/separator.tsx +28 -0
  52. package/src/components/ui/sheet.tsx +139 -0
  53. package/src/components/ui/sidebar.tsx +723 -0
  54. package/src/components/ui/skeleton.tsx +15 -0
  55. package/src/components/ui/sonner.tsx +27 -0
  56. package/src/components/ui/spinner.tsx +67 -0
  57. package/src/components/ui/switch.tsx +26 -0
  58. package/src/components/ui/table.tsx +113 -0
  59. package/src/components/ui/tabs.tsx +63 -0
  60. package/src/components/ui/textarea.tsx +21 -0
  61. package/src/components/ui/toast.tsx +146 -0
  62. package/src/components/ui/toaster.tsx +33 -0
  63. package/src/components/ui/toggle-group.tsx +58 -0
  64. package/src/components/ui/toggle.tsx +44 -0
  65. package/src/components/ui/tooltip.tsx +61 -0
  66. package/src/hooks/index.ts +7 -0
  67. package/src/hooks/use-mobile.ts +20 -0
  68. package/src/hooks/use-toast.ts +190 -0
  69. package/src/index.ts +25 -0
  70. package/src/types/index.ts +17 -0
  71. package/src/utils/atom-label-detection.ts +689 -0
  72. package/src/utils/atom.ts +279 -0
  73. package/src/utils/cn.ts +18 -0
  74. package/src/utils/formatting.ts +624 -0
  75. package/src/utils/index.ts +11 -0
  76. package/src/utils/multivault-errors.ts +581 -0
  77. package/src/utils/search/formatting.tsx +95 -0
  78. package/src/utils/search/index.ts +28 -0
  79. package/src/utils/search/ranking.ts +203 -0
  80. package/src/utils/search/types.ts +114 -0
  81. package/tailwind.config.js +3 -3
  82. package/dist/chunk-2RGM3KJL.js.map +0 -1
  83. package/dist/chunk-ERZSVDIB.js.map +0 -1
  84. package/dist/chunk-H4RMZQ2Z.js +0 -213
  85. package/dist/chunk-H4RMZQ2Z.js.map +0 -1
@@ -0,0 +1,279 @@
1
+ /**
2
+ * Atom-related utility functions for Intuition protocol
3
+ */
4
+
5
+ /**
6
+ * All possible atom types from the Intuition protocol.
7
+ * These correspond to the PostgreSQL enum and Rust AtomType.
8
+ */
9
+ export const ATOM_TYPES = [
10
+ 'Account',
11
+ 'Book',
12
+ 'ByteObject',
13
+ 'Caip10',
14
+ 'FollowAction',
15
+ 'JsonObject',
16
+ 'Keywords',
17
+ 'LikeAction',
18
+ 'Organization',
19
+ 'OrganizationPredicate',
20
+ 'Person',
21
+ 'PersonPredicate',
22
+ 'TextObject',
23
+ 'Thing',
24
+ 'ThingPredicate',
25
+ 'Unknown',
26
+ ] as const
27
+
28
+ export type AtomType = typeof ATOM_TYPES[number]
29
+
30
+ /**
31
+ * Detects atom type from data string patterns.
32
+ * Used as a fallback when type field is not available.
33
+ *
34
+ * @param data - The raw atom data string
35
+ * @returns Detected atom type or undefined
36
+ */
37
+ function detectTypeFromData(data: string): AtomType | undefined {
38
+ if (!data) return undefined
39
+
40
+ const lowered = data.toLowerCase()
41
+ const trimmed = data.trim()
42
+
43
+ // EVM addresses
44
+ if (data.startsWith('0x') && data.length === 42) {
45
+ return 'Account'
46
+ }
47
+
48
+ // CAIP-10 identifiers
49
+ if (lowered.startsWith('caip10:') || lowered.includes('eip155:')) {
50
+ return 'Caip10'
51
+ }
52
+
53
+ // Schema.org predicate URLs
54
+ if (lowered.includes('schema.org/')) {
55
+ if (lowered.includes('person')) return 'PersonPredicate'
56
+ if (lowered.includes('organization')) return 'OrganizationPredicate'
57
+ if (lowered.includes('thing')) return 'ThingPredicate'
58
+ if (lowered.includes('likeaction')) return 'LikeAction'
59
+ if (lowered.includes('followaction')) return 'FollowAction'
60
+ }
61
+
62
+ // IPFS URIs typically contain JSON data
63
+ if (data.startsWith('ipfs://')) {
64
+ return undefined // Can't determine type without fetching
65
+ }
66
+
67
+ // HTTP/HTTPS URLs - could be many types, can't determine without fetching
68
+ if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) {
69
+ return undefined
70
+ }
71
+
72
+ // JSON-like strings (starts with { or [) - likely JsonObject, but can't parse here
73
+ const firstChar = trimmed[0]
74
+ if (firstChar === '{' || firstChar === '[') {
75
+ return undefined // Could be JsonObject, but needs parsing to confirm
76
+ }
77
+
78
+ // Plain text strings that don't match other patterns are likely TextObject
79
+ // This matches the indexer behavior: if data is not JSON, not an address,
80
+ // not a CAIP10, not a schema.org URL, and not IPFS, it becomes a TextObject
81
+ if (trimmed.length > 0) {
82
+ return 'TextObject'
83
+ }
84
+
85
+ return undefined
86
+ }
87
+
88
+ /**
89
+ * Shape of atom data that can be passed to getAtomType.
90
+ * Supports various atom object shapes from GraphQL responses.
91
+ */
92
+ export interface AtomTypeInput {
93
+ /** Direct type field from GraphQL (primary source) */
94
+ type?: string
95
+ /** Alternate naming used in some contexts */
96
+ atomType?: string
97
+ /** Value object with typed sub-objects (secondary source) */
98
+ value?: {
99
+ // Structured entity types (schema.org)
100
+ thing?: unknown
101
+ person?: unknown
102
+ organization?: unknown
103
+ book?: unknown
104
+ // Identity types
105
+ account?: unknown
106
+ // Raw data types
107
+ text_object?: unknown // Plain text like "John Doe", "Hive Mind"
108
+ json_object?: unknown // JSON without schema.org context
109
+ byte_object?: unknown // Binary data
110
+ }
111
+ /** Raw atom data string for pattern detection (tertiary source) */
112
+ data?: string
113
+ }
114
+
115
+ /**
116
+ * Extracts the atom type from an atom object using a cascade/fallback strategy:
117
+ *
118
+ * 1. **Primary**: Direct `type` or `atomType` field from GraphQL
119
+ * 2. **Secondary**: Inferred from populated `value.*` sub-objects
120
+ * 3. **Tertiary**: Pattern detection from `data` string
121
+ *
122
+ * @param atom - Atom object with type information
123
+ * @returns The atom type string, or undefined if not determinable
124
+ *
125
+ * @example
126
+ * // From GraphQL type field
127
+ * getAtomType({ type: 'Person' }) // Returns: 'Person'
128
+ *
129
+ * @example
130
+ * // From value sub-object
131
+ * getAtomType({ value: { person: { name: 'Vitalik' } } }) // Returns: 'Person'
132
+ *
133
+ * @example
134
+ * // From text_object value (plain text atoms)
135
+ * getAtomType({ value: { text_object: { data: 'Hive Mind' } } }) // Returns: 'TextObject'
136
+ *
137
+ * @example
138
+ * // From data pattern
139
+ * getAtomType({ data: '0x1234...5678' }) // Returns: 'Account'
140
+ *
141
+ * @example
142
+ * // Plain text detection
143
+ * getAtomType({ data: 'Hive Mind' }) // Returns: 'TextObject'
144
+ * getAtomType({ data: 'John Doe' }) // Returns: 'TextObject'
145
+ */
146
+ export function getAtomType(atom: AtomTypeInput): AtomType | undefined {
147
+ console.log('getAtomType', atom)
148
+ if (!atom) return undefined
149
+
150
+ // 1. Primary: Direct type field
151
+ if (atom.type && typeof atom.type === 'string') {
152
+ return atom.type as AtomType
153
+ }
154
+ if (atom.atomType && typeof atom.atomType === 'string') {
155
+ return atom.atomType as AtomType
156
+ }
157
+
158
+ // 2. Secondary: Infer from value sub-objects
159
+ // Only check value sub-objects if they are truthy (not null/undefined/false)
160
+ if (atom.value) {
161
+ // Structured entity types (schema.org)
162
+ if (atom.value.person) return 'Person'
163
+ if (atom.value.organization) return 'Organization'
164
+ if (atom.value.book) return 'Book'
165
+ if (atom.value.thing) return 'Thing'
166
+ // Identity types
167
+ if (atom.value.account) return 'Account'
168
+ // Raw data types
169
+ if (atom.value.text_object) return 'TextObject'
170
+ if (atom.value.json_object) return 'JsonObject'
171
+ if (atom.value.byte_object) return 'ByteObject'
172
+ }
173
+
174
+ // 3. Tertiary: Pattern detection from data
175
+ if (atom.data && typeof atom.data === 'string') {
176
+ return detectTypeFromData(atom.data)
177
+ }
178
+
179
+ return undefined
180
+ }
181
+
182
+ /**
183
+ * Formats an atom type for display purposes.
184
+ * Converts internal type names to user-friendly labels.
185
+ *
186
+ * @param type - The atom type string
187
+ * @returns Formatted display string
188
+ *
189
+ * @example
190
+ * formatAtomType('TextObject') // Returns: 'Text'
191
+ * formatAtomType('PersonPredicate') // Returns: 'Person Predicate'
192
+ * formatAtomType('FollowAction') // Returns: 'Follow'
193
+ */
194
+ export function formatAtomType(type: string | undefined): string {
195
+ console.log('formatAtomType', type)
196
+ if (!type) return ''
197
+
198
+ // Handle "Object" suffix types
199
+ if (type.endsWith('Object')) {
200
+ return type.replace('Object', '')
201
+ }
202
+
203
+ // Handle "Predicate" suffix types
204
+ if (type.endsWith('Predicate')) {
205
+ const base = type.replace('Predicate', '')
206
+ return `${base} Predicate`
207
+ }
208
+
209
+ // Handle "Action" suffix types
210
+ if (type.endsWith('Action')) {
211
+ return type.replace('Action', '')
212
+ }
213
+
214
+ return type
215
+ }
216
+
217
+ /**
218
+ * Checks if an atom type is a predicate type.
219
+ * Predicates are used as the middle component of triples.
220
+ *
221
+ * @param type - The atom type to check
222
+ * @returns True if the type is a predicate
223
+ *
224
+ * @example
225
+ * isPredicateType('ThingPredicate') // Returns: true
226
+ * isPredicateType('Person') // Returns: false
227
+ */
228
+ export function isPredicateType(type: string | undefined): boolean {
229
+ if (!type) return false
230
+ return (
231
+ type.endsWith('Predicate') ||
232
+ type === 'LikeAction' ||
233
+ type === 'FollowAction'
234
+ )
235
+ }
236
+
237
+ /**
238
+ * Checks if an atom type represents a structured entity (Person, Organization, Thing).
239
+ * These types typically have rich metadata from schema.org.
240
+ *
241
+ * @param type - The atom type to check
242
+ * @returns True if the type is a structured entity
243
+ */
244
+ export function isEntityType(type: string | undefined): boolean {
245
+ if (!type) return false
246
+ return ['Person', 'Organization', 'Thing', 'Book'].includes(type)
247
+ }
248
+
249
+ /**
250
+ * Checks if an atom type is a raw data type (TextObject, JsonObject, ByteObject).
251
+ * These types contain data without schema.org structure.
252
+ *
253
+ * @param type - The atom type to check
254
+ * @returns True if the type is a raw data type
255
+ *
256
+ * @example
257
+ * isRawDataType('TextObject') // Returns: true
258
+ * isRawDataType('Person') // Returns: false
259
+ */
260
+ export function isRawDataType(type: string | undefined): boolean {
261
+ if (!type) return false
262
+ return ['TextObject', 'JsonObject', 'ByteObject'].includes(type)
263
+ }
264
+
265
+ /**
266
+ * Checks if an atom type is plain text (TextObject).
267
+ * Plain text atoms contain simple strings like names, labels, or concepts.
268
+ *
269
+ * @param type - The atom type to check
270
+ * @returns True if the type is TextObject
271
+ *
272
+ * @example
273
+ * isPlainTextType('TextObject') // Returns: true
274
+ * isPlainTextType('Person') // Returns: false
275
+ */
276
+ export function isPlainTextType(type: string | undefined): boolean {
277
+ return type === 'TextObject'
278
+ }
279
+
@@ -0,0 +1,18 @@
1
+ import { clsx, type ClassValue } from 'clsx'
2
+ import { twMerge } from 'tailwind-merge'
3
+
4
+ /**
5
+ * Combines class names using clsx and merges Tailwind classes intelligently.
6
+ * This is the standard utility for conditional and merged class names.
7
+ *
8
+ * @param inputs - Class values to combine (strings, objects, arrays)
9
+ * @returns Merged class string with Tailwind conflicts resolved
10
+ *
11
+ * @example
12
+ * cn('px-4 py-2', isActive && 'bg-blue-500', { 'opacity-50': isDisabled })
13
+ * // Returns: "px-4 py-2 bg-blue-500" (if isActive is true, isDisabled is false)
14
+ */
15
+ export function cn(...inputs: ClassValue[]) {
16
+ return twMerge(clsx(inputs))
17
+ }
18
+