llm-stream-assemble 1.0.0 → 1.0.1
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 +7 -114
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# llm-stream-assemble
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|

|
|
5
5
|

|
|
6
6
|

|
|
7
7
|
[](https://github.com/01laky/llm-stream-assemble/actions/workflows/ci.yml)
|
|
8
|
-

|
|
9
9
|
|
|
10
10
|
A zero-dependency TypeScript library that normalizes LLM streaming responses — text, tool calls, reasoning, JSON, usage, errors, and non-streaming payloads — into unified events.
|
|
11
11
|
|
|
12
|
-
**Status:** Stable `1.0.
|
|
12
|
+
**Status:** Stable `1.0.1`. Core, OpenAI Chat, OpenAI-compatible, Anthropic Messages, OpenAI Responses adapters, transforms, replay helpers, and examples are production-ready. Pin semver ranges as usual and review [CHANGELOG.md](./CHANGELOG.md) before major upgrades.
|
|
13
13
|
|
|
14
14
|
> A zero-dependency TypeScript layer for assembling OpenAI, Anthropic, and compatible LLM streams into unified events for text, tool calls, reasoning, JSON, usage, errors, and non-streaming responses - so you can stop hand-rolling provider parsers and keep one clean, typed event model across LLM apps, agents, proxies, and backends.
|
|
15
15
|
|
|
@@ -17,120 +17,13 @@ A zero-dependency TypeScript library that normalizes LLM streaming responses —
|
|
|
17
17
|
|
|
18
18
|
Raw provider bytes enter through a **thin adapter**, get assembled into **typed events**, and leave through the same transform layer whether you stream live, replay fixtures, or proxy to a browser.
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
flowchart TB
|
|
22
|
-
subgraph PROVIDERS["LLM providers"]
|
|
23
|
-
direction LR
|
|
24
|
-
PC["OpenAI Chat"]
|
|
25
|
-
PA["Anthropic Messages"]
|
|
26
|
-
PO["OpenAI-compatible hosts"]
|
|
27
|
-
PR["OpenAI Responses"]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
subgraph ADAPTERS["Adapters · parseChunk / parseResponse"]
|
|
31
|
-
direction LR
|
|
32
|
-
AC["openaiChatAdapter"]
|
|
33
|
-
AA["anthropicAdapter"]
|
|
34
|
-
AO["openaiCompatibleAdapter"]
|
|
35
|
-
AR["openaiResponsesAdapter"]
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
subgraph CORE["Core assembly · provider-agnostic"]
|
|
39
|
-
direction TB
|
|
40
|
-
STREAM(["ReadableStream / SSE"])
|
|
41
|
-
JSON(["JSON response body"])
|
|
42
|
-
PARSE["parseSSE · parsePartialJSON"]
|
|
43
|
-
RAW["RawChunk[]"]
|
|
44
|
-
ASM["EventAssembler"]
|
|
45
|
-
EVENTS(["StreamEvent stream"])
|
|
46
|
-
STREAM --> PARSE --> RAW --> ASM --> EVENTS
|
|
47
|
-
JSON --> RAW
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
subgraph TRANSFORMS["Transforms & helpers"]
|
|
51
|
-
direction LR
|
|
52
|
-
COL["collectStream"]
|
|
53
|
-
TAP["tapEvents"]
|
|
54
|
-
SSEOUT["toSSE"]
|
|
55
|
-
REPLAY["assembleFromFile"]
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
subgraph APPS["Your application"]
|
|
59
|
-
direction LR
|
|
60
|
-
UI["Chat UI"]
|
|
61
|
-
AGENT["Agents & tool routing"]
|
|
62
|
-
PROXY["Backend proxy"]
|
|
63
|
-
OBS["Logs & metrics"]
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
PC --> AC
|
|
67
|
-
PA --> AA
|
|
68
|
-
PO --> AO
|
|
69
|
-
PR --> AR
|
|
70
|
-
PARSE --> AC
|
|
71
|
-
PARSE --> AA
|
|
72
|
-
PARSE --> AO
|
|
73
|
-
PARSE --> AR
|
|
74
|
-
AC --> RAW
|
|
75
|
-
AA --> RAW
|
|
76
|
-
AO --> RAW
|
|
77
|
-
AR --> RAW
|
|
78
|
-
JSON --> AC
|
|
79
|
-
JSON --> AA
|
|
80
|
-
JSON --> AO
|
|
81
|
-
JSON --> AR
|
|
82
|
-
EVENTS --> COL
|
|
83
|
-
EVENTS --> TAP
|
|
84
|
-
EVENTS --> SSEOUT
|
|
85
|
-
EVENTS --> REPLAY
|
|
86
|
-
COL --> UI
|
|
87
|
-
COL --> AGENT
|
|
88
|
-
SSEOUT --> PROXY
|
|
89
|
-
TAP --> OBS
|
|
90
|
-
|
|
91
|
-
classDef provider fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#e0f2fe
|
|
92
|
-
classDef adapter fill:#1e1b4b,stroke:#818cf8,stroke-width:2px,color:#ede9fe
|
|
93
|
-
classDef core fill:#042f2e,stroke:#2dd4bf,stroke-width:2px,color:#ccfbf1
|
|
94
|
-
classDef io fill:#134e4a,stroke:#5eead4,stroke-width:2px,color:#f0fdfa
|
|
95
|
-
classDef transform fill:#431407,stroke:#fb923c,stroke-width:2px,color:#ffedd5
|
|
96
|
-
classDef app fill:#172554,stroke:#60a5fa,stroke-width:2px,color:#dbeafe
|
|
97
|
-
|
|
98
|
-
class PC,PA,PO,PR provider
|
|
99
|
-
class AC,AA,AO,AR adapter
|
|
100
|
-
class PARSE,RAW,ASM core
|
|
101
|
-
class STREAM,JSON,EVENTS io
|
|
102
|
-
class COL,TAP,SSEOUT,REPLAY transform
|
|
103
|
-
class UI,AGENT,PROXY,OBS app
|
|
104
|
-
```
|
|
20
|
+

|
|
105
21
|
|
|
106
22
|
Every adapter maps provider-specific fragments into the same **`StreamEvent`** union — one event model for streaming and non-streaming code paths:
|
|
107
23
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Text
|
|
112
|
-
text.delta
|
|
113
|
-
text.done
|
|
114
|
-
Reasoning
|
|
115
|
-
reasoning.delta
|
|
116
|
-
reasoning.done
|
|
117
|
-
Tools
|
|
118
|
-
tool_call.start
|
|
119
|
-
tool_call.args.delta
|
|
120
|
-
tool_call.done
|
|
121
|
-
Structured
|
|
122
|
-
json.delta
|
|
123
|
-
json.done
|
|
124
|
-
Control
|
|
125
|
-
message.start
|
|
126
|
-
metadata
|
|
127
|
-
usage
|
|
128
|
-
finish
|
|
129
|
-
error
|
|
130
|
-
Safety
|
|
131
|
-
refusal.delta
|
|
132
|
-
refusal.done
|
|
133
|
-
```
|
|
24
|
+

|
|
25
|
+
|
|
26
|
+
Diagram sources (Mermaid): [`docs/img/pipeline.mmd`](./docs/img/pipeline.mmd), [`docs/img/stream-event.mmd`](./docs/img/stream-event.mmd). Regenerate SVGs with `@mermaid-js/mermaid-cli` after editing.
|
|
134
27
|
|
|
135
28
|
**Design constraints:** adapters never accumulate cross-chunk state beyond id/index reconciliation; assembly, buffering, and `.done` emission live in core. No HTTP client, no tool execution, no UI — just the stream layer.
|
|
136
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-stream-assemble",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A zero-dependency TypeScript layer for assembling OpenAI, Anthropic, and compatible LLM streams into unified events for text, tool calls, reasoning, JSON, usage, errors, and non-streaming responses.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ladislav Kostolny <01laky@gmail.com>",
|