@ag-ui/proto 0.0.27
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/.turbo/turbo-build.log +23 -0
- package/.turbo/turbo-generate.log +5 -0
- package/__tests__/message-events.test.ts +268 -0
- package/__tests__/proto.test.ts +194 -0
- package/__tests__/run-events.test.ts +277 -0
- package/__tests__/state-events.test.ts +237 -0
- package/__tests__/test-utils.ts +33 -0
- package/__tests__/tool-call-events.test.ts +178 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2017 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1988 -0
- package/dist/index.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +35 -0
- package/src/generated/events.ts +1601 -0
- package/src/generated/google/protobuf/struct.ts +467 -0
- package/src/generated/patch.ts +129 -0
- package/src/generated/src/events.ts +1575 -0
- package/src/generated/types.ts +285 -0
- package/src/index.ts +3 -0
- package/src/proto/events.proto +143 -0
- package/src/proto/patch.proto +21 -0
- package/src/proto/types.proto +22 -0
- package/src/proto.ts +91 -0
- package/tsconfig.json +12 -0
- package/tsup.config.ts +10 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { EventType, ToolCallStartEvent, ToolCallArgsEvent, ToolCallEndEvent } from "@ag-ui/core";
|
|
2
|
+
import { expect, describe, it } from "@jest/globals";
|
|
3
|
+
import { encode, decode } from "../src/proto";
|
|
4
|
+
import { expectRoundTripEquality } from "./test-utils";
|
|
5
|
+
|
|
6
|
+
describe("Tool Call Events", () => {
|
|
7
|
+
describe("ToolCallStartEvent", () => {
|
|
8
|
+
it("should round-trip encode/decode correctly", () => {
|
|
9
|
+
const event: ToolCallStartEvent = {
|
|
10
|
+
type: EventType.TOOL_CALL_START,
|
|
11
|
+
timestamp: Date.now(),
|
|
12
|
+
toolCallId: "tool-1",
|
|
13
|
+
toolCallName: "get_weather",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
expectRoundTripEquality(event);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should handle event with parent message id", () => {
|
|
20
|
+
const event: ToolCallStartEvent = {
|
|
21
|
+
type: EventType.TOOL_CALL_START,
|
|
22
|
+
toolCallId: "tool-1",
|
|
23
|
+
toolCallName: "search_database",
|
|
24
|
+
parentMessageId: "msg-123",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
expectRoundTripEquality(event);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should preserve all optional fields", () => {
|
|
31
|
+
const event: ToolCallStartEvent = {
|
|
32
|
+
type: EventType.TOOL_CALL_START,
|
|
33
|
+
timestamp: 1698765432123,
|
|
34
|
+
toolCallId: "tool-call-id-123",
|
|
35
|
+
toolCallName: "very_long_tool_name_with_underscores",
|
|
36
|
+
parentMessageId: "parent-message-id-456",
|
|
37
|
+
rawEvent: { original: "event data", from: "source system" },
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
expectRoundTripEquality(event);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("ToolCallArgsEvent", () => {
|
|
45
|
+
it("should round-trip encode/decode correctly", () => {
|
|
46
|
+
const event: ToolCallArgsEvent = {
|
|
47
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
48
|
+
timestamp: Date.now(),
|
|
49
|
+
toolCallId: "tool-1",
|
|
50
|
+
delta: '{"location":"San Francisco"}',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
expectRoundTripEquality(event);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should handle complex JSON in delta", () => {
|
|
57
|
+
const complexJson = JSON.stringify({
|
|
58
|
+
query: "SELECT * FROM users",
|
|
59
|
+
filters: {
|
|
60
|
+
age: { min: 18, max: 65 },
|
|
61
|
+
status: ["active", "pending"],
|
|
62
|
+
location: {
|
|
63
|
+
country: "US",
|
|
64
|
+
states: ["CA", "NY", "TX"],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
options: {
|
|
68
|
+
limit: 100,
|
|
69
|
+
offset: 0,
|
|
70
|
+
sort: { field: "created_at", order: "desc" },
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const event: ToolCallArgsEvent = {
|
|
75
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
76
|
+
toolCallId: "db-query-tool-123",
|
|
77
|
+
delta: complexJson,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
expectRoundTripEquality(event);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should handle special characters in delta", () => {
|
|
84
|
+
const event: ToolCallArgsEvent = {
|
|
85
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
86
|
+
toolCallId: "tool-1",
|
|
87
|
+
delta: '{"text":"Special chars: 🚀 ñ € 😊 \\n\\t\\"\'\\\\"}',
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
expectRoundTripEquality(event);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should handle partial JSON in delta (streaming case)", () => {
|
|
94
|
+
// Test case for when JSON might be sent in chunks
|
|
95
|
+
const event: ToolCallArgsEvent = {
|
|
96
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
97
|
+
toolCallId: "streaming-tool",
|
|
98
|
+
delta: '{"location":"San Fran',
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
expectRoundTripEquality(event);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("ToolCallEndEvent", () => {
|
|
106
|
+
it("should round-trip encode/decode correctly", () => {
|
|
107
|
+
const event: ToolCallEndEvent = {
|
|
108
|
+
type: EventType.TOOL_CALL_END,
|
|
109
|
+
timestamp: Date.now(),
|
|
110
|
+
toolCallId: "tool-1",
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
expectRoundTripEquality(event);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should handle minimal required fields", () => {
|
|
117
|
+
const event: ToolCallEndEvent = {
|
|
118
|
+
type: EventType.TOOL_CALL_END,
|
|
119
|
+
toolCallId: "tool-1",
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
expectRoundTripEquality(event);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("Complex Tool Call Sequence", () => {
|
|
127
|
+
it("should correctly encode/decode a sequence of related tool call events", () => {
|
|
128
|
+
// Create a sequence of related tool call events
|
|
129
|
+
const startEvent: ToolCallStartEvent = {
|
|
130
|
+
type: EventType.TOOL_CALL_START,
|
|
131
|
+
timestamp: 1000,
|
|
132
|
+
toolCallId: "complex-tool-1",
|
|
133
|
+
toolCallName: "query_database",
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const argsEvent1: ToolCallArgsEvent = {
|
|
137
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
138
|
+
timestamp: 1001,
|
|
139
|
+
toolCallId: "complex-tool-1",
|
|
140
|
+
delta: '{"query":"SELECT * FROM',
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const argsEvent2: ToolCallArgsEvent = {
|
|
144
|
+
type: EventType.TOOL_CALL_ARGS,
|
|
145
|
+
timestamp: 1002,
|
|
146
|
+
toolCallId: "complex-tool-1",
|
|
147
|
+
delta: ' users WHERE age > 18"}',
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const endEvent: ToolCallEndEvent = {
|
|
151
|
+
type: EventType.TOOL_CALL_END,
|
|
152
|
+
timestamp: 1003,
|
|
153
|
+
toolCallId: "complex-tool-1",
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// Test each event in the sequence
|
|
157
|
+
expectRoundTripEquality(startEvent);
|
|
158
|
+
expectRoundTripEquality(argsEvent1);
|
|
159
|
+
expectRoundTripEquality(argsEvent2);
|
|
160
|
+
expectRoundTripEquality(endEvent);
|
|
161
|
+
|
|
162
|
+
// Ensure toolCallId is preserved across events
|
|
163
|
+
const decodedStart = decode(encode(startEvent)) as ToolCallStartEvent;
|
|
164
|
+
const decodedArgs1 = decode(encode(argsEvent1)) as ToolCallArgsEvent;
|
|
165
|
+
const decodedArgs2 = decode(encode(argsEvent2)) as ToolCallArgsEvent;
|
|
166
|
+
const decodedEnd = decode(encode(endEvent)) as ToolCallEndEvent;
|
|
167
|
+
|
|
168
|
+
// Check consistent fields across events
|
|
169
|
+
expect(decodedStart.toolCallId).toBe(startEvent.toolCallId);
|
|
170
|
+
|
|
171
|
+
expect(decodedArgs1.toolCallId).toBe(argsEvent1.toolCallId);
|
|
172
|
+
|
|
173
|
+
expect(decodedArgs2.toolCallId).toBe(argsEvent2.toolCallId);
|
|
174
|
+
|
|
175
|
+
expect(decodedEnd.toolCallId).toBe(endEvent.toolCallId);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseEvent } from '@ag-ui/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Encodes an event message to a protocol buffer binary format.
|
|
5
|
+
*/
|
|
6
|
+
declare function encode(event: BaseEvent): Uint8Array;
|
|
7
|
+
/**
|
|
8
|
+
* Decodes a protocol buffer binary format to an event message.
|
|
9
|
+
* The format includes a 4-byte length prefix followed by the message.
|
|
10
|
+
*/
|
|
11
|
+
declare function decode(data: Uint8Array): BaseEvent;
|
|
12
|
+
|
|
13
|
+
declare const AGUI_MEDIA_TYPE = "application/vnd.ag-ui.event+proto";
|
|
14
|
+
|
|
15
|
+
export { AGUI_MEDIA_TYPE, decode, encode };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseEvent } from '@ag-ui/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Encodes an event message to a protocol buffer binary format.
|
|
5
|
+
*/
|
|
6
|
+
declare function encode(event: BaseEvent): Uint8Array;
|
|
7
|
+
/**
|
|
8
|
+
* Decodes a protocol buffer binary format to an event message.
|
|
9
|
+
* The format includes a 4-byte length prefix followed by the message.
|
|
10
|
+
*/
|
|
11
|
+
declare function decode(data: Uint8Array): BaseEvent;
|
|
12
|
+
|
|
13
|
+
declare const AGUI_MEDIA_TYPE = "application/vnd.ag-ui.event+proto";
|
|
14
|
+
|
|
15
|
+
export { AGUI_MEDIA_TYPE, decode, encode };
|