@opencode/plugin 0.0.0-dev-1141 → 0.0.0-dev-1147

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.
@@ -382,6 +382,7 @@ export function fromPromise(plugin) {
382
382
  update(value);
383
383
  Object.assign(tool, value, {
384
384
  output: value.output,
385
+ freeform: value.freeform,
385
386
  options: value.options,
386
387
  execute: (input, context) => executePromiseTool(value, input, context),
387
388
  });
@@ -495,10 +496,29 @@ const toolHook = {
495
496
  "execute.after": (run) => Effect.promise(run),
496
497
  };
497
498
  const executePromiseTool = (tool, input, context) => Effect.tryPromise({
498
- try: (signal) => tool.execute(input, {
499
- ...context,
500
- signal,
501
- progress: (update) => Effect.runPromise(context.progress(update), { signal }),
502
- }),
499
+ try: (interrupted) => {
500
+ // `signal` aborts when the call is interrupted, and also when the user stops the call once the tool has read
501
+ // it. Reading it awaits `cancel`, which tells the step this tool stops on its own instead of being interrupted.
502
+ const stopped = new AbortController();
503
+ const finished = new AbortController();
504
+ const signal = AbortSignal.any([interrupted, stopped.signal]);
505
+ // `cancel` stays out of the promise context; promise tools stop through `signal`.
506
+ const { cancel, ...rest } = context;
507
+ let listening = false;
508
+ const listen = () => {
509
+ if (listening || !cancel)
510
+ return;
511
+ listening = true;
512
+ Effect.runPromise(cancel, { signal: AbortSignal.any([interrupted, finished.signal]) }).then(() => stopped.abort(), () => { });
513
+ };
514
+ return Promise.resolve(tool.execute(input, {
515
+ ...rest,
516
+ get signal() {
517
+ listen();
518
+ return signal;
519
+ },
520
+ progress: (update) => Effect.runPromise(context.progress(update), { signal: interrupted }),
521
+ })).finally(() => finished.abort());
522
+ },
503
523
  catch: toolError,
504
524
  });
@@ -7,6 +7,12 @@ import type { SessionMessage } from "@opencode/schema/session-message";
7
7
  import type { Types } from "effect";
8
8
  import type { Hooks, Transform } from "./registration.js";
9
9
  export interface ToolContext extends Omit<Tool.Context, "progress" | "cancel"> {
10
+ /**
11
+ * Aborted when the call is interrupted, and when the user stops the call if the tool has read this property.
12
+ * Reading it (spreading the context reads it too) opts the tool into a cooperative stop: on the user's stop the
13
+ * signal aborts and whatever the tool then returns or throws is still reported as the call's result. A tool
14
+ * that never reads it, or does not settle soon after the stop, is interrupted.
15
+ */
10
16
  readonly signal: AbortSignal;
11
17
  readonly progress: (update: Tool.Metadata) => Promise<void>;
12
18
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/plugin",
4
- "version": "0.0.0-dev-1141",
4
+ "version": "0.0.0-dev-1147",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -78,15 +78,15 @@
78
78
  ],
79
79
  "dependencies": {
80
80
  "@ai-sdk/provider": "3.0.8",
81
- "@opencode/ai": "0.0.0-dev-1141",
82
- "@opencode/client": "0.0.0-dev-1141",
83
- "@opencode/protocol": "0.0.0-dev-1141",
84
- "@opencode/schema": "0.0.0-dev-1141",
85
- "@opencode/util": "0.0.0-dev-1141",
81
+ "@opencode/ai": "0.0.0-dev-1147",
82
+ "@opencode/client": "0.0.0-dev-1147",
83
+ "@opencode/protocol": "0.0.0-dev-1147",
84
+ "@opencode/schema": "0.0.0-dev-1147",
85
+ "@opencode/util": "0.0.0-dev-1147",
86
86
  "effect": "4.1.0"
87
87
  },
88
88
  "peerDependencies": {
89
- "@opencode/theme": "0.0.0-dev-1141",
89
+ "@opencode/theme": "0.0.0-dev-1147",
90
90
  "@opentui/core": ">=0.8.1",
91
91
  "@opentui/solid": ">=0.8.1",
92
92
  "electron": "*",
@@ -118,7 +118,7 @@
118
118
  }
119
119
  },
120
120
  "devDependencies": {
121
- "@opencode/theme": "0.0.0-dev-1141",
121
+ "@opencode/theme": "0.0.0-dev-1147",
122
122
  "@opentui/core": "0.8.1",
123
123
  "@opentui/solid": "0.8.1",
124
124
  "@tsconfig/bun": "1.0.9",