diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts index 1ceda6f9ac..505722b991 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts @@ -1143,6 +1143,36 @@ function describe(tool: string, values: Values, result: unknown, names: AiDetail } return {hood: text('save-relations'), blocks}; } + case 'read_versions': { + const versions = isObject(result) && Array.isArray(result.versions) ? result.versions.filter(isObject) : undefined; + if (!versions) { + return {hood: text('read-versions'), blocks: generic(result, 'result')}; + } + const rows = versions.slice(0, MAX_ROWS).map(version => [str(version.name), str(version.author), + str(version.time) ? new Date(version.time).toLocaleString() : undefined].filter(Boolean).join(' · ')); + return {hood: text('read-versions'), blocks: rows.length ? [{type: 'list', rows}] : []}; + } + case 'commit_version': { + const saved = isObject(result) ? result : {}; + const rows: AiDetailFact[] = []; + if (str(saved.versionId)) { + rows.push({label: K + 'fact.version', value: saved.versionId, mono: true}); + } + if (str(saved.branch)) { + rows.push({label: K + 'fact.branch', value: saved.branch}); + } + for (const field of ['added', 'modified', 'removed']) { + if (typeof saved[field] === 'number') { + rows.push({label: K + 'fact.' + field, value: String(saved[field])}); + } + } + return {hood: text('commit-version', {name: str(values.name) ?? '—'}), blocks: rows.length ? [{type: 'facts', rows}] : generic(result, 'result')}; + } + case 'restore_version': { + const types = isObject(result) && Array.isArray(result.result) ? result.result.filter(isObject) : undefined; + const rows = (types ?? []).map(type => `${type.entityType}: +${type.created} · ~${type.updated} · −${type.deleted}`); + return {hood: text('restore-version', {version: String(values.versionId ?? '').slice(0, 8)}), blocks: types ? [{type: 'list', rows}] : generic(result, 'result')}; + } case 'read_platform_settings': return {hood: text('read-platform-settings'), blocks: json('settings', result)}; case 'save_platform_settings': diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts index 2d52441e53..cb704e8439 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts @@ -64,6 +64,7 @@ const TOOL_WORDS: Record = { save_image: 'save-image', read_platform_settings: 'read-platform-settings', save_relations: 'save-relations', + read_versions: 'read-versions', save_platform_settings: 'save-platform-settings', read_device_connect_commands: 'read-connection-settings', search_web: 'search-web', @@ -77,6 +78,8 @@ const TOOL_WORDS: Record = { const GENERATING_TOOLS: Record = { set_dashboard_html_page: 'lay-out-dashboard', reprocess_calculated_field: 'recalculate-history', + commit_version: 'commit-version', + restore_version: 'restore-version', research_device_connectivity: 'research-device' }; diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts index 56ef799da6..569c5f0496 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts @@ -51,7 +51,7 @@ const VALUE_TOKENS: Record = { const CODE_FIELDS = new Set(['arguments', 'expression', 'output']); -const OWN_TYPE_LABELS = new Set(['DASHBOARD_WIDGET', 'DASHBOARD_STATE', 'DASHBOARD_ENTITY_ALIAS', 'DASHBOARD_FILTER', 'NOTIFICATION', 'NOTIFICATION_SETTINGS', 'NOTIFICATION_PREFERENCES', 'IMAGE', 'PLATFORM_SETTINGS', 'RELATION']); +const OWN_TYPE_LABELS = new Set(['DASHBOARD_WIDGET', 'DASHBOARD_STATE', 'DASHBOARD_ENTITY_ALIAS', 'DASHBOARD_FILTER', 'NOTIFICATION', 'NOTIFICATION_SETTINGS', 'NOTIFICATION_PREFERENCES', 'IMAGE', 'PLATFORM_SETTINGS', 'RELATION', 'VERSION']); const PROFILE_TYPES = new Set([EntityType.DEVICE_PROFILE, EntityType.ASSET_PROFILE]); diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts index 9ca3567999..336054e458 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts @@ -87,7 +87,7 @@ const WELCOMES: Partial> = { [AiAssistantViewType.SELF_REGISTRATION]: {key: 'self-registration'}, [AiAssistantViewType.SECRETS]: {key: 'secrets', examples: ['create']}, [AiAssistantViewType.AUDIT_LOGS]: {key: 'audit-logs', examples: ['changes', 'logins']}, - [AiAssistantViewType.VERSION_CONTROL]: {key: 'version-control'}, + [AiAssistantViewType.VERSION_CONTROL]: {key: 'version-control', examples: ['save', 'history']}, [AiAssistantViewType.TASK_MANAGER]: {key: 'task-manager', examples: ['failed']}, [AiAssistantViewType.SCHEDULER]: {key: 'scheduler'}, [AiAssistantViewType.HOME_SETTINGS]: {key: 'home-settings', examples: ['set']}, diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 5d19e7d614..117300635d 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -880,6 +880,9 @@ "relations-added": "Added", "relations-removed": "Removed", "relations-failed": "Failed", + "read-versions": "Read the saved versions", + "commit-version": "Saved the version '{{name}}'", + "restore-version": "Restored from version {{version}}", "read-platform-settings": "Read the platform settings", "save-platform-settings": "Saved the platform settings", "usage": { @@ -975,6 +978,11 @@ "no": "No", "fact": { "link": "Link", + "version": "Version", + "branch": "Branch", + "added": "Added", + "modified": "Modified", + "removed": "Removed", "comment": "Comment", "reference": "Reference", "tested": "Tested before saving", @@ -1274,6 +1282,18 @@ "run": "Changing the relations", "done": "Changed the relations" }, + "read-versions": { + "run": "Reading the versions", + "done": "Read the versions" + }, + "commit-version": { + "run": "Saving a version", + "done": "Saved a version" + }, + "restore-version": { + "run": "Restoring from the version", + "done": "Restored from the version" + }, "create-entity-view": { "run": "Creating the entity view", "done": "Created the entity view" @@ -1590,6 +1610,9 @@ "ask-again-message": "Ask me again for the same change.", "field": { "source": "Source", + "entities": "Entities", + "includes": "Also saves", + "removeOthers": "Delete what the version lacks", "assignee": "Assignee", "comment": "Comment", "timeseries": "Telemetry", @@ -1665,6 +1688,7 @@ }, "type": { "IMAGE": "Image", + "VERSION": "Version", "RELATION": "Relations", "PLATFORM_SETTINGS": "Platform settings", "ENTITY_GROUP": "Group", @@ -2417,7 +2441,11 @@ "version-control": { "title": "Ask about version control", "line": "Keep your entities in Git and restore earlier versions.", - "suggestion": "How do I save my dashboards to Git?" + "suggestion": "How do I save my dashboards to Git?", + "example": { + "save": {"label": "Save a version", "message": "Save a version of all my dashboards."}, + "history": {"label": "Recent versions", "message": "What versions were saved this week, and by whom?"} + } }, "task-manager": { "title": "Ask about the task manager",