rystem.playframework.client 0.1.5 → 10.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -0
- package/lib/engine/PlayFrameworkClient.js +7 -7
- package/lib/servicecollection/PlayFrameworkSettings.d.ts +42 -0
- package/lib/servicecollection/PlayFrameworkSettings.d.ts.map +1 -1
- package/lib/servicecollection/PlayFrameworkSettings.js +48 -0
- package/package.json +1 -1
- package/lib/hooks/hooks.d.ts +0 -28
- package/lib/index.d.ts +0 -30
package/README.md
CHANGED
|
@@ -98,6 +98,157 @@ If you only configure one factory, `resolve()` with no name returns the first co
|
|
|
98
98
|
const defaultClient = PlayFrameworkServices.resolve();
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
## Example: custom fetch adapter (Angular, Node.js, test spy)
|
|
102
|
+
|
|
103
|
+
By default the client uses `globalThis.fetch`. Call `settings.setFetch(fn)` to replace it with any
|
|
104
|
+
function that matches the native Fetch API signature `(input, init?) => Promise<Response>`.
|
|
105
|
+
Callers that never invoke `setFetch()` are **not affected** — zero breaking change.
|
|
106
|
+
|
|
107
|
+
### Generic / framework-agnostic
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
await PlayFrameworkServices.configure("default", "https://api.example.com/api/ai", settings => {
|
|
111
|
+
settings.setFetch(async (url, init) => {
|
|
112
|
+
const token = localStorage.getItem("token");
|
|
113
|
+
const headers = new Headers(init?.headers);
|
|
114
|
+
if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
115
|
+
return fetch(url, { ...init, headers });
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Angular — reuse the same refresh-token logic as your HttpInterceptor
|
|
121
|
+
|
|
122
|
+
Angular's `HttpInterceptor` only intercepts requests made via `HttpClient` (XHR / managed fetch).
|
|
123
|
+
Because PlayFramework uses native `fetch` for SSE streaming it bypasses Angular's pipeline entirely.
|
|
124
|
+
The solution is to register a **fetch bridge** on `PlayFrameworkSettings` that contains the same
|
|
125
|
+
token-attach + refresh logic you already have in your interceptor, without importing any Angular
|
|
126
|
+
module into the library.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// play-framework-setup.service.ts
|
|
130
|
+
import { Injectable } from '@angular/core';
|
|
131
|
+
import { firstValueFrom } from 'rxjs';
|
|
132
|
+
import { PlayFrameworkServices } from 'rystem.playframework.client';
|
|
133
|
+
import { AuthService } from './auth.service';
|
|
134
|
+
import { GlobalService } from '../shared/service/global.service';
|
|
135
|
+
|
|
136
|
+
@Injectable({ providedIn: 'root' })
|
|
137
|
+
export class PlayFrameworkSetupService {
|
|
138
|
+
private isRefreshing = false;
|
|
139
|
+
private refreshPromise: Promise<string | null> | null = null;
|
|
140
|
+
|
|
141
|
+
constructor(
|
|
142
|
+
private authService: AuthService,
|
|
143
|
+
private globalService: GlobalService,
|
|
144
|
+
) {}
|
|
145
|
+
|
|
146
|
+
/** Call once during application startup (e.g. APP_INITIALIZER). */
|
|
147
|
+
async configure(factoryName: string, baseUrl: string): Promise<void> {
|
|
148
|
+
await PlayFrameworkServices.configure(factoryName, baseUrl, (settings) => {
|
|
149
|
+
settings.setFetch(this.createFetchBridge());
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private createFetchBridge(): typeof fetch {
|
|
154
|
+
return async (url: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
155
|
+
// 1. Attach current Bearer token (mirrors addAuthorizationHeader)
|
|
156
|
+
const headers = new Headers(init?.headers);
|
|
157
|
+
const token = this.authService.token;
|
|
158
|
+
if (token) headers.set('Authorization', `Bearer ${token}`);
|
|
159
|
+
|
|
160
|
+
const response = await fetch(url, { ...init, headers });
|
|
161
|
+
|
|
162
|
+
// 2. If not 401, return immediately
|
|
163
|
+
if (response.status !== 401) return response;
|
|
164
|
+
|
|
165
|
+
// 3. Token expired → refresh once (mirrors handle401Error, deduplicates concurrent calls)
|
|
166
|
+
if (!this.isRefreshing) {
|
|
167
|
+
this.isRefreshing = true;
|
|
168
|
+
this.refreshPromise = firstValueFrom(this.globalService.getRefreshToken())
|
|
169
|
+
.then((r: any) => {
|
|
170
|
+
const newToken = r?.accessToken;
|
|
171
|
+
if (!newToken) { window.location.reload(); return null; }
|
|
172
|
+
this.authService.token = newToken;
|
|
173
|
+
localStorage.setItem('token', newToken);
|
|
174
|
+
if (r?.refreshToken) localStorage.setItem('refreshToken', r.refreshToken);
|
|
175
|
+
return newToken;
|
|
176
|
+
})
|
|
177
|
+
.catch(() => { window.location.reload(); return null; })
|
|
178
|
+
.finally(() => { this.isRefreshing = false; this.refreshPromise = null; });
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const newToken = await this.refreshPromise;
|
|
182
|
+
if (!newToken) return response; // reload already triggered
|
|
183
|
+
|
|
184
|
+
// 4. Retry original request with fresh token
|
|
185
|
+
const retryHeaders = new Headers(init?.headers);
|
|
186
|
+
retryHeaders.set('Authorization', `Bearer ${newToken}`);
|
|
187
|
+
return fetch(url, { ...init, headers: retryHeaders });
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Wire it via `APP_INITIALIZER` so the factory is ready before any component calls `resolve()`:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// app.config.ts
|
|
197
|
+
import { ApplicationConfig, APP_INITIALIZER } from '@angular/core';
|
|
198
|
+
import { PlayFrameworkSetupService } from './services/play-framework-setup.service';
|
|
199
|
+
|
|
200
|
+
function initPlayFramework(svc: PlayFrameworkSetupService) {
|
|
201
|
+
return () => svc.configure('default', 'https://api.example.com/api/ai');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export const appConfig: ApplicationConfig = {
|
|
205
|
+
providers: [
|
|
206
|
+
{
|
|
207
|
+
provide: APP_INITIALIZER,
|
|
208
|
+
useFactory: initPlayFramework,
|
|
209
|
+
deps: [PlayFrameworkSetupService],
|
|
210
|
+
multi: true,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Then use the client anywhere as normal — the Angular interceptor is **not needed** for PlayFramework
|
|
217
|
+
requests since the fetch bridge handles auth directly:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
// your-chat.component.ts
|
|
221
|
+
import { usePlayFramework } from 'rystem.playframework.client';
|
|
222
|
+
|
|
223
|
+
const client = usePlayFramework('default');
|
|
224
|
+
for await (const step of client.executeStepByStep({ message: userInput })) {
|
|
225
|
+
if (step.message) appendText(step.message);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Node.js (SSR / server-side)
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import nodeFetch from 'node-fetch';
|
|
233
|
+
|
|
234
|
+
await PlayFrameworkServices.configure("default", "https://api.example.com/api/ai", settings => {
|
|
235
|
+
settings.setFetch(nodeFetch as unknown as typeof fetch);
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Testing — intercept and assert outgoing requests
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const calls: { url: RequestInfo | URL; init?: RequestInit }[] = [];
|
|
243
|
+
|
|
244
|
+
settings.setFetch(async (url, init) => {
|
|
245
|
+
calls.push({ url, init });
|
|
246
|
+
return new Response(JSON.stringify({ status: 'completed' }), {
|
|
247
|
+
headers: { 'Content-Type': 'application/json' },
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
101
252
|
## Example: configure multiple factories
|
|
102
253
|
|
|
103
254
|
The sample workspace in `src/AI/Rystem.PlayFramework.Client/src/App.tsx` configures both `default` and `foundry` against the same base path.
|
|
@@ -84,7 +84,7 @@ class PlayFrameworkClient {
|
|
|
84
84
|
let shouldRetry = true;
|
|
85
85
|
while (shouldRetry) {
|
|
86
86
|
try {
|
|
87
|
-
const response = await
|
|
87
|
+
const response = await this.settings.getFetch()(url, {
|
|
88
88
|
method: "POST",
|
|
89
89
|
headers,
|
|
90
90
|
body: JSON.stringify(currentRequest),
|
|
@@ -242,7 +242,7 @@ class PlayFrameworkClient {
|
|
|
242
242
|
const url = `${this.settings.baseUrl}/${this.settings.factoryName}/discovery`;
|
|
243
243
|
const headers = await this.settings.enrichHeaders(url, "GET", undefined, undefined);
|
|
244
244
|
const effectiveSignal = this.createTimeoutSignal(signal);
|
|
245
|
-
const response = await
|
|
245
|
+
const response = await this.settings.getFetch()(url, {
|
|
246
246
|
method: "GET",
|
|
247
247
|
headers,
|
|
248
248
|
signal: effectiveSignal
|
|
@@ -264,7 +264,7 @@ class PlayFrameworkClient {
|
|
|
264
264
|
const url = `${this.settings.baseUrl}/${this.settings.factoryName}/conversations${queryString}`;
|
|
265
265
|
const headers = await this.settings.enrichHeaders(url, "GET", undefined, undefined);
|
|
266
266
|
const effectiveSignal = this.createTimeoutSignal(signal);
|
|
267
|
-
const response = await
|
|
267
|
+
const response = await this.settings.getFetch()(url, {
|
|
268
268
|
method: "GET",
|
|
269
269
|
headers,
|
|
270
270
|
signal: effectiveSignal
|
|
@@ -287,7 +287,7 @@ class PlayFrameworkClient {
|
|
|
287
287
|
const url = `${this.settings.baseUrl}/${this.settings.factoryName}/conversations/${conversationKey}${queryString}`;
|
|
288
288
|
const headers = await this.settings.enrichHeaders(url, "GET", undefined, undefined);
|
|
289
289
|
const effectiveSignal = this.createTimeoutSignal(signal);
|
|
290
|
-
const response = await
|
|
290
|
+
const response = await this.settings.getFetch()(url, {
|
|
291
291
|
method: "GET",
|
|
292
292
|
headers,
|
|
293
293
|
signal: effectiveSignal
|
|
@@ -311,7 +311,7 @@ class PlayFrameworkClient {
|
|
|
311
311
|
const url = `${this.settings.baseUrl}/${this.settings.factoryName}/conversations/${conversationKey}`;
|
|
312
312
|
const headers = await this.settings.enrichHeaders(url, "DELETE", undefined, undefined);
|
|
313
313
|
const effectiveSignal = this.createTimeoutSignal(signal);
|
|
314
|
-
const response = await
|
|
314
|
+
const response = await this.settings.getFetch()(url, {
|
|
315
315
|
method: "DELETE",
|
|
316
316
|
headers,
|
|
317
317
|
signal: effectiveSignal
|
|
@@ -333,7 +333,7 @@ class PlayFrameworkClient {
|
|
|
333
333
|
const body = { isPublic };
|
|
334
334
|
const headers = await this.settings.enrichHeaders(url, "PATCH", undefined, body);
|
|
335
335
|
const effectiveSignal = this.createTimeoutSignal(signal);
|
|
336
|
-
const response = await
|
|
336
|
+
const response = await this.settings.getFetch()(url, {
|
|
337
337
|
method: "PATCH",
|
|
338
338
|
headers,
|
|
339
339
|
body: JSON.stringify(body),
|
|
@@ -409,7 +409,7 @@ class PlayFrameworkClient {
|
|
|
409
409
|
const baseHeaders = await this.settings.enrichHeaders(url, "POST", undefined, undefined);
|
|
410
410
|
const headers = new Headers(baseHeaders);
|
|
411
411
|
headers.delete('Content-Type'); // Let browser set multipart boundary
|
|
412
|
-
const response = await
|
|
412
|
+
const response = await this.settings.getFetch()(url, {
|
|
413
413
|
method: 'POST',
|
|
414
414
|
headers,
|
|
415
415
|
body: formData,
|
|
@@ -36,6 +36,12 @@ export declare class PlayFrameworkSettings {
|
|
|
36
36
|
* Error handlers for retry logic.
|
|
37
37
|
*/
|
|
38
38
|
private errorHandlers;
|
|
39
|
+
/**
|
|
40
|
+
* Underlying fetch implementation.
|
|
41
|
+
* Defaults to globalThis.fetch. Override via setFetch() to plug in a custom adapter
|
|
42
|
+
* (e.g., an Angular HTTP interceptor bridge, a Node.js fetch polyfill, or a test spy).
|
|
43
|
+
*/
|
|
44
|
+
private fetchFn;
|
|
39
45
|
constructor(factoryName: string, baseUrl: string);
|
|
40
46
|
/**
|
|
41
47
|
* Add a header enricher function (e.g., dynamic Authorization token).
|
|
@@ -45,6 +51,42 @@ export declare class PlayFrameworkSettings {
|
|
|
45
51
|
* Add an error handler for retry logic.
|
|
46
52
|
*/
|
|
47
53
|
addErrorHandler(handler: (url: string, method: string, headers: HeadersInit, body: any, error: any) => Promise<boolean>): this;
|
|
54
|
+
/**
|
|
55
|
+
* Replace the underlying fetch function used by PlayFrameworkClient for every HTTP request,
|
|
56
|
+
* including SSE streaming, conversation management and voice endpoints.
|
|
57
|
+
*
|
|
58
|
+
* Use this to plug in a custom adapter that wraps each request — for example:
|
|
59
|
+
* - An Angular fetch bridge that attaches Bearer tokens and handles 401 token refresh
|
|
60
|
+
* - A Node.js fetch polyfill (e.g., `node-fetch` for SSR)
|
|
61
|
+
* - A test spy that records and intercepts outgoing requests
|
|
62
|
+
*
|
|
63
|
+
* The adapter receives the same `(input, init?)` arguments as the native Fetch API
|
|
64
|
+
* and MUST return a `Promise<Response>`. Callers that never invoke `setFetch()` use
|
|
65
|
+
* `globalThis.fetch` transparently — no behaviour change.
|
|
66
|
+
*
|
|
67
|
+
* @example Generic token injection (framework-agnostic):
|
|
68
|
+
* ```typescript
|
|
69
|
+
* settings.setFetch(async (url, init) => {
|
|
70
|
+
* const token = localStorage.getItem("token");
|
|
71
|
+
* const headers = new Headers(init?.headers);
|
|
72
|
+
* if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
73
|
+
* return fetch(url, { ...init, headers });
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example Angular — bridge the existing HttpInterceptor logic:
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // In an Angular @Injectable service:
|
|
80
|
+
* settings.setFetch(this.createFetchBridge());
|
|
81
|
+
* // See README "Custom fetch adapter" section for the full Angular example.
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
setFetch(fn: typeof fetch): this;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the active fetch implementation (custom or globalThis.fetch).
|
|
87
|
+
* Used internally by PlayFrameworkClient — not intended for direct use.
|
|
88
|
+
*/
|
|
89
|
+
getFetch(): typeof fetch;
|
|
48
90
|
/**
|
|
49
91
|
* Enrich headers with all registered enrichers.
|
|
50
92
|
*/
|
|
@@ -1 +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;
|
|
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;IAE7H;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAe;gBAElB,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAchD;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACI,QAAQ,CAAC,EAAE,EAAE,OAAO,KAAK,GAAG,IAAI;IAKvC;;;OAGG;IACI,QAAQ,IAAI,OAAO,KAAK;IAI/B;;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"}
|
|
@@ -39,6 +39,12 @@ class PlayFrameworkSettings {
|
|
|
39
39
|
* Error handlers for retry logic.
|
|
40
40
|
*/
|
|
41
41
|
errorHandlers;
|
|
42
|
+
/**
|
|
43
|
+
* Underlying fetch implementation.
|
|
44
|
+
* Defaults to globalThis.fetch. Override via setFetch() to plug in a custom adapter
|
|
45
|
+
* (e.g., an Angular HTTP interceptor bridge, a Node.js fetch polyfill, or a test spy).
|
|
46
|
+
*/
|
|
47
|
+
fetchFn;
|
|
42
48
|
constructor(factoryName, baseUrl) {
|
|
43
49
|
this.factoryName = factoryName;
|
|
44
50
|
this.baseUrl = baseUrl;
|
|
@@ -50,6 +56,7 @@ class PlayFrameworkSettings {
|
|
|
50
56
|
this.reconnectBaseDelay = 1000;
|
|
51
57
|
this.headersEnrichers = [];
|
|
52
58
|
this.errorHandlers = [];
|
|
59
|
+
this.fetchFn = globalThis.fetch.bind(globalThis);
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
62
|
* Add a header enricher function (e.g., dynamic Authorization token).
|
|
@@ -65,6 +72,47 @@ class PlayFrameworkSettings {
|
|
|
65
72
|
this.errorHandlers.push(handler);
|
|
66
73
|
return this;
|
|
67
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Replace the underlying fetch function used by PlayFrameworkClient for every HTTP request,
|
|
77
|
+
* including SSE streaming, conversation management and voice endpoints.
|
|
78
|
+
*
|
|
79
|
+
* Use this to plug in a custom adapter that wraps each request — for example:
|
|
80
|
+
* - An Angular fetch bridge that attaches Bearer tokens and handles 401 token refresh
|
|
81
|
+
* - A Node.js fetch polyfill (e.g., `node-fetch` for SSR)
|
|
82
|
+
* - A test spy that records and intercepts outgoing requests
|
|
83
|
+
*
|
|
84
|
+
* The adapter receives the same `(input, init?)` arguments as the native Fetch API
|
|
85
|
+
* and MUST return a `Promise<Response>`. Callers that never invoke `setFetch()` use
|
|
86
|
+
* `globalThis.fetch` transparently — no behaviour change.
|
|
87
|
+
*
|
|
88
|
+
* @example Generic token injection (framework-agnostic):
|
|
89
|
+
* ```typescript
|
|
90
|
+
* settings.setFetch(async (url, init) => {
|
|
91
|
+
* const token = localStorage.getItem("token");
|
|
92
|
+
* const headers = new Headers(init?.headers);
|
|
93
|
+
* if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
94
|
+
* return fetch(url, { ...init, headers });
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Angular — bridge the existing HttpInterceptor logic:
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // In an Angular @Injectable service:
|
|
101
|
+
* settings.setFetch(this.createFetchBridge());
|
|
102
|
+
* // See README "Custom fetch adapter" section for the full Angular example.
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
setFetch(fn) {
|
|
106
|
+
this.fetchFn = fn;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns the active fetch implementation (custom or globalThis.fetch).
|
|
111
|
+
* Used internally by PlayFrameworkClient — not intended for direct use.
|
|
112
|
+
*/
|
|
113
|
+
getFetch() {
|
|
114
|
+
return this.fetchFn;
|
|
115
|
+
}
|
|
68
116
|
/**
|
|
69
117
|
* Enrich headers with all registered enrichers.
|
|
70
118
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rystem.playframework.client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0-beta.2",
|
|
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.",
|
package/lib/hooks/hooks.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PlayFrameworkClient } from "../engine/PlayFrameworkClient";
|
|
2
|
-
/**
|
|
3
|
-
* Get a PlayFrameworkClient instance by optional factory name.
|
|
4
|
-
*
|
|
5
|
-
* If `name` is provided, returns the client for that specific factory.
|
|
6
|
-
* If `name` is omitted, returns the default (first configured) client.
|
|
7
|
-
*
|
|
8
|
-
* Framework-agnostic — works with React, Vue, Angular, Svelte, or plain TypeScript.
|
|
9
|
-
*
|
|
10
|
-
* @param name - Optional factory name. Omit to use the default client.
|
|
11
|
-
* @returns PlayFrameworkClient instance.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Use default (first configured) client
|
|
16
|
-
* const client = usePlayFramework();
|
|
17
|
-
*
|
|
18
|
-
* // Use a specific factory
|
|
19
|
-
* const chatClient = usePlayFramework("chat");
|
|
20
|
-
*
|
|
21
|
-
* // Execute
|
|
22
|
-
* for await (const step of client.executeStepByStep({ message: "Hello" })) {
|
|
23
|
-
* console.log(step.message);
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export declare function usePlayFramework(name?: string): PlayFrameworkClient;
|
|
28
|
-
//# sourceMappingURL=hooks.d.ts.map
|
package/lib/index.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export type { ContentItem } from "./models/ContentItem";
|
|
2
|
-
export type { PlayFrameworkRequest, SceneRequestSettings, SceneExecutionMode, CacheBehavior } from "./models/PlayFrameworkRequest";
|
|
3
|
-
export type { ForcedToolRequest, PlayFrameworkToolSourceType, PlayFrameworkToolInfo, PlayFrameworkToolSourceInfo, PlayFrameworkSceneInfo, PlayFrameworkDiscoveryResponse } from "./models/PlayFrameworkDiscovery";
|
|
4
|
-
export type { AiSceneResponse, AiResponseStatus, SSEEvent, CompletionMarker, ErrorMarker } from "./models/AiSceneResponse";
|
|
5
|
-
export type { ClientInteractionRequest } from "./models/ClientInteractionRequest";
|
|
6
|
-
export type { ClientInteractionResult, AIContent } from "./models/ClientInteractionResult";
|
|
7
|
-
export type { StoredConversation, ConversationQueryParameters, UpdateConversationVisibilityRequest } from "./models/StoredConversation";
|
|
8
|
-
export { ConversationSortOrder } from "./models/StoredConversation";
|
|
9
|
-
export type { StoredMessage } from "./models/StoredMessage";
|
|
10
|
-
export type { ExecutionState } from "./models/ExecutionState";
|
|
11
|
-
export type { CommandResult } from "./models/CommandResult";
|
|
12
|
-
export { CommandResult as CommandResultHelper } from "./models/CommandResult";
|
|
13
|
-
export type { VoiceEvent, VoiceRequestOptions, VoiceResponseType } from "./models/VoiceResponse";
|
|
14
|
-
export { PlayFrameworkClient } from "./engine/PlayFrameworkClient";
|
|
15
|
-
export { ClientInteractionRegistry } from "./engine/ClientInteractionRegistry";
|
|
16
|
-
export type { ClientTool, ClientCommand, CommandFeedbackMode, CommandOptions } from "./engine/ClientInteractionRegistry";
|
|
17
|
-
export { AIContentConverter } from "./utils/AIContentConverter";
|
|
18
|
-
export { ContentUrlConverter } from "./utils/ContentUrlConverter";
|
|
19
|
-
export { VoiceRecorder } from "./utils/VoiceRecorder";
|
|
20
|
-
export type { VoiceRecordingMode, VoiceRecorderOptions, VoiceRecorderCallbacks } from "./utils/VoiceRecorder";
|
|
21
|
-
export { BrowserSpeechRecognizer } from "./utils/BrowserSpeechRecognizer";
|
|
22
|
-
export type { BrowserSpeechRecognizerOptions, BrowserSpeechRecognizerCallbacks, SpeechRecognitionResult } from "./utils/BrowserSpeechRecognizer";
|
|
23
|
-
export { BrowserSpeechSynthesizer } from "./utils/BrowserSpeechSynthesizer";
|
|
24
|
-
export type { BrowserSpeechSynthesizerOptions, BrowserSpeechSynthesizerCallbacks } from "./utils/BrowserSpeechSynthesizer";
|
|
25
|
-
export { BrowserVoiceClient } from "./utils/BrowserVoiceClient";
|
|
26
|
-
export type { BrowserVoiceOptions, BrowserVoiceEvent, BrowserVoiceStatus, BrowserVoiceStreamingMode } from "./utils/BrowserVoiceClient";
|
|
27
|
-
export { PlayFrameworkSettings } from "./servicecollection/PlayFrameworkSettings";
|
|
28
|
-
export { PlayFrameworkServices } from "./servicecollection/PlayFrameworkServices";
|
|
29
|
-
export { usePlayFramework } from "./hooks/hooks";
|
|
30
|
-
//# sourceMappingURL=index.d.ts.map
|