@mininglamp-oss/octo-runtime 1.1.2 → 1.1.4
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 +1 -1
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/help.js +5 -1
- package/apps/cli/dist/main.js +32 -6
- package/apps/cli/dist/manifest.json +5 -0
- package/apps/cli/dist/openclaw.js +32 -8
- package/apps/cli/dist/output.js +3 -0
- package/apps/cli/dist/playboard.d.ts +5 -0
- package/apps/cli/dist/playboard.js +41 -13
- package/dist/public/dsh.d.ts +2 -0
- package/dist/public/dsh.js +1 -0
- package/dist/public/executor-kernel.d.ts +1 -1
- package/dist/public/executor-kernel.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +26 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-DYOJCNWF.js +854 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-G5PWGRL5.js +209 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-UOQRXV3Q.js +340 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-client-LICENSE.txt +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-protocol-LICENSE.txt +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +35 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +52 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +306 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +11 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +13 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.d.ts +12 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +10 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +214 -55
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +24 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/hourly-log.js +11 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +12 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +30 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +15 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +29 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +32 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +32 -8
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +41 -13
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -23
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.js +16 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/systemd.js +9 -7
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +36 -11
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +16 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +181 -27
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +9 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +8 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +17 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +57 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +167 -25
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +20 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +23 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +43 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +283 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +15 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -13
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.js +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +26 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +104 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/rules.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +49 -17
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/image-input.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.js +4 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +10 -7
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +141 -16
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/session-store.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-CXTvRGim.js +74 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +33 -9
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +9 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +39 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +76 -7
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +35 -29
- package/packages/octo-runtime-extra-channel-gateway/config-schema.json +57 -1
- package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +443 -56
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +357 -37
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +0 -74
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { lstat, open, realpath } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
6
|
+
import { inferContentType } from "../transport/api/files.js";
|
|
7
|
+
function span(node) {
|
|
8
|
+
const start = node.position?.start.offset, end = node.position?.end.offset;
|
|
9
|
+
return start === undefined || end === undefined ? undefined : { start, end };
|
|
10
|
+
}
|
|
11
|
+
/** AST 决定哪些引用有效,parser token 提供精确地址区间,避免重序列化破坏原 Markdown。 */
|
|
12
|
+
function references(text) {
|
|
13
|
+
const tokens = [];
|
|
14
|
+
const tree = fromMarkdown(text, {
|
|
15
|
+
mdastExtensions: [
|
|
16
|
+
{
|
|
17
|
+
beforeEnter(token) {
|
|
18
|
+
if ([
|
|
19
|
+
"resourceDestinationString",
|
|
20
|
+
"definitionDestinationString",
|
|
21
|
+
"label",
|
|
22
|
+
"definitionTitle"
|
|
23
|
+
].includes(token.type))
|
|
24
|
+
tokens.push({ type: token.type, start: token.start.offset, end: token.end.offset });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
const definitions = new Map();
|
|
30
|
+
const uses = [];
|
|
31
|
+
const inline = [];
|
|
32
|
+
const visit = (node, blocked = false) => {
|
|
33
|
+
blocked ||= ["blockquote", "code", "inlineCode", "html"].includes(node.type);
|
|
34
|
+
if (node.type === "definition" && node.identifier && !definitions.has(node.identifier))
|
|
35
|
+
definitions.set(node.identifier, { node, blocked });
|
|
36
|
+
if (["linkReference", "imageReference"].includes(node.type))
|
|
37
|
+
uses.push({ node, blocked });
|
|
38
|
+
if (!blocked && ["link", "image"].includes(node.type))
|
|
39
|
+
inline.push(node);
|
|
40
|
+
for (const child of node.children ?? [])
|
|
41
|
+
visit(child, blocked);
|
|
42
|
+
};
|
|
43
|
+
visit(tree);
|
|
44
|
+
const within = (node, type) => {
|
|
45
|
+
const range = span(node);
|
|
46
|
+
return (range &&
|
|
47
|
+
tokens
|
|
48
|
+
.filter((token) => token.type === type && token.start >= range.start && token.end <= range.end)
|
|
49
|
+
.at(-1));
|
|
50
|
+
};
|
|
51
|
+
const targets = [];
|
|
52
|
+
const fileTargets = new Set();
|
|
53
|
+
for (const node of inline) {
|
|
54
|
+
const destination = within(node, "resourceDestinationString");
|
|
55
|
+
if (destination && node.url) {
|
|
56
|
+
targets.push({ ...destination, url: node.url });
|
|
57
|
+
if (node.type === "link")
|
|
58
|
+
fileTargets.add(node.url);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const expansions = [];
|
|
62
|
+
const expansionDestinations = new Set();
|
|
63
|
+
const used = new Set();
|
|
64
|
+
for (const use of uses) {
|
|
65
|
+
if (use.blocked || !use.node.identifier)
|
|
66
|
+
continue;
|
|
67
|
+
const definition = definitions.get(use.node.identifier);
|
|
68
|
+
if (!definition?.node.url)
|
|
69
|
+
continue;
|
|
70
|
+
const destination = within(definition.node, "definitionDestinationString");
|
|
71
|
+
if (!destination)
|
|
72
|
+
continue;
|
|
73
|
+
if (use.node.type === "linkReference")
|
|
74
|
+
fileTargets.add(definition.node.url);
|
|
75
|
+
const protectedExample = definition.blocked ||
|
|
76
|
+
uses.some((other) => other.blocked && other.node.identifier === use.node.identifier);
|
|
77
|
+
if (protectedExample) {
|
|
78
|
+
const range = span(use.node), label = tokens.find((token) => token.type === "label" && token.start === range?.start);
|
|
79
|
+
if (range && label) {
|
|
80
|
+
expansions.push({
|
|
81
|
+
range,
|
|
82
|
+
label,
|
|
83
|
+
title: within(definition.node, "definitionTitle"),
|
|
84
|
+
url: definition.node.url
|
|
85
|
+
});
|
|
86
|
+
expansionDestinations.add(`${destination.start}:${destination.end}`);
|
|
87
|
+
targets.push({ ...destination, url: definition.node.url });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (!used.has(use.node.identifier)) {
|
|
91
|
+
targets.push({ ...destination, url: definition.node.url });
|
|
92
|
+
used.add(use.node.identifier);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
targets,
|
|
97
|
+
fileTargets,
|
|
98
|
+
edits: (urls) => {
|
|
99
|
+
let edits = targets
|
|
100
|
+
.filter((target) => !expansionDestinations.has(`${target.start}:${target.end}`))
|
|
101
|
+
.flatMap((target) => {
|
|
102
|
+
const url = urls.get(target.url);
|
|
103
|
+
return url ? [{ ...target, url }] : [];
|
|
104
|
+
});
|
|
105
|
+
// 内层图片先替换,再将已替换的 label 合入外层引用,避免区间重叠破坏 Markdown。
|
|
106
|
+
for (const entry of expansions.sort((a, b) => a.range.end - a.range.start - (b.range.end - b.range.start))) {
|
|
107
|
+
const url = urls.get(entry.url);
|
|
108
|
+
if (!url)
|
|
109
|
+
continue;
|
|
110
|
+
let label = text.slice(entry.label.start, entry.label.end);
|
|
111
|
+
const nested = edits.filter((edit) => edit.start >= entry.label.start && edit.end <= entry.label.end);
|
|
112
|
+
for (const edit of nested.sort((a, b) => b.start - a.start))
|
|
113
|
+
label =
|
|
114
|
+
label.slice(0, edit.start - entry.label.start) +
|
|
115
|
+
edit.url +
|
|
116
|
+
label.slice(edit.end - entry.label.start);
|
|
117
|
+
edits = edits.filter((edit) => edit.start < entry.range.start || edit.end > entry.range.end);
|
|
118
|
+
edits.push({
|
|
119
|
+
...entry.range,
|
|
120
|
+
url: `${label}(<${url}>${entry.title ? ` ${text.slice(entry.title.start, entry.title.end)}` : ""})`
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return edits;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function localPath(target, workspace) {
|
|
128
|
+
if (/^file:/i.test(target)) {
|
|
129
|
+
try {
|
|
130
|
+
return fileURLToPath(target);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
throw new Error("path-unavailable");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// 其他操作系统的盘符/UNC 也是本地引用,不能当作外部 URL 跳过或在本机错误拼接。
|
|
137
|
+
if (/^[a-z]:[\\/]/i.test(target) || target.startsWith("\\\\")) {
|
|
138
|
+
if (process.platform !== "win32")
|
|
139
|
+
throw new Error("path-unavailable");
|
|
140
|
+
return target;
|
|
141
|
+
}
|
|
142
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(target) || target.startsWith("//") || target.startsWith("#"))
|
|
143
|
+
return undefined;
|
|
144
|
+
const clean = target.split(/[?#]/, 1)[0];
|
|
145
|
+
let decoded;
|
|
146
|
+
try {
|
|
147
|
+
decoded = decodeURIComponent(clean);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
throw new Error("invalid-path");
|
|
151
|
+
}
|
|
152
|
+
if (!decoded || decoded.includes("\0") || decoded.startsWith("~"))
|
|
153
|
+
throw new Error("invalid-path");
|
|
154
|
+
if (path.isAbsolute(decoded))
|
|
155
|
+
return decoded;
|
|
156
|
+
if (!workspace)
|
|
157
|
+
throw new Error("workspace-unavailable");
|
|
158
|
+
return path.resolve(workspace, decoded);
|
|
159
|
+
}
|
|
160
|
+
function contained(root, file) {
|
|
161
|
+
const relative = path.relative(root, file);
|
|
162
|
+
return (relative === "" ||
|
|
163
|
+
(!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative)));
|
|
164
|
+
}
|
|
165
|
+
function failureName(target) {
|
|
166
|
+
const name = target.split(/[\\/]/).at(-1)?.split(/[?#]/, 1)[0] || "file";
|
|
167
|
+
return name.replace(/[\r\n`[\]<>]/g, "_").slice(0, 120);
|
|
168
|
+
}
|
|
169
|
+
/** 只交付成功 final 的显式引用;失败不改变生成终态,缓存由 transport 的 final effect 闭包持有。 */
|
|
170
|
+
export async function prepareArtifacts(text, policy, ownerSignal, upload) {
|
|
171
|
+
if (policy.mode === "tools")
|
|
172
|
+
return { text, files: [] };
|
|
173
|
+
ownerSignal.throwIfAborted();
|
|
174
|
+
const parsed = references(text);
|
|
175
|
+
const signal = AbortSignal.any([ownerSignal, AbortSignal.timeout(policy.timeoutMs)]);
|
|
176
|
+
const urls = new Map();
|
|
177
|
+
const files = new Map();
|
|
178
|
+
const cards = new Map();
|
|
179
|
+
const failures = [];
|
|
180
|
+
let total = 0;
|
|
181
|
+
let count = 0;
|
|
182
|
+
let roots;
|
|
183
|
+
for (const target of new Set(parsed.targets.map((entry) => entry.url))) {
|
|
184
|
+
try {
|
|
185
|
+
const file = localPath(target, policy.workspace);
|
|
186
|
+
if (file === undefined)
|
|
187
|
+
continue;
|
|
188
|
+
signal.throwIfAborted();
|
|
189
|
+
if (!policy.local)
|
|
190
|
+
throw new Error("remote-file-unavailable");
|
|
191
|
+
if (!roots)
|
|
192
|
+
roots = await Promise.all(policy.roots.map((root) => realpath(root)));
|
|
193
|
+
const resolved = await realpath(file).catch(() => {
|
|
194
|
+
throw new Error("file-unavailable");
|
|
195
|
+
});
|
|
196
|
+
if (!roots.some((root) => contained(root, resolved)))
|
|
197
|
+
throw new Error("directory-policy");
|
|
198
|
+
let result = files.get(resolved);
|
|
199
|
+
if (!result) {
|
|
200
|
+
if (++count > policy.maxFiles)
|
|
201
|
+
throw new Error("file-count-limit");
|
|
202
|
+
result = (async () => {
|
|
203
|
+
let handle;
|
|
204
|
+
try {
|
|
205
|
+
const entry = await lstat(resolved);
|
|
206
|
+
if (!entry.isFile())
|
|
207
|
+
throw new Error("not-regular-file");
|
|
208
|
+
handle = await open(resolved, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
209
|
+
const stat = await handle.stat();
|
|
210
|
+
if (!stat.isFile() ||
|
|
211
|
+
stat.dev !== entry.dev ||
|
|
212
|
+
stat.ino !== entry.ino ||
|
|
213
|
+
(await realpath(file)) !== resolved)
|
|
214
|
+
throw new Error("file-changed");
|
|
215
|
+
if (stat.size > policy.maxFileBytes)
|
|
216
|
+
throw new Error("file-size-limit");
|
|
217
|
+
if (total + stat.size > policy.maxTotalBytes)
|
|
218
|
+
throw new Error("total-size-limit");
|
|
219
|
+
const mime = inferContentType(resolved);
|
|
220
|
+
if (policy.mimeTypes && !policy.mimeTypes.includes(mime))
|
|
221
|
+
throw new Error("type-policy");
|
|
222
|
+
total += stat.size;
|
|
223
|
+
signal.throwIfAborted();
|
|
224
|
+
// 同一描述符读取且预分配有界容量,文件增长也不能绕过已核验的字节预算。
|
|
225
|
+
const bytes = Buffer.alloc(stat.size);
|
|
226
|
+
let offset = 0;
|
|
227
|
+
while (offset < bytes.length) {
|
|
228
|
+
signal.throwIfAborted();
|
|
229
|
+
const read = await handle.read(bytes, offset, Math.min(64 << 10, bytes.length - offset), offset);
|
|
230
|
+
if (!read.bytesRead)
|
|
231
|
+
throw new Error("file-changed");
|
|
232
|
+
offset += read.bytesRead;
|
|
233
|
+
}
|
|
234
|
+
const after = await handle.stat();
|
|
235
|
+
if (after.size !== stat.size ||
|
|
236
|
+
after.mtimeMs !== stat.mtimeMs ||
|
|
237
|
+
after.ctimeMs !== stat.ctimeMs)
|
|
238
|
+
throw new Error("file-changed");
|
|
239
|
+
signal.throwIfAborted();
|
|
240
|
+
const name = path.basename(resolved);
|
|
241
|
+
return {
|
|
242
|
+
url: await upload(bytes, name, mime, signal),
|
|
243
|
+
name,
|
|
244
|
+
size: bytes.length,
|
|
245
|
+
extension: path.extname(name).slice(1).toLowerCase()
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
await handle?.close();
|
|
250
|
+
}
|
|
251
|
+
})();
|
|
252
|
+
files.set(resolved, result);
|
|
253
|
+
}
|
|
254
|
+
const artifact = await result;
|
|
255
|
+
if (parsed.fileTargets.has(target))
|
|
256
|
+
cards.set(resolved, artifact);
|
|
257
|
+
// 对最终 Markdown 只写安全地址字节;不让云地址中的括号、空格或实体改变原文结构。
|
|
258
|
+
urls.set(target, artifact.url
|
|
259
|
+
.replace(/[\s()<>"\\]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`)
|
|
260
|
+
.replace(/&/g, "&"));
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
ownerSignal.throwIfAborted();
|
|
264
|
+
const reason = signal.aborted
|
|
265
|
+
? "delivery-timeout"
|
|
266
|
+
: error instanceof Error && /^[a-z-]+$/.test(error.message)
|
|
267
|
+
? error.message
|
|
268
|
+
: "upload-failed";
|
|
269
|
+
failures.push(`${failureName(target)} (${reason})`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
ownerSignal.throwIfAborted();
|
|
273
|
+
let output = text;
|
|
274
|
+
const edits = parsed.edits(urls);
|
|
275
|
+
// 同一定义可能被多个 reference 使用,重复区间只替换一次。
|
|
276
|
+
for (const edit of [
|
|
277
|
+
...new Map(edits.map((entry) => [`${entry.start}:${entry.end}`, entry])).values()
|
|
278
|
+
].sort((a, b) => b.start - a.start))
|
|
279
|
+
output = output.slice(0, edit.start) + edit.url + output.slice(edit.end);
|
|
280
|
+
if (failures.length)
|
|
281
|
+
output += `\n\nAttachment delivery failed: ${failures.join("; ")}. These local references are unavailable to channel recipients; generation was not rerun.`;
|
|
282
|
+
return { text: output, files: [...cards.values()] };
|
|
283
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ContextEnvelope, type InvokeInput } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
2
|
import type { ImBotConfig, ImInboundMessage, ImSession } from "../contracts.js";
|
|
3
|
+
import type { ImArtifactPolicy } from "../delivery/artifact-policy.js";
|
|
3
4
|
export type ImInvocationInput = InvokeInput & {
|
|
4
5
|
runId: string;
|
|
5
6
|
invocationId: string;
|
|
@@ -9,4 +10,5 @@ export type ImInvocationInput = InvokeInput & {
|
|
|
9
10
|
export declare function createImInvocation(config: ImBotConfig, message: ImInboundMessage, context: ContextEnvelope, sessionKey: string, session: ImSession, _signal: AbortSignal, occurrenceId?: string): {
|
|
10
11
|
request: ImInvocationInput;
|
|
11
12
|
adapterType: string;
|
|
13
|
+
artifacts: ImArtifactPolicy;
|
|
12
14
|
};
|
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js
CHANGED
|
@@ -10,6 +10,7 @@ import { assertContextEnvelope, mergeContext } from "@mininglamp-oss/octo-runtim
|
|
|
10
10
|
import { validateImConfig } from "../lifecycle/configuration.js";
|
|
11
11
|
import { compactHistoryGap, historyGapContext } from "../application/context-gap.js";
|
|
12
12
|
import { MENTION_GUIDANCE } from "../transport/mentions.js";
|
|
13
|
+
import { artifactContext, artifactPolicy } from "../delivery/artifact-policy.js";
|
|
13
14
|
export function createImInvocation(config, message, context, sessionKey, session, _signal, occurrenceId = message.messageId) {
|
|
14
15
|
validateImConfig(config);
|
|
15
16
|
assertContextEnvelope(context);
|
|
@@ -113,6 +114,15 @@ export function createImInvocation(config, message, context, sessionKey, session
|
|
|
113
114
|
]) {
|
|
114
115
|
try {
|
|
115
116
|
snapshot = mergeContext(defaults, submitted);
|
|
117
|
+
// 固定交付约定也计入 Context 预算;沿原策略只移除自动辅助材料。
|
|
118
|
+
snapshot = {
|
|
119
|
+
...snapshot,
|
|
120
|
+
items: [
|
|
121
|
+
...snapshot.items.filter((item) => !(item.namespace === "extra.im" && item.name === "artifact-delivery")),
|
|
122
|
+
artifactContext(artifactPolicy(config, snapshot, agentSource === "provisioned"))
|
|
123
|
+
]
|
|
124
|
+
};
|
|
125
|
+
assertContextEnvelope(snapshot);
|
|
116
126
|
break;
|
|
117
127
|
}
|
|
118
128
|
catch (error) {
|
|
@@ -203,5 +213,9 @@ export function createImInvocation(config, message, context, sessionKey, session
|
|
|
203
213
|
mkdirSync(defaultWorkdir, { recursive: true, mode: 0o700 });
|
|
204
214
|
session.lastEventId = eventId;
|
|
205
215
|
session.lastRunId = runId;
|
|
206
|
-
return {
|
|
216
|
+
return {
|
|
217
|
+
request,
|
|
218
|
+
adapterType: selectedAdapter,
|
|
219
|
+
artifacts: artifactPolicy(config, snapshot, agentSource === "provisioned")
|
|
220
|
+
};
|
|
207
221
|
}
|
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ImModuleDependencies } from "../ports.js";
|
|
2
2
|
import type { ImInvocationInput } from "./dispatcher.js";
|
|
3
|
-
import { type CanonicalEvent, type InvokeEnvironment } from "@mininglamp-oss/octo-runtime-protocol";
|
|
3
|
+
import { type FailureEnvelope, type CanonicalEvent, type InvokeEnvironment } from "@mininglamp-oss/octo-runtime-protocol";
|
|
4
4
|
import type { ImBotConfig, ImTaskAttempt } from "../contracts.js";
|
|
5
5
|
export declare const DEFAULT_CODEX_RETRY: Readonly<{
|
|
6
6
|
enabled: true;
|
|
@@ -26,6 +26,8 @@ export declare class ImTask {
|
|
|
26
26
|
readonly onAttempt: (request: ImInvocationInput) => void;
|
|
27
27
|
readonly time: ImTaskClock;
|
|
28
28
|
readonly attempts: ImTaskAttempt[];
|
|
29
|
+
/** 与 Channel 展示、诊断共用的本次未提交事实;不注入执行源事件。 */
|
|
30
|
+
notSubmittedFailure?: FailureEnvelope;
|
|
29
31
|
stopReason?: string;
|
|
30
32
|
constructor(kernel: ImModuleDependencies["kernel"], request: ImInvocationInput, adapterType: string, config: ImBotConfig, environment: InvokeEnvironment, onAttempt: (request: ImInvocationInput) => void, time?: ImTaskClock);
|
|
31
33
|
/** reset 只阻止后续尝试,不把 reset 变成取消当前 Provider 执行。 */
|
|
@@ -33,5 +35,7 @@ export declare class ImTask {
|
|
|
33
35
|
/** owner stop 只取消执行和后续尝试;当前订阅须继续消费真实终态。 */
|
|
34
36
|
drain(reason?: string): Promise<void>;
|
|
35
37
|
cancel(reason?: string): Promise<boolean>;
|
|
38
|
+
/** 展示故障只请求停止执行及重试,保留观察 signal;返回取消受理结果,不代表执行终态。 */
|
|
39
|
+
cancelExecution(reason: string): Promise<boolean>;
|
|
36
40
|
events(): AsyncGenerator<CanonicalEvent>;
|
|
37
41
|
}
|
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { performance } from "node:perf_hooks";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
-
import { KernelError } from "@mininglamp-oss/octo-runtime-executor-kernel";
|
|
5
|
+
import { KernelError, isInvocationNotSubmitted } from "@mininglamp-oss/octo-runtime-executor-kernel";
|
|
6
|
+
import { failurePayload } from "@mininglamp-oss/octo-runtime-protocol";
|
|
6
7
|
export const DEFAULT_CODEX_RETRY = Object.freeze({
|
|
7
8
|
enabled: true,
|
|
8
9
|
max_consecutive_retries: 5,
|
|
@@ -32,6 +33,8 @@ export class ImTask {
|
|
|
32
33
|
onAttempt;
|
|
33
34
|
time;
|
|
34
35
|
attempts = [];
|
|
36
|
+
/** 与 Channel 展示、诊断共用的本次未提交事实;不注入执行源事件。 */
|
|
37
|
+
notSubmittedFailure;
|
|
35
38
|
#policy;
|
|
36
39
|
#abort = new AbortController();
|
|
37
40
|
#retryStop = new AbortController();
|
|
@@ -68,7 +71,7 @@ export class ImTask {
|
|
|
68
71
|
this.#draining = true;
|
|
69
72
|
this.stopRetries();
|
|
70
73
|
const active = this.#active;
|
|
71
|
-
if (!active)
|
|
74
|
+
if (!active || active.completion === "not_submitted")
|
|
72
75
|
return;
|
|
73
76
|
try {
|
|
74
77
|
this.#cancelPending ??= this.kernel.cancelInvocation(active.invocationId, reason);
|
|
@@ -76,18 +79,31 @@ export class ImTask {
|
|
|
76
79
|
}
|
|
77
80
|
catch (error) {
|
|
78
81
|
// Kernel 可在订阅 ACK 时先确认终态并释放登记,业务迭代器此时仍可能等待交互展示。
|
|
79
|
-
//
|
|
80
|
-
if (!(error
|
|
81
|
-
!(
|
|
82
|
+
// 登记缺失本身不是完成证据;只接受同次原流确认终态或可信未提交,仍受 owner 共享期限约束。
|
|
83
|
+
if (!isInvocationNotSubmitted(error) &&
|
|
84
|
+
(!(error instanceof KernelError && error.code === "INVOCATION_NOT_TRACKED") ||
|
|
85
|
+
(await active.finished) === "unresolved"))
|
|
82
86
|
throw error;
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
async cancel(reason = "IM user stop") {
|
|
86
90
|
this.#abort.abort(reason);
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
return this.cancelExecution(reason);
|
|
92
|
+
}
|
|
93
|
+
/** 展示故障只请求停止执行及重试,保留观察 signal;返回取消受理结果,不代表执行终态。 */
|
|
94
|
+
async cancelExecution(reason) {
|
|
95
|
+
this.stopRetries();
|
|
96
|
+
if (!this.#active || this.#active.completion === "not_submitted")
|
|
97
|
+
return true;
|
|
89
98
|
this.#cancelPending ??= this.kernel.cancelInvocation(this.#active.invocationId, reason);
|
|
90
|
-
|
|
99
|
+
try {
|
|
100
|
+
return (await this.#cancelPending).accepted;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (isInvocationNotSubmitted(error))
|
|
104
|
+
return true;
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
91
107
|
}
|
|
92
108
|
#stop(reason) {
|
|
93
109
|
this.stopReason ??= reason;
|
|
@@ -176,12 +192,13 @@ export class ImTask {
|
|
|
176
192
|
item.payload.run_timeout_ms = remaining;
|
|
177
193
|
this.onAttempt(request);
|
|
178
194
|
let finish;
|
|
179
|
-
|
|
195
|
+
const active = {
|
|
180
196
|
invocationId: request.invocationId,
|
|
181
197
|
finished: new Promise((resolve) => {
|
|
182
198
|
finish = resolve;
|
|
183
199
|
})
|
|
184
200
|
};
|
|
201
|
+
this.#active = active;
|
|
185
202
|
this.#cancelPending = undefined;
|
|
186
203
|
const attempt = {
|
|
187
204
|
runId: request.runId,
|
|
@@ -190,7 +207,7 @@ export class ImTask {
|
|
|
190
207
|
};
|
|
191
208
|
this.attempts.push(attempt);
|
|
192
209
|
let terminal;
|
|
193
|
-
let
|
|
210
|
+
let completion = "unresolved";
|
|
194
211
|
try {
|
|
195
212
|
for await (const event of this.kernel.invoke(request, {
|
|
196
213
|
...this.environment,
|
|
@@ -210,10 +227,28 @@ export class ImTask {
|
|
|
210
227
|
yield event;
|
|
211
228
|
}
|
|
212
229
|
// 看到终态后仍须正常耗尽:终态后的传输/控制错误不能被 drain 当成成功。
|
|
213
|
-
|
|
230
|
+
if (!terminal)
|
|
231
|
+
throw new Error("IM_RUN_WITHOUT_TERMINAL");
|
|
232
|
+
completion = "terminal_confirmed";
|
|
214
233
|
}
|
|
215
234
|
catch (error) {
|
|
216
|
-
|
|
235
|
+
if (isInvocationNotSubmitted(error)) {
|
|
236
|
+
completion = "not_submitted";
|
|
237
|
+
active.completion = completion;
|
|
238
|
+
this.stopRetries();
|
|
239
|
+
this.notSubmittedFailure = failurePayload(error, {
|
|
240
|
+
stage: "channel_admission",
|
|
241
|
+
defaultDomain: "runtime",
|
|
242
|
+
invocationNotSubmitted: true,
|
|
243
|
+
source: { component: "octo-runtime", adapter: this.adapterType },
|
|
244
|
+
runId: request.runId
|
|
245
|
+
}).failure;
|
|
246
|
+
attempt.outcome = "not_submitted";
|
|
247
|
+
attempt.failureCode = this.notSubmittedFailure.code;
|
|
248
|
+
attempt.diagnosticId = this.notSubmittedFailure.diagnosticId;
|
|
249
|
+
}
|
|
250
|
+
else
|
|
251
|
+
attempt.outcome = "unknown";
|
|
217
252
|
throw error;
|
|
218
253
|
}
|
|
219
254
|
finally {
|
|
@@ -221,7 +256,7 @@ export class ImTask {
|
|
|
221
256
|
await this.#settleCancellation();
|
|
222
257
|
this.#active = undefined;
|
|
223
258
|
// #cancelPending 只保存原始取消回执,不能反过来等待 finished,否则这里会循环等待。
|
|
224
|
-
finish(
|
|
259
|
+
finish(completion);
|
|
225
260
|
}
|
|
226
261
|
if (!terminal)
|
|
227
262
|
throw new Error("IM_RUN_WITHOUT_TERMINAL");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ContextEnvsPayload } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
|
-
/**
|
|
2
|
+
/** 当前连接拥有工具身份;规范 token 与兼容别名同时覆盖默认环境,不读取消息中的凭据。 */
|
|
3
3
|
export declare function octoCliEnvironment(apiUrl: string, token: string): ContextEnvsPayload;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { trimTrailingSlashes } from "../transport/api/url.js";
|
|
2
|
+
/** 当前连接拥有工具身份;规范 token 与兼容别名同时覆盖默认环境,不读取消息中的凭据。 */
|
|
2
3
|
export function octoCliEnvironment(apiUrl, token) {
|
|
3
4
|
if (!/^bf_[A-Za-z0-9_-]+$/.test(token))
|
|
4
5
|
throw new Error("IM_BOT_TOKEN_INVALID");
|
|
@@ -15,11 +16,12 @@ export function octoCliEnvironment(apiUrl, token) {
|
|
|
15
16
|
url.search ||
|
|
16
17
|
url.hash)
|
|
17
18
|
throw new Error("IM_API_URL_INVALID");
|
|
18
|
-
url.pathname = url.pathname
|
|
19
|
+
url.pathname = trimTrailingSlashes(url.pathname).replace(/\/api$/, "");
|
|
19
20
|
return {
|
|
20
21
|
env_variables: [
|
|
21
22
|
{ key: "OCTO_BOT_TOKEN", value: token },
|
|
22
|
-
{ key: "OCTO_API_BASE_URL", value: url.href
|
|
23
|
+
{ key: "OCTO_API_BASE_URL", value: trimTrailingSlashes(url.href) },
|
|
24
|
+
{ key: "OCTO_TOKEN", value: token }
|
|
23
25
|
]
|
|
24
26
|
};
|
|
25
27
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { isAbsolute } from "node:path";
|
|
4
4
|
import { assertApprovalMode, assertContextEnvelope, assertJsonByteLimit } from "@mininglamp-oss/octo-runtime-protocol";
|
|
5
|
+
import { trimTrailingSlashes } from "../transport/api/url.js";
|
|
6
|
+
import { ARTIFACT_LIMITS } from "../delivery/artifact-policy.js";
|
|
5
7
|
export const IM_MAX_BOTS = 64;
|
|
6
8
|
export const IM_MAX_CONFIG_OPERATIONS = 64;
|
|
7
9
|
export const IM_MAX_CONFIG_BYTES = 256 * 1024;
|
|
@@ -62,6 +64,29 @@ export function validateImConfig(config) {
|
|
|
62
64
|
}
|
|
63
65
|
if (config.context !== undefined)
|
|
64
66
|
assertContextEnvelope(config.context);
|
|
67
|
+
const delivery = config.artifact_delivery;
|
|
68
|
+
if (delivery !== undefined) {
|
|
69
|
+
if (!delivery || typeof delivery !== "object" || Array.isArray(delivery))
|
|
70
|
+
throw new Error("IM_ARTIFACT_CONFIG_INVALID");
|
|
71
|
+
if (delivery.mode !== undefined && !["channel", "tools"].includes(delivery.mode))
|
|
72
|
+
throw new Error("IM_ARTIFACT_CONFIG_INVALID");
|
|
73
|
+
for (const field of ["allowed_roots", "allowed_mime_types"]) {
|
|
74
|
+
const values = delivery[field];
|
|
75
|
+
if (values !== undefined &&
|
|
76
|
+
(!Array.isArray(values) ||
|
|
77
|
+
values.length > 32 ||
|
|
78
|
+
values.some((value) => typeof value !== "string" ||
|
|
79
|
+
!value.trim() ||
|
|
80
|
+
(field === "allowed_roots" ? !isAbsolute(value) : !/^[\w.+-]+\/[\w.+-]+$/.test(value)))))
|
|
81
|
+
throw new Error("IM_ARTIFACT_CONFIG_INVALID");
|
|
82
|
+
}
|
|
83
|
+
for (const field of Object.keys(ARTIFACT_LIMITS)) {
|
|
84
|
+
const value = delivery[field];
|
|
85
|
+
if (value !== undefined &&
|
|
86
|
+
(!Number.isInteger(value) || value < 1 || value > ARTIFACT_LIMITS[field]))
|
|
87
|
+
throw new Error("IM_ARTIFACT_CONFIG_INVALID");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
65
90
|
assertApprovalMode(config.approval_mode ?? "full_access");
|
|
66
91
|
if (config.allowed_sender_ids !== undefined &&
|
|
67
92
|
(!Array.isArray(config.allowed_sender_ids) ||
|
|
@@ -112,7 +137,7 @@ export function validateImConfig(config) {
|
|
|
112
137
|
}
|
|
113
138
|
/** Stable local lookup key, not a caller-supplied identity or authorization token. */
|
|
114
139
|
export function imBotIdentity(config) {
|
|
115
|
-
const identity = ["octo", new URL(config.api_url).href
|
|
140
|
+
const identity = ["octo", trimTrailingSlashes(new URL(config.api_url).href), config.bot_id];
|
|
116
141
|
return createHash("sha256").update(JSON.stringify(identity)).digest("hex");
|
|
117
142
|
}
|
|
118
143
|
function validateUrl(value, secure, local) {
|
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MessageType } from "./types.js";
|
|
2
2
|
import { postJson, generateClientMsgNo, DEFAULT_TIMEOUT_MS } from "./client.js";
|
|
3
3
|
import { OctoApiError } from "./errors.js";
|
|
4
|
+
import { trimTrailingSlashes } from "./url.js";
|
|
4
5
|
function validateTemplateFrame(params) {
|
|
5
6
|
const templateRef = params.templateRef;
|
|
6
7
|
if (templateRef === null || typeof templateRef !== "object" || Array.isArray(templateRef)) {
|
|
@@ -176,7 +177,7 @@ function parseBotCardConfig(value) {
|
|
|
176
177
|
* 传输 / 5xx 抛错,交由调用方重试节奏处理。
|
|
177
178
|
*/
|
|
178
179
|
export async function getCardProfile(params) {
|
|
179
|
-
const url = `${params.apiUrl
|
|
180
|
+
const url = `${trimTrailingSlashes(params.apiUrl)}/v1/bot/card/profile`;
|
|
180
181
|
const resp = await fetch(url, {
|
|
181
182
|
method: "GET",
|
|
182
183
|
headers: { Authorization: `Bearer ${params.botToken}` },
|
|
@@ -52,6 +52,7 @@ interface JsonRequestOptions {
|
|
|
52
52
|
/** Optional decoded response cap for callers that fetch large documents. */
|
|
53
53
|
maxResponseBytes?: number;
|
|
54
54
|
}
|
|
55
|
+
export declare function readResponseText(response: Response, maxBytes?: number): Promise<string>;
|
|
55
56
|
export declare function postJson<T>(apiUrl: string, botToken: string, path: string, payload: Record<string, unknown>, signal?: AbortSignal, opts?: JsonRequestOptions): Promise<T | undefined>;
|
|
56
57
|
export declare function getJson<T>(apiUrl: string, botToken: string, path: string, signal?: AbortSignal, opts?: JsonRequestOptions): Promise<T | undefined>;
|
|
57
58
|
export {};
|
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// Adapted from Mininglamp-OSS/openclaw-channel-octo/src/api-fetch.ts.
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { OctoApiError, OctoApiStatusMismatchError, OctoApiProtocolError } from "./errors.js";
|
|
8
|
+
import { trimTrailingSlashes } from "./url.js";
|
|
8
9
|
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
9
10
|
/**
|
|
10
11
|
* 生成出站消息的客户端幂等编号 client_msg_no(UUID)。
|
|
@@ -78,7 +79,7 @@ function backoffSleep(ms, signal, cause) {
|
|
|
78
79
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
|
-
async function readResponseText(response, maxBytes) {
|
|
82
|
+
export async function readResponseText(response, maxBytes) {
|
|
82
83
|
if (maxBytes === undefined)
|
|
83
84
|
return response.text();
|
|
84
85
|
const reader = response.body?.getReader();
|
|
@@ -114,7 +115,7 @@ async function readResponseText(response, maxBytes) {
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
async function requestJson(apiUrl, botToken, path, method, payload, signal, opts = {}) {
|
|
117
|
-
const url = `${apiUrl
|
|
118
|
+
const url = `${trimTrailingSlashes(apiUrl)}${path}`;
|
|
118
119
|
const retryOn429 = opts.retryOn429 ?? true;
|
|
119
120
|
let waited = 0;
|
|
120
121
|
for (let attempt = 0;; attempt++) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_TIMEOUT_MS, postJson, getJson } from "./client.js";
|
|
2
|
+
import { trimTrailingSlashes } from "./url.js";
|
|
2
3
|
// Fetch the groups the bot belongs to
|
|
3
4
|
export async function fetchBotGroups(params) {
|
|
4
5
|
const url = `${params.apiUrl}/v1/bot/groups`;
|
|
@@ -88,7 +89,7 @@ export async function getChannelMessagePage(params) {
|
|
|
88
89
|
* so callers can gracefully degrade.
|
|
89
90
|
*/
|
|
90
91
|
export async function fetchUserInfo(params) {
|
|
91
|
-
const url = `${params.apiUrl
|
|
92
|
+
const url = `${trimTrailingSlashes(params.apiUrl)}/v1/bot/user/info?uid=${encodeURIComponent(params.uid)}`;
|
|
92
93
|
try {
|
|
93
94
|
const resp = await fetch(url, {
|
|
94
95
|
method: "GET",
|
|
@@ -123,7 +124,7 @@ export async function searchSpaceMembers(params) {
|
|
|
123
124
|
query.set("space_id", params.spaceId);
|
|
124
125
|
if (params.limit)
|
|
125
126
|
query.set("limit", String(params.limit));
|
|
126
|
-
const url = `${params.apiUrl
|
|
127
|
+
const url = `${trimTrailingSlashes(params.apiUrl)}/v1/bot/space/members?${query.toString()}`;
|
|
127
128
|
const resp = await fetch(url, {
|
|
128
129
|
headers: { Authorization: `Bearer ${params.botToken}` },
|
|
129
130
|
signal: AbortSignal.timeout(DEFAULT_TIMEOUT_MS)
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/** 校验服务端返回的长期下载地址;不把 PUT 地址、签名有效期或 Bot 鉴权路由冒充附件。 */
|
|
2
|
+
export declare function attachmentUrl(raw: unknown, apiUrl: string): string;
|
|
3
|
+
/** 当前 Bot 获取聊天上传凭据后直传;只交付独立 downloadUrl,绝不转发 Bot Token。 */
|
|
4
|
+
export declare function uploadChatAttachment(apiUrl: string, token: string, bytes: Uint8Array, filename: string, mime: string, signal: AbortSignal): Promise<string>;
|
|
1
5
|
/**
|
|
2
6
|
* Infer MIME type from filename extension. Returns a sensible default if unknown.
|
|
3
7
|
*/
|