Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/.vitepress/theme/Layout.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="tiny-robot-layout">
<div class="tr-layout">
<!-- 自定义顶部导航栏 -->
<CustomHeader />

Expand Down Expand Up @@ -44,7 +44,7 @@ const DefaultLayout = DefaultTheme.Layout
</script>

<style scoped>
.tiny-robot-layout {
.tr-layout {
min-height: 100vh;
display: flex;
flex-direction: column;
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/themeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const sharedSidebarItems = [
{ text: '快速开始', link: 'quick-start' },
Comment thread
gene9831 marked this conversation as resolved.
{ text: '主题配置', link: 'theme-config' },
{ text: '更新日志', link: 'update-log' },
{ text: 'CLI 接入', link: 'cli-integration' },
],
},
{
Expand Down Expand Up @@ -38,7 +39,6 @@ const sharedSidebarItems = [
{ text: 'useConversation 会话数据管理', link: 'conversation' },
{ text: 'AIClient 模型交互工具类', link: 'ai-client' },
{ text: '工具函数', link: 'utils' },
{ text: 'CLI 命令行工具', link: 'cli' },
],
},
{
Expand Down
146 changes: 146 additions & 0 deletions docs/src/guide/cli-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
outline: [1, 3]
---

# CLI 接入

TinyRobot 提供官方 CLI 工具 [`@opentiny/tiny-robot-cli`](https://www.npmjs.com/package/@opentiny/tiny-robot-cli),用于:

- `create` 创建完整的 TinyRobot 示例工程
- `add` 向现有 Vue 项目快速注入聊天能力

## 安装方式

无需全局安装,可直接通过 `npx` 或 `pnpm dlx` 使用。

```bash
# npm
npx @opentiny/tiny-robot-cli

# pnpm
pnpm dlx @opentiny/tiny-robot-cli
```

## create

创建一个完整的 TinyRobot 工程。

```bash
npx @opentiny/tiny-robot-cli create <project-name> --template basic
```

示例:

```bash
npx @opentiny/tiny-robot-cli create my-app --template basic
```

创建完成后:

```bash
cd my-app
pnpm install

# configure your API key
# edit .env

pnpm dev
```

create 命令特性

- 自动生成 Vue 工程结构
- 内置 TinyRobot 基础聊天能力
- 自动生成环境变量模板
- 提供可直接运行的示例页面

## add

向现有项目添加 TinyRobot 能力。

```bash
npx @opentiny/tiny-robot-cli add chat
```

CLI 会自动检测当前项目或 workspace 包,并引导选择目标 package。

```bash
npx @opentiny/tiny-robot-cli add chat
```

执行后,CLI 会根据当前项目状态自动处理以下内容:

| 变更项 | 说明 |
| ----------------------- | -------------------------------------- |
| `src/TinyRobotChat.vue` | 集成 TinyRobot Chat 组件 |
| `main.ts` / `main.js` | 自动插入 TinyRobot 样式导入 |
| `.env` | 添加所需环境变量 |
| `package.json` | 添加或升级 `@opentiny/tiny-robot` 依赖 |

执行过程中会展示变更确认列表,可按需勾选。

```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
```

### 下一步操作

**导入样式**

如果没有 `src/main.ts` 或者 `src/main.js` 文件,CLI 不会写入样式相关代码,此时你需要手动在应用入口导入样式

```shell
import '@opentiny/tiny-robot/dist/style.css'
```

**接入组件**

在你的主业务组件中,添加 CLI 创建的 `<TinyRobotChat/>` 组件代码。比如 `src/App.vue` 是你的主应用

```vue
<!-- src/App.vue -->
<script setup lang="ts">
import HelloWord from './components/HelloWorld.vue'
import TinyRobotChat from './TinyRobotChat.vue' // [!code ++]
</script>

<template>
<HelloWorld />
<!-- [!code ++] -->
<TinyRobotChat />
</template>
```

**配置 API_KEY**

在 `.env` 文件里面配置大模型的 `API_KEY`。比如

```shell
# .env
VITE_DEEPSEEK_API_KEY=your_api_key
```
Comment thread
gene9831 marked this conversation as resolved.

**更新依赖**

如果依赖更新了,不要忘记安装

```shell
npm install
pnpm install
```

现在你可以启动你的应用体验 AI 聊天应用了

### Workspace 支持

CLI 支持 pnpm workspace。

当检测到多 package workspace 时:

- 自动识别 workspace 根目录
- 自动识别 package 列表
- 支持交互式选择目标 package
47 changes: 44 additions & 3 deletions docs/src/guide/quick-start.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
outline: deep
outline: [1, 3]
---

# 快速开始
Expand All @@ -16,6 +16,15 @@ TinyRobot 是符合 OpenTiny Design 设计体系的 AI 组件库,提供了丰

## 安装

::: tip 推荐
TinyRobot 提供官方 CLI 工具,可快速创建示例项目或向现有 Vue 项目注入聊天能力。

- 查看 [CLI 快速接入](#cli-快速接入)
- 查看 [CLI 详细文档](./cli-integration)

如果你是首次体验 TinyRobot,推荐优先使用 CLI。
:::

### 依赖说明

TinyRobot 由以下几个核心包组成:
Expand Down Expand Up @@ -110,10 +119,10 @@ import { TrBubble } from '@opentiny/tiny-robot'
import { createApp } from 'vue'
import App from './App.vue'
import TinyRobot from '@opentiny/tiny-robot' // 全量引入组件库 [!code ++]
import '@opentiny/tiny-robot/dist/style.css' // 引入样式 [!code ++]
import '@opentiny/tiny-robot/dist/style.css' // 引入样式 [!code ++]

const app = createApp(App)
app.use(TinyRobot) // 注册所有组件 [!code ++]
app.use(TinyRobot) // 注册所有组件 [!code ++]

app.mount('#app')
```
Expand All @@ -135,6 +144,38 @@ app.mount('#app')
<!-- 无需在 script 中引入组件 -->
```

## CLI 快速接入

除了手动安装和配置组件,TinyRobot 还提供了官方 CLI 工具,可以帮助你快速创建 AI 应用或向现有 Vue 项目注入聊天能力。

### 创建示例项目

```bash
npx @opentiny/tiny-robot-cli create my-app --template basic
```

自动生成:

- Vue 工程结构
- TinyRobot 聊天示例
- 环境变量模板
- 开箱即用的演示页面

### 接入现有项目

```bash
npx @opentiny/tiny-robot-cli add chat
```

自动完成:

- 安装 TinyRobot 依赖
- 导入样式文件
- 创建聊天组件
- 环境变量模板

👉 更多功能请查看 [CLI 接入](./cli-integration)

## 注意事项

1. **样式引入**:无论使用哪种引入方式,都必须在 `main.js/main.ts` 中引入样式文件 `@opentiny/tiny-robot/dist/style.css`
Expand Down
64 changes: 0 additions & 64 deletions docs/src/tools/cli.md

This file was deleted.

Loading