@adminforth/agent 1.24.11 → 1.24.13

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/apiBasedTools.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  type IAdminForth,
6
6
  type IAdminForthHttpResponse,
7
7
  type IHttpServer,
8
+ type IRegisteredApiSchema,
8
9
  } from 'adminforth';
9
10
  import dayjs from 'dayjs';
10
11
  import timezone from 'dayjs/plugin/timezone.js';
@@ -467,6 +468,25 @@ function endpointPathToToolName(path: string) {
467
468
  .replace(/^_+|_+$/g, '');
468
469
  }
469
470
 
471
+ function stripAdminApiPrefix(path: string, adminforth: IAdminForth) {
472
+ const configuredBaseUrl = adminforth.config.baseUrl || '';
473
+ const normalizedBaseUrl = configuredBaseUrl.endsWith('/')
474
+ ? configuredBaseUrl.slice(0, -1)
475
+ : configuredBaseUrl;
476
+ const apiPrefix = `${normalizedBaseUrl}/adminapi/v1`;
477
+
478
+ if (path.startsWith(apiPrefix)) {
479
+ const strippedPath = path.slice(apiPrefix.length);
480
+ return strippedPath.startsWith('/') ? strippedPath : `/${strippedPath}`;
481
+ }
482
+
483
+ return path;
484
+ }
485
+
486
+ function openApiSchemaPathToToolName(path: string, adminforth: IAdminForth) {
487
+ return endpointPathToToolName(stripAdminApiPrefix(path, adminforth));
488
+ }
489
+
470
490
  export async function formatApiBasedToolCall(params: {
471
491
  adminforth: IAdminForth;
472
492
  adminUser?: AdminUser;
@@ -739,15 +759,10 @@ export function prepareApiBasedTools(adminforth: IAdminForth): Record<string, Ap
739
759
  const captureServer: IHttpServer = {
740
760
  setupSpaServer() {},
741
761
  endpoint: ((options: EndpointWithSchemas) => {
742
- const normalizedResponseSchema = options.response_schema ?? options.responce_schema;
743
- if (!options.request_schema && !normalizedResponseSchema) {
744
- return;
745
- }
746
-
747
762
  capturedEndpoints.push({
748
763
  ...options,
749
- response_schema: normalizedResponseSchema,
750
- normalizedResponseSchema,
764
+ response_schema: options.response_schema ?? options.responce_schema,
765
+ normalizedResponseSchema: options.response_schema ?? options.responce_schema,
751
766
  });
752
767
  }) as IHttpServer['endpoint'],
753
768
  };
@@ -758,15 +773,30 @@ export function prepareApiBasedTools(adminforth: IAdminForth): Record<string, Ap
758
773
  const capturedEndpointsByToolName = Object.fromEntries(
759
774
  capturedEndpoints.map((endpoint) => [endpointPathToToolName(endpoint.path), endpoint]),
760
775
  );
776
+ const openApiSchemas = adminforth.openApi.registeredSchemas.filter(
777
+ (schema) => schema.request_schema || schema.response_schema,
778
+ );
779
+ const openApiSchemasByToolName = new Map<string, IRegisteredApiSchema>();
761
780
 
762
- for (const endpoint of capturedEndpoints) {
763
- const toolName = endpointPathToToolName(endpoint.path);
781
+ for (const schema of openApiSchemas) {
782
+ const toolName = openApiSchemaPathToToolName(schema.path, adminforth);
783
+ openApiSchemasByToolName.set(toolName, schema);
784
+ }
785
+
786
+ for (const [toolName, schema] of openApiSchemasByToolName.entries()) {
787
+ const endpoint = capturedEndpointsByToolName[toolName];
764
788
  apiBasedTools[toolName] = {
765
- description: endpoint.description,
766
- input_schema: endpoint.request_schema,
767
- input_schma: endpoint.request_schema,
768
- output_schema: endpoint.normalizedResponseSchema,
789
+ description: schema.description,
790
+ input_schema: schema.request_schema,
791
+ input_schma: schema.request_schema,
792
+ output_schema: schema.response_schema,
769
793
  call: async ({ adminUser, adminuser, inputs, httpExtra, userTimeZone } = {}) => {
794
+ if (!endpoint) {
795
+ throw new Error(
796
+ `Tool "${toolName}" is defined in OpenAPI but has no callable AdminForth endpoint handler.`,
797
+ );
798
+ }
799
+
770
800
  const output = await callCapturedEndpoint({
771
801
  adminforth,
772
802
  endpoint,
package/build.log CHANGED
@@ -38,5 +38,5 @@ custom/skills/fetch_data/SKILL.md
38
38
  custom/skills/mutate_data/
39
39
  custom/skills/mutate_data/SKILL.md
40
40
 
41
- sent 201,345 bytes received 566 bytes 403,822.00 bytes/sec
42
- total size is 199,037 speedup is 0.99
41
+ sent 202,025 bytes received 566 bytes 405,182.00 bytes/sec
42
+ total size is 199,751 speedup is 0.99
@@ -254,6 +254,7 @@ onMounted(async () => {
254
254
  agentStore.setIsTeleportedToBody(isTeleportedToBodyFromLocalStorage || props.meta.stickByDefault);
255
255
  }
256
256
  await agentStore.fetchSessionsList();
257
+ agentStore.setFullScreen(true);
257
258
  });
258
259
 
259
260
  function autoResize() {
@@ -11,12 +11,16 @@
11
11
  </template>
12
12
 
13
13
  <script setup lang="ts">
14
- import { ref, onMounted, onUnmounted, nextTick, watch } from 'vue'
14
+ import { ref, onMounted, onUnmounted, nextTick, computed } from 'vue'
15
15
  import CustomScrollbar from 'custom-vue-scrollbar';
16
16
  import 'custom-vue-scrollbar/dist/style.css';
17
17
  import { useAgentStore } from './composables/useAgentStore';
18
18
 
19
- const agentStore = useAgentStore();
19
+ const scrollParams = ref({
20
+ scrollTop: 0,
21
+ scrollHeight: 0,
22
+ clientHeight: 0
23
+ });
20
24
 
21
25
  const props = withDefaults(defineProps<{
22
26
  enabled?: boolean
@@ -42,6 +46,9 @@ function isNearBottom(): boolean {
42
46
  if (!container) return true
43
47
 
44
48
  const { scrollTop, scrollHeight, clientHeight } = container
49
+ scrollParams.value.scrollTop = scrollTop
50
+ scrollParams.value.scrollHeight = scrollHeight
51
+ scrollParams.value.clientHeight = clientHeight
45
52
  return scrollHeight - scrollTop - clientHeight <= props.threshold
46
53
  }
47
54
 
@@ -107,6 +114,9 @@ onMounted(() => {
107
114
  }
108
115
 
109
116
  lastScrollHeight = containerRef.value.scrollEl.scrollHeight
117
+ scrollParams.value.scrollTop = containerRef.value.scrollEl.scrollTop
118
+ scrollParams.value.scrollHeight = containerRef.value.scrollEl.scrollHeight
119
+ scrollParams.value.clientHeight = containerRef.value.scrollEl.clientHeight
110
120
  if (props.enabled && !isUserScrolledUp.value) {
111
121
  scrollToBottom()
112
122
  }
@@ -128,7 +138,8 @@ defineExpose({
128
138
  scrollToBottom: () => scrollToBottom(true),
129
139
  isUserScrolledUp: () => isUserScrolledUp.value,
130
140
  container: containerRef,
131
- handleScroll
141
+ handleScroll,
142
+ scrollParams
132
143
  })
133
144
  </script>
134
145
 
@@ -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 class="relative flex-1 min-h-0 overflow-hidden" @click="recalculateScroll()">
11
+ <div ref="chatContainerRef" class="relative flex-1 min-h-0 overflow-hidden" @click="recalculateScroll()">
12
12
  <CustomAutoScrollContainer
13
13
  v-if="showScrollContainer"
14
14
  :enabled="!showScrollToBottomButton"
@@ -24,10 +24,6 @@
24
24
  marginLeft: 'auto',
25
25
  marginRight: 'auto',
26
26
  }"
27
- :contentStyle="{
28
- height: '100%',
29
- maxHeight: '100%',
30
- }"
31
27
  :style="{
32
28
  maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'rem' : '100%',
33
29
  transition: `
@@ -46,11 +42,15 @@
46
42
  </div>
47
43
  <div
48
44
  v-if="props.messages.length === 0"
49
- class="flex-1 flex flex-col items-center justify-center text-gray-400 tracking-widest text-xl font-medium h-full"
45
+ class="flex-1 flex flex-col items-center justify-center text-gray-400 tracking-widest text-xl font-medium h-max"
46
+ :style="{
47
+ height: chatContainerRef ? chatContainerRef.clientHeight + 'px' : '100%',
48
+ }"
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>
53
+ <div></div>
54
54
  </CustomAutoScrollContainer>
55
55
  <button @click="scrollContainer.scrollToBottom();">
56
56
  <IconArrowDownOutline
@@ -83,6 +83,11 @@ const innerScrollContainerRef = ref(null);
83
83
  const agentStore = useAgentStore();
84
84
  const agentTransitions = useAgentTransitions();
85
85
  const showScrollContainer = ref(true);
86
+ const chatContainerRef = ref(null);
87
+
88
+ const scrollHeight = computed(() => {
89
+ return scrollContainer.value ? scrollContainer.value.scrollParams.scrollHeight : 0;
90
+ });
86
91
 
87
92
  function recalculateScroll() {
88
93
  if (scrollContainer.value) {
@@ -286,6 +286,21 @@ function endpointPathToToolName(path) {
286
286
  .replace(/[^a-zA-Z0-9_]+/g, '_')
287
287
  .replace(/^_+|_+$/g, '');
288
288
  }
289
+ function stripAdminApiPrefix(path, adminforth) {
290
+ const configuredBaseUrl = adminforth.config.baseUrl || '';
291
+ const normalizedBaseUrl = configuredBaseUrl.endsWith('/')
292
+ ? configuredBaseUrl.slice(0, -1)
293
+ : configuredBaseUrl;
294
+ const apiPrefix = `${normalizedBaseUrl}/adminapi/v1`;
295
+ if (path.startsWith(apiPrefix)) {
296
+ const strippedPath = path.slice(apiPrefix.length);
297
+ return strippedPath.startsWith('/') ? strippedPath : `/${strippedPath}`;
298
+ }
299
+ return path;
300
+ }
301
+ function openApiSchemaPathToToolName(path, adminforth) {
302
+ return endpointPathToToolName(stripAdminApiPrefix(path, adminforth));
303
+ }
289
304
  export function formatApiBasedToolCall(params) {
290
305
  return __awaiter(this, void 0, void 0, function* () {
291
306
  var _a;
@@ -478,25 +493,30 @@ export function prepareApiBasedTools(adminforth) {
478
493
  const captureServer = {
479
494
  setupSpaServer() { },
480
495
  endpoint: ((options) => {
481
- var _a;
482
- const normalizedResponseSchema = (_a = options.response_schema) !== null && _a !== void 0 ? _a : options.responce_schema;
483
- if (!options.request_schema && !normalizedResponseSchema) {
484
- return;
485
- }
486
- capturedEndpoints.push(Object.assign(Object.assign({}, options), { response_schema: normalizedResponseSchema, normalizedResponseSchema }));
496
+ var _a, _b;
497
+ capturedEndpoints.push(Object.assign(Object.assign({}, options), { response_schema: (_a = options.response_schema) !== null && _a !== void 0 ? _a : options.responce_schema, normalizedResponseSchema: (_b = options.response_schema) !== null && _b !== void 0 ? _b : options.responce_schema }));
487
498
  }),
488
499
  };
489
500
  adminforth.setupEndpoints(captureServer);
490
501
  const apiBasedTools = {};
491
502
  const capturedEndpointsByToolName = Object.fromEntries(capturedEndpoints.map((endpoint) => [endpointPathToToolName(endpoint.path), endpoint]));
492
- for (const endpoint of capturedEndpoints) {
493
- const toolName = endpointPathToToolName(endpoint.path);
503
+ const openApiSchemas = adminforth.openApi.registeredSchemas.filter((schema) => schema.request_schema || schema.response_schema);
504
+ const openApiSchemasByToolName = new Map();
505
+ for (const schema of openApiSchemas) {
506
+ const toolName = openApiSchemaPathToToolName(schema.path, adminforth);
507
+ openApiSchemasByToolName.set(toolName, schema);
508
+ }
509
+ for (const [toolName, schema] of openApiSchemasByToolName.entries()) {
510
+ const endpoint = capturedEndpointsByToolName[toolName];
494
511
  apiBasedTools[toolName] = {
495
- description: endpoint.description,
496
- input_schema: endpoint.request_schema,
497
- input_schma: endpoint.request_schema,
498
- output_schema: endpoint.normalizedResponseSchema,
512
+ description: schema.description,
513
+ input_schema: schema.request_schema,
514
+ input_schma: schema.request_schema,
515
+ output_schema: schema.response_schema,
499
516
  call: (...args_1) => __awaiter(this, [...args_1], void 0, function* ({ adminUser, adminuser, inputs, httpExtra, userTimeZone } = {}) {
517
+ if (!endpoint) {
518
+ throw new Error(`Tool "${toolName}" is defined in OpenAPI but has no callable AdminForth endpoint handler.`);
519
+ }
500
520
  const output = yield callCapturedEndpoint({
501
521
  adminforth,
502
522
  endpoint,
@@ -254,6 +254,7 @@ onMounted(async () => {
254
254
  agentStore.setIsTeleportedToBody(isTeleportedToBodyFromLocalStorage || props.meta.stickByDefault);
255
255
  }
256
256
  await agentStore.fetchSessionsList();
257
+ agentStore.setFullScreen(true);
257
258
  });
258
259
 
259
260
  function autoResize() {
@@ -11,12 +11,16 @@
11
11
  </template>
12
12
 
13
13
  <script setup lang="ts">
14
- import { ref, onMounted, onUnmounted, nextTick, watch } from 'vue'
14
+ import { ref, onMounted, onUnmounted, nextTick, computed } from 'vue'
15
15
  import CustomScrollbar from 'custom-vue-scrollbar';
16
16
  import 'custom-vue-scrollbar/dist/style.css';
17
17
  import { useAgentStore } from './composables/useAgentStore';
18
18
 
19
- const agentStore = useAgentStore();
19
+ const scrollParams = ref({
20
+ scrollTop: 0,
21
+ scrollHeight: 0,
22
+ clientHeight: 0
23
+ });
20
24
 
21
25
  const props = withDefaults(defineProps<{
22
26
  enabled?: boolean
@@ -42,6 +46,9 @@ function isNearBottom(): boolean {
42
46
  if (!container) return true
43
47
 
44
48
  const { scrollTop, scrollHeight, clientHeight } = container
49
+ scrollParams.value.scrollTop = scrollTop
50
+ scrollParams.value.scrollHeight = scrollHeight
51
+ scrollParams.value.clientHeight = clientHeight
45
52
  return scrollHeight - scrollTop - clientHeight <= props.threshold
46
53
  }
47
54
 
@@ -107,6 +114,9 @@ onMounted(() => {
107
114
  }
108
115
 
109
116
  lastScrollHeight = containerRef.value.scrollEl.scrollHeight
117
+ scrollParams.value.scrollTop = containerRef.value.scrollEl.scrollTop
118
+ scrollParams.value.scrollHeight = containerRef.value.scrollEl.scrollHeight
119
+ scrollParams.value.clientHeight = containerRef.value.scrollEl.clientHeight
110
120
  if (props.enabled && !isUserScrolledUp.value) {
111
121
  scrollToBottom()
112
122
  }
@@ -128,7 +138,8 @@ defineExpose({
128
138
  scrollToBottom: () => scrollToBottom(true),
129
139
  isUserScrolledUp: () => isUserScrolledUp.value,
130
140
  container: containerRef,
131
- handleScroll
141
+ handleScroll,
142
+ scrollParams
132
143
  })
133
144
  </script>
134
145
 
@@ -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 class="relative flex-1 min-h-0 overflow-hidden" @click="recalculateScroll()">
11
+ <div ref="chatContainerRef" class="relative flex-1 min-h-0 overflow-hidden" @click="recalculateScroll()">
12
12
  <CustomAutoScrollContainer
13
13
  v-if="showScrollContainer"
14
14
  :enabled="!showScrollToBottomButton"
@@ -24,10 +24,6 @@
24
24
  marginLeft: 'auto',
25
25
  marginRight: 'auto',
26
26
  }"
27
- :contentStyle="{
28
- height: '100%',
29
- maxHeight: '100%',
30
- }"
31
27
  :style="{
32
28
  maxWidth: agentStore.isFullScreen ? agentStore.MAX_WIDTH+'rem' : '100%',
33
29
  transition: `
@@ -46,11 +42,15 @@
46
42
  </div>
47
43
  <div
48
44
  v-if="props.messages.length === 0"
49
- class="flex-1 flex flex-col items-center justify-center text-gray-400 tracking-widest text-xl font-medium h-full"
45
+ class="flex-1 flex flex-col items-center justify-center text-gray-400 tracking-widest text-xl font-medium h-max"
46
+ :style="{
47
+ height: chatContainerRef ? chatContainerRef.clientHeight + 'px' : '100%',
48
+ }"
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>
53
+ <div></div>
54
54
  </CustomAutoScrollContainer>
55
55
  <button @click="scrollContainer.scrollToBottom();">
56
56
  <IconArrowDownOutline
@@ -83,6 +83,11 @@ const innerScrollContainerRef = ref(null);
83
83
  const agentStore = useAgentStore();
84
84
  const agentTransitions = useAgentTransitions();
85
85
  const showScrollContainer = ref(true);
86
+ const chatContainerRef = ref(null);
87
+
88
+ const scrollHeight = computed(() => {
89
+ return scrollContainer.value ? scrollContainer.value.scrollParams.scrollHeight : 0;
90
+ });
86
91
 
87
92
  function recalculateScroll() {
88
93
  if (scrollContainer.value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "1.24.11",
3
+ "version": "1.24.13",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",