@cuylabs/agent-http 0.1.6 → 0.5.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 +36 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +15 -19
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# @cuylabs/agent-http
|
|
2
2
|
|
|
3
|
-
HTTP streaming adapter for [@cuylabs/agent-core](https://github.com/cuylabs-ai/agents-ts/tree/main/packages/agent-core). Bridges agent events to AI SDK v6 UIMessageStream for use with `useChat()`.
|
|
3
|
+
HTTP streaming adapter for [@cuylabs/agent-core](https://github.com/cuylabs-ai/agents-ts/tree/main/packages/agent-core). Bridges agent events to AI SDK v6 `UIMessageStream` for use with `useChat()`.
|
|
4
|
+
|
|
5
|
+
It maps the UI-facing streaming events (`text-*`, `reasoning-*`, `tool-*`, `error`) and intentionally skips advanced agent-core events that do not have a direct `UIMessageStream` equivalent (`turn-boundary`, `turn-summary`, approvals, interventions, retries, etc.).
|
|
6
|
+
|
|
7
|
+
This package is intentionally narrow:
|
|
8
|
+
|
|
9
|
+
- It is a good way to expose an agent over HTTP when your client already speaks the AI SDK v6 chat stream protocol.
|
|
10
|
+
- It is not a full generic agent hosting layer, REST API surface, or control plane.
|
|
11
|
+
- For broader host/runtime concerns, keep those in your app or use the runtime packages.
|
|
4
12
|
|
|
5
13
|
## Installation
|
|
6
14
|
|
|
@@ -34,6 +42,12 @@ export async function POST(req: Request) {
|
|
|
34
42
|
const { messages, id } = await req.json();
|
|
35
43
|
const lastMessage = messages[messages.length - 1];
|
|
36
44
|
|
|
45
|
+
if (typeof lastMessage?.content !== "string") {
|
|
46
|
+
return new Response("agent-http expects a plain text user message", {
|
|
47
|
+
status: 400,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
37
51
|
return createAgentStreamResponse(agent, {
|
|
38
52
|
sessionId: id,
|
|
39
53
|
message: lastMessage.content,
|
|
@@ -85,9 +99,12 @@ interface AgentStreamOptions {
|
|
|
85
99
|
message: string;
|
|
86
100
|
abortSignal?: AbortSignal;
|
|
87
101
|
system?: string;
|
|
102
|
+
onFinish?: (result: { response: string; messageId?: string }) => void | Promise<void>;
|
|
88
103
|
}
|
|
89
104
|
```
|
|
90
105
|
|
|
106
|
+
`message` is plain text. If your HTTP route accepts richer UI message parts, convert or validate them before calling `createAgentStreamResponse(...)`.
|
|
107
|
+
|
|
91
108
|
### createAgentStream
|
|
92
109
|
|
|
93
110
|
Lower-level API that returns a ReadableStream.
|
|
@@ -99,6 +116,24 @@ function createAgentStream(
|
|
|
99
116
|
): ReturnType<typeof createUIMessageStream>;
|
|
100
117
|
```
|
|
101
118
|
|
|
119
|
+
Use `createAgentStream(...)` when you need to compose the stream yourself before turning it into a `Response`.
|
|
120
|
+
|
|
121
|
+
## Boundary
|
|
122
|
+
|
|
123
|
+
`agent-http` is best thought of as:
|
|
124
|
+
|
|
125
|
+
- `agent-core` -> AI SDK chat stream adapter
|
|
126
|
+
|
|
127
|
+
It does not own:
|
|
128
|
+
|
|
129
|
+
- request parsing
|
|
130
|
+
- auth
|
|
131
|
+
- session storage policy
|
|
132
|
+
- non-AI-SDK wire formats
|
|
133
|
+
- approval or intervention HTTP APIs
|
|
134
|
+
|
|
135
|
+
If you need a generic HTTP interface for agents, build that at the app layer and treat `createAgentStream(...)` as one rendering option.
|
|
136
|
+
|
|
102
137
|
## License
|
|
103
138
|
|
|
104
139
|
Apache-2.0
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { createUIMessageStream, createUIMessageStreamResponse } from 'ai';
|
|
|
8
8
|
*
|
|
9
9
|
* HTTP streaming adapter for @cuylabs/agent-core.
|
|
10
10
|
* Bridges agent events to AI SDK v6 compatible UIMessageStream for use with useChat().
|
|
11
|
+
* Advanced agent-core events without a direct UIMessageStream equivalent are
|
|
12
|
+
* intentionally skipped here.
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
13
15
|
* ```typescript
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,6 @@ function generatePartId() {
|
|
|
9
9
|
}
|
|
10
10
|
async function writeAgentEventsToStream(agent, options, writer) {
|
|
11
11
|
let currentTextId = null;
|
|
12
|
-
let currentReasoningId = null;
|
|
13
12
|
let fullResponse = "";
|
|
14
13
|
for await (const event of agent.chat(options.sessionId, options.message, {
|
|
15
14
|
abort: options.abortSignal,
|
|
@@ -45,29 +44,23 @@ async function writeAgentEventsToStream(agent, options, writer) {
|
|
|
45
44
|
break;
|
|
46
45
|
// Reasoning/thinking streaming
|
|
47
46
|
case "reasoning-start":
|
|
48
|
-
currentReasoningId = generatePartId();
|
|
49
47
|
writer.write({
|
|
50
48
|
type: "reasoning-start",
|
|
51
|
-
id:
|
|
49
|
+
id: event.id
|
|
52
50
|
});
|
|
53
51
|
break;
|
|
54
52
|
case "reasoning-delta":
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
}
|
|
53
|
+
writer.write({
|
|
54
|
+
type: "reasoning-delta",
|
|
55
|
+
id: event.id,
|
|
56
|
+
delta: event.text
|
|
57
|
+
});
|
|
62
58
|
break;
|
|
63
59
|
case "reasoning-end":
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
currentReasoningId = null;
|
|
70
|
-
}
|
|
60
|
+
writer.write({
|
|
61
|
+
type: "reasoning-end",
|
|
62
|
+
id: event.id
|
|
63
|
+
});
|
|
71
64
|
break;
|
|
72
65
|
// Tool invocations
|
|
73
66
|
case "tool-start":
|
|
@@ -99,11 +92,14 @@ async function writeAgentEventsToStream(agent, options, writer) {
|
|
|
99
92
|
errorText: event.error.message
|
|
100
93
|
});
|
|
101
94
|
break;
|
|
102
|
-
// Step
|
|
103
|
-
// These can be exposed via custom data parts if
|
|
95
|
+
// Step/message/runtime lifecycle events - no direct mapping in AI SDK v6.
|
|
96
|
+
// These can be exposed later via custom data parts if the UI needs them.
|
|
104
97
|
case "step-start":
|
|
105
98
|
case "step-finish":
|
|
99
|
+
case "turn-boundary":
|
|
106
100
|
case "message":
|
|
101
|
+
case "intervention-applied":
|
|
102
|
+
case "turn-summary":
|
|
107
103
|
case "complete":
|
|
108
104
|
break;
|
|
109
105
|
// Events we don't need to stream
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuylabs/agent-http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "HTTP streaming adapter for @cuylabs/agent-core - bridges agent events to AI SDK compatible streams",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"README.md"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@cuylabs/agent-core": "^0.
|
|
20
|
+
"@cuylabs/agent-core": "^0.5.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^22.0.0",
|