@apia/ai 5.2.2 → 6.0.2
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.
- package/dist/assistant/index.d.d.ts +49 -0
- package/dist/assistant/index.d.d.ts.map +1 -0
- package/dist/assistant/index.js +154 -0
- package/dist/assistant/index.js.map +1 -0
- package/dist/assistant/runtime/conversationActivity.js +11 -0
- package/dist/assistant/runtime/conversationActivity.js.map +1 -0
- package/dist/assistant/runtime/conversationAnnotations.js +28 -0
- package/dist/assistant/runtime/conversationAnnotations.js.map +1 -0
- package/dist/assistant/runtime/conversationAttachmentPreview.js +33 -0
- package/dist/assistant/runtime/conversationAttachmentPreview.js.map +1 -0
- package/dist/assistant/runtime/conversationAttachments.js +24 -0
- package/dist/assistant/runtime/conversationAttachments.js.map +1 -0
- package/dist/assistant/runtime/conversationClient.d.d.ts +26 -0
- package/dist/assistant/runtime/conversationClient.d.d.ts.map +1 -0
- package/dist/assistant/runtime/conversationClient.js +599 -0
- package/dist/assistant/runtime/conversationClient.js.map +1 -0
- package/dist/assistant/runtime/conversationPlan.js +12 -0
- package/dist/assistant/runtime/conversationPlan.js.map +1 -0
- package/dist/assistant/runtime/conversationProjection.d.d.ts +8 -0
- package/dist/assistant/runtime/conversationProjection.d.d.ts.map +1 -0
- package/dist/assistant/runtime/conversationProjection.js +184 -0
- package/dist/assistant/runtime/conversationProjection.js.map +1 -0
- package/dist/assistant/runtime/coordinatorProxy.js +302 -0
- package/dist/assistant/runtime/coordinatorProxy.js.map +1 -0
- package/dist/chat/ChatController/ChatController.d.ts +13 -9
- package/dist/chat/ChatController/ChatController.js +103 -94
- package/dist/chat/ChatController/ChatController.js.map +1 -1
- package/dist/chat/ChatController/annotationStyles.js +1 -78
- package/dist/chat/ChatController/annotationStyles.js.map +1 -1
- package/dist/chat/ChatController/annotationTargets.d.ts +3 -1
- package/dist/chat/ChatController/annotationTargets.js +7 -1
- package/dist/chat/ChatController/annotationTargets.js.map +1 -1
- package/dist/chat/ChatController/components/AnnotationDraft.js +79 -0
- package/dist/chat/ChatController/components/AnnotationDraft.js.map +1 -0
- package/dist/chat/ChatController/components/AssistantMessageActions.d.ts +4 -0
- package/dist/chat/ChatController/components/AssistantMessageActions.d.ts.map +1 -0
- package/dist/chat/ChatController/components/AssistantMessageActions.js +102 -0
- package/dist/chat/ChatController/components/AssistantMessageActions.js.map +1 -0
- package/dist/chat/ChatController/components/AssistantTurnMessage.d.ts +24 -1
- package/dist/chat/ChatController/components/AssistantTurnMessage.js +155 -26
- package/dist/chat/ChatController/components/AssistantTurnMessage.js.map +1 -1
- package/dist/chat/ChatController/components/ChatMessage.d.ts +8 -5
- package/dist/chat/ChatController/components/ChatMessage.js +27 -22
- package/dist/chat/ChatController/components/ChatMessage.js.map +1 -1
- package/dist/chat/ChatController/components/History.d.ts +5 -1
- package/dist/chat/ChatController/components/History.js +19 -8
- package/dist/chat/ChatController/components/History.js.map +1 -1
- package/dist/chat/ChatController/components/Message.d.ts +7 -2
- package/dist/chat/ChatController/components/Message.js +22 -8
- package/dist/chat/ChatController/components/Message.js.map +1 -1
- package/dist/chat/ChatController/components/MessageBlocks.d.ts +2 -5
- package/dist/chat/ChatController/components/MessageBlocks.js +6 -48
- package/dist/chat/ChatController/components/MessageBlocks.js.map +1 -1
- package/dist/chat/ChatController/components/MessageBody.js +10 -3
- package/dist/chat/ChatController/components/MessageBody.js.map +1 -1
- package/dist/chat/ChatController/components/PendingMessagesPanel.js +2 -3
- package/dist/chat/ChatController/components/PendingMessagesPanel.js.map +1 -1
- package/dist/chat/ChatController/components/SentAnnotations.js +6 -3
- package/dist/chat/ChatController/components/SentAnnotations.js.map +1 -1
- package/dist/chat/ChatController/components/TextArea.d.ts +3 -5
- package/dist/chat/ChatController/components/TextArea.js +5 -67
- package/dist/chat/ChatController/components/TextArea.js.map +1 -1
- package/dist/chat/ChatController/types.d.ts +28 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/stream/ResponseStream.d.ts +15 -10
- package/dist/stream/ResponseStream.js +58 -61
- package/dist/stream/ResponseStream.js.map +1 -1
- package/dist/stream/reasoningSummary.js +19 -0
- package/dist/stream/reasoningSummary.js.map +1 -0
- package/package.json +8 -8
- package/dist/assistant/AssistantController.d.ts +0 -53
- package/dist/assistant/AssistantController.d.ts.map +0 -1
- package/dist/assistant/AssistantController.js +0 -131
- package/dist/assistant/AssistantController.js.map +0 -1
- package/dist/assistant/HandoffCoordinator.d.ts +0 -18
- package/dist/assistant/HandoffCoordinator.d.ts.map +0 -1
- package/dist/assistant/HandoffCoordinator.js +0 -35
- package/dist/assistant/HandoffCoordinator.js.map +0 -1
- package/dist/assistant/PanelAssistantTransport.d.ts +0 -28
- package/dist/assistant/PanelAssistantTransport.d.ts.map +0 -1
- package/dist/assistant/PanelAssistantTransport.js +0 -48
- package/dist/assistant/PanelAssistantTransport.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TabAssistantsClient } from '@apia/components';
|
|
2
|
+
import { ConversationClient } from './runtime/conversationClient.d.js';
|
|
3
|
+
|
|
4
|
+
declare class AssistantApiError extends Error { code: string; status: number; constructor(message: string, code?: string, status?: number); }
|
|
5
|
+
interface AssistantTransport {
|
|
6
|
+
request(body: Record<string, unknown>, options?: { signal?: AbortSignal }): Promise<any>;
|
|
7
|
+
download?(reference: string): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
interface AssistantHost { tabs: TabAssistantsClient; tabOrder?: () => string[] | undefined; closeTaskTab?: (tabId: string) => Promise<boolean>; }
|
|
10
|
+
interface AssistantOptions {
|
|
11
|
+
contentId: string | number;
|
|
12
|
+
transport: AssistantTransport;
|
|
13
|
+
host?: () => AssistantHost | undefined | Promise<AssistantHost | undefined>;
|
|
14
|
+
hostTimeoutMs?: number;
|
|
15
|
+
storage?: Storage;
|
|
16
|
+
key?: string;
|
|
17
|
+
replyMode?: 'automatic';
|
|
18
|
+
onState?: (state: any) => void;
|
|
19
|
+
pause?: () => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
interface AssistantSession {
|
|
22
|
+
readonly state: any;
|
|
23
|
+
subscribe(observer: (state: any) => void): () => void;
|
|
24
|
+
send: ConversationClient['enqueue'];
|
|
25
|
+
waitUntilIdle: ConversationClient['waitUntilIdle'];
|
|
26
|
+
clearHistory: ConversationClient['clearHistory'];
|
|
27
|
+
resume: ConversationClient['resume'];
|
|
28
|
+
requestActions: ConversationClient['requestActions'];
|
|
29
|
+
confirm: ConversationClient['confirm'];
|
|
30
|
+
act: ConversationClient['act'];
|
|
31
|
+
cancel: ConversationClient['cancel'];
|
|
32
|
+
cancelTurn: ConversationClient['cancelTurn'];
|
|
33
|
+
withdrawAdmission: ConversationClient['withdrawAdmission'];
|
|
34
|
+
deliveryAction: ConversationClient['deliveryAction'];
|
|
35
|
+
openTaskLink: ConversationClient['openTaskLink'];
|
|
36
|
+
resolveReferral(reference: string): Promise<any>;
|
|
37
|
+
diagnostics(args: { enabled?: boolean; executionId?: string }): Promise<any>;
|
|
38
|
+
download(reference: string): Promise<unknown>;
|
|
39
|
+
dispose(): void;
|
|
40
|
+
}
|
|
41
|
+
declare function createAssistant(options: AssistantOptions): Promise<AssistantSession>;
|
|
42
|
+
declare function assistantTaskLink(href: string, pageUrl: string): { conversationId: string; reference: string } | undefined;
|
|
43
|
+
declare function createAssistantMemoryStorage(): Storage;
|
|
44
|
+
declare function discoverAssistantHost(view?: Window): AssistantHost | undefined;
|
|
45
|
+
declare function createHttpAssistantTransport(options: { endpoint: string; headers?: () => Record<string,string> | Promise<Record<string,string>>; fetch?: typeof fetch; credentials?: RequestCredentials }): AssistantTransport;
|
|
46
|
+
declare function createPanelAssistantTransport(options: { dispatch: (params: { action: string; payload: string }) => Promise<any>; action?: string; unwrap?: (response: any) => unknown }): AssistantTransport;
|
|
47
|
+
|
|
48
|
+
export { AssistantApiError, type AssistantHost, type AssistantOptions, type AssistantSession, type AssistantTransport, assistantTaskLink, createAssistant, createAssistantMemoryStorage, createHttpAssistantTransport, createPanelAssistantTransport, discoverAssistantHost };
|
|
49
|
+
//# sourceMappingURL=index.d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ConversationClient } from './runtime/conversationClient.js';
|
|
2
|
+
|
|
3
|
+
class AssistantApiError extends Error {
|
|
4
|
+
constructor(message, code = 'ASSISTANT_FAILURE', status = 0) {
|
|
5
|
+
super(message); this.name = 'AssistantApiError'; this.code = code; this.status = status;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function errorFrom(value, status = 0) {
|
|
10
|
+
return new AssistantApiError(value?.message ?? 'No se pudo completar la solicitud del asistente.', value?.code, status);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The entry point supplies its transport. Protocol processing stays in this library. */
|
|
14
|
+
function createHttpAssistantTransport({ endpoint, headers = () => ({}), fetch: request = globalThis.fetch, credentials = 'same-origin' }) {
|
|
15
|
+
if (!endpoint || typeof request !== 'function') throw new AssistantApiError('Falta configurar el transporte.', 'TRANSPORT_UNAVAILABLE');
|
|
16
|
+
return {
|
|
17
|
+
async request(body, { signal } = {}) {
|
|
18
|
+
let response;
|
|
19
|
+
try {
|
|
20
|
+
response = await request(endpoint, { method: 'POST', credentials, signal,
|
|
21
|
+
headers: { 'Content-Type': 'application/json', ...await headers() }, body: JSON.stringify(body) });
|
|
22
|
+
} catch (cause) {
|
|
23
|
+
if (cause?.name === 'AbortError') throw cause;
|
|
24
|
+
throw new AssistantApiError('No se pudo contactar al asistente.', 'TRANSPORT_UNAVAILABLE');
|
|
25
|
+
}
|
|
26
|
+
let result;
|
|
27
|
+
try { result = await response.json(); }
|
|
28
|
+
catch { throw new AssistantApiError('La entrada del asistente devolvió una respuesta inválida.', 'INVALID_RESPONSE', response.status); }
|
|
29
|
+
if (!response.ok) throw errorFrom(result, response.status);
|
|
30
|
+
return result;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** onAction receives one JSON payload. unwrap adapts AjaxXml/dispatcher envelopes. */
|
|
36
|
+
function createPanelAssistantTransport({ dispatch, action = 'assistantProtocol', unwrap = response => response?.data?.assistantProtocol }) {
|
|
37
|
+
if (typeof dispatch !== 'function' || typeof unwrap !== 'function') throw new AssistantApiError('Falta configurar la entrada del panel.', 'TRANSPORT_UNAVAILABLE');
|
|
38
|
+
return {
|
|
39
|
+
async download(reference) {
|
|
40
|
+
const query = String(reference).split('#apia-assistant-file?')[1];
|
|
41
|
+
const params = new URLSearchParams(query);
|
|
42
|
+
if (!query || !params.get('conversationId') || !params.get('fileId')) throw new AssistantApiError('La referencia del archivo no es válida.', 'INVALID_DOWNLOAD');
|
|
43
|
+
const response = await dispatch({ action: 'assistantDownload', payload: JSON.stringify({ conversationId: params.get('conversationId'), fileId: params.get('fileId') }) });
|
|
44
|
+
let result = response?.data?.assistantDownload;
|
|
45
|
+
if (typeof result === 'string') { try { result = JSON.parse(result); } catch { throw new AssistantApiError('La descarga del panel no es válida.', 'INVALID_RESPONSE'); } }
|
|
46
|
+
if (response?.hasError || result?.error) throw errorFrom(result?.error ?? response?.error);
|
|
47
|
+
if (typeof result?.name !== 'string' || typeof result?.base64 !== 'string') throw new AssistantApiError('La descarga del panel está incompleta.', 'INVALID_RESPONSE');
|
|
48
|
+
return result;
|
|
49
|
+
},
|
|
50
|
+
async request(body) {
|
|
51
|
+
const response = await dispatch({ action, payload: JSON.stringify(body) });
|
|
52
|
+
if (response?.hasError) throw errorFrom(response.error ?? response);
|
|
53
|
+
let result = await unwrap(response);
|
|
54
|
+
if (typeof result === 'string') {
|
|
55
|
+
try { result = JSON.parse(result); }
|
|
56
|
+
catch { throw new AssistantApiError('La entrada del panel devolvió JSON inválido.', 'INVALID_RESPONSE'); }
|
|
57
|
+
}
|
|
58
|
+
if (!result || typeof result !== 'object' || Array.isArray(result)) throw new AssistantApiError('La entrada del panel no devolvió el protocolo del asistente.', 'INVALID_RESPONSE');
|
|
59
|
+
if (result.error) throw errorFrom(result.error, result.error.status);
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Host discovery is internal; callers never need to locate main or a tabsController. */
|
|
66
|
+
function discoverAssistantHost(view = globalThis.window) {
|
|
67
|
+
try {
|
|
68
|
+
const host = view?.top ?? view;
|
|
69
|
+
const tabs = host?.apiaTabAssistants;
|
|
70
|
+
if (!tabs) return undefined;
|
|
71
|
+
const getTabHandler = () => host.tabsController?.getHandler?.() ?? host.tabsController?.handler;
|
|
72
|
+
return { tabs, tabOrder: () => {
|
|
73
|
+
const rows = getTabHandler()?.tabsList;
|
|
74
|
+
if (!Array.isArray(rows)) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return rows.filter(tab => !tab.fixed && !tab.state?.isFixed).map(tab => String(tab.id));
|
|
78
|
+
}, closeTaskTab: async tabId => {
|
|
79
|
+
const handler = getTabHandler();
|
|
80
|
+
const tab = handler?.getTab?.(tabId);
|
|
81
|
+
if (!tab?.state?.isClosable || tab.state.isFixed) return false;
|
|
82
|
+
return await tab.close(true) === true && !handler.getTab(tabId);
|
|
83
|
+
} };
|
|
84
|
+
} catch { return undefined; }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function createAssistantMemoryStorage() {
|
|
88
|
+
const values = new Map();
|
|
89
|
+
return { get length() { return values.size; }, key: index => [...values.keys()][index] ?? null,
|
|
90
|
+
getItem: key => values.get(String(key)) ?? null,
|
|
91
|
+
setItem: (key, value) => { values.set(String(key), String(value)); },
|
|
92
|
+
removeItem: key => { values.delete(String(key)); }, clear: () => values.clear() };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function assistantTaskLink(href, pageUrl) {
|
|
96
|
+
if (!href) return;
|
|
97
|
+
try {
|
|
98
|
+
const page = new URL(pageUrl);
|
|
99
|
+
const link = new URL(href, page);
|
|
100
|
+
if (link.origin !== page.origin || link.pathname !== page.pathname) return;
|
|
101
|
+
const match = /^#apia-task\/([a-f0-9-]{36})\/([a-f0-9-]{36})$/i.exec(link.hash);
|
|
102
|
+
if (match) return { conversationId: match[1].toLowerCase(), reference: match[2].toLowerCase() };
|
|
103
|
+
} catch { return; }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function createAssistant(options) {
|
|
107
|
+
if (!options || typeof options.transport?.request !== 'function' || !String(options.contentId ?? '').trim())
|
|
108
|
+
throw new AssistantApiError('Indicá el contenido y el transporte del asistente.', 'INVALID_CONFIGURATION');
|
|
109
|
+
const hostProvider = options.host ?? (() => discoverAssistantHost());
|
|
110
|
+
const timeout = options.hostTimeoutMs ?? 3000;
|
|
111
|
+
const deadline = Date.now() + timeout;
|
|
112
|
+
let host;
|
|
113
|
+
do {
|
|
114
|
+
host = await hostProvider();
|
|
115
|
+
if (host?.tabs) break;
|
|
116
|
+
if (Date.now() >= deadline) throw new AssistantApiError('El contenedor de Apia no está disponible.', 'HOST_UNAVAILABLE');
|
|
117
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(25, Math.max(0, deadline - Date.now()))));
|
|
118
|
+
} while (true);
|
|
119
|
+
const observers = new Set(options.onState ? [options.onState] : []);
|
|
120
|
+
const transport = options.transport;
|
|
121
|
+
const client = new ConversationClient({ api: body => transport.request(body), tabs: host.tabs,
|
|
122
|
+
tabOrder: host.tabOrder, closeTaskTab: host.closeTaskTab, storage: options.storage ?? createAssistantMemoryStorage(),
|
|
123
|
+
key: options.key ?? `assistant:${host.tabs.newRequestId()}`, contentId: String(options.contentId),
|
|
124
|
+
replyMode: options.replyMode, pause: options.pause,
|
|
125
|
+
onChange: state => { for (const observer of observers) observer(state); } });
|
|
126
|
+
try { await client.initialize(); }
|
|
127
|
+
catch (error) { client.dispose(); throw error; }
|
|
128
|
+
return Object.freeze({
|
|
129
|
+
get state() { return client.state; },
|
|
130
|
+
subscribe(observer) { observers.add(observer); return () => observers.delete(observer); },
|
|
131
|
+
send: (message, attachments, annotations) => client.enqueue(message, attachments, annotations),
|
|
132
|
+
waitUntilIdle: () => client.waitUntilIdle(),
|
|
133
|
+
clearHistory: () => client.clearHistory(),
|
|
134
|
+
resume: recover => client.resume(recover),
|
|
135
|
+
requestActions: () => client.requestActions(),
|
|
136
|
+
confirm: (requestId, confirmationId, ids) => client.confirm(requestId, confirmationId, ids),
|
|
137
|
+
act: (action, requestId) => client.act(action, requestId),
|
|
138
|
+
cancel: () => client.cancel(),
|
|
139
|
+
cancelTurn: turnId => client.cancelTurn(turnId),
|
|
140
|
+
withdrawAdmission: id => client.withdrawAdmission(id),
|
|
141
|
+
deliveryAction: (action, attention) => client.deliveryAction(action, attention),
|
|
142
|
+
openTaskLink: (conversationId, reference) => client.openTaskLink(conversationId, reference),
|
|
143
|
+
resolveReferral: reference => transport.request({ action: 'resolveReferral', conversationId: client.state.conversationId, reference }),
|
|
144
|
+
diagnostics: args => transport.request({ ...args, action: 'codeDiagnostics', conversationId: client.state.conversationId }),
|
|
145
|
+
async download(reference) {
|
|
146
|
+
if (typeof transport.download !== 'function') throw new AssistantApiError('Esta entrada no tiene descargas registradas.', 'DOWNLOAD_UNAVAILABLE');
|
|
147
|
+
return transport.download(reference);
|
|
148
|
+
},
|
|
149
|
+
dispose() { client.dispose(); observers.clear(); },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { AssistantApiError, assistantTaskLink, createAssistant, createAssistantMemoryStorage, createHttpAssistantTransport, createPanelAssistantTransport, discoverAssistantHost };
|
|
154
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/assistant/index.mjs"],"sourcesContent":["import { ConversationClient } from './runtime/conversationClient.mjs';\nexport { ConversationProjection as AssistantConversationProjection } from './runtime/conversationProjection.mjs';\n\nexport class AssistantApiError extends Error {\n constructor(message, code = 'ASSISTANT_FAILURE', status = 0) {\n super(message); this.name = 'AssistantApiError'; this.code = code; this.status = status;\n }\n}\n\nfunction errorFrom(value, status = 0) {\n return new AssistantApiError(value?.message ?? 'No se pudo completar la solicitud del asistente.', value?.code, status);\n}\n\n/** The entry point supplies its transport. Protocol processing stays in this library. */\nexport function createHttpAssistantTransport({ endpoint, headers = () => ({}), fetch: request = globalThis.fetch, credentials = 'same-origin' }) {\n if (!endpoint || typeof request !== 'function') throw new AssistantApiError('Falta configurar el transporte.', 'TRANSPORT_UNAVAILABLE');\n return {\n async request(body, { signal } = {}) {\n let response;\n try {\n response = await request(endpoint, { method: 'POST', credentials, signal,\n headers: { 'Content-Type': 'application/json', ...await headers() }, body: JSON.stringify(body) });\n } catch (cause) {\n if (cause?.name === 'AbortError') throw cause;\n throw new AssistantApiError('No se pudo contactar al asistente.', 'TRANSPORT_UNAVAILABLE');\n }\n let result;\n try { result = await response.json(); }\n catch { throw new AssistantApiError('La entrada del asistente devolvió una respuesta inválida.', 'INVALID_RESPONSE', response.status); }\n if (!response.ok) throw errorFrom(result, response.status);\n return result;\n },\n };\n}\n\n/** onAction receives one JSON payload. unwrap adapts AjaxXml/dispatcher envelopes. */\nexport function createPanelAssistantTransport({ dispatch, action = 'assistantProtocol', unwrap = response => response?.data?.assistantProtocol }) {\n if (typeof dispatch !== 'function' || typeof unwrap !== 'function') throw new AssistantApiError('Falta configurar la entrada del panel.', 'TRANSPORT_UNAVAILABLE');\n return {\n async download(reference) {\n const query = String(reference).split('#apia-assistant-file?')[1];\n const params = new URLSearchParams(query);\n if (!query || !params.get('conversationId') || !params.get('fileId')) throw new AssistantApiError('La referencia del archivo no es válida.', 'INVALID_DOWNLOAD');\n const response = await dispatch({ action: 'assistantDownload', payload: JSON.stringify({ conversationId: params.get('conversationId'), fileId: params.get('fileId') }) });\n let result = response?.data?.assistantDownload;\n if (typeof result === 'string') { try { result = JSON.parse(result); } catch { throw new AssistantApiError('La descarga del panel no es válida.', 'INVALID_RESPONSE'); } }\n if (response?.hasError || result?.error) throw errorFrom(result?.error ?? response?.error);\n if (typeof result?.name !== 'string' || typeof result?.base64 !== 'string') throw new AssistantApiError('La descarga del panel está incompleta.', 'INVALID_RESPONSE');\n return result;\n },\n async request(body) {\n const response = await dispatch({ action, payload: JSON.stringify(body) });\n if (response?.hasError) throw errorFrom(response.error ?? response);\n let result = await unwrap(response);\n if (typeof result === 'string') {\n try { result = JSON.parse(result); }\n catch { throw new AssistantApiError('La entrada del panel devolvió JSON inválido.', 'INVALID_RESPONSE'); }\n }\n if (!result || typeof result !== 'object' || Array.isArray(result)) throw new AssistantApiError('La entrada del panel no devolvió el protocolo del asistente.', 'INVALID_RESPONSE');\n if (result.error) throw errorFrom(result.error, result.error.status);\n return result;\n },\n };\n}\n\n/** Host discovery is internal; callers never need to locate main or a tabsController. */\nexport function discoverAssistantHost(view = globalThis.window) {\n try {\n const host = view?.top ?? view;\n const tabs = host?.apiaTabAssistants;\n if (!tabs) return undefined;\n const getTabHandler = () => host.tabsController?.getHandler?.() ?? host.tabsController?.handler;\n return { tabs, tabOrder: () => {\n const rows = getTabHandler()?.tabsList;\n if (!Array.isArray(rows)) {\n return undefined;\n }\n return rows.filter(tab => !tab.fixed && !tab.state?.isFixed).map(tab => String(tab.id));\n }, closeTaskTab: async tabId => {\n const handler = getTabHandler();\n const tab = handler?.getTab?.(tabId);\n if (!tab?.state?.isClosable || tab.state.isFixed) return false;\n return await tab.close(true) === true && !handler.getTab(tabId);\n } };\n } catch { return undefined; }\n}\n\nexport function createAssistantMemoryStorage() {\n const values = new Map();\n return { get length() { return values.size; }, key: index => [...values.keys()][index] ?? null,\n getItem: key => values.get(String(key)) ?? null,\n setItem: (key, value) => { values.set(String(key), String(value)); },\n removeItem: key => { values.delete(String(key)); }, clear: () => values.clear() };\n}\n\nexport function assistantTaskLink(href, pageUrl) {\n if (!href) return;\n try {\n const page = new URL(pageUrl);\n const link = new URL(href, page);\n if (link.origin !== page.origin || link.pathname !== page.pathname) return;\n const match = /^#apia-task\\/([a-f0-9-]{36})\\/([a-f0-9-]{36})$/i.exec(link.hash);\n if (match) return { conversationId: match[1].toLowerCase(), reference: match[2].toLowerCase() };\n } catch { return; }\n}\n\nexport async function createAssistant(options) {\n if (!options || typeof options.transport?.request !== 'function' || !String(options.contentId ?? '').trim())\n throw new AssistantApiError('Indicá el contenido y el transporte del asistente.', 'INVALID_CONFIGURATION');\n const hostProvider = options.host ?? (() => discoverAssistantHost());\n const timeout = options.hostTimeoutMs ?? 3000;\n const deadline = Date.now() + timeout;\n let host;\n do {\n host = await hostProvider();\n if (host?.tabs) break;\n if (Date.now() >= deadline) throw new AssistantApiError('El contenedor de Apia no está disponible.', 'HOST_UNAVAILABLE');\n await new Promise(resolve => setTimeout(resolve, Math.min(25, Math.max(0, deadline - Date.now()))));\n } while (true);\n const observers = new Set(options.onState ? [options.onState] : []);\n const transport = options.transport;\n const client = new ConversationClient({ api: body => transport.request(body), tabs: host.tabs,\n tabOrder: host.tabOrder, closeTaskTab: host.closeTaskTab, storage: options.storage ?? createAssistantMemoryStorage(),\n key: options.key ?? `assistant:${host.tabs.newRequestId()}`, contentId: String(options.contentId),\n replyMode: options.replyMode, pause: options.pause,\n onChange: state => { for (const observer of observers) observer(state); } });\n try { await client.initialize(); }\n catch (error) { client.dispose(); throw error; }\n return Object.freeze({\n get state() { return client.state; },\n subscribe(observer) { observers.add(observer); return () => observers.delete(observer); },\n send: (message, attachments, annotations) => client.enqueue(message, attachments, annotations),\n waitUntilIdle: () => client.waitUntilIdle(),\n clearHistory: () => client.clearHistory(),\n resume: recover => client.resume(recover),\n requestActions: () => client.requestActions(),\n confirm: (requestId, confirmationId, ids) => client.confirm(requestId, confirmationId, ids),\n act: (action, requestId) => client.act(action, requestId),\n cancel: () => client.cancel(),\n cancelTurn: turnId => client.cancelTurn(turnId),\n withdrawAdmission: id => client.withdrawAdmission(id),\n deliveryAction: (action, attention) => client.deliveryAction(action, attention),\n openTaskLink: (conversationId, reference) => client.openTaskLink(conversationId, reference),\n resolveReferral: reference => transport.request({ action: 'resolveReferral', conversationId: client.state.conversationId, reference }),\n diagnostics: args => transport.request({ ...args, action: 'codeDiagnostics', conversationId: client.state.conversationId }),\n async download(reference) {\n if (typeof transport.download !== 'function') throw new AssistantApiError('Esta entrada no tiene descargas registradas.', 'DOWNLOAD_UNAVAILABLE');\n return transport.download(reference);\n },\n dispose() { client.dispose(); observers.clear(); },\n });\n}\n"],"names":[],"mappings":";;AAGO,MAAM,iBAAiB,SAAS,KAAK,CAAC;AAC7C,EAAE,WAAW,CAAC,OAAO,EAAE,IAAI,GAAG,mBAAmB,EAAE,MAAM,GAAG,CAAC,EAAE;AAC/D,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM;AAC3F;AACA;;AAEA,SAAS,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE;AACtC,EAAE,OAAO,IAAI,iBAAiB,CAAC,KAAK,EAAE,OAAO,IAAI,kDAAkD,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC;AACzH;;AAEA;AACO,SAAS,4BAA4B,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,EAAE,EAAE;AACjJ,EAAE,IAAI,CAAC,QAAQ,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,MAAM,IAAI,iBAAiB,CAAC,iCAAiC,EAAE,uBAAuB,CAAC;AACzI,EAAE,OAAO;AACT,IAAI,MAAM,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;AACzC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it = 160) {
|
|
3
|
+
if (typeof response !== 'string') return undefined;
|
|
4
|
+
const lines = response.split(/\r?\n/).map(line => line.trim().replace(/^[-*]\s+/, '')).filter(Boolean);
|
|
5
|
+
const label = lines.at(-1)?.replace(/\s+/g, ' ');
|
|
6
|
+
if (!label) return undefined;
|
|
7
|
+
return label.length <= limit ? label : `${label.slice(0, limit - 1).trimEnd()}…`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { conversationActivitySummary };
|
|
11
|
+
//# sourceMappingURL=conversationActivity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversationActivity.js","sources":["../../../src/assistant/runtime/conversationActivity.mjs"],"sourcesContent":["/** Public summaries only. Full responses remain in the expanded activity segment. */\nexport function conversationActivitySummary(response, limit = 160) {\n if (typeof response !== 'string') return undefined;\n const lines = response.split(/\\r?\\n/).map(line => line.trim().replace(/^[-*]\\s+/, '')).filter(Boolean);\n const label = lines.at(-1)?.replace(/\\s+/g, ' ');\n if (!label) return undefined;\n return label.length <= limit ? label : `${label.slice(0, limit - 1).trimEnd()}…`;\n}\n"],"names":[],"mappings":"AAAA;AACO,SAAS,2BAA2B,CAAC,QAAQ,EAAE,KAAK,GAAG,GAAG,EAAE;AACnE,EAAE,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,OAAO,SAAS;AACpD,EAAE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;AACxG,EAAE,MAAM,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;AAClD,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,SAAS;AAC9B,EAAE,OAAO,KAAK,CAAC,MAAM,IAAI,KAAK,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAClF;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Browser source metadata is evidence supplied by the user; the backend decides whether it can verify it. */
|
|
2
|
+
function normalizeConversationAnnotations(value = []) {
|
|
3
|
+
if (!Array.isArray(value) || value.length > 16) throw new Error('Hasta 16 anotaciones por petición.');
|
|
4
|
+
const ids = new Set();
|
|
5
|
+
const normalized = value.map(annotation => {
|
|
6
|
+
if (!annotation || typeof annotation !== 'object' || typeof annotation.id !== 'string' || !annotation.id || annotation.id.length > 256 || ids.has(annotation.id)
|
|
7
|
+
|| typeof annotation.text !== 'string' || !annotation.text.trim() || annotation.text.length > 8000
|
|
8
|
+
|| (annotation.comment != null && (typeof annotation.comment !== 'string' || annotation.comment.length > 8000))) throw new Error('Anotación inválida.');
|
|
9
|
+
ids.add(annotation.id);
|
|
10
|
+
const sources = annotation.sources ?? [];
|
|
11
|
+
if (!Array.isArray(sources) || sources.length > 8) throw new Error('Fuentes de anotación inválidas.');
|
|
12
|
+
return { id: annotation.id, kind: 'quote', label: String(annotation.label ?? 'Texto seleccionado').slice(0, 255), text: annotation.text,
|
|
13
|
+
...(annotation.comment ? { comment: annotation.comment } : {}), sourceMessageIds: [],
|
|
14
|
+
sources: sources.map(source => {
|
|
15
|
+
if (!source || typeof source !== 'object' || typeof source.segmentId !== 'string') throw new Error('Identidad de cita inválida.');
|
|
16
|
+
const result = { verified: false };
|
|
17
|
+
for (const field of ['conversationId', 'turnId', 'requestId', 'tabId', 'assistantId', 'segmentId', 'version']) {
|
|
18
|
+
if (source[field] != null) { if (typeof source[field] !== 'string' || source[field].length > 256) throw new Error('Identidad de cita inválida.'); result[field] = source[field]; }
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}) };
|
|
22
|
+
});
|
|
23
|
+
if (JSON.stringify(normalized).length > 48000) throw new Error('Las anotaciones superan el límite del contexto.');
|
|
24
|
+
return normalized;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { normalizeConversationAnnotations };
|
|
28
|
+
//# sourceMappingURL=conversationAnnotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversationAnnotations.js","sources":["../../../src/assistant/runtime/conversationAnnotations.mjs"],"sourcesContent":["/** Browser source metadata is evidence supplied by the user; the backend decides whether it can verify it. */\nexport function normalizeConversationAnnotations(value = []) {\n if (!Array.isArray(value) || value.length > 16) throw new Error('Hasta 16 anotaciones por petición.');\n const ids = new Set();\n const normalized = value.map(annotation => {\n if (!annotation || typeof annotation !== 'object' || typeof annotation.id !== 'string' || !annotation.id || annotation.id.length > 256 || ids.has(annotation.id)\n || typeof annotation.text !== 'string' || !annotation.text.trim() || annotation.text.length > 8000\n || (annotation.comment != null && (typeof annotation.comment !== 'string' || annotation.comment.length > 8000))) throw new Error('Anotación inválida.');\n ids.add(annotation.id);\n const sources = annotation.sources ?? [];\n if (!Array.isArray(sources) || sources.length > 8) throw new Error('Fuentes de anotación inválidas.');\n return { id: annotation.id, kind: 'quote', label: String(annotation.label ?? 'Texto seleccionado').slice(0, 255), text: annotation.text,\n ...(annotation.comment ? { comment: annotation.comment } : {}), sourceMessageIds: [],\n sources: sources.map(source => {\n if (!source || typeof source !== 'object' || typeof source.segmentId !== 'string') throw new Error('Identidad de cita inválida.');\n const result = { verified: false };\n for (const field of ['conversationId', 'turnId', 'requestId', 'tabId', 'assistantId', 'segmentId', 'version']) {\n if (source[field] != null) { if (typeof source[field] !== 'string' || source[field].length > 256) throw new Error('Identidad de cita inválida.'); result[field] = source[field]; }\n }\n return result;\n }) };\n });\n if (JSON.stringify(normalized).length > 48000) throw new Error('Las anotaciones superan el límite del contexto.');\n return normalized;\n}\n"],"names":[],"mappings":"AAAA;AACO,SAAS,gCAAgC,CAAC,KAAK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
2
|
+
class ConversationAttachmentPreviews {
|
|
3
|
+
constructor({ urls = URL, decode = encoded => globalThis.atob(encoded) } = {}) {
|
|
4
|
+
this.urls = urls;
|
|
5
|
+
this.decode = decode;
|
|
6
|
+
this.retained = new Map();
|
|
7
|
+
}
|
|
8
|
+
project(attachments) {
|
|
9
|
+
return attachments.map(attachment => {
|
|
10
|
+
if (!/\.pdf$/i.test(attachment.name) || /^(blob:|https?:|\/)/i.test(attachment.base64)) return attachment;
|
|
11
|
+
const key = attachment.reference ?? attachment.base64;
|
|
12
|
+
let retained = this.retained.get(key);
|
|
13
|
+
if (!retained || retained.original !== attachment.base64) {
|
|
14
|
+
let url;
|
|
15
|
+
try {
|
|
16
|
+
const encoded = attachment.base64.replace(/^data:[^,]*,/, '').replace(/\s/g, '');
|
|
17
|
+
const bytes = Uint8Array.from(this.decode(encoded), char => char.charCodeAt(0));
|
|
18
|
+
url = this.urls.createObjectURL(new Blob([bytes], { type: 'application/pdf' }));
|
|
19
|
+
} catch {
|
|
20
|
+
// A display failure must not interrupt turn submission or transcript rendering.
|
|
21
|
+
return attachment;
|
|
22
|
+
}
|
|
23
|
+
if (retained) this.urls.revokeObjectURL(retained.url);
|
|
24
|
+
retained = { original: attachment.base64, url }; this.retained.set(key, retained);
|
|
25
|
+
}
|
|
26
|
+
return { ...attachment, base64: retained.url };
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
clear() { for (const value of this.retained.values()) this.urls.revokeObjectURL(value.url); this.retained.clear(); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { ConversationAttachmentPreviews };
|
|
33
|
+
//# sourceMappingURL=conversationAttachmentPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversationAttachmentPreview.js","sources":["../../../src/assistant/runtime/conversationAttachmentPreview.mjs"],"sourcesContent":["/** Display-only URLs. Originals remain in the conversation's attachment store. */\nexport class ConversationAttachmentPreviews {\n constructor({ urls = URL, decode = encoded => globalThis.atob(encoded) } = {}) {\n this.urls = urls;\n this.decode = decode;\n this.retained = new Map();\n }\n project(attachments) {\n return attachments.map(attachment => {\n if (!/\\.pdf$/i.test(attachment.name) || /^(blob:|https?:|\\/)/i.test(attachment.base64)) return attachment;\n const key = attachment.reference ?? attachment.base64;\n let retained = this.retained.get(key);\n if (!retained || retained.original !== attachment.base64) {\n let url;\n try {\n const encoded = attachment.base64.replace(/^data:[^,]*,/, '').replace(/\\s/g, '');\n const bytes = Uint8Array.from(this.decode(encoded), char => char.charCodeAt(0));\n url = this.urls.createObjectURL(new Blob([bytes], { type: 'application/pdf' }));\n } catch {\n // A display failure must not interrupt turn submission or transcript rendering.\n return attachment;\n }\n if (retained) this.urls.revokeObjectURL(retained.url);\n retained = { original: attachment.base64, url }; this.retained.set(key, retained);\n }\n return { ...attachment, base64: retained.url };\n });\n }\n clear() { for (const value of this.retained.values()) this.urls.revokeObjectURL(value.url); this.retained.clear(); }\n}\n"],"names":[],"mappings":"AAAA;AACO,MAAM,8BAA8B,CAAC;AAC5C,EAAE,WAAW,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,MAAM,GAAG,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,EAAE;AACjF,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI;AACpB,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM;AACxB,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE;AAC7B;AACA,EAAE,OAAO,CAAC,WAAW,EAAE;AACvB,IAAI,OAAO,WAAW,CAAC,GAAG,CAAC,UAAU,IAAI;AACzC,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,UAAU;AAC/G,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,SAAS,IAAI,UAAU,CAAC,MA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C,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;AACpH;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const MAX_CONVERSATION_ATTACHMENT_BYTES = 25 * 1024 * 1024;
|
|
2
|
+
const MAX_CONVERSATION_REQUEST_BYTES = Math.ceil(MAX_CONVERSATION_ATTACHMENT_BYTES / 3) * 4 + 1024 * 1024;
|
|
3
|
+
|
|
4
|
+
function conversationAttachmentBytes(base64) {
|
|
5
|
+
if (typeof base64 !== 'string') throw new Error('El adjunto no contiene un archivo válido.');
|
|
6
|
+
const encoded = base64.slice(base64.indexOf(',') + 1).replace(/\s/g, '');
|
|
7
|
+
const padding = encoded.endsWith('==') ? 2 : encoded.endsWith('=') ? 1 : 0;
|
|
8
|
+
return Math.floor(encoded.length * 3 / 4) - padding;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function validateConversationAttachments(attachments) {
|
|
12
|
+
for (const file of attachments) {
|
|
13
|
+
if (!file || typeof file.name !== 'string' || !file.name.trim() || typeof file.base64 !== 'string'
|
|
14
|
+
|| !/^(?:data:[^,]*;base64,)?[A-Za-z0-9+/\s]*={0,2}$/.test(file.base64)
|
|
15
|
+
|| conversationAttachmentBytes(file.base64) <= 0)
|
|
16
|
+
throw new Error('El adjunto no contiene un archivo válido.');
|
|
17
|
+
}
|
|
18
|
+
const bytes = attachments.reduce((total, file) => total + conversationAttachmentBytes(file.base64), 0);
|
|
19
|
+
if (bytes > MAX_CONVERSATION_ATTACHMENT_BYTES)
|
|
20
|
+
throw new Error('Los archivos del mensaje superan los 25 MiB permitidos.');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { MAX_CONVERSATION_ATTACHMENT_BYTES, MAX_CONVERSATION_REQUEST_BYTES, conversationAttachmentBytes, validateConversationAttachments };
|
|
24
|
+
//# sourceMappingURL=conversationAttachments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversationAttachments.js","sources":["../../../src/assistant/runtime/conversationAttachments.mjs"],"sourcesContent":["export const MAX_CONVERSATION_ATTACHMENT_BYTES = 25 * 1024 * 1024;\nexport const MAX_CONVERSATION_REQUEST_BYTES = Math.ceil(MAX_CONVERSATION_ATTACHMENT_BYTES / 3) * 4 + 1024 * 1024;\n\nexport function conversationAttachmentBytes(base64) {\n if (typeof base64 !== 'string') throw new Error('El adjunto no contiene un archivo válido.');\n const encoded = base64.slice(base64.indexOf(',') + 1).replace(/\\s/g, '');\n const padding = encoded.endsWith('==') ? 2 : encoded.endsWith('=') ? 1 : 0;\n return Math.floor(encoded.length * 3 / 4) - padding;\n}\n\nexport function validateConversationAttachments(attachments) {\n for (const file of attachments) {\n if (!file || typeof file.name !== 'string' || !file.name.trim() || typeof file.base64 !== 'string'\n || !/^(?:data:[^,]*;base64,)?[A-Za-z0-9+/\\s]*={0,2}$/.test(file.base64)\n || conversationAttachmentBytes(file.base64) <= 0)\n throw new Error('El adjunto no contiene un archivo válido.');\n }\n const bytes = attachments.reduce((total, file) => total + conversationAttachmentBytes(file.base64), 0);\n if (bytes > MAX_CONVERSATION_ATTACHMENT_BYTES)\n throw new Error('Los archivos del mensaje superan los 25 MiB permitidos.');\n}\n"],"names":[],"mappings":"AAAY,MAAC,iCAAiC,GAAG,EAAE,GAAG,IAAI,GAAG;AACjD,MAAC,8BAA8B,GAAG,IAAI,CAAC,IAAI,CAAC,iCAAiC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG;;AAErG,SAAS,2BAA2B,CAAC,MAAM,EAAE;AACpD,EAAE,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;AAC9F,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;AAC1E,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;AAC5E,EAAE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO;AACrD;;AAEO,SAAS,+BAA+B,CAAC,WAAW,EAAE;AAC7D,EAAE,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;AAClC,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK;AAC9F,WAAW,CAAC,iDAAiD,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;AAC9E,WAAW,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;AACxD,MAAM,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;AAClE;AACA,EAAE,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,GAAG,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACxG,EAAE,IAAI,KAAK,GAAG,iCAAiC;AAC/C,IAAI,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAC9E;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as _apia_components from '@apia/components';
|
|
2
|
+
import { TabAssistantsClient } from '@apia/components';
|
|
3
|
+
import { TChatAnnotation } from '../../chat/ChatController/types.js';
|
|
4
|
+
|
|
5
|
+
declare class ConversationClient {
|
|
6
|
+
constructor(options: { api: (body: Record<string, unknown>) => Promise<any>; tabs: TabAssistantsClient; storage: Storage; key: string; contentId: string; onChange: (state: any) => void; replyMode?: 'automatic'; tabOrder?: () => string[] | undefined; closeTaskTab?: (tabId: string) => Promise<boolean> });
|
|
7
|
+
state: any;
|
|
8
|
+
initialize(validate?: boolean): Promise<any>;
|
|
9
|
+
clearHistory(): Promise<void>;
|
|
10
|
+
submit(message: string, attachments?: Array<{ name: string; base64: string; description?: string }>): Promise<any>;
|
|
11
|
+
waitUntilIdle(): Promise<void>;
|
|
12
|
+
enqueue(message: string, attachments?: Array<{ name: string; base64: string; description?: string }>, annotations?: TChatAnnotation[], referralTurnId?: string): Promise<string>;
|
|
13
|
+
withdrawAdmission(id: string): void;
|
|
14
|
+
cancelTurn(turnId: string): Promise<any>;
|
|
15
|
+
deliveryAction(action: 'reconcileDelivery' | 'abandonDelivery', attention: { turnId: string; toolCallId: string; startId: string; revision: number }): Promise<any>;
|
|
16
|
+
resume(recover?: boolean): Promise<any>;
|
|
17
|
+
requestActions(): { operationId?: string; requestId?: string; status?: string; message?: string; confirmation?: _apia_components.TabAssistantConfirmation; actions: readonly string[] };
|
|
18
|
+
confirm(requestId: string, confirmationId: string, approvedItemIds: readonly string[]): Promise<any>;
|
|
19
|
+
act(action: 'recover' | 'reconcile' | 'cancel', requestId: string): Promise<any>;
|
|
20
|
+
cancel(): Promise<void>;
|
|
21
|
+
openTaskLink(conversationId: string, reference: string): Promise<void>;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ConversationClient };
|
|
26
|
+
//# sourceMappingURL=conversationClient.d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversationClient.d.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|