diff --git a/.changeset/37864-capability-unavailable-languages.md b/.changeset/37864-capability-unavailable-languages.md new file mode 100644 index 00000000000..88b2c5f46ee --- /dev/null +++ b/.changeset/37864-capability-unavailable-languages.md @@ -0,0 +1,19 @@ +--- +'@objectstack/runtime': patch +'@objectstack/spec': patch +'@objectstack/types': patch +--- + +fix(runtime): the mounted-but-unimplemented `501` of `/ai`, `/automation`, `/notifications`, `/ui` and a custom flow endpoint answers in the request's language + +Clause-②: yes (widening) — `@objectstack/spec` `BUILTIN_OPERATION_MESSAGES` gains `capability_unavailable_install`, `capability_unavailable_unshipped`, `capability_unavailable_ui`, `capability_unavailable_ai` and `capability_unavailable_search` in every locale; `@objectstack/runtime` `HttpDispatcherResult.response` gains the optional, never-written `faultLogMessage` +Metadata-protocol: none + +When a dispatcher domain's route is mounted and nothing implements the capability behind it, it answers `501 NOT_IMPLEMENTED` with the remedy sentence discovery reports for the slot. That sentence was fixed English for every reader. It now follows the request's top `Accept-Language` tag, as the other domain `501`s already do, and carries `Vary: Accept-Language`, so a shared cache cannot hand one reader's language to the next. The same holds for a custom API endpoint whose flow target finds no automation service. + +- The English sentence, the status and `error.code` are unchanged byte for byte. A request with no `Accept-Language`, or with a language the catalog does not carry, reads exactly the English it read before. +- Discovery's `services..message` stays English: it is read by SDKs, codegen and AI clients, and a host-level `/discovery` has no request to read a language from. A pin holds the `501`'s English equal to `serviceUnavailableMessage(slot)` for every slot, so the two still name the same remedy. +- The operator's fault log stays English: the one line a declared capability absence earns per route per process prints the English sentence whatever language the first request asked for. +- zh-CN now says 「定制包」 for the customization package in the three operation sentences that said 「定制软件包」, the term the console uses. + +Nothing to migrate. diff --git a/packages/runtime/src/declared-capability-absence-warn-once.test.ts b/packages/runtime/src/declared-capability-absence-warn-once.test.ts index 63b40084996..3b0c0772b75 100644 --- a/packages/runtime/src/declared-capability-absence-warn-once.test.ts +++ b/packages/runtime/src/declared-capability-absence-warn-once.test.ts @@ -59,6 +59,8 @@ import { describe, it, expect, vi } from 'vitest'; // `sendError` read the same `@objectstack/types` registry. import { createDispatcherPlugin } from './dispatcher-plugin.js'; import { sendError } from '@objectstack/types'; +// [#37864] Paid at collection too: the dispatcher's reach loads `@objectstack/metadata` (check:test-source-alias). +import '@objectstack/metadata'; // [#21061] The analytics domain refuses an anonymous caller first (ADR-0056 D2), // so every analytics boot below also registers an `auth` slot in the shape @@ -349,3 +351,33 @@ describe('#14656 — the wire does not move', () => { ); }); }); + +// [#37864] The wire answers in the caller's language; the operator's one line +// does not. Under the once-per-route dedupe, the FIRST request decides what the +// log holds for the life of the process, so the line is the English whatever +// that request asked for: `serviceUnavailableMessage('notification')`, which is +// also the sentence discovery publishes for the slot. +describe('#37864 — a localized 501 still logs its English', () => { + it('a ja-JP first request answers Japanese and leaves the English line', async () => { + const { route, logger } = await boot({ auth: SIGNED_IN_AUTH }); + + const ja = makeRes(); + await route('GET /notifications')({ ...REQ, headers: { 'accept-language': 'ja-JP,ja;q=0.9' } }, ja); + const en = makeRes(); + await route('GET /notifications')({ ...REQ }, en); + + expect(ja.statusCode).toBe(501); + expect(ja.body.error.code).toBe('NOT_IMPLEMENTED'); + expect(ja.body.error.message).not.toBe(en.body.error.message); + expect(ja.body.error.message).toContain('@objectstack/service-messaging'); + expect(en.body.error.message).toBe('Install @objectstack/service-messaging to enable'); + // `faultLogMessage` is the log's, never the wire's. + expect(JSON.stringify(ja.body)).not.toContain('faultLogMessage'); + + const warned = lines(logger.warn); + expect(warned, 'two requests, one line').toHaveLength(1); + expect(String(warned[0][0])).toContain('Install @objectstack/service-messaging to enable'); + expect(String(warned[0][0])).not.toContain(ja.body.error.message); + expect(lines(logger.error)).toHaveLength(0); + }); +}); diff --git a/packages/runtime/src/dispatcher-plugin.ts b/packages/runtime/src/dispatcher-plugin.ts index 18b9f712fff..b38a69adcad 100644 --- a/packages/runtime/src/dispatcher-plugin.ts +++ b/packages/runtime/src/dispatcher-plugin.ts @@ -457,11 +457,17 @@ function sendResultBase( // exit's, one function up. if (result.handled && result.response) { const body = result.response.body as { error?: { code?: unknown; message?: unknown } } | undefined; + // [#37864] An answer whose body is in the caller's language names the + // English its log line prints (`faultLogMessage`): the operator's line + // keeps one language whoever asked first. + const logMessage = typeof result.response.faultLogMessage === 'string' + ? result.response.faultLogMessage + : body?.error?.message; logServerFault( { status: result.response.status, ...(typeof body?.error?.code === 'string' ? { code: body.error.code } : {}), - ...(typeof body?.error?.message === 'string' ? { message: body.error.message } : {}), + ...(typeof logMessage === 'string' ? { message: logMessage } : {}), request: describeFaultRequest(fault?.req ?? (res as any)?.__obsRequest), }, fault?.logger, diff --git a/packages/runtime/src/domains/ai.ts b/packages/runtime/src/domains/ai.ts index d4c61d83475..7103f66c292 100644 --- a/packages/runtime/src/domains/ai.ts +++ b/packages/runtime/src/domains/ai.ts @@ -114,7 +114,7 @@ export async function handleAIRequest(deps: DomainHandlerDeps, subPath: string, // which is false for a Cloud/Enterprise deployment. The shared table // says the accurate thing now (REMEDY_DETAIL), so the override is gone // and this answer matches what discovery reports for the slot. - return capabilityUnavailable(deps, 'ai'); + return capabilityUnavailable(deps, context, 'ai'); }; // [#4058] A slot filled by a self-declared non-handler (`handlerReady: diff --git a/packages/runtime/src/domains/automation.ts b/packages/runtime/src/domains/automation.ts index b0e6cd7f966..1a46bb3eaff 100644 --- a/packages/runtime/src/domains/automation.ts +++ b/packages/runtime/src/domains/automation.ts @@ -3787,7 +3787,7 @@ async function respondToRecordUpdateStarts( } const { object, recordId, changes } = parsed.data; const svc = automationService as Pick; - if (typeof svc.listRecordUpdateStarts !== 'function') return capabilityUnavailable(deps, 'automation'); + if (typeof svc.listRecordUpdateStarts !== 'function') return capabilityUnavailable(deps, context, 'automation'); let stored: Record; try { const read = await callData( @@ -4144,7 +4144,7 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str // 501, not the `handled: false` this used to return: `/automation` IS // mounted, so the dispatcher's ROUTE_NOT_FOUND exit ("No handler matched // this request") described neither half truthfully. See ./unavailable.ts. - if (!isServiceServeable(automationService)) return capabilityUnavailable(deps, 'automation'); + if (!isServiceServeable(automationService)) return capabilityUnavailable(deps, context, 'automation'); // [ADR-0150 D5, epic child G1] THE ADDRESS, judged: an addressed path is // served when its qualifier names the one holder the bare name resolves diff --git a/packages/runtime/src/domains/catalog-activation-door.test.ts b/packages/runtime/src/domains/catalog-activation-door.test.ts index 14277aa4031..87f641f34b2 100644 --- a/packages/runtime/src/domains/catalog-activation-door.test.ts +++ b/packages/runtime/src/domains/catalog-activation-door.test.ts @@ -1164,3 +1164,60 @@ describe('[#37811] the no-ledger 501 follows the request\'s language, its noun i } }); }); + +// [#37864] Every type the door accepts names its noun through the catalog, in +// every catalog locale. The type list is read off the door's own shape refusal +// (it enumerates `CatalogActivationType`), so a type added there without a +// `catalog_activation_noun_` key, or without a row here, fails. +describe('[#37864] the no-ledger 501 names every activation type\'s noun in the request\'s language', () => { + const RULE = 'share_red_projects'; + const HOOK = 'crm_contact_changed'; + const QUEUE = 'support_intake'; + const ASSIGN = 'route_new_cases'; + const declared = (name: string) => ({ name, packageId: 'crm' }); + const TYPES: ReadonlyArray]> = [ + ['position', POSITION, {}, {}], + ['permission', SET, {}, {}], + ['sharing_rule', RULE, {}, { sharingRules: { async declaredRuleNamed(n: string) { return n === RULE ? declared(n) : null; } } }], + ['webhook', HOOK, {}, { + declaredWebhooks: { + async declaredWebhookNamed(n: string) { return n === HOOK ? { webhook: { name: n }, active: true, packageId: 'crm' } : null; }, + }, + }], + ['queue', QUEUE, {}, { 'ownership-queue': { async declaredQueueNamed(n: string) { return n === QUEUE ? declared(n) : null; } } }], + ['assignment_rule', ASSIGN, { registryItems: { assignment_rule: [{ name: ASSIGN, object: 'crm_case', _packageId: 'crm' }] } }, {}], + ]; + const LANGS = [ + ['en', {}], + ['ja-JP', { request: { headers: { 'accept-language': 'ja-JP,ja;q=0.9' } } }], + ['zh-CN', { request: { headers: { 'accept-language': 'zh-CN' } } }], + ['es-ES', { request: { headers: { 'accept-language': 'es-ES' } } }], + ] as const; + const fill = (locale: string, key: string, params: Record = {}): string => + BUILTIN_OPERATION_MESSAGES[locale][key].replace(/\{\{(\w+)\}\}/g, (_m, name: string) => params[name] ?? ''); + + it('the rows here are exactly the types the door accepts', async () => { + const refusal = await flip(boot('single'), TENANT_ADMIN(), '/_activation/no_such_type/x'); + expect(statusOf(refusal)).toBe(400); + const accepted = [...String(messageOf(refusal)).matchAll(/`([a-z_]+)`/g)].map((m) => m[1]); + expect(accepted.sort()).toEqual(TYPES.map(([type]) => type).sort()); + }); + + it.each(TYPES)('%s: the catalog defines its noun in every locale, and the door renders it in the request\'s', async (type, name, opts, services) => { + for (const locale of Object.keys(BUILTIN_OPERATION_MESSAGES)) { + expect(BUILTIN_OPERATION_MESSAGES[locale][`catalog_activation_noun_${type}`], `${locale} ${type}`).toBeTruthy(); + } + for (const [locale, extra] of LANGS) { + const h = boot('single', { ...opts, omitLedger: true }, services); + const res = await flip(h, { ...TENANT_ADMIN(), ...extra } as HttpProtocolContext, `/_activation/${type}/${name}`, { enabled: false }); + expect(statusOf(res), `${locale} ${type}`).toBe(501); + expect(messageOf(res), `${locale} ${type}`).toBe(fill(locale, 'catalog_activation_ledger_missing_off', { + table: METADATA_ACTIVATION_TABLE, + noun: fill(locale, `catalog_activation_noun_${type}`), + name, + })); + expect(vary37811(res.response), `${locale} ${type}`).toBe('Accept-Language'); + expect(h.writes).toEqual([]); + } + }); +}); diff --git a/packages/runtime/src/domains/domain-501-language-37811.test.ts b/packages/runtime/src/domains/domain-501-language-37811.test.ts index 4992b7d629c..07079eb2a21 100644 --- a/packages/runtime/src/domains/domain-501-language-37811.test.ts +++ b/packages/runtime/src/domains/domain-501-language-37811.test.ts @@ -18,17 +18,26 @@ * 1. the doors that had no `501` fixture: `/auth`, `/mcp`, the `/meta` * layered read and save, `/share-links`, the `/security` reopen, and the * `/automation` run list, resume and flow clone; - * 2. a source walk over `src/domains/`: no `deps.error(…, 501)` is left - * outside the two modules that build one on purpose, so a new fixed-English - * `501` fails here and is written through the catalog instead. + * 2. a source walk over `src/domains/`: no `501` is written in code outside + * the one module that builds one on purpose, except the reasoned + * exemptions it names, so a new fixed-English `501` fails here and is + * written through the catalog instead (#37864 widened it from a literal + * `deps.error(…, 501)` to every `501` in code, strings and comments + * stripped); + * 3. [#37864] `capabilityUnavailable`, the mounted-but-unimplemented `501` + * of `/ai`, `/automation`, `/notifications` and `/ui`, in the request's + * language, its English held equal to discovery's + * `serviceUnavailableMessage(slot)` for every slot; and the `/mcp/skill` + * door's own language case. */ import { describe, it, expect, vi } from 'vitest'; // [#37811] Paid at collection: the dispatcher's reach loads `@objectstack/metadata` (check:test-source-alias). import '@objectstack/metadata'; import { readFileSync, readdirSync } from 'node:fs'; -import { BUILTIN_OPERATION_MESSAGES } from '@objectstack/spec/system'; +import { BUILTIN_OPERATION_MESSAGES, CoreServiceName, serviceUnavailableMessage } from '@objectstack/spec/system'; import { HttpDispatcher } from '../http-dispatcher.js'; +import { capabilityUnavailableMessage } from './unavailable.js'; const LANGS = [ ['en', {}], @@ -144,46 +153,217 @@ describe('#37811 · 1 · the doors with no 501 fixture of their own', () => { }); }); -/** Every `deps.error(` call in `source` whose status argument is the literal `501`. */ -function literal501Calls(source: string): string[] { +/** + * `source` with every comment and string literal blanked out (each character + * replaced by a space, newlines kept), so what is left is code: a `501` in a + * message or a comment is not a status, and a parenthesis inside a string + * cannot unbalance anything. Template literals are blanked too, their `${…}` + * holes kept as code. + * + * Two limits, by design: regex literals are not lexed (a quote, `//` or + * backtick inside one would blank code after it; no domain module has such a + * regex today, and the exactly-one-site exemption tests would trip if one + * hid a site), and only `src/domains/` is walked, so a `501` reached through + * a helper outside it is not seen. + */ +function codeOnly(source: string): string { + const out = source.split(''); + const blank = (from: number, to: number): void => { + for (let k = from; k < to; k++) if (out[k] !== '\n') out[k] = ' '; + }; + // A stack of open template literals: each entry is the brace depth of the + // `${` hole the scan is in (0 = in the template's text). + const templates: number[] = []; + let i = 0; + while (i < source.length) { + const c = source[i]; + const next = source[i + 1]; + const inTemplateText = templates.length > 0 && templates[templates.length - 1] === 0; + if (inTemplateText) { + if (c === '\\') { blank(i, i + 2); i += 2; continue; } + if (c === '`') { templates.pop(); blank(i, i + 1); i++; continue; } + if (c === '$' && next === '{') { templates[templates.length - 1] = 1; i += 2; continue; } + blank(i, i + 1); i++; continue; + } + if (c === '/' && next === '/') { + const end = source.indexOf('\n', i); + const stop = end < 0 ? source.length : end; + blank(i, stop); i = stop; continue; + } + if (c === '/' && next === '*') { + const end = source.indexOf('*/', i + 2); + const stop = end < 0 ? source.length : end + 2; + blank(i, stop); i = stop; continue; + } + if (c === '\'' || c === '"') { + let j = i + 1; + while (j < source.length && source[j] !== c && source[j] !== '\n') j += source[j] === '\\' ? 2 : 1; + blank(i, j + 1); i = j + 1; continue; + } + if (c === '`') { templates.push(0); blank(i, i + 1); i++; continue; } + if (templates.length > 0) { + if (c === '{') templates[templates.length - 1]++; + else if (c === '}' && --templates[templates.length - 1] === 0) { i++; continue; } + } + i++; + } + return out.join(''); +} + +/** Every `501` written in code in `source`, each with the last 160 characters of code up to it (whitespace collapsed). */ +function code501Sites(source: string): string[] { + const code = codeOnly(source); const out: string[] = []; - let from = 0; - for (;;) { - const at = source.indexOf('deps.error(', from); - if (at < 0) return out; - let depth = 0; - let end = at + 'deps.error'.length; - for (; end < source.length; end++) { - const c = source[end]; - if (c === '(') depth++; - else if (c === ')' && --depth === 0) break; - } - const call = source.slice(at, end + 1); - if (/,\s*501\s*[,)]/.test(call)) out.push(call.replace(/\s+/g, ' ').slice(0, 160)); - from = end + 1; + for (const m of code.matchAll(/(? { - // The two modules that build a 501 from `deps.error` on purpose: - // - `own-door-bridge.ts` is `localizedNotImplemented`, the builder every - // localized 501 goes through; - // - `unavailable.ts` is `capabilityUnavailable`, whose sentence is the - // discovery remedy (`serviceUnavailableMessage`, `services..message`) - // by contract, byte for byte: it stays English while discovery is English. - // The MCP resume door's `501` (`mcp.ts`, `resumeDoorError`) is not a - // `deps.error` call either: it is thrown into the resume tool's error - // mapping, read by the calling agent beside the door's other English - // refusals, and it stays English. - const BUILDERS = new Set(['own-door-bridge.ts', 'unavailable.ts']); + // The one module that builds a 501 from `deps.error` on purpose: + // `own-door-bridge.ts` is `localizedNotImplemented`, the builder every + // localized 501 goes through. [#37864] `unavailable.ts` is no longer one: + // `capabilityUnavailable` answers through `catalogNotImplemented` too. + const BUILDERS = new Set(['own-door-bridge.ts']); + // [#37864] The `501`s in code that are not a fixed English sentence of a + // domain's own, each matched by the code just before it and each with its + // reason. A site that matches none of these fails; an exemption that + // matches nothing fails too, so the list cannot outlive its sites. + const EXEMPT: ReadonlyArray<{ file: string; before: RegExp; reason: string }> = [ + { + file: 'meta.ts', + before: /deps\.errorFromThrown\(e, 501$/, + reason: 'the metadata service threw: the message is that error\'s own, 501 only its fallback status', + }, + { + file: 'mcp.ts', + before: /throw resumeDoorError\( deps,[ +,]*501$/, + reason: 'thrown into the resume tool\'s error mapping and read by the calling agent beside the door\'s other English refusals: it stays English', + }, + { + file: 'permission-set-clone.ts', + before: /\{ statusCode: 501$/, + reason: 'a catalog messageKey (PAIR_UNSUPPORTED_KEY), rendered in the request\'s language where it is answered', + }, + { + file: 'permission-set-clone.ts', + before: /thrown\?\.statusCode === 501$/, + reason: 'reads that same throw back, it answers nothing', + }, + ]; const dir = new URL('./', import.meta.url); const modules = readdirSync(dir).filter((f) => f.endsWith('.ts') && !f.endsWith('.test.ts') && !BUILDERS.has(f)); + const sitesOf = (file: string): string[] => code501Sites(readFileSync(new URL(file, dir), 'utf8')); it('walks the domain modules (a guard against an empty walk)', () => { - expect(modules).toEqual(expect.arrayContaining(['auth.ts', 'meta.ts', 'packages.ts', 'automation.ts', 'security.ts'])); + expect(modules).toEqual(expect.arrayContaining(['auth.ts', 'meta.ts', 'packages.ts', 'automation.ts', 'security.ts', 'unavailable.ts'])); + }); + + it('sees a 501 through any call, and none inside a string or a comment (the walker itself)', () => { + expect(code501Sites('return deps.error(\'a (b\', 501);')).toHaveLength(1); + expect(code501Sites('return deps.errorFromThrown(e, 501);')).toHaveLength(1); + expect(code501Sites('return respond501(ctx, 501);')).toHaveLength(1); + expect(code501Sites('const s = `${x ? 501 : 0}`;')).toHaveLength(1); + expect(code501Sites('const s = \'501 Not Implemented\'; // 501\n/* 501 */ const t = "(501"; const u = `501 ${y}`;')).toEqual([]); + expect(code501Sites('const v = 5010; const w = x.501;')).toEqual([]); }); - it.each(modules)('%s answers no deps.error(…, 501): its 501s go through catalogNotImplemented', (file) => { - expect(literal501Calls(readFileSync(new URL(file, dir), 'utf8'))).toEqual([]); + it.each(modules)('%s writes no 501 in code but the exempted ones: its 501s go through catalogNotImplemented', (file) => { + const unexplained = sitesOf(file).filter((site) => !EXEMPT.some((e) => e.file === file && e.before.test(site))); + expect(unexplained).toEqual([]); + }); + + it.each(EXEMPT.map((e) => [e.file, e.before.source, e] as const))('the exemption in %s (%s) still names exactly one site', (_file, _src, e) => { + expect(sitesOf(e.file).filter((site) => e.before.test(site))).toHaveLength(1); + }); +}); + +/** The catalog sentence for `key` in `locale`, its `{{params}}` filled. */ +const rendered = (locale: string, key: string, params: Record = {}): string => + BUILTIN_OPERATION_MESSAGES[locale][key].replace(/\{\{(\w+)\}\}/g, (_m, name: string) => params[name] ?? ''); + +describe('#37864 · 3 · capabilityUnavailable follows the request\'s language; its English stays discovery\'s', () => { + const CAPABILITY_KEYS = Object.keys(BUILTIN_OPERATION_MESSAGES.en).filter((key) => key.startsWith('capability_unavailable_')); + const placeholders = (template: string): string[] => [...template.matchAll(/\{\{(\w+)\}\}/g)].map((m) => m[1]).sort(); + + it('the English of every CoreServiceName slot is serviceUnavailableMessage(slot), byte for byte', () => { + // The drift half: discovery stays English (`services..message`), + // the 501 renders the catalog, and the two must name the same remedy. + // A slot given a sentence of its own in `core-services.zod.ts` fails + // here until `unavailable.ts` maps it to a key. + expect(CoreServiceName.options.length).toBeGreaterThan(10); + for (const slot of [...CoreServiceName.options, 'not-a-real-slot']) { + expect(capabilityUnavailableMessage(slot), slot).toBe(serviceUnavailableMessage(slot)); + expect(capabilityUnavailableMessage(slot, 'en-US'), slot).toBe(serviceUnavailableMessage(slot)); + } + }); + + it('names the five keys, each translated in every locale with the English placeholders kept', () => { + expect(CAPABILITY_KEYS.sort()).toEqual([ + 'capability_unavailable_ai', + 'capability_unavailable_install', + 'capability_unavailable_search', + 'capability_unavailable_ui', + 'capability_unavailable_unshipped', + ]); + for (const key of CAPABILITY_KEYS) { + const en = BUILTIN_OPERATION_MESSAGES.en[key]; + for (const locale of ['zh-CN', 'ja-JP', 'es-ES']) { + const text = BUILTIN_OPERATION_MESSAGES[locale][key]; + expect(text, `${locale} ${key}`).toBeTruthy(); + expect(text, `${locale} ${key}`).not.toBe(en); + expect(placeholders(text), `${locale} ${key}`).toEqual(placeholders(en)); + } + } + }); + + it('every slot renders a non-English sentence in each catalog locale, its package and slot names untranslated', () => { + for (const slot of CoreServiceName.options) { + for (const locale of ['zh-CN', 'ja-JP', 'es-ES']) { + const text = capabilityUnavailableMessage(slot, locale); + expect(text, `${locale} ${slot}`).not.toBe(serviceUnavailableMessage(slot)); + expect(text, `${locale} ${slot}`).not.toMatch(/\{\{/); + } + } + expect(capabilityUnavailableMessage('notification', 'zh-CN')).toContain('@objectstack/service-messaging'); + expect(capabilityUnavailableMessage('not-a-real-slot', 'ja-JP')).toContain('not-a-real-slot'); + }); + + const LANGS3 = [ + ['en', {}], + ['ja-JP', { 'accept-language': 'ja-JP,ja;q=0.9' }], + ['zh-CN', { 'accept-language': 'zh-CN' }], + ] as const; + // Each door with nothing behind it, as the dispatcher reaches it. + const DOORS: ReadonlyArray Promise<{ response?: any }>]> = [ + ['/ai', 'ai', (d, ctx) => d.handleAI('/ai/models', 'GET', undefined, {}, ctx)], + ['/automation', 'automation', (d, ctx) => d.handleAutomation('', 'GET', undefined, ctx, {})], + ['/notifications', 'notification', (d, ctx) => d.handleNotification('', 'GET', undefined, {}, ctx)], + ['/ui', 'ui', (d, ctx) => d.handleUi('/view/account', {}, ctx)], + ]; + + it.each(DOORS)('%s with no %s service: 501, NOT_IMPLEMENTED, the slot\'s sentence in the request\'s language, Vary', async (_door, slot, call) => { + for (const [locale, headers] of LANGS3) { + const result = await call(dispatcherWith({}), ADMIN(headers)); + expect(result.response?.status, locale).toBe(501); + expect(result.response?.body?.error?.code, locale).toBe('NOT_IMPLEMENTED'); + expect(result.response?.body?.error?.message, locale).toBe(capabilityUnavailableMessage(slot, locale)); + expect(result.response?.headers?.Vary, locale).toBe('Accept-Language'); + } + // No header: the English discovery reports, byte for byte. + const plain = await call(dispatcherWith({}), ADMIN({})); + expect(plain.response?.body?.error?.message).toBe(serviceUnavailableMessage(slot)); + }); + + it('/mcp/skill with no MCP server registered: mcp_server_unavailable in the request\'s language (N2)', async () => { + for (const [locale, headers] of LANGS3) { + const result = await dispatcherWith({}).handleMcpSkill('GET', ADMIN(headers)); + expect(result.response?.status, locale).toBe(501); + expect(result.response?.body?.error?.code, locale).toBe('NOT_IMPLEMENTED'); + expect(result.response?.body?.error?.message, locale).toBe(rendered(locale, 'mcp_server_unavailable')); + expect(result.response?.headers?.Vary, locale).toBe('Accept-Language'); + } }); }); diff --git a/packages/runtime/src/domains/notifications.ts b/packages/runtime/src/domains/notifications.ts index 217064cda08..e9090d97260 100644 --- a/packages/runtime/src/domains/notifications.ts +++ b/packages/runtime/src/domains/notifications.ts @@ -186,7 +186,7 @@ export async function handleNotificationRequest( // discovery endpoint") pointed at a page that correctly does not list the // route. See ./unavailable.ts. The slot key is `notification`, singular. if (!service || !isServiceServeable(service)) { - return capabilityUnavailable(deps, 'notification'); + return capabilityUnavailable(deps, context, 'notification'); } const m = method.toUpperCase(); @@ -208,7 +208,7 @@ export async function handleNotificationRequest( if (segments[0] === 'devices') { // POST /notifications/devices — register or refresh this user's device. if (segments.length === 1 && m === 'POST') { - if (typeof service.registerDevice !== 'function') return capabilityUnavailable(deps, 'notification'); + if (typeof service.registerDevice !== 'function') return capabilityUnavailable(deps, context, 'notification'); // Validated against the declared contract (`RegisterDeviceRequestSchema`, // the catalog row's `requestSchema`), as mark-read is (#3899). const parsed = RegisterDeviceRequestSchema.safeParse(body ?? {}); @@ -227,7 +227,7 @@ export async function handleNotificationRequest( // the service's `NOT_FOUND` throw, which the dispatcher answers 404: // never a distinct "forbidden", so the id's existence is not disclosed. if (segments.length === 2 && m === 'DELETE') { - if (typeof service.unregisterDevice !== 'function') return capabilityUnavailable(deps, 'notification'); + if (typeof service.unregisterDevice !== 'function') return capabilityUnavailable(deps, context, 'notification'); const result = await service.unregisterDevice(userId, decodeDeviceSegment(segments[1])); return { handled: true, response: deps.success(result) }; } @@ -235,7 +235,7 @@ export async function handleNotificationRequest( } if (typeof service.listInbox !== 'function') { - return capabilityUnavailable(deps, 'notification'); + return capabilityUnavailable(deps, context, 'notification'); } // Narrowed for the routes below: the entry probe established `listInbox`. const inbox = service as INotificationService & Required>; @@ -264,7 +264,7 @@ export async function handleNotificationRequest( // POST /notifications/read — mark specific notifications read. if (subPath === 'read' && m === 'POST') { - if (typeof inbox.markRead !== 'function') return capabilityUnavailable(deps, 'notification'); + if (typeof inbox.markRead !== 'function') return capabilityUnavailable(deps, context, 'notification'); // [#3899] Validate against the declared contract // (`MarkNotificationsReadRequestSchema`, catalog `requestSchema`). // The old read was `Array.isArray(body?.ids) ? … : []`, so @@ -287,7 +287,7 @@ export async function handleNotificationRequest( // POST /notifications/read/all — mark all of the user's inbox read. if (subPath === 'read/all' && m === 'POST') { - if (typeof inbox.markAllRead !== 'function') return capabilityUnavailable(deps, 'notification'); + if (typeof inbox.markAllRead !== 'function') return capabilityUnavailable(deps, context, 'notification'); const result = await inbox.markAllRead(userId); return { handled: true, response: deps.success(result) }; } diff --git a/packages/runtime/src/domains/own-door-bridge.ts b/packages/runtime/src/domains/own-door-bridge.ts index e2486ea4c41..4f0d6b19a31 100644 --- a/packages/runtime/src/domains/own-door-bridge.ts +++ b/packages/runtime/src/domains/own-door-bridge.ts @@ -307,7 +307,12 @@ function notImplementedSentence( * the comment doors (`comments.ts`) and the webhook redelivery door * (`webhooks.ts`, both #37610), the approval action-page door (`approvals.ts`) * and the inbound automation hooks (`automation-hooks.ts`, both #37662), and - * the other domain modules' `501`s (#37811). + * the other domain modules' `501`s (#37811), `capabilityUnavailable` + * (`unavailable.ts`, #37864) among them. Two callers read it directly: the + * activation door (`catalog-activation.ts`), for the noun its `501` names in + * the same language, and `capabilityUnavailableMessageFor` + * (`unavailable.ts`), for the custom-endpoint flow target's `501`, which + * builds its own envelope. */ export function requestLocaleOf(context: HttpProtocolContext): string | undefined { const headers = (context.request as { headers?: unknown } | undefined)?.headers as diff --git a/packages/runtime/src/domains/ui.ts b/packages/runtime/src/domains/ui.ts index 5eb283169ae..bbe463a626f 100644 --- a/packages/runtime/src/domains/ui.ts +++ b/packages/runtime/src/domains/ui.ts @@ -157,7 +157,7 @@ export async function handleUiRequest( // is temporary, but an uninstalled MetadataPlugin does not become // installed by retrying. The message now names that remedy, and is // the same sentence discovery reports for the slot (#4146). - return capabilityUnavailable(deps, 'ui'); + return capabilityUnavailable(deps, _context, 'ui'); } } diff --git a/packages/runtime/src/domains/unavailable.ts b/packages/runtime/src/domains/unavailable.ts index c40c2149a67..0f4aa7de375 100644 --- a/packages/runtime/src/domains/unavailable.ts +++ b/packages/runtime/src/domains/unavailable.ts @@ -1,8 +1,10 @@ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. -import { serviceUnavailableMessage } from '@objectstack/spec/system'; -import type { HttpDispatcherResult } from '../http-dispatcher.js'; +import { CORE_SERVICE_PROVIDER } from '@objectstack/spec/system'; +import { operationUserMessage } from '@objectstack/core'; +import type { HttpProtocolContext, HttpDispatcherResult } from '../http-dispatcher.js'; import type { DomainHandlerDeps } from '../domain-handler-registry.js'; +import { catalogNotImplemented, requestLocaleOf } from './own-door-bridge.js'; /** * The one answer a dispatcher domain gives when its route is mounted but @@ -39,24 +41,88 @@ import type { DomainHandlerDeps } from '../domain-handler-registry.js'; * `/ui` said **503**, which claims the condition is temporary. An uninstalled * MetadataPlugin does not become installed by retrying. * - * ## Why the message comes from `spec` + * ## Why the English comes from `spec`, and the other languages do not * - * `serviceUnavailableMessage` is the same sentence `services..message` - * carries in discovery (#4093 follow-up), so the 501 body and the discovery - * entry cannot drift into naming different remedies — and a caller who hits - * the wall gets the fix without a second round trip. + * `serviceUnavailableMessage` is the sentence `services..message` + * carries in discovery (#4093 follow-up), and the 501's English is that + * sentence byte for byte, so the 501 body and the discovery entry cannot + * drift into naming different remedies, and a caller who hits the wall gets + * the fix without a second round trip. + * + * [#37864] The 501 answers in the request's top `Accept-Language` tag, with + * the `Vary: Accept-Language` such a body owes (`catalogNotImplemented`), as + * the other catalog 501s do. Discovery does not follow it: it is a + * machine-read surface (SDKs, codegen, AI clients), and a host-level + * `/discovery` is served with no request to read a language from. So the + * sentence lives twice: once in `serviceUnavailableMessage` for discovery, + * once as the `capability_unavailable_*` keys of the operation-message + * catalog for the 501, and `domain-501-language-37811.test.ts` holds the + * English of every `CoreServiceName` slot equal to `serviceUnavailableMessage`. + * A slot whose `serviceUnavailableMessage` has a sentence of its own needs a + * key in {@link SLOT_SENTENCE_KEY}; that pin fails until it has one. + * + * The operator's fault log stays English too. A declared capability absence + * is logged once per route per process (`logServerFault`, + * `@objectstack/types`), so a line in the caller's language would carry the + * language of whichever request reached the route first for the life of the + * process. The answer names the English as its `faultLogMessage`, which the + * dispatcher plugin's writer prints in place of the body's message. * * There is deliberately no per-call message override. One briefly existed for * `ai`, whose provider ships outside this workspace, and it hid the real bug: * the shared table said "nothing ships" for a slot that Cloud/Enterprise does * provide. Teaching the table to say the accurate thing fixed the domain AND * discovery, which the override could only ever have fixed here. A slot whose - * sentence is wrong needs the table corrected, not a local exception. + * sentence is wrong needs the table corrected, not a local exception, and + * its catalog key with it (the pin above fails until both say the same). * + * @param context the request, whose top `Accept-Language` tag picks the language. * @param slot the `CoreServiceName` key, NOT the route segment — `/notifications` * is served by the `notification` slot, and the remedy is looked up * by slot. */ -export function capabilityUnavailable(deps: DomainHandlerDeps, slot: string): HttpDispatcherResult { - return { handled: true, response: deps.error(serviceUnavailableMessage(slot), 501) }; +export function capabilityUnavailable(deps: DomainHandlerDeps, context: HttpProtocolContext, slot: string): HttpDispatcherResult { + const { key, params } = capabilityUnavailableSentence(slot); + const answer = catalogNotImplemented(deps, context, key, params); + // The operator's fault log keeps the English (`faultLogMessage`): its one + // line per route per process is not the first caller's language. + return answer.response + ? { ...answer, response: { ...answer.response, faultLogMessage: capabilityUnavailableMessage(slot) } } + : answer; +} + +/** + * The slots whose `serviceUnavailableMessage` is a sentence of its own + * (`REMEDY_DETAIL` in `core-services.zod.ts`), each with its catalog key. + * Every other slot is `Install to enable` or, when nothing ships + * for it, the generic unshipped sentence. + */ +const SLOT_SENTENCE_KEY: Readonly> = { + ui: 'capability_unavailable_ui', + ai: 'capability_unavailable_ai', + search: 'capability_unavailable_search', +}; + +function capabilityUnavailableSentence(slot: string): { key: string; params?: Record } { + const own = SLOT_SENTENCE_KEY[slot]; + if (own) return { key: own }; + const pkg = CORE_SERVICE_PROVIDER[slot]; + return pkg + ? { key: 'capability_unavailable_install', params: { package: pkg } } + : { key: 'capability_unavailable_unshipped', params: { slot } }; +} + +/** + * The same sentence as a string, for a door that builds its own `501` + * envelope (the custom-endpoint flow target, `endpoint-executor.ts`): in the + * caller's locale, English when it names none. + */ +export function capabilityUnavailableMessage(slot: string, locale?: string): string { + const { key, params } = capabilityUnavailableSentence(slot); + return operationUserMessage(key, { locale }, params); +} + +/** {@link capabilityUnavailableMessage} in the request's top `Accept-Language` tag. */ +export function capabilityUnavailableMessageFor(context: HttpProtocolContext, slot: string): string { + return capabilityUnavailableMessage(slot, requestLocaleOf(context)); } diff --git a/packages/runtime/src/endpoint-executor.test.ts b/packages/runtime/src/endpoint-executor.test.ts index ff1d43a6a6a..55601035c13 100644 --- a/packages/runtime/src/endpoint-executor.test.ts +++ b/packages/runtime/src/endpoint-executor.test.ts @@ -16,11 +16,13 @@ */ import { describe, it, expect, vi } from 'vitest'; +// [#37864] Paid at collection: the executor's reach loads `@objectstack/metadata` (check:test-source-alias). +import '@objectstack/metadata'; import { ApiEndpointSchema, ApiErrorSchema, BaseResponseSchema, DispatcherErrorCode, envelopeViolations, SERVICE_SELF_INFO_KEY } from '@objectstack/spec/api'; import type { ApiEndpoint } from '@objectstack/spec/api'; import type { ApiEndpointMatch } from '@objectstack/spec/contracts'; import type { ExecutionContext } from '@objectstack/spec/kernel'; -import { serviceUnavailableMessage } from '@objectstack/spec/system'; +import { BUILTIN_OPERATION_MESSAGES, serviceUnavailableMessage } from '@objectstack/spec/system'; import { INTERNAL_ERROR_MESSAGE } from '@objectstack/types'; import { @@ -666,3 +668,38 @@ describe('a delegated failure maps onto the EXISTING envelope, class by class', expect(endpointErrorAnswer(new Error('nope'), 502).status).toBe(502); }); }); + +// [#37864] The flow target's 501 is `/automation`'s `capabilityUnavailable` +// sentence: in the request's top `Accept-Language` tag, with +// `Vary: Accept-Language`, and byte-identical English with no header. +describe('a flow endpoint with no automation service answers in the request\'s language', () => { + const FLOW = () => endpoint({ type: 'flow', target: 'purge_inquiries', method: 'POST', objectParams: undefined }); + const sentence = (locale: string): string => + BUILTIN_OPERATION_MESSAGES[locale].capability_unavailable_install.replace('{{package}}', '@objectstack/service-automation'); + + it('ja-JP and zh-CN read their catalog sentence; no header reads the discovery English; Vary on every one', async () => { + for (const [headers, expected] of [ + [{ 'accept-language': 'ja-JP,ja;q=0.9' }, sentence('ja-JP')], + [{ 'accept-language': 'zh-CN' }, sentence('zh-CN')], + [{}, serviceUnavailableMessage('automation')], + ] as const) { + const answer = await executeEndpointTarget(contextFor(FLOW(), { method: 'POST', headers }), depsWith({ automationService: undefined })); + expect(answer.status).toBe(501); + const error = expectConformantError(answer); + expect(error.code).toBe(DispatcherErrorCode.enum.NOT_IMPLEMENTED); + expect(error.message).toBe(expected); + expect(answer.headers).toEqual({ Vary: 'Accept-Language' }); + } + expect(sentence('en')).toBe(serviceUnavailableMessage('automation')); + }); + + it('a serveable occupant that cannot execute is the same answer', async () => { + const answer = await executeEndpointTarget( + contextFor(FLOW(), { method: 'POST', headers: { 'accept-language': 'ja-JP' } }), + depsWith({ automationService: { listFlows: async () => [] } }), + ); + expect(answer.status).toBe(501); + expect(expectConformantError(answer).message).toBe(sentence('ja-JP')); + expect(answer.headers).toEqual({ Vary: 'Accept-Language' }); + }); +}); diff --git a/packages/runtime/src/endpoint-executor.ts b/packages/runtime/src/endpoint-executor.ts index 90948840ab4..44469373eb7 100644 --- a/packages/runtime/src/endpoint-executor.ts +++ b/packages/runtime/src/endpoint-executor.ts @@ -48,9 +48,9 @@ import type { ApiEndpoint } from '@objectstack/spec/api'; import type { ApiEndpointMatch, IAutomationService } from '@objectstack/spec/contracts'; import type { AutomationContext } from '@objectstack/spec/contracts'; import type { ExecutionContext } from '@objectstack/spec/kernel'; -import { serviceUnavailableMessage } from '@objectstack/spec/system'; import { INTERNAL_ERROR_MESSAGE, looksLikeInternalErrorLeak, resolveThrownHttpError, demotedDeclaredCode } from '@objectstack/types'; import { apiErrorResponse } from './error-envelope.js'; +import { capabilityUnavailableMessageFor } from './domains/unavailable.js'; import { isServiceServeable } from './service-serveable.js'; import { validationFailure } from './validation-failure.js'; import { buildAutomationContext, flowStartRecordKeys } from './domains/automation.js'; @@ -466,6 +466,23 @@ async function executeObjectOperation( return successAnswer(await call('delete', { object, id })); } +/** + * The flow target's `501` when no automation service can run it: the sentence + * `/automation` answers (`capabilityUnavailable`), in the request's top + * `Accept-Language` tag, with the `Vary: Accept-Language` a localized body + * owes (a `501` is cacheable by default). + */ +function automationUnavailableAnswer(ctx: EndpointExecutionContext): EndpointExecutionAnswer { + return { + ...apiErrorResponse({ + code: DispatcherErrorCode.enum.NOT_IMPLEMENTED, + httpStatus: 501, + message: capabilityUnavailableMessageFor(ctx.protocolContext, 'automation'), + }), + headers: { Vary: 'Accept-Language' }, + }; +} + /** * `flow` → `IAutomationService.execute`, with the context the trigger route * builds. @@ -527,15 +544,12 @@ async function executeFlow( // Empty slot, or a slot filled by a self-declared non-handler — the same // amount of automation capability, and the same answer `/automation` gives: // 501 carrying the remedy sentence discovery reports for the slot - // (`domains/unavailable.ts`, `serviceUnavailableMessage`). NOT a 404: the + // (`domains/unavailable.ts`), in the request's language with the + // `Vary: Accept-Language` that owes (#37864). NOT a 404: the // endpoint IS declared and IS matched; what is missing is the implementation // behind it. if (!isServiceServeable(slot)) { - return apiErrorResponse({ - code: DispatcherErrorCode.enum.NOT_IMPLEMENTED, - httpStatus: 501, - message: serviceUnavailableMessage('automation'), - }); + return automationUnavailableAnswer(ctx); } // [ADR-0150 D3, #31696] The `target` is a reference the endpoint's own @@ -552,11 +566,7 @@ async function executeFlow( // A serveable occupant that cannot execute is the same wall from the // caller's side, and saying so is more use than letting a TypeError // become an opaque 500. - return apiErrorResponse({ - code: DispatcherErrorCode.enum.NOT_IMPLEMENTED, - httpStatus: 501, - message: serviceUnavailableMessage('automation'), - }); + return automationUnavailableAnswer(ctx); } // [#9462] Row 1 of the table, answered by the SAME optional `getFlow` diff --git a/packages/runtime/src/http-dispatcher.ts b/packages/runtime/src/http-dispatcher.ts index 3672eca887c..2a8676d8d84 100644 --- a/packages/runtime/src/http-dispatcher.ts +++ b/packages/runtime/src/http-dispatcher.ts @@ -171,6 +171,15 @@ export interface HttpDispatcherResult { * (#27506: the api-action forward relays a target's cookie rotation). */ headers?: Record; + /** + * [#37864] The sentence the operator's fault log prints for this + * answer when it is not the body's `error.message`. Never written to + * the wire. A `501` whose body is in the caller's language sets it to + * the English, so the one line a declared capability absence earns per + * route per process (`logServerFault`, `@objectstack/types`) does not + * take the language of whichever request reached the route first. + */ + faultLogMessage?: string; }; result?: any; // For flexible return types or direct response objects (Response/NextResponse) } diff --git a/packages/spec/src/system/operation-message.ts b/packages/spec/src/system/operation-message.ts index 2acc5b32062..7dac498e598 100644 --- a/packages/spec/src/system/operation-message.ts +++ b/packages/spec/src/system/operation-message.ts @@ -398,6 +398,22 @@ export function operationMessageTranslationKey(messageKey: string): string { * `{{member}}`, `{{table}}`, `{{name}}` and `{{packageId}}` are code, table, * item and package names, never translated; `{{noun}}` is one of the * `catalog_activation_noun_*` keys, rendered in the same locale. + * + * The `capability_unavailable_*` keys are the `501` a dispatcher domain + * answers when its route is mounted and nothing implements the capability + * behind it (`capabilityUnavailable`, `domains/unavailable.ts` and the + * custom-endpoint flow target, `@objectstack/runtime`, #37864), read the same + * way. Their English is byte-identical to `serviceUnavailableMessage(slot)` + * (`core-services.zod.ts`), the sentence discovery reports for the slot under + * `services..message`: discovery is a machine-read surface and stays + * English, so only the `501` follows the request's language, and a pin holds + * the two English sentences equal for every slot. `_ui`, `_ai` and `_search` + * carry the slots with a sentence of their own; every other slot reads + * `_install` (`{{package}}`, the slot's provider package) or `_unshipped` + * (`{{slot}}`); package, slot, plugin and route names are never translated. + * The operator's fault log does not follow the request: the line a declared + * capability absence earns once per route per process prints the English + * (the answer's `faultLogMessage`), never the first caller's language. */ export const BUILTIN_OPERATION_MESSAGES: Record> = { en: { @@ -544,6 +560,14 @@ export const BUILTIN_OPERATION_MESSAGES: Record> security_audience_reopen_unsupported: "This deployment's security service does not implement re-opening a dismissed audience-binding suggestion, so the dismissal stands.", share_links_unconfigured: 'Sharing is not configured', + capability_unavailable_install: 'Install {{package}} to enable', + capability_unavailable_unshipped: "No implementation ships for the '{{slot}}' slot — register a service under it to enable", + capability_unavailable_ui: + 'Served by the protocol service — register MetadataPlugin (@objectstack/metadata-protocol) to enable', + capability_unavailable_ai: + 'Provided by @objectstack/service-ai in ObjectOS Cloud/Enterprise — no implementation ships in the open framework', + capability_unavailable_search: + "No implementation ships for the 'search' slot — a dedicated search engine (Elasticsearch/Meilisearch); register a service under it to enable. Cross-object search does not depend on it: GET {basePath}/search is served by the protocol itself, and whether it is served on this host is reported by capabilities.search — not by this slot.", }, 'zh-CN': { permission_denied: '您没有执行此操作的权限,如需访问请联系管理员。', @@ -626,12 +650,12 @@ export const BUILTIN_OPERATION_MESSAGES: Record> packages_commit_rollback_unsupported: '不支持回滚到某次提交。', packages_orphan_adoption_unsupported: '不支持认领孤立的元数据。', packages_duplication_unsupported: '不支持复制软件包。', - packages_customization_ensure_unsupported: '不支持确保定制软件包存在。', + packages_customization_ensure_unsupported: '不支持确保定制包存在。', automation_connector_credentials_unsupported: '此部署挂载的自动化服务不支持连接器凭据:它未实现 `IAutomationService` 的可选成员 `{{member}}`。未读取或更改任何内容。', automation_connector_connections_unsupported: '此部署挂载的自动化服务不支持连接器连接:它未实现 `IAutomationService` 的可选成员 `{{member}}`。未读取或更改任何内容。', - automation_flow_clone_unsupported: '不支持复制流程:副本要存入一个软件包,而此部署没有能够确保定制软件包存在并将流程保存进去的元数据协议。', + automation_flow_clone_unsupported: '不支持复制流程:副本要存入一个软件包,而此部署没有能够确保定制包存在并将流程保存进去的元数据协议。', automation_resume_unsupported: '不支持恢复运行。', automation_run_cancel_unsupported: '此部署挂载的自动化服务不支持取消运行:它未实现 `IAutomationService` 的可选成员 `cancelRun`。没有取消任何运行。', automation_run_restore_unsupported: @@ -648,10 +672,16 @@ export const BUILTIN_OPERATION_MESSAGES: Record> catalog_activation_noun_queue: '声明的队列', catalog_activation_noun_assignment_rule: '声明的分配规则', permission_set_clone_pair_unsupported: - "权限集 '{{name}}' 由只读软件包 '{{packageId}}' 提供,因此它的副本应存入该软件包配对的定制软件包,而此部署的元数据协议无法确保该定制软件包存在。", + "权限集 '{{name}}' 由只读软件包 '{{packageId}}' 提供,因此它的副本应存入该软件包配对的定制包,而此部署的元数据协议无法确保该定制包存在。", permission_set_clone_no_protocol: '此部署没有可用于保存副本的元数据协议,因此无法在这里复制权限集。', security_audience_reopen_unsupported: '此部署的安全服务未实现重新打开已忽略的受众绑定建议,因此该忽略保持有效。', share_links_unconfigured: '未配置共享。', + capability_unavailable_install: '安装 {{package}} 即可启用。', + capability_unavailable_unshipped: "'{{slot}}' 槽位没有随附的实现:在该槽位下注册一个服务即可启用。", + capability_unavailable_ui: '由协议服务提供:注册 MetadataPlugin(@objectstack/metadata-protocol)即可启用。', + capability_unavailable_ai: '由 ObjectOS Cloud/Enterprise 中的 @objectstack/service-ai 提供,开源框架没有随附的实现。', + capability_unavailable_search: + "'search' 槽位没有随附的实现:它对应专用搜索引擎(Elasticsearch/Meilisearch),在该槽位下注册一个服务即可启用。跨对象搜索不依赖它:GET {basePath}/search 由协议本身提供,本主机是否提供它由 capabilities.search 报告,而不是由这个槽位报告。", }, 'ja-JP': { permission_denied: 'この操作を実行する権限がありません。アクセスが必要な場合は管理者にお問い合わせください。', @@ -790,6 +820,15 @@ export const BUILTIN_OPERATION_MESSAGES: Record> permission_set_clone_no_protocol: 'このデプロイメントにはコピーを保存するためのメタデータプロトコルがないため、ここでは権限セットを複製できません。', security_audience_reopen_unsupported: 'このデプロイメントのセキュリティサービスは却下された対象者バインドの提案を再度開く機能を実装していないため、却下はそのまま有効です。', share_links_unconfigured: '共有が構成されていません。', + capability_unavailable_install: '有効にするには {{package}} をインストールしてください。', + capability_unavailable_unshipped: + "'{{slot}}' スロットには同梱の実装がありません。有効にするには、このスロットにサービスを登録してください。", + capability_unavailable_ui: + 'プロトコルサービスが提供します。有効にするには MetadataPlugin(@objectstack/metadata-protocol)を登録してください。', + capability_unavailable_ai: + 'ObjectOS Cloud/Enterprise の @objectstack/service-ai が提供します。オープンフレームワークには実装が同梱されていません。', + capability_unavailable_search: + "'search' スロットには同梱の実装がありません。これは専用の検索エンジン(Elasticsearch/Meilisearch)用のスロットで、有効にするにはこのスロットにサービスを登録してください。オブジェクト横断検索はこれに依存しません。GET {basePath}/search はプロトコル自体が提供し、このホストで提供されているかどうかはこのスロットではなく capabilities.search が報告します。", }, 'es-ES': { permission_denied: @@ -937,6 +976,15 @@ export const BUILTIN_OPERATION_MESSAGES: Record> security_audience_reopen_unsupported: 'El servicio de seguridad de esta implementación no implementa reabrir una sugerencia de vinculación de audiencia descartada, por lo que el descarte se mantiene.', share_links_unconfigured: 'El uso compartido no está configurado.', + capability_unavailable_install: 'Instale {{package}} para habilitarlo.', + capability_unavailable_unshipped: + "No se incluye ninguna implementación para la ranura '{{slot}}': registre un servicio en ella para habilitarla.", + capability_unavailable_ui: + 'Lo proporciona el servicio de protocolo: registre MetadataPlugin (@objectstack/metadata-protocol) para habilitarlo.', + capability_unavailable_ai: + 'Lo proporciona @objectstack/service-ai en ObjectOS Cloud/Enterprise; el framework abierto no incluye ninguna implementación.', + capability_unavailable_search: + "No se incluye ninguna implementación para la ranura 'search': corresponde a un motor de búsqueda dedicado (Elasticsearch/Meilisearch); registre un servicio en ella para habilitarla. La búsqueda entre objetos no depende de ella: GET {basePath}/search lo sirve el propio protocolo, y si se sirve en este host lo indica capabilities.search, no esta ranura.", }, }; diff --git a/packages/types/src/server-fault-log.ts b/packages/types/src/server-fault-log.ts index bc383a4fd5a..b8c2d7c1f74 100644 --- a/packages/types/src/server-fault-log.ts +++ b/packages/types/src/server-fault-log.ts @@ -153,10 +153,14 @@ export function isServerFault(status: number): boolean { * Two members, and the ruling names both: the `NOT_IMPLEMENTED` / * `SERVICE_UNAVAILABLE` family a platform chooses when an optional service is * absent. `packages/runtime`'s `capabilityUnavailable` is the producer that - * motivated the card — its `501` carries `serviceUnavailableMessage(slot)`, + * motivated the card — its `501` names `serviceUnavailableMessage(slot)`, * the same remedy sentence discovery publishes for that slot, which is what * makes "naming the missing service" a property of the existing message rather - * than a second string composed here. + * than a second string composed here. [#37864] The wire body renders that + * sentence in the caller's language; the line printed here stays the English, + * which the answer hands the dispatcher plugin's writer as its + * `faultLogMessage`, so the one line per route per process is not in the + * language of whichever request came first. * * ⛔ Deliberately NOT derived from `HttpStatusErrorCodeMap` (`@objectstack/spec`), * whose 501/503 rows happen to hold these two spellings today. That map answers