https://github.com/rubriclab/actions
https://github.com/rubriclab/actions
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rubriclab/actions
- Owner: RubricLab
- Created: 2024-10-03T00:56:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-04T14:08:39.000Z (over 1 year ago)
- Last Synced: 2025-02-04T15:22:46.803Z (over 1 year ago)
- Language: TypeScript
- Size: 75.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @rubriclab/actions
The Actions package aims to provide a powerful and simple way to define actions (which are essentially API primitives) and execute them safely with JSON serializable payloads.
It is part of Rubric's architecture for Generative UI when used with:
- [@rubriclab/actions](https://github.com/rubriclab/actions)
- [@rubriclab/blocks](https://github.com/rubriclab/blocks)
- [@rubriclab/chains](https://github.com/rubriclab/chains)
- [@rubriclab/agents](https://github.com/rubriclab/agents)
- [@rubriclab/events](https://github.com/rubriclab/events)
[Demo](https://chat.rubric.sh)
## Get Started
### Installation
`bun add @rubriclab/actions`
> @rubriclab scope packages are not built, they are all raw typescript. If using in a next.js app, make sure to transpile.
```ts
// next.config.ts
import type { NextConfig } from 'next'
export default {
transpilePackages: ['@rubriclab/actions'],
reactStrictMode: true
} satisfies NextConfig
```
> If using inside the monorepo (@rubric), simply add `{"@rubriclab/actions": "*"}` to dependencies and then run `bun i`
### Define Actions
To get started, define a few actions.
```ts
import { createAction } from '@rubriclab/actions'
import { z } from 'zod'
const convertStringToNumber = createAction({
schema: {
input: z.object({
str: z.string()
}),
output: z.number()
},
execute: ({ str }) => Number(str)
})
export const actions = { convertStringToNumber }
```
### Create an Executor
Pass all your actions into an executor to get a function to execute it.
```ts
'use server'
import { createActionExecutor } from '@rubriclab/actions'
import { actions } from './actions'
export const { execute } = createActionExecutor({ actions })
```
### Execute an Action
```ts
const number = await execute({ action: 'convertStringToNumber' params: { str: '2' } })
```