@kubohiroya/turbowarp-named-functions 0.1.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/LICENSE +373 -0
- package/README.ja.md +209 -0
- package/README.md +258 -0
- package/dist/composition.js +398 -0
- package/dist/extension-manifest.json +133 -0
- package/dist/turbowarp-named-functions.js +701 -0
- package/dist/types/composition.d.ts +49 -0
- package/dist/types/config.d.ts +11 -0
- package/dist/types/extension-manifest.d.ts +30 -0
- package/dist/types/extension.d.ts +29 -0
- package/dist/types/function-dispatcher.d.ts +60 -0
- package/dist/types/function-registry.d.ts +28 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/runtime-types.d.ts +37 -0
- package/dist/types/schema-validator.d.ts +9 -0
- package/package.json +75 -0
- package/schemas/extension-manifest.schema.json +49 -0
- package/src/block-definitions.json +168 -0
- package/src/composition.ts +220 -0
- package/src/config.ts +12 -0
- package/src/extension-manifest.ts +149 -0
- package/src/extension.ts +200 -0
- package/src/function-dispatcher.ts +208 -0
- package/src/function-registry.ts +124 -0
- package/src/globals.d.ts +26 -0
- package/src/index.ts +14 -0
- package/src/runtime-types.ts +42 -0
- package/src/schema-validator.ts +101 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type FunctionScan, type FunctionTool } from './function-registry.js';
|
|
2
|
+
import type { RuntimeLike, RuntimeThread } from './runtime-types.js';
|
|
3
|
+
export type { FunctionDefinition, FunctionScan, FunctionTool } from './function-registry.js';
|
|
4
|
+
export { FUNCTION_NAME_PATTERN, scanFunctionDefinitions, toFunctionTools } from './function-registry.js';
|
|
5
|
+
export type { RuntimeLike, RuntimeThread, BlockUtilityLike } from './runtime-types.js';
|
|
6
|
+
export { parseJsonOrText, readArgumentPath, toScratchValue } from './function-dispatcher.js';
|
|
7
|
+
export { validateAgainstSchema } from './schema-validator.js';
|
|
8
|
+
export interface PromiseRef {
|
|
9
|
+
$promise: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CallOptions {
|
|
12
|
+
/** Thread of the calling block, used to detect reentrant calls. */
|
|
13
|
+
caller?: RuntimeThread;
|
|
14
|
+
/** Refuse functions that are not exported as tools (for calls chosen by a model). */
|
|
15
|
+
exportedOnly?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface NamedFunctionsOptions {
|
|
18
|
+
runtime: RuntimeLike;
|
|
19
|
+
/** Opcode of the consumer extension's `define function` hat, e.g. `myextension_defineFunction`. */
|
|
20
|
+
functionHatOpcode: string;
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
/** Maximum concurrently running `start`ed calls; further starts wait for a slot. Default 8. */
|
|
23
|
+
maxInFlight?: number;
|
|
24
|
+
/** Settled promise results kept for `await`; the oldest settled ones are dropped first. Default 256. */
|
|
25
|
+
maxRetainedPromises?: number;
|
|
26
|
+
setTimer?: (callback: () => void, ms: number) => unknown;
|
|
27
|
+
clearTimer?: (handle: unknown) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface NamedFunctions {
|
|
30
|
+
scan(): FunctionScan;
|
|
31
|
+
/** Functions exported as tools, in OpenAI function-calling shape. Throws if any definition is invalid. */
|
|
32
|
+
tools(): FunctionTool[];
|
|
33
|
+
isDefined(name: string): boolean;
|
|
34
|
+
/** Calls a function and waits for its result. Arguments are always validated against its schema. */
|
|
35
|
+
call(name: string, args: unknown, options?: CallOptions): Promise<unknown>;
|
|
36
|
+
/** Starts a function and returns a reference to await later. */
|
|
37
|
+
start(name: string, args: unknown, options?: CallOptions): PromiseRef;
|
|
38
|
+
await(ref: unknown): Promise<unknown>;
|
|
39
|
+
/** Waits for every reference; failed ones become `{"$error": message}` in place. */
|
|
40
|
+
awaitAll(refs: unknown): Promise<unknown[]>;
|
|
41
|
+
isSettled(ref: unknown): boolean;
|
|
42
|
+
/** Call from the `define function` hat predicate. */
|
|
43
|
+
matchHat(name: string, thread: RuntimeThread | undefined): boolean;
|
|
44
|
+
argumentsFor(thread: RuntimeThread | undefined): unknown;
|
|
45
|
+
returnFrom(thread: RuntimeThread | undefined, value: unknown): void;
|
|
46
|
+
cancelAll(reason: string): void;
|
|
47
|
+
release(): void;
|
|
48
|
+
}
|
|
49
|
+
export declare function createNamedFunctions(options: NamedFunctionsOptions): NamedFunctions;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const extensionConfig: {
|
|
2
|
+
readonly id: "kubohiroyanamedfunctions";
|
|
3
|
+
readonly slug: "turbowarp-named-functions";
|
|
4
|
+
readonly name: "TurboWarp-Named-Functions";
|
|
5
|
+
readonly description: "Named JSON functions that scripts can call by name, synchronously or asynchronously.";
|
|
6
|
+
readonly author: "Hiroya Kubo";
|
|
7
|
+
readonly license: "MPL-2.0";
|
|
8
|
+
readonly unsandboxed: true;
|
|
9
|
+
readonly docsURI: "https://kubohiroya.github.io/turbowarp-named-functions/";
|
|
10
|
+
readonly blockIconURI: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+PHJlY3QgeD0iNCIgeT0iOCIgd2lkdGg9IjQwIiBoZWlnaHQ9IjMyIiByeD0iNiIgZmlsbD0iIzhBNTVENyIvPjx0ZXh0IHg9IjI0IiB5PSIzMSIgZm9udC1mYW1pbHk9Im1vbm9zcGFjZSIgZm9udC1zaXplPSIxNiIgZm9udC13ZWlnaHQ9ImJvbGQiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGZpbGw9IiNmZmYiPmYoeCk8L3RleHQ+PC9zdmc+";
|
|
11
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export declare const EXTENSION_MANIFEST_FORMAT_VERSION: 1;
|
|
3
|
+
export interface ExtensionManifestArgument {
|
|
4
|
+
id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
menu?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ExtensionManifestBlock {
|
|
9
|
+
opcode: string;
|
|
10
|
+
blockType: string;
|
|
11
|
+
arguments: ExtensionManifestArgument[];
|
|
12
|
+
}
|
|
13
|
+
export interface ExtensionManifestMenu {
|
|
14
|
+
id: string;
|
|
15
|
+
acceptReporters: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface ExtensionManifest {
|
|
18
|
+
formatVersion: typeof EXTENSION_MANIFEST_FORMAT_VERSION;
|
|
19
|
+
id: string;
|
|
20
|
+
blocks: ExtensionManifestBlock[];
|
|
21
|
+
menus: ExtensionManifestMenu[];
|
|
22
|
+
}
|
|
23
|
+
export interface ExtensionManifestPluginOptions {
|
|
24
|
+
id: string;
|
|
25
|
+
definitions: unknown;
|
|
26
|
+
fileName?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function createExtensionManifest(id: string, definitions: unknown): ExtensionManifest;
|
|
29
|
+
export declare function serializeExtensionManifest(id: string, definitions: unknown): string;
|
|
30
|
+
export declare function extensionManifestPlugin(options: ExtensionManifestPluginOptions): Plugin;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type NamedFunctionsOptions } from './composition.js';
|
|
2
|
+
import type { BlockUtilityLike } from './runtime-types.js';
|
|
3
|
+
export declare const DEFINE_FUNCTION_OPCODE: string;
|
|
4
|
+
export type NamedFunctionsExtensionDependencies = Omit<NamedFunctionsOptions, 'functionHatOpcode'>;
|
|
5
|
+
type Args = Record<string, unknown>;
|
|
6
|
+
type Util = BlockUtilityLike & {
|
|
7
|
+
stopThisScript?: () => void;
|
|
8
|
+
};
|
|
9
|
+
/** Block surface over the named-functions composition. */
|
|
10
|
+
export declare class NamedFunctionsExtension implements TurboWarpExtension {
|
|
11
|
+
private lastErrorMessage;
|
|
12
|
+
private readonly functions;
|
|
13
|
+
constructor(deps: NamedFunctionsExtensionDependencies);
|
|
14
|
+
getInfo(): Record<string, unknown>;
|
|
15
|
+
defineFunction(args: Args, util?: Util): boolean;
|
|
16
|
+
functionArgument(args: Args, util?: Util): string | number | boolean;
|
|
17
|
+
functionArgumentsJson(_args: Args, util?: Util): string;
|
|
18
|
+
returnValue(args: Args, util?: Util): void;
|
|
19
|
+
callFunction(args: Args, util?: Util): Promise<string | number | boolean>;
|
|
20
|
+
startFunction(args: Args, util?: Util): string;
|
|
21
|
+
awaitResult(args: Args): Promise<string | number | boolean>;
|
|
22
|
+
awaitAll(args: Args): Promise<string>;
|
|
23
|
+
isSettled(args: Args): boolean;
|
|
24
|
+
isDefined(args: Args): boolean;
|
|
25
|
+
lastError(): string;
|
|
26
|
+
private guard;
|
|
27
|
+
private toScratchBlock;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { RuntimeLike, RuntimeThread } from './runtime-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Runs `define function` hats as named functions.
|
|
4
|
+
*
|
|
5
|
+
* A call starts every `define function` hat; the hat predicate lets only the script whose NAME
|
|
6
|
+
* matches the invocation being started continue, and binds that thread to the invocation. Extension
|
|
7
|
+
* hats are not restarted while running, so calls to the same name are queued and run one at a time.
|
|
8
|
+
*
|
|
9
|
+
* The next invocation is started only between steps (or directly from outside a step). Inside a step,
|
|
10
|
+
* the hats that failed their predicate and the script that just returned still count as running
|
|
11
|
+
* threads, so starting hats there would silently skip them.
|
|
12
|
+
*
|
|
13
|
+
* Each invocation records the chain of function names that led to it. Calling a name that is already
|
|
14
|
+
* in the chain would wait for itself in the per-name queue, so it fails immediately as reentrant.
|
|
15
|
+
*/
|
|
16
|
+
export interface FunctionDispatcherOptions {
|
|
17
|
+
hatOpcode: string;
|
|
18
|
+
/** Names that have a `define function` hat. Used to fail fast on unknown names. */
|
|
19
|
+
knownNames: () => ReadonlySet<string>;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
setTimer?: (callback: () => void, ms: number) => unknown;
|
|
22
|
+
clearTimer?: (handle: unknown) => void;
|
|
23
|
+
}
|
|
24
|
+
export declare const DEFAULT_FUNCTION_TIMEOUT_MS = 30000;
|
|
25
|
+
export declare class FunctionDispatcher {
|
|
26
|
+
private readonly runtime;
|
|
27
|
+
private readonly options;
|
|
28
|
+
private readonly queue;
|
|
29
|
+
private readonly running;
|
|
30
|
+
private readonly byThread;
|
|
31
|
+
private starting;
|
|
32
|
+
private step;
|
|
33
|
+
private readonly timeoutMs;
|
|
34
|
+
private readonly setTimer;
|
|
35
|
+
private readonly clearTimer;
|
|
36
|
+
private readonly onAfterExecute;
|
|
37
|
+
private readonly onStopAll;
|
|
38
|
+
constructor(runtime: RuntimeLike, options: FunctionDispatcherOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Starts a named function. `caller` is the thread of the block making the call, if any; it is used
|
|
41
|
+
* to detect reentrant calls.
|
|
42
|
+
*/
|
|
43
|
+
invoke(name: string, args: unknown, caller?: RuntimeThread): Promise<unknown>;
|
|
44
|
+
/** Hat predicate: true only for the script that should run the invocation being started. */
|
|
45
|
+
matchHat(name: string, thread: RuntimeThread | undefined): boolean;
|
|
46
|
+
argumentsFor(thread: RuntimeThread | undefined): unknown;
|
|
47
|
+
returnFrom(thread: RuntimeThread | undefined, value: unknown): void;
|
|
48
|
+
cancelAll(reason: string): void;
|
|
49
|
+
get pendingCount(): number;
|
|
50
|
+
release(): void;
|
|
51
|
+
private pump;
|
|
52
|
+
private afterStep;
|
|
53
|
+
private settle;
|
|
54
|
+
}
|
|
55
|
+
/** Resolves a dotted path such as `items.0.name` inside parsed JSON arguments. */
|
|
56
|
+
export declare function readArgumentPath(args: unknown, path: string): unknown;
|
|
57
|
+
/** Converts a value for a Scratch reporter: objects and arrays become JSON text. */
|
|
58
|
+
export declare function toScratchValue(value: unknown): string | number | boolean;
|
|
59
|
+
/** Parses block text: JSON text becomes JSON, anything else stays a string. */
|
|
60
|
+
export declare function parseJsonOrText(text: string): unknown;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RuntimeTarget } from './runtime-types.js';
|
|
2
|
+
/** A function exported as a tool, in the shape used by OpenAI function calling. */
|
|
3
|
+
export interface FunctionTool {
|
|
4
|
+
type: 'function';
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
parameters: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export declare const FUNCTION_NAME_PATTERN: RegExp;
|
|
10
|
+
export declare const MAX_DESCRIPTION_LENGTH = 1024;
|
|
11
|
+
export interface FunctionDefinition {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
parameters: Record<string, unknown>;
|
|
15
|
+
exportAs: 'tool' | 'none';
|
|
16
|
+
targetName: string;
|
|
17
|
+
blockId: string;
|
|
18
|
+
}
|
|
19
|
+
export interface FunctionScan {
|
|
20
|
+
functions: FunctionDefinition[];
|
|
21
|
+
errors: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads every `define function` hat in the project. NAME, DESCRIPTION, and SCHEMA are part of the
|
|
25
|
+
* tool contract sent to the model before any script runs, so they must be literal text.
|
|
26
|
+
*/
|
|
27
|
+
export declare function scanFunctionDefinitions(targets: readonly RuntimeTarget[], hatOpcode: string): FunctionScan;
|
|
28
|
+
export declare function toFunctionTools(functions: readonly FunctionDefinition[]): FunctionTool[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** The narrow slice of the TurboWarp VM runtime this extension depends on. */
|
|
2
|
+
export interface SerializedField {
|
|
3
|
+
value?: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface SerializedInput {
|
|
6
|
+
block?: string | null;
|
|
7
|
+
shadow?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface SerializedBlock {
|
|
10
|
+
id: string;
|
|
11
|
+
opcode: string;
|
|
12
|
+
topLevel?: boolean;
|
|
13
|
+
shadow?: boolean;
|
|
14
|
+
inputs?: Record<string, SerializedInput>;
|
|
15
|
+
fields?: Record<string, SerializedField>;
|
|
16
|
+
}
|
|
17
|
+
export interface RuntimeTarget {
|
|
18
|
+
isOriginal?: boolean;
|
|
19
|
+
isStage?: boolean;
|
|
20
|
+
getName?(): string;
|
|
21
|
+
blocks: {
|
|
22
|
+
_blocks: Record<string, SerializedBlock>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface RuntimeThread {
|
|
26
|
+
topBlock?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface RuntimeLike {
|
|
29
|
+
targets: RuntimeTarget[];
|
|
30
|
+
threads: RuntimeThread[];
|
|
31
|
+
startHats(opcode: string, matchFields?: Record<string, string>): RuntimeThread[] | undefined;
|
|
32
|
+
on(event: string, listener: (...args: unknown[]) => void): void;
|
|
33
|
+
off?(event: string, listener: (...args: unknown[]) => void): void;
|
|
34
|
+
}
|
|
35
|
+
export interface BlockUtilityLike {
|
|
36
|
+
thread?: RuntimeThread;
|
|
37
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small JSON Schema validator for function arguments. It interprets the schema at run time and
|
|
3
|
+
* never generates code, so it also works where `eval` is unavailable (for example Cloudflare Workers).
|
|
4
|
+
*
|
|
5
|
+
* Supported keywords: type, properties, required, additionalProperties (boolean), items, enum,
|
|
6
|
+
* const, minimum, maximum, minLength, maxLength, minItems, maxItems. Other keywords, such as
|
|
7
|
+
* description and title, are ignored.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateAgainstSchema(value: unknown, schema: unknown, path?: string): string[];
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubohiroya/turbowarp-named-functions",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Named, JSON-in/JSON-out functions for TurboWarp that can be called by name, synchronously or asynchronously, and exported as tools.",
|
|
5
|
+
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
6
|
+
"license": "MPL-2.0",
|
|
7
|
+
"homepage": "https://github.com/kubohiroya/turbowarp-named-functions#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/kubohiroya/turbowarp-named-functions.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/kubohiroya/turbowarp-named-functions/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"turbowarp",
|
|
17
|
+
"scratch",
|
|
18
|
+
"extension",
|
|
19
|
+
"functions",
|
|
20
|
+
"json-schema",
|
|
21
|
+
"tools",
|
|
22
|
+
"vite",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/",
|
|
28
|
+
"src/",
|
|
29
|
+
"schemas/",
|
|
30
|
+
"README.md",
|
|
31
|
+
"README.ja.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"packageManager": "pnpm@11.11.0",
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22.18.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"dev": "vite build --watch",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"build": "vite build && vite build --config vite.composition.config.ts && tsc --project tsconfig.build.json",
|
|
46
|
+
"lint": "eslint src tests scripts vite.config.ts vite.composition.config.ts eslint.config.ts",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"docs": "node scripts/generate-readme.ts",
|
|
49
|
+
"docs:check": "node scripts/generate-readme.ts --check",
|
|
50
|
+
"repo:check": "node scripts/check-repo.ts",
|
|
51
|
+
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
52
|
+
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run docs:check && pnpm run check:dist && pnpm run types:composition:check && pnpm run repo:check && pnpm run pack:check",
|
|
53
|
+
"check:dist": "pnpm run build && node scripts/check-dist.ts",
|
|
54
|
+
"types:composition:check": "tsc --project tsconfig.composition-consumer.json"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@eslint/js": "^9.39.5",
|
|
58
|
+
"@kubohiroya/vite-plugin-turbowarp-extension": "0.3.0",
|
|
59
|
+
"@types/node": "^24.13.3",
|
|
60
|
+
"eslint": "^9.39.5",
|
|
61
|
+
"jiti": "^2.7.0",
|
|
62
|
+
"typescript": "^5.9.3",
|
|
63
|
+
"typescript-eslint": "^8.66.0",
|
|
64
|
+
"vite": "^8.2.2",
|
|
65
|
+
"vitest": "^5.0.0"
|
|
66
|
+
},
|
|
67
|
+
"exports": {
|
|
68
|
+
"./composition": {
|
|
69
|
+
"types": "./dist/types/composition.d.ts",
|
|
70
|
+
"import": "./dist/composition.js"
|
|
71
|
+
},
|
|
72
|
+
"./turbowarp-named-functions.js": "./dist/turbowarp-named-functions.js",
|
|
73
|
+
"./package.json": "./package.json"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://raw.githubusercontent.com/kubohiroya/turbowarp-named-functions/main/schemas/extension-manifest.schema.json",
|
|
4
|
+
"title": "TurboWarp Extension API Manifest",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["formatVersion", "id", "blocks", "menus"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"formatVersion": {"const": 1},
|
|
10
|
+
"id": {"type": "string", "pattern": "^[a-z0-9]+$"},
|
|
11
|
+
"blocks": {
|
|
12
|
+
"type": "array",
|
|
13
|
+
"items": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"additionalProperties": false,
|
|
16
|
+
"required": ["opcode", "blockType", "arguments"],
|
|
17
|
+
"properties": {
|
|
18
|
+
"opcode": {"type": "string", "minLength": 1},
|
|
19
|
+
"blockType": {"type": "string", "minLength": 1},
|
|
20
|
+
"arguments": {
|
|
21
|
+
"type": "array",
|
|
22
|
+
"items": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"additionalProperties": false,
|
|
25
|
+
"required": ["id", "type"],
|
|
26
|
+
"properties": {
|
|
27
|
+
"id": {"type": "string", "minLength": 1},
|
|
28
|
+
"type": {"type": "string", "minLength": 1},
|
|
29
|
+
"menu": {"type": "string", "minLength": 1}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"menus": {
|
|
37
|
+
"type": "array",
|
|
38
|
+
"items": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"additionalProperties": false,
|
|
41
|
+
"required": ["id", "acceptReporters"],
|
|
42
|
+
"properties": {
|
|
43
|
+
"id": {"type": "string", "minLength": 1},
|
|
44
|
+
"acceptReporters": {"type": "boolean"}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extensionName": "Named Functions",
|
|
3
|
+
"blocks": [
|
|
4
|
+
{
|
|
5
|
+
"opcode": "defineFunction",
|
|
6
|
+
"blockType": "HAT",
|
|
7
|
+
"text": "define function [NAME] description [DESCRIPTION] args schema [SCHEMA] export as [EXPORT]",
|
|
8
|
+
"description": "Defines a named function. NAME, DESCRIPTION, and SCHEMA must be literal text. export as tool marks it for consumers such as AI tool calling.",
|
|
9
|
+
"descriptionJa": "名前を持つ関数を定義します。NAME、DESCRIPTION、SCHEMAには文字列を直接書く必要があります。export asをtoolにすると、AIのツール呼び出しなどの利用側に公開する印になります。",
|
|
10
|
+
"arguments": {
|
|
11
|
+
"NAME": {
|
|
12
|
+
"type": "STRING",
|
|
13
|
+
"defaultValue": "add"
|
|
14
|
+
},
|
|
15
|
+
"DESCRIPTION": {
|
|
16
|
+
"type": "STRING",
|
|
17
|
+
"defaultValue": "Adds two numbers."
|
|
18
|
+
},
|
|
19
|
+
"SCHEMA": {
|
|
20
|
+
"type": "STRING",
|
|
21
|
+
"defaultValue": "{\"type\":\"object\",\"properties\":{\"a\":{\"type\":\"number\"},\"b\":{\"type\":\"number\"}},\"required\":[\"a\",\"b\"]}"
|
|
22
|
+
},
|
|
23
|
+
"EXPORT": {
|
|
24
|
+
"type": "STRING",
|
|
25
|
+
"defaultValue": "none",
|
|
26
|
+
"menu": "exportModes"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"opcode": "functionArgument",
|
|
32
|
+
"blockType": "REPORTER",
|
|
33
|
+
"text": "function argument [PATH]",
|
|
34
|
+
"description": "Inside a function, reports the argument at a dotted path such as a or items.0.name.",
|
|
35
|
+
"descriptionJa": "関数の中で、aやitems.0.nameのようなドット区切りのパスにある引数を返します。",
|
|
36
|
+
"arguments": {
|
|
37
|
+
"PATH": {
|
|
38
|
+
"type": "STRING",
|
|
39
|
+
"defaultValue": "a"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"opcode": "functionArgumentsJson",
|
|
45
|
+
"blockType": "REPORTER",
|
|
46
|
+
"text": "function arguments JSON",
|
|
47
|
+
"description": "Inside a function, reports all arguments as JSON text.",
|
|
48
|
+
"descriptionJa": "関数の中で、すべての引数をJSONテキストとして返します。",
|
|
49
|
+
"arguments": {}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"opcode": "returnValue",
|
|
53
|
+
"blockType": "COMMAND",
|
|
54
|
+
"text": "return [VALUE]",
|
|
55
|
+
"description": "Inside a function, returns a value and ends the script. JSON text is returned as JSON; other text is returned as a string.",
|
|
56
|
+
"descriptionJa": "関数の中で値を返し、スクリプトを終了します。JSONテキストはJSONとして、それ以外のテキストは文字列として返します。",
|
|
57
|
+
"arguments": {
|
|
58
|
+
"VALUE": {
|
|
59
|
+
"type": "STRING",
|
|
60
|
+
"defaultValue": "0"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"opcode": "callFunction",
|
|
66
|
+
"blockType": "REPORTER",
|
|
67
|
+
"text": "call function [NAME] with [ARGS]",
|
|
68
|
+
"description": "Calls a function and waits for its result. ARGS is JSON text and is checked against the args schema. Takes at least one frame.",
|
|
69
|
+
"descriptionJa": "関数を呼び出し、結果を待って返します。ARGSはJSONテキストで、args schemaで検査されます。少なくとも1フレームかかります。",
|
|
70
|
+
"arguments": {
|
|
71
|
+
"NAME": {
|
|
72
|
+
"type": "STRING",
|
|
73
|
+
"defaultValue": "add"
|
|
74
|
+
},
|
|
75
|
+
"ARGS": {
|
|
76
|
+
"type": "STRING",
|
|
77
|
+
"defaultValue": "{\"a\":1,\"b\":2}"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"opcode": "startFunction",
|
|
83
|
+
"blockType": "REPORTER",
|
|
84
|
+
"text": "start function [NAME] with [ARGS]",
|
|
85
|
+
"description": "Starts a function without waiting and reports a promise reference as JSON text.",
|
|
86
|
+
"descriptionJa": "関数を待たずに開始し、Promiseへの参照をJSONテキストで返します。",
|
|
87
|
+
"arguments": {
|
|
88
|
+
"NAME": {
|
|
89
|
+
"type": "STRING",
|
|
90
|
+
"defaultValue": "add"
|
|
91
|
+
},
|
|
92
|
+
"ARGS": {
|
|
93
|
+
"type": "STRING",
|
|
94
|
+
"defaultValue": "{\"a\":1,\"b\":2}"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"opcode": "awaitResult",
|
|
100
|
+
"blockType": "REPORTER",
|
|
101
|
+
"text": "await [PROMISE]",
|
|
102
|
+
"description": "Waits for a promise reference from start function and reports its result.",
|
|
103
|
+
"descriptionJa": "start functionが返したPromiseへの参照を待ち、その結果を返します。",
|
|
104
|
+
"arguments": {
|
|
105
|
+
"PROMISE": {
|
|
106
|
+
"type": "STRING",
|
|
107
|
+
"defaultValue": "{\"$promise\":\"p_1\"}"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"opcode": "awaitAll",
|
|
113
|
+
"blockType": "REPORTER",
|
|
114
|
+
"text": "await all [PROMISES]",
|
|
115
|
+
"description": "Waits for a JSON array of promise references and reports a JSON array of results. Failed calls become {\"$error\": message}.",
|
|
116
|
+
"descriptionJa": "Promiseへの参照のJSON配列をすべて待ち、結果のJSON配列を返します。失敗した呼び出しは{\"$error\": メッセージ}になります。",
|
|
117
|
+
"arguments": {
|
|
118
|
+
"PROMISES": {
|
|
119
|
+
"type": "STRING",
|
|
120
|
+
"defaultValue": "[]"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"opcode": "isSettled",
|
|
126
|
+
"blockType": "BOOLEAN",
|
|
127
|
+
"text": "[PROMISE] settled?",
|
|
128
|
+
"description": "Reports whether a started function has finished, without waiting.",
|
|
129
|
+
"descriptionJa": "開始した関数が終わったかを、待たずに返します。",
|
|
130
|
+
"arguments": {
|
|
131
|
+
"PROMISE": {
|
|
132
|
+
"type": "STRING",
|
|
133
|
+
"defaultValue": "{\"$promise\":\"p_1\"}"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"opcode": "isDefined",
|
|
139
|
+
"blockType": "BOOLEAN",
|
|
140
|
+
"text": "function [NAME] defined?",
|
|
141
|
+
"description": "Reports whether a valid define function hat with this name exists.",
|
|
142
|
+
"descriptionJa": "この名前の正しいdefine functionハットがあるかを返します。",
|
|
143
|
+
"arguments": {
|
|
144
|
+
"NAME": {
|
|
145
|
+
"type": "STRING",
|
|
146
|
+
"defaultValue": "add"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"opcode": "lastError",
|
|
152
|
+
"blockType": "REPORTER",
|
|
153
|
+
"text": "last function error",
|
|
154
|
+
"description": "Reports the most recent function error, or an empty string.",
|
|
155
|
+
"descriptionJa": "直近の関数のエラーを返します。エラーがなければ空文字列を返します。",
|
|
156
|
+
"arguments": {}
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"menus": {
|
|
160
|
+
"exportModes": {
|
|
161
|
+
"acceptReporters": false,
|
|
162
|
+
"items": [
|
|
163
|
+
"none",
|
|
164
|
+
"tool"
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|