@agentapplicationprotocol/sdk 0.2.1 → 0.3.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/dist/client.d.ts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +21 -2
- package/dist/types.d.ts +4 -3
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentResponse, CreateSessionRequest, MetaResponse, SessionListResponse, SessionResponse, SessionTurnRequest, SSEEvent } from "./types";
|
|
1
|
+
import { AgentResponse, CreateSessionRequest, CreateSessionResponse, MetaResponse, SessionListResponse, SessionResponse, SessionTurnRequest, SSEEvent } from "./types";
|
|
2
2
|
export interface ClientOptions {
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
apiKey: string;
|
|
@@ -29,7 +29,7 @@ export declare class Client {
|
|
|
29
29
|
/** PUT /session — non-streaming */
|
|
30
30
|
createSession(req: CreateSessionRequest & {
|
|
31
31
|
stream?: "none";
|
|
32
|
-
}): Promise<
|
|
32
|
+
}): Promise<CreateSessionResponse>;
|
|
33
33
|
/** PUT /session — SSE streaming */
|
|
34
34
|
createSession(req: CreateSessionRequest & {
|
|
35
35
|
stream: "delta" | "message";
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
2
|
import type { Context } from "hono";
|
|
3
|
-
import { AgentResponse, CreateSessionRequest, MetaResponse, SessionListResponse, SessionResponse, SessionTurnRequest, SSEEvent } from "./types";
|
|
3
|
+
import { AgentResponse, CreateSessionRequest, CreateSessionResponse, MetaResponse, SessionListResponse, SessionResponse, SessionTurnRequest, SSEEvent } from "./types";
|
|
4
4
|
export interface ServerHandler {
|
|
5
5
|
getMeta(): Promise<MetaResponse>;
|
|
6
6
|
listSessions(params: {
|
|
@@ -8,7 +8,7 @@ export interface ServerHandler {
|
|
|
8
8
|
}): Promise<SessionListResponse>;
|
|
9
9
|
getSession(sessionId: string): Promise<SessionResponse>;
|
|
10
10
|
/** The last message in `req.messages` is guaranteed to be a user message. */
|
|
11
|
-
createSession(req: CreateSessionRequest): Promise<
|
|
11
|
+
createSession(req: CreateSessionRequest): Promise<CreateSessionResponse | AsyncIterable<SSEEvent>>;
|
|
12
12
|
sendTurn(sessionId: string, req: SessionTurnRequest): Promise<AgentResponse | AsyncIterable<SSEEvent>>;
|
|
13
13
|
deleteSession(sessionId: string): Promise<void>;
|
|
14
14
|
}
|
package/dist/server.js
CHANGED
|
@@ -10,6 +10,22 @@ async function writeSSEEvents(stream, events) {
|
|
|
10
10
|
await stream.writeSSE({ event, data: JSON.stringify(data) });
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
function redactSecretOptions(session, agents) {
|
|
14
|
+
const { options } = session.agent;
|
|
15
|
+
if (!options)
|
|
16
|
+
return session;
|
|
17
|
+
const agentInfo = agents.find((a) => a.name === session.agent.name);
|
|
18
|
+
const secretNames = new Set(agentInfo?.options?.filter((o) => o.type === "secret").map((o) => o.name) ?? []);
|
|
19
|
+
if (secretNames.size === 0)
|
|
20
|
+
return session;
|
|
21
|
+
return {
|
|
22
|
+
...session,
|
|
23
|
+
agent: {
|
|
24
|
+
...session.agent,
|
|
25
|
+
options: Object.fromEntries(Object.entries(options).map(([k, v]) => [k, secretNames.has(k) ? "***" : v])),
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
13
29
|
class Server {
|
|
14
30
|
constructor(handler, options = {}) {
|
|
15
31
|
this.app = new hono_1.Hono();
|
|
@@ -55,8 +71,11 @@ class Server {
|
|
|
55
71
|
});
|
|
56
72
|
// GET /session/:id
|
|
57
73
|
router.get("/session/:id", async (c) => {
|
|
58
|
-
const session = await
|
|
59
|
-
|
|
74
|
+
const [session, meta] = await Promise.all([
|
|
75
|
+
handler.getSession(c.req.param("id")),
|
|
76
|
+
handler.getMeta(),
|
|
77
|
+
]);
|
|
78
|
+
return c.json(redactSecretOptions(session, meta.agents));
|
|
60
79
|
});
|
|
61
80
|
// GET /sessions
|
|
62
81
|
router.get("/sessions", async (c) => {
|
package/dist/types.d.ts
CHANGED
|
@@ -159,7 +159,7 @@ export interface CreateSessionRequest {
|
|
|
159
159
|
}
|
|
160
160
|
/** Request body for `POST /session/:id`. */
|
|
161
161
|
export interface SessionTurnRequest {
|
|
162
|
-
/** Session-level agent overrides. Agent name cannot be changed. */
|
|
162
|
+
/** Session-level agent overrides. Agent name cannot be changed. Options merged by key. */
|
|
163
163
|
agent?: Omit<AgentConfig, "name">;
|
|
164
164
|
/** Response mode. Defaults to `"none"`. */
|
|
165
165
|
stream?: StreamMode;
|
|
@@ -170,11 +170,12 @@ export interface SessionTurnRequest {
|
|
|
170
170
|
}
|
|
171
171
|
/** JSON response body for non-streaming (`stream: "none"`) requests. */
|
|
172
172
|
export interface AgentResponse {
|
|
173
|
-
/** Present in `PUT /session` response only. */
|
|
174
|
-
sessionId?: string;
|
|
175
173
|
stopReason: StopReason;
|
|
176
174
|
messages: HistoryMessage[];
|
|
177
175
|
}
|
|
176
|
+
export interface CreateSessionResponse extends AgentResponse {
|
|
177
|
+
sessionId: string;
|
|
178
|
+
}
|
|
178
179
|
/** Response body for `GET /session/:id`. */
|
|
179
180
|
export interface SessionResponse {
|
|
180
181
|
sessionId: string;
|