@howone/sdk 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/README.md +0 -129
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howone/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Howone client library encapsulating various components and utilities",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/README.md DELETED
@@ -1,129 +0,0 @@
1
- # HowOne Client Library
2
-
3
- A comprehensive client library for AI templates with reusable components, hooks, and services.
4
-
5
- ## Components
6
-
7
- ### Auth Components
8
-
9
- #### LoginForm
10
-
11
- A simplified login form component with email/code authentication and social login buttons.
12
-
13
- ```tsx
14
- import { LoginForm } from "howone-client";
15
-
16
- function LoginPage() {
17
- return <LoginForm />;
18
- }
19
- ```
20
-
21
- # @howone/sdk — Howone 客户端(中文使用手册)
22
-
23
- 本包为 Howone 提供前端 SDK,公开用于创建客户端实例的工厂函数:`createClient`。
24
-
25
- 本说明以 `createClient` 为中心,示例展示如何通过 `createClient` 创建并使用客户端实例来调用业务 API、执行 AI workflow、管理 token 与操作 artifacts。
26
-
27
- 目录
28
-
29
- - 快速概览
30
- - 安装
31
- - 快速开始(以 howone 为主)
32
- - howone 对象详解
33
- - Auth / token 注入(iframe 与 standalone)
34
- - Artifacts 使用
35
- - 进阶指引与常见问题
36
- - 开发与构建
37
-
38
- ## 快速概览
39
-
40
- @howone/sdk — Howone 客户端(简明使用手册)
41
-
42
- 本包提供 Howone 前端 SDK 的核心工厂:`createClient`,用于创建并配置客户端实例。
43
-
44
- ## 快速概览
45
-
46
- - `createClient(opts)`:创建自定义客户端实例(包含 `request`、`workflowRequest`、`executeWorkflow`、`artifacts`、`auth`)。
47
-
48
- ## 安装
49
-
50
- 工作区(monorepo)开发:
51
-
52
- ```bash
53
- pnpm -w install
54
- ```
55
-
56
- 外部项目:
57
-
58
- ```bash
59
- pnpm add @howone/sdk
60
- ```
61
-
62
- ## 快速开始
63
-
64
- 在应用启动时创建并使用客户端实例:
65
-
66
- ```ts
67
- import { createClient } from "@howone/sdk";
68
-
69
- const client = createClient({
70
- projectId: "demo",
71
- baseUrl: "https://your-business.api",
72
- aiBaseUrl: "https://your-ai.api",
73
- authRequired: false,
74
- auth: {
75
- getToken: async () => localStorage.getItem("howone_token") ?? null,
76
- tokenInjection: {
77
- allowedOrigins: ["https://parent.example.com"],
78
- waitMs: 3000,
79
- },
80
- },
81
- });
82
-
83
- // 业务请求
84
- await client.request.post({ url: "/items", data: { name: "hello" } });
85
-
86
- // 执行 AI workflow(使用 workflowRequest)
87
- // 直接调用独立的 AI 请求实例,POST 到 /workflow/{id}/execute
88
- await client.workflowRequest.post({
89
- url: `/workflow/${encodeURIComponent("workflow-id")}/execute`,
90
- data: { input: { text: "hi" } },
91
- });
92
-
93
- // Auth helper
94
- client.auth.setToken("Bearer xxx");
95
- ```
96
-
97
- ## API 概览
98
-
99
- - `client.request` — 业务 API 的 Request 实例(基于 axios 的包装器)。
100
- - `client.workflowRequest` — AI workflow 的 Request 实例(独立于业务 API)。
101
- - `client.workflowRequest` — 用于直接调用 AI workflow 后端,请构造 POST 到 `/workflow/{id}/execute`(或使用 `createAIWorkflowClientAxios` / `createAIWorkflowClient` 提供的高阶 helper)。
102
- - `client.artifacts` — artifacts 客户端:{ create, list, get, setVisibility, delete }。
103
- - `client.auth` — 轻量 auth 辅助:{ setToken, getToken, isAuthenticated, login, logout }。
104
-
105
- ## Auth / token 注入
106
-
107
- 初始化 token 优先级(createClient 默认行为):
108
-
109
- 1. `auth.getToken()` 回调(最高优先级)
110
- 2. 嵌入式场景下的父页面 postMessage 注入(当配置了 `auth.tokenInjection`)
111
- 3. 否则不自动设置 token,需手动 `client.auth.setToken`
112
-
113
- 注意:SDK 只在内存中写入 axios header;持久化请在 `getToken`/`setToken` 中实现或使用后端 HttpOnly cookie。
114
-
115
- ## 开发与构建
116
-
117
- ```bash
118
- pnpm -w install
119
- pnpm -w -F @howone/sdk build
120
- ```
121
-
122
- ## 代码结构(快速浏览)
123
-
124
- - `src/services/index.ts` — createClient 与请求实例构造
125
- - `src/services/ai-workflow.ts` / `ai-workflow-axios.ts` — AI workflow 客户端实现
126
- - `src/services/artifacts-client.ts` — artifacts 封装
127
-
128
- 如需完整示例(iframe 注入、redirect 登录、后端交换)请告知,我可以把示例代码直接添加到 template。
129
- 工作区内(monorepo):