@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.
Files changed (53) hide show
  1. package/dist/{engine-CrlhH0nw.d.mts → engine-BeVuHpVx.d.mts} +163 -0
  2. package/dist/{engine-5ndtBaCr.d.ts → engine-DSc1Em4V.d.ts} +163 -0
  3. package/dist/hooks/index.d.mts +132 -3
  4. package/dist/hooks/index.d.ts +132 -3
  5. package/dist/hooks/index.js +351 -0
  6. package/dist/hooks/index.js.map +1 -1
  7. package/dist/hooks/index.mjs +345 -2
  8. package/dist/hooks/index.mjs.map +1 -1
  9. package/dist/index.d.mts +3 -3
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +352 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +345 -2
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/providers/index.d.mts +1 -1
  16. package/dist/providers/index.d.ts +1 -1
  17. package/dist/providers/index.js +98 -0
  18. package/dist/providers/index.js.map +1 -1
  19. package/dist/providers/index.mjs +98 -0
  20. package/dist/providers/index.mjs.map +1 -1
  21. package/dist/react-native.d.mts +140 -3
  22. package/dist/react-native.d.ts +140 -3
  23. package/dist/react-native.js +642 -0
  24. package/dist/react-native.js.map +1 -1
  25. package/dist/react-native.mjs +636 -1
  26. package/dist/react-native.mjs.map +1 -1
  27. package/dist/services/index.d.mts +99 -79
  28. package/dist/services/index.d.ts +99 -79
  29. package/dist/services/index.js +254 -0
  30. package/dist/services/index.js.map +1 -1
  31. package/dist/services/index.mjs +252 -1
  32. package/dist/services/index.mjs.map +1 -1
  33. package/dist/supabase-BT0c7q9e.d.mts +82 -0
  34. package/dist/supabase-BT0c7q9e.d.ts +82 -0
  35. package/package.json +5 -1
  36. package/src/components/OneSwapWidget.tsx +1 -1
  37. package/src/components/ai/OneChainSelector.tsx +183 -0
  38. package/src/components/ai/OneCycleSelector.tsx +187 -0
  39. package/src/components/ai/OnePairSelector.tsx +181 -0
  40. package/src/components/ai/OneTierSelector.tsx +187 -0
  41. package/src/components/ai/index.ts +17 -0
  42. package/src/components/index.ts +3 -0
  43. package/src/hooks/index.ts +20 -0
  44. package/src/hooks/useAITrading.ts +444 -0
  45. package/src/index.ts +20 -0
  46. package/src/react-native.ts +23 -0
  47. package/src/services/engine.ts +184 -0
  48. package/src/services/index.ts +16 -0
  49. package/src/services/usage.ts +249 -0
  50. package/.turbo/turbo-build.log +0 -0
  51. package/.turbo/turbo-type-check.log +0 -0
  52. package/tsconfig.json +0 -22
  53. package/tsup.config.ts +0 -25
@@ -28,3 +28,19 @@ export { SupabaseService, createSupabaseClient, getSupabaseClient } from './supa
28
28
 
29
29
  // ===== Price Service (fallback for offline/cache) =====
30
30
  export { PriceService, priceService } from './price';
31
+
32
+ // ===== Usage Tracking Service =====
33
+ export {
34
+ UsageService,
35
+ getUsageService,
36
+ createUsageService,
37
+ } from './usage';
38
+
39
+ export type {
40
+ UsageCategory,
41
+ DisplayCategory,
42
+ UsageRecord,
43
+ UsageSummary,
44
+ UsageActivity,
45
+ UsageResponse,
46
+ } from './usage';
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Usage Tracking Service
3
+ * Tracks AI usage for Personal Assistant and Trading Agent
4
+ */
5
+
6
+ import { getConfig } from '../config';
7
+
8
+ // Usage categories (internal)
9
+ export type UsageCategory =
10
+ | 'wallet'
11
+ | 'payment'
12
+ | 'exchange_onramper'
13
+ | 'exchange_swap'
14
+ | 'ai_thirdweb'
15
+ | 'ai_trading_engine';
16
+
17
+ // Display categories (client-facing)
18
+ export type DisplayCategory = 'personal_assistant' | 'trading_agent';
19
+
20
+ export interface UsageRecord {
21
+ userId: string;
22
+ category: UsageCategory;
23
+ action: string;
24
+ requestTokens?: number;
25
+ responseTokens?: number;
26
+ creditsUsed?: number;
27
+ metadata?: Record<string, any>;
28
+ }
29
+
30
+ export interface UsageSummary {
31
+ personal_assistant: {
32
+ requestCount: number;
33
+ totalTokens: number;
34
+ totalCredits: number;
35
+ };
36
+ trading_agent: {
37
+ requestCount: number;
38
+ totalTokens: number;
39
+ totalCredits: number;
40
+ };
41
+ }
42
+
43
+ export interface UsageActivity {
44
+ type: DisplayCategory;
45
+ action: string;
46
+ tokens: number;
47
+ credits: number;
48
+ timestamp: string;
49
+ }
50
+
51
+ export interface UsageResponse {
52
+ summary: UsageSummary;
53
+ dailyBreakdown: Array<{
54
+ date: string;
55
+ personal_assistant: number;
56
+ trading_agent: number;
57
+ }>;
58
+ recentActivity: UsageActivity[];
59
+ period: {
60
+ days: number;
61
+ startDate: string;
62
+ endDate: string;
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Usage Tracking Service
68
+ */
69
+ export class UsageService {
70
+ private baseUrl: string;
71
+ private userId: string | null = null;
72
+
73
+ constructor(baseUrl?: string) {
74
+ this.baseUrl = baseUrl || getConfig().oneEngineUrl || '';
75
+ }
76
+
77
+ /**
78
+ * Set the current user ID for tracking
79
+ */
80
+ setUserId(userId: string): void {
81
+ this.userId = userId;
82
+ }
83
+
84
+ /**
85
+ * Record Personal Assistant usage (Thirdweb AI)
86
+ */
87
+ async trackPersonalAssistant(
88
+ action: string,
89
+ tokens?: { request?: number; response?: number },
90
+ credits?: number,
91
+ metadata?: Record<string, any>
92
+ ): Promise<boolean> {
93
+ return this.recordUsage({
94
+ userId: this.userId!,
95
+ category: 'ai_thirdweb',
96
+ action,
97
+ requestTokens: tokens?.request,
98
+ responseTokens: tokens?.response,
99
+ creditsUsed: credits,
100
+ metadata,
101
+ });
102
+ }
103
+
104
+ /**
105
+ * Record Trading Agent usage (Engine AI)
106
+ */
107
+ async trackTradingAgent(
108
+ action: string,
109
+ credits?: number,
110
+ metadata?: Record<string, any>
111
+ ): Promise<boolean> {
112
+ return this.recordUsage({
113
+ userId: this.userId!,
114
+ category: 'ai_trading_engine',
115
+ action,
116
+ creditsUsed: credits,
117
+ metadata,
118
+ });
119
+ }
120
+
121
+ /**
122
+ * Record wallet operation usage
123
+ */
124
+ async trackWallet(action: string, metadata?: Record<string, any>): Promise<boolean> {
125
+ return this.recordUsage({
126
+ userId: this.userId!,
127
+ category: 'wallet',
128
+ action,
129
+ metadata,
130
+ });
131
+ }
132
+
133
+ /**
134
+ * Record payment usage
135
+ */
136
+ async trackPayment(action: string, metadata?: Record<string, any>): Promise<boolean> {
137
+ return this.recordUsage({
138
+ userId: this.userId!,
139
+ category: 'payment',
140
+ action,
141
+ metadata,
142
+ });
143
+ }
144
+
145
+ /**
146
+ * Record exchange usage (onramper)
147
+ */
148
+ async trackOnramper(action: string, metadata?: Record<string, any>): Promise<boolean> {
149
+ return this.recordUsage({
150
+ userId: this.userId!,
151
+ category: 'exchange_onramper',
152
+ action,
153
+ metadata,
154
+ });
155
+ }
156
+
157
+ /**
158
+ * Record exchange usage (swap)
159
+ */
160
+ async trackSwap(action: string, metadata?: Record<string, any>): Promise<boolean> {
161
+ return this.recordUsage({
162
+ userId: this.userId!,
163
+ category: 'exchange_swap',
164
+ action,
165
+ metadata,
166
+ });
167
+ }
168
+
169
+ /**
170
+ * Record any usage
171
+ */
172
+ async recordUsage(record: UsageRecord): Promise<boolean> {
173
+ if (!record.userId) {
174
+ console.warn('[UsageService] No userId set, skipping usage tracking');
175
+ return false;
176
+ }
177
+
178
+ try {
179
+ const response = await fetch(`${this.baseUrl}/api/v1/usage/user`, {
180
+ method: 'POST',
181
+ headers: {
182
+ 'Content-Type': 'application/json',
183
+ },
184
+ body: JSON.stringify({
185
+ userId: record.userId,
186
+ category: record.category,
187
+ action: record.action,
188
+ requestTokens: record.requestTokens || 0,
189
+ responseTokens: record.responseTokens || 0,
190
+ creditsUsed: record.creditsUsed || 0,
191
+ metadata: record.metadata || {},
192
+ }),
193
+ });
194
+
195
+ if (!response.ok) {
196
+ const error = await response.json().catch(() => ({}));
197
+ console.error('[UsageService] Failed to record usage:', error);
198
+ return false;
199
+ }
200
+
201
+ return true;
202
+ } catch (error) {
203
+ console.error('[UsageService] Error recording usage:', error);
204
+ return false;
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Get AI usage summary for current user
210
+ */
211
+ async getAIUsage(days: number = 30): Promise<UsageResponse | null> {
212
+ if (!this.userId) {
213
+ console.warn('[UsageService] No userId set');
214
+ return null;
215
+ }
216
+
217
+ try {
218
+ const response = await fetch(
219
+ `${this.baseUrl}/api/v1/usage/user?userId=${this.userId}&days=${days}`
220
+ );
221
+
222
+ if (!response.ok) {
223
+ const error = await response.json().catch(() => ({}));
224
+ console.error('[UsageService] Failed to get usage:', error);
225
+ return null;
226
+ }
227
+
228
+ const result = await response.json();
229
+ return result.data;
230
+ } catch (error) {
231
+ console.error('[UsageService] Error getting usage:', error);
232
+ return null;
233
+ }
234
+ }
235
+ }
236
+
237
+ // Singleton instance
238
+ let usageServiceInstance: UsageService | null = null;
239
+
240
+ export function getUsageService(): UsageService {
241
+ if (!usageServiceInstance) {
242
+ usageServiceInstance = new UsageService();
243
+ }
244
+ return usageServiceInstance;
245
+ }
246
+
247
+ export function createUsageService(baseUrl?: string): UsageService {
248
+ return new UsageService(baseUrl);
249
+ }
File without changes
File without changes
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "jsx": "react-jsx",
8
- "declaration": true,
9
- "declarationMap": true,
10
- "sourceMap": true,
11
- "outDir": "./dist",
12
- "rootDir": "./src",
13
- "strict": true,
14
- "esModuleInterop": true,
15
- "skipLibCheck": true,
16
- "forceConsistentCasingInFileNames": true,
17
- "resolveJsonModule": true,
18
- "isolatedModules": true
19
- },
20
- "include": ["src/**/*"],
21
- "exclude": ["node_modules", "dist"]
22
- }
package/tsup.config.ts DELETED
@@ -1,25 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entry: {
5
- index: 'src/index.ts',
6
- 'services/index': 'src/services/index.ts',
7
- 'types/index': 'src/types/index.ts',
8
- 'utils/index': 'src/utils/index.ts',
9
- 'config/index': 'src/config/index.ts',
10
- 'providers/index': 'src/providers/index.ts',
11
- 'hooks/index': 'src/hooks/index.ts',
12
- 'react-native': 'src/react-native.ts',
13
- },
14
- format: ['cjs', 'esm'],
15
- dts: true,
16
- splitting: false,
17
- sourcemap: true,
18
- clean: true,
19
- external: ['react', 'react-native', 'react-dom'],
20
- treeshake: true,
21
- minify: false,
22
- banner: {
23
- js: '"use client";',
24
- },
25
- });