@lincyaw/kernel 1.0.0-rc.41 → 1.0.0-rc.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/kernel",
3
- "version": "1.0.0-rc.41",
3
+ "version": "1.0.0-rc.43",
4
4
  "description": "Presmium's shared kernel: the IR and plugin contracts, the service registry, anchors and checks",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,3 +1,5 @@
1
+ import type { Schema } from '@cfworker/json-schema'
2
+
1
3
  /** Operator configuration is separate from document voice choices. Secret values are write-only. */
2
4
  export interface SpeechSettingsAnswer {
3
5
  provider: 'volcengine'
@@ -14,3 +16,14 @@ export interface SpeechSettingsAnswer {
14
16
  export type SpeechSettingsChange =
15
17
  | { action: 'save', revision: string, apiKey?: string, appId?: string }
16
18
  | { action: 'clear', revision: string }
19
+
20
+ export interface SpeechSettings {
21
+ read(): SpeechSettingsAnswer
22
+ change(change: SpeechSettingsChange): Promise<SpeechSettingsAnswer>
23
+ }
24
+
25
+ export const SPEECH_SETTINGS_CHANGE_SCHEMA: Schema = {
26
+ type: 'object', additionalProperties: false,
27
+ properties: { action: { enum: ['save', 'clear'] }, revision: { type: 'string', maxLength: 200 }, apiKey: { type: 'string', maxLength: 8192 }, appId: { type: 'string', maxLength: 32 } },
28
+ required: ['action', 'revision'],
29
+ }
package/src/node/index.ts CHANGED
@@ -26,6 +26,6 @@ export { validateAuthoringClientRequest, validateAuthoringClientQuery, validateA
26
26
  export { validateProjectPlan, validateProjectApply } from './projects.ts'
27
27
  export { validateDocumentWorkspaceImageInspect, validateDocumentWorkspaceImageImport } from './document-image.ts'
28
28
  export { systemLocale } from './locale.ts'
29
- export { OperatorSpeechSettings, operatorSpeechSecrets, SpeechSettingsError } from './operator-speech.ts'
29
+ export { OperatorSpeechSettings, operatorSpeechSecrets, SpeechSettingsError, validateSpeechSettingsChange } from './operator-speech.ts'
30
30
  export { devStateFile, readServiceState, removeServiceState, serveStateDir } from './service-state.ts'
31
31
  export type { ServiceState } from './service-state.ts'
@@ -2,10 +2,14 @@ import { createRequire } from 'node:module'
2
2
  import { randomUUID } from 'node:crypto'
3
3
  import { constants, closeSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
4
4
  import { dirname, join } from 'node:path'
5
+ import { Validator } from '@cfworker/json-schema'
6
+ import { SPEECH_SETTINGS_CHANGE_SCHEMA } from '../contracts/speech-settings.ts'
5
7
  import type { SpeechSettingsAnswer, SpeechSettingsChange } from '../contracts/speech-settings.ts'
6
8
 
7
9
  const KEY = 'PRESMIUM_SPEECH_VOLCENGINE_KEY', APPID = 'PRESMIUM_SPEECH_VOLCENGINE_APPID'
8
10
  const MAX_BYTES = 16384
11
+ const settingsChangeValidator = new Validator(structuredClone(SPEECH_SETTINGS_CHANGE_SCHEMA), '2020-12', false)
12
+ export const validateSpeechSettingsChange = (value: unknown): value is SpeechSettingsChange => settingsChangeValidator.validate(value).valid
9
13
  const lockfile = createRequire(import.meta.url)('proper-lockfile') as { lock(file: string, options: { realpath: boolean, retries: number }): Promise<() => Promise<void>> }
10
14
  interface Stored { version: 1, revision: string, key?: string, appId?: string }
11
15
  const empty = (): Stored => ({ version: 1, revision: 'none' })