import { Readable } from 'node:stream'; declare const DEFAULT_BASE_URL = "https://api.dify.ai/v1"; declare const DEFAULT_TIMEOUT_SECONDS = 60; declare const DEFAULT_MAX_RETRIES = 3; declare const DEFAULT_RETRY_DELAY_SECONDS = 1; type RequestMethod = "GET" | "POST" | "PATCH" | "PUT" | "DELETE"; type ResponseMode = "blocking" | "streaming"; type JsonPrimitive = string | number | boolean | null; type JsonValue = JsonPrimitive | JsonObject | JsonArray; type JsonObject = { [key: string]: JsonValue; }; type JsonArray = JsonValue[]; type QueryParamValue = string | number | boolean | Array | undefined; type QueryParams = Record; type Headers = Record; type DifyRequestFile = JsonObject; type SuccessResponse = { result: "success"; }; type SuggestedQuestionsResponse = SuccessResponse & { data: string[]; }; type DifyClientConfig = { apiKey: string; baseUrl?: string; timeout?: number; maxRetries?: number; retryDelay?: number; enableLogging?: boolean; }; type DifyResponse = { data: T; status: number; headers: Headers; requestId?: string; }; type MessageFeedbackRequest = { messageId: string; user: string; rating?: "like" | "dislike" | null; content?: string | null; }; type TextToAudioRequest = { user: string; text?: string; message_id?: string; streaming?: boolean; voice?: string; }; type StreamEvent = { event?: string; data: T | string | null; raw: string; }; type DifyStream = AsyncIterable> & { data: Readable; status: number; headers: Headers; requestId?: string; toText(): Promise; toReadable(): Readable; }; type BinaryStream = { data: Readable; status: number; headers: Headers; requestId?: string; toReadable(): Readable; }; type FormDataAppendValue = Blob | string; type WebFormData = FormData; type LegacyNodeFormData = { append: (name: string, value: FormDataAppendValue, fileName?: string) => void; getHeaders: () => Headers; constructor?: { name?: string; }; }; type SdkFormData = WebFormData | LegacyNodeFormData; type HttpResponseType = "json" | "bytes" | "stream" | "arraybuffer"; type HttpRequestBody = JsonValue | Readable | SdkFormData | URLSearchParams | ArrayBuffer | ArrayBufferView | Blob | string | null; type ResponseDataFor = TResponseType extends "stream" ? Readable : TResponseType extends "bytes" | "arraybuffer" ? Buffer : JsonValue | string | null; type RawHttpResponse = { data: TData; status: number; headers: Headers; requestId?: string; url: string; }; type RequestOptions = { method: RequestMethod; path: string; query?: QueryParams; data?: HttpRequestBody; headers?: Headers; responseType?: TResponseType; }; type HttpClientSettings = Required> & { apiKey: string; }; declare class HttpClient { private settings; constructor(config: DifyClientConfig); updateApiKey(apiKey: string): void; getSettings(): HttpClientSettings; request(options: RequestOptions): Promise>; requestStream(options: RequestOptions): Promise>; requestBinaryStream(options: RequestOptions): Promise; requestRaw(options: RequestOptions): Promise>>; } declare class DifyClient { protected http: HttpClient; constructor(config: string | DifyClientConfig | HttpClient, baseUrl?: string); updateApiKey(apiKey: string): void; getHttpClient(): HttpClient; sendRequest(method: RequestMethod, endpoint: string, data?: HttpRequestBody, params?: QueryParams | null, stream?: boolean, headerParams?: Record): ReturnType; getRoot(): Promise>; getApplicationParameters(user?: string): Promise>; getParameters(user?: string): Promise>; getMeta(user?: string): Promise>; messageFeedback(request: MessageFeedbackRequest): Promise>; messageFeedback(messageId: string, rating: "like" | "dislike" | null, user: string, content?: string): Promise>; getInfo(user?: string): Promise>; getSite(user?: string): Promise>; fileUpload(form: unknown, user: string): Promise>; filePreview(fileId: string, user: string, asAttachment?: boolean): Promise>; audioToText(form: unknown, user: string): Promise>; textToAudio(request: TextToAudioRequest): Promise | BinaryStream>; textToAudio(text: string, user: string, streaming?: boolean, voice?: string): Promise | BinaryStream>; } type ChatMessageRequest = { inputs?: JsonObject; query: string; user: string; response_mode?: ResponseMode; files?: DifyRequestFile[] | null; conversation_id?: string; auto_generate_name?: boolean; workflow_id?: string; retriever_from?: "app" | "dataset"; }; type ChatMessageResponse = JsonObject; type ChatStreamEvent = StreamEvent; type ConversationSortBy = "created_at" | "-created_at" | "updated_at" | "-updated_at"; type AnnotationCreateRequest = { question: string; answer: string; }; type AnnotationReplyActionRequest = { score_threshold: number; embedding_provider_name: string; embedding_model_name: string; }; type AnnotationListOptions = { page?: number; limit?: number; keyword?: string; }; type AnnotationResponse = JsonObject; declare class ChatClient extends DifyClient { createChatMessage(request: ChatMessageRequest): Promise | DifyStream>; createChatMessage(inputs: JsonObject, query: string, user: string, stream?: boolean, conversationId?: string | null, files?: ChatMessageRequest["files"]): Promise | DifyStream>; stopChatMessage(taskId: string, user: string): Promise>; stopMessage(taskId: string, user: string): Promise>; getSuggested(messageId: string, user: string): Promise>; getAppFeedbacks(page?: number, limit?: number): Promise>; getConversations(user: string, lastId?: string | null, limit?: number | null, sortBy?: ConversationSortBy | null): Promise>; getConversationMessages(user: string, conversationId: string, firstId?: string | null, limit?: number | null): Promise>; renameConversation(conversationId: string, name: string, user: string, autoGenerate?: boolean): Promise>; renameConversation(conversationId: string, user: string, options?: { name?: string | null; autoGenerate?: boolean; }): Promise>; deleteConversation(conversationId: string, user: string): Promise>; getConversationVariables(conversationId: string, user: string, lastId?: string | null, limit?: number | null, variableName?: string | null): Promise>; updateConversationVariable(conversationId: string, variableId: string, user: string, value: JsonValue): Promise>; annotationReplyAction(action: "enable" | "disable", request: AnnotationReplyActionRequest): Promise>; getAnnotationReplyStatus(action: "enable" | "disable", jobId: string): Promise>; listAnnotations(options?: AnnotationListOptions): Promise>; createAnnotation(request: AnnotationCreateRequest): Promise>; updateAnnotation(annotationId: string, request: AnnotationCreateRequest): Promise>; deleteAnnotation(annotationId: string): Promise>; } type CompletionRequest = { inputs?: JsonObject; response_mode?: ResponseMode; user: string; files?: DifyRequestFile[] | null; retriever_from?: "app" | "dataset"; }; type CompletionResponse = JsonObject; type CompletionStreamEvent = StreamEvent; declare class CompletionClient extends DifyClient { createCompletionMessage(request: CompletionRequest): Promise | DifyStream>; createCompletionMessage(inputs: JsonObject, user: string, stream?: boolean, files?: CompletionRequest["files"]): Promise | DifyStream>; stopCompletionMessage(taskId: string, user: string): Promise>; stop(taskId: string, user: string): Promise>; runWorkflow(inputs: JsonObject, user: string, stream?: boolean): Promise | DifyStream>; } type WorkflowRunRequest = { inputs?: JsonObject; user: string; response_mode?: ResponseMode; files?: DifyRequestFile[] | null; }; type WorkflowRunResponse = JsonObject; type WorkflowStreamEvent = StreamEvent; declare class WorkflowClient extends DifyClient { run(request: WorkflowRunRequest): Promise | DifyStream>; run(inputs: JsonObject, user: string, stream?: boolean): Promise | DifyStream>; runById(workflowId: string, request: WorkflowRunRequest): Promise | DifyStream>; getRun(workflowRunId: string): Promise>; stop(taskId: string, user: string): Promise>; /** * Get workflow execution logs with filtering options. * * Note: The backend API filters by `createdByEndUserSessionId` (end user session ID) * or `createdByAccount` (account ID), not by a generic `user` parameter. */ getLogs(options?: { keyword?: string; status?: string; createdAtBefore?: string; createdAtAfter?: string; createdByEndUserSessionId?: string; createdByAccount?: string; page?: number; limit?: number; startTime?: string; endTime?: string; }): Promise>; } type DatasetListOptions = { page?: number; limit?: number; keyword?: string | null; tagIds?: string[]; includeAll?: boolean; }; type DatasetCreateRequest = { name: string; description?: string; indexing_technique?: "high_quality" | "economy"; permission?: string | null; external_knowledge_api_id?: string | null; provider?: string; external_knowledge_id?: string | null; retrieval_model?: JsonObject | null; embedding_model?: string | null; embedding_model_provider?: string | null; }; type DatasetUpdateRequest = { name?: string; description?: string | null; indexing_technique?: "high_quality" | "economy" | null; permission?: string | null; embedding_model?: string | null; embedding_model_provider?: string | null; retrieval_model?: JsonObject | null; partial_member_list?: Array> | null; external_retrieval_model?: JsonObject | null; external_knowledge_id?: string | null; external_knowledge_api_id?: string | null; }; type DocumentStatusAction = "enable" | "disable" | "archive" | "un_archive"; type DatasetTagCreateRequest = { name: string; }; type DatasetTagUpdateRequest = { tag_id: string; name: string; }; type DatasetTagDeleteRequest = { tag_id: string; }; type DatasetTagBindingRequest = { tag_ids: string[]; target_id: string; }; type DatasetTagUnbindingRequest = { tag_id: string; target_id: string; }; type DocumentTextCreateRequest = { name: string; text: string; process_rule?: JsonObject | null; original_document_id?: string | null; doc_form?: string; doc_language?: string; indexing_technique?: string | null; retrieval_model?: JsonObject | null; embedding_model?: string | null; embedding_model_provider?: string | null; }; type DocumentTextUpdateRequest = { name?: string | null; text?: string | null; process_rule?: JsonObject | null; doc_form?: string; doc_language?: string; retrieval_model?: JsonObject | null; }; type DocumentListOptions = { page?: number; limit?: number; keyword?: string | null; status?: string | null; }; type DocumentGetOptions = { metadata?: "all" | "only" | "without"; }; type SegmentCreateRequest = { segments: JsonObject[]; }; type SegmentUpdateRequest = { segment: { content?: string | null; answer?: string | null; keywords?: string[] | null; regenerate_child_chunks?: boolean; enabled?: boolean | null; attachment_ids?: string[] | null; }; }; type SegmentListOptions = { page?: number; limit?: number; status?: string[]; keyword?: string | null; }; type ChildChunkCreateRequest = { content: string; }; type ChildChunkUpdateRequest = { content: string; }; type ChildChunkListOptions = { page?: number; limit?: number; keyword?: string | null; }; type MetadataCreateRequest = { type: "string" | "number" | "time"; name: string; }; type MetadataUpdateRequest = { name: string; value?: string | number | null; }; type DocumentMetadataDetail = { id: string; name: string; value?: string | number | null; }; type DocumentMetadataOperation = { document_id: string; metadata_list: DocumentMetadataDetail[]; partial_update?: boolean; }; type MetadataOperationRequest = { operation_data: DocumentMetadataOperation[]; }; type HitTestingRequest = { query?: string | null; retrieval_model?: JsonObject | null; external_retrieval_model?: JsonObject | null; attachment_ids?: string[] | null; }; type DatasourcePluginListOptions = { isPublished?: boolean; }; type DatasourceNodeRunRequest = { inputs: JsonObject; datasource_type: string; credential_id?: string | null; is_published: boolean; }; type PipelineRunRequest = { inputs: JsonObject; datasource_type: string; datasource_info_list: JsonObject[]; start_node_id: string; is_published: boolean; response_mode: ResponseMode; }; type KnowledgeBaseResponse = JsonObject; type PipelineStreamEvent = JsonObject; declare class KnowledgeBaseClient extends DifyClient { listDatasets(options?: DatasetListOptions): Promise>; createDataset(request: DatasetCreateRequest): Promise>; getDataset(datasetId: string): Promise>; updateDataset(datasetId: string, request: DatasetUpdateRequest): Promise>; deleteDataset(datasetId: string): Promise>; updateDocumentStatus(datasetId: string, action: DocumentStatusAction, documentIds: string[]): Promise>; listTags(): Promise>; createTag(request: DatasetTagCreateRequest): Promise>; updateTag(request: DatasetTagUpdateRequest): Promise>; deleteTag(request: DatasetTagDeleteRequest): Promise>; bindTags(request: DatasetTagBindingRequest): Promise>; unbindTags(request: DatasetTagUnbindingRequest): Promise>; getDatasetTags(datasetId: string): Promise>; createDocumentByText(datasetId: string, request: DocumentTextCreateRequest): Promise>; updateDocumentByText(datasetId: string, documentId: string, request: DocumentTextUpdateRequest): Promise>; createDocumentByFile(datasetId: string, form: unknown): Promise>; updateDocumentByFile(datasetId: string, documentId: string, form: unknown): Promise>; listDocuments(datasetId: string, options?: DocumentListOptions): Promise>; getDocument(datasetId: string, documentId: string, options?: DocumentGetOptions): Promise>; deleteDocument(datasetId: string, documentId: string): Promise>; getDocumentIndexingStatus(datasetId: string, batch: string): Promise>; createSegments(datasetId: string, documentId: string, request: SegmentCreateRequest): Promise>; listSegments(datasetId: string, documentId: string, options?: SegmentListOptions): Promise>; getSegment(datasetId: string, documentId: string, segmentId: string): Promise>; updateSegment(datasetId: string, documentId: string, segmentId: string, request: SegmentUpdateRequest): Promise>; deleteSegment(datasetId: string, documentId: string, segmentId: string): Promise>; createChildChunk(datasetId: string, documentId: string, segmentId: string, request: ChildChunkCreateRequest): Promise>; listChildChunks(datasetId: string, documentId: string, segmentId: string, options?: ChildChunkListOptions): Promise>; updateChildChunk(datasetId: string, documentId: string, segmentId: string, childChunkId: string, request: ChildChunkUpdateRequest): Promise>; deleteChildChunk(datasetId: string, documentId: string, segmentId: string, childChunkId: string): Promise>; listMetadata(datasetId: string): Promise>; createMetadata(datasetId: string, request: MetadataCreateRequest): Promise>; updateMetadata(datasetId: string, metadataId: string, request: MetadataUpdateRequest): Promise>; deleteMetadata(datasetId: string, metadataId: string): Promise>; listBuiltInMetadata(datasetId: string): Promise>; updateBuiltInMetadata(datasetId: string, action: "enable" | "disable"): Promise>; updateDocumentsMetadata(datasetId: string, request: MetadataOperationRequest): Promise>; hitTesting(datasetId: string, request: HitTestingRequest): Promise>; retrieve(datasetId: string, request: HitTestingRequest): Promise>; listDatasourcePlugins(datasetId: string, options?: DatasourcePluginListOptions): Promise>; runDatasourceNode(datasetId: string, nodeId: string, request: DatasourceNodeRunRequest): Promise>; runPipeline(datasetId: string, request: PipelineRunRequest): Promise | DifyStream>; uploadPipelineFile(form: unknown): Promise>; } type WorkspaceModelType = string; type WorkspaceModelsResponse = JsonObject; declare class WorkspaceClient extends DifyClient { getModelsByType(modelType: WorkspaceModelType): Promise>; } type DifyErrorOptions = { statusCode?: number; responseBody?: unknown; requestId?: string; retryAfter?: number; cause?: unknown; }; declare class DifyError extends Error { statusCode?: number; responseBody?: unknown; requestId?: string; retryAfter?: number; constructor(message: string, options?: DifyErrorOptions); } declare class APIError extends DifyError { constructor(message: string, options?: DifyErrorOptions); } declare class AuthenticationError extends APIError { constructor(message: string, options?: DifyErrorOptions); } declare class RateLimitError extends APIError { constructor(message: string, options?: DifyErrorOptions); } declare class ValidationError extends APIError { constructor(message: string, options?: DifyErrorOptions); } declare class NetworkError extends DifyError { constructor(message: string, options?: DifyErrorOptions); } declare class TimeoutError extends DifyError { constructor(message: string, options?: DifyErrorOptions); } declare class FileUploadError extends DifyError { constructor(message: string, options?: DifyErrorOptions); } declare const BASE_URL = "https://api.dify.ai/v1"; declare const routes: { feedback: { method: string; url: (messageId: string) => string; }; application: { method: string; url: () => string; }; fileUpload: { method: string; url: () => string; }; filePreview: { method: string; url: (fileId: string) => string; }; textToAudio: { method: string; url: () => string; }; audioToText: { method: string; url: () => string; }; getMeta: { method: string; url: () => string; }; getInfo: { method: string; url: () => string; }; getSite: { method: string; url: () => string; }; createCompletionMessage: { method: string; url: () => string; }; stopCompletionMessage: { method: string; url: (taskId: string) => string; }; createChatMessage: { method: string; url: () => string; }; getSuggested: { method: string; url: (messageId: string) => string; }; stopChatMessage: { method: string; url: (taskId: string) => string; }; getConversations: { method: string; url: () => string; }; getConversationMessages: { method: string; url: () => string; }; renameConversation: { method: string; url: (conversationId: string) => string; }; deleteConversation: { method: string; url: (conversationId: string) => string; }; runWorkflow: { method: string; url: () => string; }; stopWorkflow: { method: string; url: (taskId: string) => string; }; }; export { APIError, type AnnotationCreateRequest, type AnnotationListOptions, type AnnotationReplyActionRequest, type AnnotationResponse, AuthenticationError, BASE_URL, type BinaryStream, ChatClient, type ChatMessageRequest, type ChatMessageResponse, type ChatStreamEvent, type ChildChunkCreateRequest, type ChildChunkListOptions, type ChildChunkUpdateRequest, CompletionClient, type CompletionRequest, type CompletionResponse, type CompletionStreamEvent, type ConversationSortBy, DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_DELAY_SECONDS, DEFAULT_TIMEOUT_SECONDS, type DatasetCreateRequest, type DatasetListOptions, type DatasetTagBindingRequest, type DatasetTagCreateRequest, type DatasetTagDeleteRequest, type DatasetTagUnbindingRequest, type DatasetTagUpdateRequest, type DatasetUpdateRequest, type DatasourceNodeRunRequest, type DatasourcePluginListOptions, DifyClient, type DifyClientConfig, DifyError, type DifyErrorOptions, type DifyRequestFile, type DifyResponse, type DifyStream, type DocumentGetOptions, type DocumentListOptions, type DocumentMetadataDetail, type DocumentMetadataOperation, type DocumentStatusAction, type DocumentTextCreateRequest, type DocumentTextUpdateRequest, FileUploadError, type Headers, type HitTestingRequest, HttpClient, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, KnowledgeBaseClient, type KnowledgeBaseResponse, type MessageFeedbackRequest, type MetadataCreateRequest, type MetadataOperationRequest, type MetadataUpdateRequest, NetworkError, type PipelineRunRequest, type PipelineStreamEvent, type QueryParamValue, type QueryParams, RateLimitError, type RequestMethod, type ResponseMode, type SegmentCreateRequest, type SegmentListOptions, type SegmentUpdateRequest, type StreamEvent, type SuccessResponse, type SuggestedQuestionsResponse, type TextToAudioRequest, TimeoutError, ValidationError, WorkflowClient, type WorkflowRunRequest, type WorkflowRunResponse, type WorkflowStreamEvent, WorkspaceClient, type WorkspaceModelType, type WorkspaceModelsResponse, routes };