Files
SillyTavern/public/scripts
Rebecca Turner 7ef296d43a Feature: Allow tools to accept arrays of values as an array (#4085)
Previously, a tool that that registered itself as having an array parameter
had each element of the array registered as a variable, but it did not
register the array parameter itself.  This meant that it was only really
useful with fixed length arrays.

This patch adds a variable for the array itself that lives alongside the
existing args.  I don't expect this to have any backward compatiblity
concerns.

Repro:

```stscript
// this requires lalib to function |
/let key=schema {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "string",
    "properties": {
        "example": {
            "type": "array",
            "contains": {
                "type": "string"
            }
        }
    },
    "required": [
        "example"
    ]
} ||
/tools-register name=YourFunc description="filler" parameters={{var::schema}} {:
    /let ex {: /try {: /return {{var::arg.example}} :} :}() | /= ex.isException | /if rule=not left={{pipe}} else={:
        /console-log {{var::ex}}
    :} {:
        /console-log "arg.example: {{var::arg.example}}" |
        /foreach {{var::arg.example}} {: /console-log "#{{var::index}}: {{var::item}}" :}
    :} |
    /try {: /return {{var::arg.example.0}} :}  | /console-log "arg.example.0: {{pipe}}" |
    /try {: /return {{var::arg.example.1}} :}  | /console-log "arg.example.1: {{pipe}}" |
    /try {: /return {{var::arg.example.2}} :}  | /console-log "arg.example.2: {{pipe}}" |
    /try {: /return {{var::arg.example.3}} :}  | /console-log "arg.example.3: {{pipe}}" |
:} ||
/let key=params {
    "example": [
    	"test1", "test2", "test3"
    ]
} |
/tools-invoke parameters={{var::params}} YourFunc
```
Currently produces:

```
[/console-log] arg.example: {"isException":true,"exception":"No such variable: \"arg.example\""}
[/console-log] arg.example.0: {"isException":false,"result":"test1"}
[/console-log] arg.example.1: {"isException":false,"result":"test2"}
[/console-log] arg.example.2: {"isException":false,"result":"test3"}
[/console-log] arg.example.3: {"isException":true,"exception":"No such variable: \"arg.example.3\""}
```

With this patch it produces:

```
[/console-log] arg.example: ["test1","test2","test3"]
[/console-log] #0: test1
[/console-log] #1: test2
[/console-log] #2: test3
[/console-log] arg.example.0: {"isException":false,"result":"test1"}
[/console-log] arg.example.1: {"isException":false,"result":"test2"}
[/console-log] arg.example.2: {"isException":false,"result":"test3"}
[/console-log] arg.example.3: {"isException":true,"exception":"No such variable: \"arg.example.3\""}
```
2025-06-02 10:54:10 +03:00
..
2025-02-12 12:00:31 +02:00
2025-03-18 18:15:59 +02:00
2025-03-19 20:00:33 +02:00
2025-06-01 15:04:16 +03:00
2025-03-27 20:46:27 +02:00
2025-05-29 11:56:59 +02:00
2025-04-28 18:55:10 +07:00
2025-05-29 11:56:59 +02:00
2025-06-01 15:04:16 +03:00
2025-05-29 11:56:59 +02:00
2025-05-29 11:56:59 +02:00
2025-05-29 11:56:59 +02:00
2025-05-21 19:25:14 +09:00
2025-03-14 20:15:04 +02:00
2025-05-29 11:56:59 +02:00
2025-05-29 11:56:59 +02:00
2025-05-10 05:42:15 -05:00
2025-05-17 16:50:02 +03:00
2025-05-26 01:20:28 +03:00
2025-03-19 21:10:42 +02:00
2025-05-29 11:56:59 +02:00