@qfei-design/make-ai-assistant 0.2.9 → 0.2.11
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/PUBLIC_API.md +17 -23
- package/README.md +12 -24
- package/capabilities.json +36 -9
- package/dist/conversation-CZfbgCXd.js +1111 -0
- package/dist/conversation-Cvh-IVRV.cjs +1 -0
- package/dist/core/conversation-management.d.ts +212 -0
- package/dist/core/conversation.d.ts +34 -2
- package/dist/core/index.d.ts +2 -0
- package/dist/core/response-state.d.ts +8 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +4 -4
- package/dist/make-app/protocol.d.ts +27 -0
- package/dist/make-app/stream.d.ts +20 -0
- package/dist/make-app.cjs +1 -1
- package/dist/make-app.d.ts +46 -11
- package/dist/make-app.mjs +698 -259
- package/dist/make-console.cjs +1 -1
- package/dist/make-console.mjs +1 -1
- package/dist/react/conversation-controls.d.ts +20 -0
- package/dist/react/use-attachments.d.ts +33 -0
- package/dist/react/use-conversation-manager.d.ts +35 -0
- package/dist/react.cjs +4 -4
- package/dist/react.mjs +2000 -845
- package/dist/sse.cjs +1 -1
- package/dist/sse.mjs +1 -1
- package/dist/styles.css +428 -13
- package/docs/backend-contract.md +8 -21
- package/docs/make-app-integration.md +80 -0
- package/examples/make-app/README.md +11 -0
- package/examples/make-app/index.html +5 -0
- package/examples/make-app/main.tsx +34 -0
- package/examples/make-app/style.css +4 -0
- package/examples/make-app/transport.ts +163 -0
- package/examples/make-app/vite.config.ts +7 -0
- package/package.json +10 -2
- package/recipes.json +36 -13
- package/dist/conversation-B7eGUXi-.js +0 -727
- package/dist/conversation-Cv1wdvCR.cjs +0 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Make App 助手接入验收</title></head>
|
|
4
|
+
<body><div id="root"></div><script type="module" src="/main.tsx"></script></body>
|
|
5
|
+
</html>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { StrictMode } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import { AssistantPanel } from "@qfei-design/make-ai-assistant/react";
|
|
4
|
+
import { createHostTransport, type Configuration } from "./transport";
|
|
5
|
+
import "@qfei-design/make-ai-assistant/styles.css";
|
|
6
|
+
import "./style.css";
|
|
7
|
+
|
|
8
|
+
const config: Configuration = await fetch("/runtime-config").then((response) =>
|
|
9
|
+
response.json(),
|
|
10
|
+
);
|
|
11
|
+
if (
|
|
12
|
+
![config.appKey, config.agentId, config.identityKey].every(
|
|
13
|
+
(value) => typeof value === "string" && value.length > 0,
|
|
14
|
+
)
|
|
15
|
+
)
|
|
16
|
+
throw new Error("缺少宿主产品、Agent 或身份配置");
|
|
17
|
+
const transport = createHostTransport(config);
|
|
18
|
+
createRoot(document.getElementById("root")!).render(
|
|
19
|
+
<StrictMode>
|
|
20
|
+
<main className="example-shell">
|
|
21
|
+
<p className="example-notice">本地接入验收 · 使用宿主配置的真实后端</p>
|
|
22
|
+
<AssistantPanel
|
|
23
|
+
context={{
|
|
24
|
+
app: { id: config.appKey, name: config.appName },
|
|
25
|
+
location: { pathname: "/" },
|
|
26
|
+
locale: "zh-CN",
|
|
27
|
+
timezone: "Asia/Shanghai",
|
|
28
|
+
}}
|
|
29
|
+
transport={transport}
|
|
30
|
+
suggestions={[]}
|
|
31
|
+
/>
|
|
32
|
+
</main>
|
|
33
|
+
</StrictMode>,
|
|
34
|
+
);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
body { margin: 0; background: #f4f6f9; font-family: system-ui, sans-serif; }
|
|
2
|
+
.example-shell { margin: 20px auto; max-width: 880px; padding: 0 12px; }
|
|
3
|
+
.example-notice { color: #617086; font-size: 12px; }
|
|
4
|
+
.example-shell .make-ai-assistant__panel { background: white; border: 1px solid #dbe3ef; border-radius: 12px; height: calc(100dvh - 85px); min-height: 420px; }
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMakeAppAssistantTransport,
|
|
3
|
+
type MakeAppAssistantEventSource,
|
|
4
|
+
type MakeAppAssistantEventSourceEvent,
|
|
5
|
+
} from "@qfei-design/make-ai-assistant/make-app";
|
|
6
|
+
export interface Configuration {
|
|
7
|
+
appKey: string;
|
|
8
|
+
appName: string;
|
|
9
|
+
agentId: string;
|
|
10
|
+
identityKey: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createHostTransport(
|
|
14
|
+
config: Configuration,
|
|
15
|
+
fetcher: typeof fetch = fetch,
|
|
16
|
+
) {
|
|
17
|
+
const prefix = "/api/make/app/ai";
|
|
18
|
+
const id = encodeURIComponent;
|
|
19
|
+
const query = (values: Record<string, string | number | undefined>) =>
|
|
20
|
+
new URLSearchParams(
|
|
21
|
+
Object.entries(values)
|
|
22
|
+
.filter(
|
|
23
|
+
(entry): entry is [string, string | number] => entry[1] !== undefined,
|
|
24
|
+
)
|
|
25
|
+
.map(([key, value]) => [key, String(value)]),
|
|
26
|
+
).toString();
|
|
27
|
+
const request = async (
|
|
28
|
+
path: string,
|
|
29
|
+
init: RequestInit = {},
|
|
30
|
+
binary = false,
|
|
31
|
+
) => {
|
|
32
|
+
// 替换为 POC 已有的认证请求封装;本示例同样只访问宿主同源接口。
|
|
33
|
+
const response = await fetcher(prefix + path, {
|
|
34
|
+
credentials: "include",
|
|
35
|
+
...init,
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const body = await response.json().catch(() => ({}));
|
|
39
|
+
throw Object.assign(new Error("请求未完成"), {
|
|
40
|
+
status: response.status,
|
|
41
|
+
code: body.code,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (response.status === 204) return undefined;
|
|
45
|
+
return binary
|
|
46
|
+
? new Uint8Array(await response.arrayBuffer())
|
|
47
|
+
: response.json();
|
|
48
|
+
};
|
|
49
|
+
const json = (
|
|
50
|
+
method: string,
|
|
51
|
+
body: unknown,
|
|
52
|
+
signal?: AbortSignal,
|
|
53
|
+
): RequestInit => ({
|
|
54
|
+
method,
|
|
55
|
+
signal,
|
|
56
|
+
headers: { "Content-Type": "application/json" },
|
|
57
|
+
body: JSON.stringify(body),
|
|
58
|
+
});
|
|
59
|
+
return createMakeAppAssistantTransport({
|
|
60
|
+
resolveScope: () => ({
|
|
61
|
+
appKey: config.appKey,
|
|
62
|
+
agentId: config.agentId,
|
|
63
|
+
identityKey: config.identityKey,
|
|
64
|
+
}),
|
|
65
|
+
listAgents: (input, options) => request(`/agents?${query(input)}`, options),
|
|
66
|
+
listChats: (input, options) => request(`/chats?${query(input)}`, options),
|
|
67
|
+
createChat: (input, options) =>
|
|
68
|
+
request("/chats", json("POST", input, options.signal)),
|
|
69
|
+
getChat: ({ chatId }, options) => request(`/chats/${id(chatId)}`, options),
|
|
70
|
+
updateChat: ({ chatId, ...body }, options) =>
|
|
71
|
+
request(`/chats/${id(chatId)}`, json("PATCH", body, options.signal)),
|
|
72
|
+
deleteChat: async ({ chatId, expectedRevision }, options) => {
|
|
73
|
+
await request(`/chats/${id(chatId)}?${query({ expectedRevision })}`, {
|
|
74
|
+
method: "DELETE",
|
|
75
|
+
signal: options.signal,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
loadHistory: ({ chatId, ...page }, options) =>
|
|
79
|
+
request(`/chats/${id(chatId)}/messages?${query(page)}`, options),
|
|
80
|
+
sendMessage: ({ chatId, ...body }, options) =>
|
|
81
|
+
request(
|
|
82
|
+
`/chats/${id(chatId)}/messages`,
|
|
83
|
+
json("POST", body, options.signal),
|
|
84
|
+
),
|
|
85
|
+
getResponse: ({ chatId, responseId }, options) =>
|
|
86
|
+
request(`/chats/${id(chatId)}/responses/${id(responseId)}`, options),
|
|
87
|
+
cancelResponse: ({ chatId, responseId }, options) =>
|
|
88
|
+
request(
|
|
89
|
+
`/chats/${id(chatId)}/responses/${id(responseId)}/cancel`,
|
|
90
|
+
json("POST", {}, options.signal),
|
|
91
|
+
),
|
|
92
|
+
setFeedback: ({ chatId, messageId, ...body }, options) =>
|
|
93
|
+
request(
|
|
94
|
+
`/chats/${id(chatId)}/messages/${id(messageId)}/feedback`,
|
|
95
|
+
json("PUT", body, options.signal),
|
|
96
|
+
),
|
|
97
|
+
startUpload: ({ chatId, ...body }, options) =>
|
|
98
|
+
request(
|
|
99
|
+
`/chats/${id(chatId)}/uploads`,
|
|
100
|
+
json("POST", body, options.signal),
|
|
101
|
+
),
|
|
102
|
+
getUpload: ({ chatId, uploadId }, options) =>
|
|
103
|
+
request(`/chats/${id(chatId)}/uploads/${id(uploadId)}`, options),
|
|
104
|
+
uploadPart: async ({ chatId, uploadId, part, bytes }, options) => {
|
|
105
|
+
await request(
|
|
106
|
+
`/chats/${id(chatId)}/uploads/${id(uploadId)}/parts/${part}`,
|
|
107
|
+
{
|
|
108
|
+
method: "PUT",
|
|
109
|
+
signal: options.signal,
|
|
110
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
111
|
+
body: new Uint8Array(bytes).buffer,
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
completeUpload: ({ chatId, uploadId }, options) =>
|
|
116
|
+
request(
|
|
117
|
+
`/chats/${id(chatId)}/uploads/${id(uploadId)}/complete`,
|
|
118
|
+
json("POST", {}, options.signal),
|
|
119
|
+
),
|
|
120
|
+
readContent: async ({ chatId, contentRef }, options) =>
|
|
121
|
+
request(`/chats/${id(chatId)}/content/${id(contentRef)}`, options, true),
|
|
122
|
+
eventSourceFactory: ({ chatId, responseId, cursor }, init) => {
|
|
123
|
+
const source = new EventSource(
|
|
124
|
+
`${prefix}/chats/${id(chatId)}/events?${query({ responseId, cursor })}`,
|
|
125
|
+
init,
|
|
126
|
+
);
|
|
127
|
+
type Listener = (event: MakeAppAssistantEventSourceEvent) => void;
|
|
128
|
+
const listeners = new Map<string, Map<Listener, EventListener>>();
|
|
129
|
+
const wrapped: MakeAppAssistantEventSource = {
|
|
130
|
+
get readyState() {
|
|
131
|
+
return source.readyState;
|
|
132
|
+
},
|
|
133
|
+
onerror: null,
|
|
134
|
+
addEventListener(type, listener) {
|
|
135
|
+
const receive: EventListener = (event) => {
|
|
136
|
+
const message = event as MessageEvent<unknown>;
|
|
137
|
+
if (typeof message.data === "string")
|
|
138
|
+
listener({
|
|
139
|
+
data: message.data,
|
|
140
|
+
lastEventId: message.lastEventId,
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
const group = listeners.get(type) ?? new Map();
|
|
144
|
+
group.set(listener, receive);
|
|
145
|
+
listeners.set(type, group);
|
|
146
|
+
source.addEventListener(type, receive);
|
|
147
|
+
},
|
|
148
|
+
removeEventListener(type, listener) {
|
|
149
|
+
const receive = listeners.get(type)?.get(listener);
|
|
150
|
+
if (receive) source.removeEventListener(type, receive);
|
|
151
|
+
listeners.get(type)?.delete(listener);
|
|
152
|
+
},
|
|
153
|
+
close() {
|
|
154
|
+
source.close();
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
source.onerror = (event) => wrapped.onerror?.(event);
|
|
158
|
+
return wrapped;
|
|
159
|
+
},
|
|
160
|
+
// 按实际模型验收开放类型;上传存储能力与模型理解能力独立。
|
|
161
|
+
modelInputKinds: ["text"],
|
|
162
|
+
});
|
|
163
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qfei-design/make-ai-assistant",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Platform-wide Make AI Assistant contracts, React shell, and context-aware artifact templates.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -55,13 +55,21 @@
|
|
|
55
55
|
"recipes.json",
|
|
56
56
|
"capabilities.json",
|
|
57
57
|
"docs/artifact-v1.md",
|
|
58
|
-
"docs/backend-contract.md"
|
|
58
|
+
"docs/backend-contract.md",
|
|
59
|
+
"docs/make-app-integration.md",
|
|
60
|
+
"examples/make-app/main.tsx",
|
|
61
|
+
"examples/make-app/style.css",
|
|
62
|
+
"examples/make-app/README.md",
|
|
63
|
+
"examples/make-app/vite.config.ts",
|
|
64
|
+
"examples/make-app/index.html",
|
|
65
|
+
"examples/make-app/transport.ts"
|
|
59
66
|
],
|
|
60
67
|
"scripts": {
|
|
61
68
|
"test": "vitest run",
|
|
62
69
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
63
70
|
"build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly && node scripts/copy-styles.mjs && node scripts/smoke-dist.mjs",
|
|
64
71
|
"gallery:build": "vite build --config examples/gallery/vite.config.ts",
|
|
72
|
+
"make-app:build": "vite build --config examples/make-app/vite.config.ts",
|
|
65
73
|
"sprint:init": "qfei-release sprint-init",
|
|
66
74
|
"release:init": "qfei-release release-init",
|
|
67
75
|
"publish:alpha": "qfei-release publish --channel alpha",
|
package/recipes.json
CHANGED
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
"AssistantTransport",
|
|
15
15
|
"ArtifactActionHandler"
|
|
16
16
|
],
|
|
17
|
-
"readNext": [
|
|
17
|
+
"readNext": [
|
|
18
|
+
"README.md",
|
|
19
|
+
"PUBLIC_API.md"
|
|
20
|
+
],
|
|
18
21
|
"commonMistakes": [
|
|
19
22
|
"Calling Make API directly from the UI",
|
|
20
23
|
"Passing Make tokens through the package",
|
|
@@ -32,7 +35,10 @@
|
|
|
32
35
|
"Service endpoint",
|
|
33
36
|
"Optional credentials and request headers"
|
|
34
37
|
],
|
|
35
|
-
"readNext": [
|
|
38
|
+
"readNext": [
|
|
39
|
+
"README.md",
|
|
40
|
+
"docs/backend-contract.md"
|
|
41
|
+
],
|
|
36
42
|
"commonMistakes": [
|
|
37
43
|
"Importing the SSE implementation from the headless root",
|
|
38
44
|
"Sending Make tokens from the browser",
|
|
@@ -41,20 +47,27 @@
|
|
|
41
47
|
},
|
|
42
48
|
{
|
|
43
49
|
"id": "make-app-browser-api",
|
|
44
|
-
"summary": "
|
|
50
|
+
"summary": "接入当前 Make App 多会话、反馈、类型化附件和 item/part SSE 合同。",
|
|
45
51
|
"use": [
|
|
46
52
|
"@qfei-design/make-ai-assistant/make-app:createMakeAppAssistantTransport"
|
|
47
53
|
],
|
|
48
54
|
"hostProvides": [
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
55
|
+
"明确 appKey/agentId/identityKey 的 resolveScope",
|
|
56
|
+
"17 项已认证语义回调及带凭据的 EventSource 工厂",
|
|
57
|
+
"实际模型已验收的 modelInputKinds"
|
|
58
|
+
],
|
|
59
|
+
"readNext": [
|
|
60
|
+
"README.md",
|
|
61
|
+
"PUBLIC_API.md",
|
|
62
|
+
"docs/backend-contract.md",
|
|
63
|
+
"docs/make-app-integration.md"
|
|
52
64
|
],
|
|
53
|
-
"readNext": ["README.md", "PUBLIC_API.md", "docs/backend-contract.md"],
|
|
54
65
|
"commonMistakes": [
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
66
|
+
"浏览器读写服务凭据",
|
|
67
|
+
"将 itemId 当作持久反馈 messageId",
|
|
68
|
+
"用关闭连接冒充远程取消",
|
|
69
|
+
"忽略空历史页的 hasMore",
|
|
70
|
+
"把上传成功视为模型理解成功"
|
|
58
71
|
]
|
|
59
72
|
},
|
|
60
73
|
{
|
|
@@ -68,7 +81,11 @@
|
|
|
68
81
|
"Credentialed Run EventSource factory",
|
|
69
82
|
"Current Make Console App context"
|
|
70
83
|
],
|
|
71
|
-
"readNext": [
|
|
84
|
+
"readNext": [
|
|
85
|
+
"README.md",
|
|
86
|
+
"PUBLIC_API.md",
|
|
87
|
+
"docs/backend-contract.md"
|
|
88
|
+
],
|
|
72
89
|
"commonMistakes": [
|
|
73
90
|
"Reading or copying zs_session in application code",
|
|
74
91
|
"Treating SSE as the durable source of truth",
|
|
@@ -88,7 +105,10 @@
|
|
|
88
105
|
"canRender predicate based on Artifact semantics and host context",
|
|
89
106
|
"Accessible React presentation"
|
|
90
107
|
],
|
|
91
|
-
"readNext": [
|
|
108
|
+
"readNext": [
|
|
109
|
+
"README.md",
|
|
110
|
+
"PUBLIC_API.md"
|
|
111
|
+
],
|
|
92
112
|
"commonMistakes": [
|
|
93
113
|
"Registering a business-specific template as a platform default",
|
|
94
114
|
"Using a backend component name as an executable import path",
|
|
@@ -106,7 +126,10 @@
|
|
|
106
126
|
"App context",
|
|
107
127
|
"Optional request-specific mock response"
|
|
108
128
|
],
|
|
109
|
-
"readNext": [
|
|
129
|
+
"readNext": [
|
|
130
|
+
"README.md",
|
|
131
|
+
"PUBLIC_API.md"
|
|
132
|
+
],
|
|
110
133
|
"commonMistakes": [
|
|
111
134
|
"Building a second mock-only component path",
|
|
112
135
|
"Putting POC business fixtures into platform default templates",
|