import type { CreateArtifactRequest, CreateArtifactResponse, RunNodeScriptJobRequest, RunNodeScriptJobResponse, GetToolJobResponse, LoginRequest, LoginResponse, LoginOptions, CreateSessionRequest, SessionEnvelopeResponse, ChatRequest, ChatResponse, StreamEvent, StreamingChatRequest, SemanticSearchRequest, SemanticSearchResponse, WilliNetzSemanticSearchRequest, WilliNetzSemanticSearchResponse, WilliNetzChatRequest, WilliNetzChatResponse, CombinedSemanticSearchRequest, CombinedSemanticSearchResponse, CombinedChatRequest, CombinedChatResponse, ReasoningGenerateRequest, ReasoningGenerateResponse, ContextResolveRequest, ContextResolveResponse, ClarificationAnalyzeRequest, ClarificationAnalyzeResponse, GenerateToolScriptRequest, GenerateToolScriptJobOperationResponse, RepairGenerateToolScriptRequest, UploadDocumentRequest, UploadDocumentResponse, UploadMultipleDocumentsRequest, UploadMultipleDocumentsResponse, ListDocumentsQuery, ListDocumentsResponse, GetDocumentResponse, UpdateDocumentRequest, UpdateDocumentResponse, ToggleAiContextResponse, ReprocessDocumentResponse, AnalyzeEdifactMessageRequest, AnalyzeEdifactMessageResponse, EdifactChatRequest, EdifactChatResponse, ExplainEdifactMessageRequest, ExplainEdifactMessageResponse, ValidateEdifactMessageRequest, ValidateEdifactMessageResponse, ModifyEdifactMessageRequest, ModifyEdifactMessageResponse, MarketPartnerSearchQuery, MarketPartnerSearchResponse, StructuredDataQueryRequest, StructuredDataQueryResponse, ResolveIntentRequest, ResolveIntentResponse, GetProvidersResponse, GetProvidersHealthResponse, ChatCompletionRequest, ChatCompletionResponse } from './types.js'; declare const openApiDocument: Record; export * from './types.js'; export * from './tool-generation.js'; /** * Default base URL pointing to the productive Willi-Mako API v2 endpoint. * Located at: https://stromhaltig.de/api/v2 */ export declare const DEFAULT_BASE_URL = "https://stromhaltig.de/api/v2"; /** * Pre-bundled OpenAPI 3.0 specification for the Willi-Mako API v2. * This schema is included in the package for offline access and code generation tools. */ export declare const bundledOpenApiDocument: Record; /** * Configuration options for the WilliMakoClient. */ export interface WilliMakoClientOptions { /** * Base URL of the Willi-Mako API. Defaults to the productive environment. * @default "https://stromhaltig.de/api/v2" */ baseUrl?: string; /** * Bearer token for API authentication. * Falls back to the WILLI_MAKO_TOKEN environment variable if not provided. * @default process.env.WILLI_MAKO_TOKEN */ token?: string | null; /** * Custom fetch implementation for testing or polyfills. * @default globalThis.fetch */ fetch?: typeof fetch; } /** * Additional options for individual API requests. */ export interface RequestOptions extends RequestInit { /** * Skip attaching the Authorization header for public endpoints. * @default false */ skipAuth?: boolean; } /** * Custom error class for Willi-Mako API failures. * Provides structured access to HTTP status codes and response bodies. * * @example * ```typescript * try { * await client.createArtifact(request); * } catch (error) { * if (error instanceof WilliMakoError) { * console.error(`API error ${error.status}:`, error.body); * } * } * ``` */ /** * Custom error class for Willi-Mako API failures. * Provides structured access to HTTP status codes and response bodies. * * @example * ```typescript * try { * await client.createArtifact(request); * } catch (error) { * if (error instanceof WilliMakoError) { * console.error(`API error ${error.status}:`, error.body); * } * } * ``` */ export declare class WilliMakoError extends Error { /** HTTP status code of the failed request */ readonly status: number; /** Parsed response body (may be an error object or text) */ readonly body: unknown; constructor(message: string, status: number, body: unknown); } /** * Official TypeScript client for the Willi-Mako API v2. * * Willi-Mako is the knowledge and automation platform for energy market communication * (Marktkommunikation) in the German energy sector. This client provides type-safe * access to APIs for: * * - **EDIFACT/edi@energy processing**: Parse, validate, and transform messages * like UTILMD, MSCONS, ORDERS according to market communication standards * - **Tooling Sandbox**: Execute Node.js scripts in a secure environment for * testing parsing logic, validation rules, or data transformations * - **Artifact Storage**: Store and retrieve ETL outputs, compliance reports, * validation results, or EDIFACT message snapshots * - **Market Roles & Billing**: Access reference data for market locations * (Marktlokationen), billing periods, and energy supplier relationships * * @example * **Basic Usage** * ```typescript * import { WilliMakoClient } from 'willi-mako-client'; * * const client = new WilliMakoClient({ * token: process.env.WILLI_MAKO_TOKEN * }); * * // Fetch the API schema * const schema = await client.getRemoteOpenApiDocument(); * console.log(schema.info.title); * ``` * * @example * **Testing EDIFACT Parsing Logic** * ```typescript * const job = await client.createNodeScriptJob({ * sessionId: 'my-session-id', * source: ` * // Parse UTILMD message segments * const message = 'UNH+1+UTILMD:D:04B:UN:2.3e'; * const segments = message.split('+'); * console.log('Message type:', segments[1]); * `, * timeoutMs: 5000 * }); * * console.log('Job status:', job.data.job.status); * * // Poll for results * const result = await client.getToolJob(job.data.job.id); * if (result.data.job.status === 'succeeded') { * console.log('Output:', result.data.job.result?.stdout); * } * ``` * * @example * **Storing Validation Results** * ```typescript * await client.createArtifact({ * sessionId: 'my-session-id', * type: 'validation-report', * name: 'utilmd-validation-2024-03.json', * mimeType: 'application/json', * encoding: 'utf8', * content: JSON.stringify({ * timestamp: new Date().toISOString(), * validMessages: 142, * errors: [] * }), * tags: ['utilmd', 'validation', 'Q1-2024'] * }); * ``` */ export declare class WilliMakoClient { private baseUrl; private token; private readonly fetchImpl; /** * Creates a new Willi-Mako API client instance. * * @param options - Configuration options for the client * * @example * ```typescript * // Use default productive endpoint with token from environment * const client = new WilliMakoClient(); * * // Provide token explicitly * const client = new WilliMakoClient({ * token: 'your-bearer-token' * }); * * // Use custom base URL (e.g., for testing) * const client = new WilliMakoClient({ * baseUrl: 'http://localhost:3000/api/v2', * token: 'test-token' * }); * ``` */ constructor(options?: WilliMakoClientOptions); /** * Updates the bearer token used for API authentication. * Useful for implementing token refresh logic or switching between different user sessions. * * @param token - The new bearer token, or null to clear authentication * * @example * ```typescript * client.setToken('new-token-after-refresh'); * ``` */ setToken(token: string | null): void; /** * Performs a credential based login flow to obtain a JWT bearer token. * On success the token is automatically stored on the client instance. * * @param credentials - Email/password combination issued by the platform * @returns Login response including the access token and expiry timestamp */ login(credentials: LoginRequest, options?: LoginOptions): Promise; /** * Returns the currently configured base URL. * * @returns The base URL (without trailing slash) */ getBaseUrl(): string; /** * Creates a new workspace session. Sessions group tooling jobs, artefacts and * conversational state. They also carry policy information such as market role. */ createSession(payload?: CreateSessionRequest): Promise; /** * Retrieves the metadata of an existing session. */ getSession(sessionId: string): Promise; /** * Deletes a session and all associated sandbox jobs / artefacts. */ deleteSession(sessionId: string): Promise; /** * Sends a conversational message to the Willi-Mako chat endpoint. * * ⚠️ **WARNING**: This method is synchronous and waits for complete AI processing. * For long-running operations (> 90 seconds), use `chatStreaming()` or `chatWithPolling()` * to avoid 504 Gateway Timeout errors from Cloudflare. * * @see {@link chatStreaming} for streaming alternative with real-time progress updates * @see {@link chatWithPolling} for polling-based workflow (API v1.0.2+) * @see {@link ask} for high-level helper with automatic streaming */ chat(payload: ChatRequest): Promise; /** * Sends a message via Server-Sent Events (SSE) streaming. * **Recommended for long-running AI operations (> 90 seconds)** with real-time progress. * * ✅ **SOLVED in API v1.0.2**: The streaming endpoint now sends heartbeat events every 30 seconds * during AI processing, preventing Cloudflare timeout issues. Streaming is production-ready. * * This method uses the `/api/chat/chats/{chatId}/messages/stream` endpoint which provides * real-time progress updates and works reliably for operations that take several minutes. * * For environments where SSE is problematic, consider using {@link chatWithPolling} instead. * * @param chatId - The legacyChatId from session creation (see {@link createSession}) * @param payload - Message content and optional context settings * @param onProgress - Optional callback for progress events (status, progress percentage) * @returns Final completion event with user and assistant messages * * @throws {WilliMakoError} When the stream fails or returns an error event * * @example * ```typescript * const session = await client.createSession(); * const result = await client.chatStreaming( * session.data.legacyChatId!, * { content: 'Erkläre den GPKE-Prozess im Detail' }, * (event) => { * console.log(`${event.message} (${event.progress}%)`); * } * ); * console.log(result.data.assistantMessage.content); * ``` */ chatStreaming(chatId: string, payload: StreamingChatRequest, onProgress?: (event: StreamEvent) => void): Promise; /** * High-level helper for streaming chat with automatic session management. * * ✅ **SOLVED in API v1.0.2**: The streaming endpoint now sends heartbeat events every 30 seconds * during AI processing, preventing Cloudflare timeout issues. Both streaming and polling are * production-ready approaches. * * This method creates a session automatically, sends the message via streaming, * and returns the assistant's response. Perfect for one-off questions or scripts * that don't need to maintain session state. * * @param question - The question or message to send * @param contextSettings - Optional context settings (e.g., companiesOfInterest) * @param onProgress - Optional callback for progress updates (status message, progress %) * @returns The assistant's message object with content and metadata * * @example * ```typescript * const response = await client.ask( * 'Erkläre GPKE im Detail', * { companiesOfInterest: ['Enerchy'] }, * (status, progress) => console.log(`${status} (${progress}%)`) * ); * console.log(response.content); * ``` */ ask(question: string, contextSettings?: Record, onProgress?: (status: string, progress: number) => void): Promise; /** * Executes a hybrid semantic search against the knowledge base. */ semanticSearch(payload: SemanticSearchRequest): Promise; /** * Executes a semantic search against the willi-netz collection. * The willi-netz collection is specialized on network management, regulation, TAB, and asset management. * Contains: Energy law (EnWG, StromNEV, ARegV), BNetzA regulations & monitoring reports, * TAB from network operators, BDEW guidelines, VDE-FNN instructions, Asset Management (ISO 55000). */ williNetzSemanticSearch(payload: WilliNetzSemanticSearchRequest): Promise; /** * Chat interaction based on the willi-netz collection. * Ideal for questions about: BNetzA regulation, incentive regulation (ARegV), * technical connection requirements, §14a EnWG, smart meters, e-mobility, storage, supply quality. */ williNetzChat(payload: WilliNetzChatRequest): Promise; /** * Executes a combined semantic search across both willi_mako and willi-netz collections. * Results include sourceCollection information in the payload. * Ideal for cross-cutting research covering both market processes and regulatory/technical network topics. */ combinedSemanticSearch(payload: CombinedSemanticSearchRequest): Promise; /** * Chat interaction with access to both willi_mako and willi-netz collections. * Automatically uses the most relevant collection based on the request. * Ideal for complex questions covering both market communication aspects (EDIFACT, supplier switch) * and regulatory/technical network topics (network fees, TAB, §14a EnWG). */ combinedChat(payload: CombinedChatRequest): Promise; /** * Triggers the advanced reasoning pipeline. */ generateReasoning(payload: ReasoningGenerateRequest): Promise; /** * Resolves the most relevant context for a user query. */ resolveContext(payload: ContextResolveRequest): Promise; /** * Analyzes whether clarification questions are required before continuing. */ analyzeClarification(payload: ClarificationAnalyzeRequest): Promise; /** * Returns the bundled OpenAPI 3.0 specification. * This is the schema that was bundled with this package version. * * @returns The OpenAPI document object * * @example * ```typescript * const schema = client.getBundledOpenApiDocument(); * console.log('API version:', schema.info.version); * ``` */ getBundledOpenApiDocument(): typeof openApiDocument; /** * Fetches the current OpenAPI specification from the remote API. * Use this to get the most up-to-date schema, which may include newer * endpoints or fields not yet available in the bundled version. * * @returns Promise resolving to the OpenAPI document * * @example * ```typescript * const remoteSchema = await client.getRemoteOpenApiDocument(); * console.log('Available endpoints:', Object.keys(remoteSchema.paths)); * ``` */ getRemoteOpenApiDocument(): Promise; /** * Creates a new Node.js sandbox job for executing custom scripts. * * The tooling sandbox provides a secure environment for running JavaScript/TypeScript * code. Common use cases include: * - Testing EDIFACT parsing logic before production deployment * - Validating market communication message structures * - Prototyping data transformations for ETL pipelines * - Running compliance checks on energy data * * Jobs are executed asynchronously. Use {@link getToolJob} to poll for results. * * @param payload - Job creation request with source code and configuration * @returns Promise resolving to the created job with initial status * * @example * ```typescript * const job = await client.createNodeScriptJob({ * sessionId: 'session-uuid', * source: ` * // Parse MSCONS (meter reading) message * const reading = 'SEQ+Z02+1234'; * const parts = reading.split('+'); * console.log('Reading value:', parts[2]); * `, * timeoutMs: 3000, * metadata: { messageType: 'MSCONS', purpose: 'parsing-test' } * }); * * console.log('Job ID:', job.data.job.id); * console.log('Initial status:', job.data.job.status); * ``` */ createNodeScriptJob(payload: RunNodeScriptJobRequest): Promise; /** * Retrieves the current status and results of a tooling job. * * Use this method to poll for job completion after creating a job with * {@link createNodeScriptJob}. Jobs may take time to execute depending * on queue length and code complexity. * * @param jobId - The unique identifier of the job * @returns Promise resolving to the job details including status and results * * @example * ```typescript * // Poll until job completes * let job = await client.getToolJob('job-uuid'); * * while (job.data.job.status === 'queued' || job.data.job.status === 'running') { * await new Promise(resolve => setTimeout(resolve, 1000)); * job = await client.getToolJob('job-uuid'); * } * * if (job.data.job.status === 'succeeded') { * console.log('Output:', job.data.job.result?.stdout); * } else { * console.error('Error:', job.data.job.result?.error); * } * ``` */ getToolJob(jobId: string): Promise; /** * Creates a new artifact to store data snapshots, reports, or EDIFACT messages. * * Artifacts are versioned data objects associated with a session. They serve as * an audit trail for ETL processes and can be used to: * - Store imported EDIFACT messages (UTILMD, MSCONS, ORDERS, etc.) * - Save validation or compliance reports * - Archive ETL transformation results * - Keep meter reading snapshots for billing periods * * @param payload - Artifact creation request with content and metadata * @returns Promise resolving to the created artifact details * * @example * **Store an EDIFACT Message** * ```typescript * await client.createArtifact({ * sessionId: 'session-uuid', * type: 'edifact-message', * name: 'UTILMD_Stammdaten_2024-03-15.edi', * mimeType: 'text/plain', * encoding: 'utf8', * content: 'UNH+1+UTILMD:D:04B:UN:2.3e...', * description: 'Stammdatenänderung für Marktlokation DE0001234567890', * tags: ['utilmd', 'stammdaten', 'march-2024'], * version: '1.0' * }); * ``` * * @example * **Store a Validation Report** * ```typescript * const report = { * timestamp: new Date().toISOString(), * messageType: 'MSCONS', * totalMessages: 150, * validMessages: 148, * errors: [ * { line: 42, message: 'Invalid meter ID format' } * ] * }; * * await client.createArtifact({ * sessionId: 'session-uuid', * type: 'validation-report', * name: 'mscons-validation-2024-Q1.json', * mimeType: 'application/json', * encoding: 'utf8', * content: JSON.stringify(report, null, 2), * tags: ['mscons', 'validation', 'Q1-2024'] * }); * ``` */ createArtifact(payload: CreateArtifactRequest): Promise; /** * Generates a deterministic Node.js tooling script using the dedicated tooling endpoint. */ generateToolScript(payload: GenerateToolScriptRequest): Promise; /** * Requests an automatic repair attempt for a failed tooling generation job. */ repairToolScript(payload: RepairGenerateToolScriptRequest): Promise; /** * Uploads a single document to the knowledge base. * * Documents can be PDF, DOCX, TXT, or MD files (max 50MB). They are automatically * processed for text extraction and can be included in semantic search and AI chat * when `is_ai_context_enabled` is true. * * @param payload - Document upload request with file and metadata * @returns Promise resolving to the uploaded document details * * @example * ```typescript * import { readFileSync } from 'fs'; * * const fileBuffer = readFileSync('./compliance-guide.pdf'); * const response = await client.uploadDocument({ * file: fileBuffer, * title: 'GPKE Compliance Guide 2024', * description: 'Internal compliance documentation for GPKE processes', * tags: ['gpke', 'compliance', '2024'], * is_ai_context_enabled: true * }); * * console.log('Document ID:', response.data.document.id); * ``` */ uploadDocument(payload: UploadDocumentRequest): Promise; /** * Uploads multiple documents at once (max 10 files). * * @param payload - Multiple document upload request * @returns Promise resolving to array of uploaded documents * * @example * ```typescript * import { readFileSync } from 'fs'; * * const files = [ * readFileSync('./doc1.pdf'), * readFileSync('./doc2.pdf') * ]; * * const response = await client.uploadMultipleDocuments({ * files: files, * is_ai_context_enabled: true * }); * * console.log(`Uploaded ${response.data.documents.length} documents`); * ``` */ uploadMultipleDocuments(payload: UploadMultipleDocumentsRequest): Promise; /** * Lists all documents with optional pagination, search, and filtering. * * @param query - Query parameters for filtering and pagination * @returns Promise resolving to paginated list of documents * * @example * ```typescript * // Get first page with default settings * const response = await client.listDocuments(); * * // Search for specific documents * const searchResults = await client.listDocuments({ * search: 'GPKE', * processed: true, * page: 1, * limit: 20 * }); * * console.log(`Found ${searchResults.data.pagination.total} documents`); * searchResults.data.documents.forEach(doc => { * console.log(`- ${doc.title} (${doc.file_size} bytes)`); * }); * ``` */ listDocuments(query?: ListDocumentsQuery): Promise; /** * Retrieves a single document by its ID. * * @param documentId - The unique document identifier * @returns Promise resolving to the document details * * @example * ```typescript * const document = await client.getDocument('doc-uuid'); * console.log('Title:', document.data.title); * console.log('Processed:', document.data.is_processed); * console.log('Extracted text length:', document.data.extracted_text_length); * ``` */ getDocument(documentId: string): Promise; /** * Updates document metadata (title, description, tags, AI context setting). * * @param documentId - The unique document identifier * @param payload - Fields to update * @returns Promise resolving to the updated document * * @example * ```typescript * const updated = await client.updateDocument('doc-uuid', { * title: 'Updated GPKE Guide 2024', * description: 'Revised compliance documentation', * tags: ['gpke', 'compliance', '2024', 'revised'], * is_ai_context_enabled: true * }); * ``` */ updateDocument(documentId: string, payload: UpdateDocumentRequest): Promise; /** * Deletes a document permanently. * * @param documentId - The unique document identifier * @returns Promise that resolves when the document is deleted * * @example * ```typescript * await client.deleteDocument('doc-uuid'); * console.log('Document deleted successfully'); * ``` */ deleteDocument(documentId: string): Promise; /** * Downloads the original document file. * * @param documentId - The unique document identifier * @returns Promise resolving to the file content as ArrayBuffer * * @example * ```typescript * import { writeFileSync } from 'fs'; * * const fileData = await client.downloadDocument('doc-uuid'); * writeFileSync('./downloaded.pdf', Buffer.from(fileData)); * ``` */ downloadDocument(documentId: string): Promise; /** * Triggers reprocessing of a document (re-extraction of text and re-embedding). * * Useful when a document failed to process initially or when you want to * refresh the extracted content with updated processing logic. * * @param documentId - The unique document identifier * @returns Promise resolving to the reprocessing status message * * @example * ```typescript * const response = await client.reprocessDocument('doc-uuid'); * console.log(response.data.message); // "Reprocessing started" * ``` */ reprocessDocument(documentId: string): Promise; /** * Toggles whether a document should be included in AI context for chat and reasoning. * * When enabled, the document's content will be available to semantic search and * can be referenced in chat responses and reasoning pipelines. * * @param documentId - The unique document identifier * @param enabled - Whether to enable or disable AI context * @returns Promise resolving to the updated document * * @example * ```typescript * // Enable AI context for a document * await client.toggleAiContext('doc-uuid', true); * * // Disable AI context * await client.toggleAiContext('doc-uuid', false); * ``` */ toggleAiContext(documentId: string, enabled: boolean): Promise; /** * Analyzes an EDIFACT message structurally. * * Performs a structural analysis of an EDIFACT message, extracts segments, * and enriches them with code lookup information from BDEW/EIC databases. * * @param payload - Request containing the EDIFACT message to analyze * @returns Promise resolving to the analysis result with structured data * * @example * ```typescript * const analysis = await client.analyzeEdifactMessage({ * message: 'UNH+00000000001111+MSCONS:D:11A:UN:2.6e\\nBGM+E01+1234567890+9\\nUNT+3+00000000001111' * }); * * console.log('Format:', analysis.data.format); * console.log('Summary:', analysis.data.summary); * console.log('Segments:', analysis.data.structuredData.segments.length); * * analysis.data.structuredData.segments.forEach(segment => { * console.log(`${segment.tag}: ${segment.description}`); * if (segment.resolvedCodes) { * console.log('Resolved codes:', segment.resolvedCodes); * } * }); * ``` */ analyzeEdifactMessage(payload: AnalyzeEdifactMessageRequest): Promise; /** * Enables interactive chat about an EDIFACT message. * * Ask questions and have discussions about an EDIFACT message with a context-aware * AI assistant that understands market communication standards and EDIFACT structure. * * @param payload - Request with message, chat history, and current EDIFACT context * @returns Promise resolving to the AI assistant's response * * @example * ```typescript * const edifactMessage = 'UNH+1+MSCONS:D:11A:UN:2.6e\\n...'; * * // First question * const response1 = await client.chatAboutEdifactMessage({ * message: 'Welche Zählernummer ist in dieser Nachricht enthalten?', * currentEdifactMessage: edifactMessage * }); * * console.log('Answer:', response1.data.response); * * // Follow-up question with history * const response2 = await client.chatAboutEdifactMessage({ * message: 'In welchem Zeitfenster ist der Verbrauch am höchsten?', * chatHistory: [ * { role: 'user', content: 'Welche Zählernummer ist in dieser Nachricht enthalten?' }, * { role: 'assistant', content: response1.data.response } * ], * currentEdifactMessage: edifactMessage * }); * ``` */ chatAboutEdifactMessage(payload: EdifactChatRequest): Promise; /** * Generates a human-readable explanation of an EDIFACT message. * * Uses LLM and expert knowledge to create a structured, understandable explanation * of what the EDIFACT message contains and represents in business terms. * * @param payload - Request containing the EDIFACT message to explain * @returns Promise resolving to the generated explanation * * @example * ```typescript * const explanation = await client.explainEdifactMessage({ * message: 'UNH+1+UTILMD:D:04B:UN:2.3e\\nBGM+E01+123456+9\\n...' * }); * * console.log('Explanation:'); * console.log(explanation.data.explanation); * ``` */ explainEdifactMessage(payload: ExplainEdifactMessageRequest): Promise; /** * Validates an EDIFACT message structurally and semantically. * * Performs comprehensive validation with detailed error and warning lists. * Checks both EDIFACT structure and business logic according to market communication rules. * * @param payload - Request containing the EDIFACT message to validate * @returns Promise resolving to the validation result with errors and warnings * * @example * ```typescript * const validation = await client.validateEdifactMessage({ * message: 'UNH+1+MSCONS:D:11A:UN:2.6e\\n...' * }); * * console.log('Valid:', validation.data.isValid); * console.log('Message Type:', validation.data.messageType); * console.log('Segments:', validation.data.segmentCount); * * if (validation.data.errors.length > 0) { * console.log('Errors:'); * validation.data.errors.forEach(error => console.log(` - ${error}`)); * } * * if (validation.data.warnings.length > 0) { * console.log('Warnings:'); * validation.data.warnings.forEach(warning => console.log(` - ${warning}`)); * } * ``` */ validateEdifactMessage(payload: ValidateEdifactMessageRequest): Promise; /** * Modifies an EDIFACT message based on natural language instructions. * * Uses AI to understand and apply modifications while maintaining valid EDIFACT structure. * Perfect for testing scenarios or creating message variants. * * @param payload - Request with modification instruction and current message * @returns Promise resolving to the modified message and validation status * * @example * ```typescript * const modified = await client.modifyEdifactMessage({ * instruction: 'Erhöhe den Verbrauch in jedem Zeitfenster um 10%', * currentMessage: 'UNH+1+MSCONS:D:11A:UN:2.6e\\n...' * }); * * console.log('Modified message:'); * console.log(modified.data.modifiedMessage); * console.log('Valid:', modified.data.isValid); * * // Save modified message * await client.createArtifact({ * sessionId: 'session-uuid', * type: 'edifact-message', * name: 'modified-mscons.edi', * mimeType: 'text/plain', * encoding: 'utf8', * content: modified.data.modifiedMessage, * tags: ['mscons', 'modified'] * }); * ``` */ modifyEdifactMessage(payload: ModifyEdifactMessageRequest): Promise; /** * Searches for market partners using BDEW/EIC codes, company names, cities, etc. * This is a public endpoint that does not require authentication. * * @param query - Search parameters including the search term, optional limit, and optional role filter * @returns Search results containing market partner information * * @example * ```typescript * // Search by company name * const results = await client.searchMarketPartners({ * q: 'Stadtwerke München', * limit: 5 * }); * * // Search for distribution network operators (VNB) * const vnbResults = await client.searchMarketPartners({ * q: 'Stadtwerke', * role: 'VNB', * limit: 20 * }); * * for (const partner of results.data.results) { * console.log(`${partner.companyName} (${partner.code})`); * console.log(` Type: ${partner.codeType}, Source: ${partner.source}`); * if (partner.contacts?.length) { * console.log(` Contacts: ${partner.contacts.length}`); * } * if (partner.allSoftwareSystems?.length) { * console.log(` Software: ${partner.allSoftwareSystems.map(s => s.name).join(', ')}`); * } * } * * // Search by BDEW code * const codeResults = await client.searchMarketPartners({ * q: '9900123456789' * }); * ``` */ searchMarketPartners(query: MarketPartnerSearchQuery): Promise; /** * Executes a structured data query against registered Data Providers. * Supports two modes: * 1. Explicit capability with parameters * 2. Natural language query with automatic intent resolution * * @param payload - Query request (explicit or natural language) * @returns Provider-specific data and metadata * * @example * ```typescript * // Explicit capability query * const explicitResult = await client.structuredDataQuery({ * capability: 'market-partner-search', * parameters: { * q: 'netz', * limit: 5 * } * }); * * // Natural language query * const nlResult = await client.structuredDataQuery({ * query: 'Wie viele Solaranlagen gibt es in Bayern?' * }); * * console.log('Provider:', nlResult.metadata.providerId); * console.log('Capability:', nlResult.metadata.capability); * console.log('Execution time:', nlResult.metadata.executionTimeMs, 'ms'); * console.log('Cache hit:', nlResult.metadata.cacheHit); * * if (nlResult.metadata.intentResolution) { * console.log('Original query:', nlResult.metadata.intentResolution.originalQuery); * console.log('Confidence:', nlResult.metadata.intentResolution.confidence); * } * * console.log('Data:', nlResult.data); * ``` */ structuredDataQuery(payload: StructuredDataQueryRequest): Promise; /** * Analyzes a natural language query and shows detected capabilities without execution. * Useful for testing intent detection and understanding how queries are interpreted. * * @param payload - Request with natural language query * @returns Detected capabilities, suggested capability, and reasoning * * @example * ```typescript * const intent = await client.resolveIntent({ * query: 'Wie viele Windkraftanlagen gibt es in Schleswig-Holstein?' * }); * * console.log('Original query:', intent.data.originalQuery); * console.log('Suggested capability:', intent.data.suggestedCapability); * console.log('Confidence:', intent.data.confidence); * console.log('Reasoning:', intent.data.reasoning); * * console.log('\nDetected capabilities:'); * for (const cap of intent.data.detectedCapabilities) { * console.log(` - ${cap.capability} (confidence: ${cap.confidence})`); * console.log(` Parameters:`, cap.parameters); * } * * console.log('\nAvailable capabilities:'); * for (const cap of intent.data.availableCapabilities) { * console.log(` - ${cap.capability} (provider: ${cap.providerId})`); * console.log(` Examples:`, cap.examples); * } * ``` */ resolveIntent(payload: ResolveIntentRequest): Promise; /** * Lists all registered Data Providers with their capabilities and health status. * * @returns List of providers with their metadata and aggregate statistics * * @example * ```typescript * const providers = await client.getProviders(); * * console.log(`Total providers: ${providers.data.stats.totalProviders}`); * console.log(`Available capabilities: ${providers.data.stats.capabilities.join(', ')}`); * * for (const provider of providers.data.providers) { * console.log(`\n${provider.displayName} (${provider.id}) - v${provider.version}`); * console.log(` Status: ${provider.healthy ? 'healthy' : 'degraded'}`); * console.log(` Description: ${provider.description}`); * console.log(` Capabilities: ${provider.capabilities.join(', ')}`); * } * ``` */ getProviders(): Promise; /** * Checks the health status of all registered Data Providers. * * @returns Overall health status and individual provider health information * * @example * ```typescript * const health = await client.getProvidersHealth(); * * console.log(`Overall status: ${health.data.overall}`); * * for (const provider of health.data.providers) { * const status = provider.healthy ? '✓' : '✗'; * console.log(`${status} ${provider.providerId}`); * console.log(` Last check: ${provider.lastCheckAt}`); * if (provider.errorMessage) { * console.log(` Error: ${provider.errorMessage}`); * } * } * ``` */ getProvidersHealth(): Promise; private resolveUrl; private request; /** * Get chat status for polling-based workflows (API v1.0.2+) */ getChatStatus(chatId: string): Promise; /** * Get only the latest assistant response (API v1.0.2+) */ getLatestResponse(chatId: string): Promise; /** * Send a chat message and poll for completion (API v1.0.2+) */ chatWithPolling(sessionId: string, message: string, onProgress?: (status: string, progress: number) => void, pollInterval?: number, maxPollTime?: number): Promise; /** * Create an OpenAI-compatible chat completion with RAG enhancement. * * This endpoint provides a drop-in replacement for OpenAI's chat completions API, * but with automatic semantic search across Willi-Mako's energy sector knowledge base. * * **Key Features:** * - OpenAI SDK compatible (works with Python, Node.js OpenAI clients) * - Automatic QDrant search over 5 collections (ALWAYS active) * - Stateless operation (no session required, but optional) * - System instructions via messages array * - RAG metadata included in response * * **Use Cases:** * - Migration from OpenAI to Willi-Mako (only change base URL + API key) * - External integrations using OpenAI SDK * - Stateless requests without session management * - Custom system instructions per request * * @param request - Chat completion request in OpenAI format * @returns OpenAI-compatible response with RAG metadata extensions * * @example * **Simple Question** * ```typescript * const response = await client.createChatCompletion({ * messages: [ * { role: 'user', content: 'Was ist der Unterschied zwischen UTILMD und MSCONS?' } * ] * }); * console.log(response.choices[0].message.content); * console.log(`RAG docs: ${response.x_rag_metadata.retrieved_documents}`); * ``` * * @example * **With System Instructions** * ```typescript * const response = await client.createChatCompletion({ * messages: [ * { * role: 'system', * content: 'Du bist ein Senior-Berater für Netzbetreiber. Antworte präzise.' * }, * { role: 'user', content: 'Welche Fristen gelten für den Lieferantenwechsel?' } * ], * temperature: 0.5, * max_tokens: 1500 * }); * ``` * * @example * **Restrict to Specific Collections** * ```typescript * const response = await client.createChatCompletion({ * messages: [ * { role: 'user', content: 'Was sind die TAB-Anforderungen für PV-Anlagen?' } * ], * context_settings: { * targetCollections: ['willi-netz'] * } * }); * ``` * * @see https://platform.openai.com/docs/api-reference/chat/create */ createChatCompletion(request: ChatCompletionRequest): Promise; }