rystem.playframework.client 0.1.0 → 0.1.1
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 +576 -100
- package/lib/engine/ClientInteractionRegistry.d.ts +1 -0
- package/lib/engine/ClientInteractionRegistry.d.ts.map +1 -0
- package/lib/engine/PlayFrameworkClient.d.ts +1 -0
- package/lib/engine/PlayFrameworkClient.d.ts.map +1 -0
- package/lib/engine/PlayFrameworkClient.js +22 -21
- package/lib/hooks/hooks.d.ts +1 -0
- package/lib/hooks/hooks.d.ts.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/models/AiSceneResponse.d.ts +3 -2
- package/lib/models/AiSceneResponse.d.ts.map +1 -0
- package/lib/models/ClientInteractionRequest.d.ts +1 -0
- package/lib/models/ClientInteractionRequest.d.ts.map +1 -0
- package/lib/models/ClientInteractionResult.d.ts +1 -0
- package/lib/models/ClientInteractionResult.d.ts.map +1 -0
- package/lib/models/ContentItem.d.ts +1 -0
- package/lib/models/ContentItem.d.ts.map +1 -0
- package/lib/models/PlayFrameworkRequest.d.ts +5 -6
- package/lib/models/PlayFrameworkRequest.d.ts.map +1 -0
- package/lib/servicecollection/PlayFrameworkServices.d.ts +1 -0
- package/lib/servicecollection/PlayFrameworkServices.d.ts.map +1 -0
- package/lib/servicecollection/PlayFrameworkSettings.d.ts +1 -0
- package/lib/servicecollection/PlayFrameworkSettings.d.ts.map +1 -0
- package/lib/utils/AIContentConverter.d.ts +1 -0
- package/lib/utils/AIContentConverter.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,104 +1,115 @@
|
|
|
1
|
-
# Rystem PlayFramework Client
|
|
1
|
+
# 🎮 Rystem PlayFramework Client
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
-
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
3
|
+
[](https://www.npmjs.com/package/@rystem/playframework-client)
|
|
4
|
+
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
> **Official TypeScript/JavaScript client for [Rystem PlayFramework](https://rystem.net) HTTP API**
|
|
8
|
+
|
|
9
|
+
Production-ready client with full support for:
|
|
10
|
+
- ✅ **Step-by-step streaming** (SSE) - Each scene/actor as separate event
|
|
11
|
+
- ✅ **Token-level streaming** (SSE) - Real-time text chunks
|
|
12
|
+
- ✅ **Client-side tools** - Camera, geolocation, file picker, microphone
|
|
13
|
+
- ✅ **Multi-modal content** - Images, audio, video, PDFs, URIs
|
|
14
|
+
- ✅ **React hooks** - `usePlayFramework()` for easy integration
|
|
15
|
+
- ✅ **Execution modes** - Direct, Planning, DynamicChaining, Scene
|
|
16
|
+
- ✅ **Configurable** - Headers, retry, error handling, timeouts
|
|
17
|
+
- ✅ **Type-safe** - Full TypeScript definitions
|
|
10
18
|
|
|
11
19
|
---
|
|
12
20
|
|
|
13
|
-
## Installation
|
|
21
|
+
## 📦 Installation
|
|
14
22
|
|
|
15
23
|
```bash
|
|
16
|
-
npm install rystem
|
|
24
|
+
npm install @rystem/playframework-client
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or with yarn:
|
|
28
|
+
```bash
|
|
29
|
+
yarn add @rystem/playframework-client
|
|
17
30
|
```
|
|
18
31
|
|
|
19
32
|
---
|
|
20
33
|
|
|
21
|
-
## Quick Start
|
|
34
|
+
## 🚀 Quick Start
|
|
22
35
|
|
|
23
36
|
### 1. Configure Client
|
|
24
37
|
|
|
25
38
|
```typescript
|
|
26
|
-
import { PlayFrameworkServices } from "rystem
|
|
39
|
+
import { PlayFrameworkServices } from "@rystem/playframework-client";
|
|
27
40
|
|
|
28
|
-
// Configure factory
|
|
29
|
-
PlayFrameworkServices.configure("
|
|
30
|
-
//
|
|
31
|
-
settings.
|
|
32
|
-
|
|
33
|
-
...headers,
|
|
34
|
-
"Authorization": `Bearer ${getToken()}`
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Add retry logic
|
|
39
|
-
settings.addErrorHandler(async (url, method, headers, body, error) => {
|
|
40
|
-
console.error("Request failed, retrying...", error);
|
|
41
|
-
return true; // Retry
|
|
42
|
-
});
|
|
41
|
+
// Configure factory (once at app startup)
|
|
42
|
+
await PlayFrameworkServices.configure("default", "http://localhost:5158/api/ai", settings => {
|
|
43
|
+
settings.timeout = 120_000; // 2 minutes
|
|
44
|
+
settings.maxReconnectAttempts = 3;
|
|
45
|
+
settings.reconnectBaseDelay = 1000;
|
|
43
46
|
});
|
|
44
47
|
```
|
|
45
48
|
|
|
46
49
|
### 2. Use Client (Vanilla JS/TS)
|
|
47
50
|
|
|
48
51
|
```typescript
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const client = PlayFrameworkServices.getClient("chat");
|
|
52
|
+
const client = PlayFrameworkServices.resolve("default");
|
|
52
53
|
|
|
53
54
|
// Step-by-step streaming
|
|
54
55
|
for await (const step of client.executeStepByStep({
|
|
55
|
-
|
|
56
|
-
sceneName: "ChatScene"
|
|
56
|
+
message: "Tell me a joke"
|
|
57
57
|
})) {
|
|
58
58
|
console.log(`[${step.status}] ${step.message}`);
|
|
59
|
-
// Output:
|
|
60
|
-
// [Planning] Analyzing request...
|
|
61
|
-
// [Running] Generating joke...
|
|
62
|
-
// [Running] Why did the chicken cross the road? To get to the other side!
|
|
63
59
|
}
|
|
60
|
+
// Output:
|
|
61
|
+
// [planning] Analyzing request...
|
|
62
|
+
// [executingScene] Generating joke...
|
|
63
|
+
// [completed] Why did the chicken cross the road? To get to the other side!
|
|
64
64
|
|
|
65
|
-
// Token-level streaming (
|
|
65
|
+
// Token-level streaming (real-time chunks)
|
|
66
66
|
for await (const chunk of client.executeTokenStreaming({
|
|
67
|
-
|
|
67
|
+
message: "Write a short story"
|
|
68
68
|
})) {
|
|
69
|
-
process.stdout.write(chunk.
|
|
70
|
-
// Output: "Once" → " upon" → " a" → " time" → "..."
|
|
69
|
+
process.stdout.write(chunk.streamingChunk || "");
|
|
71
70
|
}
|
|
71
|
+
// Output: "Once" → " upon" → " a" → " time" → "..."
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
### 3. Use with React
|
|
75
75
|
|
|
76
76
|
```tsx
|
|
77
|
-
import { usePlayFramework } from "rystem
|
|
77
|
+
import { usePlayFramework } from "@rystem/playframework-client";
|
|
78
78
|
import { useState } from "react";
|
|
79
79
|
|
|
80
80
|
function ChatComponent() {
|
|
81
|
-
const client = usePlayFramework("
|
|
81
|
+
const client = usePlayFramework("default");
|
|
82
82
|
const [messages, setMessages] = useState<string[]>([]);
|
|
83
|
+
const [loading, setLoading] = useState(false);
|
|
83
84
|
|
|
84
|
-
const handleSend = async () => {
|
|
85
|
+
const handleSend = async (input: string) => {
|
|
86
|
+
setLoading(true);
|
|
85
87
|
const newMessages: string[] = [];
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
try {
|
|
90
|
+
for await (const step of client.executeStepByStep({
|
|
91
|
+
message: input
|
|
92
|
+
})) {
|
|
93
|
+
if (step.streamingChunk) {
|
|
94
|
+
// Real-time token streaming
|
|
95
|
+
newMessages.push(step.streamingChunk);
|
|
96
|
+
} else if (step.message) {
|
|
97
|
+
// Step-by-step message
|
|
98
|
+
newMessages.push(`[${step.status}] ${step.message}`);
|
|
99
|
+
}
|
|
93
100
|
setMessages([...newMessages]);
|
|
94
101
|
}
|
|
102
|
+
} finally {
|
|
103
|
+
setLoading(false);
|
|
95
104
|
}
|
|
96
105
|
};
|
|
97
106
|
|
|
98
107
|
return (
|
|
99
108
|
<div>
|
|
100
|
-
<
|
|
101
|
-
|
|
109
|
+
<input onKeyDown={e => e.key === 'Enter' && handleSend(e.currentTarget.value)} />
|
|
110
|
+
<div>
|
|
111
|
+
{messages.map((msg, i) => <div key={i}>{msg}</div>)}
|
|
112
|
+
</div>
|
|
102
113
|
</div>
|
|
103
114
|
);
|
|
104
115
|
}
|
|
@@ -106,14 +117,169 @@ function ChatComponent() {
|
|
|
106
117
|
|
|
107
118
|
---
|
|
108
119
|
|
|
109
|
-
##
|
|
120
|
+
## 🎯 Core Features
|
|
121
|
+
|
|
122
|
+
### Step-by-Step vs Token Streaming
|
|
123
|
+
|
|
124
|
+
**Step-by-Step** (`executeStepByStep`):
|
|
125
|
+
- Returns each **scene/actor execution** as separate event
|
|
126
|
+
- Best for: Multi-step workflows, debugging, progress tracking
|
|
127
|
+
- Example: Planning → Actor1 → Actor2 → Completed
|
|
128
|
+
|
|
129
|
+
**Token Streaming** (`executeTokenStreaming`):
|
|
130
|
+
- Returns **individual text chunks** as they're generated
|
|
131
|
+
- Best for: Real-time chat UIs, typewriter effects
|
|
132
|
+
- Example: "Hello" → " world" → "!" → "..."
|
|
110
133
|
|
|
111
134
|
```typescript
|
|
112
|
-
|
|
135
|
+
// Step-by-step - structured workflow
|
|
136
|
+
for await (const step of client.executeStepByStep({ message: "..." })) {
|
|
137
|
+
console.log(step.status); // "planning", "executingScene", "completed"
|
|
138
|
+
console.log(step.sceneName); // "ChatScene"
|
|
139
|
+
console.log(step.message); // Full response
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Token streaming - real-time chunks
|
|
143
|
+
for await (const chunk of client.executeTokenStreaming({ message: "..." })) {
|
|
144
|
+
console.log(chunk.streamingChunk); // "Hello", " world", "!"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 🛠️ Client-Side Tools
|
|
151
|
+
|
|
152
|
+
Execute **browser-specific operations** (camera, geolocation, file picker) when LLM requests them.
|
|
153
|
+
|
|
154
|
+
### Server Setup (C#)
|
|
155
|
+
|
|
156
|
+
```csharp
|
|
157
|
+
services.AddPlayFramework(builder =>
|
|
158
|
+
{
|
|
159
|
+
builder.AddScene("vision", "Analyze user photos", scene =>
|
|
160
|
+
{
|
|
161
|
+
scene.OnClient(client =>
|
|
162
|
+
{
|
|
163
|
+
client.AddTool("capturePhoto", "Take photo from camera");
|
|
164
|
+
client.AddTool("getCurrentLocation", "Get GPS coordinates");
|
|
165
|
+
client.AddTool("selectFiles", "Open file picker");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Client Setup (TypeScript)
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { PlayFrameworkServices, AIContentConverter } from "@rystem/playframework-client";
|
|
175
|
+
|
|
176
|
+
const client = PlayFrameworkServices.resolve("default");
|
|
177
|
+
const registry = client.getClientRegistry();
|
|
178
|
+
|
|
179
|
+
// Register camera tool
|
|
180
|
+
registry.register("capturePhoto", async () => {
|
|
181
|
+
const content = await AIContentConverter.fromCamera(
|
|
182
|
+
{ video: { facingMode: "environment" } }, // Rear camera
|
|
183
|
+
1920, 1080
|
|
184
|
+
);
|
|
185
|
+
return [content];
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Register geolocation tool
|
|
189
|
+
registry.register("getCurrentLocation", async () => {
|
|
190
|
+
const content = await AIContentConverter.fromGeolocation({ timeout: 10_000 });
|
|
191
|
+
return [content];
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Register file picker
|
|
195
|
+
registry.register("selectFiles", async (args?: { accept?: string }) => {
|
|
196
|
+
return new Promise((resolve) => {
|
|
197
|
+
const input = document.createElement("input");
|
|
198
|
+
input.type = "file";
|
|
199
|
+
input.accept = args?.accept || "*/*";
|
|
200
|
+
input.onchange = async () => {
|
|
201
|
+
const contents = await AIContentConverter.fromMultipleFiles(input.files!);
|
|
202
|
+
resolve(contents);
|
|
203
|
+
};
|
|
204
|
+
input.click();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**Client automatically resumes execution after tool completion!**
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
for await (const step of client.executeStepByStep({ message: "Take a photo and describe it" })) {
|
|
213
|
+
console.log(step.status);
|
|
214
|
+
// 1. "executingScene" - LLM requests camera
|
|
215
|
+
// 2. "awaitingClient" - Client executes tool
|
|
216
|
+
// 3. "executingScene" - LLM analyzes photo
|
|
217
|
+
// 4. "completed" - Final response
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### AIContentConverter Helpers
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
// Camera (returns Base64 JPEG)
|
|
225
|
+
const photo = await AIContentConverter.fromCamera();
|
|
226
|
+
|
|
227
|
+
// Geolocation (returns JSON with lat/lng)
|
|
228
|
+
const location = await AIContentConverter.fromGeolocation();
|
|
229
|
+
|
|
230
|
+
// File upload (returns Base64 data)
|
|
231
|
+
const file = await AIContentConverter.fromFile(fileInput.files[0]);
|
|
232
|
+
|
|
233
|
+
// Multiple files
|
|
234
|
+
const files = await AIContentConverter.fromMultipleFiles(fileInput.files);
|
|
235
|
+
|
|
236
|
+
// Microphone (returns Base64 audio)
|
|
237
|
+
const audio = await AIContentConverter.fromMicrophone(5000); // 5 seconds
|
|
238
|
+
|
|
239
|
+
// Plain text
|
|
240
|
+
const text = AIContentConverter.fromText("Hello world");
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## 🎛️ Execution Modes
|
|
246
|
+
|
|
247
|
+
Control **how scenes are selected and executed**:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { PlayFrameworkRequest } from "@rystem/playframework-client";
|
|
251
|
+
|
|
252
|
+
const request: PlayFrameworkRequest = {
|
|
253
|
+
message: "Book a flight to Paris",
|
|
254
|
+
settings: {
|
|
255
|
+
executionMode: "Planning", // Direct | Planning | DynamicChaining | Scene
|
|
256
|
+
maxRecursionDepth: 5,
|
|
257
|
+
enableSummarization: true,
|
|
258
|
+
enableDirector: false
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Available Modes
|
|
264
|
+
|
|
265
|
+
| Mode | Description | Use Case |
|
|
266
|
+
|------|-------------|----------|
|
|
267
|
+
| `Direct` | Single scene, no planning | Simple queries, fast responses |
|
|
268
|
+
| `Planning` | Upfront multi-step plan | Known workflows (booking, checkout) |
|
|
269
|
+
| `DynamicChaining` | LLM decides next step live | Exploratory tasks (research, debugging) |
|
|
270
|
+
| `Scene` | Execute specific scene by name | Resuming after client interaction |
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## 📸 Multi-Modal Content
|
|
275
|
+
|
|
276
|
+
Send **images, audio, video, PDFs, URIs** with your request:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { PlayFrameworkRequest, ContentItem } from "@rystem/playframework-client";
|
|
113
280
|
|
|
114
281
|
const request: PlayFrameworkRequest = {
|
|
115
|
-
|
|
116
|
-
sceneName: "VisionScene",
|
|
282
|
+
message: "Describe this image and summarize the PDF",
|
|
117
283
|
contents: [
|
|
118
284
|
{
|
|
119
285
|
type: "image",
|
|
@@ -121,13 +287,18 @@ const request: PlayFrameworkRequest = {
|
|
|
121
287
|
mediaType: "image/png"
|
|
122
288
|
},
|
|
123
289
|
{
|
|
124
|
-
type: "
|
|
125
|
-
|
|
290
|
+
type: "data",
|
|
291
|
+
base64Data: "JVBERi0xLjQKJeLjz9M...",
|
|
292
|
+
mediaType: "application/pdf"
|
|
126
293
|
},
|
|
127
294
|
{
|
|
128
295
|
type: "uri",
|
|
129
296
|
uri: "https://example.com/document.pdf",
|
|
130
297
|
mediaType: "application/pdf"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
type: "text",
|
|
301
|
+
text: "Additional context"
|
|
131
302
|
}
|
|
132
303
|
]
|
|
133
304
|
};
|
|
@@ -139,26 +310,28 @@ for await (const step of client.executeStepByStep(request)) {
|
|
|
139
310
|
|
|
140
311
|
---
|
|
141
312
|
|
|
142
|
-
## Configuration
|
|
313
|
+
## ⚙️ Configuration & Settings
|
|
314
|
+
|
|
315
|
+
### Global Configuration
|
|
143
316
|
|
|
144
317
|
```typescript
|
|
145
|
-
PlayFrameworkServices
|
|
146
|
-
|
|
147
|
-
|
|
318
|
+
import { PlayFrameworkServices } from "@rystem/playframework-client";
|
|
319
|
+
|
|
320
|
+
await PlayFrameworkServices.configure("premium", "https://api.example.com/api/ai", settings => {
|
|
321
|
+
// Timeout (ms)
|
|
322
|
+
settings.timeout = 120_000; // 2 minutes
|
|
148
323
|
|
|
149
|
-
//
|
|
150
|
-
settings.
|
|
324
|
+
// Reconnection on SSE failures
|
|
325
|
+
settings.maxReconnectAttempts = 3;
|
|
326
|
+
settings.reconnectBaseDelay = 1000; // 1 second
|
|
151
327
|
|
|
152
328
|
// Default headers
|
|
153
329
|
settings.defaultHeaders = {
|
|
154
330
|
"Content-Type": "application/json",
|
|
155
|
-
"X-
|
|
331
|
+
"X-App-Version": "1.0.0"
|
|
156
332
|
};
|
|
157
333
|
|
|
158
|
-
//
|
|
159
|
-
settings.timeout = 120000; // 2 minutes
|
|
160
|
-
|
|
161
|
-
// Add dynamic headers (e.g., auth token)
|
|
334
|
+
// Dynamic headers (auth token)
|
|
162
335
|
settings.addHeadersEnricher(async (url, method, headers, body) => {
|
|
163
336
|
const token = await getAuthToken();
|
|
164
337
|
return {
|
|
@@ -170,7 +343,7 @@ PlayFrameworkServices.configure("premium", "https://api.example.com/api/ai/premi
|
|
|
170
343
|
// Error handling with retry
|
|
171
344
|
settings.addErrorHandler(async (url, method, headers, body, error) => {
|
|
172
345
|
if (error.message.includes("401")) {
|
|
173
|
-
await
|
|
346
|
+
await refreshAuthToken();
|
|
174
347
|
return true; // Retry
|
|
175
348
|
}
|
|
176
349
|
return false; // Don't retry
|
|
@@ -178,20 +351,95 @@ PlayFrameworkServices.configure("premium", "https://api.example.com/api/ai/premi
|
|
|
178
351
|
});
|
|
179
352
|
```
|
|
180
353
|
|
|
354
|
+
### Per-Request Settings
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
const request: PlayFrameworkRequest = {
|
|
358
|
+
message: "Your query",
|
|
359
|
+
settings: {
|
|
360
|
+
// Execution mode
|
|
361
|
+
executionMode: "Planning", // Direct | Planning | DynamicChaining | Scene
|
|
362
|
+
|
|
363
|
+
// Planning settings
|
|
364
|
+
maxRecursionDepth: 5, // Max planning depth
|
|
365
|
+
maxDynamicScenes: 10, // Max scenes in DynamicChaining
|
|
366
|
+
|
|
367
|
+
// Features
|
|
368
|
+
enableSummarization: true, // Auto-summarize long contexts
|
|
369
|
+
enableDirector: false, // Multi-scene orchestration
|
|
370
|
+
enableStreaming: true, // Token-level streaming
|
|
371
|
+
|
|
372
|
+
// Model overrides
|
|
373
|
+
modelId: "gpt-4o", // Override default model
|
|
374
|
+
temperature: 0.7, // 0.0 - 2.0
|
|
375
|
+
maxTokens: 4096, // Max response tokens
|
|
376
|
+
|
|
377
|
+
// Caching
|
|
378
|
+
cacheBehavior: "Default", // Default | Avoidable | Forever
|
|
379
|
+
conversationKey: "user-123-session-1", // Unique conversation ID
|
|
380
|
+
|
|
381
|
+
// Budget
|
|
382
|
+
maxBudget: 0.50, // Max cost in USD (null = unlimited)
|
|
383
|
+
|
|
384
|
+
// Scene selection (Scene mode only)
|
|
385
|
+
sceneName: "SpecificScene" // Execute specific scene
|
|
386
|
+
},
|
|
387
|
+
metadata: {
|
|
388
|
+
userId: "user-123",
|
|
389
|
+
sessionId: "session-abc",
|
|
390
|
+
customKey: "customValue"
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## 🔄 Conversation State & Caching
|
|
398
|
+
|
|
399
|
+
Use `conversationKey` to maintain **multi-turn conversations**:
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
const conversationKey = crypto.randomUUID();
|
|
403
|
+
|
|
404
|
+
// First request
|
|
405
|
+
for await (const step of client.executeStepByStep({
|
|
406
|
+
message: "What's the weather in Paris?",
|
|
407
|
+
settings: { conversationKey }
|
|
408
|
+
})) {
|
|
409
|
+
console.log(step.message);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Follow-up request (uses cached context)
|
|
413
|
+
for await (const step of client.executeStepByStep({
|
|
414
|
+
message: "And in London?",
|
|
415
|
+
settings: { conversationKey }
|
|
416
|
+
})) {
|
|
417
|
+
console.log(step.message); // LLM remembers Paris context
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
181
421
|
---
|
|
182
422
|
|
|
183
|
-
## Cancellation
|
|
423
|
+
## 🚫 Cancellation
|
|
424
|
+
|
|
425
|
+
Use `AbortController` to **cancel ongoing requests**:
|
|
184
426
|
|
|
185
427
|
```typescript
|
|
186
428
|
const controller = new AbortController();
|
|
187
429
|
|
|
188
430
|
// Start streaming
|
|
189
431
|
const promise = (async () => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
432
|
+
try {
|
|
433
|
+
for await (const step of client.executeStepByStep(
|
|
434
|
+
{ message: "Long task..." },
|
|
435
|
+
controller.signal
|
|
436
|
+
)) {
|
|
437
|
+
console.log(step.message);
|
|
438
|
+
}
|
|
439
|
+
} catch (error) {
|
|
440
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
441
|
+
console.log("Request cancelled");
|
|
442
|
+
}
|
|
195
443
|
}
|
|
196
444
|
})();
|
|
197
445
|
|
|
@@ -201,65 +449,293 @@ setTimeout(() => controller.abort(), 5000);
|
|
|
201
449
|
|
|
202
450
|
---
|
|
203
451
|
|
|
204
|
-
##
|
|
452
|
+
## 📊 Response Status Types
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
type AiResponseStatus =
|
|
456
|
+
| "initializing" // Starting execution
|
|
457
|
+
| "planning" // Creating execution plan
|
|
458
|
+
| "executingScene" // Running scene/actor
|
|
459
|
+
| "functionRequest" // Calling server-side tool
|
|
460
|
+
| "functionCompleted" // Tool call completed
|
|
461
|
+
| "streaming" // Streaming text chunks
|
|
462
|
+
| "awaitingClient" // Waiting for client-side tool
|
|
463
|
+
| "completed" // Success
|
|
464
|
+
| "error" // Failure
|
|
465
|
+
| "budgetExceeded"; // Max cost exceeded
|
|
466
|
+
```
|
|
205
467
|
|
|
206
|
-
|
|
468
|
+
---
|
|
207
469
|
|
|
208
|
-
|
|
470
|
+
## 🧪 Testing
|
|
209
471
|
|
|
210
|
-
|
|
472
|
+
```typescript
|
|
473
|
+
import { PlayFrameworkClient, PlayFrameworkSettings } from "@rystem/playframework-client";
|
|
211
474
|
|
|
212
|
-
|
|
475
|
+
describe("PlayFramework Client", () => {
|
|
476
|
+
it("should stream responses", async () => {
|
|
477
|
+
const settings = new PlayFrameworkSettings("default", "http://localhost:5158/api/ai");
|
|
478
|
+
const client = new PlayFrameworkClient(settings);
|
|
213
479
|
|
|
214
|
-
|
|
480
|
+
const responses: string[] = [];
|
|
215
481
|
|
|
216
|
-
|
|
482
|
+
for await (const step of client.executeStepByStep({ message: "Test" })) {
|
|
483
|
+
if (step.message) responses.push(step.message);
|
|
484
|
+
}
|
|
217
485
|
|
|
218
|
-
|
|
486
|
+
expect(responses.length).toBeGreaterThan(0);
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
```
|
|
219
490
|
|
|
220
491
|
---
|
|
221
492
|
|
|
222
|
-
|
|
493
|
+
## 📚 API Reference
|
|
494
|
+
|
|
495
|
+
### `PlayFrameworkServices`
|
|
223
496
|
|
|
224
|
-
#### `configure(name, baseUrl, configure
|
|
497
|
+
#### `configure(name: string, baseUrl: string, configure?: (settings: PlayFrameworkSettings) => void): Promise<PlayFrameworkSettings>`
|
|
225
498
|
|
|
226
499
|
Configure a PlayFramework client factory.
|
|
227
500
|
|
|
228
501
|
```typescript
|
|
229
|
-
PlayFrameworkServices.configure("chat", "
|
|
502
|
+
await PlayFrameworkServices.configure("chat", "http://localhost:5158/api/ai");
|
|
230
503
|
```
|
|
231
504
|
|
|
232
|
-
#### `
|
|
505
|
+
#### `resolve(name: string): PlayFrameworkClient`
|
|
233
506
|
|
|
234
|
-
Get configured client.
|
|
507
|
+
Get configured client instance.
|
|
235
508
|
|
|
236
509
|
```typescript
|
|
237
|
-
const client = PlayFrameworkServices.
|
|
510
|
+
const client = PlayFrameworkServices.resolve("chat");
|
|
238
511
|
```
|
|
239
512
|
|
|
240
|
-
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
### `PlayFrameworkClient`
|
|
516
|
+
|
|
517
|
+
#### `executeStepByStep(request: PlayFrameworkRequest, signal?: AbortSignal): AsyncIterableIterator<AiSceneResponse>`
|
|
518
|
+
|
|
519
|
+
Execute with **step-by-step streaming** (each scene as separate event).
|
|
520
|
+
|
|
521
|
+
#### `executeTokenStreaming(request: PlayFrameworkRequest, signal?: AbortSignal): AsyncIterableIterator<AiSceneResponse>`
|
|
522
|
+
|
|
523
|
+
Execute with **token-level streaming** (each text chunk as separate event).
|
|
241
524
|
|
|
242
|
-
|
|
525
|
+
#### `getClientRegistry(): ClientInteractionRegistry`
|
|
526
|
+
|
|
527
|
+
Get registry for client-side tools.
|
|
528
|
+
|
|
529
|
+
---
|
|
530
|
+
|
|
531
|
+
### `ClientInteractionRegistry`
|
|
532
|
+
|
|
533
|
+
#### `register<TArgs = any>(toolName: string, handler: ClientTool<TArgs>): void`
|
|
534
|
+
|
|
535
|
+
Register client-side tool.
|
|
243
536
|
|
|
244
537
|
```typescript
|
|
245
|
-
|
|
246
|
-
|
|
538
|
+
registry.register("myTool", async (args?: { key: string }) => {
|
|
539
|
+
return [AIContentConverter.fromText(args?.key || "default")];
|
|
540
|
+
});
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
---
|
|
544
|
+
|
|
545
|
+
### `AIContentConverter`
|
|
546
|
+
|
|
547
|
+
#### Static Methods
|
|
548
|
+
|
|
549
|
+
- `fromCamera(constraints?, width?, height?): Promise<AIContent>` - Capture photo
|
|
550
|
+
- `fromGeolocation(options?): Promise<AIContent>` - Get GPS coordinates
|
|
551
|
+
- `fromFile(file: File | Blob): Promise<AIContent>` - Convert file to Base64
|
|
552
|
+
- `fromMultipleFiles(files: FileList): Promise<AIContent[]>` - Convert multiple files
|
|
553
|
+
- `fromMicrophone(durationMs?: number, mimeType?: string): Promise<AIContent>` - Record audio
|
|
554
|
+
- `fromText(text: string): AIContent` - Create text content
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
## 🎨 React Hook (`usePlayFramework`)
|
|
559
|
+
|
|
560
|
+
```tsx
|
|
561
|
+
import { usePlayFramework } from "@rystem/playframework-client";
|
|
562
|
+
|
|
563
|
+
function MyComponent() {
|
|
564
|
+
const client = usePlayFramework("default");
|
|
565
|
+
|
|
566
|
+
const handleClick = async () => {
|
|
567
|
+
for await (const step of client.executeStepByStep({ message: "Hello" })) {
|
|
568
|
+
console.log(step);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
return <button onClick={handleClick}>Send</button>;
|
|
573
|
+
}
|
|
247
574
|
```
|
|
248
575
|
|
|
249
576
|
---
|
|
250
577
|
|
|
251
|
-
|
|
578
|
+
## 📁 Where to Place This README
|
|
579
|
+
|
|
580
|
+
This README should be placed in:
|
|
581
|
+
```
|
|
582
|
+
src/AI/Rystem.PlayFramework.Client/src/rystem/README.md
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
This is the **library source** directory that gets published to npm.
|
|
586
|
+
|
|
587
|
+
---
|
|
588
|
+
|
|
589
|
+
## 🔗 Links
|
|
590
|
+
|
|
591
|
+
- 📖 **Documentation**: https://rystem.net/playframework
|
|
592
|
+
- 💻 **GitHub**: https://github.com/KeyserDSoze/Rystem
|
|
593
|
+
- 📦 **npm**: https://www.npmjs.com/package/@rystem/playframework-client
|
|
594
|
+
- 🎯 **MCP Tools**: https://rystem.net/mcp
|
|
595
|
+
|
|
596
|
+
---
|
|
597
|
+
|
|
598
|
+
## 📄 License
|
|
599
|
+
|
|
600
|
+
MIT © [Alessandro Rapiti](https://github.com/KeyserDSoze)
|
|
252
601
|
|
|
253
|
-
|
|
602
|
+
---
|
|
254
603
|
|
|
255
|
-
|
|
604
|
+
## 🤝 Contributing
|
|
256
605
|
|
|
257
|
-
|
|
606
|
+
Contributions welcome! Please open an issue or PR.
|
|
258
607
|
|
|
259
|
-
|
|
608
|
+
1. Fork the repo
|
|
609
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
610
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
611
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
612
|
+
5. Open a Pull Request
|
|
260
613
|
|
|
261
614
|
---
|
|
262
615
|
|
|
263
|
-
##
|
|
616
|
+
## 💡 Examples
|
|
617
|
+
|
|
618
|
+
### Complete Chat Application
|
|
619
|
+
|
|
620
|
+
```tsx
|
|
621
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
622
|
+
import { usePlayFramework, AIContentConverter } from '@rystem/playframework-client';
|
|
623
|
+
|
|
624
|
+
interface Message {
|
|
625
|
+
role: 'user' | 'assistant';
|
|
626
|
+
text: string;
|
|
627
|
+
status?: string;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function ChatApp() {
|
|
631
|
+
const client = usePlayFramework('default');
|
|
632
|
+
const [messages, setMessages] = useState<Message[]>([]);
|
|
633
|
+
const [input, setInput] = useState('');
|
|
634
|
+
const [loading, setLoading] = useState(false);
|
|
635
|
+
const [conversationKey] = useState(crypto.randomUUID());
|
|
636
|
+
|
|
637
|
+
// Register client tools
|
|
638
|
+
useEffect(() => {
|
|
639
|
+
const registry = client.getClientRegistry();
|
|
640
|
+
|
|
641
|
+
registry.register('getCurrentLocation', async () => {
|
|
642
|
+
const content = await AIContentConverter.fromGeolocation();
|
|
643
|
+
return [content];
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
registry.register('getUserConfirmation', async (args?: { question?: string }) => {
|
|
647
|
+
const confirmed = window.confirm(args?.question ?? 'Do you confirm?');
|
|
648
|
+
return [AIContentConverter.fromText(confirmed ? 'confirmed' : 'denied')];
|
|
649
|
+
});
|
|
650
|
+
}, [client]);
|
|
651
|
+
|
|
652
|
+
const handleSend = async () => {
|
|
653
|
+
if (!input.trim() || loading) return;
|
|
654
|
+
|
|
655
|
+
const userMessage: Message = { role: 'user', text: input };
|
|
656
|
+
setMessages(prev => [...prev, userMessage]);
|
|
657
|
+
setInput('');
|
|
658
|
+
setLoading(true);
|
|
659
|
+
|
|
660
|
+
try {
|
|
661
|
+
const assistantMessage: Message = { role: 'assistant', text: '', status: 'initializing' };
|
|
662
|
+
setMessages(prev => [...prev, assistantMessage]);
|
|
663
|
+
|
|
664
|
+
for await (const step of client.executeStepByStep({
|
|
665
|
+
message: input,
|
|
666
|
+
settings: {
|
|
667
|
+
conversationKey,
|
|
668
|
+
executionMode: 'Direct',
|
|
669
|
+
enableStreaming: true
|
|
670
|
+
}
|
|
671
|
+
})) {
|
|
672
|
+
setMessages(prev => {
|
|
673
|
+
const updated = [...prev];
|
|
674
|
+
const last = updated[updated.length - 1];
|
|
675
|
+
|
|
676
|
+
if (step.streamingChunk) {
|
|
677
|
+
last.text += step.streamingChunk;
|
|
678
|
+
} else if (step.message) {
|
|
679
|
+
last.text = step.message;
|
|
680
|
+
}
|
|
681
|
+
last.status = step.status;
|
|
682
|
+
|
|
683
|
+
return updated;
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
} catch (error) {
|
|
687
|
+
console.error('Chat error:', error);
|
|
688
|
+
setMessages(prev => [...prev, {
|
|
689
|
+
role: 'assistant',
|
|
690
|
+
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
691
|
+
status: 'error'
|
|
692
|
+
}]);
|
|
693
|
+
} finally {
|
|
694
|
+
setLoading(false);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
return (
|
|
699
|
+
<div style={{ maxWidth: '800px', margin: '0 auto', padding: '20px' }}>
|
|
700
|
+
<h1>PlayFramework Chat</h1>
|
|
701
|
+
|
|
702
|
+
<div style={{ height: '500px', overflowY: 'auto', border: '1px solid #ccc', padding: '10px', marginBottom: '10px' }}>
|
|
703
|
+
{messages.map((msg, i) => (
|
|
704
|
+
<div key={i} style={{
|
|
705
|
+
padding: '10px',
|
|
706
|
+
margin: '5px 0',
|
|
707
|
+
borderRadius: '8px',
|
|
708
|
+
backgroundColor: msg.role === 'user' ? '#e3f2fd' : '#f5f5f5',
|
|
709
|
+
textAlign: msg.role === 'user' ? 'right' : 'left'
|
|
710
|
+
}}>
|
|
711
|
+
<strong>{msg.role === 'user' ? 'You' : 'AI'}</strong>
|
|
712
|
+
{msg.status && <small style={{ color: '#666', marginLeft: '8px' }}>[{msg.status}]</small>}
|
|
713
|
+
<div>{msg.text}</div>
|
|
714
|
+
</div>
|
|
715
|
+
))}
|
|
716
|
+
</div>
|
|
717
|
+
|
|
718
|
+
<div style={{ display: 'flex', gap: '10px' }}>
|
|
719
|
+
<input
|
|
720
|
+
type="text"
|
|
721
|
+
value={input}
|
|
722
|
+
onChange={e => setInput(e.target.value)}
|
|
723
|
+
onKeyDown={e => e.key === 'Enter' && handleSend()}
|
|
724
|
+
placeholder="Type a message..."
|
|
725
|
+
disabled={loading}
|
|
726
|
+
style={{ flex: 1, padding: '10px', fontSize: '16px' }}
|
|
727
|
+
/>
|
|
728
|
+
<button onClick={handleSend} disabled={loading} style={{ padding: '10px 20px', fontSize: '16px' }}>
|
|
729
|
+
{loading ? 'Sending...' : 'Send'}
|
|
730
|
+
</button>
|
|
731
|
+
</div>
|
|
732
|
+
</div>
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
export default ChatApp;
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
---
|
|
264
740
|
|
|
265
|
-
|
|
741
|
+
**Made with ❤️ by the Rystem team**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientInteractionRegistry.d.ts","sourceRoot":"","sources":["../../src/engine/ClientInteractionRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEvF;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;AAE7E;;;GAGG;AACH,qBAAa,yBAAyB;IAClC,OAAO,CAAC,KAAK,CAAsC;IAEnD;;;;;;;;;;;OAWG;IACI,QAAQ,CAAC,KAAK,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI;IAOvF;;;;;;;;OAQG;IACU,OAAO,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IA+CzF;;OAEG;IACI,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIrC;;OAEG;IACI,YAAY,IAAI,MAAM,EAAE;IAI/B;;OAEG;IACI,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI5C;;OAEG;IACI,KAAK,IAAI,IAAI;CAGvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlayFrameworkClient.d.ts","sourceRoot":"","sources":["../../src/engine/PlayFrameworkClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAyB,MAAM,2BAA2B,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAGxE;;;GAGG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,cAAc,CAA4B;gBAEtC,QAAQ,EAAE,qBAAqB,EAAE,cAAc,CAAC,EAAE,yBAAyB;IAKvF;;OAEG;IACI,iBAAiB,IAAI,yBAAyB;IAIrD;;;;;;;OAOG;IACW,iBAAiB,CAC3B,OAAO,EAAE,oBAAoB,EAC7B,MAAM,CAAC,EAAE,WAAW,GACrB,qBAAqB,CAAC,eAAe,CAAC;IAKzC;;;;;;;OAOG;IACW,qBAAqB,CAC/B,OAAO,EAAE,oBAAoB,EAC7B,MAAM,CAAC,EAAE,WAAW,GACrB,qBAAqB,CAAC,eAAe,CAAC;IAKzC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAuB3B;;;OAGG;YACY,SAAS;CA6J3B"}
|
|
@@ -78,6 +78,7 @@ class PlayFrameworkClient {
|
|
|
78
78
|
while (shouldContinue) {
|
|
79
79
|
const headers = await this.settings.enrichHeaders(url, "POST", undefined, currentRequest);
|
|
80
80
|
let reconnectAttempts = 0;
|
|
81
|
+
let awaitingClientResponse = null; // Reset for each request iteration
|
|
81
82
|
let shouldRetry = true;
|
|
82
83
|
while (shouldRetry) {
|
|
83
84
|
try {
|
|
@@ -98,7 +99,6 @@ class PlayFrameworkClient {
|
|
|
98
99
|
const reader = response.body.getReader();
|
|
99
100
|
const decoder = new TextDecoder();
|
|
100
101
|
let buffer = "";
|
|
101
|
-
let awaitingClientResponse = null;
|
|
102
102
|
try {
|
|
103
103
|
while (true) {
|
|
104
104
|
const { done, value } = await reader.read();
|
|
@@ -124,54 +124,55 @@ class PlayFrameworkClient {
|
|
|
124
124
|
}
|
|
125
125
|
// Check for completion/error markers
|
|
126
126
|
if (event.status === "completed") {
|
|
127
|
-
shouldContinue = false
|
|
128
|
-
|
|
127
|
+
// Don't set shouldContinue = false yet - check if client interaction needed first
|
|
128
|
+
shouldRetry = false; // Don't retry, stream closed successfully
|
|
129
|
+
break; // Exit read loop to handle client interaction if needed
|
|
129
130
|
}
|
|
130
131
|
if (event.status === "error") {
|
|
131
132
|
shouldContinue = false;
|
|
133
|
+
shouldRetry = false; // Don't retry on error
|
|
132
134
|
throw new Error(event.errorMessage || "Unknown error");
|
|
133
135
|
}
|
|
134
|
-
// Check for AwaitingClient status
|
|
135
|
-
if (event.status === "
|
|
136
|
+
// Check for AwaitingClient status (camelCase from server)
|
|
137
|
+
if (event.status === "awaitingClient") {
|
|
136
138
|
awaitingClientResponse = event;
|
|
139
|
+
console.log('⏸️ [PlayFrameworkClient] Received awaitingClient, tool:', awaitingClientResponse.clientInteractionRequest?.toolName);
|
|
137
140
|
yield awaitingClientResponse; // Yield to user
|
|
138
|
-
|
|
141
|
+
// Don't break - continue reading until stream closes
|
|
142
|
+
continue; // Skip the second yield below to avoid duplication
|
|
139
143
|
}
|
|
140
144
|
// Yield valid AiSceneResponse
|
|
141
145
|
yield event;
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
|
-
//
|
|
145
|
-
if (
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
+
// Continue reading stream until "completed" event - don't exit early
|
|
149
|
+
// even if AwaitingClient was received (stream must close properly)
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
finally {
|
|
151
153
|
reader.releaseLock();
|
|
152
154
|
}
|
|
153
155
|
shouldRetry = false; // Success, no retry
|
|
154
|
-
// Handle client interaction if AwaitingClient
|
|
155
|
-
if (awaitingClientResponse?.clientInteractionRequest) {
|
|
156
|
+
// Handle client interaction if AwaitingClient (and stream wasn't closed by completed/error)
|
|
157
|
+
if (shouldContinue && awaitingClientResponse?.clientInteractionRequest) {
|
|
156
158
|
const clientRequest = awaitingClientResponse.clientInteractionRequest;
|
|
159
|
+
console.log('🔧 [PlayFrameworkClient] Executing client tool:', clientRequest.toolName);
|
|
157
160
|
// Execute client tool
|
|
158
161
|
const result = await this.clientRegistry.execute(clientRequest);
|
|
159
|
-
|
|
162
|
+
console.log('✅ [PlayFrameworkClient] Client tool completed, resuming with results');
|
|
163
|
+
// Prepare new request with client interaction results
|
|
164
|
+
// The server uses conversationKey + cache to restore context
|
|
160
165
|
currentRequest = {
|
|
161
166
|
...currentRequest,
|
|
162
|
-
|
|
163
|
-
clientInteractionResults: [result],
|
|
164
|
-
settings: {
|
|
165
|
-
...currentRequest.settings,
|
|
166
|
-
continuationToken: awaitingClientResponse.continuationToken,
|
|
167
|
-
clientInteractionResults: [result]
|
|
168
|
-
}
|
|
167
|
+
clientInteractionResults: [result]
|
|
169
168
|
};
|
|
169
|
+
console.log('📤 [PlayFrameworkClient] Sending resume request with clientInteractionResults');
|
|
170
170
|
// Continue loop to resume execution
|
|
171
171
|
shouldContinue = true;
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
174
|
-
|
|
174
|
+
console.log('✅ [PlayFrameworkClient] Stream completed normally (no client interaction)');
|
|
175
|
+
shouldContinue = false; // Normal completion or already closed by completed/error
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
catch (error) {
|
package/lib/hooks/hooks.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/hooks/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAGpE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAEnE"}
|
package/lib/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export { AIContentConverter } from "./utils/AIContentConverter";
|
|
|
10
10
|
export { PlayFrameworkSettings } from "./servicecollection/PlayFrameworkSettings";
|
|
11
11
|
export { PlayFrameworkServices } from "./servicecollection/PlayFrameworkServices";
|
|
12
12
|
export { usePlayFramework } from "./hooks/hooks";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,YAAY,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnI,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC3H,YAAY,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAClF,YAAY,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAG3F,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,YAAY,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAGrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ClientInteractionRequest } from "./ClientInteractionRequest";
|
|
2
2
|
/**
|
|
3
3
|
* Response status from PlayFramework execution.
|
|
4
|
-
* Matches all 18 C# AiResponseStatus enum values (serialized as
|
|
4
|
+
* Matches all 18 C# AiResponseStatus enum values (serialized as camelCase via JsonStringEnumConverter).
|
|
5
5
|
*/
|
|
6
|
-
export type AiResponseStatus = "
|
|
6
|
+
export type AiResponseStatus = "initializing" | "loadingCache" | "executingMainActors" | "planning" | "executingScene" | "functionRequest" | "functionCompleted" | "toolSkipped" | "streaming" | "running" | "summarizing" | "directorDecision" | "generatingFinalResponse" | "savingCache" | "savingMemory" | "awaitingClient" | "completed" | "budgetExceeded" | "error";
|
|
7
7
|
/**
|
|
8
8
|
* Single step response from PlayFramework (used in step-by-step streaming).
|
|
9
9
|
* Matches C# AiSceneResponse contract.
|
|
@@ -116,3 +116,4 @@ export interface ErrorMarker {
|
|
|
116
116
|
* SSE event types.
|
|
117
117
|
*/
|
|
118
118
|
export type SSEEvent = AiSceneResponse | CompletionMarker | ErrorMarker;
|
|
119
|
+
//# sourceMappingURL=AiSceneResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiSceneResponse.d.ts","sourceRoot":"","sources":["../../src/models/AiSceneResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACtB,cAAc,GACd,cAAc,GACd,qBAAqB,GACrB,UAAU,GACV,gBAAgB,GAChB,iBAAiB,GACjB,mBAAmB,GACnB,aAAa,GACb,WAAW,GACX,SAAS,GACT,aAAa,GACb,kBAAkB,GAClB,yBAAyB,GACzB,aAAa,GACb,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,GAChB,OAAO,CAAC;AAEd;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAAC;IAEzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IAEpD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;CACN;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,WAAW,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,eAAe,GAAG,gBAAgB,GAAG,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientInteractionRequest.d.ts","sourceRoot":"","sources":["../../src/models/ClientInteractionRequest.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACrC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEhC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientInteractionResult.d.ts","sourceRoot":"","sources":["../../src/models/ClientInteractionResult.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACpC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,EAAE,SAAS,EAAE,CAAC;IAEtB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentItem.d.ts","sourceRoot":"","sources":["../../src/models/ContentItem.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IAE5D;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -36,8 +36,6 @@ export interface SceneRequestSettings {
|
|
|
36
36
|
maxDynamicScenes?: number;
|
|
37
37
|
/** Unique key for this conversation (used by cache and memory). */
|
|
38
38
|
conversationKey?: string;
|
|
39
|
-
/** Continuation token for resuming execution after client interaction. */
|
|
40
|
-
continuationToken?: string;
|
|
41
39
|
/** Name of the scene to execute directly (used with SceneExecutionMode "Scene"). */
|
|
42
40
|
sceneName?: string;
|
|
43
41
|
/** Results from client-side tool executions. */
|
|
@@ -65,13 +63,14 @@ export interface PlayFrameworkRequest {
|
|
|
65
63
|
*/
|
|
66
64
|
settings?: SceneRequestSettings;
|
|
67
65
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
66
|
+
* Conversation key for resuming execution after client interaction.
|
|
67
|
+
* When present, server loads conversation state from cache.
|
|
70
68
|
*/
|
|
71
|
-
|
|
69
|
+
conversationKey?: string;
|
|
72
70
|
/**
|
|
73
71
|
* Results from client-side tool executions.
|
|
74
|
-
*
|
|
72
|
+
* Used to resume execution after AwaitingClient status.
|
|
75
73
|
*/
|
|
76
74
|
clientInteractionResults?: ClientInteractionResult[];
|
|
77
75
|
}
|
|
76
|
+
//# sourceMappingURL=PlayFrameworkRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlayFrameworkRequest.d.ts","sourceRoot":"","sources":["../../src/models/PlayFrameworkRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,UAAU,GAAG,iBAAiB,GAAG,OAAO,CAAC;AAErF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,yDAAyD;IACzD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gEAAgE;IAChE,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC,uCAAuC;IACvC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gEAAgE;IAChE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,wBAAwB,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACxD;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE/B;;OAEG;IACH,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAEhC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,wBAAwB,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlayFrameworkServices.d.ts","sourceRoot":"","sources":["../../src/servicecollection/PlayFrameworkServices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;GAEG;AACH,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,MAAM,CAAC,OAAO,CAA+C;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiD;IAExE;;;;;;;;OAQG;WACiB,SAAS,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACtE,OAAO,CAAC,qBAAqB,CAAC;IAqBjC;;;;;;OAMG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB;IAU1D;;;;;;OAMG;WACW,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB;IAU9D;;;;;OAKG;WACW,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjD;;;;OAIG;WACW,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKxC;;OAEG;WACW,KAAK,IAAI,IAAI;IAK3B;;;;;;OAMG;WACW,gBAAgB,IAAI,mBAAmB;IAQrD;;;;;OAKG;WACW,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,mBAAmB;CAG5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlayFrameworkSettings.d.ts","sourceRoot":"","sources":["../../src/servicecollection/PlayFrameworkSettings.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,qBAAqB;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,cAAc,EAAE,WAAW,CAAC;IAE5B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAgG;IAExH;;OAEG;IACH,OAAO,CAAC,aAAa,CAAwG;gBAEjH,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAahD;;OAEG;IACI,kBAAkB,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAKjI;;OAEG;IACI,eAAe,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI;IAKrI;;OAEG;IACU,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;IAmC1H;;OAEG;IACU,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;CAWvH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIContentConverter.d.ts","sourceRoot":"","sources":["../../src/utils/AIContentConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAE9D;;;GAGG;AACH,qBAAa,kBAAkB;IAC3B;;;;;;;;;OASG;WACiB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC;IAwBnE;;;;;;;OAOG;WACW,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAO/C;;;;;;;;;OASG;WACiB,UAAU,CAC1B,WAAW,GAAE,sBAAwC,EACrD,KAAK,GAAE,MAAY,EACnB,MAAM,GAAE,MAAY,GACrB,OAAO,CAAC,SAAS,CAAC;IAmCrB;;;;;;;;OAQG;WACiB,eAAe,CAC/B,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,SAAS,CAAC;IA2BrB;;;;;;;;OAQG;WACiB,iBAAiB,CACjC,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,GACzB,OAAO,CAAC,SAAS,EAAE,CAAC;IAKvB;;;;;;;;OAQG;WACiB,cAAc,CAC9B,UAAU,GAAE,MAAa,EACzB,QAAQ,GAAE,MAAqB,GAChC,OAAO,CAAC,SAAS,CAAC;CA8BxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rystem.playframework.client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"author": "Alessandro Rapiti <alessandro.rapiti44@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "TypeScript client for Rystem PlayFramework HTTP API with step-by-step and token-level streaming support.",
|