Skip to content

Plugin package not using latest SDK types #7147

Closed as not planned
Closed as not planned

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

Activity

  1. Y4tacker commented on Jan 10, 2026

    @Y4tacker

    The world really is just one big shitshow.Can we stop changing the event types all the time?

  2. eXamadeus commented on Jan 18, 2026

    @eXamadeus
    Contributor

    I made a PR to address this #8380. This is a pretty massive gap for the plugin ecosystem, if I'm being honest. It bit me multiple times when working on my own plugins.

  3. eXamadeus commented on Mar 26, 2026

    @eXamadeus
    Contributor

    Still relevant, but fix hasn't been reviewed yet.

  4. removed
    bugSomething isn't working
    on May 3, 2026
  5. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions