@lincyaw/kernel 1.0.0-rc.46 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/kernel",
3
- "version": "1.0.0-rc.46",
3
+ "version": "1.0.0-rc.47",
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": {
@@ -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
package/src/contracts.ts CHANGED
@@ -25,6 +25,7 @@ export * from './contracts/speech.ts'
25
25
  export * from './contracts/speech-settings.ts'
26
26
  export * from './contracts/workspace-review.ts'
27
27
  export * from './contracts/workspace-source.ts'
28
+ export * from './contracts/workspace-changes.ts'
28
29
  export * from './contracts/transcription.ts'
29
30
  export * from './contracts/transcription-adoption.ts'
30
31
  export * from './contracts/voice.ts'
package/src/node/index.ts CHANGED
@@ -31,3 +31,4 @@ export { devStateFile, readServiceState, removeServiceState, serveStateDir } fro
31
31
  export type { ServiceState } from './service-state.ts'
32
32
  export { validateWorkspaceReviewQuery, validateWorkspaceReviewChange } from './workspace-review.ts'
33
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