@apia/ai 4.0.102 → 5.0.1
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/chat/AutoscrollContainer.d.ts +12 -0
- package/dist/chat/AutoscrollContainer.d.ts.map +1 -0
- package/dist/chat/AutoscrollContainer.js +150 -0
- package/dist/chat/AutoscrollContainer.js.map +1 -0
- package/dist/chat/ChatController/CameraController.d.ts +18 -0
- package/dist/chat/ChatController/CameraController.d.ts.map +1 -0
- package/dist/chat/ChatController/CameraController.js +99 -0
- package/dist/chat/ChatController/CameraController.js.map +1 -0
- package/dist/chat/ChatController/ChatController.d.ts +58 -0
- package/dist/chat/ChatController/ChatController.d.ts.map +1 -0
- package/dist/chat/ChatController/ChatController.js +320 -0
- package/dist/chat/ChatController/ChatController.js.map +1 -0
- package/dist/chat/ChatController/StreamMessage.d.ts +39 -0
- package/dist/chat/ChatController/StreamMessage.d.ts.map +1 -0
- package/dist/chat/ChatController/StreamMessage.js +84 -0
- package/dist/chat/ChatController/StreamMessage.js.map +1 -0
- package/dist/chat/ChatController/components/Attachments.d.ts +14 -0
- package/dist/chat/ChatController/components/Attachments.d.ts.map +1 -0
- package/dist/chat/ChatController/components/Attachments.js +35 -0
- package/dist/chat/ChatController/components/Attachments.js.map +1 -0
- package/dist/chat/ChatController/components/ChatMessage.d.ts +28 -0
- package/dist/chat/ChatController/components/ChatMessage.d.ts.map +1 -0
- package/dist/chat/ChatController/components/ChatMessage.js +74 -0
- package/dist/chat/ChatController/components/ChatMessage.js.map +1 -0
- package/dist/chat/ChatController/components/Ellipsis.d.ts +6 -0
- package/dist/chat/ChatController/components/Ellipsis.d.ts.map +1 -0
- package/dist/chat/ChatController/components/Ellipsis.js +23 -0
- package/dist/chat/ChatController/components/Ellipsis.js.map +1 -0
- package/dist/chat/ChatController/components/FileAttachment.js +76 -0
- package/dist/chat/ChatController/components/FileAttachment.js.map +1 -0
- package/dist/chat/ChatController/components/Header.d.ts +11 -0
- package/dist/chat/ChatController/components/Header.d.ts.map +1 -0
- package/dist/chat/ChatController/components/Header.js +12 -0
- package/dist/chat/ChatController/components/Header.js.map +1 -0
- package/dist/chat/ChatController/components/History.d.ts +12 -0
- package/dist/chat/ChatController/components/History.d.ts.map +1 -0
- package/dist/chat/ChatController/components/History.js +47 -0
- package/dist/chat/ChatController/components/History.js.map +1 -0
- package/dist/chat/ChatController/components/Message.d.ts +17 -0
- package/dist/chat/ChatController/components/Message.d.ts.map +1 -0
- package/dist/chat/ChatController/components/Message.js +38 -0
- package/dist/chat/ChatController/components/Message.js.map +1 -0
- package/dist/chat/ChatController/components/MessageBlock.d.ts +9 -0
- package/dist/chat/ChatController/components/MessageBlock.d.ts.map +1 -0
- package/dist/chat/ChatController/components/MessageBlock.js +16 -0
- package/dist/chat/ChatController/components/MessageBlock.js.map +1 -0
- package/dist/chat/ChatController/components/MessageBlocks.d.ts +26 -0
- package/dist/chat/ChatController/components/MessageBlocks.d.ts.map +1 -0
- package/dist/chat/ChatController/components/MessageBlocks.js +87 -0
- package/dist/chat/ChatController/components/MessageBlocks.js.map +1 -0
- package/dist/chat/ChatController/components/MessageBody.d.ts +12 -0
- package/dist/chat/ChatController/components/MessageBody.d.ts.map +1 -0
- package/dist/chat/ChatController/components/MessageBody.js +78 -0
- package/dist/chat/ChatController/components/MessageBody.js.map +1 -0
- package/dist/chat/ChatController/components/QuestionAnswerMessage.d.ts +12 -0
- package/dist/chat/ChatController/components/QuestionAnswerMessage.d.ts.map +1 -0
- package/dist/chat/ChatController/components/QuestionAnswerMessage.js +21 -0
- package/dist/chat/ChatController/components/QuestionAnswerMessage.js.map +1 -0
- package/dist/chat/ChatController/components/QuestionBlocks.d.ts +11 -0
- package/dist/chat/ChatController/components/QuestionBlocks.d.ts.map +1 -0
- package/dist/chat/ChatController/components/QuestionBlocks.js +24 -0
- package/dist/chat/ChatController/components/QuestionBlocks.js.map +1 -0
- package/dist/chat/ChatController/components/TextArea.d.ts +39 -0
- package/dist/chat/ChatController/components/TextArea.d.ts.map +1 -0
- package/dist/chat/ChatController/components/TextArea.js +377 -0
- package/dist/chat/ChatController/components/TextArea.js.map +1 -0
- package/dist/chat/ChatController/components/ThinkingBlocks.d.ts +17 -0
- package/dist/chat/ChatController/components/ThinkingBlocks.d.ts.map +1 -0
- package/dist/chat/ChatController/components/ThinkingBlocks.js +259 -0
- package/dist/chat/ChatController/components/ThinkingBlocks.js.map +1 -0
- package/dist/chat/ChatController/components/rate.d.ts +4 -0
- package/dist/chat/ChatController/components/rate.d.ts.map +1 -0
- package/dist/chat/ChatController/components/rate.js +68 -0
- package/dist/chat/ChatController/components/rate.js.map +1 -0
- package/dist/chat/ChatController/types.d.ts +39 -0
- package/dist/chat/ChatController/types.d.ts.map +1 -0
- package/dist/chat/ChatController/util.js +22 -0
- package/dist/chat/ChatController/util.js.map +1 -0
- package/dist/chat/FloatingChatController.d.ts +35 -0
- package/dist/chat/FloatingChatController.d.ts.map +1 -0
- package/dist/chat/FloatingChatController.js +81 -0
- package/dist/chat/FloatingChatController.js.map +1 -0
- package/dist/components/chat/messages/MultipleChoiceMessage.d.ts +17 -0
- package/dist/components/chat/messages/MultipleChoiceMessage.d.ts.map +1 -0
- package/dist/components/chat/messages/MultipleChoiceMessage.js +31 -0
- package/dist/components/chat/messages/MultipleChoiceMessage.js.map +1 -0
- package/dist/components/documents/ImageBinaryField/getImage.d.ts +14 -0
- package/dist/components/documents/ImageBinaryField/getImage.d.ts.map +1 -0
- package/dist/components/documents/ImageBinaryField/getImage.js +47 -0
- package/dist/components/documents/ImageBinaryField/getImage.js.map +1 -0
- package/dist/components/documents/ImageBinaryField/getImageSrcString.js +6 -0
- package/dist/components/documents/ImageBinaryField/getImageSrcString.js.map +1 -0
- package/dist/components/documents/UploadModal/ImageIcon.js +18 -0
- package/dist/components/documents/UploadModal/ImageIcon.js.map +1 -0
- package/dist/components/documents/UploadModal/getImagesWithDescription.d.ts +10 -0
- package/dist/components/documents/UploadModal/getImagesWithDescription.d.ts.map +1 -0
- package/dist/components/documents/UploadModal/getImagesWithDescription.js +148 -0
- package/dist/components/documents/UploadModal/getImagesWithDescription.js.map +1 -0
- package/dist/index.d.ts +30 -495
- package/dist/index.js +29 -1884
- package/dist/index.js.map +1 -1
- package/dist/routines/DashboardRoutinesGeneration.d.ts +22 -0
- package/dist/routines/DashboardRoutinesGeneration.d.ts.map +1 -0
- package/dist/routines/DashboardRoutinesGeneration.js +54 -0
- package/dist/routines/DashboardRoutinesGeneration.js.map +1 -0
- package/dist/routines/RoutinesGeneration.d.ts +54 -0
- package/dist/routines/RoutinesGeneration.d.ts.map +1 -0
- package/dist/routines/RoutinesGeneration.js +174 -0
- package/dist/routines/RoutinesGeneration.js.map +1 -0
- package/dist/semanticSearch/SearchController/index.d.ts +23 -0
- package/dist/semanticSearch/SearchController/index.d.ts.map +1 -0
- package/dist/semanticSearch/SearchController/index.js +56 -0
- package/dist/semanticSearch/SearchController/index.js.map +1 -0
- package/dist/semanticSearch/SearchController/objects/SemanticSearchReference/Component.js +15 -0
- package/dist/semanticSearch/SearchController/objects/SemanticSearchReference/Component.js.map +1 -0
- package/dist/semanticSearch/SearchController/objects/SemanticSearchReference/index.d.ts +15 -0
- package/dist/semanticSearch/SearchController/objects/SemanticSearchReference/index.d.ts.map +1 -0
- package/dist/semanticSearch/SearchController/objects/SemanticSearchReference/index.js +25 -0
- package/dist/semanticSearch/SearchController/objects/SemanticSearchReference/index.js.map +1 -0
- package/dist/semanticSearch/ViewController/types.d.ts +62 -0
- package/dist/semanticSearch/ViewController/types.d.ts.map +1 -0
- package/dist/semanticSearch/ViewController/types.js +8 -0
- package/dist/semanticSearch/ViewController/types.js.map +1 -0
- package/dist/stream/ResponseStream.d.ts +55 -0
- package/dist/stream/ResponseStream.d.ts.map +1 -0
- package/dist/stream/ResponseStream.js +214 -0
- package/dist/stream/ResponseStream.js.map +1 -0
- package/dist/stream/StreamServicePoller.d.ts +16 -0
- package/dist/stream/StreamServicePoller.d.ts.map +1 -0
- package/dist/stream/StreamServicePoller.js +52 -0
- package/dist/stream/StreamServicePoller.js.map +1 -0
- package/package.json +8 -8
- package/LICENSE.md +0 -6
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { EventEmitter, decodeBase64ToUtf8 } from '@apia/util';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __publicField = (obj, key, value) => {
|
|
6
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
+
return value;
|
|
8
|
+
};
|
|
9
|
+
class ResponseStream extends EventEmitter {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
__publicField(this, "buffer", "");
|
|
13
|
+
__publicField(this, "isRunning", false);
|
|
14
|
+
__publicField(this, "locked", false);
|
|
15
|
+
__publicField(this, "maxCompletionTime", 150);
|
|
16
|
+
// ms
|
|
17
|
+
__publicField(this, "minPartSize", 2);
|
|
18
|
+
__publicField(this, "partSize", 2);
|
|
19
|
+
__publicField(this, "timing", 5);
|
|
20
|
+
// ms
|
|
21
|
+
__publicField(this, "waiting", []);
|
|
22
|
+
}
|
|
23
|
+
calculatePartSize() {
|
|
24
|
+
const totalSize = this.buffer.length + this.waiting.reduce((a, b) => a + b.length, 0);
|
|
25
|
+
this.partSize = Math.max(
|
|
26
|
+
this.minPartSize,
|
|
27
|
+
totalSize * (this.timing / this.maxCompletionTime)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
emit(ev, data) {
|
|
31
|
+
if (ev === "part") {
|
|
32
|
+
let chunk = data;
|
|
33
|
+
const structuredMatches = extractStructuredMatches(chunk);
|
|
34
|
+
if (structuredMatches.length > 0) {
|
|
35
|
+
const textChunks = [];
|
|
36
|
+
let currentIndex = 0;
|
|
37
|
+
structuredMatches.forEach((match) => {
|
|
38
|
+
textChunks.push(chunk.slice(currentIndex, match.start));
|
|
39
|
+
currentIndex = match.end;
|
|
40
|
+
if (match.kind === "block") {
|
|
41
|
+
this.emitBlock(match.block);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.emitResponse(match.response);
|
|
45
|
+
});
|
|
46
|
+
textChunks.push(chunk.slice(currentIndex));
|
|
47
|
+
chunk = textChunks.join("");
|
|
48
|
+
}
|
|
49
|
+
if (this.locked) {
|
|
50
|
+
this.waiting.push(chunk);
|
|
51
|
+
} else {
|
|
52
|
+
this.buffer += chunk;
|
|
53
|
+
}
|
|
54
|
+
this.calculatePartSize();
|
|
55
|
+
this.run();
|
|
56
|
+
} else {
|
|
57
|
+
super.emit(ev, data);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
emitBlock(block) {
|
|
61
|
+
super.emit("block", block);
|
|
62
|
+
}
|
|
63
|
+
emitResponse(response) {
|
|
64
|
+
super.emit("response", response);
|
|
65
|
+
}
|
|
66
|
+
run() {
|
|
67
|
+
if (!this.isRunning) {
|
|
68
|
+
this.isRunning = true;
|
|
69
|
+
const interval = setInterval(() => {
|
|
70
|
+
this.locked = true;
|
|
71
|
+
const choosedSize = Math.min(this.buffer.length, this.partSize);
|
|
72
|
+
const part = this.buffer.slice(0, choosedSize);
|
|
73
|
+
this.buffer = this.buffer.slice(choosedSize);
|
|
74
|
+
while (this.waiting.length > 0) {
|
|
75
|
+
const part2 = this.waiting.shift();
|
|
76
|
+
if (part2) {
|
|
77
|
+
this.buffer += part2;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
this.locked = false;
|
|
81
|
+
if (part) {
|
|
82
|
+
super.emit("part", part);
|
|
83
|
+
} else {
|
|
84
|
+
this.isRunning = false;
|
|
85
|
+
clearInterval(interval);
|
|
86
|
+
}
|
|
87
|
+
}, this.timing);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const BLOCK_REGEX = /<BLOCK-START([^>]*)>([\s\S]*?)<\/BLOCK-END(?: [^>]*)?>/g;
|
|
92
|
+
const BLOCK_RESPONSE_REGEX = /<BLOCK-RESPONSE([^>]*)>([\s\S]*?)<\/BLOCK-RESPONSE>/g;
|
|
93
|
+
const ATTRIBUTE_REGEX = /([a-zA-Z0-9_-]+)="([^"]*)"/g;
|
|
94
|
+
function extractStructuredMatches(chunk) {
|
|
95
|
+
const matches = [];
|
|
96
|
+
const blockRegex = new RegExp(BLOCK_REGEX);
|
|
97
|
+
let blockMatch = null;
|
|
98
|
+
while ((blockMatch = blockRegex.exec(chunk)) !== null) {
|
|
99
|
+
const attributes = parseAttributes(blockMatch[1]);
|
|
100
|
+
const type = attributes.type;
|
|
101
|
+
if (!type || blockMatch.index === void 0) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
matches.push({
|
|
105
|
+
block: {
|
|
106
|
+
arguments: decodeOptionalBase64(attributes.arguments),
|
|
107
|
+
description: blockMatch[2],
|
|
108
|
+
id: attributes.id,
|
|
109
|
+
question: type === "question" ? parseQuestionContent(blockMatch[2], attributes.id) : void 0,
|
|
110
|
+
type
|
|
111
|
+
},
|
|
112
|
+
end: blockMatch.index + blockMatch[0].length,
|
|
113
|
+
kind: "block",
|
|
114
|
+
start: blockMatch.index
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const responseRegex = new RegExp(BLOCK_RESPONSE_REGEX);
|
|
118
|
+
let responseMatch = null;
|
|
119
|
+
while ((responseMatch = responseRegex.exec(chunk)) !== null) {
|
|
120
|
+
const attributes = parseAttributes(responseMatch[1]);
|
|
121
|
+
const id = attributes.id;
|
|
122
|
+
if (!id || responseMatch.index === void 0) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
matches.push({
|
|
126
|
+
end: responseMatch.index + responseMatch[0].length,
|
|
127
|
+
kind: "response",
|
|
128
|
+
response: {
|
|
129
|
+
id,
|
|
130
|
+
response: decodeOptionalBase64(responseMatch[2]) ?? ""
|
|
131
|
+
},
|
|
132
|
+
start: responseMatch.index
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return matches.sort((left, right) => left.start - right.start);
|
|
136
|
+
}
|
|
137
|
+
function parseAttributes(source) {
|
|
138
|
+
const attributes = {};
|
|
139
|
+
const attributeRegex = new RegExp(ATTRIBUTE_REGEX);
|
|
140
|
+
let match = null;
|
|
141
|
+
while ((match = attributeRegex.exec(source)) !== null) {
|
|
142
|
+
attributes[match[1]] = decodeAttribute(match[2]);
|
|
143
|
+
}
|
|
144
|
+
return attributes;
|
|
145
|
+
}
|
|
146
|
+
function decodeAttribute(value) {
|
|
147
|
+
return value.replaceAll(""", '"').replaceAll("<", "<").replaceAll(">", ">").replaceAll("'", "'").replaceAll("'", "'").replaceAll("&", "&");
|
|
148
|
+
}
|
|
149
|
+
function decodeOptionalBase64(value) {
|
|
150
|
+
if (!value) {
|
|
151
|
+
return void 0;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
return decodeBase64ToUtf8(value);
|
|
155
|
+
} catch (_error) {
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function parseQuestionContent(content, fallbackId) {
|
|
160
|
+
const title = matchDecodedTag(content, "title") ?? "Necesito una aclaracion del cliente";
|
|
161
|
+
const description = matchDecodedTag(content, "description");
|
|
162
|
+
const dataAttributes = parseAttributes(
|
|
163
|
+
matchTagAttributes(content, "data") ?? ""
|
|
164
|
+
);
|
|
165
|
+
const options = extractQuestionOptions(content);
|
|
166
|
+
return {
|
|
167
|
+
description,
|
|
168
|
+
id: trimToUndefined(dataAttributes.id) ?? fallbackId ?? "",
|
|
169
|
+
options,
|
|
170
|
+
title
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function matchDecodedTag(content, tagName) {
|
|
174
|
+
const match = content.match(
|
|
175
|
+
new RegExp(`<${tagName}>([\\s\\S]*?)<\\/${tagName}>`, "i")
|
|
176
|
+
);
|
|
177
|
+
if (!match?.[1]) {
|
|
178
|
+
return void 0;
|
|
179
|
+
}
|
|
180
|
+
return trimToUndefined(decodeAttribute(match[1]));
|
|
181
|
+
}
|
|
182
|
+
function matchTagAttributes(content, tagName) {
|
|
183
|
+
const match = content.match(new RegExp(`<${tagName}([^>]*)\\/?>`, "i"));
|
|
184
|
+
return match?.[1];
|
|
185
|
+
}
|
|
186
|
+
function extractQuestionOptions(content) {
|
|
187
|
+
const options = [];
|
|
188
|
+
const optionRegex = /<option([^>]*)>([\s\S]*?)<\/option>/gi;
|
|
189
|
+
let optionMatch = null;
|
|
190
|
+
while ((optionMatch = optionRegex.exec(content)) !== null) {
|
|
191
|
+
const attributes = parseAttributes(optionMatch[1] ?? "");
|
|
192
|
+
const label = trimToUndefined(decodeAttribute(optionMatch[2] ?? ""));
|
|
193
|
+
const value = trimToUndefined(attributes.value);
|
|
194
|
+
if (!label && !value) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
options.push({
|
|
198
|
+
description: trimToUndefined(attributes.description),
|
|
199
|
+
label: label ?? value ?? `Opcion ${options.length + 1}`,
|
|
200
|
+
value: value ?? label ?? `option_${options.length + 1}`
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return options;
|
|
204
|
+
}
|
|
205
|
+
function trimToUndefined(value) {
|
|
206
|
+
if (value === void 0 || value === null) {
|
|
207
|
+
return void 0;
|
|
208
|
+
}
|
|
209
|
+
const trimmed = value.trim();
|
|
210
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { ResponseStream };
|
|
214
|
+
//# sourceMappingURL=ResponseStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResponseStream.js","sources":["../../src/stream/ResponseStream.ts"],"sourcesContent":["import { decodeBase64ToUtf8, EventEmitter } from '@apia/util';\r\n\r\nexport type StreamBlock = {\r\n type: string;\r\n description: string;\r\n id?: string;\r\n arguments?: string;\r\n question?: StreamQuestion;\r\n};\r\n\r\nexport type StreamToolResponse = {\r\n id: string;\r\n response: string;\r\n};\r\n\r\nexport type StreamQuestionOption = {\r\n value: string;\r\n label: string;\r\n description?: string;\r\n};\r\n\r\nexport type StreamQuestion = {\r\n id: string;\r\n title: string;\r\n description?: string;\r\n options: StreamQuestionOption[];\r\n};\r\n\r\nexport type ResponseStreamEvents = {\r\n block: StreamBlock;\r\n part: string;\r\n response: StreamToolResponse;\r\n};\r\n\r\nexport type ResponseStreamBlock = {\r\n type: string;\r\n content: string;\r\n id?: string;\r\n arguments?: string;\r\n response?: string;\r\n question?: StreamQuestion;\r\n};\r\n\r\nexport class ResponseStream<\r\n T extends ResponseStreamEvents = ResponseStreamEvents,\r\n> extends EventEmitter<T> {\r\n private buffer: string = '';\r\n private isRunning = false;\r\n private locked = false;\r\n public maxCompletionTime = 150; // ms\r\n private minPartSize = 2;\r\n private partSize = 2;\r\n private timing = 5; // ms\r\n private waiting: string[] = [];\r\n\r\n private calculatePartSize() {\r\n const totalSize =\r\n this.buffer.length +\r\n this.waiting.reduce<number>((a, b) => a + b.length, 0);\r\n\r\n this.partSize = Math.max(\r\n this.minPartSize,\r\n totalSize * (this.timing / this.maxCompletionTime),\r\n );\r\n }\r\n\r\n emit<K extends keyof T>(ev: K, data: T[K]): void {\r\n if (ev === 'part') {\r\n let chunk = data as string;\r\n const structuredMatches = extractStructuredMatches(chunk);\r\n\r\n if (structuredMatches.length > 0) {\r\n const textChunks: string[] = [];\r\n let currentIndex = 0;\r\n\r\n structuredMatches.forEach((match) => {\r\n textChunks.push(chunk.slice(currentIndex, match.start));\r\n currentIndex = match.end;\r\n\r\n if (match.kind === 'block') {\r\n this.emitBlock(match.block);\r\n return;\r\n }\r\n\r\n this.emitResponse(match.response);\r\n });\r\n\r\n textChunks.push(chunk.slice(currentIndex));\r\n chunk = textChunks.join('');\r\n }\r\n\r\n if (this.locked) {\r\n this.waiting.push(chunk);\r\n } else {\r\n this.buffer += chunk;\r\n }\r\n this.calculatePartSize();\r\n this.run();\r\n } else {\r\n super.emit(ev, data);\r\n }\r\n }\r\n\r\n private emitBlock(block: StreamBlock) {\r\n super.emit('block' as keyof T, block as T[keyof T]);\r\n }\r\n\r\n private emitResponse(response: StreamToolResponse) {\r\n super.emit('response' as keyof T, response as T[keyof T]);\r\n }\r\n\r\n run() {\r\n if (!this.isRunning) {\r\n this.isRunning = true;\r\n const interval = setInterval(() => {\r\n this.locked = true;\r\n\r\n const choosedSize = Math.min(this.buffer.length, this.partSize);\r\n\r\n const part = this.buffer.slice(0, choosedSize);\r\n this.buffer = this.buffer.slice(choosedSize);\r\n\r\n while (this.waiting.length > 0) {\r\n const part = this.waiting.shift();\r\n if (part) {\r\n this.buffer += part;\r\n }\r\n }\r\n this.locked = false;\r\n if (part) {\r\n super.emit('part', part);\r\n } else {\r\n this.isRunning = false;\r\n clearInterval(interval);\r\n }\r\n }, this.timing);\r\n }\r\n }\r\n}\r\n\r\nconst BLOCK_REGEX = /<BLOCK-START([^>]*)>([\\s\\S]*?)<\\/BLOCK-END(?: [^>]*)?>/g;\r\nconst BLOCK_RESPONSE_REGEX = /<BLOCK-RESPONSE([^>]*)>([\\s\\S]*?)<\\/BLOCK-RESPONSE>/g;\r\nconst ATTRIBUTE_REGEX = /([a-zA-Z0-9_-]+)=\"([^\"]*)\"/g;\r\n\r\ntype TStructuredMatch =\r\n | {\r\n kind: 'block';\r\n start: number;\r\n end: number;\r\n block: StreamBlock;\r\n }\r\n | {\r\n kind: 'response';\r\n start: number;\r\n end: number;\r\n response: StreamToolResponse;\r\n };\r\n\r\nfunction extractStructuredMatches(chunk: string) {\r\n const matches: TStructuredMatch[] = [];\r\n\r\n const blockRegex = new RegExp(BLOCK_REGEX);\r\n let blockMatch: RegExpExecArray | null = null;\r\n while ((blockMatch = blockRegex.exec(chunk)) !== null) {\r\n const attributes = parseAttributes(blockMatch[1]);\r\n const type = attributes.type;\r\n\r\n if (!type || blockMatch.index === undefined) {\r\n continue;\r\n }\r\n\r\n matches.push({\r\n block: {\r\n arguments: decodeOptionalBase64(attributes.arguments),\r\n description: blockMatch[2],\r\n id: attributes.id,\r\n question:\r\n type === 'question'\r\n ? parseQuestionContent(blockMatch[2], attributes.id)\r\n : undefined,\r\n type,\r\n },\r\n end: blockMatch.index + blockMatch[0].length,\r\n kind: 'block',\r\n start: blockMatch.index,\r\n });\r\n }\r\n\r\n const responseRegex = new RegExp(BLOCK_RESPONSE_REGEX);\r\n let responseMatch: RegExpExecArray | null = null;\r\n while ((responseMatch = responseRegex.exec(chunk)) !== null) {\r\n const attributes = parseAttributes(responseMatch[1]);\r\n const id = attributes.id;\r\n\r\n if (!id || responseMatch.index === undefined) {\r\n continue;\r\n }\r\n\r\n matches.push({\r\n end: responseMatch.index + responseMatch[0].length,\r\n kind: 'response',\r\n response: {\r\n id,\r\n response: decodeOptionalBase64(responseMatch[2]) ?? '',\r\n },\r\n start: responseMatch.index,\r\n });\r\n }\r\n\r\n return matches.sort((left, right) => left.start - right.start);\r\n}\r\n\r\nfunction parseAttributes(source: string) {\r\n const attributes: Record<string, string> = {};\r\n const attributeRegex = new RegExp(ATTRIBUTE_REGEX);\r\n let match: RegExpExecArray | null = null;\r\n\r\n while ((match = attributeRegex.exec(source)) !== null) {\r\n attributes[match[1]] = decodeAttribute(match[2]);\r\n }\r\n\r\n return attributes;\r\n}\r\n\r\nfunction decodeAttribute(value: string) {\r\n return value\r\n .replaceAll('"', '\"')\r\n .replaceAll('<', '<')\r\n .replaceAll('>', '>')\r\n .replaceAll(''', \"'\")\r\n .replaceAll(''', \"'\")\r\n .replaceAll('&', '&');\r\n}\r\n\r\nfunction decodeOptionalBase64(value?: string) {\r\n if (!value) {\r\n return undefined;\r\n }\r\n\r\n try {\r\n return decodeBase64ToUtf8(value);\r\n } catch (_error) {\r\n return value;\r\n }\r\n}\r\n\r\nfunction parseQuestionContent(content: string, fallbackId?: string): StreamQuestion {\r\n const title =\r\n matchDecodedTag(content, 'title') ?? 'Necesito una aclaracion del cliente';\r\n const description = matchDecodedTag(content, 'description');\r\n const dataAttributes = parseAttributes(\r\n matchTagAttributes(content, 'data') ?? '',\r\n );\r\n const options = extractQuestionOptions(content);\r\n\r\n return {\r\n description,\r\n id: trimToUndefined(dataAttributes.id) ?? fallbackId ?? '',\r\n options,\r\n title,\r\n };\r\n}\r\n\r\nfunction matchDecodedTag(content: string, tagName: string) {\r\n const match = content.match(\r\n new RegExp(`<${tagName}>([\\\\s\\\\S]*?)<\\\\/${tagName}>`, 'i'),\r\n );\r\n\r\n if (!match?.[1]) {\r\n return undefined;\r\n }\r\n\r\n return trimToUndefined(decodeAttribute(match[1]));\r\n}\r\n\r\nfunction matchTagAttributes(content: string, tagName: string) {\r\n const match = content.match(new RegExp(`<${tagName}([^>]*)\\\\/?>`, 'i'));\r\n return match?.[1];\r\n}\r\n\r\nfunction extractQuestionOptions(content: string) {\r\n const options: StreamQuestionOption[] = [];\r\n const optionRegex = /<option([^>]*)>([\\s\\S]*?)<\\/option>/gi;\r\n let optionMatch: RegExpExecArray | null = null;\r\n\r\n while ((optionMatch = optionRegex.exec(content)) !== null) {\r\n const attributes = parseAttributes(optionMatch[1] ?? '');\r\n const label = trimToUndefined(decodeAttribute(optionMatch[2] ?? ''));\r\n const value = trimToUndefined(attributes.value);\r\n\r\n if (!label && !value) {\r\n continue;\r\n }\r\n\r\n options.push({\r\n description: trimToUndefined(attributes.description),\r\n label: label ?? value ?? `Opcion ${options.length + 1}`,\r\n value: value ?? label ?? `option_${options.length + 1}`,\r\n });\r\n }\r\n\r\n return options;\r\n}\r\n\r\nfunction trimToUndefined(value?: string | null) {\r\n if (value === undefined || value === null) {\r\n return undefined;\r\n }\r\n\r\n const trimmed = value.trim();\r\n return trimmed.length > 0 ? trimmed : undefined;\r\n}\r\n"],"names":["part"],"mappings":";;;;;;;;AA2CO,MAAM,uBAEH,YAAA,CAAgB;AAAA,EAFnB,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CA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MAAM,QAAQ,eAAA,CAAgB,eAAA,CAAgB,YAAY,CAAC,CAAA,IAAK,EAAE,CAAC,CAAA;AACnE,IAAA,MAAM,KAAA,GAAQ,eAAA,CAAgB,UAAA,CAAW,KAAK,CAAA;AAE9C,IAAA,IAAI,CAAC,KAAA,IAAS,CAAC,KAAA,EAAO;AACpB,MAAA;AAAA;AAGF,IAAA,OAAA,CAAQ,IAAA,CAAK;AAAA,MACX,WAAA,EAAa,eAAA,CAAgB,UAAA,CAAW,WAAW,CAAA;AAAA,MACnD,OAAO,KAAA,IAAS,KAAA,IAAS,CAAA,OAAA,EAAU,OAAA,CAAQ,SAAS,CAAC,CAAA,CAAA;AAAA,MACrD,OAAO,KAAA,IAAS,KAAA,IAAS,CAAA,OAAA,EAAU,OAAA,CAAQ,SAAS,CAAC,CAAA;AAAA,KACtD,CAAA;AAAA;AAGH,EAAA,OAAO,OAAA;AACT;AAEA,SAAS,gBAAgB,KAAA,EAAuB;AAC9C,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,IAAA,EAAM;AACzC,IAAA,OAAO,MAAA;AAAA;AAGT,EAAA,MAAM,OAAA,GAAU,MAAM,IAAA,EAAK;AAC3B,EAAA,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,OAAA,GAAU,MAAA;AACxC;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as _apia_util from '@apia/util';
|
|
2
|
+
import { ResponseStream, ResponseStreamEvents } from './ResponseStream.js';
|
|
3
|
+
|
|
4
|
+
type PollerEvents = ResponseStreamEvents & {
|
|
5
|
+
close: null;
|
|
6
|
+
error: null;
|
|
7
|
+
};
|
|
8
|
+
declare class StreamServicePoller {
|
|
9
|
+
closed: boolean;
|
|
10
|
+
stream: ResponseStream<PollerEvents>;
|
|
11
|
+
on<K extends keyof PollerEvents>(ev: K, cb: (ev: PollerEvents[K]) => unknown): _apia_util.UnSubscriber;
|
|
12
|
+
start(token: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { type PollerEvents, StreamServicePoller };
|
|
16
|
+
//# sourceMappingURL=StreamServicePoller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamServicePoller.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ApiaApi, makeApiaUrl } from '@apia/api';
|
|
2
|
+
import { ResponseStream } from './ResponseStream.js';
|
|
3
|
+
import { decodeBase64ToUtf8 } from '@apia/util';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __publicField = (obj, key, value) => {
|
|
8
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
class StreamServicePoller {
|
|
12
|
+
constructor() {
|
|
13
|
+
__publicField(this, "closed", true);
|
|
14
|
+
__publicField(this, "stream", new ResponseStream());
|
|
15
|
+
}
|
|
16
|
+
on(ev, cb) {
|
|
17
|
+
return this.stream.on(ev, cb);
|
|
18
|
+
}
|
|
19
|
+
async start(token) {
|
|
20
|
+
this.closed = false;
|
|
21
|
+
try {
|
|
22
|
+
while (!this.closed) {
|
|
23
|
+
const res = await ApiaApi.post(
|
|
24
|
+
makeApiaUrl({
|
|
25
|
+
ajaxUrl: "apia.execution.StreamAction.run",
|
|
26
|
+
action: "poll",
|
|
27
|
+
streamToken: token
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
if (!res) {
|
|
31
|
+
this.closed = true;
|
|
32
|
+
this.stream.emit("error", null);
|
|
33
|
+
}
|
|
34
|
+
if (res?.data?.part) {
|
|
35
|
+
this.stream.emit("part", decodeBase64ToUtf8(res.data.part));
|
|
36
|
+
}
|
|
37
|
+
if (res?.data?.closed === "true") {
|
|
38
|
+
this.closed = true;
|
|
39
|
+
this.stream.emit("close", null);
|
|
40
|
+
}
|
|
41
|
+
if (res?.data?.failed === "true") {
|
|
42
|
+
this.stream.emit("error", null);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} finally {
|
|
46
|
+
this.closed = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { StreamServicePoller };
|
|
52
|
+
//# sourceMappingURL=StreamServicePoller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamServicePoller.js","sources":["../../src/stream/StreamServicePoller.ts"],"sourcesContent":["import { ApiaApi, makeApiaUrl } from '@apia/api';\nimport { ResponseStream, ResponseStreamEvents } from './ResponseStream';\nimport { decodeBase64ToUtf8 } from '@apia/util';\n\nexport type PollRepsonse = {\n closed: string;\n part: string;\n failed: string;\n};\n\nexport type PollerEvents = ResponseStreamEvents & { close: null; error: null };\n\nexport class StreamServicePoller {\n closed = true;\n stream = new ResponseStream<PollerEvents>();\n\n on<K extends keyof PollerEvents>(\n ev: K,\n cb: (ev: PollerEvents[K]) => unknown,\n ) {\n return this.stream.on(ev, cb);\n }\n\n async start(token: string) {\n this.closed = false;\n try {\n while (!this.closed) {\n const res = await ApiaApi.post<PollRepsonse>(\n makeApiaUrl({\n ajaxUrl: 'apia.execution.StreamAction.run',\n action: 'poll',\n streamToken: token,\n }),\n );\n if (!res) {\n this.closed = true;\n this.stream.emit('error', null);\n }\n\n if (res?.data?.part) {\n this.stream.emit('part', decodeBase64ToUtf8(res.data.part));\n }\n\n if (res?.data?.closed === 'true') {\n this.closed = true;\n this.stream.emit('close', null);\n }\n\n if (res?.data?.failed === 'true') {\n this.stream.emit('error', null);\n }\n }\n } finally {\n this.closed = true;\n }\n }\n}\n\n/*\nussage:\n\nconst poller = new StreamServicePoller();\n\npoller.on('block', (block) => {\n console.log({ block });\n });\n poller.on('part', (part) => {\n console.log({ part });\n });\n poller.on('close', () => {\n console.log('Terminé de stemear!');\n });\n \n poller.start('mytokenquerecibidelserver');\n*/\n"],"names":[],"mappings":";;;;;;;;;;AAYO,MAAM,mBAAA,CAAoB;AAAA,EAA1B,WAAA,GAAA;AACL,IAAA,aAAA,CAAA,IAAA,EAAA,QAAA,EAAS,IAAA,CAAA;AACT,IAAA,aAAA,CAAA,IAAA,EAAA,QAAA,EAAS,IAAI,cAAA,EAA6B,CAAA;AAAA;AAAA,EAE1C,EAAA,CACE,IACA,EAAA,EACA;AACA,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,EAAA,CAAG,EAAA,EAAI,EAAE,CAAA;AAAA;AAC9B,EAEA,MAAM,MAAM,KAAA,EAAe;AACzB,IAAA,IAAA,CAAK,MAAA,GAAS,KAAA;AACd,IAAA,IAAI;AACF,MAAA,OAAO,CAAC,KAAK,MAAA,EAAQ;AACnB,QAAA,MAAM,GAAA,GAAM,MAAM,OAAA,CAAQ,IAAA;AAAA,UACxB,WAAA,CAAY;AAAA,YACV,OAAA,EAAS,iCAAA;AAAA,YACT,MAAA,EAAQ,MAAA;AAAA,YACR,WAAA,EAAa;AAAA,WACd;AAAA,SACH;AACA,QAAA,IAAI,CAAC,GAAA,EAAK;AACR,UAAA,IAAA,CAAK,MAAA,GAAS,IAAA;AACd,UAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,OAAA,EAAS,IAAI,CAAA;AAAA;AAGhC,QAAA,IAAI,GAAA,EAAK,MAAM,IAAA,EAAM;AACnB,UAAA,IAAA,CAAK,OAAO,IAAA,CAAK,MAAA,EAAQ,mBAAmB,GAAA,CAAI,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA;AAG5D,QAAA,IAAI,GAAA,EAAK,IAAA,EAAM,MAAA,KAAW,MAAA,EAAQ;AAChC,UAAA,IAAA,CAAK,MAAA,GAAS,IAAA;AACd,UAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,OAAA,EAAS,IAAI,CAAA;AAAA;AAGhC,QAAA,IAAI,GAAA,EAAK,IAAA,EAAM,MAAA,KAAW,MAAA,EAAQ;AAChC,UAAA,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,OAAA,EAAS,IAAI,CAAA;AAAA;AAChC;AACF,KACF,SAAE;AACA,MAAA,IAAA,CAAK,MAAA,GAAS,IAAA;AAAA;AAChB;AAEJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apia/ai",
|
|
3
|
-
"
|
|
4
|
-
"version": "4.0.102",
|
|
3
|
+
"version": "5.0.1",
|
|
5
4
|
"sideEffects": false,
|
|
6
5
|
"author": "Alexis Leite <alexisleite@live.com>",
|
|
7
6
|
"main": "dist/index.js",
|
|
@@ -16,11 +15,12 @@
|
|
|
16
15
|
"libWatchForDashboards": "rollup --watch --config ../../config/rollup.common.mjs --environment MODE:development,ENTRY:index.ts,WATCH:true,DEV_SERVER_MODULE:dashboards"
|
|
17
16
|
},
|
|
18
17
|
"dependencies": {
|
|
19
|
-
"@apia/api": "^
|
|
20
|
-
"@apia/components": "^
|
|
21
|
-
"@apia/dashboard-controller": "^
|
|
22
|
-
"@apia/
|
|
23
|
-
"@apia/
|
|
18
|
+
"@apia/api": "^5.0.1",
|
|
19
|
+
"@apia/components": "^5.0.1",
|
|
20
|
+
"@apia/dashboard-controller": "^5.0.1",
|
|
21
|
+
"@apia/icons": "^5.0.1",
|
|
22
|
+
"@apia/theme": "^5.0.1",
|
|
23
|
+
"@apia/util": "^5.0.1",
|
|
24
24
|
"mobx": "6.12.3",
|
|
25
25
|
"mobx-react-lite": "3.4.3"
|
|
26
26
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"access": "public",
|
|
42
42
|
"registry": "https://registry.npmjs.org/"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "6d9a616690ac8454136310af79a721a8ccd6588d"
|
|
45
45
|
}
|