@agentskit/adapters 0.12.0 → 0.13.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/dist/catalog/index.cjs +153745 -0
- package/dist/catalog/index.cjs.map +1 -0
- package/dist/catalog/index.d.cts +205 -0
- package/dist/catalog/index.d.ts +205 -0
- package/dist/catalog/index.js +153479 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/chunk-6FPLWOVE.js +26 -0
- package/dist/chunk-6FPLWOVE.js.map +1 -0
- package/dist/chunk-726IKNNR.js +486 -0
- package/dist/chunk-726IKNNR.js.map +1 -0
- package/dist/createAdapter-Dfnf3Iio.d.cts +14 -0
- package/dist/createAdapter-Dfnf3Iio.d.ts +14 -0
- package/dist/createAdapter.cjs +28 -0
- package/dist/createAdapter.cjs.map +1 -0
- package/dist/createAdapter.d.cts +2 -0
- package/dist/createAdapter.d.ts +2 -0
- package/dist/createAdapter.js +3 -0
- package/dist/createAdapter.js.map +1 -0
- package/dist/index.cjs +297 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +202 -77
- package/dist/index.d.ts +202 -77
- package/dist/index.js +277 -556
- package/dist/index.js.map +1 -1
- package/dist/utils-ddwu4MN4.d.cts +66 -0
- package/dist/utils-ddwu4MN4.d.ts +66 -0
- package/package.json +19 -6
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { StreamSource } from '@agentskit/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retry knobs for adapter fetches. Tunable per call to createStreamSource.
|
|
5
|
+
*
|
|
6
|
+
* Default behavior:
|
|
7
|
+
* - 3 attempts total (1 initial + 2 retries)
|
|
8
|
+
* - exponential backoff: 500ms, 1000ms, 2000ms ... (capped at maxDelayMs)
|
|
9
|
+
* - full jitter on each delay
|
|
10
|
+
* - retry on HTTP 408, 429, 500, 502, 503, 504
|
|
11
|
+
* - retry on network errors (fetch throws)
|
|
12
|
+
* - DO NOT retry on 4xx other than 408/429 (those are bad requests / auth)
|
|
13
|
+
* - retries only the initial fetch — never mid-stream
|
|
14
|
+
* - respects Retry-After header when present
|
|
15
|
+
*/
|
|
16
|
+
interface RetryOptions {
|
|
17
|
+
maxAttempts?: number;
|
|
18
|
+
baseDelayMs?: number;
|
|
19
|
+
maxDelayMs?: number;
|
|
20
|
+
jitter?: boolean;
|
|
21
|
+
retryOn?: (info: {
|
|
22
|
+
error?: unknown;
|
|
23
|
+
response?: Response;
|
|
24
|
+
attempt: number;
|
|
25
|
+
}) => boolean;
|
|
26
|
+
/** Hook for tests + logging. Called after every failed attempt. */
|
|
27
|
+
onRetry?: (info: {
|
|
28
|
+
attempt: number;
|
|
29
|
+
delayMs: number;
|
|
30
|
+
reason: string;
|
|
31
|
+
}) => void;
|
|
32
|
+
/** Sleep override for tests. Defaults to setTimeout. */
|
|
33
|
+
sleep?: (ms: number) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Run a fetch with retries on transient failures. Returns the final
|
|
37
|
+
* Response (whether successful or not — caller decides), or throws if
|
|
38
|
+
* the AbortSignal fires or all attempts fail with a thrown error.
|
|
39
|
+
*/
|
|
40
|
+
declare function fetchWithRetry(doFetch: (signal: AbortSignal) => Promise<Response>, signal: AbortSignal, retryOpt?: RetryOptions): Promise<Response>;
|
|
41
|
+
/**
|
|
42
|
+
* Chunk-splitter that turns one large string into N streamable text chunks.
|
|
43
|
+
* Useful when a provider returns the full response in one shot and you
|
|
44
|
+
* want to feed it to a UI that expects streaming.
|
|
45
|
+
*
|
|
46
|
+
* Default splits by whitespace boundaries with a target chunk size of ~32
|
|
47
|
+
* characters.
|
|
48
|
+
*/
|
|
49
|
+
declare function chunkText(text: string, targetSize?: number): string[];
|
|
50
|
+
/**
|
|
51
|
+
* Build a StreamSource from a non-streaming fetch. The adapter is
|
|
52
|
+
* auto-completing: it fetches once, then yields the text as a sequence
|
|
53
|
+
* of chunks so UIs see the same streaming shape they'd see from a
|
|
54
|
+
* native streaming provider.
|
|
55
|
+
*
|
|
56
|
+
* Use this when you're wiring a provider that only has a non-streaming
|
|
57
|
+
* endpoint but you want consumers (useChat, the runtime) to get
|
|
58
|
+
* identical ergonomics.
|
|
59
|
+
*/
|
|
60
|
+
declare function simulateStream(doFetch: (signal: AbortSignal) => Promise<Response>, extractText: (response: Response) => Promise<string>, errorLabel: string, options?: {
|
|
61
|
+
chunkSize?: number;
|
|
62
|
+
delayMs?: number;
|
|
63
|
+
retry?: RetryOptions;
|
|
64
|
+
}): StreamSource;
|
|
65
|
+
|
|
66
|
+
export { type RetryOptions as R, chunkText as c, fetchWithRetry as f, simulateStream as s };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { StreamSource } from '@agentskit/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retry knobs for adapter fetches. Tunable per call to createStreamSource.
|
|
5
|
+
*
|
|
6
|
+
* Default behavior:
|
|
7
|
+
* - 3 attempts total (1 initial + 2 retries)
|
|
8
|
+
* - exponential backoff: 500ms, 1000ms, 2000ms ... (capped at maxDelayMs)
|
|
9
|
+
* - full jitter on each delay
|
|
10
|
+
* - retry on HTTP 408, 429, 500, 502, 503, 504
|
|
11
|
+
* - retry on network errors (fetch throws)
|
|
12
|
+
* - DO NOT retry on 4xx other than 408/429 (those are bad requests / auth)
|
|
13
|
+
* - retries only the initial fetch — never mid-stream
|
|
14
|
+
* - respects Retry-After header when present
|
|
15
|
+
*/
|
|
16
|
+
interface RetryOptions {
|
|
17
|
+
maxAttempts?: number;
|
|
18
|
+
baseDelayMs?: number;
|
|
19
|
+
maxDelayMs?: number;
|
|
20
|
+
jitter?: boolean;
|
|
21
|
+
retryOn?: (info: {
|
|
22
|
+
error?: unknown;
|
|
23
|
+
response?: Response;
|
|
24
|
+
attempt: number;
|
|
25
|
+
}) => boolean;
|
|
26
|
+
/** Hook for tests + logging. Called after every failed attempt. */
|
|
27
|
+
onRetry?: (info: {
|
|
28
|
+
attempt: number;
|
|
29
|
+
delayMs: number;
|
|
30
|
+
reason: string;
|
|
31
|
+
}) => void;
|
|
32
|
+
/** Sleep override for tests. Defaults to setTimeout. */
|
|
33
|
+
sleep?: (ms: number) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Run a fetch with retries on transient failures. Returns the final
|
|
37
|
+
* Response (whether successful or not — caller decides), or throws if
|
|
38
|
+
* the AbortSignal fires or all attempts fail with a thrown error.
|
|
39
|
+
*/
|
|
40
|
+
declare function fetchWithRetry(doFetch: (signal: AbortSignal) => Promise<Response>, signal: AbortSignal, retryOpt?: RetryOptions): Promise<Response>;
|
|
41
|
+
/**
|
|
42
|
+
* Chunk-splitter that turns one large string into N streamable text chunks.
|
|
43
|
+
* Useful when a provider returns the full response in one shot and you
|
|
44
|
+
* want to feed it to a UI that expects streaming.
|
|
45
|
+
*
|
|
46
|
+
* Default splits by whitespace boundaries with a target chunk size of ~32
|
|
47
|
+
* characters.
|
|
48
|
+
*/
|
|
49
|
+
declare function chunkText(text: string, targetSize?: number): string[];
|
|
50
|
+
/**
|
|
51
|
+
* Build a StreamSource from a non-streaming fetch. The adapter is
|
|
52
|
+
* auto-completing: it fetches once, then yields the text as a sequence
|
|
53
|
+
* of chunks so UIs see the same streaming shape they'd see from a
|
|
54
|
+
* native streaming provider.
|
|
55
|
+
*
|
|
56
|
+
* Use this when you're wiring a provider that only has a non-streaming
|
|
57
|
+
* endpoint but you want consumers (useChat, the runtime) to get
|
|
58
|
+
* identical ergonomics.
|
|
59
|
+
*/
|
|
60
|
+
declare function simulateStream(doFetch: (signal: AbortSignal) => Promise<Response>, extractText: (response: Response) => Promise<string>, errorLabel: string, options?: {
|
|
61
|
+
chunkSize?: number;
|
|
62
|
+
delayMs?: number;
|
|
63
|
+
retry?: RetryOptions;
|
|
64
|
+
}): StreamSource;
|
|
65
|
+
|
|
66
|
+
export { type RetryOptions as R, chunkText as c, fetchWithRetry as f, simulateStream as s };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentskit/adapters",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Provider adapters for AgentsKit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentskit",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"provider-adapter"
|
|
26
26
|
],
|
|
27
27
|
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
28
29
|
"main": "./dist/index.cjs",
|
|
29
30
|
"module": "./dist/index.js",
|
|
30
31
|
"types": "./dist/index.d.ts",
|
|
@@ -33,20 +34,32 @@
|
|
|
33
34
|
"types": "./dist/index.d.ts",
|
|
34
35
|
"import": "./dist/index.js",
|
|
35
36
|
"require": "./dist/index.cjs"
|
|
37
|
+
},
|
|
38
|
+
"./createAdapter": {
|
|
39
|
+
"types": "./dist/createAdapter.d.ts",
|
|
40
|
+
"import": "./dist/createAdapter.js",
|
|
41
|
+
"require": "./dist/createAdapter.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./catalog": {
|
|
44
|
+
"types": "./dist/catalog/index.d.ts",
|
|
45
|
+
"import": "./dist/catalog/index.js",
|
|
46
|
+
"require": "./dist/catalog/index.cjs"
|
|
36
47
|
}
|
|
37
48
|
},
|
|
38
49
|
"files": [
|
|
39
50
|
"dist"
|
|
40
51
|
],
|
|
41
52
|
"dependencies": {
|
|
42
|
-
"@agentskit/core": "1.
|
|
53
|
+
"@agentskit/core": "1.8.0"
|
|
43
54
|
},
|
|
44
55
|
"devDependencies": {
|
|
45
|
-
"@types/
|
|
46
|
-
"
|
|
47
|
-
"
|
|
56
|
+
"@types/json-schema": "^7.0.15",
|
|
57
|
+
"@types/node": "^25.9.2",
|
|
58
|
+
"msw": "^2.14.6",
|
|
59
|
+
"tsup": "^8.5.1",
|
|
48
60
|
"typescript": "^6.0.3",
|
|
49
|
-
"vitest": "^4.1.
|
|
61
|
+
"vitest": "^4.1.8",
|
|
62
|
+
"@agentskit/validation": "0.2.0"
|
|
50
63
|
},
|
|
51
64
|
"peerDependencies": {
|
|
52
65
|
"@aws-sdk/client-bedrock-runtime": "^3.0.0"
|