@adminforth/agent 1.31.0 → 1.32.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.
@@ -58,17 +58,24 @@ function formatSkills(skills: AgentSkillManifest[], label: "skill_name" | "tool_
58
58
  .join("\n");
59
59
  }
60
60
 
61
- export async function buildAgentSystemPrompt(adminforth: IAdminForth) {
61
+ export async function buildAgentSystemPrompt(
62
+ adminforth: IAdminForth,
63
+ hiddenResourceIds: Iterable<string> = [],
64
+ ) {
62
65
  const [primarySkills, defaultSkills] = await Promise.all([
63
66
  listProjectSkillManifests(adminforth.config.customization.customComponentsDir),
64
67
  listBundledSkillManifests(),
65
68
  ]);
66
69
  const alwaysAvailableTools = ALWAYS_AVAILABLE_API_TOOL_NAMES.join(", ");
67
70
  const adminBasePath = adminforth.config.baseUrlSlashed;
71
+ const hiddenResourceIdSet = new Set(hiddenResourceIds);
72
+ const visibleResources = adminforth.config.resources.filter(
73
+ (resource) => !hiddenResourceIdSet.has(resource.resourceId),
74
+ );
68
75
  const sections = [
69
76
  DEFAULT_AGENT_SYSTEM_PROMPT,
70
77
  `ADMIN_BASE_PATH: ${adminBasePath}`,
71
- `List of resources:\n${formatResources(adminforth.config.resources)}`,
78
+ `List of resources:\n${formatResources(visibleResources)}`,
72
79
  `You have always-available base tools: ${alwaysAvailableTools}.`,
73
80
  primarySkills.length > 0
74
81
  ? `You have primary skills set:\n${formatSkills(primarySkills, "skill_name")}`
package/apiBasedTools.ts CHANGED
@@ -58,6 +58,15 @@ function getInputString(inputs: Record<string, unknown> | undefined, key: string
58
58
  return typeof value === 'string' && value ? value : undefined;
59
59
  }
60
60
 
61
+ function isHiddenResourceCall(
62
+ hiddenResourceIds: ReadonlySet<string>,
63
+ inputs: Record<string, unknown> | undefined,
64
+ ) {
65
+ const resourceId = getInputString(inputs, 'resourceId');
66
+
67
+ return resourceId ? hiddenResourceIds.has(resourceId) : false;
68
+ }
69
+
61
70
  function getInputArrayLength(inputs: Record<string, unknown> | undefined, key: string) {
62
71
  const value = inputs?.[key];
63
72
 
@@ -721,12 +730,16 @@ async function callOpenApiSchema(params: {
721
730
  return parseOpenApiToolResponse(response);
722
731
  }
723
732
 
724
- export function prepareApiBasedTools(adminforth: IAdminForth): Record<string, ApiBasedTool> {
733
+ export function prepareApiBasedTools(
734
+ adminforth: IAdminForth,
735
+ hiddenResourceIds: Iterable<string> = [],
736
+ ): Record<string, ApiBasedTool> {
725
737
  const apiBasedTools: Record<string, ApiBasedTool> = {};
726
738
  const openApiSchemas = adminforth.openApi.registeredSchemas.filter(
727
739
  (schema) => schema.request_schema || schema.response_schema,
728
740
  );
729
741
  const openApiSchemasByToolName = new Map<string, IRegisteredApiSchema>();
742
+ const hiddenResourceIdSet = new Set(hiddenResourceIds);
730
743
 
731
744
  for (const schema of openApiSchemas) {
732
745
  const toolName = openApiSchemaPathToToolName(schema.path, adminforth);
@@ -749,6 +762,13 @@ export function prepareApiBasedTools(adminforth: IAdminForth): Record<string, Ap
749
762
  input_schma: schema.request_schema,
750
763
  output_schema: schema.response_schema,
751
764
  call: async ({ adminUser, adminuser, inputs, httpExtra, userTimeZone } = {}) => {
765
+ if (isHiddenResourceCall(hiddenResourceIdSet, inputs)) {
766
+ return YAML.stringify({
767
+ error: 'RESOURCE_NOT_AVAILABLE',
768
+ message: 'This resource is not available to the agent.',
769
+ });
770
+ }
771
+
752
772
  const invokeTool = async (
753
773
  nextToolName: string,
754
774
  nextParams: ToolOverrideCallParams = {},
package/build.log CHANGED
@@ -40,5 +40,5 @@ custom/skills/fetch_data/SKILL.md
40
40
  custom/skills/mutate_data/
41
41
  custom/skills/mutate_data/SKILL.md
42
42
 
43
- sent 208,782 bytes received 585 bytes 418,734.00 bytes/sec
44
- total size is 206,372 speedup is 0.99
43
+ sent 209,092 bytes received 585 bytes 419,354.00 bytes/sec
44
+ total size is 206,682 speedup is 0.99
@@ -39,7 +39,7 @@ import type { Code } from 'mdast';
39
39
  import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
40
40
  import embed from 'vega-embed';
41
41
 
42
- import { highlightCodeSnippetHtml, type IncremarkCodeTheme } from './incremarkCodeHighlight';
42
+ import type { IncremarkCodeTheme } from './incremarkCodeHighlight';
43
43
 
44
44
  const props = withDefaults(defineProps<{
45
45
  node: Code;
@@ -67,6 +67,7 @@ let renderRequestId = 0;
67
67
  let scheduledFrameId: number | null = null;
68
68
  let themeObserver: MutationObserver | null = null;
69
69
  let vegaResult: { finalize: () => void } | null = null;
70
+ let highlightModulePromise: Promise<typeof import('./incremarkCodeHighlight')> | null = null;
70
71
 
71
72
  const sourceCode = computed(() => props.node.value ?? '');
72
73
  const language = computed(() => props.node.lang?.trim().toLowerCase() || 'text');
@@ -165,6 +166,14 @@ function scheduleHighlight() {
165
166
  });
166
167
  }
167
168
 
169
+ function loadHighlightModule() {
170
+ if (!highlightModulePromise) {
171
+ highlightModulePromise = import('./incremarkCodeHighlight');
172
+ }
173
+
174
+ return highlightModulePromise;
175
+ }
176
+
168
177
  async function renderHighlight() {
169
178
  const requestId = ++renderRequestId;
170
179
 
@@ -219,6 +228,7 @@ async function renderHighlight() {
219
228
  }
220
229
 
221
230
  try {
231
+ const { highlightCodeSnippetHtml } = await loadHighlightModule();
222
232
  const html = await highlightCodeSnippetHtml(sourceCode.value, language.value, codeTheme.value);
223
233
 
224
234
  if (requestId === renderRequestId) {
@@ -48,18 +48,20 @@ function formatSkills(skills, label) {
48
48
  .map((skill) => `- ${label}: ${skill.name}\n description: ${skill.description}`)
49
49
  .join("\n");
50
50
  }
51
- export function buildAgentSystemPrompt(adminforth) {
52
- return __awaiter(this, void 0, void 0, function* () {
51
+ export function buildAgentSystemPrompt(adminforth_1) {
52
+ return __awaiter(this, arguments, void 0, function* (adminforth, hiddenResourceIds = []) {
53
53
  const [primarySkills, defaultSkills] = yield Promise.all([
54
54
  listProjectSkillManifests(adminforth.config.customization.customComponentsDir),
55
55
  listBundledSkillManifests(),
56
56
  ]);
57
57
  const alwaysAvailableTools = ALWAYS_AVAILABLE_API_TOOL_NAMES.join(", ");
58
58
  const adminBasePath = adminforth.config.baseUrlSlashed;
59
+ const hiddenResourceIdSet = new Set(hiddenResourceIds);
60
+ const visibleResources = adminforth.config.resources.filter((resource) => !hiddenResourceIdSet.has(resource.resourceId));
59
61
  const sections = [
60
62
  DEFAULT_AGENT_SYSTEM_PROMPT,
61
63
  `ADMIN_BASE_PATH: ${adminBasePath}`,
62
- `List of resources:\n${formatResources(adminforth.config.resources)}`,
64
+ `List of resources:\n${formatResources(visibleResources)}`,
63
65
  `You have always-available base tools: ${alwaysAvailableTools}.`,
64
66
  primarySkills.length > 0
65
67
  ? `You have primary skills set:\n${formatSkills(primarySkills, "skill_name")}`
@@ -20,6 +20,10 @@ function getInputString(inputs, key) {
20
20
  const value = inputs === null || inputs === void 0 ? void 0 : inputs[key];
21
21
  return typeof value === 'string' && value ? value : undefined;
22
22
  }
23
+ function isHiddenResourceCall(hiddenResourceIds, inputs) {
24
+ const resourceId = getInputString(inputs, 'resourceId');
25
+ return resourceId ? hiddenResourceIds.has(resourceId) : false;
26
+ }
23
27
  function getInputArrayLength(inputs, key) {
24
28
  const value = inputs === null || inputs === void 0 ? void 0 : inputs[key];
25
29
  return Array.isArray(value) ? value.length : undefined;
@@ -492,10 +496,11 @@ function callOpenApiSchema(params) {
492
496
  return parseOpenApiToolResponse(response);
493
497
  });
494
498
  }
495
- export function prepareApiBasedTools(adminforth) {
499
+ export function prepareApiBasedTools(adminforth, hiddenResourceIds = []) {
496
500
  const apiBasedTools = {};
497
501
  const openApiSchemas = adminforth.openApi.registeredSchemas.filter((schema) => schema.request_schema || schema.response_schema);
498
502
  const openApiSchemasByToolName = new Map();
503
+ const hiddenResourceIdSet = new Set(hiddenResourceIds);
499
504
  for (const schema of openApiSchemas) {
500
505
  const toolName = openApiSchemaPathToToolName(schema.path, adminforth);
501
506
  openApiSchemasByToolName.set(toolName, schema);
@@ -509,6 +514,12 @@ export function prepareApiBasedTools(adminforth) {
509
514
  input_schma: schema.request_schema,
510
515
  output_schema: schema.response_schema,
511
516
  call: (...args_1) => __awaiter(this, [...args_1], void 0, function* ({ adminUser, adminuser, inputs, httpExtra, userTimeZone } = {}) {
517
+ if (isHiddenResourceCall(hiddenResourceIdSet, inputs)) {
518
+ return YAML.stringify({
519
+ error: 'RESOURCE_NOT_AVAILABLE',
520
+ message: 'This resource is not available to the agent.',
521
+ });
522
+ }
512
523
  const invokeTool = (nextToolName_1, ...args_2) => __awaiter(this, [nextToolName_1, ...args_2], void 0, function* (nextToolName, nextParams = {}) {
513
524
  const nextSchema = openApiSchemasByToolName.get(nextToolName);
514
525
  if (!nextSchema) {
@@ -39,7 +39,7 @@ import type { Code } from 'mdast';
39
39
  import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
40
40
  import embed from 'vega-embed';
41
41
 
42
- import { highlightCodeSnippetHtml, type IncremarkCodeTheme } from './incremarkCodeHighlight';
42
+ import type { IncremarkCodeTheme } from './incremarkCodeHighlight';
43
43
 
44
44
  const props = withDefaults(defineProps<{
45
45
  node: Code;
@@ -67,6 +67,7 @@ let renderRequestId = 0;
67
67
  let scheduledFrameId: number | null = null;
68
68
  let themeObserver: MutationObserver | null = null;
69
69
  let vegaResult: { finalize: () => void } | null = null;
70
+ let highlightModulePromise: Promise<typeof import('./incremarkCodeHighlight')> | null = null;
70
71
 
71
72
  const sourceCode = computed(() => props.node.value ?? '');
72
73
  const language = computed(() => props.node.lang?.trim().toLowerCase() || 'text');
@@ -165,6 +166,14 @@ function scheduleHighlight() {
165
166
  });
166
167
  }
167
168
 
169
+ function loadHighlightModule() {
170
+ if (!highlightModulePromise) {
171
+ highlightModulePromise = import('./incremarkCodeHighlight');
172
+ }
173
+
174
+ return highlightModulePromise;
175
+ }
176
+
168
177
  async function renderHighlight() {
169
178
  const requestId = ++renderRequestId;
170
179
 
@@ -219,6 +228,7 @@ async function renderHighlight() {
219
228
  }
220
229
 
221
230
  try {
231
+ const { highlightCodeSnippetHtml } = await loadHighlightModule();
222
232
  const html = await highlightCodeSnippetHtml(sourceCode.value, language.value, codeTheme.value);
223
233
 
224
234
  if (requestId === renderRequestId) {
package/dist/index.js CHANGED
@@ -154,6 +154,14 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
154
154
  : new MemorySaver();
155
155
  return this.checkpointer;
156
156
  }
157
+ getInternalAgentResourceIds() {
158
+ var _a;
159
+ return [
160
+ this.options.sessionResource.resourceId,
161
+ this.options.turnResource.resourceId,
162
+ (_a = this.options.checkpointResource) === null || _a === void 0 ? void 0 : _a.resourceId,
163
+ ].filter((resourceId) => Boolean(resourceId));
164
+ }
157
165
  constructor(options) {
158
166
  super(options, import.meta.url);
159
167
  this.apiBasedTools = {};
@@ -191,7 +199,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
191
199
  });
192
200
  }
193
201
  validateConfigAfterDiscover(adminforth, resourceConfig) {
194
- this.agentSystemPromptPromise = buildAgentSystemPrompt(adminforth)
202
+ this.agentSystemPromptPromise = buildAgentSystemPrompt(adminforth, this.getInternalAgentResourceIds())
195
203
  .then((systemPrompt) => appendCustomSystemPrompt(systemPrompt, this.options.systemPrompt));
196
204
  }
197
205
  instanceUniqueRepresentation(pluginOptions) {
@@ -316,7 +324,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
316
324
  formatAdminUserPrompt(adminUser, this.adminforth.config.auth.usernameField),
317
325
  formatLanguagePrompt(userLanguage),
318
326
  ].join("\n\n");
319
- const apiBasedTools = buildApiBasedTools(this.adminforth);
327
+ const apiBasedTools = buildApiBasedTools(this.adminforth, this.getInternalAgentResourceIds());
320
328
  for (const toolName of ALWAYS_AVAILABLE_API_TOOL_NAMES) {
321
329
  assertRequiredApiTool(apiBasedTools, toolName);
322
330
  }
package/index.ts CHANGED
@@ -213,6 +213,14 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
213
213
  return this.checkpointer;
214
214
  }
215
215
 
216
+ private getInternalAgentResourceIds() {
217
+ return [
218
+ this.options.sessionResource.resourceId,
219
+ this.options.turnResource.resourceId,
220
+ this.options.checkpointResource?.resourceId,
221
+ ].filter((resourceId): resourceId is string => Boolean(resourceId));
222
+ }
223
+
216
224
  constructor(options: PluginOptions) {
217
225
  super(options, import.meta.url);
218
226
  this.options = options;
@@ -245,7 +253,10 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
245
253
  }
246
254
 
247
255
  validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
248
- this.agentSystemPromptPromise = buildAgentSystemPrompt(adminforth)
256
+ this.agentSystemPromptPromise = buildAgentSystemPrompt(
257
+ adminforth,
258
+ this.getInternalAgentResourceIds(),
259
+ )
249
260
  .then((systemPrompt) => appendCustomSystemPrompt(systemPrompt, this.options.systemPrompt));
250
261
  }
251
262
 
@@ -392,7 +403,10 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
392
403
  formatAdminUserPrompt(adminUser, this.adminforth.config.auth.usernameField),
393
404
  formatLanguagePrompt(userLanguage),
394
405
  ].join("\n\n");
395
- const apiBasedTools = buildApiBasedTools(this.adminforth);
406
+ const apiBasedTools = buildApiBasedTools(
407
+ this.adminforth,
408
+ this.getInternalAgentResourceIds(),
409
+ );
396
410
  for (const toolName of ALWAYS_AVAILABLE_API_TOOL_NAMES) {
397
411
  assertRequiredApiTool(apiBasedTools, toolName);
398
412
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "1.31.0",
3
+ "version": "1.32.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",