bazis 0.105.2 → 0.105.3
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/core/app/runApp.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
} from "../../library/ui";
|
|
22
22
|
import { modelValidatorAdapter } from "../../library/validation";
|
|
23
23
|
import { createLocalize, type AppLanguage, type AppMessages } from "./messages";
|
|
24
|
+
import { useCodexLanguage } from "../infra/connectors/codex/contracts";
|
|
24
25
|
import {
|
|
25
26
|
type RunAppUiOptions,
|
|
26
27
|
type RunAppUiSurfaceOptions,
|
|
@@ -290,6 +291,7 @@ export async function runApp(root: BazisModuleRef, options: RunAppOptions = {}):
|
|
|
290
291
|
export function composeApp(root: BazisModuleRef, options: RunAppOptions = {}): BazisModuleRef {
|
|
291
292
|
// Checked even without HTTP: an unknown language is a startup error.
|
|
292
293
|
const localize = createLocalize(options.language, options.messages);
|
|
294
|
+
useCodexLanguage(options.language ?? "en");
|
|
293
295
|
// Infrastructure and cache are global modules; add them to the graph next to the feature root.
|
|
294
296
|
const globals: BazisModuleRef[] = [];
|
|
295
297
|
if (options.infra !== undefined) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ServiceValidationError } from "../errors";
|
|
2
2
|
import { missingNamedDependencyIssue } from "../errors/NamedDependencyNotFoundError";
|
|
3
|
-
import { isLazyDependency, isNamedDependency, isOptionalDependency } from "../provider";
|
|
3
|
+
import { isClassProvider, isLazyDependency, isNamedDependency, isOptionalDependency } from "../provider";
|
|
4
4
|
import type {
|
|
5
5
|
KeyedDependency,
|
|
6
6
|
NamedDependency,
|
|
@@ -99,7 +99,7 @@ export class GraphValidator {
|
|
|
99
99
|
const inner = isLazy || isOptional ? dependency.inner : dependency;
|
|
100
100
|
// An optional dependency on a name nothing registered is simply absent.
|
|
101
101
|
if (isNamedDependency(inner) && !this.context.hasName(inner.name)) {
|
|
102
|
-
if (!isOptional) issues.add(missingNamedDependencyIssue(inner.name,
|
|
102
|
+
if (!isOptional) issues.add(missingNamedDependencyIssue(inner.name, serviceName(registration)));
|
|
103
103
|
continue;
|
|
104
104
|
}
|
|
105
105
|
const descriptor = this.context.describeDependency(inner);
|
|
@@ -109,15 +109,15 @@ export class GraphValidator {
|
|
|
109
109
|
}
|
|
110
110
|
if (!depRegistration) {
|
|
111
111
|
issues.add(
|
|
112
|
-
`Missing dependency "${tokenToDebugName(descriptor.token)}" for "${
|
|
112
|
+
`Missing dependency "${tokenToDebugName(descriptor.token)}" for "${serviceName(registration)}"`,
|
|
113
113
|
);
|
|
114
114
|
continue;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
if (this.context.validateScopes && rootLifetime === "singleton" && depRegistration.lifetime === "scoped") {
|
|
118
118
|
issues.add(
|
|
119
|
-
`Singleton "${
|
|
120
|
-
+ `A scoped service lives for one request or scope: make "${tokenToDebugName(registration.token)}" scoped too, `
|
|
119
|
+
`Singleton "${serviceName(registration)}" depends on scoped "${tokenToDebugName(descriptor.token)}". `
|
|
120
|
+
+ `A scoped service lives for one request or scope: make "${className(registration) ?? tokenToDebugName(registration.token)}" scoped too, `
|
|
121
121
|
+ `or inject ServiceProvider and resolve "${tokenToDebugName(descriptor.token)}" in a scope you create (provider.createScope()).`,
|
|
122
122
|
);
|
|
123
123
|
}
|
|
@@ -136,3 +136,17 @@ export class GraphValidator {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
/** The class behind a token registration, when it is not the token itself: `singleton(LIFECYCLE_HOOK, WarmUp)`. */
|
|
141
|
+
function className(registration: ServiceRegistration): string | undefined {
|
|
142
|
+
if (!isClassProvider(registration.provider)) return undefined;
|
|
143
|
+
const name = registration.provider.useClass.name;
|
|
144
|
+
return name && name !== tokenToDebugName(registration.token) ? name : undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** `WarmUp (as BazisLifecycleHook)` for a class under a token, else the token. */
|
|
148
|
+
function serviceName(registration: ServiceRegistration): string {
|
|
149
|
+
const token = tokenToDebugName(registration.token);
|
|
150
|
+
const name = className(registration);
|
|
151
|
+
return name ? `${name} (as ${token})` : token;
|
|
152
|
+
}
|
|
@@ -232,7 +232,7 @@ export class CodexAppServerClient implements CodexClient {
|
|
|
232
232
|
if (method === "account/updated") this.modelCache = undefined;
|
|
233
233
|
}, () => { this.clearLogin(); this.modelCache = undefined; });
|
|
234
234
|
const initialized = await client.request("initialize", {
|
|
235
|
-
clientInfo: { name: "bazis", title: "Bazis", version: "0.105.
|
|
235
|
+
clientInfo: { name: "bazis", title: "Bazis", version: "0.105.3" }, capabilities: { experimentalApi: true },
|
|
236
236
|
}, 15_000, signal);
|
|
237
237
|
if (resolve(text(initialized.codexHome, 4096)) !== this.paths.home) throw new CodexError("PROTOCOL_ERROR");
|
|
238
238
|
client.notify("initialized");
|
|
@@ -52,7 +52,7 @@ const EN_CODEX_MESSAGES: Readonly<Record<CodexErrorCode, string>> = Object.freez
|
|
|
52
52
|
LOGIN_EXPIRED: "The sign-in window expired. Start signing in again.",
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
/** Russian texts for every code
|
|
55
|
+
/** Russian texts for every code; `runApp({ language: "ru" })` turns them on. */
|
|
56
56
|
export const RU_CODEX_MESSAGES: Readonly<Record<CodexErrorCode, string>> = Object.freeze({
|
|
57
57
|
NOT_CONFIGURED: "Подключение ChatGPT не настроено на сервере.",
|
|
58
58
|
UNAVAILABLE: "Codex App Server недоступен. Проверьте его установку и настройки.",
|
|
@@ -67,15 +67,31 @@ export const RU_CODEX_MESSAGES: Readonly<Record<CodexErrorCode, string>> = Objec
|
|
|
67
67
|
LOGIN_EXPIRED: "Время для входа истекло. Начните вход заново.",
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
+
const CODEX_LANGUAGES = { en: EN_CODEX_MESSAGES, ru: RU_CODEX_MESSAGES } as const;
|
|
71
|
+
let language: Readonly<Record<CodexErrorCode, string>> = EN_CODEX_MESSAGES;
|
|
72
|
+
let own: Partial<Record<CodexErrorCode, string>> = {};
|
|
70
73
|
let messages: Readonly<Record<CodexErrorCode, string>> = EN_CODEX_MESSAGES;
|
|
71
74
|
|
|
72
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* @internal `runApp({ language })` sets the language of the texts. It is
|
|
77
|
+
* process-wide, like the texts themselves: the last started application wins.
|
|
78
|
+
*/
|
|
79
|
+
export function useCodexLanguage(name: keyof typeof CODEX_LANGUAGES): void {
|
|
80
|
+
language = CODEX_LANGUAGES[name];
|
|
81
|
+
messages = Object.freeze({ ...language, ...own });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** `message` is user-facing text for `code`, in the language of `runApp({ language })`. */
|
|
73
85
|
export class CodexError extends Error {
|
|
74
86
|
constructor(readonly code: CodexErrorCode) { super(messages[code]); this.name = "CodexError"; }
|
|
75
87
|
|
|
76
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Own texts for some or all codes (process-wide), on top of the application
|
|
90
|
+
* language; missing codes keep it. `useMessages({})` drops own texts.
|
|
91
|
+
*/
|
|
77
92
|
static useMessages(overrides: Partial<Record<CodexErrorCode, string>>): void {
|
|
78
|
-
|
|
93
|
+
own = { ...overrides };
|
|
94
|
+
messages = Object.freeze({ ...language, ...own });
|
|
79
95
|
}
|
|
80
96
|
}
|
|
81
97
|
export const CODEX_MODEL_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,120}$/;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bazis",
|
|
3
|
-
"version": "0.105.
|
|
3
|
+
"version": "0.105.3",
|
|
4
4
|
"description": "Modular backend framework for Bun in TypeScript: DI wired by codegen, HTTP, a PostgreSQL ORM, JWT, WebSocket, agents and a CLI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexander Alenin",
|