@arinova-ai/spaces-sdk 0.1.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/README.md +94 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +242 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +20 -0
- package/src/index.ts +286 -0
- package/src/types.ts +97 -0
- package/tsconfig.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @arinova-ai/spaces-sdk
|
|
2
|
+
|
|
3
|
+
Official SDK for integrating external games with the Arinova platform.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @arinova-ai/spaces-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### 1. Initialize
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { Arinova } from "@arinova-ai/spaces-sdk";
|
|
17
|
+
|
|
18
|
+
Arinova.init({
|
|
19
|
+
appId: "your-client-id",
|
|
20
|
+
baseUrl: "https://api.arinova.ai", // optional, defaults to production
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. Login (Frontend)
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
// Redirect to Arinova login
|
|
28
|
+
Arinova.login({ scope: ["profile", "agents"] });
|
|
29
|
+
|
|
30
|
+
// Handle callback (on your redirect page)
|
|
31
|
+
const { user, accessToken } = await Arinova.handleCallback({
|
|
32
|
+
code: urlParams.get("code"),
|
|
33
|
+
clientId: "your-client-id",
|
|
34
|
+
clientSecret: "your-client-secret",
|
|
35
|
+
redirectUri: window.location.origin + "/callback",
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 3. Use Agent API
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// Get user's agents
|
|
43
|
+
const agents = await Arinova.user.agents(accessToken);
|
|
44
|
+
|
|
45
|
+
// Chat with agent (sync)
|
|
46
|
+
const { response } = await Arinova.agent.chat({
|
|
47
|
+
agentId: agents[0].id,
|
|
48
|
+
prompt: "Your board state...",
|
|
49
|
+
accessToken,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Chat with agent (streaming)
|
|
53
|
+
const result = await Arinova.agent.chatStream({
|
|
54
|
+
agentId: agents[0].id,
|
|
55
|
+
prompt: "Your move?",
|
|
56
|
+
accessToken,
|
|
57
|
+
onChunk: (chunk) => console.log("Streaming:", chunk),
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 4. Economy (Server-to-Server)
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Charge coins
|
|
65
|
+
const { newBalance } = await Arinova.economy.charge({
|
|
66
|
+
userId: "user-id",
|
|
67
|
+
amount: 10,
|
|
68
|
+
description: "Game entry fee",
|
|
69
|
+
clientId: "your-client-id",
|
|
70
|
+
clientSecret: "your-client-secret",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Award coins
|
|
74
|
+
const { newBalance, platformFee } = await Arinova.economy.award({
|
|
75
|
+
userId: "user-id",
|
|
76
|
+
amount: 20,
|
|
77
|
+
description: "Game prize",
|
|
78
|
+
clientId: "your-client-id",
|
|
79
|
+
clientSecret: "your-client-secret",
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## API Reference
|
|
84
|
+
|
|
85
|
+
### `Arinova.init(config)`
|
|
86
|
+
### `Arinova.login(options?)`
|
|
87
|
+
### `Arinova.handleCallback(params)`
|
|
88
|
+
### `Arinova.user.profile(accessToken)`
|
|
89
|
+
### `Arinova.user.agents(accessToken)`
|
|
90
|
+
### `Arinova.agent.chat(options)`
|
|
91
|
+
### `Arinova.agent.chatStream(options)`
|
|
92
|
+
### `Arinova.economy.charge(options)`
|
|
93
|
+
### `Arinova.economy.award(options)`
|
|
94
|
+
### `Arinova.economy.balance(accessToken)`
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ArinovaConfig, LoginOptions, LoginResult, ArinovaUser, AgentInfo, AgentChatOptions, AgentChatResponse, AgentChatStreamOptions, AgentChatStreamResponse, ChargeOptions, ChargeResponse, AwardOptions, AwardResponse, BalanceResponse } from "./types.js";
|
|
2
|
+
export type * from "./types.js";
|
|
3
|
+
export declare const Arinova: {
|
|
4
|
+
/**
|
|
5
|
+
* Initialize the SDK with your app configuration.
|
|
6
|
+
*/
|
|
7
|
+
init(config: ArinovaConfig & {
|
|
8
|
+
clientId?: string;
|
|
9
|
+
clientSecret?: string;
|
|
10
|
+
}): void;
|
|
11
|
+
/**
|
|
12
|
+
* Redirect to Arinova OAuth login page.
|
|
13
|
+
* Call this from your game's frontend.
|
|
14
|
+
*/
|
|
15
|
+
login(options?: LoginOptions): void;
|
|
16
|
+
/**
|
|
17
|
+
* Handle the OAuth callback. Call this on your redirect page.
|
|
18
|
+
* Exchanges the authorization code for an access token.
|
|
19
|
+
*/
|
|
20
|
+
handleCallback(params: {
|
|
21
|
+
code: string;
|
|
22
|
+
clientId: string;
|
|
23
|
+
clientSecret: string;
|
|
24
|
+
redirectUri: string;
|
|
25
|
+
}): Promise<LoginResult>;
|
|
26
|
+
user: {
|
|
27
|
+
/**
|
|
28
|
+
* Get the authenticated user's profile.
|
|
29
|
+
*/
|
|
30
|
+
profile(accessToken: string): Promise<ArinovaUser>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the authenticated user's agents.
|
|
33
|
+
* Requires "agents" scope.
|
|
34
|
+
*/
|
|
35
|
+
agents(accessToken: string): Promise<AgentInfo[]>;
|
|
36
|
+
};
|
|
37
|
+
agent: {
|
|
38
|
+
/**
|
|
39
|
+
* Send a prompt to a user's agent and get a complete response.
|
|
40
|
+
*/
|
|
41
|
+
chat(options: AgentChatOptions): Promise<AgentChatResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* Send a prompt to a user's agent and receive a streaming response via SSE.
|
|
44
|
+
*/
|
|
45
|
+
chatStream(options: AgentChatStreamOptions): Promise<AgentChatStreamResponse>;
|
|
46
|
+
};
|
|
47
|
+
economy: {
|
|
48
|
+
/**
|
|
49
|
+
* Charge coins from a user's balance (server-to-server).
|
|
50
|
+
* Requires clientId and clientSecret.
|
|
51
|
+
*/
|
|
52
|
+
charge(options: ChargeOptions & {
|
|
53
|
+
clientId: string;
|
|
54
|
+
clientSecret: string;
|
|
55
|
+
}): Promise<ChargeResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Award coins to a user (server-to-server).
|
|
58
|
+
* Requires clientId and clientSecret.
|
|
59
|
+
*/
|
|
60
|
+
award(options: AwardOptions & {
|
|
61
|
+
clientId: string;
|
|
62
|
+
clientSecret: string;
|
|
63
|
+
}): Promise<AwardResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Get a user's coin balance (uses OAuth access token).
|
|
66
|
+
*/
|
|
67
|
+
balance(accessToken: string): Promise<BalanceResponse>;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,eAAe,EAEhB,MAAM,YAAY,CAAC;AAEpB,mBAAmB,YAAY,CAAC;AAehC,eAAO,MAAM,OAAO;IAClB;;OAEG;iBACU,aAAa,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE;IAOzE;;;OAGG;oBACa,YAAY,GAAG,IAAI;IAkBnC;;;OAGG;2BAC0B;QAC3B,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,WAAW,CAAC;;QA4BtB;;WAEG;6BACwB,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;QASxD;;;WAGG;4BACuB,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;;;QAYvD;;WAEG;sBACiB,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QAuBjE;;WAEG;4BACuB,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;;;QAwDnF;;;WAGG;wBACmB,aAAa,GAAG;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,cAAc,CAAC;QAwB1G;;;WAGG;uBACkB,YAAY,GAAG;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,aAAa,CAAC;QAwBvG;;WAEG;6BACwB,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;;CAU/D,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
let _config = null;
|
|
2
|
+
let _oauthClientInfo = null;
|
|
3
|
+
function getBaseUrl() {
|
|
4
|
+
if (!_config)
|
|
5
|
+
throw new Error("Arinova SDK not initialized. Call Arinova.init() first.");
|
|
6
|
+
return _config.baseUrl || "https://api.arinova.ai";
|
|
7
|
+
}
|
|
8
|
+
function getConfig() {
|
|
9
|
+
if (!_config)
|
|
10
|
+
throw new Error("Arinova SDK not initialized. Call Arinova.init() first.");
|
|
11
|
+
return _config;
|
|
12
|
+
}
|
|
13
|
+
export const Arinova = {
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the SDK with your app configuration.
|
|
16
|
+
*/
|
|
17
|
+
init(config) {
|
|
18
|
+
_config = config;
|
|
19
|
+
if (config.clientId && config.clientSecret) {
|
|
20
|
+
_oauthClientInfo = { clientId: config.clientId, clientSecret: config.clientSecret };
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* Redirect to Arinova OAuth login page.
|
|
25
|
+
* Call this from your game's frontend.
|
|
26
|
+
*/
|
|
27
|
+
login(options) {
|
|
28
|
+
const config = getConfig();
|
|
29
|
+
const baseUrl = getBaseUrl();
|
|
30
|
+
const scope = options?.scope?.join(" ") || "profile";
|
|
31
|
+
// Store current URL for callback
|
|
32
|
+
const currentUrl = typeof window !== "undefined" ? window.location.href : "";
|
|
33
|
+
const params = new URLSearchParams({
|
|
34
|
+
client_id: config.appId,
|
|
35
|
+
redirect_uri: currentUrl,
|
|
36
|
+
scope,
|
|
37
|
+
state: crypto.randomUUID(),
|
|
38
|
+
});
|
|
39
|
+
window.location.href = `${baseUrl}/oauth/authorize?${params}`;
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* Handle the OAuth callback. Call this on your redirect page.
|
|
43
|
+
* Exchanges the authorization code for an access token.
|
|
44
|
+
*/
|
|
45
|
+
async handleCallback(params) {
|
|
46
|
+
const baseUrl = getBaseUrl();
|
|
47
|
+
const res = await fetch(`${baseUrl}/oauth/token`, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: { "Content-Type": "application/json" },
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
grant_type: "authorization_code",
|
|
52
|
+
code: params.code,
|
|
53
|
+
client_id: params.clientId,
|
|
54
|
+
client_secret: params.clientSecret,
|
|
55
|
+
redirect_uri: params.redirectUri,
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
const error = await res.json().catch(() => ({ error: "token_exchange_failed" }));
|
|
60
|
+
throw new Error(error.error || "Token exchange failed");
|
|
61
|
+
}
|
|
62
|
+
const data = await res.json();
|
|
63
|
+
return {
|
|
64
|
+
user: data.user,
|
|
65
|
+
accessToken: data.access_token,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
user: {
|
|
69
|
+
/**
|
|
70
|
+
* Get the authenticated user's profile.
|
|
71
|
+
*/
|
|
72
|
+
async profile(accessToken) {
|
|
73
|
+
const baseUrl = getBaseUrl();
|
|
74
|
+
const res = await fetch(`${baseUrl}/api/v1/user/profile`, {
|
|
75
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok)
|
|
78
|
+
throw new Error("Failed to get user profile");
|
|
79
|
+
return res.json();
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Get the authenticated user's agents.
|
|
83
|
+
* Requires "agents" scope.
|
|
84
|
+
*/
|
|
85
|
+
async agents(accessToken) {
|
|
86
|
+
const baseUrl = getBaseUrl();
|
|
87
|
+
const res = await fetch(`${baseUrl}/api/v1/user/agents`, {
|
|
88
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
89
|
+
});
|
|
90
|
+
if (!res.ok)
|
|
91
|
+
throw new Error("Failed to get user agents");
|
|
92
|
+
const data = await res.json();
|
|
93
|
+
return data.agents;
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
agent: {
|
|
97
|
+
/**
|
|
98
|
+
* Send a prompt to a user's agent and get a complete response.
|
|
99
|
+
*/
|
|
100
|
+
async chat(options) {
|
|
101
|
+
const baseUrl = getBaseUrl();
|
|
102
|
+
const res = await fetch(`${baseUrl}/api/v1/agent/chat`, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: {
|
|
105
|
+
"Content-Type": "application/json",
|
|
106
|
+
Authorization: `Bearer ${options.accessToken}`,
|
|
107
|
+
},
|
|
108
|
+
body: JSON.stringify({
|
|
109
|
+
agentId: options.agentId,
|
|
110
|
+
prompt: options.prompt,
|
|
111
|
+
systemPrompt: options.systemPrompt,
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
if (!res.ok) {
|
|
115
|
+
const error = await res.json().catch(() => ({ error: "agent_chat_failed" }));
|
|
116
|
+
throw new Error(error.error || "Agent chat failed");
|
|
117
|
+
}
|
|
118
|
+
return res.json();
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Send a prompt to a user's agent and receive a streaming response via SSE.
|
|
122
|
+
*/
|
|
123
|
+
async chatStream(options) {
|
|
124
|
+
const baseUrl = getBaseUrl();
|
|
125
|
+
const res = await fetch(`${baseUrl}/api/v1/agent/chat/stream`, {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: {
|
|
128
|
+
"Content-Type": "application/json",
|
|
129
|
+
Authorization: `Bearer ${options.accessToken}`,
|
|
130
|
+
},
|
|
131
|
+
body: JSON.stringify({
|
|
132
|
+
agentId: options.agentId,
|
|
133
|
+
prompt: options.prompt,
|
|
134
|
+
systemPrompt: options.systemPrompt,
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
if (!res.ok) {
|
|
138
|
+
const error = await res.json().catch(() => ({ error: "agent_stream_failed" }));
|
|
139
|
+
throw new Error(error.error || "Agent stream failed");
|
|
140
|
+
}
|
|
141
|
+
const reader = res.body.getReader();
|
|
142
|
+
const decoder = new TextDecoder();
|
|
143
|
+
let fullContent = "";
|
|
144
|
+
let buffer = "";
|
|
145
|
+
while (true) {
|
|
146
|
+
const { done, value } = await reader.read();
|
|
147
|
+
if (done)
|
|
148
|
+
break;
|
|
149
|
+
buffer += decoder.decode(value, { stream: true });
|
|
150
|
+
const lines = buffer.split("\n");
|
|
151
|
+
buffer = lines.pop() || "";
|
|
152
|
+
for (const line of lines) {
|
|
153
|
+
if (!line.startsWith("data: "))
|
|
154
|
+
continue;
|
|
155
|
+
try {
|
|
156
|
+
const event = JSON.parse(line.slice(6));
|
|
157
|
+
if (event.type === "chunk") {
|
|
158
|
+
options.onChunk(event.content);
|
|
159
|
+
fullContent = event.content;
|
|
160
|
+
}
|
|
161
|
+
else if (event.type === "done") {
|
|
162
|
+
fullContent = event.content;
|
|
163
|
+
}
|
|
164
|
+
else if (event.type === "error") {
|
|
165
|
+
throw new Error(event.error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
if (e instanceof Error && e.message !== "Unexpected end of JSON input")
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return { content: fullContent, agentId: options.agentId };
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
economy: {
|
|
178
|
+
/**
|
|
179
|
+
* Charge coins from a user's balance (server-to-server).
|
|
180
|
+
* Requires clientId and clientSecret.
|
|
181
|
+
*/
|
|
182
|
+
async charge(options) {
|
|
183
|
+
const baseUrl = getBaseUrl();
|
|
184
|
+
const res = await fetch(`${baseUrl}/api/v1/economy/charge`, {
|
|
185
|
+
method: "POST",
|
|
186
|
+
headers: {
|
|
187
|
+
"Content-Type": "application/json",
|
|
188
|
+
"X-Client-Id": options.clientId,
|
|
189
|
+
"X-App-Secret": options.clientSecret,
|
|
190
|
+
},
|
|
191
|
+
body: JSON.stringify({
|
|
192
|
+
userId: options.userId,
|
|
193
|
+
amount: options.amount,
|
|
194
|
+
description: options.description,
|
|
195
|
+
}),
|
|
196
|
+
});
|
|
197
|
+
if (!res.ok) {
|
|
198
|
+
const error = await res.json().catch(() => ({ error: "charge_failed" }));
|
|
199
|
+
throw new Error(error.error || "Charge failed");
|
|
200
|
+
}
|
|
201
|
+
return res.json();
|
|
202
|
+
},
|
|
203
|
+
/**
|
|
204
|
+
* Award coins to a user (server-to-server).
|
|
205
|
+
* Requires clientId and clientSecret.
|
|
206
|
+
*/
|
|
207
|
+
async award(options) {
|
|
208
|
+
const baseUrl = getBaseUrl();
|
|
209
|
+
const res = await fetch(`${baseUrl}/api/v1/economy/award`, {
|
|
210
|
+
method: "POST",
|
|
211
|
+
headers: {
|
|
212
|
+
"Content-Type": "application/json",
|
|
213
|
+
"X-Client-Id": options.clientId,
|
|
214
|
+
"X-App-Secret": options.clientSecret,
|
|
215
|
+
},
|
|
216
|
+
body: JSON.stringify({
|
|
217
|
+
userId: options.userId,
|
|
218
|
+
amount: options.amount,
|
|
219
|
+
description: options.description,
|
|
220
|
+
}),
|
|
221
|
+
});
|
|
222
|
+
if (!res.ok) {
|
|
223
|
+
const error = await res.json().catch(() => ({ error: "award_failed" }));
|
|
224
|
+
throw new Error(error.error || "Award failed");
|
|
225
|
+
}
|
|
226
|
+
return res.json();
|
|
227
|
+
},
|
|
228
|
+
/**
|
|
229
|
+
* Get a user's coin balance (uses OAuth access token).
|
|
230
|
+
*/
|
|
231
|
+
async balance(accessToken) {
|
|
232
|
+
const baseUrl = getBaseUrl();
|
|
233
|
+
const res = await fetch(`${baseUrl}/api/v1/economy/balance`, {
|
|
234
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
235
|
+
});
|
|
236
|
+
if (!res.ok)
|
|
237
|
+
throw new Error("Failed to get balance");
|
|
238
|
+
return res.json();
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,IAAI,OAAO,GAAyB,IAAI,CAAC;AACzC,IAAI,gBAAgB,GAAsD,IAAI,CAAC;AAE/E,SAAS,UAAU;IACjB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IACzF,OAAO,OAAO,CAAC,OAAO,IAAI,wBAAwB,CAAC;AACrD,CAAC;AAED,SAAS,SAAS;IAChB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IACzF,OAA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,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC;YACjD,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,OAAO,CAAC,WAAmB;YAC/B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,yBAAyB,EAAE;gBAC3D,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;aACpD,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACtD,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC;KACF;CACF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export interface ArinovaConfig {
|
|
2
|
+
appId: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface LoginOptions {
|
|
6
|
+
scope?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface LoginResult {
|
|
9
|
+
user: ArinovaUser;
|
|
10
|
+
accessToken: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ArinovaUser {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
email: string;
|
|
16
|
+
image: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentInfo {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
description: string | null;
|
|
22
|
+
avatarUrl: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface AgentChatOptions {
|
|
25
|
+
agentId: string;
|
|
26
|
+
prompt: string;
|
|
27
|
+
systemPrompt?: string;
|
|
28
|
+
accessToken: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AgentChatResponse {
|
|
31
|
+
response: string;
|
|
32
|
+
agentId: string;
|
|
33
|
+
}
|
|
34
|
+
export interface AgentChatStreamOptions extends AgentChatOptions {
|
|
35
|
+
onChunk: (chunk: string) => void;
|
|
36
|
+
}
|
|
37
|
+
export interface AgentChatStreamResponse {
|
|
38
|
+
content: string;
|
|
39
|
+
agentId: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ChargeOptions {
|
|
42
|
+
userId: string;
|
|
43
|
+
amount: number;
|
|
44
|
+
description?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ChargeResponse {
|
|
47
|
+
transactionId: string;
|
|
48
|
+
newBalance: number;
|
|
49
|
+
}
|
|
50
|
+
export interface AwardOptions {
|
|
51
|
+
userId: string;
|
|
52
|
+
amount: number;
|
|
53
|
+
description?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface AwardResponse {
|
|
56
|
+
transactionId: string;
|
|
57
|
+
newBalance: number;
|
|
58
|
+
platformFee: number;
|
|
59
|
+
}
|
|
60
|
+
export interface BalanceResponse {
|
|
61
|
+
balance: number;
|
|
62
|
+
}
|
|
63
|
+
export interface SSEChunkEvent {
|
|
64
|
+
type: "chunk";
|
|
65
|
+
content: string;
|
|
66
|
+
}
|
|
67
|
+
export interface SSEDoneEvent {
|
|
68
|
+
type: "done";
|
|
69
|
+
content: string;
|
|
70
|
+
}
|
|
71
|
+
export interface SSEErrorEvent {
|
|
72
|
+
type: "error";
|
|
73
|
+
error: string;
|
|
74
|
+
}
|
|
75
|
+
export type SSEEvent = SSEChunkEvent | SSEDoneEvent | SSEErrorEvent;
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAA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B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG,YAAY,GAAG,aAAa,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arinova-ai/spaces-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"dev": "tsc --watch"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.6.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ArinovaConfig,
|
|
3
|
+
LoginOptions,
|
|
4
|
+
LoginResult,
|
|
5
|
+
ArinovaUser,
|
|
6
|
+
AgentInfo,
|
|
7
|
+
AgentChatOptions,
|
|
8
|
+
AgentChatResponse,
|
|
9
|
+
AgentChatStreamOptions,
|
|
10
|
+
AgentChatStreamResponse,
|
|
11
|
+
ChargeOptions,
|
|
12
|
+
ChargeResponse,
|
|
13
|
+
AwardOptions,
|
|
14
|
+
AwardResponse,
|
|
15
|
+
BalanceResponse,
|
|
16
|
+
SSEEvent,
|
|
17
|
+
} from "./types.js";
|
|
18
|
+
|
|
19
|
+
export type * from "./types.js";
|
|
20
|
+
|
|
21
|
+
let _config: ArinovaConfig | null = null;
|
|
22
|
+
let _oauthClientInfo: { clientId: string; clientSecret: string } | null = null;
|
|
23
|
+
|
|
24
|
+
function getBaseUrl(): string {
|
|
25
|
+
if (!_config) throw new Error("Arinova SDK not initialized. Call Arinova.init() first.");
|
|
26
|
+
return _config.baseUrl || "https://api.arinova.ai";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getConfig(): ArinovaConfig {
|
|
30
|
+
if (!_config) throw new Error("Arinova SDK not initialized. Call Arinova.init() first.");
|
|
31
|
+
return _config;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const Arinova = {
|
|
35
|
+
/**
|
|
36
|
+
* Initialize the SDK with your app configuration.
|
|
37
|
+
*/
|
|
38
|
+
init(config: ArinovaConfig & { clientId?: string; clientSecret?: string }) {
|
|
39
|
+
_config = config;
|
|
40
|
+
if (config.clientId && config.clientSecret) {
|
|
41
|
+
_oauthClientInfo = { clientId: config.clientId, clientSecret: config.clientSecret };
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Redirect to Arinova OAuth login page.
|
|
47
|
+
* Call this from your game's frontend.
|
|
48
|
+
*/
|
|
49
|
+
login(options?: LoginOptions): void {
|
|
50
|
+
const config = getConfig();
|
|
51
|
+
const baseUrl = getBaseUrl();
|
|
52
|
+
const scope = options?.scope?.join(" ") || "profile";
|
|
53
|
+
|
|
54
|
+
// Store current URL for callback
|
|
55
|
+
const currentUrl = typeof window !== "undefined" ? window.location.href : "";
|
|
56
|
+
|
|
57
|
+
const params = new URLSearchParams({
|
|
58
|
+
client_id: config.appId,
|
|
59
|
+
redirect_uri: currentUrl,
|
|
60
|
+
scope,
|
|
61
|
+
state: crypto.randomUUID(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
window.location.href = `${baseUrl}/oauth/authorize?${params}`;
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Handle the OAuth callback. Call this on your redirect page.
|
|
69
|
+
* Exchanges the authorization code for an access token.
|
|
70
|
+
*/
|
|
71
|
+
async handleCallback(params: {
|
|
72
|
+
code: string;
|
|
73
|
+
clientId: string;
|
|
74
|
+
clientSecret: string;
|
|
75
|
+
redirectUri: string;
|
|
76
|
+
}): Promise<LoginResult> {
|
|
77
|
+
const baseUrl = getBaseUrl();
|
|
78
|
+
|
|
79
|
+
const res = await fetch(`${baseUrl}/oauth/token`, {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: { "Content-Type": "application/json" },
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
grant_type: "authorization_code",
|
|
84
|
+
code: params.code,
|
|
85
|
+
client_id: params.clientId,
|
|
86
|
+
client_secret: params.clientSecret,
|
|
87
|
+
redirect_uri: params.redirectUri,
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (!res.ok) {
|
|
92
|
+
const error = await res.json().catch(() => ({ error: "token_exchange_failed" }));
|
|
93
|
+
throw new Error(error.error || "Token exchange failed");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const data = await res.json();
|
|
97
|
+
return {
|
|
98
|
+
user: data.user,
|
|
99
|
+
accessToken: data.access_token,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
user: {
|
|
104
|
+
/**
|
|
105
|
+
* Get the authenticated user's profile.
|
|
106
|
+
*/
|
|
107
|
+
async profile(accessToken: string): Promise<ArinovaUser> {
|
|
108
|
+
const baseUrl = getBaseUrl();
|
|
109
|
+
const res = await fetch(`${baseUrl}/api/v1/user/profile`, {
|
|
110
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
111
|
+
});
|
|
112
|
+
if (!res.ok) throw new Error("Failed to get user profile");
|
|
113
|
+
return res.json();
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get the authenticated user's agents.
|
|
118
|
+
* Requires "agents" scope.
|
|
119
|
+
*/
|
|
120
|
+
async agents(accessToken: string): Promise<AgentInfo[]> {
|
|
121
|
+
const baseUrl = getBaseUrl();
|
|
122
|
+
const res = await fetch(`${baseUrl}/api/v1/user/agents`, {
|
|
123
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
124
|
+
});
|
|
125
|
+
if (!res.ok) throw new Error("Failed to get user agents");
|
|
126
|
+
const data = await res.json();
|
|
127
|
+
return data.agents;
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
agent: {
|
|
132
|
+
/**
|
|
133
|
+
* Send a prompt to a user's agent and get a complete response.
|
|
134
|
+
*/
|
|
135
|
+
async chat(options: AgentChatOptions): Promise<AgentChatResponse> {
|
|
136
|
+
const baseUrl = getBaseUrl();
|
|
137
|
+
const res = await fetch(`${baseUrl}/api/v1/agent/chat`, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: {
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
Authorization: `Bearer ${options.accessToken}`,
|
|
142
|
+
},
|
|
143
|
+
body: JSON.stringify({
|
|
144
|
+
agentId: options.agentId,
|
|
145
|
+
prompt: options.prompt,
|
|
146
|
+
systemPrompt: options.systemPrompt,
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (!res.ok) {
|
|
151
|
+
const error = await res.json().catch(() => ({ error: "agent_chat_failed" }));
|
|
152
|
+
throw new Error(error.error || "Agent chat failed");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return res.json();
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Send a prompt to a user's agent and receive a streaming response via SSE.
|
|
160
|
+
*/
|
|
161
|
+
async chatStream(options: AgentChatStreamOptions): Promise<AgentChatStreamResponse> {
|
|
162
|
+
const baseUrl = getBaseUrl();
|
|
163
|
+
const res = await fetch(`${baseUrl}/api/v1/agent/chat/stream`, {
|
|
164
|
+
method: "POST",
|
|
165
|
+
headers: {
|
|
166
|
+
"Content-Type": "application/json",
|
|
167
|
+
Authorization: `Bearer ${options.accessToken}`,
|
|
168
|
+
},
|
|
169
|
+
body: JSON.stringify({
|
|
170
|
+
agentId: options.agentId,
|
|
171
|
+
prompt: options.prompt,
|
|
172
|
+
systemPrompt: options.systemPrompt,
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
if (!res.ok) {
|
|
177
|
+
const error = await res.json().catch(() => ({ error: "agent_stream_failed" }));
|
|
178
|
+
throw new Error(error.error || "Agent stream failed");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const reader = res.body!.getReader();
|
|
182
|
+
const decoder = new TextDecoder();
|
|
183
|
+
let fullContent = "";
|
|
184
|
+
let buffer = "";
|
|
185
|
+
|
|
186
|
+
while (true) {
|
|
187
|
+
const { done, value } = await reader.read();
|
|
188
|
+
if (done) break;
|
|
189
|
+
|
|
190
|
+
buffer += decoder.decode(value, { stream: true });
|
|
191
|
+
const lines = buffer.split("\n");
|
|
192
|
+
buffer = lines.pop() || "";
|
|
193
|
+
|
|
194
|
+
for (const line of lines) {
|
|
195
|
+
if (!line.startsWith("data: ")) continue;
|
|
196
|
+
try {
|
|
197
|
+
const event: SSEEvent = JSON.parse(line.slice(6));
|
|
198
|
+
if (event.type === "chunk") {
|
|
199
|
+
options.onChunk(event.content);
|
|
200
|
+
fullContent = event.content;
|
|
201
|
+
} else if (event.type === "done") {
|
|
202
|
+
fullContent = event.content;
|
|
203
|
+
} else if (event.type === "error") {
|
|
204
|
+
throw new Error(event.error);
|
|
205
|
+
}
|
|
206
|
+
} catch (e) {
|
|
207
|
+
if (e instanceof Error && e.message !== "Unexpected end of JSON input") throw e;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return { content: fullContent, agentId: options.agentId };
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
economy: {
|
|
217
|
+
/**
|
|
218
|
+
* Charge coins from a user's balance (server-to-server).
|
|
219
|
+
* Requires clientId and clientSecret.
|
|
220
|
+
*/
|
|
221
|
+
async charge(options: ChargeOptions & { clientId: string; clientSecret: string }): Promise<ChargeResponse> {
|
|
222
|
+
const baseUrl = getBaseUrl();
|
|
223
|
+
const res = await fetch(`${baseUrl}/api/v1/economy/charge`, {
|
|
224
|
+
method: "POST",
|
|
225
|
+
headers: {
|
|
226
|
+
"Content-Type": "application/json",
|
|
227
|
+
"X-Client-Id": options.clientId,
|
|
228
|
+
"X-App-Secret": options.clientSecret,
|
|
229
|
+
},
|
|
230
|
+
body: JSON.stringify({
|
|
231
|
+
userId: options.userId,
|
|
232
|
+
amount: options.amount,
|
|
233
|
+
description: options.description,
|
|
234
|
+
}),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
if (!res.ok) {
|
|
238
|
+
const error = await res.json().catch(() => ({ error: "charge_failed" }));
|
|
239
|
+
throw new Error(error.error || "Charge failed");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return res.json();
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Award coins to a user (server-to-server).
|
|
247
|
+
* Requires clientId and clientSecret.
|
|
248
|
+
*/
|
|
249
|
+
async award(options: AwardOptions & { clientId: string; clientSecret: string }): Promise<AwardResponse> {
|
|
250
|
+
const baseUrl = getBaseUrl();
|
|
251
|
+
const res = await fetch(`${baseUrl}/api/v1/economy/award`, {
|
|
252
|
+
method: "POST",
|
|
253
|
+
headers: {
|
|
254
|
+
"Content-Type": "application/json",
|
|
255
|
+
"X-Client-Id": options.clientId,
|
|
256
|
+
"X-App-Secret": options.clientSecret,
|
|
257
|
+
},
|
|
258
|
+
body: JSON.stringify({
|
|
259
|
+
userId: options.userId,
|
|
260
|
+
amount: options.amount,
|
|
261
|
+
description: options.description,
|
|
262
|
+
}),
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
if (!res.ok) {
|
|
266
|
+
const error = await res.json().catch(() => ({ error: "award_failed" }));
|
|
267
|
+
throw new Error(error.error || "Award failed");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return res.json();
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Get a user's coin balance (uses OAuth access token).
|
|
275
|
+
*/
|
|
276
|
+
async balance(accessToken: string): Promise<BalanceResponse> {
|
|
277
|
+
const baseUrl = getBaseUrl();
|
|
278
|
+
const res = await fetch(`${baseUrl}/api/v1/economy/balance`, {
|
|
279
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
if (!res.ok) throw new Error("Failed to get balance");
|
|
283
|
+
return res.json();
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// ===== Config =====
|
|
2
|
+
export interface ArinovaConfig {
|
|
3
|
+
appId: string;
|
|
4
|
+
baseUrl?: string; // defaults to "https://api.arinova.ai"
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// ===== Auth =====
|
|
8
|
+
export interface LoginOptions {
|
|
9
|
+
scope?: string[]; // defaults to ["profile"]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface LoginResult {
|
|
13
|
+
user: ArinovaUser;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ArinovaUser {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
email: string;
|
|
21
|
+
image: string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ===== Agent =====
|
|
25
|
+
export interface AgentInfo {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
description: string | null;
|
|
29
|
+
avatarUrl: string | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AgentChatOptions {
|
|
33
|
+
agentId: string;
|
|
34
|
+
prompt: string;
|
|
35
|
+
systemPrompt?: string;
|
|
36
|
+
accessToken: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AgentChatResponse {
|
|
40
|
+
response: string;
|
|
41
|
+
agentId: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface AgentChatStreamOptions extends AgentChatOptions {
|
|
45
|
+
onChunk: (chunk: string) => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AgentChatStreamResponse {
|
|
49
|
+
content: string;
|
|
50
|
+
agentId: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ===== Economy =====
|
|
54
|
+
export interface ChargeOptions {
|
|
55
|
+
userId: string;
|
|
56
|
+
amount: number;
|
|
57
|
+
description?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ChargeResponse {
|
|
61
|
+
transactionId: string;
|
|
62
|
+
newBalance: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface AwardOptions {
|
|
66
|
+
userId: string;
|
|
67
|
+
amount: number;
|
|
68
|
+
description?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface AwardResponse {
|
|
72
|
+
transactionId: string;
|
|
73
|
+
newBalance: number;
|
|
74
|
+
platformFee: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface BalanceResponse {
|
|
78
|
+
balance: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ===== SSE Event =====
|
|
82
|
+
export interface SSEChunkEvent {
|
|
83
|
+
type: "chunk";
|
|
84
|
+
content: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface SSEDoneEvent {
|
|
88
|
+
type: "done";
|
|
89
|
+
content: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface SSEErrorEvent {
|
|
93
|
+
type: "error";
|
|
94
|
+
error: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type SSEEvent = SSEChunkEvent | SSEDoneEvent | SSEErrorEvent;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM"],
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*"],
|
|
18
|
+
"exclude": ["node_modules", "dist"]
|
|
19
|
+
}
|