maxun-sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/dist/builders/extract-builder.d.ts +34 -0
- package/dist/builders/extract-builder.d.ts.map +1 -0
- package/dist/builders/extract-builder.js +71 -0
- package/dist/builders/extract-builder.js.map +1 -0
- package/dist/builders/workflow-builder.d.ts +92 -0
- package/dist/builders/workflow-builder.d.ts.map +1 -0
- package/dist/builders/workflow-builder.js +207 -0
- package/dist/builders/workflow-builder.js.map +1 -0
- package/dist/client/maxun-client.d.ts +74 -0
- package/dist/client/maxun-client.d.ts.map +1 -0
- package/dist/client/maxun-client.js +210 -0
- package/dist/client/maxun-client.js.map +1 -0
- package/dist/extract.d.ts +54 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +81 -0
- package/dist/extract.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/index.d.ts +12 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +32 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/providers/anthropic.d.ts +13 -0
- package/dist/llm/providers/anthropic.d.ts.map +1 -0
- package/dist/llm/providers/anthropic.js +61 -0
- package/dist/llm/providers/anthropic.js.map +1 -0
- package/dist/llm/providers/base.d.ts +30 -0
- package/dist/llm/providers/base.d.ts.map +1 -0
- package/dist/llm/providers/base.js +27 -0
- package/dist/llm/providers/base.js.map +1 -0
- package/dist/llm/providers/ollama.d.ts +14 -0
- package/dist/llm/providers/ollama.d.ts.map +1 -0
- package/dist/llm/providers/ollama.js +56 -0
- package/dist/llm/providers/ollama.js.map +1 -0
- package/dist/llm/providers/openai.d.ts +13 -0
- package/dist/llm/providers/openai.d.ts.map +1 -0
- package/dist/llm/providers/openai.js +58 -0
- package/dist/llm/providers/openai.js.map +1 -0
- package/dist/llm/types.d.ts +25 -0
- package/dist/llm/types.d.ts.map +1 -0
- package/dist/llm/types.js +6 -0
- package/dist/llm/types.js.map +1 -0
- package/dist/robot/robot.d.ts +82 -0
- package/dist/robot/robot.d.ts.map +1 -0
- package/dist/robot/robot.js +128 -0
- package/dist/robot/robot.js.map +1 -0
- package/dist/scrape.d.ts +30 -0
- package/dist/scrape.d.ts.map +1 -0
- package/dist/scrape.js +39 -0
- package/dist/scrape.js.map +1 -0
- package/dist/types/index.d.ts +162 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Maxun API Client
|
|
4
|
+
* Handles all HTTP communication with the Maxun backend API
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Client = void 0;
|
|
11
|
+
const axios_1 = __importDefault(require("axios"));
|
|
12
|
+
const http_1 = __importDefault(require("http"));
|
|
13
|
+
const https_1 = __importDefault(require("https"));
|
|
14
|
+
const types_1 = require("../types");
|
|
15
|
+
class Client {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.apiKey = config.apiKey;
|
|
18
|
+
this.axios = axios_1.default.create({
|
|
19
|
+
baseURL: config.baseUrl || 'http://localhost:8080/api/sdk',
|
|
20
|
+
headers: {
|
|
21
|
+
'x-api-key': this.apiKey,
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
},
|
|
24
|
+
timeout: 30000,
|
|
25
|
+
});
|
|
26
|
+
// Add response interceptor for error handling
|
|
27
|
+
this.axios.interceptors.response.use((response) => response, (error) => {
|
|
28
|
+
throw this.handleError(error);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Handle API errors and convert to MaxunError
|
|
33
|
+
*/
|
|
34
|
+
handleError(error) {
|
|
35
|
+
if (error.response) {
|
|
36
|
+
const data = error.response.data;
|
|
37
|
+
return new types_1.MaxunError(data?.error || data?.message || 'API request failed', error.response.status, data);
|
|
38
|
+
}
|
|
39
|
+
else if (error.request) {
|
|
40
|
+
return new types_1.MaxunError('No response from server', undefined, error.message);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return new types_1.MaxunError(error.message);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get all robots for the authenticated user
|
|
48
|
+
*/
|
|
49
|
+
async getRobots() {
|
|
50
|
+
const response = await this.axios.get('/robots');
|
|
51
|
+
return response.data.data || [];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get a specific robot by ID
|
|
55
|
+
*/
|
|
56
|
+
async getRobot(robotId) {
|
|
57
|
+
const response = await this.axios.get(`/robots/${robotId}`);
|
|
58
|
+
if (!response.data.data) {
|
|
59
|
+
throw new types_1.MaxunError(`Robot ${robotId} not found`, 404);
|
|
60
|
+
}
|
|
61
|
+
return response.data.data;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a new robot
|
|
65
|
+
*/
|
|
66
|
+
async createRobot(workflowFile) {
|
|
67
|
+
// Create a fresh HTTP agent for this request to avoid stale connections
|
|
68
|
+
const httpAgent = new http_1.default.Agent({ keepAlive: false });
|
|
69
|
+
const httpsAgent = new https_1.default.Agent({ keepAlive: false });
|
|
70
|
+
const robotTypeValue = workflowFile.meta?.robotType || workflowFile.meta?.type;
|
|
71
|
+
const payload = {
|
|
72
|
+
...workflowFile,
|
|
73
|
+
meta: {
|
|
74
|
+
...workflowFile.meta,
|
|
75
|
+
type: robotTypeValue,
|
|
76
|
+
robotType: robotTypeValue,
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const response = await this.axios.post('/robots', payload, {
|
|
80
|
+
timeout: 120000,
|
|
81
|
+
httpAgent,
|
|
82
|
+
httpsAgent,
|
|
83
|
+
});
|
|
84
|
+
if (!response.data.data) {
|
|
85
|
+
throw new types_1.MaxunError('Failed to create robot');
|
|
86
|
+
}
|
|
87
|
+
return response.data.data;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Update an existing robot
|
|
91
|
+
*/
|
|
92
|
+
async updateRobot(robotId, updates) {
|
|
93
|
+
const response = await this.axios.put(`/robots/${robotId}`, updates);
|
|
94
|
+
if (!response.data.data) {
|
|
95
|
+
throw new types_1.MaxunError(`Failed to update robot ${robotId}`);
|
|
96
|
+
}
|
|
97
|
+
return response.data.data;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Delete a robot
|
|
101
|
+
*/
|
|
102
|
+
async deleteRobot(robotId) {
|
|
103
|
+
await this.axios.delete(`/robots/${robotId}`);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Execute a robot and get results
|
|
107
|
+
*/
|
|
108
|
+
async executeRobot(robotId, options) {
|
|
109
|
+
// Execute and wait for completion (endpoint handles waiting)
|
|
110
|
+
const response = await this.axios.post(`/robots/${robotId}/execute`, {
|
|
111
|
+
params: options?.params,
|
|
112
|
+
webhook: options?.webhook,
|
|
113
|
+
}, {
|
|
114
|
+
timeout: options?.timeout || 300000, // 5 minutes default
|
|
115
|
+
});
|
|
116
|
+
if (!response.data.data) {
|
|
117
|
+
throw new types_1.MaxunError('Failed to execute robot');
|
|
118
|
+
}
|
|
119
|
+
return response.data.data;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get all runs for a robot
|
|
123
|
+
*/
|
|
124
|
+
async getRuns(robotId) {
|
|
125
|
+
const response = await this.axios.get(`/robots/${robotId}/runs`);
|
|
126
|
+
return response.data.data || [];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get a specific run by ID
|
|
130
|
+
*/
|
|
131
|
+
async getRun(robotId, runId) {
|
|
132
|
+
const response = await this.axios.get(`/robots/${robotId}/runs/${runId}`);
|
|
133
|
+
if (!response.data.data) {
|
|
134
|
+
throw new types_1.MaxunError(`Run ${runId} not found`, 404);
|
|
135
|
+
}
|
|
136
|
+
return response.data.data;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Abort a running or queued run
|
|
140
|
+
*/
|
|
141
|
+
async abortRun(robotId, runId) {
|
|
142
|
+
await this.axios.post(`/robots/${robotId}/runs/${runId}/abort`);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Schedule a robot for periodic execution
|
|
146
|
+
*/
|
|
147
|
+
async scheduleRobot(robotId, schedule) {
|
|
148
|
+
const response = await this.axios.put(`/robots/${robotId}`, { schedule });
|
|
149
|
+
if (!response.data.data) {
|
|
150
|
+
throw new types_1.MaxunError(`Failed to schedule robot ${robotId}`);
|
|
151
|
+
}
|
|
152
|
+
return response.data.data;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Remove schedule from a robot
|
|
156
|
+
*/
|
|
157
|
+
async unscheduleRobot(robotId) {
|
|
158
|
+
const response = await this.axios.put(`/robots/${robotId}`, { schedule: null });
|
|
159
|
+
if (!response.data.data) {
|
|
160
|
+
throw new types_1.MaxunError(`Failed to unschedule robot ${robotId}`);
|
|
161
|
+
}
|
|
162
|
+
return response.data.data;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Add a webhook to a robot
|
|
166
|
+
*/
|
|
167
|
+
async addWebhook(robotId, webhook) {
|
|
168
|
+
const robot = await this.getRobot(robotId);
|
|
169
|
+
const webhooks = robot.webhooks || [];
|
|
170
|
+
// Add webhook with proper structure
|
|
171
|
+
const newWebhook = {
|
|
172
|
+
id: `webhook_${Date.now()}`,
|
|
173
|
+
url: webhook.url,
|
|
174
|
+
events: webhook.events || ['run.completed', 'run.failed'],
|
|
175
|
+
active: true,
|
|
176
|
+
createdAt: new Date().toISOString(),
|
|
177
|
+
updatedAt: new Date().toISOString(),
|
|
178
|
+
};
|
|
179
|
+
webhooks.push(newWebhook);
|
|
180
|
+
const response = await this.axios.put(`/robots/${robotId}`, {
|
|
181
|
+
webhooks,
|
|
182
|
+
});
|
|
183
|
+
if (!response.data.data) {
|
|
184
|
+
throw new types_1.MaxunError(`Failed to add webhook to robot ${robotId}`);
|
|
185
|
+
}
|
|
186
|
+
return response.data.data;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* LLM-based extraction - extract data using natural language prompt
|
|
190
|
+
*/
|
|
191
|
+
async extractWithLLM(url, options) {
|
|
192
|
+
const response = await this.axios.post('/extract/llm', {
|
|
193
|
+
url,
|
|
194
|
+
prompt: options.prompt,
|
|
195
|
+
llmProvider: options.llmProvider,
|
|
196
|
+
llmModel: options.llmModel,
|
|
197
|
+
llmApiKey: options.llmApiKey,
|
|
198
|
+
llmBaseUrl: options.llmBaseUrl,
|
|
199
|
+
robotName: options.robotName,
|
|
200
|
+
}, {
|
|
201
|
+
timeout: 300000,
|
|
202
|
+
});
|
|
203
|
+
if (!response.data.data) {
|
|
204
|
+
throw new types_1.MaxunError('Failed to extract data with LLM');
|
|
205
|
+
}
|
|
206
|
+
return response.data.data;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.Client = Client;
|
|
210
|
+
//# sourceMappingURL=maxun-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maxun-client.js","sourceRoot":"","sources":["../../src/client/maxun-client.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,kDAAyD;AACzD,gDAAwB;AACxB,kDAA0B;AAC1B,oCAWkB;AAElB,MAAa,MAAM;IAIjB,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE5B,IAAI,CAAC,KAAK,GAAG,eAAK,CAAC,MAAM,CAAC;YACxB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,+BAA+B;YAC1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;YACE,OAAO,EAAE,MAAM;SAChB,CACF,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,kBAAU,CAAC,iCAAiC,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF;AAxPD,wBAwPC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract - Main class for the Extract SDK
|
|
3
|
+
*/
|
|
4
|
+
import { Client } from './client/maxun-client';
|
|
5
|
+
import { Config } from './types';
|
|
6
|
+
import { ExtractBuilder } from './builders/extract-builder';
|
|
7
|
+
import { Robot } from './robot/robot';
|
|
8
|
+
export declare class Extract {
|
|
9
|
+
client: Client;
|
|
10
|
+
constructor(config: Config);
|
|
11
|
+
/**
|
|
12
|
+
* Create a new extraction workflow
|
|
13
|
+
*/
|
|
14
|
+
create(name: string): ExtractBuilder;
|
|
15
|
+
/**
|
|
16
|
+
* Build and save the robot to Maxun
|
|
17
|
+
*/
|
|
18
|
+
build(builder: ExtractBuilder): Promise<Robot>;
|
|
19
|
+
/**
|
|
20
|
+
* Get all extract robots
|
|
21
|
+
*/
|
|
22
|
+
getRobots(): Promise<Robot[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Get a specific robot by ID
|
|
25
|
+
*/
|
|
26
|
+
getRobot(robotId: string): Promise<Robot>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete a robot
|
|
29
|
+
*/
|
|
30
|
+
deleteRobot(robotId: string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* LLM-based extraction - create a robot using natural language prompt
|
|
33
|
+
* The robot is saved and can be executed anytime by the user
|
|
34
|
+
*
|
|
35
|
+
* @param url - The URL to extract data from
|
|
36
|
+
* @param options - Extraction options
|
|
37
|
+
* @param options.prompt - Natural language prompt describing what to extract
|
|
38
|
+
* @param options.llmProvider - LLM provider to use: 'anthropic', 'openai', or 'ollama' (default: 'ollama')
|
|
39
|
+
* @param options.llmModel - Model name (default: 'llama3.2-vision' for ollama, 'claude-3-5-sonnet-20241022' for anthropic, 'gpt-4-vision-preview' for openai)
|
|
40
|
+
* @param options.llmApiKey - API key for the LLM provider (not needed for ollama)
|
|
41
|
+
* @param options.llmBaseUrl - Base URL for the LLM provider (default: 'http://localhost:11434' for ollama)
|
|
42
|
+
* @param options.robotName - Optional custom name for the robot
|
|
43
|
+
* @returns Robot instance that can be executed
|
|
44
|
+
*/
|
|
45
|
+
extract(url: string, options: {
|
|
46
|
+
prompt: string;
|
|
47
|
+
llmProvider?: 'anthropic' | 'openai' | 'ollama';
|
|
48
|
+
llmModel?: string;
|
|
49
|
+
llmApiKey?: string;
|
|
50
|
+
llmBaseUrl?: string;
|
|
51
|
+
robotName?: string;
|
|
52
|
+
}): Promise<Robot>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAA2B,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,qBAAa,OAAO;IACX,MAAM,EAAE,MAAM,CAAC;gBAEV,MAAM,EAAE,MAAM;IAI1B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc;IAMpC;;OAEG;IACG,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC;IAmBpD;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAQnC;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAK/C;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD;;;;;;;;;;;;;OAaG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE;QAClC,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;QAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,KAAK,CAAC;CAKnB"}
|
package/dist/extract.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Extract - Main class for the Extract SDK
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Extract = void 0;
|
|
7
|
+
const maxun_client_1 = require("./client/maxun-client");
|
|
8
|
+
const extract_builder_1 = require("./builders/extract-builder");
|
|
9
|
+
const robot_1 = require("./robot/robot");
|
|
10
|
+
class Extract {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.client = new maxun_client_1.Client(config);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a new extraction workflow
|
|
16
|
+
*/
|
|
17
|
+
create(name) {
|
|
18
|
+
const builder = new extract_builder_1.ExtractBuilder(name);
|
|
19
|
+
builder.setExtractor(this);
|
|
20
|
+
return builder;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build and save the robot to Maxun
|
|
24
|
+
*/
|
|
25
|
+
async build(builder) {
|
|
26
|
+
const workflow = builder.getWorkflowArray();
|
|
27
|
+
const meta = builder.getMeta();
|
|
28
|
+
// Generate a unique ID for the robot
|
|
29
|
+
const robotId = `robot_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
30
|
+
meta.id = robotId;
|
|
31
|
+
const workflowFile = {
|
|
32
|
+
meta: meta,
|
|
33
|
+
workflow,
|
|
34
|
+
};
|
|
35
|
+
// Create the robot
|
|
36
|
+
const robot = await this.client.createRobot(workflowFile);
|
|
37
|
+
return new robot_1.Robot(this.client, robot);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all extract robots
|
|
41
|
+
*/
|
|
42
|
+
async getRobots() {
|
|
43
|
+
const robots = await this.client.getRobots();
|
|
44
|
+
const extractRobots = robots.filter((r) => r.recording_meta.robotType === 'extract');
|
|
45
|
+
return extractRobots.map((r) => new robot_1.Robot(this.client, r));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get a specific robot by ID
|
|
49
|
+
*/
|
|
50
|
+
async getRobot(robotId) {
|
|
51
|
+
const robot = await this.client.getRobot(robotId);
|
|
52
|
+
return new robot_1.Robot(this.client, robot);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Delete a robot
|
|
56
|
+
*/
|
|
57
|
+
async deleteRobot(robotId) {
|
|
58
|
+
await this.client.deleteRobot(robotId);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* LLM-based extraction - create a robot using natural language prompt
|
|
62
|
+
* The robot is saved and can be executed anytime by the user
|
|
63
|
+
*
|
|
64
|
+
* @param url - The URL to extract data from
|
|
65
|
+
* @param options - Extraction options
|
|
66
|
+
* @param options.prompt - Natural language prompt describing what to extract
|
|
67
|
+
* @param options.llmProvider - LLM provider to use: 'anthropic', 'openai', or 'ollama' (default: 'ollama')
|
|
68
|
+
* @param options.llmModel - Model name (default: 'llama3.2-vision' for ollama, 'claude-3-5-sonnet-20241022' for anthropic, 'gpt-4-vision-preview' for openai)
|
|
69
|
+
* @param options.llmApiKey - API key for the LLM provider (not needed for ollama)
|
|
70
|
+
* @param options.llmBaseUrl - Base URL for the LLM provider (default: 'http://localhost:11434' for ollama)
|
|
71
|
+
* @param options.robotName - Optional custom name for the robot
|
|
72
|
+
* @returns Robot instance that can be executed
|
|
73
|
+
*/
|
|
74
|
+
async extract(url, options) {
|
|
75
|
+
const robotData = await this.client.extractWithLLM(url, options);
|
|
76
|
+
const robot = await this.client.getRobot(robotData.robotId);
|
|
77
|
+
return new robot_1.Robot(this.client, robot);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.Extract = Extract;
|
|
81
|
+
//# sourceMappingURL=extract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,wDAA+C;AAE/C,gEAA4D;AAC5D,yCAAsC;AAEtC,MAAa,OAAO;IAGlB,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAM,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAY;QACjB,MAAM,OAAO,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,OAAuB;QACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QAE/B,qCAAqC;QACrC,MAAM,OAAO,GAAG,SAAS,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACjF,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC;QAElB,MAAM,YAAY,GAAQ;YACxB,IAAI,EAAE,IA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CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;CACF;AA1FD,0BA0FC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maxun SDK - Unified package for web automation and data extraction
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { Extract } from './extract';
|
|
7
|
+
export { Scrape } from './scrape';
|
|
8
|
+
export { Robot } from './robot/robot';
|
|
9
|
+
export { Client } from './client/maxun-client';
|
|
10
|
+
export * from './types';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Maxun SDK - Unified package for web automation and data extraction
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.Client = exports.Robot = exports.Scrape = exports.Extract = void 0;
|
|
23
|
+
// Main classes
|
|
24
|
+
var extract_1 = require("./extract");
|
|
25
|
+
Object.defineProperty(exports, "Extract", { enumerable: true, get: function () { return extract_1.Extract; } });
|
|
26
|
+
var scrape_1 = require("./scrape");
|
|
27
|
+
Object.defineProperty(exports, "Scrape", { enumerable: true, get: function () { return scrape_1.Scrape; } });
|
|
28
|
+
var robot_1 = require("./robot/robot");
|
|
29
|
+
Object.defineProperty(exports, "Robot", { enumerable: true, get: function () { return robot_1.Robot; } });
|
|
30
|
+
var maxun_client_1 = require("./client/maxun-client");
|
|
31
|
+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return maxun_client_1.Client; } });
|
|
32
|
+
// All types
|
|
33
|
+
__exportStar(require("./types"), exports);
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;AAEH,eAAe;AACf,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,uCAAsC;AAA7B,8FAAA,KAAK,OAAA;AACd,sDAA+C;AAAtC,sGAAA,MAAM,OAAA;AAEf,YAAY;AACZ,0CAAwB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseLLMProvider } from './providers/base';
|
|
2
|
+
import { LLMConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Factory function to create LLM provider instances
|
|
5
|
+
*/
|
|
6
|
+
export declare function createLLMProvider(config: LLMConfig): BaseLLMProvider;
|
|
7
|
+
export { BaseLLMProvider } from './providers/base';
|
|
8
|
+
export { OllamaProvider } from './providers/ollama';
|
|
9
|
+
export { AnthropicProvider } from './providers/anthropic';
|
|
10
|
+
export { OpenAIProvider } from './providers/openai';
|
|
11
|
+
export type { LLMConfig, LLMMessage, LLMResponse, LLMProvider } from '../types';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,eAAe,CAWpE;AAGD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAIProvider = exports.AnthropicProvider = exports.OllamaProvider = exports.BaseLLMProvider = void 0;
|
|
4
|
+
exports.createLLMProvider = createLLMProvider;
|
|
5
|
+
const ollama_1 = require("./providers/ollama");
|
|
6
|
+
const anthropic_1 = require("./providers/anthropic");
|
|
7
|
+
const openai_1 = require("./providers/openai");
|
|
8
|
+
/**
|
|
9
|
+
* Factory function to create LLM provider instances
|
|
10
|
+
*/
|
|
11
|
+
function createLLMProvider(config) {
|
|
12
|
+
switch (config.provider) {
|
|
13
|
+
case 'ollama':
|
|
14
|
+
return new ollama_1.OllamaProvider(config);
|
|
15
|
+
case 'anthropic':
|
|
16
|
+
return new anthropic_1.AnthropicProvider(config);
|
|
17
|
+
case 'openai':
|
|
18
|
+
return new openai_1.OpenAIProvider(config);
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`Unsupported LLM provider: ${config.provider}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Re-export types and base class
|
|
24
|
+
var base_1 = require("./providers/base");
|
|
25
|
+
Object.defineProperty(exports, "BaseLLMProvider", { enumerable: true, get: function () { return base_1.BaseLLMProvider; } });
|
|
26
|
+
var ollama_2 = require("./providers/ollama");
|
|
27
|
+
Object.defineProperty(exports, "OllamaProvider", { enumerable: true, get: function () { return ollama_2.OllamaProvider; } });
|
|
28
|
+
var anthropic_2 = require("./providers/anthropic");
|
|
29
|
+
Object.defineProperty(exports, "AnthropicProvider", { enumerable: true, get: function () { return anthropic_2.AnthropicProvider; } });
|
|
30
|
+
var openai_2 = require("./providers/openai");
|
|
31
|
+
Object.defineProperty(exports, "OpenAIProvider", { enumerable: true, get: function () { return openai_2.OpenAIProvider; } });
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":";;;AASA,8CAWC;AAnBD,+CAAoD;AACpD,qDAA0D;AAC1D,+CAAoD;AAGpD;;GAEG;AACH,SAAgB,iBAAiB,CAAC,MAAiB;IACjD,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,KAAK,QAAQ;YACX,OAAO,IAAI,uBAAc,CAAC,MAAM,CAAC,CAAC;QACpC,KAAK,WAAW;YACd,OAAO,IAAI,6BAAiB,CAAC,MAAM,CAAC,CAAC;QACvC,KAAK,QAAQ;YACX,OAAO,IAAI,uBAAc,CAAC,MAAM,CAAC,CAAC;QACpC;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED,iCAAiC;AACjC,yCAAmD;AAA1C,uGAAA,eAAe,OAAA;AACxB,6CAAoD;AAA3C,wGAAA,cAAc,OAAA;AACvB,mDAA0D;AAAjD,8GAAA,iBAAiB,OAAA;AAC1B,6CAAoD;AAA3C,wGAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseLLMProvider } from './base';
|
|
2
|
+
import { LLMMessage, LLMResponse, LLMConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Anthropic provider for Claude models
|
|
5
|
+
*/
|
|
6
|
+
export declare class AnthropicProvider extends BaseLLMProvider {
|
|
7
|
+
private client;
|
|
8
|
+
constructor(config: LLMConfig);
|
|
9
|
+
chat(messages: LLMMessage[]): Promise<LLMResponse>;
|
|
10
|
+
validateConfig(): void;
|
|
11
|
+
getProviderName(): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/llm/providers/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9D;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,eAAe;IACpD,OAAO,CAAC,MAAM,CAAY;gBAEd,MAAM,EAAE,SAAS;IAQvB,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAgCxD,cAAc,IAAI,IAAI;IAUtB,eAAe,IAAI,MAAM;CAG1B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AnthropicProvider = void 0;
|
|
7
|
+
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
8
|
+
const base_1 = require("./base");
|
|
9
|
+
/**
|
|
10
|
+
* Anthropic provider for Claude models
|
|
11
|
+
*/
|
|
12
|
+
class AnthropicProvider extends base_1.BaseLLMProvider {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
super(config);
|
|
15
|
+
this.client = new sdk_1.default({
|
|
16
|
+
apiKey: config.apiKey || process.env.ANTHROPIC_API_KEY
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async chat(messages) {
|
|
20
|
+
try {
|
|
21
|
+
// Anthropic requires system message separately
|
|
22
|
+
const systemMessage = messages.find(m => m.role === 'system');
|
|
23
|
+
const userMessages = messages.filter(m => m.role !== 'system');
|
|
24
|
+
const response = await this.client.messages.create({
|
|
25
|
+
model: this.config.model || 'claude-3-5-sonnet-20241022',
|
|
26
|
+
max_tokens: this.config.maxTokens || 4096,
|
|
27
|
+
temperature: this.config.temperature || 0.7,
|
|
28
|
+
system: systemMessage?.content,
|
|
29
|
+
messages: userMessages.map(msg => ({
|
|
30
|
+
role: msg.role,
|
|
31
|
+
content: msg.content
|
|
32
|
+
}))
|
|
33
|
+
});
|
|
34
|
+
const textContent = response.content.find((c) => c.type === 'text');
|
|
35
|
+
return {
|
|
36
|
+
content: textContent?.type === 'text' ? textContent.text : '',
|
|
37
|
+
usage: {
|
|
38
|
+
promptTokens: response.usage.input_tokens,
|
|
39
|
+
completionTokens: response.usage.output_tokens,
|
|
40
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new Error(`Anthropic API error: ${error.message || error}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
validateConfig() {
|
|
49
|
+
if (!this.config.apiKey && !process.env.ANTHROPIC_API_KEY) {
|
|
50
|
+
throw new Error('Anthropic API key required. Set ANTHROPIC_API_KEY environment variable or provide apiKey in config.');
|
|
51
|
+
}
|
|
52
|
+
if (!this.config.model) {
|
|
53
|
+
console.warn('Anthropic model not specified, using default: claude-3-5-sonnet-20241022');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
getProviderName() {
|
|
57
|
+
return 'Anthropic';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.AnthropicProvider = AnthropicProvider;
|
|
61
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/llm/providers/anthropic.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0C;AAC1C,iCAAyC;AAGzC;;GAEG;AACH,MAAa,iBAAkB,SAAQ,sBAAe;IAGpD,YAAY,MAAiB;QAC3B,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,MAAM,GAAG,IAAI,aAAS,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB;SACvD,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAsB;QAC/B,IAAI,CAAC;YACH,+CAA+C;YAC/C,MAAM,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;YAC9D,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;YAE/D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AE,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,qGAAqG,CAAC,CAAC;QACzH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;IAED,eAAe;QACb,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAxDD,8CAwDC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LLMConfig, LLMMessage, LLMResponse } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for LLM providers
|
|
4
|
+
* Provides common interface for Anthropic, OpenAI, and Ollama
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseLLMProvider {
|
|
7
|
+
protected config: LLMConfig;
|
|
8
|
+
constructor(config: LLMConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Send chat messages to LLM and get response
|
|
11
|
+
*/
|
|
12
|
+
abstract chat(messages: LLMMessage[]): Promise<LLMResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Validate provider-specific configuration
|
|
15
|
+
*/
|
|
16
|
+
abstract validateConfig(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get the provider name
|
|
19
|
+
*/
|
|
20
|
+
abstract getProviderName(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Helper to create system message
|
|
23
|
+
*/
|
|
24
|
+
protected createSystemMessage(content: string): LLMMessage;
|
|
25
|
+
/**
|
|
26
|
+
* Helper to create user message
|
|
27
|
+
*/
|
|
28
|
+
protected createUserMessage(content: string): LLMMessage;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/llm/providers/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE9D;;;GAGG;AACH,8BAAsB,eAAe;IACnC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC;gBAEhB,MAAM,EAAE,SAAS;IAK7B;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAE3D;;OAEG;IACH,QAAQ,CAAC,cAAc,IAAI,IAAI;IAE/B;;OAEG;IACH,QAAQ,CAAC,eAAe,IAAI,MAAM;IAElC;;OAEG;IACH,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU;IAI1D;;OAEG;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU;CAGzD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseLLMProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for LLM providers
|
|
6
|
+
* Provides common interface for Anthropic, OpenAI, and Ollama
|
|
7
|
+
*/
|
|
8
|
+
class BaseLLMProvider {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.validateConfig();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Helper to create system message
|
|
15
|
+
*/
|
|
16
|
+
createSystemMessage(content) {
|
|
17
|
+
return { role: 'system', content };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Helper to create user message
|
|
21
|
+
*/
|
|
22
|
+
createUserMessage(content) {
|
|
23
|
+
return { role: 'user', content };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.BaseLLMProvider = BaseLLMProvider;
|
|
27
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/llm/providers/base.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAsB,eAAe;IAGnC,YAAY,MAAiB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAiBD;;OAEG;IACO,mBAAmB,CAAC,OAAe;QAC3C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IACrC,CAAC;IAED;;OAEG;IACO,iBAAiB,CAAC,OAAe;QACzC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IACnC,CAAC;CACF;AApCD,0CAoCC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseLLMProvider } from './base';
|
|
2
|
+
import { LLMMessage, LLMResponse, LLMConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Ollama provider for local LLM inference
|
|
5
|
+
* Supports Llama, Mistral, and other open-source models
|
|
6
|
+
*/
|
|
7
|
+
export declare class OllamaProvider extends BaseLLMProvider {
|
|
8
|
+
private client;
|
|
9
|
+
constructor(config: LLMConfig);
|
|
10
|
+
chat(messages: LLMMessage[]): Promise<LLMResponse>;
|
|
11
|
+
validateConfig(): void;
|
|
12
|
+
getProviderName(): string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ollama.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../../src/llm/providers/ollama.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9D;;;GAGG;AACH,qBAAa,cAAe,SAAQ,eAAe;IACjD,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,SAAS;IAQvB,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IA2BxD,cAAc,IAAI,IAAI;IAUtB,eAAe,IAAI,MAAM;CAG1B"}
|