@cleave-protocol/ai-sdk 0.0.0-stage → 0.1.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.
@@ -0,0 +1,83 @@
1
+ import { Tool } from 'ai';
2
+ import { z } from 'zod/v4';
3
+
4
+ declare const DEFAULT_BASE_URL = "https://api.cleave.fi";
5
+ declare const DEFAULT_TIMEOUT_MS = 30000;
6
+ interface CleaveToolsOptions {
7
+ baseUrl?: string;
8
+ apiKey?: string;
9
+ timeoutMs?: number;
10
+ fetch?: typeof globalThis.fetch;
11
+ getGasApproval?: boolean;
12
+ }
13
+ type CleaveResult = Record<string, unknown>;
14
+ declare class CleaveApiError extends Error {
15
+ readonly status: number;
16
+ readonly requestId: string | null;
17
+ constructor(message: string, status: number, requestId?: string | null, options?: {
18
+ cause?: unknown;
19
+ });
20
+ }
21
+
22
+ declare const CHAIN_IDS: readonly [1, 10, 56, 137, 8453, 42161];
23
+ declare const planSwapInput: z.ZodObject<{
24
+ fromChainId: z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>;
25
+ toChainId: z.ZodOptional<z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>>;
26
+ sellToken: z.ZodString;
27
+ buyToken: z.ZodString;
28
+ amount: z.ZodString;
29
+ wallet: z.ZodString;
30
+ recipient: z.ZodOptional<z.ZodString>;
31
+ maxSlippageBps: z.ZodOptional<z.ZodNumber>;
32
+ }, z.core.$strict>;
33
+ declare const trackSwapInput: z.ZodObject<{
34
+ chainId: z.ZodOptional<z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>>;
35
+ txHash: z.ZodOptional<z.ZodString>;
36
+ requestId: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strict>;
38
+ declare const findTokenInput: z.ZodObject<{
39
+ chainId: z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>;
40
+ query: z.ZodString;
41
+ }, z.core.$strict>;
42
+ declare const getGasInput: z.ZodObject<{
43
+ payChainId: z.ZodOptional<z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>>;
44
+ chainId: z.ZodOptional<z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>>;
45
+ recipient: z.ZodOptional<z.ZodString>;
46
+ amount: z.ZodOptional<z.ZodString>;
47
+ wallet: z.ZodOptional<z.ZodString>;
48
+ refundTo: z.ZodOptional<z.ZodString>;
49
+ offer: z.ZodOptional<z.ZodString>;
50
+ signature: z.ZodOptional<z.ZodString>;
51
+ }, z.core.$strict>;
52
+ type PlanSwapInput = z.infer<typeof planSwapInput>;
53
+ type TrackSwapInput = z.infer<typeof trackSwapInput>;
54
+ type FindTokenInput = z.infer<typeof findTokenInput>;
55
+ type GetGasInput = z.infer<typeof getGasInput>;
56
+
57
+ type CleaveTools = {
58
+ planSwap: Tool<PlanSwapInput, CleaveResult>;
59
+ trackSwap: Tool<TrackSwapInput, CleaveResult>;
60
+ findToken: Tool<FindTokenInput, CleaveResult>;
61
+ getGas: Tool<GetGasInput, CleaveResult>;
62
+ };
63
+ declare function planSwap(options?: CleaveToolsOptions): Tool<PlanSwapInput, CleaveResult>;
64
+ declare function trackSwap(options?: CleaveToolsOptions): Tool<TrackSwapInput, CleaveResult>;
65
+ declare function findToken(options?: CleaveToolsOptions): Tool<FindTokenInput, CleaveResult>;
66
+ declare function getGas(options?: CleaveToolsOptions): Tool<GetGasInput, CleaveResult>;
67
+ declare function cleaveTools(options?: CleaveToolsOptions): CleaveTools;
68
+
69
+ type CheckRule = "P1" | "P2" | "P3" | "P4" | "P5" | "P6" | "G1" | "G2" | "G3" | "G4";
70
+ type CheckResult = {
71
+ ok: true;
72
+ } | {
73
+ ok: false;
74
+ rule: CheckRule;
75
+ message: string;
76
+ };
77
+ declare function checkPlanSwap(request: PlanSwapInput, body: Record<string, unknown>): CheckResult;
78
+ declare function checkGetGas(request: GetGasInput, body: Record<string, unknown>, nowSec?: number): CheckResult;
79
+ declare function screenPlanSwap(request: PlanSwapInput, body: Record<string, unknown>): Record<string, unknown>;
80
+ declare function screenGetGas(request: GetGasInput, body: Record<string, unknown>, nowSec?: number): Record<string, unknown>;
81
+
82
+ export { CHAIN_IDS, CleaveApiError, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, checkGetGas, checkPlanSwap, cleaveTools, findToken, getGas, planSwap, screenGetGas, screenPlanSwap, trackSwap };
83
+ export type { CheckResult, CheckRule, CleaveResult, CleaveTools, CleaveToolsOptions, FindTokenInput, GetGasInput, PlanSwapInput, TrackSwapInput };
@@ -0,0 +1,83 @@
1
+ import { Tool } from 'ai';
2
+ import { z } from 'zod/v4';
3
+
4
+ declare const DEFAULT_BASE_URL = "https://api.cleave.fi";
5
+ declare const DEFAULT_TIMEOUT_MS = 30000;
6
+ interface CleaveToolsOptions {
7
+ baseUrl?: string;
8
+ apiKey?: string;
9
+ timeoutMs?: number;
10
+ fetch?: typeof globalThis.fetch;
11
+ getGasApproval?: boolean;
12
+ }
13
+ type CleaveResult = Record<string, unknown>;
14
+ declare class CleaveApiError extends Error {
15
+ readonly status: number;
16
+ readonly requestId: string | null;
17
+ constructor(message: string, status: number, requestId?: string | null, options?: {
18
+ cause?: unknown;
19
+ });
20
+ }
21
+
22
+ declare const CHAIN_IDS: readonly [1, 10, 56, 137, 8453, 42161];
23
+ declare const planSwapInput: z.ZodObject<{
24
+ fromChainId: z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>;
25
+ toChainId: z.ZodOptional<z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>>;
26
+ sellToken: z.ZodString;
27
+ buyToken: z.ZodString;
28
+ amount: z.ZodString;
29
+ wallet: z.ZodString;
30
+ recipient: z.ZodOptional<z.ZodString>;
31
+ maxSlippageBps: z.ZodOptional<z.ZodNumber>;
32
+ }, z.core.$strict>;
33
+ declare const trackSwapInput: z.ZodObject<{
34
+ chainId: z.ZodOptional<z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>>;
35
+ txHash: z.ZodOptional<z.ZodString>;
36
+ requestId: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strict>;
38
+ declare const findTokenInput: z.ZodObject<{
39
+ chainId: z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>;
40
+ query: z.ZodString;
41
+ }, z.core.$strict>;
42
+ declare const getGasInput: z.ZodObject<{
43
+ payChainId: z.ZodOptional<z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>>;
44
+ chainId: z.ZodOptional<z.ZodLiteral<1 | 10 | 56 | 137 | 8453 | 42161>>;
45
+ recipient: z.ZodOptional<z.ZodString>;
46
+ amount: z.ZodOptional<z.ZodString>;
47
+ wallet: z.ZodOptional<z.ZodString>;
48
+ refundTo: z.ZodOptional<z.ZodString>;
49
+ offer: z.ZodOptional<z.ZodString>;
50
+ signature: z.ZodOptional<z.ZodString>;
51
+ }, z.core.$strict>;
52
+ type PlanSwapInput = z.infer<typeof planSwapInput>;
53
+ type TrackSwapInput = z.infer<typeof trackSwapInput>;
54
+ type FindTokenInput = z.infer<typeof findTokenInput>;
55
+ type GetGasInput = z.infer<typeof getGasInput>;
56
+
57
+ type CleaveTools = {
58
+ planSwap: Tool<PlanSwapInput, CleaveResult>;
59
+ trackSwap: Tool<TrackSwapInput, CleaveResult>;
60
+ findToken: Tool<FindTokenInput, CleaveResult>;
61
+ getGas: Tool<GetGasInput, CleaveResult>;
62
+ };
63
+ declare function planSwap(options?: CleaveToolsOptions): Tool<PlanSwapInput, CleaveResult>;
64
+ declare function trackSwap(options?: CleaveToolsOptions): Tool<TrackSwapInput, CleaveResult>;
65
+ declare function findToken(options?: CleaveToolsOptions): Tool<FindTokenInput, CleaveResult>;
66
+ declare function getGas(options?: CleaveToolsOptions): Tool<GetGasInput, CleaveResult>;
67
+ declare function cleaveTools(options?: CleaveToolsOptions): CleaveTools;
68
+
69
+ type CheckRule = "P1" | "P2" | "P3" | "P4" | "P5" | "P6" | "G1" | "G2" | "G3" | "G4";
70
+ type CheckResult = {
71
+ ok: true;
72
+ } | {
73
+ ok: false;
74
+ rule: CheckRule;
75
+ message: string;
76
+ };
77
+ declare function checkPlanSwap(request: PlanSwapInput, body: Record<string, unknown>): CheckResult;
78
+ declare function checkGetGas(request: GetGasInput, body: Record<string, unknown>, nowSec?: number): CheckResult;
79
+ declare function screenPlanSwap(request: PlanSwapInput, body: Record<string, unknown>): Record<string, unknown>;
80
+ declare function screenGetGas(request: GetGasInput, body: Record<string, unknown>, nowSec?: number): Record<string, unknown>;
81
+
82
+ export { CHAIN_IDS, CleaveApiError, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, checkGetGas, checkPlanSwap, cleaveTools, findToken, getGas, planSwap, screenGetGas, screenPlanSwap, trackSwap };
83
+ export type { CheckResult, CheckRule, CleaveResult, CleaveTools, CleaveToolsOptions, FindTokenInput, GetGasInput, PlanSwapInput, TrackSwapInput };