playkit-sdk 1.2.1-beta.1 → 1.2.3
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/LICENSE +86 -86
- package/README.md +244 -244
- package/dist/playkit-sdk.cjs.js +1762 -742
- package/dist/playkit-sdk.cjs.js.map +1 -1
- package/dist/playkit-sdk.d.ts +858 -104
- package/dist/playkit-sdk.esm.js +1757 -742
- package/dist/playkit-sdk.esm.js.map +1 -1
- package/dist/playkit-sdk.umd.js +1762 -742
- package/dist/playkit-sdk.umd.js.map +1 -1
- package/package.json +70 -70
package/LICENSE
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
PlayKit SDK License Agreement
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Agentland Lab. All rights reserved.
|
|
4
|
-
|
|
5
|
-
NOTICE: This software and its documentation are proprietary products of Agentland Lab.
|
|
6
|
-
|
|
7
|
-
TERMS AND CONDITIONS
|
|
8
|
-
|
|
9
|
-
1. GRANT OF LICENSE
|
|
10
|
-
Subject to the terms and conditions of this Agreement, Agentland Lab grants you a
|
|
11
|
-
limited, non-exclusive, non-transferable, revocable license to use the PlayKit SDK
|
|
12
|
-
solely for the purpose of developing and operating games that integrate with the
|
|
13
|
-
PlayKit platform.2
|
|
14
|
-
|
|
15
|
-
2. RESTRICTIONS
|
|
16
|
-
You may NOT:
|
|
17
|
-
a) Modify, adapt, translate, reverse engineer, decompile, or disassemble the SDK
|
|
18
|
-
b) Remove or alter any copyright, trademark, or proprietary notices
|
|
19
|
-
c) Use the SDK to develop competing products or services
|
|
20
|
-
d) Redistribute, sublicense, rent, lease, or lend the SDK to third parties
|
|
21
|
-
e) Use the SDK in any manner that violates applicable laws or regulations
|
|
22
|
-
f) Use the SDK to create malicious, harmful, or illegal applications
|
|
23
|
-
|
|
24
|
-
3. OWNERSHIP
|
|
25
|
-
Agentland Lab retains all right, title, and interest in and to the SDK, including
|
|
26
|
-
all intellectual property rights. This license does not grant you any rights to
|
|
27
|
-
trademarks, service marks, or trade names of Agentland Lab.
|
|
28
|
-
|
|
29
|
-
4. API USAGE AND BILLING
|
|
30
|
-
a) Use of the SDK requires a valid Agentland Lab account
|
|
31
|
-
b) API usage will be billed according to Agentland Lab' current pricing structure
|
|
32
|
-
c) You are responsible for all charges incurred through your use of the SDK
|
|
33
|
-
d) Agentland Lab reserves the right to modify pricing with reasonable notice
|
|
34
|
-
|
|
35
|
-
5. DEVELOPER TOKEN
|
|
36
|
-
a) Developer tokens are provided for development and testing purposes only
|
|
37
|
-
b) Developer tokens must not be used in production environments
|
|
38
|
-
c) You are responsible for keeping your developer tokens confidential
|
|
39
|
-
d) Agentland Lab may revoke developer tokens at any time
|
|
40
|
-
|
|
41
|
-
6. DATA AND PRIVACY
|
|
42
|
-
a) You are responsible for complying with all applicable data protection laws
|
|
43
|
-
b) You must provide appropriate privacy notices to your end users
|
|
44
|
-
c) Agentland Lab' collection and use of data is governed by its Privacy Policy
|
|
45
|
-
|
|
46
|
-
7. TERMINATION
|
|
47
|
-
a) This license is effective until terminated
|
|
48
|
-
b) Agentland Lab may terminate this license at any time if you breach any terms
|
|
49
|
-
c) Upon termination, you must cease all use of the SDK and destroy all copies
|
|
50
|
-
d) Termination does not relieve you of any payment obligations
|
|
51
|
-
|
|
52
|
-
8. WARRANTY DISCLAIMER
|
|
53
|
-
THE SDK IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
54
|
-
INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
55
|
-
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. Agentland Lab DOES NOT WARRANT THAT
|
|
56
|
-
THE SDK WILL BE ERROR-FREE OR UNINTERRUPTED.
|
|
57
|
-
|
|
58
|
-
9. LIMITATION OF LIABILITY
|
|
59
|
-
IN NO EVENT SHALL Agentland Lab BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
|
|
60
|
-
CONSEQUENTIAL, OR PUNITIVE DAMAGES, INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS,
|
|
61
|
-
DATA, OR USE, ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE USE OF THE SDK,
|
|
62
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
63
|
-
|
|
64
|
-
10. SUPPORT AND UPDATES
|
|
65
|
-
a) Agentland Lab may, but is not obligated to, provide support or updates
|
|
66
|
-
b) Updates may be subject to additional or different license terms
|
|
67
|
-
c) You are responsible for implementing updates in a timely manner
|
|
68
|
-
|
|
69
|
-
11. MODIFICATIONS TO TERMS
|
|
70
|
-
Agentland Lab reserves the right to modify these terms at any time. Continued
|
|
71
|
-
use of the SDK after modifications constitutes acceptance of the new terms.
|
|
72
|
-
|
|
73
|
-
12. GOVERNING LAW
|
|
74
|
-
This Agreement shall be governed by and construed in accordance with the laws
|
|
75
|
-
of the jurisdiction in which Agentland Lab is registered, without regard to
|
|
76
|
-
its conflict of law provisions.
|
|
77
|
-
|
|
78
|
-
13. ENTIRE AGREEMENT
|
|
79
|
-
This Agreement constitutes the entire agreement between you and Agentland Lab
|
|
80
|
-
regarding the SDK and supersedes all prior agreements and understandings.
|
|
81
|
-
|
|
82
|
-
14. CONTACT
|
|
83
|
-
For questions about this license, contact: legal@Agentland Lab.com
|
|
84
|
-
|
|
85
|
-
BY USING THE SDK, YOU ACKNOWLEDGE THAT YOU HAVE READ THIS AGREEMENT, UNDERSTAND IT,
|
|
86
|
-
AND AGREE TO BE BOUND BY ITS TERMS AND CONDITIONS.
|
|
1
|
+
PlayKit SDK License Agreement
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Agentland Lab. All rights reserved.
|
|
4
|
+
|
|
5
|
+
NOTICE: This software and its documentation are proprietary products of Agentland Lab.
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS
|
|
8
|
+
|
|
9
|
+
1. GRANT OF LICENSE
|
|
10
|
+
Subject to the terms and conditions of this Agreement, Agentland Lab grants you a
|
|
11
|
+
limited, non-exclusive, non-transferable, revocable license to use the PlayKit SDK
|
|
12
|
+
solely for the purpose of developing and operating games that integrate with the
|
|
13
|
+
PlayKit platform.2
|
|
14
|
+
|
|
15
|
+
2. RESTRICTIONS
|
|
16
|
+
You may NOT:
|
|
17
|
+
a) Modify, adapt, translate, reverse engineer, decompile, or disassemble the SDK
|
|
18
|
+
b) Remove or alter any copyright, trademark, or proprietary notices
|
|
19
|
+
c) Use the SDK to develop competing products or services
|
|
20
|
+
d) Redistribute, sublicense, rent, lease, or lend the SDK to third parties
|
|
21
|
+
e) Use the SDK in any manner that violates applicable laws or regulations
|
|
22
|
+
f) Use the SDK to create malicious, harmful, or illegal applications
|
|
23
|
+
|
|
24
|
+
3. OWNERSHIP
|
|
25
|
+
Agentland Lab retains all right, title, and interest in and to the SDK, including
|
|
26
|
+
all intellectual property rights. This license does not grant you any rights to
|
|
27
|
+
trademarks, service marks, or trade names of Agentland Lab.
|
|
28
|
+
|
|
29
|
+
4. API USAGE AND BILLING
|
|
30
|
+
a) Use of the SDK requires a valid Agentland Lab account
|
|
31
|
+
b) API usage will be billed according to Agentland Lab' current pricing structure
|
|
32
|
+
c) You are responsible for all charges incurred through your use of the SDK
|
|
33
|
+
d) Agentland Lab reserves the right to modify pricing with reasonable notice
|
|
34
|
+
|
|
35
|
+
5. DEVELOPER TOKEN
|
|
36
|
+
a) Developer tokens are provided for development and testing purposes only
|
|
37
|
+
b) Developer tokens must not be used in production environments
|
|
38
|
+
c) You are responsible for keeping your developer tokens confidential
|
|
39
|
+
d) Agentland Lab may revoke developer tokens at any time
|
|
40
|
+
|
|
41
|
+
6. DATA AND PRIVACY
|
|
42
|
+
a) You are responsible for complying with all applicable data protection laws
|
|
43
|
+
b) You must provide appropriate privacy notices to your end users
|
|
44
|
+
c) Agentland Lab' collection and use of data is governed by its Privacy Policy
|
|
45
|
+
|
|
46
|
+
7. TERMINATION
|
|
47
|
+
a) This license is effective until terminated
|
|
48
|
+
b) Agentland Lab may terminate this license at any time if you breach any terms
|
|
49
|
+
c) Upon termination, you must cease all use of the SDK and destroy all copies
|
|
50
|
+
d) Termination does not relieve you of any payment obligations
|
|
51
|
+
|
|
52
|
+
8. WARRANTY DISCLAIMER
|
|
53
|
+
THE SDK IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
54
|
+
INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
55
|
+
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. Agentland Lab DOES NOT WARRANT THAT
|
|
56
|
+
THE SDK WILL BE ERROR-FREE OR UNINTERRUPTED.
|
|
57
|
+
|
|
58
|
+
9. LIMITATION OF LIABILITY
|
|
59
|
+
IN NO EVENT SHALL Agentland Lab BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
|
|
60
|
+
CONSEQUENTIAL, OR PUNITIVE DAMAGES, INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS,
|
|
61
|
+
DATA, OR USE, ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE USE OF THE SDK,
|
|
62
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
63
|
+
|
|
64
|
+
10. SUPPORT AND UPDATES
|
|
65
|
+
a) Agentland Lab may, but is not obligated to, provide support or updates
|
|
66
|
+
b) Updates may be subject to additional or different license terms
|
|
67
|
+
c) You are responsible for implementing updates in a timely manner
|
|
68
|
+
|
|
69
|
+
11. MODIFICATIONS TO TERMS
|
|
70
|
+
Agentland Lab reserves the right to modify these terms at any time. Continued
|
|
71
|
+
use of the SDK after modifications constitutes acceptance of the new terms.
|
|
72
|
+
|
|
73
|
+
12. GOVERNING LAW
|
|
74
|
+
This Agreement shall be governed by and construed in accordance with the laws
|
|
75
|
+
of the jurisdiction in which Agentland Lab is registered, without regard to
|
|
76
|
+
its conflict of law provisions.
|
|
77
|
+
|
|
78
|
+
13. ENTIRE AGREEMENT
|
|
79
|
+
This Agreement constitutes the entire agreement between you and Agentland Lab
|
|
80
|
+
regarding the SDK and supersedes all prior agreements and understandings.
|
|
81
|
+
|
|
82
|
+
14. CONTACT
|
|
83
|
+
For questions about this license, contact: legal@Agentland Lab.com
|
|
84
|
+
|
|
85
|
+
BY USING THE SDK, YOU ACKNOWLEDGE THAT YOU HAVE READ THIS AGREEMENT, UNDERSTAND IT,
|
|
86
|
+
AND AGREE TO BE BOUND BY ITS TERMS AND CONDITIONS.
|
package/README.md
CHANGED
|
@@ -1,244 +1,244 @@
|
|
|
1
|
-
# PlayKit SDK for JavaScript
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/playkit)
|
|
4
|
-
|
|
5
|
-
JavaScript/TypeScript SDK for integrating AI capabilities into web-based games.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- AI-powered text generation using GPT models
|
|
10
|
-
- Image generation using DALL-E models
|
|
11
|
-
- NPC conversation management with automatic history tracking
|
|
12
|
-
- JWT-based authentication and token management
|
|
13
|
-
- Real-time streaming responses
|
|
14
|
-
- Framework-agnostic design (compatible with P5.js, Phaser, PixiJS, etc.)
|
|
15
|
-
- Multiple bundle formats (ESM, CJS, UMD)
|
|
16
|
-
- Encrypted token storage using Web Crypto API
|
|
17
|
-
- Full TypeScript support with type definitions
|
|
18
|
-
- Player balance management and recharge functionality
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install playkit-sdk
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Quick Start
|
|
27
|
-
|
|
28
|
-
### Basic Setup
|
|
29
|
-
|
|
30
|
-
```typescript
|
|
31
|
-
import { PlayKitSDK } from 'playkit-sdk';
|
|
32
|
-
|
|
33
|
-
const sdk = new PlayKitSDK({
|
|
34
|
-
gameId: 'your-game-id',
|
|
35
|
-
developerToken: 'your-dev-token', // For development
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
await sdk.initialize();
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Text Generation
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
const chat = sdk.createChatClient('gpt-4o-mini');
|
|
45
|
-
|
|
46
|
-
// Simple chat
|
|
47
|
-
const response = await chat.chat('Hello, introduce yourself');
|
|
48
|
-
console.log(response);
|
|
49
|
-
|
|
50
|
-
// With system prompt
|
|
51
|
-
const response = await chat.chat(
|
|
52
|
-
'How should I explore this dungeon?',
|
|
53
|
-
'You are a wise dungeon guide.'
|
|
54
|
-
);
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Streaming Text
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
await chat.chatStream(
|
|
61
|
-
'Tell a story about a brave knight',
|
|
62
|
-
(chunk) => {
|
|
63
|
-
process.stdout.write(chunk);
|
|
64
|
-
},
|
|
65
|
-
(fullText) => {
|
|
66
|
-
console.log('\nComplete:', fullText);
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Image Generation
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
const imageClient = sdk.createImageClient('dall-e-3');
|
|
75
|
-
|
|
76
|
-
const image = await imageClient.generate('A futuristic cyberpunk city at night');
|
|
77
|
-
|
|
78
|
-
console.log('Base64:', image.base64);
|
|
79
|
-
console.log('Data URL:', image.toDataURL());
|
|
80
|
-
|
|
81
|
-
// Display in browser
|
|
82
|
-
const imgElement = await image.toHTMLImage();
|
|
83
|
-
document.body.appendChild(imgElement);
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### NPC Conversations
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
const npc = sdk.createNPCClient({
|
|
90
|
-
systemPrompt: 'You are a mysterious wizard who speaks in riddles.',
|
|
91
|
-
temperature: 0.8,
|
|
92
|
-
maxHistoryLength: 20,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const reply1 = await npc.talk('Who are you?');
|
|
96
|
-
console.log('Wizard:', reply1);
|
|
97
|
-
|
|
98
|
-
const reply2 = await npc.talk('What is your quest?');
|
|
99
|
-
console.log('Wizard:', reply2);
|
|
100
|
-
|
|
101
|
-
// Save/load history
|
|
102
|
-
const savedHistory = npc.saveHistory();
|
|
103
|
-
localStorage.setItem('npc_history', savedHistory);
|
|
104
|
-
|
|
105
|
-
// Later...
|
|
106
|
-
npc.loadHistory(localStorage.getItem('npc_history'));
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Player Balance Management
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
// Get player info and balance
|
|
113
|
-
const playerInfo = await sdk.getPlayerInfo();
|
|
114
|
-
console.log('Player ID:', playerInfo.userId);
|
|
115
|
-
console.log('Credits:', playerInfo.credits);
|
|
116
|
-
|
|
117
|
-
// Open recharge window
|
|
118
|
-
sdk.openRechargeWindow();
|
|
119
|
-
|
|
120
|
-
// Show insufficient balance modal
|
|
121
|
-
await sdk.showInsufficientBalanceModal();
|
|
122
|
-
|
|
123
|
-
// Enable automatic balance checking
|
|
124
|
-
sdk.enableAutoBalanceCheck(30000); // Check every 30 seconds
|
|
125
|
-
|
|
126
|
-
// Listen to balance events
|
|
127
|
-
sdk.on('balance_updated', (credits) => {
|
|
128
|
-
console.log('New balance:', credits);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
sdk.on('insufficient_credits', (error) => {
|
|
132
|
-
console.log('User needs to recharge');
|
|
133
|
-
});
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
## Usage with P5.js
|
|
137
|
-
|
|
138
|
-
```javascript
|
|
139
|
-
let sdk, npc, generatedImage;
|
|
140
|
-
|
|
141
|
-
async function setup() {
|
|
142
|
-
createCanvas(800, 600);
|
|
143
|
-
|
|
144
|
-
sdk = new PlayKitSDK({
|
|
145
|
-
gameId: 'your-game-id',
|
|
146
|
-
developerToken: 'your-dev-token'
|
|
147
|
-
});
|
|
148
|
-
await sdk.initialize();
|
|
149
|
-
|
|
150
|
-
npc = sdk.createNPCClient({
|
|
151
|
-
systemPrompt: 'You are a friendly game character.'
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async function mousePressed() {
|
|
156
|
-
const reply = await npc.talk('Hello!');
|
|
157
|
-
console.log(reply);
|
|
158
|
-
|
|
159
|
-
const imageClient = sdk.createImageClient();
|
|
160
|
-
const img = await imageClient.generate('A magical forest');
|
|
161
|
-
|
|
162
|
-
const htmlImg = await img.toHTMLImage();
|
|
163
|
-
generatedImage = loadImage(htmlImg.src);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function draw() {
|
|
167
|
-
background(220);
|
|
168
|
-
if (generatedImage) {
|
|
169
|
-
image(generatedImage, 0, 0, 400, 400);
|
|
170
|
-
}
|
|
171
|
-
text('Click to talk to NPC or generate image', 10, height - 20);
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Usage with Vanilla JavaScript
|
|
176
|
-
|
|
177
|
-
```html
|
|
178
|
-
<!DOCTYPE html>
|
|
179
|
-
<html>
|
|
180
|
-
<head>
|
|
181
|
-
<script src="https://unpkg.com/playkit-sdk@latest/dist/index.umd.js"></script>
|
|
182
|
-
</head>
|
|
183
|
-
<body>
|
|
184
|
-
<div id="output"></div>
|
|
185
|
-
<input id="userInput" type="text" placeholder="Type a message...">
|
|
186
|
-
<button onclick="sendMessage()">Send</button>
|
|
187
|
-
|
|
188
|
-
<script>
|
|
189
|
-
let sdk, chat;
|
|
190
|
-
|
|
191
|
-
async function init() {
|
|
192
|
-
sdk = new PlayKitSDK.PlayKitSDK({
|
|
193
|
-
gameId: 'your-game-id',
|
|
194
|
-
developerToken: 'your-dev-token'
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
await sdk.initialize();
|
|
198
|
-
chat = sdk.createChatClient();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async function sendMessage() {
|
|
202
|
-
const input = document.getElementById('userInput').value;
|
|
203
|
-
const output = document.getElementById('output');
|
|
204
|
-
|
|
205
|
-
output.innerHTML += `<p><strong>You:</strong> ${input}</p>`;
|
|
206
|
-
output.innerHTML += `<p><strong>AI:</strong> <span id="aiReply"></span></p>`;
|
|
207
|
-
|
|
208
|
-
const replyElement = document.getElementById('aiReply');
|
|
209
|
-
await chat.chatStream(
|
|
210
|
-
input,
|
|
211
|
-
(chunk) => { replyElement.innerHTML += chunk; }
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
document.getElementById('userInput').value = '';
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
init();
|
|
218
|
-
</script>
|
|
219
|
-
</body>
|
|
220
|
-
</html>
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
## License
|
|
225
|
-
|
|
226
|
-
Proprietary License - see [LICENSE](LICENSE) file for details.
|
|
227
|
-
|
|
228
|
-
This SDK is proprietary software owned by Agentland Lab. Use of this SDK is subject to the terms and conditions of the license agreement.
|
|
229
|
-
|
|
230
|
-
## Support
|
|
231
|
-
|
|
232
|
-
- Email: support@
|
|
233
|
-
- Issues: [GitHub Issues](https://github.com/cnqdztp/
|
|
234
|
-
|
|
235
|
-
## Changelog
|
|
236
|
-
|
|
237
|
-
### 1.0.0-beta.1
|
|
238
|
-
- Initial public beta release
|
|
239
|
-
- AI chat support (text generation)
|
|
240
|
-
- Image generation support
|
|
241
|
-
- NPC conversation management
|
|
242
|
-
- Authentication and player management
|
|
243
|
-
- Streaming response support
|
|
244
|
-
- Player balance management and recharge functionality
|
|
1
|
+
# PlayKit SDK for JavaScript
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/playkit)
|
|
4
|
+
|
|
5
|
+
JavaScript/TypeScript SDK for integrating AI capabilities into web-based games.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- AI-powered text generation using GPT models
|
|
10
|
+
- Image generation using DALL-E models
|
|
11
|
+
- NPC conversation management with automatic history tracking
|
|
12
|
+
- JWT-based authentication and token management
|
|
13
|
+
- Real-time streaming responses
|
|
14
|
+
- Framework-agnostic design (compatible with P5.js, Phaser, PixiJS, etc.)
|
|
15
|
+
- Multiple bundle formats (ESM, CJS, UMD)
|
|
16
|
+
- Encrypted token storage using Web Crypto API
|
|
17
|
+
- Full TypeScript support with type definitions
|
|
18
|
+
- Player balance management and recharge functionality
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install playkit-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Basic Setup
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { PlayKitSDK } from 'playkit-sdk';
|
|
32
|
+
|
|
33
|
+
const sdk = new PlayKitSDK({
|
|
34
|
+
gameId: 'your-game-id',
|
|
35
|
+
developerToken: 'your-dev-token', // For development
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await sdk.initialize();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Text Generation
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const chat = sdk.createChatClient('gpt-4o-mini');
|
|
45
|
+
|
|
46
|
+
// Simple chat
|
|
47
|
+
const response = await chat.chat('Hello, introduce yourself');
|
|
48
|
+
console.log(response);
|
|
49
|
+
|
|
50
|
+
// With system prompt
|
|
51
|
+
const response = await chat.chat(
|
|
52
|
+
'How should I explore this dungeon?',
|
|
53
|
+
'You are a wise dungeon guide.'
|
|
54
|
+
);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Streaming Text
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
await chat.chatStream(
|
|
61
|
+
'Tell a story about a brave knight',
|
|
62
|
+
(chunk) => {
|
|
63
|
+
process.stdout.write(chunk);
|
|
64
|
+
},
|
|
65
|
+
(fullText) => {
|
|
66
|
+
console.log('\nComplete:', fullText);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Image Generation
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const imageClient = sdk.createImageClient('dall-e-3');
|
|
75
|
+
|
|
76
|
+
const image = await imageClient.generate('A futuristic cyberpunk city at night');
|
|
77
|
+
|
|
78
|
+
console.log('Base64:', image.base64);
|
|
79
|
+
console.log('Data URL:', image.toDataURL());
|
|
80
|
+
|
|
81
|
+
// Display in browser
|
|
82
|
+
const imgElement = await image.toHTMLImage();
|
|
83
|
+
document.body.appendChild(imgElement);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### NPC Conversations
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const npc = sdk.createNPCClient({
|
|
90
|
+
systemPrompt: 'You are a mysterious wizard who speaks in riddles.',
|
|
91
|
+
temperature: 0.8,
|
|
92
|
+
maxHistoryLength: 20,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const reply1 = await npc.talk('Who are you?');
|
|
96
|
+
console.log('Wizard:', reply1);
|
|
97
|
+
|
|
98
|
+
const reply2 = await npc.talk('What is your quest?');
|
|
99
|
+
console.log('Wizard:', reply2);
|
|
100
|
+
|
|
101
|
+
// Save/load history
|
|
102
|
+
const savedHistory = npc.saveHistory();
|
|
103
|
+
localStorage.setItem('npc_history', savedHistory);
|
|
104
|
+
|
|
105
|
+
// Later...
|
|
106
|
+
npc.loadHistory(localStorage.getItem('npc_history'));
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Player Balance Management
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// Get player info and balance
|
|
113
|
+
const playerInfo = await sdk.getPlayerInfo();
|
|
114
|
+
console.log('Player ID:', playerInfo.userId);
|
|
115
|
+
console.log('Credits:', playerInfo.credits);
|
|
116
|
+
|
|
117
|
+
// Open recharge window
|
|
118
|
+
sdk.openRechargeWindow();
|
|
119
|
+
|
|
120
|
+
// Show insufficient balance modal
|
|
121
|
+
await sdk.showInsufficientBalanceModal();
|
|
122
|
+
|
|
123
|
+
// Enable automatic balance checking
|
|
124
|
+
sdk.enableAutoBalanceCheck(30000); // Check every 30 seconds
|
|
125
|
+
|
|
126
|
+
// Listen to balance events
|
|
127
|
+
sdk.on('balance_updated', (credits) => {
|
|
128
|
+
console.log('New balance:', credits);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
sdk.on('insufficient_credits', (error) => {
|
|
132
|
+
console.log('User needs to recharge');
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Usage with P5.js
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
let sdk, npc, generatedImage;
|
|
140
|
+
|
|
141
|
+
async function setup() {
|
|
142
|
+
createCanvas(800, 600);
|
|
143
|
+
|
|
144
|
+
sdk = new PlayKitSDK({
|
|
145
|
+
gameId: 'your-game-id',
|
|
146
|
+
developerToken: 'your-dev-token'
|
|
147
|
+
});
|
|
148
|
+
await sdk.initialize();
|
|
149
|
+
|
|
150
|
+
npc = sdk.createNPCClient({
|
|
151
|
+
systemPrompt: 'You are a friendly game character.'
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function mousePressed() {
|
|
156
|
+
const reply = await npc.talk('Hello!');
|
|
157
|
+
console.log(reply);
|
|
158
|
+
|
|
159
|
+
const imageClient = sdk.createImageClient();
|
|
160
|
+
const img = await imageClient.generate('A magical forest');
|
|
161
|
+
|
|
162
|
+
const htmlImg = await img.toHTMLImage();
|
|
163
|
+
generatedImage = loadImage(htmlImg.src);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function draw() {
|
|
167
|
+
background(220);
|
|
168
|
+
if (generatedImage) {
|
|
169
|
+
image(generatedImage, 0, 0, 400, 400);
|
|
170
|
+
}
|
|
171
|
+
text('Click to talk to NPC or generate image', 10, height - 20);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Usage with Vanilla JavaScript
|
|
176
|
+
|
|
177
|
+
```html
|
|
178
|
+
<!DOCTYPE html>
|
|
179
|
+
<html>
|
|
180
|
+
<head>
|
|
181
|
+
<script src="https://unpkg.com/playkit-sdk@latest/dist/index.umd.js"></script>
|
|
182
|
+
</head>
|
|
183
|
+
<body>
|
|
184
|
+
<div id="output"></div>
|
|
185
|
+
<input id="userInput" type="text" placeholder="Type a message...">
|
|
186
|
+
<button onclick="sendMessage()">Send</button>
|
|
187
|
+
|
|
188
|
+
<script>
|
|
189
|
+
let sdk, chat;
|
|
190
|
+
|
|
191
|
+
async function init() {
|
|
192
|
+
sdk = new PlayKitSDK.PlayKitSDK({
|
|
193
|
+
gameId: 'your-game-id',
|
|
194
|
+
developerToken: 'your-dev-token'
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
await sdk.initialize();
|
|
198
|
+
chat = sdk.createChatClient();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function sendMessage() {
|
|
202
|
+
const input = document.getElementById('userInput').value;
|
|
203
|
+
const output = document.getElementById('output');
|
|
204
|
+
|
|
205
|
+
output.innerHTML += `<p><strong>You:</strong> ${input}</p>`;
|
|
206
|
+
output.innerHTML += `<p><strong>AI:</strong> <span id="aiReply"></span></p>`;
|
|
207
|
+
|
|
208
|
+
const replyElement = document.getElementById('aiReply');
|
|
209
|
+
await chat.chatStream(
|
|
210
|
+
input,
|
|
211
|
+
(chunk) => { replyElement.innerHTML += chunk; }
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
document.getElementById('userInput').value = '';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
init();
|
|
218
|
+
</script>
|
|
219
|
+
</body>
|
|
220
|
+
</html>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
Proprietary License - see [LICENSE](LICENSE) file for details.
|
|
227
|
+
|
|
228
|
+
This SDK is proprietary software owned by Agentland Lab. Use of this SDK is subject to the terms and conditions of the license agreement.
|
|
229
|
+
|
|
230
|
+
## Support
|
|
231
|
+
|
|
232
|
+
- Email: support@playkit.ai
|
|
233
|
+
- Issues: [GitHub Issues](https://github.com/cnqdztp/PlayKit-JavascriptSDK/issues)
|
|
234
|
+
|
|
235
|
+
## Changelog
|
|
236
|
+
|
|
237
|
+
### 1.0.0-beta.1
|
|
238
|
+
- Initial public beta release
|
|
239
|
+
- AI chat support (text generation)
|
|
240
|
+
- Image generation support
|
|
241
|
+
- NPC conversation management
|
|
242
|
+
- Authentication and player management
|
|
243
|
+
- Streaming response support
|
|
244
|
+
- Player balance management and recharge functionality
|