@runflow-ai/sdk 1.0.7 → 1.0.8
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/core/agent.d.ts +20 -0
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +165 -25
- package/dist/core/agent.js.map +1 -1
- package/dist/core/api-client.js +1 -1
- package/dist/core/api-client.js.map +1 -1
- package/dist/core/context.d.ts +108 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +148 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/models.d.ts +1 -0
- package/dist/core/models.d.ts.map +1 -1
- package/dist/core/models.js +7 -0
- package/dist/core/models.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/dist/knowledge/index.d.ts +4 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +8 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/knowledge-manager.d.ts +54 -0
- package/dist/knowledge/knowledge-manager.d.ts.map +1 -0
- package/dist/knowledge/knowledge-manager.js +139 -0
- package/dist/knowledge/knowledge-manager.js.map +1 -0
- package/dist/llm/index.d.ts +3 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +7 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/llm-manager.d.ts +47 -0
- package/dist/llm/llm-manager.d.ts.map +1 -0
- package/dist/llm/llm-manager.js +177 -0
- package/dist/llm/llm-manager.js.map +1 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +5 -2
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/memory-manager.d.ts +81 -0
- package/dist/memory/memory-manager.d.ts.map +1 -0
- package/dist/memory/memory-manager.js +193 -0
- package/dist/memory/memory-manager.js.map +1 -0
- package/dist/observability/trace-collector.d.ts +19 -0
- package/dist/observability/trace-collector.d.ts.map +1 -1
- package/dist/observability/trace-collector.js +122 -7
- package/dist/observability/trace-collector.js.map +1 -1
- package/dist/providers/index.d.ts +10 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +14 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/runflow/memory-provider.d.ts +21 -0
- package/dist/providers/runflow/memory-provider.d.ts.map +1 -0
- package/dist/providers/runflow/memory-provider.js +33 -0
- package/dist/providers/runflow/memory-provider.js.map +1 -0
- package/dist/providers/types.d.ts +107 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +11 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/types/all-types.d.ts +26 -4
- package/dist/types/all-types.d.ts.map +1 -1
- package/package.json +22 -2
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* RUNFLOW CONTEXT - Global State for Execution
|
|
5
|
+
* ============================================================================
|
|
6
|
+
*
|
|
7
|
+
* Singleton que mantém contexto global da execução no worker thread.
|
|
8
|
+
* Permite que desenvolvedores identifiquem a execução uma vez e todos os
|
|
9
|
+
* agentes/workflows usam automaticamente.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Runflow = void 0;
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// RUNFLOW CONTEXT CLASS
|
|
15
|
+
// ============================================================================
|
|
16
|
+
class RunflowContext {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.state = {};
|
|
19
|
+
// Private constructor para singleton
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get singleton instance
|
|
23
|
+
*/
|
|
24
|
+
static getInstance() {
|
|
25
|
+
if (!RunflowContext.instance) {
|
|
26
|
+
RunflowContext.instance = new RunflowContext();
|
|
27
|
+
}
|
|
28
|
+
return RunflowContext.instance;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Identify execution (método principal - 99% dos casos)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // WhatsApp
|
|
35
|
+
* Runflow.identify({ type: 'phone', value: '+5511999999999' });
|
|
36
|
+
*
|
|
37
|
+
* // Email
|
|
38
|
+
* Runflow.identify({ type: 'email', value: 'user@example.com' });
|
|
39
|
+
*
|
|
40
|
+
* // HubSpot
|
|
41
|
+
* Runflow.identify({
|
|
42
|
+
* type: 'hubspot_contact',
|
|
43
|
+
* value: 'contact_123',
|
|
44
|
+
* userId: 'user@example.com'
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Custom
|
|
48
|
+
* Runflow.identify({
|
|
49
|
+
* type: 'order',
|
|
50
|
+
* value: 'order_456',
|
|
51
|
+
* userId: 'customer_789'
|
|
52
|
+
* });
|
|
53
|
+
*/
|
|
54
|
+
identify(config) {
|
|
55
|
+
const threadId = config.threadId || this.generateThreadId(config.type, config.value);
|
|
56
|
+
this.setState({
|
|
57
|
+
entityType: config.type,
|
|
58
|
+
entityValue: config.value,
|
|
59
|
+
userId: config.userId || config.value,
|
|
60
|
+
threadId,
|
|
61
|
+
});
|
|
62
|
+
console.log(`🔍 [Runflow] Identified:`, {
|
|
63
|
+
type: config.type,
|
|
64
|
+
value: config.value,
|
|
65
|
+
threadId,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Set state customizado (avançado - 1% dos casos)
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* Runflow.setState({
|
|
73
|
+
* entityType: 'custom',
|
|
74
|
+
* entityValue: 'xyz',
|
|
75
|
+
* threadId: 'my_custom_thread_123',
|
|
76
|
+
* userId: 'user_123',
|
|
77
|
+
* metadata: { custom: 'data' }
|
|
78
|
+
* });
|
|
79
|
+
*/
|
|
80
|
+
setState(state) {
|
|
81
|
+
this.state = { ...this.state, ...state };
|
|
82
|
+
console.log('🔧 [Runflow] State updated');
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get complete state
|
|
86
|
+
*/
|
|
87
|
+
getState() {
|
|
88
|
+
return { ...this.state };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get specific value from state
|
|
92
|
+
*/
|
|
93
|
+
get(key) {
|
|
94
|
+
return this.state[key];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Clear state (útil para testes)
|
|
98
|
+
*/
|
|
99
|
+
clearState() {
|
|
100
|
+
this.state = {};
|
|
101
|
+
console.log('🧹 [Runflow] State cleared');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Initialize from environment variables (auto-chamado quando SDK é importado)
|
|
105
|
+
*/
|
|
106
|
+
initFromEnvironment() {
|
|
107
|
+
if (process.env.RUNFLOW_EXECUTION_ID) {
|
|
108
|
+
this.state.executionId = process.env.RUNFLOW_EXECUTION_ID;
|
|
109
|
+
}
|
|
110
|
+
if (process.env.RUNFLOW_THREAD_ID) {
|
|
111
|
+
this.state.threadId = process.env.RUNFLOW_THREAD_ID;
|
|
112
|
+
}
|
|
113
|
+
if (process.env.RUNFLOW_TENANT_ID) {
|
|
114
|
+
this.state.companyId = process.env.RUNFLOW_TENANT_ID;
|
|
115
|
+
}
|
|
116
|
+
if (Object.keys(this.state).length > 0) {
|
|
117
|
+
console.log('🌍 [Runflow] Initialized from environment:', Object.keys(this.state));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Generate threadId baseado no tipo e valor
|
|
122
|
+
*/
|
|
123
|
+
generateThreadId(type, value) {
|
|
124
|
+
const companyId = this.state.companyId || 'default';
|
|
125
|
+
const cleanValue = value.replace(/[^a-zA-Z0-9]/g, '_'); // Sanitize
|
|
126
|
+
return `${type}_${companyId}_${cleanValue}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// ============================================================================
|
|
130
|
+
// EXPORT SINGLETON INSTANCE
|
|
131
|
+
// ============================================================================
|
|
132
|
+
/**
|
|
133
|
+
* Runflow singleton - Use para identificar execuções e manter estado global
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* import { Runflow } from '@runflow-ai/sdk/core';
|
|
137
|
+
*
|
|
138
|
+
* // Identificar por telefone
|
|
139
|
+
* Runflow.identify({ type: 'phone', value: '+5511999999999' });
|
|
140
|
+
*
|
|
141
|
+
* // Todos os agentes/workflows usarão automaticamente
|
|
142
|
+
* const agent = new Agent({ ... });
|
|
143
|
+
* await agent.process(input); // Usa threadId automaticamente
|
|
144
|
+
*/
|
|
145
|
+
exports.Runflow = RunflowContext.getInstance();
|
|
146
|
+
// Auto-initialize from environment when SDK is imported
|
|
147
|
+
exports.Runflow.initFromEnvironment();
|
|
148
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAwBH,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E,MAAM,cAAc;IAIlB;QAFQ,UAAK,GAAiB,EAAE,CAAC;QAG/B,qCAAqC;IACvC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC7B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,QAAQ,CAAC,MAAsB;QAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,MAA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AI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;YAClC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACvD,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvC,OAAO,CAAC,GAAG,CAAC,4CAA4C,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACrF,CAAC;IACH,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,IAAY,EAAE,KAAa;QAClD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,SAAS,CAAC;QACpD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,CAAC,WAAW;QACnE,OAAO,GAAG,IAAI,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;IAC9C,CAAC;CACF;AAED,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E;;;;;;;;;;;;GAYG;AACU,QAAA,OAAO,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;AAEpD,wDAAwD;AACxD,eAAO,CAAC,mBAAmB,EAAE,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Agent } from './agent';
|
|
2
|
-
export { openai, anthropic } from './models';
|
|
2
|
+
export { openai, anthropic, bedrock } from './models';
|
|
3
3
|
export { createRunflowAPIClient, RunflowAPIClientImpl } from './api-client';
|
|
4
|
+
export { Runflow } from './context';
|
|
4
5
|
export type { AgentConfig, AgentInput, AgentOutput } from '../types';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RunflowAPIClientImpl = exports.createRunflowAPIClient = exports.anthropic = exports.openai = exports.Agent = void 0;
|
|
3
|
+
exports.Runflow = exports.RunflowAPIClientImpl = exports.createRunflowAPIClient = exports.bedrock = exports.anthropic = exports.openai = exports.Agent = void 0;
|
|
4
4
|
// Core exports
|
|
5
5
|
var agent_1 = require("./agent");
|
|
6
6
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_1.Agent; } });
|
|
7
7
|
var models_1 = require("./models");
|
|
8
8
|
Object.defineProperty(exports, "openai", { enumerable: true, get: function () { return models_1.openai; } });
|
|
9
9
|
Object.defineProperty(exports, "anthropic", { enumerable: true, get: function () { return models_1.anthropic; } });
|
|
10
|
+
Object.defineProperty(exports, "bedrock", { enumerable: true, get: function () { return models_1.bedrock; } });
|
|
10
11
|
var api_client_1 = require("./api-client");
|
|
11
12
|
Object.defineProperty(exports, "createRunflowAPIClient", { enumerable: true, get: function () { return api_client_1.createRunflowAPIClient; } });
|
|
12
13
|
Object.defineProperty(exports, "RunflowAPIClientImpl", { enumerable: true, get: function () { return api_client_1.RunflowAPIClientImpl; } });
|
|
14
|
+
var context_1 = require("./context");
|
|
15
|
+
Object.defineProperty(exports, "Runflow", { enumerable: true, get: function () { return context_1.Runflow; } });
|
|
13
16
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACf,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACf,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,mCAAsD;AAA7C,gGAAA,MAAM,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,iGAAA,OAAO,OAAA;AACnC,2CAA4E;AAAnE,oHAAA,sBAAsB,OAAA;AAAE,kHAAA,oBAAoB,OAAA;AACrD,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
|
package/dist/core/models.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ModelProvider } from '../types';
|
|
2
2
|
export declare function openai(model: string): ModelProvider;
|
|
3
3
|
export declare function anthropic(model: string): ModelProvider;
|
|
4
|
+
export declare function bedrock(model: string): ModelProvider;
|
|
4
5
|
//# sourceMappingURL=models.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/core/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAMzC,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAKnD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAKtD"}
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/core/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAMzC,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAKnD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAKtD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAKpD"}
|
package/dist/core/models.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.openai = openai;
|
|
4
4
|
exports.anthropic = anthropic;
|
|
5
|
+
exports.bedrock = bedrock;
|
|
5
6
|
// ============================================================================
|
|
6
7
|
// MODEL PROVIDERS
|
|
7
8
|
// ============================================================================
|
|
@@ -17,4 +18,10 @@ function anthropic(model) {
|
|
|
17
18
|
model,
|
|
18
19
|
};
|
|
19
20
|
}
|
|
21
|
+
function bedrock(model) {
|
|
22
|
+
return {
|
|
23
|
+
provider: 'bedrock',
|
|
24
|
+
model,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
20
27
|
//# sourceMappingURL=models.js.map
|
package/dist/core/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/core/models.ts"],"names":[],"mappings":";;AAMA,wBAKC;AAED,8BAKC;
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/core/models.ts"],"names":[],"mappings":";;AAMA,wBAKC;AAED,8BAKC;AAED,0BAKC;AAvBD,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,SAAgB,MAAM,CAAC,KAAa;IAClC,OAAO;QACL,QAAQ,EAAE,QAAQ;QAClB,KAAK;KACN,CAAC;AACJ,CAAC;AAED,SAAgB,SAAS,CAAC,KAAa;IACrC,OAAO;QACL,QAAQ,EAAE,WAAW;QACrB,KAAK;KACN,CAAC;AACJ,CAAC;AAED,SAAgB,OAAO,CAAC,KAAa;IACnC,OAAO;QACL,QAAQ,EAAE,SAAS;QACnB,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
export { Agent, openai, anthropic, createRunflowAPIClient, RunflowAPIClientImpl, } from './core';
|
|
1
|
+
export { Agent, openai, anthropic, bedrock, createRunflowAPIClient, RunflowAPIClientImpl, Runflow, } from './core';
|
|
2
2
|
export { createTool, } from './tools';
|
|
3
3
|
export { createConnectorTool, hubspot, twilio, email, slack, } from './connectors';
|
|
4
4
|
export { Workflow, WorkflowBuilder, createWorkflow, createStep, createAgentStep, createFunctionStep, createConnectorStep, } from './workflows';
|
|
5
5
|
export { RunflowTraceCollector, RunflowTraceSpan, createTraceCollector, traced, } from './observability';
|
|
6
|
-
export type { AgentConfig, AgentInput, AgentOutput, AgentContext, ModelProvider, RunflowTool, ToolConfig, ToolContext, WorkflowConfig, WorkflowStep, WorkflowContext, WorkflowExecution, MemoryConfig, MemoryData, MemoryMessage,
|
|
6
|
+
export type { AgentConfig, AgentInput, AgentOutput, AgentContext, ModelProvider, RunflowTool, ToolConfig, ToolContext, WorkflowConfig, WorkflowStep, WorkflowContext, WorkflowExecution, MemoryConfig, MemoryData, MemoryMessage, StreamingConfig, ChatStreamChunk, TraceData, TraceMetadata, TraceCosts, TraceCollector, TraceSpan, RunflowAPIClient, ChatRequest, ChatResponse, VectorSearchOptions, VectorSearchResponse, ExecutionContext, } from './types';
|
|
7
|
+
export { Memory } from './memory';
|
|
8
|
+
export type { MemoryOptions } from './memory';
|
|
9
|
+
export { Knowledge, RAG } from './knowledge';
|
|
10
|
+
export type { KnowledgeOptions, RAGOptions, HybridSearchOptions } from './knowledge';
|
|
11
|
+
export { LLM } from './llm';
|
|
12
|
+
export type { LLMConfig, LLMOptions } from './llm';
|
|
13
|
+
export type { MemoryProvider, KnowledgeProvider, LLMProvider } from './providers/types';
|
|
14
|
+
export { RunflowMemoryProvider } from './providers/runflow/memory-provider';
|
|
7
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,EACL,MAAM,EACN,SAAS,EACT,sBAAsB,EACtB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,EACL,MAAM,EACN,SAAS,EACT,OAAO,EACP,sBAAsB,EACtB,oBAAoB,EACpB,OAAO,GACR,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACL,UAAU,GACX,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,mBAAmB,EACnB,OAAO,EACP,MAAM,EACN,KAAK,EACL,KAAK,GACN,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,QAAQ,EACR,eAAe,EACf,cAAc,EACd,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,GACP,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAEV,WAAW,EACX,UAAU,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EAGb,WAAW,EACX,UAAU,EACV,WAAW,EAKX,cAAc,EACd,YAAY,EACZ,eAAe,EACf,iBAAiB,EAGjB,YAAY,EACZ,UAAU,EACV,aAAa,EAGb,eAAe,EACf,eAAe,EAGf,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,SAAS,EAGT,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EAGpB,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAOjB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGrF,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAOnD,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
// RUNFLOW SDK V2 - MAIN EXPORTS
|
|
4
4
|
// ============================================================================
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.traced = exports.createTraceCollector = exports.RunflowTraceSpan = exports.RunflowTraceCollector = exports.createConnectorStep = exports.createFunctionStep = exports.createAgentStep = exports.createStep = exports.createWorkflow = exports.WorkflowBuilder = exports.Workflow = exports.slack = exports.email = exports.twilio = exports.hubspot = exports.createConnectorTool = exports.createTool = exports.RunflowAPIClientImpl = exports.createRunflowAPIClient = exports.anthropic = exports.openai = exports.Agent = void 0;
|
|
7
|
-
// Core (Agent + Models + API Client)
|
|
6
|
+
exports.RunflowMemoryProvider = exports.LLM = exports.RAG = exports.Knowledge = exports.Memory = exports.traced = exports.createTraceCollector = exports.RunflowTraceSpan = exports.RunflowTraceCollector = exports.createConnectorStep = exports.createFunctionStep = exports.createAgentStep = exports.createStep = exports.createWorkflow = exports.WorkflowBuilder = exports.Workflow = exports.slack = exports.email = exports.twilio = exports.hubspot = exports.createConnectorTool = exports.createTool = exports.Runflow = exports.RunflowAPIClientImpl = exports.createRunflowAPIClient = exports.bedrock = exports.anthropic = exports.openai = exports.Agent = void 0;
|
|
7
|
+
// Core (Agent + Models + API Client + Context)
|
|
8
8
|
var core_1 = require("./core");
|
|
9
9
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return core_1.Agent; } });
|
|
10
10
|
Object.defineProperty(exports, "openai", { enumerable: true, get: function () { return core_1.openai; } });
|
|
11
11
|
Object.defineProperty(exports, "anthropic", { enumerable: true, get: function () { return core_1.anthropic; } });
|
|
12
|
+
Object.defineProperty(exports, "bedrock", { enumerable: true, get: function () { return core_1.bedrock; } });
|
|
12
13
|
Object.defineProperty(exports, "createRunflowAPIClient", { enumerable: true, get: function () { return core_1.createRunflowAPIClient; } });
|
|
13
14
|
Object.defineProperty(exports, "RunflowAPIClientImpl", { enumerable: true, get: function () { return core_1.RunflowAPIClientImpl; } });
|
|
15
|
+
Object.defineProperty(exports, "Runflow", { enumerable: true, get: function () { return core_1.Runflow; } });
|
|
14
16
|
// Tools
|
|
15
17
|
var tools_1 = require("./tools");
|
|
16
18
|
Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return tools_1.createTool; } });
|
|
@@ -37,10 +39,24 @@ Object.defineProperty(exports, "RunflowTraceSpan", { enumerable: true, get: func
|
|
|
37
39
|
Object.defineProperty(exports, "createTraceCollector", { enumerable: true, get: function () { return observability_1.createTraceCollector; } });
|
|
38
40
|
Object.defineProperty(exports, "traced", { enumerable: true, get: function () { return observability_1.traced; } });
|
|
39
41
|
// ============================================================================
|
|
40
|
-
//
|
|
42
|
+
// STANDALONE MODULES
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// Memory Management
|
|
45
|
+
var memory_1 = require("./memory");
|
|
46
|
+
Object.defineProperty(exports, "Memory", { enumerable: true, get: function () { return memory_1.Memory; } });
|
|
47
|
+
// Knowledge/RAG
|
|
48
|
+
var knowledge_1 = require("./knowledge");
|
|
49
|
+
Object.defineProperty(exports, "Knowledge", { enumerable: true, get: function () { return knowledge_1.Knowledge; } });
|
|
50
|
+
Object.defineProperty(exports, "RAG", { enumerable: true, get: function () { return knowledge_1.RAG; } });
|
|
51
|
+
// LLM
|
|
52
|
+
var llm_1 = require("./llm");
|
|
53
|
+
Object.defineProperty(exports, "LLM", { enumerable: true, get: function () { return llm_1.LLM; } });
|
|
54
|
+
// Runflow providers (default)
|
|
55
|
+
var memory_provider_1 = require("./providers/runflow/memory-provider");
|
|
56
|
+
Object.defineProperty(exports, "RunflowMemoryProvider", { enumerable: true, get: function () { return memory_provider_1.RunflowMemoryProvider; } });
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// FUTURE MODULES
|
|
41
59
|
// ============================================================================
|
|
42
|
-
// Memory (quando precisar de mais features)
|
|
43
|
-
// export { MemoryManager } from './memory';
|
|
44
60
|
// Streaming (quando precisar de mais features)
|
|
45
61
|
// export { StreamProcessor } from './streaming';
|
|
46
62
|
// Analytics (futuro)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,gCAAgC;AAChC,+EAA+E;;;AAE/E
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,gCAAgC;AAChC,+EAA+E;;;AAE/E,+CAA+C;AAC/C,+BAQgB;AAPd,6FAAA,KAAK,OAAA;AACL,8FAAA,MAAM,OAAA;AACN,iGAAA,SAAS,OAAA;AACT,+FAAA,OAAO,OAAA;AACP,8GAAA,sBAAsB,OAAA;AACtB,4GAAA,oBAAoB,OAAA;AACpB,+FAAA,OAAO,OAAA;AAGT,QAAQ;AACR,iCAEiB;AADf,mGAAA,UAAU,OAAA;AAGZ,aAAa;AACb,2CAMsB;AALpB,iHAAA,mBAAmB,OAAA;AACnB,qGAAA,OAAO,OAAA;AACP,oGAAA,MAAM,OAAA;AACN,mGAAA,KAAK,OAAA;AACL,mGAAA,KAAK,OAAA;AAGP,YAAY;AACZ,yCAQqB;AAPnB,qGAAA,QAAQ,OAAA;AACR,4GAAA,eAAe,OAAA;AACf,2GAAA,cAAc,OAAA;AACd,uGAAA,UAAU,OAAA;AACV,4GAAA,eAAe,OAAA;AACf,+GAAA,kBAAkB,OAAA;AAClB,gHAAA,mBAAmB,OAAA;AAGrB,gBAAgB;AAChB,iDAKyB;AAJvB,sHAAA,qBAAqB,OAAA;AACrB,iHAAA,gBAAgB,OAAA;AAChB,qHAAA,oBAAoB,OAAA;AACpB,uGAAA,MAAM,OAAA;AAoDR,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,oBAAoB;AACpB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAGf,gBAAgB;AAChB,yCAA6C;AAApC,sGAAA,SAAS,OAAA;AAAE,gGAAA,GAAG,OAAA;AAGvB,MAAM;AACN,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AAUZ,8BAA8B;AAC9B,uEAA4E;AAAnE,wHAAA,qBAAqB,OAAA;AAE9B,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,iDAAiD;AACjD,iDAAiD;AAEjD,qBAAqB;AACrB,oDAAoD;AAEpD,oBAAoB;AACpB,kDAAkD;AAElD,sBAAsB;AACtB,mDAAmD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/knowledge/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAGjF,YAAY,EAAE,gBAAgB,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RAG = exports.Knowledge = void 0;
|
|
4
|
+
// Knowledge exports
|
|
5
|
+
var knowledge_manager_1 = require("./knowledge-manager");
|
|
6
|
+
Object.defineProperty(exports, "Knowledge", { enumerable: true, get: function () { return knowledge_manager_1.Knowledge; } });
|
|
7
|
+
Object.defineProperty(exports, "RAG", { enumerable: true, get: function () { return knowledge_manager_1.RAG; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/knowledge/index.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,yDAAqD;AAA5C,8GAAA,SAAS,OAAA;AAAE,wGAAA,GAAG,OAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* KNOWLEDGE MANAGER - Standalone RAG Module
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* Gerencia base de conhecimento (RAG) de forma independente.
|
|
7
|
+
* Suporta providers plugáveis.
|
|
8
|
+
*/
|
|
9
|
+
import { RunflowAPIClient } from '../types';
|
|
10
|
+
import { KnowledgeProvider, SearchOptions, SearchResult } from '../providers/types';
|
|
11
|
+
export interface KnowledgeOptions {
|
|
12
|
+
vectorStore: string;
|
|
13
|
+
k?: number;
|
|
14
|
+
threshold?: number;
|
|
15
|
+
provider?: KnowledgeProvider;
|
|
16
|
+
apiClient?: RunflowAPIClient;
|
|
17
|
+
}
|
|
18
|
+
export interface HybridSearchOptions {
|
|
19
|
+
query: string;
|
|
20
|
+
keywords?: string[];
|
|
21
|
+
k?: number;
|
|
22
|
+
threshold?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class Knowledge {
|
|
25
|
+
private provider;
|
|
26
|
+
private options;
|
|
27
|
+
constructor(options: KnowledgeOptions);
|
|
28
|
+
search(query: string, options?: Partial<SearchOptions>): Promise<SearchResult[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Hybrid search: Combine semantic + keyword search
|
|
31
|
+
*/
|
|
32
|
+
hybridSearch(options: HybridSearchOptions): Promise<SearchResult[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Multi-query search: Expand query with variants
|
|
35
|
+
*/
|
|
36
|
+
multiQuery(primaryQuery: string, options: {
|
|
37
|
+
variants: string[];
|
|
38
|
+
k?: number;
|
|
39
|
+
}): Promise<SearchResult[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Get context formatted for LLM prompts
|
|
42
|
+
*/
|
|
43
|
+
getContext(query: string, options?: {
|
|
44
|
+
k?: number;
|
|
45
|
+
}): Promise<string>;
|
|
46
|
+
getVectorStore(): string;
|
|
47
|
+
getOptions(): KnowledgeOptions;
|
|
48
|
+
getProvider(): KnowledgeProvider;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Alias for Knowledge (for those who prefer RAG terminology)
|
|
52
|
+
*/
|
|
53
|
+
export declare const RAG: typeof Knowledge;
|
|
54
|
+
//# sourceMappingURL=knowledge-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-manager.d.ts","sourceRoot":"","sources":["../../src/knowledge/knowledge-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAA6C,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOpF,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAoCD,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,OAAO,CAAmB;gBAEtB,OAAO,EAAE,gBAAgB;IAkB/B,MAAM,CACV,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC/B,OAAO,CAAC,YAAY,EAAE,CAAC;IAY1B;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAsBzE;;OAEG;IACG,UAAU,CACd,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1C,OAAO,CAAC,YAAY,EAAE,CAAC;IAgC1B;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAgB1E,cAAc,IAAI,MAAM;IAIxB,UAAU,IAAI,gBAAgB;IAI9B,WAAW,IAAI,iBAAiB;CAGjC;AAMD;;GAEG;AACH,eAAO,MAAM,GAAG,kBAAY,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* KNOWLEDGE MANAGER - Standalone RAG Module
|
|
5
|
+
* ============================================================================
|
|
6
|
+
*
|
|
7
|
+
* Gerencia base de conhecimento (RAG) de forma independente.
|
|
8
|
+
* Suporta providers plugáveis.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.RAG = exports.Knowledge = void 0;
|
|
12
|
+
const api_client_1 = require("../core/api-client");
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// RUNFLOW KNOWLEDGE PROVIDER (Default)
|
|
15
|
+
// ============================================================================
|
|
16
|
+
class RunflowKnowledgeProvider {
|
|
17
|
+
constructor(apiClient, vectorStore) {
|
|
18
|
+
this.apiClient = apiClient;
|
|
19
|
+
this.vectorStore = vectorStore;
|
|
20
|
+
}
|
|
21
|
+
async search(query, options) {
|
|
22
|
+
const response = await this.apiClient.vectorSearch(query, {
|
|
23
|
+
vectorStore: this.vectorStore,
|
|
24
|
+
k: options.k || 5,
|
|
25
|
+
threshold: options.threshold || 0.7,
|
|
26
|
+
...options,
|
|
27
|
+
});
|
|
28
|
+
return response.results.map((r) => ({
|
|
29
|
+
id: r.id,
|
|
30
|
+
content: r.content,
|
|
31
|
+
score: r.score,
|
|
32
|
+
metadata: r.metadata,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// KNOWLEDGE CLASS
|
|
38
|
+
// ============================================================================
|
|
39
|
+
class Knowledge {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
if (!options.vectorStore) {
|
|
42
|
+
throw new Error('Knowledge requires vectorStore');
|
|
43
|
+
}
|
|
44
|
+
this.options = options;
|
|
45
|
+
// Resolver provider
|
|
46
|
+
this.provider = options.provider || new RunflowKnowledgeProvider(options.apiClient || (0, api_client_1.createRunflowAPIClient)(), options.vectorStore);
|
|
47
|
+
}
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// BASIC SEARCH
|
|
50
|
+
// ============================================================================
|
|
51
|
+
async search(query, options) {
|
|
52
|
+
return this.provider.search(query, {
|
|
53
|
+
k: options?.k || this.options.k || 5,
|
|
54
|
+
threshold: options?.threshold || this.options.threshold || 0.7,
|
|
55
|
+
...options,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// ============================================================================
|
|
59
|
+
// ADVANCED SEARCH
|
|
60
|
+
// ============================================================================
|
|
61
|
+
/**
|
|
62
|
+
* Hybrid search: Combine semantic + keyword search
|
|
63
|
+
*/
|
|
64
|
+
async hybridSearch(options) {
|
|
65
|
+
// Perform semantic search
|
|
66
|
+
const semanticResults = await this.search(options.query, {
|
|
67
|
+
k: options.k || 10,
|
|
68
|
+
threshold: options.threshold,
|
|
69
|
+
});
|
|
70
|
+
// If keywords provided, filter results
|
|
71
|
+
if (options.keywords && options.keywords.length > 0) {
|
|
72
|
+
const filtered = semanticResults.filter(result => {
|
|
73
|
+
const content = result.content.toLowerCase();
|
|
74
|
+
return options.keywords.some(keyword => content.includes(keyword.toLowerCase()));
|
|
75
|
+
});
|
|
76
|
+
return filtered.slice(0, options.k || 5);
|
|
77
|
+
}
|
|
78
|
+
return semanticResults;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Multi-query search: Expand query with variants
|
|
82
|
+
*/
|
|
83
|
+
async multiQuery(primaryQuery, options) {
|
|
84
|
+
// Search with multiple query variants
|
|
85
|
+
const allQueries = [primaryQuery, ...options.variants];
|
|
86
|
+
const allResults = await Promise.all(allQueries.map(q => this.search(q, { k: options.k || 3 })));
|
|
87
|
+
// Merge and deduplicate results
|
|
88
|
+
const mergedResults = new Map();
|
|
89
|
+
for (const results of allResults) {
|
|
90
|
+
for (const item of results) {
|
|
91
|
+
const key = item.id || item.content;
|
|
92
|
+
if (!mergedResults.has(key)) {
|
|
93
|
+
mergedResults.set(key, item);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return Array.from(mergedResults.values()).slice(0, options.k || 5);
|
|
98
|
+
}
|
|
99
|
+
// ============================================================================
|
|
100
|
+
// FUTURE FEATURES
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// rerank() - Requires reranking API implementation
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// CONTEXT FORMATTING
|
|
105
|
+
// ============================================================================
|
|
106
|
+
/**
|
|
107
|
+
* Get context formatted for LLM prompts
|
|
108
|
+
*/
|
|
109
|
+
async getContext(query, options) {
|
|
110
|
+
const results = await this.search(query, { k: options?.k });
|
|
111
|
+
if (results.length === 0) {
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
return 'Context:\n' + results
|
|
115
|
+
.map((result, index) => `${index + 1}. ${result.content}`)
|
|
116
|
+
.join('\n\n');
|
|
117
|
+
}
|
|
118
|
+
// ============================================================================
|
|
119
|
+
// GETTERS
|
|
120
|
+
// ============================================================================
|
|
121
|
+
getVectorStore() {
|
|
122
|
+
return this.options.vectorStore;
|
|
123
|
+
}
|
|
124
|
+
getOptions() {
|
|
125
|
+
return this.options;
|
|
126
|
+
}
|
|
127
|
+
getProvider() {
|
|
128
|
+
return this.provider;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.Knowledge = Knowledge;
|
|
132
|
+
// ============================================================================
|
|
133
|
+
// ALIAS EXPORT
|
|
134
|
+
// ============================================================================
|
|
135
|
+
/**
|
|
136
|
+
* Alias for Knowledge (for those who prefer RAG terminology)
|
|
137
|
+
*/
|
|
138
|
+
exports.RAG = Knowledge;
|
|
139
|
+
//# sourceMappingURL=knowledge-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-manager.js","sourceRoot":"","sources":["../../src/knowledge/knowledge-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAIH,mDAA4D;AAqB5D,+EAA+E;AAC/E,uCAAuC;AACvC,+EAA+E;AAE/E,MAAM,wBAAwB;IAI5B,YAAY,SAA2B,EAAE,WAAmB;QAC1D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,OAAsB;QAChD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE;YACxD,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,CAAC,EAAE,O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T,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAlID,8BAkIC;AAED,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E;;GAEG;AACU,QAAA,GAAG,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LLM = void 0;
|
|
4
|
+
// LLM exports
|
|
5
|
+
var llm_manager_1 = require("./llm-manager");
|
|
6
|
+
Object.defineProperty(exports, "LLM", { enumerable: true, get: function () { return llm_manager_1.LLM; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":";;;AAAA,cAAc;AACd,6CAAoC;AAA3B,kGAAA,GAAG,OAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* LLM MANAGER - Standalone LLM Module
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* Gerencia chamadas a LLMs de forma independente.
|
|
7
|
+
* Suporta providers plugáveis e múltiplos modelos.
|
|
8
|
+
*/
|
|
9
|
+
import { RunflowAPIClient, ModelProvider, ModelConfig } from '../types';
|
|
10
|
+
import { LLMProvider, Message, GenerateOptions, LLMResponse, StreamChunk } from '../providers/types';
|
|
11
|
+
export interface LLMConfig extends ModelConfig {
|
|
12
|
+
provider: 'openai' | 'anthropic' | 'bedrock';
|
|
13
|
+
model: string;
|
|
14
|
+
}
|
|
15
|
+
export interface LLMOptions extends ModelConfig {
|
|
16
|
+
customProvider?: LLMProvider;
|
|
17
|
+
apiClient?: RunflowAPIClient;
|
|
18
|
+
}
|
|
19
|
+
export declare class LLM {
|
|
20
|
+
private provider;
|
|
21
|
+
private modelConfig;
|
|
22
|
+
private options;
|
|
23
|
+
constructor(config: LLMConfig & LLMOptions);
|
|
24
|
+
generate(input: string | Message[], options?: GenerateOptions): Promise<LLMResponse>;
|
|
25
|
+
generateStream(input: string | Message[], options?: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
26
|
+
private normalizeInput;
|
|
27
|
+
/**
|
|
28
|
+
* Create OpenAI LLM
|
|
29
|
+
* @example LLM.openai('gpt-4o', { temperature: 0.7 })
|
|
30
|
+
*/
|
|
31
|
+
static openai(model: string, options?: LLMOptions): LLM;
|
|
32
|
+
/**
|
|
33
|
+
* Create Anthropic LLM
|
|
34
|
+
* @example LLM.anthropic('claude-3-5-sonnet-20241022', { temperature: 0.9 })
|
|
35
|
+
*/
|
|
36
|
+
static anthropic(model: string, options?: LLMOptions): LLM;
|
|
37
|
+
/**
|
|
38
|
+
* Create AWS Bedrock LLM
|
|
39
|
+
* @example LLM.bedrock('anthropic.claude-3-sonnet-20240229-v1:0')
|
|
40
|
+
* @example LLM.bedrock('amazon.titan-text-express-v1')
|
|
41
|
+
*/
|
|
42
|
+
static bedrock(model: string, options?: LLMOptions): LLM;
|
|
43
|
+
getModel(): ModelProvider;
|
|
44
|
+
getOptions(): LLMOptions;
|
|
45
|
+
getProvider(): LLMProvider;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=llm-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-manager.d.ts","sourceRoot":"","sources":["../../src/llm/llm-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,WAAW,EAIZ,MAAM,UAAU,CAAC;A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