@adminforth/agent 1.49.0 → 1.49.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.
@@ -47,70 +47,6 @@ function getEnabledApiToolNames(messages: unknown[]) {
47
47
  return enabledToolNames;
48
48
  }
49
49
 
50
- const loadedApiToolNamesBySession = new Map<string, Set<string>>();
51
-
52
- function getSessionLoadedApiToolNames(sessionId: string) {
53
- let toolNames = loadedApiToolNamesBySession.get(sessionId);
54
-
55
- if (!toolNames) {
56
- toolNames = new Set<string>();
57
- loadedApiToolNamesBySession.set(sessionId, toolNames);
58
- }
59
-
60
- return toolNames;
61
- }
62
-
63
- function getEnabledApiToolNamesForSession(messages: unknown[], sessionId?: string) {
64
- const enabledToolNames = getEnabledApiToolNames(messages);
65
-
66
- if (!sessionId) {
67
- return enabledToolNames;
68
- }
69
-
70
- for (const toolName of getSessionLoadedApiToolNames(sessionId)) {
71
- enabledToolNames.add(toolName);
72
- }
73
-
74
- return enabledToolNames;
75
- }
76
-
77
- function getToolMessageContent(message: unknown) {
78
- if (!ToolMessage.isInstance(message)) {
79
- return "";
80
- }
81
-
82
- return typeof message.content === "string"
83
- ? message.content
84
- : Array.isArray(message.content)
85
- ? message.content
86
- .map((block) =>
87
- typeof block === "string"
88
- ? block
89
- : "text" in block
90
- ? block.text
91
- : "",
92
- )
93
- .join("")
94
- : "";
95
- }
96
-
97
- function rememberLoadedToolFromFetchResult(sessionId: string, result: unknown) {
98
- if (!ToolMessage.isInstance(result) || result.name !== "fetch_tool_schema") {
99
- return;
100
- }
101
-
102
- try {
103
- const parsed = JSON.parse(getToolMessageContent(result)) as {
104
- status?: number;
105
- name?: string;
106
- };
107
-
108
- if (parsed.status === 200 && parsed.name) {
109
- getSessionLoadedApiToolNames(sessionId).add(parsed.name);
110
- }
111
- } catch {}
112
- }
113
-
114
50
  export function createApiBasedToolsMiddleware(
115
51
  apiBasedTools: Record<string, ApiBasedTool>,
116
52
  adminforth: IAdminForth,
@@ -126,11 +62,7 @@ export function createApiBasedToolsMiddleware(
126
62
  return createMiddleware({
127
63
  name: "ApiBasedToolsMiddleware",
128
64
  async wrapModelCall(request, handler) {
129
- const { sessionId } = request.runtime.context as { sessionId?: string };
130
- const enabledApiToolNames = getEnabledApiToolNamesForSession(
131
- request.state.messages,
132
- sessionId,
133
- );
65
+ const enabledApiToolNames = getEnabledApiToolNames(request.state.messages);
134
66
  const tools = [...enabledApiToolNames]
135
67
  .filter((toolName) => !alwaysAvailableApiToolNames.has(toolName))
136
68
  .map((toolName) => dynamicTools[toolName]);
@@ -148,10 +80,9 @@ export function createApiBasedToolsMiddleware(
148
80
  async wrapToolCall(request, handler) {
149
81
  const startedAt = Date.now();
150
82
  const toolInput = JSON.stringify(request.toolCall.args ?? {});
151
- const { adminUser, emitToolCallEvent, sessionId, userTimeZone } = request.runtime.context as {
83
+ const { adminUser, emitToolCallEvent, userTimeZone } = request.runtime.context as {
152
84
  adminUser: AdminUser;
153
85
  emitToolCallEvent: ToolCallEventSink;
154
- sessionId: string;
155
86
  userTimeZone: string;
156
87
  };
157
88
  const toolArgs = (request.toolCall.args ?? {}) as Record<string, unknown>;
@@ -189,10 +120,7 @@ export function createApiBasedToolsMiddleware(
189
120
  if (request.tool) {
190
121
  result = await handler(request);
191
122
  } else {
192
- const enabledApiToolNames = getEnabledApiToolNamesForSession(
193
- request.state.messages,
194
- sessionId,
195
- );
123
+ const enabledApiToolNames = getEnabledApiToolNames(request.state.messages);
196
124
 
197
125
  if (enabledApiToolNames.has(request.toolCall.name)) {
198
126
  result = await handler({
@@ -209,10 +137,6 @@ export function createApiBasedToolsMiddleware(
209
137
  }
210
138
  }
211
139
 
212
- if (sessionId) {
213
- rememberLoadedToolFromFetchResult(sessionId, result);
214
- }
215
-
216
140
  toolCallTracker.finishSuccess(result);
217
141
  return result;
218
142
  } catch (error) {
@@ -1,9 +1,6 @@
1
1
  import { tool } from "langchain";
2
2
  import { z } from "zod";
3
- import {
4
- serializeApiBasedTool,
5
- type ApiBasedTool,
6
- } from "../../apiBasedTools.js";
3
+ import type { ApiBasedTool } from "../../apiBasedTools.js";
7
4
 
8
5
  const fetchToolSchemaSchema = z.object({
9
6
  toolName: z
@@ -34,7 +31,7 @@ export async function createFetchToolSchemaTool(
34
31
  {
35
32
  status: 200,
36
33
  name: toolName,
37
- ...serializeApiBasedTool(toolDefinition),
34
+ loaded: true,
38
35
  },
39
36
  null,
40
37
  2,
package/apiBasedTools.ts CHANGED
@@ -175,7 +175,6 @@ export type ApiBasedToolCallParams = {
175
175
  export type ApiBasedTool = {
176
176
  description?: string;
177
177
  input_schema?: unknown;
178
- output_schema?: unknown;
179
178
  call: (params?: ApiBasedToolCallParams) => Promise<string>;
180
179
  };
181
180
 
@@ -616,7 +615,6 @@ export function prepareApiBasedTools(
616
615
  apiBasedTools[toolName] = {
617
616
  description: schema.description,
618
617
  input_schema: schema.request_schema,
619
- output_schema: schema.response_schema,
620
618
  call: async ({ adminUser, adminuser, abortSignal, inputs, userTimeZone, acceptLanguage } = {}) => {
621
619
  if (isHiddenResourceCall(hiddenResourceIdSet, inputs)) {
622
620
  return YAML.stringify({
@@ -652,16 +650,3 @@ export function prepareApiBasedTools(
652
650
 
653
651
  return apiBasedTools;
654
652
  }
655
-
656
- export function serializeApiBasedTool(tool: ApiBasedTool | undefined) {
657
- if (!tool) {
658
- return null;
659
- }
660
-
661
- return {
662
- description: tool.description,
663
- input_schema: tool.input_schema,
664
- output_schema: tool.output_schema,
665
- call: '[Function]',
666
- };
667
- }
@@ -41,53 +41,6 @@ function getEnabledApiToolNames(messages) {
41
41
  }
42
42
  return enabledToolNames;
43
43
  }
44
- const loadedApiToolNamesBySession = new Map();
45
- function getSessionLoadedApiToolNames(sessionId) {
46
- let toolNames = loadedApiToolNamesBySession.get(sessionId);
47
- if (!toolNames) {
48
- toolNames = new Set();
49
- loadedApiToolNamesBySession.set(sessionId, toolNames);
50
- }
51
- return toolNames;
52
- }
53
- function getEnabledApiToolNamesForSession(messages, sessionId) {
54
- const enabledToolNames = getEnabledApiToolNames(messages);
55
- if (!sessionId) {
56
- return enabledToolNames;
57
- }
58
- for (const toolName of getSessionLoadedApiToolNames(sessionId)) {
59
- enabledToolNames.add(toolName);
60
- }
61
- return enabledToolNames;
62
- }
63
- function getToolMessageContent(message) {
64
- if (!ToolMessage.isInstance(message)) {
65
- return "";
66
- }
67
- return typeof message.content === "string"
68
- ? message.content
69
- : Array.isArray(message.content)
70
- ? message.content
71
- .map((block) => typeof block === "string"
72
- ? block
73
- : "text" in block
74
- ? block.text
75
- : "")
76
- .join("")
77
- : "";
78
- }
79
- function rememberLoadedToolFromFetchResult(sessionId, result) {
80
- if (!ToolMessage.isInstance(result) || result.name !== "fetch_tool_schema") {
81
- return;
82
- }
83
- try {
84
- const parsed = JSON.parse(getToolMessageContent(result));
85
- if (parsed.status === 200 && parsed.name) {
86
- getSessionLoadedApiToolNames(sessionId).add(parsed.name);
87
- }
88
- }
89
- catch (_a) { }
90
- }
91
44
  export function createApiBasedToolsMiddleware(apiBasedTools, adminforth) {
92
45
  const alwaysAvailableApiToolNames = new Set(ALWAYS_AVAILABLE_API_TOOL_NAMES);
93
46
  const dynamicTools = Object.fromEntries(Object.entries(apiBasedTools).map(([toolName, apiBasedTool]) => [
@@ -98,8 +51,7 @@ export function createApiBasedToolsMiddleware(apiBasedTools, adminforth) {
98
51
  name: "ApiBasedToolsMiddleware",
99
52
  wrapModelCall(request, handler) {
100
53
  return __awaiter(this, void 0, void 0, function* () {
101
- const { sessionId } = request.runtime.context;
102
- const enabledApiToolNames = getEnabledApiToolNamesForSession(request.state.messages, sessionId);
54
+ const enabledApiToolNames = getEnabledApiToolNames(request.state.messages);
103
55
  const tools = [...enabledApiToolNames]
104
56
  .filter((toolName) => !alwaysAvailableApiToolNames.has(toolName))
105
57
  .map((toolName) => dynamicTools[toolName]);
@@ -113,7 +65,7 @@ export function createApiBasedToolsMiddleware(apiBasedTools, adminforth) {
113
65
  var _a, _b, _c, _d;
114
66
  const startedAt = Date.now();
115
67
  const toolInput = JSON.stringify((_a = request.toolCall.args) !== null && _a !== void 0 ? _a : {});
116
- const { adminUser, emitToolCallEvent, sessionId, userTimeZone } = request.runtime.context;
68
+ const { adminUser, emitToolCallEvent, userTimeZone } = request.runtime.context;
117
69
  const toolArgs = ((_b = request.toolCall.args) !== null && _b !== void 0 ? _b : {});
118
70
  let toolInfo;
119
71
  if (request.toolCall.name === "fetch_skill") {
@@ -147,7 +99,7 @@ export function createApiBasedToolsMiddleware(apiBasedTools, adminforth) {
147
99
  result = yield handler(request);
148
100
  }
149
101
  else {
150
- const enabledApiToolNames = getEnabledApiToolNamesForSession(request.state.messages, sessionId);
102
+ const enabledApiToolNames = getEnabledApiToolNames(request.state.messages);
151
103
  if (enabledApiToolNames.has(request.toolCall.name)) {
152
104
  result = yield handler(Object.assign(Object.assign({}, request), { tool: dynamicTools[request.toolCall.name] }));
153
105
  }
@@ -160,9 +112,6 @@ export function createApiBasedToolsMiddleware(apiBasedTools, adminforth) {
160
112
  });
161
113
  }
162
114
  }
163
- if (sessionId) {
164
- rememberLoadedToolFromFetchResult(sessionId, result);
165
- }
166
115
  toolCallTracker.finishSuccess(result);
167
116
  return result;
168
117
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { type ApiBasedTool } from "../../apiBasedTools.js";
2
+ import type { ApiBasedTool } from "../../apiBasedTools.js";
3
3
  export declare function createFetchToolSchemaTool(apiBasedTools: Record<string, ApiBasedTool>): Promise<import("langchain").DynamicStructuredTool<z.ZodObject<{
4
4
  toolName: z.ZodString;
5
5
  }, z.core.$strip>, {
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { tool } from "langchain";
11
11
  import { z } from "zod";
12
- import { serializeApiBasedTool, } from "../../apiBasedTools.js";
13
12
  const fetchToolSchemaSchema = z.object({
14
13
  toolName: z
15
14
  .string()
@@ -26,7 +25,11 @@ export function createFetchToolSchemaTool(apiBasedTools) {
26
25
  message: `Tool "${toolName}" not found.`,
27
26
  }, null, 2);
28
27
  }
29
- return JSON.stringify(Object.assign({ status: 200, name: toolName }, serializeApiBasedTool(toolDefinition)), null, 2);
28
+ return JSON.stringify({
29
+ status: 200,
30
+ name: toolName,
31
+ loaded: true,
32
+ }, null, 2);
30
33
  }), {
31
34
  name: "fetch_tool_schema",
32
35
  description: "Fetch the schema for an API-based AdminForth tool by name and load it for later use. Use this right after fetch_skill when the skill mentions non-base tools.",
@@ -10,7 +10,6 @@ export type ApiBasedToolCallParams = {
10
10
  export type ApiBasedTool = {
11
11
  description?: string;
12
12
  input_schema?: unknown;
13
- output_schema?: unknown;
14
13
  call: (params?: ApiBasedToolCallParams) => Promise<string>;
15
14
  };
16
15
  export declare function formatApiBasedToolCall(params: {
@@ -21,9 +20,3 @@ export declare function formatApiBasedToolCall(params: {
21
20
  userTimeZone?: string;
22
21
  }): Promise<string | undefined>;
23
22
  export declare function prepareApiBasedTools(adminforth: IAdminForth, hiddenResourceIds?: Iterable<string>): Record<string, ApiBasedTool>;
24
- export declare function serializeApiBasedTool(tool: ApiBasedTool | undefined): {
25
- description: string | undefined;
26
- input_schema: unknown;
27
- output_schema: unknown;
28
- call: string;
29
- } | null;
@@ -410,7 +410,6 @@ export function prepareApiBasedTools(adminforth, hiddenResourceIds = []) {
410
410
  apiBasedTools[toolName] = {
411
411
  description: schema.description,
412
412
  input_schema: schema.request_schema,
413
- output_schema: schema.response_schema,
414
413
  call: (...args_1) => __awaiter(this, [...args_1], void 0, function* ({ adminUser, adminuser, abortSignal, inputs, userTimeZone, acceptLanguage } = {}) {
415
414
  if (isHiddenResourceCall(hiddenResourceIdSet, inputs)) {
416
415
  return YAML.stringify({
@@ -442,14 +441,3 @@ export function prepareApiBasedTools(adminforth, hiddenResourceIds = []) {
442
441
  }
443
442
  return apiBasedTools;
444
443
  }
445
- export function serializeApiBasedTool(tool) {
446
- if (!tool) {
447
- return null;
448
- }
449
- return {
450
- description: tool.description,
451
- input_schema: tool.input_schema,
452
- output_schema: tool.output_schema,
453
- call: '[Function]',
454
- };
455
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "1.49.0",
3
+ "version": "1.49.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",