strapi-plugin-ai-sdk 0.7.1 → 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.
- package/dist/_chunks/{App-DcU3uMiY.js → App-CEEsJsKL.js} +20 -6
- package/dist/_chunks/{App-Dwx6guC-.mjs → App-DCV7o6Hc.mjs} +20 -6
- package/dist/_chunks/{index-skxI4tiW.mjs → index-BMrDQVQl.mjs} +1 -1
- package/dist/_chunks/{index-D0dDUeEO.js → index-Cw2aiQ8K.js} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +9 -2
- package/dist/server/index.mjs +9 -2
- package/dist/server/src/lib/types.d.ts +2 -0
- package/dist/server/src/tools/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ const reactRouterDom = require("react-router-dom");
|
|
|
6
6
|
const designSystem = require("@strapi/design-system");
|
|
7
7
|
const react = require("react");
|
|
8
8
|
const styled = require("styled-components");
|
|
9
|
-
const index = require("./index-
|
|
9
|
+
const index = require("./index-Cw2aiQ8K.js");
|
|
10
10
|
const icons = require("@strapi/icons");
|
|
11
11
|
const Markdown = require("react-markdown");
|
|
12
12
|
const remarkGfm = require("remark-gfm");
|
|
@@ -101,11 +101,25 @@ function generateId() {
|
|
|
101
101
|
return globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
102
102
|
}
|
|
103
103
|
function toUIMessages(messages) {
|
|
104
|
-
return messages.map((message) =>
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
return messages.map((message) => {
|
|
105
|
+
const parts = [];
|
|
106
|
+
if (message.content) {
|
|
107
|
+
parts.push({ type: "text", text: message.content });
|
|
108
|
+
}
|
|
109
|
+
if (message.toolCalls) {
|
|
110
|
+
for (const tc of message.toolCalls) {
|
|
111
|
+
parts.push({
|
|
112
|
+
type: `tool-${tc.toolName}`,
|
|
113
|
+
toolCallId: tc.toolCallId,
|
|
114
|
+
toolName: tc.toolName,
|
|
115
|
+
state: tc.output !== void 0 ? "output-available" : "input-available",
|
|
116
|
+
input: tc.input,
|
|
117
|
+
...tc.output !== void 0 ? { output: tc.output } : {}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { id: message.id, role: message.role, parts };
|
|
122
|
+
});
|
|
109
123
|
}
|
|
110
124
|
async function fetchChatStream(messages, enabledToolSources) {
|
|
111
125
|
const token = getToken();
|
|
@@ -4,7 +4,7 @@ import { Link, useNavigate, Routes, Route } from "react-router-dom";
|
|
|
4
4
|
import { Box, Typography, TextInput, Button, Main, SearchForm, Searchbar, Table, Thead, Tr, Th, Tbody, Td, Flex, Pagination, Modal, Field, Textarea, SingleSelect, SingleSelectOption } from "@strapi/design-system";
|
|
5
5
|
import { useState, useEffect, useCallback, useMemo, useRef, forwardRef } from "react";
|
|
6
6
|
import styled from "styled-components";
|
|
7
|
-
import { P as PLUGIN_ID } from "./index-
|
|
7
|
+
import { P as PLUGIN_ID } from "./index-BMrDQVQl.mjs";
|
|
8
8
|
import { Plus, Trash, Sparkle, ArrowLeft, Pencil } from "@strapi/icons";
|
|
9
9
|
import Markdown from "react-markdown";
|
|
10
10
|
import remarkGfm from "remark-gfm";
|
|
@@ -95,11 +95,25 @@ function generateId() {
|
|
|
95
95
|
return globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
96
96
|
}
|
|
97
97
|
function toUIMessages(messages) {
|
|
98
|
-
return messages.map((message) =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
return messages.map((message) => {
|
|
99
|
+
const parts = [];
|
|
100
|
+
if (message.content) {
|
|
101
|
+
parts.push({ type: "text", text: message.content });
|
|
102
|
+
}
|
|
103
|
+
if (message.toolCalls) {
|
|
104
|
+
for (const tc of message.toolCalls) {
|
|
105
|
+
parts.push({
|
|
106
|
+
type: `tool-${tc.toolName}`,
|
|
107
|
+
toolCallId: tc.toolCallId,
|
|
108
|
+
toolName: tc.toolName,
|
|
109
|
+
state: tc.output !== void 0 ? "output-available" : "input-available",
|
|
110
|
+
input: tc.input,
|
|
111
|
+
...tc.output !== void 0 ? { output: tc.output } : {}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { id: message.id, role: message.role, parts };
|
|
116
|
+
});
|
|
103
117
|
}
|
|
104
118
|
async function fetchChatStream(messages, enabledToolSources) {
|
|
105
119
|
const token = getToken();
|
|
@@ -37,7 +37,7 @@ const index = {
|
|
|
37
37
|
defaultMessage: PLUGIN_ID
|
|
38
38
|
},
|
|
39
39
|
Component: async () => {
|
|
40
|
-
const { App } = await Promise.resolve().then(() => require("./App-
|
|
40
|
+
const { App } = await Promise.resolve().then(() => require("./App-CEEsJsKL.js"));
|
|
41
41
|
return App;
|
|
42
42
|
}
|
|
43
43
|
});
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -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 {
|
package/dist/server/index.mjs
CHANGED
|
@@ -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