@nevermined-io/openclaw-plugin 1.0.11-rc.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 +63 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +19 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/tools.d.ts +16 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +218 -0
- package/dist/tools.js.map +1 -0
- package/openclaw.plugin.json +63 -0
- package/package.json +55 -0
- package/skills/nevermined/SKILL.md +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @nevermined-io/openclaw-plugin
|
|
2
|
+
|
|
3
|
+
OpenClaw plugin for [Nevermined](https://nevermined.io) — exposes AI agent payment operations as gateway tools callable from any OpenClaw channel (Telegram, Discord, WhatsApp, etc.).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
openclaw plugin install @nevermined-io/openclaw-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
Add the Nevermined plugin config to your `openclaw.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"plugins": {
|
|
18
|
+
"nevermined": {
|
|
19
|
+
"nvmApiKey": "sandbox:eyJhbG...",
|
|
20
|
+
"environment": "sandbox",
|
|
21
|
+
"planId": "did:nv:abc123",
|
|
22
|
+
"agentId": "did:nv:def456",
|
|
23
|
+
"creditsPerRequest": 1
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Field | Required | Default | Description |
|
|
30
|
+
|-------|----------|---------|-------------|
|
|
31
|
+
| `nvmApiKey` | Yes | — | Your Nevermined API key |
|
|
32
|
+
| `environment` | No | `sandbox` | `sandbox` or `live` |
|
|
33
|
+
| `planId` | No | — | Default plan ID for subscriber tools |
|
|
34
|
+
| `agentId` | No | — | Default agent ID for multi-agent plans |
|
|
35
|
+
| `creditsPerRequest` | No | `1` | Credits consumed per request |
|
|
36
|
+
|
|
37
|
+
## Available Tools
|
|
38
|
+
|
|
39
|
+
### Subscriber Tools
|
|
40
|
+
|
|
41
|
+
| Tool | Description | Key Params |
|
|
42
|
+
|------|-------------|------------|
|
|
43
|
+
| `nevermined.checkBalance` | Check credit balance for a plan | `planId` |
|
|
44
|
+
| `nevermined.getAccessToken` | Get an x402 access token | `planId`, `agentId` |
|
|
45
|
+
| `nevermined.orderPlan` | Purchase a payment plan | `planId` |
|
|
46
|
+
| `nevermined.queryAgent` | Query an agent end-to-end | `agentUrl`, `prompt`, `planId`, `agentId` |
|
|
47
|
+
|
|
48
|
+
### Builder Tools
|
|
49
|
+
|
|
50
|
+
| Tool | Description | Key Params |
|
|
51
|
+
|------|-------------|------------|
|
|
52
|
+
| `nevermined.registerAgent` | Register an agent with a plan | `name`, `agentUrl`, `planName`, `priceAmounts`, `priceReceivers`, `creditsAmount` |
|
|
53
|
+
| `nevermined.createPlan` | Create a payment plan | `name`, `priceAmounts`, `priceReceivers`, `creditsAmount` |
|
|
54
|
+
| `nevermined.listPlans` | List your plans | — |
|
|
55
|
+
|
|
56
|
+
## Documentation
|
|
57
|
+
|
|
58
|
+
- [Nevermined Docs](https://docs.nevermined.app)
|
|
59
|
+
- [Payments SDK](https://github.com/nevermined-io/payments)
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
Apache-2.0
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Payments } from '@nevermined-io/payments';
|
|
3
|
+
export declare const NeverminedPluginConfigSchema: z.ZodObject<{
|
|
4
|
+
nvmApiKey: z.ZodString;
|
|
5
|
+
environment: z.ZodDefault<z.ZodEnum<["sandbox", "live"]>>;
|
|
6
|
+
planId: z.ZodOptional<z.ZodString>;
|
|
7
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
8
|
+
creditsPerRequest: z.ZodDefault<z.ZodNumber>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
nvmApiKey: string;
|
|
11
|
+
environment: "sandbox" | "live";
|
|
12
|
+
creditsPerRequest: number;
|
|
13
|
+
planId?: string | undefined;
|
|
14
|
+
agentId?: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
nvmApiKey: string;
|
|
17
|
+
environment?: "sandbox" | "live" | undefined;
|
|
18
|
+
planId?: string | undefined;
|
|
19
|
+
agentId?: string | undefined;
|
|
20
|
+
creditsPerRequest?: number | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export type NeverminedPluginConfig = z.infer<typeof NeverminedPluginConfigSchema>;
|
|
23
|
+
export declare function validateConfig(raw: unknown): NeverminedPluginConfig;
|
|
24
|
+
export declare function createPaymentsFromConfig(config: NeverminedPluginConfig): Payments;
|
|
25
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAGlD,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;EAMvC,CAAA;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAA;AAEjF,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,sBAAsB,CAEnE;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,sBAAsB,GAAG,QAAQ,CAKjF"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Payments } from '@nevermined-io/payments';
|
|
3
|
+
export const NeverminedPluginConfigSchema = z.object({
|
|
4
|
+
nvmApiKey: z.string().min(1, 'nvmApiKey is required'),
|
|
5
|
+
environment: z.enum(['sandbox', 'live']).default('sandbox'),
|
|
6
|
+
planId: z.string().optional(),
|
|
7
|
+
agentId: z.string().optional(),
|
|
8
|
+
creditsPerRequest: z.number().int().positive().default(1),
|
|
9
|
+
});
|
|
10
|
+
export function validateConfig(raw) {
|
|
11
|
+
return NeverminedPluginConfigSchema.parse(raw);
|
|
12
|
+
}
|
|
13
|
+
export function createPaymentsFromConfig(config) {
|
|
14
|
+
return Payments.getInstance({
|
|
15
|
+
nvmApiKey: config.nvmApiKey,
|
|
16
|
+
environment: config.environment,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAGlD,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,MAAM,CAAC;IACnD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;IACrD,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC3D,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;CAC1D,CAAC,CAAA;AAIF,MAAM,UAAU,cAAc,CAAC,GAAY;IACzC,OAAO,4BAA4B,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAChD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,MAA8B;IACrE,OAAO,QAAQ,CAAC,WAAW,CAAC;QAC1B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,WAAW,EAAE,MAAM,CAAC,WAA8B;KACnD,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { validateConfig, createPaymentsFromConfig } from './config.js';
|
|
2
|
+
import { allTools } from './tools.js';
|
|
3
|
+
import type { Payments } from '@nevermined-io/payments';
|
|
4
|
+
import type { NeverminedPluginConfig } from './config.js';
|
|
5
|
+
import type { ToolDefinition } from './tools.js';
|
|
6
|
+
export type { NeverminedPluginConfig, ToolDefinition };
|
|
7
|
+
export { validateConfig, createPaymentsFromConfig, allTools };
|
|
8
|
+
export interface OpenClawPluginAPI {
|
|
9
|
+
getConfig(namespace: string): unknown;
|
|
10
|
+
registerGatewayMethod(name: string, options: {
|
|
11
|
+
description: string;
|
|
12
|
+
params: Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
required: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
handler: (params: Record<string, unknown>) => Promise<unknown>;
|
|
19
|
+
}): void;
|
|
20
|
+
}
|
|
21
|
+
export interface RegisterOptions {
|
|
22
|
+
paymentsFactory?: (config: NeverminedPluginConfig) => Payments;
|
|
23
|
+
}
|
|
24
|
+
export declare function register(api: OpenClawPluginAPI, options?: RegisterOptions): void;
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,YAAY,EAAE,sBAAsB,EAAE,cAAc,EAAE,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,QAAQ,EAAE,CAAA;AAE7D,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAA;IACrC,qBAAqB,CACnB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAA;QACnB,MAAM,EAAE,KAAK,CAAC;YACZ,IAAI,EAAE,MAAM,CAAA;YACZ,IAAI,EAAE,MAAM,CAAA;YACZ,WAAW,EAAE,MAAM,CAAA;YACnB,QAAQ,EAAE,OAAO,CAAA;SAClB,CAAC,CAAA;QACF,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;KAC/D,GACA,IAAI,CAAA;CACR;AAED,MAAM,WAAW,eAAe;IAC9B,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,QAAQ,CAAA;CAC/D;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAoBhF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { validateConfig, createPaymentsFromConfig } from './config.js';
|
|
2
|
+
import { allTools } from './tools.js';
|
|
3
|
+
export { validateConfig, createPaymentsFromConfig, allTools };
|
|
4
|
+
export function register(api, options) {
|
|
5
|
+
const rawConfig = api.getConfig('nevermined');
|
|
6
|
+
const config = validateConfig(rawConfig);
|
|
7
|
+
const factory = options?.paymentsFactory ?? createPaymentsFromConfig;
|
|
8
|
+
const payments = factory(config);
|
|
9
|
+
for (const tool of allTools) {
|
|
10
|
+
api.registerGatewayMethod(tool.name, {
|
|
11
|
+
description: tool.description,
|
|
12
|
+
params: tool.params,
|
|
13
|
+
handler: async (params) => {
|
|
14
|
+
try {
|
|
15
|
+
return await tool.handler(payments, config, params);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
19
|
+
throw new Error(`[nevermined] ${tool.name} failed: ${message}`);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAMrC,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,QAAQ,EAAE,CAAA;AAuB7D,MAAM,UAAU,QAAQ,CAAC,GAAsB,EAAE,OAAyB;IACxE,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IAC7C,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,CAAA;IACxC,MAAM,OAAO,GAAG,OAAO,EAAE,eAAe,IAAI,wBAAwB,CAAA;IACpE,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAEhC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,EAAE;YACnC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;gBACxB,IAAI,CAAC;oBACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;gBACrD,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;oBAChE,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,IAAI,YAAY,OAAO,EAAE,CAAC,CAAA;gBACjE,CAAC;YACH,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Payments } from '@nevermined-io/payments';
|
|
2
|
+
import type { NeverminedPluginConfig } from './config.js';
|
|
3
|
+
export interface ToolParam {
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
description: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ToolDefinition {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
params: ToolParam[];
|
|
13
|
+
handler: (payments: Payments, config: NeverminedPluginConfig, params: Record<string, unknown>) => Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare const allTools: ToolDefinition[];
|
|
16
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,SAAS,EAAE,CAAA;IACnB,OAAO,EAAE,CACP,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,sBAAsB,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,OAAO,CAAC,CAAA;CACtB;AAqPD,eAAO,MAAM,QAAQ,EAAE,cAAc,EAUpC,CAAA"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
function requireParam(params, name) {
|
|
2
|
+
const value = params[name];
|
|
3
|
+
if (value === undefined || value === null || value === '') {
|
|
4
|
+
throw new Error(`Missing required parameter: ${name}`);
|
|
5
|
+
}
|
|
6
|
+
return String(value);
|
|
7
|
+
}
|
|
8
|
+
function optionalParam(params, name, fallback) {
|
|
9
|
+
const value = params[name];
|
|
10
|
+
if (value === undefined || value === null || value === '') {
|
|
11
|
+
return fallback;
|
|
12
|
+
}
|
|
13
|
+
return String(value);
|
|
14
|
+
}
|
|
15
|
+
// --- Subscriber tools ---
|
|
16
|
+
const checkBalance = {
|
|
17
|
+
name: 'nevermined.checkBalance',
|
|
18
|
+
description: 'Check the credit balance for a Nevermined payment plan',
|
|
19
|
+
params: [
|
|
20
|
+
{ name: 'planId', type: 'string', description: 'The payment plan ID', required: false },
|
|
21
|
+
],
|
|
22
|
+
handler: async (payments, config, params) => {
|
|
23
|
+
const planId = optionalParam(params, 'planId', config.planId);
|
|
24
|
+
if (!planId) {
|
|
25
|
+
throw new Error('planId is required — provide it as a parameter or in the plugin config');
|
|
26
|
+
}
|
|
27
|
+
const balance = await payments.plans.getPlanBalance(planId);
|
|
28
|
+
return {
|
|
29
|
+
planId: balance.planId,
|
|
30
|
+
planName: balance.planName,
|
|
31
|
+
balance: balance.balance.toString(),
|
|
32
|
+
isSubscriber: balance.isSubscriber,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const getAccessToken = {
|
|
37
|
+
name: 'nevermined.getAccessToken',
|
|
38
|
+
description: 'Get an x402 access token for authenticating requests to a Nevermined agent',
|
|
39
|
+
params: [
|
|
40
|
+
{ name: 'planId', type: 'string', description: 'The payment plan ID', required: false },
|
|
41
|
+
{ name: 'agentId', type: 'string', description: 'The agent ID', required: false },
|
|
42
|
+
],
|
|
43
|
+
handler: async (payments, config, params) => {
|
|
44
|
+
const planId = optionalParam(params, 'planId', config.planId);
|
|
45
|
+
if (!planId) {
|
|
46
|
+
throw new Error('planId is required — provide it as a parameter or in the plugin config');
|
|
47
|
+
}
|
|
48
|
+
const agentId = optionalParam(params, 'agentId', config.agentId);
|
|
49
|
+
const result = await payments.x402.getX402AccessToken(planId, agentId);
|
|
50
|
+
return { accessToken: result.accessToken };
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const orderPlan = {
|
|
54
|
+
name: 'nevermined.orderPlan',
|
|
55
|
+
description: 'Order (purchase) a Nevermined payment plan',
|
|
56
|
+
params: [
|
|
57
|
+
{ name: 'planId', type: 'string', description: 'The payment plan ID to order', required: false },
|
|
58
|
+
],
|
|
59
|
+
handler: async (payments, config, params) => {
|
|
60
|
+
const planId = optionalParam(params, 'planId', config.planId);
|
|
61
|
+
if (!planId) {
|
|
62
|
+
throw new Error('planId is required — provide it as a parameter or in the plugin config');
|
|
63
|
+
}
|
|
64
|
+
const result = await payments.plans.orderPlan(planId);
|
|
65
|
+
return result;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
const queryAgent = {
|
|
69
|
+
name: 'nevermined.queryAgent',
|
|
70
|
+
description: 'Query a Nevermined AI agent end-to-end: acquires an x402 access token, sends the prompt to the agent, and returns the response',
|
|
71
|
+
params: [
|
|
72
|
+
{ name: 'agentUrl', type: 'string', description: 'The URL of the agent to query', required: true },
|
|
73
|
+
{ name: 'prompt', type: 'string', description: 'The prompt to send to the agent', required: true },
|
|
74
|
+
{ name: 'planId', type: 'string', description: 'The payment plan ID', required: false },
|
|
75
|
+
{ name: 'agentId', type: 'string', description: 'The agent ID', required: false },
|
|
76
|
+
{ name: 'method', type: 'string', description: 'HTTP method (default: POST)', required: false },
|
|
77
|
+
],
|
|
78
|
+
handler: async (payments, config, params) => {
|
|
79
|
+
const agentUrl = requireParam(params, 'agentUrl');
|
|
80
|
+
const prompt = requireParam(params, 'prompt');
|
|
81
|
+
const planId = optionalParam(params, 'planId', config.planId);
|
|
82
|
+
if (!planId) {
|
|
83
|
+
throw new Error('planId is required — provide it as a parameter or in the plugin config');
|
|
84
|
+
}
|
|
85
|
+
const agentId = optionalParam(params, 'agentId', config.agentId);
|
|
86
|
+
const method = optionalParam(params, 'method', 'POST') ?? 'POST';
|
|
87
|
+
const { accessToken } = await payments.x402.getX402AccessToken(planId, agentId);
|
|
88
|
+
const response = await fetch(agentUrl, {
|
|
89
|
+
method,
|
|
90
|
+
headers: {
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
'PAYMENT-SIGNATURE': accessToken,
|
|
93
|
+
},
|
|
94
|
+
body: method !== 'GET' ? JSON.stringify({ prompt }) : undefined,
|
|
95
|
+
});
|
|
96
|
+
if (response.status === 402) {
|
|
97
|
+
return {
|
|
98
|
+
error: 'Payment required — insufficient credits. Order the plan first using nevermined.orderPlan.',
|
|
99
|
+
status: 402,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
return {
|
|
104
|
+
error: `Agent returned HTTP ${response.status}: ${response.statusText}`,
|
|
105
|
+
status: response.status,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const body = await response.json();
|
|
109
|
+
return body;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
// --- Builder tools ---
|
|
113
|
+
const registerAgent = {
|
|
114
|
+
name: 'nevermined.registerAgent',
|
|
115
|
+
description: 'Register a new AI agent with an associated payment plan on Nevermined',
|
|
116
|
+
params: [
|
|
117
|
+
{ name: 'name', type: 'string', description: 'Agent name', required: true },
|
|
118
|
+
{ name: 'description', type: 'string', description: 'Agent description', required: false },
|
|
119
|
+
{ name: 'agentUrl', type: 'string', description: 'The endpoint URL for the agent', required: true },
|
|
120
|
+
{ name: 'planName', type: 'string', description: 'Name for the payment plan', required: true },
|
|
121
|
+
{ name: 'priceAmounts', type: 'string', description: 'Comma-separated price amounts in wei', required: true },
|
|
122
|
+
{ name: 'priceReceivers', type: 'string', description: 'Comma-separated receiver addresses', required: true },
|
|
123
|
+
{ name: 'creditsAmount', type: 'number', description: 'Number of credits in the plan', required: true },
|
|
124
|
+
],
|
|
125
|
+
handler: async (payments, _config, params) => {
|
|
126
|
+
const name = requireParam(params, 'name');
|
|
127
|
+
const description = optionalParam(params, 'description', '');
|
|
128
|
+
const agentUrl = requireParam(params, 'agentUrl');
|
|
129
|
+
const planName = requireParam(params, 'planName');
|
|
130
|
+
const priceAmounts = requireParam(params, 'priceAmounts')
|
|
131
|
+
.split(',')
|
|
132
|
+
.map((s) => BigInt(s.trim()));
|
|
133
|
+
const priceReceivers = requireParam(params, 'priceReceivers')
|
|
134
|
+
.split(',')
|
|
135
|
+
.map((s) => s.trim());
|
|
136
|
+
const creditsAmount = Number(requireParam(params, 'creditsAmount'));
|
|
137
|
+
const result = await payments.agents.registerAgentAndPlan({ name, description }, {
|
|
138
|
+
endpoints: [{ POST: agentUrl }],
|
|
139
|
+
agentDefinitionUrl: agentUrl,
|
|
140
|
+
}, { name: planName }, {
|
|
141
|
+
amounts: priceAmounts,
|
|
142
|
+
receivers: priceReceivers,
|
|
143
|
+
isCrypto: true,
|
|
144
|
+
}, {
|
|
145
|
+
isRedemptionAmountFixed: true,
|
|
146
|
+
redemptionType: 4, // ONLY_SUBSCRIBER
|
|
147
|
+
proofRequired: false,
|
|
148
|
+
durationSecs: 0n,
|
|
149
|
+
amount: BigInt(creditsAmount),
|
|
150
|
+
minAmount: 1n,
|
|
151
|
+
maxAmount: BigInt(creditsAmount),
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
agentId: result.agentId,
|
|
155
|
+
planId: result.planId,
|
|
156
|
+
txHash: result.txHash,
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
const createPlan = {
|
|
161
|
+
name: 'nevermined.createPlan',
|
|
162
|
+
description: 'Create a new payment plan on Nevermined',
|
|
163
|
+
params: [
|
|
164
|
+
{ name: 'name', type: 'string', description: 'Plan name', required: true },
|
|
165
|
+
{ name: 'description', type: 'string', description: 'Plan description', required: false },
|
|
166
|
+
{ name: 'priceAmounts', type: 'string', description: 'Comma-separated price amounts in wei', required: true },
|
|
167
|
+
{ name: 'priceReceivers', type: 'string', description: 'Comma-separated receiver addresses', required: true },
|
|
168
|
+
{ name: 'creditsAmount', type: 'number', description: 'Number of credits in the plan', required: true },
|
|
169
|
+
{ name: 'accessLimit', type: 'string', description: '"credits" or "time" (default: credits)', required: false },
|
|
170
|
+
],
|
|
171
|
+
handler: async (payments, _config, params) => {
|
|
172
|
+
const name = requireParam(params, 'name');
|
|
173
|
+
const description = optionalParam(params, 'description', '');
|
|
174
|
+
const priceAmounts = requireParam(params, 'priceAmounts')
|
|
175
|
+
.split(',')
|
|
176
|
+
.map((s) => BigInt(s.trim()));
|
|
177
|
+
const priceReceivers = requireParam(params, 'priceReceivers')
|
|
178
|
+
.split(',')
|
|
179
|
+
.map((s) => s.trim());
|
|
180
|
+
const creditsAmount = Number(requireParam(params, 'creditsAmount'));
|
|
181
|
+
const accessLimit = optionalParam(params, 'accessLimit', 'credits');
|
|
182
|
+
const result = await payments.plans.registerPlan({ name, description, accessLimit }, {
|
|
183
|
+
amounts: priceAmounts,
|
|
184
|
+
receivers: priceReceivers,
|
|
185
|
+
isCrypto: true,
|
|
186
|
+
}, {
|
|
187
|
+
isRedemptionAmountFixed: true,
|
|
188
|
+
redemptionType: 4,
|
|
189
|
+
proofRequired: false,
|
|
190
|
+
durationSecs: 0n,
|
|
191
|
+
amount: BigInt(creditsAmount),
|
|
192
|
+
minAmount: 1n,
|
|
193
|
+
maxAmount: BigInt(creditsAmount),
|
|
194
|
+
}, undefined, accessLimit);
|
|
195
|
+
return { planId: result.planId };
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
const listPlans = {
|
|
199
|
+
name: 'nevermined.listPlans',
|
|
200
|
+
description: "List the builder's payment plans on Nevermined",
|
|
201
|
+
params: [],
|
|
202
|
+
handler: async (payments) => {
|
|
203
|
+
const result = await payments.plans.getPlans();
|
|
204
|
+
return result;
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
export const allTools = [
|
|
208
|
+
// Subscriber
|
|
209
|
+
checkBalance,
|
|
210
|
+
getAccessToken,
|
|
211
|
+
orderPlan,
|
|
212
|
+
queryAgent,
|
|
213
|
+
// Builder
|
|
214
|
+
registerAgent,
|
|
215
|
+
createPlan,
|
|
216
|
+
listPlans,
|
|
217
|
+
];
|
|
218
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAqBA,SAAS,YAAY,CAAC,MAA+B,EAAE,IAAY;IACjE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;AACtB,CAAC;A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uB,CAAA;QAEzF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,YAAY,CAC9C,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,EAClC;YACE,OAAO,EAAE,YAAY;YACrB,SAAS,EAAE,cAAc;YACzB,QAAQ,EAAE,IAAI;SACf,EACD;YACE,uBAAuB,EAAE,IAAI;YAC7B,cAAc,EAAE,CAAC;YACjB,aAAa,EAAE,KAAK;YACpB,YAAY,EAAE,EAAE;YAChB,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC;YAC7B,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,MAAM,CAAC,aAAa,CAAC;SACjC,EACD,SAAS,EACT,WAAW,CACZ,CAAA;QAED,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAA;IAClC,CAAC;CACF,CAAA;AAED,MAAM,SAAS,GAAmB;IAChC,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EAAE,gDAAgD;IAC7D,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QAC1B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAA;QAC9C,OAAO,MAAM,CAAA;IACf,CAAC;CACF,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAqB;IACxC,aAAa;IACb,YAAY;IACZ,cAAc;IACd,SAAS;IACT,UAAU;IACV,UAAU;IACV,aAAa;IACb,UAAU;IACV,SAAS;CACV,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nevermined-io/openclaw-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Nevermined plugin for OpenClaw — AI agent payments and access control",
|
|
5
|
+
"configSchema": {
|
|
6
|
+
"nvmApiKey": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"required": true,
|
|
9
|
+
"description": "Your Nevermined API key"
|
|
10
|
+
},
|
|
11
|
+
"environment": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"enum": ["sandbox", "live"],
|
|
14
|
+
"default": "sandbox",
|
|
15
|
+
"description": "Nevermined environment to connect to"
|
|
16
|
+
},
|
|
17
|
+
"planId": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"required": false,
|
|
20
|
+
"description": "Default payment plan ID (required for subscriber tools)"
|
|
21
|
+
},
|
|
22
|
+
"agentId": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"required": false,
|
|
25
|
+
"description": "Default agent ID (required for multi-agent plans)"
|
|
26
|
+
},
|
|
27
|
+
"creditsPerRequest": {
|
|
28
|
+
"type": "number",
|
|
29
|
+
"default": 1,
|
|
30
|
+
"description": "Number of credits consumed per request"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"uiHints": {
|
|
34
|
+
"nvmApiKey": {
|
|
35
|
+
"sensitive": true,
|
|
36
|
+
"label": "Nevermined API Key",
|
|
37
|
+
"placeholder": "sandbox:eyJhbG..."
|
|
38
|
+
},
|
|
39
|
+
"environment": {
|
|
40
|
+
"label": "Environment"
|
|
41
|
+
},
|
|
42
|
+
"planId": {
|
|
43
|
+
"label": "Plan ID",
|
|
44
|
+
"placeholder": "did:nv:..."
|
|
45
|
+
},
|
|
46
|
+
"agentId": {
|
|
47
|
+
"label": "Agent ID",
|
|
48
|
+
"placeholder": "did:nv:..."
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"skills": ["skills/nevermined/SKILL.md"],
|
|
52
|
+
"gateway": {
|
|
53
|
+
"methods": [
|
|
54
|
+
"nevermined.checkBalance",
|
|
55
|
+
"nevermined.getAccessToken",
|
|
56
|
+
"nevermined.orderPlan",
|
|
57
|
+
"nevermined.queryAgent",
|
|
58
|
+
"nevermined.registerAgent",
|
|
59
|
+
"nevermined.createPlan",
|
|
60
|
+
"nevermined.listPlans"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nevermined-io/openclaw-plugin",
|
|
3
|
+
"version": "1.0.11-rc.1",
|
|
4
|
+
"description": "OpenClaw plugin for Nevermined — exposes subscriber and builder tools as gateway methods",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/",
|
|
16
|
+
"openclaw.plugin.json",
|
|
17
|
+
"skills/",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest --config jest.config.js",
|
|
23
|
+
"lint": "eslint src/ tests/ --ext .ts"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@nevermined-io/payments": ">= 1.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@nevermined-io/payments": "^1.0.10",
|
|
30
|
+
"@types/jest": "^29.5.0",
|
|
31
|
+
"jest": "^29.7.0",
|
|
32
|
+
"ts-jest": "^29.1.0",
|
|
33
|
+
"typescript": "^5.4.0",
|
|
34
|
+
"eslint": "^8.57.0",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
36
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
37
|
+
"zod": "^3.23.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"zod": "^3.23.0"
|
|
41
|
+
},
|
|
42
|
+
"license": "Apache-2.0",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/nevermined-io/payments.git",
|
|
46
|
+
"directory": "openclaw"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"nevermined",
|
|
50
|
+
"openclaw",
|
|
51
|
+
"ai-agents",
|
|
52
|
+
"payments",
|
|
53
|
+
"plugin"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
metadata:
|
|
3
|
+
openclaw:
|
|
4
|
+
requires:
|
|
5
|
+
config: ["plugins.nevermined.nvmApiKey"]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Nevermined Tools
|
|
9
|
+
|
|
10
|
+
This plugin provides gateway tools for interacting with Nevermined AI agent payments.
|
|
11
|
+
|
|
12
|
+
## Subscriber Tools
|
|
13
|
+
|
|
14
|
+
### `nevermined.checkBalance`
|
|
15
|
+
Check credit balance for a payment plan.
|
|
16
|
+
- `planId` (optional if set in config) — the plan to check
|
|
17
|
+
|
|
18
|
+
### `nevermined.getAccessToken`
|
|
19
|
+
Get an x402 access token for authenticating agent requests.
|
|
20
|
+
- `planId` (optional if set in config)
|
|
21
|
+
- `agentId` (optional if set in config)
|
|
22
|
+
|
|
23
|
+
### `nevermined.orderPlan`
|
|
24
|
+
Purchase a payment plan.
|
|
25
|
+
- `planId` (optional if set in config)
|
|
26
|
+
|
|
27
|
+
### `nevermined.queryAgent`
|
|
28
|
+
End-to-end agent query — acquires a token, calls the agent, returns the response.
|
|
29
|
+
- `agentUrl` (required) — the agent endpoint URL
|
|
30
|
+
- `prompt` (required) — the prompt to send
|
|
31
|
+
- `planId` (optional if set in config)
|
|
32
|
+
- `agentId` (optional if set in config)
|
|
33
|
+
- `method` (optional, default `POST`)
|
|
34
|
+
|
|
35
|
+
## Builder Tools
|
|
36
|
+
|
|
37
|
+
### `nevermined.registerAgent`
|
|
38
|
+
Register a new AI agent with a payment plan.
|
|
39
|
+
- `name` (required) — agent name
|
|
40
|
+
- `agentUrl` (required) — agent endpoint
|
|
41
|
+
- `planName` (required) — plan name
|
|
42
|
+
- `priceAmounts` (required) — comma-separated prices in wei
|
|
43
|
+
- `priceReceivers` (required) — comma-separated receiver addresses
|
|
44
|
+
- `creditsAmount` (required) — number of credits
|
|
45
|
+
|
|
46
|
+
### `nevermined.createPlan`
|
|
47
|
+
Create a standalone payment plan.
|
|
48
|
+
- `name` (required) — plan name
|
|
49
|
+
- `priceAmounts` (required) — comma-separated prices in wei
|
|
50
|
+
- `priceReceivers` (required) — comma-separated receiver addresses
|
|
51
|
+
- `creditsAmount` (required) — number of credits
|
|
52
|
+
- `accessLimit` (optional) — `"credits"` or `"time"`
|
|
53
|
+
|
|
54
|
+
### `nevermined.listPlans`
|
|
55
|
+
List your payment plans. No parameters.
|