@kubohiroya/turbowarp-named-functions 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # TurboWarp-Named-Functions
2
2
 
3
+ <img src="assets/block-icon.svg" alt="" width="48" height="48">
4
+
3
5
  [English](README.md) | [日本語](README.ja.md)
4
6
 
5
7
  JSONの引数を受け取りJSONの結果を返す「名前を持つ関数」を定義するTurboWarp機能拡張です。スクリプトから名前で呼び出して結果を待つことも、いくつか開始しておいてあとでまとめて待つこともできます。ツールとして公開する印を付けると、AIのツール呼び出しなど、ほかの拡張から使えるようになります。
@@ -35,7 +37,7 @@ JSONの引数を受け取りJSONの結果を返す「名前を持つ関数」を
35
37
  npm packageとして使う場合は、検証済みのversionをexact pinします。
36
38
 
37
39
  ```bash
38
- pnpm add --save-exact @kubohiroya/turbowarp-named-functions@0.1.2
40
+ pnpm add --save-exact @kubohiroya/turbowarp-named-functions@0.2.0
39
41
  ```
40
42
 
41
43
  ## クイックスタート
@@ -56,7 +58,7 @@ say (call function [add] with [{"a":1,"b":2}])
56
58
 
57
59
  ### `define function [NAME] description [DESCRIPTION] args schema [SCHEMA] returns schema [RETURNS] export as [EXPORT]`
58
60
 
59
- 名前を持つ関数を定義します。NAME、DESCRIPTION、SCHEMAには文字列を直接書く必要があります。RETURNSには任意の戻り値JSON Schemaを指定でき、空欄なら戻り値を検証しません。
61
+ 名前を持つ関数を定義します。NAME、DESCRIPTION、SCHEMAには文字列を直接書く必要があります。SCHEMAとRETURNSには、JSON Schema文字列、または`define schema`ハットの名前(Name@1.0.0の形でバージョン固定も可)を書けます。RETURNSは任意で、空欄なら戻り値を検証しません。
60
62
 
61
63
  | 項目 | 値 |
62
64
  |---|---|
@@ -68,6 +70,104 @@ say (call function [add] with [{"a":1,"b":2}])
68
70
  | `RETURNS` | 文字列, 既定値: `` |
69
71
  | `EXPORT` | 文字列, 既定値: `none`, 選択肢: `none`, `tool` |
70
72
 
73
+ ### `define schema [NAME] version [VERSION]`
74
+
75
+ 下に積まれたpropertyブロックから、名前付きJSON Schemaを宣言します。NAMEとVERSIONには文字列を直接書く必要があり、VERSIONは完全なSemVer値でなければなりません。この積み木は宣言として読まれるだけで実行されず、結果はSchema文字列と同じcanonical JSON Schemaになります。
76
+
77
+ | 項目 | 値 |
78
+ |---|---|
79
+ | 種類 | ハット |
80
+ | Opcode | `defineSchema` |
81
+ | `NAME` | 文字列, 既定値: `Player` |
82
+ | `VERSION` | 文字列, 既定値: `1.0.0` |
83
+
84
+ ### `property [NAME] type [TYPE] [PRESENCE]`
85
+
86
+ `define schema`の積み木の中で、Schemaのプロパティを1つ宣言します。
87
+
88
+ | 項目 | 値 |
89
+ |---|---|
90
+ | 種類 | コマンド |
91
+ | Opcode | `schemaProperty` |
92
+ | `NAME` | 文字列, 既定値: `name` |
93
+ | `TYPE` | 文字列, 既定値: `string`, 選択肢: `string`, `number`, `integer`, `boolean`, `null`, `object`, `array`, `array of string`, `array of number`, `array of integer`, `array of boolean`, `array of object` |
94
+ | `PRESENCE` | 文字列, 既定値: `required`, 選択肢: `required`, `optional` |
95
+
96
+ ### `property [NAME] schema [SCHEMA] [PRESENCE]`
97
+
98
+ 別の名前付きSchemaに従う値を持つプロパティを宣言します。SCHEMAには`define schema`の名前を書き、Name@1.0.0の形でバージョンを固定できます。
99
+
100
+ | 項目 | 値 |
101
+ |---|---|
102
+ | 種類 | コマンド |
103
+ | Opcode | `schemaPropertySchema` |
104
+ | `NAME` | 文字列, 既定値: `profile` |
105
+ | `SCHEMA` | 文字列, 既定値: `Profile` |
106
+ | `PRESENCE` | 文字列, 既定値: `required`, 選択肢: `required`, `optional` |
107
+
108
+ ### `property [NAME] array of schema [SCHEMA] [PRESENCE]`
109
+
110
+ 項目が別の名前付きSchemaに従う配列を持つプロパティを宣言します。
111
+
112
+ | 項目 | 値 |
113
+ |---|---|
114
+ | 種類 | コマンド |
115
+ | Opcode | `schemaPropertyArraySchema` |
116
+ | `NAME` | 文字列, 既定値: `items` |
117
+ | `SCHEMA` | 文字列, 既定値: `Item` |
118
+ | `PRESENCE` | 文字列, 既定値: `optional`, 選択肢: `required`, `optional` |
119
+
120
+ ### `limit [KEYWORD] to [VALUE]`
121
+
122
+ すぐ上で宣言したプロパティに制約を加えます。`minItems`と`maxItems`は配列そのものに、その他の制約は配列の各項目に適用されます。
123
+
124
+ | 項目 | 値 |
125
+ |---|---|
126
+ | 種類 | コマンド |
127
+ | Opcode | `schemaConstraint` |
128
+ | `KEYWORD` | 文字列, 既定値: `minimum`, 選択肢: `minimum`, `maximum`, `minLength`, `maxLength`, `minItems`, `maxItems` |
129
+ | `VALUE` | 数値, 既定値: `0` |
130
+
131
+ ### `allowed values [VALUES]`
132
+
133
+ すぐ上で宣言したプロパティの値をenumに制限します。VALUESにはJSON配列、またはカンマ区切りの文字列を書きます。
134
+
135
+ | 項目 | 値 |
136
+ |---|---|
137
+ | 種類 | コマンド |
138
+ | Opcode | `schemaAllowedValues` |
139
+ | `VALUES` | 文字列, 既定値: `red, green, blue` |
140
+
141
+ ### `allow undeclared properties [ALLOW]`
142
+
143
+ 宣言していないプロパティをSchemaが受け入れるかどうかを設定します。省略した場合は、JSON Schemaと同じく受け入れます。
144
+
145
+ | 項目 | 値 |
146
+ |---|---|
147
+ | 種類 | コマンド |
148
+ | Opcode | `schemaAdditionalProperties` |
149
+ | `ALLOW` | 文字列, 既定値: `no`, 選択肢: `no`, `yes` |
150
+
151
+ ### `schema [NAME] JSON`
152
+
153
+ `define schema`ハットが変換されたcanonical JSON Schemaを返します。未定義または不正な場合は空文字列を返します。
154
+
155
+ | 項目 | 値 |
156
+ |---|---|
157
+ | 種類 | 値ブロック |
158
+ | Opcode | `schemaJson` |
159
+ | `NAME` | 文字列, 既定値: `Player` |
160
+
161
+ ### `schema [NAME] defined?`
162
+
163
+ その名前の正しい`define schema`ハットがあればtrueを返します。Name@1.0.0の形でバージョンを固定できます。
164
+
165
+ | 項目 | 値 |
166
+ |---|---|
167
+ | 種類 | 真偽値ブロック |
168
+ | Opcode | `isSchemaDefined` |
169
+ | `NAME` | 文字列, 既定値: `Player` |
170
+
71
171
  ### `function argument [PATH]`
72
172
 
73
173
  関数の中で、aやitems.0.nameのようなドット区切りのパスにある引数を返します。
@@ -186,20 +286,62 @@ Promiseへの参照のJSON配列をすべて待ち、結果のJSON配列を返
186
286
  | プロジェクトの停止 | 実行中の呼び出しは失敗し、Promiseへの参照は消去される |
187
287
  | `define function`ハットが不正(文字列の直書きでない、スキーマが不正、名前の重複) | 関数は定義されない。`function [NAME] defined?`はfalseを返す |
188
288
 
189
- 初回は既存のJSON文字列入力を維持します。視覚Schemaビルダーは、`define schema`ハットの下に宣言的なpropertyブロックを並べる形を提案します。
289
+ ## ブロックでSchemaを組み立てる
290
+
291
+ Schemaは従来どおりJSON文字列で書けますし、ブロックで組み立てることもできます。`define schema`ハットの下にpropertyブロックを積むと、名前付きSchemaを宣言できます。
190
292
 
191
293
  ```text
192
294
  define schema [Player] version [1.0.0]
193
295
  property [name] type [string] required
194
- property [score] type [number] required minimum (0)
296
+ property [score] type [number] required
297
+ limit [minimum] to (0)
195
298
  property [tags] type [array of string] optional
196
299
  ```
197
300
 
198
- ネストしたobjectやarrayのpropertyは別の名前付きSchemaを参照できるようにし、同じSchemaを関数の引数・戻り値・名前付きデータに選べるようにします。ブロック列は`validateAgainstSchema`が扱うcanonical JSON Schemaへ変換し、別の検証形式を作らず、既存のJSON文字列プロジェクトもそのまま使います。これはブロック仕様案であり、まだ実装されていません。実装境界はSchema定義と変換層です。リテラルのブロック項目を読み、重複・不正な定義を報告してcanonical schemaを生成します。Schema読み込み時に任意のブロックを実行しません。ブロックのmutation UIやネストSchemaの編集体験は別の実装作業です。
301
+ この積み木は、文字列で書いた場合とまったく同じJSON Schemaへ変換されます。
302
+
303
+ ```json
304
+ {
305
+ "type": "object",
306
+ "properties": {
307
+ "name": {"type": "string"},
308
+ "score": {"type": "number", "minimum": 0},
309
+ "tags": {"type": "array", "items": {"type": "string"}}
310
+ },
311
+ "required": ["name", "score"]
312
+ }
313
+ ```
314
+
315
+ `schema [NAME] JSON`はこのcanonical schemaを返すので、変換結果をプロジェクト上で確認できます。
316
+
317
+ `define schema`の積み木はスクリプトではなく宣言です。実行前に読み取られ、ハットは起動せず、積み木をクリックしても下のブロックは何もしません。読み取る項目はすべて文字列の直書きである必要があり、値ブロックを差し込んだ場合は評価せずにエラーとして報告します。
318
+
319
+ ### 関数で名前付きSchemaを使う
320
+
321
+ `args schema`と`returns schema`には、JSON文字列のほかに`define schema`ハットの名前を書けます。`args schema [Player]`と書けば、上のSchemaで呼び出しを検証します。`Player@1.0.0`の形でバージョンを固定できます。JSONとして解釈できない文字列は名前として読むため、JSON文字列を使っている既存プロジェクトはそのまま動き、名前で指定した場合も文字列と同じ`validateAgainstSchema`のsubsetを通ります。
322
+
323
+ ### どのブロックが何になるか
324
+
325
+ | ブロック | 変換結果 |
326
+ |---|---|
327
+ | `property [NAME] type [TYPE] [PRESENCE]` | その型のproperty。`required`なら`required`に追加します。 |
328
+ | `property [NAME] schema [SCHEMA] [PRESENCE]` | 名前付きSchemaをそのまま展開したproperty。 |
329
+ | `property [NAME] array of schema [SCHEMA] [PRESENCE]` | `{"type": "array", "items": <名前付きSchema>}`。 |
330
+ | `limit [KEYWORD] to (VALUE)` | すぐ上のpropertyへの`minimum`、`maximum`、`minLength`、`maxLength`、`minItems`、`maxItems`。 |
331
+ | `allowed values [VALUES]` | JSON配列またはカンマ区切りの一覧からの`enum`。 |
332
+ | `allow undeclared properties [ALLOW]` | `additionalProperties`。省略した場合は宣言していないpropertyを受け入れます。 |
333
+
334
+ `minItems`と`maxItems`は配列そのものを、その他の制約は配列の各項目を対象とします。したがって`array of number`に`limit minimum to 0`を付けると、各項目が0以上であることを要求します。`allowed values`の値は、propertyの宣言した型と一致している必要があります。
335
+
336
+ ### Schemaの診断
337
+
338
+ 読み取れないSchemaは、それを含むスプライトとブロックとともに報告され、未定義として扱われます。その場合`schema [NAME] defined?`はfalseを返し、他のSchemaはそのまま使えます。propertyの名前の重複、`name@version`の重複、propertyの上にない制約やallowed values、積み木に属さないブロック、未知のSchema名、参照の循環は、いずれも定義エラーです。複数バージョンがある名前をバージョン指定なしで参照した場合は、推測せずに曖昧として失敗し、未知のバージョンは別バージョンへfallbackせずに失敗します。
339
+
340
+ ブロックのmutation UIやネストSchemaの編集体験は別の作業です。ネストは現在、別の名前付きSchemaを参照する形で表現します。
199
341
 
200
342
  ### named dataとのSchema identity
201
343
 
202
- named-dataが運ぶのはstructured valueの`{id, version}` identityだけです。IDは`^[a-z][a-z0-9.-]{0,127}$`に一致し、versionは完全なSemVerである必要があります。Schema catalogはconsumerが所有します。戻されたJSON値を検証する前にidentityと完全一致するSchemaを解決してください。IDやversionが見つからない場合は明示的に失敗し、別versionへfallbackしません。このpackageの関数引数/戻り値Schemaは引き続きinlineのcanonical JSON Schemaです。対応subsetは`type`、`properties`、`required`、Boolean形式の`additionalProperties`、`items`、`enum`、`const`、`minimum`、`maximum`、`minLength`、`maxLength`、`minItems`、`maxItems`です。その他のkeywordは検証動作を追加しません。
344
+ named-dataが運ぶのはstructured valueの`{id, version}` identityだけです。IDは`^[a-z][a-z0-9.-]{0,127}$`に一致し、versionは完全なSemVerである必要があります。Schema catalogはconsumerが所有します。戻されたJSON値を検証する前にidentityと完全一致するSchemaを解決してください。IDやversionが見つからない場合は明示的に失敗し、別versionへfallbackしません。このpackage内でも`define schema`の名前は同じ`name@version` identityと完全SemVerの規則に従い、関数の引数と戻り値は、その名前と文字列形式のどちらからも得られるcanonical JSON Schemaを使います。対応subsetは`type`、`properties`、`required`、Boolean形式の`additionalProperties`、`items`、`enum`、`const`、`minimum`、`maximum`、`minLength`、`maxLength`、`minItems`、`maxItems`です。その他のkeywordは検証動作を追加しません。
203
345
 
204
346
  ## Composition API
205
347
 
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # TurboWarp-Named-Functions
2
2
 
3
+ <img src="assets/block-icon.svg" alt="" width="48" height="48">
4
+
3
5
  [English](README.md) | [日本語](README.ja.md)
4
6
 
5
7
  A TurboWarp extension for defining named functions that take JSON arguments and return JSON results. Scripts can call them by name, wait for the result, or start several calls and await them later. Functions can be marked for export as tools so that other extensions, such as AI tool calling, can use them.
@@ -38,7 +40,7 @@ A TurboWarp extension for defining named functions that take JSON arguments and
38
40
  ### npm package
39
41
 
40
42
  ```bash
41
- pnpm add --save-exact @kubohiroya/turbowarp-named-functions@0.1.2
43
+ pnpm add --save-exact @kubohiroya/turbowarp-named-functions@0.2.0
42
44
  ```
43
45
 
44
46
  Standalone bundle:
@@ -67,7 +69,7 @@ generated section manually.
67
69
 
68
70
  ### `define function [NAME] description [DESCRIPTION] args schema [SCHEMA] returns schema [RETURNS] export as [EXPORT]`
69
71
 
70
- Defines a named function. NAME, DESCRIPTION, and SCHEMA must be literal text. RETURNS is an optional JSON Schema for the return value; leave it blank to disable return validation.
72
+ Defines a named function. NAME, DESCRIPTION, and SCHEMA must be literal text. SCHEMA and RETURNS each take JSON Schema text or the name of a `define schema` hat, optionally pinned as Name@1.0.0. RETURNS is optional; leave it blank to disable return validation.
71
73
 
72
74
  | Property | Value |
73
75
  |---|---|
@@ -79,6 +81,104 @@ Defines a named function. NAME, DESCRIPTION, and SCHEMA must be literal text. RE
79
81
  | `RETURNS` | String, default: `` |
80
82
  | `EXPORT` | String, default: `none`, choices: `none`, `tool` |
81
83
 
84
+ ### `define schema [NAME] version [VERSION]`
85
+
86
+ Declares a named JSON Schema from the property blocks stacked under it. NAME and VERSION must be literal text, and VERSION must be a complete SemVer value. The stack is read as a declaration and never run; the result is the same canonical JSON Schema that schema text produces.
87
+
88
+ | Property | Value |
89
+ |---|---|
90
+ | Type | Hat |
91
+ | Opcode | `defineSchema` |
92
+ | `NAME` | String, default: `Player` |
93
+ | `VERSION` | String, default: `1.0.0` |
94
+
95
+ ### `property [NAME] type [TYPE] [PRESENCE]`
96
+
97
+ Inside a `define schema` stack, declares one property of the schema.
98
+
99
+ | Property | Value |
100
+ |---|---|
101
+ | Type | Command |
102
+ | Opcode | `schemaProperty` |
103
+ | `NAME` | String, default: `name` |
104
+ | `TYPE` | String, default: `string`, choices: `string`, `number`, `integer`, `boolean`, `null`, `object`, `array`, `array of string`, `array of number`, `array of integer`, `array of boolean`, `array of object` |
105
+ | `PRESENCE` | String, default: `required`, choices: `required`, `optional` |
106
+
107
+ ### `property [NAME] schema [SCHEMA] [PRESENCE]`
108
+
109
+ Declares a property whose value follows another named schema. SCHEMA is a `define schema` name, optionally pinned as Name@1.0.0.
110
+
111
+ | Property | Value |
112
+ |---|---|
113
+ | Type | Command |
114
+ | Opcode | `schemaPropertySchema` |
115
+ | `NAME` | String, default: `profile` |
116
+ | `SCHEMA` | String, default: `Profile` |
117
+ | `PRESENCE` | String, default: `required`, choices: `required`, `optional` |
118
+
119
+ ### `property [NAME] array of schema [SCHEMA] [PRESENCE]`
120
+
121
+ Declares a property holding an array whose items follow another named schema.
122
+
123
+ | Property | Value |
124
+ |---|---|
125
+ | Type | Command |
126
+ | Opcode | `schemaPropertyArraySchema` |
127
+ | `NAME` | String, default: `items` |
128
+ | `SCHEMA` | String, default: `Item` |
129
+ | `PRESENCE` | String, default: `optional`, choices: `required`, `optional` |
130
+
131
+ ### `limit [KEYWORD] to [VALUE]`
132
+
133
+ Adds a limit to the property declared just above. `minItems` and `maxItems` apply to an array property itself; the other limits apply to each of its items.
134
+
135
+ | Property | Value |
136
+ |---|---|
137
+ | Type | Command |
138
+ | Opcode | `schemaConstraint` |
139
+ | `KEYWORD` | String, default: `minimum`, choices: `minimum`, `maximum`, `minLength`, `maxLength`, `minItems`, `maxItems` |
140
+ | `VALUE` | Number, default: `0` |
141
+
142
+ ### `allowed values [VALUES]`
143
+
144
+ Restricts the property declared just above to an enum. VALUES is a JSON array, or a comma-separated list of strings.
145
+
146
+ | Property | Value |
147
+ |---|---|
148
+ | Type | Command |
149
+ | Opcode | `schemaAllowedValues` |
150
+ | `VALUES` | String, default: `red, green, blue` |
151
+
152
+ ### `allow undeclared properties [ALLOW]`
153
+
154
+ Sets whether the schema accepts properties it does not declare. Left out, undeclared properties are accepted, as in JSON Schema.
155
+
156
+ | Property | Value |
157
+ |---|---|
158
+ | Type | Command |
159
+ | Opcode | `schemaAdditionalProperties` |
160
+ | `ALLOW` | String, default: `no`, choices: `no`, `yes` |
161
+
162
+ ### `schema [NAME] JSON`
163
+
164
+ Reports the canonical JSON Schema a `define schema` hat lowers to, or an empty string if it is unknown or invalid.
165
+
166
+ | Property | Value |
167
+ |---|---|
168
+ | Type | Reporter |
169
+ | Opcode | `schemaJson` |
170
+ | `NAME` | String, default: `Player` |
171
+
172
+ ### `schema [NAME] defined?`
173
+
174
+ True when a valid `define schema` hat has that name. A name may be pinned as Name@1.0.0.
175
+
176
+ | Property | Value |
177
+ |---|---|
178
+ | Type | Boolean |
179
+ | Opcode | `isSchemaDefined` |
180
+ | `NAME` | String, default: `Player` |
181
+
82
182
  ### `function argument [PATH]`
83
183
 
84
184
  Inside a function, reports the argument at a dotted path such as a or items.0.name.
@@ -197,24 +297,72 @@ Reports the most recent function error, or an empty string.
197
297
  | Project stop | Running calls fail and promise references are cleared. |
198
298
  | Invalid `define function` hats (non-literal inputs, invalid schema, duplicate names) | The function is not defined; `function [NAME] defined?` reports false. |
199
299
 
200
- The first version keeps schema authoring as literal JSON text. The visual builder should use a
201
- `define schema` hat followed by declarative property blocks. For example:
300
+ ## Building a schema from blocks
301
+
302
+ Schemas can be written as JSON text, as before, or built from blocks. A `define schema` hat with
303
+ property blocks stacked under it declares a named schema:
202
304
 
203
305
  ```text
204
306
  define schema [Player] version [1.0.0]
205
307
  property [name] type [string] required
206
- property [score] type [number] required minimum (0)
308
+ property [score] type [number] required
309
+ limit [minimum] to (0)
207
310
  property [tags] type [array of string] optional
208
311
  ```
209
312
 
210
- Nested object and array properties should reference another named schema, so the same schema can
211
- be selected for function arguments, return values, and named data. The block sequence must lower
212
- to the canonical JSON Schema object consumed by `validateAgainstSchema`; it must not create a
213
- second validation format or change existing JSON-text projects. This is a proposed block contract,
214
- not an implemented feature. The implementation boundary is the schema definition and conversion
215
- layer: it reads literal block fields, reports duplicate/invalid definitions, and produces the
216
- canonical schema. It does not execute arbitrary blocks while loading a schema. Editor block
217
- mutation and nested-schema UX remain separate implementation work.
313
+ That stack lowers to exactly the JSON Schema the text form would produce:
314
+
315
+ ```json
316
+ {
317
+ "type": "object",
318
+ "properties": {
319
+ "name": {"type": "string"},
320
+ "score": {"type": "number", "minimum": 0},
321
+ "tags": {"type": "array", "items": {"type": "string"}}
322
+ },
323
+ "required": ["name", "score"]
324
+ }
325
+ ```
326
+
327
+ `schema [NAME] JSON` reports that canonical schema, so the lowering is visible in the project.
328
+
329
+ A `define schema` stack is a declaration, not a script. It is read before anything runs, its hat
330
+ never activates, and the blocks under it do nothing if the stack is clicked. Every field it reads
331
+ must be literal text; a reporter plugged into one is rejected rather than evaluated.
332
+
333
+ ### Using a named schema in a function
334
+
335
+ `args schema` and `returns schema` take either JSON text or the name of a `define schema` hat, so
336
+ `args schema [Player]` validates calls against the schema above. A name may be pinned to a version
337
+ as `Player@1.0.0`. Text that is not JSON is read as a name, so projects that hold JSON text keep
338
+ working unchanged, and a name is resolved through the same `validateAgainstSchema` subset as text.
339
+
340
+ ### Which blocks build what
341
+
342
+ | Block | Lowers to |
343
+ |---|---|
344
+ | `property [NAME] type [TYPE] [PRESENCE]` | A property of that type; `required` adds it to `required`. |
345
+ | `property [NAME] schema [SCHEMA] [PRESENCE]` | A property holding the named schema, inlined. |
346
+ | `property [NAME] array of schema [SCHEMA] [PRESENCE]` | `{"type": "array", "items": <named schema>}`. |
347
+ | `limit [KEYWORD] to (VALUE)` | `minimum`, `maximum`, `minLength`, `maxLength`, `minItems` or `maxItems` on the property above. |
348
+ | `allowed values [VALUES]` | `enum`, from a JSON array or a comma-separated list. |
349
+ | `allow undeclared properties [ALLOW]` | `additionalProperties`; left out, undeclared properties are accepted. |
350
+
351
+ `minItems` and `maxItems` describe an array property itself; the other limits describe each of its
352
+ items, so `array of number` with `limit minimum to 0` requires every item to be at least 0. An
353
+ `allowed values` list must match the property's declared type.
354
+
355
+ ### Schema diagnostics
356
+
357
+ A schema that cannot be read is reported with the sprite and block that holds it, and is left
358
+ undefined; `schema [NAME] defined?` then reports false and other schemas keep working. Duplicate
359
+ property names, duplicate `name@version` pairs, a limit or an allowed-values list with no property
360
+ above it, a block that does not belong in the stack, an unknown schema name, and a reference cycle
361
+ are all definition errors. A name with several versions and no pinned version is ambiguous rather
362
+ than guessed, and an unknown version fails instead of falling back to a different one.
363
+
364
+ Editor block mutation and a nested-schema editing UX remain separate work; nesting is expressed
365
+ today by referring to another named schema.
218
366
 
219
367
  ### Schema identity with named data
220
368
 
@@ -222,8 +370,10 @@ Named-data carries only a structured value's `{id, version}` schema identity; ID
222
370
  `^[a-z][a-z0-9.-]{0,127}$` and versions must be complete SemVer values. The consumer owns the
223
371
  schema catalog. Resolve the exact identity before validating the returned JSON value with
224
372
  `validateAgainstSchema`. An unknown ID or version must fail explicitly, with no fallback to a
225
- different version. This package continues to use inline canonical JSON Schema for function
226
- arguments and returns. Its supported subset is `type`, `properties`, `required`,
373
+ different version. Within this package, `define schema` names follow the same `name@version`
374
+ identity and the same complete-SemVer rule, and function arguments and returns use the canonical
375
+ JSON Schema those names and the text form both produce. Its supported subset is `type`,
376
+ `properties`, `required`,
227
377
  `additionalProperties` (boolean), `items`, `enum`, `const`, `minimum`, `maximum`, `minLength`,
228
378
  `maxLength`, `minItems`, and `maxItems`; other keywords do not add validation behavior.
229
379
 
@@ -255,11 +405,36 @@ functions.release();
255
405
  | Member | Purpose |
256
406
  |---|---|
257
407
  | `scan()` / `tools()` / `isDefined(name)` | Read and validate `define function` hats |
408
+ | `schemas()` | `define schema` hats lowered to canonical JSON Schema, with their definition errors |
258
409
  | `call(name, args, {caller, exportedOnly})` | Validate arguments, run the function, and resolve with its return value |
259
410
  | `start(...)` / `await(ref)` / `awaitAll(refs)` / `isSettled(ref)` | Asynchronous calls through `{"$promise": id}` references |
260
411
  | `matchHat` / `argumentsFor` / `returnFrom` | Bridge from the consumer's blocks |
261
412
  | `cancelAll(reason)` / `release()` | Fail pending calls; `release` also detaches runtime listeners |
262
413
 
414
+ The visual schema builder is opt-in. A consumer that owns schema blocks of its own passes their
415
+ opcodes as `schemaBlockOpcodes`, and `args schema` and `returns schema` then accept a schema name
416
+ as well as JSON text. Left out, those inputs accept JSON text only, exactly as before.
417
+
418
+ ```ts
419
+ const functions = createNamedFunctions({
420
+ runtime: Scratch.vm.runtime,
421
+ functionHatOpcode: 'myextension_defineFunction',
422
+ schemaBlockOpcodes: {
423
+ hat: 'myextension_defineSchema',
424
+ property: 'myextension_schemaProperty',
425
+ propertySchema: 'myextension_schemaPropertySchema',
426
+ propertyArraySchema: 'myextension_schemaPropertyArraySchema',
427
+ constraint: 'myextension_schemaConstraint',
428
+ allowedValues: 'myextension_schemaAllowedValues',
429
+ additionalProperties: 'myextension_schemaAdditionalProperties'
430
+ }
431
+ });
432
+ ```
433
+
434
+ `scanSchemaDefinitions(targets, opcodes)` and `resolveSchemaReference(schemas, name, label)` are
435
+ exported for consumers that resolve schemas themselves, and `scanFunctionDefinitions` takes a
436
+ `resolveSchema` callback for any other schema catalog.
437
+
263
438
  ## Compatibility
264
439
 
265
440
  | Identifier | Value | Stability |