Add SDK package

This commit is contained in:
2026-05-05 12:03:46 +00:00
commit d74a0871b4
10 changed files with 266 additions and 0 deletions
+47
View File
@@ -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,
});
}
}