@ouro.bot/cli 0.1.0-alpha.289 → 0.1.0-alpha.290
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 +4 -2
- package/changelog.json +7 -0
- package/dist/arc/packets.js +203 -0
- package/dist/heart/attachments/image-normalize.js +194 -0
- package/dist/heart/attachments/materialize.js +230 -0
- package/dist/heart/attachments/render.js +29 -0
- package/dist/heart/attachments/store.js +103 -0
- package/dist/heart/attachments/types.js +138 -0
- package/dist/heart/core.js +187 -162
- package/dist/heart/tool-description.js +3 -3
- package/dist/heart/tool-friction.js +55 -0
- package/dist/mind/prompt.js +27 -16
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +316 -0
- package/dist/repertoire/tools-base.js +2 -0
- package/dist/repertoire/tools-bluebubbles.js +0 -107
- package/dist/repertoire/tools-flow.js +48 -5
- package/dist/repertoire/tools.js +2 -10
- package/dist/senses/attention-queue.js +20 -1
- package/dist/senses/bluebubbles/attachment-download.js +137 -0
- package/dist/senses/bluebubbles/media.js +36 -101
- package/dist/senses/bluebubbles/model.js +9 -11
- package/dist/senses/cli/image-paste.js +79 -3
- package/dist/senses/inner-dialog.js +9 -0
- package/dist/senses/shared-turn.js +3 -7
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderAttachmentBlock = renderAttachmentBlock;
|
|
4
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
5
|
+
function formatBytes(byteCount) {
|
|
6
|
+
if (typeof byteCount !== "number" || !Number.isFinite(byteCount) || byteCount < 0) {
|
|
7
|
+
return "unknown size";
|
|
8
|
+
}
|
|
9
|
+
if (byteCount >= 1024 * 1024) {
|
|
10
|
+
return `${(byteCount / (1024 * 1024)).toFixed(1)} MB`;
|
|
11
|
+
}
|
|
12
|
+
if (byteCount >= 1024) {
|
|
13
|
+
return `${Math.round(byteCount / 1024)} KB`;
|
|
14
|
+
}
|
|
15
|
+
return `${byteCount} B`;
|
|
16
|
+
}
|
|
17
|
+
function renderAttachmentBlock(attachments) {
|
|
18
|
+
if (attachments.length === 0)
|
|
19
|
+
return "";
|
|
20
|
+
const body = attachments.map((attachment) => `- ${attachment.id} | ${attachment.kind} | ${attachment.displayName} | ${attachment.mimeType ?? "unknown mime"} | ${formatBytes(attachment.byteCount)}`);
|
|
21
|
+
const rendered = ["[attachments]", ...body].join("\n");
|
|
22
|
+
(0, runtime_1.emitNervesEvent)({
|
|
23
|
+
component: "engine",
|
|
24
|
+
event: "engine.attachment_block_rendered",
|
|
25
|
+
message: "attachment transcript block rendered",
|
|
26
|
+
meta: { count: attachments.length },
|
|
27
|
+
});
|
|
28
|
+
return rendered;
|
|
29
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.MAX_RECENT_ATTACHMENTS = void 0;
|
|
37
|
+
exports.getRecentAttachmentsPath = getRecentAttachmentsPath;
|
|
38
|
+
exports.readRecentAttachments = readRecentAttachments;
|
|
39
|
+
exports.rememberRecentAttachment = rememberRecentAttachment;
|
|
40
|
+
exports.getRecentAttachment = getRecentAttachment;
|
|
41
|
+
exports.listRecentAttachments = listRecentAttachments;
|
|
42
|
+
const fs = __importStar(require("node:fs"));
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
45
|
+
const identity_1 = require("../identity");
|
|
46
|
+
exports.MAX_RECENT_ATTACHMENTS = 100;
|
|
47
|
+
function getRecentAttachmentsPath(agentName, agentRoot = (0, identity_1.getAgentRoot)(agentName)) {
|
|
48
|
+
return path.join(agentRoot, "state", "attachments", "recent.json");
|
|
49
|
+
}
|
|
50
|
+
function readRecentAttachments(agentName, agentRoot = (0, identity_1.getAgentRoot)(agentName)) {
|
|
51
|
+
const targetPath = getRecentAttachmentsPath(agentName, agentRoot);
|
|
52
|
+
if (!fs.existsSync(targetPath)) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(fs.readFileSync(targetPath, "utf-8"));
|
|
57
|
+
if (!Array.isArray(parsed)) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
return parsed;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
(0, runtime_1.emitNervesEvent)({
|
|
64
|
+
level: "warn",
|
|
65
|
+
component: "engine",
|
|
66
|
+
event: "engine.attachment_store_read_error",
|
|
67
|
+
message: "failed to read recent attachments store",
|
|
68
|
+
meta: {
|
|
69
|
+
path: targetPath,
|
|
70
|
+
reason: String(error),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function writeRecentAttachments(agentName, agentRoot, attachments) {
|
|
77
|
+
const targetPath = getRecentAttachmentsPath(agentName, agentRoot);
|
|
78
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
79
|
+
fs.writeFileSync(targetPath, JSON.stringify(attachments, null, 2), "utf-8");
|
|
80
|
+
}
|
|
81
|
+
function rememberRecentAttachment(agentName, attachment, agentRoot = (0, identity_1.getAgentRoot)(agentName)) {
|
|
82
|
+
const deduped = readRecentAttachments(agentName, agentRoot).filter((entry) => entry.id !== attachment.id);
|
|
83
|
+
const updated = [attachment, ...deduped]
|
|
84
|
+
.sort((a, b) => b.lastSeenAt - a.lastSeenAt)
|
|
85
|
+
.slice(0, exports.MAX_RECENT_ATTACHMENTS);
|
|
86
|
+
writeRecentAttachments(agentName, agentRoot, updated);
|
|
87
|
+
(0, runtime_1.emitNervesEvent)({
|
|
88
|
+
component: "engine",
|
|
89
|
+
event: "engine.attachment_store_updated",
|
|
90
|
+
message: "recent attachment stored",
|
|
91
|
+
meta: { attachmentId: attachment.id, source: attachment.source, kind: attachment.kind },
|
|
92
|
+
});
|
|
93
|
+
return attachment;
|
|
94
|
+
}
|
|
95
|
+
function getRecentAttachment(agentName, attachmentId, agentRoot = (0, identity_1.getAgentRoot)(agentName)) {
|
|
96
|
+
return readRecentAttachments(agentName, agentRoot).find((entry) => entry.id === attachmentId) ?? null;
|
|
97
|
+
}
|
|
98
|
+
function listRecentAttachments(agentName, options = {}, agentRoot = (0, identity_1.getAgentRoot)(agentName)) {
|
|
99
|
+
const limit = Math.max(1, options.limit ?? exports.MAX_RECENT_ATTACHMENTS);
|
|
100
|
+
return readRecentAttachments(agentName, agentRoot)
|
|
101
|
+
.filter((entry) => !options.kind || entry.kind === options.kind)
|
|
102
|
+
.slice(0, limit);
|
|
103
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.buildAttachmentId = buildAttachmentId;
|
|
37
|
+
exports.classifyAttachmentKind = classifyAttachmentKind;
|
|
38
|
+
exports.buildBlueBubblesAttachmentRecord = buildBlueBubblesAttachmentRecord;
|
|
39
|
+
exports.buildCliLocalFileAttachmentRecord = buildCliLocalFileAttachmentRecord;
|
|
40
|
+
const node_crypto_1 = require("node:crypto");
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
+
function buildAttachmentId(source, stableId) {
|
|
44
|
+
(0, runtime_1.emitNervesEvent)({
|
|
45
|
+
component: "engine",
|
|
46
|
+
event: "engine.attachment_id_built",
|
|
47
|
+
message: "attachment record helper invoked",
|
|
48
|
+
meta: { source },
|
|
49
|
+
});
|
|
50
|
+
return `attachment:${source}:${stableId}`;
|
|
51
|
+
}
|
|
52
|
+
function classifyAttachmentKind(mimeType, displayName) {
|
|
53
|
+
const normalizedMime = mimeType?.trim().toLowerCase() ?? "";
|
|
54
|
+
const extension = path.extname(displayName ?? "").toLowerCase();
|
|
55
|
+
if (normalizedMime.startsWith("image/"))
|
|
56
|
+
return "image";
|
|
57
|
+
if (normalizedMime.startsWith("audio/"))
|
|
58
|
+
return "audio";
|
|
59
|
+
if (normalizedMime.startsWith("text/")
|
|
60
|
+
|| normalizedMime === "application/pdf"
|
|
61
|
+
|| extension === ".pdf"
|
|
62
|
+
|| extension === ".txt"
|
|
63
|
+
|| extension === ".md"
|
|
64
|
+
|| extension === ".doc"
|
|
65
|
+
|| extension === ".docx") {
|
|
66
|
+
return "document";
|
|
67
|
+
}
|
|
68
|
+
if (!normalizedMime && !displayName)
|
|
69
|
+
return "unknown";
|
|
70
|
+
return "binary";
|
|
71
|
+
}
|
|
72
|
+
function stableCliLocalFileId(filePath) {
|
|
73
|
+
return (0, node_crypto_1.createHash)("sha1").update(path.resolve(filePath)).digest("hex").slice(0, 16);
|
|
74
|
+
}
|
|
75
|
+
function buildBlueBubblesAttachmentRecord(summary, now = Date.now(), options = {}) {
|
|
76
|
+
const guid = summary.guid?.trim();
|
|
77
|
+
if (!guid) {
|
|
78
|
+
throw new Error("BlueBubbles attachment guid is required");
|
|
79
|
+
}
|
|
80
|
+
const displayName = summary.transferName?.trim() || guid;
|
|
81
|
+
const mimeType = options.mimeType?.trim().toLowerCase() || summary.mimeType?.trim().toLowerCase() || undefined;
|
|
82
|
+
const record = {
|
|
83
|
+
id: buildAttachmentId("bluebubbles", guid),
|
|
84
|
+
source: "bluebubbles",
|
|
85
|
+
sourceId: guid,
|
|
86
|
+
kind: classifyAttachmentKind(mimeType, displayName),
|
|
87
|
+
displayName,
|
|
88
|
+
mimeType,
|
|
89
|
+
byteCount: options.byteCount ?? summary.totalBytes,
|
|
90
|
+
createdAt: now,
|
|
91
|
+
lastSeenAt: now,
|
|
92
|
+
sourceData: {
|
|
93
|
+
...summary,
|
|
94
|
+
guid,
|
|
95
|
+
...(options.localPath ? { localPath: path.resolve(options.localPath) } : {}),
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
(0, runtime_1.emitNervesEvent)({
|
|
99
|
+
component: "engine",
|
|
100
|
+
event: "engine.attachment_record_built",
|
|
101
|
+
message: "attachment record helper invoked",
|
|
102
|
+
meta: {
|
|
103
|
+
source: "bluebubbles",
|
|
104
|
+
kind: record.kind,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
return record;
|
|
108
|
+
}
|
|
109
|
+
function buildCliLocalFileAttachmentRecord(input, now = Date.now()) {
|
|
110
|
+
const resolvedPath = path.resolve(input.path);
|
|
111
|
+
const displayName = input.displayName?.trim() || path.basename(resolvedPath);
|
|
112
|
+
const mimeType = input.mimeType?.trim().toLowerCase() || undefined;
|
|
113
|
+
const stableId = stableCliLocalFileId(resolvedPath);
|
|
114
|
+
const record = {
|
|
115
|
+
id: buildAttachmentId("cli-local-file", stableId),
|
|
116
|
+
source: "cli-local-file",
|
|
117
|
+
sourceId: stableId,
|
|
118
|
+
kind: classifyAttachmentKind(mimeType, displayName),
|
|
119
|
+
displayName,
|
|
120
|
+
mimeType,
|
|
121
|
+
byteCount: input.byteCount,
|
|
122
|
+
createdAt: now,
|
|
123
|
+
lastSeenAt: now,
|
|
124
|
+
sourceData: {
|
|
125
|
+
path: resolvedPath,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
(0, runtime_1.emitNervesEvent)({
|
|
129
|
+
component: "engine",
|
|
130
|
+
event: "engine.attachment_record_built",
|
|
131
|
+
message: "attachment record helper invoked",
|
|
132
|
+
meta: {
|
|
133
|
+
source: "cli-local-file",
|
|
134
|
+
kind: record.kind,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
return record;
|
|
138
|
+
}
|