@asteby/metacore-runtime-react 51.0.0 → 52.1.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 (62) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/activity-diff.d.ts +5 -0
  3. package/dist/activity-diff.d.ts.map +1 -1
  4. package/dist/activity-timeline.d.ts.map +1 -1
  5. package/dist/activity-timeline.js +7 -2
  6. package/dist/audit-info.d.ts.map +1 -1
  7. package/dist/audit-info.js +14 -1
  8. package/dist/barcode-scanner.js +4 -4
  9. package/dist/dialogs/dynamic-record.d.ts +3 -1
  10. package/dist/dialogs/dynamic-record.d.ts.map +1 -1
  11. package/dist/dialogs/dynamic-record.js +11 -1
  12. package/dist/dynamic-columns.d.ts.map +1 -1
  13. package/dist/dynamic-columns.js +11 -0
  14. package/dist/dynamic-date-field.js +1 -1
  15. package/dist/dynamic-form.js +2 -2
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -1
  19. package/dist/org-runtime-context.d.ts +27 -0
  20. package/dist/org-runtime-context.d.ts.map +1 -1
  21. package/dist/org-runtime-context.js +6 -0
  22. package/dist/org-runtime-provider.d.ts +13 -2
  23. package/dist/org-runtime-provider.d.ts.map +1 -1
  24. package/dist/org-runtime-provider.js +3 -3
  25. package/dist/provenance.d.ts +216 -0
  26. package/dist/provenance.d.ts.map +1 -0
  27. package/dist/provenance.js +386 -0
  28. package/dist/record-history.d.ts.map +1 -1
  29. package/dist/record-history.js +3 -1
  30. package/dist/sidebar-layout-manager.js +2 -2
  31. package/dist/widgets/charts.d.ts +9 -0
  32. package/dist/widgets/charts.d.ts.map +1 -0
  33. package/dist/widgets/charts.js +55 -0
  34. package/dist/widgets/lazy-charts.d.ts +10 -0
  35. package/dist/widgets/lazy-charts.d.ts.map +1 -0
  36. package/dist/widgets/lazy-charts.js +30 -0
  37. package/dist/widgets/renderers.d.ts +5 -5
  38. package/dist/widgets/renderers.d.ts.map +1 -1
  39. package/dist/widgets/renderers.js +3 -53
  40. package/dist/widgets/widget-renderer.d.ts.map +1 -1
  41. package/dist/widgets/widget-renderer.js +2 -1
  42. package/package.json +8 -4
  43. package/src/__tests__/index-static-graph.test.ts +65 -0
  44. package/src/__tests__/provenance.test.tsx +209 -0
  45. package/src/activity-diff.tsx +5 -0
  46. package/src/activity-timeline.tsx +13 -1
  47. package/src/audit-info.tsx +17 -1
  48. package/src/barcode-scanner.tsx +4 -4
  49. package/src/dialogs/dynamic-record.tsx +18 -0
  50. package/src/dynamic-columns.tsx +14 -0
  51. package/src/dynamic-date-field.tsx +1 -1
  52. package/src/dynamic-form.tsx +2 -2
  53. package/src/index.ts +10 -4
  54. package/src/org-runtime-context.ts +36 -0
  55. package/src/org-runtime-provider.tsx +22 -1
  56. package/src/provenance.tsx +585 -0
  57. package/src/record-history.tsx +14 -3
  58. package/src/sidebar-layout-manager.tsx +2 -2
  59. package/src/widgets/charts.tsx +225 -0
  60. package/src/widgets/lazy-charts.tsx +51 -0
  61. package/src/widgets/renderers.tsx +5 -210
  62. package/src/widgets/widget-renderer.tsx +6 -4
@@ -0,0 +1,216 @@
1
+ /**
2
+ * provenance.tsx — who made a record, and how.
3
+ *
4
+ * The kernel's `provenance` package stores, per record and per change, the
5
+ * actor kind (human | agent | system | integration), the person the agent
6
+ * acted for, who authorized an agent proposal and when, the channel (`via`),
7
+ * the origin and the mode (manual | assisted | automated). Hosts attach the
8
+ * creation provenance to list rows at `created_by.provenance` (or
9
+ * `row.provenance`); this module turns it into one of four presentations:
10
+ *
11
+ * human — a person on their own: their avatar and name.
12
+ * agent — the app's agent (OrgRuntimeProvider `agentActor`, e.g. Gobi)
13
+ * with the origin; "pending proposal" when it waits for a person.
14
+ * system — platform work or an integration: system icon + origin.
15
+ * assisted — "Ana with Gobi": the person's avatar with the agent's
16
+ * superimposed, and an accessible tooltip with who authorized,
17
+ * what the agent proposed and when.
18
+ *
19
+ * Rows without stored provenance keep the legacy rules: a null/system
20
+ * `created_by_id` is the system (origin from OrgRuntimeProvider
21
+ * `provenanceOrigin`), anything else is the person in `created_by`.
22
+ */
23
+ import * as React from 'react';
24
+ export type ProvenanceActorKind = 'human' | 'agent' | 'system' | 'integration';
25
+ export type ProvenanceMode = 'manual' | 'assisted' | 'automated';
26
+ /** Wire shape of a stored change's provenance (kernel `Entry.Presentation`). */
27
+ export interface ProvenanceData {
28
+ actor_kind: ProvenanceActorKind;
29
+ mode?: ProvenanceMode;
30
+ actor_id?: string;
31
+ actor_name?: string;
32
+ actor_person_name?: string;
33
+ actor_person_avatar?: string;
34
+ on_behalf_of?: string;
35
+ on_behalf_of_name?: string;
36
+ on_behalf_of_avatar?: string;
37
+ authorized_by?: string;
38
+ authorized_by_name?: string;
39
+ authorized_by_avatar?: string;
40
+ authorized_at?: string;
41
+ via?: string;
42
+ origin?: string;
43
+ ref_kind?: string;
44
+ ref_id?: string;
45
+ session_id?: string;
46
+ summary?: string;
47
+ proposed?: boolean;
48
+ /** When the change happened. */
49
+ at?: string;
50
+ }
51
+ /** The four presentations. */
52
+ export type AuthorshipKind = 'human' | 'agent' | 'system' | 'assisted';
53
+ /** Defensive reader: an object or JSON string with a known `actor_kind`. */
54
+ export declare function parseProvenance(raw: unknown): ProvenanceData | undefined;
55
+ /** Reads a row's creation provenance (`created_by.provenance` or `provenance`). */
56
+ export declare function readProvenance(row: Record<string, unknown> | null | undefined): ProvenanceData | undefined;
57
+ /** Which of the four presentations a provenance gets. */
58
+ export declare function classifyProvenance(p: ProvenanceData): AuthorshipKind;
59
+ /** True when the row's creator is the system (null / nil / kernel actor). */
60
+ export declare function isSystemCreated(row: Record<string, unknown> | null | undefined): boolean;
61
+ declare const COPY: {
62
+ readonly es: {
63
+ readonly system: "Sistema";
64
+ readonly agent: "Asistente";
65
+ readonly user: "Usuario";
66
+ readonly with: "{{person}} con {{agent}}";
67
+ readonly proposedBy: "Propuesto por {{agent}}";
68
+ readonly pending: "Propuesta pendiente";
69
+ readonly authorizedBy: "Autorizó: {{person}}";
70
+ readonly onBehalfOf: "En nombre de {{person}}";
71
+ readonly proposal: "{{agent}} propuso: {{summary}}";
72
+ readonly createdBy: "Creado por {{who}}";
73
+ readonly 'via.chat': "Chat";
74
+ readonly 'via.automation': "Automatización";
75
+ readonly 'via.import': "Importación";
76
+ readonly 'via.webhook': "Webhook";
77
+ readonly 'via.seed': "Datos iniciales";
78
+ readonly 'via.migration': "Migración";
79
+ readonly 'via.job': "Proceso programado";
80
+ readonly 'via.event': "Evento";
81
+ readonly 'via.ui': "Manual";
82
+ readonly 'via.api': "API";
83
+ readonly 'mode.manual': "Manual";
84
+ readonly 'mode.assisted': "Con asistencia";
85
+ readonly 'mode.automated': "Automático";
86
+ };
87
+ readonly en: {
88
+ readonly system: "System";
89
+ readonly agent: "Assistant";
90
+ readonly user: "User";
91
+ readonly with: "{{person}} with {{agent}}";
92
+ readonly proposedBy: "Proposed by {{agent}}";
93
+ readonly pending: "Pending proposal";
94
+ readonly authorizedBy: "Authorized by: {{person}}";
95
+ readonly onBehalfOf: "On behalf of {{person}}";
96
+ readonly proposal: "{{agent}} proposed: {{summary}}";
97
+ readonly createdBy: "Created by {{who}}";
98
+ readonly 'via.chat': "Chat";
99
+ readonly 'via.automation': "Automation";
100
+ readonly 'via.import': "Import";
101
+ readonly 'via.webhook': "Webhook";
102
+ readonly 'via.seed': "Initial data";
103
+ readonly 'via.migration': "Migration";
104
+ readonly 'via.job': "Scheduled job";
105
+ readonly 'via.event': "Event";
106
+ readonly 'via.ui': "Manual";
107
+ readonly 'via.api': "API";
108
+ readonly 'mode.manual': "Manual";
109
+ readonly 'mode.assisted': "Assisted";
110
+ readonly 'mode.automated': "Automated";
111
+ };
112
+ };
113
+ export type ProvenanceCopyKey = keyof (typeof COPY)['es'];
114
+ /** Copy lookup: `provenance.<key>` from the host i18n, else the built-in es/en. */
115
+ export declare function useProvenanceCopy(): {
116
+ tt: (key: ProvenanceCopyKey, vars?: Record<string, string>) => string;
117
+ lang: string;
118
+ };
119
+ /** Person shown for a provenance (assisted / human), from the row or the data. */
120
+ export interface ProvenancePerson {
121
+ name?: string;
122
+ avatar?: string;
123
+ }
124
+ export interface ResolvedAuthorship {
125
+ kind: AuthorshipKind;
126
+ /** Main line ("Ana Pérez con Gobi", "Gobi", "Sistema", "gobiernos-intel"). */
127
+ label: string;
128
+ /** Secondary line (origin / channel / pending proposal). */
129
+ subtitle?: string;
130
+ /** Full sentence for tooltip and screen readers. */
131
+ description: string;
132
+ person?: ProvenancePerson;
133
+ agentName: string;
134
+ agentAvatar?: string;
135
+ systemAvatar?: string;
136
+ integration: boolean;
137
+ proposed: boolean;
138
+ }
139
+ /** Pure-ish resolver (hooks for copy and presentation contexts). */
140
+ export declare function useResolvedAuthorship(input: {
141
+ provenance?: ProvenanceData;
142
+ person?: ProvenancePerson;
143
+ /** Origin for system rows without provenance (legacy). */
144
+ fallbackOrigin?: string;
145
+ /** Force the system presentation (legacy null created_by). */
146
+ system?: boolean;
147
+ }): ResolvedAuthorship | null;
148
+ type Size = 'sm' | 'md';
149
+ /** Avatar for a resolved authorship (person with the agent superimposed when assisted). */
150
+ export declare function ProvenanceAvatar({ authorship: a, size }: {
151
+ authorship: ResolvedAuthorship;
152
+ size?: Size;
153
+ }): React.JSX.Element;
154
+ export interface ProvenanceBadgeProps {
155
+ /** Stored provenance (kernel wire shape). */
156
+ provenance?: ProvenanceData;
157
+ /** Person from the row (`created_by` sibling) when the data has no names. */
158
+ person?: ProvenancePerson;
159
+ /** Legacy system row without provenance. */
160
+ system?: boolean;
161
+ /** Origin for `system` rows without provenance. */
162
+ fallbackOrigin?: string;
163
+ /** `cell`: two lines with a 32px avatar (tables). `inline`: one line (detail, history, notifications). */
164
+ variant?: 'cell' | 'inline';
165
+ className?: string;
166
+ }
167
+ /**
168
+ * Who made a record and how — the four presentations (see module doc) with a
169
+ * keyboard-focusable trigger whose tooltip and screen-reader description say
170
+ * who authorized, what the agent proposed and when.
171
+ */
172
+ export declare function ProvenanceBadge({ provenance, person, system, fallbackOrigin, variant, className }: ProvenanceBadgeProps): React.JSX.Element | null;
173
+ /** True when the row has something AuthorshipCell renders differently from a plain person. */
174
+ export declare function hasSpecialAuthorship(row: Record<string, unknown> | null | undefined): boolean;
175
+ export interface AuthorshipCellProps {
176
+ /** The record row (reads `created_by`, `created_by_id`, provenance). */
177
+ row: Record<string, unknown> | null | undefined;
178
+ /** Model key, passed to the host origin resolver for legacy system rows. */
179
+ model?: string;
180
+ variant?: 'cell' | 'inline';
181
+ className?: string;
182
+ }
183
+ /**
184
+ * "Created by" for any record: the stored provenance when the host attached
185
+ * it, else the legacy rule (system when `created_by_id` is empty or the kernel
186
+ * actor, the `created_by` person otherwise). Renders nothing for a row with no
187
+ * creator information at all.
188
+ */
189
+ export declare function AuthorshipCell({ row, model, variant, className }: AuthorshipCellProps): React.JSX.Element | null;
190
+ /**
191
+ * Avatar + name for an activity/history event that carries provenance (no
192
+ * tooltip trigger: it lives inside the event's toggle button). The full
193
+ * sentence goes to `title` and to screen readers.
194
+ */
195
+ export declare function ProvenanceActorChip({ provenance, person, className, }: {
196
+ provenance: ProvenanceData;
197
+ person?: ProvenancePerson;
198
+ className?: string;
199
+ }): React.JSX.Element | null;
200
+ /** Provenance carried by a notification (metadata.provenance), if any. */
201
+ export declare function notificationProvenance(item: {
202
+ metadata?: unknown;
203
+ } | null | undefined): ProvenanceData | undefined;
204
+ /**
205
+ * Avatar for a notification list (`renderAvatar` of the notifications
206
+ * dropdown): the provenance avatar when the notification carries one, else
207
+ * `fallback`.
208
+ */
209
+ export declare function NotificationProvenanceAvatar({ item, fallback, }: {
210
+ item: {
211
+ metadata?: unknown;
212
+ } | null | undefined;
213
+ fallback?: React.ReactNode;
214
+ }): React.JSX.Element;
215
+ export {};
216
+ //# sourceMappingURL=provenance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../src/provenance.tsx"],"names":[],"mappings":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AK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,OAAgB,EAAE,SAAS,EAAE,EAAE,mBAAmB,4BA0B9F;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,EAChC,UAAU,EACV,MAAM,EACN,SAAS,GACZ,EAAE;IACC,UAAU,EAAE,cAAc,CAAA;IAC1B,MAAM,CAAC,EAAE,gBAAgB,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB,4BAUA;AAED,0EAA0E;AAC1E,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAWlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,EACzC,IAAI,EACJ,QAAe,GAClB,EAAE;IACC,IAAI,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,GAAG,SAAS,CAAA;IAC/C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC7B,qBASA"}
@@ -0,0 +1,386 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * provenance.tsx — who made a record, and how.
4
+ *
5
+ * The kernel's `provenance` package stores, per record and per change, the
6
+ * actor kind (human | agent | system | integration), the person the agent
7
+ * acted for, who authorized an agent proposal and when, the channel (`via`),
8
+ * the origin and the mode (manual | assisted | automated). Hosts attach the
9
+ * creation provenance to list rows at `created_by.provenance` (or
10
+ * `row.provenance`); this module turns it into one of four presentations:
11
+ *
12
+ * human — a person on their own: their avatar and name.
13
+ * agent — the app's agent (OrgRuntimeProvider `agentActor`, e.g. Gobi)
14
+ * with the origin; "pending proposal" when it waits for a person.
15
+ * system — platform work or an integration: system icon + origin.
16
+ * assisted — "Ana with Gobi": the person's avatar with the agent's
17
+ * superimposed, and an accessible tooltip with who authorized,
18
+ * what the agent proposed and when.
19
+ *
20
+ * Rows without stored provenance keep the legacy rules: a null/system
21
+ * `created_by_id` is the system (origin from OrgRuntimeProvider
22
+ * `provenanceOrigin`), anything else is the person in `created_by`.
23
+ */
24
+ import * as React from 'react';
25
+ import { useTranslation } from 'react-i18next';
26
+ import { Bot, Plug, Server } from 'lucide-react';
27
+ import { Avatar, AvatarFallback, AvatarImage, Tooltip, TooltipContent, TooltipTrigger } from '@asteby/metacore-ui';
28
+ import { cn, getInitials } from '@asteby/metacore-ui/lib';
29
+ import { useImageUrl } from './image-url-context';
30
+ import { isNilUuid } from './nil-uuid';
31
+ import { useAgentActor, useProvenanceOrigin, useSystemActor, useTimeZone } from './org-runtime-context';
32
+ /** The kernel's fixed actor for unattended work. */
33
+ const KERNEL_SYSTEM_ACTOR_ID = '00000000-0000-0000-0000-000000000001';
34
+ const KINDS = new Set(['human', 'agent', 'system', 'integration']);
35
+ function str(v) {
36
+ return typeof v === 'string' && v.trim() !== '' ? v : undefined;
37
+ }
38
+ /** Defensive reader: an object or JSON string with a known `actor_kind`. */
39
+ export function parseProvenance(raw) {
40
+ let v = raw;
41
+ if (typeof v === 'string') {
42
+ try {
43
+ v = JSON.parse(v);
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ }
49
+ if (!v || typeof v !== 'object' || Array.isArray(v))
50
+ return undefined;
51
+ const o = v;
52
+ if (typeof o.actor_kind !== 'string' || !KINDS.has(o.actor_kind))
53
+ return undefined;
54
+ return o;
55
+ }
56
+ /** Reads a row's creation provenance (`created_by.provenance` or `provenance`). */
57
+ export function readProvenance(row) {
58
+ if (!row)
59
+ return undefined;
60
+ const cb = row.created_by;
61
+ if (cb && typeof cb === 'object') {
62
+ const p = parseProvenance(cb.provenance);
63
+ if (p)
64
+ return p;
65
+ }
66
+ return parseProvenance(row.provenance);
67
+ }
68
+ /** Which of the four presentations a provenance gets. */
69
+ export function classifyProvenance(p) {
70
+ if (p.actor_kind === 'human')
71
+ return 'human';
72
+ if (p.mode === 'assisted' || (p.authorized_by && !p.proposed))
73
+ return 'assisted';
74
+ if (p.actor_kind === 'agent')
75
+ return 'agent';
76
+ return 'system';
77
+ }
78
+ /** True when the row's creator is the system (null / nil / kernel actor). */
79
+ export function isSystemCreated(row) {
80
+ if (!row)
81
+ return false;
82
+ const cb = row.created_by;
83
+ if (cb && typeof cb === 'object') {
84
+ const o = cb;
85
+ if (o.system === true)
86
+ return true;
87
+ if (str(o.name) || str(o.email))
88
+ return false;
89
+ }
90
+ if ('created_by_id' in row) {
91
+ const id = row.created_by_id;
92
+ if (id === null || id === undefined || id === '')
93
+ return true;
94
+ const s = String(id).trim().toLowerCase();
95
+ return s === '<nil>' || isNilUuid(s) || s === KERNEL_SYSTEM_ACTOR_ID;
96
+ }
97
+ return false;
98
+ }
99
+ // ---- copy -------------------------------------------------------------------
100
+ const COPY = {
101
+ es: {
102
+ system: 'Sistema',
103
+ agent: 'Asistente',
104
+ user: 'Usuario',
105
+ with: '{{person}} con {{agent}}',
106
+ proposedBy: 'Propuesto por {{agent}}',
107
+ pending: 'Propuesta pendiente',
108
+ authorizedBy: 'Autorizó: {{person}}',
109
+ onBehalfOf: 'En nombre de {{person}}',
110
+ proposal: '{{agent}} propuso: {{summary}}',
111
+ createdBy: 'Creado por {{who}}',
112
+ 'via.chat': 'Chat',
113
+ 'via.automation': 'Automatización',
114
+ 'via.import': 'Importación',
115
+ 'via.webhook': 'Webhook',
116
+ 'via.seed': 'Datos iniciales',
117
+ 'via.migration': 'Migración',
118
+ 'via.job': 'Proceso programado',
119
+ 'via.event': 'Evento',
120
+ 'via.ui': 'Manual',
121
+ 'via.api': 'API',
122
+ 'mode.manual': 'Manual',
123
+ 'mode.assisted': 'Con asistencia',
124
+ 'mode.automated': 'Automático',
125
+ },
126
+ en: {
127
+ system: 'System',
128
+ agent: 'Assistant',
129
+ user: 'User',
130
+ with: '{{person}} with {{agent}}',
131
+ proposedBy: 'Proposed by {{agent}}',
132
+ pending: 'Pending proposal',
133
+ authorizedBy: 'Authorized by: {{person}}',
134
+ onBehalfOf: 'On behalf of {{person}}',
135
+ proposal: '{{agent}} proposed: {{summary}}',
136
+ createdBy: 'Created by {{who}}',
137
+ 'via.chat': 'Chat',
138
+ 'via.automation': 'Automation',
139
+ 'via.import': 'Import',
140
+ 'via.webhook': 'Webhook',
141
+ 'via.seed': 'Initial data',
142
+ 'via.migration': 'Migration',
143
+ 'via.job': 'Scheduled job',
144
+ 'via.event': 'Event',
145
+ 'via.ui': 'Manual',
146
+ 'via.api': 'API',
147
+ 'mode.manual': 'Manual',
148
+ 'mode.assisted': 'Assisted',
149
+ 'mode.automated': 'Automated',
150
+ },
151
+ };
152
+ /** Copy lookup: `provenance.<key>` from the host i18n, else the built-in es/en. */
153
+ export function useProvenanceCopy() {
154
+ const { t, i18n } = useTranslation();
155
+ const lang = (i18n?.language || 'es').toLowerCase().startsWith('en') ? 'en' : 'es';
156
+ const copy = COPY[lang];
157
+ const tt = React.useCallback((key, vars) => {
158
+ const fallback = copy[key].replace(/\{\{(\w+)\}\}/g, (_, k) => vars?.[k] ?? '');
159
+ const out = t(`provenance.${key}`, { defaultValue: fallback, ...vars });
160
+ // i18n mocks/backends that ignore defaultValue echo the key back.
161
+ return !out || out === `provenance.${key}` ? fallback : out;
162
+ }, [t, copy]);
163
+ return { tt, lang };
164
+ }
165
+ function formatWhen(iso, lang, timeZone) {
166
+ if (!iso)
167
+ return undefined;
168
+ const d = new Date(iso);
169
+ if (Number.isNaN(d.getTime()))
170
+ return undefined;
171
+ try {
172
+ return d.toLocaleString(lang === 'en' ? 'en-US' : 'es-MX', {
173
+ dateStyle: 'medium',
174
+ timeStyle: 'short',
175
+ ...(timeZone ? { timeZone } : {}),
176
+ });
177
+ }
178
+ catch {
179
+ return d.toISOString();
180
+ }
181
+ }
182
+ /** Pure-ish resolver (hooks for copy and presentation contexts). */
183
+ export function useResolvedAuthorship(input) {
184
+ const { tt, lang } = useProvenanceCopy();
185
+ const agent = useAgentActor();
186
+ const sys = useSystemActor();
187
+ const tz = useTimeZone();
188
+ const { provenance: p, person, fallbackOrigin, system } = input;
189
+ const viaLabel = (via) => {
190
+ if (!via)
191
+ return undefined;
192
+ const key = `via.${via}`;
193
+ return key in COPY.es ? tt(key) : via;
194
+ };
195
+ if (!p) {
196
+ if (!system)
197
+ return null;
198
+ const name = sys?.name || tt('system');
199
+ return {
200
+ kind: 'system', label: name, subtitle: fallbackOrigin,
201
+ description: [tt('createdBy', { who: name }), fallbackOrigin].filter(Boolean).join(' · '),
202
+ agentName: agent?.name || tt('agent'), systemAvatar: sys?.avatarUrl, integration: false, proposed: false,
203
+ };
204
+ }
205
+ const kind = classifyProvenance(p);
206
+ const agentName = agent?.name || str(p.actor_name) || tt('agent');
207
+ const when = formatWhen(p.authorized_at || p.at, lang, tz);
208
+ const origin = str(p.origin);
209
+ if (kind === 'human') {
210
+ const name = str(person?.name) || str(p.actor_person_name) || tt('user');
211
+ return {
212
+ kind, label: name, subtitle: origin,
213
+ description: [tt('createdBy', { who: name }), viaLabel(p.via), when].filter(Boolean).join(' · '),
214
+ person: { name, avatar: person?.avatar || p.actor_person_avatar },
215
+ agentName, integration: false, proposed: false,
216
+ };
217
+ }
218
+ if (kind === 'assisted') {
219
+ const name = str(p.authorized_by_name) || str(person?.name) || str(p.on_behalf_of_name) || tt('user');
220
+ const avatar = p.authorized_by_avatar || person?.avatar || p.on_behalf_of_avatar;
221
+ const parts = [tt('authorizedBy', { person: name })];
222
+ parts.push(p.summary ? tt('proposal', { agent: agentName, summary: p.summary }) : tt('proposedBy', { agent: agentName }));
223
+ if (origin)
224
+ parts.push(origin);
225
+ if (when)
226
+ parts.push(when);
227
+ return {
228
+ kind, label: tt('with', { person: name, agent: agentName }),
229
+ subtitle: origin || tt('proposedBy', { agent: agentName }),
230
+ description: parts.join(' · '),
231
+ person: { name, avatar }, agentName, agentAvatar: agent?.avatarUrl, integration: false, proposed: false,
232
+ };
233
+ }
234
+ if (kind === 'agent') {
235
+ const proposed = !!p.proposed;
236
+ const sub = proposed ? tt('pending') : origin || viaLabel(p.via);
237
+ const parts = [tt('createdBy', { who: agentName })];
238
+ if (proposed)
239
+ parts.push(tt('pending'));
240
+ if (origin)
241
+ parts.push(origin);
242
+ else if (p.via)
243
+ parts.push(viaLabel(p.via));
244
+ if (p.on_behalf_of_name)
245
+ parts.push(tt('onBehalfOf', { person: p.on_behalf_of_name }));
246
+ if (p.summary)
247
+ parts.push(p.summary);
248
+ if (when)
249
+ parts.push(when);
250
+ return {
251
+ kind, label: agentName, subtitle: sub, description: parts.join(' · '),
252
+ agentName, agentAvatar: agent?.avatarUrl, integration: false, proposed,
253
+ };
254
+ }
255
+ const integration = p.actor_kind === 'integration';
256
+ const name = integration ? str(p.actor_name) || tt('system') : sys?.name || tt('system');
257
+ const sub = origin || viaLabel(p.via);
258
+ return {
259
+ kind: 'system', label: name, subtitle: sub,
260
+ description: [tt('createdBy', { who: name }), sub, when].filter(Boolean).join(' · '),
261
+ agentName, systemAvatar: integration ? undefined : sys?.avatarUrl, integration, proposed: false,
262
+ };
263
+ }
264
+ const PX = { sm: 20, md: 32 };
265
+ function PersonAvatar({ name, avatar, size }) {
266
+ const getImageUrl = useImageUrl();
267
+ const px = PX[size];
268
+ return (_jsxs(Avatar, { className: "rounded-lg ring-1 ring-border/50", style: { width: px, height: px }, children: [_jsx(AvatarImage, { src: avatar ? getImageUrl(avatar) : '', alt: "", className: "object-cover" }), _jsx(AvatarFallback, { className: "rounded-lg bg-primary/5 text-[10px] font-bold text-primary", children: getInitials(name) })] }));
269
+ }
270
+ function AgentAvatar({ name, url, px, round }) {
271
+ const radius = round ? 'rounded-full' : 'rounded-lg';
272
+ if (url) {
273
+ return (_jsx("img", { src: url, alt: "", "aria-hidden": "true", draggable: false, className: cn('shrink-0 select-none bg-primary/5 object-contain', radius), style: { width: px, height: px } }));
274
+ }
275
+ return (_jsx("span", { "aria-hidden": "true", "data-agent-initials": getInitials(name), className: cn('flex shrink-0 items-center justify-center bg-primary/10 text-primary', radius), style: { width: px, height: px }, children: _jsx(Bot, { style: { width: px * 0.6, height: px * 0.6 } }) }));
276
+ }
277
+ function SystemAvatar({ url, integration, px }) {
278
+ if (url) {
279
+ return _jsx("img", { src: url, alt: "", "aria-hidden": "true", className: "shrink-0 rounded-lg object-contain", style: { width: px, height: px } });
280
+ }
281
+ const Icon = integration ? Plug : Server;
282
+ return (_jsx("span", { "aria-hidden": "true", className: "flex shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground ring-1 ring-border/50", style: { width: px, height: px }, children: _jsx(Icon, { style: { width: px * 0.55, height: px * 0.55 } }) }));
283
+ }
284
+ /** Avatar for a resolved authorship (person with the agent superimposed when assisted). */
285
+ export function ProvenanceAvatar({ authorship: a, size = 'md' }) {
286
+ const px = PX[size];
287
+ if (a.kind === 'agent')
288
+ return _jsx(AgentAvatar, { name: a.agentName, url: a.agentAvatar, px: px });
289
+ if (a.kind === 'system')
290
+ return _jsx(SystemAvatar, { url: a.systemAvatar, integration: a.integration, px: px });
291
+ const person = _jsx(PersonAvatar, { name: a.person?.name || a.label, avatar: a.person?.avatar, size: size });
292
+ if (a.kind === 'human')
293
+ return person;
294
+ const mini = Math.max(12, Math.round(px * 0.5));
295
+ return (_jsxs("span", { className: "relative inline-flex shrink-0", style: { width: px, height: px }, "data-provenance-overlay": "", children: [person, _jsx("span", { className: "absolute -bottom-1 -right-1 rounded-full bg-background p-px ring-1 ring-border", style: { lineHeight: 0 }, children: _jsx(AgentAvatar, { name: a.agentName, url: a.agentAvatar, px: mini, round: true }) })] }));
296
+ }
297
+ /**
298
+ * Who made a record and how — the four presentations (see module doc) with a
299
+ * keyboard-focusable trigger whose tooltip and screen-reader description say
300
+ * who authorized, what the agent proposed and when.
301
+ */
302
+ export function ProvenanceBadge({ provenance, person, system, fallbackOrigin, variant = 'cell', className }) {
303
+ const a = useResolvedAuthorship({ provenance, person, system, fallbackOrigin });
304
+ const descId = React.useId();
305
+ if (!a)
306
+ return null;
307
+ const inline = variant === 'inline';
308
+ const body = inline ? (_jsxs("span", { className: "inline-flex min-w-0 max-w-full items-center gap-2 overflow-hidden", children: [_jsx(ProvenanceAvatar, { authorship: a, size: "sm" }), _jsx("span", { className: "shrink-0 truncate font-medium", children: a.label }), a.subtitle ? _jsxs("span", { className: "min-w-0 truncate text-muted-foreground", children: ["\u00B7 ", a.subtitle] }) : null] })) : (_jsxs("span", { className: "flex min-w-0 items-center gap-3", children: [_jsx(ProvenanceAvatar, { authorship: a, size: "md" }), _jsxs("span", { className: "flex min-w-0 flex-col overflow-hidden", children: [_jsx("span", { className: "mb-0.5 truncate text-sm font-medium leading-none text-foreground/90", children: a.label }), a.subtitle ? (_jsx("span", { className: cn('truncate text-[11px] leading-none', a.proposed ? 'text-amber-700 dark:text-amber-400' : 'text-muted-foreground'), children: a.subtitle })) : null] })] }));
309
+ return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs("span", { tabIndex: 0, role: "group", "aria-label": a.label, "aria-describedby": descId, "data-provenance": a.kind, className: cn('min-w-0 rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring', inline ? 'inline-flex max-w-full text-sm' : 'flex max-w-full', className), children: [body, _jsx("span", { id: descId, className: "sr-only", children: a.description })] }) }), _jsx(TooltipContent, { className: "max-w-xs", children: a.description })] }));
310
+ }
311
+ function personFromRow(row) {
312
+ const cb = row?.created_by;
313
+ if (cb && typeof cb === 'object') {
314
+ const o = cb;
315
+ const name = str(o.name) || str(o.label) || str(o.email);
316
+ const avatar = str(o.avatar) || str(o.image) || str(o.photo);
317
+ if (name || avatar)
318
+ return { name, avatar };
319
+ }
320
+ if (typeof cb === 'string' && cb.trim())
321
+ return { name: cb };
322
+ return undefined;
323
+ }
324
+ /** True when the row has something AuthorshipCell renders differently from a plain person. */
325
+ export function hasSpecialAuthorship(row) {
326
+ const p = readProvenance(row);
327
+ if (p)
328
+ return classifyProvenance(p) !== 'human';
329
+ return isSystemCreated(row);
330
+ }
331
+ /**
332
+ * "Created by" for any record: the stored provenance when the host attached
333
+ * it, else the legacy rule (system when `created_by_id` is empty or the kernel
334
+ * actor, the `created_by` person otherwise). Renders nothing for a row with no
335
+ * creator information at all.
336
+ */
337
+ export function AuthorshipCell({ row, model, variant = 'cell', className }) {
338
+ const originFor = useProvenanceOrigin();
339
+ const provenance = readProvenance(row);
340
+ const person = personFromRow(row);
341
+ const system = !provenance && isSystemCreated(row);
342
+ if (!provenance && !system && !person)
343
+ return null;
344
+ if (!provenance && !system) {
345
+ return (_jsx(ProvenanceBadge, { provenance: { actor_kind: 'human', mode: 'manual' }, person: person, variant: variant, className: className }));
346
+ }
347
+ return (_jsx(ProvenanceBadge, { provenance: provenance, person: person, system: system, fallbackOrigin: system ? originFor?.(model, row) : undefined, variant: variant, className: className }));
348
+ }
349
+ /**
350
+ * Avatar + name for an activity/history event that carries provenance (no
351
+ * tooltip trigger: it lives inside the event's toggle button). The full
352
+ * sentence goes to `title` and to screen readers.
353
+ */
354
+ export function ProvenanceActorChip({ provenance, person, className, }) {
355
+ const a = useResolvedAuthorship({ provenance, person });
356
+ if (!a)
357
+ return null;
358
+ return (_jsxs("span", { className: cn('inline-flex min-w-0 items-center gap-2', className), title: a.description, "data-provenance": a.kind, children: [_jsx(ProvenanceAvatar, { authorship: a, size: "sm" }), _jsx("span", { className: "truncate text-sm font-semibold text-foreground", children: a.label }), _jsxs("span", { className: "sr-only", children: ["(", a.description, ")"] })] }));
359
+ }
360
+ /** Provenance carried by a notification (metadata.provenance), if any. */
361
+ export function notificationProvenance(item) {
362
+ let meta = item?.metadata;
363
+ if (typeof meta === 'string') {
364
+ try {
365
+ meta = JSON.parse(meta);
366
+ }
367
+ catch {
368
+ return undefined;
369
+ }
370
+ }
371
+ if (!meta || typeof meta !== 'object')
372
+ return undefined;
373
+ return parseProvenance(meta.provenance);
374
+ }
375
+ /**
376
+ * Avatar for a notification list (`renderAvatar` of the notifications
377
+ * dropdown): the provenance avatar when the notification carries one, else
378
+ * `fallback`.
379
+ */
380
+ export function NotificationProvenanceAvatar({ item, fallback = null, }) {
381
+ const p = notificationProvenance(item);
382
+ const a = useResolvedAuthorship({ provenance: p });
383
+ if (!a)
384
+ return _jsx(_Fragment, { children: fallback });
385
+ return (_jsx("span", { title: a.description, "aria-label": a.description, role: "img", className: "inline-flex", children: _jsx(ProvenanceAvatar, { authorship: a, size: "md" }) }));
386
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"record-history.d.ts","sourceRoot":"","sources":["../src/record-history.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAgB9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAOpD,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAC5C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IAC3C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAoCD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAuLtD,CAAA"}
1
+ {"version":3,"file":"record-history.d.ts","sourceRoot":"","sources":["../src/record-history.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAiB9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAOpD,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAC5C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IAC3C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAoCD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAiMtD,CAAA"}
@@ -12,6 +12,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  */
13
13
  import * as React from 'react';
14
14
  import { useSystemActor } from './org-runtime-context';
15
+ import { parseProvenance, ProvenanceActorChip } from './provenance';
15
16
  import { formatDistanceToNow } from 'date-fns';
16
17
  import { es, enUS } from 'date-fns/locale';
17
18
  import { ChevronDown, ChevronRight, Clock, ExternalLink } from 'lucide-react';
@@ -76,6 +77,7 @@ export const RecordHistory = ({ events, columns, timeZone, currency, locale = 'e
76
77
  const isOpen = openIds.has(event.id);
77
78
  const dotColor = actionDotColor(event.action);
78
79
  const actor = event.actor_label || event.actor_id || systemName;
80
+ const prov = parseProvenance(event.provenance);
79
81
  const timeAgo = (() => {
80
82
  try {
81
83
  return formatDistanceToNow(new Date(event.occurred_at), { addSuffix: true, locale: dateLocale });
@@ -96,7 +98,7 @@ export const RecordHistory = ({ events, columns, timeZone, currency, locale = 'e
96
98
  return event.occurred_at;
97
99
  }
98
100
  })();
99
- return (_jsx(Collapsible, { open: isOpen, onOpenChange: () => toggle(event.id), children: _jsxs("div", { className: "relative", children: [_jsx("span", { className: "absolute -left-5 top-3.5 h-2.5 w-2.5 rounded-full border-2 border-background -translate-x-[4px]", style: { background: dotColor }, "aria-hidden": "true" }), _jsxs("div", { className: "rounded-lg border border-border/60 bg-card overflow-hidden", children: [_jsx(CollapsibleTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-muted/30 transition-colors", children: [_jsxs(Avatar, { className: "h-7 w-7 rounded-full shrink-0", children: [event.actor_avatar ? (_jsx(AvatarImage, { src: resolveAvatarUrl ? resolveAvatarUrl(event.actor_avatar) : event.actor_avatar, alt: actor })) : null, _jsx(AvatarFallback, { className: "text-[9px] font-bold bg-primary/10 text-primary", children: getInitials(actor) })] }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [_jsx("span", { className: "text-sm font-semibold text-foreground truncate", children: actor }), _jsx("span", { className: "text-sm text-muted-foreground", children: actionLabel(event.action) })] }), _jsxs("div", { className: "flex items-center gap-1.5 mt-0.5", children: [_jsx(Clock, { className: "h-3 w-3 text-muted-foreground/60 shrink-0" }), _jsx("span", { className: "text-xs text-muted-foreground", title: fullDate, children: timeAgo }), (moduleLabel || event.addon_key) && (_jsx(Badge, { variant: "outline", className: "text-[10px] px-1.5 py-0 h-4 ml-1", children: moduleLabel || event.addon_key }))] })] }), onOpenEvent && (_jsx("span", { role: "button", tabIndex: 0, "aria-label": "Ver en registro de actividad", title: "Ver en registro de actividad", className: "shrink-0 rounded-md p-1.5 text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors cursor-pointer", onClick: (e) => {
101
+ return (_jsx(Collapsible, { open: isOpen, onOpenChange: () => toggle(event.id), children: _jsxs("div", { className: "relative", children: [_jsx("span", { className: "absolute -left-5 top-3.5 h-2.5 w-2.5 rounded-full border-2 border-background -translate-x-[4px]", style: { background: dotColor }, "aria-hidden": "true" }), _jsxs("div", { className: "rounded-lg border border-border/60 bg-card overflow-hidden", children: [_jsx(CollapsibleTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-muted/30 transition-colors", children: [prov ? null : (_jsxs(Avatar, { className: "h-7 w-7 rounded-full shrink-0", children: [event.actor_avatar ? (_jsx(AvatarImage, { src: resolveAvatarUrl ? resolveAvatarUrl(event.actor_avatar) : event.actor_avatar, alt: actor })) : null, _jsx(AvatarFallback, { className: "text-[9px] font-bold bg-primary/10 text-primary", children: getInitials(actor) })] })), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [prov ? (_jsx(ProvenanceActorChip, { provenance: prov, person: { name: event.actor_label ?? undefined, avatar: event.actor_avatar ?? undefined } })) : (_jsx("span", { className: "text-sm font-semibold text-foreground truncate", children: actor })), _jsx("span", { className: "text-sm text-muted-foreground", children: actionLabel(event.action) })] }), _jsxs("div", { className: "flex items-center gap-1.5 mt-0.5", children: [_jsx(Clock, { className: "h-3 w-3 text-muted-foreground/60 shrink-0" }), _jsx("span", { className: "text-xs text-muted-foreground", title: fullDate, children: timeAgo }), (moduleLabel || event.addon_key) && (_jsx(Badge, { variant: "outline", className: "text-[10px] px-1.5 py-0 h-4 ml-1", children: moduleLabel || event.addon_key }))] })] }), onOpenEvent && (_jsx("span", { role: "button", tabIndex: 0, "aria-label": "Ver en registro de actividad", title: "Ver en registro de actividad", className: "shrink-0 rounded-md p-1.5 text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors cursor-pointer", onClick: (e) => {
100
102
  e.stopPropagation();
101
103
  onOpenEvent(event);
102
104
  }, onKeyDown: (e) => {