@stacknet/stacks 0.2.0 → 0.2.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.
Files changed (63) hide show
  1. package/README.md +136 -0
  2. package/dist/{billing-eQZIWeNW.d.cts → billing-cj0eSVrp.d.cts} +59 -1
  3. package/dist/{billing-eQZIWeNW.d.ts → billing-cj0eSVrp.d.ts} +59 -1
  4. package/dist/clients/index.cjs +4 -4
  5. package/dist/clients/index.d.cts +24 -1
  6. package/dist/clients/index.d.ts +24 -1
  7. package/dist/clients/index.js +4 -4
  8. package/dist/index.cjs +7 -7
  9. package/dist/index.d.cts +3 -3
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +7 -7
  12. package/dist/proxy/index.cjs +2 -2
  13. package/dist/proxy/index.js +2 -2
  14. package/dist/streaming/index.cjs +5 -5
  15. package/dist/streaming/index.js +5 -5
  16. package/dist/types/index.d.cts +1 -1
  17. package/dist/types/index.d.ts +1 -1
  18. package/package.json +15 -13
  19. package/src/clients/agents.ts +0 -250
  20. package/src/clients/billing.ts +0 -197
  21. package/src/clients/coder.ts +0 -655
  22. package/src/clients/files.ts +0 -86
  23. package/src/clients/index.ts +0 -93
  24. package/src/clients/magma.ts +0 -299
  25. package/src/clients/mcp.ts +0 -208
  26. package/src/clients/network.ts +0 -118
  27. package/src/clients/points.ts +0 -403
  28. package/src/clients/skills.ts +0 -236
  29. package/src/clients/social.ts +0 -286
  30. package/src/clients/stack-management.ts +0 -279
  31. package/src/clients/task-network.ts +0 -303
  32. package/src/clients/user.ts +0 -84
  33. package/src/clients/widgets.ts +0 -171
  34. package/src/index.ts +0 -387
  35. package/src/managers/index.ts +0 -10
  36. package/src/managers/task-manager.ts +0 -332
  37. package/src/proxy/forwarder.ts +0 -235
  38. package/src/proxy/index.ts +0 -32
  39. package/src/proxy/route-handlers.ts +0 -1107
  40. package/src/streaming/component-stream.ts +0 -319
  41. package/src/streaming/index.ts +0 -21
  42. package/src/streaming/sse.ts +0 -266
  43. package/src/types/agent.ts +0 -108
  44. package/src/types/billing.ts +0 -121
  45. package/src/types/chat.ts +0 -58
  46. package/src/types/coder.ts +0 -345
  47. package/src/types/credential.ts +0 -111
  48. package/src/types/file.ts +0 -15
  49. package/src/types/imagination.ts +0 -50
  50. package/src/types/index.ts +0 -20
  51. package/src/types/mcp.ts +0 -35
  52. package/src/types/network.ts +0 -97
  53. package/src/types/points.ts +0 -250
  54. package/src/types/skill.ts +0 -107
  55. package/src/types/social.ts +0 -109
  56. package/src/types/stack.ts +0 -269
  57. package/src/types/task.ts +0 -41
  58. package/src/types/user.ts +0 -29
  59. package/src/types/widget.ts +0 -57
  60. package/src/utils/constants.ts +0 -26
  61. package/src/utils/errors.ts +0 -169
  62. package/src/utils/helpers.ts +0 -85
  63. package/src/utils/index.ts +0 -7
@@ -1,269 +0,0 @@
1
- /**
2
- * Stack management type definitions
3
- * Types for stack CRUD, configuration, providers, capabilities, and allowlists
4
- */
5
-
6
- // ============================================================================
7
- // Stack Configuration
8
- // ============================================================================
9
-
10
- export interface StackConfig {
11
- id: string;
12
- name: string;
13
- displayName: string;
14
- description?: string;
15
- ownerId: string;
16
- allowedChains: string[];
17
- oauthProviders: StackOAuthProvider[];
18
- web3Providers?: StackWeb3Provider[];
19
- stripeProvider?: StackStripeProvider;
20
- webhookEndpoint?: string;
21
- allowedOrigins: string[];
22
- rateLimits?: { requestsPerMinute: number; requestsPerDay: number };
23
- features?: { web3Auth: boolean; oauthAuth: boolean; apiKeyAuth: boolean; billing: boolean };
24
- metadata?: Record<string, any>;
25
- modelAliases?: StackModelAlias[];
26
- logoCid?: string;
27
- logoUrl?: string;
28
- createdAt: number;
29
- updatedAt: number;
30
- isActive: boolean;
31
- capabilityBitmask?: number;
32
- }
33
-
34
- export interface CreateStackRequest {
35
- name: string;
36
- displayName: string;
37
- description?: string;
38
- allowedChains?: string[];
39
- allowedOrigins?: string[];
40
- }
41
-
42
- export interface StackResponse {
43
- stack: StackConfig;
44
- }
45
-
46
- export interface StackListResponse {
47
- stacks: StackConfig[];
48
- }
49
-
50
- // ============================================================================
51
- // Auth Providers
52
- // ============================================================================
53
-
54
- export interface StackOAuthProvider {
55
- provider: string;
56
- clientId: string;
57
- scopes: string[];
58
- redirectUri?: string;
59
- enabled: boolean;
60
- }
61
-
62
- export interface StackWeb3Provider {
63
- provider: 'siwe' | 'siws';
64
- domain: string;
65
- statement: string;
66
- chainId: string;
67
- expirationTime?: number;
68
- enabled: boolean;
69
- }
70
-
71
- export interface StackStripeProvider {
72
- provider: 'stripe';
73
- publishableKey: string;
74
- enabled: boolean;
75
- mode: 'test' | 'live';
76
- }
77
-
78
- /**
79
- * @server-only — Contains secrets. Only use from server-side code (API routes, server actions).
80
- * Never import or call from browser/client bundles.
81
- */
82
- export interface ConfigureOAuthInput {
83
- clientId: string;
84
- /** @secret OAuth client secret — never expose to the browser */
85
- clientSecret: string;
86
- scopes?: string[];
87
- redirectUri?: string;
88
- }
89
-
90
- export interface ConfigureWeb3Input {
91
- domain: string;
92
- statement: string;
93
- chainId: string;
94
- expirationTime?: number;
95
- }
96
-
97
- /**
98
- * @server-only — Contains secrets. Only use from server-side code (API routes, server actions).
99
- * Never import or call from browser/client bundles.
100
- */
101
- export interface ConfigureStripeInput {
102
- publishableKey: string;
103
- /** @secret Stripe secret key — never expose to the browser */
104
- secretKey: string;
105
- }
106
-
107
- // ============================================================================
108
- // Stack Keys
109
- // ============================================================================
110
-
111
- export interface StackKeyInfo {
112
- id: string;
113
- keyPrefix: string;
114
- name: string;
115
- permission: 'read' | 'write';
116
- lastUsedAt: number | null;
117
- createdAt: number;
118
- isRevoked: boolean;
119
- }
120
-
121
- export interface CreateKeyResponse {
122
- key: string;
123
- keyId: string;
124
- keyPrefix: string;
125
- }
126
-
127
- export interface StackKeysListResponse {
128
- keys: StackKeyInfo[];
129
- }
130
-
131
- // ============================================================================
132
- // Allowlist
133
- // ============================================================================
134
-
135
- export type AllowlistMode = 'global_fallback' | 'open' | 'explicit';
136
-
137
- export interface AllowlistConfig {
138
- solana: string[];
139
- evm: string[];
140
- solanaMode: AllowlistMode;
141
- evmMode: AllowlistMode;
142
- customSignInMessage: string | null;
143
- }
144
-
145
- export interface AllowlistUpdateInput {
146
- solana?: string[];
147
- evm?: string[];
148
- customSignInMessage?: string | null;
149
- }
150
-
151
- // ============================================================================
152
- // Model Layers
153
- // ============================================================================
154
-
155
- export interface StackModelAlias {
156
- layer: string;
157
- capability: string;
158
- alias: string;
159
- }
160
-
161
- export interface ModelLayerInfo {
162
- name: string;
163
- aliases: Array<{
164
- capability: string;
165
- alias: string;
166
- defaultAlias: string;
167
- modelId: string;
168
- }>;
169
- }
170
-
171
- export interface ModelLayersResponse {
172
- layers: ModelLayerInfo[];
173
- }
174
-
175
- // ============================================================================
176
- // Capabilities Bitmask
177
- // ============================================================================
178
-
179
- export const CAPABILITY_BITS = {
180
- text_input: 1 << 0,
181
- image_input: 1 << 1,
182
- file_input: 1 << 2,
183
- audio_input: 1 << 3,
184
- video_input: 1 << 4,
185
- music_input: 1 << 5,
186
- text_output: 1 << 6,
187
- image_output: 1 << 7,
188
- audio_output: 1 << 8,
189
- video_output: 1 << 9,
190
- embeddings_output: 1 << 10,
191
- music_output: 1 << 11,
192
- skills: 1 << 12,
193
- loops: 1 << 13,
194
- tools: 1 << 14,
195
- pipelines: 1 << 15,
196
- training: 1 << 16,
197
- } as const;
198
-
199
- export const ALL_CAPABILITIES_BITMASK = 0x1FFFF;
200
-
201
- export type CapabilityKey = keyof typeof CAPABILITY_BITS;
202
-
203
- export interface StackCapabilities {
204
- text_input: boolean;
205
- image_input: boolean;
206
- file_input: boolean;
207
- audio_input: boolean;
208
- video_input: boolean;
209
- music_input: boolean;
210
- text_output: boolean;
211
- image_output: boolean;
212
- audio_output: boolean;
213
- video_output: boolean;
214
- embeddings_output: boolean;
215
- music_output: boolean;
216
- skills: boolean;
217
- loops: boolean;
218
- tools: boolean;
219
- pipelines: boolean;
220
- training: boolean;
221
- }
222
-
223
- export function capabilitiesToBitmask(caps: StackCapabilities): number {
224
- let mask = 0;
225
- for (const [key, bit] of Object.entries(CAPABILITY_BITS)) {
226
- if (caps[key as CapabilityKey]) mask |= bit;
227
- }
228
- return mask;
229
- }
230
-
231
- export function bitmaskToCapabilities(mask: number): StackCapabilities {
232
- const caps = {} as StackCapabilities;
233
- for (const [key, bit] of Object.entries(CAPABILITY_BITS)) {
234
- caps[key as CapabilityKey] = (mask & bit) !== 0;
235
- }
236
- return caps;
237
- }
238
-
239
- // ============================================================================
240
- // Members
241
- // ============================================================================
242
-
243
- export interface StackMember {
244
- id: string;
245
- stack_id: string;
246
- user_id: string;
247
- role: 'admin' | 'user';
248
- auth_method?: string;
249
- display_name?: string;
250
- created_at: number;
251
- last_seen_at: number;
252
- }
253
-
254
- export interface StackMemberStats {
255
- total: number;
256
- admins: number;
257
- users: number;
258
- activeLastWeek: number;
259
- }
260
-
261
- // ============================================================================
262
- // Client Config
263
- // ============================================================================
264
-
265
- export interface StackManagementClientConfig {
266
- baseUrl?: string;
267
- /** JWT auth token for authenticated requests */
268
- authToken?: string;
269
- }
package/src/types/task.ts DELETED
@@ -1,41 +0,0 @@
1
- /**
2
- * Task-related type definitions
3
- */
4
-
5
- export type TaskType = 'video' | 'music' | 'image' | 'ai-prompt' | 'mcp-tool';
6
-
7
- export type TaskStatus = 'pending' | 'generating' | 'complete' | 'failed';
8
-
9
- export interface TaskState {
10
- id: string;
11
- chatId: string;
12
- messageId: string;
13
- type: TaskType;
14
- status: TaskStatus;
15
- progress: number;
16
- message: string;
17
- result?: string;
18
- error?: string;
19
- createdAt: number;
20
- updatedAt: number;
21
- }
22
-
23
- export interface TaskPayload {
24
- type: string;
25
- model?: string;
26
- prompt?: string;
27
- sessionId?: string;
28
- temperature?: number;
29
- maxTokens?: number;
30
- stream?: boolean;
31
- search?: boolean; // Enable/disable web search tools (default: true)
32
- noTools?: boolean; // Disable all tools
33
- [key: string]: unknown;
34
- }
35
-
36
- export interface TaskResponse {
37
- taskId: string;
38
- status: TaskStatus;
39
- result?: unknown;
40
- error?: string;
41
- }
package/src/types/user.ts DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * User type definitions
3
- */
4
-
5
- export interface UserProfile {
6
- mid: string;
7
- username: string;
8
- avatar_url: string | null;
9
- bio?: string | null;
10
- preferences?: string | null;
11
- created_at?: string;
12
- updated_at?: string;
13
- }
14
-
15
- export interface UserProfileUpdateInput {
16
- username?: string;
17
- avatar_url?: string | null;
18
- bio?: string | null;
19
- preferences?: string | null;
20
- }
21
-
22
- export interface UserProfileResponse {
23
- profile?: UserProfile;
24
- error?: string;
25
- }
26
-
27
- export interface UserClientConfig {
28
- baseUrl?: string;
29
- }
@@ -1,57 +0,0 @@
1
- /**
2
- * Widget type definitions
3
- */
4
-
5
- export interface Widget {
6
- id: string;
7
- name: string;
8
- description?: string;
9
- component_code: string;
10
- styles?: string;
11
- props_schema?: Record<string, unknown>;
12
- default_props?: Record<string, unknown>;
13
- scope?: 'public' | 'private';
14
- creator_mid?: string;
15
- created_at?: string;
16
- updated_at?: string;
17
- usage_count?: number;
18
- }
19
-
20
- export interface WidgetsListResponse {
21
- widgets: Widget[];
22
- }
23
-
24
- export interface WidgetResponse {
25
- widget?: Widget;
26
- id?: string;
27
- error?: string;
28
- }
29
-
30
- export interface WidgetCreateInput {
31
- name: string;
32
- description?: string;
33
- component_code: string;
34
- styles?: string;
35
- props_schema?: Record<string, unknown>;
36
- default_props?: Record<string, unknown>;
37
- scope?: 'public' | 'private';
38
- creator_mid?: string;
39
- }
40
-
41
- export interface WidgetUpdateInput {
42
- name?: string;
43
- description?: string;
44
- component_code?: string;
45
- styles?: string;
46
- props_schema?: Record<string, unknown>;
47
- default_props?: Record<string, unknown>;
48
- scope?: 'public' | 'private';
49
- }
50
-
51
- export interface WidgetSystemPromptResponse {
52
- prompt: string;
53
- }
54
-
55
- export interface WidgetsClientConfig {
56
- baseUrl?: string;
57
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * SDK Constants
3
- */
4
-
5
- export const DEFAULT_GLAYER_NETWORK_URL = 'https://stacknet.magma-rpc.com';
6
-
7
- /** @deprecated Use DEFAULT_GLAYER_NETWORK_URL */
8
- export const DEFAULT_TASK_NETWORK_URL = DEFAULT_GLAYER_NETWORK_URL;
9
-
10
- /** @deprecated Use DEFAULT_GLAYER_NETWORK_URL */
11
- export const DEFAULT_P2P_NETWORK_URL = DEFAULT_GLAYER_NETWORK_URL;
12
- export const DEFAULT_MAGMA_RPC_URL = 'http://geoff.magma-rpc.com';
13
-
14
- export const TASK_PREFIX = 'task:';
15
- export const CHAT_TASKS_PREFIX = 'chat:tasks:';
16
- export const TASK_TTL = 86400 * 7; // 7 days in seconds
17
-
18
- export const SSE_HEADERS = {
19
- 'Content-Type': 'text/event-stream',
20
- 'Cache-Control': 'no-cache',
21
- 'Connection': 'keep-alive',
22
- } as const;
23
-
24
- export const JSON_HEADERS = {
25
- 'Content-Type': 'application/json',
26
- } as const;
@@ -1,169 +0,0 @@
1
- /**
2
- * Error handling utilities for the Stacks SDK
3
- */
4
-
5
- export type ErrorType =
6
- | 'bad_request'
7
- | 'unauthorized'
8
- | 'forbidden'
9
- | 'not_found'
10
- | 'rate_limit'
11
- | 'payment_required'
12
- | 'offline'
13
- | 'internal';
14
-
15
- export type Surface =
16
- | 'chat'
17
- | 'auth'
18
- | 'api'
19
- | 'stream'
20
- | 'database'
21
- | 'history'
22
- | 'vote'
23
- | 'document'
24
- | 'suggestions'
25
- | 'task'
26
- | 'agent'
27
- | 'imagination';
28
-
29
- export type ErrorCode = `${ErrorType}:${Surface}`;
30
-
31
- export type ErrorVisibility = 'response' | 'log' | 'none';
32
-
33
- export const visibilityBySurface: Record<Surface, ErrorVisibility> = {
34
- database: 'log',
35
- chat: 'response',
36
- auth: 'response',
37
- stream: 'response',
38
- api: 'response',
39
- history: 'response',
40
- vote: 'response',
41
- document: 'response',
42
- suggestions: 'response',
43
- task: 'response',
44
- agent: 'response',
45
- imagination: 'response',
46
- };
47
-
48
- export class StacksSDKError extends Error {
49
- public type: ErrorType;
50
- public surface: Surface;
51
- public statusCode: number;
52
-
53
- constructor(errorCode: ErrorCode, cause?: string) {
54
- super();
55
-
56
- const [type, surface] = errorCode.split(':');
57
-
58
- this.type = type as ErrorType;
59
- this.cause = cause;
60
- this.surface = surface as Surface;
61
- this.message = getMessageByErrorCode(errorCode);
62
- this.statusCode = getStatusCodeByType(this.type);
63
- }
64
-
65
- public toJSON() {
66
- return {
67
- code: `${this.type}:${this.surface}`,
68
- message: this.message,
69
- cause: this.cause,
70
- statusCode: this.statusCode,
71
- };
72
- }
73
-
74
- public toResponse(): Response {
75
- const code: ErrorCode = `${this.type}:${this.surface}`;
76
- const visibility = visibilityBySurface[this.surface];
77
-
78
- const { message, cause, statusCode } = this;
79
-
80
- if (visibility === 'log') {
81
- console.error({ code, message, cause });
82
- return Response.json(
83
- { code: '', message: 'Something went wrong. Please try again later.' },
84
- { status: statusCode }
85
- );
86
- }
87
-
88
- return Response.json({ code, message, cause }, { status: statusCode });
89
- }
90
- }
91
-
92
- export function getMessageByErrorCode(errorCode: ErrorCode): string {
93
- if (errorCode.includes('database')) {
94
- return 'An error occurred while executing a database query.';
95
- }
96
-
97
- switch (errorCode) {
98
- case 'bad_request:api':
99
- return "The request couldn't be processed. Please check your input and try again.";
100
-
101
- case 'unauthorized:auth':
102
- return 'You need to sign in before continuing.';
103
- case 'unauthorized:api':
104
- return 'Your session has expired. Please sign in again.';
105
- case 'forbidden:auth':
106
- return 'Your account does not have access to this feature.';
107
-
108
- case 'rate_limit:chat':
109
- return 'You have exceeded your maximum number of messages for the day. Please try again later.';
110
- case 'not_found:chat':
111
- return 'The requested chat was not found.';
112
- case 'forbidden:chat':
113
- return 'This chat belongs to another user.';
114
- case 'unauthorized:chat':
115
- return 'You need to sign in to view this chat.';
116
- case 'offline:chat':
117
- return "We're having trouble sending your message. Please check your internet connection.";
118
-
119
- case 'not_found:task':
120
- return 'The requested task was not found.';
121
- case 'forbidden:task':
122
- return 'You do not have access to this task.';
123
-
124
- case 'not_found:agent':
125
- return 'The requested agent was not found.';
126
- case 'forbidden:agent':
127
- return 'You do not have access to this agent.';
128
-
129
- case 'not_found:imagination':
130
- return 'The requested imagination was not found.';
131
- case 'forbidden:imagination':
132
- return 'You do not have access to this imagination.';
133
-
134
- case 'not_found:document':
135
- return 'The requested document was not found.';
136
- case 'forbidden:document':
137
- return 'This document belongs to another user.';
138
- case 'unauthorized:document':
139
- return 'You need to sign in to view this document.';
140
- case 'bad_request:document':
141
- return 'The request to create or update the document was invalid.';
142
-
143
- default:
144
- return 'Something went wrong. Please try again later.';
145
- }
146
- }
147
-
148
- function getStatusCodeByType(type: ErrorType): number {
149
- switch (type) {
150
- case 'bad_request':
151
- return 400;
152
- case 'unauthorized':
153
- return 401;
154
- case 'payment_required':
155
- return 402;
156
- case 'forbidden':
157
- return 403;
158
- case 'not_found':
159
- return 404;
160
- case 'rate_limit':
161
- return 429;
162
- case 'offline':
163
- return 503;
164
- case 'internal':
165
- return 500;
166
- default:
167
- return 500;
168
- }
169
- }
@@ -1,85 +0,0 @@
1
- /**
2
- * Utility helper functions
3
- */
4
-
5
- /**
6
- * Generate a UUID v4
7
- */
8
- export function generateUUID(): string {
9
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
10
- const r = (Math.random() * 16) | 0;
11
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
12
- return v.toString(16);
13
- });
14
- }
15
-
16
- /**
17
- * Generate a CID-like hash from content
18
- */
19
- export async function generateCID(buffer: ArrayBuffer): Promise<string> {
20
- const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
21
- const hashArray = Array.from(new Uint8Array(hashBuffer));
22
- const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
23
- return `baf${hashHex.substring(0, 52)}`;
24
- }
25
-
26
- /**
27
- * Sleep for a specified duration
28
- */
29
- export function sleep(ms: number): Promise<void> {
30
- return new Promise((resolve) => setTimeout(resolve, ms));
31
- }
32
-
33
- /**
34
- * Retry a function with exponential backoff
35
- */
36
- export async function retry<T>(
37
- fn: () => Promise<T>,
38
- options: {
39
- maxAttempts?: number;
40
- initialDelay?: number;
41
- maxDelay?: number;
42
- backoffFactor?: number;
43
- } = {}
44
- ): Promise<T> {
45
- const {
46
- maxAttempts = 3,
47
- initialDelay = 1000,
48
- maxDelay = 30000,
49
- backoffFactor = 2,
50
- } = options;
51
-
52
- let lastError: Error | undefined;
53
- let delay = initialDelay;
54
-
55
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
56
- try {
57
- return await fn();
58
- } catch (error) {
59
- lastError = error as Error;
60
- if (attempt === maxAttempts) break;
61
-
62
- await sleep(delay);
63
- delay = Math.min(delay * backoffFactor, maxDelay);
64
- }
65
- }
66
-
67
- throw lastError;
68
- }
69
-
70
- /**
71
- * Parse SSE data line
72
- */
73
- export function parseSSELine(line: string): { event?: string; data?: string } | null {
74
- if (!line || line.startsWith(':')) return null;
75
-
76
- if (line.startsWith('event:')) {
77
- return { event: line.slice(6).trim() };
78
- }
79
-
80
- if (line.startsWith('data:')) {
81
- return { data: line.slice(5).trim() };
82
- }
83
-
84
- return null;
85
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * @stacknet/stacks - Utilities
3
- */
4
-
5
- export * from './errors';
6
- export * from './constants';
7
- export * from './helpers';