@kubohiroya/turbowarp-openai-realtime-api 0.5.0 → 0.5.1

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
@@ -55,7 +55,7 @@ OpenAI Realtime APIと音声やテキストで会話し、ブロックで書い
55
55
  npm packageとして使う場合は、検証済みのversionをexact pinします。
56
56
 
57
57
  ```bash
58
- pnpm add --save-exact @kubohiroya/turbowarp-openai-realtime-api@0.5.0
58
+ pnpm add --save-exact @kubohiroya/turbowarp-openai-realtime-api@0.5.1
59
59
  ```
60
60
 
61
61
  ## クイックスタート
package/README.md CHANGED
@@ -61,7 +61,7 @@ The reviewed JavaScript build is committed to this repository, so users do not n
61
61
  Install an exact version that you have reviewed:
62
62
 
63
63
  ```bash
64
- pnpm add --save-exact @kubohiroya/turbowarp-openai-realtime-api@0.5.0
64
+ pnpm add --save-exact @kubohiroya/turbowarp-openai-realtime-api@0.5.1
65
65
  ```
66
66
 
67
67
  Standalone bundle:
@@ -196,26 +196,50 @@ function fixedInputEditorOptions() {
196
196
  })
197
197
  }));
198
198
  }
199
- /** Register only visible static contracts; ordinary composition consumers load no editor runtime. */
199
+ /**
200
+ * Register only visible static contracts; ordinary composition consumers load no editor runtime.
201
+ * Every project load disposes the runtime while the extension stays loaded for the next project,
202
+ * so RUNTIME_DISPOSED only releases the registrations and the next PROJECT_LOADED registers the
203
+ * same ones again. The returned dispose is final.
204
+ */
200
205
  function registerFixedInputEditors(scratch, runtime, visibleBlocks) {
201
206
  const api = scratch.gui?.blockEditors;
202
207
  if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function") return void 0;
208
+ const registerEditor = api.registerFixedInputEditor;
203
209
  const visibleOpcodes = new Set(visibleBlocks.flatMap((block) => {
204
210
  if (typeof block !== "object" || block === null || !("opcode" in block)) return [];
205
211
  return typeof block.opcode === "string" ? [block.opcode] : [];
206
212
  }));
213
+ const visibleOptions = fixedInputEditorOptions().filter((options) => options.opcodes.some((opcode) => visibleOpcodes.has(opcode.slice(25))));
207
214
  const events = runtime;
208
215
  const removers = [];
209
- let active = true;
210
- const dispose = () => {
211
- if (!active) return;
212
- active = false;
213
- events?.off?.("RUNTIME_DISPOSED", dispose);
216
+ let registered = false;
217
+ let disposed = false;
218
+ const release = () => {
219
+ registered = false;
214
220
  for (const remove of removers.splice(0).reverse()) remove();
215
221
  };
222
+ const register = () => {
223
+ if (disposed || registered) return;
224
+ registered = true;
225
+ try {
226
+ for (const options of visibleOptions) removers.push(registerEditor.call(api, options));
227
+ } catch (error) {
228
+ release();
229
+ throw error;
230
+ }
231
+ };
232
+ const dispose = () => {
233
+ if (disposed) return;
234
+ disposed = true;
235
+ events?.off?.("RUNTIME_DISPOSED", release);
236
+ events?.off?.("PROJECT_LOADED", register);
237
+ release();
238
+ };
216
239
  try {
217
- for (const options of fixedInputEditorOptions()) if (options.opcodes.some((opcode) => visibleOpcodes.has(opcode.slice(25)))) removers.push(api.registerFixedInputEditor.call(api, options));
218
- events?.on?.("RUNTIME_DISPOSED", dispose);
240
+ register();
241
+ events?.on?.("RUNTIME_DISPOSED", release);
242
+ events?.on?.("PROJECT_LOADED", register);
219
243
  } catch (error) {
220
244
  dispose();
221
245
  throw error;
@@ -10,6 +10,11 @@ export declare function readNumber(value: LiteralValue): number;
10
10
  export declare function newNumberToken(value: JsonValue): string;
11
11
  export declare function candidateValid(_opcode: string, _argument: string, schema: InputSchema, value: LiteralValue): boolean;
12
12
  export declare function fixedInputEditorOptions(): readonly FixedInputEditorOptions[];
13
- /** Register only visible static contracts; ordinary composition consumers load no editor runtime. */
13
+ /**
14
+ * Register only visible static contracts; ordinary composition consumers load no editor runtime.
15
+ * Every project load disposes the runtime while the extension stays loaded for the next project,
16
+ * so RUNTIME_DISPOSED only releases the registrations and the next PROJECT_LOADED registers the
17
+ * same ones again. The returned dispose is final.
18
+ */
14
19
  export declare function registerFixedInputEditors(scratch: unknown, runtime: unknown, visibleBlocks: readonly unknown[]): (() => void) | undefined;
15
20
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-openai-realtime-api",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "A TurboWarp extension for the OpenAI Realtime API, using a localhost relay for credentials.",
5
5
  "author": {
6
6
  "name": "Hiroya Kubo",
@@ -157,7 +157,12 @@ interface RegistrationRuntime {
157
157
  on?(event: string, listener: () => void): void;
158
158
  off?(event: string, listener: () => void): void;
159
159
  }
160
- /** Register only visible static contracts; ordinary composition consumers load no editor runtime. */
160
+ /**
161
+ * Register only visible static contracts; ordinary composition consumers load no editor runtime.
162
+ * Every project load disposes the runtime while the extension stays loaded for the next project,
163
+ * so RUNTIME_DISPOSED only releases the registrations and the next PROJECT_LOADED registers the
164
+ * same ones again. The returned dispose is final.
165
+ */
161
166
  export function registerFixedInputEditors(
162
167
  scratch: unknown,
163
168
  runtime: unknown,
@@ -180,6 +185,7 @@ export function registerFixedInputEditors(
180
185
  typeof api.registerFixedInputEditor !== "function"
181
186
  )
182
187
  return undefined;
188
+ const registerEditor = api.registerFixedInputEditor;
183
189
  const visibleOpcodes = new Set(
184
190
  visibleBlocks.flatMap((block) => {
185
191
  if (typeof block !== "object" || block === null || !("opcode" in block))
@@ -187,25 +193,41 @@ export function registerFixedInputEditors(
187
193
  return typeof block.opcode === "string" ? [block.opcode] : [];
188
194
  }),
189
195
  );
196
+ const visibleOptions = fixedInputEditorOptions().filter((options) =>
197
+ options.opcodes.some((opcode) =>
198
+ visibleOpcodes.has(opcode.slice(extensionId.length + 1)),
199
+ ),
200
+ );
190
201
  const events = runtime as RegistrationRuntime | undefined;
191
202
  const removers: (() => void)[] = [];
192
- let active = true;
193
- const dispose = () => {
194
- if (!active) return;
195
- active = false;
196
- events?.off?.("RUNTIME_DISPOSED", dispose);
203
+ let registered = false;
204
+ let disposed = false;
205
+ const release = () => {
206
+ registered = false;
197
207
  for (const remove of removers.splice(0).reverse()) remove();
198
208
  };
199
- try {
200
- for (const options of fixedInputEditorOptions()) {
201
- if (
202
- options.opcodes.some((opcode) =>
203
- visibleOpcodes.has(opcode.slice(extensionId.length + 1)),
204
- )
205
- )
206
- removers.push(api.registerFixedInputEditor.call(api, options));
209
+ const register = () => {
210
+ if (disposed || registered) return;
211
+ registered = true;
212
+ try {
213
+ for (const options of visibleOptions)
214
+ removers.push(registerEditor.call(api, options));
215
+ } catch (error) {
216
+ release();
217
+ throw error;
207
218
  }
208
- events?.on?.("RUNTIME_DISPOSED", dispose);
219
+ };
220
+ const dispose = () => {
221
+ if (disposed) return;
222
+ disposed = true;
223
+ events?.off?.("RUNTIME_DISPOSED", release);
224
+ events?.off?.("PROJECT_LOADED", register);
225
+ release();
226
+ };
227
+ try {
228
+ register();
229
+ events?.on?.("RUNTIME_DISPOSED", release);
230
+ events?.on?.("PROJECT_LOADED", register);
209
231
  } catch (error) {
210
232
  dispose();
211
233
  throw error;