@qfei-design/make-ai-assistant 0.1.0 → 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.
package/dist/sse.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./conversation-DpYszfVd.cjs"),S=1e6,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),p=(e,t,r)=>{const a=Object.keys(e).find(s=>s.toLowerCase()===t.toLowerCase());a&&delete e[a],e[t]=r},A=e=>{const t={};return Array.isArray(e)?e.forEach(([r,a])=>p(t,r,a)):e&&typeof e.forEach=="function"?e.forEach((r,a)=>p(t,a,r)):e&&Object.entries(e).forEach(([r,a])=>p(t,r,a)),p(t,"Accept","text/event-stream"),p(t,"Content-Type","application/json"),t},I=(e,t)=>{if(!u(t))throw new Error("Invalid assistant SSE event: data");if(Object.prototype.hasOwnProperty.call(t,"type"))throw new Error("Invalid assistant SSE event: unsupported field");try{return b.parseAssistantEvent({...t,type:e})}catch(r){throw r instanceof Error&&r.message.startsWith("Invalid assistant event")?new Error(r.message.replace("Invalid assistant event","Invalid assistant SSE event")):r}},w=e=>{if(!e.trim())return;const t=e.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./conversation-Yku9Lzj_.cjs"),S=1e6,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),p=(e,t,r)=>{const a=Object.keys(e).find(s=>s.toLowerCase()===t.toLowerCase());a&&delete e[a],e[t]=r},A=e=>{const t={};return Array.isArray(e)?e.forEach(([r,a])=>p(t,r,a)):e&&typeof e.forEach=="function"?e.forEach((r,a)=>p(t,a,r)):e&&Object.entries(e).forEach(([r,a])=>p(t,r,a)),p(t,"Accept","text/event-stream"),p(t,"Content-Type","application/json"),t},I=(e,t)=>{if(!u(t))throw new Error("Invalid assistant SSE event: data");if(Object.prototype.hasOwnProperty.call(t,"type"))throw new Error("Invalid assistant SSE event: unsupported field");try{return b.parseAssistantEvent({...t,type:e})}catch(r){throw r instanceof Error&&r.message.startsWith("Invalid assistant event")?new Error(r.message.replace("Invalid assistant event","Invalid assistant SSE event")):r}},w=e=>{if(!e.trim())return;const t=e.split(`
2
2
  `),r=t.find(n=>n.startsWith("event:"))?.slice(6).trim(),a=t.filter(n=>n.startsWith("data:")).map(n=>n.slice(5).trimStart()).join(`
3
3
  `);if(t.some(n=>n.startsWith("event:")||n.startsWith("data:"))){if(!r||!a)throw new Error("Invalid assistant SSE event: missing event or data");try{return I(r,JSON.parse(a))}catch(n){throw n instanceof Error&&n.message.startsWith("Invalid assistant SSE event")?n:new Error("Invalid assistant SSE event: JSON")}}};async function*T(e,t,r=S){if(!e.body)throw new Error("当前运行环境无法读取 AI 助手流式响应");const a=e.body.getReader(),s=new TextDecoder;let n="",d=!1,h=!1,l;const c=()=>(l??=a.cancel().catch(o=>{console.error("[make-ai-assistant] SSE reader cancellation failed",{errorType:o instanceof Error?o.name:typeof o})}),l),f=()=>{c()};t?.addEventListener("abort",f,{once:!0});const m=o=>{const i=o.type==="error"||o.type==="run.cancelled"||o.type==="run.complete";return h||=i,i};try{for(;;){if(t?.aborted)throw new DOMException("Aborted","AbortError");const o=await a.read();if(t?.aborted)throw new DOMException("Aborted","AbortError");let i=s.decode(o.value,{stream:!o.done});d&&(i=`\r${i}`,d=!1),!o.done&&i.endsWith("\r")&&(i=i.slice(0,-1),d=!0),o.done&&d&&(i+="\r",d=!1),n+=i.replace(/\r\n|\r/g,`
4
4
  `);let E=n.indexOf(`
package/dist/sse.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { p as b } from "./conversation-B5kECJz8.js";
1
+ import { p as b } from "./conversation-Dy2Sghjv.js";
2
2
  const S = 1e6, u = (e) => typeof e == "object" && e !== null && !Array.isArray(e), E = (e, t, r) => {
3
3
  const a = Object.keys(e).find(
4
4
  (s) => s.toLowerCase() === t.toLowerCase()
package/dist/styles.css CHANGED
@@ -330,6 +330,34 @@
330
330
  padding: 10px 12px;
331
331
  }
332
332
 
333
+ .make-ai-assistant__progress {
334
+ align-items: center;
335
+ color: var(--make-ai-internal-text-secondary);
336
+ display: flex;
337
+ font-size: 12px;
338
+ gap: 7px;
339
+ margin-left: 45px;
340
+ }
341
+
342
+ .make-ai-assistant__progress > span {
343
+ animation: make-ai-pulse 1.2s ease-in-out infinite;
344
+ background: var(--make-ai-internal-accent);
345
+ border-radius: 50%;
346
+ height: 7px;
347
+ width: 7px;
348
+ }
349
+
350
+ .make-ai-assistant__retry {
351
+ background: var(--make-ai-internal-accent);
352
+ border: 0;
353
+ border-radius: 8px;
354
+ color: white;
355
+ cursor: pointer;
356
+ font-size: 12px;
357
+ margin-top: 4px;
358
+ padding: 7px 12px;
359
+ }
360
+
333
361
  .make-ai-assistant__composer-region {
334
362
  background: var(--make-ai-internal-bg);
335
363
  border-top: 1px solid var(--make-ai-internal-border);
@@ -608,6 +636,7 @@ button.make-ai-artifact__record:hover { background: var(--make-ai-internal-accen
608
636
  @media (prefers-reduced-motion: reduce) {
609
637
  .make-ai-assistant__drawer,
610
638
  .make-ai-assistant__launcher-orbit,
639
+ .make-ai-assistant__progress > span,
611
640
  .make-ai-assistant__typing span {
612
641
  animation: none;
613
642
  }
@@ -1,8 +1,57 @@
1
1
  # Make AI 助手后端 V1 配合合同
2
2
 
3
- ## 接口能力
3
+ ## Make Console 当前 Web 接口
4
4
 
5
- 后端第一版至少提供以下能力:
5
+ `/make-console` adapter 对应 Console BFF 的五个语义操作。普通接口由宿主解包响应 `data`,
6
+ SSE 保持原始 `text/event-stream`:
7
+
8
+ | 语义操作 | Console Web 接口 |
9
+ | --- | --- |
10
+ | 查询 Agent | `GET /api/make/console/v1/apps/{appKey}/agent`,读取 `data.agents` |
11
+ | 创建/复用 Session | `POST /api/make/console/v1/apps/{appKey}/agent/{agentID}/sessions` |
12
+ | 读取持久事件 | `GET /api/make/console/v1/apps/{appKey}/agent/{agentID}/sessions/{sessionID}/events?from={seq}&limit={limit}` |
13
+ | 发送消息 | `POST /api/make/console/v1/apps/{appKey}/agent/messages?agentID={agentID}`,Body 为 `{ text }` |
14
+ | 订阅 Run | `GET /api/make/console/v1/apps/{appKey}/agent/{agentID}/sessions/{sessionID}/runs/{runID}/stream?after={cursor}` |
15
+
16
+ Console 浏览器请求使用已有登录态的 `credentials: "include"`,EventSource 使用
17
+ `withCredentials: true`。前端包和 App 业务代码不得读取、写入或复制 `zs_session`。
18
+ 租户、操作人、Agent 指令、模型和 MCP 工具均由 Console/Context/Runtime 服务端链路确定。
19
+
20
+ SSE 事件包括:`ready` 建连、`run-output` 增量或终态、`fallback` 实时流降级以及注释心跳。
21
+ `output_text.delta` 只追加到当前气泡;`response.completed` 后必须读取持久事件完成最终对账;
22
+ `response.failed` 使用稳定 `failureCode`;`fallback` 从用户消息 `seq + 1` 开始轮询。持久
23
+ `message` 事件且 `actor.kind=agent` 的完整文本是最终事实源。
24
+
25
+ Console BFF 与 Make App Browser API 的认证和资源模型不同,不能只替换 base URL 复用同一
26
+ transport。平台包分别提供 `/make-console` 与 `/make-app` 两个入口,聊天 UI 与 Artifact
27
+ 模板保持共享。
28
+
29
+ ## Make App 现有后端接入
30
+
31
+ Make App 内嵌助手可以通过 `/make-app` adapter 对接宿主已有的 Browser API。npm 包只定义
32
+ 下列语义操作,不定义或拼接任何部署路径:
33
+
34
+ | 语义操作 | 输入 | 输出 |
35
+ | --- | --- | --- |
36
+ | 定位会话 | 当前 `MakeAssistantHostContext` | `{ chatId }` |
37
+ | 加载历史 | `{ chatId, cursor: -1, limit }` | `{ messages }` |
38
+ | 提交消息 | `{ chatId, messageId, text }` | `{ chatId, responseId, acceptedCursor }` |
39
+ | 订阅响应 | `{ chatId, responseId, cursor }` | 兼容 adapter 合同的 EventSource |
40
+
41
+ 实际请求由宿主认证边界发起。URL、请求方法、Cookie、Ingress、Service 代理、租户与当前用户
42
+ 解析都由宿主决定;浏览器不能读取或构造服务端凭证。宿主必须传递 `AbortSignal`,并在取消
43
+ 后尽快停止尚未完成的请求。
44
+
45
+ 当前事件包括 `run.started`、`response.delta`、`response.progress`、
46
+ `response.message`、`response.completed`、`response.failed` 和 `heartbeat`。
47
+ `response.message` 是完整文本替换,不是 delta。当前接口没有新建会话、远程取消和
48
+ Artifact;前端必须按能力降级,不应伪造这些能力。
49
+ Make App adapter 会在 `JSON.parse` 前限制单个 EventSource `data` 字符数,默认
50
+ 1,000,000;历史恢复最多接受 200 条消息、1,000,000 字符正文和 500 个 Artifact。
51
+
52
+ ## 通用标准接口能力
53
+
54
+ 当接入自有 Agent 后端或未来统一协议时,建议至少提供以下能力:
6
55
 
7
56
  1. 创建或继续一次 run;
8
57
  2. 通过 SSE 流式返回文本与 Artifact;
@@ -20,7 +69,7 @@
20
69
  | `GET` | `/api/assistant/threads/:threadId` | 会话与历史消息 |
21
70
  | `DELETE` | `/api/assistant/threads/:threadId` | 删除会话,可放到后续版本 |
22
71
 
23
- 宿主 UI 只调用自己的 Service `/api`,不直接调用 Make API、模型服务或透传 Make token。
72
+ 宿主 UI 只经过平台同源入口或自己的 Service `/api`,不直接调用数据 API、模型服务或透传 Make token。
24
73
 
25
74
  ## Run 请求
26
75
 
package/package.ai.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "packageName": "@qfei-design/make-ai-assistant",
3
- "minimumRuntimeVersion": "0.1.0",
3
+ "minimumRuntimeVersion": "0.1.1",
4
4
  "readOrder": [
5
5
  "package.ai.json",
6
6
  "README.md",
@@ -15,14 +15,16 @@
15
15
  "ssrSupported": true
16
16
  },
17
17
  "install": {
18
- "pnpm": "pnpm add @qfei-design/make-ai-assistant@^0.1.0",
19
- "npm": "npm install @qfei-design/make-ai-assistant@^0.1.0",
20
- "yarn": "yarn add @qfei-design/make-ai-assistant@^0.1.0"
18
+ "pnpm": "pnpm add @qfei-design/make-ai-assistant@^0.1.1",
19
+ "npm": "npm install @qfei-design/make-ai-assistant@^0.1.1",
20
+ "yarn": "yarn add @qfei-design/make-ai-assistant@^0.1.1"
21
21
  },
22
22
  "exports": [
23
23
  "@qfei-design/make-ai-assistant",
24
24
  "@qfei-design/make-ai-assistant/react",
25
25
  "@qfei-design/make-ai-assistant/sse",
26
+ "@qfei-design/make-ai-assistant/make-app",
27
+ "@qfei-design/make-ai-assistant/make-console",
26
28
  "@qfei-design/make-ai-assistant/testing",
27
29
  "@qfei-design/make-ai-assistant/styles.css",
28
30
  "@qfei-design/make-ai-assistant/artifact-v1.schema.json"
@@ -37,6 +39,8 @@
37
39
  "Artifact V1 contracts and validation",
38
40
  "Conversation event reduction",
39
41
  "Standard abortable SSE transport",
42
+ "Host-injected Make App AI semantic transport",
43
+ "Host-injected Make Console Agent and Run semantic transport",
40
44
  "Template registration and capability negotiation",
41
45
  "Floating launcher, right drawer and embedded assistant panel",
42
46
  "Platform artifact templates",
@@ -44,7 +48,7 @@
44
48
  ],
45
49
  "hostResponsibilities": [
46
50
  "Current App and route context",
47
- "SSE or AG-UI transport adapter",
51
+ "Authenticated semantic operations and EventSource boundary",
48
52
  "Service authentication and server-side authorization",
49
53
  "Safe action execution and route mapping",
50
54
  "Optional App-specific templates and theme variables"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qfei-design/make-ai-assistant",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Platform-wide Make AI Assistant contracts, React shell, and context-aware artifact templates.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -25,6 +25,16 @@
25
25
  "import": "./dist/sse.mjs",
26
26
  "require": "./dist/sse.cjs"
27
27
  },
28
+ "./make-app": {
29
+ "types": "./dist/make-app.d.ts",
30
+ "import": "./dist/make-app.mjs",
31
+ "require": "./dist/make-app.cjs"
32
+ },
33
+ "./make-console": {
34
+ "types": "./dist/make-console.d.ts",
35
+ "import": "./dist/make-console.mjs",
36
+ "require": "./dist/make-console.cjs"
37
+ },
28
38
  "./testing": {
29
39
  "types": "./dist/testing/index.d.ts",
30
40
  "import": "./dist/testing.mjs",
package/recipes.json CHANGED
@@ -39,6 +39,42 @@
39
39
  "Ending a stream without run.complete, run.cancelled or error"
40
40
  ]
41
41
  },
42
+ {
43
+ "id": "make-app-browser-api",
44
+ "summary": "Connect the assistant to the existing Make App AI Browser API.",
45
+ "use": [
46
+ "@qfei-design/make-ai-assistant/make-app:createMakeAppAssistantTransport"
47
+ ],
48
+ "hostProvides": [
49
+ "Authenticated semantic callbacks for chat lookup, history and message submission",
50
+ "Credentialed response EventSource factory",
51
+ "Current Make App context"
52
+ ],
53
+ "readNext": ["README.md", "PUBLIC_API.md", "docs/backend-contract.md"],
54
+ "commonMistakes": [
55
+ "Creating or forwarding service credentials in browser code",
56
+ "Treating response.message as a text delta",
57
+ "Showing new-chat or remote-cancel controls when the backend does not support them"
58
+ ]
59
+ },
60
+ {
61
+ "id": "make-console-agent-api",
62
+ "summary": "Connect the assistant to the Make Console Agent, Session, durable-event and Run SSE APIs.",
63
+ "use": [
64
+ "@qfei-design/make-ai-assistant/make-console:createMakeConsoleAssistantTransport"
65
+ ],
66
+ "hostProvides": [
67
+ "Authenticated semantic callbacks for Agent lookup, Session lookup, durable events and message submission",
68
+ "Credentialed Run EventSource factory",
69
+ "Current Make Console App context"
70
+ ],
71
+ "readNext": ["README.md", "PUBLIC_API.md", "docs/backend-contract.md"],
72
+ "commonMistakes": [
73
+ "Reading or copying zs_session in application code",
74
+ "Treating SSE as the durable source of truth",
75
+ "Reusing the Make App Browser API transport by only replacing its base URL"
76
+ ]
77
+ },
42
78
  {
43
79
  "id": "app-artifact-template",
44
80
  "summary": "Register an App-specific result template without changing the platform package.",