@lincyaw/kernel 1.0.0-rc.45 → 1.0.0-rc.47
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 +1 -1
- package/src/contracts/projects.ts +4 -1
- package/src/contracts/workspace-changes.ts +27 -0
- package/src/contracts/workspace-source.ts +38 -0
- package/src/contracts.ts +2 -0
- package/src/node/index.ts +2 -0
- package/src/node/workspace-changes.ts +7 -0
- package/src/node/workspace-source.ts +10 -0
package/package.json
CHANGED
|
@@ -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,27 @@
|
|
|
1
|
+
import type { Member } from './server.ts'
|
|
2
|
+
import type { Revision, UncommittedFile } from './workspace.ts'
|
|
3
|
+
export const CHANGES_MAX_REQUEST_CHARS = 1 << 20
|
|
4
|
+
export const CHANGES_MAX_RESPONSE_CHARS = 7168
|
|
5
|
+
export const CHANGES_MAX_FILES = 16_384
|
|
6
|
+
export const CHANGES_MAX_BYTES = 512 << 20
|
|
7
|
+
export interface ChangesCaller { member: Member, origin: 'editor' | 'agent', boundDocument?: string, confirmed?: boolean }
|
|
8
|
+
export interface ChangesQuery { document?: string, offset?: number, snapshot?: string }
|
|
9
|
+
export interface WorkspaceChangesAnswer { available: boolean, files: (UncommittedFile & { unsupported?: true })[], snapshot?: string, nextOffset?: number }
|
|
10
|
+
export type WorkspaceChangesRequest = { document?: string, paths?: string[], snapshot?: string } & (
|
|
11
|
+
| { action: 'commit', message: string }
|
|
12
|
+
| { action: 'discard', confirm: true }
|
|
13
|
+
)
|
|
14
|
+
export interface WorkspaceChangesResult { action: 'commit' | 'discard', files: number, refreshed?: false, revision?: Revision, committed?: boolean }
|
|
15
|
+
export interface PreparedWorkspaceChanges { readonly paths: readonly string[], change(signal?: AbortSignal): Promise<WorkspaceChangesResult> }
|
|
16
|
+
export interface WorkspaceChanges {
|
|
17
|
+
list(query: ChangesQuery, caller: ChangesCaller): Promise<WorkspaceChangesAnswer>
|
|
18
|
+
prepare(request: WorkspaceChangesRequest, caller: ChangesCaller): Promise<PreparedWorkspaceChanges>
|
|
19
|
+
}
|
|
20
|
+
const document = { type: 'string', maxLength: 500 } as const
|
|
21
|
+
const snapshot = { type: 'string', pattern: '^[a-f0-9]{64}$' } as const
|
|
22
|
+
const paths = { type: 'array', minItems: 1, maxItems: CHANGES_MAX_FILES, uniqueItems: true, items: { type: 'string', minLength: 1, maxLength: 500 } } as const
|
|
23
|
+
export const CHANGES_QUERY_SCHEMA = { type: 'object', additionalProperties: false, properties: { document, snapshot, offset: { type: 'integer', minimum: 0 } } } as const
|
|
24
|
+
export const CHANGES_REQUEST_SCHEMA = { oneOf: [
|
|
25
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'message'], properties: { document, paths, snapshot, action: { const: 'commit' }, message: { type: 'string', minLength: 1, maxLength: 4000 } } },
|
|
26
|
+
{ type: 'object', additionalProperties: false, required: ['action', 'confirm'], properties: { document, paths, snapshot, action: { const: 'discard' }, confirm: { const: true } } },
|
|
27
|
+
] } 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,8 @@ 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'
|
|
28
|
+
export * from './contracts/workspace-changes.ts'
|
|
27
29
|
export * from './contracts/transcription.ts'
|
|
28
30
|
export * from './contracts/transcription-adoption.ts'
|
|
29
31
|
export * from './contracts/voice.ts'
|
package/src/node/index.ts
CHANGED
|
@@ -30,3 +30,5 @@ 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'
|
|
34
|
+
export { validateChangesQuery, validateWorkspaceChangesRequest } from './workspace-changes.ts'
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Validator } from '@cfworker/json-schema'
|
|
2
|
+
import type { Schema } from '@cfworker/json-schema'
|
|
3
|
+
import { CHANGES_QUERY_SCHEMA, CHANGES_REQUEST_SCHEMA } from '../contracts/workspace-changes.ts'
|
|
4
|
+
import type { ChangesQuery, WorkspaceChangesRequest } from '../contracts/workspace-changes.ts'
|
|
5
|
+
const query = new Validator(CHANGES_QUERY_SCHEMA as unknown as Schema), change = new Validator(CHANGES_REQUEST_SCHEMA as unknown as Schema)
|
|
6
|
+
export const validateChangesQuery = (value: unknown): value is ChangesQuery => query.validate(value).valid
|
|
7
|
+
export const validateWorkspaceChangesRequest = (value: unknown): value is WorkspaceChangesRequest => change.validate(value).valid
|
|
@@ -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
|