Files
theia-code-os/packages/ai-chat/README.md
mawkone 8bb5110148
Some checks failed
Playwright Tests / Playwright Tests (ubuntu-22.04, Node.js 22.x) (push) Has been cancelled
3PP License Check / 3PP License Check (11, 22.x, ubuntu-22.04) (push) Has been cancelled
Publish packages to NPM / Perform Publishing (push) Has been cancelled
deploy: current vibn theia state
Made-with: Cursor
2026-02-27 12:01:08 -08:00

3.2 KiB


theia-ext-logo

ECLIPSE THEIA - AI CHAT EXTENSION


Description

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.

Tool Context Patterns

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

Generic Tools (no chat dependency)

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';
            }
        };
    }
}

Chat-Bound Tools (requires chat session)

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.

Additional Information

License

Trademark

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