Skip to content

Commit

Permalink
Fix agent toggle reset (#439)
Browse files Browse the repository at this point in the history
Also don't show command disabled if command isn't implemented for the
agent.
  • Loading branch information
curtisman authored Nov 27, 2024
1 parent 833d18f commit 37705f5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
30 changes: 15 additions & 15 deletions ts/packages/dispatcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,29 @@ Dispatcher agent's schema, action and command can be toggled independently as we
To list all avaiable agents and their status, just the command without any parameters:

```bash
🤖🚧💾 [🎧📅📩📝🌐🪟⚛️💬🤖🔧📷🖐🖼️📱🗎]@config agent
🤖🚧💾 [🎧📅📩📝🌐💬🤖🔧📷🖐🖼️📱🗎]> @config agent
|Agent |Schemas|Actions|Commands|
|--------------------|-------|-------|--------|
|androidMobile ||| |
|androidMobile ||| |
|browser ||||
| browser.commerce | | | |
| browser.crossword | | | |
| browser.paleoBioDb| | | |
| browser.commerce |💤 |💤 | |
| browser.crossword |💤 |💤 | |
| browser.paleoBioDb|💤 |💤 | |
|calendar ||||
|chat ||| |
|code | | | |
| code.code-debug | | | |
| code.code-display | | | |
| code.code-general | | | |
|desktop | || |
|chat ||| |
|code | | | |
| code.code-debug | | | |
| code.code-display | | | |
| code.code-general | | | |
|desktop | || |
|dispatcher ||||
| dispatcher.clarify||| |
|email ||||
|greeting ||||
|image ||| |
|list ||| |
|markdown ||| |
|photo ||| |
|image ||| |
|list ||| |
|markdown ||| |
|photo ||| |
|player ||||
|system | | ||
| system.config ||| |
Expand Down
11 changes: 11 additions & 0 deletions ts/packages/dispatcher/src/handlers/common/appAgentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ export class AppAgentManager implements ActionConfigProvider {
: false;
}

// Return undefined if we don't know because the agent isn't loaded yet.
// Return null if the agent doesn't support commands.
public getCommandEnabledState(appAgentName: string) {
const record = this.agents.get(appAgentName);
return record !== undefined && record.appAgent !== undefined
? record.appAgent.executeCommand !== undefined
? record.commands
: null
: undefined;
}

public getEmojis(): Readonly<Record<string, string>> {
return this.emojis;
}
Expand Down
15 changes: 8 additions & 7 deletions ts/packages/dispatcher/src/handlers/configCommandHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,13 @@ function setStatus(
status: StatusRecords,
kind: keyof ChangedAgent,
name: string,
enable: boolean,
enable: boolean | undefined | null,
active: boolean,
changes?: ChangedAgent,
) {
if (enable === null) {
return;
}
const defaultStr = getDefaultStr(changes, kind, name);
if (defaultStr === undefined) {
return;
Expand All @@ -184,11 +187,9 @@ function setStatus(
}
}

status[name][kind] = enable
? active
? `✅${defaultStr}`
: `💤${defaultStr}`
: `❌${defaultStr}`;
const statusChar =
enable === undefined ? "❔" : enable ? (active ? "✅" : "💤") : "❌";
status[name][kind] = `${statusChar}${defaultStr}`;
}

function showAgentStatus(
Expand Down Expand Up @@ -229,7 +230,7 @@ function showAgentStatus(

if (showCommand) {
for (const name of agents.getAppAgentNames()) {
const state = agents.isCommandEnabled(name);
const state = agents.getCommandEnabledState(name);
setStatus(status, "commands", name, state, true, changes);
}
}
Expand Down
13 changes: 6 additions & 7 deletions ts/packages/dispatcher/src/session/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ export function mergeConfig(
const keys = strict ? Object.keys(config) : Object.keys(options);
for (const key of keys) {
if (options.hasOwnProperty(key)) {
let value = options[key];
if (value === undefined) {
const optionValue = options[key];

if (optionValue === undefined) {
continue;
}
if (value === null) {
// null means undefined
value = undefined;
}
// null means undefined
const value = optionValue === null ? undefined : optionValue;
let configValue = config[key];
const strictKey = flexKeys ? !flexKeys.includes(key) : strict;
if (strictKey && typeof configValue !== typeof value) {
Expand All @@ -55,7 +54,7 @@ export function mergeConfig(
} else {
config[key] = value;
}
changed[key] = value;
changed[key] = optionValue;
}
}
}
Expand Down

0 comments on commit 37705f5

Please sign in to comment.