@quilltap/plugin-utils 1.6.2 → 1.7.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.
- package/README.md +43 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +79 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -1
- package/dist/index.mjs.map +1 -1
- package/dist/system-prompts/index.d.mts +65 -0
- package/dist/system-prompts/index.d.ts +65 -0
- package/dist/system-prompts/index.js +106 -0
- package/dist/system-prompts/index.js.map +1 -0
- package/dist/system-prompts/index.mjs +78 -0
- package/dist/system-prompts/index.mjs.map +1 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -205,6 +205,49 @@ export const plugin = createRoleplayTemplatePlugin({
|
|
|
205
205
|
| `validateTemplateConfig(template)` | Validate an individual template configuration |
|
|
206
206
|
| `validateRoleplayTemplatePlugin(plugin)` | Validate a complete roleplay template plugin |
|
|
207
207
|
|
|
208
|
+
### System Prompt Plugin Utilities
|
|
209
|
+
|
|
210
|
+
Create system prompt plugins that provide character prompt templates from `.md` files:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { createSystemPromptPlugin } from '@quilltap/plugin-utils';
|
|
214
|
+
import type { SystemPromptData } from '@quilltap/plugin-types';
|
|
215
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
216
|
+
import { join, dirname } from 'node:path';
|
|
217
|
+
|
|
218
|
+
function loadPrompts(): SystemPromptData[] {
|
|
219
|
+
const promptsDir = join(dirname(__filename), 'prompts');
|
|
220
|
+
return readdirSync(promptsDir)
|
|
221
|
+
.filter(f => f.endsWith('.md'))
|
|
222
|
+
.map(file => {
|
|
223
|
+
const name = file.replace(/\.md$/i, '');
|
|
224
|
+
const parts = name.split('_');
|
|
225
|
+
const category = parts.pop()!;
|
|
226
|
+
const modelHint = parts.join('_');
|
|
227
|
+
return {
|
|
228
|
+
name,
|
|
229
|
+
content: readFileSync(join(promptsDir, file), 'utf-8'),
|
|
230
|
+
modelHint,
|
|
231
|
+
category,
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export const plugin = createSystemPromptPlugin({
|
|
237
|
+
metadata: {
|
|
238
|
+
pluginId: 'my-prompts',
|
|
239
|
+
displayName: 'My System Prompts',
|
|
240
|
+
version: '1.0.0',
|
|
241
|
+
},
|
|
242
|
+
prompts: loadPrompts(),
|
|
243
|
+
});
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
| Function | Description |
|
|
247
|
+
|----------|-------------|
|
|
248
|
+
| `createSystemPromptPlugin(options)` | Create a system prompt plugin with validation |
|
|
249
|
+
| `validateSystemPromptPlugin(plugin)` | Validate a complete system prompt plugin |
|
|
250
|
+
|
|
208
251
|
## Example: Complete Plugin Provider
|
|
209
252
|
|
|
210
253
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ export { T as ToolCallFormat, a as ToolConvertTarget, b as applyDescriptionLimit
|
|
|
3
3
|
export { PluginLoggerWithChild, __clearCoreLoggerFactory, __injectCoreLoggerFactory, createPluginLogger, getLogLevelFromEnv, hasCoreLogger } from './logging/index.mjs';
|
|
4
4
|
export { OpenAICompatibleProvider, OpenAICompatibleProviderConfig } from './providers/index.mjs';
|
|
5
5
|
export { CreateRoleplayTemplatePluginOptions, CreateSingleTemplatePluginOptions, createRoleplayTemplatePlugin, createSingleTemplatePlugin, validateRoleplayTemplatePlugin, validateTemplateConfig } from './roleplay-templates/index.mjs';
|
|
6
|
+
export { CreateSystemPromptPluginOptions, createSystemPromptPlugin, validateSystemPromptPlugin } from './system-prompts/index.mjs';
|
|
6
7
|
export { isVMEnvironment, resolveHostGateway, rewriteLocalhostUrl } from './host-rewrite.mjs';
|
|
7
8
|
import 'openai';
|
|
8
9
|
|
|
@@ -134,6 +135,6 @@ declare function getQuilltapUserAgent(): string;
|
|
|
134
135
|
* Version of the plugin-utils package.
|
|
135
136
|
* Can be used at runtime to check compatibility.
|
|
136
137
|
*/
|
|
137
|
-
declare const PLUGIN_UTILS_VERSION = "1.
|
|
138
|
+
declare const PLUGIN_UTILS_VERSION = "1.7.0";
|
|
138
139
|
|
|
139
140
|
export { BUILTIN_TOOL_NAMES, PLUGIN_UTILS_VERSION, __clearQuilltapVersion, __injectQuilltapVersion, getBuiltinToolNames, getQuilltapUserAgent, getQuilltapVersion };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { T as ToolCallFormat, a as ToolConvertTarget, b as applyDescriptionLimit
|
|
|
3
3
|
export { PluginLoggerWithChild, __clearCoreLoggerFactory, __injectCoreLoggerFactory, createPluginLogger, getLogLevelFromEnv, hasCoreLogger } from './logging/index.js';
|
|
4
4
|
export { OpenAICompatibleProvider, OpenAICompatibleProviderConfig } from './providers/index.js';
|
|
5
5
|
export { CreateRoleplayTemplatePluginOptions, CreateSingleTemplatePluginOptions, createRoleplayTemplatePlugin, createSingleTemplatePlugin, validateRoleplayTemplatePlugin, validateTemplateConfig } from './roleplay-templates/index.js';
|
|
6
|
+
export { CreateSystemPromptPluginOptions, createSystemPromptPlugin, validateSystemPromptPlugin } from './system-prompts/index.js';
|
|
6
7
|
export { isVMEnvironment, resolveHostGateway, rewriteLocalhostUrl } from './host-rewrite.js';
|
|
7
8
|
import 'openai';
|
|
8
9
|
|
|
@@ -134,6 +135,6 @@ declare function getQuilltapUserAgent(): string;
|
|
|
134
135
|
* Version of the plugin-utils package.
|
|
135
136
|
* Can be used at runtime to check compatibility.
|
|
136
137
|
*/
|
|
137
|
-
declare const PLUGIN_UTILS_VERSION = "1.
|
|
138
|
+
declare const PLUGIN_UTILS_VERSION = "1.7.0";
|
|
138
139
|
|
|
139
140
|
export { BUILTIN_TOOL_NAMES, PLUGIN_UTILS_VERSION, __clearQuilltapVersion, __injectQuilltapVersion, getBuiltinToolNames, getQuilltapUserAgent, getQuilltapVersion };
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ __export(src_exports, {
|
|
|
51
51
|
createPluginLogger: () => createPluginLogger,
|
|
52
52
|
createRoleplayTemplatePlugin: () => createRoleplayTemplatePlugin,
|
|
53
53
|
createSingleTemplatePlugin: () => createSingleTemplatePlugin,
|
|
54
|
+
createSystemPromptPlugin: () => createSystemPromptPlugin,
|
|
54
55
|
detectToolCallFormat: () => detectToolCallFormat,
|
|
55
56
|
getBuiltinToolNames: () => getBuiltinToolNames,
|
|
56
57
|
getLogLevelFromEnv: () => getLogLevelFromEnv,
|
|
@@ -66,6 +67,7 @@ __export(src_exports, {
|
|
|
66
67
|
resolveHostGateway: () => resolveHostGateway,
|
|
67
68
|
rewriteLocalhostUrl: () => rewriteLocalhostUrl,
|
|
68
69
|
validateRoleplayTemplatePlugin: () => validateRoleplayTemplatePlugin,
|
|
70
|
+
validateSystemPromptPlugin: () => validateSystemPromptPlugin,
|
|
69
71
|
validateTemplateConfig: () => validateTemplateConfig
|
|
70
72
|
});
|
|
71
73
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -808,6 +810,80 @@ function validateRoleplayTemplatePlugin(plugin) {
|
|
|
808
810
|
return true;
|
|
809
811
|
}
|
|
810
812
|
|
|
813
|
+
// src/system-prompts/builder.ts
|
|
814
|
+
function createSystemPromptPlugin(options) {
|
|
815
|
+
const { metadata, prompts, initialize } = options;
|
|
816
|
+
if (prompts.length === 0) {
|
|
817
|
+
throw new Error("At least one system prompt is required");
|
|
818
|
+
}
|
|
819
|
+
const names = /* @__PURE__ */ new Set();
|
|
820
|
+
for (const prompt of prompts) {
|
|
821
|
+
if (!prompt.name || prompt.name.trim() === "") {
|
|
822
|
+
throw new Error("Prompt name is required");
|
|
823
|
+
}
|
|
824
|
+
if (!prompt.content || prompt.content.trim() === "") {
|
|
825
|
+
throw new Error(`Prompt "${prompt.name}" requires content`);
|
|
826
|
+
}
|
|
827
|
+
if (!prompt.modelHint || prompt.modelHint.trim() === "") {
|
|
828
|
+
throw new Error(`Prompt "${prompt.name}" requires a modelHint`);
|
|
829
|
+
}
|
|
830
|
+
if (!prompt.category || prompt.category.trim() === "") {
|
|
831
|
+
throw new Error(`Prompt "${prompt.name}" requires a category`);
|
|
832
|
+
}
|
|
833
|
+
if (names.has(prompt.name)) {
|
|
834
|
+
throw new Error(`Duplicate prompt name: "${prompt.name}"`);
|
|
835
|
+
}
|
|
836
|
+
names.add(prompt.name);
|
|
837
|
+
}
|
|
838
|
+
const plugin = {
|
|
839
|
+
metadata,
|
|
840
|
+
prompts
|
|
841
|
+
};
|
|
842
|
+
if (initialize) {
|
|
843
|
+
plugin.initialize = async () => {
|
|
844
|
+
await initialize();
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
return plugin;
|
|
848
|
+
}
|
|
849
|
+
function validateSystemPromptPlugin(plugin) {
|
|
850
|
+
if (!plugin.metadata) {
|
|
851
|
+
throw new Error("Plugin metadata is required");
|
|
852
|
+
}
|
|
853
|
+
if (!plugin.metadata.pluginId || plugin.metadata.pluginId.trim() === "") {
|
|
854
|
+
throw new Error("Plugin metadata.pluginId is required");
|
|
855
|
+
}
|
|
856
|
+
if (!/^[a-z0-9-]+$/.test(plugin.metadata.pluginId)) {
|
|
857
|
+
throw new Error("Plugin pluginId must be lowercase alphanumeric with hyphens only");
|
|
858
|
+
}
|
|
859
|
+
if (!plugin.metadata.displayName || plugin.metadata.displayName.trim() === "") {
|
|
860
|
+
throw new Error("Plugin metadata.displayName is required");
|
|
861
|
+
}
|
|
862
|
+
if (!plugin.prompts || !Array.isArray(plugin.prompts) || plugin.prompts.length === 0) {
|
|
863
|
+
throw new Error("Plugin must have at least one prompt");
|
|
864
|
+
}
|
|
865
|
+
const names = /* @__PURE__ */ new Set();
|
|
866
|
+
for (const prompt of plugin.prompts) {
|
|
867
|
+
if (!prompt.name || prompt.name.trim() === "") {
|
|
868
|
+
throw new Error("Prompt name is required");
|
|
869
|
+
}
|
|
870
|
+
if (!prompt.content || prompt.content.trim() === "") {
|
|
871
|
+
throw new Error(`Prompt "${prompt.name}" requires content`);
|
|
872
|
+
}
|
|
873
|
+
if (!prompt.modelHint || prompt.modelHint.trim() === "") {
|
|
874
|
+
throw new Error(`Prompt "${prompt.name}" requires a modelHint`);
|
|
875
|
+
}
|
|
876
|
+
if (!prompt.category || prompt.category.trim() === "") {
|
|
877
|
+
throw new Error(`Prompt "${prompt.name}" requires a category`);
|
|
878
|
+
}
|
|
879
|
+
if (names.has(prompt.name)) {
|
|
880
|
+
throw new Error(`Duplicate prompt name: "${prompt.name}"`);
|
|
881
|
+
}
|
|
882
|
+
names.add(prompt.name);
|
|
883
|
+
}
|
|
884
|
+
return true;
|
|
885
|
+
}
|
|
886
|
+
|
|
811
887
|
// src/builtin-tools.ts
|
|
812
888
|
var BUILTIN_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
813
889
|
"generate_image",
|
|
@@ -956,7 +1032,7 @@ function rewriteLocalhostUrl(url) {
|
|
|
956
1032
|
}
|
|
957
1033
|
|
|
958
1034
|
// src/index.ts
|
|
959
|
-
var PLUGIN_UTILS_VERSION = "1.
|
|
1035
|
+
var PLUGIN_UTILS_VERSION = "1.7.0";
|
|
960
1036
|
// Annotate the CommonJS export names for ESM import in node:
|
|
961
1037
|
0 && (module.exports = {
|
|
962
1038
|
BUILTIN_TOOL_NAMES,
|
|
@@ -980,6 +1056,7 @@ var PLUGIN_UTILS_VERSION = "1.6.1";
|
|
|
980
1056
|
createPluginLogger,
|
|
981
1057
|
createRoleplayTemplatePlugin,
|
|
982
1058
|
createSingleTemplatePlugin,
|
|
1059
|
+
createSystemPromptPlugin,
|
|
983
1060
|
detectToolCallFormat,
|
|
984
1061
|
getBuiltinToolNames,
|
|
985
1062
|
getLogLevelFromEnv,
|
|
@@ -995,6 +1072,7 @@ var PLUGIN_UTILS_VERSION = "1.6.1";
|
|
|
995
1072
|
resolveHostGateway,
|
|
996
1073
|
rewriteLocalhostUrl,
|
|
997
1074
|
validateRoleplayTemplatePlugin,
|
|
1075
|
+
validateSystemPromptPlugin,
|
|
998
1076
|
validateTemplateConfig
|
|
999
1077
|
});
|
|
1000
1078
|
//# sourceMappingURL=index.js.map
|