@skillzmarket/sdk 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 +313 -0
- package/dist/client.d.ts +18 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +118 -0
- package/dist/client.js.map +1 -0
- package/dist/creator/auth.d.ts +50 -0
- package/dist/creator/auth.d.ts.map +1 -0
- package/dist/creator/auth.js +114 -0
- package/dist/creator/auth.js.map +1 -0
- package/dist/creator/index.d.ts +27 -0
- package/dist/creator/index.d.ts.map +1 -0
- package/dist/creator/index.js +26 -0
- package/dist/creator/index.js.map +1 -0
- package/dist/creator/payment.d.ts +20 -0
- package/dist/creator/payment.d.ts.map +1 -0
- package/dist/creator/payment.js +46 -0
- package/dist/creator/payment.js.map +1 -0
- package/dist/creator/register.d.ts +35 -0
- package/dist/creator/register.d.ts.map +1 -0
- package/dist/creator/register.js +165 -0
- package/dist/creator/register.js.map +1 -0
- package/dist/creator/serve.d.ts +19 -0
- package/dist/creator/serve.d.ts.map +1 -0
- package/dist/creator/serve.js +163 -0
- package/dist/creator/serve.js.map +1 -0
- package/dist/creator/skill.d.ts +20 -0
- package/dist/creator/skill.d.ts.map +1 -0
- package/dist/creator/skill.js +40 -0
- package/dist/creator/skill.js.map +1 -0
- package/dist/creator/types.d.ts +173 -0
- package/dist/creator/types.d.ts.map +1 -0
- package/dist/creator/types.js +2 -0
- package/dist/creator/types.js.map +1 -0
- package/dist/creator/utils/price.d.ts +19 -0
- package/dist/creator/utils/price.d.ts.map +1 -0
- package/dist/creator/utils/price.js +62 -0
- package/dist/creator/utils/price.js.map +1 -0
- package/dist/creator/utils/wallet.d.ts +22 -0
- package/dist/creator/utils/wallet.d.ts.map +1 -0
- package/dist/creator/utils/wallet.js +45 -0
- package/dist/creator/utils/wallet.js.map +1 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +40 -0
- package/dist/discovery.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/payment.d.ts +20 -0
- package/dist/payment.d.ts.map +1 -0
- package/dist/payment.js +34 -0
- package/dist/payment.js.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/creator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG3D,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @skillzmarket/sdk/creator - Create monetized skills with zero x402 knowledge
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { skill, serve } from '@skillzmarket/sdk/creator';
|
|
7
|
+
*
|
|
8
|
+
* const echo = skill({
|
|
9
|
+
* price: '$0.001',
|
|
10
|
+
* description: 'Echoes input back',
|
|
11
|
+
* }, async (input) => {
|
|
12
|
+
* return { echo: input };
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* serve({ echo });
|
|
16
|
+
* // Run: SKILLZ_WALLET_KEY=0x... npx tsx index.ts
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export { skill } from './skill.js';
|
|
20
|
+
export { serve } from './serve.js';
|
|
21
|
+
export { register } from './register.js';
|
|
22
|
+
export { authenticate, refreshAccessToken } from './auth.js';
|
|
23
|
+
// Re-export utilities for advanced usage
|
|
24
|
+
export { parsePrice, formatPriceForX402 } from './utils/price.js';
|
|
25
|
+
export { resolveWallet, maskPrivateKey } from './utils/wallet.js';
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/creator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAgB7D,yCAAyC;AACzC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
import type { SkillsMap, ProtectedRoutes } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Build x402 protected routes configuration from skill definitions.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildProtectedRoutes(skills: SkillsMap, walletAddress: string, network: `${string}:${string}`): ProtectedRoutes;
|
|
7
|
+
/**
|
|
8
|
+
* Create production x402 payment middleware.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createProductionPaymentMiddleware(protectedRoutes: ProtectedRoutes, facilitatorUrl: string, appName: string, network: `${string}:${string}`): Promise<MiddlewareHandler>;
|
|
11
|
+
/**
|
|
12
|
+
* Create x402 payment middleware.
|
|
13
|
+
* Always uses production x402 middleware for security.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createPaymentMiddleware(skills: SkillsMap, walletAddress: string, options: {
|
|
16
|
+
network: `${string}:${string}`;
|
|
17
|
+
facilitatorUrl: string;
|
|
18
|
+
appName: string;
|
|
19
|
+
}): Promise<MiddlewareHandler>;
|
|
20
|
+
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../src/creator/payment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7D;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,GAC7B,eAAe,CAkBjB;AAED;;GAEG;AACH,wBAAsB,iCAAiC,CACrD,eAAe,EAAE,eAAe,EAChC,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,GAC7B,OAAO,CAAC,iBAAiB,CAAC,CAc5B;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,SAAS,EACjB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE;IACP,OAAO,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,GACA,OAAO,CAAC,iBAAiB,CAAC,CAa5B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { formatPriceForX402 } from './utils/price.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build x402 protected routes configuration from skill definitions.
|
|
4
|
+
*/
|
|
5
|
+
export function buildProtectedRoutes(skills, walletAddress, network) {
|
|
6
|
+
const routes = {};
|
|
7
|
+
for (const [name, definition] of Object.entries(skills)) {
|
|
8
|
+
const routeKey = `POST /${name}`;
|
|
9
|
+
routes[routeKey] = {
|
|
10
|
+
accepts: {
|
|
11
|
+
scheme: 'exact',
|
|
12
|
+
price: formatPriceForX402(definition.parsedPrice),
|
|
13
|
+
network,
|
|
14
|
+
payTo: walletAddress,
|
|
15
|
+
maxTimeoutSeconds: Math.ceil((definition.options.timeout ?? 60000) / 1000),
|
|
16
|
+
},
|
|
17
|
+
description: definition.options.description ?? `${name} skill`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return routes;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create production x402 payment middleware.
|
|
24
|
+
*/
|
|
25
|
+
export async function createProductionPaymentMiddleware(protectedRoutes, facilitatorUrl, appName, network) {
|
|
26
|
+
const { paymentMiddleware, x402ResourceServer } = await import('@x402/hono');
|
|
27
|
+
const { ExactEvmScheme } = await import('@x402/evm/exact/server');
|
|
28
|
+
const { HTTPFacilitatorClient } = await import('@x402/core/server');
|
|
29
|
+
const facilitatorClient = new HTTPFacilitatorClient({ url: facilitatorUrl });
|
|
30
|
+
const resourceServer = new x402ResourceServer(facilitatorClient)
|
|
31
|
+
.register('eip155:8453', new ExactEvmScheme())
|
|
32
|
+
.register('eip155:84532', new ExactEvmScheme());
|
|
33
|
+
return paymentMiddleware(protectedRoutes, resourceServer, {
|
|
34
|
+
appName,
|
|
35
|
+
testnet: network.includes('84532'),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create x402 payment middleware.
|
|
40
|
+
* Always uses production x402 middleware for security.
|
|
41
|
+
*/
|
|
42
|
+
export async function createPaymentMiddleware(skills, walletAddress, options) {
|
|
43
|
+
const protectedRoutes = buildProtectedRoutes(skills, walletAddress, options.network);
|
|
44
|
+
return createProductionPaymentMiddleware(protectedRoutes, options.facilitatorUrl, options.appName, options.network);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../src/creator/payment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAiB,EACjB,aAAqB,EACrB,OAA8B;IAE9B,MAAM,MAAM,GAAoB,EAAE,CAAC;IAEnC,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACxD,MAAM,QAAQ,GAAG,SAAS,IAAI,EAA2B,CAAC;QAC1D,MAAM,CAAC,QAAQ,CAAC,GAAG;YACjB,OAAO,EAAE;gBACP,MAAM,EAAE,OAAgB;gBACxB,KAAK,EAAE,kBAAkB,CAAC,UAAU,CAAC,WAAW,CAAC;gBACjD,OAAO;gBACP,KAAK,EAAE,aAAa;gBACpB,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC;aAC3E;YACD,WAAW,EAAE,UAAU,CAAC,OAAO,CAAC,WAAW,IAAI,GAAG,IAAI,QAAQ;SAC/D,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,eAAgC,EAChC,cAAsB,EACtB,OAAe,EACf,OAA8B;IAE9B,MAAM,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;IAC7E,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;IAClE,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAEpE,MAAM,iBAAiB,GAAG,IAAI,qBAAqB,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,CAAC;IAC7E,MAAM,cAAc,GAAG,IAAI,kBAAkB,CAAC,iBAAiB,CAAC;SAC7D,QAAQ,CAAC,aAAa,EAAE,IAAI,cAAc,EAAE,CAAC;SAC7C,QAAQ,CAAC,cAAc,EAAE,IAAI,cAAc,EAAE,CAAC,CAAC;IAElD,OAAO,iBAAiB,CAAC,eAAe,EAAE,cAAc,EAAE;QACxD,OAAO;QACP,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;KACnC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAiB,EACjB,aAAqB,EACrB,OAIC;IAED,MAAM,eAAe,GAAG,oBAAoB,CAC1C,MAAM,EACN,aAAa,EACb,OAAO,CAAC,OAAO,CAChB,CAAC;IAEF,OAAO,iCAAiC,CACtC,eAAe,EACf,OAAO,CAAC,cAAc,EACtB,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,OAAO,CAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PrivateKeyAccount } from 'viem/accounts';
|
|
2
|
+
import type { SkillsMap, RegistrationResult, RegistrationOptions } from './types.js';
|
|
3
|
+
export interface RegisterOptions {
|
|
4
|
+
account: PrivateKeyAccount;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
apiUrl?: string;
|
|
7
|
+
onError?: 'throw' | 'warn' | 'silent';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Register skills with the Skillz Market registry.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { skill, register } from '@skillzmarket/sdk/creator';
|
|
15
|
+
* import { privateKeyToAccount } from 'viem/accounts';
|
|
16
|
+
*
|
|
17
|
+
* const echo = skill({ price: '$0.001' }, async (input) => ({ echo: input }));
|
|
18
|
+
*
|
|
19
|
+
* const account = privateKeyToAccount('0x...');
|
|
20
|
+
* const results = await register({ echo }, {
|
|
21
|
+
* account,
|
|
22
|
+
* endpoint: 'https://my-skills.example.com',
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param skills - Map of skill names to their definitions
|
|
27
|
+
* @param options - Registration options
|
|
28
|
+
* @returns Array of registration results for each skill
|
|
29
|
+
*/
|
|
30
|
+
export declare function register(skills: SkillsMap, options: RegisterOptions): Promise<RegistrationResult[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Build registration options from ServeOptions.register
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildRegisterOptions(registerOpts: RegistrationOptions, account: PrivateKeyAccount): RegisterOptions;
|
|
35
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/creator/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAOrF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;CACvC;AA0BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA0C/B;AAgHD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,iBAAiB,GACzB,eAAe,CAOjB"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { authenticate, authenticatedFetch } from './auth.js';
|
|
2
|
+
const DEFAULT_API_URL = 'https://api.skillz.market';
|
|
3
|
+
const MAX_RETRIES = 3;
|
|
4
|
+
const BASE_DELAY_MS = 1000;
|
|
5
|
+
/**
|
|
6
|
+
* Sleep for a given number of milliseconds
|
|
7
|
+
*/
|
|
8
|
+
function sleep(ms) {
|
|
9
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Calculate exponential backoff delay
|
|
13
|
+
*/
|
|
14
|
+
function getBackoffDelay(attempt) {
|
|
15
|
+
return BASE_DELAY_MS * Math.pow(2, attempt);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Register skills with the Skillz Market registry.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { skill, register } from '@skillzmarket/sdk/creator';
|
|
23
|
+
* import { privateKeyToAccount } from 'viem/accounts';
|
|
24
|
+
*
|
|
25
|
+
* const echo = skill({ price: '$0.001' }, async (input) => ({ echo: input }));
|
|
26
|
+
*
|
|
27
|
+
* const account = privateKeyToAccount('0x...');
|
|
28
|
+
* const results = await register({ echo }, {
|
|
29
|
+
* account,
|
|
30
|
+
* endpoint: 'https://my-skills.example.com',
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param skills - Map of skill names to their definitions
|
|
35
|
+
* @param options - Registration options
|
|
36
|
+
* @returns Array of registration results for each skill
|
|
37
|
+
*/
|
|
38
|
+
export async function register(skills, options) {
|
|
39
|
+
const { account, endpoint, apiUrl = DEFAULT_API_URL, onError = 'warn' } = options;
|
|
40
|
+
const skillNames = Object.keys(skills);
|
|
41
|
+
if (skillNames.length === 0) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
// Normalize endpoint (remove trailing slash)
|
|
45
|
+
const normalizedEndpoint = endpoint.replace(/\/$/, '');
|
|
46
|
+
// Authenticate with the API
|
|
47
|
+
let token;
|
|
48
|
+
try {
|
|
49
|
+
const authResult = await authenticate(account, { apiUrl });
|
|
50
|
+
token = authResult.token;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const message = `Failed to authenticate for registration: ${error instanceof Error ? error.message : String(error)}`;
|
|
54
|
+
return handleRegistrationError(message, skillNames, onError);
|
|
55
|
+
}
|
|
56
|
+
// Register each skill
|
|
57
|
+
const results = [];
|
|
58
|
+
for (const [name, definition] of Object.entries(skills)) {
|
|
59
|
+
const skillEndpoint = `${normalizedEndpoint}/${name}`;
|
|
60
|
+
const payload = {
|
|
61
|
+
name,
|
|
62
|
+
endpoint: skillEndpoint,
|
|
63
|
+
price: definition.parsedPrice.amount,
|
|
64
|
+
paymentAddress: account.address,
|
|
65
|
+
description: definition.options.description,
|
|
66
|
+
inputSchema: definition.options.inputSchema,
|
|
67
|
+
outputSchema: definition.options.outputSchema,
|
|
68
|
+
};
|
|
69
|
+
const result = await registerSkillWithRetry(name, payload, token, apiUrl, onError);
|
|
70
|
+
results.push(result);
|
|
71
|
+
}
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Register a single skill with retry logic
|
|
76
|
+
*/
|
|
77
|
+
async function registerSkillWithRetry(name, payload, token, apiUrl, onError) {
|
|
78
|
+
let lastError;
|
|
79
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
80
|
+
try {
|
|
81
|
+
const response = await authenticatedFetch(`${apiUrl}/skills`, token, {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
body: JSON.stringify(payload),
|
|
84
|
+
});
|
|
85
|
+
if (response.ok) {
|
|
86
|
+
const data = (await response.json());
|
|
87
|
+
return {
|
|
88
|
+
name,
|
|
89
|
+
success: true,
|
|
90
|
+
slug: data.slug,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Handle non-retryable errors
|
|
94
|
+
if (response.status >= 400 && response.status < 500) {
|
|
95
|
+
const errorText = await response.text();
|
|
96
|
+
let errorMessage;
|
|
97
|
+
try {
|
|
98
|
+
const errorData = JSON.parse(errorText);
|
|
99
|
+
errorMessage = errorData.message || errorData.error || errorText;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
errorMessage = errorText;
|
|
103
|
+
}
|
|
104
|
+
// Don't retry client errors (except rate limiting)
|
|
105
|
+
if (response.status !== 429) {
|
|
106
|
+
return handleSkillError(name, errorMessage, onError);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Retryable error
|
|
110
|
+
lastError = new Error(`HTTP ${response.status}: ${await response.text()}`);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
114
|
+
}
|
|
115
|
+
// Wait before retry (unless this was the last attempt)
|
|
116
|
+
if (attempt < MAX_RETRIES - 1) {
|
|
117
|
+
await sleep(getBackoffDelay(attempt));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return handleSkillError(name, `Failed after ${MAX_RETRIES} attempts: ${lastError?.message}`, onError);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Handle error for a single skill registration
|
|
124
|
+
*/
|
|
125
|
+
function handleSkillError(name, message, onError) {
|
|
126
|
+
if (onError === 'throw') {
|
|
127
|
+
throw new Error(`Failed to register skill "${name}": ${message}`);
|
|
128
|
+
}
|
|
129
|
+
if (onError === 'warn') {
|
|
130
|
+
console.warn(`⚠️ Failed to register skill "${name}": ${message}`);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
name,
|
|
134
|
+
success: false,
|
|
135
|
+
error: message,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Handle error affecting all skills
|
|
140
|
+
*/
|
|
141
|
+
function handleRegistrationError(message, skillNames, onError) {
|
|
142
|
+
if (onError === 'throw') {
|
|
143
|
+
throw new Error(message);
|
|
144
|
+
}
|
|
145
|
+
if (onError === 'warn') {
|
|
146
|
+
console.warn(`⚠️ ${message}`);
|
|
147
|
+
}
|
|
148
|
+
return skillNames.map((name) => ({
|
|
149
|
+
name,
|
|
150
|
+
success: false,
|
|
151
|
+
error: message,
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Build registration options from ServeOptions.register
|
|
156
|
+
*/
|
|
157
|
+
export function buildRegisterOptions(registerOpts, account) {
|
|
158
|
+
return {
|
|
159
|
+
account,
|
|
160
|
+
endpoint: registerOpts.endpoint,
|
|
161
|
+
apiUrl: registerOpts.apiUrl,
|
|
162
|
+
onError: registerOpts.onError,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/creator/register.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE7D,MAAM,eAAe,GAAG,2BAA2B,CAAC;AACpD,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,aAAa,GAAG,IAAI,CAAC;AAmB3B;;GAEG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAA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MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,iCAAiC,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,OAAO;KACf,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAC9B,OAAe,EACf,UAAoB,EACpB,OAAoC;IAEpC,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC/B,IAAI;QACJ,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,OAAO;KACf,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,YAAiC,EACjC,OAA0B;IAE1B,OAAO;QACL,OAAO;QACP,QAAQ,EAAE,YAAY,CAAC,QAAQ;QAC/B,MAAM,EAAE,YAAY,CAAC,MAAM;QAC3B,OAAO,EAAE,YAAY,CAAC,OAAO;KAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SkillsMap, ServeOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Start a server with the provided skills.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { skill, serve } from '@skillzmarket/sdk/creator';
|
|
8
|
+
*
|
|
9
|
+
* const echo = skill({ price: '$0.001' }, async (input) => ({ echo: input }));
|
|
10
|
+
* const upper = skill({ price: '$0.0005' }, async ({ text }) => ({ result: text.toUpperCase() }));
|
|
11
|
+
*
|
|
12
|
+
* serve({ echo, upper });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param skills - Map of skill names to their definitions
|
|
16
|
+
* @param options - Server configuration options
|
|
17
|
+
*/
|
|
18
|
+
export declare function serve(skills: SkillsMap, options?: ServeOptions): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=serve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/creator/serve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAY1D;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,KAAK,CACzB,MAAM,EAAE,SAAS,EACjB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CA6Kf"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { cors } from 'hono/cors';
|
|
3
|
+
import { serve as honoServe } from '@hono/node-server';
|
|
4
|
+
import { resolveWallet } from './utils/wallet.js';
|
|
5
|
+
import { createPaymentMiddleware } from './payment.js';
|
|
6
|
+
import { register, buildRegisterOptions } from './register.js';
|
|
7
|
+
const DEFAULT_PORT = 3002;
|
|
8
|
+
const DEFAULT_NETWORK = 'eip155:8453';
|
|
9
|
+
const DEFAULT_FACILITATOR_URL = 'https://x402.dexter.cash';
|
|
10
|
+
const DEFAULT_APP_NAME = 'Skillz Market Skill';
|
|
11
|
+
const DEFAULT_API_URL = 'https://api.skillz.market';
|
|
12
|
+
/**
|
|
13
|
+
* Start a server with the provided skills.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { skill, serve } from '@skillzmarket/sdk/creator';
|
|
18
|
+
*
|
|
19
|
+
* const echo = skill({ price: '$0.001' }, async (input) => ({ echo: input }));
|
|
20
|
+
* const upper = skill({ price: '$0.0005' }, async ({ text }) => ({ result: text.toUpperCase() }));
|
|
21
|
+
*
|
|
22
|
+
* serve({ echo, upper });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param skills - Map of skill names to their definitions
|
|
26
|
+
* @param options - Server configuration options
|
|
27
|
+
*/
|
|
28
|
+
export async function serve(skills, options = {}) {
|
|
29
|
+
const { port = DEFAULT_PORT, wallet, network = DEFAULT_NETWORK, facilitatorUrl = DEFAULT_FACILITATOR_URL, appName = DEFAULT_APP_NAME, onCall, onError, register: registerOpts, trackCalls = true, apiUrl = DEFAULT_API_URL, } = options;
|
|
30
|
+
// Validate skills
|
|
31
|
+
const skillNames = Object.keys(skills);
|
|
32
|
+
if (skillNames.length === 0) {
|
|
33
|
+
throw new Error('No skills provided. Pass at least one skill to serve().');
|
|
34
|
+
}
|
|
35
|
+
// Resolve wallet
|
|
36
|
+
const { account, address: walletAddress } = resolveWallet(wallet);
|
|
37
|
+
// Create Hono app
|
|
38
|
+
const app = new Hono();
|
|
39
|
+
// Enable CORS
|
|
40
|
+
app.use('*', cors());
|
|
41
|
+
// Create and apply payment middleware
|
|
42
|
+
const paymentMiddleware = await createPaymentMiddleware(skills, walletAddress, {
|
|
43
|
+
network,
|
|
44
|
+
facilitatorUrl,
|
|
45
|
+
appName,
|
|
46
|
+
});
|
|
47
|
+
app.use('*', paymentMiddleware);
|
|
48
|
+
// Health check endpoint (not protected)
|
|
49
|
+
app.get('/health', (c) => c.json({
|
|
50
|
+
status: 'ok',
|
|
51
|
+
skills: skillNames,
|
|
52
|
+
}));
|
|
53
|
+
// Register skill endpoints
|
|
54
|
+
for (const [name, definition] of Object.entries(skills)) {
|
|
55
|
+
app.post(`/${name}`, async (c) => {
|
|
56
|
+
let input;
|
|
57
|
+
try {
|
|
58
|
+
input = await c.req.json();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
input = {};
|
|
62
|
+
}
|
|
63
|
+
// Call onCall callback if provided
|
|
64
|
+
if (onCall) {
|
|
65
|
+
try {
|
|
66
|
+
onCall(name, input);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Ignore callback errors
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const result = await definition.handler(input);
|
|
74
|
+
// Track call to Skillz Market analytics (non-blocking)
|
|
75
|
+
if (trackCalls) {
|
|
76
|
+
fetch(`${apiUrl}/analytics/call`, {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: { 'Content-Type': 'application/json' },
|
|
79
|
+
body: JSON.stringify({ skillSlug: name }),
|
|
80
|
+
}).catch(() => { }); // Silently ignore tracking errors
|
|
81
|
+
}
|
|
82
|
+
return c.json({
|
|
83
|
+
success: true,
|
|
84
|
+
result,
|
|
85
|
+
timestamp: new Date().toISOString(),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
90
|
+
// Call onError callback if provided
|
|
91
|
+
if (onError) {
|
|
92
|
+
try {
|
|
93
|
+
onError(name, err);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Ignore callback errors
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Mask error details in production to prevent information disclosure
|
|
100
|
+
const errorMsg = process.env.NODE_ENV === 'production'
|
|
101
|
+
? 'Internal server error'
|
|
102
|
+
: err.message;
|
|
103
|
+
return c.json({
|
|
104
|
+
success: false,
|
|
105
|
+
error: errorMsg,
|
|
106
|
+
timestamp: new Date().toISOString(),
|
|
107
|
+
}, 500);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// Start server
|
|
112
|
+
honoServe({
|
|
113
|
+
fetch: app.fetch,
|
|
114
|
+
port,
|
|
115
|
+
}, async (info) => {
|
|
116
|
+
console.log('');
|
|
117
|
+
console.log('='.repeat(50));
|
|
118
|
+
console.log(' Skillz Market - Creator Server');
|
|
119
|
+
console.log('='.repeat(50));
|
|
120
|
+
console.log('');
|
|
121
|
+
console.log(` URL: http://localhost:${info.port}`);
|
|
122
|
+
console.log(` Network: ${network}`);
|
|
123
|
+
console.log(` Wallet: ${walletAddress}`);
|
|
124
|
+
console.log('');
|
|
125
|
+
console.log(' Skills:');
|
|
126
|
+
for (const [name, definition] of Object.entries(skills)) {
|
|
127
|
+
console.log(` POST /${name} - ${definition.parsedPrice.amount} USDC`);
|
|
128
|
+
if (definition.options.description) {
|
|
129
|
+
console.log(` ${definition.options.description}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
console.log('');
|
|
133
|
+
console.log('='.repeat(50));
|
|
134
|
+
console.log('');
|
|
135
|
+
// Auto-register skills if registration is configured
|
|
136
|
+
if (registerOpts && registerOpts.enabled !== false) {
|
|
137
|
+
console.log(' Registering skills with Skillz Market...');
|
|
138
|
+
console.log('');
|
|
139
|
+
const registerOptions = buildRegisterOptions(registerOpts, account);
|
|
140
|
+
const results = await register(skills, registerOptions);
|
|
141
|
+
// Log registration results
|
|
142
|
+
const successful = results.filter((r) => r.success);
|
|
143
|
+
const failed = results.filter((r) => !r.success);
|
|
144
|
+
if (successful.length > 0) {
|
|
145
|
+
console.log(' ✓ Registered skills:');
|
|
146
|
+
for (const result of successful) {
|
|
147
|
+
console.log(` - ${result.name} (${result.slug})`);
|
|
148
|
+
}
|
|
149
|
+
console.log('');
|
|
150
|
+
}
|
|
151
|
+
if (failed.length > 0 && registerOpts.onError !== 'silent') {
|
|
152
|
+
console.log(' ✗ Failed to register:');
|
|
153
|
+
for (const result of failed) {
|
|
154
|
+
console.log(` - ${result.name}: ${result.error}`);
|
|
155
|
+
}
|
|
156
|
+
console.log('');
|
|
157
|
+
}
|
|
158
|
+
console.log('='.repeat(50));
|
|
159
|
+
console.log('');
|
|
160
|
+
}
|
|
161
|
+
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;gBACvD,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAClB,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SkillOptions, SkillHandler, SkillDefinition } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Define a monetized skill.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const echo = skill({
|
|
8
|
+
* price: '$0.001',
|
|
9
|
+
* description: 'Echoes input back',
|
|
10
|
+
* }, async (input) => {
|
|
11
|
+
* return { echo: input };
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param options - Skill configuration (price, description, timeout)
|
|
16
|
+
* @param handler - Async function that processes input and returns output
|
|
17
|
+
* @returns SkillDefinition ready to be served
|
|
18
|
+
*/
|
|
19
|
+
export declare function skill<TInput = unknown, TOutput = unknown>(options: SkillOptions, handler: SkillHandler<TInput, TOutput>): SkillDefinition<TInput, TOutput>;
|
|
20
|
+
//# sourceMappingURL=skill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/creator/skill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG9E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EACvD,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CA0BlC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { parsePrice } from './utils/price.js';
|
|
2
|
+
/**
|
|
3
|
+
* Define a monetized skill.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const echo = skill({
|
|
8
|
+
* price: '$0.001',
|
|
9
|
+
* description: 'Echoes input back',
|
|
10
|
+
* }, async (input) => {
|
|
11
|
+
* return { echo: input };
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param options - Skill configuration (price, description, timeout)
|
|
16
|
+
* @param handler - Async function that processes input and returns output
|
|
17
|
+
* @returns SkillDefinition ready to be served
|
|
18
|
+
*/
|
|
19
|
+
export function skill(options, handler) {
|
|
20
|
+
// Validate and parse price upfront
|
|
21
|
+
const parsedPrice = parsePrice(options.price);
|
|
22
|
+
// Validate timeout if provided
|
|
23
|
+
if (options.timeout !== undefined) {
|
|
24
|
+
if (typeof options.timeout !== 'number' || options.timeout <= 0) {
|
|
25
|
+
throw new Error(`Invalid timeout: ${options.timeout}. Must be a positive number (milliseconds).`);
|
|
26
|
+
}
|
|
27
|
+
if (options.timeout > 300000) {
|
|
28
|
+
throw new Error(`Timeout too long: ${options.timeout}ms. Maximum is 300000ms (5 minutes).`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
options: {
|
|
33
|
+
...options,
|
|
34
|
+
timeout: options.timeout ?? 60000, // Default 60 seconds
|
|
35
|
+
},
|
|
36
|
+
handler,
|
|
37
|
+
parsedPrice,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=skill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.js","sourceRoot":"","sources":["../../src/creator/skill.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,KAAK,CACnB,OAAqB,EACrB,OAAsC;IAEtC,mCAAmC;IACnC,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE9C,+BAA+B;IAC/B,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,EAAE,CAAC;YAChE,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,CAAC,OAAO,6CAA6C,CACjF,CAAC;QACJ,CAAC;QACD,IAAI,OAAO,CAAC,OAAO,GAAG,MAAM,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,qBAAqB,OAAO,CAAC,OAAO,sCAAsC,CAC3E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE;YACP,GAAG,OAAO;YACV,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,KAAK,EAAE,qBAAqB;SACzD;QACD,OAAO;QACP,WAAW;KACZ,CAAC;AACJ,CAAC"}
|