@goodpeanuts/dsh-sui 0.1.1 → 0.1.2-fix.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/README.md +2 -0
- package/apps/cli/dist/packages/finance-module/src/database.mjs +1 -1
- package/bundles/sui-ledger/dist/capabilities/book-authorization.mjs +96 -0
- package/bundles/sui-ledger/dist/capabilities/tools.mjs +12 -2
- package/bundles/sui-ledger/dist/client.js +501 -82
- package/bundles/sui-ledger/dist/finance-state-context.mjs +1 -1
- package/bundles/sui-ledger/dist/index.mjs +15 -2
- package/bundles/sui-ledger/dist/node_modules/.pnpm/{@deepseek-ai_dsh-home-paths_159c15e70066431314381a350c2ee56a → @deepseek-ai_dsh-home-paths_43f382ed782d46f05123e7add538564e}/node_modules/@deepseek-ai/dsh-home-paths/lib/index.mjs +1 -1
- package/bundles/sui-ledger/dist/packages/finance-module/src/capabilities.mjs +1 -1
- package/bundles/sui-ledger/dist/packages/finance-module/src/database.mjs +1 -1
- package/bundles/sui-ledger/dist/packages/finance-module/src/interactions.mjs +9 -4
- package/bundles/sui-ledger/dist/packages/finance-module/src/routes.mjs +56 -2
- package/bundles/sui-ledger/dist/packages/finance-module/src/service.mjs +15 -3
- package/bundles/sui-ledger/dist/packages/finance-module/src/tool-contracts.mjs +2 -2
- package/bundles/sui-ledger/dist/storage/business-runtime.mjs +1 -0
- package/bundles/sui-ledger/dist/storage/paths.mjs +1 -1
- package/bundles/sui-ledger/dist/style.css +222 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,6 +45,8 @@ npx --yes --package=@goodpeanuts/dsh-sui feidee sync recent --book '上一步返
|
|
|
45
45
|
|
|
46
46
|
### 会话草稿与待入账
|
|
47
47
|
|
|
48
|
+
在账本页面的“数据与同步 → 账本授权”选择默认账本,勾选后续会话自动使用并确认。普通会话没有常驻授权按钮,也不会因打开会话而获得授权。未设置默认账本时,首次需要账本访问的财务工具会通过宿主原生提问请求用户选择账本,可选择以后自动使用或仅本次会话;跳过、取消或自定义文本不会授予访问。后续使用默认账本无需重复确认。可在授权设置中停止为新会话自动授权;已有会话授权与草稿不受影响。草稿工作台内提供“切换账本”,切换前须先处理当前非空草稿。没有可选账本时,先登录并同步。实际入账仍需单独人工确认。
|
|
49
|
+
|
|
48
50
|
模型通过受限 finance 工具读取账本、维护当前会话的一份流水草稿。用户和 Agent 共同编辑同一份字段;缺项由必填字段和校验结果派生,未知信息通过宿主提问,不写入草稿问题状态。
|
|
49
51
|
|
|
50
52
|
非空草稿在输入框上方显示单个图标,点击打开工作台,关闭后保留编辑。完整条目可加入“待入账”,原批次冻结为只读存档;部分加入时剩余条目继续使用原入口,整批加入后入口收起,后续记账另开批次。其他会话的 open 草稿不共享,已加入同一账本的待入账记录可读。
|
|
@@ -61,7 +61,7 @@ var FinanceDatabase = class {
|
|
|
61
61
|
assertTimestamp(input.now, "now");
|
|
62
62
|
return this.db.transaction(() => {
|
|
63
63
|
const current = this.getActiveGrant(input.subjectId);
|
|
64
|
-
if (input.expectedRevision !== void 0 && current?.revision !== input.expectedRevision) throw new Error("finance_grant_revision_conflict");
|
|
64
|
+
if (input.expectedRevision !== void 0 && (current?.revision ?? 0) !== input.expectedRevision) throw new Error("finance_grant_revision_conflict");
|
|
65
65
|
if (current?.bookId === input.bookId) return current;
|
|
66
66
|
const revision = (current?.revision ?? 0) + 1;
|
|
67
67
|
if (current) this.db.prepare("UPDATE book_read_grants SET replaced_at=? WHERE id=? AND replaced_at IS NULL").run(input.now, current.id);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { FinancePublicError } from "../packages/finance/src/public-error.mjs";
|
|
2
|
+
import { createFinanceTrustedControlRoute } from "../packages/finance-module/src/routes.mjs";
|
|
3
|
+
import "../packages/finance-module/src/index.mjs";
|
|
4
|
+
import "../packages/finance-module/src/tool-contracts.mjs";
|
|
5
|
+
//#region src/capabilities/book-authorization.ts
|
|
6
|
+
/** Human-owned host questions are the only source of a contextual authorization. */
|
|
7
|
+
function createBookAuthorization(options) {
|
|
8
|
+
const pending = /* @__PURE__ */ new Map();
|
|
9
|
+
const lifetime = new AbortController();
|
|
10
|
+
const authorize = (context, exec) => {
|
|
11
|
+
const existing = pending.get(context.subjectId);
|
|
12
|
+
if (existing) return existing;
|
|
13
|
+
const operation = requestAuthorization(context, exec).finally(() => {
|
|
14
|
+
if (pending.get(context.subjectId) === operation) pending.delete(context.subjectId);
|
|
15
|
+
});
|
|
16
|
+
pending.set(context.subjectId, operation);
|
|
17
|
+
return operation;
|
|
18
|
+
};
|
|
19
|
+
const requestAuthorization = async (context, exec) => {
|
|
20
|
+
const ask = options.questions();
|
|
21
|
+
if (!ask) throw failure("finance_grant_missing", "请打开账本页面的“数据与同步 → 账本授权”设置默认账本,再继续当前任务。");
|
|
22
|
+
const signal = exec.signal ? AbortSignal.any([exec.signal, lifetime.signal]) : lifetime.signal;
|
|
23
|
+
signal.throwIfAborted();
|
|
24
|
+
const { service, interaction } = options.runtime();
|
|
25
|
+
const books = service.describeBooks(context).books;
|
|
26
|
+
if (!Array.isArray(books) || !books.length) throw failure("finance_grant_missing", "尚无可用账本,请先在账本页面登录并同步,再设置账本授权。");
|
|
27
|
+
const route = createFinanceTrustedControlRoute(service, interaction);
|
|
28
|
+
const base = `/v1/finance/subjects/${context.subjectId}/grant/selection`;
|
|
29
|
+
const selection = (await route.handle({
|
|
30
|
+
method: "POST",
|
|
31
|
+
pathname: base,
|
|
32
|
+
query: {},
|
|
33
|
+
body: async () => ({})
|
|
34
|
+
})).body;
|
|
35
|
+
const respond = async (body) => route.handle({
|
|
36
|
+
method: "POST",
|
|
37
|
+
pathname: `${base}/${selection.request.id}`,
|
|
38
|
+
query: {},
|
|
39
|
+
body: async () => body
|
|
40
|
+
});
|
|
41
|
+
const labels = selection.books.map((book, index) => {
|
|
42
|
+
const name = book.name?.trim() || "未命名账本";
|
|
43
|
+
return selection.books.filter((other) => (other.name?.trim() || "未命名账本") === name).length > 1 ? `${name}(${index + 1})` : name;
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
const answer = await ask({
|
|
47
|
+
...exec.agent ? { agent: exec.agent } : {},
|
|
48
|
+
signal,
|
|
49
|
+
questions: [{
|
|
50
|
+
id: "book",
|
|
51
|
+
header: "账本授权",
|
|
52
|
+
question: "本次任务使用哪个账本?授权后可读取账本并维护草稿,实际入账仍需人工确认。",
|
|
53
|
+
options: labels.map((label) => ({ label }))
|
|
54
|
+
}, {
|
|
55
|
+
id: "remember",
|
|
56
|
+
header: "后续使用",
|
|
57
|
+
question: "后续会话使用财务功能时,是否自动使用所选账本?",
|
|
58
|
+
options: [{
|
|
59
|
+
label: "以后自动使用",
|
|
60
|
+
description: "设置为默认账本,之后使用财务功能时无需重复授权。"
|
|
61
|
+
}, {
|
|
62
|
+
label: "仅本次会话",
|
|
63
|
+
description: "只授权当前会话,保留原有默认设置。"
|
|
64
|
+
}]
|
|
65
|
+
}]
|
|
66
|
+
});
|
|
67
|
+
signal.throwIfAborted();
|
|
68
|
+
const chosen = answer.answers.find((item) => item.id === "book");
|
|
69
|
+
const remember = answer.answers.find((item) => item.id === "remember");
|
|
70
|
+
const index = chosen?.selected.length === 1 ? labels.indexOf(chosen.selected[0]) : -1;
|
|
71
|
+
if (index < 0 || chosen?.custom || remember?.custom || remember?.selected.length !== 1 || !["以后自动使用", "仅本次会话"].includes(remember.selected[0])) throw failure("finance_grant_cancelled", "用户没有完成账本授权,本次操作已停止。不要重复请求授权;等待用户明确要求继续。");
|
|
72
|
+
if ((await respond({
|
|
73
|
+
decision: "confirm",
|
|
74
|
+
bookId: selection.books[index].id,
|
|
75
|
+
makeDefault: remember.selected[0] === "以后自动使用"
|
|
76
|
+
}))?.status !== 200) throw failure("finance_grant_changed", "账本授权已变化,请重新确认当前会话使用的账本。");
|
|
77
|
+
} catch (error) {
|
|
78
|
+
await respond({ decision: "cancel" }).catch(() => void 0);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
authorize,
|
|
84
|
+
dispose() {
|
|
85
|
+
lifetime.abort();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function failure(code, message) {
|
|
90
|
+
return new FinancePublicError(JSON.stringify({
|
|
91
|
+
code,
|
|
92
|
+
message
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { createBookAuthorization };
|
|
@@ -3,7 +3,7 @@ import { financeCallContext } from "../session/call-context.mjs";
|
|
|
3
3
|
/** Wire-format tool names every provider route accepts (OpenAI function-name charset). */
|
|
4
4
|
const TOOL_NAME_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
5
5
|
/** Project only the explicitly exported business tool set. */
|
|
6
|
-
function projectFinanceTools(definitions) {
|
|
6
|
+
function projectFinanceTools(definitions, authorize) {
|
|
7
7
|
const names = /* @__PURE__ */ new Set();
|
|
8
8
|
return definitions.map((definition) => {
|
|
9
9
|
if (!TOOL_NAME_PATTERN.test(definition.name) || names.has(definition.name)) throw new Error("finance_tool_name_invalid");
|
|
@@ -23,7 +23,17 @@ function projectFinanceTools(definitions) {
|
|
|
23
23
|
},
|
|
24
24
|
async execute(args, exec) {
|
|
25
25
|
const context = financeCallContext(definition.name, exec);
|
|
26
|
-
|
|
26
|
+
try {
|
|
27
|
+
return await definition.execute(context, args);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
let code;
|
|
30
|
+
try {
|
|
31
|
+
code = JSON.parse(error instanceof Error ? error.message : "").code;
|
|
32
|
+
} catch {}
|
|
33
|
+
if (!authorize || code !== "finance_grant_missing" && code !== "finance_grant_book_mismatch") throw error;
|
|
34
|
+
await authorize(context, exec);
|
|
35
|
+
return await definition.execute(context, args);
|
|
36
|
+
}
|
|
27
37
|
}
|
|
28
38
|
};
|
|
29
39
|
});
|