@olane/o-intelligence 0.6.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.
Files changed (38) hide show
  1. package/README.md +11 -0
  2. package/dist/src/anthropic-intelligence.tool.d.ts +224 -0
  3. package/dist/src/anthropic-intelligence.tool.d.ts.map +1 -0
  4. package/dist/src/anthropic-intelligence.tool.js +477 -0
  5. package/dist/src/enums/intelligence-storage-keys.enum.d.ts +5 -0
  6. package/dist/src/enums/intelligence-storage-keys.enum.d.ts.map +1 -0
  7. package/dist/src/enums/intelligence-storage-keys.enum.js +5 -0
  8. package/dist/src/enums/llm-providers.enum.d.ts +8 -0
  9. package/dist/src/enums/llm-providers.enum.d.ts.map +1 -0
  10. package/dist/src/enums/llm-providers.enum.js +8 -0
  11. package/dist/src/gemini-intelligence.tool.d.ts +29 -0
  12. package/dist/src/gemini-intelligence.tool.d.ts.map +1 -0
  13. package/dist/src/gemini-intelligence.tool.js +267 -0
  14. package/dist/src/grok-intelligence.tool.d.ts +13 -0
  15. package/dist/src/grok-intelligence.tool.d.ts.map +1 -0
  16. package/dist/src/grok-intelligence.tool.js +214 -0
  17. package/dist/src/index.d.ts +7 -0
  18. package/dist/src/index.d.ts.map +1 -0
  19. package/dist/src/index.js +6 -0
  20. package/dist/src/intelligence.tool.d.ts +21 -0
  21. package/dist/src/intelligence.tool.d.ts.map +1 -0
  22. package/dist/src/intelligence.tool.js +201 -0
  23. package/dist/src/methods/intelligence.methods.d.ts +5 -0
  24. package/dist/src/methods/intelligence.methods.d.ts.map +1 -0
  25. package/dist/src/methods/intelligence.methods.js +132 -0
  26. package/dist/src/ollama-intelligence.tool.d.ts +36 -0
  27. package/dist/src/ollama-intelligence.tool.d.ts.map +1 -0
  28. package/dist/src/ollama-intelligence.tool.js +312 -0
  29. package/dist/src/openai-intelligence.tool.d.ts +29 -0
  30. package/dist/src/openai-intelligence.tool.d.ts.map +1 -0
  31. package/dist/src/openai-intelligence.tool.js +261 -0
  32. package/dist/src/perplexity-intelligence.tool.d.ts +28 -0
  33. package/dist/src/perplexity-intelligence.tool.d.ts.map +1 -0
  34. package/dist/src/perplexity-intelligence.tool.js +310 -0
  35. package/dist/test/basic.spec.d.ts +1 -0
  36. package/dist/test/basic.spec.d.ts.map +1 -0
  37. package/dist/test/basic.spec.js +1 -0
  38. package/package.json +70 -0
@@ -0,0 +1,29 @@
1
+ import { oRequest } from '@olane/o-core';
2
+ import { oToolConfig, oVirtualTool, ToolResult } from '@olane/o-tool';
3
+ export declare class OpenAIIntelligenceTool extends oVirtualTool {
4
+ private baseUrl;
5
+ private defaultModel;
6
+ private organization?;
7
+ constructor(config: oToolConfig);
8
+ /**
9
+ * Chat completion with OpenAI
10
+ */
11
+ _tool_completion(request: oRequest): Promise<ToolResult>;
12
+ /**
13
+ * Generate text with OpenAI
14
+ */
15
+ _tool_generate(request: oRequest): Promise<ToolResult>;
16
+ /**
17
+ * List available models
18
+ */
19
+ _tool_list_models(request: oRequest): Promise<ToolResult>;
20
+ /**
21
+ * Get model information
22
+ */
23
+ _tool_model_info(request: oRequest): Promise<ToolResult>;
24
+ /**
25
+ * Check OpenAI API status
26
+ */
27
+ _tool_status(request: oRequest): Promise<ToolResult>;
28
+ }
29
+ //# sourceMappingURL=openai-intelligence.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-intelligence.tool.d.ts","sourceRoot":"","sources":["../../src/openai-intelligence.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAoHtE,qBAAa,sBAAuB,SAAQ,YAAY;IACtD,OAAO,CAAC,OAAO,CAAuC;IACtD,OAAO,CAAC,YAAY,CAAwB;IAC5C,OAAO,CAAC,YAAY,CAAC,CAAS;gBAElB,MAAM,EAAE,WAAW;IAU/B;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAyE9D;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAmE5D;;OAEG;IACG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAgD/D;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA+C9D;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAuC3D"}
@@ -0,0 +1,261 @@
1
+ import { oAddress } from '@olane/o-core';
2
+ import { oVirtualTool } from '@olane/o-tool';
3
+ import { INTELLIGENCE_PARAMS } from './methods/intelligence.methods.js';
4
+ export class OpenAIIntelligenceTool extends oVirtualTool {
5
+ constructor(config) {
6
+ super({
7
+ ...config,
8
+ address: new oAddress('o://openai'),
9
+ description: "Open AI's suite of intelligence models.",
10
+ methods: INTELLIGENCE_PARAMS,
11
+ dependencies: [],
12
+ });
13
+ this.baseUrl = 'https://api.openai.com/v1';
14
+ this.defaultModel = 'gpt-5-mini';
15
+ }
16
+ /**
17
+ * Chat completion with OpenAI
18
+ */
19
+ async _tool_completion(request) {
20
+ try {
21
+ const params = request.params;
22
+ const { model = this.defaultModel, messages, apiKey, ...options } = params;
23
+ if (!apiKey) {
24
+ return {
25
+ success: false,
26
+ error: 'OpenAI API key is required',
27
+ };
28
+ }
29
+ if (!messages || !Array.isArray(messages)) {
30
+ return {
31
+ success: false,
32
+ error: '"messages" array is required',
33
+ };
34
+ }
35
+ const chatRequest = {
36
+ model: model,
37
+ messages: messages,
38
+ stream: false,
39
+ // ...options,
40
+ };
41
+ const headers = {
42
+ 'Content-Type': 'application/json',
43
+ Authorization: `Bearer ${apiKey}`,
44
+ };
45
+ if (this.organization) {
46
+ headers['OpenAI-Organization'] = this.organization;
47
+ }
48
+ const response = await fetch(`${this.baseUrl}/chat/completions`, {
49
+ method: 'POST',
50
+ headers,
51
+ body: JSON.stringify(chatRequest),
52
+ });
53
+ if (!response.ok) {
54
+ const errorText = await response.text();
55
+ return {
56
+ success: false,
57
+ error: `OpenAI API error: ${response.status} - ${errorText}`,
58
+ };
59
+ }
60
+ const result = (await response.json());
61
+ return {
62
+ success: true,
63
+ message: result.choices[0]?.message?.content || '',
64
+ model: result.model,
65
+ usage: result.usage,
66
+ finish_reason: result.choices[0]?.finish_reason,
67
+ function_call: result.choices[0]?.message?.function_call,
68
+ };
69
+ }
70
+ catch (error) {
71
+ return {
72
+ success: false,
73
+ error: `Failed to complete chat: ${error.message}`,
74
+ };
75
+ }
76
+ }
77
+ /**
78
+ * Generate text with OpenAI
79
+ */
80
+ async _tool_generate(request) {
81
+ try {
82
+ const params = request.params;
83
+ const { model = this.defaultModel, prompt, apiKey, ...options } = params;
84
+ if (!apiKey) {
85
+ return {
86
+ success: false,
87
+ error: 'OpenAI API key is required',
88
+ };
89
+ }
90
+ if (!prompt) {
91
+ return {
92
+ success: false,
93
+ error: 'Prompt is required',
94
+ };
95
+ }
96
+ const completionRequest = {
97
+ model: model,
98
+ prompt: prompt,
99
+ stream: false,
100
+ ...options,
101
+ };
102
+ const headers = {
103
+ 'Content-Type': 'application/json',
104
+ Authorization: `Bearer ${apiKey}`,
105
+ };
106
+ // if (this.organization) {
107
+ // headers['OpenAI-Organization'] = this.organization;
108
+ // }
109
+ const response = await fetch(`${this.baseUrl}/completions`, {
110
+ method: 'POST',
111
+ headers,
112
+ body: JSON.stringify(completionRequest),
113
+ });
114
+ if (!response.ok) {
115
+ const errorText = await response.text();
116
+ return {
117
+ success: false,
118
+ error: `OpenAI API error: ${response.status} - ${errorText}`,
119
+ };
120
+ }
121
+ const result = (await response.json());
122
+ return {
123
+ success: true,
124
+ response: result.choices[0]?.text || '',
125
+ model: result.model,
126
+ usage: result.usage,
127
+ finish_reason: result.choices[0]?.finish_reason,
128
+ };
129
+ }
130
+ catch (error) {
131
+ return {
132
+ success: false,
133
+ error: `Failed to generate text: ${error.message}`,
134
+ };
135
+ }
136
+ }
137
+ /**
138
+ * List available models
139
+ */
140
+ async _tool_list_models(request) {
141
+ try {
142
+ const params = request.params;
143
+ const { apiKey } = params;
144
+ if (!apiKey) {
145
+ return {
146
+ success: false,
147
+ error: 'OpenAI API key is required',
148
+ };
149
+ }
150
+ const headers = {
151
+ Authorization: `Bearer ${apiKey}`,
152
+ };
153
+ if (this.organization) {
154
+ headers['OpenAI-Organization'] = this.organization;
155
+ }
156
+ const response = await fetch(`${this.baseUrl}/models`, {
157
+ method: 'GET',
158
+ headers,
159
+ });
160
+ if (!response.ok) {
161
+ const errorText = await response.text();
162
+ return {
163
+ success: false,
164
+ error: `OpenAI API error: ${response.status} - ${errorText}`,
165
+ };
166
+ }
167
+ const result = (await response.json());
168
+ return {
169
+ success: true,
170
+ models: result.data,
171
+ };
172
+ }
173
+ catch (error) {
174
+ return {
175
+ success: false,
176
+ error: `Failed to list models: ${error.message}`,
177
+ };
178
+ }
179
+ }
180
+ /**
181
+ * Get model information
182
+ */
183
+ async _tool_model_info(request) {
184
+ try {
185
+ const params = request.params;
186
+ const { model = this.defaultModel, apiKey } = params;
187
+ if (!apiKey) {
188
+ return {
189
+ success: false,
190
+ error: 'OpenAI API key is required',
191
+ };
192
+ }
193
+ const headers = {
194
+ Authorization: `Bearer ${apiKey}`,
195
+ };
196
+ if (this.organization) {
197
+ headers['OpenAI-Organization'] = this.organization;
198
+ }
199
+ const response = await fetch(`${this.baseUrl}/models/${model}`, {
200
+ method: 'GET',
201
+ headers,
202
+ });
203
+ if (!response.ok) {
204
+ const errorText = await response.text();
205
+ return {
206
+ success: false,
207
+ error: `OpenAI API error: ${response.status} - ${errorText}`,
208
+ };
209
+ }
210
+ const result = (await response.json());
211
+ return {
212
+ success: true,
213
+ model_info: result,
214
+ };
215
+ }
216
+ catch (error) {
217
+ return {
218
+ success: false,
219
+ error: `Failed to get model info: ${error.message}`,
220
+ };
221
+ }
222
+ }
223
+ /**
224
+ * Check OpenAI API status
225
+ */
226
+ async _tool_status(request) {
227
+ try {
228
+ const params = request.params;
229
+ const { apiKey } = params;
230
+ if (!apiKey) {
231
+ return {
232
+ success: false,
233
+ status: 'no_api_key',
234
+ error: 'OpenAI API key is required',
235
+ };
236
+ }
237
+ const headers = {
238
+ Authorization: `Bearer ${apiKey}`,
239
+ };
240
+ if (this.organization) {
241
+ headers['OpenAI-Organization'] = this.organization;
242
+ }
243
+ const response = await fetch(`${this.baseUrl}/models`, {
244
+ method: 'GET',
245
+ headers,
246
+ });
247
+ return {
248
+ success: response.ok,
249
+ status: response.ok ? 'online' : 'offline',
250
+ status_code: response.status,
251
+ };
252
+ }
253
+ catch (error) {
254
+ return {
255
+ success: false,
256
+ status: 'offline',
257
+ error: `Connection failed: ${error.message}`,
258
+ };
259
+ }
260
+ }
261
+ }
@@ -0,0 +1,28 @@
1
+ import { oRequest } from '@olane/o-core';
2
+ import { oToolConfig, oVirtualTool, ToolResult } from '@olane/o-tool';
3
+ export declare class PerplexityIntelligenceTool extends oVirtualTool {
4
+ private defaultModel;
5
+ private defaultApiKey;
6
+ constructor(config: oToolConfig);
7
+ /**
8
+ * Chat completion with Perplexity
9
+ */
10
+ _tool_completion(request: oRequest): Promise<ToolResult>;
11
+ /**
12
+ * Generate text with Perplexity (alias for completion)
13
+ */
14
+ _tool_generate(request: oRequest): Promise<ToolResult>;
15
+ /**
16
+ * List available models
17
+ */
18
+ _tool_list_models(request: oRequest): Promise<ToolResult>;
19
+ /**
20
+ * Search with Perplexity
21
+ */
22
+ _tool_search(request: oRequest): Promise<ToolResult>;
23
+ /**
24
+ * Check Perplexity API status
25
+ */
26
+ _tool_status(request: oRequest): Promise<ToolResult>;
27
+ }
28
+ //# sourceMappingURL=perplexity-intelligence.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perplexity-intelligence.tool.d.ts","sourceRoot":"","sources":["../../src/perplexity-intelligence.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAqFtE,qBAAa,0BAA2B,SAAQ,YAAY;IAC1D,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,aAAa,CAA2C;gBAEpD,MAAM,EAAE,WAAW;IAU/B;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA+F9D;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAuG5D;;OAEG;IACG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAyC/D;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA6E1D;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAgC3D"}
@@ -0,0 +1,310 @@
1
+ import { oAddress } from '@olane/o-core';
2
+ import { oVirtualTool } from '@olane/o-tool';
3
+ import { INTELLIGENCE_PARAMS } from './methods/intelligence.methods.js';
4
+ export class PerplexityIntelligenceTool extends oVirtualTool {
5
+ constructor(config) {
6
+ super({
7
+ ...config,
8
+ address: new oAddress('o://perplexity'),
9
+ description: 'Intelligence tool using Perplexity LLM suite of models',
10
+ methods: INTELLIGENCE_PARAMS,
11
+ dependencies: [],
12
+ });
13
+ this.defaultApiKey = process.env.SONAR_API_KEY || '';
14
+ }
15
+ /**
16
+ * Chat completion with Perplexity
17
+ */
18
+ async _tool_completion(request) {
19
+ try {
20
+ const params = request.params;
21
+ const { model = this.defaultModel, messages, max_tokens, temperature, top_p, top_k, presence_penalty, frequency_penalty, apiKey = this.defaultApiKey, search_domain, return_citations, return_images, return_related_questions, } = params;
22
+ if (!messages || !Array.isArray(messages)) {
23
+ return {
24
+ success: false,
25
+ error: '"messages" array is required',
26
+ };
27
+ }
28
+ if (!apiKey) {
29
+ return {
30
+ success: false,
31
+ error: 'Perplexity API key is required',
32
+ };
33
+ }
34
+ const chatRequest = {
35
+ model: model,
36
+ messages: messages,
37
+ stream: false,
38
+ };
39
+ // Add optional parameters if provided
40
+ if (max_tokens !== undefined)
41
+ chatRequest.max_tokens = max_tokens;
42
+ if (temperature !== undefined)
43
+ chatRequest.temperature = temperature;
44
+ if (top_p !== undefined)
45
+ chatRequest.top_p = top_p;
46
+ if (top_k !== undefined)
47
+ chatRequest.top_k = top_k;
48
+ if (presence_penalty !== undefined)
49
+ chatRequest.presence_penalty = presence_penalty;
50
+ if (frequency_penalty !== undefined)
51
+ chatRequest.frequency_penalty = frequency_penalty;
52
+ if (search_domain !== undefined)
53
+ chatRequest.search_domain = search_domain;
54
+ if (return_citations !== undefined)
55
+ chatRequest.return_citations = return_citations;
56
+ if (return_images !== undefined)
57
+ chatRequest.return_images = return_images;
58
+ if (return_related_questions !== undefined)
59
+ chatRequest.return_related_questions = return_related_questions;
60
+ const response = await fetch(`https://api.perplexity.ai/chat/completions`, {
61
+ method: 'POST',
62
+ headers: {
63
+ 'Content-Type': 'application/json',
64
+ Authorization: `Bearer ${apiKey}`,
65
+ },
66
+ body: JSON.stringify(chatRequest),
67
+ });
68
+ if (!response.ok) {
69
+ const errorText = await response.text();
70
+ return {
71
+ success: false,
72
+ error: `Perplexity API error: ${response.status} - ${errorText}`,
73
+ };
74
+ }
75
+ const result = (await response.json());
76
+ return {
77
+ success: true,
78
+ message: result.choices[0]?.message?.content || '',
79
+ model: result.model,
80
+ usage: result.usage,
81
+ finish_reason: result.choices[0]?.finish_reason,
82
+ };
83
+ }
84
+ catch (error) {
85
+ return {
86
+ success: false,
87
+ error: `Failed to complete chat: ${error.message}`,
88
+ };
89
+ }
90
+ }
91
+ /**
92
+ * Generate text with Perplexity (alias for completion)
93
+ */
94
+ async _tool_generate(request) {
95
+ try {
96
+ const params = request.params;
97
+ const { model = this.defaultModel, prompt, system, max_tokens, temperature, top_p, top_k, presence_penalty, frequency_penalty, search_domain, return_citations, return_images, return_related_questions, apiKey = this.defaultApiKey, } = params;
98
+ if (!prompt) {
99
+ return {
100
+ success: false,
101
+ error: 'Prompt is required',
102
+ };
103
+ }
104
+ if (!apiKey) {
105
+ return {
106
+ success: false,
107
+ error: 'Perplexity API key is required',
108
+ };
109
+ }
110
+ // Convert prompt to messages format
111
+ const messages = [];
112
+ if (system) {
113
+ messages.push({ role: 'system', content: system });
114
+ }
115
+ messages.push({ role: 'user', content: prompt });
116
+ const chatRequest = {
117
+ model: model,
118
+ messages,
119
+ stream: false,
120
+ };
121
+ // Add optional parameters if provided
122
+ if (max_tokens !== undefined)
123
+ chatRequest.max_tokens = max_tokens;
124
+ if (temperature !== undefined)
125
+ chatRequest.temperature = temperature;
126
+ if (top_p !== undefined)
127
+ chatRequest.top_p = top_p;
128
+ if (top_k !== undefined)
129
+ chatRequest.top_k = top_k;
130
+ if (presence_penalty !== undefined)
131
+ chatRequest.presence_penalty = presence_penalty;
132
+ if (frequency_penalty !== undefined)
133
+ chatRequest.frequency_penalty = frequency_penalty;
134
+ if (search_domain !== undefined)
135
+ chatRequest.search_domain = search_domain;
136
+ if (return_citations !== undefined)
137
+ chatRequest.return_citations = return_citations;
138
+ if (return_images !== undefined)
139
+ chatRequest.return_images = return_images;
140
+ if (return_related_questions !== undefined)
141
+ chatRequest.return_related_questions = return_related_questions;
142
+ const response = await fetch(`https://api.perplexity.ai/chat/completions`, {
143
+ method: 'POST',
144
+ headers: {
145
+ 'Content-Type': 'application/json',
146
+ Authorization: `Bearer ${apiKey}`,
147
+ },
148
+ body: JSON.stringify(chatRequest),
149
+ });
150
+ if (!response.ok) {
151
+ const errorText = await response.text();
152
+ return {
153
+ success: false,
154
+ error: `Perplexity API error: ${response.status} - ${errorText}`,
155
+ };
156
+ }
157
+ const result = (await response.json());
158
+ return {
159
+ success: true,
160
+ response: result.choices[0]?.message?.content || '',
161
+ model: result.model,
162
+ usage: result.usage,
163
+ finish_reason: result.choices[0]?.finish_reason,
164
+ };
165
+ }
166
+ catch (error) {
167
+ return {
168
+ success: false,
169
+ error: `Failed to generate text: ${error.message}`,
170
+ };
171
+ }
172
+ }
173
+ /**
174
+ * List available models
175
+ */
176
+ async _tool_list_models(request) {
177
+ try {
178
+ const params = request.params;
179
+ const { apiKey = this.defaultApiKey } = params;
180
+ if (!apiKey) {
181
+ return {
182
+ success: false,
183
+ error: 'Perplexity API key is required',
184
+ };
185
+ }
186
+ const response = await fetch(`https://api.perplexity.ai/models`, {
187
+ method: 'GET',
188
+ headers: {
189
+ Authorization: `Bearer ${apiKey}`,
190
+ },
191
+ });
192
+ if (!response.ok) {
193
+ const errorText = await response.text();
194
+ return {
195
+ success: false,
196
+ error: `Perplexity API error: ${response.status} - ${errorText}`,
197
+ };
198
+ }
199
+ const result = (await response.json());
200
+ return {
201
+ success: true,
202
+ models: result.data,
203
+ };
204
+ }
205
+ catch (error) {
206
+ return {
207
+ success: false,
208
+ error: `Failed to list models: ${error.message}`,
209
+ };
210
+ }
211
+ }
212
+ /**
213
+ * Search with Perplexity
214
+ */
215
+ async _tool_search(request) {
216
+ try {
217
+ const params = request.params;
218
+ const { query, search_domain, include_domains, exclude_domains, use_autoprompt, type, apiKey = this.defaultApiKey, } = params;
219
+ if (!query) {
220
+ return {
221
+ success: false,
222
+ error: 'Query is required',
223
+ };
224
+ }
225
+ if (!apiKey) {
226
+ return {
227
+ success: false,
228
+ error: 'Perplexity API key is required',
229
+ };
230
+ }
231
+ const searchRequest = {
232
+ query: query,
233
+ };
234
+ // Add optional parameters if provided
235
+ if (search_domain !== undefined)
236
+ searchRequest.search_domain = search_domain;
237
+ if (include_domains !== undefined)
238
+ searchRequest.include_domains = include_domains;
239
+ if (exclude_domains !== undefined)
240
+ searchRequest.exclude_domains = exclude_domains;
241
+ if (use_autoprompt !== undefined)
242
+ searchRequest.use_autoprompt = use_autoprompt;
243
+ if (type !== undefined)
244
+ searchRequest.type = type;
245
+ const response = await fetch(`https://api.perplexity.ai/search`, {
246
+ method: 'POST',
247
+ headers: {
248
+ 'Content-Type': 'application/json',
249
+ Authorization: `Bearer ${apiKey}`,
250
+ },
251
+ body: JSON.stringify(searchRequest),
252
+ });
253
+ if (!response.ok) {
254
+ const errorText = await response.text();
255
+ return {
256
+ success: false,
257
+ error: `Perplexity API error: ${response.status} - ${errorText}`,
258
+ };
259
+ }
260
+ const result = (await response.json());
261
+ return {
262
+ success: true,
263
+ response: result.choices[0]?.message?.content || '',
264
+ model: result.model,
265
+ usage: result.usage,
266
+ finish_reason: result.choices[0]?.finish_reason,
267
+ };
268
+ }
269
+ catch (error) {
270
+ return {
271
+ success: false,
272
+ error: `Failed to search: ${error.message}`,
273
+ };
274
+ }
275
+ }
276
+ /**
277
+ * Check Perplexity API status
278
+ */
279
+ async _tool_status(request) {
280
+ try {
281
+ const params = request.params;
282
+ const { apiKey = this.defaultApiKey } = params;
283
+ if (!apiKey) {
284
+ return {
285
+ success: false,
286
+ status: 'error',
287
+ error: 'Perplexity API key is required',
288
+ };
289
+ }
290
+ const response = await fetch(`https://api.perplexity.ai/models`, {
291
+ method: 'GET',
292
+ headers: {
293
+ Authorization: `Bearer ${apiKey}`,
294
+ },
295
+ });
296
+ return {
297
+ success: response.ok,
298
+ status: response.ok ? 'online' : 'offline',
299
+ status_code: response.status,
300
+ };
301
+ }
302
+ catch (error) {
303
+ return {
304
+ success: false,
305
+ status: 'offline',
306
+ error: `Connection failed: ${error.message}`,
307
+ };
308
+ }
309
+ }
310
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=basic.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic.spec.d.ts","sourceRoot":"","sources":["../../test/basic.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";