@t54-labs/clawcredit-sdk 0.1.0 → 0.1.2
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 +120 -0
- package/SKILL.md +6 -1
- package/bin/clawcredit.js +74 -0
- package/index.js +9 -2
- package/lib/config.js +50 -0
- package/package.json +13 -3
- package/clawcredit-sdk-0.1.0.tgz +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# ClawCredit SDK for Open Claw
|
|
2
|
+
|
|
3
|
+
ClawCredit provides a credit line and payment workflow for Open Claw Agents using t54's Trustline and the x402 protocol.
|
|
4
|
+
This SDK lets an agent register for credit, submit audit materials, and pay
|
|
5
|
+
merchants with this credit service. Trustline's risk engine evaluates the
|
|
6
|
+
agent's integration depth, richness of risk signals, and credit history
|
|
7
|
+
(including on-time repayments and other records) to issue updated credit
|
|
8
|
+
limits daily or dynamically.
|
|
9
|
+
|
|
10
|
+
## About Open Claw
|
|
11
|
+
|
|
12
|
+
Open Claw is an open-source agent framework that runs your personal AI assistant
|
|
13
|
+
across platforms, with a gateway, skills, and channel integrations. It is
|
|
14
|
+
designed to let agents run locally or remotely, with a configurable workspace
|
|
15
|
+
and a modular “skills” system you can extend.
|
|
16
|
+
Repository: https://github.com/openclaw/openclaw
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
Install the SDK:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @t54-labs/clawcredit-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Configure token via CLI (recommended for humans, not agents):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
clawcredit configure --token YOUR_API_TOKEN --service-url https://api.claw.credit
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Initialize and register:
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const { ClawCredit, audit } = require('@t54-labs/clawcredit-sdk');
|
|
36
|
+
|
|
37
|
+
function myCoreLogic(input) {
|
|
38
|
+
return input * 2;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Optional but recommended: capture core code for audit
|
|
42
|
+
audit(myCoreLogic);
|
|
43
|
+
|
|
44
|
+
const credit = new ClawCredit({
|
|
45
|
+
agentName: "MyOpenClawAgent"
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await credit.register({
|
|
49
|
+
inviteCode: "YOUR_INVITE_CODE",
|
|
50
|
+
coreCode: "function main() { ... }",
|
|
51
|
+
systemPrompt: "You are a helpful assistant.",
|
|
52
|
+
runtimeEnv: "node-v22",
|
|
53
|
+
model: "gpt-5.2" // Optional
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Enable Reasoning Trace (Recommended)
|
|
58
|
+
|
|
59
|
+
Trace helps the risk engine evaluate why a payment is needed.
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const OpenAI = require('openai');
|
|
63
|
+
const { wrapOpenAI, withTrace } = require('@t54-labs/clawcredit-sdk');
|
|
64
|
+
|
|
65
|
+
const openai = wrapOpenAI(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }));
|
|
66
|
+
|
|
67
|
+
await withTrace(async () => {
|
|
68
|
+
await openai.chat.completions.create({
|
|
69
|
+
messages: [{ role: "user", content: "Fetch the latest BTC price." }],
|
|
70
|
+
model: "gpt-5.2"
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Pay a Merchant
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
const result = await credit.pay({
|
|
79
|
+
transaction: {
|
|
80
|
+
recipient: "merchant_address_or_id",
|
|
81
|
+
amount: 1.5,
|
|
82
|
+
chain: "BASE",
|
|
83
|
+
asset: "USDC"
|
|
84
|
+
},
|
|
85
|
+
request_body: {
|
|
86
|
+
service_name: "PremiumSearch",
|
|
87
|
+
params: { query: "BTC price" }
|
|
88
|
+
},
|
|
89
|
+
// Optional: reasoning process can increase approval probability
|
|
90
|
+
// context: { reasoning_process: "I need real-time data to answer the user." }
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
console.log(result);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## How an Open Claw Agent Learns This Skill
|
|
97
|
+
|
|
98
|
+
Open Claw agents can be taught via a skill guide. Provide the agent with the
|
|
99
|
+
`SKILL.md` in this package and instruct it to:
|
|
100
|
+
|
|
101
|
+
1. Install the SDK: `npm install @t54-labs/clawcredit-sdk`
|
|
102
|
+
2. Register using `credit.register()` with audit materials.
|
|
103
|
+
3. Wrap the OpenAI client with `wrapOpenAI()` for trace capture.
|
|
104
|
+
4. Use `credit.pay()` with `transaction` and `request_body`.
|
|
105
|
+
|
|
106
|
+
The `SKILL.md` file in this package contains a step-by-step guide tailored for
|
|
107
|
+
agent use. You can host it and prompt agents to read and follow it.
|
|
108
|
+
|
|
109
|
+
## Exports
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
const {
|
|
113
|
+
ClawCredit,
|
|
114
|
+
audit,
|
|
115
|
+
wrapOpenAI,
|
|
116
|
+
withTrace
|
|
117
|
+
} = require('@t54-labs/clawcredit-sdk');
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
|
package/SKILL.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: clawcredit
|
|
3
|
+
description: ClawCredit integration for Open Claw Agents (registration, trace, and payments).
|
|
4
|
+
---
|
|
5
|
+
|
|
1
6
|
# ClawCredit Integration Skill
|
|
2
7
|
|
|
3
8
|
## 1. Overview
|
|
4
9
|
This skill allows Open Claw Agents to access **ClawCredit**, a decentralized credit service.
|
|
5
|
-
By integrating the `@clawcredit
|
|
10
|
+
By integrating the `@t54-labs/clawcredit-sdk`, agents can:
|
|
6
11
|
1. **Get a Credit Line**: Prove your worth (code, prompt, environment) and get funded.
|
|
7
12
|
2. **Pay for Services**: Use your credit to pay other agents/merchants via x402.
|
|
8
13
|
3. **Build Credit**: Good repayment and low-risk behavior increases your limit.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { loadConfig, saveConfig, DEFAULT_SERVICE_URL } = require('../lib/config');
|
|
3
|
+
|
|
4
|
+
function printHelp() {
|
|
5
|
+
console.log(`
|
|
6
|
+
ClawCredit CLI
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
clawcredit configure --token <API_TOKEN> [--service-url <URL>] [--agent <id>]
|
|
10
|
+
clawcredit show [--agent <id>]
|
|
11
|
+
|
|
12
|
+
Notes:
|
|
13
|
+
- Config is stored at: ~/.openclaw/agents/<agent>/agent/clawcredit.json
|
|
14
|
+
- You can override the config path with CLAWCREDIT_CONFIG
|
|
15
|
+
`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function parseArgs(argv) {
|
|
19
|
+
const args = {};
|
|
20
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
21
|
+
const key = argv[i];
|
|
22
|
+
if (!key.startsWith('--')) continue;
|
|
23
|
+
const value = argv[i + 1];
|
|
24
|
+
args[key.slice(2)] = value;
|
|
25
|
+
i += 1;
|
|
26
|
+
}
|
|
27
|
+
return args;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function main() {
|
|
31
|
+
const [,, command, ...rest] = process.argv;
|
|
32
|
+
const args = parseArgs(rest);
|
|
33
|
+
const agent = args.agent || 'default';
|
|
34
|
+
|
|
35
|
+
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
36
|
+
printHelp();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (command === 'configure' || command === 'set-token') {
|
|
41
|
+
const token = args.token;
|
|
42
|
+
const serviceUrl = args['service-url'] || DEFAULT_SERVICE_URL;
|
|
43
|
+
|
|
44
|
+
if (!token) {
|
|
45
|
+
console.error('Missing --token');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const configPath = saveConfig({ agent, token, serviceUrl });
|
|
50
|
+
console.log(`Saved: ${configPath}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (command === 'show') {
|
|
55
|
+
const { configPath, data, error } = loadConfig(agent);
|
|
56
|
+
if (error) {
|
|
57
|
+
console.error(`Failed to read ${configPath}: ${error.message}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
if (!data) {
|
|
61
|
+
console.log(`No config found at: ${configPath}`);
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
console.log(JSON.stringify(data, null, 2));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.error(`Unknown command: ${command}`);
|
|
69
|
+
printHelp();
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main();
|
|
74
|
+
|
package/index.js
CHANGED
|
@@ -2,12 +2,19 @@ const axios = require('axios');
|
|
|
2
2
|
const { v4: uuidv4 } = require('uuid');
|
|
3
3
|
const { audit, getAuditedSnapshot } = require('./lib/audit');
|
|
4
4
|
const { wrapOpenAI, withTrace, getTraceContext } = require('./lib/monitor');
|
|
5
|
+
const { loadConfig, DEFAULT_SERVICE_URL } = require('./lib/config');
|
|
5
6
|
|
|
6
7
|
class ClawCredit {
|
|
7
8
|
constructor(config = {}) {
|
|
8
|
-
|
|
9
|
+
const agent = config.agent || 'default';
|
|
10
|
+
const loaded = loadConfig(agent);
|
|
11
|
+
const loadedData = loaded.data || {};
|
|
12
|
+
|
|
13
|
+
this.serviceUrl = config.serviceUrl
|
|
14
|
+
|| loadedData.serviceUrl
|
|
15
|
+
|| DEFAULT_SERVICE_URL;
|
|
9
16
|
this.agentName = config.agentName;
|
|
10
|
-
this.apiToken = config.apiToken; // Token stored after registration
|
|
17
|
+
this.apiToken = config.apiToken || loadedData.apiToken; // Token stored after registration
|
|
11
18
|
this.agentId = config.agentId;
|
|
12
19
|
}
|
|
13
20
|
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_SERVICE_URL = 'https://api.claw.credit';
|
|
6
|
+
|
|
7
|
+
function getDefaultConfigPath(agent = 'default') {
|
|
8
|
+
const home = os.homedir();
|
|
9
|
+
return path.join(home, '.openclaw', 'agents', agent, 'agent', 'clawcredit.json');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function loadConfig(agent = 'default') {
|
|
13
|
+
const overridePath = process.env.CLAWCREDIT_CONFIG;
|
|
14
|
+
const configPath = overridePath || getDefaultConfigPath(agent);
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(configPath)) {
|
|
17
|
+
return { configPath, data: null };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const raw = fs.readFileSync(configPath, 'utf-8');
|
|
22
|
+
const data = JSON.parse(raw);
|
|
23
|
+
return { configPath, data };
|
|
24
|
+
} catch (err) {
|
|
25
|
+
return { configPath, data: null, error: err };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function saveConfig({ agent = 'default', token, serviceUrl }) {
|
|
30
|
+
const configPath = getDefaultConfigPath(agent);
|
|
31
|
+
const dir = path.dirname(configPath);
|
|
32
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
33
|
+
|
|
34
|
+
const payload = {
|
|
35
|
+
apiToken: token,
|
|
36
|
+
serviceUrl: serviceUrl || DEFAULT_SERVICE_URL,
|
|
37
|
+
updatedAt: new Date().toISOString()
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
fs.writeFileSync(configPath, JSON.stringify(payload, null, 2));
|
|
41
|
+
return configPath;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
DEFAULT_SERVICE_URL,
|
|
46
|
+
getDefaultConfigPath,
|
|
47
|
+
loadConfig,
|
|
48
|
+
saveConfig
|
|
49
|
+
};
|
|
50
|
+
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t54-labs/clawcredit-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Integration SDK for Open Claw Agents to access ClawCredit",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"clawcredit": "bin/clawcredit.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"lib",
|
|
12
|
+
"bin",
|
|
13
|
+
"README.md",
|
|
14
|
+
"SKILL.md"
|
|
15
|
+
],
|
|
6
16
|
"dependencies": {
|
|
7
17
|
"axios": "^1.6.0",
|
|
8
18
|
"uuid": "^9.0.0"
|
|
9
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT"
|
|
10
21
|
}
|
|
11
|
-
|
package/clawcredit-sdk-0.1.0.tgz
DELETED
|
Binary file
|