@agentapplicationprotocol/server 0.4.1 → 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.
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const hono_1 = require("hono");
5
+ const bearer_auth_1 = require("hono/bearer-auth");
6
+ const cors_1 = require("hono/cors");
7
+ const server_1 = require("./server");
8
+ const meta = { version: 1, agents: [] };
9
+ const session = { sessionId: "s1", agent: { name: "a" } };
10
+ const agentResponse = { stopReason: "end_turn", messages: [] };
11
+ const createSessionResponse = { ...agentResponse, sessionId: "s1" };
12
+ const sessionList = { sessions: ["s1"] };
13
+ async function* sseEvents() {
14
+ yield { event: "turn_start" };
15
+ yield { event: "text", text: "hi" };
16
+ yield { event: "turn_stop", stopReason: "end_turn" };
17
+ }
18
+ function makeHandler(overrides = {}) {
19
+ return {
20
+ getMeta: vitest_1.vi.fn().mockReturnValue(meta),
21
+ listSessions: vitest_1.vi.fn().mockResolvedValue(sessionList),
22
+ getSession: vitest_1.vi.fn().mockResolvedValue(session),
23
+ createSession: vitest_1.vi.fn().mockResolvedValue(createSessionResponse),
24
+ sendTurn: vitest_1.vi.fn().mockResolvedValue(agentResponse),
25
+ deleteSession: vitest_1.vi.fn().mockResolvedValue(undefined),
26
+ ...overrides,
27
+ };
28
+ }
29
+ function makeApp(handler, setup) {
30
+ const app = new hono_1.Hono();
31
+ setup?.(app);
32
+ app.route("/", (0, server_1.aap)(handler));
33
+ return app;
34
+ }
35
+ function req(method, path, body, headers) {
36
+ return new Request(`http://localhost${path}`, {
37
+ method,
38
+ headers: { "Content-Type": "application/json", ...headers },
39
+ body: body !== undefined ? JSON.stringify(body) : undefined,
40
+ });
41
+ }
42
+ (0, vitest_1.describe)("aap middleware", () => {
43
+ (0, vitest_1.it)("GET /meta returns meta", async () => {
44
+ const app = makeApp(makeHandler());
45
+ const res = await app.fetch(req("GET", "/meta"));
46
+ (0, vitest_1.expect)(res.status).toBe(200);
47
+ (0, vitest_1.expect)(await res.json()).toEqual(meta);
48
+ });
49
+ (0, vitest_1.it)("GET /session/:id returns session", async () => {
50
+ const app = makeApp(makeHandler());
51
+ const res = await app.fetch(req("GET", "/session/s1"));
52
+ (0, vitest_1.expect)(res.status).toBe(200);
53
+ (0, vitest_1.expect)(await res.json()).toEqual(session);
54
+ });
55
+ (0, vitest_1.it)("GET /session/:id redacts secret options", async () => {
56
+ const secretSession = {
57
+ sessionId: "s1",
58
+ agent: { name: "a", options: { key: "mysecret", model: "gpt-4" } },
59
+ };
60
+ const secretMeta = {
61
+ version: 1,
62
+ agents: [
63
+ {
64
+ name: "a",
65
+ version: "1.0.0",
66
+ options: [
67
+ { type: "secret", name: "key", default: "" },
68
+ { type: "text", name: "model", default: "" },
69
+ ],
70
+ },
71
+ ],
72
+ };
73
+ const app = makeApp(makeHandler({
74
+ getSession: vitest_1.vi.fn().mockResolvedValue(secretSession),
75
+ getMeta: vitest_1.vi.fn().mockReturnValue(secretMeta),
76
+ }));
77
+ const res = await app.fetch(req("GET", "/session/s1"));
78
+ (0, vitest_1.expect)(res.status).toBe(200);
79
+ (0, vitest_1.expect)(await res.json()).toEqual({
80
+ ...secretSession,
81
+ agent: { ...secretSession.agent, options: { key: "***", model: "gpt-4" } },
82
+ });
83
+ });
84
+ (0, vitest_1.it)("GET /sessions returns session list", async () => {
85
+ const handler = makeHandler();
86
+ const app = makeApp(handler);
87
+ const res = await app.fetch(req("GET", "/sessions?after=cursor1"));
88
+ (0, vitest_1.expect)(res.status).toBe(200);
89
+ (0, vitest_1.expect)(await res.json()).toEqual(sessionList);
90
+ (0, vitest_1.expect)(handler.listSessions).toHaveBeenCalledWith({ after: "cursor1" });
91
+ });
92
+ (0, vitest_1.it)("PUT /session returns 400 if last message is not a user message", async () => {
93
+ const app = makeApp(makeHandler());
94
+ const res = await app.fetch(req("PUT", "/session", {
95
+ agent: { name: "a" },
96
+ messages: [{ role: "assistant", content: "hi" }],
97
+ }));
98
+ (0, vitest_1.expect)(res.status).toBe(400);
99
+ });
100
+ (0, vitest_1.it)("PUT /session returns 201 with AgentResponse", async () => {
101
+ const app = makeApp(makeHandler());
102
+ const res = await app.fetch(req("PUT", "/session", { agent: { name: "a" }, messages: [{ role: "user", content: "hi" }] }));
103
+ (0, vitest_1.expect)(res.status).toBe(201);
104
+ (0, vitest_1.expect)(await res.json()).toEqual(createSessionResponse);
105
+ });
106
+ (0, vitest_1.it)("PUT /session with stream returns SSE", async () => {
107
+ const app = makeApp(makeHandler({ createSession: vitest_1.vi.fn().mockResolvedValue(sseEvents()) }));
108
+ const res = await app.fetch(req("PUT", "/session", {
109
+ agent: { name: "a" },
110
+ messages: [{ role: "user", content: "hi" }],
111
+ stream: "message",
112
+ }));
113
+ (0, vitest_1.expect)(res.status).toBe(200);
114
+ (0, vitest_1.expect)(res.headers.get("content-type")).toContain("text/event-stream");
115
+ });
116
+ (0, vitest_1.it)("POST /session/:id returns AgentResponse", async () => {
117
+ const app = makeApp(makeHandler());
118
+ const res = await app.fetch(req("POST", "/session/s1", { messages: [{ role: "user", content: "hi" }] }));
119
+ (0, vitest_1.expect)(res.status).toBe(200);
120
+ (0, vitest_1.expect)(await res.json()).toEqual(agentResponse);
121
+ });
122
+ (0, vitest_1.it)("POST /session/:id with stream returns SSE", async () => {
123
+ const app = makeApp(makeHandler({ sendTurn: vitest_1.vi.fn().mockResolvedValue(sseEvents()) }));
124
+ const res = await app.fetch(req("POST", "/session/s1", { messages: [{ role: "user", content: "hi" }], stream: "delta" }));
125
+ (0, vitest_1.expect)(res.status).toBe(200);
126
+ (0, vitest_1.expect)(res.headers.get("content-type")).toContain("text/event-stream");
127
+ });
128
+ (0, vitest_1.it)("DELETE /session/:id returns 204", async () => {
129
+ const app = makeApp(makeHandler());
130
+ const res = await app.fetch(req("DELETE", "/session/s1"));
131
+ (0, vitest_1.expect)(res.status).toBe(204);
132
+ });
133
+ (0, vitest_1.it)("auth middleware: returns 401 when rejected", async () => {
134
+ const app = makeApp(makeHandler(), (a) => a.use((0, bearer_auth_1.bearerAuth)({ token: "secret" })));
135
+ const res = await app.fetch(req("GET", "/meta"));
136
+ (0, vitest_1.expect)(res.status).toBe(401);
137
+ });
138
+ (0, vitest_1.it)("auth middleware: passes with valid token", async () => {
139
+ const app = makeApp(makeHandler(), (a) => a.use((0, bearer_auth_1.bearerAuth)({ token: "secret" })));
140
+ const res = await app.fetch(req("GET", "/meta", undefined, { Authorization: "Bearer secret" }));
141
+ (0, vitest_1.expect)(res.status).toBe(200);
142
+ });
143
+ (0, vitest_1.it)("base path: mounts under sub-router", async () => {
144
+ const app = new hono_1.Hono();
145
+ app.route("/api/v1", (0, server_1.aap)(makeHandler()));
146
+ const res = await app.fetch(req("GET", "/api/v1/meta"));
147
+ (0, vitest_1.expect)(res.status).toBe(200);
148
+ });
149
+ (0, vitest_1.it)("cors: sets Access-Control-Allow-Origin header", async () => {
150
+ const app = makeApp(makeHandler(), (a) => a.use((0, cors_1.cors)({ origin: "https://example.com" })));
151
+ const res = await app.fetch(req("GET", "/meta", undefined, { Origin: "https://example.com" }));
152
+ (0, vitest_1.expect)(res.headers.get("access-control-allow-origin")).toBe("https://example.com");
153
+ });
154
+ (0, vitest_1.it)("GET /session/:id does not redact when agent not found in meta", async () => {
155
+ const sessionWithOptions = {
156
+ sessionId: "s1",
157
+ agent: { name: "unknown", options: { key: "secret" } },
158
+ };
159
+ const app = makeApp(makeHandler({
160
+ getSession: vitest_1.vi.fn().mockResolvedValue(sessionWithOptions),
161
+ getMeta: vitest_1.vi.fn().mockReturnValue({ version: 1, agents: [] }),
162
+ }));
163
+ const res = await app.fetch(req("GET", "/session/s1"));
164
+ (0, vitest_1.expect)(await res.json()).toEqual(sessionWithOptions);
165
+ });
166
+ (0, vitest_1.it)("GET /session/:id does not redact when agent has no secret options", async () => {
167
+ const sessionWithOptions = {
168
+ sessionId: "s1",
169
+ agent: { name: "a", options: { model: "gpt-4" } },
170
+ };
171
+ const app = makeApp(makeHandler({
172
+ getSession: vitest_1.vi.fn().mockResolvedValue(sessionWithOptions),
173
+ getMeta: vitest_1.vi.fn().mockReturnValue({
174
+ version: 1,
175
+ agents: [
176
+ {
177
+ name: "a",
178
+ version: "1.0.0",
179
+ options: [{ type: "text", name: "model", default: "" }],
180
+ },
181
+ ],
182
+ }),
183
+ }));
184
+ const res = await app.fetch(req("GET", "/session/s1"));
185
+ (0, vitest_1.expect)(await res.json()).toEqual(sessionWithOptions);
186
+ });
187
+ (0, vitest_1.it)("GET /session/:id?history=compacted passes param and strips full", async () => {
188
+ const handler = makeHandler({
189
+ getSession: vitest_1.vi.fn().mockResolvedValue({
190
+ ...session,
191
+ history: { compacted: [], full: [] },
192
+ }),
193
+ });
194
+ const app = makeApp(handler);
195
+ const res = await app.fetch(req("GET", "/session/s1?history=compacted"));
196
+ (0, vitest_1.expect)(handler.getSession).toHaveBeenCalledWith("s1", "compacted");
197
+ (0, vitest_1.expect)(await res.json()).toEqual({ ...session, history: { compacted: [] } });
198
+ });
199
+ (0, vitest_1.it)("GET /session/:id?history=full passes param and strips compacted", async () => {
200
+ const handler = makeHandler({
201
+ getSession: vitest_1.vi.fn().mockResolvedValue({
202
+ ...session,
203
+ history: { compacted: [], full: [] },
204
+ }),
205
+ });
206
+ const app = makeApp(handler);
207
+ const res = await app.fetch(req("GET", "/session/s1?history=full"));
208
+ (0, vitest_1.expect)(handler.getSession).toHaveBeenCalledWith("s1", "full");
209
+ (0, vitest_1.expect)(await res.json()).toEqual({ ...session, history: { full: [] } });
210
+ });
211
+ (0, vitest_1.it)("GET /session/:id without ?history passes undefined and strips history from response", async () => {
212
+ const handler = makeHandler({
213
+ getSession: vitest_1.vi.fn().mockResolvedValue({
214
+ ...session,
215
+ history: { compacted: [], full: [] },
216
+ }),
217
+ });
218
+ const app = makeApp(handler);
219
+ const res = await app.fetch(req("GET", "/session/s1"));
220
+ (0, vitest_1.expect)(handler.getSession).toHaveBeenCalledWith("s1", undefined);
221
+ (0, vitest_1.expect)(await res.json()).toEqual(session);
222
+ });
223
+ (0, vitest_1.it)("GET /session/:id with invalid ?history passes undefined", async () => {
224
+ const handler = makeHandler();
225
+ const app = makeApp(handler);
226
+ await app.fetch(req("GET", "/session/s1?history=invalid"));
227
+ (0, vitest_1.expect)(handler.getSession).toHaveBeenCalledWith("s1", undefined);
228
+ });
229
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,303 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const vitest_1 = require("vitest");
7
+ const session_1 = require("./session");
8
+ const agent_1 = require("./agent");
9
+ const zod_1 = __importDefault(require("zod"));
10
+ function makeModel(overrides = {}) {
11
+ return {
12
+ stream: vitest_1.vi.fn(async function* () {
13
+ yield { event: "text_delta", delta: "hi" };
14
+ yield { event: "turn_stop", stopReason: "end_turn" };
15
+ }),
16
+ call: vitest_1.vi.fn().mockResolvedValue({
17
+ stopReason: "end_turn",
18
+ messages: [{ role: "assistant", content: "hi" }],
19
+ }),
20
+ ...overrides,
21
+ };
22
+ }
23
+ function makeAgent() {
24
+ const agent = new agent_1.Agent("test-agent");
25
+ agent.tool("echo", { inputSchema: zod_1.default.object({ msg: zod_1.default.string() }) }, async ({ msg }) => msg);
26
+ return agent;
27
+ }
28
+ function makeSession(agentConfig = { name: "test-agent" }, model = makeModel(), agent = makeAgent()) {
29
+ return new session_1.Session("sess-1", agent, model, agentConfig);
30
+ }
31
+ const userMsg = { role: "user", content: "hello" };
32
+ (0, vitest_1.describe)("Session", () => {
33
+ (0, vitest_1.it)("initializes with empty history and clientTools", () => {
34
+ const s = makeSession();
35
+ (0, vitest_1.expect)(s.sessionId).toBe("sess-1");
36
+ (0, vitest_1.expect)(s.history).toEqual([]);
37
+ (0, vitest_1.expect)(s.clientTools).toEqual([]);
38
+ });
39
+ (0, vitest_1.it)("toSessionResponse returns sessionId and agentConfig", () => {
40
+ const s = makeSession({ name: "test-agent", options: { model: "gpt-4" } });
41
+ (0, vitest_1.expect)(s.toSessionResponse()).toEqual({
42
+ sessionId: "sess-1",
43
+ agent: { name: "test-agent", options: { model: "gpt-4" } },
44
+ });
45
+ });
46
+ (0, vitest_1.it)("toSessionResponse includes tools when clientTools is set", () => {
47
+ const s = makeSession();
48
+ s.clientTools = [{ name: "t", description: "", inputSchema: {} }];
49
+ (0, vitest_1.expect)(s.toSessionResponse().tools).toHaveLength(1);
50
+ });
51
+ (0, vitest_1.describe)("runTurn (none mode)", () => {
52
+ (0, vitest_1.it)("calls model and accumulates history", async () => {
53
+ const s = makeSession();
54
+ const res = (await s.runTurn({ messages: [userMsg] }));
55
+ (0, vitest_1.expect)(res).toEqual({
56
+ stopReason: "end_turn",
57
+ messages: [{ role: "assistant", content: "hi" }],
58
+ });
59
+ (0, vitest_1.expect)(s.history).toHaveLength(2); // user + assistant
60
+ });
61
+ (0, vitest_1.it)("executes trusted tools inline and loops", async () => {
62
+ const agent = makeAgent();
63
+ const agentConfig = {
64
+ name: "test-agent",
65
+ tools: [{ name: "echo", trust: true }],
66
+ };
67
+ // First call returns tool_use, second returns end_turn
68
+ const model = makeModel({
69
+ call: vitest_1.vi
70
+ .fn()
71
+ .mockResolvedValueOnce({
72
+ stopReason: "tool_use",
73
+ messages: [
74
+ {
75
+ role: "assistant",
76
+ content: [
77
+ { type: "tool_use", toolCallId: "c1", name: "echo", input: { msg: "hi" } },
78
+ ],
79
+ },
80
+ ],
81
+ })
82
+ .mockResolvedValueOnce({
83
+ stopReason: "end_turn",
84
+ messages: [{ role: "assistant", content: "done" }],
85
+ }),
86
+ });
87
+ const s = new session_1.Session("s", agent, model, agentConfig);
88
+ const res = await s.runTurn({ messages: [userMsg] });
89
+ (0, vitest_1.expect)(res.stopReason).toBe("end_turn");
90
+ (0, vitest_1.expect)(model.call).toHaveBeenCalledTimes(2);
91
+ });
92
+ (0, vitest_1.it)("stops and returns tool_use when tool is untrusted", async () => {
93
+ const agent = makeAgent();
94
+ const agentConfig = {
95
+ name: "test-agent",
96
+ tools: [{ name: "echo", trust: false }],
97
+ };
98
+ const model = makeModel({
99
+ call: vitest_1.vi.fn().mockResolvedValue({
100
+ stopReason: "tool_use",
101
+ messages: [
102
+ {
103
+ role: "assistant",
104
+ content: [{ type: "tool_use", toolCallId: "c1", name: "echo", input: { msg: "hi" } }],
105
+ },
106
+ ],
107
+ }),
108
+ });
109
+ const s = new session_1.Session("s", agent, model, agentConfig);
110
+ const res = (await s.runTurn({ messages: [userMsg] }));
111
+ (0, vitest_1.expect)(res.stopReason).toBe("tool_use");
112
+ (0, vitest_1.expect)(model.call).toHaveBeenCalledTimes(1);
113
+ });
114
+ });
115
+ (0, vitest_1.describe)("runTurn (delta mode)", () => {
116
+ (0, vitest_1.it)("yields turn_start and turn_stop events", async () => {
117
+ const s = makeSession();
118
+ const result = s.runTurn({ messages: [userMsg], stream: "delta" });
119
+ const events = [];
120
+ for await (const e of result)
121
+ events.push(e);
122
+ (0, vitest_1.expect)(events[0].event).toBe("turn_start");
123
+ (0, vitest_1.expect)(events.at(-1).event).toBe("turn_stop");
124
+ });
125
+ (0, vitest_1.it)("executes trusted tools inline and loops in delta mode", async () => {
126
+ const agent = makeAgent();
127
+ const agentConfig = {
128
+ name: "test-agent",
129
+ tools: [{ name: "echo", trust: true }],
130
+ };
131
+ const model = makeModel({
132
+ stream: vitest_1.vi
133
+ .fn()
134
+ .mockImplementationOnce(async function* () {
135
+ yield {
136
+ event: "tool_call",
137
+ toolCallId: "c1",
138
+ name: "echo",
139
+ input: { msg: "hi" },
140
+ };
141
+ yield { event: "turn_stop", stopReason: "tool_use" };
142
+ })
143
+ .mockImplementationOnce(async function* () {
144
+ yield { event: "text_delta", delta: "done" };
145
+ yield { event: "turn_stop", stopReason: "end_turn" };
146
+ }),
147
+ });
148
+ const s = new session_1.Session("s", agent, model, agentConfig);
149
+ const events = [];
150
+ for await (const e of s.runTurn({
151
+ messages: [userMsg],
152
+ stream: "delta",
153
+ })) {
154
+ events.push(e);
155
+ }
156
+ (0, vitest_1.expect)(events.some((e) => e.event === "tool_result")).toBe(true);
157
+ (0, vitest_1.expect)(model.stream).toHaveBeenCalledTimes(2);
158
+ });
159
+ });
160
+ (0, vitest_1.describe)("runTurn (message mode)", () => {
161
+ (0, vitest_1.it)("yields turn_start, text, and turn_stop events", async () => {
162
+ const s = makeSession();
163
+ const result = s.runTurn({ messages: [userMsg], stream: "message" });
164
+ const events = [];
165
+ for await (const e of result)
166
+ events.push(e);
167
+ (0, vitest_1.expect)(events[0].event).toBe("turn_start");
168
+ (0, vitest_1.expect)(events.some((e) => e.event === "text")).toBe(true);
169
+ (0, vitest_1.expect)(events.at(-1).event).toBe("turn_stop");
170
+ });
171
+ (0, vitest_1.it)("yields thinking event for thinking blocks", async () => {
172
+ const model = makeModel({
173
+ call: vitest_1.vi.fn().mockResolvedValue({
174
+ stopReason: "end_turn",
175
+ messages: [{ role: "assistant", content: [{ type: "thinking", thinking: "hmm" }] }],
176
+ }),
177
+ });
178
+ const s = makeSession({ name: "test-agent" }, model);
179
+ const events = [];
180
+ for await (const e of s.runTurn({
181
+ messages: [userMsg],
182
+ stream: "message",
183
+ })) {
184
+ events.push(e);
185
+ }
186
+ (0, vitest_1.expect)(events.some((e) => e.event === "thinking")).toBe(true);
187
+ });
188
+ (0, vitest_1.it)("executes trusted tools inline and loops in message mode", async () => {
189
+ const agent = makeAgent();
190
+ const agentConfig = {
191
+ name: "test-agent",
192
+ tools: [{ name: "echo", trust: true }],
193
+ };
194
+ const model = makeModel({
195
+ call: vitest_1.vi
196
+ .fn()
197
+ .mockResolvedValueOnce({
198
+ stopReason: "tool_use",
199
+ messages: [
200
+ {
201
+ role: "assistant",
202
+ content: [
203
+ { type: "tool_use", toolCallId: "c1", name: "echo", input: { msg: "hi" } },
204
+ ],
205
+ },
206
+ ],
207
+ })
208
+ .mockResolvedValueOnce({
209
+ stopReason: "end_turn",
210
+ messages: [{ role: "assistant", content: "done" }],
211
+ }),
212
+ });
213
+ const s = new session_1.Session("s", agent, model, agentConfig);
214
+ const events = [];
215
+ for await (const e of s.runTurn({
216
+ messages: [userMsg],
217
+ stream: "message",
218
+ })) {
219
+ events.push(e);
220
+ }
221
+ (0, vitest_1.expect)(events.some((e) => e.event === "tool_result")).toBe(true);
222
+ (0, vitest_1.expect)(model.call).toHaveBeenCalledTimes(2);
223
+ });
224
+ });
225
+ (0, vitest_1.describe)("runTurn with tool_permission", () => {
226
+ (0, vitest_1.it)("resolves granted tool_permission into tool result", async () => {
227
+ const agent = makeAgent();
228
+ const agentConfig = { name: "test-agent" };
229
+ // Seed history with an assistant message containing a tool_use
230
+ const model = makeModel();
231
+ const s = new session_1.Session("s", agent, model, agentConfig);
232
+ s.history = [
233
+ { role: "user", content: "hi" },
234
+ {
235
+ role: "assistant",
236
+ content: [{ type: "tool_use", toolCallId: "c1", name: "echo", input: { msg: "hello" } }],
237
+ },
238
+ ];
239
+ await s.runTurn({
240
+ messages: [{ role: "tool_permission", toolCallId: "c1", granted: true }],
241
+ });
242
+ // model.call should have received a tool result message
243
+ const callArg = model.call.mock.calls[0][0];
244
+ const toolResult = callArg.find((m) => m.role === "tool");
245
+ (0, vitest_1.expect)(toolResult).toBeDefined();
246
+ (0, vitest_1.expect)(toolResult.content).toBe('"hello"');
247
+ });
248
+ (0, vitest_1.it)("resolves denied tool_permission with denial message", async () => {
249
+ const agent = makeAgent();
250
+ const model = makeModel();
251
+ const s = new session_1.Session("s", agent, model, { name: "test-agent" });
252
+ s.history = [
253
+ {
254
+ role: "assistant",
255
+ content: [{ type: "tool_use", toolCallId: "c2", name: "echo", input: { msg: "x" } }],
256
+ },
257
+ ];
258
+ await s.runTurn({
259
+ messages: [{ role: "tool_permission", toolCallId: "c2", granted: false, reason: "no" }],
260
+ });
261
+ const callArg = model.call.mock.calls[0][0];
262
+ const toolResult = callArg.find((m) => m.role === "tool");
263
+ (0, vitest_1.expect)(toolResult.content).toBe("Tool use denied: no");
264
+ });
265
+ });
266
+ (0, vitest_1.describe)("applySessionOverrides via runTurn", () => {
267
+ (0, vitest_1.it)("overrides clientTools when req.tools is provided", async () => {
268
+ const s = makeSession();
269
+ const newTool = { name: "x", description: "", inputSchema: {} };
270
+ await s.runTurn({ messages: [userMsg], tools: [newTool] });
271
+ (0, vitest_1.expect)(s.clientTools).toEqual([newTool]);
272
+ });
273
+ (0, vitest_1.it)("overrides agentConfig.tools when req.agent.tools is provided", async () => {
274
+ const s = makeSession();
275
+ await s.runTurn({ messages: [userMsg], agent: { tools: [{ name: "echo", trust: true }] } });
276
+ (0, vitest_1.expect)(s.agentConfig.tools).toEqual([{ name: "echo", trust: true }]);
277
+ });
278
+ (0, vitest_1.it)("overrides agentConfig.options when req.agent.options is provided", async () => {
279
+ const s = makeSession({ name: "test-agent", options: { model: "gpt-4" } });
280
+ await s.runTurn({ messages: [userMsg], agent: { options: { model: "gpt-5" } } });
281
+ (0, vitest_1.expect)(s.agentConfig.options).toEqual({ model: "gpt-5" });
282
+ });
283
+ });
284
+ (0, vitest_1.describe)("runNewSession", () => {
285
+ (0, vitest_1.it)("returns CreateSessionResponse with sessionId (none mode)", async () => {
286
+ const s = makeSession();
287
+ const res = await s.runNewSession({ agent: { name: "test-agent" }, messages: [userMsg] });
288
+ (0, vitest_1.expect)(res.sessionId).toBe("sess-1");
289
+ });
290
+ (0, vitest_1.it)("yields session_start event first (delta mode)", async () => {
291
+ const s = makeSession();
292
+ const result = s.runNewSession({
293
+ agent: { name: "test-agent" },
294
+ messages: [userMsg],
295
+ stream: "delta",
296
+ });
297
+ const events = [];
298
+ for await (const e of result)
299
+ events.push(e);
300
+ (0, vitest_1.expect)(events[0]).toEqual({ event: "session_start", sessionId: "sess-1" });
301
+ });
302
+ });
303
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentapplicationprotocol/server",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "AAP server",
5
5
  "keywords": [
6
6
  "aap",
@@ -21,17 +21,17 @@
21
21
  "directory": "packages/server"
22
22
  },
23
23
  "files": [
24
- "dist",
25
- "!dist/**/*.test.js",
26
- "!dist/**/*.test.d.ts"
24
+ "dist/src",
25
+ "!dist/src/examples",
26
+ "!dist/src/**/*.test.*"
27
27
  ],
28
- "main": "dist/index.js",
29
- "types": "dist/index.d.ts",
28
+ "main": "dist/src/index.js",
29
+ "types": "dist/src/index.d.ts",
30
30
  "dependencies": {
31
31
  "ai": "^6.0.141",
32
32
  "hono": "^4.12.8",
33
33
  "zod": "^4.3.6",
34
- "@agentapplicationprotocol/core": "0.4.1"
34
+ "@agentapplicationprotocol/core": "0.5.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@ai-sdk/openai": "^3.0.48",