@adminforth/agent 2.8.2 → 2.9.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/README.md CHANGED
@@ -115,7 +115,7 @@ sequenceDiagram
115
115
  M-->>LLM: reasoning and text deltas
116
116
  LLM-->>UI: reasoning-delta and text-delta frames
117
117
  M-->>LLM: tool call
118
- alt tool has agent.isDangerous
118
+ alt tool has agent.requiresHumanApproval
119
119
  LLM-->>UI: data-interrupt, generation pauses
120
120
  U->>UI: approve or reject
121
121
  UI->>EP: POST /agent/approval
@@ -152,7 +152,7 @@ flowchart LR
152
152
  C -- yes --> E["fetch_skill returns the SKILL.md<br/>for the matching skill"]
153
153
  E --> F["fetch_tool_schema loads one<br/>API tool schema by name"]
154
154
  F --> G["ApiBasedToolsMiddleware sees the<br/>status 200 tool message and adds that<br/>tool to the next model call"]
155
- G --> H{"agent.isDangerous?"}
155
+ G --> H{"agent.requiresHumanApproval?"}
156
156
  H -- yes --> I["humanInTheLoopMiddleware interrupt,<br/>approve or reject in the UI"]
157
157
  H -- no --> J["Execute through the AdminForth API layer"]
158
158
  I -- approved --> J
@@ -419,7 +419,7 @@ directories are also discovered.
419
419
 
420
420
  ## Human-in-the-loop approvals
421
421
 
422
- Tools whose definition marks them dangerous (`agent.isDangerous === true`) trigger an
422
+ Tools whose endpoint sets `agent.requiresHumanApproval` (or the older `agent.isDangerous`) trigger an
423
423
  approval interrupt: generation pauses and the UI shows an approve/reject prompt. The client
424
424
  resolves it via `POST /agent/approval`, and the run resumes (or, on reject, the model is
425
425
  told the action was declined).
@@ -8,7 +8,7 @@
8
8
  class="absolute bg-black/10 backdrop-blur-md z-10 h-full w-full"
9
9
  >
10
10
  </div>
11
- <div ref="chatContainerRef" class="relative flex-1 min-h-0 overflow-hidden" @click="recalculateScroll()">
11
+ <div class="relative flex-1 min-h-0 overflow-hidden [container-type:size]" @click="recalculateScroll()">
12
12
  <CustomAutoScrollContainer
13
13
  v-if="showScrollContainer"
14
14
  class="relative h-full flex flex-col overflow-y-auto translate-x-[-50%] left-1/2"
@@ -26,6 +26,7 @@
26
26
  }"
27
27
  :style="{
28
28
  maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'rem' : '100%',
29
+ paddingBottom: showBottomSpacer ? `max(0px, 100cqh - ${lastTurnHeight}px)` : undefined,
29
30
  transition: `
30
31
  max-width ${agentTransitions.TRANSITION_DURATION}ms ease-in-out,
31
32
  transform ${agentTransitions.TRANSITION_DURATION}ms ease-in-out
@@ -41,17 +42,14 @@
41
42
  >
42
43
  <MessageRenderer :message="message" :isLastMessageInChat="index === props.messages.length - 1"/>
43
44
  </div>
44
- <div
45
+ <!-- absolute, so it doesn't resize the scroll content when the container resizes (see the spacer comment) -->
46
+ <div
45
47
  v-if="props.messages.length === 0"
46
- class="flex-1 flex flex-col items-center justify-center text-gray-400 tracking-widest text-xl font-medium h-max"
47
- :style="{
48
- height: chatContainerRef ? chatContainerRef.clientHeight + 'px' : '100%',
49
- }"
48
+ class="absolute inset-0 flex flex-col items-center justify-center text-gray-400 tracking-widest text-xl font-medium"
50
49
  >
51
50
  <p>{{ $t('Start the conversation') }}</p>
52
51
  <p class="tracking-normal text-base text">{{ $t('Give any input to begin') }}</p>
53
52
  </div>
54
- <div v-if="showBottomSpacer" class="w-full" :style="{ height: spacerHeight + 'px' }"></div>
55
53
  </CustomAutoScrollContainer>
56
54
  <Transition
57
55
  enter-active-class="transition-all duration-250 ease-out"
@@ -113,7 +111,6 @@ const innerScrollContainerRef = ref<HTMLElement | null>(null);
113
111
  const agentStore = useAgentStore();
114
112
  const agentTransitions = useAgentTransitions();
115
113
  const showScrollContainer = ref(true);
116
- const chatContainerRef = ref<HTMLElement | null>(null);
117
114
  const messagesRefs = ref<Array<HTMLElement | null>>([]);
118
115
  /*
119
116
  * Whenever user sends a message, it adds a bottom spacer, that takes the remaining height
@@ -121,11 +118,17 @@ const messagesRefs = ref<Array<HTMLElement | null>>([]);
121
118
  *
122
119
  * On send message, happens the following logic:
123
120
  * 1) showBottomSpacer is set to true
124
- * 2) updateSpacerHeight is called, which calculates the height for spacer based on scroll container height and messages height
125
- * 3) Spacer moves text up
121
+ * 2) updateSpacerHeight is called, which measures the last turn (last user + last agent message)
122
+ * 3) Spacer moves text up
123
+ *
124
+ * The spacer is the scroll element's padding-bottom, resolved in CSS (100cqh minus the last turn), so
125
+ * it follows the container height in the same layout pass, e.g. when the prompt textarea grows.
126
+ * It is padding rather than a child element on purpose: custom-vue-scrollbar measures the viewport and
127
+ * the content with separate debounced observers, and when both resize together it briefly computes a
128
+ * wrong scroll range and flashes the scrollbar thumb. Padding keeps the content size unchanged.
126
129
  */
127
130
  const showBottomSpacer = ref(false);
128
- const spacerHeight = ref(0);
131
+ const lastTurnHeight = ref(0);
129
132
  const MASK_HEIGHT = 20;
130
133
  const EMPTY_MESSAGE_HEIGHT = 18;
131
134
  const THRESHOLD_TO_SHOW_BUTTON = 10;
@@ -195,7 +198,7 @@ watch(scrollContainer, async () => {
195
198
 
196
199
  function resetSpacer() {
197
200
  showBottomSpacer.value = false;
198
- spacerHeight.value = 0;
201
+ lastTurnHeight.value = 0;
199
202
  }
200
203
 
201
204
  function getLastMessageElement(role: 'user' | 'assistant') {
@@ -230,15 +233,7 @@ async function updateSpacerHeight() {
230
233
  return;
231
234
  }
232
235
 
233
- const clientHeight = getScrollClientHeight();
234
- if (!clientHeight) {
235
- return;
236
- }
237
-
238
- const lastUserMessageHeight = getHeightOfLastUserMessage();
239
- const lastAgentMessageHeight = getHeightOfLastAgentMessage();
240
- const newSpacerHeight = Math.max(0, clientHeight - (lastUserMessageHeight + MASK_HEIGHT + lastAgentMessageHeight));
241
- spacerHeight.value = newSpacerHeight;
236
+ lastTurnHeight.value = getHeightOfLastUserMessage() + MASK_HEIGHT + getHeightOfLastAgentMessage();
242
237
  }
243
238
 
244
239
  function scheduleSpacerHeightUpdate() {
@@ -328,7 +323,8 @@ async function handleSendMessage() {
328
323
 
329
324
  function recalculateScroll() {
330
325
  if (scrollContainer.value) {
331
- scrollContainer.value.handleScroll(false,spacerHeight.value + THRESHOLD_TO_SHOW_BUTTON);
326
+ const spacerHeight = parseFloat(getComputedStyle(scrollContainer.value.container.scrollEl).paddingBottom);
327
+ scrollContainer.value.handleScroll(false, spacerHeight + THRESHOLD_TO_SHOW_BUTTON);
332
328
  const isScrolledUp = scrollContainer.value.isUserScrolledUp();
333
329
  showScrollToBottomButton.value = !!isScrolledUp;
334
330
  }
@@ -17,7 +17,7 @@ import { createLegacySystemMessagesMiddleware } from "./middleware/legacySystemM
17
17
  import { buildDynamicSystemPrompt } from "../domain/systemPrompt.js";
18
18
  function createHumanInTheLoopInterrupts(apiBasedTools) {
19
19
  return Object.fromEntries(Object.entries(apiBasedTools)
20
- .filter(([, apiBasedTool]) => { var _a; return ((_a = apiBasedTool.agent) === null || _a === void 0 ? void 0 : _a.isDangerous) === true; })
20
+ .filter(([, { agent }]) => (agent === null || agent === void 0 ? void 0 : agent.requiresHumanApproval) || (agent === null || agent === void 0 ? void 0 : agent.isDangerous))
21
21
  .map(([toolName]) => [
22
22
  toolName,
23
23
  {
@@ -1,6 +1,9 @@
1
1
  import { type AdminUser, type IAdminForth } from 'adminforth';
2
2
  type AgentToolMeta = {
3
+ requiresHumanApproval?: boolean;
4
+ /** @deprecated Older name of `requiresHumanApproval`, still set by endpoints built for earlier AdminForth versions. */
3
5
  isDangerous?: boolean;
6
+ hiddenFromAgents?: boolean;
4
7
  };
5
8
  export type ApiBasedToolCallParams = {
6
9
  adminUser?: AdminUser;
@@ -438,13 +438,14 @@ function attachDurationMs(output, durationMs) {
438
438
  return { result: output, durationMs };
439
439
  }
440
440
  export function prepareApiBasedTools(adminforth, hiddenResourceIds = []) {
441
+ var _a;
441
442
  const apiBasedTools = {};
442
443
  const openApiSchemas = adminforth.openApi.registeredSchemas;
443
444
  const openApiSchemasByToolName = new Map();
444
445
  const hiddenResourceIdSet = new Set(hiddenResourceIds);
445
446
  for (const schema of openApiSchemas) {
446
447
  const toolName = openApiSchemaPathToToolName(schema.path, adminforth);
447
- if (hasRegisteredApiToolHandler(schema)) {
448
+ if (hasRegisteredApiToolHandler(schema) && !((_a = schema.agent) === null || _a === void 0 ? void 0 : _a.hiddenFromAgents)) {
448
449
  openApiSchemasByToolName.set(toolName, schema);
449
450
  }
450
451
  }
@@ -33,6 +33,9 @@ export function setupChatSurfaceEndpoints(ctx, server) {
33
33
  method: "POST",
34
34
  noAuth: true,
35
35
  path: `/agent/surface/${adapter.name}/webhook`,
36
+ agent: {
37
+ hiddenFromAgents: true,
38
+ },
36
39
  handler: (endpointInput) => __awaiter(this, void 0, void 0, function* () {
37
40
  var _a;
38
41
  const surfaceContext = {
@@ -71,6 +71,9 @@ export function setupCoreEndpoints(ctx, server) {
71
71
  server.endpoint({
72
72
  method: 'POST',
73
73
  path: `/agent/get-placeholder-messages`,
74
+ agent: {
75
+ hiddenFromAgents: true,
76
+ },
74
77
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ headers, adminUser }) {
75
78
  if (!ctx.options.placeholderMessages) {
76
79
  return {
@@ -89,6 +92,9 @@ export function setupCoreEndpoints(ctx, server) {
89
92
  server.endpoint({
90
93
  method: 'POST',
91
94
  path: `/agent/response`,
95
+ agent: {
96
+ hiddenFromAgents: true,
97
+ },
92
98
  request_schema: agentResponseBodySchema,
93
99
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, _raw_express_res, abortSignal }) {
94
100
  var _b;
@@ -115,6 +121,9 @@ export function setupCoreEndpoints(ctx, server) {
115
121
  server.endpoint({
116
122
  method: 'POST',
117
123
  path: `/agent/edit`,
124
+ agent: {
125
+ hiddenFromAgents: true,
126
+ },
118
127
  request_schema: agentEditBodySchema,
119
128
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, _raw_express_res, abortSignal }) {
120
129
  var _b;
@@ -142,6 +151,9 @@ export function setupCoreEndpoints(ctx, server) {
142
151
  server.endpoint({
143
152
  method: 'POST',
144
153
  path: `/agent/approval`,
154
+ agent: {
155
+ hiddenFromAgents: true,
156
+ },
145
157
  request_schema: agentApprovalBodySchema,
146
158
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, _raw_express_res, abortSignal }) {
147
159
  const data = body;
@@ -166,6 +178,9 @@ export function setupCoreEndpoints(ctx, server) {
166
178
  server.endpoint({
167
179
  method: 'POST',
168
180
  path: `/agent/steer`,
181
+ agent: {
182
+ hiddenFromAgents: true,
183
+ },
169
184
  request_schema: agentSteerBodySchema,
170
185
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser }) {
171
186
  const data = body;
@@ -183,6 +198,9 @@ export function setupCoreEndpoints(ctx, server) {
183
198
  server.endpoint({
184
199
  method: 'POST',
185
200
  path: `/agent/speech-response`,
201
+ agent: {
202
+ hiddenFromAgents: true,
203
+ },
186
204
  target: 'upload',
187
205
  request_schema: agentSpeechResponseShapeSchema,
188
206
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, _raw_express_req, _raw_express_res, abortSignal }) {
@@ -32,6 +32,9 @@ export function setupSessionEndpoints(ctx, server) {
32
32
  server.endpoint({
33
33
  method: 'POST',
34
34
  path: `/agent/get-sessions`,
35
+ agent: {
36
+ hiddenFromAgents: true,
37
+ },
35
38
  request_schema: getSessionsBodySchema,
36
39
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
37
40
  var _b;
@@ -51,6 +54,9 @@ export function setupSessionEndpoints(ctx, server) {
51
54
  server.endpoint({
52
55
  method: 'POST',
53
56
  path: `/agent/get-session-info`,
57
+ agent: {
58
+ hiddenFromAgents: true,
59
+ },
54
60
  request_schema: sessionIdBodySchema,
55
61
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
56
62
  const data = body;
@@ -114,6 +120,9 @@ export function setupSessionEndpoints(ctx, server) {
114
120
  server.endpoint({
115
121
  method: 'POST',
116
122
  path: `/agent/create-session`,
123
+ agent: {
124
+ hiddenFromAgents: true,
125
+ },
117
126
  request_schema: createSessionBodySchema,
118
127
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
119
128
  const data = body;
@@ -137,6 +146,9 @@ export function setupSessionEndpoints(ctx, server) {
137
146
  server.endpoint({
138
147
  method: 'POST',
139
148
  path: `/agent/delete-session`,
149
+ agent: {
150
+ hiddenFromAgents: true,
151
+ },
140
152
  request_schema: sessionIdBodySchema,
141
153
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
142
154
  const data = body;
@@ -166,6 +178,9 @@ export function setupSessionEndpoints(ctx, server) {
166
178
  server.endpoint({
167
179
  method: 'POST',
168
180
  path: `/agent/add-system-message-to-turns`,
181
+ agent: {
182
+ hiddenFromAgents: true,
183
+ },
169
184
  request_schema: addSystemMessageBodySchema,
170
185
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
171
186
  const data = body;
@@ -191,6 +206,9 @@ export function setupSessionEndpoints(ctx, server) {
191
206
  server.endpoint({
192
207
  method: 'POST',
193
208
  path: `/agent/append-steer-to-turn`,
209
+ agent: {
210
+ hiddenFromAgents: true,
211
+ },
194
212
  request_schema: appendSteerBodySchema,
195
213
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
196
214
  const data = body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "2.8.2",
3
+ "version": "2.9.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  "devDependencies": {
37
37
  "@types/jest": "^30.0.0",
38
38
  "@types/node": "latest",
39
- "adminforth": "^3.8.2",
39
+ "adminforth": "^3.32.0",
40
40
  "jest": "^30.3.0",
41
41
  "semantic-release": "^24.2.1",
42
42
  "semantic-release-slack-bot": "^4.0.2",
@@ -80,6 +80,6 @@
80
80
  }
81
81
  ],
82
82
  "peerDependencies": {
83
- "adminforth": "^3.8.2"
83
+ "adminforth": "^3.32.0"
84
84
  }
85
85
  }