### Development Setup Commands
Source: https://github.com/opentiny/tiny-robot/blob/develop/README.md
Commands to install dependencies and launch the development environment.
```bash
# Install dependencies
pnpm install
# Start development server (playground + docs)
pnpm dev
```
--------------------------------
### Local Startup Steps for Tiny Robot
Source: https://github.com/opentiny/tiny-robot/blob/develop/CONTRIBUTING.md
Follow these steps to clone the repository, set up upstream remote, install dependencies, and start the development server for docs and playground.
```shell
# Replace username with your own GitHub username
git clone git@github.com:username/tiny-robot.git
cd tiny-robot
# Add upstream remote
git remote add upstream git@github.com:opentiny/tiny-robot.git
# Install dependencies
pnpm i
# Start docs and playground
pnpm dev
```
--------------------------------
### Copy Environment Variables
Source: https://github.com/opentiny/tiny-robot/blob/develop/packages/cli/templates/basic/README.md
Copy the example environment file to start configuring your project. This is the first step before filling in provider keys.
```bash
cp .env.example .env
```
--------------------------------
### Post-creation steps for a TinyRobot project
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/cli-integration.md
Steps to navigate into the created project, install dependencies, configure environment variables, and start the development server.
```bash
cd my-app
pnpm install
# configure your API key
# edit .env
pnpm dev
```
--------------------------------
### Welcome Component Usage Examples
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/welcome.md
Examples demonstrating how to use the Welcome component with different configurations.
```APIDOC
## Welcome Component Usage Examples
### Basic Usage
This example shows the basic implementation of the Welcome component.
```vue
```
### Alignment
Demonstrates how to change the alignment of the content using the `align` prop.
```vue
```
### Footer Content
Shows how to add custom content to the footer using the `footer` slot.
```vue
Thank you for visiting!
```
```
--------------------------------
### Example: Create 'my-app' project
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/cli-integration.md
An example of creating a project named 'my-app' using the 'basic' template.
```bash
npx @opentiny/tiny-robot-cli create my-app --template basic
```
--------------------------------
### Markdown Rendering Setup
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Instructions for installing necessary dependencies (markdown-it, dompurify) to enable Markdown rendering in Bubble components.
```bash
# npm
npm install markdown-it dompurify
# yarn
yarn add markdown-it dompurify
# pnpm
pnpm add markdown-it dompurify
```
--------------------------------
### Sender Extension Setup
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/sender.md
Provides examples of how to set up Sender extensions using convenient functions like `TrSender.mention`, `TrSender.suggestion`, and `TrSender.template`, as well as the standard configuration method for complex scenarios.
```typescript
import { TrSender } from '@opentiny/tiny-robot'
// Convenient functions (recommended)
TrSender.mention(mentions, '@')
TrSender.suggestion(suggestions) // No filtering
TrSender.suggestion(suggestions, { filterFn: customFilter }) // Custom filtering
TrSender.template(templates)
// Standard configuration (for complex scenarios)
TrSender.Mention.configure({ items: mentions, char: '@', allowSpaces: false })
TrSender.Suggestion.configure({ items: suggestions, filterFn: customFilter })
```
--------------------------------
### Start Development Server
Source: https://github.com/opentiny/tiny-robot/blob/develop/packages/cli/templates/basic/README.md
Run the development server to start building and testing your application. This command is used during development.
```bash
pnpm dev
```
--------------------------------
### Install Dependencies
Source: https://github.com/opentiny/tiny-robot/blob/develop/packages/cli/templates/basic/README.md
Install project dependencies using pnpm. Ensure you have pnpm installed globally.
```bash
pnpm install
```
--------------------------------
### Install TinyRobot Core Package
Source: https://github.com/opentiny/tiny-robot/blob/develop/README.md
Install the main @opentiny/tiny-robot package using your preferred package manager.
```bash
# Using pnpm (recommended)
pnpm add @opentiny/tiny-robot
# Using npm
npm install @opentiny/tiny-robot
# Using yarn
yarn add @opentiny/tiny-robot
```
--------------------------------
### Schema Card Rendering Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Example demonstrating schema card rendering, potentially involving multiple Vue files for custom components.
```vue
```
--------------------------------
### List Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Basic example of using the BubbleList component to display a list of bubbles.
```vue
```
--------------------------------
### Install TinyRobot Kit Package
Source: https://github.com/opentiny/tiny-robot/blob/develop/README.md
Install the optional @opentiny/tiny-robot-kit package if you need AI model request or data-processing features.
```bash
pnpm add @opentiny/tiny-robot-kit
```
--------------------------------
### Install MCP SDK
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/tools/message.md
Installs the Model Context Protocol (MCP) SDK using pnpm. This is required for extending AI tool capabilities with MCP services.
```bash
# 使用 @modelcontextprotocol/sdk 接入 MCP 服务
pnpm add @modelcontextprotocol/sdk
```
--------------------------------
### Install/Update Dependencies
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/cli-integration.md
After making changes, install or update your project's dependencies using npm or pnpm.
```bash
npm install
pnpm install
```
--------------------------------
### Install TinyRobot CLI using npm or pnpm
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/cli-integration.md
Use npx or pnpm dlx to run the TinyRobot CLI without global installation.
```bash
# npm
npx @opentiny/tiny-robot-cli
# pnpm
pnpm dlx @opentiny/tiny-robot-cli
```
--------------------------------
### Install TinyRobot Dependencies
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/quick-start.md
Install the core TinyRobot components, utility functions, and SVG icons using your preferred package manager.
```bash
pnpm add @opentiny/tiny-robot @opentiny/tiny-robot-kit @opentiny/tiny-robot-svgs
```
```bash
yarn add @opentiny/tiny-robot @opentiny/tiny-robot-kit @opentiny/tiny-robot-svgs
```
```bash
npm install @opentiny/tiny-robot @opentiny/tiny-robot-kit @opentiny/tiny-robot-svgs
```
--------------------------------
### Loading State Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Demonstrates how to display a loading indicator within the bubble using the 'loading' prop.
```vue
```
--------------------------------
### Install TinyRobot SVGs Package
Source: https://github.com/opentiny/tiny-robot/blob/develop/README.md
Install the optional @opentiny/tiny-robot-svgs package if you need to use the SVG icon library standalone or with custom icons.
```bash
pnpm add @opentiny/tiny-robot-svgs
```
--------------------------------
### Avatar and Placement Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Shows how to set a custom avatar and control the placement of the bubble using the 'avatar' and 'placement' props.
```vue
```
--------------------------------
### Built-in Tools Renderer Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Showcases the built-in renderer for displaying tool call lists.
```vue
```
--------------------------------
### 0.4.x useMessage Non-Streaming Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/migration/use-message-migration.md
This example demonstrates the 0.4.x usage of useMessage for non-streaming responses. It requires a responseProvider that returns a Promise.
```typescript
import { useMessage } from '@opentiny/tiny-robot-kit'
import type { MessageRequestBody } from '@opentiny/tiny-robot-kit'
const responseProvider = async (requestBody: MessageRequestBody, abortSignal: AbortSignal) => {
const resp = await fetch('/your-api/chat-completions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(requestBody),
signal: abortSignal,
})
return await resp.json()
}
const { messages, requestState, processingState, isProcessing, sendMessage, send, abortRequest } = useMessage({
initialMessages: [],
responseProvider,
})
```
--------------------------------
### Built-in Loading Renderer Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Demonstrates the usage of the built-in loading renderer, typically used for messages with a loading state.
```vue
```
--------------------------------
### Basic Bubble Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Demonstrates the basic usage of the Bubble component. Content is set using the 'content' prop. CSS variables can be used for styling.
```vue
```
--------------------------------
### Streaming Text Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Demonstrates how to achieve streaming text effects by dynamically updating the 'content' prop.
```vue
```
--------------------------------
### 0.4.x useMessage Streaming Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/migration/use-message-migration.md
This example shows the 0.4.x usage of useMessage for streaming responses. It uses sseStreamToGenerator to convert SSE to an AsyncGenerator.
```typescript
import { sseStreamToGenerator, useMessage } from '@opentiny/tiny-robot-kit'
import type { MessageRequestBody } from '@opentiny/tiny-robot-kit'
const responseProvider = async (requestBody: MessageRequestBody, abortSignal: AbortSignal) => {
const resp = await fetch('/your-api/chat-completions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ...requestBody, stream: true }),
signal: abortSignal,
})
return sseStreamToGenerator(resp, { signal: abortSignal })
}
const engine = useMessage({ responseProvider })
```
--------------------------------
### Markdown Content Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Shows how to render Markdown content within a Bubble component. Requires BubbleProvider for custom renderers.
```vue
```
--------------------------------
### Bubble Slots Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Shows how to utilize the available slots (prefix, suffix, content-footer, after) for adding custom elements around the bubble content.
```vue
Prefix Content
Main Bubble Content
Suffix Content
Footer Content
After Content
```
--------------------------------
### Image Rendering Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Illustrates how to render images within a Bubble component. Supports 'single' and 'split' content render modes for mixed content.
```vue
```
--------------------------------
### Custom Content Resolver Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Demonstrates how to use the 'contentResolver' prop to define custom logic for extracting message content from different fields.
```vue
```
--------------------------------
### Content Render Mode Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Explains the 'contentRenderMode' prop, which controls how multiple content items (text, images) are rendered within a bubble.
```vue
```
--------------------------------
### Interactive file changes confirmation
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/cli-integration.md
During the 'add chat' process, the CLI prompts for confirmation on which files to modify. This example shows the default selection.
```shell
? Select which file changes to apply (all selected by default):
❯◉ create TinyRobotChat.vue — integrate TinyRobot chat component
◉ modify main entry style import — import TinyRobot styles
◉ create .env — add environment variables
◉ modify package.json — add TinyRobot dependencies
```
--------------------------------
### Sender Component CSS Variables Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/sender.md
Demonstrates how to customize the Sender component's appearance using CSS variables for background, text, placeholder colors, and button hover effects.
```css
/* 自定义背景色 */
.my-sender {
--tr-sender-bg-color: #f5f5f5;
--tr-sender-text-color: #333;
}
/* 自定义按钮尺寸 */
.my-sender {
--tr-sender-button-size: 40px;
--tr-sender-button-size-submit: 44px;
}
/* 全局调整 Sender 按钮 Tooltip 间距 */
:root {
--tr-sender-tooltip-gap: 10px;
}
```
--------------------------------
### Custom Composite Content Renderer Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Implements a composite content renderer that handles reasoning content and remaining message content. It uses `useOmitMessageFields` and `useBubbleContentRenderer` for recursive rendering and ensures attributes are passed down.
```vue
```
```vue
Reasoning: {{ props.message.reasoning_content }}
```
--------------------------------
### Migrate Footer Slot from v0.3.x to 0.4.x
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/migration/bubble-migration.md
This example shows the migration of the `footer` slot in v0.3.x to the `content-footer` slot in 0.4.x. Note the change in slot parameters from `bubbleProps` to `messages`, requiring access to the message ID via `messages[0]?.id`.
```vue
id: {{ bubbleProps.id }}
```
```vue
id: {{ messages[0]?.id }}
```
--------------------------------
### Welcome Basic Usage
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/welcome.md
Demonstrates the basic implementation of the Welcome component. Ensure the component is imported and used within a Vue application.
```vue
```
--------------------------------
### AIClient Constructor and Configuration
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/tools/ai-client.md
Details on how to instantiate the AIClient and the configuration interface it accepts.
```APIDOC
## AIClient Constructor
### Description
Instantiates the AIClient with the provided configuration.
### Method
`new AIClient(config: AIModelConfig)`
### Parameters
#### Request Body
- **config** (AIModelConfig) - Required - Configuration object for the AI model.
### AIModelConfig Interface
```typescript
interface AIModelConfig {
provider: AIProvider
apiKey?: string
apiUrl?: string
apiVersion?: string
defaultModel?: string
defaultOptions?: ChatCompletionOptions
}
```
```
--------------------------------
### Create a new TinyRobot project
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/cli-integration.md
Use the 'create' command to scaffold a new TinyRobot project with a specified template.
```bash
npx @opentiny/tiny-robot-cli create --template basic
```
--------------------------------
### Basic Prompts Usage
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/prompts.md
Demonstrates the basic implementation of the Prompts component.
```vue
```
--------------------------------
### Preview Production Build
Source: https://github.com/opentiny/tiny-robot/blob/develop/packages/cli/templates/basic/README.md
Preview the production build locally. This command allows you to test the production version before deploying.
```bash
pnpm preview
```
--------------------------------
### Run Test Suite
Source: https://github.com/opentiny/tiny-robot/blob/develop/README.md
Command to execute the project's test suite.
```bash
pnpm test
```
--------------------------------
### Consecutive Grouping Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Demonstrates the 'consecutive' grouping strategy for BubbleList, merging messages from the same role.
```vue
```
--------------------------------
### Hidden Role Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Demonstrates how to hide messages from a specific role by configuring it as 'hidden' in the role settings.
```vue
```
--------------------------------
### Welcome Component API
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/welcome.md
This section details the properties and slots available for the Welcome component.
```APIDOC
## Welcome Component API
### Description
The Welcome component is a general-purpose component for displaying welcome messages, including titles, descriptions, and icons. It supports custom alignment, icons, and footer content.
### Props
#### Path Parameters
- **title** (string) - Required - The main title to display.
- **description** (string) - Required - A descriptive text accompanying the title.
- **align** (string) - Optional - The alignment of the content. Accepts 'left', 'center', or 'right'. Defaults to 'center'.
- **icon** (VNode) - Optional - A custom icon node. Supports Vue components or JSX.
### Slots
#### Path Parameters
- **footer** - This slot allows for custom content to be placed at the bottom of the component.
```
--------------------------------
### Basic toolPlugin Usage
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/tools/message.md
Demonstrates the fundamental integration of `toolPlugin`. It shows how to declare tools, execute them, and receive status callbacks for tool execution. Ensure `responseProvider` is defined elsewhere.
```typescript
import { toolPlugin, useMessage } from '@opentiny/tiny-robot-kit'
useMessage({
responseProvider,
plugins: [
toolPlugin({
getTools: async () => [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get weather by city name.',
parameters: {
type: 'object',
properties: { city: { type: 'string' } },
required: ['city'],
},
},
},
],
callTool: async (toolCall) => {
const args = JSON.parse(toolCall.function?.arguments || '{}')
return `Weather of ${args.city}: Sunny.`
},
onToolCallEnd: (toolCall, { status }) => console.log('Tool end:', status),
}),
],
})
```
--------------------------------
### Custom Grouping Function Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Shows how to implement custom grouping logic for BubbleList using a custom function.
```vue
```
--------------------------------
### Auto Scroll Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Enables automatic scrolling to the bottom of the BubbleList when new messages arrive using the 'autoScroll' prop.
```vue
```
--------------------------------
### Welcome with Footer Content
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/welcome.md
Shows how to add custom content to the bottom of the Welcome component using the `footer` slot. This is useful for adding action buttons or additional information.
```vue
```
--------------------------------
### Welcome with Custom Alignment
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/welcome.md
Illustrates how to control the text alignment within the Welcome component using the `align` prop. Supported values are 'left', 'center', and 'right'.
```vue
```
--------------------------------
### Build for Production
Source: https://github.com/opentiny/tiny-robot/blob/develop/packages/cli/templates/basic/README.md
Build the project for production deployment. This command optimizes assets and code for a production environment.
```bash
pnpm build
```
--------------------------------
### Integrate TinyRobotChat component in App.vue
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/cli-integration.md
Example of how to import and use the TinyRobotChat component within your main application file (e.g., App.vue).
```vue
```
--------------------------------
### Configure API Key in .env file
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/guide/cli-integration.md
Set your large model API key in the .env file. This example shows the variable for Deepseek.
```dotenv
# .env
VITE_DEEPSEEK_API_KEY=your_api_key
```
--------------------------------
### Configure thinkingPlugin
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/tools/message.md
Shows how to integrate the thinkingPlugin into useMessage, with a placeholder for custom options.
```typescript
import { thinkingPlugin, useMessage } from '@opentiny/tiny-robot-kit'
useMessage({
responseProvider,
plugins: [
thinkingPlugin({ /* 自定义选项 */ }),
],
})
```
--------------------------------
### Attachments Download and Preview Handling
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/attachments.md
Shows how to handle download and preview events for local and network files in the Attachments component, including preventing default behavior.
```vue
```
--------------------------------
### Bubble Shape Example
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/bubble.md
Illustrates different bubble shapes ('rounded', 'corner', 'none') using the 'shape' prop. Custom border-radius can be set via CSS variables.
```vue
```
--------------------------------
### Use TrBubble Component
Source: https://github.com/opentiny/tiny-robot/blob/develop/README.md
Demonstrates how to use the TrBubble component to display AI and user messages within a Vue 3 application. Ensure the component is imported in your script setup.
```vue
```
--------------------------------
### Basic Streaming Request with useMessage
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/tools/message.md
Initiates a streaming request using responseProvider and displays an initial welcome message. It converts SSE fetch responses into an async generator for chunked consumption by useMessage.
```typescript
import { useMessage, sseStreamToGenerator } from '@opentiny/vue-common'
import type { ChatMessage, ResponseProvider } from '@opentiny/vue-common'
const initialMessages: ChatMessage[] = [
{
role: 'assistant',
content: '你好!有什么可以帮您的吗?'
}
]
const responseProvider: ResponseProvider = async (message, options) => {
const response = await fetch('/api/chat-stream', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
messages: [message],
stream: true,
...options.requestBody
})
})
return sseStreamToGenerator(response)
}
const { messages, sendMessage, isProcessing } = useMessage({
initialMessages,
responseProvider
})
async function handleSend(content: string) {
await sendMessage(content)
}
```
--------------------------------
### 0.4.x 消息结构示例
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/migration/bubble-migration.md
展示了 0.4.x 版本中消息数组的结构,支持将 loading 状态直接嵌入消息对象中。
```typescript
const messages = [
{ role: 'assistant', content: 'Hello' },
{ role: 'assistant', loading: true }, // Loading as a message (recommended)
]
```
--------------------------------
### Sender Custom Voice Recognition
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/sender.md
Demonstrates integrating third-party speech recognition services with the `VoiceButton` component. The example references `speechHandlers.ts` for a complete implementation including audio processing and API calls.
```vue
```
--------------------------------
### Basic Anchor Usage
Source: https://github.com/opentiny/tiny-robot/blob/develop/docs/src/components/anchor.md
This snippet shows a basic Anchor component setup for general content scenarios. It emphasizes setting 'data-anchor-id' on chapter nodes and optionally providing a 'scrollContainer' for in-container scrolling.
```vue