diff --git a/.changeset/deprecate-server-i18n.md b/.changeset/deprecate-server-i18n.md new file mode 100644 index 0000000..dcf773b --- /dev/null +++ b/.changeset/deprecate-server-i18n.md @@ -0,0 +1,5 @@ +--- +"@chatcops/server": patch +--- + +Deprecate the `i18n` option, which the server never read. Setting it now logs a warning. diff --git a/packages/server/src/config.ts b/packages/server/src/config.ts index 9c49ac7..38b2466 100644 --- a/packages/server/src/config.ts +++ b/packages/server/src/config.ts @@ -12,6 +12,7 @@ export interface ChatCopsServerConfig { analytics?: boolean; /** Allowed CORS origin. Defaults to `'*'`. */ cors?: string; + /** @deprecated The server ignores this. Set the widget's text with its `strings` option. */ i18n?: { defaultLocale: string; locales: Record }; } diff --git a/packages/server/src/handler.ts b/packages/server/src/handler.ts index 29c80b7..586a36c 100644 --- a/packages/server/src/handler.ts +++ b/packages/server/src/handler.ts @@ -11,6 +11,10 @@ import { RateLimiter } from './rate-limit.js'; import { WebhookDispatcher } from './webhook.js'; export function createChatHandler(config: ChatCopsServerConfig) { + if (config.i18n) { + console.warn('[chatcops] The `i18n` option is deprecated and ignored. Set the widget text with its `strings` option.'); + } + const providerPromise = createProvider(config.provider); const conversations = new ConversationManager(); const rateLimiter = config.rateLimit ? new RateLimiter(config.rateLimit) : new RateLimiter(); diff --git a/packages/server/tests/handler.test.ts b/packages/server/tests/handler.test.ts index dd00d53..8a5f312 100644 --- a/packages/server/tests/handler.test.ts +++ b/packages/server/tests/handler.test.ts @@ -131,6 +131,32 @@ describe('createChatHandler', () => { expect(clearIntervalSpy).toHaveBeenCalledOnce(); }); + it('warns once when the deprecated i18n option is set', () => { + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + + const { cleanup } = createChatHandler({ + provider: { type: 'openai', apiKey: 'test-key' }, + systemPrompt: 'Test', + i18n: { defaultLocale: 'en', locales: {} }, + }); + cleanup(); + + expect(warnSpy).toHaveBeenCalledOnce(); + expect(warnSpy.mock.calls[0][0]).toContain('i18n'); + }); + + it('does not warn when i18n is not set', () => { + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + + const { cleanup } = createChatHandler({ + provider: { type: 'openai', apiKey: 'test-key' }, + systemPrompt: 'Test', + }); + cleanup(); + + expect(warnSpy).not.toHaveBeenCalled(); + }); + it('passes a working tool executor into the streaming provider', async () => { const weatherTool = { name: 'get_weather', diff --git a/website/src/content/docs/server/setup.mdx b/website/src/content/docs/server/setup.mdx index 8cbf0f9..aaa8b55 100644 --- a/website/src/content/docs/server/setup.mdx +++ b/website/src/content/docs/server/setup.mdx @@ -64,12 +64,6 @@ const handler = chatcopsMiddleware({ // Optional: CORS origin cors: '*', - - // Optional: i18n (accepted, but the server doesn't read it yet) - i18n: { - defaultLocale: 'en', - locales: { /* custom strings */ }, - }, }); ``` @@ -93,6 +87,7 @@ interface ChatCopsServerConfig { webhooks?: WebhookConfig[]; analytics?: boolean; cors?: string; + /** @deprecated Ignored by the server. Use the widget's `strings` option. */ i18n?: { defaultLocale: string; locales: Record; diff --git a/website/src/content/docs/widget/i18n.mdx b/website/src/content/docs/widget/i18n.mdx index 1f0ffd6..09b6e72 100644 --- a/website/src/content/docs/widget/i18n.mdx +++ b/website/src/content/docs/widget/i18n.mdx @@ -88,4 +88,4 @@ The server doesn't translate anything itself. When a request has a `locale`, it Respond in the user's language. Current locale: es ``` -Error messages the visitor sees come from the widget's `strings` (`errorGeneric`, `errorNetwork`, `errorRateLimit`). The server config also has an `i18n` option, but nothing reads it yet. +Error messages the visitor sees come from the widget's `strings` (`errorGeneric`, `errorNetwork`, `errorRateLimit`). The server config's `i18n` option is deprecated: the server ignores it and logs a warning when it's set, and it will be removed in a later release.