dify/web/models/app.ts
yungle246 be6612f454 feat: allow knowledge base API keys to be scoped to a single dataset
Reintroduce the nullable api_tokens.dataset_id column (dropped in 2e9819ca5b28)
so dataset API keys can opt into per-knowledge-base scoping:

- NULL dataset_id keeps today's workspace-wide behavior, so every existing key
  and the existing /datasets/api-keys create route are unchanged.
- validate_dataset_token rejects a bound key for any other dataset, and for
  endpoints that carry no dataset id (e.g. list-all), with 403.
- CachedApiToken carries dataset_id with a None default so cache entries
  written before deploy keep deserializing.
- The per-dataset console routes in apikey.py (previously dead code that 500ed
  on a missing ApiToken.dataset_id) now create bound keys; their list returns
  bound keys plus workspace keys so the dataset page shows the full access
  picture.
- Frontend: the knowledge base API access popover gains an API keys entry; the
  secret key modal accepts datasetId, shows a scope column, and offers a
  workspace / this-knowledge-base scope choice on create. New strings are
  localized for all 23 locales.
2026-06-11 11:41:47 +09:00

156 lines
3.3 KiB
TypeScript

import type {
AliyunConfig,
ArizeConfig,
DatabricksConfig,
LangFuseConfig,
LangSmithConfig,
MLflowConfig,
OpikConfig,
PhoenixConfig,
TencentConfig,
TracingProvider,
WeaveConfig,
} from '@/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/type'
import type { Dependency } from '@/app/components/plugins/types'
import type { App, AppModeEnum, SiteConfig } from '@/types/app'
export enum DSLImportMode {
YAML_CONTENT = 'yaml-content',
YAML_URL = 'yaml-url',
}
export enum DSLImportStatus {
COMPLETED = 'completed',
COMPLETED_WITH_WARNINGS = 'completed-with-warnings',
PENDING = 'pending',
FAILED = 'failed',
}
export type AppListResponse = {
data: App[]
has_more: boolean
limit: number
page: number
total: number
}
export type AppDetailResponse = App
export type DSLImportResponse = {
id: string
status: DSLImportStatus
app_mode: AppModeEnum
app_id?: string
current_dsl_version?: string
imported_dsl_version?: string
error: string
leaked_dependencies: Dependency[]
}
export type UpdateAppSiteCodeResponse = { app_id: string } & SiteConfig
export type AppDailyMessagesResponse = {
data: Array<{ date: string, message_count: number }>
}
export type AppDailyConversationsResponse = {
data: Array<{ date: string, conversation_count: number }>
}
export type WorkflowDailyConversationsResponse = {
data: Array<{ date: string, runs: number }>
}
export type AppStatisticsResponse = {
data: Array<{ date: string }>
}
export type AppDailyEndUsersResponse = {
data: Array<{ date: string, terminal_count: number }>
}
export type AppTokenCostsResponse = {
data: Array<{ date: string, token_count: number, total_price: number, currency: number }>
}
export type UpdateAppModelConfigResponse = { result: string }
type ApiKeyItemResponse = {
id: string
token: string
/** Dataset keys only: the bound dataset id, or null for workspace-scoped keys. */
dataset_id?: string | null
last_used_at: string
created_at: string
}
export type ApiKeysListResponse = {
data: ApiKeyItemResponse[]
}
export type CreateApiKeyResponse = {
id: string
token: string
dataset_id?: string | null
created_at: string
}
export type ValidateOpenAIKeyResponse = {
result: string
error?: string
}
export type UpdateOpenAIKeyResponse = ValidateOpenAIKeyResponse
export type AppVoicesListResponse = [{
name: string
value: string
}]
export type WorkflowOnlineUser = {
user_id?: string
username?: string
avatar?: string | null
sid?: string
}
export type WorkflowOnlineUsersResponse = {
data: Record<string, WorkflowOnlineUser[]> | Array<{
app_id: string
users: WorkflowOnlineUser[]
}>
}
export type TracingStatus = {
enabled: boolean
tracing_provider: TracingProvider | null
}
export type TracingConfig = {
tracing_provider: TracingProvider
tracing_config: ArizeConfig | PhoenixConfig | LangSmithConfig | LangFuseConfig | DatabricksConfig | MLflowConfig | OpikConfig | WeaveConfig | AliyunConfig | TencentConfig
}
export type WebhookTriggerResponse = {
id: string
webhook_id: string
webhook_url: string
webhook_debug_url: string
node_id: string
created_at: string
}
export type Banner = {
id: string
content: {
'category': string
'title': string
'description': string
'img-src': string
}
link: string
sort: number
status: string
created_at: string
}