mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-08 10:41:49 +08:00
merge
This commit is contained in:
@@ -5,7 +5,8 @@ import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { execFile } from "node:child_process";
|
||||
import { getOpenAIClient, routeDecision, type LLMDecisionResult } from "../../utils/openai";
|
||||
import { getOpenAIClient, routeDecision } from "../../utils/openai";
|
||||
import type { LLMDecisionResult } from "~~/shared/types/llm";
|
||||
import { createReadStream } from "node:fs";
|
||||
import { TransmissionLog } from "../../models/TransmissionLog";
|
||||
import { getUserFromEvent } from "../../utils/auth";
|
||||
@@ -17,9 +18,10 @@ interface PTTRequest {
|
||||
context: {
|
||||
state_id: string;
|
||||
state: any;
|
||||
candidates: Array<{ id: string; state: any }>;
|
||||
candidates: Array<{ id: string; state: any; flow?: string }>;
|
||||
variables: Record<string, any>;
|
||||
flags: Record<string, any>;
|
||||
flow_slug?: string;
|
||||
};
|
||||
moduleId: string;
|
||||
lessonId: string;
|
||||
@@ -30,12 +32,9 @@ interface PTTRequest {
|
||||
interface PTTResponse {
|
||||
success: boolean;
|
||||
transcription: string;
|
||||
decision?: {
|
||||
next_state: string;
|
||||
controller_say_tpl?: string;
|
||||
off_schema?: boolean;
|
||||
radio_check?: boolean;
|
||||
};
|
||||
decision?: LLMDecisionResult['decision'];
|
||||
trace?: LLMDecisionResult['trace'];
|
||||
active_nodes?: LLMDecisionResult['active_nodes'];
|
||||
}
|
||||
|
||||
async function sh(cmd: string, args: string[]) {
|
||||
@@ -225,6 +224,7 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
return {
|
||||
id: candidate.id,
|
||||
flow: candidate.flow || undefined,
|
||||
state: candidateState
|
||||
};
|
||||
})
|
||||
@@ -232,12 +232,17 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
const selectedCandidate = contextCandidates?.find(c => c.id === decision?.next_state);
|
||||
|
||||
const sessionId = typeof body.context?.flags?.session_id === 'string'
|
||||
? body.context.flags.session_id
|
||||
: undefined;
|
||||
|
||||
await TransmissionLog.create({
|
||||
user: user?._id,
|
||||
role: "pilot",
|
||||
channel: "ptt",
|
||||
direction: "incoming",
|
||||
text: transcribedText,
|
||||
sessionId,
|
||||
metadata: {
|
||||
moduleId: body.moduleId,
|
||||
lessonId: body.lessonId,
|
||||
@@ -267,6 +272,12 @@ export default defineEventHandler(async (event) => {
|
||||
if (decision) {
|
||||
result.decision = decision;
|
||||
}
|
||||
if (decisionResult?.trace) {
|
||||
result.trace = decisionResult.trace;
|
||||
}
|
||||
if (decisionResult?.active_nodes?.length) {
|
||||
result.active_nodes = decisionResult.active_nodes;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
@@ -123,10 +123,16 @@ export default defineEventHandler(async (event) => {
|
||||
lessonId?: string;
|
||||
tag?: string;
|
||||
format?: AudioFmt | "smallest";
|
||||
sessionId?: string;
|
||||
}>(event);
|
||||
|
||||
const user = await requireUserSession(event);
|
||||
|
||||
const rawSessionId = typeof body?.sessionId === "string"
|
||||
? body.sessionId.trim()
|
||||
: "";
|
||||
const sessionId = rawSessionId.length ? rawSessionId : undefined;
|
||||
|
||||
const raw = (body?.text || "").trim();
|
||||
if (!raw) throw createError({ statusCode: 400, statusMessage: "text required" });
|
||||
|
||||
@@ -226,6 +232,7 @@ export default defineEventHandler(async (event) => {
|
||||
direction: "outgoing",
|
||||
text: raw,
|
||||
normalized,
|
||||
sessionId,
|
||||
metadata: {
|
||||
level,
|
||||
voice,
|
||||
|
||||
Reference in New Issue
Block a user