@aliyunrds/ctxdb-dsh 0.0.0-stage → 0.0.1-beta.3
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/README.md +77 -2
- package/cordis.patch.yml +6 -0
- package/dist/client.js +482 -0
- package/dist/configure-host.js +249 -0
- package/dist/configure.js +1988 -0
- package/dist/index.js +9272 -0
- package/package.json +56 -3
- package/skills/contextdb-dsh/SKILL.md +20 -0
package/README.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ContextDB 记忆与知识库
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
将 ContextDB 工作空间接入 DeepSeek Harness。你可以让助手查找以前保存的偏好和项目约定,也可以直接在对话里查询团队知识库。换一个会话,同样能检索这些内容。
|
|
4
|
+
|
|
5
|
+
## 安装插件
|
|
6
|
+
|
|
7
|
+
1. 在 DSH 左侧打开 **插件**,点击 **添加插件**。
|
|
8
|
+
2. 粘贴收到的 `.tgz` 安装包的完整路径,点击 **安装**,确认插件已启用。
|
|
9
|
+
|
|
10
|
+
适用于 DSH `0.2.2` 系列,包括 RC 和正式版。
|
|
11
|
+
|
|
12
|
+
## 连接工作空间
|
|
13
|
+
|
|
14
|
+
打开 **设置 → ContextDB**,在 **Site** 选择工作空间所在站点,再选择一种认证方式。
|
|
15
|
+
|
|
16
|
+
- 选择 **Device Code(浏览器登录)** 后,点击 **Start authorization**,在浏览器里选择工作空间并确认授权。如果浏览器未自动打开,点击 **Open authorization page**。从 API Key 切换时,原连接会一直可用,直到浏览器授权成功。授权成功后,设置页会显示工作空间和授权成员的 ID,同一站点可点 **Reauthorize** 重新授权。
|
|
17
|
+
- 已有工作空间的 API Key 时,选择 **API Key**,粘贴并点击 **Save API Key**。DSH 会在本机保存凭据。更换时输入新 Key,再点 **Replace API Key**。
|
|
18
|
+
|
|
19
|
+
Device Code 模式下,也可以在对话中输入 `/ctxdb-login`(中国站)或 `/ctxdb-login intl`(国际站)。插件会尝试打开系统浏览器,并在对话里显示授权链接和设备码。
|
|
20
|
+
|
|
21
|
+
## 在终端使用
|
|
22
|
+
|
|
23
|
+
在 `--profile` 后填要连接 ContextDB 的 DSH profile 名。下面以 `web` 为例,也可以指定 `headless` 或自建 profile。配置 `desktop` 时,先打开一次桌面客户端完成初始化,再完全退出,使用 Desktop 自带的 `dsh` 命令。
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
dsh plugin --profile web add /path/to/aliyunrds-ctxdb-dsh-0.0.1-beta.3.tgz
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Device Code 登录**。中国站用 `cn`,国际站用 `intl`。
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
dsh plugin --profile web exec ctxdb-dsh configure --site cn --device-code
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
命令会尝试打开浏览器,并在终端显示授权链接和用户码。也可以在另一台设备上打开链接。授权成功后,登录会话保存在所选 profile 里。按 Ctrl+C 可取消并保留原连接。
|
|
36
|
+
|
|
37
|
+
**API Key 配置**。运行下面的命令,根据提示输入 Key,终端会隐藏输入。再次运行可以更换该 profile 的 Key。
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
dsh plugin --profile web exec ctxdb-dsh configure --site cn
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
脚本或 CI 可以通过标准输入传入 Key。
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
printf '%s\n' "$CONTEXTDB_API_KEY" | dsh plugin --profile web exec ctxdb-dsh configure --site cn --key-stdin
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
API Key 由 DSH 原生凭据服务保存,每个 profile 和站点使用独立的凭据引用。如果 `ctxdb-dsh` 已在 PATH 中,也可以直接运行 `ctxdb-dsh configure --profile web --site cn --device-code`,或用同一写法输入 API Key。
|
|
50
|
+
|
|
51
|
+
## 在对话中使用
|
|
52
|
+
|
|
53
|
+
连接后,可以直接把这类问题发给助手。
|
|
54
|
+
|
|
55
|
+
- 「记住发布前要检查备份。如果以后改了,我会告诉你更新这条记忆。」
|
|
56
|
+
- 「帮我回顾一下我之前保存的发布检查事项。」
|
|
57
|
+
- 「在团队知识库里查一下回滚流程,告诉我依据的是哪份文档。」
|
|
58
|
+
- 「列出团队知识库里的文档,读一下发布指南。」
|
|
59
|
+
- 「把我刚附上的 `notes.md` 上传到团队知识库。」
|
|
60
|
+
- 「把工作区里的 `reports/weekly.md` 上传到团队知识库。」
|
|
61
|
+
- 「查一下发布系统关联的实体,给出支持这些关系的文档片段。」
|
|
62
|
+
- 「在团队 Wiki 里找到发布流程页,补上我刚才给出的检查步骤。」
|
|
63
|
+
|
|
64
|
+
日常搜索、上传文件和读 Wiki 时,助手会直接使用插件工具。你也可以说「列出待审核的知识库文档」或「把这些记忆整理成文档草稿」。助手可以按需加载随包的 **contextdb-dsh** 使用指南,用 `ctxdb` 工具查询子命令和参数。
|
|
65
|
+
|
|
66
|
+
上传和替换文件时,助手可以使用当前会话的附件或你给出的文件路径。DSH 会尝试读取指定文件,并在读取失败时提示原因。上传受理后,可以让助手查看入库状态。Wiki 正文修改按当前页面版本提交。
|
|
67
|
+
|
|
68
|
+
## 它如何工作
|
|
69
|
+
|
|
70
|
+
默认开启自动召回。你发出消息时,插件会用消息文本在 ContextDB 查找相关记忆,把找到的片段补充给助手,供本轮回答参考。你也可以让助手按需查知识库。ContextDB 按当前授权返回可访问的内容。
|
|
71
|
+
|
|
72
|
+
自动采集默认开启。连接工作空间后,插件会在符合条件的对话轮次结束时,将用户和助手的对话文字发送到 ContextDB,用于生成今后可检索的记忆。调用 ContextDB 写入工具的轮次会跳过自动采集,例如删除记忆、上传文档或编辑 Wiki。可随时在 **设置 → ContextDB → Context settings** 中关闭自动采集或自动召回。
|
|
73
|
+
|
|
74
|
+
在 **Memory scope** 可以设置采集写入的标识。`user_id` 默认为 `default`,`agent_id` 默认为 `dsh`,`app_id` 默认使用当前 DSH 工作区名称。填写自定义的 `app_id` 后点击 **Save memory scope** 生效。清空输入框再保存会恢复默认。
|
|
75
|
+
|
|
76
|
+
自动召回和助手主动搜记忆使用 **Recall filters** 中已勾选的标识。**User ID** 默认勾选,可以取消。**Agent ID** 和 **App ID** 默认关闭。三项都取消时会跳过记忆搜索。
|
|
77
|
+
|
|
78
|
+
`project_id` 默认取当前 DSH 工作区 ID,随采集请求的 `background` 消息发送。如需让新采集的记忆也在元数据里记录它,在当前 DSH profile 的 `aliyun-contextdb/ctxdb.json` 中设置 `dsh_context.capture_project_metadata` 为 `true`,然后重启 DSH。也可以在 DSH 的 `cordis.patch.yml` 中为 `aliyun-contextdb` 的 `config` 设置 `captureProjectMetadata: true`。插件自己的 `ctxdb.json` 优先。
|
package/cordis.patch.yml
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({ id: "@aliyunrds/ctxdb-dsh", factory: (require) => {
|
|
2
|
+
var module = { exports: {} }; var exports = module.exports;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// ../../plugins/dsh-plugins/src/client.js
|
|
22
|
+
var client_exports = {};
|
|
23
|
+
__export(client_exports, {
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
inject: () => inject
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(client_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
|
|
30
|
+
// ../../plugins/dsh-plugins/src/settings-contract.ts
|
|
31
|
+
var packageName = "@aliyunrds/ctxdb-dsh";
|
|
32
|
+
var settingsNamespace = "aliyunContextdbSettings";
|
|
33
|
+
var settingsEndpoint = `${settingsNamespace}/auth`;
|
|
34
|
+
var memoryScopeFields = ["project_id", "user_id", "agent_id", "app_id"];
|
|
35
|
+
var memoryRecallFields = ["project_id", "user_id", "agent_id", "app_id"];
|
|
36
|
+
function parseMemoryScope(input) {
|
|
37
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return;
|
|
38
|
+
const values = input;
|
|
39
|
+
const scope = {};
|
|
40
|
+
for (const field of memoryScopeFields) {
|
|
41
|
+
if (!Object.hasOwn(values, field)) continue;
|
|
42
|
+
const value = values[field];
|
|
43
|
+
if (field === "app_id" && value === null) {
|
|
44
|
+
scope.app_id = null;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (typeof value !== "string" || value.length > 256 || /[\x00-\x1f\x7f]/.test(value) || value.trim() === "*") return;
|
|
48
|
+
scope[field] = value.trim();
|
|
49
|
+
}
|
|
50
|
+
return scope;
|
|
51
|
+
}
|
|
52
|
+
function parseMemoryRecallFilters(input) {
|
|
53
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return;
|
|
54
|
+
const values = input;
|
|
55
|
+
const filters = {};
|
|
56
|
+
for (const field of memoryRecallFields) {
|
|
57
|
+
if (!Object.hasOwn(values, field)) continue;
|
|
58
|
+
const value = values[field];
|
|
59
|
+
if (typeof value !== "boolean") return;
|
|
60
|
+
filters[field] = value;
|
|
61
|
+
}
|
|
62
|
+
return filters;
|
|
63
|
+
}
|
|
64
|
+
function parseRequest(input) {
|
|
65
|
+
if (input && typeof input === "object" && !Array.isArray(input)) {
|
|
66
|
+
const { action, site, apiKey, pendingId, setting, enabled, scope: rawScope, recallFilters: rawFilters } = input;
|
|
67
|
+
if (action === "status" || action === "disconnect" || action === "use-login") return { action };
|
|
68
|
+
if (action === "cancel" && typeof pendingId === "string" && pendingId.length === 36) return { action, pendingId };
|
|
69
|
+
if (action === "set-context" && (setting === "autoRecall" || setting === "autoCapture") && typeof enabled === "boolean") {
|
|
70
|
+
return { action, setting, enabled };
|
|
71
|
+
}
|
|
72
|
+
if (action === "set-memory-scope") {
|
|
73
|
+
const scope = parseMemoryScope(rawScope);
|
|
74
|
+
const recallFilters = parseMemoryRecallFilters(rawFilters);
|
|
75
|
+
if (scope && (rawFilters === void 0 || recallFilters)) return { action, scope, recallFilters };
|
|
76
|
+
}
|
|
77
|
+
if (site === "cn" || site === "intl") {
|
|
78
|
+
if (action === "start") return { action, site };
|
|
79
|
+
if (action === "save-key" && typeof apiKey === "string" && apiKey.length <= 4096) return { action, site, apiKey };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
throw new Error("Invalid ContextDB request.");
|
|
83
|
+
}
|
|
84
|
+
var settingsInvocation = {
|
|
85
|
+
id: `${packageName}#${settingsEndpoint}`,
|
|
86
|
+
service: settingsNamespace,
|
|
87
|
+
namespace: settingsNamespace,
|
|
88
|
+
method: "auth",
|
|
89
|
+
invocation: { kind: "direct" },
|
|
90
|
+
parameters: [{
|
|
91
|
+
name: "request",
|
|
92
|
+
wire: "request",
|
|
93
|
+
source: "json",
|
|
94
|
+
codec: { mode: "strict", typeSymbol: `${packageName}#SettingsRequest`, create: () => ({ parse: parseRequest }) }
|
|
95
|
+
}],
|
|
96
|
+
cancellation: { parameter: "signal" },
|
|
97
|
+
result: { mode: "src-json" }
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// ../../plugins/dsh-plugins/src/client.js
|
|
101
|
+
var inject = ["slots", "remote", "remoteAccess"];
|
|
102
|
+
var styles = {
|
|
103
|
+
section: { maxWidth: 560, display: "grid", gap: 18, color: "var(--dsw-alias-label-primary)" },
|
|
104
|
+
body: { display: "grid", gap: 16, padding: "16px 0", borderTop: "1px solid var(--dsw-alias-border-l2)" },
|
|
105
|
+
heading: { margin: 0, fontSize: 16, fontWeight: 600 },
|
|
106
|
+
field: { display: "grid", gap: 6, fontSize: 14 },
|
|
107
|
+
control: {
|
|
108
|
+
width: "100%",
|
|
109
|
+
boxSizing: "border-box",
|
|
110
|
+
font: "inherit",
|
|
111
|
+
color: "inherit",
|
|
112
|
+
minHeight: 36,
|
|
113
|
+
padding: "6px 10px",
|
|
114
|
+
borderRadius: "var(--dsw-radius-md, 8px)",
|
|
115
|
+
border: "1px solid var(--dsw-alias-border-l3)",
|
|
116
|
+
background: "var(--dsw-alias-fill-l1, transparent)"
|
|
117
|
+
},
|
|
118
|
+
actions: { display: "flex", alignItems: "center", flexWrap: "wrap", gap: 8 },
|
|
119
|
+
button: {
|
|
120
|
+
minHeight: 34,
|
|
121
|
+
padding: "6px 12px",
|
|
122
|
+
font: "inherit",
|
|
123
|
+
borderRadius: "var(--dsw-radius-md, 8px)",
|
|
124
|
+
border: "1px solid var(--dsw-alias-border-l3)",
|
|
125
|
+
color: "inherit",
|
|
126
|
+
background: "transparent"
|
|
127
|
+
},
|
|
128
|
+
primary: { color: "white", background: "var(--dsw-alias-state-business-primary, #425ee8)", borderColor: "transparent" },
|
|
129
|
+
text: { margin: 0, fontSize: 14, color: "var(--dsw-alias-label-secondary)" }
|
|
130
|
+
};
|
|
131
|
+
var siteName = { cn: "China", intl: "International" };
|
|
132
|
+
var memoryScopeDefaults = { user_id: "default", agent_id: "dsh", app_id: "Current DSH workspace name" };
|
|
133
|
+
var phaseText = {
|
|
134
|
+
cancelled: "Authorization cancelled.",
|
|
135
|
+
expired: "The device code expired. Start authorization again.",
|
|
136
|
+
failed: "Authorization failed. Start authorization again.",
|
|
137
|
+
"cleanup-unconfirmed": "ContextDB could not confirm revocation of the previous login."
|
|
138
|
+
};
|
|
139
|
+
function button(text, onClick, busy, primary = false) {
|
|
140
|
+
return (0, import_react.createElement)("button", {
|
|
141
|
+
type: "button",
|
|
142
|
+
disabled: busy,
|
|
143
|
+
onClick,
|
|
144
|
+
style: { ...styles.button, ...primary ? styles.primary : {}, cursor: busy ? "default" : "pointer", opacity: busy ? 0.55 : 1 }
|
|
145
|
+
}, text);
|
|
146
|
+
}
|
|
147
|
+
function contextSwitch({ id, title, description, enabled, busy, onClick }) {
|
|
148
|
+
return (0, import_react.createElement)(
|
|
149
|
+
"div",
|
|
150
|
+
{ style: { display: "flex", gap: 16, alignItems: "center", justifyContent: "space-between" } },
|
|
151
|
+
(0, import_react.createElement)(
|
|
152
|
+
"div",
|
|
153
|
+
{ style: styles.field },
|
|
154
|
+
(0, import_react.createElement)("span", { id }, title),
|
|
155
|
+
(0, import_react.createElement)("p", { id: `${id}-description`, style: styles.text }, description)
|
|
156
|
+
),
|
|
157
|
+
(0, import_react.createElement)("button", {
|
|
158
|
+
type: "button",
|
|
159
|
+
role: "switch",
|
|
160
|
+
"aria-checked": enabled,
|
|
161
|
+
"aria-labelledby": id,
|
|
162
|
+
"aria-describedby": `${id}-description`,
|
|
163
|
+
disabled: busy,
|
|
164
|
+
onClick,
|
|
165
|
+
style: {
|
|
166
|
+
width: 38,
|
|
167
|
+
height: 22,
|
|
168
|
+
display: "flex",
|
|
169
|
+
flex: "0 0 auto",
|
|
170
|
+
alignItems: "center",
|
|
171
|
+
justifyContent: enabled ? "flex-end" : "flex-start",
|
|
172
|
+
padding: 3,
|
|
173
|
+
border: 0,
|
|
174
|
+
borderRadius: 11,
|
|
175
|
+
background: enabled ? "var(--dsw-alias-state-business-primary, #425ee8)" : "var(--dsw-alias-border-l4, #727784)",
|
|
176
|
+
cursor: busy ? "default" : "pointer",
|
|
177
|
+
opacity: busy ? 0.55 : 1
|
|
178
|
+
}
|
|
179
|
+
}, (0, import_react.createElement)("span", { "aria-hidden": true, style: { width: 16, height: 16, borderRadius: "50%", background: "white" } }))
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
function prepareAuthorizationPage() {
|
|
183
|
+
const desktop = "dshDesktop" in window;
|
|
184
|
+
let pendingTab;
|
|
185
|
+
function close() {
|
|
186
|
+
const tab = pendingTab;
|
|
187
|
+
pendingTab = void 0;
|
|
188
|
+
try {
|
|
189
|
+
tab?.close();
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!desktop) {
|
|
194
|
+
try {
|
|
195
|
+
pendingTab = window.open("about:blank", "_blank");
|
|
196
|
+
if (pendingTab) pendingTab.opener = null;
|
|
197
|
+
} catch {
|
|
198
|
+
close();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
open(url) {
|
|
203
|
+
try {
|
|
204
|
+
if (desktop) {
|
|
205
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
206
|
+
} else if (pendingTab && !pendingTab.closed) {
|
|
207
|
+
pendingTab.location.replace(url);
|
|
208
|
+
pendingTab = void 0;
|
|
209
|
+
}
|
|
210
|
+
} catch {
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
close
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function MemoryScopeForm({ context, busy, save }) {
|
|
217
|
+
const filter = (field, label, props) => (0, import_react.createElement)(
|
|
218
|
+
"label",
|
|
219
|
+
{ key: field, style: { display: "flex", alignItems: "center", gap: 6, fontSize: 14 } },
|
|
220
|
+
(0, import_react.createElement)("input", {
|
|
221
|
+
type: "checkbox",
|
|
222
|
+
name: `recall.${field}`,
|
|
223
|
+
disabled: busy,
|
|
224
|
+
style: { margin: 0, accentColor: "var(--dsw-alias-state-business-primary, #425ee8)" },
|
|
225
|
+
...props
|
|
226
|
+
}),
|
|
227
|
+
label
|
|
228
|
+
);
|
|
229
|
+
return (0, import_react.createElement)(
|
|
230
|
+
"form",
|
|
231
|
+
{
|
|
232
|
+
style: { display: "grid", gap: 12, marginTop: 6 },
|
|
233
|
+
onSubmit: (event) => {
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
if (busy) return;
|
|
236
|
+
const fields = new FormData(event.currentTarget);
|
|
237
|
+
save({
|
|
238
|
+
action: "set-memory-scope",
|
|
239
|
+
scope: Object.fromEntries(Object.keys(memoryScopeDefaults).map((field) => [field, fields.get(field)])),
|
|
240
|
+
recallFilters: {
|
|
241
|
+
user_id: fields.has("recall.user_id"),
|
|
242
|
+
agent_id: fields.has("recall.agent_id"),
|
|
243
|
+
app_id: fields.has("recall.app_id")
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
(0, import_react.createElement)("h4", { style: styles.heading }, "Memory scope"),
|
|
249
|
+
...Object.entries(memoryScopeDefaults).map(([field, placeholder]) => (0, import_react.createElement)(
|
|
250
|
+
"label",
|
|
251
|
+
{ key: field, style: styles.field },
|
|
252
|
+
field,
|
|
253
|
+
(0, import_react.createElement)("input", {
|
|
254
|
+
name: field,
|
|
255
|
+
defaultValue: context.memoryScope[field] ?? "",
|
|
256
|
+
placeholder: context.memoryScope[field] === null ? "No App ID" : placeholder,
|
|
257
|
+
maxLength: 256,
|
|
258
|
+
disabled: busy,
|
|
259
|
+
style: styles.control
|
|
260
|
+
})
|
|
261
|
+
)),
|
|
262
|
+
(0, import_react.createElement)(
|
|
263
|
+
"fieldset",
|
|
264
|
+
{ style: { margin: 0, padding: 0, border: 0, minWidth: 0 } },
|
|
265
|
+
(0, import_react.createElement)("legend", { style: { padding: 0, marginBottom: 6, fontSize: 14 } }, "Recall filters"),
|
|
266
|
+
(0, import_react.createElement)(
|
|
267
|
+
"div",
|
|
268
|
+
{ style: { ...styles.actions, gap: "8px 16px", marginTop: 8 } },
|
|
269
|
+
filter("user_id", "User ID", { defaultChecked: context.memoryRecallFilters.user_id }),
|
|
270
|
+
filter("agent_id", "Agent ID", { defaultChecked: context.memoryRecallFilters.agent_id }),
|
|
271
|
+
filter("app_id", "App ID", { defaultChecked: context.memoryRecallFilters.app_id })
|
|
272
|
+
)
|
|
273
|
+
),
|
|
274
|
+
(0, import_react.createElement)("div", { style: styles.actions }, (0, import_react.createElement)("button", {
|
|
275
|
+
type: "submit",
|
|
276
|
+
disabled: busy,
|
|
277
|
+
style: { ...styles.button, opacity: busy ? 0.55 : 1 }
|
|
278
|
+
}, "Save memory scope"))
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
function SettingsPage({ request }) {
|
|
282
|
+
const [status, setStatus] = (0, import_react.useState)(void 0);
|
|
283
|
+
const [draft, setDraft] = (0, import_react.useState)(void 0);
|
|
284
|
+
const [prompt, setPrompt] = (0, import_react.useState)(void 0);
|
|
285
|
+
const [busy, setBusy] = (0, import_react.useState)(false);
|
|
286
|
+
const [error, setError] = (0, import_react.useState)("");
|
|
287
|
+
const fieldId = (0, import_react.useId)();
|
|
288
|
+
const lifetime = (0, import_react.useRef)(void 0);
|
|
289
|
+
const password = (0, import_react.useRef)(null);
|
|
290
|
+
(0, import_react.useEffect)(() => {
|
|
291
|
+
const controller = new AbortController();
|
|
292
|
+
lifetime.current = controller;
|
|
293
|
+
return () => controller.abort();
|
|
294
|
+
}, []);
|
|
295
|
+
(0, import_react.useEffect)(() => {
|
|
296
|
+
if (busy) return;
|
|
297
|
+
const controller = new AbortController();
|
|
298
|
+
let timer;
|
|
299
|
+
async function refresh() {
|
|
300
|
+
try {
|
|
301
|
+
const result = await request({ action: "status" }, controller.signal);
|
|
302
|
+
if (controller.signal.aborted) return;
|
|
303
|
+
setStatus(result.status);
|
|
304
|
+
if (result.status.login.pendingId) timer = setTimeout(refresh, 1e3);
|
|
305
|
+
else setPrompt(void 0);
|
|
306
|
+
} catch (failure) {
|
|
307
|
+
if (!controller.signal.aborted) setError(failure.message);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (!status || status.login.pendingId) void refresh();
|
|
311
|
+
return () => {
|
|
312
|
+
controller.abort();
|
|
313
|
+
clearTimeout(timer);
|
|
314
|
+
};
|
|
315
|
+
}, [busy, request, status?.login.pendingId]);
|
|
316
|
+
async function change(input) {
|
|
317
|
+
const signal = lifetime.current.signal;
|
|
318
|
+
const authorizationPage = input.action === "start" ? prepareAuthorizationPage() : void 0;
|
|
319
|
+
if (authorizationPage) signal.addEventListener("abort", authorizationPage.close, { once: true });
|
|
320
|
+
setBusy(true);
|
|
321
|
+
setError("");
|
|
322
|
+
try {
|
|
323
|
+
const result = await request(input, signal);
|
|
324
|
+
if (signal.aborted) return;
|
|
325
|
+
setStatus(result.status);
|
|
326
|
+
if (result.prompt || !result.status.login.pendingId) setPrompt(result.prompt);
|
|
327
|
+
if (result.prompt && result.prompt.id === result.status.login.pendingId) authorizationPage?.open(result.prompt.url);
|
|
328
|
+
if (["save-key", "use-login"].includes(input.action)) setDraft(void 0);
|
|
329
|
+
} catch (failure) {
|
|
330
|
+
if (!signal.aborted) setError(failure.message);
|
|
331
|
+
} finally {
|
|
332
|
+
if (authorizationPage) {
|
|
333
|
+
signal.removeEventListener("abort", authorizationPage.close);
|
|
334
|
+
authorizationPage.close();
|
|
335
|
+
}
|
|
336
|
+
if (!signal.aborted) setBusy(false);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function saveKey(apiKey) {
|
|
340
|
+
password.current.value = "";
|
|
341
|
+
void change({ action: "save-key", site, apiKey });
|
|
342
|
+
}
|
|
343
|
+
const pendingId = status?.login.pendingId;
|
|
344
|
+
const mode = draft?.mode ?? (pendingId ? "oauth" : status?.mode);
|
|
345
|
+
const site = draft?.site ?? status?.login.pendingSite ?? status?.site;
|
|
346
|
+
const userPrompt = prompt?.id === pendingId ? prompt : void 0;
|
|
347
|
+
const connected = status?.login.connection?.ready ? status.login.connection : void 0;
|
|
348
|
+
const canReauthorize = Boolean(connected && site === status.login.site);
|
|
349
|
+
const hasSavedKey = status?.keySites[site];
|
|
350
|
+
const keySelected = status?.mode === "api-key" && status.site === site && status.keyConfigured;
|
|
351
|
+
const activeMethod = status?.mode === "oauth" ? "Device Code" : "API Key";
|
|
352
|
+
return (0, import_react.createElement)(
|
|
353
|
+
"section",
|
|
354
|
+
{ style: styles.section, "aria-label": "ContextDB authentication" },
|
|
355
|
+
(0, import_react.createElement)("h2", { style: { margin: 0, fontSize: 20, fontWeight: 600 } }, "ContextDB"),
|
|
356
|
+
error && (0, import_react.createElement)("p", { role: "alert", style: { ...styles.text, color: "var(--dsw-alias-state-danger, #c14040)" } }, error),
|
|
357
|
+
!status ? (0, import_react.createElement)("p", { role: "status", style: styles.text }, error ? "Reopen settings to retry." : "Loading ContextDB settings\u2026") : (0, import_react.createElement)(
|
|
358
|
+
import_react.Fragment,
|
|
359
|
+
{},
|
|
360
|
+
(0, import_react.createElement)(
|
|
361
|
+
"section",
|
|
362
|
+
{ style: styles.body, "aria-labelledby": `${fieldId}-authentication` },
|
|
363
|
+
(0, import_react.createElement)("h3", { id: `${fieldId}-authentication`, style: styles.heading }, "Authentication"),
|
|
364
|
+
(0, import_react.createElement)("p", { role: "status", style: styles.text }, `Active method: ${activeMethod} \xB7 ${siteName[status.site]}`),
|
|
365
|
+
(0, import_react.createElement)(
|
|
366
|
+
"div",
|
|
367
|
+
{ style: styles.field },
|
|
368
|
+
(0, import_react.createElement)("label", { htmlFor: `${fieldId}-method` }, "Authentication method"),
|
|
369
|
+
(0, import_react.createElement)("select", { id: `${fieldId}-method`, value: mode, style: styles.control, disabled: busy, onChange: (event) => {
|
|
370
|
+
setDraft({ mode: event.target.value, site });
|
|
371
|
+
setError("");
|
|
372
|
+
} }, (0, import_react.createElement)("option", { value: "oauth" }, "Device Code"), (0, import_react.createElement)("option", { value: "api-key" }, "API Key"))
|
|
373
|
+
),
|
|
374
|
+
(0, import_react.createElement)(
|
|
375
|
+
"div",
|
|
376
|
+
{ style: styles.field },
|
|
377
|
+
(0, import_react.createElement)("label", { htmlFor: `${fieldId}-site` }, "Site"),
|
|
378
|
+
(0, import_react.createElement)("select", { id: `${fieldId}-site`, value: site, style: styles.control, disabled: busy || mode === "oauth" && Boolean(pendingId), onChange: (event) => {
|
|
379
|
+
if (password.current) password.current.value = "";
|
|
380
|
+
setDraft({ mode, site: event.target.value });
|
|
381
|
+
setError("");
|
|
382
|
+
} }, (0, import_react.createElement)("option", { value: "cn" }, siteName.cn), (0, import_react.createElement)("option", { value: "intl" }, siteName.intl))
|
|
383
|
+
),
|
|
384
|
+
mode === "api-key" ? (0, import_react.createElement)(
|
|
385
|
+
"form",
|
|
386
|
+
{ style: { display: "grid", gap: 12 }, onSubmit: (event) => {
|
|
387
|
+
event.preventDefault();
|
|
388
|
+
if (!busy && password.current.value) saveKey(password.current.value);
|
|
389
|
+
} },
|
|
390
|
+
(0, import_react.createElement)(
|
|
391
|
+
"label",
|
|
392
|
+
{ style: styles.field },
|
|
393
|
+
"ContextDB API Key",
|
|
394
|
+
(0, import_react.createElement)("input", {
|
|
395
|
+
key: site,
|
|
396
|
+
ref: password,
|
|
397
|
+
type: "password",
|
|
398
|
+
autoComplete: "new-password",
|
|
399
|
+
spellCheck: false,
|
|
400
|
+
maxLength: 4096,
|
|
401
|
+
placeholder: hasSavedKey ? "Enter a replacement key" : "Paste a workspace API Key",
|
|
402
|
+
required: true,
|
|
403
|
+
disabled: busy,
|
|
404
|
+
style: styles.control
|
|
405
|
+
})
|
|
406
|
+
),
|
|
407
|
+
(0, import_react.createElement)("p", { role: "status", style: styles.text }, keySelected ? "API Key saved and selected." : hasSavedKey ? "A key is saved for this site." : "No saved API Key for this site."),
|
|
408
|
+
(0, import_react.createElement)(
|
|
409
|
+
"div",
|
|
410
|
+
{ style: styles.actions },
|
|
411
|
+
hasSavedKey && !keySelected && button("Use saved API Key", () => saveKey(""), busy, true),
|
|
412
|
+
(0, import_react.createElement)("button", {
|
|
413
|
+
type: "submit",
|
|
414
|
+
disabled: busy,
|
|
415
|
+
style: { ...styles.button, ...hasSavedKey ? {} : styles.primary, opacity: busy ? 0.55 : 1 }
|
|
416
|
+
}, hasSavedKey ? "Replace API Key" : "Save API Key")
|
|
417
|
+
)
|
|
418
|
+
) : (0, import_react.createElement)(
|
|
419
|
+
"div",
|
|
420
|
+
{ style: { display: "grid", gap: 12 } },
|
|
421
|
+
(0, import_react.createElement)("p", { role: "status", style: styles.text }, pendingId ? "Waiting for browser authorization\u2026" : connected ? `${status.mode === "oauth" ? "Connected to" : "Saved login for"} Workspace ${connected.workspaceId} \xB7 Member ${connected.memberId} \xB7 ${siteName[status.login.site]}` : "Browser login is disconnected."),
|
|
422
|
+
!pendingId && phaseText[status.login.phase] && (0, import_react.createElement)("p", { role: "status", style: styles.text }, phaseText[status.login.phase]),
|
|
423
|
+
userPrompt && (0, import_react.createElement)("p", { style: styles.text }, "Device code ", (0, import_react.createElement)("code", {}, userPrompt.userCode)),
|
|
424
|
+
(0, import_react.createElement)("div", { style: styles.actions }, pendingId ? [
|
|
425
|
+
userPrompt && (0, import_react.createElement)("a", { key: "authorize", href: userPrompt.url, target: "_blank", rel: "noopener noreferrer" }, "Open authorization page"),
|
|
426
|
+
(0, import_react.createElement)("span", { key: "cancel" }, button("Cancel authorization", () => void change({ action: "cancel", pendingId }), busy))
|
|
427
|
+
] : [
|
|
428
|
+
connected && status.mode !== "oauth" && (0, import_react.createElement)("span", { key: "use" }, button("Use saved login", () => void change({ action: "use-login" }), busy, canReauthorize)),
|
|
429
|
+
(0, import_react.createElement)("span", { key: "start" }, button(canReauthorize ? "Reauthorize" : "Start authorization", () => void change({ action: "start", site }), busy, !canReauthorize)),
|
|
430
|
+
connected && status.mode === "oauth" && (0, import_react.createElement)("span", { key: "disconnect" }, button("Disconnect", () => void change({ action: "disconnect" }), busy))
|
|
431
|
+
])
|
|
432
|
+
)
|
|
433
|
+
),
|
|
434
|
+
(0, import_react.createElement)(
|
|
435
|
+
"section",
|
|
436
|
+
{ style: styles.body, "aria-labelledby": `${fieldId}-context` },
|
|
437
|
+
(0, import_react.createElement)("h3", { id: `${fieldId}-context`, style: styles.heading }, "Context settings"),
|
|
438
|
+
contextSwitch({
|
|
439
|
+
id: `${fieldId}-recall`,
|
|
440
|
+
title: "Automatic recall",
|
|
441
|
+
description: "Find relevant ContextDB memories for new messages.",
|
|
442
|
+
enabled: status.context.autoRecall,
|
|
443
|
+
busy,
|
|
444
|
+
onClick: () => void change({ action: "set-context", setting: "autoRecall", enabled: !status.context.autoRecall })
|
|
445
|
+
}),
|
|
446
|
+
contextSwitch({
|
|
447
|
+
id: `${fieldId}-capture`,
|
|
448
|
+
title: "Automatic capture",
|
|
449
|
+
description: "Send eligible completed conversation turns to ContextDB to create memories.",
|
|
450
|
+
enabled: status.context.autoCapture,
|
|
451
|
+
busy,
|
|
452
|
+
onClick: () => void change({ action: "set-context", setting: "autoCapture", enabled: !status.context.autoCapture })
|
|
453
|
+
}),
|
|
454
|
+
(0, import_react.createElement)(MemoryScopeForm, {
|
|
455
|
+
key: JSON.stringify([status.context.memoryScope, status.context.memoryRecallFilters]),
|
|
456
|
+
context: status.context,
|
|
457
|
+
busy,
|
|
458
|
+
save: (input) => void change(input)
|
|
459
|
+
})
|
|
460
|
+
)
|
|
461
|
+
)
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
async function apply(ctx) {
|
|
465
|
+
await ctx.remote.$mount({ package: packageName, descriptors: [settingsInvocation] });
|
|
466
|
+
ctx.inject([`remote.${settingsNamespace}`], (scope) => {
|
|
467
|
+
const request = async (input, signal) => {
|
|
468
|
+
const result = await scope.remote[settingsNamespace].auth(input, signal).catch(() => void 0);
|
|
469
|
+
if (!result?.ok) throw new Error("Could not reach the ContextDB plugin on this DSH Host.");
|
|
470
|
+
if (result.value.error) throw new Error(result.value.error);
|
|
471
|
+
return result.value;
|
|
472
|
+
};
|
|
473
|
+
scope.remoteAccess.whenAccess(settingsEndpoint, () => scope.slots.inject("settings.section", () => scope.slots.register({
|
|
474
|
+
name: "settings.section",
|
|
475
|
+
id: "aliyun-contextdb",
|
|
476
|
+
label: () => "ContextDB",
|
|
477
|
+
order: 60
|
|
478
|
+
}, () => (0, import_react.createElement)(SettingsPage, { request }))));
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
return module.exports;
|
|
482
|
+
} });
|