@nebulaos/client 0.1.2 → 0.1.4
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/LICENSE.txt +21 -0
- package/dist/index.d.mts +79 -28
- package/dist/index.d.ts +79 -28
- package/dist/index.js +7 -187
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -216
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,201 +1,3 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
13
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
14
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
|
-
};
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
-
for (let key of __getOwnPropNames(from))
|
|
19
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
-
mod
|
|
31
|
-
));
|
|
32
|
-
|
|
33
|
-
// ../rag-openai-skill/dist/ClientContext.js
|
|
34
|
-
var require_ClientContext = __commonJS({
|
|
35
|
-
"../rag-openai-skill/dist/ClientContext.js"(exports) {
|
|
36
|
-
"use strict";
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.ClientContext = void 0;
|
|
39
|
-
var ClientContextManager = class {
|
|
40
|
-
apiKey;
|
|
41
|
-
serverUrl;
|
|
42
|
-
setApiKey(apiKey) {
|
|
43
|
-
this.apiKey = apiKey;
|
|
44
|
-
}
|
|
45
|
-
setServerUrl(url) {
|
|
46
|
-
this.serverUrl = url;
|
|
47
|
-
}
|
|
48
|
-
getApiKey() {
|
|
49
|
-
return this.apiKey;
|
|
50
|
-
}
|
|
51
|
-
getServerUrl() {
|
|
52
|
-
return this.serverUrl;
|
|
53
|
-
}
|
|
54
|
-
clear() {
|
|
55
|
-
this.apiKey = void 0;
|
|
56
|
-
this.serverUrl = void 0;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
exports.ClientContext = new ClientContextManager();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// ../rag-openai-skill/dist/RagOpenAISkill.js
|
|
64
|
-
var require_RagOpenAISkill = __commonJS({
|
|
65
|
-
"../rag-openai-skill/dist/RagOpenAISkill.js"(exports) {
|
|
66
|
-
"use strict";
|
|
67
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
-
exports.RagOpenAISkill = void 0;
|
|
69
|
-
var core_1 = __require("@nebulaos/core");
|
|
70
|
-
var ClientContext_js_1 = require_ClientContext();
|
|
71
|
-
var RagOpenAISkill = class {
|
|
72
|
-
config;
|
|
73
|
-
constructor(config) {
|
|
74
|
-
const apiKey = config.apiKey || ClientContext_js_1.ClientContext.getApiKey();
|
|
75
|
-
const apiEndpoint = config.apiEndpoint || ClientContext_js_1.ClientContext.getServerUrl() || "https://api.nebulaos.com";
|
|
76
|
-
this.config = {
|
|
77
|
-
connectionId: config.connectionId,
|
|
78
|
-
apiKey: apiKey || "",
|
|
79
|
-
// Will be validated in initialize
|
|
80
|
-
apiEndpoint,
|
|
81
|
-
timeout: config.timeout || 3e4,
|
|
82
|
-
maxResults: config.maxResults,
|
|
83
|
-
minScore: config.minScore
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Optional initialization - validates configuration
|
|
88
|
-
*/
|
|
89
|
-
async initialize() {
|
|
90
|
-
if (!this.config.connectionId) {
|
|
91
|
-
throw new Error("RagOpenAISkill: connectionId is required");
|
|
92
|
-
}
|
|
93
|
-
if (!this.config.apiKey) {
|
|
94
|
-
const contextApiKey = ClientContext_js_1.ClientContext.getApiKey();
|
|
95
|
-
if (contextApiKey) {
|
|
96
|
-
this.config.apiKey = contextApiKey;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (!this.config.apiKey) {
|
|
100
|
-
throw new Error("RagOpenAISkill: apiKey is required. Make sure your agent is registered with a NebulaClient that has server.apiKey configured.");
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Returns the vector store search tool
|
|
105
|
-
*/
|
|
106
|
-
getTools() {
|
|
107
|
-
const toolId = `search_vector_store_${this.config.connectionId.slice(-8)}`;
|
|
108
|
-
return [
|
|
109
|
-
new core_1.Tool({
|
|
110
|
-
id: toolId,
|
|
111
|
-
description: `Search through the knowledge base using semantic search. Returns relevant documents and information based on the query.`,
|
|
112
|
-
inputSchema: core_1.z.object({
|
|
113
|
-
query: core_1.z.string().describe("The search query or question to find relevant information"),
|
|
114
|
-
maxResults: core_1.z.number().optional().describe("Maximum number of results to return (overrides default)"),
|
|
115
|
-
minScore: core_1.z.number().min(0).max(1).optional().describe("Minimum relevance score threshold (0-1, overrides default)")
|
|
116
|
-
}),
|
|
117
|
-
handler: async (ctx, input) => {
|
|
118
|
-
return this.searchVectorStore(input.query, {
|
|
119
|
-
maxResults: input.maxResults,
|
|
120
|
-
minScore: input.minScore
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Optional instructions for the agent on how to use the RAG tool
|
|
128
|
-
*/
|
|
129
|
-
getInstructions() {
|
|
130
|
-
return `You have access to a knowledge base search tool. Use it whenever you need to:
|
|
131
|
-
- Find specific information or documentation
|
|
132
|
-
- Answer questions that require domain knowledge
|
|
133
|
-
- Retrieve relevant context before responding
|
|
134
|
-
|
|
135
|
-
The search results include relevance scores. Prioritize higher-scoring results when formulating your response.`;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Search the vector store via NebulaOS Cloud API
|
|
139
|
-
*/
|
|
140
|
-
async searchVectorStore(query, options = {}) {
|
|
141
|
-
const url = `${this.config.apiEndpoint}/rag-openai/search`;
|
|
142
|
-
const requestBody = {
|
|
143
|
-
connectionId: this.config.connectionId,
|
|
144
|
-
query,
|
|
145
|
-
maxResults: options.maxResults ?? this.config.maxResults,
|
|
146
|
-
minScore: options.minScore ?? this.config.minScore
|
|
147
|
-
};
|
|
148
|
-
try {
|
|
149
|
-
const controller = new AbortController();
|
|
150
|
-
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
151
|
-
const response = await fetch(url, {
|
|
152
|
-
method: "POST",
|
|
153
|
-
headers: {
|
|
154
|
-
"Content-Type": "application/json",
|
|
155
|
-
Authorization: `Bearer ${this.config.apiKey}`
|
|
156
|
-
},
|
|
157
|
-
body: JSON.stringify(requestBody),
|
|
158
|
-
signal: controller.signal
|
|
159
|
-
});
|
|
160
|
-
clearTimeout(timeoutId);
|
|
161
|
-
if (!response.ok) {
|
|
162
|
-
const errorText = await response.text();
|
|
163
|
-
throw new Error(`RAG search failed: ${response.status} ${response.statusText}. ${errorText}`);
|
|
164
|
-
}
|
|
165
|
-
const data = await response.json();
|
|
166
|
-
return data;
|
|
167
|
-
} catch (error) {
|
|
168
|
-
if (error instanceof Error) {
|
|
169
|
-
if (error.name === "AbortError") {
|
|
170
|
-
throw new Error(`RAG search timeout after ${this.config.timeout}ms`);
|
|
171
|
-
}
|
|
172
|
-
throw new Error(`RAG search error: ${error.message}`);
|
|
173
|
-
}
|
|
174
|
-
throw error;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
exports.RagOpenAISkill = RagOpenAISkill;
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// ../rag-openai-skill/dist/index.js
|
|
183
|
-
var require_dist = __commonJS({
|
|
184
|
-
"../rag-openai-skill/dist/index.js"(exports) {
|
|
185
|
-
"use strict";
|
|
186
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
187
|
-
exports.ClientContext = exports.RagOpenAISkill = void 0;
|
|
188
|
-
var RagOpenAISkill_js_1 = require_RagOpenAISkill();
|
|
189
|
-
Object.defineProperty(exports, "RagOpenAISkill", { enumerable: true, get: function() {
|
|
190
|
-
return RagOpenAISkill_js_1.RagOpenAISkill;
|
|
191
|
-
} });
|
|
192
|
-
var ClientContext_js_1 = require_ClientContext();
|
|
193
|
-
Object.defineProperty(exports, "ClientContext", { enumerable: true, get: function() {
|
|
194
|
-
return ClientContext_js_1.ClientContext;
|
|
195
|
-
} });
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
|
|
199
1
|
// src/config/client-config.ts
|
|
200
2
|
import { z } from "zod";
|
|
201
3
|
var serverConfigSchema = z.object({
|
|
@@ -1730,9 +1532,6 @@ var NebulaClient = class {
|
|
|
1730
1532
|
if (!config.clientId) {
|
|
1731
1533
|
config.clientId = `client-${uuid2()}`;
|
|
1732
1534
|
}
|
|
1733
|
-
if (config.server) {
|
|
1734
|
-
this.setGlobalClientContext(config.server.apiKey, config.server.url);
|
|
1735
|
-
}
|
|
1736
1535
|
this.registry = new Registry();
|
|
1737
1536
|
this.registry.setHttpClient(new InstrumentedHttpClient());
|
|
1738
1537
|
config.agents?.forEach((agent) => this.registry.registerAgent(agent));
|
|
@@ -1821,6 +1620,11 @@ var NebulaClient = class {
|
|
|
1821
1620
|
}
|
|
1822
1621
|
throw new Error(`Failed to connect to NebulaOS Cloud: ${String(error)}`);
|
|
1823
1622
|
}
|
|
1623
|
+
for (const agent of this.registry.listAgents()) {
|
|
1624
|
+
if (typeof agent.setClient === "function") {
|
|
1625
|
+
agent.setClient(this);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1824
1628
|
}
|
|
1825
1629
|
}
|
|
1826
1630
|
async stop() {
|
|
@@ -1832,21 +1636,8 @@ var NebulaClient = class {
|
|
|
1832
1636
|
isConnected() {
|
|
1833
1637
|
return this.serverConnection?.isConnected() ?? false;
|
|
1834
1638
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
* This allows skills like RagOpenAISkill to automatically use the client's credentials
|
|
1838
|
-
*/
|
|
1839
|
-
setGlobalClientContext(apiKey, serverUrl) {
|
|
1840
|
-
try {
|
|
1841
|
-
Promise.resolve().then(() => __toESM(require_dist())).then((module) => {
|
|
1842
|
-
if (module.ClientContext) {
|
|
1843
|
-
module.ClientContext.setApiKey(apiKey);
|
|
1844
|
-
module.ClientContext.setServerUrl(serverUrl);
|
|
1845
|
-
}
|
|
1846
|
-
}).catch(() => {
|
|
1847
|
-
});
|
|
1848
|
-
} catch {
|
|
1849
|
-
}
|
|
1639
|
+
getSocket() {
|
|
1640
|
+
return this.serverConnection?.getSocket();
|
|
1850
1641
|
}
|
|
1851
1642
|
};
|
|
1852
1643
|
|