@1claw/sdk 0.2.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 +133 -0
- package/README.md +246 -0
- package/dist/access.d.ts +35 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +52 -0
- package/dist/access.js.map +1 -0
- package/dist/agents.d.ts +41 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +61 -0
- package/dist/agents.js.map +1 -0
- package/dist/api-keys.d.ts +20 -0
- package/dist/api-keys.d.ts.map +1 -0
- package/dist/api-keys.js +25 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/approvals.d.ts +45 -0
- package/dist/approvals.d.ts.map +1 -0
- package/dist/approvals.js +76 -0
- package/dist/approvals.js.map +1 -0
- package/dist/audit.d.ts +23 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +41 -0
- package/dist/audit.js.map +1 -0
- package/dist/auth.d.ts +42 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +79 -0
- package/dist/auth.js.map +1 -0
- package/dist/billing.d.ts +17 -0
- package/dist/billing.d.ts.map +1 -0
- package/dist/billing.js +22 -0
- package/dist/billing.js.map +1 -0
- package/dist/chains.d.ts +25 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +39 -0
- package/dist/chains.js.map +1 -0
- package/dist/client.d.ts +99 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +116 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +56 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +115 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +42 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +145 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/handler.d.ts +40 -0
- package/dist/mcp/handler.d.ts.map +1 -0
- package/dist/mcp/handler.js +216 -0
- package/dist/mcp/handler.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/tools.d.ts +29 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +236 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/org.d.ts +16 -0
- package/dist/org.d.ts.map +1 -0
- package/dist/org.js +21 -0
- package/dist/org.js.map +1 -0
- package/dist/secrets.d.ts +42 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +48 -0
- package/dist/secrets.js.map +1 -0
- package/dist/sharing.d.ts +59 -0
- package/dist/sharing.d.ts.map +1 -0
- package/dist/sharing.js +69 -0
- package/dist/sharing.js.map +1 -0
- package/dist/types.d.ts +446 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/vault.d.ts +18 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/vault.js +30 -0
- package/dist/vault.js.map +1 -0
- package/dist/x402.d.ts +40 -0
- package/dist/x402.d.ts.map +1 -0
- package/dist/x402.js +129 -0
- package/dist/x402.js.map +1 -0
- package/package.json +47 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { HttpClient } from "./http";
|
|
2
|
+
import { VaultResource } from "./vault";
|
|
3
|
+
import { SecretsResource } from "./secrets";
|
|
4
|
+
import { AccessResource } from "./access";
|
|
5
|
+
import { AgentsResource } from "./agents";
|
|
6
|
+
import { SharingResource } from "./sharing";
|
|
7
|
+
import { ApprovalsResource } from "./approvals";
|
|
8
|
+
import { BillingResource } from "./billing";
|
|
9
|
+
import { AuditResource } from "./audit";
|
|
10
|
+
import { OrgResource } from "./org";
|
|
11
|
+
import { AuthResource } from "./auth";
|
|
12
|
+
import { ApiKeysResource } from "./api-keys";
|
|
13
|
+
import { ChainsResource } from "./chains";
|
|
14
|
+
import { X402Resource } from "./x402";
|
|
15
|
+
/**
|
|
16
|
+
* The main 1Claw SDK client. All API resources are exposed as
|
|
17
|
+
* namespaced properties for discoverability and tree-shaking.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { createClient } from "@1claw/sdk";
|
|
22
|
+
*
|
|
23
|
+
* const client = createClient({
|
|
24
|
+
* baseUrl: "https://api.1claw.xyz",
|
|
25
|
+
* apiKey: "ocv_...",
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Authenticate (exchanges API key for a JWT)
|
|
29
|
+
* await client.auth.apiKeyToken({ api_key: "ocv_..." });
|
|
30
|
+
*
|
|
31
|
+
* // Use resources
|
|
32
|
+
* const vaults = await client.vault.list();
|
|
33
|
+
* const secret = await client.secrets.get(vaultId, "my-key");
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class OneclawClient {
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.http = new HttpClient(config);
|
|
39
|
+
if (config.apiKey && !config.token) {
|
|
40
|
+
this.autoAuthenticate(config);
|
|
41
|
+
}
|
|
42
|
+
this.vault = new VaultResource(this.http);
|
|
43
|
+
this.secrets = new SecretsResource(this.http);
|
|
44
|
+
this.access = new AccessResource(this.http);
|
|
45
|
+
this.agents = new AgentsResource(this.http);
|
|
46
|
+
this.sharing = new SharingResource(this.http);
|
|
47
|
+
this.approvals = new ApprovalsResource(this.http);
|
|
48
|
+
this.billing = new BillingResource(this.http);
|
|
49
|
+
this.audit = new AuditResource(this.http);
|
|
50
|
+
this.org = new OrgResource(this.http);
|
|
51
|
+
this.auth = new AuthResource(this.http);
|
|
52
|
+
this.apiKeys = new ApiKeysResource(this.http);
|
|
53
|
+
this.chains = new ChainsResource(this.http);
|
|
54
|
+
this.x402 = new X402Resource(this.http, config.x402Signer);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* When an API key is provided without a pre-existing token, lazily
|
|
58
|
+
* exchange it for a JWT on construction. This is async but fires
|
|
59
|
+
* without blocking the constructor — the first actual request
|
|
60
|
+
* will await token resolution.
|
|
61
|
+
*/
|
|
62
|
+
autoAuthenticate(config) {
|
|
63
|
+
const authPromise = config.agentId
|
|
64
|
+
? this.http
|
|
65
|
+
.request("POST", "/v1/auth/agent-token", {
|
|
66
|
+
body: {
|
|
67
|
+
agent_id: config.agentId,
|
|
68
|
+
api_key: config.apiKey,
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
.then((res) => {
|
|
72
|
+
if (res.data?.access_token)
|
|
73
|
+
this.http.setToken(res.data.access_token);
|
|
74
|
+
})
|
|
75
|
+
: this.http
|
|
76
|
+
.request("POST", "/v1/auth/api-key-token", {
|
|
77
|
+
body: { api_key: config.apiKey },
|
|
78
|
+
})
|
|
79
|
+
.then((res) => {
|
|
80
|
+
if (res.data?.access_token)
|
|
81
|
+
this.http.setToken(res.data.access_token);
|
|
82
|
+
});
|
|
83
|
+
authPromise.catch(() => {
|
|
84
|
+
/* auth failure will surface on the next request */
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Factory function to create a new 1Claw SDK client.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* // User with API key
|
|
94
|
+
* const client = createClient({
|
|
95
|
+
* baseUrl: "https://api.1claw.xyz",
|
|
96
|
+
* apiKey: "ocv_...",
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Agent with API key
|
|
100
|
+
* const agent = createClient({
|
|
101
|
+
* baseUrl: "https://api.1claw.xyz",
|
|
102
|
+
* apiKey: "ocv_...",
|
|
103
|
+
* agentId: "agent-uuid",
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // Pre-authenticated with JWT
|
|
107
|
+
* const authed = createClient({
|
|
108
|
+
* baseUrl: "https://api.1claw.xyz",
|
|
109
|
+
* token: "eyJ...",
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export function createClient(config) {
|
|
114
|
+
return new OneclawClient(config);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,aAAa;IA8BtB,YAAY,MAA2B;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QAEnC,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACjC,IAAI,CAAC,gBAAgB,CAAC,MAA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,MAAM,EACN,sBAAsB,EACtB;gBACI,IAAI,EAAE;oBACF,QAAQ,EAAE,MAAM,CAAC,OAAO;oBACxB,OAAO,EAAE,MAAM,CAAC,MAAM;iBACzB;aACJ,CACJ;iBACA,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;gBACV,IAAI,GAAG,CAAC,IAAI,EAAE,YAAY;oBACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAClD,CAAC,CAAC;YACR,CAAC,CAAC,IAAI,CAAC,IAAI;iBACJ,OAAO,CACJ,MAAM,EACN,wBAAwB,EACxB;gBACI,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE;aACnC,CACJ;iBACA,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;gBACV,IAAI,GAAG,CAAC,IAAI,EAAE,YAAY;oBACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QAEb,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE;YACnB,mDAAmD;QACvD,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,YAAY,CAAC,MAA2B;IACpD,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { PaymentRequirement } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Base error class for all 1Claw SDK errors.
|
|
4
|
+
* Includes the HTTP status code and a machine-readable error type.
|
|
5
|
+
*/
|
|
6
|
+
export declare class OneclawError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly type: string;
|
|
9
|
+
readonly detail?: string;
|
|
10
|
+
constructor(message: string, status: number, type: string, detail?: string);
|
|
11
|
+
}
|
|
12
|
+
/** Thrown on 401 Unauthorized or 403 Forbidden responses. */
|
|
13
|
+
export declare class AuthError extends OneclawError {
|
|
14
|
+
constructor(message: string, status?: 401 | 403);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Thrown on 402 Payment Required responses.
|
|
18
|
+
* Contains the full `PaymentRequirement` so callers can inspect
|
|
19
|
+
* price, network, and payment address before deciding to pay.
|
|
20
|
+
*/
|
|
21
|
+
export declare class PaymentRequiredError extends OneclawError {
|
|
22
|
+
readonly paymentRequirement: PaymentRequirement;
|
|
23
|
+
constructor(message: string, paymentRequirement: PaymentRequirement);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Thrown when a secret is gated behind human approval.
|
|
27
|
+
* The `approvalRequestId` can be used to poll for approval status.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ApprovalRequiredError extends OneclawError {
|
|
30
|
+
readonly approvalRequestId: string;
|
|
31
|
+
constructor(approvalRequestId: string, message?: string);
|
|
32
|
+
}
|
|
33
|
+
/** Thrown on 404 Not Found responses. */
|
|
34
|
+
export declare class NotFoundError extends OneclawError {
|
|
35
|
+
constructor(message?: string);
|
|
36
|
+
}
|
|
37
|
+
/** Thrown on 429 Too Many Requests responses. Includes retry timing when available. */
|
|
38
|
+
export declare class RateLimitError extends OneclawError {
|
|
39
|
+
readonly retryAfterMs?: number;
|
|
40
|
+
constructor(message?: string, retryAfterMs?: number);
|
|
41
|
+
}
|
|
42
|
+
/** Thrown on 400 Bad Request responses for validation failures. */
|
|
43
|
+
export declare class ValidationError extends OneclawError {
|
|
44
|
+
readonly fields?: Record<string, string>;
|
|
45
|
+
constructor(message: string, fields?: Record<string, string>);
|
|
46
|
+
}
|
|
47
|
+
/** Thrown on 500+ server-side errors. */
|
|
48
|
+
export declare class ServerError extends OneclawError {
|
|
49
|
+
constructor(message?: string, status?: number);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse an HTTP response into the appropriate typed error.
|
|
53
|
+
* Falls back to a generic `OneclawError` for unrecognised status codes.
|
|
54
|
+
*/
|
|
55
|
+
export declare function errorFromResponse(res: Response): Promise<OneclawError>;
|
|
56
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAGrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM;CAQtB;AAED,6DAA6D;AAC7D,qBAAa,SAAU,SAAQ,YAAY;gBAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,GAAG,GAAS;CAIvD;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,YAAY;IAClD,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBAEpC,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,kBAAkB;CAKtE;AAED;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;IACnD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;gBAEvB,iBAAiB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAS1D;AAED,yCAAyC;AACzC,qBAAa,aAAc,SAAQ,YAAY;gBAC/B,OAAO,GAAE,MAA6B;CAIrD;AAED,uFAAuF;AACvF,qBAAa,cAAe,SAAQ,YAAY;IAC5C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;gBAG3B,OAAO,GAAE,MAA8B,EACvC,YAAY,CAAC,EAAE,MAAM;CAM5B;AAED,mEAAmE;AACnE,qBAAa,eAAgB,SAAQ,YAAY;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAK/D;AAED,yCAAyC;AACzC,qBAAa,WAAY,SAAQ,YAAY;gBAErC,OAAO,GAAE,MAAgC,EACzC,MAAM,GAAE,MAAY;CAK3B;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,CAwC5E"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all 1Claw SDK errors.
|
|
3
|
+
* Includes the HTTP status code and a machine-readable error type.
|
|
4
|
+
*/
|
|
5
|
+
export class OneclawError extends Error {
|
|
6
|
+
constructor(message, status, type, detail) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "OneclawError";
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.type = type;
|
|
11
|
+
this.detail = detail;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Thrown on 401 Unauthorized or 403 Forbidden responses. */
|
|
15
|
+
export class AuthError extends OneclawError {
|
|
16
|
+
constructor(message, status = 401) {
|
|
17
|
+
super(message, status, "auth_error");
|
|
18
|
+
this.name = "AuthError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Thrown on 402 Payment Required responses.
|
|
23
|
+
* Contains the full `PaymentRequirement` so callers can inspect
|
|
24
|
+
* price, network, and payment address before deciding to pay.
|
|
25
|
+
*/
|
|
26
|
+
export class PaymentRequiredError extends OneclawError {
|
|
27
|
+
constructor(message, paymentRequirement) {
|
|
28
|
+
super(message, 402, "payment_required");
|
|
29
|
+
this.name = "PaymentRequiredError";
|
|
30
|
+
this.paymentRequirement = paymentRequirement;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Thrown when a secret is gated behind human approval.
|
|
35
|
+
* The `approvalRequestId` can be used to poll for approval status.
|
|
36
|
+
*/
|
|
37
|
+
export class ApprovalRequiredError extends OneclawError {
|
|
38
|
+
constructor(approvalRequestId, message) {
|
|
39
|
+
super(message ?? "Human approval is required to access this secret", 403, "approval_required");
|
|
40
|
+
this.name = "ApprovalRequiredError";
|
|
41
|
+
this.approvalRequestId = approvalRequestId;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Thrown on 404 Not Found responses. */
|
|
45
|
+
export class NotFoundError extends OneclawError {
|
|
46
|
+
constructor(message = "Resource not found") {
|
|
47
|
+
super(message, 404, "not_found");
|
|
48
|
+
this.name = "NotFoundError";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Thrown on 429 Too Many Requests responses. Includes retry timing when available. */
|
|
52
|
+
export class RateLimitError extends OneclawError {
|
|
53
|
+
constructor(message = "Rate limit exceeded", retryAfterMs) {
|
|
54
|
+
super(message, 429, "rate_limit");
|
|
55
|
+
this.name = "RateLimitError";
|
|
56
|
+
this.retryAfterMs = retryAfterMs;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Thrown on 400 Bad Request responses for validation failures. */
|
|
60
|
+
export class ValidationError extends OneclawError {
|
|
61
|
+
constructor(message, fields) {
|
|
62
|
+
super(message, 400, "validation_error");
|
|
63
|
+
this.name = "ValidationError";
|
|
64
|
+
this.fields = fields;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Thrown on 500+ server-side errors. */
|
|
68
|
+
export class ServerError extends OneclawError {
|
|
69
|
+
constructor(message = "Internal server error", status = 500) {
|
|
70
|
+
super(message, status, "server_error");
|
|
71
|
+
this.name = "ServerError";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Parse an HTTP response into the appropriate typed error.
|
|
76
|
+
* Falls back to a generic `OneclawError` for unrecognised status codes.
|
|
77
|
+
*/
|
|
78
|
+
export async function errorFromResponse(res) {
|
|
79
|
+
let body = {};
|
|
80
|
+
try {
|
|
81
|
+
body = (await res.json());
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
/* response may not be JSON */
|
|
85
|
+
}
|
|
86
|
+
const message = body.detail ??
|
|
87
|
+
body.message ??
|
|
88
|
+
body.error ??
|
|
89
|
+
`HTTP ${res.status}`;
|
|
90
|
+
switch (res.status) {
|
|
91
|
+
case 400:
|
|
92
|
+
return new ValidationError(message, body.fields);
|
|
93
|
+
case 401:
|
|
94
|
+
case 403:
|
|
95
|
+
return new AuthError(message, res.status);
|
|
96
|
+
case 402: {
|
|
97
|
+
const requirement = body;
|
|
98
|
+
return new PaymentRequiredError(message, requirement);
|
|
99
|
+
}
|
|
100
|
+
case 404:
|
|
101
|
+
return new NotFoundError(message);
|
|
102
|
+
case 429: {
|
|
103
|
+
const retryHeader = res.headers.get("Retry-After");
|
|
104
|
+
const retryAfterMs = retryHeader
|
|
105
|
+
? parseInt(retryHeader, 10) * 1000
|
|
106
|
+
: undefined;
|
|
107
|
+
return new RateLimitError(message, retryAfterMs);
|
|
108
|
+
}
|
|
109
|
+
default:
|
|
110
|
+
if (res.status >= 500)
|
|
111
|
+
return new ServerError(message, res.status);
|
|
112
|
+
return new OneclawError(message, res.status, "unknown");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAKnC,YACI,OAAe,EACf,MAAc,EACd,IAAY,EACZ,MAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CA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,MAAmB,CAAC,CAAC;QAC3D,KAAK,GAAG,CAAC,CAAC,CAAC;YACP,MAAM,WAAW,GAAG,IAAqC,CAAC;YAC1D,OAAO,IAAI,oBAAoB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC1D,CAAC;QACD,KAAK,GAAG;YACJ,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QACtC,KAAK,GAAG,CAAC,CAAC,CAAC;YACP,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YACnD,MAAM,YAAY,GAAG,WAAW;gBAC5B,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,GAAG,IAAI;gBAClC,CAAC,CAAC,SAAS,CAAC;YAChB,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACrD,CAAC;QACD;YACI,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG;gBAAE,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;YACnE,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;AACL,CAAC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { OneclawClientConfig, OneclawResponse } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Internal HTTP transport used by every resource module.
|
|
4
|
+
* Handles authentication headers, 402 auto-pay, and error mapping.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HttpClient {
|
|
7
|
+
private baseUrl;
|
|
8
|
+
private token?;
|
|
9
|
+
private signer?;
|
|
10
|
+
private maxAutoPayUsd;
|
|
11
|
+
constructor(config: OneclawClientConfig);
|
|
12
|
+
/** Replace the current Bearer token (called by auth methods). */
|
|
13
|
+
setToken(token: string): void;
|
|
14
|
+
getToken(): string | undefined;
|
|
15
|
+
getBaseUrl(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Perform a typed request against the API and return an envelope.
|
|
18
|
+
* Automatically retries once with an x402 payment header when
|
|
19
|
+
* a signer is configured and the price is within limits.
|
|
20
|
+
*/
|
|
21
|
+
request<T>(method: string, path: string, options?: {
|
|
22
|
+
body?: unknown;
|
|
23
|
+
query?: Record<string, string | number | undefined>;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
}): Promise<OneclawResponse<T>>;
|
|
26
|
+
/**
|
|
27
|
+
* Same as `request` but throws on error instead of returning an envelope.
|
|
28
|
+
* Convenient for callers that prefer exceptions.
|
|
29
|
+
*/
|
|
30
|
+
requestOrThrow<T>(method: string, path: string, options?: {
|
|
31
|
+
body?: unknown;
|
|
32
|
+
query?: Record<string, string | number | undefined>;
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
}): Promise<T>;
|
|
35
|
+
private buildUrl;
|
|
36
|
+
/**
|
|
37
|
+
* Attempt to sign an x402 payment and retry the original request
|
|
38
|
+
* with the `X-PAYMENT` header attached.
|
|
39
|
+
*/
|
|
40
|
+
private handlePayment;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,mBAAmB,EACnB,eAAe,EAGlB,MAAM,SAAS,CAAC;AAGjB;;;GAGG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,MAAM,CAAC,CAAa;IAC5B,OAAO,CAAC,aAAa,CAAS;gBAElB,MAAM,EAAE,mBAAmB;IAOvC,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,QAAQ,IAAI,MAAM,GAAG,SAAS;IAI9B,UAAU,IAAI,MAAM;IAIpB;;;;OAIG;IACG,OAAO,CAAC,CAAC,EACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QACL,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;QACpD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC/B,GACP,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IA8C9B;;;OAGG;IACG,cAAc,CAAC,CAAC,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QACL,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;QACpD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC/B,GACP,OAAO,CAAC,CAAC,CAAC;IAoCb,OAAO,CAAC,QAAQ;IAahB;;;OAGG;YACW,aAAa;CA6C9B"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { errorFromResponse, PaymentRequiredError } from "./errors";
|
|
2
|
+
/**
|
|
3
|
+
* Internal HTTP transport used by every resource module.
|
|
4
|
+
* Handles authentication headers, 402 auto-pay, and error mapping.
|
|
5
|
+
*/
|
|
6
|
+
export class HttpClient {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
9
|
+
this.token = config.token;
|
|
10
|
+
this.signer = config.x402Signer;
|
|
11
|
+
this.maxAutoPayUsd = config.maxAutoPayUsd ?? 0;
|
|
12
|
+
}
|
|
13
|
+
/** Replace the current Bearer token (called by auth methods). */
|
|
14
|
+
setToken(token) {
|
|
15
|
+
this.token = token;
|
|
16
|
+
}
|
|
17
|
+
getToken() {
|
|
18
|
+
return this.token;
|
|
19
|
+
}
|
|
20
|
+
getBaseUrl() {
|
|
21
|
+
return this.baseUrl;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Perform a typed request against the API and return an envelope.
|
|
25
|
+
* Automatically retries once with an x402 payment header when
|
|
26
|
+
* a signer is configured and the price is within limits.
|
|
27
|
+
*/
|
|
28
|
+
async request(method, path, options = {}) {
|
|
29
|
+
const url = this.buildUrl(path, options.query);
|
|
30
|
+
const headers = {
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
...options.headers,
|
|
33
|
+
};
|
|
34
|
+
if (this.token) {
|
|
35
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
36
|
+
}
|
|
37
|
+
const init = { method, headers };
|
|
38
|
+
if (options.body !== undefined) {
|
|
39
|
+
init.body = JSON.stringify(options.body);
|
|
40
|
+
}
|
|
41
|
+
let res = await fetch(url, init);
|
|
42
|
+
if (res.status === 402 && this.signer) {
|
|
43
|
+
res = await this.handlePayment(res, url, init);
|
|
44
|
+
}
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
const err = await errorFromResponse(res);
|
|
47
|
+
return {
|
|
48
|
+
data: null,
|
|
49
|
+
error: {
|
|
50
|
+
type: err.type,
|
|
51
|
+
message: err.message,
|
|
52
|
+
detail: err.detail,
|
|
53
|
+
},
|
|
54
|
+
meta: { status: res.status },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (res.status === 204) {
|
|
58
|
+
return {
|
|
59
|
+
data: null,
|
|
60
|
+
error: null,
|
|
61
|
+
meta: { status: 204 },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const data = (await res.json());
|
|
65
|
+
return { data, error: null, meta: { status: res.status } };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Same as `request` but throws on error instead of returning an envelope.
|
|
69
|
+
* Convenient for callers that prefer exceptions.
|
|
70
|
+
*/
|
|
71
|
+
async requestOrThrow(method, path, options = {}) {
|
|
72
|
+
const url = this.buildUrl(path, options.query);
|
|
73
|
+
const headers = {
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
...options.headers,
|
|
76
|
+
};
|
|
77
|
+
if (this.token) {
|
|
78
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
79
|
+
}
|
|
80
|
+
const init = { method, headers };
|
|
81
|
+
if (options.body !== undefined) {
|
|
82
|
+
init.body = JSON.stringify(options.body);
|
|
83
|
+
}
|
|
84
|
+
let res = await fetch(url, init);
|
|
85
|
+
if (res.status === 402 && this.signer) {
|
|
86
|
+
res = await this.handlePayment(res, url, init);
|
|
87
|
+
}
|
|
88
|
+
if (!res.ok) {
|
|
89
|
+
throw await errorFromResponse(res);
|
|
90
|
+
}
|
|
91
|
+
if (res.status === 204) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
return (await res.json());
|
|
95
|
+
}
|
|
96
|
+
// -----------------------------------------------------------------------
|
|
97
|
+
// Private helpers
|
|
98
|
+
// -----------------------------------------------------------------------
|
|
99
|
+
buildUrl(path, query) {
|
|
100
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
101
|
+
if (query) {
|
|
102
|
+
for (const [k, v] of Object.entries(query)) {
|
|
103
|
+
if (v !== undefined)
|
|
104
|
+
url.searchParams.set(k, String(v));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return url.toString();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Attempt to sign an x402 payment and retry the original request
|
|
111
|
+
* with the `X-PAYMENT` header attached.
|
|
112
|
+
*/
|
|
113
|
+
async handlePayment(originalRes, url, init) {
|
|
114
|
+
let requirement;
|
|
115
|
+
try {
|
|
116
|
+
requirement = (await originalRes.json());
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return originalRes;
|
|
120
|
+
}
|
|
121
|
+
const accept = requirement.accepts?.[0];
|
|
122
|
+
if (!accept || !this.signer)
|
|
123
|
+
return originalRes;
|
|
124
|
+
const price = parseFloat(accept.price);
|
|
125
|
+
if (this.maxAutoPayUsd > 0 && price > this.maxAutoPayUsd) {
|
|
126
|
+
throw new PaymentRequiredError(`Payment of $${price} exceeds auto-pay limit of $${this.maxAutoPayUsd}`, requirement);
|
|
127
|
+
}
|
|
128
|
+
if (this.maxAutoPayUsd === 0) {
|
|
129
|
+
throw new PaymentRequiredError(`Payment of $${price} required. Enable auto-pay via maxAutoPayUsd config.`, requirement);
|
|
130
|
+
}
|
|
131
|
+
const signature = await this.signer.signPayment(accept);
|
|
132
|
+
const paymentPayload = {
|
|
133
|
+
x402Version: requirement.x402Version,
|
|
134
|
+
scheme: accept.scheme,
|
|
135
|
+
network: accept.network,
|
|
136
|
+
payload: signature,
|
|
137
|
+
};
|
|
138
|
+
const retryHeaders = {
|
|
139
|
+
...init.headers,
|
|
140
|
+
"X-PAYMENT": JSON.stringify(paymentPayload),
|
|
141
|
+
};
|
|
142
|
+
return fetch(url, { ...init, headers: retryHeaders });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEnE;;;GAGG;AACH,MAAM,OAAO,UAAU;IAMnB,YAAY,MAA2B;QACnC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,CAAC,CAAC;IACnD,CAAC;IAED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AAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,WAAW,CAAC;QAEhD,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACvD,MAAM,IAAI,oBAAoB,CAC1B,eAAe,KAAK,+BAA+B,IAAI,CAAC,aAAa,EAAE,EACvE,WAAW,CACd,CAAC;QACN,CAAC;QACD,IAAI,IAAI,CAAC,aAAa,KAAK,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,oBAAoB,CAC1B,eAAe,KAAK,sDAAsD,EAC1E,WAAW,CACd,CAAC;QACN,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAExD,MAAM,cAAc,GAAG;YACnB,WAAW,EAAE,WAAW,CAAC,WAAW;YACpC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,SAAS;SACrB,CAAC;QAEF,MAAM,YAAY,GAAG;YACjB,GAAI,IAAI,CAAC,OAAkC;YAC3C,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;SAC9C,CAAC;QAEF,OAAO,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;IAC1D,CAAC;CACJ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { OneclawClient, createClient } from "./client";
|
|
2
|
+
export { VaultResource } from "./vault";
|
|
3
|
+
export { SecretsResource } from "./secrets";
|
|
4
|
+
export { AccessResource } from "./access";
|
|
5
|
+
export { AgentsResource } from "./agents";
|
|
6
|
+
export { SharingResource } from "./sharing";
|
|
7
|
+
export { ApprovalsResource } from "./approvals";
|
|
8
|
+
export { BillingResource } from "./billing";
|
|
9
|
+
export { AuditResource } from "./audit";
|
|
10
|
+
export { OrgResource } from "./org";
|
|
11
|
+
export { AuthResource } from "./auth";
|
|
12
|
+
export { ApiKeysResource } from "./api-keys";
|
|
13
|
+
export { ChainsResource } from "./chains";
|
|
14
|
+
export { X402Resource } from "./x402";
|
|
15
|
+
export { OneclawError, AuthError, PaymentRequiredError, ApprovalRequiredError, NotFoundError, RateLimitError, ValidationError, ServerError, } from "./errors";
|
|
16
|
+
export type { OneclawClientConfig, OneclawResponse, ResponseMeta, TokenRequest, AgentTokenRequest, UserApiKeyTokenRequest, GoogleAuthRequest, SignupRequest, TokenResponse, ChangePasswordRequest, CreateApiKeyRequest, ApiKeyResponse, ApiKeyCreatedResponse, ApiKeyListResponse, CreateVaultRequest, VaultResponse, VaultListResponse, PutSecretRequest, SecretMetadataResponse, SecretResponse, SecretListResponse, CreatePolicyRequest, UpdatePolicyRequest, PolicyResponse, PolicyListResponse, CreateAgentRequest, UpdateAgentRequest, AgentResponse, AgentCreatedResponse, AgentListResponse, AgentKeyRotatedResponse, ChainResponse, ChainListResponse, CreateChainRequest, UpdateChainRequest, SubmitTransactionRequest, TransactionResponse, TransactionListResponse, CreateShareRequest, ShareResponse, SharedSecretResponse, OrgMemberResponse, OrgMemberListResponse, UpdateMemberRoleRequest, MonthSummary, UsageSummaryResponse, UsageEventResponse, UsageHistoryResponse, AuditQuery, AuditEvent, AuditEventsResponse, PaymentAccept, PaymentRequirement, PaymentPayload, PaymentReceipt, X402Signer, ApprovalRequest, CreateApprovalRequest, ApprovalListResponse, SettingResponse, SettingsListResponse, X402ConfigResponse, HealthResponse, McpToolDefinition, McpToolResult, } from "./types";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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AkB,EAElB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EAEvB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAElB,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EAEvB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EAEpB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EAEvB,YAAY,EACZ,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EAEpB,UAAU,EACV,UAAU,EACV,mBAAmB,EAEnB,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,UAAU,EAEV,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EAEpB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAElB,cAAc,EAEd,iBAAiB,EACjB,aAAa,GAChB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Client
|
|
2
|
+
export { OneclawClient, createClient } from "./client";
|
|
3
|
+
// Resource modules
|
|
4
|
+
export { VaultResource } from "./vault";
|
|
5
|
+
export { SecretsResource } from "./secrets";
|
|
6
|
+
export { AccessResource } from "./access";
|
|
7
|
+
export { AgentsResource } from "./agents";
|
|
8
|
+
export { SharingResource } from "./sharing";
|
|
9
|
+
export { ApprovalsResource } from "./approvals";
|
|
10
|
+
export { BillingResource } from "./billing";
|
|
11
|
+
export { AuditResource } from "./audit";
|
|
12
|
+
export { OrgResource } from "./org";
|
|
13
|
+
export { AuthResource } from "./auth";
|
|
14
|
+
export { ApiKeysResource } from "./api-keys";
|
|
15
|
+
export { ChainsResource } from "./chains";
|
|
16
|
+
export { X402Resource } from "./x402";
|
|
17
|
+
// Errors
|
|
18
|
+
export { OneclawError, AuthError, PaymentRequiredError, ApprovalRequiredError, NotFoundError, RateLimitError, ValidationError, ServerError, } from "./errors";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEvD,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,SAAS;AACT,OAAO,EACH,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,eAAe,EACf,WAAW,GACd,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { McpToolResult } from "../types";
|
|
2
|
+
import type { OneclawClient } from "../client";
|
|
3
|
+
type ToolArgs = Record<string, unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* MCP tool dispatcher — routes incoming tool calls to the appropriate
|
|
6
|
+
* SDK methods and returns structured MCP-compatible results.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createClient } from "@1claw/sdk";
|
|
11
|
+
* import { McpHandler } from "@1claw/sdk/mcp";
|
|
12
|
+
*
|
|
13
|
+
* const client = createClient({ ... });
|
|
14
|
+
* const handler = new McpHandler(client);
|
|
15
|
+
* const result = await handler.handle("1claw_get_secret", { vault_id: "...", key: "..." });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class McpHandler {
|
|
19
|
+
private readonly client;
|
|
20
|
+
private handlers;
|
|
21
|
+
constructor(client: OneclawClient);
|
|
22
|
+
/** Dispatch a tool call by name. Throws if the tool name is unknown. */
|
|
23
|
+
handle(toolName: string, args: ToolArgs): Promise<McpToolResult>;
|
|
24
|
+
/** Return the set of tool names this handler supports. */
|
|
25
|
+
getToolNames(): string[];
|
|
26
|
+
private getSecret;
|
|
27
|
+
private setSecret;
|
|
28
|
+
private listSecretKeys;
|
|
29
|
+
private deleteSecret;
|
|
30
|
+
private listVaults;
|
|
31
|
+
private createVault;
|
|
32
|
+
private requestApproval;
|
|
33
|
+
private checkApproval;
|
|
34
|
+
private payAndFetch;
|
|
35
|
+
private shareSecret;
|
|
36
|
+
private text;
|
|
37
|
+
private error;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/mcp/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExC;;;;;;;;;;;;;GAaG;AACH,qBAAa,UAAU;IAGP,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,QAAQ,CAA0D;gBAE7C,MAAM,EAAE,aAAa;IAelD,wEAAwE;IAClE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC;IAmBtE,0DAA0D;IAC1D,YAAY,IAAI,MAAM,EAAE;YAQV,SAAS;YA+BT,SAAS;YAqBT,cAAc;YAgBd,YAAY;YAUZ,UAAU;YAaV,WAAW;YAgBX,eAAe;YAsBf,aAAa;YAeb,WAAW;YAmBX,WAAW;IA6BzB,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,KAAK;CAGhB"}
|