@adminforth/agent 3.5.1 → 3.5.2

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 CHANGED
@@ -186,9 +186,11 @@ pnpm add @adminforth/agent @adminforth/mcp @adminforth/completion-adapter-openai
186
186
  ## Setup
187
187
 
188
188
  Setup has three parts: (1) create the storage resources, (2) configure the plugin, and
189
- (3) register both in your AdminForth config. Set up the
190
- [MCP plugin](https://adminforth.dev/docs/tutorial/Plugins/mcp/) as its documentation describes
191
- and add it to the same `globalPlugins`.
189
+ (3) register both in your AdminForth config. Add the
190
+ [MCP plugin](https://adminforth.dev/docs/tutorial/Plugins/mcp/) to the same `globalPlugins`.
191
+ If only the agent uses it, `new AdminForthMcpPlugin({ internalOnly: true })` needs no auth
192
+ secret table and no `adminPanelOrigin`; to connect other MCP clients too, set it up as its
193
+ documentation describes.
192
194
 
193
195
  ### 1. Create the storage resources
194
196
 
@@ -66,6 +66,7 @@ export interface LlmPort {
66
66
  completionAdapter: AgentModeCompletionAdapter;
67
67
  sessionId: string;
68
68
  adminUser: AdminUser;
69
+ adminPublicOrigin: string;
69
70
  }): Promise<PendingInterrupt[]>;
70
71
  /**
71
72
  * Return the session thread's latest (tip) checkpoint id, or null when the thread
@@ -76,6 +77,7 @@ export interface LlmPort {
76
77
  completionAdapter: AgentModeCompletionAdapter;
77
78
  sessionId: string;
78
79
  adminUser: AdminUser;
80
+ adminPublicOrigin: string;
79
81
  }): Promise<string | null>;
80
82
  /**
81
83
  * Drop the entire LangGraph checkpoint thread for a session. Used when editing the
@@ -81,7 +81,7 @@ export declare class RunTurnUseCase {
81
81
  * page reload would otherwise leave the user with no way to answer it. Empty when
82
82
  * nothing is pending.
83
83
  */
84
- getPendingApprovals(sessionId: string, adminUser: AdminUser, modeName?: string | null): Promise<ApprovalDescription[]>;
84
+ getPendingApprovals(sessionId: string, adminUser: AdminUser, adminPublicOrigin: string, modeName?: string | null): Promise<ApprovalDescription[]>;
85
85
  private requiresSessionOwnership;
86
86
  /** Verify the session exists and belongs to the requesting admin user. */
87
87
  assertSessionOwnership(sessionId: string, adminUser: BaseAgentTurnInput["adminUser"]): Promise<void>;
@@ -95,7 +95,7 @@ export class RunTurnUseCase {
95
95
  return (_a = this.deps.modes.find((mode) => mode.name === modeName)) !== null && _a !== void 0 ? _a : this.deps.modes[0];
96
96
  }
97
97
  buildContext(input, turnId) {
98
- var _a, _b;
98
+ var _a;
99
99
  return {
100
100
  adminUser: input.adminUser,
101
101
  sessionId: input.sessionId,
@@ -104,7 +104,7 @@ export class RunTurnUseCase {
104
104
  currentPage: input.currentPage,
105
105
  chatSurface: input.chatSurface,
106
106
  userTimeZone: (_a = input.userTimeZone) !== null && _a !== void 0 ? _a : "UTC",
107
- adminPublicOrigin: (_b = input.adminPublicOrigin) !== null && _b !== void 0 ? _b : this.deps.getAdminforth().config.baseUrlSlashed,
107
+ adminPublicOrigin: input.adminPublicOrigin,
108
108
  };
109
109
  }
110
110
  /**
@@ -112,7 +112,7 @@ export class RunTurnUseCase {
112
112
  * checkpoint is authoritative (correct across instances and restarts); with the in-memory
113
113
  * MemorySaver the in-process cache is authoritative (single process, cannot be stale).
114
114
  */
115
- resolvePendingInterrupts(sessionId, mode, adminUser) {
115
+ resolvePendingInterrupts(sessionId, mode, adminUser, adminPublicOrigin) {
116
116
  return __awaiter(this, void 0, void 0, function* () {
117
117
  var _a;
118
118
  if (this.deps.hasPersistentCheckpointer) {
@@ -124,6 +124,7 @@ export class RunTurnUseCase {
124
124
  completionAdapter: mode.completionAdapter,
125
125
  sessionId,
126
126
  adminUser,
127
+ adminPublicOrigin,
127
128
  });
128
129
  }
129
130
  catch (error) {
@@ -147,12 +148,12 @@ export class RunTurnUseCase {
147
148
  * page reload would otherwise leave the user with no way to answer it. Empty when
148
149
  * nothing is pending.
149
150
  */
150
- getPendingApprovals(sessionId, adminUser, modeName) {
151
+ getPendingApprovals(sessionId, adminUser, adminPublicOrigin, modeName) {
151
152
  return __awaiter(this, void 0, void 0, function* () {
152
153
  // Loading a conversation must not fail because the checkpoint store is unhappy
153
154
  // (already logged by resolvePendingInterrupts). Without the prompt the user simply
154
155
  // falls back to the implicit reject in `prepareTurn`.
155
- const interrupts = yield this.resolvePendingInterrupts(sessionId, this.resolveMode(modeName), adminUser)
156
+ const interrupts = yield this.resolvePendingInterrupts(sessionId, this.resolveMode(modeName), adminUser, adminPublicOrigin)
156
157
  .catch(() => []);
157
158
  return this.describeApprovals(interrupts);
158
159
  });
@@ -257,7 +258,7 @@ export class RunTurnUseCase {
257
258
  let initialResponse;
258
259
  let resume;
259
260
  if (shouldResume) {
260
- const resumeInterrupts = yield this.resolvePendingInterrupts(input.sessionId, mode, input.adminUser);
261
+ const resumeInterrupts = yield this.resolvePendingInterrupts(input.sessionId, mode, input.adminUser, input.adminPublicOrigin);
261
262
  if (resumeInterrupts.length === 0) {
262
263
  throw new Error(`No pending approval interrupt found for session "${input.sessionId}".`);
263
264
  }
@@ -273,7 +274,7 @@ export class RunTurnUseCase {
273
274
  // pending call is rejected as part of this turn and the prompt rides along in
274
275
  // the rejection. Reached whenever the approval UI is gone — after a page
275
276
  // reload, from a second tab, or from a chat surface.
276
- const pending = yield this.resolvePendingInterrupts(input.sessionId, mode, input.adminUser);
277
+ const pending = yield this.resolvePendingInterrupts(input.sessionId, mode, input.adminUser, input.adminPublicOrigin);
277
278
  // The prompt rides along in the rejection of the pending call, which has no place for images.
278
279
  if (pending.length > 0 && ((_a = input.attachments) === null || _a === void 0 ? void 0 : _a.length)) {
279
280
  throw new Error("Answer the pending approval before sending images.");
@@ -469,6 +470,7 @@ export class RunTurnUseCase {
469
470
  completionAdapter: prepared.mode.completionAdapter,
470
471
  sessionId: prepared.sessionId,
471
472
  adminUser: prepared.context.adminUser,
473
+ adminPublicOrigin: prepared.context.adminPublicOrigin,
472
474
  });
473
475
  }
474
476
  catch (error) {
@@ -41,7 +41,8 @@ export type BaseAgentTurnInput = {
41
41
  userTimeZone?: string;
42
42
  currentPage?: CurrentPageContext;
43
43
  chatSurface?: string;
44
- adminPublicOrigin?: string;
44
+ /** Public origin the request reached the admin panel on, e.g. https://example.com: links of the turn point to it. */
45
+ adminPublicOrigin: string;
45
46
  attachments?: AttachmentRef[];
46
47
  abortSignal?: AbortSignal;
47
48
  adminUser: AdminUser;
@@ -71,7 +72,7 @@ export type AgentTurnContext = {
71
72
  abortSignal?: AbortSignal;
72
73
  currentPage?: CurrentPageContext;
73
74
  chatSurface?: string;
74
- adminPublicOrigin?: string;
75
+ adminPublicOrigin: string;
75
76
  userLanguage?: DetectedLanguage | null;
76
77
  };
77
78
  export type AgentTurnObservability = {
package/dist/index.js CHANGED
@@ -163,7 +163,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
163
163
  }),
164
164
  runAndPersistAgentResponse: this.runTurnUseCase.runAndPersistAgentResponse.bind(this.runTurnUseCase),
165
165
  getSessionTurns: this.sessionStore.getSessionTurns.bind(this.sessionStore),
166
- getPendingApprovals: (sessionId, adminUser) => this.runTurnUseCase.getPendingApprovals(sessionId, adminUser),
166
+ getPendingApprovals: (sessionId, adminUser, adminPublicOrigin) => this.runTurnUseCase.getPendingApprovals(sessionId, adminUser, adminPublicOrigin),
167
167
  createNewTurn: this.sessionStore.createNewTurn.bind(this.sessionStore),
168
168
  deleteSession: this.sessionStore.deleteSession.bind(this.sessionStore),
169
169
  createSystemTurn: this.sessionStore.createSystemTurn.bind(this.sessionStore),
@@ -14,7 +14,7 @@ export declare const contextSchema: z.ZodObject<{
14
14
  currentPage: z.ZodOptional<z.ZodCustom<CurrentPageContext, CurrentPageContext>>;
15
15
  chatSurface: z.ZodOptional<z.ZodString>;
16
16
  adminBaseUrl: z.ZodOptional<z.ZodString>;
17
- adminPublicOrigin: z.ZodOptional<z.ZodString>;
17
+ adminPublicOrigin: z.ZodString;
18
18
  userLanguage: z.ZodOptional<z.ZodCustom<DetectedLanguage | null, DetectedLanguage | null>>;
19
19
  emit: z.ZodOptional<z.ZodCustom<AgentEventEmitter, AgentEventEmitter>>;
20
20
  sequenceDebugSink: z.ZodCustom<SequenceDebugCollector, SequenceDebugCollector>;
@@ -8,7 +8,7 @@ export const contextSchema = z.object({
8
8
  currentPage: z.custom().optional(),
9
9
  chatSurface: z.string().optional(),
10
10
  adminBaseUrl: z.string().optional(),
11
- adminPublicOrigin: z.string().optional(),
11
+ adminPublicOrigin: z.string(),
12
12
  userLanguage: z.custom().optional(),
13
13
  emit: z.custom().optional(),
14
14
  sequenceDebugSink: z.custom(),
@@ -36,6 +36,7 @@ export declare class AgentRuntime {
36
36
  models: AgentTurnModels;
37
37
  sessionId: string;
38
38
  adminUser: AdminUser;
39
+ adminPublicOrigin: string;
39
40
  }): Promise<unknown[]>;
40
41
  /**
41
42
  * Return the thread's latest (tip) checkpoint id, or null when the thread has no
@@ -46,6 +47,7 @@ export declare class AgentRuntime {
46
47
  models: AgentTurnModels;
47
48
  sessionId: string;
48
49
  adminUser: AdminUser;
50
+ adminPublicOrigin: string;
49
51
  }): Promise<string | null>;
50
52
  /**
51
53
  * Drop the entire LangGraph checkpoint thread for a session. Used when editing the
@@ -75,6 +75,7 @@ export class AgentRuntime {
75
75
  adminUser: input.context.adminUser,
76
76
  sessionId: input.context.sessionId,
77
77
  userTimeZone: input.context.userTimeZone,
78
+ adminPublicOrigin: input.context.adminPublicOrigin,
78
79
  });
79
80
  try {
80
81
  const adminforth = this.options.getAdminforth();
@@ -141,6 +142,7 @@ export class AgentRuntime {
141
142
  const toolSet = yield this.options.toolProvider.open({
142
143
  adminUser: input.adminUser,
143
144
  sessionId: input.sessionId,
145
+ adminPublicOrigin: input.adminPublicOrigin,
144
146
  });
145
147
  try {
146
148
  const agent = createAgent({
@@ -23,11 +23,13 @@ export declare class LangGraphLlm implements LlmPort {
23
23
  completionAdapter: AgentModeCompletionAdapter;
24
24
  sessionId: string;
25
25
  adminUser: AdminUser;
26
+ adminPublicOrigin: string;
26
27
  }): Promise<PendingInterrupt[]>;
27
28
  getLatestCheckpointId(input: {
28
29
  completionAdapter: AgentModeCompletionAdapter;
29
30
  sessionId: string;
30
31
  adminUser: AdminUser;
32
+ adminPublicOrigin: string;
31
33
  }): Promise<string | null>;
32
34
  resetThreadCheckpoints(input: {
33
35
  completionAdapter: AgentModeCompletionAdapter;
@@ -57,6 +57,7 @@ export class LangGraphLlm {
57
57
  models,
58
58
  sessionId: input.sessionId,
59
59
  adminUser: input.adminUser,
60
+ adminPublicOrigin: input.adminPublicOrigin,
60
61
  });
61
62
  return normalizeInterrupts(raw);
62
63
  });
@@ -68,6 +69,7 @@ export class LangGraphLlm {
68
69
  models,
69
70
  sessionId: input.sessionId,
70
71
  adminUser: input.adminUser,
72
+ adminPublicOrigin: input.adminPublicOrigin,
71
73
  });
72
74
  });
73
75
  }
@@ -12,6 +12,8 @@ type McpSession = {
12
12
  readOnly: boolean;
13
13
  headers: Record<string, string>;
14
14
  requestUrl: string;
15
+ /** Links to admin panel pages, such as 2FA confirmations, are built from it. */
16
+ adminPanelOrigin: string;
15
17
  timeZone?: string;
16
18
  };
17
19
  /** The part of the @adminforth/mcp plugin the agent works through. */
@@ -22,6 +24,7 @@ export type McpConnectionInput = {
22
24
  adminUser: AdminUser;
23
25
  sessionId: string;
24
26
  userTimeZone?: string;
27
+ adminPublicOrigin: string;
25
28
  requestUrl: string;
26
29
  };
27
30
  /** One MCP connection of an agent turn, open until `close`. */
@@ -23,6 +23,7 @@ export function connectMcp(mcp, input) {
23
23
  readOnly: false,
24
24
  headers: {},
25
25
  requestUrl: input.requestUrl,
26
+ adminPanelOrigin: input.adminPublicOrigin,
26
27
  timeZone: input.userTimeZone,
27
28
  }));
28
29
  const { tools } = yield client.listTools();
@@ -7,25 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- function getHeaderValue(headers, name) {
11
- var _a;
12
- const value = (_a = headers[name]) !== null && _a !== void 0 ? _a : headers[name.toLowerCase()];
13
- if (Array.isArray(value)) {
14
- return value[0];
15
- }
16
- return typeof value === "string" ? value : undefined;
17
- }
18
- function getRequestOrigin(input) {
19
- var _a, _b, _c, _d;
20
- const forwardedProto = (_b = (_a = getHeaderValue(input.headers, "x-forwarded-proto")) === null || _a === void 0 ? void 0 : _a.split(",")[0]) === null || _b === void 0 ? void 0 : _b.trim();
21
- const forwardedHost = (_d = (_c = getHeaderValue(input.headers, "x-forwarded-host")) === null || _c === void 0 ? void 0 : _c.split(",")[0]) === null || _d === void 0 ? void 0 : _d.trim();
22
- const host = forwardedHost !== null && forwardedHost !== void 0 ? forwardedHost : getHeaderValue(input.headers, "host");
23
- if (!host) {
24
- return undefined;
25
- }
26
- const proto = forwardedProto !== null && forwardedProto !== void 0 ? forwardedProto : (host.startsWith("localhost") || host.startsWith("127.0.0.1") ? "http" : "https");
27
- return `${proto}://${host}`;
28
- }
10
+ import { getRequestOrigin } from "./requestOrigin.js";
29
11
  export function setupChatSurfaceEndpoints(ctx, server) {
30
12
  var _a;
31
13
  for (const adapter of (_a = ctx.options.chatSurfaceAdapters) !== null && _a !== void 0 ? _a : []) {
@@ -48,7 +30,7 @@ export function setupChatSurfaceEndpoints(ctx, server) {
48
30
  const incoming = yield adapter.parseIncomingMessage(surfaceContext);
49
31
  if (!incoming)
50
32
  return { ok: true };
51
- incoming.metadata = Object.assign(Object.assign({}, incoming.metadata), { adminPublicOrigin: getRequestOrigin(endpointInput) });
33
+ incoming.metadata = Object.assign(Object.assign({}, incoming.metadata), { adminPublicOrigin: getRequestOrigin(endpointInput.headers) });
52
34
  const sink = yield adapter.createEventSink(surfaceContext, incoming);
53
35
  try {
54
36
  yield ctx.handleChatSurfaceMessage(adapter, incoming, sink, endpointInput);
@@ -41,7 +41,7 @@ export type AgentEndpointsContext = {
41
41
  }>;
42
42
  runAndPersistAgentResponse(input: RunAndPersistAgentResponseInput): Promise<RunAndPersistAgentResponseResult>;
43
43
  getSessionTurns(sessionId: string): Promise<SessionTurn[]>;
44
- getPendingApprovals(sessionId: string, adminUser: AdminUser): Promise<ApprovalDescription[]>;
44
+ getPendingApprovals(sessionId: string, adminUser: AdminUser, adminPublicOrigin: string): Promise<ApprovalDescription[]>;
45
45
  createNewTurn(sessionId: string, prompt: string, attachments?: string[]): Promise<string>;
46
46
  deleteSession(sessionId: string): Promise<void>;
47
47
  createSystemTurn(sessionId: string, systemMessage: string): Promise<string>;
@@ -11,6 +11,7 @@ import { logger } from "adminforth";
11
11
  import { z } from "zod";
12
12
  import { createSseEventEmitter } from "../sse/sseWriter.js";
13
13
  import { getErrorMessage } from "../../shared/errors.js";
14
+ import { getRequestOrigin } from "./requestOrigin.js";
14
15
  const currentPageContextSchema = z.object({
15
16
  path: z.string(),
16
17
  fullPath: z.string(),
@@ -140,7 +141,7 @@ export function setupCoreEndpoints(ctx, server) {
140
141
  hiddenFromAgents: true,
141
142
  },
142
143
  request_schema: agentResponseBodySchema,
143
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, _raw_express_res, abortSignal }) {
144
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers, adminUser, _raw_express_res, abortSignal }) {
144
145
  const data = body;
145
146
  const emit = createSseEventEmitter(_raw_express_res, {
146
147
  vercelAiUiMessageStream: true,
@@ -155,6 +156,7 @@ export function setupCoreEndpoints(ctx, server) {
155
156
  userTimeZone: (_a = data.timeZone) !== null && _a !== void 0 ? _a : 'UTC',
156
157
  currentPage: data.currentPage,
157
158
  attachments: data.attachments,
159
+ adminPublicOrigin: getRequestOrigin(headers),
158
160
  abortSignal,
159
161
  adminUser: adminUser,
160
162
  emit,
@@ -172,7 +174,7 @@ export function setupCoreEndpoints(ctx, server) {
172
174
  hiddenFromAgents: true,
173
175
  },
174
176
  request_schema: agentEditBodySchema,
175
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, _raw_express_res, abortSignal }) {
177
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers, adminUser, _raw_express_res, abortSignal }) {
176
178
  const data = body;
177
179
  const emit = createSseEventEmitter(_raw_express_res, {
178
180
  vercelAiUiMessageStream: true,
@@ -188,6 +190,7 @@ export function setupCoreEndpoints(ctx, server) {
188
190
  userTimeZone: (_a = data.timeZone) !== null && _a !== void 0 ? _a : 'UTC',
189
191
  currentPage: data.currentPage,
190
192
  attachments: data.attachments,
193
+ adminPublicOrigin: getRequestOrigin(headers),
191
194
  abortSignal,
192
195
  adminUser: adminUser,
193
196
  emit,
@@ -205,7 +208,7 @@ export function setupCoreEndpoints(ctx, server) {
205
208
  hiddenFromAgents: true,
206
209
  },
207
210
  request_schema: agentApprovalBodySchema,
208
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, _raw_express_res, abortSignal }) {
211
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers, adminUser, _raw_express_res, abortSignal }) {
209
212
  const data = body;
210
213
  const emit = createSseEventEmitter(_raw_express_res, {
211
214
  vercelAiUiMessageStream: true,
@@ -216,6 +219,7 @@ export function setupCoreEndpoints(ctx, server) {
216
219
  sessionId: data.sessionId,
217
220
  modeName: data.mode,
218
221
  approvalDecision: data.decision,
222
+ adminPublicOrigin: getRequestOrigin(headers),
219
223
  abortSignal,
220
224
  adminUser: adminUser,
221
225
  emit,
@@ -272,7 +276,7 @@ export function setupCoreEndpoints(ctx, server) {
272
276
  },
273
277
  target: 'upload',
274
278
  request_schema: agentSpeechResponseShapeSchema,
275
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, _raw_express_req, _raw_express_res, abortSignal }) {
279
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers, adminUser, response, _raw_express_req, _raw_express_res, abortSignal }) {
276
280
  var _b;
277
281
  const req = _raw_express_req;
278
282
  const audioAdapter = ctx.options.audioAdapter;
@@ -302,6 +306,7 @@ export function setupCoreEndpoints(ctx, server) {
302
306
  modeName: data.mode,
303
307
  userTimeZone: (_b = data.timeZone) !== null && _b !== void 0 ? _b : 'UTC',
304
308
  currentPage: data.currentPage,
309
+ adminPublicOrigin: getRequestOrigin(headers),
305
310
  abortSignal,
306
311
  adminUser: adminUser,
307
312
  emit,
@@ -0,0 +1,2 @@
1
+ /** The public origin a request reached the admin panel on, e.g. https://example.com, behind a proxy too. */
2
+ export declare function getRequestOrigin(headers: Record<string, unknown>): string;
@@ -0,0 +1,18 @@
1
+ function getHeaderValue(headers, name) {
2
+ var _a;
3
+ const value = (_a = headers[name]) !== null && _a !== void 0 ? _a : headers[name.toLowerCase()];
4
+ if (Array.isArray(value)) {
5
+ return value[0];
6
+ }
7
+ return typeof value === "string" ? value : undefined;
8
+ }
9
+ /** The public origin a request reached the admin panel on, e.g. https://example.com, behind a proxy too. */
10
+ export function getRequestOrigin(headers) {
11
+ var _a, _b, _c, _d;
12
+ const forwardedProto = (_b = (_a = getHeaderValue(headers, "x-forwarded-proto")) === null || _a === void 0 ? void 0 : _a.split(",")[0]) === null || _b === void 0 ? void 0 : _b.trim();
13
+ const forwardedHost = (_d = (_c = getHeaderValue(headers, "x-forwarded-host")) === null || _c === void 0 ? void 0 : _c.split(",")[0]) === null || _d === void 0 ? void 0 : _d.trim();
14
+ // Node rejects HTTP/1.1 requests without a Host header.
15
+ const host = forwardedHost !== null && forwardedHost !== void 0 ? forwardedHost : getHeaderValue(headers, "host");
16
+ const proto = forwardedProto !== null && forwardedProto !== void 0 ? forwardedProto : (host.startsWith("localhost") || host.startsWith("127.0.0.1") ? "http" : "https");
17
+ return `${proto}://${host}`;
18
+ }
@@ -11,6 +11,7 @@ import { Filters, Sorts } from "adminforth";
11
11
  import { randomUUID } from "crypto";
12
12
  import { z } from "zod";
13
13
  import { AGENT_SYSTEM_TURN_PROMPT } from "../../persistence/sessionStore.js";
14
+ import { getRequestOrigin } from "./requestOrigin.js";
14
15
  const addSystemMessageBodySchema = z.object({
15
16
  sessionId: z.string(),
16
17
  systemMessage: z.string(),
@@ -62,7 +63,7 @@ export function setupSessionEndpoints(ctx, server) {
62
63
  hiddenFromAgents: true,
63
64
  },
64
65
  request_schema: sessionIdBodySchema,
65
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
66
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers, adminUser, response }) {
66
67
  const data = body;
67
68
  const userId = adminUser.pk;
68
69
  const sessionId = data.sessionId;
@@ -83,7 +84,7 @@ export function setupSessionEndpoints(ctx, server) {
83
84
  ctx.getSessionTurns(sessionId),
84
85
  // The approval prompt lives only in the browser, so a reload has to rebuild it
85
86
  // from the agent's persisted state — otherwise the user cannot answer it.
86
- ctx.getPendingApprovals(sessionId, adminUser),
87
+ ctx.getPendingApprovals(sessionId, adminUser, getRequestOrigin(headers)),
87
88
  ]);
88
89
  return {
89
90
  session: {
@@ -131,18 +131,17 @@ export class ChatSurfaceService {
131
131
  }
132
132
  handleAgentSurfaceResponse(incoming, sink, adminUser, prompt, options) {
133
133
  return __awaiter(this, void 0, void 0, function* () {
134
- var _a, _b, _c, _d;
134
+ var _a, _b, _c;
135
135
  const emitDone = (_a = options === null || options === void 0 ? void 0 : options.emitDone) !== null && _a !== void 0 ? _a : true;
136
- const adminPublicOrigin = typeof ((_b = incoming.metadata) === null || _b === void 0 ? void 0 : _b.adminPublicOrigin) === "string"
137
- ? incoming.metadata.adminPublicOrigin
138
- : undefined;
136
+ // Set by the webhook endpoint for every incoming message.
137
+ const adminPublicOrigin = incoming.metadata.adminPublicOrigin;
139
138
  const sessionId = yield this.sessionStore.getOrCreateChatSurfaceSession(Object.assign(Object.assign({}, incoming), { prompt }), adminUser);
140
139
  if (emitDone) {
141
140
  yield this.handleTurn({
142
141
  prompt,
143
142
  sessionId,
144
143
  modeName: incoming.modeName,
145
- userTimeZone: (_c = incoming.userTimeZone) !== null && _c !== void 0 ? _c : "UTC",
144
+ userTimeZone: (_b = incoming.userTimeZone) !== null && _b !== void 0 ? _b : "UTC",
146
145
  chatSurface: incoming.surface,
147
146
  adminPublicOrigin,
148
147
  adminUser,
@@ -156,7 +155,7 @@ export class ChatSurfaceService {
156
155
  prompt,
157
156
  sessionId,
158
157
  modeName: incoming.modeName,
159
- userTimeZone: (_d = incoming.userTimeZone) !== null && _d !== void 0 ? _d : "UTC",
158
+ userTimeZone: (_c = incoming.userTimeZone) !== null && _c !== void 0 ? _c : "UTC",
160
159
  chatSurface: incoming.surface,
161
160
  adminPublicOrigin,
162
161
  adminUser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "3.5.1",
3
+ "version": "3.5.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",