Theia API Documentation v1.68.0
    Preparing search index...

    Module @theia/ai-chat


    theia-ext-logo

    ECLIPSE THEIA - AI CHAT EXTENSION


    The @theia/ai-chat extension provides the concept of a language model chat to Theia. It serves as the basis for @theia/ai-chat-ui to provide the Chat UI.

    When implementing tool handlers, there are two patterns depending on whether your tool requires chat-specific features:

    For tools that only need basic context like cancellation support:

    import { ToolInvocationContext, ToolProvider, ToolRequest } from '@theia/ai-core';

    @injectable()
    export class MyGenericTool implements ToolProvider {
    getTool(): ToolRequest {
    return {
    id: 'myTool',
    name: 'myTool',
    description: 'A generic tool',
    parameters: { type: 'object', properties: {} },
    handler: async (args: string, ctx?: ToolInvocationContext) => {
    if (ctx?.cancellationToken?.isCancellationRequested) {
    return JSON.stringify({ error: 'Operation cancelled' });
    }
    // Tool implementation
    return 'result';
    }
    };
    }
    }

    For tools that need access to the chat session, request model, or response:

    import { assertChatContext, ChatToolContext } from '@theia/ai-chat';
    import { ToolInvocationContext, ToolProvider, ToolRequest } from '@theia/ai-core';

    @injectable()
    export class MyChatTool implements ToolProvider {
    getTool(): ToolRequest {
    return {
    id: 'myChatTool',
    name: 'myChatTool',
    description: 'A chat-bound tool',
    parameters: { type: 'object', properties: {} },
    handler: async (args: string, ctx?: ToolInvocationContext) => {
    assertChatContext(ctx); // Throws if not in chat context
    if (ctx.cancellationToken?.isCancellationRequested) {
    return JSON.stringify({ error: 'Operation cancelled' });
    }
    // Access chat-specific features
    const sessionId = ctx.request.session.id;
    ctx.request.session.changeSet.addElements(...);
    return 'result';
    }
    };
    }
    }

    The assertChatContext() function serves as both a runtime validator and TypeScript type guard, ensuring the context is a ChatToolContext with request and response properties.

    "Theia" is a trademark of the Eclipse Foundation https://www.eclipse.org/theia

    Modules

    browser/agent-delegation-tool
    browser/ai-chat-frontend-contribution
    browser/ai-chat-frontend-module
    browser/ai-chat-preference-contribution
    browser/change-set-decorator-service
    browser/change-set-file-element
    browser/change-set-file-element-deserializer
    browser/change-set-file-resource
    browser/change-set-file-service
    browser/change-set-variable
    browser/chat-session-store-impl
    browser/chat-tool-preference-bindings
    browser/chat-tool-request-service
    browser/context-file-validation-service
    browser/context-file-variable-label-provider
    browser/context-variable-label-provider
    browser/custom-agent-factory
    browser/custom-agent-frontend-application-contribution
    browser/delegation-response-content
    browser/file-chat-variable-contribution
    browser/frontend-chat-service
    browser/image-context-variable-contribution
    browser/session-storage-defaults-provider
    browser/task-context-service
    browser/task-context-storage-service
    browser/task-context-variable
    browser/task-context-variable-contribution
    browser/task-context-variable-label-provider
    common
    common/ai-chat-preferences
    common/change-set
    common/change-set-element-deserializer
    common/chat-agent-recommendation-service
    common/chat-agent-service
    common/chat-agents
    common/chat-agents-variable-contribution
    common/chat-content-deserializer
    common/chat-model
    common/chat-model-serialization
    common/chat-model-util
    common/chat-request-parser
    common/chat-service
    common/chat-session-naming-prompt-template
    common/chat-session-naming-service
    common/chat-session-store
    common/chat-session-summary-agent
    common/chat-session-summary-agent-prompt
    common/chat-string-utils
    common/chat-tool-preferences
    common/chat-tool-request-service
    common/context-details-variable
    common/context-summary-variable
    common/context-variables
    common/custom-chat-agent
    common/image-context-variable
    common/parse-contents
    common/parsed-chat-request
    common/response-content-matcher
    node/ai-chat-backend-module