ocean-crew 0.0.0-stage → 0.4.0
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/LICENSE +21 -0
- package/README.md +156 -2
- package/THIRD_PARTY_NOTICES.md +159 -0
- package/client.js +31389 -0
- package/cordis.patch.yml +6 -0
- package/dist/host/chat/btw.js +436 -0
- package/dist/host/chat/channel.js +1241 -0
- package/dist/host/chat/chat-index.js +344 -0
- package/dist/host/chat/delivery.js +231 -0
- package/dist/host/chat/feed.js +165 -0
- package/dist/host/chat/handoffs.js +625 -0
- package/dist/host/chat/parts.js +2033 -0
- package/dist/host/chat/requests.js +155 -0
- package/dist/host/chat/resume.js +364 -0
- package/dist/host/chat/side.js +457 -0
- package/dist/host/chat/steer.js +346 -0
- package/dist/host/chat/turns.js +1457 -0
- package/dist/host/connectors/catalog.js +331 -0
- package/dist/host/connectors/gateway.js +339 -0
- package/dist/host/connectors/index.js +1235 -0
- package/dist/host/connectors/mail/index.js +912 -0
- package/dist/host/connectors/mail/presets.js +53 -0
- package/dist/host/connectors/mail/transport.js +519 -0
- package/dist/host/connectors/oauth.js +337 -0
- package/dist/host/core/constants.js +123 -0
- package/dist/host/core/diagnostics.js +310 -0
- package/dist/host/core/dsh-update.js +212 -0
- package/dist/host/core/events.js +16 -0
- package/dist/host/core/files.js +37 -0
- package/dist/host/core/folders.js +283 -0
- package/dist/host/core/home-lock.js +137 -0
- package/dist/host/core/links.js +52 -0
- package/dist/host/core/runtime.js +5 -0
- package/dist/host/core/store.js +662 -0
- package/dist/host/core/text.js +59 -0
- package/dist/host/core/thinking.js +60 -0
- package/dist/host/core/time-context.js +69 -0
- package/dist/host/core/update.js +466 -0
- package/dist/host/groups/calls.js +684 -0
- package/dist/host/groups/index.js +79 -0
- package/dist/host/groups/log.js +334 -0
- package/dist/host/groups/prompt.js +124 -0
- package/dist/host/groups/relay.js +489 -0
- package/dist/host/groups/round.js +992 -0
- package/dist/host/groups/tasks.js +217 -0
- package/dist/host/groups/tools.js +478 -0
- package/dist/host/groups/types.js +8 -0
- package/dist/host/im/format.js +228 -0
- package/dist/host/im/index.js +2461 -0
- package/dist/host/im/platforms/feishu.js +1134 -0
- package/dist/host/im/platforms/index.js +6 -0
- package/dist/host/im/platforms/media-type.js +70 -0
- package/dist/host/im/platforms/weixin.js +1117 -0
- package/dist/host/im/reaction.js +51 -0
- package/dist/host/im/supervisor.js +56 -0
- package/dist/host/team/agents.js +161 -0
- package/dist/host/team/models.js +427 -0
- package/dist/host/team/permissions.js +263 -0
- package/dist/host/team/privacy.js +108 -0
- package/dist/host/team/prompt.js +86 -0
- package/dist/host/team/providers.js +461 -0
- package/dist/host/team/roster.js +1011 -0
- package/dist/host/team/tools.js +1638 -0
- package/dist/host/work/approvals.js +290 -0
- package/dist/host/work/avatar-library.js +155 -0
- package/dist/host/work/avatar.js +132 -0
- package/dist/host/work/capabilities.js +862 -0
- package/dist/host/work/companion.js +306 -0
- package/dist/host/work/goal-skills.js +91 -0
- package/dist/host/work/goals.js +1337 -0
- package/dist/host/work/images.js +283 -0
- package/dist/host/work/learning.js +1021 -0
- package/dist/host/work/memory-pending.js +108 -0
- package/dist/host/work/memory.js +3237 -0
- package/dist/host/work/notify.js +146 -0
- package/dist/host/work/reset.js +43 -0
- package/dist/host/work/schedules.js +309 -0
- package/dist/host/work/secrets.js +702 -0
- package/dist/host/work/steward.js +166 -0
- package/dist/host/work/tts.js +192 -0
- package/dist/host/work/usage.js +84 -0
- package/dist/index.js +137 -0
- package/dist/shared/api.js +32 -0
- package/dist/shared/companion.js +110 -0
- package/dist/shared/config.js +3 -0
- package/dist/shared/coordination.js +6 -0
- package/dist/shared/group-replies.js +95 -0
- package/dist/shared/im-platforms.js +35 -0
- package/dist/shared/im.js +3 -0
- package/dist/shared/mentions.js +85 -0
- package/dist/shared/state.js +25 -0
- package/package.json +81 -5
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Outbound text for IM platforms. Bots write Markdown; each platform adapter turns it
|
|
2
|
+
// into what the platform renders (Telegram HTML) or plain text, and cuts it at the
|
|
3
|
+
// platform's per-message limit without breaking inside a code fence when it can help it.
|
|
4
|
+
const escapeHtml = (text) => String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
5
|
+
// Inline Markdown inside one line or block: `code`, **bold**, _italic_, ~~strike~~,
|
|
6
|
+
// [label](url). Code spans are pulled out first so markers inside them stay literal.
|
|
7
|
+
function inlineHtml(line) {
|
|
8
|
+
const spans = [];
|
|
9
|
+
const kept = line.replace(/`([^`]+)`/g, (_all, code) => {
|
|
10
|
+
spans.push(`<code>${escapeHtml(code)}</code>`);
|
|
11
|
+
return `\x00${spans.length - 1}\x00`;
|
|
12
|
+
});
|
|
13
|
+
const html = escapeHtml(kept)
|
|
14
|
+
.replace(/\[([^\]]*)\]\(([^)\s]+)\)/g, (_all, label, url) => `<a href="${escapeHtml(url)}">${label}</a>`)
|
|
15
|
+
.replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>")
|
|
16
|
+
.replace(/__([^_]+)__/g, "<b>$1</b>")
|
|
17
|
+
.replace(/\*([^*]+)\*/g, "<i>$1</i>")
|
|
18
|
+
.replace(/\b_([^_]+)_\b/g, "<i>$1</i>")
|
|
19
|
+
.replace(/~~([^~]+)~~/g, "<s>$1</s>");
|
|
20
|
+
return html.replace(/\u0000(\d+)\u0000/g, (_all, index) => spans[Number(index)]);
|
|
21
|
+
}
|
|
22
|
+
function inlinePlain(line) {
|
|
23
|
+
return line
|
|
24
|
+
.replace(/`([^`]+)`/g, "$1")
|
|
25
|
+
.replace(/\[([^\]]*)\]\(([^)\s]+)\)/g, (_all, label, url) => label === url ? label : `${label} (${url})`)
|
|
26
|
+
.replace(/\*\*([^*]+)\*\*/g, "$1")
|
|
27
|
+
.replace(/__([^_]+)__/g, "$1")
|
|
28
|
+
.replace(/\*([^*]+)\*/g, "$1")
|
|
29
|
+
.replace(/\b_([^_]+)_\b/g, "$1")
|
|
30
|
+
.replace(/~~([^~]+)~~/g, "$1");
|
|
31
|
+
}
|
|
32
|
+
function blocks(markdown) {
|
|
33
|
+
const out = [];
|
|
34
|
+
const lines = String(markdown).split("\n");
|
|
35
|
+
let at = 0;
|
|
36
|
+
let buffer = [];
|
|
37
|
+
const flush = () => {
|
|
38
|
+
if (buffer.length > 0)
|
|
39
|
+
out.push({ kind: "text", lines: buffer });
|
|
40
|
+
buffer = [];
|
|
41
|
+
};
|
|
42
|
+
while (at < lines.length) {
|
|
43
|
+
const line = lines[at];
|
|
44
|
+
const fence = /^```(\S*)\s*$/.exec(line);
|
|
45
|
+
if (fence !== null) {
|
|
46
|
+
flush();
|
|
47
|
+
const close = lines.slice(at + 1).findIndex((item) => /^```\s*$/.test(item));
|
|
48
|
+
const body = close === -1 ? lines.slice(at + 1) : lines.slice(at + 1, at + 1 + close);
|
|
49
|
+
out.push({ kind: "code", lang: fence[1] ?? "", lines: body, open: true });
|
|
50
|
+
at += 1 + (close === -1 ? body.length : close + 1);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (line.trim() === "")
|
|
54
|
+
flush();
|
|
55
|
+
else
|
|
56
|
+
buffer.push(line);
|
|
57
|
+
at += 1;
|
|
58
|
+
}
|
|
59
|
+
flush();
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
const renderHtml = (block) => block.kind === "code"
|
|
63
|
+
? `<pre><code${block.lang ? ` class="language-${escapeHtml(block.lang)}"` : ""}>${escapeHtml(block.lines.join("\n"))}</code></pre>`
|
|
64
|
+
: block.lines.map(inlineHtml).join("\n");
|
|
65
|
+
const renderPlain = (block) => block.kind === "code" ? block.lines.join("\n") : block.lines.map(inlinePlain).join("\n");
|
|
66
|
+
export function toTelegramHtml(markdown) {
|
|
67
|
+
return blocks(markdown).map(renderHtml).join("\n");
|
|
68
|
+
}
|
|
69
|
+
export function toPlain(markdown) {
|
|
70
|
+
return blocks(markdown).map(renderPlain).join("\n");
|
|
71
|
+
}
|
|
72
|
+
const points = (text) => Array.from(text).length;
|
|
73
|
+
// Split a block that alone exceeds the limit: text at line boundaries (a line that
|
|
74
|
+
// is still too long is cut where it lands — Telegram answers it as plain text), a
|
|
75
|
+
// code fence into several fenced blocks.
|
|
76
|
+
function forceCut(block, limit) {
|
|
77
|
+
if (block.kind !== "code") {
|
|
78
|
+
const chunks = [];
|
|
79
|
+
let html = "";
|
|
80
|
+
let text = "";
|
|
81
|
+
const flush = () => {
|
|
82
|
+
if (html === "")
|
|
83
|
+
return;
|
|
84
|
+
chunks.push({ html, text });
|
|
85
|
+
html = "";
|
|
86
|
+
text = "";
|
|
87
|
+
};
|
|
88
|
+
for (const line of block.lines) {
|
|
89
|
+
const lineHtml = inlineHtml(line);
|
|
90
|
+
const candidate = html === "" ? lineHtml : `${html}\n${lineHtml}`;
|
|
91
|
+
if (points(candidate) <= limit) {
|
|
92
|
+
html = candidate;
|
|
93
|
+
text = text === "" ? inlinePlain(line) : `${text}\n${inlinePlain(line)}`;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
flush();
|
|
97
|
+
// A single line over the limit is cut on its rendered text.
|
|
98
|
+
let rest = lineHtml;
|
|
99
|
+
let restPlain = inlinePlain(line);
|
|
100
|
+
while (points(rest) > limit) {
|
|
101
|
+
const part = Array.from(rest).slice(0, limit).join("");
|
|
102
|
+
const plainPart = Array.from(restPlain).slice(0, limit).join("");
|
|
103
|
+
chunks.push({ html: part, text: plainPart });
|
|
104
|
+
rest = Array.from(rest).slice(limit).join("");
|
|
105
|
+
restPlain = Array.from(restPlain).slice(limit).join("");
|
|
106
|
+
}
|
|
107
|
+
html = rest;
|
|
108
|
+
text = restPlain;
|
|
109
|
+
}
|
|
110
|
+
flush();
|
|
111
|
+
return chunks;
|
|
112
|
+
}
|
|
113
|
+
const chunks = [];
|
|
114
|
+
const open = `<pre><code${block.lang ? ` class="language-${escapeHtml(block.lang)}"` : ""}>`;
|
|
115
|
+
const close = "</code></pre>";
|
|
116
|
+
let body = block.lines.join("\n");
|
|
117
|
+
const room = limit - points(open) - points(close);
|
|
118
|
+
while (body !== "") {
|
|
119
|
+
let at = Math.min(points(body), Math.max(1, room));
|
|
120
|
+
const chars = Array.from(body);
|
|
121
|
+
const newline = body.lastIndexOf("\n", at);
|
|
122
|
+
if (newline > room / 2)
|
|
123
|
+
at = newline;
|
|
124
|
+
const part = chars.slice(0, at).join("");
|
|
125
|
+
chunks.push({ html: `${open}${escapeHtml(part)}${close}`, text: part });
|
|
126
|
+
body = chars.slice(at).join("").replace(/^\n/, "");
|
|
127
|
+
}
|
|
128
|
+
return chunks;
|
|
129
|
+
}
|
|
130
|
+
// Chunks of one Markdown message, each under `limit` rendered characters. Block
|
|
131
|
+
// A fence left open at a cut would render the next chunk as a bare body, so the cut closes
|
|
132
|
+
// it and the next chunk reopens it with the same language. When the reply is split into
|
|
133
|
+
// more than one part, each part says which one it is, so the reader knows more is coming.
|
|
134
|
+
const FENCE_LINE = /^\s*(?:```|~~~)(.*)$/;
|
|
135
|
+
const fenceOpen = (text) => {
|
|
136
|
+
let open = false;
|
|
137
|
+
let lang = "";
|
|
138
|
+
for (const line of text.split("\n")) {
|
|
139
|
+
const found = FENCE_LINE.exec(line);
|
|
140
|
+
if (found === null)
|
|
141
|
+
continue;
|
|
142
|
+
if (!open)
|
|
143
|
+
lang = found[1].trim();
|
|
144
|
+
open = !open;
|
|
145
|
+
}
|
|
146
|
+
return { open, lang };
|
|
147
|
+
};
|
|
148
|
+
export function chunkMarkdown(markdown, limit) {
|
|
149
|
+
const whole = String(markdown ?? "").trimEnd();
|
|
150
|
+
if (whole === "")
|
|
151
|
+
return [];
|
|
152
|
+
if (points(whole) <= limit)
|
|
153
|
+
return [whole];
|
|
154
|
+
// A part marker is only useful when the budget is much larger than the marker itself;
|
|
155
|
+
// on a tiny limit it would eat the text and say nothing.
|
|
156
|
+
const marked = limit >= 128;
|
|
157
|
+
// Room for "(i/n)" comes out of the limit, so every part stays within it.
|
|
158
|
+
const budgetTotal = Math.max(1, limit - (marked ? 8 : 0));
|
|
159
|
+
const raw = [];
|
|
160
|
+
let rest = whole;
|
|
161
|
+
let inside = false;
|
|
162
|
+
let lang = "";
|
|
163
|
+
while (points(rest) > budgetTotal) {
|
|
164
|
+
const opening = inside ? `\`\`\`${lang}\n` : "";
|
|
165
|
+
const closing = inside || FENCE_LINE.test(rest) ? 4 : 0;
|
|
166
|
+
const budget = Math.max(1, budgetTotal - points(opening) - closing);
|
|
167
|
+
const chars = [...rest];
|
|
168
|
+
let at = budget;
|
|
169
|
+
const slice = chars.slice(0, budget).join("");
|
|
170
|
+
const newline = slice.lastIndexOf("\n");
|
|
171
|
+
if (newline > budget / 2)
|
|
172
|
+
at = newline;
|
|
173
|
+
else {
|
|
174
|
+
const space = slice.lastIndexOf(" ");
|
|
175
|
+
if (space > budget / 2)
|
|
176
|
+
at = space;
|
|
177
|
+
}
|
|
178
|
+
const body = chars.slice(0, at).join("");
|
|
179
|
+
rest = chars.slice(at).join("").replace(/^\s+/, "");
|
|
180
|
+
let state = inside;
|
|
181
|
+
for (const line of body.split("\n")) {
|
|
182
|
+
const found = FENCE_LINE.exec(line);
|
|
183
|
+
if (found === null)
|
|
184
|
+
continue;
|
|
185
|
+
if (!state)
|
|
186
|
+
lang = found[1].trim();
|
|
187
|
+
state = !state;
|
|
188
|
+
}
|
|
189
|
+
raw.push(`${opening}${body}${state ? "\n```" : ""}`);
|
|
190
|
+
inside = state;
|
|
191
|
+
}
|
|
192
|
+
if (rest !== "")
|
|
193
|
+
raw.push(`${inside ? `\`\`\`${lang}\n` : ""}${rest}`);
|
|
194
|
+
if (!marked || raw.length <= 1)
|
|
195
|
+
return raw;
|
|
196
|
+
return raw.map((piece, index) => `${piece} (${index + 1}/${raw.length})`);
|
|
197
|
+
}
|
|
198
|
+
export function chunkTelegram(markdown, limit = 4096) {
|
|
199
|
+
const chunks = [];
|
|
200
|
+
let html = "";
|
|
201
|
+
let text = "";
|
|
202
|
+
const flush = () => {
|
|
203
|
+
if (html === "" && text === "")
|
|
204
|
+
return;
|
|
205
|
+
chunks.push({ html, text });
|
|
206
|
+
html = "";
|
|
207
|
+
text = "";
|
|
208
|
+
};
|
|
209
|
+
for (const block of blocks(markdown)) {
|
|
210
|
+
const blockHtml = renderHtml(block);
|
|
211
|
+
const blockText = renderPlain(block);
|
|
212
|
+
const candidate = html === "" ? blockHtml : `${html}\n${blockHtml}`;
|
|
213
|
+
if (points(candidate) <= limit) {
|
|
214
|
+
html = candidate;
|
|
215
|
+
text = text === "" ? blockText : `${text}\n${blockText}`;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
flush();
|
|
219
|
+
if (points(blockHtml) <= limit) {
|
|
220
|
+
html = blockHtml;
|
|
221
|
+
text = blockText;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
chunks.push(...forceCut(block, limit));
|
|
225
|
+
}
|
|
226
|
+
flush();
|
|
227
|
+
return chunks;
|
|
228
|
+
}
|