@one_deploy/sdk 1.0.3 → 1.0.5
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/dist/{engine-CrlhH0nw.d.mts → engine-BeVuHpVx.d.mts} +163 -0
- package/dist/{engine-5ndtBaCr.d.ts → engine-DSc1Em4V.d.ts} +163 -0
- package/dist/hooks/index.d.mts +132 -3
- package/dist/hooks/index.d.ts +132 -3
- package/dist/hooks/index.js +351 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +345 -2
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +352 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +345 -2
- package/dist/index.mjs.map +1 -1
- package/dist/providers/index.d.mts +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +98 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +98 -0
- package/dist/providers/index.mjs.map +1 -1
- package/dist/react-native.d.mts +140 -3
- package/dist/react-native.d.ts +140 -3
- package/dist/react-native.js +642 -0
- package/dist/react-native.js.map +1 -1
- package/dist/react-native.mjs +636 -1
- package/dist/react-native.mjs.map +1 -1
- package/dist/services/index.d.mts +99 -79
- package/dist/services/index.d.ts +99 -79
- package/dist/services/index.js +254 -0
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +252 -1
- package/dist/services/index.mjs.map +1 -1
- package/dist/supabase-BT0c7q9e.d.mts +82 -0
- package/dist/supabase-BT0c7q9e.d.ts +82 -0
- package/package.json +5 -1
- package/src/components/OneSwapWidget.tsx +1 -1
- package/src/components/ai/OneChainSelector.tsx +183 -0
- package/src/components/ai/OneCycleSelector.tsx +187 -0
- package/src/components/ai/OnePairSelector.tsx +181 -0
- package/src/components/ai/OneTierSelector.tsx +187 -0
- package/src/components/ai/index.ts +17 -0
- package/src/components/index.ts +3 -0
- package/src/hooks/index.ts +20 -0
- package/src/hooks/useAITrading.ts +444 -0
- package/src/index.ts +20 -0
- package/src/react-native.ts +23 -0
- package/src/services/engine.ts +184 -0
- package/src/services/index.ts +16 -0
- package/src/services/usage.ts +249 -0
- package/.turbo/turbo-build.log +0 -0
- package/.turbo/turbo-type-check.log +0 -0
- package/tsconfig.json +0 -22
- package/tsup.config.ts +0 -25
|
@@ -1,85 +1,105 @@
|
|
|
1
|
-
export { E as EngineAuthResponse, b as EngineTransactionRequest, d as EngineTransactionResponse, a as EngineWalletBalance, O as OneEngineClient, g as OnrampQuote, f as OnrampSession, e as OnrampSessionRequest, h as OnrampTransaction, j as SwapExecuteRequest, i as SwapQuote, S as SwapQuoteRequest, k as SwapResult, c as createOneEngineClient } from '../engine-
|
|
2
|
-
|
|
3
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
1
|
+
export { E as EngineAuthResponse, b as EngineTransactionRequest, d as EngineTransactionResponse, a as EngineWalletBalance, O as OneEngineClient, g as OnrampQuote, f as OnrampSession, e as OnrampSessionRequest, h as OnrampTransaction, j as SwapExecuteRequest, i as SwapQuote, S as SwapQuoteRequest, k as SwapResult, c as createOneEngineClient } from '../engine-BeVuHpVx.mjs';
|
|
2
|
+
export { S as SupabaseService, c as createSupabaseClient, g as getSupabaseClient } from '../supabase-BT0c7q9e.mjs';
|
|
4
3
|
export { P as PriceService, p as priceService } from '../price-ClbLHHjv.mjs';
|
|
5
4
|
import '../types/index.mjs';
|
|
5
|
+
import '@supabase/supabase-js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
48
|
-
}>;
|
|
49
|
-
updateUserProfile(userId: string, updates: Record<string, any>): Promise<{
|
|
50
|
-
data: any;
|
|
51
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
52
|
-
}>;
|
|
53
|
-
getTransactions(userId: string, limit?: number): Promise<{
|
|
54
|
-
data: any[] | null;
|
|
55
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
56
|
-
}>;
|
|
57
|
-
createTransaction(transaction: Record<string, any>): Promise<{
|
|
58
|
-
data: any;
|
|
59
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
60
|
-
}>;
|
|
61
|
-
getStrategies(status?: string): Promise<{
|
|
62
|
-
data: any[] | null;
|
|
63
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
64
|
-
}>;
|
|
65
|
-
getStrategyById(strategyId: string): Promise<{
|
|
66
|
-
data: any;
|
|
67
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
68
|
-
}>;
|
|
69
|
-
getUserOrders(userId: string): Promise<{
|
|
70
|
-
data: any[] | null;
|
|
71
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
72
|
-
}>;
|
|
73
|
-
createOrder(order: Record<string, any>): Promise<{
|
|
74
|
-
data: any;
|
|
75
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
76
|
-
}>;
|
|
77
|
-
getUserCards(userId: string): Promise<{
|
|
78
|
-
data: any[] | null;
|
|
79
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
7
|
+
/**
|
|
8
|
+
* Usage Tracking Service
|
|
9
|
+
* Tracks AI usage for Personal Assistant and Trading Agent
|
|
10
|
+
*/
|
|
11
|
+
type UsageCategory = 'wallet' | 'payment' | 'exchange_onramper' | 'exchange_swap' | 'ai_thirdweb' | 'ai_trading_engine';
|
|
12
|
+
type DisplayCategory = 'personal_assistant' | 'trading_agent';
|
|
13
|
+
interface UsageRecord {
|
|
14
|
+
userId: string;
|
|
15
|
+
category: UsageCategory;
|
|
16
|
+
action: string;
|
|
17
|
+
requestTokens?: number;
|
|
18
|
+
responseTokens?: number;
|
|
19
|
+
creditsUsed?: number;
|
|
20
|
+
metadata?: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
interface UsageSummary {
|
|
23
|
+
personal_assistant: {
|
|
24
|
+
requestCount: number;
|
|
25
|
+
totalTokens: number;
|
|
26
|
+
totalCredits: number;
|
|
27
|
+
};
|
|
28
|
+
trading_agent: {
|
|
29
|
+
requestCount: number;
|
|
30
|
+
totalTokens: number;
|
|
31
|
+
totalCredits: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface UsageActivity {
|
|
35
|
+
type: DisplayCategory;
|
|
36
|
+
action: string;
|
|
37
|
+
tokens: number;
|
|
38
|
+
credits: number;
|
|
39
|
+
timestamp: string;
|
|
40
|
+
}
|
|
41
|
+
interface UsageResponse {
|
|
42
|
+
summary: UsageSummary;
|
|
43
|
+
dailyBreakdown: Array<{
|
|
44
|
+
date: string;
|
|
45
|
+
personal_assistant: number;
|
|
46
|
+
trading_agent: number;
|
|
80
47
|
}>;
|
|
81
|
-
|
|
82
|
-
|
|
48
|
+
recentActivity: UsageActivity[];
|
|
49
|
+
period: {
|
|
50
|
+
days: number;
|
|
51
|
+
startDate: string;
|
|
52
|
+
endDate: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Usage Tracking Service
|
|
57
|
+
*/
|
|
58
|
+
declare class UsageService {
|
|
59
|
+
private baseUrl;
|
|
60
|
+
private userId;
|
|
61
|
+
constructor(baseUrl?: string);
|
|
62
|
+
/**
|
|
63
|
+
* Set the current user ID for tracking
|
|
64
|
+
*/
|
|
65
|
+
setUserId(userId: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Record Personal Assistant usage (Thirdweb AI)
|
|
68
|
+
*/
|
|
69
|
+
trackPersonalAssistant(action: string, tokens?: {
|
|
70
|
+
request?: number;
|
|
71
|
+
response?: number;
|
|
72
|
+
}, credits?: number, metadata?: Record<string, any>): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Record Trading Agent usage (Engine AI)
|
|
75
|
+
*/
|
|
76
|
+
trackTradingAgent(action: string, credits?: number, metadata?: Record<string, any>): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Record wallet operation usage
|
|
79
|
+
*/
|
|
80
|
+
trackWallet(action: string, metadata?: Record<string, any>): Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* Record payment usage
|
|
83
|
+
*/
|
|
84
|
+
trackPayment(action: string, metadata?: Record<string, any>): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Record exchange usage (onramper)
|
|
87
|
+
*/
|
|
88
|
+
trackOnramper(action: string, metadata?: Record<string, any>): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Record exchange usage (swap)
|
|
91
|
+
*/
|
|
92
|
+
trackSwap(action: string, metadata?: Record<string, any>): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Record any usage
|
|
95
|
+
*/
|
|
96
|
+
recordUsage(record: UsageRecord): Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Get AI usage summary for current user
|
|
99
|
+
*/
|
|
100
|
+
getAIUsage(days?: number): Promise<UsageResponse | null>;
|
|
83
101
|
}
|
|
102
|
+
declare function getUsageService(): UsageService;
|
|
103
|
+
declare function createUsageService(baseUrl?: string): UsageService;
|
|
84
104
|
|
|
85
|
-
export {
|
|
105
|
+
export { type DisplayCategory, type UsageActivity, type UsageCategory, type UsageRecord, type UsageResponse, UsageService, type UsageSummary, createUsageService, getUsageService };
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,85 +1,105 @@
|
|
|
1
|
-
export { E as EngineAuthResponse, b as EngineTransactionRequest, d as EngineTransactionResponse, a as EngineWalletBalance, O as OneEngineClient, g as OnrampQuote, f as OnrampSession, e as OnrampSessionRequest, h as OnrampTransaction, j as SwapExecuteRequest, i as SwapQuote, S as SwapQuoteRequest, k as SwapResult, c as createOneEngineClient } from '../engine-
|
|
2
|
-
|
|
3
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
1
|
+
export { E as EngineAuthResponse, b as EngineTransactionRequest, d as EngineTransactionResponse, a as EngineWalletBalance, O as OneEngineClient, g as OnrampQuote, f as OnrampSession, e as OnrampSessionRequest, h as OnrampTransaction, j as SwapExecuteRequest, i as SwapQuote, S as SwapQuoteRequest, k as SwapResult, c as createOneEngineClient } from '../engine-DSc1Em4V.js';
|
|
2
|
+
export { S as SupabaseService, c as createSupabaseClient, g as getSupabaseClient } from '../supabase-BT0c7q9e.js';
|
|
4
3
|
export { P as PriceService, p as priceService } from '../price-CgqXPnT3.js';
|
|
5
4
|
import '../types/index.js';
|
|
5
|
+
import '@supabase/supabase-js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
48
|
-
}>;
|
|
49
|
-
updateUserProfile(userId: string, updates: Record<string, any>): Promise<{
|
|
50
|
-
data: any;
|
|
51
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
52
|
-
}>;
|
|
53
|
-
getTransactions(userId: string, limit?: number): Promise<{
|
|
54
|
-
data: any[] | null;
|
|
55
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
56
|
-
}>;
|
|
57
|
-
createTransaction(transaction: Record<string, any>): Promise<{
|
|
58
|
-
data: any;
|
|
59
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
60
|
-
}>;
|
|
61
|
-
getStrategies(status?: string): Promise<{
|
|
62
|
-
data: any[] | null;
|
|
63
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
64
|
-
}>;
|
|
65
|
-
getStrategyById(strategyId: string): Promise<{
|
|
66
|
-
data: any;
|
|
67
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
68
|
-
}>;
|
|
69
|
-
getUserOrders(userId: string): Promise<{
|
|
70
|
-
data: any[] | null;
|
|
71
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
72
|
-
}>;
|
|
73
|
-
createOrder(order: Record<string, any>): Promise<{
|
|
74
|
-
data: any;
|
|
75
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
76
|
-
}>;
|
|
77
|
-
getUserCards(userId: string): Promise<{
|
|
78
|
-
data: any[] | null;
|
|
79
|
-
error: _supabase_supabase_js.PostgrestError | null;
|
|
7
|
+
/**
|
|
8
|
+
* Usage Tracking Service
|
|
9
|
+
* Tracks AI usage for Personal Assistant and Trading Agent
|
|
10
|
+
*/
|
|
11
|
+
type UsageCategory = 'wallet' | 'payment' | 'exchange_onramper' | 'exchange_swap' | 'ai_thirdweb' | 'ai_trading_engine';
|
|
12
|
+
type DisplayCategory = 'personal_assistant' | 'trading_agent';
|
|
13
|
+
interface UsageRecord {
|
|
14
|
+
userId: string;
|
|
15
|
+
category: UsageCategory;
|
|
16
|
+
action: string;
|
|
17
|
+
requestTokens?: number;
|
|
18
|
+
responseTokens?: number;
|
|
19
|
+
creditsUsed?: number;
|
|
20
|
+
metadata?: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
interface UsageSummary {
|
|
23
|
+
personal_assistant: {
|
|
24
|
+
requestCount: number;
|
|
25
|
+
totalTokens: number;
|
|
26
|
+
totalCredits: number;
|
|
27
|
+
};
|
|
28
|
+
trading_agent: {
|
|
29
|
+
requestCount: number;
|
|
30
|
+
totalTokens: number;
|
|
31
|
+
totalCredits: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface UsageActivity {
|
|
35
|
+
type: DisplayCategory;
|
|
36
|
+
action: string;
|
|
37
|
+
tokens: number;
|
|
38
|
+
credits: number;
|
|
39
|
+
timestamp: string;
|
|
40
|
+
}
|
|
41
|
+
interface UsageResponse {
|
|
42
|
+
summary: UsageSummary;
|
|
43
|
+
dailyBreakdown: Array<{
|
|
44
|
+
date: string;
|
|
45
|
+
personal_assistant: number;
|
|
46
|
+
trading_agent: number;
|
|
80
47
|
}>;
|
|
81
|
-
|
|
82
|
-
|
|
48
|
+
recentActivity: UsageActivity[];
|
|
49
|
+
period: {
|
|
50
|
+
days: number;
|
|
51
|
+
startDate: string;
|
|
52
|
+
endDate: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Usage Tracking Service
|
|
57
|
+
*/
|
|
58
|
+
declare class UsageService {
|
|
59
|
+
private baseUrl;
|
|
60
|
+
private userId;
|
|
61
|
+
constructor(baseUrl?: string);
|
|
62
|
+
/**
|
|
63
|
+
* Set the current user ID for tracking
|
|
64
|
+
*/
|
|
65
|
+
setUserId(userId: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Record Personal Assistant usage (Thirdweb AI)
|
|
68
|
+
*/
|
|
69
|
+
trackPersonalAssistant(action: string, tokens?: {
|
|
70
|
+
request?: number;
|
|
71
|
+
response?: number;
|
|
72
|
+
}, credits?: number, metadata?: Record<string, any>): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Record Trading Agent usage (Engine AI)
|
|
75
|
+
*/
|
|
76
|
+
trackTradingAgent(action: string, credits?: number, metadata?: Record<string, any>): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Record wallet operation usage
|
|
79
|
+
*/
|
|
80
|
+
trackWallet(action: string, metadata?: Record<string, any>): Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* Record payment usage
|
|
83
|
+
*/
|
|
84
|
+
trackPayment(action: string, metadata?: Record<string, any>): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Record exchange usage (onramper)
|
|
87
|
+
*/
|
|
88
|
+
trackOnramper(action: string, metadata?: Record<string, any>): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Record exchange usage (swap)
|
|
91
|
+
*/
|
|
92
|
+
trackSwap(action: string, metadata?: Record<string, any>): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Record any usage
|
|
95
|
+
*/
|
|
96
|
+
recordUsage(record: UsageRecord): Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Get AI usage summary for current user
|
|
99
|
+
*/
|
|
100
|
+
getAIUsage(days?: number): Promise<UsageResponse | null>;
|
|
83
101
|
}
|
|
102
|
+
declare function getUsageService(): UsageService;
|
|
103
|
+
declare function createUsageService(baseUrl?: string): UsageService;
|
|
84
104
|
|
|
85
|
-
export {
|
|
105
|
+
export { type DisplayCategory, type UsageActivity, type UsageCategory, type UsageRecord, type UsageResponse, UsageService, type UsageSummary, createUsageService, getUsageService };
|
package/dist/services/index.js
CHANGED
|
@@ -1065,6 +1065,43 @@ var OneEngineClient = class {
|
|
|
1065
1065
|
async adminClearRateLimits(identifier) {
|
|
1066
1066
|
return this.request(`/api/v1/admin/rate-limits/${identifier}`, { method: "DELETE" });
|
|
1067
1067
|
}
|
|
1068
|
+
// ========== AI Agent Configuration ==========
|
|
1069
|
+
/**
|
|
1070
|
+
* Get all AI agent configurations
|
|
1071
|
+
* This returns the full agent setup including tiers, cycles, and trading parameters
|
|
1072
|
+
*/
|
|
1073
|
+
async getAgentConfigs(options) {
|
|
1074
|
+
const params = new URLSearchParams();
|
|
1075
|
+
if (options?.includeInactive) params.set("includeInactive", "true");
|
|
1076
|
+
if (options?.agentId) params.set("agentId", options.agentId);
|
|
1077
|
+
const query = params.toString();
|
|
1078
|
+
return this.request(`/api/v1/agents${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Calculate subscription parameters for an agent
|
|
1082
|
+
*/
|
|
1083
|
+
async calculateAgentParams(params) {
|
|
1084
|
+
return this.request("/api/v1/agents/calculate", {
|
|
1085
|
+
method: "POST",
|
|
1086
|
+
body: JSON.stringify(params)
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Get supported trading pairs from agents
|
|
1091
|
+
*/
|
|
1092
|
+
async getTradingPairs() {
|
|
1093
|
+
const result = await this.getAgentConfigs();
|
|
1094
|
+
if (result.success && result.data?.agents) {
|
|
1095
|
+
const allPairs = /* @__PURE__ */ new Set();
|
|
1096
|
+
const byAgent = {};
|
|
1097
|
+
for (const agent of result.data.agents) {
|
|
1098
|
+
byAgent[agent.id] = agent.supported_pairs;
|
|
1099
|
+
agent.supported_pairs.forEach((p) => allPairs.add(p));
|
|
1100
|
+
}
|
|
1101
|
+
return { success: true, data: { pairs: Array.from(allPairs), byAgent } };
|
|
1102
|
+
}
|
|
1103
|
+
return { success: false, error: result.error };
|
|
1104
|
+
}
|
|
1068
1105
|
// ========== AI Quant Trading ==========
|
|
1069
1106
|
/**
|
|
1070
1107
|
* Get all AI trading strategies
|
|
@@ -1203,6 +1240,67 @@ var OneEngineClient = class {
|
|
|
1203
1240
|
async getCryptoMarketOverview() {
|
|
1204
1241
|
return this.request("/api/v1/prices?type=overview", { method: "GET" });
|
|
1205
1242
|
}
|
|
1243
|
+
// ========== Project Management ==========
|
|
1244
|
+
/**
|
|
1245
|
+
* Get user's projects
|
|
1246
|
+
*/
|
|
1247
|
+
async getProjects(options) {
|
|
1248
|
+
const params = new URLSearchParams();
|
|
1249
|
+
if (options?.isActive !== void 0) params.set("isActive", String(options.isActive));
|
|
1250
|
+
const query = params.toString();
|
|
1251
|
+
return this.request(`/api/v1/projects${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Create a new project for ecosystem partners
|
|
1255
|
+
*/
|
|
1256
|
+
async createProject(params) {
|
|
1257
|
+
return this.request("/api/v1/projects", {
|
|
1258
|
+
method: "POST",
|
|
1259
|
+
body: JSON.stringify(params)
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Get project details
|
|
1264
|
+
*/
|
|
1265
|
+
async getProject(projectId) {
|
|
1266
|
+
return this.request(`/api/v1/projects/${projectId}`, { method: "GET" });
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Update project settings
|
|
1270
|
+
*/
|
|
1271
|
+
async updateProject(projectId, updates) {
|
|
1272
|
+
return this.request(`/api/v1/projects/${projectId}`, {
|
|
1273
|
+
method: "PATCH",
|
|
1274
|
+
body: JSON.stringify(updates)
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Get project features status
|
|
1279
|
+
*/
|
|
1280
|
+
async getProjectFeatures(projectId) {
|
|
1281
|
+
return this.request(`/api/v1/projects/${projectId}/features`, { method: "GET" });
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Enable/disable features for a project
|
|
1285
|
+
*/
|
|
1286
|
+
async updateProjectFeatures(projectId, features) {
|
|
1287
|
+
return this.request(`/api/v1/projects/${projectId}/features`, {
|
|
1288
|
+
method: "PATCH",
|
|
1289
|
+
body: JSON.stringify(features)
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Regenerate project API key
|
|
1294
|
+
*/
|
|
1295
|
+
async regenerateProjectApiKey(projectId) {
|
|
1296
|
+
return this.request(`/api/v1/projects/${projectId}/api-key`, { method: "POST" });
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Delete project
|
|
1300
|
+
*/
|
|
1301
|
+
async deleteProject(projectId) {
|
|
1302
|
+
return this.request(`/api/v1/projects/${projectId}`, { method: "DELETE" });
|
|
1303
|
+
}
|
|
1206
1304
|
};
|
|
1207
1305
|
function createOneEngineClient(options) {
|
|
1208
1306
|
return new OneEngineClient(options);
|
|
@@ -1455,12 +1553,168 @@ var PriceService = class {
|
|
|
1455
1553
|
};
|
|
1456
1554
|
var priceService = new PriceService();
|
|
1457
1555
|
|
|
1556
|
+
// src/services/usage.ts
|
|
1557
|
+
var UsageService = class {
|
|
1558
|
+
constructor(baseUrl) {
|
|
1559
|
+
this.userId = null;
|
|
1560
|
+
this.baseUrl = baseUrl || getConfig().oneEngineUrl || "";
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Set the current user ID for tracking
|
|
1564
|
+
*/
|
|
1565
|
+
setUserId(userId) {
|
|
1566
|
+
this.userId = userId;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Record Personal Assistant usage (Thirdweb AI)
|
|
1570
|
+
*/
|
|
1571
|
+
async trackPersonalAssistant(action, tokens, credits, metadata) {
|
|
1572
|
+
return this.recordUsage({
|
|
1573
|
+
userId: this.userId,
|
|
1574
|
+
category: "ai_thirdweb",
|
|
1575
|
+
action,
|
|
1576
|
+
requestTokens: tokens?.request,
|
|
1577
|
+
responseTokens: tokens?.response,
|
|
1578
|
+
creditsUsed: credits,
|
|
1579
|
+
metadata
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Record Trading Agent usage (Engine AI)
|
|
1584
|
+
*/
|
|
1585
|
+
async trackTradingAgent(action, credits, metadata) {
|
|
1586
|
+
return this.recordUsage({
|
|
1587
|
+
userId: this.userId,
|
|
1588
|
+
category: "ai_trading_engine",
|
|
1589
|
+
action,
|
|
1590
|
+
creditsUsed: credits,
|
|
1591
|
+
metadata
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Record wallet operation usage
|
|
1596
|
+
*/
|
|
1597
|
+
async trackWallet(action, metadata) {
|
|
1598
|
+
return this.recordUsage({
|
|
1599
|
+
userId: this.userId,
|
|
1600
|
+
category: "wallet",
|
|
1601
|
+
action,
|
|
1602
|
+
metadata
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Record payment usage
|
|
1607
|
+
*/
|
|
1608
|
+
async trackPayment(action, metadata) {
|
|
1609
|
+
return this.recordUsage({
|
|
1610
|
+
userId: this.userId,
|
|
1611
|
+
category: "payment",
|
|
1612
|
+
action,
|
|
1613
|
+
metadata
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Record exchange usage (onramper)
|
|
1618
|
+
*/
|
|
1619
|
+
async trackOnramper(action, metadata) {
|
|
1620
|
+
return this.recordUsage({
|
|
1621
|
+
userId: this.userId,
|
|
1622
|
+
category: "exchange_onramper",
|
|
1623
|
+
action,
|
|
1624
|
+
metadata
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Record exchange usage (swap)
|
|
1629
|
+
*/
|
|
1630
|
+
async trackSwap(action, metadata) {
|
|
1631
|
+
return this.recordUsage({
|
|
1632
|
+
userId: this.userId,
|
|
1633
|
+
category: "exchange_swap",
|
|
1634
|
+
action,
|
|
1635
|
+
metadata
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Record any usage
|
|
1640
|
+
*/
|
|
1641
|
+
async recordUsage(record) {
|
|
1642
|
+
if (!record.userId) {
|
|
1643
|
+
console.warn("[UsageService] No userId set, skipping usage tracking");
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
try {
|
|
1647
|
+
const response = await fetch(`${this.baseUrl}/api/v1/usage/user`, {
|
|
1648
|
+
method: "POST",
|
|
1649
|
+
headers: {
|
|
1650
|
+
"Content-Type": "application/json"
|
|
1651
|
+
},
|
|
1652
|
+
body: JSON.stringify({
|
|
1653
|
+
userId: record.userId,
|
|
1654
|
+
category: record.category,
|
|
1655
|
+
action: record.action,
|
|
1656
|
+
requestTokens: record.requestTokens || 0,
|
|
1657
|
+
responseTokens: record.responseTokens || 0,
|
|
1658
|
+
creditsUsed: record.creditsUsed || 0,
|
|
1659
|
+
metadata: record.metadata || {}
|
|
1660
|
+
})
|
|
1661
|
+
});
|
|
1662
|
+
if (!response.ok) {
|
|
1663
|
+
const error = await response.json().catch(() => ({}));
|
|
1664
|
+
console.error("[UsageService] Failed to record usage:", error);
|
|
1665
|
+
return false;
|
|
1666
|
+
}
|
|
1667
|
+
return true;
|
|
1668
|
+
} catch (error) {
|
|
1669
|
+
console.error("[UsageService] Error recording usage:", error);
|
|
1670
|
+
return false;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Get AI usage summary for current user
|
|
1675
|
+
*/
|
|
1676
|
+
async getAIUsage(days = 30) {
|
|
1677
|
+
if (!this.userId) {
|
|
1678
|
+
console.warn("[UsageService] No userId set");
|
|
1679
|
+
return null;
|
|
1680
|
+
}
|
|
1681
|
+
try {
|
|
1682
|
+
const response = await fetch(
|
|
1683
|
+
`${this.baseUrl}/api/v1/usage/user?userId=${this.userId}&days=${days}`
|
|
1684
|
+
);
|
|
1685
|
+
if (!response.ok) {
|
|
1686
|
+
const error = await response.json().catch(() => ({}));
|
|
1687
|
+
console.error("[UsageService] Failed to get usage:", error);
|
|
1688
|
+
return null;
|
|
1689
|
+
}
|
|
1690
|
+
const result = await response.json();
|
|
1691
|
+
return result.data;
|
|
1692
|
+
} catch (error) {
|
|
1693
|
+
console.error("[UsageService] Error getting usage:", error);
|
|
1694
|
+
return null;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
var usageServiceInstance = null;
|
|
1699
|
+
function getUsageService() {
|
|
1700
|
+
if (!usageServiceInstance) {
|
|
1701
|
+
usageServiceInstance = new UsageService();
|
|
1702
|
+
}
|
|
1703
|
+
return usageServiceInstance;
|
|
1704
|
+
}
|
|
1705
|
+
function createUsageService(baseUrl) {
|
|
1706
|
+
return new UsageService(baseUrl);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1458
1709
|
exports.OneEngineClient = OneEngineClient;
|
|
1459
1710
|
exports.PriceService = PriceService;
|
|
1460
1711
|
exports.SupabaseService = SupabaseService;
|
|
1712
|
+
exports.UsageService = UsageService;
|
|
1461
1713
|
exports.createOneEngineClient = createOneEngineClient;
|
|
1462
1714
|
exports.createSupabaseClient = createSupabaseClient;
|
|
1715
|
+
exports.createUsageService = createUsageService;
|
|
1463
1716
|
exports.getSupabaseClient = getSupabaseClient;
|
|
1717
|
+
exports.getUsageService = getUsageService;
|
|
1464
1718
|
exports.priceService = priceService;
|
|
1465
1719
|
//# sourceMappingURL=index.js.map
|
|
1466
1720
|
//# sourceMappingURL=index.js.map
|