mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 02:21:51 +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:
+50
-36
@@ -10,49 +10,63 @@ WHERE "id" IN (
|
||||
'copilot.providers.defaults'
|
||||
);
|
||||
|
||||
DELETE FROM "ai_workspace_byok_configs";
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF to_regclass('public.runtime_states') IS NOT NULL THEN
|
||||
DELETE FROM "runtime_states"
|
||||
WHERE "purpose" IN (
|
||||
'copilot_byok_local_lease',
|
||||
'copilot_byok_local_lease:active'
|
||||
);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
ALTER TABLE "ai_workspace_byok_configs"
|
||||
DROP COLUMN "endpoint",
|
||||
DROP COLUMN "disabled_reason",
|
||||
DROP COLUMN "last_validated_at",
|
||||
DROP COLUMN "last_validation_error",
|
||||
ADD COLUMN "definition" JSONB NOT NULL,
|
||||
ADD COLUMN "definition" JSONB NOT NULL DEFAULT '{}',
|
||||
ADD COLUMN "revision" INTEGER NOT NULL DEFAULT 1,
|
||||
ADD COLUMN "credential_generation" INTEGER NOT NULL DEFAULT 1,
|
||||
ADD COLUMN "validation" JSONB;
|
||||
|
||||
ALTER TABLE "ai_sessions_metadata"
|
||||
DROP CONSTRAINT "ai_sessions_metadata_prompt_name_fkey",
|
||||
DROP COLUMN "tokenCost";
|
||||
|
||||
UPDATE "ai_action_runs"
|
||||
SET "action_id" = 'transcript.audio'
|
||||
WHERE "action_id" = 'transcript.audio.gemini';
|
||||
|
||||
UPDATE "ai_transcript_tasks"
|
||||
SET
|
||||
"recipe_id" = 'transcript.audio',
|
||||
"input_snapshot" = "input_snapshot"::jsonb - 'providerMeta' - 'strategy',
|
||||
"public_meta" = "public_meta"::jsonb - 'providerMeta' - 'strategy',
|
||||
"protected_result" = "protected_result"::jsonb - 'providerMeta' - 'strategy'
|
||||
WHERE "recipe_id" = 'transcript.audio.gemini';
|
||||
DROP CONSTRAINT "ai_sessions_metadata_prompt_name_fkey";
|
||||
|
||||
ALTER TABLE "ai_transcript_tasks"
|
||||
DROP COLUMN "strategy";
|
||||
ALTER COLUMN "strategy" SET DEFAULT '';
|
||||
|
||||
DROP TABLE "ai_prompts_messages";
|
||||
DROP TABLE "ai_prompts_metadata";
|
||||
ALTER TABLE "ai_sessions_messages" ADD COLUMN "scope_snapshot" JSONB;
|
||||
ALTER TABLE "ai_sessions_metadata" ADD COLUMN "focus" JSONB;
|
||||
|
||||
ALTER TYPE "AiPromptRole" RENAME TO "AiSessionMessageRole";
|
||||
CREATE TABLE "workspace_artifacts" (
|
||||
"id" UUID NOT NULL,
|
||||
"workspace_id" VARCHAR NOT NULL,
|
||||
"content_hash" VARCHAR NOT NULL,
|
||||
"display_name" VARCHAR,
|
||||
"file_name" VARCHAR,
|
||||
"canonical_media_type" VARCHAR NOT NULL,
|
||||
"size_bytes" BIGINT NOT NULL,
|
||||
"storage_scope" VARCHAR NOT NULL,
|
||||
"storage_key" TEXT NOT NULL,
|
||||
"status" VARCHAR NOT NULL,
|
||||
"library_owned" BOOLEAN NOT NULL DEFAULT false,
|
||||
"reservation_expires_at" TIMESTAMPTZ(3),
|
||||
"ready_at" TIMESTAMPTZ(3),
|
||||
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "workspace_artifacts_pkey" PRIMARY KEY ("id"),
|
||||
CONSTRAINT "workspace_artifacts_library_display_name_check"
|
||||
CHECK (NOT "library_owned" OR NULLIF(BTRIM("display_name"), '') IS NOT NULL),
|
||||
CONSTRAINT "workspace_artifacts_workspace_id_fkey" FOREIGN KEY ("workspace_id") REFERENCES "workspaces"("id") ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX "workspace_artifacts_workspace_id_content_hash_key" ON "workspace_artifacts"("workspace_id", "content_hash");
|
||||
CREATE UNIQUE INDEX "workspace_artifacts_workspace_id_id_key" ON "workspace_artifacts"("workspace_id", "id");
|
||||
CREATE INDEX "workspace_artifacts_workspace_id_status_idx" ON "workspace_artifacts"("workspace_id", "status");
|
||||
CREATE INDEX "workspace_artifacts_status_reservation_expires_at_idx" ON "workspace_artifacts"("status", "reservation_expires_at");
|
||||
|
||||
CREATE TABLE "ai_message_artifacts" (
|
||||
"message_id" VARCHAR NOT NULL,
|
||||
"workspace_id" VARCHAR NOT NULL,
|
||||
"artifact_id" UUID NOT NULL,
|
||||
"role" VARCHAR NOT NULL,
|
||||
"display_name" VARCHAR,
|
||||
"metadata" JSONB,
|
||||
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "ai_message_artifacts_pkey" PRIMARY KEY ("message_id", "artifact_id", "role"),
|
||||
CONSTRAINT "ai_message_artifacts_message_id_fkey" FOREIGN KEY ("message_id") REFERENCES "ai_sessions_messages"("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "ai_message_artifacts_workspace_id_artifact_id_fkey" FOREIGN KEY ("workspace_id", "artifact_id") REFERENCES "workspace_artifacts"("workspace_id", "id") ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX "ai_message_artifacts_workspace_id_artifact_id_idx" ON "ai_message_artifacts"("workspace_id", "artifact_id");
|
||||
|
||||
-- After stable and beta no longer run binaries built with the 115-migration
|
||||
-- schema, remove the old provider keys, obsolete local-lease rows, ai_contexts,
|
||||
-- ai_context_embeddings, and ai_workspace_embeddings in one cleanup migration.
|
||||
|
||||
Reference in New Issue
Block a user