ai-props 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +9 -0
- package/dist/ai.d.ts +125 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +199 -0
- package/dist/ai.js.map +1 -0
- package/dist/cache.d.ts +66 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +183 -0
- package/dist/cache.js.map +1 -0
- package/dist/cascade.d.ts +329 -0
- package/dist/cascade.d.ts.map +1 -0
- package/dist/cascade.js +522 -0
- package/dist/cascade.js.map +1 -0
- package/dist/client.d.ts +233 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +191 -0
- package/dist/client.js.map +1 -0
- package/dist/durable-cascade.d.ts +280 -0
- package/dist/durable-cascade.d.ts.map +1 -0
- package/dist/durable-cascade.js +469 -0
- package/dist/durable-cascade.js.map +1 -0
- package/dist/event-bridge.d.ts +257 -0
- package/dist/event-bridge.d.ts.map +1 -0
- package/dist/event-bridge.js +317 -0
- package/dist/event-bridge.js.map +1 -0
- package/dist/generate.d.ts +69 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +227 -0
- package/dist/generate.js.map +1 -0
- package/dist/hoc.d.ts +164 -0
- package/dist/hoc.d.ts.map +1 -0
- package/dist/hoc.js +236 -0
- package/dist/hoc.js.map +1 -0
- package/dist/hono-jsx.d.ts +208 -0
- package/dist/hono-jsx.d.ts.map +1 -0
- package/dist/hono-jsx.js +459 -0
- package/dist/hono-jsx.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/mdx-types.d.ts +152 -0
- package/dist/mdx-types.d.ts.map +1 -0
- package/dist/mdx-types.js +9 -0
- package/dist/mdx-types.js.map +1 -0
- package/dist/mdx-utils.d.ts +106 -0
- package/dist/mdx-utils.d.ts.map +1 -0
- package/dist/mdx-utils.js +384 -0
- package/dist/mdx-utils.js.map +1 -0
- package/dist/mdx.d.ts +230 -0
- package/dist/mdx.d.ts.map +1 -0
- package/dist/mdx.js +820 -0
- package/dist/mdx.js.map +1 -0
- package/dist/rpc.d.ts +313 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +359 -0
- package/dist/rpc.js.map +1 -0
- package/dist/streaming.d.ts +199 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +402 -0
- package/dist/streaming.js.map +1 -0
- package/dist/types.d.ts +152 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +58 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +251 -0
- package/dist/validate.js.map +1 -0
- package/dist/worker.d.ts +270 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +405 -0
- package/dist/worker.js.map +1 -0
- package/package.json +4 -4
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC Export - Cloudflare Workers RPC utilities for AI Props
|
|
3
|
+
*
|
|
4
|
+
* This module provides RPC-specific functionality for consuming the AI Props
|
|
5
|
+
* service via Cloudflare Workers Service Bindings. It exports the service
|
|
6
|
+
* classes, types, and utilities for building RPC clients.
|
|
7
|
+
*
|
|
8
|
+
* ## RPC Pattern Overview
|
|
9
|
+
*
|
|
10
|
+
* Cloudflare Workers RPC allows direct method invocation between workers
|
|
11
|
+
* using Service Bindings. The AI Props service exposes methods through:
|
|
12
|
+
*
|
|
13
|
+
* 1. **WorkerEntrypoint** (`PropsService`) - The main entry point that workers
|
|
14
|
+
* bind to. Provides `getService()` to get an RPC-callable service instance.
|
|
15
|
+
*
|
|
16
|
+
* 2. **RpcTarget** (`PropsServiceCore`) - The actual service implementation
|
|
17
|
+
* with all callable methods. Returned by `getService()`.
|
|
18
|
+
*
|
|
19
|
+
* ## Usage Patterns
|
|
20
|
+
*
|
|
21
|
+
* ### Basic Service Binding
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // wrangler.jsonc
|
|
24
|
+
* {
|
|
25
|
+
* "services": [
|
|
26
|
+
* { "binding": "AI_PROPS", "service": "ai-props" }
|
|
27
|
+
* ]
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* // worker.ts
|
|
31
|
+
* import type { PropsService } from 'ai-props/rpc'
|
|
32
|
+
*
|
|
33
|
+
* interface Env {
|
|
34
|
+
* AI_PROPS: Service<PropsService>
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* export default {
|
|
38
|
+
* async fetch(request: Request, env: Env) {
|
|
39
|
+
* const service = env.AI_PROPS.getService()
|
|
40
|
+
* const result = await service.generate({
|
|
41
|
+
* schema: { title: 'Page title' }
|
|
42
|
+
* })
|
|
43
|
+
* return Response.json(result)
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* ### With Typed Client Factory
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { createPropsClient, type PropsClientOptions } from 'ai-props/rpc'
|
|
51
|
+
*
|
|
52
|
+
* const client = createPropsClient({
|
|
53
|
+
* service: env.AI_PROPS,
|
|
54
|
+
* timeout: 30000,
|
|
55
|
+
* retry: { attempts: 3, backoff: 'exponential' }
|
|
56
|
+
* })
|
|
57
|
+
*
|
|
58
|
+
* const result = await client.generate({
|
|
59
|
+
* schema: { title: 'Page title' }
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* ### Error Handling
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { PropsRPCError, isPropsRPCError } from 'ai-props/rpc'
|
|
66
|
+
*
|
|
67
|
+
* try {
|
|
68
|
+
* const result = await service.generate(options)
|
|
69
|
+
* } catch (error) {
|
|
70
|
+
* if (isPropsRPCError(error)) {
|
|
71
|
+
* console.error(`RPC Error: ${error.code} - ${error.message}`)
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @packageDocumentation
|
|
77
|
+
*/
|
|
78
|
+
// Re-export service classes from worker
|
|
79
|
+
export { PropsService, PropsServiceCore, PropsWorker } from './worker.js';
|
|
80
|
+
// ==================== RPC Error Types ====================
|
|
81
|
+
/**
|
|
82
|
+
* Error codes for RPC operations
|
|
83
|
+
*/
|
|
84
|
+
export var PropsRPCErrorCode;
|
|
85
|
+
(function (PropsRPCErrorCode) {
|
|
86
|
+
/** Method not found on service */
|
|
87
|
+
PropsRPCErrorCode["METHOD_NOT_FOUND"] = "METHOD_NOT_FOUND";
|
|
88
|
+
/** Invalid arguments passed to method */
|
|
89
|
+
PropsRPCErrorCode["INVALID_ARGUMENTS"] = "INVALID_ARGUMENTS";
|
|
90
|
+
/** Service connection failed */
|
|
91
|
+
PropsRPCErrorCode["CONNECTION_FAILED"] = "CONNECTION_FAILED";
|
|
92
|
+
/** Request timed out */
|
|
93
|
+
PropsRPCErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
94
|
+
/** Service returned an error */
|
|
95
|
+
PropsRPCErrorCode["SERVICE_ERROR"] = "SERVICE_ERROR";
|
|
96
|
+
/** Network error during RPC call */
|
|
97
|
+
PropsRPCErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
98
|
+
/** Unknown error */
|
|
99
|
+
PropsRPCErrorCode["UNKNOWN"] = "UNKNOWN";
|
|
100
|
+
})(PropsRPCErrorCode || (PropsRPCErrorCode = {}));
|
|
101
|
+
/**
|
|
102
|
+
* Structured error for RPC failures
|
|
103
|
+
*
|
|
104
|
+
* Provides detailed error information for debugging RPC issues.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* try {
|
|
109
|
+
* await service.generate(options)
|
|
110
|
+
* } catch (error) {
|
|
111
|
+
* if (error instanceof PropsRPCError) {
|
|
112
|
+
* console.error(`[${error.code}] ${error.message}`)
|
|
113
|
+
* if (error.cause) console.error('Caused by:', error.cause)
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export class PropsRPCError extends Error {
|
|
119
|
+
/** Error code for programmatic handling */
|
|
120
|
+
code;
|
|
121
|
+
/** Original error that caused this RPC error */
|
|
122
|
+
originalCause;
|
|
123
|
+
/** Method that was being called */
|
|
124
|
+
method;
|
|
125
|
+
/** Timestamp when error occurred */
|
|
126
|
+
timestamp;
|
|
127
|
+
constructor(message, code = PropsRPCErrorCode.UNKNOWN, options) {
|
|
128
|
+
super(message, options?.cause ? { cause: options.cause } : undefined);
|
|
129
|
+
this.name = 'PropsRPCError';
|
|
130
|
+
this.code = code;
|
|
131
|
+
this.originalCause = options?.cause;
|
|
132
|
+
this.method = options?.method;
|
|
133
|
+
this.timestamp = Date.now();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Convert to JSON for logging/serialization
|
|
137
|
+
*/
|
|
138
|
+
toJSON() {
|
|
139
|
+
return {
|
|
140
|
+
name: this.name,
|
|
141
|
+
message: this.message,
|
|
142
|
+
code: this.code,
|
|
143
|
+
method: this.method,
|
|
144
|
+
timestamp: this.timestamp,
|
|
145
|
+
cause: this.originalCause?.message,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Type guard to check if an error is a PropsRPCError
|
|
151
|
+
*/
|
|
152
|
+
export function isPropsRPCError(error) {
|
|
153
|
+
return error instanceof PropsRPCError;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Default retry configuration
|
|
157
|
+
*/
|
|
158
|
+
export const DEFAULT_RETRY_CONFIG = {
|
|
159
|
+
attempts: 3,
|
|
160
|
+
backoff: 'exponential',
|
|
161
|
+
initialDelay: 1000,
|
|
162
|
+
maxDelay: 30000,
|
|
163
|
+
multiplier: 2,
|
|
164
|
+
retryOn: [
|
|
165
|
+
PropsRPCErrorCode.CONNECTION_FAILED,
|
|
166
|
+
PropsRPCErrorCode.TIMEOUT,
|
|
167
|
+
PropsRPCErrorCode.NETWORK_ERROR,
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Calculate delay for retry attempt based on backoff strategy
|
|
172
|
+
*/
|
|
173
|
+
export function calculateRetryDelay(attempt, config) {
|
|
174
|
+
let delay;
|
|
175
|
+
switch (config.backoff) {
|
|
176
|
+
case 'fixed':
|
|
177
|
+
delay = config.initialDelay;
|
|
178
|
+
break;
|
|
179
|
+
case 'linear':
|
|
180
|
+
delay = config.initialDelay * attempt;
|
|
181
|
+
break;
|
|
182
|
+
case 'exponential':
|
|
183
|
+
default:
|
|
184
|
+
delay = config.initialDelay * Math.pow(config.multiplier, attempt - 1);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
return Math.min(delay, config.maxDelay);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Sleep for a specified number of milliseconds
|
|
191
|
+
*/
|
|
192
|
+
function sleep(ms) {
|
|
193
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Execute a function with retry logic
|
|
197
|
+
*
|
|
198
|
+
* Wraps an async function with configurable retry behavior including
|
|
199
|
+
* exponential backoff, maximum attempts, and error code filtering.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const result = await withRetry(
|
|
204
|
+
* () => service.generate(options),
|
|
205
|
+
* { attempts: 3, backoff: 'exponential' }
|
|
206
|
+
* )
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export async function withRetry(fn, config) {
|
|
210
|
+
const fullConfig = {
|
|
211
|
+
...DEFAULT_RETRY_CONFIG,
|
|
212
|
+
...config,
|
|
213
|
+
};
|
|
214
|
+
let lastError;
|
|
215
|
+
let attempt = 0;
|
|
216
|
+
while (attempt < fullConfig.attempts) {
|
|
217
|
+
attempt++;
|
|
218
|
+
try {
|
|
219
|
+
return await fn();
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
223
|
+
// Check if we should retry this error
|
|
224
|
+
const shouldRetry = attempt < fullConfig.attempts &&
|
|
225
|
+
(isPropsRPCError(error) ? fullConfig.retryOn.includes(error.code) : true);
|
|
226
|
+
if (!shouldRetry) {
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
// Calculate and wait for delay
|
|
230
|
+
const delay = calculateRetryDelay(attempt, fullConfig);
|
|
231
|
+
await sleep(delay);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
throw lastError;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a typed Props RPC client with optional retry and monitoring
|
|
238
|
+
*
|
|
239
|
+
* Wraps the service binding with timeout handling, retry logic, and
|
|
240
|
+
* lifecycle hooks for monitoring.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* // Basic usage
|
|
245
|
+
* const client = createPropsClient({ service: env.AI_PROPS })
|
|
246
|
+
* const result = await client.generate({ schema: { title: 'Page title' } })
|
|
247
|
+
*
|
|
248
|
+
* // With retry and monitoring
|
|
249
|
+
* const client = createPropsClient({
|
|
250
|
+
* service: env.AI_PROPS,
|
|
251
|
+
* timeout: 30000,
|
|
252
|
+
* retry: { attempts: 3, backoff: 'exponential' },
|
|
253
|
+
* onRequest: (method, args) => console.log(`Calling ${method}`),
|
|
254
|
+
* onResponse: (method, result, duration) =>
|
|
255
|
+
* console.log(`${method} completed in ${duration}ms`),
|
|
256
|
+
* onError: (method, error) => console.error(`${method} failed:`, error)
|
|
257
|
+
* })
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
export function createPropsClient(options) {
|
|
261
|
+
const { service, timeout = 30000, retry, onRequest, onResponse, onError } = options;
|
|
262
|
+
// Get the underlying service instance
|
|
263
|
+
const serviceInstance = service.getService();
|
|
264
|
+
/**
|
|
265
|
+
* Wrap a method with timeout, retry, and hooks
|
|
266
|
+
*/
|
|
267
|
+
function wrapMethod(methodName, method) {
|
|
268
|
+
return async (...args) => {
|
|
269
|
+
const startTime = Date.now();
|
|
270
|
+
// Call onRequest hook
|
|
271
|
+
onRequest?.(methodName, args);
|
|
272
|
+
const executeCall = async () => {
|
|
273
|
+
// Create timeout promise
|
|
274
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
275
|
+
setTimeout(() => {
|
|
276
|
+
reject(new PropsRPCError(`Request timed out after ${timeout}ms`, PropsRPCErrorCode.TIMEOUT, {
|
|
277
|
+
method: methodName,
|
|
278
|
+
}));
|
|
279
|
+
}, timeout);
|
|
280
|
+
});
|
|
281
|
+
// Race between call and timeout
|
|
282
|
+
try {
|
|
283
|
+
return await Promise.race([method.apply(serviceInstance, args), timeoutPromise]);
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
// Convert to PropsRPCError if not already
|
|
287
|
+
if (!isPropsRPCError(error)) {
|
|
288
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
289
|
+
const errorCause = error instanceof Error ? error : undefined;
|
|
290
|
+
throw new PropsRPCError(message, PropsRPCErrorCode.SERVICE_ERROR, errorCause ? { cause: errorCause, method: methodName } : { method: methodName });
|
|
291
|
+
}
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
try {
|
|
296
|
+
// Execute with optional retry
|
|
297
|
+
const result = retry ? await withRetry(executeCall, retry) : await executeCall();
|
|
298
|
+
// Call onResponse hook
|
|
299
|
+
const duration = Date.now() - startTime;
|
|
300
|
+
onResponse?.(methodName, result, duration);
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
// Call onError hook
|
|
305
|
+
onError?.(methodName, error instanceof Error ? error : new Error(String(error)));
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Wrap a synchronous method (just adds hooks, no timeout/retry)
|
|
312
|
+
*/
|
|
313
|
+
function wrapSyncMethod(methodName, method) {
|
|
314
|
+
return (...args) => {
|
|
315
|
+
const startTime = Date.now();
|
|
316
|
+
onRequest?.(methodName, args);
|
|
317
|
+
try {
|
|
318
|
+
const result = method.apply(serviceInstance, args);
|
|
319
|
+
const duration = Date.now() - startTime;
|
|
320
|
+
onResponse?.(methodName, result, duration);
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
onError?.(methodName, error instanceof Error ? error : new Error(String(error)));
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
// Create wrapped client with type assertions to preserve generics
|
|
330
|
+
const client = {
|
|
331
|
+
// Async methods with timeout/retry
|
|
332
|
+
generate: wrapMethod('generate', serviceInstance.generate.bind(serviceInstance)),
|
|
333
|
+
prefetch: wrapMethod('prefetch', serviceInstance.prefetch.bind(serviceInstance)),
|
|
334
|
+
generateMany: wrapMethod('generateMany', serviceInstance.generateMany.bind(serviceInstance)),
|
|
335
|
+
mergeWithGenerated: wrapMethod('mergeWithGenerated', serviceInstance.mergeWithGenerated.bind(serviceInstance)),
|
|
336
|
+
// Sync methods (just hooks)
|
|
337
|
+
getSync: wrapSyncMethod('getSync', serviceInstance.getSync.bind(serviceInstance)),
|
|
338
|
+
configure: wrapSyncMethod('configure', serviceInstance.configure.bind(serviceInstance)),
|
|
339
|
+
getConfig: wrapSyncMethod('getConfig', serviceInstance.getConfig.bind(serviceInstance)),
|
|
340
|
+
resetConfig: wrapSyncMethod('resetConfig', serviceInstance.resetConfig.bind(serviceInstance)),
|
|
341
|
+
getCached: wrapSyncMethod('getCached', serviceInstance.getCached.bind(serviceInstance)),
|
|
342
|
+
setCached: wrapSyncMethod('setCached', serviceInstance.setCached.bind(serviceInstance)),
|
|
343
|
+
deleteCached: wrapSyncMethod('deleteCached', serviceInstance.deleteCached.bind(serviceInstance)),
|
|
344
|
+
clearCache: wrapSyncMethod('clearCache', serviceInstance.clearCache.bind(serviceInstance)),
|
|
345
|
+
getCacheSize: wrapSyncMethod('getCacheSize', serviceInstance.getCacheSize.bind(serviceInstance)),
|
|
346
|
+
createCacheKey: wrapSyncMethod('createCacheKey', serviceInstance.createCacheKey.bind(serviceInstance)),
|
|
347
|
+
configureCache: wrapSyncMethod('configureCache', serviceInstance.configureCache.bind(serviceInstance)),
|
|
348
|
+
validate: wrapSyncMethod('validate', serviceInstance.validate.bind(serviceInstance)),
|
|
349
|
+
hasRequired: wrapSyncMethod('hasRequired', serviceInstance.hasRequired.bind(serviceInstance)),
|
|
350
|
+
getMissing: wrapSyncMethod('getMissing', serviceInstance.getMissing.bind(serviceInstance)),
|
|
351
|
+
isComplete: wrapSyncMethod('isComplete', serviceInstance.isComplete.bind(serviceInstance)),
|
|
352
|
+
sanitize: wrapSyncMethod('sanitize', serviceInstance.sanitize.bind(serviceInstance)),
|
|
353
|
+
mergeDefaults: wrapSyncMethod('mergeDefaults', serviceInstance.mergeDefaults.bind(serviceInstance)),
|
|
354
|
+
// Utility method
|
|
355
|
+
getUnderlyingService: () => serviceInstance,
|
|
356
|
+
};
|
|
357
|
+
return client;
|
|
358
|
+
}
|
|
359
|
+
//# sourceMappingURL=rpc.js.map
|
package/dist/rpc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,wCAAwC;AACxC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;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AC5C,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimized streaming utilities for AI-powered props rendering
|
|
3
|
+
*
|
|
4
|
+
* This module provides high-performance streaming capabilities with:
|
|
5
|
+
* - Adaptive chunk sizing for network efficiency
|
|
6
|
+
* - Backpressure handling to prevent memory overflow
|
|
7
|
+
* - Progress callbacks for streaming status
|
|
8
|
+
* - Memory-efficient streaming for large components
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import { renderToReadableStream as baseRenderToReadableStream, streamJSXResponse as baseStreamJSXResponse, createStreamingRenderer as baseCreateStreamingRenderer, type StreamingOptions, type StreamingRendererOptions } from './hono-jsx.js';
|
|
13
|
+
import { type StreamMDXOptions } from './mdx.js';
|
|
14
|
+
/** Default chunk size for optimal network performance (16KB) */
|
|
15
|
+
export declare const DEFAULT_CHUNK_SIZE: number;
|
|
16
|
+
/** Minimum chunk size to avoid excessive overhead (1KB) */
|
|
17
|
+
export declare const MIN_CHUNK_SIZE = 1024;
|
|
18
|
+
/** Maximum chunk size for memory efficiency (64KB) */
|
|
19
|
+
export declare const MAX_CHUNK_SIZE: number;
|
|
20
|
+
/** High water mark for backpressure (64KB) */
|
|
21
|
+
export declare const DEFAULT_HIGH_WATER_MARK: number;
|
|
22
|
+
/**
|
|
23
|
+
* Progress information during streaming
|
|
24
|
+
*/
|
|
25
|
+
export interface StreamingProgress {
|
|
26
|
+
/** Total bytes processed so far */
|
|
27
|
+
bytesProcessed: number;
|
|
28
|
+
/** Total bytes expected (if known) */
|
|
29
|
+
totalBytes?: number;
|
|
30
|
+
/** Number of chunks sent */
|
|
31
|
+
chunksProcessed: number;
|
|
32
|
+
/** Percentage complete (0-100, if total is known) */
|
|
33
|
+
percentComplete?: number;
|
|
34
|
+
/** Current streaming phase */
|
|
35
|
+
phase: 'starting' | 'streaming' | 'hydration' | 'complete' | 'error';
|
|
36
|
+
/** Time elapsed in milliseconds */
|
|
37
|
+
elapsedMs: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Progress callback function type
|
|
41
|
+
*/
|
|
42
|
+
export type StreamingProgressCallback = (progress: StreamingProgress) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Enhanced streaming options with optimization controls
|
|
45
|
+
*/
|
|
46
|
+
export interface OptimizedStreamingOptions extends StreamingOptions {
|
|
47
|
+
/** Chunk size in bytes (default: 16KB) */
|
|
48
|
+
chunkSize?: number;
|
|
49
|
+
/** High water mark for backpressure (default: 64KB) */
|
|
50
|
+
highWaterMark?: number;
|
|
51
|
+
/** Progress callback for streaming updates */
|
|
52
|
+
onProgress?: StreamingProgressCallback;
|
|
53
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
54
|
+
timeout?: number;
|
|
55
|
+
/** Enable compression hints for response */
|
|
56
|
+
compressionHint?: boolean;
|
|
57
|
+
/** Flush chunks immediately without buffering */
|
|
58
|
+
flushImmediate?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Enhanced streaming renderer options
|
|
62
|
+
*/
|
|
63
|
+
export interface OptimizedStreamingRendererOptions extends StreamingRendererOptions {
|
|
64
|
+
/** Chunk size in bytes */
|
|
65
|
+
chunkSize?: number;
|
|
66
|
+
/** High water mark for backpressure */
|
|
67
|
+
highWaterMark?: number;
|
|
68
|
+
/** Progress callback */
|
|
69
|
+
onProgress?: StreamingProgressCallback;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Streaming statistics for monitoring
|
|
73
|
+
*/
|
|
74
|
+
export interface StreamingStats {
|
|
75
|
+
/** Total bytes streamed */
|
|
76
|
+
totalBytes: number;
|
|
77
|
+
/** Number of chunks sent */
|
|
78
|
+
totalChunks: number;
|
|
79
|
+
/** Average chunk size */
|
|
80
|
+
averageChunkSize: number;
|
|
81
|
+
/** Time to first byte in ms */
|
|
82
|
+
timeToFirstByte: number;
|
|
83
|
+
/** Total streaming duration in ms */
|
|
84
|
+
totalDuration: number;
|
|
85
|
+
/** Whether backpressure was encountered */
|
|
86
|
+
encounteredBackpressure: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Calculate optimal chunk size based on content size
|
|
90
|
+
*
|
|
91
|
+
* @param contentLength - Total content length in bytes
|
|
92
|
+
* @returns Optimal chunk size
|
|
93
|
+
*/
|
|
94
|
+
export declare function calculateOptimalChunkSize(contentLength: number): number;
|
|
95
|
+
/**
|
|
96
|
+
* Render a component to a ReadableStream with optimizations
|
|
97
|
+
*
|
|
98
|
+
* Features:
|
|
99
|
+
* - Adaptive chunk sizing based on content
|
|
100
|
+
* - Backpressure handling to prevent memory overflow
|
|
101
|
+
* - Progress callbacks for monitoring
|
|
102
|
+
* - Memory-efficient streaming for large content
|
|
103
|
+
*
|
|
104
|
+
* @param component - Component function to render
|
|
105
|
+
* @param props - Props to pass to component
|
|
106
|
+
* @param options - Optimized streaming options
|
|
107
|
+
* @returns ReadableStream of rendered HTML
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const stream = await renderToReadableStream(
|
|
112
|
+
* MyComponent,
|
|
113
|
+
* { title: 'Hello' },
|
|
114
|
+
* {
|
|
115
|
+
* chunkSize: 8192,
|
|
116
|
+
* onProgress: (progress) => console.log(`${progress.percentComplete}% complete`),
|
|
117
|
+
* }
|
|
118
|
+
* )
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function renderToReadableStream<P>(component: (props: P) => string | Promise<string>, props: P, options?: OptimizedStreamingOptions): Promise<ReadableStream<Uint8Array>>;
|
|
122
|
+
/**
|
|
123
|
+
* Create a streaming Response with optimizations
|
|
124
|
+
*
|
|
125
|
+
* @param component - Component function to render
|
|
126
|
+
* @param props - Props to pass to component
|
|
127
|
+
* @param options - Optimized streaming options
|
|
128
|
+
* @returns Response with streaming body
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* // In a Hono/Worker handler
|
|
133
|
+
* export default {
|
|
134
|
+
* fetch(request, env) {
|
|
135
|
+
* return streamJSXResponse(
|
|
136
|
+
* PageComponent,
|
|
137
|
+
* { data: pageData },
|
|
138
|
+
* {
|
|
139
|
+
* streaming: true,
|
|
140
|
+
* compressionHint: true,
|
|
141
|
+
* }
|
|
142
|
+
* )
|
|
143
|
+
* }
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function streamJSXResponse<P>(component: (props: P) => string | Promise<string>, props: P, options?: OptimizedStreamingOptions): Promise<Response>;
|
|
148
|
+
/**
|
|
149
|
+
* Create a reusable streaming renderer with configuration
|
|
150
|
+
*
|
|
151
|
+
* @param options - Renderer options with optimization controls
|
|
152
|
+
* @returns Streaming renderer instance with stats
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const renderer = createStreamingRenderer({
|
|
157
|
+
* doctype: '<!DOCTYPE html>',
|
|
158
|
+
* includeHydration: true,
|
|
159
|
+
* chunkSize: 8192,
|
|
160
|
+
* onProgress: (p) => console.log(p.phase),
|
|
161
|
+
* })
|
|
162
|
+
*
|
|
163
|
+
* const stream = await renderer.render(MyComponent, props)
|
|
164
|
+
* const stats = renderer.getStats()
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function createStreamingRenderer(options: OptimizedStreamingRendererOptions): {
|
|
168
|
+
render: <P>(component: (props: P) => string | Promise<string>, props: P) => Promise<ReadableStream<Uint8Array>>;
|
|
169
|
+
getStats: () => StreamingStats | null;
|
|
170
|
+
resetStats: () => void;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Stream MDX content with AI-generated props and optimizations
|
|
174
|
+
*
|
|
175
|
+
* @param mdx - MDX content string
|
|
176
|
+
* @param props - Props for each component
|
|
177
|
+
* @param options - Stream options with optimizations
|
|
178
|
+
* @returns ReadableStream of rendered content
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* const stream = await streamMDXWithProps(
|
|
183
|
+
* '<Hero title="Welcome" />',
|
|
184
|
+
* { Hero: { title: 'Welcome', subtitle: 'To the site' } },
|
|
185
|
+
* {
|
|
186
|
+
* chunkSize: 8192,
|
|
187
|
+
* onProgress: (p) => console.log(`${p.chunksProcessed} chunks sent`),
|
|
188
|
+
* }
|
|
189
|
+
* )
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function streamMDXWithProps(mdx: string, props: Record<string, Record<string, unknown>>, options?: StreamMDXOptions & {
|
|
193
|
+
chunkSize?: number;
|
|
194
|
+
highWaterMark?: number;
|
|
195
|
+
onProgress?: StreamingProgressCallback;
|
|
196
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
197
|
+
export { createHydrationContext, serializeHydrationData, collectHydrationData, HydrationProvider, useHydration, type HydrationContext, type HydrationData, type HydrationNode, type StreamingOptions, type StreamingRendererOptions, } from './hono-jsx.js';
|
|
198
|
+
export { baseRenderToReadableStream as renderToReadableStreamBasic, baseStreamJSXResponse as streamJSXResponseBasic, baseCreateStreamingRenderer as createStreamingRendererBasic, };
|
|
199
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,sBAAsB,IAAI,0BAA0B,EACpD,iBAAiB,IAAI,qBAAqB,EAC1C,uBAAuB,IAAI,2BAA2B,EAGtD,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAI9B,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAgD,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAM9F,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,QAAY,CAAA;AAE3C,2DAA2D;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