@adminforth/agent 2.5.1 → 2.5.3
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.
|
@@ -48,7 +48,7 @@ export function setupChatSurfaceEndpoints(ctx, server) {
|
|
|
48
48
|
incoming.metadata = Object.assign(Object.assign({}, incoming.metadata), { adminPublicOrigin: getRequestOrigin(endpointInput) });
|
|
49
49
|
const sink = yield adapter.createEventSink(surfaceContext, incoming);
|
|
50
50
|
try {
|
|
51
|
-
yield ctx.handleChatSurfaceMessage(adapter, incoming, sink);
|
|
51
|
+
yield ctx.handleChatSurfaceMessage(adapter, incoming, sink, endpointInput);
|
|
52
52
|
}
|
|
53
53
|
finally {
|
|
54
54
|
yield ((_a = sink.close) === null || _a === void 0 ? void 0 : _a.call(sink));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatSurfaceAdapter, ChatSurfaceEventSink, ChatSurfaceIncomingMessage, IAdminForth } from "adminforth";
|
|
1
|
+
import type { ChatSurfaceAdapter, ChatSurfaceEventSink, ChatSurfaceIncomingMessage, IAdminForth, IAdminForthEndpointHandlerInput } from "adminforth";
|
|
2
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 = {
|
|
@@ -24,7 +24,7 @@ export type AgentEndpointsContext = {
|
|
|
24
24
|
createNewTurn(sessionId: string, prompt: string, response?: string): Promise<string>;
|
|
25
25
|
createSystemTurn(sessionId: string, systemMessage: string): Promise<string>;
|
|
26
26
|
appendSteerToCurrentTurn(sessionId: string, steerText: string): Promise<void>;
|
|
27
|
-
handleChatSurfaceMessage(adapter: ChatSurfaceAdapter, incoming: ChatSurfaceIncomingMessage, sink: ChatSurfaceEventSink): Promise<void>;
|
|
27
|
+
handleChatSurfaceMessage(adapter: ChatSurfaceAdapter, incoming: ChatSurfaceIncomingMessage, sink: ChatSurfaceEventSink, request: IAdminForthEndpointHandlerInput): Promise<void>;
|
|
28
28
|
};
|
|
29
29
|
export type CoreEndpointsContext = Pick<AgentEndpointsContext, "options" | "handleTurn" | "handleEditTurn" | "handleSpeechTurn" | "steer">;
|
|
30
30
|
export type SessionEndpointsContext = Pick<AgentEndpointsContext, "adminforth" | "options" | "getSessionTurns" | "createNewTurn" | "createSystemTurn" | "appendSteerToCurrentTurn">;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatSurfaceAdapter, ChatSurfaceEventSink, ChatSurfaceIncomingMessage, IAdminForth } from "adminforth";
|
|
1
|
+
import type { ChatSurfaceAdapter, ChatSurfaceEventSink, ChatSurfaceIncomingMessage, IAdminForth, IAdminForthEndpointHandlerInput } from "adminforth";
|
|
2
2
|
import type { HandleTurnInput, RunAndPersistAgentResponseInput, RunAndPersistAgentResponseResult } from "../../domain/turnTypes.js";
|
|
3
3
|
import type { AgentSessionStore } from "../../persistence/sessionStore.js";
|
|
4
4
|
import type { PluginOptions } from "../../types.js";
|
|
@@ -14,5 +14,6 @@ export declare class ChatSurfaceService {
|
|
|
14
14
|
private handleAudioMessage;
|
|
15
15
|
private handleAgentSurfaceResponse;
|
|
16
16
|
private getAdminUserRecordForChatSurface;
|
|
17
|
-
|
|
17
|
+
private isAdminUserAuthorized;
|
|
18
|
+
handleMessage(adapter: ChatSurfaceAdapter, incoming: ChatSurfaceIncomingMessage, sink: ChatSurfaceEventSink, request: IAdminForthEndpointHandlerInput): Promise<void>;
|
|
18
19
|
}
|
|
@@ -214,7 +214,34 @@ export class ChatSurfaceService {
|
|
|
214
214
|
]);
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
isAdminUserAuthorized(adminUser, incoming, request) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
+
const adminforth = this.getAdminforth();
|
|
220
|
+
const hooks = adminforth.config.auth.adminUserAuthorize;
|
|
221
|
+
const extra = {
|
|
222
|
+
body: request.body,
|
|
223
|
+
query: request.query,
|
|
224
|
+
headers: request.headers,
|
|
225
|
+
cookies: request.cookies,
|
|
226
|
+
requestUrl: request.requestUrl,
|
|
227
|
+
meta: { chatSurface: incoming.surface },
|
|
228
|
+
response: request.response,
|
|
229
|
+
};
|
|
230
|
+
for (const hook of hooks) {
|
|
231
|
+
const result = yield hook({
|
|
232
|
+
adminUser,
|
|
233
|
+
response: request.response,
|
|
234
|
+
adminforth,
|
|
235
|
+
extra,
|
|
236
|
+
});
|
|
237
|
+
if ((result === null || result === void 0 ? void 0 : result.allowed) === false || (result === null || result === void 0 ? void 0 : result.error)) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return true;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
handleMessage(adapter, incoming, sink, request) {
|
|
218
245
|
return __awaiter(this, void 0, void 0, function* () {
|
|
219
246
|
if (yield this.handleLink(incoming, sink)) {
|
|
220
247
|
return;
|
|
@@ -236,6 +263,13 @@ export class ChatSurfaceService {
|
|
|
236
263
|
username: adminUserRecord[adminforth.config.auth.usernameField],
|
|
237
264
|
dbUser: adminUserRecord,
|
|
238
265
|
};
|
|
266
|
+
if (!(yield this.isAdminUserAuthorized(adminUser, incoming, request))) {
|
|
267
|
+
yield sink.emit({
|
|
268
|
+
type: "error",
|
|
269
|
+
message: "This chat account is not authorized to use AdminForth Agent.",
|
|
270
|
+
});
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
239
273
|
const incomingWithAudio = incoming;
|
|
240
274
|
if (incomingWithAudio.audio) {
|
|
241
275
|
yield this.handleAudioMessage(incomingWithAudio, sink, adminUser);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/agent",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"LICENSE"
|
|
11
11
|
],
|
|
12
12
|
"homepage": "https://adminforth.dev/docs/tutorial/Plugins/agent/",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/devforth/adminforth-agent.git"
|
|
16
|
+
},
|
|
13
17
|
"publishConfig": {
|
|
14
18
|
"access": "public"
|
|
15
19
|
},
|