@adminforth/agent 2.2.5 → 2.3.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.
@@ -1,7 +1,8 @@
1
1
  import type { ChatSurfaceAdapter, ChatSurfaceEventSink, ChatSurfaceIncomingMessage, IAdminForth } from "adminforth";
2
- import type { HandleSpeechTurnInput, HandleTurnInput, RunAndPersistAgentResponseInput, RunAndPersistAgentResponseResult } from "../../domain/turnTypes.js";
2
+ import type { HandleEditTurnInput, HandleSpeechTurnInput, HandleTurnInput, RunAndPersistAgentResponseInput, RunAndPersistAgentResponseResult } from "../../domain/turnTypes.js";
3
3
  import type { PluginOptions } from "../../types.js";
4
4
  export type SessionTurn = {
5
+ id: string;
5
6
  prompt: string;
6
7
  response: string;
7
8
  };
@@ -9,6 +10,7 @@ export type AgentEndpointsContext = {
9
10
  adminforth: IAdminForth;
10
11
  options: PluginOptions;
11
12
  handleTurn(input: HandleTurnInput): Promise<RunAndPersistAgentResponseResult>;
13
+ handleEditTurn(input: HandleEditTurnInput): Promise<RunAndPersistAgentResponseResult>;
12
14
  handleSpeechTurn(input: HandleSpeechTurnInput): Promise<RunAndPersistAgentResponseResult | null>;
13
15
  steer(input: {
14
16
  sessionId: string;
@@ -24,6 +26,6 @@ export type AgentEndpointsContext = {
24
26
  appendSteerToCurrentTurn(sessionId: string, steerText: string): Promise<void>;
25
27
  handleChatSurfaceMessage(adapter: ChatSurfaceAdapter, incoming: ChatSurfaceIncomingMessage, sink: ChatSurfaceEventSink): Promise<void>;
26
28
  };
27
- export type CoreEndpointsContext = Pick<AgentEndpointsContext, "options" | "handleTurn" | "handleSpeechTurn" | "steer">;
29
+ export type CoreEndpointsContext = Pick<AgentEndpointsContext, "options" | "handleTurn" | "handleEditTurn" | "handleSpeechTurn" | "steer">;
28
30
  export type SessionEndpointsContext = Pick<AgentEndpointsContext, "adminforth" | "options" | "getSessionTurns" | "createNewTurn" | "createSystemTurn" | "appendSteerToCurrentTurn">;
29
31
  export type ChatSurfaceEndpointsContext = Pick<AgentEndpointsContext, "adminforth" | "options" | "handleChatSurfaceMessage">;
@@ -30,6 +30,14 @@ const agentSteerBodySchema = z.object({
30
30
  sessionId: z.string(),
31
31
  message: z.string().min(1),
32
32
  }).strict();
33
+ const agentEditBodySchema = z.object({
34
+ sessionId: z.string(),
35
+ turnId: z.string(),
36
+ message: z.string().min(1),
37
+ mode: z.string().nullish(),
38
+ timeZone: z.string().optional(),
39
+ currentPage: currentPageContextSchema.optional(),
40
+ }).strict();
33
41
  // Sent as multipart/form-data (via multer), so every field arrives as a plain string on the wire.
34
42
  // `currentPage` is JSON.stringify'd by the client into a form field and must be parsed back into
35
43
  // an object. Zod -> JSON-Schema conversion cannot represent `.transform()` at all (it throws), so
@@ -103,6 +111,33 @@ export function setupCoreEndpoints(ctx, server) {
103
111
  return null;
104
112
  })
105
113
  });
114
+ server.endpoint({
115
+ method: 'POST',
116
+ path: `/agent/edit`,
117
+ request_schema: agentEditBodySchema,
118
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, _raw_express_res, abortSignal }) {
119
+ var _b;
120
+ const data = body;
121
+ const emit = createSseEventEmitter(_raw_express_res, {
122
+ vercelAiUiMessageStream: true,
123
+ closeActiveBlockOnToolStart: true,
124
+ });
125
+ yield ctx.handleEditTurn({
126
+ prompt: data.message,
127
+ turnId: data.turnId,
128
+ sessionId: data.sessionId,
129
+ modeName: data.mode,
130
+ userTimeZone: (_b = data.timeZone) !== null && _b !== void 0 ? _b : 'UTC',
131
+ currentPage: data.currentPage,
132
+ abortSignal,
133
+ adminUser: adminUser,
134
+ emit,
135
+ failureLogMessage: "Agent message edit streaming failed",
136
+ abortLogMessage: "Agent message edit streaming aborted by the client",
137
+ });
138
+ return null;
139
+ })
140
+ });
106
141
  server.endpoint({
107
142
  method: 'POST',
108
143
  path: `/agent/approval`,
@@ -81,6 +81,7 @@ export function setupSessionEndpoints(ctx, server) {
81
81
  messages.push({
82
82
  text: turn.response,
83
83
  role: 'system',
84
+ turnId: turn.id,
84
85
  });
85
86
  return messages;
86
87
  }
@@ -88,12 +89,14 @@ export function setupSessionEndpoints(ctx, server) {
88
89
  messages.push({
89
90
  text: turn.prompt,
90
91
  role: 'user',
92
+ turnId: turn.id,
91
93
  });
92
94
  }
93
95
  if (turn.response && turn.response !== "not_finished") {
94
96
  messages.push({
95
97
  text: turn.response,
96
98
  role: 'assistant',
99
+ turnId: turn.id,
97
100
  });
98
101
  }
99
102
  return messages;
@@ -124,6 +124,15 @@ function createAgentEventStream(res, options = {}) {
124
124
  },
125
125
  });
126
126
  },
127
+ turnPersisted(sessionId, turnId) {
128
+ stream.send({
129
+ type: isAiUiMessageStream ? "data-turn-persisted" : "turn-persisted",
130
+ data: {
131
+ sessionId,
132
+ turnId,
133
+ },
134
+ });
135
+ },
127
136
  response(text, sessionId, turnId) {
128
137
  stream.send({
129
138
  type: isAiUiMessageStream ? "data-response" : "response",
@@ -240,6 +249,9 @@ export function createSseEventEmitter(res, options = {}) {
240
249
  case "transcript":
241
250
  stream.transcript(event.text, event.language);
242
251
  break;
252
+ case "turn-persisted":
253
+ stream.turnPersisted(event.sessionId, event.turnId);
254
+ break;
243
255
  case "response":
244
256
  stream.response(event.text, event.sessionId, event.turnId);
245
257
  break;
package/dist/types.d.ts CHANGED
@@ -21,6 +21,7 @@ interface ITurnResource {
21
21
  promptField: string;
22
22
  responseField: string;
23
23
  debugField?: string;
24
+ checkpointIdField?: string;
24
25
  }
25
26
  interface ICheckpointResource {
26
27
  resourceId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "2.2.5",
3
+ "version": "2.3.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",