zerochat 7.3.0__py3-none-any.whl

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 (130) hide show
  1. zerochat-7.3.0.dist-info/METADATA +70 -0
  2. zerochat-7.3.0.dist-info/RECORD +130 -0
  3. zerochat-7.3.0.dist-info/WHEEL +5 -0
  4. zerochat-7.3.0.dist-info/entry_points.txt +2 -0
  5. zerochat-7.3.0.dist-info/licenses/LICENSE +34 -0
  6. zerochat-7.3.0.dist-info/top_level.txt +2 -0
  7. zerochat.py +2004 -0
  8. zerochat_runtime/__init__.py +1 -0
  9. zerochat_runtime/assets/css/base.css +199 -0
  10. zerochat_runtime/assets/css/components/composer.css +1258 -0
  11. zerochat_runtime/assets/css/components/debug.css +777 -0
  12. zerochat_runtime/assets/css/components/header.css +97 -0
  13. zerochat_runtime/assets/css/components/icons.css +39 -0
  14. zerochat_runtime/assets/css/components/markdown.css +685 -0
  15. zerochat_runtime/assets/css/components/messages.css +473 -0
  16. zerochat_runtime/assets/css/components/modals.css +1319 -0
  17. zerochat_runtime/assets/css/components/sidebar.css +622 -0
  18. zerochat_runtime/assets/css/components/tools.css +1223 -0
  19. zerochat_runtime/assets/css/layout.css +171 -0
  20. zerochat_runtime/assets/css/print.css +120 -0
  21. zerochat_runtime/assets/css/styles.css +18 -0
  22. zerochat_runtime/assets/css/theme-overrides.css +555 -0
  23. zerochat_runtime/assets/css/tokens.css +165 -0
  24. zerochat_runtime/assets/help/architecture.html +247 -0
  25. zerochat_runtime/assets/help/composer.html +134 -0
  26. zerochat_runtime/assets/help/conversations.html +105 -0
  27. zerochat_runtime/assets/help/debug.html +108 -0
  28. zerochat_runtime/assets/help/en/architecture.html +247 -0
  29. zerochat_runtime/assets/help/en/composer.html +134 -0
  30. zerochat_runtime/assets/help/en/conversations.html +104 -0
  31. zerochat_runtime/assets/help/en/debug.html +105 -0
  32. zerochat_runtime/assets/help/en/gemini-free.html +39 -0
  33. zerochat_runtime/assets/help/en/index.html +191 -0
  34. zerochat_runtime/assets/help/en/learning.html +71 -0
  35. zerochat_runtime/assets/help/en/mcp.html +143 -0
  36. zerochat_runtime/assets/help/en/openrouter-free.html +39 -0
  37. zerochat_runtime/assets/help/en/profiles.html +173 -0
  38. zerochat_runtime/assets/help/en/rag.html +130 -0
  39. zerochat_runtime/assets/help/en/reasoning-telemetry.html +108 -0
  40. zerochat_runtime/assets/help/en/tools-agent.html +133 -0
  41. zerochat_runtime/assets/help/en/webllm.html +355 -0
  42. zerochat_runtime/assets/help/gemini-free.html +39 -0
  43. zerochat_runtime/assets/help/help.css +604 -0
  44. zerochat_runtime/assets/help/help.js +51 -0
  45. zerochat_runtime/assets/help/index.html +194 -0
  46. zerochat_runtime/assets/help/learning.html +71 -0
  47. zerochat_runtime/assets/help/mcp.html +143 -0
  48. zerochat_runtime/assets/help/openrouter-free.html +39 -0
  49. zerochat_runtime/assets/help/profiles.html +174 -0
  50. zerochat_runtime/assets/help/rag.html +130 -0
  51. zerochat_runtime/assets/help/reasoning-telemetry.html +111 -0
  52. zerochat_runtime/assets/help/tools-agent.html +133 -0
  53. zerochat_runtime/assets/help/webllm.html +359 -0
  54. zerochat_runtime/assets/js/agent-core.js +1553 -0
  55. zerochat_runtime/assets/js/api.js +844 -0
  56. zerochat_runtime/assets/js/app.js +2558 -0
  57. zerochat_runtime/assets/js/attachments.js +220 -0
  58. zerochat_runtime/assets/js/charts.js +338 -0
  59. zerochat_runtime/assets/js/chat-engine.js +566 -0
  60. zerochat_runtime/assets/js/config-store.js +207 -0
  61. zerochat_runtime/assets/js/context-manager.js +584 -0
  62. zerochat_runtime/assets/js/conversation-service.js +484 -0
  63. zerochat_runtime/assets/js/cookies.js +688 -0
  64. zerochat_runtime/assets/js/data-reset-service.js +136 -0
  65. zerochat_runtime/assets/js/debug.js +508 -0
  66. zerochat_runtime/assets/js/defaults.js +16 -0
  67. zerochat_runtime/assets/js/export.js +179 -0
  68. zerochat_runtime/assets/js/file-parser.js +2088 -0
  69. zerochat_runtime/assets/js/generation-controller.js +417 -0
  70. zerochat_runtime/assets/js/i18n.js +1483 -0
  71. zerochat_runtime/assets/js/icons.js +156 -0
  72. zerochat_runtime/assets/js/ingestionEngine.js +436 -0
  73. zerochat_runtime/assets/js/markdown.js +588 -0
  74. zerochat_runtime/assets/js/mcp.js +1271 -0
  75. zerochat_runtime/assets/js/message-turns.js +62 -0
  76. zerochat_runtime/assets/js/profile-backup.js +118 -0
  77. zerochat_runtime/assets/js/profile-export-bundle.js +481 -0
  78. zerochat_runtime/assets/js/profile-repository.js +213 -0
  79. zerochat_runtime/assets/js/providers-webllm.js +486 -0
  80. zerochat_runtime/assets/js/providers.js +1560 -0
  81. zerochat_runtime/assets/js/rag-index.js +295 -0
  82. zerochat_runtime/assets/js/rag-service.js +530 -0
  83. zerochat_runtime/assets/js/rag-ui.js +997 -0
  84. zerochat_runtime/assets/js/ragStorage.js +676 -0
  85. zerochat_runtime/assets/js/sandbox.js +449 -0
  86. zerochat_runtime/assets/js/state.js +704 -0
  87. zerochat_runtime/assets/js/storage-db.js +144 -0
  88. zerochat_runtime/assets/js/tool-cards.js +330 -0
  89. zerochat_runtime/assets/js/tool-security.js +653 -0
  90. zerochat_runtime/assets/js/tools/README.md +50 -0
  91. zerochat_runtime/assets/js/tools/builtin/agent-checkpoint.tool.js +212 -0
  92. zerochat_runtime/assets/js/tools/builtin/download-pdf.tool.js +111 -0
  93. zerochat_runtime/assets/js/tools/builtin/execute-javascript.tool.js +219 -0
  94. zerochat_runtime/assets/js/tools/builtin/fetch-web-page.tool.js +112 -0
  95. zerochat_runtime/assets/js/tools/builtin/list-documents.tool.js +117 -0
  96. zerochat_runtime/assets/js/tools/builtin/read-knowledge-chunk.tool.js +129 -0
  97. zerochat_runtime/assets/js/tools/builtin/read-knowledge-image.tool.js +95 -0
  98. zerochat_runtime/assets/js/tools/builtin/render-chart.tool.js +90 -0
  99. zerochat_runtime/assets/js/tools/builtin/search-knowledge-base.tool.js +124 -0
  100. zerochat_runtime/assets/js/tools/builtin/search-web.tool.js +125 -0
  101. zerochat_runtime/assets/js/tools/tool-manifest.js +53 -0
  102. zerochat_runtime/assets/js/tools/tool-runtime.js +77 -0
  103. zerochat_runtime/assets/js/ui-composer.js +319 -0
  104. zerochat_runtime/assets/js/ui-conversation.js +655 -0
  105. zerochat_runtime/assets/js/ui-dialogs.js +132 -0
  106. zerochat_runtime/assets/js/ui-generation-status.js +119 -0
  107. zerochat_runtime/assets/js/ui-inspector.js +804 -0
  108. zerochat_runtime/assets/js/ui-mcp.js +604 -0
  109. zerochat_runtime/assets/js/ui-profiles.js +824 -0
  110. zerochat_runtime/assets/js/ui-reasoning.js +146 -0
  111. zerochat_runtime/assets/js/ui-settings.js +825 -0
  112. zerochat_runtime/assets/js/ui-shell.js +215 -0
  113. zerochat_runtime/assets/js/ui-sidebar.js +429 -0
  114. zerochat_runtime/assets/js/ui-telemetry.js +404 -0
  115. zerochat_runtime/assets/js/ui-transfer.js +262 -0
  116. zerochat_runtime/assets/js/utils.js +216 -0
  117. zerochat_runtime/assets/js/vendor/orama.browser.js +11 -0
  118. zerochat_runtime/assets/js/web-browser.js +569 -0
  119. zerochat_runtime/assets/js/web-search.js +519 -0
  120. zerochat_runtime/assets/manifest.webmanifest +20 -0
  121. zerochat_runtime/assets/services/dummy_mcp/dummy_mcp_server.py +47 -0
  122. zerochat_runtime/assets/services/dummy_mcp/service.json +22 -0
  123. zerochat_runtime/assets/services/lsp/installer.json +9 -0
  124. zerochat_runtime/assets/services/lsp/service.json +22 -0
  125. zerochat_runtime/assets/services/memory/installer.json +9 -0
  126. zerochat_runtime/assets/services/memory/service.json +24 -0
  127. zerochat_runtime/assets/services/playwright/installer.json +10 -0
  128. zerochat_runtime/assets/services/playwright/service.json +39 -0
  129. zerochat_runtime/assets/sw.js +164 -0
  130. zerochat_runtime/assets/zerochat.html +671 -0
@@ -0,0 +1,117 @@
1
+ /** Tool autocontenida: list_documents. */
2
+ (function (root, factory) {
3
+ if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = factory();
4
+ else root.ChatBuiltinListDocumentsTool = factory();
5
+ })(typeof self !== 'undefined' ? self : this, function () {
6
+ 'use strict';
7
+
8
+ const definition = {
9
+ name: 'list_documents',
10
+ description: 'Returns the catalog of available documents (title, chunks, and images). Accepts an optional filter to narrow documents by title keywords (e.g. "Walmart", "2020", "10K"). Use it when you do not know the available sources or when a previous search did not find the expected document.',
11
+ parameters: {
12
+ type: 'object',
13
+ properties: {
14
+ filter: {
15
+ type: 'string',
16
+ description: 'Optional keyword, company name, year, or topic to filter document titles (e.g. "Walmart", "2020", "10-K"). If omitted, returns all documents.'
17
+ }
18
+ },
19
+ required: []
20
+ }
21
+ };
22
+
23
+ function getBranchIds(context = {}) {
24
+ return context.activeRagBranchIds || context.activeRagBranchId || context.branchId || context.config?.activeRagBranchIds || context.config?.activeRagBranchId || '';
25
+ }
26
+ const getBranchId = getBranchIds;
27
+
28
+ function getRagService(context = {}) {
29
+ if (context.services?.ragService) return context.services.ragService;
30
+ if (typeof window !== 'undefined' && window.ChatRagService) return window.ChatRagService;
31
+ if (typeof require !== 'undefined') {
32
+ try { return require('../../rag-service.js'); } catch (e) {}
33
+ }
34
+ return null;
35
+ }
36
+
37
+ const LAYERS_ICON_SVG = '<svg class="ui-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="12 2 2 7 12 12 22 7 12 2"></polygon><polyline points="2 17 12 22 22 17"></polyline><polyline points="2 12 12 17 22 12"></polyline></svg>';
38
+
39
+ function createCardWrapper(ui) {
40
+ if (ui?.createCardWrapper) return ui.createCardWrapper();
41
+ const doc = ui?.document || (typeof document !== 'undefined' ? document : null);
42
+ if (!doc) return null;
43
+ const card = doc.createElement('div');
44
+ card.className = 'tool-card-wrapper';
45
+ return card;
46
+ }
47
+
48
+ function createLiveCard(_args, ui) {
49
+ const card = createCardWrapper(ui);
50
+ if (!card) return null;
51
+ const t = ui?.t || ((key) => key);
52
+ const spinner = ui?.SPINNER_SVG || '';
53
+ const chevron = ui?.CHEVRON_SVG || '';
54
+ const title = t('tool_rag_list_title') || 'Base de Conocimiento (Índice de Documentos)';
55
+ const loading = t('tool_rag_list_loading') || 'Consultando documentos indexados...';
56
+ const retrieving = t('tool_rag_list_retrieving') || 'Recuperando documentos desde IndexedDB...';
57
+ card.innerHTML = `<div class="tool-execution-card rag-execution-card"><div class="tool-card-header"><div class="tool-card-title"><span>${LAYERS_ICON_SVG}</span><span>${title}</span></div><div class="tool-card-header-actions"><span class="tool-card-badge status-loading">${spinner} <span>${loading}</span></span><button type="button" class="btn-tool-collapse" title="${t('tool_btn_collapse') || 'Minimizar'}">${chevron}</button></div></div><div class="tool-card-collapsible-body"><div class="tool-card-result"><div class="tool-loading-placeholder">${spinner} <span>${retrieving}</span></div></div></div></div>`;
58
+ return card;
59
+ }
60
+
61
+ const safeEscapeHtml = (value) => String(value || '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
62
+
63
+ function updateLiveCard(card, _args, result = {}, elapsedMs = 0, ui) {
64
+ if (!card) return;
65
+ const t = ui?.t || ((key, params) => key);
66
+ const Markdown = ui?.markdown || (typeof window !== 'undefined' && window.ChatMarkdown) || (typeof window !== 'undefined' && window.ChatUtils) || { escapeHtml: safeEscapeHtml };
67
+ const checkSvg = ui?.CHECK_SVG || '';
68
+ const errorSvg = ui?.ERROR_SVG || '';
69
+ const success = result?.success !== false && !result?.error;
70
+ const count = result?.count ?? 0;
71
+ const text = result?.text || (typeof result === 'object' ? JSON.stringify(result, null, 2) : String(result || ''));
72
+ const indexedLabel = t('tool_rag_list_indexed', { count, plural: count === 1 ? '' : 's' }) || `${count} doc${count === 1 ? '' : 's'} indexado${count === 1 ? '' : 's'}`;
73
+ const errorLabel = result?.error || t('tool_err_query') || 'Error al consultar';
74
+ const badge = card.querySelector('.tool-card-badge');
75
+ if (badge) {
76
+ badge.className = `tool-card-badge ${success ? 'status-success' : 'status-error'}`;
77
+ badge.innerHTML = success ? `${checkSvg} <span>${indexedLabel} (${elapsedMs || 0}ms)</span>` : `${errorSvg} <span>${Markdown.escapeHtml(errorLabel)}</span>`;
78
+ }
79
+ const body = card.querySelector('.tool-card-result');
80
+ if (body) body.innerHTML = `<pre class="tool-result-pre"><code>${Markdown.escapeHtml(text.slice(0, 3000))}${text.length > 3000 ? '\n... (texto completo truncado en tarjeta)' : ''}</code></pre>`;
81
+ }
82
+ function renderHistoricalCard(args, message, ui) { const card = createLiveCard(args, ui); if (!card) return null; let result = {}; if (message?.content) { try { result = JSON.parse(message.content); } catch (e) { result = { text: message.content }; } } updateLiveCard(card, args, result, 0, ui); return card; }
83
+
84
+ function createTool(Tool) {
85
+ if (typeof Tool !== 'function') throw new Error('La clase Tool es necesaria para crear list_documents.');
86
+ return new Tool({
87
+ id: definition.name,
88
+ definition,
89
+ aliases: ['listdocuments', 'list_knowledge_base', 'list_docs', 'get_documents', 'listar_documentos'],
90
+ category: 'rag',
91
+ metadata: { icon: 'book-open', label: definition.name },
92
+ settings: { showInSettings: false },
93
+ isAvailable: (config = {}) => Boolean(config.activeRagBranchId || (config.activeRagBranchIds && config.activeRagBranchIds.length > 0)),
94
+ execute: async (args = {}, context = {}) => {
95
+ const RagService = getRagService(context);
96
+ if (!RagService?.listDocuments) return { success: false, error: 'Servicio de RAG no disponible.' };
97
+ return RagService.listDocuments(getBranchIds(context), args);
98
+ },
99
+ result: {
100
+ toModel: (_args, result) => result?.text || JSON.stringify(result || {}),
101
+ toMarkdown: (args, result) => {
102
+ const filterSuffix = args?.filter ? ` filtrado por "${args.filter}"` : '';
103
+ return `> **list_documents** (${result?.count || 0} documentos indexados${filterSuffix})\n\n`;
104
+ }
105
+ },
106
+ displayMode: 'collapsed',
107
+ view: { id: definition.name, displayMode: 'collapsed', createLiveCard, updateLiveCard, renderHistoricalCard }
108
+ });
109
+ }
110
+
111
+ const toolModule = { id: definition.name, definition, displayMode: 'collapsed', createTool, getBranchId, getRagService, view: { id: definition.name, displayMode: 'collapsed', createLiveCard, updateLiveCard, renderHistoricalCard } };
112
+ let manifestApi = null;
113
+ if (typeof window !== 'undefined' && window.ChatToolManifest) manifestApi = window.ChatToolManifest;
114
+ else if (typeof require !== 'undefined') { try { manifestApi = require('../tool-manifest.js'); } catch (e) {} }
115
+ if (manifestApi?.builtin && !manifestApi.builtin.has(toolModule.id)) manifestApi.builtin.register(toolModule);
116
+ return toolModule;
117
+ });
@@ -0,0 +1,129 @@
1
+ /** Tool module: read_knowledge_chunk. */
2
+ (function (root, factory) {
3
+ if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = factory();
4
+ else root.ChatBuiltinReadKnowledgeChunkTool = factory();
5
+ })(typeof self !== 'undefined' ? self : this, function () {
6
+ 'use strict';
7
+
8
+ const definition = {
9
+ name: 'read_knowledge_chunk',
10
+ description: 'Reads the full content of one or several previously located chunks. Accepts chunkId for a single chunk or chunkIds (list of identifiers) to retrieve up to 5 at once in a single turn (prefer 1-2 chunks for dense financial tables). Use as internal evidence; then synthesize and respond.',
11
+ parameters: {
12
+ type: 'object',
13
+ properties: {
14
+ chunkIds: {
15
+ type: 'array',
16
+ items: { type: 'string' },
17
+ description: 'List of chunk identifiers to read simultaneously in a single turn (max 5; prefer 1-2 for dense tables).'
18
+ },
19
+ chunkId: {
20
+ type: 'string',
21
+ description: 'Unique chunk identifier (chunkId). Accepted as an alternative or complement to chunkIds.'
22
+ }
23
+ }
24
+ }
25
+ };
26
+
27
+ function getRagService(context = {}) {
28
+ if (context.services?.ragService) return context.services.ragService;
29
+ if (typeof window !== 'undefined' && window.ChatRagService) return window.ChatRagService;
30
+ if (typeof require !== 'undefined') { try { return require('../../rag-service.js'); } catch (_) {} }
31
+ return null;
32
+ }
33
+
34
+ function getBranchIds(context = {}) {
35
+ return context.activeRagBranchIds || context.activeRagBranchId || context.branchId || context.config?.activeRagBranchIds || context.config?.activeRagBranchId || '';
36
+ }
37
+ const getBranchId = getBranchIds;
38
+
39
+ function createCardWrapper(ui) {
40
+ if (ui?.createCardWrapper) return ui.createCardWrapper();
41
+ const doc = ui?.document || (typeof document !== 'undefined' ? document : null);
42
+ if (!doc) return null;
43
+ const card = doc.createElement('div');
44
+ card.className = 'tool-card-wrapper';
45
+ return card;
46
+ }
47
+
48
+ const DOC_ICON_SVG = '<svg class="ui-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>';
49
+
50
+ const safeEscapeHtml = (value) => String(value || '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
51
+
52
+ function createLiveCard(args, ui) {
53
+ const card = createCardWrapper(ui);
54
+ if (!card) return null;
55
+ const Markdown = ui?.markdown || (typeof window !== 'undefined' && window.ChatMarkdown) || (typeof window !== 'undefined' && window.ChatUtils) || { escapeHtml: safeEscapeHtml };
56
+ const t = ui?.t || ((key, params) => key);
57
+ const spinner = ui?.SPINNER_SVG || '';
58
+ const chevron = ui?.CHEVRON_SVG || '';
59
+ const title = t('tool_rag_read_title') || 'Fragmento de conocimiento';
60
+ const ids = Array.isArray(args?.chunkIds) && args.chunkIds.length > 0
61
+ ? args.chunkIds
62
+ : (args?.chunkId ? [args.chunkId] : []);
63
+ const targetLabel = ids.length > 1
64
+ ? `${ids.length} fragmentos`
65
+ : (ids[0] || '');
66
+ const loading = t('tool_rag_read_loading', { chunkId: Markdown.escapeHtml(targetLabel) }) || `Leyendo ${Markdown.escapeHtml(targetLabel)}...`;
67
+ const retrieving = t('tool_rag_read_retrieving') || 'Recuperando texto desde IndexedDB...';
68
+ card.innerHTML = `<div class="tool-execution-card rag-execution-card"><div class="tool-card-header"><div class="tool-card-title"><span>${DOC_ICON_SVG}</span><span>${title}</span></div><div class="tool-card-header-actions"><span class="tool-card-badge status-loading">${spinner} <span>${loading}</span></span><button type="button" class="btn-tool-collapse" title="${t('tool_btn_collapse') || 'Minimizar'}">${chevron}</button></div></div><div class="tool-card-collapsible-body"><div class="tool-card-result"><div class="tool-loading-placeholder">${spinner} <span>${retrieving}</span></div></div></div></div>`;
69
+ return card;
70
+ }
71
+ function updateLiveCard(card, _args, result = {}, _elapsedMs, ui) {
72
+ if (!card) return;
73
+ const t = ui?.t || ((key, params) => key);
74
+ const Markdown = ui?.markdown || (typeof window !== 'undefined' && window.ChatMarkdown) || (typeof window !== 'undefined' && window.ChatUtils) || { escapeHtml: safeEscapeHtml };
75
+ const checkSvg = ui?.CHECK_SVG || '';
76
+ const errorSvg = ui?.ERROR_SVG || '';
77
+ const success = result?.success !== false && !result?.error;
78
+ const content = result?.content || result?.error || '';
79
+ const badge = card.querySelector('.tool-card-badge');
80
+ const count = result?.count || (result?.chunkIds?.length) || 1;
81
+ const countLabel = count > 1 ? `${count} fragmentos recuperados` : 'Fragmento recuperado';
82
+ const retrievedLabel = t('tool_rag_read_retrieved', { chars: content.length }) || `${countLabel} (${content.length} caracteres)`;
83
+ const notFoundLabel = result?.error || t('tool_rag_read_not_found') || 'No encontrado';
84
+ if (badge) {
85
+ badge.className = `tool-card-badge ${success ? 'status-success' : 'status-error'}`;
86
+ badge.innerHTML = success ? `${checkSvg} <span>${retrievedLabel}</span>` : `${errorSvg} <span>${Markdown.escapeHtml(notFoundLabel)}</span>`;
87
+ }
88
+ const body = card.querySelector('.tool-card-result');
89
+ if (body) body.innerHTML = `<pre class="tool-result-pre"><code>${Markdown.escapeHtml(content.slice(0, 3000))}${content.length > 3000 ? '\n…' : ''}</code></pre>`;
90
+ }
91
+ function renderHistoricalCard(args, message, ui) {
92
+ const card = createLiveCard(args, ui); if (!card) return null;
93
+ let result = {}; try { result = JSON.parse(message?.content || '{}'); } catch (_) { result = { content: message?.content || '' }; }
94
+ updateLiveCard(card, args, result, 0, ui); return card;
95
+ }
96
+
97
+ function createTool(Tool) {
98
+ if (typeof Tool !== 'function') throw new Error('La clase Tool es necesaria para crear read_knowledge_chunk.');
99
+ return new Tool({
100
+ id: definition.name,
101
+ definition,
102
+ aliases: [],
103
+ category: 'rag',
104
+ metadata: { icon: 'file-text', label: definition.name },
105
+ settings: { showInSettings: false },
106
+ isAvailable: config => Boolean(config.activeRagBranchId || (config.activeRagBranchIds && config.activeRagBranchIds.length > 0)),
107
+ execute: async (args, context = {}) => {
108
+ const service = getRagService(context);
109
+ return service?.readKnowledgeChunk ? service.readKnowledgeChunk(getBranchIds(context), args) : { success: false, error: 'Servicio de RAG no disponible.' };
110
+ },
111
+ result: {
112
+ toModel: (_args, result) => result?.content || JSON.stringify(result || {}),
113
+ toMarkdown: (args, result) => {
114
+ const ids = result?.chunkIds || (args?.chunkIds) || [args?.chunkId || ''];
115
+ return `> **read_knowledge_chunk** (${ids.join(', ')})\n\n`;
116
+ }
117
+ },
118
+ displayMode: 'collapsed',
119
+ view: { id: definition.name, displayMode: 'collapsed', createLiveCard, updateLiveCard, renderHistoricalCard }
120
+ });
121
+ }
122
+
123
+ const toolModule = { id: definition.name, definition, displayMode: 'collapsed', createTool, getRagService, getBranchId, view: { id: definition.name, displayMode: 'collapsed', createLiveCard, updateLiveCard, renderHistoricalCard } };
124
+ let manifestApi = null;
125
+ if (typeof window !== 'undefined' && window.ChatToolManifest) manifestApi = window.ChatToolManifest;
126
+ else if (typeof require !== 'undefined') { try { manifestApi = require('../tool-manifest.js'); } catch (_) {} }
127
+ if (manifestApi?.builtin && !manifestApi.builtin.has(toolModule.id)) manifestApi.builtin.register(toolModule);
128
+ return toolModule;
129
+ });
@@ -0,0 +1,95 @@
1
+ /** Tool module: read_knowledge_image. */
2
+ (function (root, factory) {
3
+ if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = factory();
4
+ else root.ChatBuiltinReadKnowledgeImageTool = factory();
5
+ })(typeof self !== 'undefined' ? self : this, function () {
6
+ 'use strict';
7
+ const definition = {
8
+ name: 'read_knowledge_image',
9
+ description: 'Retrieves an image from a RAG document to inspect it visually. Use only if you have native vision capability and the image may provide relevant information. Provide a full rag-image://docId:imgId reference obtained from the document; do not invent identifiers. If you cannot process images, do not use this tool.',
10
+ parameters: { type: 'object', properties: { imageRef: { type: 'string', description: 'Full rag-image://docId:imgId reference obtained from a RAG document.' } }, required: ['imageRef'] }
11
+ };
12
+ function getRagService(context = {}) {
13
+ if (context.services?.ragService) return context.services.ragService;
14
+ if (typeof window !== 'undefined' && window.ChatRagService) return window.ChatRagService;
15
+ if (typeof require !== 'undefined') { try { return require('../../rag-service.js'); } catch (_) {} }
16
+ return null;
17
+ }
18
+ function getBranchIds(context = {}) { return context.activeRagBranchIds || context.activeRagBranchId || context.branchId || context.config?.activeRagBranchIds || context.config?.activeRagBranchId || ''; }
19
+ function getMarkdown(ui) {
20
+ if (ui?.markdown?.escapeHtml) return ui.markdown;
21
+ if (typeof window !== 'undefined' && window.ChatMarkdown?.escapeHtml) return window.ChatMarkdown;
22
+ if (typeof require !== 'undefined') {
23
+ try {
24
+ const md = require('../../markdown.js');
25
+ if (md?.escapeHtml) return md;
26
+ } catch (_) {}
27
+ }
28
+ return {
29
+ escapeHtml: value => String(value || '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]))
30
+ };
31
+ }
32
+
33
+ function createLiveCard(args, ui) {
34
+ if (ui?.createCardWrapper) return ui.createCardWrapper();
35
+ const doc = ui?.document || (typeof document !== 'undefined' ? document : null);
36
+ if (!doc) return null;
37
+ const cardDiv = doc.createElement('div');
38
+ cardDiv.className = 'tool-card-wrapper';
39
+ const t = ui?.t || ((key) => key);
40
+ const md = getMarkdown(ui);
41
+ const safeRef = md.escapeHtml(args?.imageRef || '');
42
+ cardDiv.innerHTML = `<div class="rag-image-card"><div class="rag-card-header"><span>${t('tool_rag_image_title') || 'Imagen RAG'}</span>: <code>${safeRef}</code></div></div>`;
43
+ return cardDiv;
44
+ }
45
+
46
+ function updateLiveCard(cardDiv, args, result, _elapsedMs, ui) {
47
+ if (!cardDiv) return;
48
+ const t = ui?.t || ((key) => key);
49
+ const md = getMarkdown(ui);
50
+ const safeRef = md.escapeHtml(args?.imageRef || '');
51
+ const content = result?.success ? (result.documentTitle || result.imageRef) : (result?.error || 'Error');
52
+ const safeContent = md.escapeHtml(content || '');
53
+ cardDiv.innerHTML = `<div class="rag-image-card"><div class="rag-card-header"><span>${t('tool_rag_image_title') || 'Imagen RAG'}</span>: <code>${safeRef}</code></div><div class="rag-card-body">${safeContent}</div></div>`;
54
+ }
55
+
56
+ function renderHistoricalCard(args, toolMessage, ui) {
57
+ const cardDiv = createLiveCard(args, ui);
58
+ if (!cardDiv) return null;
59
+ let result = {};
60
+ if (toolMessage?.content) {
61
+ try { result = JSON.parse(toolMessage.content); } catch (_) { result = { content: toolMessage.content }; }
62
+ }
63
+ updateLiveCard(cardDiv, args, result, 0, ui);
64
+ return cardDiv;
65
+ }
66
+
67
+ function createTool(Tool) {
68
+ if (typeof Tool !== 'function') throw new Error('La clase Tool es necesaria para crear read_knowledge_image.');
69
+ return new Tool({
70
+ id: definition.name,
71
+ definition,
72
+ aliases: [],
73
+ category: 'rag',
74
+ metadata: { icon: 'image', label: definition.name },
75
+ settings: { showInSettings: false },
76
+ isAvailable: config => Boolean(config.activeRagBranchId || (config.activeRagBranchIds && config.activeRagBranchIds.length > 0)),
77
+ execute: async (args, context = {}) => {
78
+ const service = getRagService(context);
79
+ return service?.readKnowledgeImage ? service.readKnowledgeImage(getBranchIds(context), args) : { success: false, error: 'Servicio de RAG no disponible.' };
80
+ },
81
+ result: {
82
+ toModel: (_args, result) => result?.success ? `Image retrieved: ${result.imageRef}${result.documentTitle ? ` (${result.documentTitle}${result.page ? `, page ${result.page}` : ''})` : ''}. Inspect it visually to answer.` : JSON.stringify(result || {}),
83
+ toMarkdown: (args, result) => result?.success ? `> **read_knowledge_image** (${result.imageRef})\n\n` : `> **read_knowledge_image** (${args?.imageRef || ''}) · ${result?.error || 'Error'}\n\n`
84
+ },
85
+ displayMode: 'collapsed',
86
+ view: { id: definition.name, displayMode: 'collapsed', createLiveCard, updateLiveCard, renderHistoricalCard }
87
+ });
88
+ }
89
+ const toolModule = { id: definition.name, definition, displayMode: 'collapsed', createTool, getRagService, view: { id: definition.name, displayMode: 'collapsed', createLiveCard, updateLiveCard, renderHistoricalCard } };
90
+ let manifestApi = null;
91
+ if (typeof window !== 'undefined' && window.ChatToolManifest) manifestApi = window.ChatToolManifest;
92
+ else if (typeof require !== 'undefined') { try { manifestApi = require('../tool-manifest.js'); } catch (_) {} }
93
+ if (manifestApi?.builtin && !manifestApi.builtin.has(toolModule.id)) manifestApi.builtin.register(toolModule);
94
+ return toolModule;
95
+ });
@@ -0,0 +1,90 @@
1
+ /** Tool autocontenida: render_chart. */
2
+ (function (root, factory) {
3
+ if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = factory();
4
+ else root.ChatBuiltinRenderChartTool = factory();
5
+ })(typeof self !== 'undefined' ? self : this, function () {
6
+ 'use strict';
7
+
8
+ const definition = {
9
+ name: 'render_chart',
10
+ description: 'Generates and displays an interactive chart (bar, line, donut, or pie) from numerical data or tables.',
11
+ parameters: {
12
+ type: 'object',
13
+ properties: {
14
+ type: { type: 'string', enum: ['bar', 'line', 'pie', 'doughnut'], description: 'Chart type.' },
15
+ title: { type: 'string', description: 'Descriptive chart title.' },
16
+ description: { type: 'string', description: 'Brief explanation of the data.' },
17
+ labels: { type: 'array', items: { type: 'string' }, description: 'X-axis labels or categories.' },
18
+ datasets: { type: 'array', items: { type: 'object', properties: { label: { type: 'string' }, data: { type: 'array', items: { type: 'number' } }, color: { type: 'string' } }, required: ['label', 'data'] }, description: 'Numerical data series.' }
19
+ },
20
+ required: ['type', 'title', 'labels', 'datasets']
21
+ }
22
+ };
23
+
24
+ function createCardWrapper(ui) {
25
+ if (ui?.createCardWrapper) return ui.createCardWrapper();
26
+ const doc = ui?.document || (typeof document !== 'undefined' ? document : null);
27
+ if (!doc) return null;
28
+ const cardDiv = doc.createElement('div');
29
+ cardDiv.className = 'tool-card-wrapper';
30
+ return cardDiv;
31
+ }
32
+
33
+ const safeEscapeHtml = (value) => String(value || '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
34
+
35
+ function renderChart(args, ui) {
36
+ const Charts = ui?.charts || null;
37
+ if (Charts?.renderChartCard) return Charts.renderChartCard(args);
38
+ const escapeHtml = ui?.markdown?.escapeHtml || (typeof window !== 'undefined' && window.ChatMarkdown?.escapeHtml) || (typeof window !== 'undefined' && window.ChatUtils?.escapeHtml) || safeEscapeHtml;
39
+ const chartIconSvg = '<svg class="ui-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="20" x2="12" y2="10"></line><line x1="18" y1="20" x2="18" y2="4"></line><line x1="6" y1="20" x2="6" y2="16"></line></svg>';
40
+ return `<div class="chat-chart-card">${chartIconSvg} ${escapeHtml(args.title || 'Gráfico')}</div>`;
41
+ }
42
+
43
+ function createLiveCard(args, ui) {
44
+ const cardDiv = createCardWrapper(ui);
45
+ if (cardDiv) cardDiv.innerHTML = renderChart(args, ui);
46
+ return cardDiv;
47
+ }
48
+
49
+ function updateLiveCard(cardDiv, args, _result, _elapsedMs, ui) {
50
+ if (cardDiv) cardDiv.innerHTML = renderChart(args, ui);
51
+ }
52
+
53
+ function renderHistoricalCard(args, _toolMessage, ui) {
54
+ const cardDiv = createCardWrapper(ui);
55
+ if (cardDiv) cardDiv.innerHTML = renderChart(args, ui);
56
+ return cardDiv;
57
+ }
58
+
59
+ function createTool(Tool) {
60
+ if (typeof Tool !== 'function') throw new Error('La clase Tool es necesaria para crear render_chart.');
61
+ return new Tool({
62
+ id: definition.name,
63
+ definition,
64
+ aliases: ['renderchart', 'draw_chart', 'create_chart', 'plot_chart', 'generate_chart', 'show_chart', 'chart', 'grafico'],
65
+ category: 'charts',
66
+ metadata: { icon: 'bar-chart', label: definition.name },
67
+ settings: { titleKey: 'agent_chart_title', titleFallback: 'Visualización de Datos y Gráficos Nativos (SVG)', descKey: 'agent_chart_desc', descFallback: 'Permite al modelo invocar render_chart para generar y mostrar gráficos interactivos de barras, líneas o sectores sin librerías externas.', icon: 'bar-chart', defaultEnabled: true, showInSettings: true },
68
+ promptGuide: () => '- `render_chart(type="...", title="...", labels=[...], datasets=[...])`: Generates and displays native interactive SVG charts (bar, line, pie, doughnut).',
69
+ execute: async (args, context = {}) => {
70
+ const Charts = context.services?.charts;
71
+ if (!Charts || (!Charts.renderChartCard && !Charts.renderBarChart)) return { success: false, error: 'Módulo Charts no disponible.' };
72
+ const svgHtml = Charts.renderChartCard ? Charts.renderChartCard(args) : Charts.renderBarChart(args.labels, args.datasets);
73
+ return { success: true, svg: svgHtml, chartData: args, title: args.title || 'Gráfico' };
74
+ },
75
+ result: {
76
+ toModel: (args, _result, outcome) => JSON.stringify({ success: outcome?.ok !== false, type: args.type || 'bar', title: args.title || 'Gráfico' }),
77
+ toMarkdown: (args) => `> **render_chart** (${args.type || 'bar'})\n> Título: "${args.title || 'Gráfico'}"\n\n`
78
+ },
79
+ displayMode: 'expanded',
80
+ view: { id: definition.name, displayMode: 'expanded', createLiveCard, updateLiveCard, renderHistoricalCard }
81
+ });
82
+ }
83
+
84
+ const toolModule = { id: definition.name, definition, displayMode: 'expanded', createTool, view: { id: definition.name, displayMode: 'expanded', createLiveCard, updateLiveCard, renderHistoricalCard } };
85
+ let manifestApi = null;
86
+ if (typeof window !== 'undefined' && window.ChatToolManifest) manifestApi = window.ChatToolManifest;
87
+ else if (typeof require !== 'undefined') { try { manifestApi = require('../tool-manifest.js'); } catch (e) {} }
88
+ if (manifestApi?.builtin && !manifestApi.builtin.has(toolModule.id)) manifestApi.builtin.register(toolModule);
89
+ return toolModule;
90
+ });
@@ -0,0 +1,124 @@
1
+ /** Tool autocontenida: search_knowledge_base. */
2
+ (function (root, factory) {
3
+ if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = factory();
4
+ else root.ChatBuiltinSearchKnowledgeBaseTool = factory();
5
+ })(typeof self !== 'undefined' ? self : this, function () {
6
+ 'use strict';
7
+
8
+ const definition = {
9
+ name: 'search_knowledge_base',
10
+ description: 'Searches relevant knowledge-base chunks. Use scope="document" with documentHint for one exact source, scope="corpus" for comparisons or multiple sources, and scope="auto" only when the target scope is unclear. For multi-document retrieval, make one corpus search instead of repeating the same query per document.',
11
+ parameters: {
12
+ type: 'object',
13
+ properties: {
14
+ query: { type: 'string', description: 'Term, topic, metric, or keywords to search in the document or knowledge base (direct terms, no quotes).' },
15
+ scope: {
16
+ type: 'string',
17
+ enum: ['auto', 'document', 'corpus'],
18
+ description: 'Search scope: "document" for a specific identifiable source, "corpus" for multiple sources, "auto" when unclear. Defaults to "auto".'
19
+ },
20
+ documentHint: {
21
+ type: 'string',
22
+ description: 'Exact name, filename, or filter for the source mentioned by the user (e.g. "AMD_2015_10K.pdf", "WALMART_2015_10K.pdf").'
23
+ },
24
+ limit: { type: 'integer', description: 'Optional number of chunks to return (default 10).' },
25
+ maxPerDocument: { type: 'integer', description: 'Optional maximum number of chunks per document in corpus search (defaults dynamically to 2-4 depending on document candidates).' }
26
+ },
27
+ required: ['query']
28
+ }
29
+ };
30
+
31
+ function getBranchIds(context = {}) {
32
+ return context.activeRagBranchIds || context.activeRagBranchId || context.branchId || context.config?.activeRagBranchIds || context.config?.activeRagBranchId || '';
33
+ }
34
+ const getBranchId = getBranchIds;
35
+
36
+ function getRagService(context = {}) {
37
+ if (context.services?.ragService) return context.services.ragService;
38
+ if (typeof window !== 'undefined' && window.ChatRagService) return window.ChatRagService;
39
+ if (typeof require !== 'undefined') {
40
+ try { return require('../../rag-service.js'); } catch (e) {}
41
+ }
42
+ return null;
43
+ }
44
+
45
+ const DB_ICON_SVG = '<svg class="ui-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><ellipse cx="12" cy="5" rx="9" ry="3"></ellipse><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"></path><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"></path></svg>';
46
+
47
+ function createCardWrapper(ui) {
48
+ if (ui?.createCardWrapper) return ui.createCardWrapper();
49
+ const doc = ui?.document || (typeof document !== 'undefined' ? document : null);
50
+ if (!doc) return null;
51
+ const card = doc.createElement('div');
52
+ card.className = 'tool-card-wrapper';
53
+ return card;
54
+ }
55
+
56
+ const safeEscapeHtml = (value) => String(value || '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
57
+
58
+ function createLiveCard(args, ui) {
59
+ const card = createCardWrapper(ui);
60
+ if (!card) return null;
61
+ const Markdown = ui?.markdown || (typeof window !== 'undefined' && window.ChatMarkdown) || (typeof window !== 'undefined' && window.ChatUtils) || { escapeHtml: safeEscapeHtml };
62
+ const t = ui?.t || ((key, params) => key);
63
+ const spinner = ui?.SPINNER_SVG || '';
64
+ const chevron = ui?.CHEVRON_SVG || '';
65
+ const query = args?.query || args?.q || args?.search || '';
66
+ const title = t('tool_rag_search_title', { query: Markdown.escapeHtml(query) }) || `Conocimiento local: "${Markdown.escapeHtml(query)}"`;
67
+ const loading = t('tool_rag_search_loading') || 'Buscando con Orama...';
68
+ const building = t('tool_rag_search_building') || 'Construyendo el índice local...';
69
+ card.innerHTML = `<div class="tool-execution-card rag-execution-card"><div class="tool-card-header"><div class="tool-card-title"><span>${DB_ICON_SVG}</span><span>${title}</span></div><div class="tool-card-header-actions"><span class="tool-card-badge status-loading">${spinner} <span>${loading}</span></span><button type="button" class="btn-tool-collapse" title="${t('tool_btn_collapse') || 'Minimizar'}">${chevron}</button></div></div><div class="tool-card-collapsible-body"><div class="tool-card-result"><div class="tool-loading-placeholder">${spinner} <span>${building}</span></div></div></div></div>`;
70
+ return card;
71
+ }
72
+
73
+ function updateLiveCard(card, _args, result = {}, elapsedMs = 0, ui) {
74
+ if (!card) return;
75
+ const t = ui?.t || ((key, params) => key);
76
+ const Markdown = ui?.markdown || (typeof window !== 'undefined' && window.ChatMarkdown) || (typeof window !== 'undefined' && window.ChatUtils) || { escapeHtml: safeEscapeHtml };
77
+ const checkSvg = ui?.CHECK_SVG || '';
78
+ const errorSvg = ui?.ERROR_SVG || '';
79
+ const success = result?.success !== false && !result?.error;
80
+ const count = result?.matchesCount ?? 0;
81
+ const text = result?.text || (typeof result === 'object' ? JSON.stringify(result, null, 2) : String(result || ''));
82
+ const badge = card.querySelector('.tool-card-badge');
83
+ const matchesLabel = t('tool_rag_search_matches', { count, plural: count === 1 ? '' : 's', scope: result?.appliedScope || 'auto' }) || `${count} coincidencia${count === 1 ? '' : 's'} · ${result?.appliedScope || 'auto'}`;
84
+ const errorLabel = result?.error || t('tool_err_query') || 'Error al consultar';
85
+ if (badge) {
86
+ badge.className = `tool-card-badge ${success ? 'status-success' : 'status-error'}`;
87
+ badge.innerHTML = success ? `${checkSvg} <span>${matchesLabel} (${elapsedMs || 0}ms)</span>` : `${errorSvg} <span>${Markdown.escapeHtml(errorLabel)}</span>`;
88
+ }
89
+ const body = card.querySelector('.tool-card-result');
90
+ if (body) body.innerHTML = `<pre class="tool-result-pre"><code>${Markdown.escapeHtml(text.slice(0, 3000))}${text.length > 3000 ? '\n... (texto completo truncado en tarjeta)' : ''}</code></pre>`;
91
+ }
92
+ function renderHistoricalCard(args, message, ui) { const card = createLiveCard(args, ui); if (!card) return null; let result = {}; if (message?.content) { try { result = JSON.parse(message.content); } catch (e) { result = { text: message.content }; } } updateLiveCard(card, args, result, 0, ui); return card; }
93
+
94
+ function createTool(Tool) {
95
+ if (typeof Tool !== 'function') throw new Error('La clase Tool es necesaria para crear search_knowledge_base.');
96
+ return new Tool({
97
+ id: definition.name,
98
+ definition,
99
+ aliases: ['search_kb', 'searchknowledgebase', 'search_documents', 'search_knowledge', 'buscar_en_documentos'],
100
+ category: 'rag',
101
+ metadata: { icon: 'search', label: definition.name },
102
+ settings: { showInSettings: false },
103
+ isAvailable: (config = {}) => Boolean(config.activeRagBranchId || (config.activeRagBranchIds && config.activeRagBranchIds.length > 0)),
104
+ execute: async (args, context = {}) => {
105
+ const RagService = getRagService(context);
106
+ if (!RagService?.searchKnowledgeBase) return { success: false, error: 'Servicio de RAG no disponible.' };
107
+ return RagService.searchKnowledgeBase(getBranchIds(context), args);
108
+ },
109
+ result: {
110
+ toModel: (_args, result) => result?.text || JSON.stringify(result || {}),
111
+ toMarkdown: (args, result) => `> **search_knowledge_base** ("${args.query || ''}") [${result?.matchesCount || 0} coincidencias]\n\n`
112
+ },
113
+ displayMode: 'collapsed',
114
+ view: { id: definition.name, displayMode: 'collapsed', createLiveCard, updateLiveCard, renderHistoricalCard }
115
+ });
116
+ }
117
+
118
+ const toolModule = { id: definition.name, definition, displayMode: 'collapsed', createTool, getBranchId, getRagService, view: { id: definition.name, displayMode: 'collapsed', createLiveCard, updateLiveCard, renderHistoricalCard } };
119
+ let manifestApi = null;
120
+ if (typeof window !== 'undefined' && window.ChatToolManifest) manifestApi = window.ChatToolManifest;
121
+ else if (typeof require !== 'undefined') { try { manifestApi = require('../tool-manifest.js'); } catch (e) {} }
122
+ if (manifestApi?.builtin && !manifestApi.builtin.has(toolModule.id)) manifestApi.builtin.register(toolModule);
123
+ return toolModule;
124
+ });