Initial import NDC_1C
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildAccountingAgentRouter = buildAccountingAgentRouter;
|
||||
const express_1 = require("express");
|
||||
const http_1 = require("../utils/http");
|
||||
const PREFIX = "/api/accounting-agent/v1";
|
||||
function buildAccountingAgentRouter(services) {
|
||||
const router = (0, express_1.Router)();
|
||||
const runtime = services.runtimeAdapter;
|
||||
router.post(`${PREFIX}/runs/start`, (req, res, next) => {
|
||||
try {
|
||||
const body = (req.body ?? {});
|
||||
const run = runtime.startRun({
|
||||
sessionId: body.sessionId ? String(body.sessionId) : undefined,
|
||||
initiator: body.initiator ? String(body.initiator) : "operator",
|
||||
source: body.source ? String(body.source) : "gui",
|
||||
metadata: (body.metadata ?? {}),
|
||||
idempotencyKey: body.idempotencyKey ? String(body.idempotencyKey) : undefined
|
||||
});
|
||||
(0, http_1.created)(res, {
|
||||
ok: true,
|
||||
sessionId: run.sessionId,
|
||||
runId: run.runId,
|
||||
status: run.status,
|
||||
run
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
router.post(`${PREFIX}/runs/finish`, (req, res, next) => {
|
||||
try {
|
||||
const body = (req.body ?? {});
|
||||
const status = String(body.status ?? "DONE");
|
||||
if (!["DONE", "ERROR", "CANCELLED"].includes(status)) {
|
||||
throw new http_1.ApiError("INVALID_STATUS", `Invalid finish status: ${status}`, 400);
|
||||
}
|
||||
const run = runtime.finishRun({
|
||||
runId: String(body.runId ?? ""),
|
||||
status,
|
||||
source: body.source ? String(body.source) : "gui",
|
||||
reason: body.reason ? String(body.reason) : undefined,
|
||||
metadata: (body.metadata ?? {}),
|
||||
idempotencyKey: body.idempotencyKey ? String(body.idempotencyKey) : undefined
|
||||
});
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
run
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
router.get(`${PREFIX}/runs`, (_req, res) => {
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
items: runtime.listRuns()
|
||||
});
|
||||
});
|
||||
router.get(`${PREFIX}/runs/:runId`, (req, res, next) => {
|
||||
try {
|
||||
const run = runtime.getRun(String(req.params.runId));
|
||||
if (!run) {
|
||||
throw new http_1.ApiError("RUN_NOT_FOUND", `Run not found: ${req.params.runId}`, 404);
|
||||
}
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
run
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
router.post(`${PREFIX}/tasks/enqueue`, (req, res, next) => {
|
||||
try {
|
||||
const body = (req.body ?? {});
|
||||
const task = runtime.enqueueTask({
|
||||
runId: String(body.runId ?? ""),
|
||||
payload: (body.payload ?? {}),
|
||||
source: body.source ? String(body.source) : "gui",
|
||||
idempotencyKey: body.idempotencyKey ? String(body.idempotencyKey) : undefined
|
||||
});
|
||||
(0, http_1.created)(res, {
|
||||
ok: true,
|
||||
task
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
router.post(`${PREFIX}/tasks/claim`, (_req, res) => {
|
||||
const task = runtime.claimTask();
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
task
|
||||
});
|
||||
});
|
||||
router.post(`${PREFIX}/tasks/:taskId/complete`, (req, res, next) => {
|
||||
try {
|
||||
const body = (req.body ?? {});
|
||||
const task = runtime.completeTask({
|
||||
taskId: String(req.params.taskId),
|
||||
result: (body.result ?? {}),
|
||||
source: body.source ? String(body.source) : "worker",
|
||||
idempotencyKey: body.idempotencyKey ? String(body.idempotencyKey) : undefined
|
||||
});
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
task
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
router.post(`${PREFIX}/tasks/:taskId/error`, (req, res, next) => {
|
||||
try {
|
||||
const body = (req.body ?? {});
|
||||
const task = runtime.failTask({
|
||||
taskId: String(req.params.taskId),
|
||||
error: {
|
||||
code: String(body.code ?? "TASK_ERROR"),
|
||||
message: String(body.message ?? "Task failed"),
|
||||
details: body.details
|
||||
},
|
||||
source: body.source ? String(body.source) : "worker",
|
||||
idempotencyKey: body.idempotencyKey ? String(body.idempotencyKey) : undefined
|
||||
});
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
task
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
router.get(`${PREFIX}/results`, (_req, res) => {
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
items: runtime.getResults()
|
||||
});
|
||||
});
|
||||
router.get(`${PREFIX}/trace/run/:runId`, (req, res) => {
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
items: runtime.getRunTrace(String(req.params.runId))
|
||||
});
|
||||
});
|
||||
router.get(`${PREFIX}/health`, (_req, res) => {
|
||||
(0, http_1.ok)(res, runtime.health());
|
||||
});
|
||||
return router;
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildAssistantRouter = buildAssistantRouter;
|
||||
const express_1 = require("express");
|
||||
const http_1 = require("../utils/http");
|
||||
function buildAssistantRouter(services) {
|
||||
const router = (0, express_1.Router)();
|
||||
router.post("/api/assistant/message", async (req, res, next) => {
|
||||
try {
|
||||
const payload = (req.body ?? {});
|
||||
const userMessageSource = typeof payload.user_message === "string"
|
||||
? payload.user_message
|
||||
: typeof payload.message === "string"
|
||||
? payload.message
|
||||
: "";
|
||||
const userMessage = userMessageSource.trim();
|
||||
if (!userMessage) {
|
||||
throw new http_1.ApiError("INVALID_ASSISTANT_MESSAGE", "Field `user_message` or `message` is required.", 400);
|
||||
}
|
||||
const response = await services.assistantService.handleMessage({
|
||||
...payload,
|
||||
user_message: userMessage,
|
||||
message: userMessage,
|
||||
mode: typeof payload.mode === "string" ? payload.mode : "assistant"
|
||||
});
|
||||
(0, http_1.ok)(res, response);
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
router.get("/api/assistant/session/:session_id", (req, res, next) => {
|
||||
try {
|
||||
const sessionId = String(req.params.session_id ?? "");
|
||||
const session = services.assistantService.getSession(sessionId);
|
||||
if (!session) {
|
||||
throw new http_1.ApiError("ASSISTANT_SESSION_NOT_FOUND", `Session not found: ${sessionId}`, 404);
|
||||
}
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
session
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
return router;
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildEvalRouter = buildEvalRouter;
|
||||
const express_1 = require("express");
|
||||
const http_1 = require("../utils/http");
|
||||
function buildEvalRouter(services) {
|
||||
const router = (0, express_1.Router)();
|
||||
router.post("/api/eval/run", async (req, res, next) => {
|
||||
try {
|
||||
const body = (req.body ?? {});
|
||||
const report = await services.evalService.run({
|
||||
normalizeConfig: (body.normalizeConfig ?? {}),
|
||||
caseIds: Array.isArray(body.caseIds) ? body.caseIds : undefined,
|
||||
useMock: Boolean(body.useMock),
|
||||
mode: body.mode ?? "standard",
|
||||
caseSetFile: typeof body.caseSetFile === "string" ? body.caseSetFile : undefined,
|
||||
rawQuestions: typeof body.rawQuestions === "string" ? body.rawQuestions : undefined,
|
||||
evalTarget: body.eval_target ?? "normalizer",
|
||||
compareWithReportFile: typeof body.compare_with_report_file === "string"
|
||||
? body.compare_with_report_file
|
||||
: typeof body.comparisonBaselineReportFile === "string"
|
||||
? body.comparisonBaselineReportFile
|
||||
: undefined
|
||||
});
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
report
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
return router;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildHistoryRouter = buildHistoryRouter;
|
||||
const express_1 = require("express");
|
||||
const traceLogger_1 = require("../services/traceLogger");
|
||||
const http_1 = require("../utils/http");
|
||||
function buildHistoryRouter() {
|
||||
const router = (0, express_1.Router)();
|
||||
router.get("/api/history", (_req, res) => {
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
items: (0, traceLogger_1.listTraces)(200)
|
||||
});
|
||||
});
|
||||
router.get("/api/history/:trace_id", (req, res, next) => {
|
||||
try {
|
||||
const traceId = String(req.params.trace_id);
|
||||
const trace = (0, traceLogger_1.getTrace)(traceId);
|
||||
if (!trace) {
|
||||
throw new http_1.ApiError("TRACE_NOT_FOUND", `Trace not found: ${traceId}`, 404);
|
||||
}
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
trace
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
return router;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildNormalizeRouter = buildNormalizeRouter;
|
||||
const express_1 = require("express");
|
||||
const http_1 = require("../utils/http");
|
||||
function buildNormalizeRouter(services) {
|
||||
const router = (0, express_1.Router)();
|
||||
router.post("/api/normalize", async (req, res, next) => {
|
||||
try {
|
||||
const payload = req.body;
|
||||
const result = await services.normalizerService.normalize(payload);
|
||||
(0, http_1.ok)(res, result);
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
return router;
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildPresetsRouter = buildPresetsRouter;
|
||||
const express_1 = require("express");
|
||||
const nanoid_1 = require("nanoid");
|
||||
const config_1 = require("../config");
|
||||
const promptBuilder_1 = require("../services/promptBuilder");
|
||||
const traceLogger_1 = require("../services/traceLogger");
|
||||
const http_1 = require("../utils/http");
|
||||
function buildPresetsRouter() {
|
||||
const router = (0, express_1.Router)();
|
||||
router.get("/api/presets", (_req, res) => {
|
||||
const stored = (0, traceLogger_1.listPresets)();
|
||||
const builtin = (0, promptBuilder_1.listBuiltinPromptPresets)();
|
||||
const combined = [...builtin, ...stored];
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
default_prompt_version: config_1.DEFAULT_PROMPT_VERSION,
|
||||
presets: combined
|
||||
});
|
||||
});
|
||||
router.post("/api/presets/save", (req, res, next) => {
|
||||
try {
|
||||
const body = (req.body ?? {});
|
||||
const now = new Date().toISOString();
|
||||
const preset = {
|
||||
id: body.id ?? `preset-${(0, nanoid_1.nanoid)(8)}`,
|
||||
name: body.name ?? "Пользовательский пресет",
|
||||
createdAt: body.createdAt ?? now,
|
||||
updatedAt: now,
|
||||
prompt_version: body.prompt_version ?? config_1.DEFAULT_PROMPT_VERSION,
|
||||
systemPrompt: body.systemPrompt ?? "",
|
||||
developerPrompt: body.developerPrompt ?? "",
|
||||
domainPrompt: body.domainPrompt ?? "",
|
||||
schemaNotes: body.schemaNotes ?? "",
|
||||
fewShotExamples: body.fewShotExamples ?? ""
|
||||
};
|
||||
(0, traceLogger_1.savePreset)(preset);
|
||||
(0, http_1.created)(res, {
|
||||
ok: true,
|
||||
preset
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
return router;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildTestConnectionRouter = buildTestConnectionRouter;
|
||||
const express_1 = require("express");
|
||||
const config_1 = require("../config");
|
||||
const http_1 = require("../utils/http");
|
||||
function buildTestConnectionRouter(client) {
|
||||
const router = (0, express_1.Router)();
|
||||
router.post("/api/openai/test-connection", async (req, res, next) => {
|
||||
try {
|
||||
const body = (req.body ?? {});
|
||||
const result = await client.testConnection({
|
||||
apiKey: String(body.apiKey ?? process.env.OPENAI_API_KEY ?? ""),
|
||||
model: String(body.model ?? config_1.DEFAULT_MODEL),
|
||||
baseUrl: String(body.baseUrl ?? config_1.DEFAULT_OPENAI_BASE_URL)
|
||||
});
|
||||
(0, http_1.ok)(res, {
|
||||
ok: true,
|
||||
model: result.model,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
return router;
|
||||
}
|
||||
Reference in New Issue
Block a user