@octelium/console-agent 0.1.0-b-ca02.1.1
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 +267 -0
- package/README.md +207 -0
- package/apis/octelium.binpb +0 -0
- package/dist/agent/pi/auth.d.ts +32 -0
- package/dist/agent/pi/auth.js +279 -0
- package/dist/agent/pi/auth.js.map +1 -0
- package/dist/agent/pi/backend.d.ts +77 -0
- package/dist/agent/pi/backend.js +518 -0
- package/dist/agent/pi/backend.js.map +1 -0
- package/dist/agent/pi/mapper.d.ts +33 -0
- package/dist/agent/pi/mapper.js +386 -0
- package/dist/agent/pi/mapper.js.map +1 -0
- package/dist/agent/pi/model.d.ts +47 -0
- package/dist/agent/pi/model.js +199 -0
- package/dist/agent/pi/model.js.map +1 -0
- package/dist/agent/prompt.d.ts +22 -0
- package/dist/agent/prompt.js +75 -0
- package/dist/agent/prompt.js.map +1 -0
- package/dist/agent/resources.d.ts +13 -0
- package/dist/agent/resources.js +78 -0
- package/dist/agent/resources.js.map +1 -0
- package/dist/agent/tools/builtin.d.ts +13 -0
- package/dist/agent/tools/builtin.js +80 -0
- package/dist/agent/tools/builtin.js.map +1 -0
- package/dist/agent/tools/octelium.d.ts +28 -0
- package/dist/agent/tools/octelium.js +236 -0
- package/dist/agent/tools/octelium.js.map +1 -0
- package/dist/agent/tools/present.d.ts +61 -0
- package/dist/agent/tools/present.js +273 -0
- package/dist/agent/tools/present.js.map +1 -0
- package/dist/agent/tools/util.d.ts +19 -0
- package/dist/agent/tools/util.js +103 -0
- package/dist/agent/tools/util.js.map +1 -0
- package/dist/agent/tools/web.d.ts +24 -0
- package/dist/agent/tools/web.js +237 -0
- package/dist/agent/tools/web.js.map +1 -0
- package/dist/agent/types.d.ts +60 -0
- package/dist/agent/types.js +2 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/app.d.ts +36 -0
- package/dist/app.js +126 -0
- package/dist/app.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +249 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +159 -0
- package/dist/config.js +251 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +18 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +11 -0
- package/dist/log.js +41 -0
- package/dist/log.js.map +1 -0
- package/dist/octelium/catalog.d.ts +61 -0
- package/dist/octelium/catalog.js +595 -0
- package/dist/octelium/catalog.js.map +1 -0
- package/dist/octelium/client.d.ts +53 -0
- package/dist/octelium/client.js +201 -0
- package/dist/octelium/client.js.map +1 -0
- package/dist/octelium/search.d.ts +24 -0
- package/dist/octelium/search.js +211 -0
- package/dist/octelium/search.js.map +1 -0
- package/dist/protocol/index.d.ts +432 -0
- package/dist/protocol/index.js +44 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/runs/builder.d.ts +17 -0
- package/dist/runs/builder.js +81 -0
- package/dist/runs/builder.js.map +1 -0
- package/dist/runs/manager.d.ts +52 -0
- package/dist/runs/manager.js +536 -0
- package/dist/runs/manager.js.map +1 -0
- package/dist/server/http.d.ts +9 -0
- package/dist/server/http.js +100 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/server.d.ts +48 -0
- package/dist/server/server.js +483 -0
- package/dist/server/server.js.map +1 -0
- package/dist/skills.d.ts +4 -0
- package/dist/skills.js +69 -0
- package/dist/skills.js.map +1 -0
- package/dist/store/conversations.d.ts +26 -0
- package/dist/store/conversations.js +183 -0
- package/dist/store/conversations.js.map +1 -0
- package/dist/store/files.d.ts +27 -0
- package/dist/store/files.js +161 -0
- package/dist/store/files.js.map +1 -0
- package/dist/store/settings.d.ts +14 -0
- package/dist/store/settings.js +48 -0
- package/dist/store/settings.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +11 -0
- package/dist/version.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Conversation, Message } from "../protocol/index.ts";
|
|
2
|
+
export declare const isValidID: (id: string) => boolean;
|
|
3
|
+
export declare const newID: () => string;
|
|
4
|
+
export declare const writeFileAtomic: (filePath: string, data: string) => void;
|
|
5
|
+
export declare class ConversationStore {
|
|
6
|
+
readonly dir: string;
|
|
7
|
+
private conversations;
|
|
8
|
+
constructor(dir: string);
|
|
9
|
+
init(): Message[];
|
|
10
|
+
private conversationDir;
|
|
11
|
+
sessionDir(id: string): string;
|
|
12
|
+
resultsDir(id: string): string;
|
|
13
|
+
private save;
|
|
14
|
+
list(): Conversation[];
|
|
15
|
+
get(id: string): Conversation | undefined;
|
|
16
|
+
getSessionFile(id: string): string | undefined;
|
|
17
|
+
setSessionFile(id: string, sessionFile: string | undefined): void;
|
|
18
|
+
create(title?: string): Conversation;
|
|
19
|
+
update(id: string, patch: Partial<Pick<Conversation, "title" | "activeRunId">>): Conversation | undefined;
|
|
20
|
+
delete(id: string): boolean;
|
|
21
|
+
getMessages(id: string): Message[];
|
|
22
|
+
appendMessage(id: string, message: Message): void;
|
|
23
|
+
savePending(id: string, message: Message): void;
|
|
24
|
+
readPending(id: string): Message | undefined;
|
|
25
|
+
clearPending(id: string): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
export const isValidID = (id) => /^[A-Za-z0-9_-]{1,64}$/.test(id);
|
|
5
|
+
export const newID = () => crypto.randomUUID();
|
|
6
|
+
export const writeFileAtomic = (filePath, data) => {
|
|
7
|
+
const tmp = `${filePath}.${process.pid}.${crypto.randomBytes(4).toString("hex")}.tmp`;
|
|
8
|
+
fs.writeFileSync(tmp, data, { mode: 0o600 });
|
|
9
|
+
fs.renameSync(tmp, filePath);
|
|
10
|
+
};
|
|
11
|
+
const toConversation = (stored) => {
|
|
12
|
+
const { sessionFile: _, ...ret } = stored;
|
|
13
|
+
return ret;
|
|
14
|
+
};
|
|
15
|
+
export class ConversationStore {
|
|
16
|
+
dir;
|
|
17
|
+
conversations = new Map();
|
|
18
|
+
constructor(dir) {
|
|
19
|
+
this.dir = dir;
|
|
20
|
+
}
|
|
21
|
+
init() {
|
|
22
|
+
fs.mkdirSync(this.dir, { recursive: true, mode: 0o700 });
|
|
23
|
+
const recovered = [];
|
|
24
|
+
for (const entry of fs.readdirSync(this.dir, { withFileTypes: true })) {
|
|
25
|
+
if (!entry.isDirectory() || !isValidID(entry.name)) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const metaPath = path.join(this.dir, entry.name, "conversation.json");
|
|
29
|
+
let stored;
|
|
30
|
+
try {
|
|
31
|
+
stored = JSON.parse(fs.readFileSync(metaPath, "utf8"));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
this.conversations.set(stored.id, stored);
|
|
37
|
+
const pending = this.readPending(stored.id);
|
|
38
|
+
if (pending) {
|
|
39
|
+
const message = {
|
|
40
|
+
...pending,
|
|
41
|
+
status: "interrupted",
|
|
42
|
+
completedAt: pending.completedAt ?? new Date().toISOString(),
|
|
43
|
+
};
|
|
44
|
+
this.appendMessage(stored.id, message);
|
|
45
|
+
this.clearPending(stored.id);
|
|
46
|
+
recovered.push(message);
|
|
47
|
+
}
|
|
48
|
+
if (stored.activeRunId) {
|
|
49
|
+
this.update(stored.id, { activeRunId: undefined });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return recovered;
|
|
53
|
+
}
|
|
54
|
+
conversationDir(id) {
|
|
55
|
+
return path.join(this.dir, id);
|
|
56
|
+
}
|
|
57
|
+
sessionDir(id) {
|
|
58
|
+
return path.join(this.conversationDir(id), "session");
|
|
59
|
+
}
|
|
60
|
+
resultsDir(id) {
|
|
61
|
+
return path.join(this.conversationDir(id), "results");
|
|
62
|
+
}
|
|
63
|
+
save(stored) {
|
|
64
|
+
writeFileAtomic(path.join(this.conversationDir(stored.id), "conversation.json"), JSON.stringify(stored, null, 2));
|
|
65
|
+
}
|
|
66
|
+
list() {
|
|
67
|
+
return [...this.conversations.values()]
|
|
68
|
+
.map(toConversation)
|
|
69
|
+
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
70
|
+
}
|
|
71
|
+
get(id) {
|
|
72
|
+
const stored = this.conversations.get(id);
|
|
73
|
+
return stored ? toConversation(stored) : undefined;
|
|
74
|
+
}
|
|
75
|
+
getSessionFile(id) {
|
|
76
|
+
return this.conversations.get(id)?.sessionFile;
|
|
77
|
+
}
|
|
78
|
+
setSessionFile(id, sessionFile) {
|
|
79
|
+
const stored = this.conversations.get(id);
|
|
80
|
+
if (!stored || stored.sessionFile === sessionFile) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
stored.sessionFile = sessionFile;
|
|
84
|
+
this.save(stored);
|
|
85
|
+
}
|
|
86
|
+
create(title) {
|
|
87
|
+
const now = new Date().toISOString();
|
|
88
|
+
const stored = {
|
|
89
|
+
id: newID(),
|
|
90
|
+
title: title?.trim() || "New conversation",
|
|
91
|
+
createdAt: now,
|
|
92
|
+
updatedAt: now,
|
|
93
|
+
messageCount: 0,
|
|
94
|
+
};
|
|
95
|
+
fs.mkdirSync(this.conversationDir(stored.id), {
|
|
96
|
+
recursive: true,
|
|
97
|
+
mode: 0o700,
|
|
98
|
+
});
|
|
99
|
+
this.save(stored);
|
|
100
|
+
this.conversations.set(stored.id, stored);
|
|
101
|
+
return toConversation(stored);
|
|
102
|
+
}
|
|
103
|
+
update(id, patch) {
|
|
104
|
+
const stored = this.conversations.get(id);
|
|
105
|
+
if (!stored) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
if (patch.title !== undefined) {
|
|
109
|
+
stored.title = patch.title.trim() || stored.title;
|
|
110
|
+
stored.updatedAt = new Date().toISOString();
|
|
111
|
+
}
|
|
112
|
+
if ("activeRunId" in patch) {
|
|
113
|
+
if (patch.activeRunId) {
|
|
114
|
+
stored.activeRunId = patch.activeRunId;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
delete stored.activeRunId;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.save(stored);
|
|
121
|
+
return toConversation(stored);
|
|
122
|
+
}
|
|
123
|
+
delete(id) {
|
|
124
|
+
if (!this.conversations.has(id)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
this.conversations.delete(id);
|
|
128
|
+
fs.rmSync(this.conversationDir(id), { recursive: true, force: true });
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
getMessages(id) {
|
|
132
|
+
let raw;
|
|
133
|
+
try {
|
|
134
|
+
raw = fs.readFileSync(path.join(this.conversationDir(id), "messages.jsonl"), "utf8");
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
const ret = [];
|
|
140
|
+
for (const line of raw.split("\n")) {
|
|
141
|
+
if (line.trim() === "") {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
ret.push(JSON.parse(line));
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return ret;
|
|
152
|
+
}
|
|
153
|
+
appendMessage(id, message) {
|
|
154
|
+
const stored = this.conversations.get(id);
|
|
155
|
+
if (!stored) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
fs.appendFileSync(path.join(this.conversationDir(id), "messages.jsonl"), `${JSON.stringify(message)}\n`, { mode: 0o600 });
|
|
159
|
+
stored.messageCount++;
|
|
160
|
+
stored.updatedAt = new Date().toISOString();
|
|
161
|
+
this.save(stored);
|
|
162
|
+
}
|
|
163
|
+
savePending(id, message) {
|
|
164
|
+
if (!this.conversations.has(id)) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
writeFileAtomic(path.join(this.conversationDir(id), "pending.json"), JSON.stringify(message));
|
|
168
|
+
}
|
|
169
|
+
readPending(id) {
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(fs.readFileSync(path.join(this.conversationDir(id), "pending.json"), "utf8"));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
clearPending(id) {
|
|
178
|
+
fs.rmSync(path.join(this.conversationDir(id), "pending.json"), {
|
|
179
|
+
force: true,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=conversations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../src/store/conversations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAU,EAAW,EAAE,CAC/C,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,KAAK,GAAG,GAAW,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;AAEvD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,IAAY,EAAE,EAAE;IAChE,MAAM,GAAG,GAAG,GAAG,QAAQ,IAAI,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC;IACtF,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7C,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,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AC;QACtB,MAAM,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC5C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IAED,WAAW,CAAC,EAAU,EAAE,OAAgB;QACtC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QACD,eAAe,CACb,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,EACnD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CACxB,CAAC;IACJ,CAAC;IAED,WAAW,CAAC,EAAU;QACpB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CACf,EAAE,CAAC,YAAY,CACb,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,EACnD,MAAM,CACP,CACF,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,YAAY,CAAC,EAAU;QACrB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,EAAE;YAC7D,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Readable } from "node:stream";
|
|
2
|
+
import { type ArtifactInfo, type FileInfo } from "../protocol/index.ts";
|
|
3
|
+
export declare const guessMimeType: (name: string) => string;
|
|
4
|
+
export declare const sanitizeFileName: (name: string) => string;
|
|
5
|
+
export declare class FileTooLargeError extends Error {
|
|
6
|
+
}
|
|
7
|
+
export interface StoredArtifact {
|
|
8
|
+
info: ArtifactInfo;
|
|
9
|
+
filePath: string;
|
|
10
|
+
conversationId?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class FileStore {
|
|
13
|
+
readonly uploadsDir: string;
|
|
14
|
+
readonly artifactsDir: string;
|
|
15
|
+
constructor(dataDir: string);
|
|
16
|
+
init(): void;
|
|
17
|
+
saveUpload(name: string, mimeType: string | undefined, source: Readable, maxBytes: number): Promise<FileInfo>;
|
|
18
|
+
getUpload(id: string): FileInfo | undefined;
|
|
19
|
+
publishArtifact(sourcePath: string, opts?: {
|
|
20
|
+
name?: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
mimeType?: string;
|
|
24
|
+
conversationId?: string;
|
|
25
|
+
}): ArtifactInfo;
|
|
26
|
+
getArtifact(id: string): StoredArtifact | undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { pipeline } from "node:stream/promises";
|
|
4
|
+
import { Transform } from "node:stream";
|
|
5
|
+
import { API_PREFIX, } from "../protocol/index.js";
|
|
6
|
+
import { isValidID, newID, writeFileAtomic } from "./conversations.js";
|
|
7
|
+
const mimeTypes = {
|
|
8
|
+
".txt": "text/plain",
|
|
9
|
+
".log": "text/plain",
|
|
10
|
+
".md": "text/markdown",
|
|
11
|
+
".csv": "text/csv",
|
|
12
|
+
".tsv": "text/tab-separated-values",
|
|
13
|
+
".json": "application/json",
|
|
14
|
+
".jsonl": "application/x-ndjson",
|
|
15
|
+
".ndjson": "application/x-ndjson",
|
|
16
|
+
".yaml": "application/yaml",
|
|
17
|
+
".yml": "application/yaml",
|
|
18
|
+
".xml": "application/xml",
|
|
19
|
+
".html": "text/html",
|
|
20
|
+
".htm": "text/html",
|
|
21
|
+
".css": "text/css",
|
|
22
|
+
".js": "text/javascript",
|
|
23
|
+
".ts": "text/plain",
|
|
24
|
+
".py": "text/x-python",
|
|
25
|
+
".go": "text/plain",
|
|
26
|
+
".sh": "text/x-shellscript",
|
|
27
|
+
".sql": "application/sql",
|
|
28
|
+
".diff": "text/x-diff",
|
|
29
|
+
".patch": "text/x-diff",
|
|
30
|
+
".png": "image/png",
|
|
31
|
+
".jpg": "image/jpeg",
|
|
32
|
+
".jpeg": "image/jpeg",
|
|
33
|
+
".gif": "image/gif",
|
|
34
|
+
".webp": "image/webp",
|
|
35
|
+
".svg": "image/svg+xml",
|
|
36
|
+
".pdf": "application/pdf",
|
|
37
|
+
".zip": "application/zip",
|
|
38
|
+
".gz": "application/gzip",
|
|
39
|
+
".tgz": "application/gzip",
|
|
40
|
+
".tar": "application/x-tar",
|
|
41
|
+
".parquet": "application/vnd.apache.parquet",
|
|
42
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
43
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
44
|
+
};
|
|
45
|
+
export const guessMimeType = (name) => mimeTypes[path.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
46
|
+
export const sanitizeFileName = (name) => {
|
|
47
|
+
const base = path.basename(name.replace(/\\/g, "/")).normalize("NFC");
|
|
48
|
+
const cleaned = base
|
|
49
|
+
.replace(/[\u0000-\u001f\u007f<>:"/\\|?*]/g, "_")
|
|
50
|
+
.replace(/^\.+/, "_")
|
|
51
|
+
.slice(0, 200)
|
|
52
|
+
.trim();
|
|
53
|
+
return cleaned === "" ? "file" : cleaned;
|
|
54
|
+
};
|
|
55
|
+
export class FileTooLargeError extends Error {
|
|
56
|
+
}
|
|
57
|
+
export class FileStore {
|
|
58
|
+
uploadsDir;
|
|
59
|
+
artifactsDir;
|
|
60
|
+
constructor(dataDir) {
|
|
61
|
+
this.uploadsDir = path.join(dataDir, "uploads");
|
|
62
|
+
this.artifactsDir = path.join(dataDir, "artifacts");
|
|
63
|
+
}
|
|
64
|
+
init() {
|
|
65
|
+
fs.mkdirSync(this.uploadsDir, { recursive: true, mode: 0o700 });
|
|
66
|
+
fs.mkdirSync(this.artifactsDir, { recursive: true, mode: 0o700 });
|
|
67
|
+
}
|
|
68
|
+
async saveUpload(name, mimeType, source, maxBytes) {
|
|
69
|
+
const id = newID();
|
|
70
|
+
const fileName = sanitizeFileName(name);
|
|
71
|
+
const dir = path.join(this.uploadsDir, id);
|
|
72
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
73
|
+
const filePath = path.join(dir, fileName);
|
|
74
|
+
let size = 0;
|
|
75
|
+
const counter = new Transform({
|
|
76
|
+
transform(chunk, _encoding, callback) {
|
|
77
|
+
size += chunk.length;
|
|
78
|
+
if (size > maxBytes) {
|
|
79
|
+
callback(new FileTooLargeError(`The file exceeds the maximum allowed size of ${maxBytes} bytes`));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
callback(null, chunk);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
await pipeline(source, counter, fs.createWriteStream(filePath, { mode: 0o600 }));
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
const info = {
|
|
93
|
+
id,
|
|
94
|
+
name: fileName,
|
|
95
|
+
mimeType: mimeType && mimeType !== "application/octet-stream"
|
|
96
|
+
? mimeType
|
|
97
|
+
: guessMimeType(fileName),
|
|
98
|
+
size,
|
|
99
|
+
path: filePath,
|
|
100
|
+
createdAt: new Date().toISOString(),
|
|
101
|
+
};
|
|
102
|
+
writeFileAtomic(path.join(dir, ".meta.json"), JSON.stringify(info));
|
|
103
|
+
return info;
|
|
104
|
+
}
|
|
105
|
+
getUpload(id) {
|
|
106
|
+
if (!isValidID(id)) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
return JSON.parse(fs.readFileSync(path.join(this.uploadsDir, id, ".meta.json"), "utf8"));
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
publishArtifact(sourcePath, opts = {}) {
|
|
117
|
+
const stat = fs.statSync(sourcePath);
|
|
118
|
+
if (!stat.isFile()) {
|
|
119
|
+
throw new Error(`Not a regular file: ${sourcePath}`);
|
|
120
|
+
}
|
|
121
|
+
const id = newID();
|
|
122
|
+
const name = sanitizeFileName(opts.name ?? path.basename(sourcePath));
|
|
123
|
+
const dir = path.join(this.artifactsDir, id);
|
|
124
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
125
|
+
const filePath = path.join(dir, name);
|
|
126
|
+
fs.copyFileSync(sourcePath, filePath);
|
|
127
|
+
const info = {
|
|
128
|
+
id,
|
|
129
|
+
name,
|
|
130
|
+
mimeType: opts.mimeType ?? guessMimeType(name),
|
|
131
|
+
size: stat.size,
|
|
132
|
+
title: opts.title,
|
|
133
|
+
description: opts.description,
|
|
134
|
+
createdAt: new Date().toISOString(),
|
|
135
|
+
url: `${API_PREFIX}/artifacts/${id}/content`,
|
|
136
|
+
};
|
|
137
|
+
const stored = {
|
|
138
|
+
info,
|
|
139
|
+
filePath,
|
|
140
|
+
conversationId: opts.conversationId,
|
|
141
|
+
};
|
|
142
|
+
writeFileAtomic(path.join(dir, ".meta.json"), JSON.stringify(stored));
|
|
143
|
+
return info;
|
|
144
|
+
}
|
|
145
|
+
getArtifact(id) {
|
|
146
|
+
if (!isValidID(id)) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const stored = JSON.parse(fs.readFileSync(path.join(this.artifactsDir, id, ".meta.json"), "utf8"));
|
|
151
|
+
if (!fs.existsSync(stored.filePath)) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
return stored;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
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AE,MAAM,CAAC,CACxE,CAAC;YACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACpC,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface AgentSettings {
|
|
2
|
+
model?: {
|
|
3
|
+
provider: string;
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
thinkingLevel?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class SettingsStore {
|
|
9
|
+
private filePath;
|
|
10
|
+
constructor(dataDir: string);
|
|
11
|
+
read(): AgentSettings;
|
|
12
|
+
write(settings: AgentSettings): void;
|
|
13
|
+
update(patch: Partial<AgentSettings>): AgentSettings;
|
|
14
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { writeFileAtomic } from "./conversations.js";
|
|
4
|
+
const isObject = (arg) => typeof arg === "object" && arg !== null && !Array.isArray(arg);
|
|
5
|
+
export class SettingsStore {
|
|
6
|
+
filePath;
|
|
7
|
+
constructor(dataDir) {
|
|
8
|
+
this.filePath = path.join(dataDir, "settings.json");
|
|
9
|
+
}
|
|
10
|
+
read() {
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = JSON.parse(fs.readFileSync(this.filePath, "utf8"));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
if (!isObject(parsed)) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
const ret = {};
|
|
22
|
+
const model = parsed.model;
|
|
23
|
+
if (isObject(model) &&
|
|
24
|
+
typeof model.provider === "string" &&
|
|
25
|
+
typeof model.id === "string") {
|
|
26
|
+
ret.model = { provider: model.provider, id: model.id };
|
|
27
|
+
}
|
|
28
|
+
if (typeof parsed.thinkingLevel === "string") {
|
|
29
|
+
ret.thinkingLevel = parsed.thinkingLevel;
|
|
30
|
+
}
|
|
31
|
+
return ret;
|
|
32
|
+
}
|
|
33
|
+
write(settings) {
|
|
34
|
+
fs.mkdirSync(path.dirname(this.filePath), { recursive: true, mode: 0o700 });
|
|
35
|
+
writeFileAtomic(this.filePath, JSON.stringify(settings, null, 2));
|
|
36
|
+
}
|
|
37
|
+
update(patch) {
|
|
38
|
+
const ret = { ...this.read(), ...patch };
|
|
39
|
+
for (const key of Object.keys(ret)) {
|
|
40
|
+
if (ret[key] === undefined) {
|
|
41
|
+
delete ret[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.write(ret);
|
|
45
|
+
return ret;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/store/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAUrD,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAkC,EAAE,CAChE,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAEjE,MAAM,OAAO,aAAa;IAChB,QAAQ,CAAS;IAEzB,YAAY,OAAe;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACtD,CAAC;IAED,IAAI;QACF,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,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AC,GAAG,CAA4B,EAAE,CAAC;YAC9D,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChB,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getVersion: () => string;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
export const getVersion = () => {
|
|
3
|
+
try {
|
|
4
|
+
const pkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
5
|
+
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return "unknown";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAW,EAAE;IACrC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CACpB,EAAE,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CACrE,CAAC;QACF,OAAO,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octelium/console-agent",
|
|
3
|
+
"version": "0.1.0-b-ca02.1.1",
|
|
4
|
+
"description": "The Octelium web console AI agent that runs inside a Cordium Workspace",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/octelium/octelium-ee.git",
|
|
10
|
+
"directory": "cluster/console-agent"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"octelium-console-agent": "./dist/cli.js"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./protocol": {
|
|
21
|
+
"types": "./dist/protocol/index.d.ts",
|
|
22
|
+
"default": "./dist/protocol/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"apis",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.19.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dev": "node src/cli.ts serve",
|
|
35
|
+
"start": "node dist/cli.js serve",
|
|
36
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"test": "node --test \"src/**/*.test.ts\"",
|
|
39
|
+
"test:publish": "node --test scripts/publish-version.test.mjs",
|
|
40
|
+
"fmt": "prettier --write src",
|
|
41
|
+
"protoc": "mkdir -p ./apis && protoc --proto_path ../../ --include_imports --include_source_info --descriptor_set_out ./apis/octelium.binpb apis/protobuf/main/corev1/corev1.proto apis/protobuf/main/userv1/userv1.proto apis/protobuf/main/enterprisev1/enterprisev1.proto apis/protobuf/main/accessv1/accessv1.proto apis/protobuf/main/cordiumv1/cordiumv1.proto apis/protobuf/main/visibilityv1/visibilityv1.proto apis/protobuf/main/visibilityv1/core/vcorev1.proto apis/protobuf/main/visibilityv1/enterprise/venterprisev1.proto apis/protobuf/main/visibilityv1/access/vaccessv1.proto apis/protobuf/main/visibilityv1/cordium/vcordiumv1.proto apis/protobuf/main/visibilityv1/metrics/vmetricsv1.proto apis/protobuf/main/visibilityv1/llm/vllmv1.proto"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@bufbuild/protobuf": "2.16.0",
|
|
45
|
+
"@connectrpc/connect": "2.2.0",
|
|
46
|
+
"@connectrpc/connect-node": "2.2.0",
|
|
47
|
+
"@earendil-works/pi-ai": "1.0.1",
|
|
48
|
+
"@earendil-works/pi-coding-agent": "1.0.1",
|
|
49
|
+
"typebox": "1.3.27"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^26.6.4",
|
|
53
|
+
"prettier": "^3.9.9",
|
|
54
|
+
"semver": "7.8.5",
|
|
55
|
+
"typescript": "~6.0.3"
|
|
56
|
+
}
|
|
57
|
+
}
|