Skip to main content

LensStudio:ChatTool.ChatTool

Class

Base class for AI-invokable operations; extend this to implement a tool that the AI can call via execute().

Index

Example

// ChatTool is the base class for building AI-invokable tools in Lens Studio.
// Override execute(parameters) to handle invocation from a ChatAssistant.
//
// Properties:
// pluginSystem (readonly) — Editor.PluginSystem for resolving interfaces
//
// Methods:
// execute(parameters: Parameters): Promise<Result>
// parameters.data contains parsed arguments matching the Descriptor's schema.
// Return a Result with data on success or error on failure.

export class LensStudioChatToolChatToolExampleTool extends ChatTool {
connections: any[];
static descriptor() {
const d = new Descriptor();
d.id = 'com.docs.LensStudioChatToolChatToolExample';
d.name = 'List Scene Objects';
d.description = 'Lists root scene objects in the current project';
d.dependencies = [Editor.Model.IModel];
d.schema = {
type: 'object',
properties: {
maxCount: { type: 'number', description: 'Maximum number of objects to return' },
},
};
return d;
}
constructor(pluginSystem: Editor.PluginSystem, descriptor?: Descriptor) {
super(pluginSystem, descriptor);
this.connections = [];
}
async execute(parameters: any): Promise<any> {
const result = new Result();
try {
const maxCount = parameters?.data?.maxCount ?? 10;
const model = this.pluginSystem.findInterface(Editor.Model.IModel) as unknown as Editor.Model.IModel;
const scene = model.project.scene;
const names = scene.rootSceneObjects
.slice(0, maxCount)
.map((obj: Editor.Model.SceneObject) => obj.name);
result.data = { objects: names, total: scene.rootSceneObjects.length };
} catch (e: any) {
result.error = `Failed: ${e?.message ?? e}`;
}
return result;
}
}

Extends

Constructors

Constructor

new ChatTool(pluginSystem, descriptor?): ChatTool

Constructs a ChatTool plugin instance with the given plugin system and optional descriptor.

Parameters

ParameterType
pluginSystemPluginSystem
descriptor?Descriptor

Returns

ChatTool

Overrides

Editor.IPlugin.constructor

Properties

id

readonly id: string

Unique string identifier of the plugin instance.

Inherited from

IPlugin.id


pluginSystem

readonly pluginSystem: PluginSystem

The PluginSystem instance used to access shared Editor interfaces via findInterface().

Methods

execute()

execute(parameters): Promise<Result>

Executes the tool with the given parameters and returns a Result containing output data or an error string.

Parameters

ParameterType
parametersParameters

Returns

Promise<Result>


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

IPlugin.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

IPlugin.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

IPlugin.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

IPlugin.isSame