Skip to content

Commit

Permalink
docs(Plugin): Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Apr 10, 2024
1 parent 2849e1b commit a8b30ce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mad_hatter/mad-hatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class MadHatter {
}

/**
* Gets the installed plugins.
* Gets a copy of the installed plugins.
*/
get installedPlugins() {
return Array.from([...this.plugins.values()])
Expand Down
31 changes: 30 additions & 1 deletion src/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,42 @@ CatForm.add('formName', /* ... the other parameters */)
CatPlugin.on('eventName', /* ... the other parameters */)
```

From inside any hook, tool or form, you can access the current plugin informations like this:

```typescript
// For example, in a hook
CatHook.add('agentPromptPrefix', (prefix, cat) => {
const info = cat.getPluginInfo()
if (!info) return prefix
return info.settings.prefix
})

// For example, in a tool
CatTool.add('myToolName', 'myToolDescription', async (input, cat) => {
const info = cat.getPluginInfo()
// ...
})

// For example, in a form
CatForm.add('myFormName', {
myKey1: z.string().describe('myKey1Description'),
myKey2: z.number().describe('myKey2Description'),
}, async ({ myKey1, myKey2 }, cat) => {
const info = cat.getPluginInfo()
// ...
}, {
description: 'myFormDescription',
startExamples: ['myFormExample1', 'myFormExample2'],
})
```

For the plugin settings, you must use `zod`. Here is an example:

```typescript
import { z } from 'zod'

CatPlugin.settings({
mySetting: z.string().default('default value')
mySetting: z.string().default('default value')
})
```

Expand Down

0 comments on commit a8b30ce

Please sign in to comment.