@ekairos/story 1.6.2 → 1.6.3
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/agent.d.ts +72 -72
- package/dist/agent.js +478 -478
- package/dist/document-parser.d.ts +15 -15
- package/dist/document-parser.js +156 -156
- package/dist/engine.d.ts +21 -21
- package/dist/engine.js +35 -35
- package/dist/events.d.ts +27 -27
- package/dist/events.js +203 -203
- package/dist/index.d.ts +11 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -52
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +107 -107
- package/dist/schema.js +63 -63
- package/dist/service.d.ts +44 -44
- package/dist/service.js +202 -202
- package/dist/steps/ai.d.ts +42 -42
- package/dist/steps/ai.js +135 -135
- package/dist/steps/base.d.ts +13 -13
- package/dist/steps/base.js +36 -36
- package/dist/steps/index.d.ts +3 -4
- package/dist/steps/index.d.ts.map +1 -1
- package/dist/steps/index.js +19 -20
- package/dist/steps/index.js.map +1 -1
- package/dist/steps/registry.d.ts +4 -4
- package/dist/steps/registry.js +28 -28
- package/dist/steps/sampleStep.d.ts.map +1 -1
- package/dist/steps/sampleStep.js +1 -1
- package/dist/steps/sampleStep.js.map +1 -1
- package/dist/steps-context.d.ts +11 -11
- package/dist/steps-context.js +19 -19
- package/dist/story.d.ts +49 -49
- package/dist/story.js +54 -54
- package/dist/storyEngine.d.ts +54 -54
- package/dist/storyEngine.js +50 -50
- package/dist/storyRunner.d.ts +7 -7
- package/dist/storyRunner.js +55 -55
- package/dist/workflows/sampleWorkflow.d.ts +5 -1
- package/dist/workflows/sampleWorkflow.d.ts.map +1 -1
- package/dist/workflows/sampleWorkflow.js +6 -2
- package/dist/workflows/sampleWorkflow.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export interface DocumentToProcess {
|
|
2
|
-
buffer: Buffer;
|
|
3
|
-
fileName: string;
|
|
4
|
-
path: string;
|
|
5
|
-
fileId: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Procesa un documento utilizando LlamaParse y almacena el resultado en la base de datos
|
|
9
|
-
*/
|
|
10
|
-
export declare function parseAndStoreDocument(db: any, buffer: Buffer, fileName: string, path: string, fileId: string): Promise<string>;
|
|
11
|
-
/**
|
|
12
|
-
* Procesa un conjunto de documentos en segundo plano
|
|
13
|
-
* Puede ser utilizado con after() en Next.js o en cualquier contexto de procesamiento asíncrono
|
|
14
|
-
*/
|
|
15
|
-
export declare function processBatchDocuments(db: any, documents: DocumentToProcess[]): Promise<string[]>;
|
|
1
|
+
export interface DocumentToProcess {
|
|
2
|
+
buffer: Buffer;
|
|
3
|
+
fileName: string;
|
|
4
|
+
path: string;
|
|
5
|
+
fileId: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Procesa un documento utilizando LlamaParse y almacena el resultado en la base de datos
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseAndStoreDocument(db: any, buffer: Buffer, fileName: string, path: string, fileId: string): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Procesa un conjunto de documentos en segundo plano
|
|
13
|
+
* Puede ser utilizado con after() en Next.js o en cualquier contexto de procesamiento asíncrono
|
|
14
|
+
*/
|
|
15
|
+
export declare function processBatchDocuments(db: any, documents: DocumentToProcess[]): Promise<string[]>;
|
|
16
16
|
//# sourceMappingURL=document-parser.d.ts.map
|
package/dist/document-parser.js
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseAndStoreDocument = parseAndStoreDocument;
|
|
4
|
-
exports.processBatchDocuments = processBatchDocuments;
|
|
5
|
-
const admin_1 = require("@instantdb/admin");
|
|
6
|
-
const LLAMA_CLOUD_BASE_URL = 'https://api.cloud.llamaindex.ai/api/v1';
|
|
7
|
-
/**
|
|
8
|
-
* Sube un archivo a LlamaCloud para procesamiento
|
|
9
|
-
*/
|
|
10
|
-
async function uploadToLlamaCloud(buffer, fileName) {
|
|
11
|
-
const formData = new FormData();
|
|
12
|
-
const uint8Array = new Uint8Array(buffer);
|
|
13
|
-
const blob = new Blob([uint8Array], { type: 'application/pdf' });
|
|
14
|
-
formData.append('file', blob, fileName);
|
|
15
|
-
formData.append('parse_mode', 'parse_page_with_llm');
|
|
16
|
-
formData.append('high_res_ocr', 'true');
|
|
17
|
-
formData.append('adaptive_long_table', 'true');
|
|
18
|
-
formData.append('outlined_table_extraction', 'true');
|
|
19
|
-
formData.append('output_tables_as_HTML', 'true');
|
|
20
|
-
const response = await fetch(`${LLAMA_CLOUD_BASE_URL}/parsing/upload`, {
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers: {
|
|
23
|
-
'Authorization': `Bearer ${process.env.LLAMA_CLOUD_API_KEY}`,
|
|
24
|
-
},
|
|
25
|
-
body: formData
|
|
26
|
-
});
|
|
27
|
-
if (!response.ok) {
|
|
28
|
-
const errorText = await response.text();
|
|
29
|
-
throw new Error(`LlamaCloud upload failed: ${response.status} ${errorText}`);
|
|
30
|
-
}
|
|
31
|
-
const result = await response.json();
|
|
32
|
-
return result.id;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Obtiene el estado del job de procesamiento
|
|
36
|
-
*/
|
|
37
|
-
async function getJobStatus(jobId) {
|
|
38
|
-
const response = await fetch(`${LLAMA_CLOUD_BASE_URL}/parsing/job/${jobId}`, {
|
|
39
|
-
method: 'GET',
|
|
40
|
-
headers: {
|
|
41
|
-
'Authorization': `Bearer ${process.env.LLAMA_CLOUD_API_KEY}`,
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
const errorText = await response.text();
|
|
46
|
-
throw new Error(`LlamaCloud status fetch failed: ${response.status} ${errorText}`);
|
|
47
|
-
}
|
|
48
|
-
return await response.json();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Obtiene el resultado del procesamiento de LlamaCloud
|
|
52
|
-
*/
|
|
53
|
-
async function getParseResult(jobId) {
|
|
54
|
-
const response = await fetch(`${LLAMA_CLOUD_BASE_URL}/parsing/job/${jobId}/result/markdown`, {
|
|
55
|
-
method: 'GET',
|
|
56
|
-
headers: {
|
|
57
|
-
'Authorization': `Bearer ${process.env.LLAMA_CLOUD_API_KEY}`,
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
if (!response.ok) {
|
|
61
|
-
const errorText = await response.text();
|
|
62
|
-
throw new Error(`LlamaCloud result fetch failed: ${response.status} ${errorText}`);
|
|
63
|
-
}
|
|
64
|
-
return await response.json();
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Espera hasta que el procesamiento esté completo
|
|
68
|
-
*/
|
|
69
|
-
async function waitForProcessing(jobId, maxAttempts = 60) {
|
|
70
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
71
|
-
const statusResponse = await getJobStatus(jobId);
|
|
72
|
-
console.log(`Job ${jobId} status: ${statusResponse.status} (attempt ${attempt + 1}/${maxAttempts})`);
|
|
73
|
-
if (statusResponse.status === 'SUCCESS' || statusResponse.status === 'COMPLETED') {
|
|
74
|
-
return await getParseResult(jobId);
|
|
75
|
-
}
|
|
76
|
-
if (statusResponse.status === 'ERROR' || statusResponse.status === 'FAILED') {
|
|
77
|
-
throw new Error(`LlamaCloud processing failed with status: ${statusResponse.status}`);
|
|
78
|
-
}
|
|
79
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
80
|
-
}
|
|
81
|
-
throw new Error('LlamaCloud processing timeout');
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Procesa un documento utilizando LlamaParse y almacena el resultado en la base de datos
|
|
85
|
-
*/
|
|
86
|
-
async function parseAndStoreDocument(db, buffer, fileName, path, fileId) {
|
|
87
|
-
try {
|
|
88
|
-
const existingDocument = await db.query({
|
|
89
|
-
documents: {
|
|
90
|
-
$: {
|
|
91
|
-
where: { 'file.id': fileId }
|
|
92
|
-
},
|
|
93
|
-
file: {}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
if (existingDocument.documents && existingDocument.documents.length > 0) {
|
|
97
|
-
const docId = existingDocument.documents[0].id;
|
|
98
|
-
console.log(`Documento ya existe para el archivo ${fileName}: ${docId}`);
|
|
99
|
-
return docId;
|
|
100
|
-
}
|
|
101
|
-
console.log(`Procesando nuevo documento: ${fileName}`);
|
|
102
|
-
const jobId = await uploadToLlamaCloud(buffer, fileName);
|
|
103
|
-
console.log(`Documento subido a LlamaCloud con job ID: ${jobId}`);
|
|
104
|
-
const result = await waitForProcessing(jobId);
|
|
105
|
-
const pages = [];
|
|
106
|
-
if (result.markdown) {
|
|
107
|
-
pages.push({
|
|
108
|
-
id: (0, admin_1.id)(),
|
|
109
|
-
text: result.markdown
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (result.pages && result.pages.length > 0) {
|
|
113
|
-
for (const page of result.pages) {
|
|
114
|
-
pages.push({
|
|
115
|
-
id: (0, admin_1.id)(),
|
|
116
|
-
text: page.text
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (pages.length === 0) {
|
|
121
|
-
throw new Error('No se pudo extraer contenido del documento');
|
|
122
|
-
}
|
|
123
|
-
const documentId = (0, admin_1.id)();
|
|
124
|
-
await db.transact([
|
|
125
|
-
db.tx.documents[documentId].update({
|
|
126
|
-
content: { pages },
|
|
127
|
-
processedAt: new Date().toISOString()
|
|
128
|
-
}),
|
|
129
|
-
db.tx.documents[documentId].link({
|
|
130
|
-
file: fileId
|
|
131
|
-
})
|
|
132
|
-
]);
|
|
133
|
-
console.log(`Documento procesado con éxito: ${fileName} -> ${documentId}`);
|
|
134
|
-
return documentId;
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
console.error(`Error al procesar el documento ${fileName}:`, error);
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Procesa un conjunto de documentos en segundo plano
|
|
143
|
-
* Puede ser utilizado con after() en Next.js o en cualquier contexto de procesamiento asíncrono
|
|
144
|
-
*/
|
|
145
|
-
async function processBatchDocuments(db, documents) {
|
|
146
|
-
try {
|
|
147
|
-
const promises = documents.map(doc => parseAndStoreDocument(db, doc.buffer, doc.fileName, doc.path, doc.fileId));
|
|
148
|
-
const results = await Promise.all(promises);
|
|
149
|
-
console.log('Todos los documentos procesados correctamente');
|
|
150
|
-
return results;
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
console.error('Error en el procesamiento por lotes de documentos:', error);
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAndStoreDocument = parseAndStoreDocument;
|
|
4
|
+
exports.processBatchDocuments = processBatchDocuments;
|
|
5
|
+
const admin_1 = require("@instantdb/admin");
|
|
6
|
+
const LLAMA_CLOUD_BASE_URL = 'https://api.cloud.llamaindex.ai/api/v1';
|
|
7
|
+
/**
|
|
8
|
+
* Sube un archivo a LlamaCloud para procesamiento
|
|
9
|
+
*/
|
|
10
|
+
async function uploadToLlamaCloud(buffer, fileName) {
|
|
11
|
+
const formData = new FormData();
|
|
12
|
+
const uint8Array = new Uint8Array(buffer);
|
|
13
|
+
const blob = new Blob([uint8Array], { type: 'application/pdf' });
|
|
14
|
+
formData.append('file', blob, fileName);
|
|
15
|
+
formData.append('parse_mode', 'parse_page_with_llm');
|
|
16
|
+
formData.append('high_res_ocr', 'true');
|
|
17
|
+
formData.append('adaptive_long_table', 'true');
|
|
18
|
+
formData.append('outlined_table_extraction', 'true');
|
|
19
|
+
formData.append('output_tables_as_HTML', 'true');
|
|
20
|
+
const response = await fetch(`${LLAMA_CLOUD_BASE_URL}/parsing/upload`, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: {
|
|
23
|
+
'Authorization': `Bearer ${process.env.LLAMA_CLOUD_API_KEY}`,
|
|
24
|
+
},
|
|
25
|
+
body: formData
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const errorText = await response.text();
|
|
29
|
+
throw new Error(`LlamaCloud upload failed: ${response.status} ${errorText}`);
|
|
30
|
+
}
|
|
31
|
+
const result = await response.json();
|
|
32
|
+
return result.id;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Obtiene el estado del job de procesamiento
|
|
36
|
+
*/
|
|
37
|
+
async function getJobStatus(jobId) {
|
|
38
|
+
const response = await fetch(`${LLAMA_CLOUD_BASE_URL}/parsing/job/${jobId}`, {
|
|
39
|
+
method: 'GET',
|
|
40
|
+
headers: {
|
|
41
|
+
'Authorization': `Bearer ${process.env.LLAMA_CLOUD_API_KEY}`,
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
const errorText = await response.text();
|
|
46
|
+
throw new Error(`LlamaCloud status fetch failed: ${response.status} ${errorText}`);
|
|
47
|
+
}
|
|
48
|
+
return await response.json();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Obtiene el resultado del procesamiento de LlamaCloud
|
|
52
|
+
*/
|
|
53
|
+
async function getParseResult(jobId) {
|
|
54
|
+
const response = await fetch(`${LLAMA_CLOUD_BASE_URL}/parsing/job/${jobId}/result/markdown`, {
|
|
55
|
+
method: 'GET',
|
|
56
|
+
headers: {
|
|
57
|
+
'Authorization': `Bearer ${process.env.LLAMA_CLOUD_API_KEY}`,
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
const errorText = await response.text();
|
|
62
|
+
throw new Error(`LlamaCloud result fetch failed: ${response.status} ${errorText}`);
|
|
63
|
+
}
|
|
64
|
+
return await response.json();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Espera hasta que el procesamiento esté completo
|
|
68
|
+
*/
|
|
69
|
+
async function waitForProcessing(jobId, maxAttempts = 60) {
|
|
70
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
71
|
+
const statusResponse = await getJobStatus(jobId);
|
|
72
|
+
console.log(`Job ${jobId} status: ${statusResponse.status} (attempt ${attempt + 1}/${maxAttempts})`);
|
|
73
|
+
if (statusResponse.status === 'SUCCESS' || statusResponse.status === 'COMPLETED') {
|
|
74
|
+
return await getParseResult(jobId);
|
|
75
|
+
}
|
|
76
|
+
if (statusResponse.status === 'ERROR' || statusResponse.status === 'FAILED') {
|
|
77
|
+
throw new Error(`LlamaCloud processing failed with status: ${statusResponse.status}`);
|
|
78
|
+
}
|
|
79
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
80
|
+
}
|
|
81
|
+
throw new Error('LlamaCloud processing timeout');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Procesa un documento utilizando LlamaParse y almacena el resultado en la base de datos
|
|
85
|
+
*/
|
|
86
|
+
async function parseAndStoreDocument(db, buffer, fileName, path, fileId) {
|
|
87
|
+
try {
|
|
88
|
+
const existingDocument = await db.query({
|
|
89
|
+
documents: {
|
|
90
|
+
$: {
|
|
91
|
+
where: { 'file.id': fileId }
|
|
92
|
+
},
|
|
93
|
+
file: {}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
if (existingDocument.documents && existingDocument.documents.length > 0) {
|
|
97
|
+
const docId = existingDocument.documents[0].id;
|
|
98
|
+
console.log(`Documento ya existe para el archivo ${fileName}: ${docId}`);
|
|
99
|
+
return docId;
|
|
100
|
+
}
|
|
101
|
+
console.log(`Procesando nuevo documento: ${fileName}`);
|
|
102
|
+
const jobId = await uploadToLlamaCloud(buffer, fileName);
|
|
103
|
+
console.log(`Documento subido a LlamaCloud con job ID: ${jobId}`);
|
|
104
|
+
const result = await waitForProcessing(jobId);
|
|
105
|
+
const pages = [];
|
|
106
|
+
if (result.markdown) {
|
|
107
|
+
pages.push({
|
|
108
|
+
id: (0, admin_1.id)(),
|
|
109
|
+
text: result.markdown
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (result.pages && result.pages.length > 0) {
|
|
113
|
+
for (const page of result.pages) {
|
|
114
|
+
pages.push({
|
|
115
|
+
id: (0, admin_1.id)(),
|
|
116
|
+
text: page.text
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (pages.length === 0) {
|
|
121
|
+
throw new Error('No se pudo extraer contenido del documento');
|
|
122
|
+
}
|
|
123
|
+
const documentId = (0, admin_1.id)();
|
|
124
|
+
await db.transact([
|
|
125
|
+
db.tx.documents[documentId].update({
|
|
126
|
+
content: { pages },
|
|
127
|
+
processedAt: new Date().toISOString()
|
|
128
|
+
}),
|
|
129
|
+
db.tx.documents[documentId].link({
|
|
130
|
+
file: fileId
|
|
131
|
+
})
|
|
132
|
+
]);
|
|
133
|
+
console.log(`Documento procesado con éxito: ${fileName} -> ${documentId}`);
|
|
134
|
+
return documentId;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error(`Error al procesar el documento ${fileName}:`, error);
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Procesa un conjunto de documentos en segundo plano
|
|
143
|
+
* Puede ser utilizado con after() en Next.js o en cualquier contexto de procesamiento asíncrono
|
|
144
|
+
*/
|
|
145
|
+
async function processBatchDocuments(db, documents) {
|
|
146
|
+
try {
|
|
147
|
+
const promises = documents.map(doc => parseAndStoreDocument(db, doc.buffer, doc.fileName, doc.path, doc.fileId));
|
|
148
|
+
const results = await Promise.all(promises);
|
|
149
|
+
console.log('Todos los documentos procesados correctamente');
|
|
150
|
+
return results;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
console.error('Error en el procesamiento por lotes de documentos:', error);
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
157
|
//# sourceMappingURL=document-parser.js.map
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export declare function evaluateToolCallsStep(params: {
|
|
2
|
-
storyKey: string;
|
|
3
|
-
toolCalls: Array<{
|
|
4
|
-
toolCallId: string;
|
|
5
|
-
toolName: string;
|
|
6
|
-
args: any;
|
|
7
|
-
}>;
|
|
8
|
-
contextId: string;
|
|
9
|
-
}): Promise<{
|
|
10
|
-
success: boolean;
|
|
11
|
-
message?: string;
|
|
12
|
-
} | {
|
|
13
|
-
success: boolean;
|
|
14
|
-
message: any;
|
|
15
|
-
}>;
|
|
16
|
-
export declare function onEndStep(params: {
|
|
17
|
-
storyKey: string;
|
|
18
|
-
lastEvent: any;
|
|
19
|
-
}): Promise<{
|
|
20
|
-
end: boolean;
|
|
21
|
-
}>;
|
|
1
|
+
export declare function evaluateToolCallsStep(params: {
|
|
2
|
+
storyKey: string;
|
|
3
|
+
toolCalls: Array<{
|
|
4
|
+
toolCallId: string;
|
|
5
|
+
toolName: string;
|
|
6
|
+
args: any;
|
|
7
|
+
}>;
|
|
8
|
+
contextId: string;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
success: boolean;
|
|
11
|
+
message?: string;
|
|
12
|
+
} | {
|
|
13
|
+
success: boolean;
|
|
14
|
+
message: any;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function onEndStep(params: {
|
|
17
|
+
storyKey: string;
|
|
18
|
+
lastEvent: any;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
end: boolean;
|
|
21
|
+
}>;
|
|
22
22
|
//# sourceMappingURL=engine.d.ts.map
|
package/dist/engine.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateToolCallsStep = evaluateToolCallsStep;
|
|
4
|
-
exports.onEndStep = onEndStep;
|
|
5
|
-
const storyEngine_1 = require("./storyEngine");
|
|
6
|
-
async function evaluateToolCallsStep(params) {
|
|
7
|
-
"use step";
|
|
8
|
-
try {
|
|
9
|
-
const rt = storyEngine_1.engine.get(params.storyKey);
|
|
10
|
-
if (!rt?.callbacks?.evaluateToolCalls)
|
|
11
|
-
return { success: true };
|
|
12
|
-
return await rt.callbacks.evaluateToolCalls(params.toolCalls);
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
return { success: false, message: error?.message ?? String(error) };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async function onEndStep(params) {
|
|
19
|
-
"use step";
|
|
20
|
-
try {
|
|
21
|
-
const rt = storyEngine_1.engine.get(params.storyKey);
|
|
22
|
-
if (!rt?.callbacks?.onEnd)
|
|
23
|
-
return { end: true };
|
|
24
|
-
const result = await rt.callbacks.onEnd(params.lastEvent);
|
|
25
|
-
if (typeof result === "boolean")
|
|
26
|
-
return { end: result };
|
|
27
|
-
if (result && typeof result === "object" && Object.prototype.hasOwnProperty.call(result, "end")) {
|
|
28
|
-
return { end: Boolean(result.end) };
|
|
29
|
-
}
|
|
30
|
-
return { end: true };
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return { end: true };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateToolCallsStep = evaluateToolCallsStep;
|
|
4
|
+
exports.onEndStep = onEndStep;
|
|
5
|
+
const storyEngine_1 = require("./storyEngine");
|
|
6
|
+
async function evaluateToolCallsStep(params) {
|
|
7
|
+
"use step";
|
|
8
|
+
try {
|
|
9
|
+
const rt = storyEngine_1.engine.get(params.storyKey);
|
|
10
|
+
if (!rt?.callbacks?.evaluateToolCalls)
|
|
11
|
+
return { success: true };
|
|
12
|
+
return await rt.callbacks.evaluateToolCalls(params.toolCalls);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
return { success: false, message: error?.message ?? String(error) };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function onEndStep(params) {
|
|
19
|
+
"use step";
|
|
20
|
+
try {
|
|
21
|
+
const rt = storyEngine_1.engine.get(params.storyKey);
|
|
22
|
+
if (!rt?.callbacks?.onEnd)
|
|
23
|
+
return { end: true };
|
|
24
|
+
const result = await rt.callbacks.onEnd(params.lastEvent);
|
|
25
|
+
if (typeof result === "boolean")
|
|
26
|
+
return { end: result };
|
|
27
|
+
if (result && typeof result === "object" && Object.prototype.hasOwnProperty.call(result, "end")) {
|
|
28
|
+
return { end: Boolean(result.end) };
|
|
29
|
+
}
|
|
30
|
+
return { end: true };
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return { end: true };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
36
|
//# sourceMappingURL=engine.js.map
|
package/dist/events.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { type ModelMessage, type UIMessage } from "ai";
|
|
2
|
-
import type { ContextEvent } from "./service";
|
|
3
|
-
export declare const USER_MESSAGE_TYPE = "user.message";
|
|
4
|
-
export declare const ASSISTANT_MESSAGE_TYPE = "assistant.message";
|
|
5
|
-
export declare const SYSTEM_MESSAGE_TYPE = "system.message";
|
|
6
|
-
export declare const WEB_CHANNEL = "web";
|
|
7
|
-
export declare const AGENT_CHANNEL = "whatsapp";
|
|
8
|
-
export declare const EMAIL_CHANNEL = "email";
|
|
9
|
-
export declare function createUserEventFromUIMessages(messages: UIMessage[]): ContextEvent;
|
|
10
|
-
export declare function createAssistantEventFromUIMessages(eventId: string, messages: UIMessage[]): ContextEvent;
|
|
11
|
-
export declare function convertToUIMessage(event: ContextEvent): UIMessage;
|
|
12
|
-
export declare function convertEventsToModelMessages(events: ContextEvent[]): Promise<ModelMessage[]>;
|
|
13
|
-
export declare function convertEventToModelMessages(event: ContextEvent): Promise<ModelMessage[]>;
|
|
14
|
-
export type AIMessage = {
|
|
15
|
-
id: string;
|
|
16
|
-
role: "user" | "assistant" | "system";
|
|
17
|
-
content: string;
|
|
18
|
-
createdAt: Date;
|
|
19
|
-
};
|
|
20
|
-
export type ResponseMessage = {
|
|
21
|
-
id: string;
|
|
22
|
-
timestamp: Date;
|
|
23
|
-
modelId: string;
|
|
24
|
-
headers?: Record<string, string>;
|
|
25
|
-
message: ModelMessage;
|
|
26
|
-
};
|
|
27
|
-
export declare function convertModelMessageToEvent(eventId: string, message: ResponseMessage): ContextEvent;
|
|
1
|
+
import { type ModelMessage, type UIMessage } from "ai";
|
|
2
|
+
import type { ContextEvent } from "./service";
|
|
3
|
+
export declare const USER_MESSAGE_TYPE = "user.message";
|
|
4
|
+
export declare const ASSISTANT_MESSAGE_TYPE = "assistant.message";
|
|
5
|
+
export declare const SYSTEM_MESSAGE_TYPE = "system.message";
|
|
6
|
+
export declare const WEB_CHANNEL = "web";
|
|
7
|
+
export declare const AGENT_CHANNEL = "whatsapp";
|
|
8
|
+
export declare const EMAIL_CHANNEL = "email";
|
|
9
|
+
export declare function createUserEventFromUIMessages(messages: UIMessage[]): ContextEvent;
|
|
10
|
+
export declare function createAssistantEventFromUIMessages(eventId: string, messages: UIMessage[]): ContextEvent;
|
|
11
|
+
export declare function convertToUIMessage(event: ContextEvent): UIMessage;
|
|
12
|
+
export declare function convertEventsToModelMessages(events: ContextEvent[]): Promise<ModelMessage[]>;
|
|
13
|
+
export declare function convertEventToModelMessages(event: ContextEvent): Promise<ModelMessage[]>;
|
|
14
|
+
export type AIMessage = {
|
|
15
|
+
id: string;
|
|
16
|
+
role: "user" | "assistant" | "system";
|
|
17
|
+
content: string;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
};
|
|
20
|
+
export type ResponseMessage = {
|
|
21
|
+
id: string;
|
|
22
|
+
timestamp: Date;
|
|
23
|
+
modelId: string;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
message: ModelMessage;
|
|
26
|
+
};
|
|
27
|
+
export declare function convertModelMessageToEvent(eventId: string, message: ResponseMessage): ContextEvent;
|
|
28
28
|
//# sourceMappingURL=events.d.ts.map
|