![rozenite-banner](https://www.rozenite.dev/rozenite-banner.jpg)

### Shared Agent types and message contracts for Rozenite packages.

[![mit licence][license-badge]][license] [![npm downloads][npm-downloads-badge]][npm-downloads] [![Chat][chat-badge]][chat] [![PRs Welcome][prs-welcome-badge]][prs-welcome]

`@rozenite/agent-shared` contains the shared type definitions used by Rozenite Agent packages. It defines the Agent tool shape, the message protocol for registering and calling tools, and the shared `AGENT_PLUGIN_ID` constant used by the bridge packages.

## Features

- **Shared Tool Types**: Common `AgentTool` and JSON-schema-like input types
- **Paginated Tool Contracts**: Typed row fields and a shared page envelope for built-in and third-party tools
- **One List Pager**: `paginateArray` pages any array with cursors that resume after a row, so a live list never skips or repeats one; runs in Node, browsers, Hermes, and Lynx
- **Bounded Reads**: `boundValue` cuts any value by depth, string length and items per level, and `sliceUtf8` reads a byte range of text without splitting a character; both run on the device
- **Non-Paginated Lists**: `rows` metadata so lists that do not page can still declare their columns
- **Row Shaping**: Frontend-neutral columnar/row-keyed encoding (`shapePaginatedRows`, `shapeToolResult`) shared by the CLI and any other Agent frontend
- **Message Contracts**: Typed payloads for register, unregister, call, and result messages
- **Single Protocol Constant**: Shared `AGENT_PLUGIN_ID` for the Agent transport
- **Package Reuse**: Intended for bridge and runtime packages that implement Agent support

## Installation

Install the shared package as a dependency:

```bash
npm install @rozenite/agent-shared
```

## Exports

This package exports:

- `AGENT_PLUGIN_ID`
- `AgentTool`
- `AgentToolPagination` (with optional `itemsKey` and `meta`) and `isAgentToolPagination`
- `AgentToolRows` and `isAgentToolRows`
- `PageEnvelope`
- `PageResult`
- `definePaginatedAgentToolContract`
- `defineRowsAgentToolContract`
- `paginateArray`, `PaginateArrayOptions`, `CursorKey`, and `CursorPayload` (`keyOf` must return a unique key per row; a duplicate throws)
- `boundValue`, `normalizeBoundedValueArgs`, `selectValuePath`, `parseValuePath`, `truncateString`, `BOUNDED_VALUE_DEFAULTS`, `BOUNDED_VALUE_LIMITS`, `BoundedValueArgs`, `BoundedValueOptions`, and `BoundedValue`
- `sliceUtf8`, `SliceUtf8Options`, and `SliceUtf8Result`
- `encodeCursor` and `decodeCursor`
- `normalizePageLimit`
- `DEFAULT_PAGE_LIMIT`
- `MAX_PAGE_LIMIT`
- `parseFields`
- `parseLimit`
- `projectRows`
- `shapePaginatedRows`
- `shapeToolResult`
- `JSONSchema7`
- `DevToolsPluginMessage`
- `RegisterToolPayload`
- `UnregisterToolPayload`
- `ToolCallPayload`
- `ToolResultPayload`
- `RegisterToolMessage`
- `UnregisterToolMessage`
- `ToolCallMessage`
- `ToolResultMessage`
- `AgentMessage`
- `AgentEventMap`
- `AGENT_MESSAGE_TYPES`
- `getErrorDetails`
- `parseAgentTargetsResponse` and `ParsedTargetsResponse`
- `BUILT_IN_DOMAIN_TOOL_NAMES`, `CONSOLE_TOOL_NAMES`, `REACT_TOOL_NAMES`, `PERFORMANCE_TOOL_NAMES`, `MEMORY_TOOL_NAMES`, `NETWORK_TOOL_NAMES`

## Usage

```typescript
import {
  AGENT_PLUGIN_ID,
  type AgentTool,
  type ToolCallMessage,
} from '@rozenite/agent-shared';

const tool: AgentTool = {
  name: 'example.echo',
  description: 'Echo a value back to the caller.',
  inputSchema: {
    type: 'object',
    properties: {
      value: { type: 'string' },
    },
    required: ['value'],
  },
};

console.log(AGENT_PLUGIN_ID);
```

## Made with ❤️ at Callstack

`rozenite` is an open source project and will always remain free to use. If you think it's cool, please star it 🌟.

[Callstack][callstack-readme-with-love] is a group of React and React Native geeks, contact us at [hello@callstack.com](mailto:hello@callstack.com) if you need any help with these or just want to say hi!

Like the project? ⚛️ [Join the team](https://callstack.com/careers/?utm_campaign=Senior_RN&utm_source=github&utm_medium=readme) who does amazing stuff for clients and drives React Native Open Source! 🔥

[callstack-readme-with-love]: https://callstack.com/?utm_source=github.com&utm_medium=referral&utm_campaign=rozenite&utm_term=readme-with-love
[license-badge]: https://img.shields.io/npm/l/@rozenite/agent-shared?style=for-the-badge
[license]: https://github.com/callstackincubator/rozenite/blob/main/LICENSE
[npm-downloads-badge]: https://img.shields.io/npm/dm/@rozenite/agent-shared?style=for-the-badge
[npm-downloads]: https://www.npmjs.com/package/@rozenite/agent-shared
[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge
[prs-welcome]: https://github.com/callstackincubator/rozenite/blob/main/CONTRIBUTING.md
[chat-badge]: https://img.shields.io/discord/426714625279524876.svg?style=for-the-badge
[chat]: https://discord.gg/xgGt7KAjxv
