Skip to content

Plugin package not using latest SDK types #7147

@jbuckmccready

Description

@jbuckmccready

Description

@opencode-ai/plugin used for plugins is using @opencode-ai/sdk but with latest changes in v1.1.x opencode now uses @opencode-ai/sdk/v2.

E.g., event.type === "permission.asked" will give type errors when using the @opencode-ai/plugin package.

My simple plugin with hacky cast workaround:

import type { Plugin } from "@opencode-ai/plugin";
import type { Event, EventSessionStatus } from "@opencode-ai/sdk/v2";

const NOTIFY_SCRIPT = "~/.claude/hooks/notify.sh";
const DELAY_MS = 15_000; // 15 seconds

export const NotificationPlugin: Plugin = async ({ $ }) => {
  let timeout: ReturnType<typeof setTimeout> | null = null;

  const clearPendingTimeout = () => {
    if (timeout) {
      clearTimeout(timeout);
      timeout = null;
    }
  };

  const scheduleNotification = (message: string) => {
    clearPendingTimeout();
    timeout = setTimeout(async () => {
      await $`echo '{"message": "${message}"}' | ${NOTIFY_SCRIPT}`
        .quiet()
        .nothrow();
      timeout = null;
    }, DELAY_MS);
  };

  return {
    event: async ({ event: _event }) => {
      // HACK: cast to v2 Event type (Plugin package not yet updated for permission.asked)
      const event = _event as Event;

      // Cancel on any user activity
      if (
        // Session became busy
        (event.type === "session.status" &&
          (event as EventSessionStatus).properties.status.type === "busy") ||
        // User replied to permission prompt
        event.type === "permission.replied"
      ) {
        clearPendingTimeout();
        return;
      }

      // Schedule delayed notification on idle or permission request
      if (event.type === "session.idle") {
        scheduleNotification("OpenCode finished");
      } else if (event.type === "permission.asked") {
        scheduleNotification("OpenCode awaiting permission");
      }
    },
  };
};

Plugins

No response

OpenCode version

v1.1.4

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions