@lincyaw/kernel 1.0.0-rc.45 → 1.0.0-rc.46

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.45",
3
+ "version": "1.0.0-rc.46",
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": {
@@ -10,6 +10,8 @@ export type ProjectOperation = DocumentOperation | { op: 'retitle', dir: string,
10
10
  export interface ProjectCaller { member: Member, origin: 'editor' | 'agent', boundDocument?: string }
11
11
  export interface ProjectObservation { snapshot?: string, configuration: string }
12
12
  export interface ProjectCapabilities {
13
+ templates?: string[]
14
+ nextTemplatesOffset?: number
13
15
  available: boolean
14
16
  actions: Record<ProjectOperation['op'], { available: boolean, reasons: string[] }>
15
17
  reasons: string[]
@@ -45,7 +47,7 @@ export interface ProjectApplied extends OperationAnswer {
45
47
  }
46
48
  /** Directory management borrows the Web writer; metadata retitle borrows canonical document CAS. */
47
49
  export interface ProjectAuthoring {
48
- capabilities(caller: ProjectCaller): Promise<ProjectCapabilities>
50
+ capabilities(caller: ProjectCaller, query?: { templatesOffset?: number }): Promise<ProjectCapabilities>
49
51
  plan(request: ProjectPlanRequest, caller: ProjectCaller): Promise<ProjectPlan>
50
52
  readPlan(request: ProjectApply, caller: ProjectCaller): Promise<ProjectPlan>
51
53
  apply(request: ProjectApply, caller: ProjectCaller, signal?: AbortSignal): Promise<ProjectApplied>
@@ -57,3 +59,4 @@ export const PROJECT_PLAN_SCHEMA = { type: 'object', additionalProperties: false
57
59
  id: text, operation: { oneOf: [operation('create', { title: text, template: text }, []), operation('copy', { to: text, title: text }, ['to']), operation('rename', { to: text }, ['to']), operation('delete', {}, []), operation('retitle', { title: text }, ['title'])] },
58
60
  } } as const
59
61
  export const PROJECT_APPLY_SCHEMA = { type: 'object', additionalProperties: false, required: ['planId', 'digest'], properties: { planId: text, digest: { type: 'string', pattern: '^[a-f0-9]{64}$' }, confirmDeletion: { const: true } } } as const
62
+ export const PROJECT_CAPABILITIES_SCHEMA = { type: 'object', additionalProperties: false, properties: { templatesOffset: { type: 'integer', minimum: 0 } } } as const
@@ -0,0 +1,38 @@
1
+ import type { Member } from './server.ts'
2
+ import type { SourceFile } from './workspace.ts'
3
+
4
+ export const SOURCE_MAX_BYTES = 2 << 20
5
+ export const SOURCE_MAX_FILES = 16
6
+ export const SOURCE_MAX_REQUEST_CHARS = SOURCE_MAX_BYTES * 3 + 8192
7
+ export const SOURCE_MAX_RESPONSE_CHARS = 7168
8
+ export const SOURCE_FRAGMENT_CHARS = 4000
9
+ /** Supplied by an adapter, never accepted as model arguments. */
10
+ export interface SourceCaller { member: Member, boundDocument?: string, confirmed?: boolean, origin: 'editor' | 'agent' }
11
+ export interface SourceListQuery { document?: string, query?: string, offset?: number, snapshot?: string }
12
+ export interface SourceListAnswer { files: SourceFile[], snapshot: string, nextOffset?: number, truncated?: true }
13
+ export interface SourceReadQuery { document?: string, path: string, offset?: number, version?: string }
14
+ export interface SourceReadAnswer { path: string, version: string, text: string, offset: number, totalChars: number, nextOffset?: number }
15
+ export type SourceEditFile = { path: string, version?: string } & ({ content: string, create?: true } | { find: string, replace: string })
16
+ export type SourceEdit = ({ document?: string } & SourceEditFile) | { document?: string, edits: SourceEditFile[] }
17
+ export interface SourceSaved { saved: true, changed: boolean, path?: string, files?: number, revision?: string, current?: false }
18
+ export interface PreparedSourceEdit { change(signal?: AbortSignal): Promise<SourceSaved> }
19
+ /** Current source editor scope and transaction owner; invalid IR is readable and repairable. */
20
+ export interface WorkspaceSource {
21
+ list(query: SourceListQuery, caller: SourceCaller): Promise<SourceListAnswer>
22
+ read(query: SourceReadQuery, caller: SourceCaller): Promise<SourceReadAnswer>
23
+ prepare(edit: SourceEdit, caller: SourceCaller): Promise<PreparedSourceEdit>
24
+ }
25
+ const document = { type: 'string', maxLength: 500 } as const
26
+ const path = { type: 'string', minLength: 1, maxLength: 500 } as const
27
+ const version = { type: 'string', pattern: '^[a-f0-9]{20}$' } as const
28
+ const offset = { type: 'integer', minimum: 0 } as const
29
+ export const SOURCE_LIST_SCHEMA = { type: 'object', additionalProperties: false, properties: { document, query: { type: 'string', maxLength: 200 }, offset, snapshot: { type: 'string', pattern: '^[a-f0-9]{64}$' } } } as const
30
+ export const SOURCE_READ_SCHEMA = { type: 'object', additionalProperties: false, required: ['path'], properties: { document, path, offset, version } } as const
31
+ const fileSchema = { oneOf: [
32
+ { type: 'object', additionalProperties: false, required: ['path', 'content'], properties: { path, version, content: { type: 'string', maxLength: SOURCE_MAX_BYTES }, create: { const: true } } },
33
+ { type: 'object', additionalProperties: false, required: ['path', 'find', 'replace'], properties: { path, version, find: { type: 'string', minLength: 1, maxLength: SOURCE_MAX_BYTES }, replace: { type: 'string', maxLength: SOURCE_MAX_BYTES } } },
34
+ ] } as const
35
+ export const SOURCE_EDIT_SCHEMA = { oneOf: [
36
+ ...fileSchema.oneOf.map(schema => ({ ...schema, properties: { document, ...schema.properties } })),
37
+ { type: 'object', additionalProperties: false, required: ['edits'], properties: { document, edits: { type: 'array', minItems: 1, maxItems: SOURCE_MAX_FILES, items: fileSchema } } },
38
+ ] } as const
package/src/contracts.ts CHANGED
@@ -24,6 +24,7 @@ export * from './contracts/service.ts'
24
24
  export * from './contracts/speech.ts'
25
25
  export * from './contracts/speech-settings.ts'
26
26
  export * from './contracts/workspace-review.ts'
27
+ export * from './contracts/workspace-source.ts'
27
28
  export * from './contracts/transcription.ts'
28
29
  export * from './contracts/transcription-adoption.ts'
29
30
  export * from './contracts/voice.ts'
package/src/node/index.ts CHANGED
@@ -30,3 +30,4 @@ export { OperatorSpeechSettings, operatorSpeechSecrets, SpeechSettingsError, val
30
30
  export { devStateFile, readServiceState, removeServiceState, serveStateDir } from './service-state.ts'
31
31
  export type { ServiceState } from './service-state.ts'
32
32
  export { validateWorkspaceReviewQuery, validateWorkspaceReviewChange } from './workspace-review.ts'
33
+ export { validateSourceList, validateSourceRead, validateSourceEdit } from './workspace-source.ts'
@@ -0,0 +1,10 @@
1
+ import { Validator } from '@cfworker/json-schema'
2
+ import type { Schema } from '@cfworker/json-schema'
3
+ import { SOURCE_EDIT_SCHEMA, SOURCE_LIST_SCHEMA, SOURCE_READ_SCHEMA } from '../contracts/workspace-source.ts'
4
+ import type { SourceEdit, SourceListQuery, SourceReadQuery } from '../contracts/workspace-source.ts'
5
+ const list = new Validator(SOURCE_LIST_SCHEMA as unknown as Schema)
6
+ const read = new Validator(SOURCE_READ_SCHEMA as unknown as Schema)
7
+ const edit = new Validator(SOURCE_EDIT_SCHEMA as unknown as Schema)
8
+ export const validateSourceList = (value: unknown): value is SourceListQuery => list.validate(value).valid
9
+ export const validateSourceRead = (value: unknown): value is SourceReadQuery => read.validate(value).valid
10
+ export const validateSourceEdit = (value: unknown): value is SourceEdit => edit.validate(value).valid