@quilltap/plugin-utils 1.5.4 → 1.6.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/dist/index.d.mts CHANGED
@@ -4,6 +4,7 @@ export { PluginLoggerWithChild, __clearCoreLoggerFactory, __injectCoreLoggerFact
4
4
  export { OpenAICompatibleProvider, OpenAICompatibleProviderConfig } from './providers/index.mjs';
5
5
  export { CreateRoleplayTemplatePluginOptions, CreateSingleTemplatePluginOptions, createRoleplayTemplatePlugin, createSingleTemplatePlugin, validateRoleplayTemplatePlugin, validateTemplateConfig } from './roleplay-templates/index.mjs';
6
6
  export { isVMEnvironment, resolveHostGateway, rewriteLocalhostUrl } from './host-rewrite.mjs';
7
+ import 'openai';
7
8
 
8
9
  /**
9
10
  * Built-in tool names for Quilltap
@@ -51,6 +52,68 @@ declare const BUILTIN_TOOL_NAMES: Set<string>;
51
52
  */
52
53
  declare function getBuiltinToolNames(): Set<string>;
53
54
 
55
+ /**
56
+ * Quilltap Version Management
57
+ *
58
+ * Provides access to the Quilltap application version for plugins.
59
+ * Uses the same globalThis injection pattern as the logger factory,
60
+ * allowing the host app to inject its version at startup.
61
+ *
62
+ * @module @quilltap/plugin-utils/version
63
+ */
64
+ /**
65
+ * Inject the Quilltap application version into the global namespace.
66
+ *
67
+ * This should be called early in plugin initialization (alongside the
68
+ * logger factory injection), before any plugins are loaded. Plugins
69
+ * can then retrieve the version via `getQuilltapVersion()`.
70
+ *
71
+ * @param version - The Quilltap application version string (e.g., '3.3.0')
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { __injectQuilltapVersion } from '@quilltap/plugin-utils';
76
+ * import packageJson from './package.json';
77
+ *
78
+ * __injectQuilltapVersion(packageJson.version);
79
+ * ```
80
+ */
81
+ declare function __injectQuilltapVersion(version: string): void;
82
+ /**
83
+ * Clear the injected Quilltap version from the global namespace.
84
+ *
85
+ * Useful for testing or cleanup.
86
+ */
87
+ declare function __clearQuilltapVersion(): void;
88
+ /**
89
+ * Get the Quilltap application version.
90
+ *
91
+ * Returns the version injected by the host app, or 'unknown' if
92
+ * no version has been injected (e.g., running outside of Quilltap).
93
+ *
94
+ * @returns The Quilltap version string (e.g., '3.3.0') or 'unknown'
95
+ */
96
+ declare function getQuilltapVersion(): string;
97
+ /**
98
+ * Get the Quilltap User-Agent string for API requests.
99
+ *
100
+ * Returns a string in the format `Quilltap/{version}` suitable for
101
+ * use as a User-Agent header or app identifier in API calls.
102
+ *
103
+ * @returns User-Agent string (e.g., 'Quilltap/3.3.0')
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * import { getQuilltapUserAgent } from '@quilltap/plugin-utils';
108
+ *
109
+ * const client = new OpenAI({
110
+ * apiKey,
111
+ * defaultHeaders: { 'User-Agent': getQuilltapUserAgent() },
112
+ * });
113
+ * ```
114
+ */
115
+ declare function getQuilltapUserAgent(): string;
116
+
54
117
  /**
55
118
  * @quilltap/plugin-utils
56
119
  *
@@ -71,6 +134,6 @@ declare function getBuiltinToolNames(): Set<string>;
71
134
  * Version of the plugin-utils package.
72
135
  * Can be used at runtime to check compatibility.
73
136
  */
74
- declare const PLUGIN_UTILS_VERSION = "1.4.0";
137
+ declare const PLUGIN_UTILS_VERSION = "1.6.1";
75
138
 
76
- export { BUILTIN_TOOL_NAMES, PLUGIN_UTILS_VERSION, getBuiltinToolNames };
139
+ export { BUILTIN_TOOL_NAMES, PLUGIN_UTILS_VERSION, __clearQuilltapVersion, __injectQuilltapVersion, getBuiltinToolNames, getQuilltapUserAgent, getQuilltapVersion };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { PluginLoggerWithChild, __clearCoreLoggerFactory, __injectCoreLoggerFact
4
4
  export { OpenAICompatibleProvider, OpenAICompatibleProviderConfig } from './providers/index.js';
5
5
  export { CreateRoleplayTemplatePluginOptions, CreateSingleTemplatePluginOptions, createRoleplayTemplatePlugin, createSingleTemplatePlugin, validateRoleplayTemplatePlugin, validateTemplateConfig } from './roleplay-templates/index.js';
6
6
  export { isVMEnvironment, resolveHostGateway, rewriteLocalhostUrl } from './host-rewrite.js';
7
+ import 'openai';
7
8
 
8
9
  /**
9
10
  * Built-in tool names for Quilltap
@@ -51,6 +52,68 @@ declare const BUILTIN_TOOL_NAMES: Set<string>;
51
52
  */
52
53
  declare function getBuiltinToolNames(): Set<string>;
53
54
 
55
+ /**
56
+ * Quilltap Version Management
57
+ *
58
+ * Provides access to the Quilltap application version for plugins.
59
+ * Uses the same globalThis injection pattern as the logger factory,
60
+ * allowing the host app to inject its version at startup.
61
+ *
62
+ * @module @quilltap/plugin-utils/version
63
+ */
64
+ /**
65
+ * Inject the Quilltap application version into the global namespace.
66
+ *
67
+ * This should be called early in plugin initialization (alongside the
68
+ * logger factory injection), before any plugins are loaded. Plugins
69
+ * can then retrieve the version via `getQuilltapVersion()`.
70
+ *
71
+ * @param version - The Quilltap application version string (e.g., '3.3.0')
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { __injectQuilltapVersion } from '@quilltap/plugin-utils';
76
+ * import packageJson from './package.json';
77
+ *
78
+ * __injectQuilltapVersion(packageJson.version);
79
+ * ```
80
+ */
81
+ declare function __injectQuilltapVersion(version: string): void;
82
+ /**
83
+ * Clear the injected Quilltap version from the global namespace.
84
+ *
85
+ * Useful for testing or cleanup.
86
+ */
87
+ declare function __clearQuilltapVersion(): void;
88
+ /**
89
+ * Get the Quilltap application version.
90
+ *
91
+ * Returns the version injected by the host app, or 'unknown' if
92
+ * no version has been injected (e.g., running outside of Quilltap).
93
+ *
94
+ * @returns The Quilltap version string (e.g., '3.3.0') or 'unknown'
95
+ */
96
+ declare function getQuilltapVersion(): string;
97
+ /**
98
+ * Get the Quilltap User-Agent string for API requests.
99
+ *
100
+ * Returns a string in the format `Quilltap/{version}` suitable for
101
+ * use as a User-Agent header or app identifier in API calls.
102
+ *
103
+ * @returns User-Agent string (e.g., 'Quilltap/3.3.0')
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * import { getQuilltapUserAgent } from '@quilltap/plugin-utils';
108
+ *
109
+ * const client = new OpenAI({
110
+ * apiKey,
111
+ * defaultHeaders: { 'User-Agent': getQuilltapUserAgent() },
112
+ * });
113
+ * ```
114
+ */
115
+ declare function getQuilltapUserAgent(): string;
116
+
54
117
  /**
55
118
  * @quilltap/plugin-utils
56
119
  *
@@ -71,6 +134,6 @@ declare function getBuiltinToolNames(): Set<string>;
71
134
  * Version of the plugin-utils package.
72
135
  * Can be used at runtime to check compatibility.
73
136
  */
74
- declare const PLUGIN_UTILS_VERSION = "1.4.0";
137
+ declare const PLUGIN_UTILS_VERSION = "1.6.1";
75
138
 
76
- export { BUILTIN_TOOL_NAMES, PLUGIN_UTILS_VERSION, getBuiltinToolNames };
139
+ export { BUILTIN_TOOL_NAMES, PLUGIN_UTILS_VERSION, __clearQuilltapVersion, __injectQuilltapVersion, getBuiltinToolNames, getQuilltapUserAgent, getQuilltapVersion };
package/dist/index.js CHANGED
@@ -34,7 +34,9 @@ __export(src_exports, {
34
34
  OpenAICompatibleProvider: () => OpenAICompatibleProvider,
35
35
  PLUGIN_UTILS_VERSION: () => PLUGIN_UTILS_VERSION,
36
36
  __clearCoreLoggerFactory: () => __clearCoreLoggerFactory,
37
+ __clearQuilltapVersion: () => __clearQuilltapVersion,
37
38
  __injectCoreLoggerFactory: () => __injectCoreLoggerFactory,
39
+ __injectQuilltapVersion: () => __injectQuilltapVersion,
38
40
  applyDescriptionLimit: () => applyDescriptionLimit,
39
41
  convertFromAnthropicFormat: () => convertFromAnthropicFormat,
40
42
  convertFromGoogleFormat: () => convertFromGoogleFormat,
@@ -52,6 +54,8 @@ __export(src_exports, {
52
54
  detectToolCallFormat: () => detectToolCallFormat,
53
55
  getBuiltinToolNames: () => getBuiltinToolNames,
54
56
  getLogLevelFromEnv: () => getLogLevelFromEnv,
57
+ getQuilltapUserAgent: () => getQuilltapUserAgent,
58
+ getQuilltapVersion: () => getQuilltapVersion,
55
59
  hasCoreLogger: () => hasCoreLogger,
56
60
  hasToolCalls: () => hasToolCalls,
57
61
  isVMEnvironment: () => isVMEnvironment,
@@ -381,6 +385,24 @@ var import_plugin_types = require("@quilltap/plugin-types");
381
385
 
382
386
  // src/providers/openai-compatible.ts
383
387
  var import_openai = __toESM(require("openai"));
388
+
389
+ // src/version.ts
390
+ var GLOBAL_VERSION_KEY = "__quilltap_app_version";
391
+ function __injectQuilltapVersion(version) {
392
+ globalThis[GLOBAL_VERSION_KEY] = version;
393
+ }
394
+ function __clearQuilltapVersion() {
395
+ globalThis[GLOBAL_VERSION_KEY] = void 0;
396
+ }
397
+ function getQuilltapVersion() {
398
+ const version = globalThis[GLOBAL_VERSION_KEY];
399
+ return typeof version === "string" ? version : "unknown";
400
+ }
401
+ function getQuilltapUserAgent() {
402
+ return `Quilltap/${getQuilltapVersion()}`;
403
+ }
404
+
405
+ // src/providers/openai-compatible.ts
384
406
  var OpenAICompatibleProvider = class {
385
407
  /**
386
408
  * Creates a new OpenAI-compatible provider instance.
@@ -446,6 +468,20 @@ var OpenAICompatibleProvider = class {
446
468
  getEffectiveApiKey(apiKey) {
447
469
  return this.requireApiKey ? apiKey : apiKey || "not-needed";
448
470
  }
471
+ /**
472
+ * Creates an OpenAI client configured with the provider's base URL,
473
+ * API key, and Quilltap User-Agent header.
474
+ *
475
+ * @param apiKey - API key for authentication
476
+ * @returns Configured OpenAI client instance
477
+ */
478
+ createClient(apiKey) {
479
+ return new import_openai.default({
480
+ apiKey: this.getEffectiveApiKey(apiKey),
481
+ baseURL: this.baseUrl,
482
+ defaultHeaders: { "User-Agent": getQuilltapUserAgent() }
483
+ });
484
+ }
449
485
  /**
450
486
  * Sends a message and returns the complete response.
451
487
  *
@@ -456,10 +492,7 @@ var OpenAICompatibleProvider = class {
456
492
  async sendMessage(params, apiKey) {
457
493
  this.validateApiKeyRequirement(apiKey);
458
494
  const attachmentResults = this.collectAttachmentFailures(params);
459
- const client = new import_openai.default({
460
- apiKey: this.getEffectiveApiKey(apiKey),
461
- baseURL: this.baseUrl
462
- });
495
+ const client = this.createClient(apiKey);
463
496
  const messages = params.messages.filter((m) => {
464
497
  if (m.role === "tool" && !m.toolCallId) return false;
465
498
  return true;
@@ -527,10 +560,7 @@ var OpenAICompatibleProvider = class {
527
560
  async *streamMessage(params, apiKey) {
528
561
  this.validateApiKeyRequirement(apiKey);
529
562
  const attachmentResults = this.collectAttachmentFailures(params);
530
- const client = new import_openai.default({
531
- apiKey: this.getEffectiveApiKey(apiKey),
532
- baseURL: this.baseUrl
533
- });
563
+ const client = this.createClient(apiKey);
534
564
  const messages = params.messages.filter((m) => {
535
565
  if (m.role === "tool" && !m.toolCallId) return false;
536
566
  return true;
@@ -618,10 +648,7 @@ var OpenAICompatibleProvider = class {
618
648
  return false;
619
649
  }
620
650
  try {
621
- const client = new import_openai.default({
622
- apiKey: this.getEffectiveApiKey(apiKey),
623
- baseURL: this.baseUrl
624
- });
651
+ const client = this.createClient(apiKey);
625
652
  await client.models.list();
626
653
  return true;
627
654
  } catch (error) {
@@ -647,10 +674,7 @@ var OpenAICompatibleProvider = class {
647
674
  return [];
648
675
  }
649
676
  try {
650
- const client = new import_openai.default({
651
- apiKey: this.getEffectiveApiKey(apiKey),
652
- baseURL: this.baseUrl
653
- });
677
+ const client = this.createClient(apiKey);
654
678
  const models = await client.models.list();
655
679
  const modelList = models.data.map((m) => m.id).sort();
656
680
  return modelList;
@@ -932,14 +956,16 @@ function rewriteLocalhostUrl(url) {
932
956
  }
933
957
 
934
958
  // src/index.ts
935
- var PLUGIN_UTILS_VERSION = "1.4.0";
959
+ var PLUGIN_UTILS_VERSION = "1.6.1";
936
960
  // Annotate the CommonJS export names for ESM import in node:
937
961
  0 && (module.exports = {
938
962
  BUILTIN_TOOL_NAMES,
939
963
  OpenAICompatibleProvider,
940
964
  PLUGIN_UTILS_VERSION,
941
965
  __clearCoreLoggerFactory,
966
+ __clearQuilltapVersion,
942
967
  __injectCoreLoggerFactory,
968
+ __injectQuilltapVersion,
943
969
  applyDescriptionLimit,
944
970
  convertFromAnthropicFormat,
945
971
  convertFromGoogleFormat,
@@ -957,6 +983,8 @@ var PLUGIN_UTILS_VERSION = "1.4.0";
957
983
  detectToolCallFormat,
958
984
  getBuiltinToolNames,
959
985
  getLogLevelFromEnv,
986
+ getQuilltapUserAgent,
987
+ getQuilltapVersion,
960
988
  hasCoreLogger,
961
989
  hasToolCalls,
962
990
  isVMEnvironment,