Add SDK package
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import type { ShxAutomationContext } from './classes.automationcontext.js';
|
||||
|
||||
export class DeviceProxy {
|
||||
constructor(private context: ShxAutomationContext) {}
|
||||
|
||||
public async call(optionsArg: {
|
||||
deviceId: string;
|
||||
toolId: string;
|
||||
title: string;
|
||||
reason: string;
|
||||
input?: Record<string, unknown>;
|
||||
confidence?: number;
|
||||
}) {
|
||||
const callId = `call:${Date.now()}:${Math.random().toString(36).slice(2)}`;
|
||||
const plan: plugins.shxInterfaces.data.IToolPlan = {
|
||||
id: `plan:${callId}`,
|
||||
callerId: this.context.options.callerId,
|
||||
title: optionsArg.title,
|
||||
reason: optionsArg.reason,
|
||||
confidence: optionsArg.confidence ?? 0.5,
|
||||
calls: [
|
||||
{
|
||||
id: callId,
|
||||
toolId: optionsArg.toolId,
|
||||
callerId: this.context.options.callerId,
|
||||
input: {
|
||||
deviceId: optionsArg.deviceId,
|
||||
...(optionsArg.input ?? {}),
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
return this.context.executePlan(plan);
|
||||
}
|
||||
|
||||
public async read(deviceIdArg: string) {
|
||||
return this.call({
|
||||
deviceId: deviceIdArg,
|
||||
toolId: `device:${deviceIdArg}:read`,
|
||||
title: `Read ${deviceIdArg}`,
|
||||
reason: 'Automation requested current device state.',
|
||||
input: {},
|
||||
confidence: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user