mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 22:18:54 +08:00
feat(server): improve context management (#15448)
#### PR Dependency Tree * **PR #15448** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added workspace artifact upload, browsing, removal, deduplication, and library ownership support. * Copilot now supports scoped document and artifact search, canvas reading, live editor context, and frontend tools. * Added scope and focus selectors with source-resolution receipts in chat. * Added embedding health, progress, synchronization, and retrieval capabilities. * Added BYOK policy visibility, provider restrictions, endpoint dialect selection, and validation. * Added delegated editor interactions and userdata document authorization. * **Bug Fixes** * Improved attachment handling, cancellation, access control, retrieval fallbacks, workspace synchronization, and configuration validation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Vendored
+289
-20
@@ -59,13 +59,27 @@ export declare class BackendRuntime {
|
||||
recalibrateWorkspaceAdminStats(lastSid: number, batchLimit: number, owner: string, leaseTtlMs: number): Promise<RuntimeWorkspaceStatsRecalibrationResult>
|
||||
writeWorkspaceAdminStatsDailySnapshot(owner: string, leaseTtlMs: number): Promise<RuntimeWorkspaceStatsSnapshotResult>
|
||||
recalibrateWorkspaceAdminStatsDaily(batchLimit: number, owner: string, leaseTtlMs: number, lockRetryTimes: number, lockRetryDelayMs: number): Promise<RuntimeWorkspaceStatsDailyRecalibrationResult>
|
||||
constructor(privateKey?: string | undefined | null)
|
||||
constructor(privateKey?: string | undefined | null, configPaths?: Array<string> | undefined | null)
|
||||
start(): Promise<void>
|
||||
stop(): Promise<void>
|
||||
reloadConfig(privateKey?: string | undefined | null): Promise<void>
|
||||
health(): Promise<BackendRuntimeHealth>
|
||||
runMigrations(): Promise<void>
|
||||
embeddingHealth(): Promise<EmbeddingHealth>
|
||||
syncEmbeddingState(input: SyncEmbeddingStateInput): Promise<RuntimeEmbeddingWorkspaceState>
|
||||
embeddingQueueCounts(): Promise<RuntimeEmbeddingQueueCounts>
|
||||
embeddingWorkspaceProgress(workspaceId: string): Promise<RuntimeEmbeddingProgress>
|
||||
reconcileEmbeddingWorkspaces(): Promise<number>
|
||||
putWorkspaceArtifact(input: PutWorkspaceArtifactInput, body: Buffer): Promise<RuntimeWorkspaceArtifact>
|
||||
ensureWorkspaceBlobArtifact(input: EnsureWorkspaceBlobArtifactInput): Promise<RuntimeWorkspaceArtifact>
|
||||
cleanupUnreferencedArtifacts(limit: number): Promise<number>
|
||||
setArtifactLibraryOwned(workspaceId: string, artifactId: string, libraryOwned: boolean, displayName?: string | undefined | null): Promise<RuntimeWorkspaceArtifact>
|
||||
compileTurnScope(input: CompileScopeInput): Promise<RuntimeTurnScopeSnapshot>
|
||||
readEmbeddingSourceContent(input: ReadEmbeddingSourceContentInput): Promise<RuntimeEmbeddingSourceContent>
|
||||
matchEmbeddingCandidates(input: MatchEmbeddingCandidatesInput): Promise<Array<RuntimeEmbeddingCandidate>>
|
||||
cancelEmbeddingCandidateRequest(requestId: string): Promise<void>
|
||||
listByokProfiles(workspaceId: string): Promise<Array<ByokProfileOutput>>
|
||||
getByokPolicy(): ByokPolicyOutput
|
||||
createByokProfile(input: CreateByokProfileInput): Promise<ByokProfileOutput>
|
||||
replaceByokProfile(input: ReplaceByokProfileInput): Promise<ByokProfileOutput>
|
||||
rotateByokCredential(input: RotateByokCredentialInput): Promise<ByokProfileOutput>
|
||||
@@ -138,12 +152,24 @@ export const AFFINE_PRO_LICENSE_AES_KEY: string | undefined | null
|
||||
|
||||
export const AFFINE_PRO_PUBLIC_KEY: string | undefined | null
|
||||
|
||||
export interface AppConfigDescriptor {
|
||||
key: string
|
||||
description: string
|
||||
defaultValue: any
|
||||
schema: any
|
||||
internal: boolean
|
||||
}
|
||||
|
||||
export declare function appConfigDescriptors(module: string): Array<AppConfigDescriptor>
|
||||
|
||||
export declare function assertSafeUrl(request: AssertSafeUrlRequest): void
|
||||
|
||||
export interface AssertSafeUrlRequest {
|
||||
url: string
|
||||
}
|
||||
|
||||
export declare function authorizeUserdataDocSubject(userId: string, workspaceId: string, docId: string): boolean
|
||||
|
||||
export declare function authSessionAccessTokenKeyId(token: string): string | null
|
||||
|
||||
export interface AuthSessionAccessTokenVerification {
|
||||
@@ -161,6 +187,7 @@ export interface AuthSessionRefreshToken {
|
||||
export interface BackendRuntimeHealth {
|
||||
started: boolean
|
||||
databaseConnected: boolean
|
||||
embedding: EmbeddingHealth
|
||||
}
|
||||
|
||||
export declare function buildPublicRootDoc(rootDocBin: Buffer, docMetas: Array<PublicDocMetaInput>): Buffer
|
||||
@@ -229,6 +256,7 @@ export interface ByokCatalogProviderOutput {
|
||||
export interface ByokEndpointInput {
|
||||
kind: string
|
||||
url?: string
|
||||
dialect?: string
|
||||
}
|
||||
|
||||
export interface ByokLocalLeaseOutput {
|
||||
@@ -252,6 +280,13 @@ export interface ByokModelProbeOutput {
|
||||
checks: Array<ByokModelProbeCheckOutput>
|
||||
}
|
||||
|
||||
export interface ByokPolicyOutput {
|
||||
enabled: boolean
|
||||
allowedProviders: Array<string>
|
||||
customEndpointMode: string
|
||||
privateEndpointSupported: boolean
|
||||
}
|
||||
|
||||
export interface ByokProbeCheckInput {
|
||||
modelId: string
|
||||
operation: string
|
||||
@@ -271,7 +306,6 @@ export interface ByokProbeStatusOutput {
|
||||
}
|
||||
|
||||
export interface ByokProfileDefinitionInput {
|
||||
version: number
|
||||
endpoint: ByokEndpointInput
|
||||
models: Array<ByokModelDeclarationInput>
|
||||
}
|
||||
@@ -366,6 +400,13 @@ export interface CommandResponse {
|
||||
error?: LicenseError
|
||||
}
|
||||
|
||||
export interface CompileScopeInput {
|
||||
workspaceId: string
|
||||
userId: string
|
||||
selectors: Array<ScopeSelectorInput>
|
||||
preferredSourceIds?: Array<string>
|
||||
}
|
||||
|
||||
export interface ContentPolicyMatch {
|
||||
type: string
|
||||
reason: string
|
||||
@@ -484,6 +525,41 @@ export declare function createLicenseCustomerPortal(request: LicenseKeyRequest):
|
||||
|
||||
export declare function deactivateLicense(request: LicenseKeyRequest): Promise<CommandResponse>
|
||||
|
||||
export interface DocumentEmbeddingProjectionInput {
|
||||
docId: string
|
||||
revision: string
|
||||
sourceHash: string
|
||||
units: Array<DocumentEmbeddingUnitInput>
|
||||
deleted?: boolean
|
||||
}
|
||||
|
||||
export interface DocumentEmbeddingUnitInput {
|
||||
unitId: string
|
||||
visibility: string
|
||||
text: string
|
||||
blockId?: string
|
||||
elementId?: string
|
||||
frameId?: string
|
||||
}
|
||||
|
||||
export interface EmbeddingHealth {
|
||||
enabled: boolean
|
||||
state: string
|
||||
reason?: string
|
||||
pgvectorVersion?: string
|
||||
schemaVersion?: number
|
||||
workerRunning: boolean
|
||||
}
|
||||
|
||||
export interface EnsureWorkspaceBlobArtifactInput {
|
||||
workspaceId: string
|
||||
blobId: string
|
||||
mimeType: string
|
||||
displayName?: string
|
||||
fileName?: string
|
||||
libraryOwned?: boolean
|
||||
}
|
||||
|
||||
export declare function evaluatePermissionV1(input: any): any
|
||||
|
||||
export declare function fetchRemoteAttachment(request: RemoteAttachmentFetchRequest): Promise<RemoteAttachmentFetchResponse>
|
||||
@@ -685,6 +761,15 @@ export declare function llmValidateContract(name: string, value: any): any
|
||||
|
||||
export declare function llmValidateJsonSchema(schema: any, value: any): any
|
||||
|
||||
export interface MatchEmbeddingCandidatesInput {
|
||||
requestId?: string
|
||||
workspaceId: string
|
||||
query: string
|
||||
sourceKind: string
|
||||
retrieval: RuntimeRetrievalScope
|
||||
limit?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge updates in form like `Y.applyUpdate(doc, update)` way and return the
|
||||
* result binary.
|
||||
@@ -723,7 +808,7 @@ export interface ModelRegistryResolveResponse {
|
||||
|
||||
export interface ModelRegistryRouteContract {
|
||||
protocol?: 'openai_chat' | 'openai_responses' | 'openai_images' | 'anthropic' | 'gemini' | 'fal_image'
|
||||
requestLayer?: 'anthropic' | 'chat_completions' | 'chat_completions_no_v1' | 'cloudflare_workers_ai' | 'responses' | 'openai_images' | 'fal' | 'vertex' | 'vertex_anthropic' | 'gemini_api' | 'gemini_vertex'
|
||||
requestLayer?: 'anthropic' | 'chat_completions' | 'cloudflare_workers_ai' | 'responses' | 'openai_images' | 'fal' | 'vertex' | 'vertex_anthropic' | 'gemini_api' | 'gemini_vertex'
|
||||
}
|
||||
|
||||
export interface ModelRegistryVariantContract {
|
||||
@@ -735,27 +820,83 @@ export interface ModelRegistryVariantContract {
|
||||
legacyAliases?: Array<string>
|
||||
capabilities: Array<CapabilityModelCapability>
|
||||
protocol?: 'openai_chat' | 'openai_responses' | 'openai_images' | 'anthropic' | 'gemini' | 'fal_image'
|
||||
requestLayer?: 'anthropic' | 'chat_completions' | 'chat_completions_no_v1' | 'cloudflare_workers_ai' | 'responses' | 'openai_images' | 'fal' | 'vertex' | 'vertex_anthropic' | 'gemini_api' | 'gemini_vertex'
|
||||
requestLayer?: 'anthropic' | 'chat_completions' | 'cloudflare_workers_ai' | 'responses' | 'openai_images' | 'fal' | 'vertex' | 'vertex_anthropic' | 'gemini_api' | 'gemini_vertex'
|
||||
routeOverrides?: Record<string, ModelRegistryRouteContract>
|
||||
behaviorFlags?: Array<string>
|
||||
}
|
||||
|
||||
export interface NativeBlockInfo {
|
||||
blockId: string
|
||||
flavour: string
|
||||
content?: Array<string>
|
||||
blob?: Array<string>
|
||||
refDocId?: Array<string>
|
||||
refInfo?: Array<string>
|
||||
export interface NativeCanvasProjection {
|
||||
version: number
|
||||
docId: string
|
||||
revision: string
|
||||
title: string
|
||||
surfaceBlockId?: string
|
||||
bounds?: NativeDocBounds
|
||||
counts: Record<string, number>
|
||||
blocks: Array<NativeCanvasProjectionBlock>
|
||||
elements: Array<NativeCanvasProjectionElement>
|
||||
warnings: Array<NativeProjectionWarning>
|
||||
}
|
||||
|
||||
export interface NativeCanvasProjectionBlock {
|
||||
id: string
|
||||
type: string
|
||||
visibility: string
|
||||
bounds?: NativeDocBounds
|
||||
text?: string
|
||||
title?: string
|
||||
childIds: Array<string>
|
||||
}
|
||||
|
||||
export interface NativeCanvasProjectionElement {
|
||||
id: string
|
||||
type: string
|
||||
bounds?: NativeDocBounds
|
||||
text?: string
|
||||
title?: string
|
||||
frameId?: string
|
||||
childIds: Array<string>
|
||||
sourceId?: string
|
||||
targetId?: string
|
||||
parentId?: string
|
||||
index?: string
|
||||
pointCount?: number
|
||||
color?: string
|
||||
lineWidth?: number
|
||||
}
|
||||
|
||||
export interface NativeDocBounds {
|
||||
x: number
|
||||
y: number
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
|
||||
export interface NativeDocumentSearchProjection {
|
||||
version: number
|
||||
docId: string
|
||||
revision: string
|
||||
sourceHash: string
|
||||
title: string
|
||||
units: Array<NativeDocumentSearchUnit>
|
||||
warnings: Array<NativeProjectionWarning>
|
||||
}
|
||||
|
||||
export interface NativeDocumentSearchUnit {
|
||||
unitId: string
|
||||
source: string
|
||||
visibility: string
|
||||
blockId?: string
|
||||
elementId?: string
|
||||
frameId?: string
|
||||
blobId?: string
|
||||
refDocIds: Array<string>
|
||||
refs: Array<string>
|
||||
parentFlavour?: string
|
||||
parentBlockId?: string
|
||||
additional?: string
|
||||
}
|
||||
|
||||
export interface NativeCrawlResult {
|
||||
blocks: Array<NativeBlockInfo>
|
||||
title: string
|
||||
summary: string
|
||||
type: string
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface NativeMarkdownResult {
|
||||
@@ -770,6 +911,11 @@ export interface NativePageDocContent {
|
||||
summary: string
|
||||
}
|
||||
|
||||
export interface NativeProjectionWarning {
|
||||
code: string
|
||||
locator: string
|
||||
}
|
||||
|
||||
export interface NativeWorkspaceDocContent {
|
||||
name: string
|
||||
avatarKey: string
|
||||
@@ -789,8 +935,6 @@ export interface ParsedDoc {
|
||||
|
||||
export declare function parseDoc(filePath: string, doc: Buffer): Promise<ParsedDoc>
|
||||
|
||||
export declare function parseDocFromBinary(docBin: Buffer, docId: string): NativeCrawlResult
|
||||
|
||||
export declare function parseDocToMarkdown(docBin: Buffer, docId: string, aiEditable?: boolean | undefined | null, docUrlPrefix?: string | undefined | null): NativeMarkdownResult
|
||||
|
||||
export declare function parsePageDoc(docBin: Buffer, maxSummaryLength?: number | undefined | null): NativePageDocContent | null
|
||||
@@ -824,6 +968,10 @@ export interface ProbeByokProfileInput {
|
||||
|
||||
export declare function processImage(input: Buffer, maxEdge: number, keepExif: boolean): Promise<Buffer>
|
||||
|
||||
export declare function projectDocCanvasFromBinary(docBin: Buffer, docId: string, revision: string): NativeCanvasProjection
|
||||
|
||||
export declare function projectDocSearchFromBinary(docBin: Buffer, docId: string, revision: string): NativeDocumentSearchProjection
|
||||
|
||||
export type PromptBuiltin = 'Date'|
|
||||
'Language'|
|
||||
'Timezone'|
|
||||
@@ -898,8 +1046,25 @@ export interface PublicDocMetaInput {
|
||||
title?: string
|
||||
}
|
||||
|
||||
export interface PutWorkspaceArtifactInput {
|
||||
workspaceId: string
|
||||
mimeType: string
|
||||
displayName?: string
|
||||
fileName?: string
|
||||
libraryOwned?: boolean
|
||||
}
|
||||
|
||||
export declare function readAllDocIdsFromRootDoc(docBin: Buffer, includeTrash?: boolean | undefined | null): Array<string>
|
||||
|
||||
export interface ReadEmbeddingSourceContentInput {
|
||||
workspaceId: string
|
||||
sourceKind: string
|
||||
sourceKey: string
|
||||
retrieval: RuntimeRetrievalScope
|
||||
maxChars?: number
|
||||
cursor?: string
|
||||
}
|
||||
|
||||
export interface RemoteAttachmentFetchRequest {
|
||||
url: string
|
||||
timeoutMs?: number
|
||||
@@ -1078,7 +1243,6 @@ export interface RuntimeDocumentCleanupEffect {
|
||||
cleanupVersion: string
|
||||
commentObjectsDone: boolean
|
||||
searchDone: boolean
|
||||
copilotDone: boolean
|
||||
}
|
||||
|
||||
export interface RuntimeDocumentCleanupExecuteResult {
|
||||
@@ -1099,6 +1263,62 @@ export interface RuntimeDocumentCleanupReconcileResult {
|
||||
recovered: number
|
||||
}
|
||||
|
||||
export interface RuntimeEmbeddingCandidate {
|
||||
sourceKind: string
|
||||
sourceKey: string
|
||||
content: string
|
||||
distance: number
|
||||
docId?: string
|
||||
artifactId?: string
|
||||
unitId?: string
|
||||
visibility?: string
|
||||
blockId?: string
|
||||
elementId?: string
|
||||
frameId?: string
|
||||
chunk: number
|
||||
}
|
||||
|
||||
export interface RuntimeEmbeddingProgress {
|
||||
total: number
|
||||
embedded: number
|
||||
}
|
||||
|
||||
export interface RuntimeEmbeddingQueueCounts {
|
||||
pending: bigint | number
|
||||
running: bigint | number
|
||||
retryWait: bigint | number
|
||||
ready: bigint | number
|
||||
failed: bigint | number
|
||||
expiredLeases: bigint | number
|
||||
oldestPendingSeconds: bigint | number
|
||||
activeVectorRows: bigint | number
|
||||
inactiveVectorRows: bigint | number
|
||||
indexBytes: bigint | number
|
||||
retryingIndexes: bigint | number
|
||||
maxIndexRetrySeconds: bigint | number
|
||||
}
|
||||
|
||||
export interface RuntimeEmbeddingSourceContent {
|
||||
content: string
|
||||
/**
|
||||
* Active materialization token. Changes whenever extracted content is
|
||||
* replaced.
|
||||
*/
|
||||
revision: string
|
||||
mimeType?: string
|
||||
name?: string
|
||||
truncated: boolean
|
||||
nextCursor?: string
|
||||
}
|
||||
|
||||
export interface RuntimeEmbeddingWorkspaceState {
|
||||
workspaceId: string
|
||||
activeIndexId?: string
|
||||
indexEpoch: bigint | number
|
||||
runtimeState: string
|
||||
reasonCode?: string
|
||||
}
|
||||
|
||||
export interface RuntimeInviteAbuseActionRequired {
|
||||
action: string
|
||||
subjectKey: string
|
||||
@@ -1208,6 +1428,23 @@ export interface RuntimeQuotaTargetDomainInput {
|
||||
count: number
|
||||
}
|
||||
|
||||
export interface RuntimeRetrievalScope {
|
||||
mode: string
|
||||
requiredDocIds: Array<string>
|
||||
requiredArtifactIds: Array<string>
|
||||
preferredSourceIds: Array<string>
|
||||
}
|
||||
|
||||
export interface RuntimeTurnScopeSnapshot {
|
||||
version: number
|
||||
resolvedAt: string
|
||||
selectors: Array<ScopeSelectorInput>
|
||||
requiredDocIds: Array<string>
|
||||
requiredArtifactIds: Array<string>
|
||||
preferredSourceIds: Array<string>
|
||||
retrieval: RuntimeRetrievalScope
|
||||
}
|
||||
|
||||
export interface RuntimeVerificationTokenRecord {
|
||||
tokenType: number
|
||||
token: string
|
||||
@@ -1215,6 +1452,20 @@ export interface RuntimeVerificationTokenRecord {
|
||||
expiresAtMs: number
|
||||
}
|
||||
|
||||
export interface RuntimeWorkspaceArtifact {
|
||||
id: string
|
||||
workspaceId: string
|
||||
contentHash: string
|
||||
displayName?: string
|
||||
fileName?: string
|
||||
canonicalMediaType: string
|
||||
size: bigint | number
|
||||
storageScope: string
|
||||
storageKey: string
|
||||
status: string
|
||||
libraryOwned: boolean
|
||||
}
|
||||
|
||||
export interface RuntimeWorkspaceInviteLinkRecord {
|
||||
workspaceId: string
|
||||
inviteId: string
|
||||
@@ -1307,6 +1558,13 @@ export interface SafeFetchResponse {
|
||||
|
||||
export declare function scanContentPolicyV1(input: ContentPolicyScanInput): ContentPolicyScanResult
|
||||
|
||||
export interface ScopeSelectorInput {
|
||||
kind: string
|
||||
id: string
|
||||
name?: string
|
||||
source: string
|
||||
}
|
||||
|
||||
export declare function signAuthSessionAccessToken(userId: string, authSessionId: string, keyId: string, secret: Buffer, issuedAt: number, expiresAt: number): string
|
||||
|
||||
export interface StorageProviderCapabilities {
|
||||
@@ -1331,6 +1589,15 @@ export interface StorageRuntimeHealth {
|
||||
bucket?: string
|
||||
}
|
||||
|
||||
export interface SyncEmbeddingStateInput {
|
||||
workspaceId: string
|
||||
enabled: boolean
|
||||
documents?: Array<DocumentEmbeddingProjectionInput>
|
||||
reconcileDocuments?: boolean
|
||||
priority?: number
|
||||
waitForReadyMs?: number
|
||||
}
|
||||
|
||||
export interface ToolContract {
|
||||
name: string
|
||||
description?: string
|
||||
@@ -1397,6 +1664,8 @@ export declare function updateLicenseSeats(request: LicenseSeatsRequest): Promis
|
||||
*/
|
||||
export declare function updateRootDocMetaTitle(rootDocBin: Buffer, docId: string, title: string): Buffer
|
||||
|
||||
export declare function validateAppConfigValue(module: string, key: string, value: any): Array<string>
|
||||
|
||||
/**
|
||||
* Check whether a Yjs update binary can be decoded without applying it to a
|
||||
* document state.
|
||||
|
||||
Reference in New Issue
Block a user