@halo-sdk/stream 1.0.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/README.md +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/stream.d.ts +18 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +68 -0
- package/dist/stream.js.map +1 -0
- package/package.json +47 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TurnChunk, ToolCall, Usage } from "@halo-sdk/core";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps an AsyncGenerator<TurnChunk> as an SSE Response.
|
|
4
|
+
* Format compatible with Vercel AI SDK's 0:/d: protocol.
|
|
5
|
+
*/
|
|
6
|
+
export declare function toDataStream(source: AsyncGenerator<TurnChunk>, opts?: {
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
}): Response;
|
|
9
|
+
/**
|
|
10
|
+
* Custom stream entry. Does not go through HaloAgent.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createHaloStream(fn: (ctrl: {
|
|
13
|
+
writeText: (delta: string) => void;
|
|
14
|
+
writeToolCall: (call: ToolCall) => void;
|
|
15
|
+
close: (usage?: Usage) => void;
|
|
16
|
+
error: (err: Error) => void;
|
|
17
|
+
}) => Promise<void>): ReadableStream;
|
|
18
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,cAAc,CAAC,SAAS,CAAC,EACjC,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAC1C,QAAQ,CAqCV;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,CAAC,IAAI,EAAE;IACT,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,aAAa,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACxC,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IAC/B,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAC7B,KAAK,OAAO,CAAC,IAAI,CAAC,GAClB,cAAc,CAoBhB"}
|
package/dist/stream.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps an AsyncGenerator<TurnChunk> as an SSE Response.
|
|
3
|
+
* Format compatible with Vercel AI SDK's 0:/d: protocol.
|
|
4
|
+
*/
|
|
5
|
+
export function toDataStream(source, opts) {
|
|
6
|
+
const stream = new ReadableStream({
|
|
7
|
+
async start(controller) {
|
|
8
|
+
const encoder = new TextEncoder();
|
|
9
|
+
try {
|
|
10
|
+
for await (const chunk of source) {
|
|
11
|
+
switch (chunk.type) {
|
|
12
|
+
case "text-delta":
|
|
13
|
+
controller.enqueue(encoder.encode(`0:${JSON.stringify(chunk.delta)}\n`));
|
|
14
|
+
break;
|
|
15
|
+
case "tool-call-delta":
|
|
16
|
+
controller.enqueue(encoder.encode(`9:${JSON.stringify([chunk])}\n`));
|
|
17
|
+
break;
|
|
18
|
+
case "tool-call-ready":
|
|
19
|
+
controller.enqueue(encoder.encode(`9:${JSON.stringify([chunk])}\n`));
|
|
20
|
+
break;
|
|
21
|
+
case "done":
|
|
22
|
+
controller.enqueue(encoder.encode(`d:${JSON.stringify({ usage: chunk.usage })}\n`));
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
controller.error(err);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
controller.close();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return new Response(stream, {
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "text/event-stream",
|
|
38
|
+
"Cache-Control": "no-cache",
|
|
39
|
+
Connection: "keep-alive",
|
|
40
|
+
...opts?.headers,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Custom stream entry. Does not go through HaloAgent.
|
|
46
|
+
*/
|
|
47
|
+
export function createHaloStream(fn) {
|
|
48
|
+
return new ReadableStream({
|
|
49
|
+
async start(controller) {
|
|
50
|
+
const encoder = new TextEncoder();
|
|
51
|
+
await fn({
|
|
52
|
+
writeText(delta) {
|
|
53
|
+
controller.enqueue(encoder.encode(delta));
|
|
54
|
+
},
|
|
55
|
+
writeToolCall(call) {
|
|
56
|
+
controller.enqueue(encoder.encode(JSON.stringify(call)));
|
|
57
|
+
},
|
|
58
|
+
close(_usage) {
|
|
59
|
+
controller.close();
|
|
60
|
+
},
|
|
61
|
+
error(err) {
|
|
62
|
+
controller.error(err);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+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;YACxB,CAAC;oBAAS,CAAC;gBACT,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;QAC1B,OAAO,EAAE;YACP,cAAc,EAAE,mBAAmB;YACnC,eAAe,EAAE,UAAU;YAC3B,UAAU,EAAE,YAAY;YACxB,GAAG,IAAI,EAAE,OAAO;SACjB;KACF,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,EAKmB;IAEnB,OAAO,IAAI,cAAc,CAAC;QACxB,KAAK,CAAC,KAAK,CAAC,UAAU;YACpB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;YAClC,MAAM,EAAE,CAAC;gBACP,SAAS,CAAC,KAAK;oBACb,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC5C,CAAC;gBACD,aAAa,CAAC,IAAI;oBAChB,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC3D,CAAC;gBACD,KAAK,CAAC,MAAM;oBACV,UAAU,CAAC,KAAK,EAAE,CAAC;gBACrB,CAAC;gBACD,KAAK,CAAC,GAAG;oBACP,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACxB,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@halo-sdk/stream",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Streaming utilities for Halo AI SDK — SSE Response for Vercel AI SDK compatibility",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"ai",
|
|
8
|
+
"llm",
|
|
9
|
+
"streaming",
|
|
10
|
+
"sse",
|
|
11
|
+
"vercel-ai-sdk"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/halo-sdk/halo-ai",
|
|
16
|
+
"directory": "packages/stream"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@halo-sdk/core": ">=1.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"typescript": "^5.8.0",
|
|
38
|
+
"vitest": "^3.0.0",
|
|
39
|
+
"@halo-sdk/core": "1.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"dev": "tsc --watch",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest"
|
|
46
|
+
}
|
|
47
|
+
}
|