@tambo-ai/typescript-sdk 0.39.0 → 0.40.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/CHANGELOG.md +9 -0
- package/lib/advance-stream.d.ts.map +1 -1
- package/lib/advance-stream.js +59 -27
- package/lib/advance-stream.js.map +1 -1
- package/lib/advance-stream.mjs +59 -27
- package/lib/advance-stream.mjs.map +1 -1
- package/package.json +1 -1
- package/src/lib/advance-stream.ts +62 -37
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.40.0 (2025-03-26)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v0.39.0...v0.40.0](https://github.com/tambo-ai/typescript-sdk/compare/v0.39.0...v0.40.0)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* fix: Try to skip broken chunk ([#193](https://github.com/tambo-ai/typescript-sdk/issues/193)) ([8822f17](https://github.com/tambo-ai/typescript-sdk/commit/8822f17f187f0a1a0a4f8316e5ba288e49a1af3b))
|
|
10
|
+
* fix: use built-in ReadableStream shim type ([#191](https://github.com/tambo-ai/typescript-sdk/issues/191)) ([4002317](https://github.com/tambo-ai/typescript-sdk/commit/40023172b988d4add3527684bf26a80ae6fbaa83))
|
|
11
|
+
|
|
3
12
|
## 0.39.0 (2025-03-26)
|
|
4
13
|
|
|
5
14
|
Full Changelog: [v0.38.1...v0.39.0](https://github.com/tambo-ai/typescript-sdk/compare/v0.38.1...v0.39.0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advance-stream.d.ts","sourceRoot":"","sources":["../src/lib/advance-stream.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"advance-stream.d.ts","sourceRoot":"","sources":["../src/lib/advance-stream.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,IAAI,CAAC;AAEzB,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE/E,wBAAsB,aAAa,CACjC,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,mBAAmB,EACzB,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAC5B,OAAO,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC,CA4B/C"}
|
package/lib/advance-stream.js
CHANGED
|
@@ -2,40 +2,72 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.advanceStream = void 0;
|
|
4
4
|
async function advanceStream(client, body, threadId, options) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const MAX_REQUEST_RETRIES = 2;
|
|
6
|
+
let requestRetryCount = 0;
|
|
7
|
+
while (true) {
|
|
8
|
+
try {
|
|
9
|
+
const responsePromise = client.post(`/threads${threadId ? `/${threadId}` : ''}/advancestream`, {
|
|
10
|
+
body,
|
|
11
|
+
...options,
|
|
12
|
+
headers: {
|
|
13
|
+
...options?.headers,
|
|
14
|
+
Accept: 'text/event-stream',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const response = await responsePromise.asResponse();
|
|
18
|
+
return handleStreamResponse(response);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (requestRetryCount < MAX_REQUEST_RETRIES) {
|
|
22
|
+
requestRetryCount++;
|
|
23
|
+
console.warn(`Request failed, attempting retry ${requestRetryCount}/${MAX_REQUEST_RETRIES}`);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
15
29
|
}
|
|
16
30
|
exports.advanceStream = advanceStream;
|
|
17
31
|
async function* handleStreamResponse(response) {
|
|
18
32
|
const decoder = new TextDecoder();
|
|
33
|
+
const MAX_CHUNK_RETRIES = 5;
|
|
34
|
+
let chunkRetryCount = 0;
|
|
19
35
|
const reader = response.body.getReader();
|
|
20
36
|
while (true) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
try {
|
|
38
|
+
const { done, value: chunk } = await reader.read();
|
|
39
|
+
if (done)
|
|
40
|
+
break;
|
|
41
|
+
const text = decoder.decode(chunk);
|
|
42
|
+
const messages = text.split('\n').filter((msg) => msg.trim());
|
|
43
|
+
for (const msg of messages) {
|
|
44
|
+
if (msg === 'data: DONE') {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (msg.startsWith('error: ')) {
|
|
48
|
+
throw new Error(msg.slice(7));
|
|
49
|
+
}
|
|
50
|
+
const jsonStr = msg.startsWith('data: ') ? msg.slice(6) : msg;
|
|
51
|
+
if (!jsonStr) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
yield JSON.parse(jsonStr);
|
|
56
|
+
chunkRetryCount = 0;
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (chunkRetryCount < MAX_CHUNK_RETRIES) {
|
|
60
|
+
chunkRetryCount++;
|
|
61
|
+
console.warn(`Failed to parse JSON chunk, skipping. Attempt ${chunkRetryCount}/${MAX_CHUNK_RETRIES}`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
throw new Error('Failed to parse JSON after multiple chunks.');
|
|
65
|
+
}
|
|
33
66
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
yield JSON.parse(jsonStr);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
reader.releaseLock();
|
|
70
|
+
throw error;
|
|
39
71
|
}
|
|
40
72
|
}
|
|
41
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advance-stream.js","sourceRoot":"","sources":["../src/lib/advance-stream.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"advance-stream.js","sourceRoot":"","sources":["../src/lib/advance-stream.ts"],"names":[],"mappings":";;;AAMO,KAAK,UAAU,aAAa,CACjC,MAAe,EACf,IAAyB,EACzB,QAAiB,EACjB,OAA6B;IAE7B,MAAM,mBAAmB,GAAG,CAAC,CAAC;IAC9B,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAE1B,OAAO,IAAI,EAAE;QACX,IAAI;YACF,MAAM,eAAe,GAA2C,MAAM,CAAC,IAAI,CACzE,WAAW,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EACzD;gBACE,IAAI;gBACJ,GAAG,OAAO;gBACV,OAAO,EAAE;oBACP,GAAG,OAAO,EAAE,OAAO;oBACnB,MAAM,EAAE,mBAAmB;iBAC5B;aACF,CACF,CAAC;YACF,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,UAAU,EAAE,CAAC;YACpD,OAAO,oBAAoB,CAAwB,QAAQ,CAAC,CAAC;SAC9D;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,iBAAiB,GAAG,mBAAmB,EAAE;gBAC3C,iBAAiB,EAAE,CAAC;gBACpB,OAAO,CAAC,IAAI,CAAC,oCAAoC,iBAAiB,IAAI,mBAAmB,EAAE,CAAC,CAAC;gBAC7F,SAAS;aACV;YACD,MAAM,KAAK,CAAC;SACb;KACF;AACH,CAAC;AAjCD,sCAiCC;AAED,KAAK,SAAS,CAAC,CAAC,oBAAoB,CAAI,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IAAI,CACV,iDAAiD,eAAe,IAAI,iBAAiB,EAAE,CACxF,CAAC;wBACF,SAAS;qBACV;oBACD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;iBAChE;aACF;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,KAAK,CAAC;SACb;KACF;AACH,CAAC"}
|
package/lib/advance-stream.mjs
CHANGED
|
@@ -1,37 +1,69 @@
|
|
|
1
1
|
export async function advanceStream(client, body, threadId, options) {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
const MAX_REQUEST_RETRIES = 2;
|
|
3
|
+
let requestRetryCount = 0;
|
|
4
|
+
while (true) {
|
|
5
|
+
try {
|
|
6
|
+
const responsePromise = client.post(`/threads${threadId ? `/${threadId}` : ''}/advancestream`, {
|
|
7
|
+
body,
|
|
8
|
+
...options,
|
|
9
|
+
headers: {
|
|
10
|
+
...options?.headers,
|
|
11
|
+
Accept: 'text/event-stream',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const response = await responsePromise.asResponse();
|
|
15
|
+
return handleStreamResponse(response);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (requestRetryCount < MAX_REQUEST_RETRIES) {
|
|
19
|
+
requestRetryCount++;
|
|
20
|
+
console.warn(`Request failed, attempting retry ${requestRetryCount}/${MAX_REQUEST_RETRIES}`);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
12
26
|
}
|
|
13
27
|
async function* handleStreamResponse(response) {
|
|
14
28
|
const decoder = new TextDecoder();
|
|
29
|
+
const MAX_CHUNK_RETRIES = 5;
|
|
30
|
+
let chunkRetryCount = 0;
|
|
15
31
|
const reader = response.body.getReader();
|
|
16
32
|
while (true) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
try {
|
|
34
|
+
const { done, value: chunk } = await reader.read();
|
|
35
|
+
if (done)
|
|
36
|
+
break;
|
|
37
|
+
const text = decoder.decode(chunk);
|
|
38
|
+
const messages = text.split('\n').filter((msg) => msg.trim());
|
|
39
|
+
for (const msg of messages) {
|
|
40
|
+
if (msg === 'data: DONE') {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (msg.startsWith('error: ')) {
|
|
44
|
+
throw new Error(msg.slice(7));
|
|
45
|
+
}
|
|
46
|
+
const jsonStr = msg.startsWith('data: ') ? msg.slice(6) : msg;
|
|
47
|
+
if (!jsonStr) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
yield JSON.parse(jsonStr);
|
|
52
|
+
chunkRetryCount = 0;
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
if (chunkRetryCount < MAX_CHUNK_RETRIES) {
|
|
56
|
+
chunkRetryCount++;
|
|
57
|
+
console.warn(`Failed to parse JSON chunk, skipping. Attempt ${chunkRetryCount}/${MAX_CHUNK_RETRIES}`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
throw new Error('Failed to parse JSON after multiple chunks.');
|
|
61
|
+
}
|
|
29
62
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
yield JSON.parse(jsonStr);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
reader.releaseLock();
|
|
66
|
+
throw error;
|
|
35
67
|
}
|
|
36
68
|
}
|
|
37
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advance-stream.mjs","sourceRoot":"","sources":["../src/lib/advance-stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"advance-stream.mjs","sourceRoot":"","sources":["../src/lib/advance-stream.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAe,EACf,IAAyB,EACzB,QAAiB,EACjB,OAA6B;IAE7B,MAAM,mBAAmB,GAAG,CAAC,CAAC;IAC9B,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAE1B,OAAO,IAAI,EAAE;QACX,IAAI;YACF,MAAM,eAAe,GAA2C,MAAM,CAAC,IAAI,CACzE,WAAW,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EACzD;gBACE,IAAI;gBACJ,GAAG,OAAO;gBACV,OAAO,EAAE;oBACP,GAAG,OAAO,EAAE,OAAO;oBACnB,MAAM,EAAE,mBAAmB;iBAC5B;aACF,CACF,CAAC;YACF,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,UAAU,EAAE,CAAC;YACpD,OAAO,oBAAoB,CAAwB,QAAQ,CAAC,CAAC;SAC9D;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,iBAAiB,GAAG,mBAAmB,EAAE;gBAC3C,iBAAiB,EAAE,CAAC;gBACpB,OAAO,CAAC,IAAI,CAAC,oCAAoC,iBAAiB,IAAI,mBAAmB,EAAE,CAAC,CAAC;gBAC7F,SAAS;aACV;YACD,MAAM,KAAK,CAAC;SACb;KACF;AACH,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,oBAAoB,CAAI,QAAkB;IACxD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,iBAAiB,GAAG,CAAC,CAAC;IAC5B,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,MAAM,MAAM,GAAI,QAAQ,CAAC,IAAkC,CAAC,SAAS,EAAE,CAAC;IAExE,OAAO,IAAI,EAAE;QACX,IAAI;YACF,MAAM,EAAE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
package/package.json
CHANGED
|
@@ -1,65 +1,90 @@
|
|
|
1
1
|
import { Response } from 'node-fetch';
|
|
2
2
|
import TamboAI from '..';
|
|
3
|
+
import { type ReadableStream } from '../_shims';
|
|
3
4
|
import * as Core from '../core';
|
|
4
5
|
import { ThreadAdvanceParams, ThreadAdvanceResponse } from '../resources/beta';
|
|
5
6
|
|
|
6
|
-
type WebReadableStream = {
|
|
7
|
-
getReader(): {
|
|
8
|
-
read(): Promise<{ done: boolean; value: Uint8Array | undefined }>;
|
|
9
|
-
releaseLock(): void;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
7
|
export async function advanceStream(
|
|
14
8
|
client: TamboAI,
|
|
15
9
|
body: ThreadAdvanceParams,
|
|
16
10
|
threadId?: string,
|
|
17
11
|
options?: Core.RequestOptions,
|
|
18
12
|
): Promise<AsyncIterable<ThreadAdvanceResponse>> {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
body,
|
|
23
|
-
...options,
|
|
24
|
-
headers: {
|
|
25
|
-
...options?.headers,
|
|
26
|
-
Accept: 'text/event-stream',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
);
|
|
30
|
-
const response = await responsePromise.asResponse();
|
|
13
|
+
const MAX_REQUEST_RETRIES = 2;
|
|
14
|
+
let requestRetryCount = 0;
|
|
31
15
|
|
|
32
|
-
|
|
16
|
+
while (true) {
|
|
17
|
+
try {
|
|
18
|
+
const responsePromise: Core.APIPromise<ThreadAdvanceResponse> = client.post(
|
|
19
|
+
`/threads${threadId ? `/${threadId}` : ''}/advancestream`,
|
|
20
|
+
{
|
|
21
|
+
body,
|
|
22
|
+
...options,
|
|
23
|
+
headers: {
|
|
24
|
+
...options?.headers,
|
|
25
|
+
Accept: 'text/event-stream',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
const response = await responsePromise.asResponse();
|
|
30
|
+
return handleStreamResponse<ThreadAdvanceResponse>(response);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (requestRetryCount < MAX_REQUEST_RETRIES) {
|
|
33
|
+
requestRetryCount++;
|
|
34
|
+
console.warn(`Request failed, attempting retry ${requestRetryCount}/${MAX_REQUEST_RETRIES}`);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
async function* handleStreamResponse<T>(response: Response): AsyncIterable<T> {
|
|
36
43
|
const decoder = new TextDecoder();
|
|
37
|
-
const
|
|
44
|
+
const MAX_CHUNK_RETRIES = 5;
|
|
45
|
+
let chunkRetryCount = 0;
|
|
46
|
+
const reader = (response.body as unknown as ReadableStream).getReader();
|
|
38
47
|
|
|
39
48
|
while (true) {
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
try {
|
|
50
|
+
const { done, value: chunk } = await reader.read();
|
|
51
|
+
if (done) break;
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
const text = decoder.decode(chunk as Uint8Array);
|
|
54
|
+
const messages = text.split('\n').filter((msg) => msg.trim());
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
for (const msg of messages) {
|
|
57
|
+
if (msg === 'data: DONE') {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
47
60
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
61
|
+
if (msg.startsWith('error: ')) {
|
|
62
|
+
throw new Error(msg.slice(7));
|
|
63
|
+
}
|
|
52
64
|
|
|
53
|
-
|
|
54
|
-
throw new Error(msg.slice(7));
|
|
55
|
-
}
|
|
65
|
+
const jsonStr = msg.startsWith('data: ') ? msg.slice(6) : msg;
|
|
56
66
|
|
|
57
|
-
|
|
67
|
+
if (!jsonStr) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
try {
|
|
72
|
+
yield JSON.parse(jsonStr) as T;
|
|
73
|
+
chunkRetryCount = 0;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (chunkRetryCount < MAX_CHUNK_RETRIES) {
|
|
76
|
+
chunkRetryCount++;
|
|
77
|
+
console.warn(
|
|
78
|
+
`Failed to parse JSON chunk, skipping. Attempt ${chunkRetryCount}/${MAX_CHUNK_RETRIES}`,
|
|
79
|
+
);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
throw new Error('Failed to parse JSON after multiple chunks.');
|
|
83
|
+
}
|
|
61
84
|
}
|
|
62
|
-
|
|
85
|
+
} catch (error) {
|
|
86
|
+
reader.releaseLock();
|
|
87
|
+
throw error;
|
|
63
88
|
}
|
|
64
89
|
}
|
|
65
90
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.40.0'; // x-release-please-version
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.40.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.40.0'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|