skillbroker 0.1.0
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 +21 -0
- package/README.md +265 -0
- package/dist/index.d.mts +147 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +176 -0
- package/dist/index.mjs +146 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 SkillBroker
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# SkillBroker JavaScript/TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Access expert knowledge in your applications with [SkillBroker](https://skillbroker.io) - the marketplace where AI agents pay for human expertise.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install skillbroker
|
|
9
|
+
# or
|
|
10
|
+
yarn add skillbroker
|
|
11
|
+
# or
|
|
12
|
+
pnpm add skillbroker
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { SkillBrokerClient } from 'skillbroker';
|
|
19
|
+
|
|
20
|
+
const client = new SkillBrokerClient();
|
|
21
|
+
|
|
22
|
+
// Search for skills
|
|
23
|
+
const results = await client.search({ query: 'tax advice' });
|
|
24
|
+
console.log(`Found ${results.skills.length} skills`);
|
|
25
|
+
|
|
26
|
+
// Invoke a skill
|
|
27
|
+
const response = await client.invoke(
|
|
28
|
+
'freelancer-tax-advisor',
|
|
29
|
+
'Can I deduct my home office as a freelancer?'
|
|
30
|
+
);
|
|
31
|
+
console.log(response.response);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
### Environment Variables
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Optional: Override the API URL (defaults to https://api.skillbroker.io)
|
|
40
|
+
export SKILLBROKER_API_URL="https://api.skillbroker.io"
|
|
41
|
+
|
|
42
|
+
# Optional: API key for authenticated requests
|
|
43
|
+
export SKILLBROKER_API_KEY="your-api-key"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Programmatic Configuration
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { SkillBrokerClient } from 'skillbroker';
|
|
50
|
+
|
|
51
|
+
const client = new SkillBrokerClient({
|
|
52
|
+
apiUrl: 'https://api.skillbroker.io',
|
|
53
|
+
apiKey: 'your-api-key',
|
|
54
|
+
timeout: 30000, // 30 seconds
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API Reference
|
|
59
|
+
|
|
60
|
+
### SkillBrokerClient
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const client = new SkillBrokerClient(config?: SkillBrokerConfig);
|
|
64
|
+
|
|
65
|
+
// Methods
|
|
66
|
+
await client.getRegistryInfo(): Promise<RegistryInfo>
|
|
67
|
+
await client.search(options?: SearchOptions): Promise<SearchResult>
|
|
68
|
+
await client.getSkill(skillId: string): Promise<Skill>
|
|
69
|
+
await client.invoke(skillId: string, query: string, context?: object): Promise<SkillResponse>
|
|
70
|
+
await client.getCategories(): Promise<Category[]>
|
|
71
|
+
await client.getTopSkills(options?: { limit?: number; category?: string }): Promise<Skill[]>
|
|
72
|
+
await client.getRecommendations(taskDescription: string, limit?: number): Promise<Skill[]>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Types
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
interface Skill {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
description: string;
|
|
82
|
+
category: string;
|
|
83
|
+
version: string;
|
|
84
|
+
author: string;
|
|
85
|
+
tags?: string[];
|
|
86
|
+
pricing?: SkillPricing;
|
|
87
|
+
stats?: SkillStats;
|
|
88
|
+
quality?: SkillQuality;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface SkillResponse {
|
|
92
|
+
success: boolean;
|
|
93
|
+
response: string;
|
|
94
|
+
skillId: string;
|
|
95
|
+
skillName: string;
|
|
96
|
+
tokensUsed?: number;
|
|
97
|
+
cost?: number;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface SearchResult {
|
|
101
|
+
skills: Skill[];
|
|
102
|
+
totalCount: number;
|
|
103
|
+
query?: string;
|
|
104
|
+
category?: string;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Examples
|
|
109
|
+
|
|
110
|
+
### Search for Skills
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { SkillBrokerClient } from 'skillbroker';
|
|
114
|
+
|
|
115
|
+
const client = new SkillBrokerClient();
|
|
116
|
+
|
|
117
|
+
// Search by query
|
|
118
|
+
const results = await client.search({ query: 'financial planning' });
|
|
119
|
+
|
|
120
|
+
// Search by category
|
|
121
|
+
const financeSkills = await client.search({
|
|
122
|
+
category: 'Finance',
|
|
123
|
+
limit: 10
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Display results
|
|
127
|
+
for (const skill of results.skills) {
|
|
128
|
+
console.log(`${skill.name}: ${skill.description}`);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Invoke a Skill
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { SkillBrokerClient } from 'skillbroker';
|
|
136
|
+
|
|
137
|
+
const client = new SkillBrokerClient();
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
const response = await client.invoke(
|
|
141
|
+
'freelancer-tax-advisor',
|
|
142
|
+
'What expenses can I deduct as a freelance developer?',
|
|
143
|
+
{ userType: 'freelancer', country: 'US' } // Optional context
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
console.log(response.response);
|
|
147
|
+
console.log(`Tokens used: ${response.tokensUsed}`);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error('Failed to invoke skill:', error.message);
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Get Recommendations
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { SkillBrokerClient } from 'skillbroker';
|
|
157
|
+
|
|
158
|
+
const client = new SkillBrokerClient();
|
|
159
|
+
|
|
160
|
+
// Get skill recommendations for a task
|
|
161
|
+
const recommendations = await client.getRecommendations(
|
|
162
|
+
'I need help understanding cryptocurrency tax implications',
|
|
163
|
+
3
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
for (const skill of recommendations) {
|
|
167
|
+
console.log(`Recommended: ${skill.name}`);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Get Top Skills
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { SkillBrokerClient } from 'skillbroker';
|
|
175
|
+
|
|
176
|
+
const client = new SkillBrokerClient();
|
|
177
|
+
|
|
178
|
+
// Get top-rated skills
|
|
179
|
+
const topSkills = await client.getTopSkills({ limit: 5 });
|
|
180
|
+
|
|
181
|
+
// Get top skills in a category
|
|
182
|
+
const topFinanceSkills = await client.getTopSkills({
|
|
183
|
+
limit: 5,
|
|
184
|
+
category: 'Finance'
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Error Handling
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import {
|
|
192
|
+
SkillBrokerClient,
|
|
193
|
+
SkillBrokerError,
|
|
194
|
+
SkillNotFoundError,
|
|
195
|
+
InvocationError
|
|
196
|
+
} from 'skillbroker';
|
|
197
|
+
|
|
198
|
+
const client = new SkillBrokerClient();
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
const response = await client.invoke('unknown-skill', 'question');
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (error instanceof SkillNotFoundError) {
|
|
204
|
+
console.error('Skill not found');
|
|
205
|
+
} else if (error instanceof InvocationError) {
|
|
206
|
+
console.error('Failed to invoke skill');
|
|
207
|
+
} else if (error instanceof SkillBrokerError) {
|
|
208
|
+
console.error('API error:', error.message);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Framework Integration
|
|
214
|
+
|
|
215
|
+
### Express.js
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import express from 'express';
|
|
219
|
+
import { SkillBrokerClient } from 'skillbroker';
|
|
220
|
+
|
|
221
|
+
const app = express();
|
|
222
|
+
const client = new SkillBrokerClient();
|
|
223
|
+
|
|
224
|
+
app.post('/ask-expert', async (req, res) => {
|
|
225
|
+
const { skillId, question } = req.body;
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
const response = await client.invoke(skillId, question);
|
|
229
|
+
res.json({ answer: response.response });
|
|
230
|
+
} catch (error) {
|
|
231
|
+
res.status(500).json({ error: error.message });
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Next.js API Route
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
// pages/api/skills/invoke.ts
|
|
240
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
241
|
+
import { SkillBrokerClient } from 'skillbroker';
|
|
242
|
+
|
|
243
|
+
const client = new SkillBrokerClient();
|
|
244
|
+
|
|
245
|
+
export default async function handler(
|
|
246
|
+
req: NextApiRequest,
|
|
247
|
+
res: NextApiResponse
|
|
248
|
+
) {
|
|
249
|
+
const { skillId, query } = req.body;
|
|
250
|
+
|
|
251
|
+
const response = await client.invoke(skillId, query);
|
|
252
|
+
res.json(response);
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Support
|
|
257
|
+
|
|
258
|
+
- Documentation: https://skillbroker.io/docs
|
|
259
|
+
- API Reference: https://api.skillbroker.io/swagger
|
|
260
|
+
- Issues: https://github.com/skillbroker/skillbroker-js/issues
|
|
261
|
+
- Email: contact@skillbroker.io
|
|
262
|
+
|
|
263
|
+
## License
|
|
264
|
+
|
|
265
|
+
MIT License - see LICENSE file for details.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillBroker TypeScript Types
|
|
3
|
+
*/
|
|
4
|
+
interface SkillCapability {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
keywords?: string[];
|
|
8
|
+
}
|
|
9
|
+
interface SkillPricing {
|
|
10
|
+
model: 'free' | 'paid';
|
|
11
|
+
pricePerQuery?: number;
|
|
12
|
+
currency?: string;
|
|
13
|
+
}
|
|
14
|
+
interface SkillStats {
|
|
15
|
+
totalQueries: number;
|
|
16
|
+
averageRating: number;
|
|
17
|
+
}
|
|
18
|
+
interface SkillQuality {
|
|
19
|
+
qualityScore: number;
|
|
20
|
+
feedbackCount: number;
|
|
21
|
+
tier: string;
|
|
22
|
+
}
|
|
23
|
+
interface Skill {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
version: string;
|
|
28
|
+
author: string;
|
|
29
|
+
category: string;
|
|
30
|
+
tags?: string[];
|
|
31
|
+
capabilities?: SkillCapability[];
|
|
32
|
+
pricing?: SkillPricing;
|
|
33
|
+
stats?: SkillStats;
|
|
34
|
+
quality?: SkillQuality;
|
|
35
|
+
}
|
|
36
|
+
interface SkillQuery {
|
|
37
|
+
query: string;
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
maxTokens?: number;
|
|
40
|
+
}
|
|
41
|
+
interface SkillResponse {
|
|
42
|
+
success: boolean;
|
|
43
|
+
response: string;
|
|
44
|
+
skillId: string;
|
|
45
|
+
skillName: string;
|
|
46
|
+
tokensUsed?: number;
|
|
47
|
+
cost?: number;
|
|
48
|
+
}
|
|
49
|
+
interface SearchResult {
|
|
50
|
+
skills: Skill[];
|
|
51
|
+
totalCount: number;
|
|
52
|
+
query?: string;
|
|
53
|
+
category?: string;
|
|
54
|
+
}
|
|
55
|
+
interface RegistryInfo {
|
|
56
|
+
stats: {
|
|
57
|
+
totalSkills: number;
|
|
58
|
+
totalCategories: number;
|
|
59
|
+
totalQueries: number;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
interface SkillBrokerConfig {
|
|
63
|
+
apiUrl?: string;
|
|
64
|
+
apiKey?: string;
|
|
65
|
+
timeout?: number;
|
|
66
|
+
}
|
|
67
|
+
interface SearchOptions {
|
|
68
|
+
query?: string;
|
|
69
|
+
category?: string;
|
|
70
|
+
limit?: number;
|
|
71
|
+
}
|
|
72
|
+
interface Category {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
count: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* SkillBroker API Client
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
declare class SkillBrokerError extends Error {
|
|
83
|
+
constructor(message: string);
|
|
84
|
+
}
|
|
85
|
+
declare class SkillNotFoundError extends SkillBrokerError {
|
|
86
|
+
constructor(skillId: string);
|
|
87
|
+
}
|
|
88
|
+
declare class InvocationError extends SkillBrokerError {
|
|
89
|
+
constructor(skillId: string, message: string);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Client for interacting with the SkillBroker API.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { SkillBrokerClient } from 'skillbroker';
|
|
97
|
+
*
|
|
98
|
+
* const client = new SkillBrokerClient();
|
|
99
|
+
*
|
|
100
|
+
* // Search for skills
|
|
101
|
+
* const results = await client.search({ query: 'tax advice' });
|
|
102
|
+
*
|
|
103
|
+
* // Invoke a skill
|
|
104
|
+
* const response = await client.invoke('skill-id', 'Your question here');
|
|
105
|
+
* console.log(response.response);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare class SkillBrokerClient {
|
|
109
|
+
private apiUrl;
|
|
110
|
+
private apiKey?;
|
|
111
|
+
private timeout;
|
|
112
|
+
constructor(config?: SkillBrokerConfig);
|
|
113
|
+
private request;
|
|
114
|
+
/**
|
|
115
|
+
* Get information about the skill registry.
|
|
116
|
+
*/
|
|
117
|
+
getRegistryInfo(): Promise<RegistryInfo>;
|
|
118
|
+
/**
|
|
119
|
+
* Search for skills in the registry.
|
|
120
|
+
*/
|
|
121
|
+
search(options?: SearchOptions): Promise<SearchResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Get a skill by ID.
|
|
124
|
+
*/
|
|
125
|
+
getSkill(skillId: string): Promise<Skill>;
|
|
126
|
+
/**
|
|
127
|
+
* Invoke a skill with a query.
|
|
128
|
+
*/
|
|
129
|
+
invoke(skillId: string, query: string, context?: Record<string, unknown>): Promise<SkillResponse>;
|
|
130
|
+
/**
|
|
131
|
+
* Get all available skill categories.
|
|
132
|
+
*/
|
|
133
|
+
getCategories(): Promise<Category[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Get top-rated skills from the leaderboard.
|
|
136
|
+
*/
|
|
137
|
+
getTopSkills(options?: {
|
|
138
|
+
limit?: number;
|
|
139
|
+
category?: string;
|
|
140
|
+
}): Promise<Skill[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Get skill recommendations for a task.
|
|
143
|
+
*/
|
|
144
|
+
getRecommendations(taskDescription: string, limit?: number): Promise<Skill[]>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { type Category, InvocationError, type RegistryInfo, type SearchOptions, type SearchResult, type Skill, SkillBrokerClient, type SkillBrokerConfig, SkillBrokerError, type SkillCapability, SkillNotFoundError, type SkillPricing, type SkillQuality, type SkillQuery, type SkillResponse, type SkillStats };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillBroker TypeScript Types
|
|
3
|
+
*/
|
|
4
|
+
interface SkillCapability {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
keywords?: string[];
|
|
8
|
+
}
|
|
9
|
+
interface SkillPricing {
|
|
10
|
+
model: 'free' | 'paid';
|
|
11
|
+
pricePerQuery?: number;
|
|
12
|
+
currency?: string;
|
|
13
|
+
}
|
|
14
|
+
interface SkillStats {
|
|
15
|
+
totalQueries: number;
|
|
16
|
+
averageRating: number;
|
|
17
|
+
}
|
|
18
|
+
interface SkillQuality {
|
|
19
|
+
qualityScore: number;
|
|
20
|
+
feedbackCount: number;
|
|
21
|
+
tier: string;
|
|
22
|
+
}
|
|
23
|
+
interface Skill {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
version: string;
|
|
28
|
+
author: string;
|
|
29
|
+
category: string;
|
|
30
|
+
tags?: string[];
|
|
31
|
+
capabilities?: SkillCapability[];
|
|
32
|
+
pricing?: SkillPricing;
|
|
33
|
+
stats?: SkillStats;
|
|
34
|
+
quality?: SkillQuality;
|
|
35
|
+
}
|
|
36
|
+
interface SkillQuery {
|
|
37
|
+
query: string;
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
maxTokens?: number;
|
|
40
|
+
}
|
|
41
|
+
interface SkillResponse {
|
|
42
|
+
success: boolean;
|
|
43
|
+
response: string;
|
|
44
|
+
skillId: string;
|
|
45
|
+
skillName: string;
|
|
46
|
+
tokensUsed?: number;
|
|
47
|
+
cost?: number;
|
|
48
|
+
}
|
|
49
|
+
interface SearchResult {
|
|
50
|
+
skills: Skill[];
|
|
51
|
+
totalCount: number;
|
|
52
|
+
query?: string;
|
|
53
|
+
category?: string;
|
|
54
|
+
}
|
|
55
|
+
interface RegistryInfo {
|
|
56
|
+
stats: {
|
|
57
|
+
totalSkills: number;
|
|
58
|
+
totalCategories: number;
|
|
59
|
+
totalQueries: number;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
interface SkillBrokerConfig {
|
|
63
|
+
apiUrl?: string;
|
|
64
|
+
apiKey?: string;
|
|
65
|
+
timeout?: number;
|
|
66
|
+
}
|
|
67
|
+
interface SearchOptions {
|
|
68
|
+
query?: string;
|
|
69
|
+
category?: string;
|
|
70
|
+
limit?: number;
|
|
71
|
+
}
|
|
72
|
+
interface Category {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
count: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* SkillBroker API Client
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
declare class SkillBrokerError extends Error {
|
|
83
|
+
constructor(message: string);
|
|
84
|
+
}
|
|
85
|
+
declare class SkillNotFoundError extends SkillBrokerError {
|
|
86
|
+
constructor(skillId: string);
|
|
87
|
+
}
|
|
88
|
+
declare class InvocationError extends SkillBrokerError {
|
|
89
|
+
constructor(skillId: string, message: string);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Client for interacting with the SkillBroker API.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { SkillBrokerClient } from 'skillbroker';
|
|
97
|
+
*
|
|
98
|
+
* const client = new SkillBrokerClient();
|
|
99
|
+
*
|
|
100
|
+
* // Search for skills
|
|
101
|
+
* const results = await client.search({ query: 'tax advice' });
|
|
102
|
+
*
|
|
103
|
+
* // Invoke a skill
|
|
104
|
+
* const response = await client.invoke('skill-id', 'Your question here');
|
|
105
|
+
* console.log(response.response);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare class SkillBrokerClient {
|
|
109
|
+
private apiUrl;
|
|
110
|
+
private apiKey?;
|
|
111
|
+
private timeout;
|
|
112
|
+
constructor(config?: SkillBrokerConfig);
|
|
113
|
+
private request;
|
|
114
|
+
/**
|
|
115
|
+
* Get information about the skill registry.
|
|
116
|
+
*/
|
|
117
|
+
getRegistryInfo(): Promise<RegistryInfo>;
|
|
118
|
+
/**
|
|
119
|
+
* Search for skills in the registry.
|
|
120
|
+
*/
|
|
121
|
+
search(options?: SearchOptions): Promise<SearchResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Get a skill by ID.
|
|
124
|
+
*/
|
|
125
|
+
getSkill(skillId: string): Promise<Skill>;
|
|
126
|
+
/**
|
|
127
|
+
* Invoke a skill with a query.
|
|
128
|
+
*/
|
|
129
|
+
invoke(skillId: string, query: string, context?: Record<string, unknown>): Promise<SkillResponse>;
|
|
130
|
+
/**
|
|
131
|
+
* Get all available skill categories.
|
|
132
|
+
*/
|
|
133
|
+
getCategories(): Promise<Category[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Get top-rated skills from the leaderboard.
|
|
136
|
+
*/
|
|
137
|
+
getTopSkills(options?: {
|
|
138
|
+
limit?: number;
|
|
139
|
+
category?: string;
|
|
140
|
+
}): Promise<Skill[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Get skill recommendations for a task.
|
|
143
|
+
*/
|
|
144
|
+
getRecommendations(taskDescription: string, limit?: number): Promise<Skill[]>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { type Category, InvocationError, type RegistryInfo, type SearchOptions, type SearchResult, type Skill, SkillBrokerClient, type SkillBrokerConfig, SkillBrokerError, type SkillCapability, SkillNotFoundError, type SkillPricing, type SkillQuality, type SkillQuery, type SkillResponse, type SkillStats };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
InvocationError: () => InvocationError,
|
|
24
|
+
SkillBrokerClient: () => SkillBrokerClient,
|
|
25
|
+
SkillBrokerError: () => SkillBrokerError,
|
|
26
|
+
SkillNotFoundError: () => SkillNotFoundError
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/client.ts
|
|
31
|
+
var SkillBrokerError = class extends Error {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "SkillBrokerError";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var SkillNotFoundError = class extends SkillBrokerError {
|
|
38
|
+
constructor(skillId) {
|
|
39
|
+
super(`Skill not found: ${skillId}`);
|
|
40
|
+
this.name = "SkillNotFoundError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var InvocationError = class extends SkillBrokerError {
|
|
44
|
+
constructor(skillId, message) {
|
|
45
|
+
super(`Failed to invoke skill ${skillId}: ${message}`);
|
|
46
|
+
this.name = "InvocationError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var DEFAULT_API_URL = "https://api.skillbroker.io";
|
|
50
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
51
|
+
var SkillBrokerClient = class {
|
|
52
|
+
constructor(config = {}) {
|
|
53
|
+
this.apiUrl = config.apiUrl || process.env.SKILLBROKER_API_URL || DEFAULT_API_URL;
|
|
54
|
+
this.apiKey = config.apiKey || process.env.SKILLBROKER_API_KEY;
|
|
55
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT;
|
|
56
|
+
}
|
|
57
|
+
async request(method, endpoint, options = {}) {
|
|
58
|
+
const url = new URL(endpoint, this.apiUrl);
|
|
59
|
+
if (options.params) {
|
|
60
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
61
|
+
url.searchParams.append(key, String(value));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const headers = {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
"User-Agent": "skillbroker-js/0.1.0"
|
|
67
|
+
};
|
|
68
|
+
if (this.apiKey) {
|
|
69
|
+
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
70
|
+
}
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(url.toString(), {
|
|
75
|
+
method,
|
|
76
|
+
headers,
|
|
77
|
+
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
78
|
+
signal: controller.signal
|
|
79
|
+
});
|
|
80
|
+
clearTimeout(timeoutId);
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
if (response.status === 404) {
|
|
83
|
+
throw new SkillNotFoundError(endpoint);
|
|
84
|
+
}
|
|
85
|
+
throw new SkillBrokerError(`API error: ${response.status} ${response.statusText}`);
|
|
86
|
+
}
|
|
87
|
+
return response.json();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
clearTimeout(timeoutId);
|
|
90
|
+
if (error instanceof SkillBrokerError) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
throw new SkillBrokerError(`Request failed: ${error}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get information about the skill registry.
|
|
98
|
+
*/
|
|
99
|
+
async getRegistryInfo() {
|
|
100
|
+
return this.request("GET", "/api/Registry");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Search for skills in the registry.
|
|
104
|
+
*/
|
|
105
|
+
async search(options = {}) {
|
|
106
|
+
const params = {};
|
|
107
|
+
if (options.query) params.q = options.query;
|
|
108
|
+
if (options.category) params.category = options.category;
|
|
109
|
+
if (options.limit) params.limit = options.limit;
|
|
110
|
+
const data = await this.request("GET", "/api/Registry/search", { params });
|
|
111
|
+
return {
|
|
112
|
+
skills: data.skills || [],
|
|
113
|
+
totalCount: data.skills?.length || 0,
|
|
114
|
+
query: options.query,
|
|
115
|
+
category: options.category
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get a skill by ID.
|
|
120
|
+
*/
|
|
121
|
+
async getSkill(skillId) {
|
|
122
|
+
return this.request("GET", `/api/Registry/skills/${skillId}/manifest`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Invoke a skill with a query.
|
|
126
|
+
*/
|
|
127
|
+
async invoke(skillId, query, context) {
|
|
128
|
+
const body = { query };
|
|
129
|
+
if (context) body.context = context;
|
|
130
|
+
try {
|
|
131
|
+
const data = await this.request("POST", `/api/Registry/skills/${skillId}/invoke`, { body });
|
|
132
|
+
return {
|
|
133
|
+
success: true,
|
|
134
|
+
response: data.response || "",
|
|
135
|
+
skillId,
|
|
136
|
+
skillName: data.skillName || "",
|
|
137
|
+
tokensUsed: data.tokensUsed,
|
|
138
|
+
cost: data.cost
|
|
139
|
+
};
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw new InvocationError(skillId, String(error));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get all available skill categories.
|
|
146
|
+
*/
|
|
147
|
+
async getCategories() {
|
|
148
|
+
return this.request("GET", "/api/Registry/categories");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get top-rated skills from the leaderboard.
|
|
152
|
+
*/
|
|
153
|
+
async getTopSkills(options = {}) {
|
|
154
|
+
const params = {};
|
|
155
|
+
if (options.limit) params.limit = options.limit;
|
|
156
|
+
if (options.category) params.category = options.category;
|
|
157
|
+
const data = await this.request("GET", "/api/quality/leaderboard", { params });
|
|
158
|
+
return data.skills || [];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get skill recommendations for a task.
|
|
162
|
+
*/
|
|
163
|
+
async getRecommendations(taskDescription, limit = 5) {
|
|
164
|
+
const data = await this.request("POST", "/api/quality/recommend", {
|
|
165
|
+
body: { taskDescription, limit }
|
|
166
|
+
});
|
|
167
|
+
return data.recommendations || [];
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
InvocationError,
|
|
173
|
+
SkillBrokerClient,
|
|
174
|
+
SkillBrokerError,
|
|
175
|
+
SkillNotFoundError
|
|
176
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var SkillBrokerError = class extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "SkillBrokerError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var SkillNotFoundError = class extends SkillBrokerError {
|
|
9
|
+
constructor(skillId) {
|
|
10
|
+
super(`Skill not found: ${skillId}`);
|
|
11
|
+
this.name = "SkillNotFoundError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var InvocationError = class extends SkillBrokerError {
|
|
15
|
+
constructor(skillId, message) {
|
|
16
|
+
super(`Failed to invoke skill ${skillId}: ${message}`);
|
|
17
|
+
this.name = "InvocationError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var DEFAULT_API_URL = "https://api.skillbroker.io";
|
|
21
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
22
|
+
var SkillBrokerClient = class {
|
|
23
|
+
constructor(config = {}) {
|
|
24
|
+
this.apiUrl = config.apiUrl || process.env.SKILLBROKER_API_URL || DEFAULT_API_URL;
|
|
25
|
+
this.apiKey = config.apiKey || process.env.SKILLBROKER_API_KEY;
|
|
26
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT;
|
|
27
|
+
}
|
|
28
|
+
async request(method, endpoint, options = {}) {
|
|
29
|
+
const url = new URL(endpoint, this.apiUrl);
|
|
30
|
+
if (options.params) {
|
|
31
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
32
|
+
url.searchParams.append(key, String(value));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const headers = {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
"User-Agent": "skillbroker-js/0.1.0"
|
|
38
|
+
};
|
|
39
|
+
if (this.apiKey) {
|
|
40
|
+
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
41
|
+
}
|
|
42
|
+
const controller = new AbortController();
|
|
43
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
44
|
+
try {
|
|
45
|
+
const response = await fetch(url.toString(), {
|
|
46
|
+
method,
|
|
47
|
+
headers,
|
|
48
|
+
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
49
|
+
signal: controller.signal
|
|
50
|
+
});
|
|
51
|
+
clearTimeout(timeoutId);
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
if (response.status === 404) {
|
|
54
|
+
throw new SkillNotFoundError(endpoint);
|
|
55
|
+
}
|
|
56
|
+
throw new SkillBrokerError(`API error: ${response.status} ${response.statusText}`);
|
|
57
|
+
}
|
|
58
|
+
return response.json();
|
|
59
|
+
} catch (error) {
|
|
60
|
+
clearTimeout(timeoutId);
|
|
61
|
+
if (error instanceof SkillBrokerError) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
throw new SkillBrokerError(`Request failed: ${error}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get information about the skill registry.
|
|
69
|
+
*/
|
|
70
|
+
async getRegistryInfo() {
|
|
71
|
+
return this.request("GET", "/api/Registry");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Search for skills in the registry.
|
|
75
|
+
*/
|
|
76
|
+
async search(options = {}) {
|
|
77
|
+
const params = {};
|
|
78
|
+
if (options.query) params.q = options.query;
|
|
79
|
+
if (options.category) params.category = options.category;
|
|
80
|
+
if (options.limit) params.limit = options.limit;
|
|
81
|
+
const data = await this.request("GET", "/api/Registry/search", { params });
|
|
82
|
+
return {
|
|
83
|
+
skills: data.skills || [],
|
|
84
|
+
totalCount: data.skills?.length || 0,
|
|
85
|
+
query: options.query,
|
|
86
|
+
category: options.category
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get a skill by ID.
|
|
91
|
+
*/
|
|
92
|
+
async getSkill(skillId) {
|
|
93
|
+
return this.request("GET", `/api/Registry/skills/${skillId}/manifest`);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Invoke a skill with a query.
|
|
97
|
+
*/
|
|
98
|
+
async invoke(skillId, query, context) {
|
|
99
|
+
const body = { query };
|
|
100
|
+
if (context) body.context = context;
|
|
101
|
+
try {
|
|
102
|
+
const data = await this.request("POST", `/api/Registry/skills/${skillId}/invoke`, { body });
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
response: data.response || "",
|
|
106
|
+
skillId,
|
|
107
|
+
skillName: data.skillName || "",
|
|
108
|
+
tokensUsed: data.tokensUsed,
|
|
109
|
+
cost: data.cost
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
throw new InvocationError(skillId, String(error));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get all available skill categories.
|
|
117
|
+
*/
|
|
118
|
+
async getCategories() {
|
|
119
|
+
return this.request("GET", "/api/Registry/categories");
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get top-rated skills from the leaderboard.
|
|
123
|
+
*/
|
|
124
|
+
async getTopSkills(options = {}) {
|
|
125
|
+
const params = {};
|
|
126
|
+
if (options.limit) params.limit = options.limit;
|
|
127
|
+
if (options.category) params.category = options.category;
|
|
128
|
+
const data = await this.request("GET", "/api/quality/leaderboard", { params });
|
|
129
|
+
return data.skills || [];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get skill recommendations for a task.
|
|
133
|
+
*/
|
|
134
|
+
async getRecommendations(taskDescription, limit = 5) {
|
|
135
|
+
const data = await this.request("POST", "/api/quality/recommend", {
|
|
136
|
+
body: { taskDescription, limit }
|
|
137
|
+
});
|
|
138
|
+
return data.recommendations || [];
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
export {
|
|
142
|
+
InvocationError,
|
|
143
|
+
SkillBrokerClient,
|
|
144
|
+
SkillBrokerError,
|
|
145
|
+
SkillNotFoundError
|
|
146
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "skillbroker",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript/TypeScript SDK for SkillBroker - Access expert knowledge in your AI applications",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
22
|
+
"test": "jest",
|
|
23
|
+
"lint": "eslint src/",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"skillbroker",
|
|
28
|
+
"ai",
|
|
29
|
+
"agents",
|
|
30
|
+
"langchain",
|
|
31
|
+
"openai",
|
|
32
|
+
"knowledge",
|
|
33
|
+
"blockchain",
|
|
34
|
+
"marketplace"
|
|
35
|
+
],
|
|
36
|
+
"author": "Alex Morozov <contact@skillbroker.io>",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/skillbroker/skillbroker-js.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/skillbroker/skillbroker-js/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://skillbroker.io",
|
|
46
|
+
"dependencies": {},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^20.0.0",
|
|
49
|
+
"tsup": "^8.0.0",
|
|
50
|
+
"typescript": "^5.0.0",
|
|
51
|
+
"jest": "^29.0.0",
|
|
52
|
+
"@types/jest": "^29.0.0",
|
|
53
|
+
"ts-jest": "^29.0.0"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=16.0.0"
|
|
57
|
+
}
|
|
58
|
+
}
|