@offerpilot/axiomruntime 0.0.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/README.md +185 -0
- package/dist/cli/commands/add.js +29 -0
- package/dist/cli/commands/context.js +29 -0
- package/dist/cli/commands/doctor.js +62 -0
- package/dist/cli/commands/edit.js +85 -0
- package/dist/cli/commands/help.js +16 -0
- package/dist/cli/commands/list.js +25 -0
- package/dist/cli/commands/log.js +63 -0
- package/dist/cli/commands/memory.js +241 -0
- package/dist/cli/commands/report.js +35 -0
- package/dist/cli/commands/session.js +74 -0
- package/dist/cli/commands/setup.js +86 -0
- package/dist/cli/commands/status.js +50 -0
- package/dist/cli/commands/telegram.js +701 -0
- package/dist/cli/commands/use.js +108 -0
- package/dist/cli/commands/version.js +12 -0
- package/dist/cli/index.js +276 -0
- package/dist/cli/output/table.js +22 -0
- package/dist/cli/prompts/prompt.js +37 -0
- package/dist/cli/registry.js +16 -0
- package/dist/core/config/cache-store.js +193 -0
- package/dist/core/config/json-store.js +114 -0
- package/dist/core/config/paths.js +85 -0
- package/dist/core/config/providers-store.js +89 -0
- package/dist/core/config/schema.js +60 -0
- package/dist/core/config/session-store.js +30 -0
- package/dist/core/config/usage-store.js +18 -0
- package/dist/core/context/context-service.js +186 -0
- package/dist/core/integrations/integration-state.js +105 -0
- package/dist/core/logs/log-service.js +56 -0
- package/dist/core/memory/embedding-check.js +121 -0
- package/dist/core/memory/memory-config.js +122 -0
- package/dist/core/models/model-discovery.js +430 -0
- package/dist/core/models/model-filter.js +13 -0
- package/dist/core/providers/provider-service.js +212 -0
- package/dist/core/reports/report-service.js +166 -0
- package/dist/core/runner/command-resolver.js +60 -0
- package/dist/core/runner/engine-registry.js +93 -0
- package/dist/core/runner/fallback.js +114 -0
- package/dist/core/runner/openai-usage-http.js +82 -0
- package/dist/core/runner/openai-usage-proxy.js +1 -0
- package/dist/core/runner/openai-usage-recording.js +172 -0
- package/dist/core/runner/openai-usage-responses.js +469 -0
- package/dist/core/runner/openai-usage-server.js +319 -0
- package/dist/core/runner/openai-usage-types.js +1 -0
- package/dist/core/runner/tool-runner.js +138 -0
- package/dist/core/sessions/session-service.js +47 -0
- package/dist/core/status/doctor-service.js +391 -0
- package/dist/core/status/status-service.js +60 -0
- package/dist/core/types.js +1 -0
- package/dist/core/usage/pricing.js +113 -0
- package/dist/core/usage/usage-service.js +30 -0
- package/dist/core/utils/is-record.js +3 -0
- package/dist/server/index.js +28 -0
- package/dist/server/runtime-server.js +430 -0
- package/dist/telegram/bot-registry.js +80 -0
- package/dist/telegram/bot.js +128 -0
- package/dist/telegram/config.js +235 -0
- package/dist/telegram/engine/claude-engine.js +240 -0
- package/dist/telegram/engine/codex-engine.js +437 -0
- package/dist/telegram/engine/engine-utils.js +67 -0
- package/dist/telegram/engine/process-utils.js +132 -0
- package/dist/telegram/engine/registry.js +31 -0
- package/dist/telegram/engine/types.js +1 -0
- package/dist/telegram/handler-registry.js +28 -0
- package/dist/telegram/handlers/callback.js +311 -0
- package/dist/telegram/handlers/command.js +272 -0
- package/dist/telegram/handlers/document.js +108 -0
- package/dist/telegram/handlers/memory.js +305 -0
- package/dist/telegram/handlers/message.js +701 -0
- package/dist/telegram/handlers/provider.js +332 -0
- package/dist/telegram/handlers/setup.js +527 -0
- package/dist/telegram/handlers/usage.js +124 -0
- package/dist/telegram/index.js +93 -0
- package/dist/telegram/interaction/approval.js +108 -0
- package/dist/telegram/interaction/command-menu.js +253 -0
- package/dist/telegram/interaction/formatter.js +487 -0
- package/dist/telegram/interaction/keyboards.js +145 -0
- package/dist/telegram/interaction/progress-reporter.js +160 -0
- package/dist/telegram/interaction/prompt-middleware.js +168 -0
- package/dist/telegram/interaction/result-store.js +41 -0
- package/dist/telegram/interaction/token-budget.js +21 -0
- package/dist/telegram/interaction/tool-name.js +41 -0
- package/dist/telegram/lifecycle-registry.js +47 -0
- package/dist/telegram/log.js +46 -0
- package/dist/telegram/memory/memory-inject.js +52 -0
- package/dist/telegram/memory/memory-service.js +413 -0
- package/dist/telegram/memory/memory-store.js +216 -0
- package/dist/telegram/memory/types.js +1 -0
- package/dist/telegram/network-retry.js +22 -0
- package/dist/telegram/network.js +53 -0
- package/dist/telegram/session/manager.js +229 -0
- package/dist/telegram/session/store.js +363 -0
- package/dist/telegram/session/types.js +1 -0
- package/dist/telegram/supervisor.js +57 -0
- package/dist/telegram/templates/messages.js +1 -0
- package/docs/README.md +98 -0
- package/docs/USAGE.html +853 -0
- package/package.json +57 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getLogPath } from "../config/paths.js";
|
|
4
|
+
export async function writeLog(input) {
|
|
5
|
+
const event = {
|
|
6
|
+
timestamp: new Date().toISOString(),
|
|
7
|
+
level: input.level ?? "info",
|
|
8
|
+
category: input.category,
|
|
9
|
+
action: input.action,
|
|
10
|
+
message: input.message,
|
|
11
|
+
metadata: input.metadata
|
|
12
|
+
};
|
|
13
|
+
try {
|
|
14
|
+
const filePath = getLogPath();
|
|
15
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
16
|
+
await fs.appendFile(filePath, `${JSON.stringify(event)}\n`, "utf8");
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Logging must never break the user command.
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export async function readRecentLogs(limit = 50) {
|
|
23
|
+
try {
|
|
24
|
+
const raw = await fs.readFile(getLogPath(), "utf8");
|
|
25
|
+
const events = raw
|
|
26
|
+
.split("\n")
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.map(parseLogLine)
|
|
29
|
+
.filter((event) => Boolean(event));
|
|
30
|
+
return events.slice(-limit);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error.code === "ENOENT") {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export async function ensureLogFile() {
|
|
40
|
+
const filePath = getLogPath();
|
|
41
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
42
|
+
await fs.appendFile(filePath, "", "utf8");
|
|
43
|
+
return filePath;
|
|
44
|
+
}
|
|
45
|
+
function parseLogLine(line) {
|
|
46
|
+
try {
|
|
47
|
+
const value = JSON.parse(line);
|
|
48
|
+
if (!value.timestamp || !value.level || !value.category || !value.action || !value.message) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { updateMemoryEmbeddingCheck } from "./memory-config.js";
|
|
2
|
+
export async function checkMemoryEmbeddingConfig(config, text = "ping", inputKind = "query") {
|
|
3
|
+
const checkedAt = new Date().toISOString();
|
|
4
|
+
try {
|
|
5
|
+
const response = await fetchWithTimeout(buildEmbeddingsUrl(config.baseUrl), {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
Accept: "application/json"
|
|
11
|
+
},
|
|
12
|
+
body: JSON.stringify(buildEmbeddingPayload(config, text, inputKind))
|
|
13
|
+
});
|
|
14
|
+
const raw = await response.text();
|
|
15
|
+
const json = parseJson(raw);
|
|
16
|
+
const embedding = readEmbedding(json);
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
return {
|
|
19
|
+
status: "error",
|
|
20
|
+
model: config.model,
|
|
21
|
+
dimensions: null,
|
|
22
|
+
checkedAt,
|
|
23
|
+
error: `POST embeddings failed with ${response.status} ${response.statusText}${extractErrorMessage(json)}`
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (!embedding) {
|
|
27
|
+
return {
|
|
28
|
+
status: "error",
|
|
29
|
+
model: config.model,
|
|
30
|
+
dimensions: null,
|
|
31
|
+
checkedAt,
|
|
32
|
+
error: "Embedding response did not include data[0].embedding."
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
status: "ok",
|
|
37
|
+
model: config.model,
|
|
38
|
+
dimensions: embedding.length,
|
|
39
|
+
checkedAt,
|
|
40
|
+
error: null
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return {
|
|
45
|
+
status: "error",
|
|
46
|
+
model: config.model,
|
|
47
|
+
dimensions: null,
|
|
48
|
+
checkedAt,
|
|
49
|
+
error: error instanceof Error ? error.message : String(error)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export async function checkAndRecordMemoryEmbeddingConfig(config, text, inputKind) {
|
|
54
|
+
const result = await checkMemoryEmbeddingConfig(config, text, inputKind);
|
|
55
|
+
await updateMemoryEmbeddingCheck({
|
|
56
|
+
dimensions: result.dimensions,
|
|
57
|
+
checkedAt: result.checkedAt,
|
|
58
|
+
error: result.error
|
|
59
|
+
});
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
function buildEmbeddingsUrl(baseUrl) {
|
|
63
|
+
const normalized = baseUrl.replace(/\/+$/, "");
|
|
64
|
+
return normalized.endsWith("/embeddings") ? normalized : `${normalized}/embeddings`;
|
|
65
|
+
}
|
|
66
|
+
function buildEmbeddingPayload(config, text, inputKind) {
|
|
67
|
+
const payload = {
|
|
68
|
+
model: config.model,
|
|
69
|
+
input: [text]
|
|
70
|
+
};
|
|
71
|
+
if (config.providerType === "jina") {
|
|
72
|
+
const task = inputKind === "query" ? config.queryTask : config.passageTask;
|
|
73
|
+
if (task)
|
|
74
|
+
payload.task = task;
|
|
75
|
+
}
|
|
76
|
+
return payload;
|
|
77
|
+
}
|
|
78
|
+
function readEmbedding(value) {
|
|
79
|
+
if (!value || typeof value !== "object")
|
|
80
|
+
return null;
|
|
81
|
+
const data = value.data;
|
|
82
|
+
if (!Array.isArray(data) || !data[0] || typeof data[0] !== "object")
|
|
83
|
+
return null;
|
|
84
|
+
const embedding = data[0].embedding;
|
|
85
|
+
if (!Array.isArray(embedding) || !embedding.length)
|
|
86
|
+
return null;
|
|
87
|
+
return embedding.every((item) => typeof item === "number") ? embedding : null;
|
|
88
|
+
}
|
|
89
|
+
function parseJson(raw) {
|
|
90
|
+
try {
|
|
91
|
+
return JSON.parse(raw);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function extractErrorMessage(value) {
|
|
98
|
+
if (!value || typeof value !== "object")
|
|
99
|
+
return "";
|
|
100
|
+
const data = value;
|
|
101
|
+
const error = data.error;
|
|
102
|
+
if (typeof error === "string")
|
|
103
|
+
return `: ${error}`;
|
|
104
|
+
if (error && typeof error === "object") {
|
|
105
|
+
const message = error.message;
|
|
106
|
+
if (typeof message === "string")
|
|
107
|
+
return `: ${message}`;
|
|
108
|
+
}
|
|
109
|
+
const message = data.message;
|
|
110
|
+
return typeof message === "string" ? `: ${message}` : "";
|
|
111
|
+
}
|
|
112
|
+
async function fetchWithTimeout(url, init, timeoutMs = 12_000) {
|
|
113
|
+
const controller = new AbortController();
|
|
114
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
115
|
+
try {
|
|
116
|
+
return await fetch(url, { ...init, signal: controller.signal });
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
clearTimeout(timeout);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { getMemoryConfigPath } from "../config/paths.js";
|
|
2
|
+
import { readJsonFile, updateJsonFile, writeJsonFile } from "../config/json-store.js";
|
|
3
|
+
import { readNumber, readOptionalString, readRecord, readString } from "../config/schema.js";
|
|
4
|
+
const DEFAULT_MEMORY_CONFIG = {
|
|
5
|
+
embedding: null
|
|
6
|
+
};
|
|
7
|
+
const VALID_PROVIDER_TYPES = new Set(["openai-compatible", "jina"]);
|
|
8
|
+
export async function readMemoryConfig() {
|
|
9
|
+
return normalizeMemoryConfig(await readJsonFile(getMemoryConfigPath(), DEFAULT_MEMORY_CONFIG));
|
|
10
|
+
}
|
|
11
|
+
export async function writeMemoryConfig(config) {
|
|
12
|
+
await writeJsonFile(getMemoryConfigPath(), normalizeMemoryConfig(config));
|
|
13
|
+
}
|
|
14
|
+
export async function getMemoryEmbeddingConfig() {
|
|
15
|
+
return (await readMemoryConfig()).embedding;
|
|
16
|
+
}
|
|
17
|
+
export async function setMemoryEmbeddingConfig(input) {
|
|
18
|
+
const next = normalizeMemoryEmbeddingConfig({
|
|
19
|
+
enabled: true,
|
|
20
|
+
name: input.name,
|
|
21
|
+
baseUrl: input.baseUrl,
|
|
22
|
+
apiKey: input.apiKey,
|
|
23
|
+
model: input.model,
|
|
24
|
+
providerType: input.providerType ?? inferProviderType(input.name, input.baseUrl, input.model),
|
|
25
|
+
queryTask: input.queryTask,
|
|
26
|
+
passageTask: input.passageTask,
|
|
27
|
+
dimensions: input.dimensions ?? null,
|
|
28
|
+
updatedAt: new Date().toISOString(),
|
|
29
|
+
lastCheckedAt: null,
|
|
30
|
+
lastError: null
|
|
31
|
+
});
|
|
32
|
+
await updateJsonFile(getMemoryConfigPath(), DEFAULT_MEMORY_CONFIG, (current) => ({
|
|
33
|
+
...normalizeMemoryConfig(current),
|
|
34
|
+
embedding: next
|
|
35
|
+
}));
|
|
36
|
+
return next;
|
|
37
|
+
}
|
|
38
|
+
export async function updateMemoryEmbeddingCheck(result) {
|
|
39
|
+
const updated = await updateJsonFile(getMemoryConfigPath(), DEFAULT_MEMORY_CONFIG, (current) => {
|
|
40
|
+
const normalized = normalizeMemoryConfig(current);
|
|
41
|
+
if (!normalized.embedding)
|
|
42
|
+
return normalized;
|
|
43
|
+
return {
|
|
44
|
+
...normalized,
|
|
45
|
+
embedding: {
|
|
46
|
+
...normalized.embedding,
|
|
47
|
+
dimensions: result.dimensions ?? normalized.embedding.dimensions,
|
|
48
|
+
lastCheckedAt: result.checkedAt,
|
|
49
|
+
lastError: result.error
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
return updated.embedding;
|
|
54
|
+
}
|
|
55
|
+
export async function clearMemoryEmbeddingConfig() {
|
|
56
|
+
const previous = await readMemoryConfig();
|
|
57
|
+
await updateJsonFile(getMemoryConfigPath(), DEFAULT_MEMORY_CONFIG, (current) => ({
|
|
58
|
+
...normalizeMemoryConfig(current),
|
|
59
|
+
embedding: null
|
|
60
|
+
}));
|
|
61
|
+
return previous.embedding !== null;
|
|
62
|
+
}
|
|
63
|
+
export function normalizeMemoryConfig(value) {
|
|
64
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
65
|
+
return DEFAULT_MEMORY_CONFIG;
|
|
66
|
+
}
|
|
67
|
+
const record = value;
|
|
68
|
+
return {
|
|
69
|
+
embedding: record.embedding ? normalizeMemoryEmbeddingConfig(record.embedding) : null
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function normalizeMemoryEmbeddingConfig(value) {
|
|
73
|
+
const record = readRecord(value, "memory.embedding");
|
|
74
|
+
const name = readString(record, "name");
|
|
75
|
+
const baseUrl = readString(record, "baseUrl").replace(/\/+$/, "");
|
|
76
|
+
const apiKey = readString(record, "apiKey");
|
|
77
|
+
const model = readString(record, "model");
|
|
78
|
+
if (!name)
|
|
79
|
+
throw new Error("Memory embedding provider name cannot be empty.");
|
|
80
|
+
if (!baseUrl)
|
|
81
|
+
throw new Error("Memory embedding baseUrl cannot be empty.");
|
|
82
|
+
if (!apiKey)
|
|
83
|
+
throw new Error("Memory embedding apiKey cannot be empty.");
|
|
84
|
+
if (!model)
|
|
85
|
+
throw new Error("Memory embedding model cannot be empty.");
|
|
86
|
+
const rawProviderType = readString(record, "providerType", {
|
|
87
|
+
fallback: inferProviderType(name, baseUrl, model)
|
|
88
|
+
});
|
|
89
|
+
const providerType = VALID_PROVIDER_TYPES.has(rawProviderType)
|
|
90
|
+
? rawProviderType
|
|
91
|
+
: inferProviderType(name, baseUrl, model);
|
|
92
|
+
const queryTask = readOptionalString(record, "queryTask") ?? defaultQueryTask(providerType);
|
|
93
|
+
const passageTask = readOptionalString(record, "passageTask") ?? defaultPassageTask(providerType);
|
|
94
|
+
const dimensions = normalizeDimensions(readNumber(record, "dimensions", 0));
|
|
95
|
+
return {
|
|
96
|
+
enabled: record.enabled === false ? false : true,
|
|
97
|
+
name,
|
|
98
|
+
baseUrl,
|
|
99
|
+
apiKey,
|
|
100
|
+
model,
|
|
101
|
+
providerType,
|
|
102
|
+
...(queryTask ? { queryTask } : {}),
|
|
103
|
+
...(passageTask ? { passageTask } : {}),
|
|
104
|
+
dimensions,
|
|
105
|
+
updatedAt: readString(record, "updatedAt", { fallback: new Date().toISOString() }),
|
|
106
|
+
lastCheckedAt: readOptionalString(record, "lastCheckedAt") ?? null,
|
|
107
|
+
lastError: readOptionalString(record, "lastError") ?? null
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function inferProviderType(name, baseUrl, model) {
|
|
111
|
+
const value = `${name} ${baseUrl} ${model}`.toLowerCase();
|
|
112
|
+
return value.includes("jina") ? "jina" : "openai-compatible";
|
|
113
|
+
}
|
|
114
|
+
function defaultQueryTask(providerType) {
|
|
115
|
+
return providerType === "jina" ? "retrieval.query" : undefined;
|
|
116
|
+
}
|
|
117
|
+
function defaultPassageTask(providerType) {
|
|
118
|
+
return providerType === "jina" ? "retrieval.passage" : undefined;
|
|
119
|
+
}
|
|
120
|
+
function normalizeDimensions(value) {
|
|
121
|
+
return Number.isInteger(value) && value > 0 ? value : null;
|
|
122
|
+
}
|