Skip to content

feat: capability module declare compile time type checking #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ktn1234
Copy link
Contributor

@ktn1234 ktn1234 commented Mar 24, 2025

Description

Improves the type safety of the capabilities system by enforcing proper input/output type structure and preventing usage of undefined capabilities. This change makes the type system more robust by adding a module augmentation pattern. now plugin developers and model developers explicitly declare the capabilities they will be consuming/producing respectively.

Related Issues

resolves #53

Core Changes

// packages/core/src/models/types.ts

/**
 * This is the base interface for all capabilities.
 * Model providers and plugins will extend ICapabilities with the input and output types
 */
export interface BaseCapability {
     input: unknown;
     output: unknown;
 }

/**
 * This is the base interface for all capabilities.
 * Model providers and plugins can extend this interface
 * to add their own capabilities.
 */
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ICapabilities {}

/**
 * This is how model providers and plugins can extend the ICapabilities interface
 * to add their own capabilities.
 */
declare module "../models/types" {
    interface ICapabilities {
        "text-generation": {
            input: string;
            output: string;
        };
    }
}

Changes Made

  • Feature added
  • Code refactored
  • Documentation updated

How to Test

  1. Try to use an undefined capability in a plugin:
await this.runtime.executeCapability(
  "fake-capability", // TypeScript should error: Argument of type '"fake-capability"' is not assignable to parameter of type 'keyof ICapabilities'
  "test input"
);
  1. Verify that existing capabilities still work:
await this.runtime.executeCapability(
  "text-generation",
  "test input"
); // Should compile successfully
  1. Try to extend capabilities without proper input/output structure:
declare module "@maiar-ai/core" {
  interface ICapabilities {
    "invalid-capability": {
      // Should error: missing input/output properties
    };
  }
}

Checklist

  • Code follows project style guidelines
  • Tests have been added/updated if needed
  • Documentation has been updated if necessary
  • Ready for review 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant