strapi-plugin-ai-sdk 0.7.3 → 0.7.4

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.
@@ -2644,15 +2644,21 @@ function createTools(strapi, context) {
2644
2644
  return tools;
2645
2645
  }
2646
2646
  const CONTENT_TOOLS = /* @__PURE__ */ new Set(["searchContent", "findOneContent", "aggregateContent"]);
2647
- function createPublicTools(strapi, allowedContentTypes) {
2647
+ function createPublicTools(strapi, allowedContentTypes, publicToolSources) {
2648
2648
  const plugin = strapi.plugin("ai-sdk");
2649
2649
  const registry = plugin.toolRegistry;
2650
2650
  if (!registry) {
2651
2651
  throw new Error("Tool registry not initialized");
2652
2652
  }
2653
2653
  const allowed = new Set(allowedContentTypes);
2654
+ const allowedSources = new Set(publicToolSources ?? []);
2654
2655
  const tools = {};
2655
2656
  for (const [name, def] of registry.getPublicSafe()) {
2657
+ const sepIndex = name.indexOf("__");
2658
+ if (sepIndex !== -1) {
2659
+ const prefix = name.substring(0, sepIndex);
2660
+ if (!allowedSources.has(prefix)) continue;
2661
+ }
2656
2662
  if (CONTENT_TOOLS.has(name)) {
2657
2663
  tools[name] = ai.tool({
2658
2664
  description: def.description,
@@ -2800,9 +2806,10 @@ ${lines.join("\n")}`;
2800
2806
  const maxSteps = publicConfig?.maxSteps ?? DEFAULT_PUBLIC_MAX_STEPS;
2801
2807
  const publicModel = publicConfig?.chatModel ?? DEFAULT_PUBLIC_CHAT_MODEL;
2802
2808
  const allowedContentTypes = publicConfig?.allowedContentTypes ?? [];
2809
+ const publicToolSources = publicConfig?.publicToolSources;
2803
2810
  const trimmedMessages = messages.length > maxMessages ? messages.slice(-maxMessages) : messages;
2804
2811
  const modelMessages = await ai.convertToModelMessages(trimmedMessages);
2805
- const tools = createPublicTools(strapi, allowedContentTypes);
2812
+ const tools = createPublicTools(strapi, allowedContentTypes, publicToolSources);
2806
2813
  const toolsDescription = describeTools(tools);
2807
2814
  let system = composeSystemPrompt(config2, toolsDescription, options2?.system || DEFAULT_PUBLIC_PREAMBLE);
2808
2815
  try {
@@ -2624,15 +2624,21 @@ function createTools(strapi, context) {
2624
2624
  return tools;
2625
2625
  }
2626
2626
  const CONTENT_TOOLS = /* @__PURE__ */ new Set(["searchContent", "findOneContent", "aggregateContent"]);
2627
- function createPublicTools(strapi, allowedContentTypes) {
2627
+ function createPublicTools(strapi, allowedContentTypes, publicToolSources) {
2628
2628
  const plugin = strapi.plugin("ai-sdk");
2629
2629
  const registry = plugin.toolRegistry;
2630
2630
  if (!registry) {
2631
2631
  throw new Error("Tool registry not initialized");
2632
2632
  }
2633
2633
  const allowed = new Set(allowedContentTypes);
2634
+ const allowedSources = new Set(publicToolSources ?? []);
2634
2635
  const tools = {};
2635
2636
  for (const [name, def] of registry.getPublicSafe()) {
2637
+ const sepIndex = name.indexOf("__");
2638
+ if (sepIndex !== -1) {
2639
+ const prefix = name.substring(0, sepIndex);
2640
+ if (!allowedSources.has(prefix)) continue;
2641
+ }
2636
2642
  if (CONTENT_TOOLS.has(name)) {
2637
2643
  tools[name] = tool({
2638
2644
  description: def.description,
@@ -2780,9 +2786,10 @@ ${lines.join("\n")}`;
2780
2786
  const maxSteps = publicConfig?.maxSteps ?? DEFAULT_PUBLIC_MAX_STEPS;
2781
2787
  const publicModel = publicConfig?.chatModel ?? DEFAULT_PUBLIC_CHAT_MODEL;
2782
2788
  const allowedContentTypes = publicConfig?.allowedContentTypes ?? [];
2789
+ const publicToolSources = publicConfig?.publicToolSources;
2783
2790
  const trimmedMessages = messages.length > maxMessages ? messages.slice(-maxMessages) : messages;
2784
2791
  const modelMessages = await convertToModelMessages(trimmedMessages);
2785
- const tools = createPublicTools(strapi, allowedContentTypes);
2792
+ const tools = createPublicTools(strapi, allowedContentTypes, publicToolSources);
2786
2793
  const toolsDescription = describeTools(tools);
2787
2794
  let system = composeSystemPrompt(config2, toolsDescription, options2?.system || DEFAULT_PUBLIC_PREAMBLE);
2788
2795
  try {
@@ -23,6 +23,8 @@ export declare const DEFAULT_PUBLIC_CHAT_MODEL = "claude-haiku-4-5-20251001";
23
23
  export interface PublicChatConfig {
24
24
  /** Content type UIDs the public chat is allowed to query (e.g. ['api::article.article']) */
25
25
  allowedContentTypes?: string[];
26
+ /** Plugin tool source IDs allowed in public chat (e.g. ['yt-embeddings-strapi-plugin']). If omitted, no plugin tools are exposed. */
27
+ publicToolSources?: string[];
26
28
  /** Model to use for public chat (defaults to Haiku for lower cost & higher rate limits) */
27
29
  chatModel?: string;
28
30
  /** Max conversation messages for public chat (defaults to 10) */
@@ -6,8 +6,9 @@ export declare function createTools(strapi: Core.Strapi, context?: ToolContext):
6
6
  * Create a restricted tool set for the public chat endpoint.
7
7
  * Only includes tools marked as publicSafe.
8
8
  * Content tools are wrapped to enforce allowedContentTypes.
9
+ * Plugin tools are only included if their source is in publicToolSources.
9
10
  */
10
- export declare function createPublicTools(strapi: Core.Strapi, allowedContentTypes: string[]): ToolSet;
11
+ export declare function createPublicTools(strapi: Core.Strapi, allowedContentTypes: string[], publicToolSources?: string[]): ToolSet;
11
12
  /**
12
13
  * Build a system prompt section describing all available tools.
13
14
  * Reads the `description` from each tool definition so it stays in sync automatically.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.3",
2
+ "version": "0.7.4",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "strapi-plugin",