Skip to content

@graphty/graphty-element / ai / AiManager

Class: AiManager ​

Defined in: graphty-element/src/ai/AiManager.ts:68

AI Manager that integrates LLM-powered natural language control with the Graph. Follows a similar pattern to the Manager interface with init() and dispose().

Note: Does not implement the Manager interface directly because it requires graph and config parameters during initialization.

Constructors ​

Constructor ​

new AiManager(): AiManager

Defined in: graphty-element/src/ai/AiManager.ts:84

Creates a new AiManager instance.

Returns ​

AiManager

Methods ​

cancel() ​

cancel(): void

Defined in: graphty-element/src/ai/AiManager.ts:307

Cancel any in-progress AI command.

Returns ​

void


dispose() ​

dispose(): void

Defined in: graphty-element/src/ai/AiManager.ts:379

Dispose of the manager and clean up resources.

Returns ​

void


execute() ​

execute(input): Promise<ExecutionResult>

Defined in: graphty-element/src/ai/AiManager.ts:250

Execute a natural language command.

Parameters ​

input ​

string

The user's natural language input

Returns ​

Promise<ExecutionResult>

Promise resolving to the execution result


getApiKeyManager() ​

getApiKeyManager(): ApiKeyManager

Defined in: graphty-element/src/ai/AiManager.ts:372

Get the API key manager for external key operations. Useful for managing keys before AI is fully initialized.

Returns ​

ApiKeyManager

The API key manager


getCommandRegistry() ​

getCommandRegistry(): CommandRegistry

Defined in: graphty-element/src/ai/AiManager.ts:339

Get the command registry for external command registration.

Returns ​

CommandRegistry

The command registry


getController() ​

getController(): AiController | null

Defined in: graphty-element/src/ai/AiManager.ts:347

Get the underlying AI controller (for advanced use).

Returns ​

AiController | null

The AI controller or null if not initialized


getProvider() ​

getProvider(): LlmProvider | null

Defined in: graphty-element/src/ai/AiManager.ts:355

Get the underlying LLM provider (for advanced use).

Returns ​

LlmProvider | null

The LLM provider or null if not initialized


getRegisteredCommands() ​

getRegisteredCommands(): string[]

Defined in: graphty-element/src/ai/AiManager.ts:241

Get names of all registered commands.

Returns ​

string[]

Array of command names


getSchemaManager() ​

getSchemaManager(): SchemaManager | null

Defined in: graphty-element/src/ai/AiManager.ts:363

Get the schema manager (for advanced use).

Returns ​

SchemaManager | null

The schema manager or null if not initialized


getStatus() ​

getStatus(): AiStatus

Defined in: graphty-element/src/ai/AiManager.ts:286

Get the current AI status.

Returns ​

AiStatus

Current status snapshot


init() ​

init(graph, config): void

Defined in: graphty-element/src/ai/AiManager.ts:95

Initialize the AI Manager with a graph and configuration.

Parameters ​

graph ​

Graph

The graph instance to control

config ​

AiManagerConfig

Configuration options

Returns ​

void


onStatusChange() ​

onStatusChange(callback): () => void

Defined in: graphty-element/src/ai/AiManager.ts:295

Subscribe to status changes.

Parameters ​

callback ​

StatusChangeCallback

Function to call on status change

Returns ​

Unsubscribe function

() => void


registerCommand() ​

registerCommand(command): void

Defined in: graphty-element/src/ai/AiManager.ts:231

Register a custom command.

Each assistant message is one undoable step. A command joins it by writing through ctx.tx (ctx.tx.styles.add, ctx.tx.layout.set, ctx.tx.run): those changes are undone with the rest of the message, and rolled back if a command throws. A change made through ctx.graph is a step of its own and is not rolled back. A command stops when ctx.abortSignal fires, which happens when the message is cancelled or undone while it is still going.

Parameters ​

command ​

GraphCommand

The command to register

Returns ​

void


retry() ​

retry(): Promise<ExecutionResult>

Defined in: graphty-element/src/ai/AiManager.ts:317

Retry the last AI command that was executed. Useful for retrying after transient errors.

Returns ​

Promise<ExecutionResult>

Promise resolving to the execution result

Throws ​

Error if no previous command exists or AI is not initialized


setApiKey() ​

setApiKey(provider, key): void

Defined in: graphty-element/src/ai/AiManager.ts:273

Set an API key for a provider.

Parameters ​

provider ​

ProviderType

The provider type (e.g., "openai")

key ​

string

The API key

Returns ​

void