Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of schema-less actions is unclear #51

Closed
Pasu4 opened this issue Feb 1, 2025 · 1 comment
Closed

Handling of schema-less actions is unclear #51

Pasu4 opened this issue Feb 1, 2025 · 1 comment

Comments

@Pasu4
Copy link
Contributor

Pasu4 commented Feb 1, 2025

I am unsure how to implement some things for Tony, since I find some parts of the specification unclear. (For more information, also see Pasu4/neuro-api-tony#17)

What is undefined?

The specification for the action command states:

data: The JSON-stringified data for the action, as sent by Neuro. This should* be an object that matches the JSON schema you provided when registering the action. If you did not provide a schema, this parameter will usually be undefined.

It is unclear to me what undefined means in this context. I see two possible interpretations:

  1. The data field should have the JSON value null, since it is kind of equivalent to a null value in JavaScript. I don't know any other languages that have undefined as a literal, so I'm assuming it comes from JS.
  2. The data field should be omitted. This is what Randy does.

Difference between multiple ways of declaring an action parameterless-less

The specification for the schema of an Action states:

If your action does not have any parameters, you can omit this field or set it to {}.

Randy handles both cases differently (expandable logs below):

When the game omits the schema field, Randy omits the data field.
<--- {
  command: 'actions/register',
  game: 'Chat',
  data: {
    actions: [ { name: 'action_54900', description: 'Random action' } ]
  }
}
<--- {
  command: 'actions/force',
  game: 'Chat',
  data: {
    query: 'Execute an action',
    ephemeral_context: false,
    action_names: [ 'action_54900' ]
  }
}
---> {
  command: 'action',
  data: { id: '0.9513848512962297', name: 'action_54900', data: undefined }
}

Note that data: undefined here means that the data field is omitted.

When the game sets the schema field to {}, Randy returns "{}" in the data field.
<--- {
  command: 'actions/register',
  game: 'Chat',
  data: { actions: [ { name: 'test', description: 'a', schema: {} } ] }
}
<--- {
  command: 'actions/force',
  game: 'Chat',
  data: { query: 'Test', ephemeral_context: false, action_names: [ 'test' ] }
}
---> {
  command: 'action',
  data: { id: '0.1708133265515932', name: 'test', data: '{}' }
}

Are these two ways of handling a schema-less action interchangeable? I.e. should I expect Neuro to return either of the two possible return values in both cases?

@Alexejhero
Copy link
Member

Alexejhero commented Feb 1, 2025

  1. undefined means omitted.

Image

  1. Yes they should be interchangeable. Both for the mod passing schema and neuro passing data.

Your implementation should be as robust as possible, you cannot have any expectations. That's why stuff like #39 shouldn't really matter. Whether ANYTHING is undefined/omitted, null, or just an empty object, it should never matter neither for Neuro nor for the game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants